index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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.appleInfo.user
  181. }
  182. console.log(req);
  183. console.log(req);
  184. wxLogin(req).then(res => {
  185. console.log(res);
  186. if (!res.data.bind) {
  187. console.log('未绑定');
  188. cacheManager.set('wxLogin', {
  189. bind: res.data.bing
  190. })
  191. telDialogFlag.value = true;
  192. nextTick(() => {
  193. telDialogRef.value.getOpenId(res.data.openId);
  194. })
  195. } else {
  196. uni.showLoading({
  197. title: '登录中'
  198. });
  199. setTimeout(() => {
  200. cacheManager.set('auth', res.data.loginVo)
  201. if (res.data.loginVo.cardId == 0) {
  202. uni.redirectTo({
  203. url: `/pages/selectGradesTerms/index`
  204. })
  205. uni.hideLoading();
  206. } else {
  207. uni.redirectTo({
  208. url: `/pages/study/index`
  209. })
  210. uni.hideLoading();
  211. }
  212. }, 1000)
  213. }
  214. }).catch((error) => {
  215. console.log(error);
  216. })
  217. },
  218. fail: function(err) {
  219. console.log('err.code', err.code);
  220. // 登录授权失败
  221. // err.code错误码参考`授权失败错误码(code)说明`
  222. }
  223. });
  224. }
  225. const wxLoginClick = () => {
  226. //获取服务商信息判断手机端是否安装了app
  227. // uni.getProvider({
  228. // service: 'oauth',// oauth 代表授权登录
  229. // success: function (res) {
  230. // // 登录
  231. // uni.login({
  232. // // 表示授权方式 如果不设置则弹出登录列表选择界面
  233. // provider: 'weixin',
  234. // "onlyAuthorize": true, // 微信登录仅请求授权认证
  235. // success: function (loginRes) {
  236. // console.log('loginRes',loginRes);
  237. // }
  238. // });
  239. // }
  240. // });
  241. if(plus.runtime.isApplicationExist({ pname: 'com.tencent.mm', action: 'weixin://' })) {
  242. console.log('111',"已安装微信");
  243. uni.login({
  244. "provider": "weixin",
  245. "onlyAuthorize": true, // 微信登录仅请求授权认证
  246. success: function(event) {
  247. console.log(event);
  248. const {
  249. code
  250. } = event
  251. //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
  252. let req = {
  253. "apple": false,
  254. "code": code
  255. }
  256. console.log(req);
  257. wxLogin(req).then(res => {
  258. console.log(res);
  259. if (!res.data.bind) {
  260. console.log('未绑定');
  261. cacheManager.set('wxLogin', {
  262. bind: res.data.bing
  263. })
  264. telDialogFlag.value = true;
  265. nextTick(() => {
  266. telDialogRef.value.getOpenId(res.data.openId);
  267. })
  268. } else {
  269. uni.showLoading({
  270. title: '登录中'
  271. });
  272. setTimeout(() => {
  273. cacheManager.set('auth', res.data.loginVo)
  274. if (res.data.loginVo.cardId == 0) {
  275. uni.redirectTo({
  276. url: `/pages/selectGradesTerms/index`
  277. })
  278. uni.hideLoading();
  279. } else {
  280. uni.redirectTo({
  281. url: `/pages/study/index`
  282. })
  283. uni.hideLoading();
  284. }
  285. }, 1000)
  286. }
  287. }).catch((error) => {
  288. console.log(error);
  289. })
  290. },
  291. fail: function(err) {
  292. console.log(err);
  293. // 登录授权失败
  294. // err.code是错误码
  295. }
  296. })
  297. } else {
  298. toast("未安装微信,请安装微信进行登录!")
  299. return false
  300. }
  301. }
  302. </script>