index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <view class="ezy-login-page">
  3. <icon class="login-img"></icon>
  4. <!-- 手机号 -->
  5. <view class="login-body-box">
  6. <view class="phone-input-box">
  7. <view class="phone-prefix">+86</view>
  8. <input class="phone-input" type="text" v-model="indexData.phoneNumber" placeholder="请输入手机号"
  9. maxlength="11" @input="clearTelInput" />
  10. <view class="close-btn" v-if="indexData.clearTelIcon" @click="clearTel"></view>
  11. </view>
  12. <!-- 协议勾选框和按钮 -->
  13. <view class="agreement-checkbox-box">
  14. <checkbox-group @change="handleAgreementChange">
  15. <checkbox class="agreement-checkbox-input" color="#FFFFFF" value="agree"
  16. :checked="indexData.isAgreed" />
  17. </checkbox-group>
  18. <view class="agreement-text-box">
  19. 我已阅读并同意<view class="agreement-text" @click="agreeBtn('yhxy')">《用户协议》</view>和<view
  20. @click="agreeBtn('ystk')" class="agreement-text">《隐私政策》</view>
  21. </view>
  22. </view>
  23. <ezyActiveVue class="ezy-btn-active login-btn" @aclick="getYzmBtn" :class="indexData.telStatus">发送验证码</ezyActiveVue>
  24. <view class="bottom-btn-box">
  25. <view class="bottom-tip">选择第三方登录</view>
  26. <view class="btn-box">
  27. <view v-if="wxFlag" class="wx-btn" @click="wxLoginClick">
  28. <icon></icon>
  29. <view>微信登录</view>
  30. </view>
  31. <!-- <view class="yk-btn" @click="ykBtn">
  32. <icon></icon>
  33. <view>游客登录</view>
  34. </view> -->
  35. <view class="apple-btn" v-if="showAppleLogin" @click="appleLoginClick">
  36. <icon></icon>
  37. <view>苹果登录</view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <agree-content-dialog ref="agreeContentDialogRef" :agreeType="agreeType"></agree-content-dialog>
  43. <agree-dialog ref="agreeDialogRef" @confirm-btn="confirmBtn"></agree-dialog>
  44. <agree-dialog ref="agreeYkDialog" @confirm-btn="ykConfirmBtn"></agree-dialog>
  45. <agree-dialog ref="agreeWxDialog" @confirm-btn="wxConfirmBtn"></agree-dialog>
  46. <tel-dialog ref="telDialogRef" @telClose="telClose" @bindBtn="bindBtn" v-if="telDialogFlag"></tel-dialog>
  47. <tip-dialog ref="tipDialogRef" :title="tipTitle" :content="tipContent"></tip-dialog>
  48. </view>
  49. </template>
  50. <script setup>
  51. import {
  52. ref,
  53. nextTick,
  54. reactive
  55. } from "vue"
  56. import {
  57. onLoad,
  58. onReady,
  59. onBackPress
  60. } from '@dcloudio/uni-app';
  61. import agreeContentDialog from './agreeContentDialog.vue';
  62. import agreeDialog from './agreeDialog.vue'
  63. import {
  64. wxLogin,
  65. getVersion
  66. } from "@/api/login.js"
  67. import {
  68. toast,
  69. getUserIdentity
  70. } from "@/utils/common";
  71. import telDialog from './telDialog.vue'
  72. import cacheManager from "@/utils/cacheManager.js";
  73. import tipDialog from '@/components/dialog/tipDialog.vue';
  74. import config from '../../config.js'
  75. import {
  76. error
  77. } from "uview-plus";
  78. import ezyActiveVue from "@/components/ezyActive/ezyActive.vue";
  79. let indexData = reactive({
  80. phoneNumber: null,
  81. clearTelIcon: false,
  82. telStatus: 'login-btn-disabled',
  83. isAgreed: false,
  84. sliderObj: {},
  85. })
  86. const agreeContentDialogRef = ref(null);
  87. const agreeType = ref(null);
  88. const agreeDialogRef = ref(null);
  89. const agreeYkDialog = ref(null);
  90. const agreeWxDialog = ref(null);
  91. const telDialogRef = ref(null);
  92. let telDialogFlag = ref(false);
  93. let showAppleLogin = ref(false);
  94. let wxFlag = ref(true);
  95. const version = config.appInfo.version;
  96. const tipDialogRef = ref(null);
  97. const tipTitle = '升级提醒';
  98. const tipContent = '您的APP不是最新版本,部分功能不能使用,请升级至最新版本!';
  99. onLoad((options) => {
  100. showAppleLogin.value = isIOS13OrAbove();
  101. getLoginInit()
  102. if (plus.runtime.isApplicationExist({
  103. pname: 'com.tencent.mm',
  104. action: 'weixin://'
  105. })) {
  106. console.log('111', "已安装微信");
  107. wxFlag.value = true
  108. } else {
  109. wxFlag.value = false
  110. }
  111. console.log('showAppleLogin.value', showAppleLogin.value);
  112. })
  113. function getLoginInit() {
  114. getVersion({}).then(res => {
  115. if (version != res.data.version) {
  116. tipDialogRef.value.handleShow();
  117. }
  118. })
  119. }
  120. const getYzmBtn = () => {
  121. if (indexData.telStatus === 'login-btn-normal') {
  122. if (indexData.isAgreed === true) {
  123. uni.redirectTo({
  124. url: `/pages/login/login?telNum=${indexData.phoneNumber}`
  125. })
  126. } else {
  127. agreeDialogRef.value.handleShow();
  128. }
  129. }
  130. }
  131. const isIOS13OrAbove = () => {
  132. const systemInfo = uni.getSystemInfoSync();
  133. if (systemInfo.platform == 'ios') {
  134. const version = systemInfo.system.split(' ')[1].split('.');
  135. const majorVersion = parseInt(version[0], 10);
  136. return majorVersion >= 13;
  137. }
  138. return false;
  139. }
  140. // 用户协议同意
  141. const confirmBtn = () => {
  142. indexData.isAgreed = true;
  143. getYzmBtn();
  144. }
  145. const telClose = () => {
  146. telDialogFlag.value = false;
  147. }
  148. const bindBtn = (res) => {
  149. telDialogFlag.value = false;
  150. if (res.cardId == 0) {
  151. uni.redirectTo({
  152. url: `/pages/selectGradesTerms/index`
  153. })
  154. } else {
  155. uni.redirectTo({
  156. url: `/pages/study/index`
  157. })
  158. }
  159. }
  160. const ykConfirmBtn = () => {
  161. uni.redirectTo({
  162. url: `/pages/selectGradesTerms/index`
  163. })
  164. }
  165. const wxConfirmBtn = () => {
  166. wxLoginFun();
  167. }
  168. // 手机号校验规则
  169. const validatePhoneNumber = (value) => {
  170. const phoneRegex = /^1[3-9]\d{9}$/;
  171. if (phoneRegex.test(value)) {
  172. indexData.telStatus = 'login-btn-normal';
  173. } else {
  174. indexData.telStatus = 'login-btn-disabled';
  175. }
  176. }
  177. const clearTelInput = (event) => {
  178. if (event.detail.value.length > 0) {
  179. indexData.clearTelIcon = true;
  180. validatePhoneNumber(event.detail.value);
  181. } else {
  182. indexData.clearTelIcon = false;
  183. }
  184. }
  185. const clearTel = () => {
  186. indexData.phoneNumber = '';
  187. indexData.telStatus = 'login-btn-disabled';
  188. indexData.clearTelIcon = false;
  189. }
  190. const agreeBtn = (data) => {
  191. if (data === 'yhxy') {
  192. agreeType.value = 'yhxy'
  193. } else {
  194. agreeType.value = 'ystk'
  195. }
  196. agreeContentDialogRef.value.handleShow();
  197. };
  198. const handleAgreementChange = (event) => {
  199. if (event.detail.value[0] === 'agree') {
  200. indexData.isAgreed = true;
  201. } else {
  202. indexData.isAgreed = false;
  203. }
  204. }
  205. // 游客登录
  206. const ykBtn = () => {
  207. if (indexData.isAgreed === true) {
  208. uni.redirectTo({
  209. url: `/pages/selectGradesTerms/index`
  210. })
  211. } else {
  212. agreeYkDialog.value.handleShow();
  213. }
  214. }
  215. const appleLoginClick = () => {
  216. uni.login({
  217. provider: 'apple',
  218. success: function(loginRes) {
  219. console.log('loginRes', loginRes);
  220. let req = {
  221. "apple": true,
  222. "code": loginRes.appleInfo.user
  223. }
  224. console.log(req);
  225. console.log(req);
  226. wxLogin(req).then(res => {
  227. console.log(res);
  228. if (!res.data.bind) {
  229. console.log('未绑定');
  230. cacheManager.set('wxLogin', {
  231. bind: res.data.bing
  232. })
  233. telDialogFlag.value = true;
  234. nextTick(() => {
  235. telDialogRef.value.getOpenId(res.data.openId);
  236. })
  237. } else {
  238. uni.showLoading({
  239. title: '登录中'
  240. });
  241. setTimeout(() => {
  242. cacheManager.set('auth', res.data.loginVo)
  243. if (res.data.loginVo.subjectId == 0 && res.data.loginVo
  244. .levelId == 0) {
  245. uni.redirectTo({
  246. url: `/pages/selectGradesTerms/index`
  247. })
  248. uni.hideLoading();
  249. } else {
  250. uni.redirectTo({
  251. url: `/pages/study/index`
  252. })
  253. uni.hideLoading();
  254. }
  255. }, 1000)
  256. }
  257. }).catch((error) => {
  258. console.log(error);
  259. })
  260. },
  261. fail: function(err) {
  262. console.log('err.code', err.code);
  263. // 登录授权失败
  264. // err.code错误码参考`授权失败错误码(code)说明`
  265. }
  266. });
  267. }
  268. // 游客登录
  269. const wxLoginClick = () => {
  270. if (indexData.isAgreed === true) {
  271. wxLoginFun();
  272. } else {
  273. agreeWxDialog.value.handleShow();
  274. }
  275. }
  276. const wxLoginFun = () => {
  277. //获取服务商信息判断手机端是否安装了app
  278. // uni.getProvider({
  279. // service: 'oauth',// oauth 代表授权登录
  280. // success: function (res) {
  281. // // 登录
  282. // uni.login({
  283. // // 表示授权方式 如果不设置则弹出登录列表选择界面
  284. // provider: 'weixin',
  285. // "onlyAuthorize": true, // 微信登录仅请求授权认证
  286. // success: function (loginRes) {
  287. // console.log('loginRes',loginRes);
  288. // }
  289. // });
  290. // }
  291. // });
  292. if (plus.runtime.isApplicationExist({
  293. pname: 'com.tencent.mm',
  294. action: 'weixin://'
  295. })) {
  296. console.log('111', "已安装微信");
  297. uni.login({
  298. "provider": "weixin",
  299. "onlyAuthorize": true, // 微信登录仅请求授权认证
  300. success: function(event) {
  301. console.log(event);
  302. const {
  303. code
  304. } = event
  305. //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
  306. let req = {
  307. "apple": false,
  308. "code": code
  309. }
  310. console.log(req);
  311. wxLogin(req).then(res => {
  312. console.log(res);
  313. if (!res.data.bind) {
  314. console.log('未绑定');
  315. cacheManager.set('wxLogin', {
  316. bind: res.data.bing
  317. })
  318. telDialogFlag.value = true;
  319. nextTick(() => {
  320. telDialogRef.value.getOpenId(res.data.openId);
  321. })
  322. } else {
  323. uni.showLoading({
  324. title: '登录中'
  325. });
  326. setTimeout(() => {
  327. cacheManager.set('auth', res.data.loginVo)
  328. if (res.data.loginVo.subjectId == 0 && res.data.loginVo
  329. .levelId == 0) {
  330. uni.redirectTo({
  331. url: `/pages/selectGradesTerms/index`
  332. })
  333. uni.hideLoading();
  334. } else {
  335. uni.redirectTo({
  336. url: `/pages/study/index`
  337. })
  338. uni.hideLoading();
  339. }
  340. }, 1000)
  341. }
  342. }).catch((error) => {
  343. console.log(error);
  344. })
  345. },
  346. fail: function(err) {
  347. console.log(err);
  348. // 登录授权失败
  349. // err.code是错误码
  350. }
  351. })
  352. } else {
  353. toast("请重启应用重试")
  354. return false
  355. }
  356. }
  357. </script>