From 2c7d89d711f545d865b55bb49630a584fae75d2c Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 17 Dec 2023 17:52:49 +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=E4=BC=98=E5=8C=96=E6=8E=A5=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sheep/api/app.js | 15 --------------- sheep/api/index.js | 5 ++++- sheep/api/member/auth.js | 8 ++++++-- sheep/api/member/user.js | 7 ++++++- sheep/api/user.js | 11 ----------- sheep/hooks/useModal.js | 2 +- sheep/request/index.js | 5 +++-- 7 files changed, 20 insertions(+), 33 deletions(-) diff --git a/sheep/api/app.js b/sheep/api/app.js index 3a2543e5..a456039a 100644 --- a/sheep/api/app.js +++ b/sheep/api/app.js @@ -26,21 +26,6 @@ export default { showLoading: false, }, }), - // 发送短信 - // TODO 芋艿:直接在 useModal 引入 AuthUtil 会报错,所以继续用这个 API - sendSms: (mobile, scene) => - request({ - url: '/app-api/member/auth/send-sms-code', - method: 'POST', - data: { - mobile, - scene - }, - custom: { - showSuccess: true, - loadingMsg: '发送中', - }, - }), // 自定义页面 page: (id) => request({ diff --git a/sheep/api/index.js b/sheep/api/index.js index c25a3493..d415fa47 100644 --- a/sheep/api/index.js +++ b/sheep/api/index.js @@ -7,4 +7,7 @@ Object.keys(files).forEach((key) => { }; }); -export default api; +// TODO 芋艿:直接在 useModal 引入 AuthUtil 会报错,所以采用这用这方式先 +api.AuthUtil = import.meta.globEager('./member/auth.js')['./member/auth.js'].default; + +export default api; \ No newline at end of file diff --git a/sheep/api/member/auth.js b/sheep/api/member/auth.js index 3cd4536c..d265e201 100644 --- a/sheep/api/member/auth.js +++ b/sheep/api/member/auth.js @@ -1,4 +1,4 @@ -import request from '@/sheep/request2'; +import request from '@/sheep/request'; const AuthUtil = { // 发送手机验证码 @@ -9,10 +9,14 @@ const AuthUtil = { data: { mobile, scene + }, + custom: { + loadingMsg: '发送中', + showSuccess: true, + successMsg: '发送成功' } }); }, - // 登出系统 logout: () => { return request({ diff --git a/sheep/api/member/user.js b/sheep/api/member/user.js index 88dcef2e..f0aba4ce 100644 --- a/sheep/api/member/user.js +++ b/sheep/api/member/user.js @@ -6,7 +6,12 @@ const UserApi = { return request({ url: '/app-api/member/user/reset-password', method: 'PUT', - data + data, + custom: { + loadingMsg: '验证中', + showSuccess: true, + successMsg: '修改成功' + } }); }, }; diff --git a/sheep/api/user.js b/sheep/api/user.js index f4e07c47..ee153b7f 100644 --- a/sheep/api/user.js +++ b/sheep/api/user.js @@ -92,17 +92,6 @@ export default { loadingMsg: '正在注册', }, }), - // 重置密码 - resetPassword: (data) => - request({ - url: '/user/api/user/resetPassword', - method: 'POST', - data, - custom: { - showSuccess: true, - loadingMsg: '验证中', - }, - }), // 修改密码 changePassword: (data) => diff --git a/sheep/hooks/useModal.js b/sheep/hooks/useModal.js index 6dfc2af1..20a74684 100644 --- a/sheep/hooks/useModal.js +++ b/sheep/hooks/useModal.js @@ -83,7 +83,7 @@ export function getSmsCode(event, mobile = '') { case 'resetPassword': scene = 4; } - $api.app.sendSms(mobile, scene).then((res) => { + $api.AuthUtil.sendSmsCode(mobile, scene).then((res) => { if (res.code === 0) { modalStore.$patch((state) => { state.lastTimer[event] = dayjs().unix(); diff --git a/sheep/request/index.js b/sheep/request/index.js index c71ea516..3de1bec0 100644 --- a/sheep/request/index.js +++ b/sheep/request/index.js @@ -124,9 +124,10 @@ http.interceptors.response.use( }); return Promise.resolve(response.data); } + // 成功时的提示 if ( - response.data.error === 0 && - response.data.msg !== '' && + (response.data.error === 0 || response.data.code === 0) && + ( response.data.msg !== '' || response.config.custom.successMsg !== '' ) && response.config.custom.showSuccess ) { uni.showToast({