index.vue 12 KB

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