index.vue 11 KB

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