index.vue 11 KB

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