index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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="isPop = true;html = member_agreement">《用户服务》</view>
  45. <view class="hint-text-2" @click="isPop = true;html = privacy_protocol">《隐私协议》</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. member_agreement: '', //用户协议
  92. privacy_protocol: '', //隐私协议
  93. };
  94. },
  95. onLoad() {},
  96. mounted() {
  97. this.getPrivacyInfo()
  98. this.getType()
  99. },
  100. methods: {
  101. getCode() {
  102. if (!this.from.phone) {
  103. return tools.error('请输入手机号')
  104. }
  105. if (this.isCode) {
  106. return
  107. }
  108. this.isCode = true;
  109. commonRegisterSms({
  110. phone: this.from.phone,
  111. }).then((res) => {
  112. if (res.code === 1) {
  113. this.codeNUm = 60;
  114. let timer = setInterval(() => {
  115. this.codeNUm -= 1;
  116. if (this.codeNUm <= 0) {
  117. clearInterval(timer);
  118. this.isCode = false;
  119. this.codeText = '获取验证码'
  120. }
  121. }, 1000);
  122. } else {
  123. this.isCode = false;
  124. tools.error('获取验证码失败,请稍后重试')
  125. }
  126. })
  127. },
  128. getPrivacyInfo() {
  129. getAgreement().then((res) => {
  130. if (res.code === 1) {
  131. this.member_agreement = res.data.member_agreement;
  132. this.privacy_protocol = res.data.privacy_protocol;
  133. }
  134. })
  135. },
  136. getType() {
  137. let that = this
  138. uni.getProvider({
  139. service: 'oauth',
  140. success: function(res) {
  141. if (res.provider[0] === 'weixin') {
  142. that.from.system_type = 2
  143. } else if (res.provider[0] === 'qq') {
  144. that.from.system_type = 3
  145. } else {
  146. that.from.system_type = 1
  147. }
  148. uni.setStorageSync('system_type', that.from.system_type)
  149. }
  150. });
  151. },
  152. setCheck(type) {
  153. if (type === 1) {
  154. this.isFlag = false
  155. }
  156. this.isPop = false
  157. },
  158. login() {
  159. if (!this.isFlag) {
  160. return tools.error("请先勾选协议");
  161. }
  162. if (this.isAjax) {
  163. return false;
  164. }
  165. this.isAjax = true;
  166. uni.login({
  167. //#ifdef MP-WEIXIN
  168. provider: "weixin",
  169. //#endif
  170. //#ifdef MP-QQ
  171. provider: "qq",
  172. //#endif
  173. success: (loginRes) => {
  174. this.from.code = loginRes.code;
  175. this.getUserInfo();
  176. },
  177. fail: (loginRes) => {
  178. this.isAjax = false;
  179. tools.error("获取授权信息失败");
  180. },
  181. });
  182. },
  183. noLogin() {
  184. uni.switchTab({
  185. url: "/pages/index/index",
  186. });
  187. },
  188. async getUserInfo() {
  189. this.from.invite_code = uni.getStorageSync('iCode');
  190. const res = await membeRphoneLogin(this.from);
  191. if (res.code == 1) {
  192. uni.setStorageSync('token', res.data.token)
  193. uni.setStorageSync('m_id', res.data.m_id)
  194. tools.success("授权成功");
  195. setTimeout(() => {
  196. uni.switchTab({
  197. url: "/pages/index/index",
  198. });
  199. }, 1000);
  200. } else {
  201. this.isAjax = false;
  202. tools.error(res.msg);
  203. }
  204. },
  205. },
  206. };
  207. </script>
  208. <style scoped lang="scss">
  209. .permission {
  210. width: 100vw;
  211. height: 100vh;
  212. background-color: #fff;
  213. position: relative;
  214. .hint {
  215. margin-top: 20rpx;
  216. display: flex;
  217. height: 34rpx;
  218. .hint-left-circle {
  219. width: 32rpx;
  220. height: 32rpx;
  221. margin-right: 18rpx;
  222. .hint-circle {
  223. width: 30rpx;
  224. height: 30rpx;
  225. border-radius: 50%;
  226. background-color: #fff;
  227. border: 2rpx solid #D9D9D9;
  228. }
  229. .hint-img {
  230. width: 32rpx;
  231. height: 32rpx;
  232. border-radius: 50%;
  233. }
  234. }
  235. .hint-text-1,
  236. .hint-text-2 {
  237. font-size: 24rpx;
  238. font-weight: 400;
  239. }
  240. .hint-text-1 {
  241. color: #999999;
  242. }
  243. .hint-text-2 {
  244. color: #ED301D;
  245. }
  246. }
  247. .hint-box {
  248. margin-top: 140rpx;
  249. margin-bottom: 20rpx;
  250. .hint-title {
  251. font-size: 28rpx;
  252. }
  253. .hint-info {
  254. font-size: 24rpx;
  255. color: #6f6f6f;
  256. margin-top: 12rpx;
  257. }
  258. }
  259. .pop-view {
  260. width: 100%;
  261. height: 100vh;
  262. position: absolute;
  263. top: 0;
  264. left: 0;
  265. background: rgba(0, 0, 0, 0.5);
  266. .pop-view-box {
  267. display: flex;
  268. flex-direction: column;
  269. margin: 400rpx auto;
  270. width: 80vw;
  271. height: 50vh;
  272. overflow: scroll;
  273. background-color: #fff;
  274. border-radius: 10rpx;
  275. box-sizing: border-box;
  276. padding: 20rpx 40rpx;
  277. .pop-info {
  278. flex: 1;
  279. overflow: auto;
  280. }
  281. .pop-botton {
  282. display: flex;
  283. justify-content: space-between;
  284. margin-top: 20rpx;
  285. box-sizing: border-box;
  286. padding: 0 130rpx;
  287. view {
  288. width: 100rpx;
  289. height: 50rpx;
  290. line-height: 50rpx;
  291. text-align: center;
  292. font-size: 30rpx;
  293. border: 2rpx solid #3169FA;
  294. border-radius: 10rpx;
  295. margin: 0 10rpx;
  296. }
  297. }
  298. }
  299. }
  300. .user-permission {
  301. position: absolute;
  302. top: 40%;
  303. left: 50%;
  304. transform: translate(-50%, -50%);
  305. width: 100%;
  306. padding: 0 36rpx;
  307. box-sizing: border-box;
  308. .head {
  309. display: flex;
  310. flex-direction: column;
  311. align-items: center;
  312. margin-bottom: 40rpx;
  313. button::after {
  314. border-color: #fff !important;
  315. }
  316. .head-button {
  317. background-color: #fff;
  318. padding: 0;
  319. }
  320. .head-text {
  321. text-align: center;
  322. margin-top: 16rpx;
  323. font-weight: 400;
  324. color: #333333;
  325. font-size: 28rpx;
  326. }
  327. .head-img {
  328. width: 120rpx;
  329. height: 120rpx;
  330. border-radius: 50%;
  331. margin: 0 auto;
  332. }
  333. }
  334. .user-name-view {
  335. display: flex;
  336. margin-top: 100rpx;
  337. .user-name {
  338. font-weight: 400;
  339. color: #333333;
  340. font-size: 32rpx;
  341. }
  342. .user-input {
  343. width: 568rpx;
  344. border-bottom: 1rpx solid #D9D9D9;
  345. font-size: 32rpx;
  346. padding-bottom: 16rpx;
  347. }
  348. }
  349. .button {
  350. margin-top: 60rpx;
  351. .common {
  352. width: 100%;
  353. height: 88rpx;
  354. line-height: 88rpx;
  355. text-align: center;
  356. border-radius: 200rpx;
  357. }
  358. .permission-login {
  359. background: #41ABF5;
  360. color: #fff;
  361. &:active {
  362. background-color: #41ABF5;
  363. }
  364. }
  365. .permission-cancel {
  366. margin-top: 40rpx;
  367. background: rgb(247, 247, 247);
  368. &:active {
  369. background-color: rgb(238, 238, 238);
  370. }
  371. }
  372. }
  373. }
  374. }
  375. .phone-box {
  376. position: relative;
  377. }
  378. .uni-input {
  379. // width: 100%;
  380. background: #F6F6F6;
  381. height: 80rpx;
  382. line-height: 80rpx;
  383. padding: 0 0 0 68rpx;
  384. }
  385. .icons {
  386. position: absolute;
  387. top: 30rpx;
  388. left: 24rpx;
  389. width: 32rpx;
  390. height: 32rpx;
  391. }
  392. .get-code-box {
  393. width: 208rpx;
  394. }
  395. .get-but {
  396. width: 100%;
  397. height: 80rpx;
  398. line-height: 80rpx;
  399. border: 2rpx solid #57CAFF;
  400. box-sizing: border-box;
  401. }
  402. </style>