index.vue 8.8 KB

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