index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <view class="ezy-login-page">
  3. <view class="ezy-login-wrap">
  4. <icon class="login-e-img"></icon>
  5. <!-- 手机号 -->
  6. <view class="login-body-box">
  7. <view class="index-title-img"></view>
  8. <view class="phone-input-box">
  9. <view class="phone-prefix">+86</view>
  10. <input class="phone-input" type="text" v-model="indexData.phoneNumber" placeholder="请输入手机号"
  11. maxlength="11" @input="clearTelInput" />
  12. <view class="close-btn" v-if="indexData.clearTelIcon" @click="clearTel"></view>
  13. </view>
  14. <!-- 协议勾选框和按钮 -->
  15. <view class="agreement-checkbox-box">
  16. <checkbox-group @change="handleAgreementChange">
  17. <checkbox class="agreement-checkbox-input" color="#FFFFFF" value="agree"
  18. :checked="indexData.isAgreed" />
  19. </checkbox-group>
  20. <view class="agreement-text-box">
  21. 登录注册代表您已同意<view class="agreement-text" @click="agreeBtn('yhxy')">《鹅状元用户协议》</view>和<view
  22. @click="agreeBtn('ystk')" class="agreement-text">《鹅状元隐私政策》</view>
  23. </view>
  24. </view>
  25. <view class="login-btn" @click="getYzmBtn" :class="indexData.telStatus"></view>
  26. </view>
  27. <view class="bottom-btn-box">
  28. <view class="yk-btn" @click="ykBtn"></view>
  29. <view class="wx-btn" @click="wxLoginClick"></view>
  30. <view class="apple-btn" v-if="showAppleLogin" @click="appleLoginClick"></view>
  31. </view>
  32. </view>
  33. <agree-content-dialog ref="agreeContentDialogRef" :agreeType="agreeType"></agree-content-dialog>
  34. <agree-dialog ref="agreeDialogRef" @confirm-btn="confirmBtn"></agree-dialog>
  35. <agree-dialog ref="agreeYkDialog" @confirm-btn="ykConfirmBtn"></agree-dialog>
  36. <tel-dialog ref="telDialogRef" @telClose="telClose" @bindBtn="bindBtn" v-if="telDialogFlag"></tel-dialog>
  37. </view>
  38. </template>
  39. <script setup>
  40. import {
  41. ref,
  42. nextTick,
  43. reactive
  44. } from "vue"
  45. import {
  46. onLoad,
  47. onReady
  48. } from '@dcloudio/uni-app';
  49. import agreeContentDialog from './agreeContentDialog.vue';
  50. import agreeDialog from './agreeDialog.vue'
  51. import {
  52. wxLogin,
  53. } from "@/api/login.js"
  54. import {
  55. toast,
  56. getUserIdentity
  57. } from "@/utils/common";
  58. import telDialog from './telDialog.vue'
  59. import cacheManager from "@/utils/cacheManager.js";
  60. import {
  61. error
  62. } from "uview-plus";
  63. let indexData = reactive({
  64. phoneNumber: null,
  65. clearTelIcon: false,
  66. telStatus: 'tel-btn-disabled',
  67. isAgreed: false,
  68. sliderObj: {},
  69. })
  70. const agreeContentDialogRef = ref(null);
  71. const agreeType = ref(null);
  72. const agreeDialogRef = ref(null);
  73. const agreeYkDialog = ref(null);
  74. const telDialogRef = ref(null);
  75. let telDialogFlag = ref(false);
  76. let showAppleLogin = ref(false);
  77. onLoad((options) => {
  78. showAppleLogin.value = isIOS13OrAbove();
  79. console.log('showAppleLogin.value',showAppleLogin.value);
  80. })
  81. const getYzmBtn = () => {
  82. if (indexData.telStatus === 'tel-btn-normal') {
  83. if (indexData.isAgreed === true) {
  84. uni.navigateTo({
  85. url: `/pages/login/login?telNum=${indexData.phoneNumber}`
  86. })
  87. } else {
  88. agreeDialogRef.value.handleShow();
  89. }
  90. }
  91. }
  92. const isIOS13OrAbove = () => {
  93. const systemInfo = uni.getSystemInfoSync();
  94. if (systemInfo.platform == 'ios') {
  95. const version = systemInfo.system.split(' ')[1].split('.');
  96. const majorVersion = parseInt(version[0], 10);
  97. return majorVersion >= 13;
  98. }
  99. return false;
  100. }
  101. // 用户协议同意
  102. const confirmBtn = () => {
  103. indexData.isAgreed = true;
  104. getYzmBtn();
  105. }
  106. const telClose = () => {
  107. telDialogFlag.value = false;
  108. }
  109. const bindBtn = (res) => {
  110. telDialogFlag.value = false;
  111. if (res.cardId == 0) {
  112. uni.redirectTo({
  113. url: `/pages/selectGradesTerms/index`
  114. })
  115. } else {
  116. uni.redirectTo({
  117. url: `/pages/study/index`
  118. })
  119. }
  120. }
  121. const ykConfirmBtn = () => {
  122. uni.navigateTo({
  123. url: `/pages/selectGradesTerms/index`
  124. })
  125. }
  126. // 手机号校验规则
  127. const validatePhoneNumber = (value) => {
  128. const phoneRegex = /^1[3-9]\d{9}$/;
  129. if (phoneRegex.test(value)) {
  130. indexData.telStatus = 'tel-btn-normal';
  131. } else {
  132. indexData.telStatus = 'tel-btn-disabled';
  133. }
  134. }
  135. const clearTelInput = (event) => {
  136. if (event.detail.value.length > 0) {
  137. indexData.clearTelIcon = true;
  138. validatePhoneNumber(event.detail.value);
  139. } else {
  140. indexData.clearTelIcon = false;
  141. }
  142. }
  143. const clearTel = () => {
  144. indexData.phoneNumber = '';
  145. indexData.telStatus = 'tel-btn-disabled';
  146. indexData.clearTelIcon = false;
  147. }
  148. const agreeBtn = (data) => {
  149. if (data === 'yhxy') {
  150. agreeType.value = 'yhxy'
  151. } else {
  152. agreeType.value = 'ystk'
  153. }
  154. agreeContentDialogRef.value.handleShow();
  155. };
  156. const handleAgreementChange = (event) => {
  157. if (event.detail.value[0] === 'agree') {
  158. indexData.isAgreed = true;
  159. } else {
  160. indexData.isAgreed = false;
  161. }
  162. }
  163. // 游客登录
  164. const ykBtn = () => {
  165. if (indexData.isAgreed === true) {
  166. uni.redirectTo({
  167. url: `/pages/selectGradesTerms/index`
  168. })
  169. } else {
  170. agreeYkDialog.value.handleShow();
  171. }
  172. }
  173. const appleLoginClick = () => {
  174. uni.login({
  175. provider: 'apple',
  176. success: function(loginRes) {
  177. console.log('loginRes', loginRes);
  178. let req = {
  179. "apple": true,
  180. "code": loginRes
  181. }
  182. console.log(req);
  183. wxLogin(req).then(res => {
  184. console.log(res);
  185. uni.showLoading({
  186. title: '登录中'
  187. });
  188. setTimeout(() => {
  189. cacheManager.set('auth', res.data.loginVo)
  190. if (res.data.loginVo.cardId == 0) {
  191. uni.redirectTo({
  192. url: `/pages/selectGradesTerms/index`
  193. })
  194. uni.hideLoading();
  195. } else {
  196. uni.redirectTo({
  197. url: `/pages/study/index`
  198. })
  199. uni.hideLoading();
  200. }
  201. }, 1000)
  202. }).catch((error) => {
  203. console.log(error);
  204. })
  205. },
  206. fail: function(err) {
  207. console.log('err.code', err.code);
  208. // 登录授权失败
  209. // err.code错误码参考`授权失败错误码(code)说明`
  210. }
  211. });
  212. }
  213. const wxLoginClick = () => {
  214. //获取服务商信息判断手机端是否安装了app
  215. // uni.getProvider({
  216. // service: 'oauth',// oauth 代表授权登录
  217. // success: function (res) {
  218. // // 登录
  219. // uni.login({
  220. // // 表示授权方式 如果不设置则弹出登录列表选择界面
  221. // provider: 'weixin',
  222. // "onlyAuthorize": true, // 微信登录仅请求授权认证
  223. // success: function (loginRes) {
  224. // console.log('loginRes',loginRes);
  225. // }
  226. // });
  227. // }
  228. // });
  229. uni.login({
  230. "provider": "weixin",
  231. "onlyAuthorize": true, // 微信登录仅请求授权认证
  232. success: function(event) {
  233. console.log(event);
  234. const {
  235. code
  236. } = event
  237. //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
  238. let req = {
  239. "apple": false,
  240. "code": code
  241. }
  242. console.log(req);
  243. wxLogin(req).then(res => {
  244. console.log(res);
  245. if (!res.data.bind) {
  246. console.log('未绑定');
  247. cacheManager.set('wxLogin', {
  248. bind: res.data.bing
  249. })
  250. telDialogFlag.value = true;
  251. nextTick(() => {
  252. telDialogRef.value.getOpenId(res.data.openId);
  253. })
  254. } else {
  255. uni.showLoading({
  256. title: '登录中'
  257. });
  258. setTimeout(() => {
  259. cacheManager.set('auth', res.data.loginVo)
  260. if (res.data.loginVo.cardId == 0) {
  261. uni.redirectTo({
  262. url: `/pages/selectGradesTerms/index`
  263. })
  264. uni.hideLoading();
  265. } else {
  266. uni.redirectTo({
  267. url: `/pages/study/index`
  268. })
  269. uni.hideLoading();
  270. }
  271. }, 1000)
  272. }
  273. }).catch((error) => {
  274. console.log(error);
  275. })
  276. },
  277. fail: function(err) {
  278. console.log(err);
  279. // 登录授权失败
  280. // err.code是错误码
  281. }
  282. })
  283. }
  284. </script>