index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. <agree-first-dialog ref="agreeFirstDialogRef" @first-confirm-btn="firstConfirmBtn"></agree-first-dialog>
  38. </view>
  39. </template>
  40. <script setup>
  41. import {
  42. ref,
  43. nextTick,
  44. reactive
  45. } from "vue"
  46. import {
  47. onLoad,
  48. onReady
  49. } from '@dcloudio/uni-app';
  50. import agreeContentDialog from './agreeContentDialog.vue';
  51. import agreeDialog from './agreeDialog.vue'
  52. import agreeFirstDialog from './agreeFirstDialog.vue'
  53. import {
  54. wxLogin,
  55. } from "@/api/login.js"
  56. import {
  57. toast,
  58. getUserIdentity
  59. } from "@/utils/common";
  60. import telDialog from './telDialog.vue'
  61. import cacheManager from "@/utils/cacheManager.js";
  62. import {
  63. error
  64. } from "uview-plus";
  65. let indexData = reactive({
  66. phoneNumber: null,
  67. clearTelIcon: false,
  68. telStatus: 'tel-btn-disabled',
  69. isAgreed: false,
  70. sliderObj: {},
  71. })
  72. const agreeContentDialogRef = ref(null);
  73. const agreeType = ref(null);
  74. const agreeDialogRef = ref(null);
  75. const agreeYkDialog = ref(null);
  76. const telDialogRef = ref(null);
  77. let telDialogFlag = ref(false);
  78. let showAppleLogin = ref(false);
  79. const agreeFirstDialogRef = ref(null);
  80. onLoad((options) => {
  81. showAppleLogin.value = isIOS13OrAbove();
  82. // 没有缓存显示用户协议弹窗
  83. if (!cacheManager.get('firstAgreeDialog')) {
  84. nextTick(() => {
  85. agreeFirstDialogRef.value.handleShow();
  86. })
  87. }
  88. })
  89. const getYzmBtn = () => {
  90. if (indexData.telStatus === 'tel-btn-normal') {
  91. if (indexData.isAgreed === true) {
  92. uni.navigateTo({
  93. url: `/pages/login/login?telNum=${indexData.phoneNumber}`
  94. })
  95. } else {
  96. agreeDialogRef.value.handleShow();
  97. }
  98. }
  99. }
  100. const isIOS13OrAbove = () => {
  101. const systemInfo = uni.getSystemInfoSync();
  102. if (systemInfo.platform == 'ios') {
  103. const version = systemInfo.system.split(' ')[1].split('.');
  104. const majorVersion = parseInt(version[0], 10);
  105. return majorVersion >= 13;
  106. }
  107. return false;
  108. }
  109. // 用户协议同意
  110. const confirmBtn = () => {
  111. indexData.isAgreed = true;
  112. getYzmBtn();
  113. }
  114. const telClose = () => {
  115. telDialogFlag.value = false;
  116. }
  117. const bindBtn = (res) => {
  118. telDialogFlag.value = false;
  119. if (res.cardId == 0) {
  120. uni.redirectTo({
  121. url: `/pages/selectGradesTerms/index`
  122. })
  123. } else {
  124. uni.redirectTo({
  125. url: `/pages/study/index`
  126. })
  127. }
  128. }
  129. const ykConfirmBtn = () => {
  130. uni.navigateTo({
  131. url: `/pages/selectGradesTerms/index`
  132. })
  133. }
  134. // 手机号校验规则
  135. const validatePhoneNumber = (value) => {
  136. const phoneRegex = /^1[3-9]\d{9}$/;
  137. if (phoneRegex.test(value)) {
  138. indexData.telStatus = 'tel-btn-normal';
  139. } else {
  140. indexData.telStatus = 'tel-btn-disabled';
  141. }
  142. }
  143. const clearTelInput = (event) => {
  144. if (event.detail.value.length > 0) {
  145. indexData.clearTelIcon = true;
  146. validatePhoneNumber(event.detail.value);
  147. } else {
  148. indexData.clearTelIcon = false;
  149. }
  150. }
  151. const clearTel = () => {
  152. indexData.phoneNumber = '';
  153. indexData.telStatus = 'tel-btn-disabled';
  154. indexData.clearTelIcon = false;
  155. }
  156. const agreeBtn = (data) => {
  157. if (data === 'yhxy') {
  158. agreeType.value = 'yhxy'
  159. } else {
  160. agreeType.value = 'ystk'
  161. }
  162. agreeContentDialogRef.value.handleShow();
  163. };
  164. const firstConfirmBtn = () => {
  165. cacheManager.set('firstAgreeDialog', {
  166. firstAgreeDialog: 'has'
  167. })
  168. }
  169. const handleAgreementChange = (event) => {
  170. if (event.detail.value[0] === 'agree') {
  171. indexData.isAgreed = true;
  172. } else {
  173. indexData.isAgreed = false;
  174. }
  175. }
  176. // 游客登录
  177. const ykBtn = () => {
  178. if (indexData.isAgreed === true) {
  179. uni.redirectTo({
  180. url: `/pages/selectGradesTerms/index`
  181. })
  182. } else {
  183. agreeYkDialog.value.handleShow();
  184. }
  185. }
  186. const appleLoginClick = () => {
  187. uni.login({
  188. provider: 'apple',
  189. success: function(loginRes) {
  190. console.log('loginRes', loginRes);
  191. let req = {
  192. "apple": true,
  193. "code": loginRes.appleInfo.user
  194. }
  195. console.log(req);
  196. console.log(req);
  197. wxLogin(req).then(res => {
  198. console.log(res);
  199. if (!res.data.bind) {
  200. console.log('未绑定');
  201. cacheManager.set('wxLogin', {
  202. bind: res.data.bing
  203. })
  204. telDialogFlag.value = true;
  205. nextTick(() => {
  206. telDialogRef.value.getOpenId(res.data.openId);
  207. })
  208. } else {
  209. uni.showLoading({
  210. title: '登录中'
  211. });
  212. setTimeout(() => {
  213. cacheManager.set('auth', res.data.loginVo)
  214. if (res.data.loginVo.cardId == 0) {
  215. uni.redirectTo({
  216. url: `/pages/selectGradesTerms/index`
  217. })
  218. uni.hideLoading();
  219. } else {
  220. uni.redirectTo({
  221. url: `/pages/study/index`
  222. })
  223. uni.hideLoading();
  224. }
  225. }, 1000)
  226. }
  227. }).catch((error) => {
  228. console.log(error);
  229. })
  230. },
  231. fail: function(err) {
  232. console.log('err.code', err.code);
  233. // 登录授权失败
  234. // err.code错误码参考`授权失败错误码(code)说明`
  235. }
  236. });
  237. }
  238. const wxLoginClick = () => {
  239. //获取服务商信息判断手机端是否安装了app
  240. // uni.getProvider({
  241. // service: 'oauth',// oauth 代表授权登录
  242. // success: function (res) {
  243. // // 登录
  244. // uni.login({
  245. // // 表示授权方式 如果不设置则弹出登录列表选择界面
  246. // provider: 'weixin',
  247. // "onlyAuthorize": true, // 微信登录仅请求授权认证
  248. // success: function (loginRes) {
  249. // console.log('loginRes',loginRes);
  250. // }
  251. // });
  252. // }
  253. // });
  254. if(plus.runtime.isApplicationExist({ pname: 'com.tencent.mm', action: 'weixin://' })) {
  255. console.log('111',"已安装微信");
  256. uni.login({
  257. "provider": "weixin",
  258. "onlyAuthorize": true, // 微信登录仅请求授权认证
  259. success: function(event) {
  260. console.log(event);
  261. const {
  262. code
  263. } = event
  264. //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
  265. let req = {
  266. "apple": false,
  267. "code": code
  268. }
  269. console.log(req);
  270. wxLogin(req).then(res => {
  271. console.log(res);
  272. if (!res.data.bind) {
  273. console.log('未绑定');
  274. cacheManager.set('wxLogin', {
  275. bind: res.data.bing
  276. })
  277. telDialogFlag.value = true;
  278. nextTick(() => {
  279. telDialogRef.value.getOpenId(res.data.openId);
  280. })
  281. } else {
  282. uni.showLoading({
  283. title: '登录中'
  284. });
  285. setTimeout(() => {
  286. cacheManager.set('auth', res.data.loginVo)
  287. if (res.data.loginVo.cardId == 0) {
  288. uni.redirectTo({
  289. url: `/pages/selectGradesTerms/index`
  290. })
  291. uni.hideLoading();
  292. } else {
  293. uni.redirectTo({
  294. url: `/pages/study/index`
  295. })
  296. uni.hideLoading();
  297. }
  298. }, 1000)
  299. }
  300. }).catch((error) => {
  301. console.log(error);
  302. })
  303. },
  304. fail: function(err) {
  305. console.log(err);
  306. // 登录授权失败
  307. // err.code是错误码
  308. }
  309. })
  310. } else {
  311. toast("未安装微信,请安装微信进行登录!")
  312. return false
  313. }
  314. }
  315. </script>