index.vue 8.5 KB

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