index.vue 11 KB

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