✨ 重置密码:接入完成
parent
46f3aa7255
commit
22fffcb029
|
@ -71,9 +71,6 @@
|
|||
if (options.page) {
|
||||
sheep.$router.go(decodeURIComponent(options.page));
|
||||
}
|
||||
|
||||
// TODO 芋艿:测试接口的调用
|
||||
sheep.$api.app.test();
|
||||
});
|
||||
|
||||
// 下拉刷新
|
||||
|
|
|
@ -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"
|
||||
/>
|
||||
<view class="gender-name">{{ item.name }}</view>
|
||||
</view>
|
||||
|
@ -90,7 +90,7 @@
|
|||
<uni-forms-item name="password" label="登录密码" @tap="onSetPassword">
|
||||
<uni-easyinput
|
||||
v-model="userInfo.password"
|
||||
:placeholder="userInfo.verification?.password ? '修改登录密码' : '点击设置登录密码'"
|
||||
placeholder="点击修改登录密码"
|
||||
:inputBorder="false"
|
||||
:styles="{ disableColor: '#fff' }"
|
||||
disabled
|
||||
|
@ -105,7 +105,7 @@
|
|||
:modelValue="true"
|
||||
/>
|
||||
<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>
|
||||
</view>
|
||||
</template>
|
||||
|
@ -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
|
||||
|
|
|
@ -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: '发送中',
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
|
@ -43,7 +43,7 @@
|
|||
type="number"
|
||||
maxlength="4"
|
||||
:inputBorder="false"
|
||||
></uni-easyinput>
|
||||
/>
|
||||
</uni-forms-item>
|
||||
|
||||
<uni-forms-item name="password" label="密码">
|
||||
|
@ -69,10 +69,11 @@
|
|||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, watch, ref, reactive, unref } from 'vue';
|
||||
import { computed, ref, reactive, unref } from 'vue';
|
||||
import sheep from '@/sheep';
|
||||
import { code, mobile, password } from '@/sheep/validate/form';
|
||||
import { showAuthModal, closeAuthModal, getSmsCode, getSmsTimer } from '@/sheep/hooks/useModal';
|
||||
import UserApi from '@/sheep/api/member/user';
|
||||
|
||||
const resetPasswordRef = ref(null);
|
||||
const isLogin = computed(() => sheep.$store('user').isLogin);
|
||||
|
@ -81,9 +82,9 @@
|
|||
const state = reactive({
|
||||
isMobileEnd: false, // 手机号输入完毕
|
||||
model: {
|
||||
mobile: '', //手机号
|
||||
code: '', //验证码
|
||||
password: '', //密码
|
||||
mobile: '', // 手机号
|
||||
code: '', // 验证码
|
||||
password: '', // 密码
|
||||
},
|
||||
rules: {
|
||||
code,
|
||||
|
@ -92,20 +93,24 @@
|
|||
},
|
||||
});
|
||||
|
||||
// 4.重置密码
|
||||
// 重置密码
|
||||
const resetPasswordSubmit = async () => {
|
||||
// 参数校验
|
||||
const validate = await unref(resetPasswordRef)
|
||||
.validate()
|
||||
.catch((error) => {
|
||||
console.log('error: ', error);
|
||||
});
|
||||
if (!validate) return;
|
||||
sheep.$api.user.resetPassword(state.model).then((res) => {
|
||||
if (res.error === 0) {
|
||||
sheep.$store('user').getInfo();
|
||||
closeAuthModal();
|
||||
}
|
||||
});
|
||||
if (!validate) {
|
||||
return;
|
||||
}
|
||||
// 发起请求
|
||||
const { code } = await UserApi.resetUserPassword(state.model);
|
||||
if (code !== 0) {
|
||||
return;
|
||||
}
|
||||
// 成功后,用户重新登录
|
||||
showAuthModal('accountLogin')
|
||||
};
|
||||
</script>
|
||||
|
||||
|
|
|
@ -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秒
|
||||
|
|
|
@ -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 || '服务器开小差啦,请稍后再试~',
|
||||
|
|
Loading…
Reference in New Issue