index.vue 11 KB

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