index.vue 10 KB

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