重置密码:接入完成

pull/29/head^2
YunaiV 2023-12-17 17:06:11 +08:00
parent 46f3aa7255
commit 22fffcb029
8 changed files with 67 additions and 52 deletions

View File

@ -71,9 +71,6 @@
if (options.page) { if (options.page) {
sheep.$router.go(decodeURIComponent(options.page)); sheep.$router.go(decodeURIComponent(options.page));
} }
// TODO
sheep.$api.app.test();
}); });
// //

View File

@ -15,7 +15,7 @@
class="content-img" class="content-img"
isPreview isPreview
:current="0" :current="0"
:src="state.model.avatar" :src="state.model?.avatar"
:height="160" :height="160"
:width="160" :width="160"
:radius="80" :radius="80"
@ -57,7 +57,7 @@
:value="item.value" :value="item.value"
color="var(--ui-BG-Main)" color="var(--ui-BG-Main)"
style="transform: scale(0.8)" style="transform: scale(0.8)"
:checked="parseInt(item.value) === state.model.sex" :checked="parseInt(item.value) === state.model?.sex"
/> />
<view class="gender-name">{{ item.name }}</view> <view class="gender-name">{{ item.name }}</view>
</view> </view>
@ -90,7 +90,7 @@
<uni-forms-item name="password" label="登录密码" @tap="onSetPassword"> <uni-forms-item name="password" label="登录密码" @tap="onSetPassword">
<uni-easyinput <uni-easyinput
v-model="userInfo.password" v-model="userInfo.password"
:placeholder="userInfo.verification?.password ? '修改登录密码' : '点击设置登录密码'" placeholder="点击修改登录密码"
:inputBorder="false" :inputBorder="false"
:styles="{ disableColor: '#fff' }" :styles="{ disableColor: '#fff' }"
disabled disabled
@ -105,7 +105,7 @@
:modelValue="true" :modelValue="true"
/> />
<button v-else class="ss-reset-button ss-flex ss-col-center ss-row-center"> <button v-else class="ss-reset-button ss-flex ss-col-center ss-row-center">
<text class="_icon-forward" style="color: #bbbbbb; font-size: 26rpx"></text> <text class="_icon-forward" style="color: #bbbbbb; font-size: 26rpx" />
</button> </button>
</view> </view>
</template> </template>
@ -245,13 +245,9 @@
state.model.avatar = data; state.model.avatar = data;
} }
// / TODO // TODO
function onSetPassword() { function onSetPassword() {
if (state.model.verification.password) {
showAuthModal('changePassword'); showAuthModal('changePassword');
} else {
showAuthModal('resetPassword');
}
} }
// TODO // TODO

View File

@ -1,19 +1,6 @@
import request from '@/sheep/request'; import request from '@/sheep/request';
import { baseUrl } from '@/sheep/config';
export default { export default {
// TODO 芋艿:测试
test: () =>
request({
url: '/app-api/promotion/decorate/list',
params: {
page: 1
},
custom: {
showError: false,
showLoading: false,
},
}),
// 系统初始化 // 系统初始化
init: (templateId) => init: (templateId) =>
request({ request({
@ -40,11 +27,15 @@ export default {
}, },
}), }),
// 发送短信 // 发送短信
sendSms: (data) => // TODO 芋艿:直接在 useModal 引入 AuthUtil 会报错,所以继续用这个 API
sendSms: (mobile, scene) =>
request({ request({
url: 'sendSms', url: '/app-api/member/auth/send-sms-code',
method: 'POST', method: 'POST',
data, data: {
mobile,
scene
},
custom: { custom: {
showSuccess: true, showSuccess: true,
loadingMsg: '发送中', loadingMsg: '发送中',

View File

@ -1,14 +1,25 @@
import request2 from '@/sheep/request2'; import request from '@/sheep/request2';
const AuthUtil = { const AuthUtil = {
// 发送手机验证码
sendSmsCode: (mobile, scene) => {
return request({
url: '/app-api/member/auth/send-sms-code',
method: 'POST',
data: {
mobile,
scene
}
});
},
// 登出系统 // 登出系统
logout: () => { logout: () => {
return request2({ return request({
url: '/app-api/member/auth/logout', url: '/app-api/member/auth/logout',
method: 'POST' method: 'POST'
}); });
}, },
}; };
export default AuthUtil; export default AuthUtil;

14
sheep/api/member/user.js Normal file
View File

@ -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;

View File

@ -43,7 +43,7 @@
type="number" type="number"
maxlength="4" maxlength="4"
:inputBorder="false" :inputBorder="false"
></uni-easyinput> />
</uni-forms-item> </uni-forms-item>
<uni-forms-item name="password" label="密码"> <uni-forms-item name="password" label="密码">
@ -69,10 +69,11 @@
</template> </template>
<script setup> <script setup>
import { computed, watch, ref, reactive, unref } from 'vue'; import { computed, ref, reactive, unref } from 'vue';
import sheep from '@/sheep'; import sheep from '@/sheep';
import { code, mobile, password } from '@/sheep/validate/form'; import { code, mobile, password } from '@/sheep/validate/form';
import { showAuthModal, closeAuthModal, getSmsCode, getSmsTimer } from '@/sheep/hooks/useModal'; import { showAuthModal, closeAuthModal, getSmsCode, getSmsTimer } from '@/sheep/hooks/useModal';
import UserApi from '@/sheep/api/member/user';
const resetPasswordRef = ref(null); const resetPasswordRef = ref(null);
const isLogin = computed(() => sheep.$store('user').isLogin); const isLogin = computed(() => sheep.$store('user').isLogin);
@ -81,9 +82,9 @@
const state = reactive({ const state = reactive({
isMobileEnd: false, // isMobileEnd: false, //
model: { model: {
mobile: '', // mobile: '', //
code: '', // code: '', //
password: '', // password: '', //
}, },
rules: { rules: {
code, code,
@ -92,20 +93,24 @@
}, },
}); });
// 4. //
const resetPasswordSubmit = async () => { const resetPasswordSubmit = async () => {
//
const validate = await unref(resetPasswordRef) const validate = await unref(resetPasswordRef)
.validate() .validate()
.catch((error) => { .catch((error) => {
console.log('error: ', error); console.log('error: ', error);
}); });
if (!validate) return; if (!validate) {
sheep.$api.user.resetPassword(state.model).then((res) => { return;
if (res.error === 0) {
sheep.$store('user').getInfo();
closeAuthModal();
} }
}); //
const { code } = await UserApi.resetUserPassword(state.model);
if (code !== 0) {
return;
}
//
showAuthModal('accountLogin')
}; };
</script> </script>

View File

@ -61,7 +61,6 @@ export function closeMenuTools() {
export function getSmsCode(event, mobile = '') { export function getSmsCode(event, mobile = '') {
const modalStore = $store('modal'); const modalStore = $store('modal');
const lastSendTimer = modalStore.lastTimer[event]; const lastSendTimer = modalStore.lastTimer[event];
if (typeof lastSendTimer === 'undefined') { if (typeof lastSendTimer === 'undefined') {
$helper.toast('短信发送事件错误'); $helper.toast('短信发送事件错误');
return; return;
@ -69,26 +68,28 @@ export function getSmsCode(event, mobile = '') {
const duration = dayjs().unix() - lastSendTimer; const duration = dayjs().unix() - lastSendTimer;
const canSend = duration >= 60; const canSend = duration >= 60;
if (!canSend) { if (!canSend) {
$helper.toast('请稍后再试'); $helper.toast('请稍后再试');
return; return;
} }
if (!test.mobile(mobile)) { if (!test.mobile(mobile)) {
$helper.toast('手机号码格式不正确'); $helper.toast('手机号码格式不正确');
return; return;
} }
// 发送验证码 + 更新上次发送验证码时间 // 发送验证码 + 更新上次发送验证码时间
$api.app.sendSms({ mobile, event }).then((res) => { let scene = -1;
if (res.error === 0) { switch (event) {
case 'resetPassword':
scene = 4;
}
$api.app.sendSms(mobile, scene).then((res) => {
if (res.code === 0) {
modalStore.$patch((state) => { modalStore.$patch((state) => {
state.lastTimer[event] = dayjs().unix(); state.lastTimer[event] = dayjs().unix();
}); });
} }
}); });
} }
// 获取短信验证码倒计时 -- 60秒 // 获取短信验证码倒计时 -- 60秒

View File

@ -115,7 +115,7 @@ http.interceptors.response.use(
} }
response.config.custom.showLoading && closeLoading(); response.config.custom.showLoading && closeLoading();
if (response.data.error !== 0) { if (response.data.error !== 0 && response.data.code !== 0) {
if (response.config.custom.showError) if (response.config.custom.showError)
uni.showToast({ uni.showToast({
title: response.data.msg || '服务器开小差啦,请稍后再试~', title: response.data.msg || '服务器开小差啦,请稍后再试~',