index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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 tipDialog from '@/components/dialog/tipDialog.vue';
  80. import config from '../../config.js'
  81. import {
  82. error
  83. } from "uview-plus";
  84. import ezyActiveVue from "@/components/ezyActive/ezyActive.vue";
  85. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  86. import {
  87. useVersionUpdate
  88. } from "@/utils/versionUpdate.js";
  89. let indexData = reactive({
  90. phoneNumber: null,
  91. clearTelIcon: false,
  92. telStatus: 'login-btn-disabled',
  93. isAgreed: false,
  94. sliderObj: {},
  95. })
  96. const agreeContentDialogRef = ref(null);
  97. const agreeType = ref(null);
  98. const agreeDialogRef = ref(null);
  99. const agreeYkDialog = ref(null);
  100. const agreeWxDialog = ref(null);
  101. const telDialogRef = ref(null);
  102. let telDialogFlag = ref(false);
  103. let showAppleLogin = ref(false);
  104. let wxFlag = ref(true);
  105. const version = config.appInfo.version;
  106. const tipDialogRef = ref(null);
  107. const uuid = ref(null);
  108. const tipTitle = '升级提醒';
  109. const tipContentAndroid = '您的APP不是最新版本,部分功能不能使用,请升级至最新版本!'
  110. const tipContent = '您的APP不是最新版本,部分功能不能使用,请升级至最新版本!'
  111. const tipDialogRef2 = ref(null)
  112. const updateUrl = ref(null)
  113. const {
  114. initDownload
  115. } = useVersionUpdate()
  116. onLoad((options) => {
  117. /* 设备信息打印
  118. const info = uni.getSystemInfoSync()
  119. console.log('窗口宽度(逻辑像素):', info.windowWidth)
  120. console.log('设备像素比 DPR:', info.pixelRatio)
  121. console.log('物理分辨率宽:', info.windowWidth * info.pixelRatio) */
  122. showAppleLogin.value = isIOS13OrAbove();
  123. getLoginInit()
  124. getUUid()
  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 handleAgreementChange = (event) => {
  252. if (event.detail.value[0] === 'agree') {
  253. indexData.isAgreed = true;
  254. } else {
  255. indexData.isAgreed = false;
  256. }
  257. }
  258. // 游客登录
  259. const ykBtn = () => {
  260. const systemInfo = uni.getSystemInfoSync();
  261. if (indexData.isAgreed === true) {
  262. if (!uuid.value) {
  263. toast("设备id丢失")
  264. getUUid()
  265. return false
  266. }
  267. let req = {
  268. uuid: uuid.value
  269. }
  270. youkeLogin(req).then(res => {
  271. if (res.code == 0) {
  272. cacheManager.set('auth', res.data)
  273. uni.switchTab({
  274. url: `/pages/chanpinXuanze/index`
  275. })
  276. }
  277. })
  278. // uni.redirectTo({
  279. // url: `/pages/selectGradesTerms/index`
  280. // })
  281. } else {
  282. agreeYkDialog.value.handleShow();
  283. }
  284. }
  285. const appleLoginClick = () => {
  286. uni.login({
  287. provider: 'apple',
  288. success: function(loginRes) {
  289. console.log('loginRes', loginRes);
  290. let req = {
  291. "apple": true,
  292. "code": loginRes.appleInfo.user
  293. }
  294. console.log(req);
  295. console.log(req);
  296. wxLogin(req).then(res => {
  297. console.log(res);
  298. if (!res.data.bind) {
  299. console.log('未绑定');
  300. cacheManager.set('wxLogin', {
  301. bind: res.data.bing
  302. })
  303. telDialogFlag.value = true;
  304. nextTick(() => {
  305. telDialogRef.value.getOpenId(res.data.openId);
  306. })
  307. } else {
  308. uni.showLoading({
  309. title: '登录中'
  310. });
  311. setTimeout(() => {
  312. cacheManager.set('auth', res.data.loginVo)
  313. if (res.data.loginVo.subjectId == 0 && res.data.loginVo
  314. .levelId == 0) {
  315. uni.redirectTo({
  316. url: `/pages/selectGradesTerms/index`
  317. })
  318. uni.hideLoading();
  319. } else {
  320. uni.redirectTo({
  321. url: `/pages/study/index`
  322. })
  323. uni.hideLoading();
  324. }
  325. }, 1000)
  326. }
  327. }).catch((error) => {
  328. console.log(error);
  329. })
  330. },
  331. fail: function(err) {
  332. console.log('err.code', err.code);
  333. // 登录授权失败
  334. // err.code错误码参考`授权失败错误码(code)说明`
  335. }
  336. });
  337. }
  338. // 游客登录
  339. const wxLoginClick = () => {
  340. if (indexData.isAgreed === true) {
  341. wxLoginFun();
  342. } else {
  343. agreeWxDialog.value.handleShow();
  344. }
  345. }
  346. const wxLoginFun = () => {
  347. //获取服务商信息判断手机端是否安装了app
  348. // uni.getProvider({
  349. // service: 'oauth',// oauth 代表授权登录
  350. // success: function (res) {
  351. // // 登录
  352. // uni.login({
  353. // // 表示授权方式 如果不设置则弹出登录列表选择界面
  354. // provider: 'weixin',
  355. // "onlyAuthorize": true, // 微信登录仅请求授权认证
  356. // success: function (loginRes) {
  357. // console.log('loginRes',loginRes);
  358. // }
  359. // });
  360. // }
  361. // });
  362. if (plus.runtime.isApplicationExist({
  363. pname: 'com.tencent.mm',
  364. action: 'weixin://'
  365. })) {
  366. console.log('111', "已安装微信");
  367. uni.login({
  368. "provider": "weixin",
  369. "onlyAuthorize": true, // 微信登录仅请求授权认证
  370. success: function(event) {
  371. console.log(event);
  372. const {
  373. code
  374. } = event
  375. //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
  376. let req = {
  377. "apple": false,
  378. "code": code
  379. }
  380. console.log(req);
  381. wxLogin(req).then(res => {
  382. console.log(res);
  383. if (!res.data.bind) {
  384. console.log('未绑定');
  385. cacheManager.set('wxLogin', {
  386. bind: res.data.bing
  387. })
  388. telDialogFlag.value = true;
  389. nextTick(() => {
  390. telDialogRef.value.getOpenId(res.data.openId);
  391. })
  392. } else {
  393. uni.showLoading({
  394. title: '登录中'
  395. });
  396. setTimeout(() => {
  397. cacheManager.set('auth', res.data.loginVo)
  398. if (res.data.loginVo.subjectId == 0 && res.data.loginVo
  399. .levelId == 0) {
  400. uni.redirectTo({
  401. url: `/pages/selectGradesTerms/index`
  402. })
  403. uni.hideLoading();
  404. } else {
  405. uni.redirectTo({
  406. url: `/pages/study/index`
  407. })
  408. uni.hideLoading();
  409. }
  410. }, 1000)
  411. }
  412. }).catch((error) => {
  413. console.log(error);
  414. })
  415. },
  416. fail: function(err) {
  417. console.log(err);
  418. // 登录授权失败
  419. // err.code是错误码
  420. }
  421. })
  422. } else {
  423. toast("请重启应用重试")
  424. return false
  425. }
  426. }
  427. </script>