index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. <template>
  2. <view class="permission">
  3. <Nav :leftShow='false' :customNav='true' title="君子校园">
  4. <template>
  5. <view slot="custom" class="text-align-center fs-36 fw-600">
  6. 授权登录/注册
  7. </view>
  8. </template>
  9. </Nav>
  10. <view class="user-permission">
  11. <view class="head">
  12. <view class="head-button">
  13. <image src="@/static/img/logo/logo.png" class="head-img" mode=""></image>
  14. <view class="head-text">君子校园</view>
  15. </view>
  16. </view>
  17. <!-- <view class="hint-box">
  18. <view class="hint-title">该程序将获取以下授权:</view>
  19. <view class="hint-info">获取你的公开信息(昵称,头像等)</view>
  20. <view class="hint-info">获取你的小程序唯一标示用于账户授权登陆</view>
  21. </view> -->
  22. <view class="phone-box mb-22">
  23. <image class="icons" src="@/static/img/my/yzm-icons.png" mode=""></image>
  24. <input v-model="from.phone" type="number" class="uni-input b-rad-200" maxlength="11" focus
  25. placeholder="请输入手机号" />
  26. </view>
  27. <view class="flex-justify-space mb-40">
  28. <view class="phone-box mr-24 common-view-css">
  29. <image class="icons" src="@/static/img/my/yzm-icons.png" mode=""></image>
  30. <input v-model="from.sms_code" type="number" class="uni-input b-rad-200" placeholder="请输入验证码" />
  31. </view>
  32. <view class="get-code-box" @click="getCode()">
  33. <view class="get-but fc-57CAFF fs-32 text-align-center b-rad-200">
  34. {{codeNUm == 0?codeText:codeNUm + 's'}}
  35. </view>
  36. </view>
  37. </view>
  38. <view class="hint">
  39. <view class="hint-left-circle" @click.stop="isFlag = !isFlag">
  40. <view v-if="!isFlag" class="hint-circle"></view>
  41. <image v-else class="hint-img" src="@/static/img/common/y-select.png" mode=""></image>
  42. </view>
  43. <view class="hint-text-1" @click.stop="isFlag = !isFlag">我已阅读并同意</view>
  44. <view class="hint-text-2" @click="openPop(0)">《用户服务》</view>
  45. <view class="hint-text-2" @click="openPop(1)">《隐私协议》</view>
  46. </view>
  47. <view class="button">
  48. <view class="common permission-login" @click="login">授权登录/注册</view>
  49. <view class="common permission-cancel" @click="noLogin">暂不登录</view>
  50. </view>
  51. </view>
  52. <view v-if="isPop" class="pop-view">
  53. <view class="pop-view-box">
  54. <view class="pop-info" v-html="html"></view>
  55. <view class="pop-botton">
  56. <view style="background-color: #3169FA;color: white;" class=" " @click="setCheck(1)">确定</view>
  57. <view style="color: #3169FA;" class="" @click="setCheck()">取消</view>
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. import tools from "@/service/tools";
  65. import {
  66. commonRegisterSms
  67. } from '@/api/common.js';
  68. import {
  69. membeRphoneLogin
  70. } from "@/api/member";
  71. import {
  72. getAgreement
  73. } from "@/api/common.js";
  74. export default {
  75. data() {
  76. return {
  77. isFlag: false,
  78. isAjax: false,
  79. from: {
  80. code: "",
  81. system_type: '',
  82. phone: '',
  83. sms_code: '',
  84. invite_code: ''
  85. },
  86. isCode: false,
  87. codeText: '获取验证码',
  88. codeNUm: 0,
  89. isPop: false,
  90. html: '',
  91. agreementData: []
  92. };
  93. },
  94. onLoad() {},
  95. mounted() {
  96. this.getPrivacyInfo()
  97. this.getType()
  98. },
  99. methods: {
  100. openPop(index) {
  101. this.html = this.agreementData[index].content
  102. this.isPop = true
  103. },
  104. getCode() {
  105. if (!this.from.phone) {
  106. return tools.error('请输入手机号')
  107. }
  108. if (this.isCode) {
  109. return
  110. }
  111. this.isCode = true;
  112. commonRegisterSms({
  113. phone: this.from.phone,
  114. }).then((res) => {
  115. if (res.code === 1) {
  116. this.codeNUm = 60;
  117. let timer = setInterval(() => {
  118. this.codeNUm -= 1;
  119. if (this.codeNUm <= 0) {
  120. clearInterval(timer);
  121. this.isCode = false;
  122. this.codeText = '获取验证码'
  123. }
  124. }, 1000);
  125. } else {
  126. this.isCode = false;
  127. tools.error('获取验证码失败,请稍后重试')
  128. }
  129. })
  130. },
  131. getPrivacyInfo() {
  132. getAgreement().then((res) => {
  133. if (res.code === 1) {
  134. this.agreementData = res.data
  135. }
  136. })
  137. },
  138. getType() {
  139. let that = this
  140. uni.getProvider({
  141. service: 'oauth',
  142. success: function(res) {
  143. if (res.provider[0] === 'weixin') {
  144. that.from.system_type = 2
  145. } else if (res.provider[0] === 'qq') {
  146. that.from.system_type = 3
  147. } else {
  148. that.from.system_type = 1
  149. }
  150. uni.setStorageSync('system_type', that.from.system_type)
  151. }
  152. });
  153. },
  154. setCheck(type) {
  155. if (type === 1) {
  156. this.isFlag = false
  157. }
  158. this.isPop = false
  159. },
  160. login() {
  161. if (!this.isFlag) {
  162. return tools.error("请先勾选协议");
  163. }
  164. if (this.isAjax) {
  165. return false;
  166. }
  167. this.isAjax = true;
  168. uni.login({
  169. //#ifdef MP-WEIXIN
  170. provider: "weixin",
  171. //#endif
  172. //#ifdef MP-QQ
  173. provider: "qq",
  174. //#endif
  175. success: (loginRes) => {
  176. this.from.code = loginRes.code;
  177. this.getUserInfo();
  178. },
  179. fail: (loginRes) => {
  180. this.isAjax = false;
  181. tools.error("获取授权信息失败");
  182. },
  183. });
  184. },
  185. noLogin() {
  186. uni.switchTab({
  187. url: "/pages/index/index",
  188. });
  189. },
  190. async getUserInfo() {
  191. this.from.invite_code = uni.getStorageSync('iCode');
  192. const res = await membeRphoneLogin(this.from);
  193. if (res.code == 1) {
  194. uni.setStorageSync('token', res.data.token)
  195. uni.setStorageSync('m_id', res.data.m_id)
  196. tools.success("授权成功");
  197. setTimeout(() => {
  198. uni.switchTab({
  199. url: "/pages/index/index",
  200. });
  201. }, 1000);
  202. } else {
  203. this.isAjax = false;
  204. tools.error(res.msg);
  205. }
  206. },
  207. },
  208. };
  209. </script>
  210. <style scoped lang="scss">
  211. .permission {
  212. width: 100vw;
  213. height: 100vh;
  214. background-color: #fff;
  215. position: relative;
  216. .hint {
  217. margin-top: 20rpx;
  218. display: flex;
  219. height: 34rpx;
  220. .hint-left-circle {
  221. width: 32rpx;
  222. height: 32rpx;
  223. margin-right: 18rpx;
  224. .hint-circle {
  225. width: 30rpx;
  226. height: 30rpx;
  227. border-radius: 50%;
  228. background-color: #fff;
  229. border: 2rpx solid #D9D9D9;
  230. }
  231. .hint-img {
  232. width: 32rpx;
  233. height: 32rpx;
  234. border-radius: 50%;
  235. }
  236. }
  237. .hint-text-1,
  238. .hint-text-2 {
  239. font-size: 24rpx;
  240. font-weight: 400;
  241. }
  242. .hint-text-1 {
  243. color: #999999;
  244. }
  245. .hint-text-2 {
  246. color: #ED301D;
  247. }
  248. }
  249. .hint-box {
  250. margin-top: 140rpx;
  251. margin-bottom: 20rpx;
  252. .hint-title {
  253. font-size: 28rpx;
  254. }
  255. .hint-info {
  256. font-size: 24rpx;
  257. color: #6f6f6f;
  258. margin-top: 12rpx;
  259. }
  260. }
  261. .pop-view {
  262. width: 100%;
  263. height: 100vh;
  264. position: absolute;
  265. top: 0;
  266. left: 0;
  267. background: rgba(0, 0, 0, 0.5);
  268. .pop-view-box {
  269. display: flex;
  270. flex-direction: column;
  271. margin: 400rpx auto;
  272. width: 80vw;
  273. height: 50vh;
  274. overflow: scroll;
  275. background-color: #fff;
  276. border-radius: 10rpx;
  277. box-sizing: border-box;
  278. padding: 20rpx 40rpx;
  279. .pop-info {
  280. flex: 1;
  281. overflow: auto;
  282. }
  283. .pop-botton {
  284. display: flex;
  285. justify-content: space-between;
  286. margin-top: 20rpx;
  287. box-sizing: border-box;
  288. padding: 0 130rpx;
  289. view {
  290. width: 100rpx;
  291. height: 50rpx;
  292. line-height: 50rpx;
  293. text-align: center;
  294. font-size: 30rpx;
  295. border: 2rpx solid #3169FA;
  296. border-radius: 10rpx;
  297. margin: 0 10rpx;
  298. }
  299. }
  300. }
  301. }
  302. .user-permission {
  303. position: absolute;
  304. top: 40%;
  305. left: 50%;
  306. transform: translate(-50%, -50%);
  307. width: 100%;
  308. padding: 0 36rpx;
  309. box-sizing: border-box;
  310. .head {
  311. display: flex;
  312. flex-direction: column;
  313. align-items: center;
  314. margin-bottom: 40rpx;
  315. button::after {
  316. border-color: #fff !important;
  317. }
  318. .head-button {
  319. background-color: #fff;
  320. padding: 0;
  321. }
  322. .head-text {
  323. text-align: center;
  324. margin-top: 16rpx;
  325. font-weight: 400;
  326. color: #333333;
  327. font-size: 28rpx;
  328. }
  329. .head-img {
  330. width: 120rpx;
  331. height: 120rpx;
  332. border-radius: 50%;
  333. margin: 0 auto;
  334. }
  335. }
  336. .user-name-view {
  337. display: flex;
  338. margin-top: 100rpx;
  339. .user-name {
  340. font-weight: 400;
  341. color: #333333;
  342. font-size: 32rpx;
  343. }
  344. .user-input {
  345. width: 568rpx;
  346. border-bottom: 1rpx solid #D9D9D9;
  347. font-size: 32rpx;
  348. padding-bottom: 16rpx;
  349. }
  350. }
  351. .button {
  352. margin-top: 60rpx;
  353. .common {
  354. width: 100%;
  355. height: 88rpx;
  356. line-height: 88rpx;
  357. text-align: center;
  358. border-radius: 200rpx;
  359. }
  360. .permission-login {
  361. background: #41ABF5;
  362. color: #fff;
  363. &:active {
  364. background-color: #41ABF5;
  365. }
  366. }
  367. .permission-cancel {
  368. margin-top: 40rpx;
  369. background: rgb(247, 247, 247);
  370. &:active {
  371. background-color: rgb(238, 238, 238);
  372. }
  373. }
  374. }
  375. }
  376. }
  377. .phone-box {
  378. position: relative;
  379. }
  380. .uni-input {
  381. // width: 100%;
  382. background: #F6F6F6;
  383. height: 80rpx;
  384. line-height: 80rpx;
  385. padding: 0 0 0 68rpx;
  386. }
  387. .icons {
  388. position: absolute;
  389. top: 30rpx;
  390. left: 24rpx;
  391. width: 32rpx;
  392. height: 32rpx;
  393. }
  394. .get-code-box {
  395. width: 208rpx;
  396. }
  397. .get-but {
  398. width: 100%;
  399. height: 80rpx;
  400. line-height: 80rpx;
  401. border: 2rpx solid #57CAFF;
  402. box-sizing: border-box;
  403. }
  404. </style>