index.vue 12 KB

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