index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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. plus.device.getInfo({
  239. success: (res) => {
  240. // res.uuid 是设备的 UUID(iOS 下为 identifierForVendor)
  241. console.log('res', res);
  242. uuid.value = res.uuid;
  243. console.log('iOS 设备 UUID:', uuid.value);
  244. },
  245. fail: (err) => {
  246. console.error('获取设备信息失败:', err);
  247. }
  248. });
  249. };
  250. const handleAgreementChange = (event) => {
  251. if (event.detail.value[0] === 'agree') {
  252. indexData.isAgreed = true;
  253. } else {
  254. indexData.isAgreed = false;
  255. }
  256. }
  257. // 游客登录
  258. const ykBtn = () => {
  259. const systemInfo = uni.getSystemInfoSync();
  260. if (indexData.isAgreed === true) {
  261. if (!uuid.value) {
  262. toast("设备id丢失")
  263. getUUid()
  264. return false
  265. }
  266. let req = {
  267. uuid: uuid.value
  268. }
  269. youkeLogin(req).then(res => {
  270. if (res.code == 0) {
  271. cacheManager.set('auth', res.data)
  272. uni.switchTab({
  273. url: `/pages/chanpinXuanze/index`
  274. })
  275. }
  276. })
  277. // uni.redirectTo({
  278. // url: `/pages/selectGradesTerms/index`
  279. // })
  280. } else {
  281. agreeYkDialog.value.handleShow();
  282. }
  283. }
  284. const appleLoginClick = () => {
  285. uni.login({
  286. provider: 'apple',
  287. success: function(loginRes) {
  288. console.log('loginRes', loginRes);
  289. let req = {
  290. "apple": true,
  291. "code": loginRes.appleInfo.user
  292. }
  293. console.log(req);
  294. console.log(req);
  295. wxLogin(req).then(res => {
  296. console.log(res);
  297. if (!res.data.bind) {
  298. console.log('未绑定');
  299. cacheManager.set('wxLogin', {
  300. bind: res.data.bing
  301. })
  302. telDialogFlag.value = true;
  303. nextTick(() => {
  304. telDialogRef.value.getOpenId(res.data.openId);
  305. })
  306. } else {
  307. uni.showLoading({
  308. title: '登录中'
  309. });
  310. setTimeout(() => {
  311. cacheManager.set('auth', res.data.loginVo)
  312. if (res.data.loginVo.subjectId == 0 && res.data.loginVo
  313. .levelId == 0) {
  314. uni.redirectTo({
  315. url: `/pages/selectGradesTerms/index`
  316. })
  317. uni.hideLoading();
  318. } else {
  319. uni.redirectTo({
  320. url: `/pages/study/index`
  321. })
  322. uni.hideLoading();
  323. }
  324. }, 1000)
  325. }
  326. }).catch((error) => {
  327. console.log(error);
  328. })
  329. },
  330. fail: function(err) {
  331. console.log('err.code', err.code);
  332. // 登录授权失败
  333. // err.code错误码参考`授权失败错误码(code)说明`
  334. }
  335. });
  336. }
  337. // 游客登录
  338. const wxLoginClick = () => {
  339. if (indexData.isAgreed === true) {
  340. wxLoginFun();
  341. } else {
  342. agreeWxDialog.value.handleShow();
  343. }
  344. }
  345. const wxLoginFun = () => {
  346. //获取服务商信息判断手机端是否安装了app
  347. // uni.getProvider({
  348. // service: 'oauth',// oauth 代表授权登录
  349. // success: function (res) {
  350. // // 登录
  351. // uni.login({
  352. // // 表示授权方式 如果不设置则弹出登录列表选择界面
  353. // provider: 'weixin',
  354. // "onlyAuthorize": true, // 微信登录仅请求授权认证
  355. // success: function (loginRes) {
  356. // console.log('loginRes',loginRes);
  357. // }
  358. // });
  359. // }
  360. // });
  361. if (plus.runtime.isApplicationExist({
  362. pname: 'com.tencent.mm',
  363. action: 'weixin://'
  364. })) {
  365. console.log('111', "已安装微信");
  366. uni.login({
  367. "provider": "weixin",
  368. "onlyAuthorize": true, // 微信登录仅请求授权认证
  369. success: function(event) {
  370. console.log(event);
  371. const {
  372. code
  373. } = event
  374. //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
  375. let req = {
  376. "apple": false,
  377. "code": code
  378. }
  379. console.log(req);
  380. wxLogin(req).then(res => {
  381. console.log(res);
  382. if (!res.data.bind) {
  383. console.log('未绑定');
  384. cacheManager.set('wxLogin', {
  385. bind: res.data.bing
  386. })
  387. telDialogFlag.value = true;
  388. nextTick(() => {
  389. telDialogRef.value.getOpenId(res.data.openId);
  390. })
  391. } else {
  392. uni.showLoading({
  393. title: '登录中'
  394. });
  395. setTimeout(() => {
  396. cacheManager.set('auth', res.data.loginVo)
  397. if (res.data.loginVo.subjectId == 0 && res.data.loginVo
  398. .levelId == 0) {
  399. uni.redirectTo({
  400. url: `/pages/selectGradesTerms/index`
  401. })
  402. uni.hideLoading();
  403. } else {
  404. uni.redirectTo({
  405. url: `/pages/study/index`
  406. })
  407. uni.hideLoading();
  408. }
  409. }, 1000)
  410. }
  411. }).catch((error) => {
  412. console.log(error);
  413. })
  414. },
  415. fail: function(err) {
  416. console.log(err);
  417. // 登录授权失败
  418. // err.code是错误码
  419. }
  420. })
  421. } else {
  422. toast("请重启应用重试")
  423. return false
  424. }
  425. }
  426. </script>