index.vue 10 KB

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