index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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. if (plus.runtime.isApplicationExist({
  125. pname: 'com.tencent.mm',
  126. action: 'weixin://'
  127. })) {
  128. console.log('111', "已安装微信");
  129. wxFlag.value = true
  130. } else {
  131. wxFlag.value = false
  132. }
  133. console.log('showAppleLogin.value', showAppleLogin.value);
  134. })
  135. function BanbenConfirmBtn() {
  136. const systemInfo = uni.getSystemInfoSync();
  137. if (systemInfo.platform == 'ios') {
  138. const appStoreUrl = 'itms-apps://itunes.apple.com/app/6741551741'
  139. plus.runtime.openURL(appStoreUrl)
  140. } else {
  141. initDownload(updateUrl.value)
  142. }
  143. }
  144. function getLoginInit() {
  145. const systemInfo = uni.getSystemInfoSync();
  146. getVersion({}).then(res => {
  147. if (version != res.data.version) {
  148. updateUrl.value = res.data.updateUrl
  149. if (systemInfo.platform == 'ios') {
  150. tipDialogRef.value.handleShow();
  151. } else {
  152. tipDialogRef2.value.handleShow();
  153. }
  154. }
  155. })
  156. }
  157. const getYzmBtn = () => {
  158. if (indexData.telStatus === 'login-btn-normal') {
  159. if (indexData.isAgreed === true) {
  160. uni.redirectTo({
  161. url: `/pages/login/login?telNum=${indexData.phoneNumber}`
  162. })
  163. } else {
  164. agreeDialogRef.value.handleShow();
  165. }
  166. }
  167. }
  168. const isIOS13OrAbove = () => {
  169. const systemInfo = uni.getSystemInfoSync();
  170. if (systemInfo.platform == 'ios') {
  171. const version = systemInfo.system.split(' ')[1].split('.');
  172. const majorVersion = parseInt(version[0], 10);
  173. return majorVersion >= 13;
  174. }
  175. return false;
  176. }
  177. // 用户协议同意
  178. const confirmBtn = () => {
  179. indexData.isAgreed = true;
  180. getYzmBtn();
  181. }
  182. const telClose = () => {
  183. telDialogFlag.value = false;
  184. }
  185. const bindBtn = (res) => {
  186. telDialogFlag.value = false;
  187. if (res.cardId == 0) {
  188. uni.redirectTo({
  189. url: `/pages/selectGradesTerms/index`
  190. })
  191. } else {
  192. uni.redirectTo({
  193. url: `/pages/study/index`
  194. })
  195. }
  196. }
  197. const ykConfirmBtn = () => {
  198. indexData.isAgreed = true;
  199. ykBtn()
  200. // uni.redirectTo({
  201. // url: `/pages/selectGradesTerms/index`
  202. // })
  203. }
  204. const wxConfirmBtn = () => {
  205. wxLoginFun();
  206. }
  207. // 手机号校验规则
  208. const validatePhoneNumber = (value) => {
  209. const phoneRegex = /^1[3-9]\d{9}$/;
  210. if (phoneRegex.test(value)) {
  211. indexData.telStatus = 'login-btn-normal';
  212. } else {
  213. indexData.telStatus = 'login-btn-disabled';
  214. }
  215. }
  216. const clearTelInput = (event) => {
  217. if (event.detail.value.length > 0) {
  218. indexData.clearTelIcon = true;
  219. validatePhoneNumber(event.detail.value);
  220. } else {
  221. indexData.clearTelIcon = false;
  222. }
  223. }
  224. const clearTel = () => {
  225. indexData.phoneNumber = '';
  226. indexData.telStatus = 'login-btn-disabled';
  227. indexData.clearTelIcon = false;
  228. }
  229. const agreeBtn = (data) => {
  230. if (data === 'yhxy') {
  231. agreeType.value = 'yhxy'
  232. } else {
  233. agreeType.value = 'ystk'
  234. }
  235. agreeContentDialogRef.value.handleShow();
  236. };
  237. const getUUid = (data) => {
  238. const systemInfo = uni.getSystemInfoSync();
  239. if (systemInfo.platform == 'ios') {
  240. plus.device.getInfo({
  241. success: (res) => {
  242. // res.uuid 是设备的 UUID(iOS 下为 identifierForVendor)
  243. console.log('res', res);
  244. uuid.value = res.uuid;
  245. console.log('iOS 设备 UUID:', uuid.value);
  246. },
  247. fail: (err) => {
  248. console.error('获取设备信息失败:', err);
  249. }
  250. });
  251. }
  252. };
  253. const handleAgreementChange = (event) => {
  254. if (event.detail.value[0] === 'agree') {
  255. indexData.isAgreed = true;
  256. } else {
  257. indexData.isAgreed = false;
  258. }
  259. }
  260. // 游客登录
  261. const ykBtn = () => {
  262. const systemInfo = uni.getSystemInfoSync();
  263. if (indexData.isAgreed === true) {
  264. if (!uuid.value && systemInfo.platform == 'ios') {
  265. toast("设备id丢失")
  266. getUUid()
  267. return false
  268. }
  269. let req = {
  270. uuid: uuid.value
  271. }
  272. youkeLogin(req).then(res => {
  273. if (res.code == 0) {
  274. cacheManager.set('auth', res.data)
  275. uni.switchTab({
  276. url: `/pages/chanpinXuanze/index`
  277. })
  278. }
  279. })
  280. // uni.redirectTo({
  281. // url: `/pages/selectGradesTerms/index`
  282. // })
  283. } else {
  284. agreeYkDialog.value.handleShow();
  285. }
  286. }
  287. const appleLoginClick = () => {
  288. uni.login({
  289. provider: 'apple',
  290. success: function(loginRes) {
  291. console.log('loginRes', loginRes);
  292. let req = {
  293. "apple": true,
  294. "code": loginRes.appleInfo.user
  295. }
  296. console.log(req);
  297. console.log(req);
  298. wxLogin(req).then(res => {
  299. console.log(res);
  300. if (!res.data.bind) {
  301. console.log('未绑定');
  302. cacheManager.set('wxLogin', {
  303. bind: res.data.bing
  304. })
  305. telDialogFlag.value = true;
  306. nextTick(() => {
  307. telDialogRef.value.getOpenId(res.data.openId);
  308. })
  309. } else {
  310. uni.showLoading({
  311. title: '登录中'
  312. });
  313. setTimeout(() => {
  314. cacheManager.set('auth', res.data.loginVo)
  315. if (res.data.loginVo.subjectId == 0 && res.data.loginVo
  316. .levelId == 0) {
  317. uni.redirectTo({
  318. url: `/pages/selectGradesTerms/index`
  319. })
  320. uni.hideLoading();
  321. } else {
  322. uni.redirectTo({
  323. url: `/pages/study/index`
  324. })
  325. uni.hideLoading();
  326. }
  327. }, 1000)
  328. }
  329. }).catch((error) => {
  330. console.log(error);
  331. })
  332. },
  333. fail: function(err) {
  334. console.log('err.code', err.code);
  335. // 登录授权失败
  336. // err.code错误码参考`授权失败错误码(code)说明`
  337. }
  338. });
  339. }
  340. // 游客登录
  341. const wxLoginClick = () => {
  342. if (indexData.isAgreed === true) {
  343. wxLoginFun();
  344. } else {
  345. agreeWxDialog.value.handleShow();
  346. }
  347. }
  348. const wxLoginFun = () => {
  349. //获取服务商信息判断手机端是否安装了app
  350. // uni.getProvider({
  351. // service: 'oauth',// oauth 代表授权登录
  352. // success: function (res) {
  353. // // 登录
  354. // uni.login({
  355. // // 表示授权方式 如果不设置则弹出登录列表选择界面
  356. // provider: 'weixin',
  357. // "onlyAuthorize": true, // 微信登录仅请求授权认证
  358. // success: function (loginRes) {
  359. // console.log('loginRes',loginRes);
  360. // }
  361. // });
  362. // }
  363. // });
  364. if (plus.runtime.isApplicationExist({
  365. pname: 'com.tencent.mm',
  366. action: 'weixin://'
  367. })) {
  368. console.log('111', "已安装微信");
  369. uni.login({
  370. "provider": "weixin",
  371. "onlyAuthorize": true, // 微信登录仅请求授权认证
  372. success: function(event) {
  373. console.log(event);
  374. const {
  375. code
  376. } = event
  377. //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
  378. let req = {
  379. "apple": false,
  380. "code": code
  381. }
  382. console.log(req);
  383. wxLogin(req).then(res => {
  384. console.log(res);
  385. if (!res.data.bind) {
  386. console.log('未绑定');
  387. cacheManager.set('wxLogin', {
  388. bind: res.data.bing
  389. })
  390. telDialogFlag.value = true;
  391. nextTick(() => {
  392. telDialogRef.value.getOpenId(res.data.openId);
  393. })
  394. } else {
  395. uni.showLoading({
  396. title: '登录中'
  397. });
  398. setTimeout(() => {
  399. cacheManager.set('auth', res.data.loginVo)
  400. if (res.data.loginVo.subjectId == 0 && res.data.loginVo
  401. .levelId == 0) {
  402. uni.redirectTo({
  403. url: `/pages/selectGradesTerms/index`
  404. })
  405. uni.hideLoading();
  406. } else {
  407. uni.redirectTo({
  408. url: `/pages/study/index`
  409. })
  410. uni.hideLoading();
  411. }
  412. }, 1000)
  413. }
  414. }).catch((error) => {
  415. console.log(error);
  416. })
  417. },
  418. fail: function(err) {
  419. console.log(err);
  420. // 登录授权失败
  421. // err.code是错误码
  422. }
  423. })
  424. } else {
  425. toast("请重启应用重试")
  426. return false
  427. }
  428. }
  429. </script>