index.vue 13 KB

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