index.vue 9.3 KB

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