index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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. uni.redirectTo({
  166. url: `/pages/selectGradesTerms/index`
  167. })
  168. }
  169. const wxConfirmBtn = () => {
  170. wxLoginFun();
  171. }
  172. // 手机号校验规则
  173. const validatePhoneNumber = (value) => {
  174. const phoneRegex = /^1[3-9]\d{9}$/;
  175. if (phoneRegex.test(value)) {
  176. indexData.telStatus = 'login-btn-normal';
  177. } else {
  178. indexData.telStatus = 'login-btn-disabled';
  179. }
  180. }
  181. const clearTelInput = (event) => {
  182. if (event.detail.value.length > 0) {
  183. indexData.clearTelIcon = true;
  184. validatePhoneNumber(event.detail.value);
  185. } else {
  186. indexData.clearTelIcon = false;
  187. }
  188. }
  189. const clearTel = () => {
  190. indexData.phoneNumber = '';
  191. indexData.telStatus = 'login-btn-disabled';
  192. indexData.clearTelIcon = false;
  193. }
  194. const agreeBtn = (data) => {
  195. if (data === 'yhxy') {
  196. agreeType.value = 'yhxy'
  197. } else {
  198. agreeType.value = 'ystk'
  199. }
  200. agreeContentDialogRef.value.handleShow();
  201. };
  202. const getUUid = (data) => {
  203. plus.device.getInfo({
  204. success: (res) => {
  205. // res.uuid 是设备的 UUID(iOS 下为 identifierForVendor)
  206. console.log('res', res);
  207. uuid.value = res.uuid;
  208. console.log('iOS 设备 UUID:', uuid.value);
  209. },
  210. fail: (err) => {
  211. console.error('获取设备信息失败:', err);
  212. }
  213. });
  214. };
  215. const handleAgreementChange = (event) => {
  216. if (event.detail.value[0] === 'agree') {
  217. indexData.isAgreed = true;
  218. } else {
  219. indexData.isAgreed = false;
  220. }
  221. }
  222. // 游客登录
  223. const ykBtn = () => {
  224. const systemInfo = uni.getSystemInfoSync();
  225. if (indexData.isAgreed === true) {
  226. if (!uuid.value) {
  227. toast("设备id丢失")
  228. getUUid()
  229. return false
  230. }
  231. let req = {
  232. uuid: uuid.value
  233. }
  234. youkeLogin(req).then(res => {
  235. if (res.code == 0) {
  236. cacheManager.set('auth', res.data)
  237. uni.switchTab({
  238. url: `/pages/chanpinXuanze/index`
  239. })
  240. }
  241. })
  242. // uni.redirectTo({
  243. // url: `/pages/selectGradesTerms/index`
  244. // })
  245. } else {
  246. agreeYkDialog.value.handleShow();
  247. }
  248. }
  249. const appleLoginClick = () => {
  250. uni.login({
  251. provider: 'apple',
  252. success: function(loginRes) {
  253. console.log('loginRes', loginRes);
  254. let req = {
  255. "apple": true,
  256. "code": loginRes.appleInfo.user
  257. }
  258. console.log(req);
  259. console.log(req);
  260. wxLogin(req).then(res => {
  261. console.log(res);
  262. if (!res.data.bind) {
  263. console.log('未绑定');
  264. cacheManager.set('wxLogin', {
  265. bind: res.data.bing
  266. })
  267. telDialogFlag.value = true;
  268. nextTick(() => {
  269. telDialogRef.value.getOpenId(res.data.openId);
  270. })
  271. } else {
  272. uni.showLoading({
  273. title: '登录中'
  274. });
  275. setTimeout(() => {
  276. cacheManager.set('auth', res.data.loginVo)
  277. if (res.data.loginVo.subjectId == 0 && res.data.loginVo
  278. .levelId == 0) {
  279. uni.redirectTo({
  280. url: `/pages/selectGradesTerms/index`
  281. })
  282. uni.hideLoading();
  283. } else {
  284. uni.redirectTo({
  285. url: `/pages/study/index`
  286. })
  287. uni.hideLoading();
  288. }
  289. }, 1000)
  290. }
  291. }).catch((error) => {
  292. console.log(error);
  293. })
  294. },
  295. fail: function(err) {
  296. console.log('err.code', err.code);
  297. // 登录授权失败
  298. // err.code错误码参考`授权失败错误码(code)说明`
  299. }
  300. });
  301. }
  302. // 游客登录
  303. const wxLoginClick = () => {
  304. if (indexData.isAgreed === true) {
  305. wxLoginFun();
  306. } else {
  307. agreeWxDialog.value.handleShow();
  308. }
  309. }
  310. const wxLoginFun = () => {
  311. //获取服务商信息判断手机端是否安装了app
  312. // uni.getProvider({
  313. // service: 'oauth',// oauth 代表授权登录
  314. // success: function (res) {
  315. // // 登录
  316. // uni.login({
  317. // // 表示授权方式 如果不设置则弹出登录列表选择界面
  318. // provider: 'weixin',
  319. // "onlyAuthorize": true, // 微信登录仅请求授权认证
  320. // success: function (loginRes) {
  321. // console.log('loginRes',loginRes);
  322. // }
  323. // });
  324. // }
  325. // });
  326. if (plus.runtime.isApplicationExist({
  327. pname: 'com.tencent.mm',
  328. action: 'weixin://'
  329. })) {
  330. console.log('111', "已安装微信");
  331. uni.login({
  332. "provider": "weixin",
  333. "onlyAuthorize": true, // 微信登录仅请求授权认证
  334. success: function(event) {
  335. console.log(event);
  336. const {
  337. code
  338. } = event
  339. //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
  340. let req = {
  341. "apple": false,
  342. "code": code
  343. }
  344. console.log(req);
  345. wxLogin(req).then(res => {
  346. console.log(res);
  347. if (!res.data.bind) {
  348. console.log('未绑定');
  349. cacheManager.set('wxLogin', {
  350. bind: res.data.bing
  351. })
  352. telDialogFlag.value = true;
  353. nextTick(() => {
  354. telDialogRef.value.getOpenId(res.data.openId);
  355. })
  356. } else {
  357. uni.showLoading({
  358. title: '登录中'
  359. });
  360. setTimeout(() => {
  361. cacheManager.set('auth', res.data.loginVo)
  362. if (res.data.loginVo.subjectId == 0 && res.data.loginVo
  363. .levelId == 0) {
  364. uni.redirectTo({
  365. url: `/pages/selectGradesTerms/index`
  366. })
  367. uni.hideLoading();
  368. } else {
  369. uni.redirectTo({
  370. url: `/pages/study/index`
  371. })
  372. uni.hideLoading();
  373. }
  374. }, 1000)
  375. }
  376. }).catch((error) => {
  377. console.log(error);
  378. })
  379. },
  380. fail: function(err) {
  381. console.log(err);
  382. // 登录授权失败
  383. // err.code是错误码
  384. }
  385. })
  386. } else {
  387. toast("请重启应用重试")
  388. return false
  389. }
  390. }
  391. </script>