index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <template>
  2. <view class="ezy-login-page">
  3. <view class="ezy-login-wrap">
  4. <icon class="login-e-img"></icon>
  5. <!-- 手机号 -->
  6. <view class="login-body-box">
  7. <view class="index-title-img"></view>
  8. <view class="phone-input-box">
  9. <view class="phone-prefix">+86</view>
  10. <input class="phone-input" type="text" v-model="indexData.phoneNumber" placeholder="请输入手机号"
  11. maxlength="11" @input="clearTelInput" />
  12. <view class="close-btn" v-if="indexData.clearTelIcon" @click="clearTel"></view>
  13. </view>
  14. <!-- 协议勾选框和按钮 -->
  15. <view class="agreement-checkbox-box">
  16. <checkbox-group @change="handleAgreementChange">
  17. <checkbox class="agreement-checkbox-input" color="#FFFFFF" value="agree"
  18. :checked="indexData.isAgreed" />
  19. </checkbox-group>
  20. <view class="agreement-text-box">
  21. 登录注册代表您已同意<view class="agreement-text" @click="agreeBtn('yhxy')">《鹅状元用户协议》</view>和<view
  22. @click="agreeBtn('ystk')" class="agreement-text">《鹅状元隐私政策》</view>
  23. </view>
  24. </view>
  25. <view class="login-btn" @click="getYzmBtn" :class="indexData.telStatus"></view>
  26. </view>
  27. <view class="bottom-btn-box">
  28. <view class="yk-btn" @click="ykBtn"></view>
  29. <view v-if="wxFlag" class="wx-btn" @click="wxLoginClick"></view>
  30. <view class="apple-btn" v-if="showAppleLogin" @click="appleLoginClick"></view>
  31. </view>
  32. </view>
  33. <agree-content-dialog ref="agreeContentDialogRef" :agreeType="agreeType"></agree-content-dialog>
  34. <agree-dialog ref="agreeDialogRef" @confirm-btn="confirmBtn"></agree-dialog>
  35. <agree-dialog ref="agreeYkDialog" @confirm-btn="ykConfirmBtn"></agree-dialog>
  36. <agree-dialog ref="agreeWxDialog" @confirm-btn="wxConfirmBtn"></agree-dialog>
  37. <tel-dialog ref="telDialogRef" @telClose="telClose" @bindBtn="bindBtn" v-if="telDialogFlag"></tel-dialog>
  38. <tip-dialog ref="tipDialogRef" :title="tipTitle" :content="tipContent"></tip-dialog>
  39. </view>
  40. </template>
  41. <script setup>
  42. import {
  43. ref,
  44. nextTick,
  45. reactive
  46. } from "vue"
  47. import {
  48. onLoad,
  49. onReady
  50. } from '@dcloudio/uni-app';
  51. import agreeContentDialog from './agreeContentDialog.vue';
  52. import agreeDialog from './agreeDialog.vue'
  53. import {
  54. wxLogin,
  55. getVersion
  56. } from "@/api/login.js"
  57. import {
  58. toast,
  59. getUserIdentity
  60. } from "@/utils/common";
  61. import telDialog from './telDialog.vue'
  62. import cacheManager from "@/utils/cacheManager.js";
  63. import {
  64. onShow,
  65. onUnload,
  66. } from '@dcloudio/uni-app';
  67. import {
  68. useIsCanBack
  69. } from "@/store/isCanBack.js"
  70. import tipDialog from '@/components/dialog/tipDialog.vue';
  71. import config from '../../config.js'
  72. import {
  73. error
  74. } from "uview-plus";
  75. let indexData = reactive({
  76. phoneNumber: null,
  77. clearTelIcon: false,
  78. telStatus: 'tel-btn-disabled',
  79. isAgreed: false,
  80. sliderObj: {},
  81. })
  82. const agreeContentDialogRef = ref(null);
  83. const agreeType = ref(null);
  84. const agreeDialogRef = ref(null);
  85. const agreeYkDialog = ref(null);
  86. const agreeWxDialog = ref(null);
  87. const telDialogRef = ref(null);
  88. let telDialogFlag = ref(false);
  89. let showAppleLogin = ref(false);
  90. let wxFlag = ref(true);
  91. const version = config.appInfo.version;
  92. const tipDialogRef = ref(null);
  93. const tipTitle = '升级提醒';
  94. const tipContent = '您的APP不是最新版本,部分功能不能使用,请升级至最新版本!';
  95. const store = useIsCanBack();
  96. onUnload(() => {
  97. console.log('unload')
  98. store.setIsCanBack(false)
  99. })
  100. onShow(() => {
  101. setTimeout(() => {
  102. console.log('onShow')
  103. store.setIsCanBack(true)
  104. }, 500)
  105. })
  106. onLoad((options) => {
  107. showAppleLogin.value = isIOS13OrAbove();
  108. getLoginInit()
  109. if (plus.runtime.isApplicationExist({
  110. pname: 'com.tencent.mm',
  111. action: 'weixin://'
  112. })) {
  113. console.log('111', "已安装微信");
  114. wxFlag.value = true
  115. } else {
  116. wxFlag.value = false
  117. }
  118. console.log('showAppleLogin.value', showAppleLogin.value);
  119. })
  120. function getLoginInit() {
  121. getVersion({}).then(res => {
  122. if (version != res.data.version) {
  123. tipDialogRef.value.handleShow();
  124. }
  125. })
  126. }
  127. const getYzmBtn = () => {
  128. if (indexData.telStatus === 'tel-btn-normal') {
  129. if (indexData.isAgreed === true) {
  130. uni.redirectTo({
  131. url: `/pages/login/login?telNum=${indexData.phoneNumber}`
  132. })
  133. } else {
  134. agreeDialogRef.value.handleShow();
  135. }
  136. }
  137. }
  138. const isIOS13OrAbove = () => {
  139. const systemInfo = uni.getSystemInfoSync();
  140. if (systemInfo.platform == 'ios') {
  141. const version = systemInfo.system.split(' ')[1].split('.');
  142. const majorVersion = parseInt(version[0], 10);
  143. return majorVersion >= 13;
  144. }
  145. return false;
  146. }
  147. // 用户协议同意
  148. const confirmBtn = () => {
  149. indexData.isAgreed = true;
  150. getYzmBtn();
  151. }
  152. const telClose = () => {
  153. telDialogFlag.value = false;
  154. }
  155. const bindBtn = (res) => {
  156. telDialogFlag.value = false;
  157. if (res.cardId == 0) {
  158. uni.redirectTo({
  159. url: `/pages/selectGradesTerms/index`
  160. })
  161. } else {
  162. uni.redirectTo({
  163. url: `/pages/study/index`
  164. })
  165. }
  166. }
  167. const ykConfirmBtn = () => {
  168. uni.redirectTo({
  169. url: `/pages/selectGradesTerms/index`
  170. })
  171. }
  172. const wxConfirmBtn = () => {
  173. wxLoginFun();
  174. }
  175. // 手机号校验规则
  176. const validatePhoneNumber = (value) => {
  177. const phoneRegex = /^1[3-9]\d{9}$/;
  178. if (phoneRegex.test(value)) {
  179. indexData.telStatus = 'tel-btn-normal';
  180. } else {
  181. indexData.telStatus = 'tel-btn-disabled';
  182. }
  183. }
  184. const clearTelInput = (event) => {
  185. if (event.detail.value.length > 0) {
  186. indexData.clearTelIcon = true;
  187. validatePhoneNumber(event.detail.value);
  188. } else {
  189. indexData.clearTelIcon = false;
  190. }
  191. }
  192. const clearTel = () => {
  193. indexData.phoneNumber = '';
  194. indexData.telStatus = 'tel-btn-disabled';
  195. indexData.clearTelIcon = false;
  196. }
  197. const agreeBtn = (data) => {
  198. if (data === 'yhxy') {
  199. agreeType.value = 'yhxy'
  200. } else {
  201. agreeType.value = 'ystk'
  202. }
  203. agreeContentDialogRef.value.handleShow();
  204. };
  205. const handleAgreementChange = (event) => {
  206. if (event.detail.value[0] === 'agree') {
  207. indexData.isAgreed = true;
  208. } else {
  209. indexData.isAgreed = false;
  210. }
  211. }
  212. // 游客登录
  213. const ykBtn = () => {
  214. if (indexData.isAgreed === true) {
  215. uni.redirectTo({
  216. url: `/pages/selectGradesTerms/index`
  217. })
  218. } else {
  219. agreeYkDialog.value.handleShow();
  220. }
  221. }
  222. const appleLoginClick = () => {
  223. uni.login({
  224. provider: 'apple',
  225. success: function(loginRes) {
  226. console.log('loginRes', loginRes);
  227. let req = {
  228. "apple": true,
  229. "code": loginRes.appleInfo.user
  230. }
  231. console.log(req);
  232. console.log(req);
  233. wxLogin(req).then(res => {
  234. console.log(res);
  235. if (!res.data.bind) {
  236. console.log('未绑定');
  237. cacheManager.set('wxLogin', {
  238. bind: res.data.bing
  239. })
  240. telDialogFlag.value = true;
  241. nextTick(() => {
  242. telDialogRef.value.getOpenId(res.data.openId);
  243. })
  244. } else {
  245. uni.showLoading({
  246. title: '登录中'
  247. });
  248. setTimeout(() => {
  249. cacheManager.set('auth', res.data.loginVo)
  250. if (res.data.loginVo.subjectId == 0 && res.data.loginVo
  251. .levelId == 0) {
  252. uni.redirectTo({
  253. url: `/pages/selectGradesTerms/index`
  254. })
  255. uni.hideLoading();
  256. } else {
  257. uni.redirectTo({
  258. url: `/pages/study/index`
  259. })
  260. uni.hideLoading();
  261. }
  262. }, 1000)
  263. }
  264. }).catch((error) => {
  265. console.log(error);
  266. })
  267. },
  268. fail: function(err) {
  269. console.log('err.code', err.code);
  270. // 登录授权失败
  271. // err.code错误码参考`授权失败错误码(code)说明`
  272. }
  273. });
  274. }
  275. // 游客登录
  276. const wxLoginClick = () => {
  277. if (indexData.isAgreed === true) {
  278. wxLoginFun();
  279. } else {
  280. agreeWxDialog.value.handleShow();
  281. }
  282. }
  283. const wxLoginFun = () => {
  284. //获取服务商信息判断手机端是否安装了app
  285. // uni.getProvider({
  286. // service: 'oauth',// oauth 代表授权登录
  287. // success: function (res) {
  288. // // 登录
  289. // uni.login({
  290. // // 表示授权方式 如果不设置则弹出登录列表选择界面
  291. // provider: 'weixin',
  292. // "onlyAuthorize": true, // 微信登录仅请求授权认证
  293. // success: function (loginRes) {
  294. // console.log('loginRes',loginRes);
  295. // }
  296. // });
  297. // }
  298. // });
  299. if (plus.runtime.isApplicationExist({
  300. pname: 'com.tencent.mm',
  301. action: 'weixin://'
  302. })) {
  303. console.log('111', "已安装微信");
  304. uni.login({
  305. "provider": "weixin",
  306. "onlyAuthorize": true, // 微信登录仅请求授权认证
  307. success: function(event) {
  308. console.log(event);
  309. const {
  310. code
  311. } = event
  312. //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
  313. let req = {
  314. "apple": false,
  315. "code": code
  316. }
  317. console.log(req);
  318. wxLogin(req).then(res => {
  319. console.log(res);
  320. if (!res.data.bind) {
  321. console.log('未绑定');
  322. cacheManager.set('wxLogin', {
  323. bind: res.data.bing
  324. })
  325. telDialogFlag.value = true;
  326. nextTick(() => {
  327. telDialogRef.value.getOpenId(res.data.openId);
  328. })
  329. } else {
  330. uni.showLoading({
  331. title: '登录中'
  332. });
  333. setTimeout(() => {
  334. cacheManager.set('auth', res.data.loginVo)
  335. if (res.data.loginVo.subjectId == 0 && res.data.loginVo
  336. .levelId == 0) {
  337. uni.redirectTo({
  338. url: `/pages/selectGradesTerms/index`
  339. })
  340. uni.hideLoading();
  341. } else {
  342. uni.redirectTo({
  343. url: `/pages/study/index`
  344. })
  345. uni.hideLoading();
  346. }
  347. }, 1000)
  348. }
  349. }).catch((error) => {
  350. console.log(error);
  351. })
  352. },
  353. fail: function(err) {
  354. console.log(err);
  355. // 登录授权失败
  356. // err.code是错误码
  357. }
  358. })
  359. } else {
  360. toast("请重启应用重试")
  361. return false
  362. }
  363. }
  364. </script>