index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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. <tipMiddleDialog ref="tipDialogRef" :closeFlag='false' :title="tipTitle" @confirm-btn="BanbenConfirmBtn" :notClose="true"
  39. :content="tipContent"></tipMiddleDialog>
  40. <tipMiddleDialog ref="tipDialogRef2" :closeFlag='false' :title="tipTitle" @confirm-btn="BanbenConfirmBtn" :notClose="true"
  41. :content="tipContentAndroid">
  42. </tipMiddleDialog>
  43. </view>
  44. </template>
  45. <script setup>
  46. import {
  47. ref,
  48. nextTick,
  49. reactive,
  50. computed
  51. } from "vue"
  52. import {
  53. onLoad,
  54. onReady
  55. } from '@dcloudio/uni-app';
  56. import agreeContentDialog from './agreeContentDialog.vue';
  57. import agreeDialog from './agreeDialog.vue'
  58. import {
  59. wxLogin,
  60. getVersion
  61. } from "@/api/login.js"
  62. import {
  63. toast,
  64. getUserIdentity
  65. } from "@/utils/common";
  66. import telDialog from './telDialog.vue'
  67. import cacheManager from "@/utils/cacheManager.js";
  68. import {
  69. onShow,
  70. onUnload,
  71. } from '@dcloudio/uni-app';
  72. import {
  73. useIsCanBack
  74. } from "@/store/isCanBack.js"
  75. // import tipDialog from '@/components/dialog/tipDialog.vue';
  76. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  77. import config from '../../config.js'
  78. import {
  79. error
  80. } from "uview-plus";
  81. import TipDialog from "@/components/dialog/tipDialog";
  82. import {useVersionUpdate} from "@/utils/versionUpdate.js"
  83. const {showUpdateDialog} = useVersionUpdate();
  84. let indexData = reactive({
  85. phoneNumber: null,
  86. clearTelIcon: false,
  87. telStatus: 'tel-btn-disabled',
  88. isAgreed: false,
  89. sliderObj: {},
  90. })
  91. const agreeContentDialogRef = ref(null);
  92. const agreeType = ref(null);
  93. const agreeDialogRef = ref(null);
  94. const agreeYkDialog = ref(null);
  95. const agreeWxDialog = ref(null);
  96. const telDialogRef = ref(null);
  97. let telDialogFlag = ref(false);
  98. let showAppleLogin = ref(false);
  99. let wxFlag = ref(true);
  100. const version = config.appInfo.version;
  101. const tipDialogRef = ref(null);
  102. const tipTitle = '升级提醒';
  103. const tipContentAndroid = '您的APP不是最新版本,部分功能不能使用,请升级至最新版本!'
  104. const tipContent = '您的APP不是最新版本,部分功能不能使用,请升级至最新版本!'
  105. const tipDialogRef2 = ref(null)
  106. const updateUrl = ref(null)
  107. const store = useIsCanBack();
  108. onUnload(() => {
  109. console.log('unload')
  110. store.setIsCanBack(false)
  111. })
  112. onShow(() => {
  113. setTimeout(() => {
  114. console.log('onShow')
  115. store.setIsCanBack(true)
  116. }, 500)
  117. })
  118. onLoad((options) => {
  119. showAppleLogin.value = isIOS13OrAbove();
  120. getLoginInit()
  121. if (plus.runtime.isApplicationExist({
  122. pname: 'com.tencent.mm',
  123. action: 'weixin://'
  124. })) {
  125. console.log('111', "已安装微信");
  126. wxFlag.value = true
  127. } else {
  128. wxFlag.value = false
  129. }
  130. console.log('showAppleLogin.value', showAppleLogin.value);
  131. })
  132. function BanbenConfirmBtn() {
  133. const systemInfo = uni.getSystemInfoSync();
  134. if (systemInfo.platform == 'ios') {
  135. const appStoreUrl = 'itms-apps://itunes.apple.com/app/6741551741'
  136. plus.runtime.openURL(appStoreUrl)
  137. } else {
  138. // plus.runtime.openURL(updateUrl.value)
  139. const { brand } = systemInfo;
  140. // 处理 Android/HarmonyOS 设备
  141. let storeUrl = '';
  142. let androidPackage = 'com.llisoft.ezy'; // 安卓包名
  143. switch (brand.toLowerCase()) {
  144. case 'huawei':
  145. storeUrl = `https://appstore.huawei.com/app/113217527`; // 华为/鸿蒙
  146. break;
  147. case 'xiaomi':
  148. storeUrl = `https://app.mi.com/details?id=${androidPackage}`; // 小米
  149. break;
  150. case 'oppo':
  151. storeUrl = `https://store.oppomobile.com/product?packagename=${androidPackage}`; // OPPO
  152. break;
  153. case 'vivo':
  154. storeUrl = `https://appstore.vivo.com.cn/app/${androidPackage}`; // vivo
  155. break;
  156. case 'honor':
  157. storeUrl = `market://details?id=${androidPackage}`; // 荣耀
  158. break;
  159. default:
  160. storeUrl = `market://details?id=${androidPackage}`; // 其他安卓品牌
  161. }
  162. plus.runtime.openURL(storeUrl);
  163. }
  164. }
  165. function getLoginInit() {
  166. getVersion({}).then(res => {
  167. if (version != res.data.version) {
  168. updateUrl.value = res.data.updateUrl
  169. const systemInfo = uni.getSystemInfoSync();
  170. if (systemInfo.platform == 'ios') {
  171. tipDialogRef.value.handleShow();
  172. } else {
  173. tipDialogRef2.value.handleShow();
  174. // showUpdateDialog({
  175. // description: '您的APP不是最新版本,部分功能不能使用,请升级至最新版本!',
  176. // url: res.data.updateUrl
  177. // })
  178. }
  179. }
  180. })
  181. }
  182. const getYzmBtn = () => {
  183. if (indexData.telStatus === 'tel-btn-normal') {
  184. if (indexData.isAgreed === true) {
  185. uni.redirectTo({
  186. url: `/pages/login/login?telNum=${indexData.phoneNumber}`
  187. })
  188. } else {
  189. agreeDialogRef.value.handleShow();
  190. }
  191. }
  192. }
  193. const isIOS13OrAbove = () => {
  194. const systemInfo = uni.getSystemInfoSync();
  195. if (systemInfo.platform == 'ios') {
  196. const version = systemInfo.system.split(' ')[1].split('.');
  197. const majorVersion = parseInt(version[0], 10);
  198. return majorVersion >= 13;
  199. }
  200. return false;
  201. }
  202. // 用户协议同意
  203. const confirmBtn = () => {
  204. indexData.isAgreed = true;
  205. getYzmBtn();
  206. }
  207. const telClose = () => {
  208. telDialogFlag.value = false;
  209. }
  210. const bindBtn = (res) => {
  211. telDialogFlag.value = false;
  212. if (res.cardId == 0) {
  213. uni.redirectTo({
  214. url: `/pages/selectGradesTerms/index`
  215. })
  216. } else {
  217. uni.redirectTo({
  218. url: `/pages/study/index`
  219. })
  220. }
  221. }
  222. const ykConfirmBtn = () => {
  223. uni.redirectTo({
  224. url: `/pages/selectGradesTerms/index`
  225. })
  226. }
  227. const wxConfirmBtn = () => {
  228. wxLoginFun();
  229. }
  230. // 手机号校验规则
  231. const validatePhoneNumber = (value) => {
  232. const phoneRegex = /^1[3-9]\d{9}$/;
  233. if (phoneRegex.test(value)) {
  234. indexData.telStatus = 'tel-btn-normal';
  235. } else {
  236. indexData.telStatus = 'tel-btn-disabled';
  237. }
  238. }
  239. const clearTelInput = (event) => {
  240. if (event.detail.value.length > 0) {
  241. indexData.clearTelIcon = true;
  242. validatePhoneNumber(event.detail.value);
  243. } else {
  244. indexData.clearTelIcon = false;
  245. }
  246. }
  247. const clearTel = () => {
  248. indexData.phoneNumber = '';
  249. indexData.telStatus = 'tel-btn-disabled';
  250. indexData.clearTelIcon = false;
  251. }
  252. const agreeBtn = (data) => {
  253. if (data === 'yhxy') {
  254. agreeType.value = 'yhxy'
  255. } else {
  256. agreeType.value = 'ystk'
  257. }
  258. agreeContentDialogRef.value.handleShow();
  259. };
  260. const handleAgreementChange = (event) => {
  261. if (event.detail.value[0] === 'agree') {
  262. indexData.isAgreed = true;
  263. } else {
  264. indexData.isAgreed = false;
  265. }
  266. }
  267. // 游客登录
  268. const ykBtn = () => {
  269. if (indexData.isAgreed === true) {
  270. uni.redirectTo({
  271. url: `/pages/selectGradesTerms/index`
  272. })
  273. } else {
  274. agreeYkDialog.value.handleShow();
  275. }
  276. }
  277. const appleLoginClick = () => {
  278. uni.login({
  279. provider: 'apple',
  280. success: function(loginRes) {
  281. console.log('loginRes', loginRes);
  282. let req = {
  283. "apple": true,
  284. "code": loginRes.appleInfo.user
  285. }
  286. console.log(req);
  287. console.log(req);
  288. wxLogin(req).then(res => {
  289. console.log(res);
  290. if (!res.data.bind) {
  291. console.log('未绑定');
  292. cacheManager.set('wxLogin', {
  293. bind: res.data.bing
  294. })
  295. telDialogFlag.value = true;
  296. nextTick(() => {
  297. telDialogRef.value.getOpenId(res.data.openId);
  298. })
  299. } else {
  300. uni.showLoading({
  301. title: '登录中'
  302. });
  303. setTimeout(() => {
  304. cacheManager.set('auth', res.data.loginVo)
  305. if (res.data.loginVo.subjectId == 0 && res.data.loginVo
  306. .levelId == 0) {
  307. uni.redirectTo({
  308. url: `/pages/selectGradesTerms/index`
  309. })
  310. uni.hideLoading();
  311. } else {
  312. uni.redirectTo({
  313. url: `/pages/study/index`
  314. })
  315. uni.hideLoading();
  316. }
  317. }, 1000)
  318. }
  319. }).catch((error) => {
  320. console.log(error);
  321. })
  322. },
  323. fail: function(err) {
  324. console.log('err.code', err.code);
  325. // 登录授权失败
  326. // err.code错误码参考`授权失败错误码(code)说明`
  327. }
  328. });
  329. }
  330. // 游客登录
  331. const wxLoginClick = () => {
  332. if (indexData.isAgreed === true) {
  333. wxLoginFun();
  334. } else {
  335. agreeWxDialog.value.handleShow();
  336. }
  337. }
  338. const wxLoginFun = () => {
  339. //获取服务商信息判断手机端是否安装了app
  340. // uni.getProvider({
  341. // service: 'oauth',// oauth 代表授权登录
  342. // success: function (res) {
  343. // // 登录
  344. // uni.login({
  345. // // 表示授权方式 如果不设置则弹出登录列表选择界面
  346. // provider: 'weixin',
  347. // "onlyAuthorize": true, // 微信登录仅请求授权认证
  348. // success: function (loginRes) {
  349. // console.log('loginRes',loginRes);
  350. // }
  351. // });
  352. // }
  353. // });
  354. if (plus.runtime.isApplicationExist({
  355. pname: 'com.tencent.mm',
  356. action: 'weixin://'
  357. })) {
  358. console.log('111', "已安装微信");
  359. uni.login({
  360. "provider": "weixin",
  361. "onlyAuthorize": true, // 微信登录仅请求授权认证
  362. success: function(event) {
  363. console.log(event);
  364. const {
  365. code
  366. } = event
  367. //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
  368. let req = {
  369. "apple": false,
  370. "code": code
  371. }
  372. console.log(req);
  373. wxLogin(req).then(res => {
  374. console.log(res);
  375. if (!res.data.bind) {
  376. console.log('未绑定');
  377. cacheManager.set('wxLogin', {
  378. bind: res.data.bing
  379. })
  380. telDialogFlag.value = true;
  381. nextTick(() => {
  382. telDialogRef.value.getOpenId(res.data.openId);
  383. })
  384. } else {
  385. uni.showLoading({
  386. title: '登录中'
  387. });
  388. setTimeout(() => {
  389. cacheManager.set('auth', res.data.loginVo)
  390. if (res.data.loginVo.subjectId == 0 && res.data.loginVo
  391. .levelId == 0) {
  392. uni.redirectTo({
  393. url: `/pages/selectGradesTerms/index`
  394. })
  395. uni.hideLoading();
  396. } else {
  397. uni.redirectTo({
  398. url: `/pages/study/index`
  399. })
  400. uni.hideLoading();
  401. }
  402. }, 1000)
  403. }
  404. }).catch((error) => {
  405. console.log(error);
  406. })
  407. },
  408. fail: function(err) {
  409. console.log(err);
  410. // 登录授权失败
  411. // err.code是错误码
  412. }
  413. })
  414. } else {
  415. toast("请重启应用重试")
  416. return false
  417. }
  418. }
  419. </script>