From 565585b07a25626366c1ae41e73b2cc074bd48e7 Mon Sep 17 00:00:00 2001 From: xuesinan <1404152492@qq.com> Date: Tue, 11 Jan 2022 14:47:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=89=8B=E6=9C=BA=E5=8F=B7=E7=99=BB?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 7 ++ hooks/user/userMixin.js | 180 ++++++++++++++++++++++++++-------- pages.json | 11 ++- pages/index/index.vue | 6 +- pages/user/accountLogin.vue | 89 +++++++++-------- pages/user/forgetPassword.vue | 8 ++ pages/user/login.vue | 128 +++++++++++++++++++++++- pages/user/rigister.vue | 8 ++ 8 files changed, 351 insertions(+), 86 deletions(-) create mode 100644 pages/user/forgetPassword.vue create mode 100644 pages/user/rigister.vue diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b32e1f..bb5a917 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,13 @@ - | defineExpose, defineEmits不需要引入 | [902cacc](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/902cacc) +### 📦 持续集成 +范围|描述|commitId +--|--|-- + - | 添加drone.yml | [9fbae89](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/9fbae89) + - | 修改.drone.yml | [f5b52e3](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/f5b52e3) + + ### 🔨 代码重构 范围|描述|commitId --|--|-- diff --git a/hooks/user/userMixin.js b/hooks/user/userMixin.js index 3ab2cd0..a5b4a0c 100644 --- a/hooks/user/userMixin.js +++ b/hooks/user/userMixin.js @@ -1,11 +1,13 @@ -import { ref, computed } from 'vue'; -import { useStore } from 'vuex'; -import clipboard from "@/common/js/dc-clipboard/clipboard.js" +import { ref, computed, reactive } from 'vue'; +import { useStore } from 'vuex'; +import { onReady } from '@dcloudio/uni-app'; +import clipboard from "@/common/js/dc-clipboard/clipboard.js"; +import Config from '@/common/js/config.js' export default function userMixin() { const store = useStore(); const user = computed(() => store.state.user.user); - const rules = ref({ + const rules = { phone: [{ required: true, message: '请输入手机号', @@ -78,46 +80,146 @@ export default function userMixin() { trigger: ['change', 'blur'], } ], - }); - const errorType = ['message']; - const labelPosition = 'left'; - const border = false; - const smsCode = ref(''); // 短信验证码 + }; + const smsCode = ref(null); // 短信验证码 const showInterval = ref(false); const interval = ref(120); const codeTimer = ref(null); - const showPaste = ref(false); - - // 获取图形验证码 - async function getImageCode() { - console.log('5555') - uni.$ui.showLoading(); - try { - const data = await uni.$u.api.getImageCode(); - const { imageBase64, verificationCodeId } = data; - imageBase64 = imageBase64 || ''; - verificationCodeId = verificationCodeId || ''; - uni.$ui.hideLoading(); - } catch (error) { - uni.$ui.hideLoading(); - uni.$ui.showToast(error); - } + const showPaste = ref(false); + + //有图片验证码的值 + function hasvalue(form) { + if(form.smsCode || form.showPaste) return + if (!verifyPhone(form.phone)) { + uni.$ui.showToast('请输入正确的手机号'); + return; + } + if (!form.verificationCodeValue) { + uni.$ui.showToast('请输入图形验证码'); + return; + } + getCode(); + } + + // 获取验证码 + async function getCode() { + try { + if (!verificationCodeId.value || !form.verificationCodeValue) { + showToast('缺少图形验证码参数'); + return; + } + const params = { + phone: form.phone, + verificationCodeId: verificationCodeId.value, + verificationCodeValue: form.verificationCodeValue, + }; + const date = await store.dispatch('user/sendCode', params); + getCodeInterval(); + showPaste.value = true; + } catch (err) { + throw err; + } + } + + // 获取验证码倒计时 + function getCodeInterval() { + showInterval.value = true; + codeTimer.value = setInterval(() => { + if (interval.value === 0) { + clearInterval(codeTimer.value); + codeTimer.value = null; + showInterval.value = false; + interval.value = 120; + return; + } + interval.value = interval.value - 1; + }, 1000); + } + + // 粘贴 + function setCode() { + // 获取粘贴板内容 + // 小程序平台 + //#ifdef MP-WEIXIN + uni.getClipboardData({ + success (res) { + smsCode.value = res.data; + } + }); + //#endif + + // 非小程序平台 + //#ifndef MP-WEIXIN + getClipboardContents() + //#endif + } + + // 非小程序平台粘贴 + async function getClipboardContents() { + try { + const text = await navigator.clipboard.readText(); + smsCode.value = text; + } catch (err) { + console.error('Failed to read clipboard contents: ', err); + } + } + + // 验证信息 + function checkRules() { + if (!verifyPhone(phone.value)) { + uni.$ui.showToast('请输入正确的手机号'); + return false; + } + if (!smsCode.value) { + uni.$ui.showToast('验证码无效'); + return false; + } + + if (phone.value === user.value.phone) { + uni.$ui.showToast('新手机号不能与旧手机号相同'); + return; + } + return true; + } + + /** + * 验证手机号格式 + * @param {string} phone 手机号 + */ + function verifyPhone(phone) { + const phoneExg = /^1\d{10}$/; + return phoneExg.test(phone); + } + + /** + * 验证账号/密码 格式 + * @param {string} account 账号 + */ + function verifyLoginname(account) { + const accountExg = /^[a-zA-Z0-9._-]{2,20}$/; + return accountExg.test(account); + } + + // 微信登录 + function handleWxLogin() { + const origin = `${Config.baseUrl}/pt-mui`; // 测试 + const appid = 'wxd1842e073e0e6d91'; + const state = 'wx_web'; + const href = 'https://open.weixin.qq.com/connect/qrconnect'; + // eslint-disable-next-line + window.location.href = + `${href}?appid=${appid}&redirect_uri=${origin}&response_type=code&scope=snsapi_login&state=${state}#wechat_redirect`; } return { - rules, - errorType, - labelPosition, - border, - getImageCode, - // hasvalue, - // getCode, - // getCodeInterval, - // checkRules, - // setCode, - // getClipboardContents, - // verifyPhone, - // verifyLoginname, - // handleWxLogin + rules, + showPaste, + showInterval, + interval, + hasvalue, + checkRules, + setCode, + verifyLoginname, + handleWxLogin } } diff --git a/pages.json b/pages.json index a3be40c..feb8e1e 100644 --- a/pages.json +++ b/pages.json @@ -12,13 +12,22 @@ "navigationStyle": "custom", "navigationBarTextStyle": "white" } - }, + }, + // 用户名密码登录 { "path": "pages/user/accountLogin", "style": { "navigationStyle": "custom", "navigationBarTextStyle": "white" } + }, + // 手机号登录 + { + "path": "pages/user/login", + "style": { + "navigationStyle": "custom", + "navigationBarTextStyle": "white" + } } ], "globalStyle": { diff --git a/pages/index/index.vue b/pages/index/index.vue index 5b0349e..e42def3 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -7,7 +7,7 @@ - +登录 @@ -104,6 +104,10 @@ function onMove(event) { prevY = y; data.value.calendar.initDate(); } + +function toLogin() { + uni.navigateTo({ url: '/pages/user/accountLogin' }) +} diff --git a/pages/user/login.vue b/pages/user/login.vue index 48d48ea..2f375cc 100644 --- a/pages/user/login.vue +++ b/pages/user/login.vue @@ -1,8 +1,132 @@ - - diff --git a/pages/user/rigister.vue b/pages/user/rigister.vue new file mode 100644 index 0000000..48d48ea --- /dev/null +++ b/pages/user/rigister.vue @@ -0,0 +1,8 @@ + + + + +