From 22fffcb02973e1f02bc16fc0521d965ee5521316 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 17 Dec 2023 17:06:11 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E9=87=8D=E7=BD=AE=E5=AF=86?= =?UTF-8?q?=E7=A0=81=EF=BC=9A=E6=8E=A5=E5=85=A5=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.vue | 3 -- pages/user/info.vue | 16 ++++------ sheep/api/app.js | 23 +++++--------- sheep/api/member/auth.js | 17 ++++++++-- sheep/api/member/user.js | 14 +++++++++ .../components/reset-password.vue | 31 +++++++++++-------- sheep/hooks/useModal.js | 13 ++++---- sheep/request/index.js | 2 +- 8 files changed, 67 insertions(+), 52 deletions(-) create mode 100644 sheep/api/member/user.js diff --git a/pages/index/index.vue b/pages/index/index.vue index 68a00bd8..3e398c12 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -71,9 +71,6 @@ if (options.page) { sheep.$router.go(decodeURIComponent(options.page)); } - - // TODO 芋艿:测试接口的调用 - sheep.$api.app.test(); }); // 下拉刷新 diff --git a/pages/user/info.vue b/pages/user/info.vue index f3784d09..3342180c 100644 --- a/pages/user/info.vue +++ b/pages/user/info.vue @@ -15,7 +15,7 @@ class="content-img" isPreview :current="0" - :src="state.model.avatar" + :src="state.model?.avatar" :height="160" :width="160" :radius="80" @@ -57,7 +57,7 @@ :value="item.value" color="var(--ui-BG-Main)" style="transform: scale(0.8)" - :checked="parseInt(item.value) === state.model.sex" + :checked="parseInt(item.value) === state.model?.sex" /> {{ item.name }} @@ -90,7 +90,7 @@ @@ -245,13 +245,9 @@ state.model.avatar = data; } - // 修改/设置密码 TODO + // 修改密码 TODO function onSetPassword() { - if (state.model.verification.password) { - showAuthModal('changePassword'); - } else { - showAuthModal('resetPassword'); - } + showAuthModal('changePassword'); } // 绑定第三方账号 TODO diff --git a/sheep/api/app.js b/sheep/api/app.js index 184882f0..3a2543e5 100644 --- a/sheep/api/app.js +++ b/sheep/api/app.js @@ -1,19 +1,6 @@ import request from '@/sheep/request'; -import { baseUrl } from '@/sheep/config'; export default { - // TODO 芋艿:测试 - test: () => - request({ - url: '/app-api/promotion/decorate/list', - params: { - page: 1 - }, - custom: { - showError: false, - showLoading: false, - }, - }), // 系统初始化 init: (templateId) => request({ @@ -40,11 +27,15 @@ export default { }, }), // 发送短信 - sendSms: (data) => + // TODO 芋艿:直接在 useModal 引入 AuthUtil 会报错,所以继续用这个 API + sendSms: (mobile, scene) => request({ - url: 'sendSms', + url: '/app-api/member/auth/send-sms-code', method: 'POST', - data, + data: { + mobile, + scene + }, custom: { showSuccess: true, loadingMsg: '发送中', diff --git a/sheep/api/member/auth.js b/sheep/api/member/auth.js index 7128dcf2..3cd4536c 100644 --- a/sheep/api/member/auth.js +++ b/sheep/api/member/auth.js @@ -1,14 +1,25 @@ -import request2 from '@/sheep/request2'; +import request from '@/sheep/request2'; const AuthUtil = { + // 发送手机验证码 + sendSmsCode: (mobile, scene) => { + return request({ + url: '/app-api/member/auth/send-sms-code', + method: 'POST', + data: { + mobile, + scene + } + }); + }, + // 登出系统 logout: () => { - return request2({ + return request({ url: '/app-api/member/auth/logout', method: 'POST' }); }, - }; export default AuthUtil; diff --git a/sheep/api/member/user.js b/sheep/api/member/user.js new file mode 100644 index 00000000..88dcef2e --- /dev/null +++ b/sheep/api/member/user.js @@ -0,0 +1,14 @@ +import request from '@/sheep/request2'; + +const UserApi = { + // 重置密码 + resetUserPassword: (data) => { + return request({ + url: '/app-api/member/user/reset-password', + method: 'PUT', + data + }); + }, +}; + +export default UserApi; diff --git a/sheep/components/s-auth-modal/components/reset-password.vue b/sheep/components/s-auth-modal/components/reset-password.vue index 81858ad9..53520432 100644 --- a/sheep/components/s-auth-modal/components/reset-password.vue +++ b/sheep/components/s-auth-modal/components/reset-password.vue @@ -43,7 +43,7 @@ type="number" maxlength="4" :inputBorder="false" - > + /> @@ -69,10 +69,11 @@ diff --git a/sheep/hooks/useModal.js b/sheep/hooks/useModal.js index 76bb333c..6dfc2af1 100644 --- a/sheep/hooks/useModal.js +++ b/sheep/hooks/useModal.js @@ -61,7 +61,6 @@ export function closeMenuTools() { export function getSmsCode(event, mobile = '') { const modalStore = $store('modal'); const lastSendTimer = modalStore.lastTimer[event]; - if (typeof lastSendTimer === 'undefined') { $helper.toast('短信发送事件错误'); return; @@ -69,26 +68,28 @@ export function getSmsCode(event, mobile = '') { const duration = dayjs().unix() - lastSendTimer; const canSend = duration >= 60; - if (!canSend) { $helper.toast('请稍后再试'); return; } - if (!test.mobile(mobile)) { $helper.toast('手机号码格式不正确'); return; } // 发送验证码 + 更新上次发送验证码时间 - $api.app.sendSms({ mobile, event }).then((res) => { - if (res.error === 0) { + let scene = -1; + switch (event) { + case 'resetPassword': + scene = 4; + } + $api.app.sendSms(mobile, scene).then((res) => { + if (res.code === 0) { modalStore.$patch((state) => { state.lastTimer[event] = dayjs().unix(); }); } }); - } // 获取短信验证码倒计时 -- 60秒 diff --git a/sheep/request/index.js b/sheep/request/index.js index e9b16c09..c71ea516 100644 --- a/sheep/request/index.js +++ b/sheep/request/index.js @@ -115,7 +115,7 @@ http.interceptors.response.use( } response.config.custom.showLoading && closeLoading(); - if (response.data.error !== 0) { + if (response.data.error !== 0 && response.data.code !== 0) { if (response.config.custom.showError) uni.showToast({ title: response.data.msg || '服务器开小差啦,请稍后再试~',