✨ 修改密码:接入完成
parent
2c7d89d711
commit
6941b869c7
|
|
@ -1,6 +1,19 @@
|
||||||
import request from '@/sheep/request2';
|
import request from '@/sheep/request2';
|
||||||
|
|
||||||
const UserApi = {
|
const UserApi = {
|
||||||
|
// 修改密码
|
||||||
|
updateUserPassword: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/app-api/member/user/update-password',
|
||||||
|
method: 'PUT',
|
||||||
|
data,
|
||||||
|
custom: {
|
||||||
|
loadingMsg: '验证中',
|
||||||
|
showSuccess: true,
|
||||||
|
successMsg: '修改成功'
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
// 重置密码
|
// 重置密码
|
||||||
resetUserPassword: (data) => {
|
resetUserPassword: (data) => {
|
||||||
return request({
|
return request({
|
||||||
|
|
|
||||||
|
|
@ -93,18 +93,6 @@ export default {
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// 修改密码
|
|
||||||
changePassword: (data) =>
|
|
||||||
request({
|
|
||||||
url: '/user/api/user/changePassword',
|
|
||||||
method: 'POST',
|
|
||||||
data,
|
|
||||||
custom: {
|
|
||||||
showSuccess: true,
|
|
||||||
loadingMsg: '验证中',
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
|
|
||||||
// 绑定、更换手机号
|
// 绑定、更换手机号
|
||||||
changeMobile: (data) =>
|
changeMobile: (data) =>
|
||||||
request({
|
request({
|
||||||
|
|
@ -117,18 +105,6 @@ export default {
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// 修改用户名
|
|
||||||
changeUsername: (data) =>
|
|
||||||
request({
|
|
||||||
url: '/user/api/user/changeUsername',
|
|
||||||
method: 'POST',
|
|
||||||
data,
|
|
||||||
custom: {
|
|
||||||
showSuccess: true,
|
|
||||||
loadingMsg: '验证中',
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
|
|
||||||
// 更新小程序信息
|
// 更新小程序信息
|
||||||
updateMpUserInfo: (data) =>
|
updateMpUserInfo: (data) =>
|
||||||
request({
|
request({
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<!-- 修改密码 - changePassword -->
|
<!-- 修改密码(登录时) -->
|
||||||
<template>
|
<template>
|
||||||
<view>
|
<view>
|
||||||
<!-- 标题栏 -->
|
<!-- 标题栏 -->
|
||||||
|
|
@ -16,29 +16,32 @@
|
||||||
labelWidth="140"
|
labelWidth="140"
|
||||||
labelAlign="center"
|
labelAlign="center"
|
||||||
>
|
>
|
||||||
<uni-forms-item name="oldPassword" label="旧密码">
|
<uni-forms-item name="code" label="验证码">
|
||||||
<uni-easyinput
|
<uni-easyinput
|
||||||
placeholder="请输入旧密码"
|
placeholder="请输入验证码"
|
||||||
v-model="state.model.oldPassword"
|
v-model="state.model.code"
|
||||||
type="text"
|
type="number"
|
||||||
|
maxlength="4"
|
||||||
:inputBorder="false"
|
:inputBorder="false"
|
||||||
/>
|
>
|
||||||
|
<template v-slot:right>
|
||||||
|
<button
|
||||||
|
class="ss-reset-button code-btn code-btn-start"
|
||||||
|
:disabled="state.isMobileEnd"
|
||||||
|
:class="{ 'code-btn-end': state.isMobileEnd }"
|
||||||
|
@tap="getSmsCode('changePassword')"
|
||||||
|
>
|
||||||
|
{{ getSmsTimer('resetPassword') }}
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
</uni-easyinput>
|
||||||
</uni-forms-item>
|
</uni-forms-item>
|
||||||
|
|
||||||
<uni-forms-item name="newPassword" label="新密码">
|
<uni-forms-item name="reNewPassword" label="密码">
|
||||||
<uni-easyinput
|
<uni-easyinput
|
||||||
type="password"
|
type="password"
|
||||||
placeholder="请输入新密码"
|
placeholder="请输入密码"
|
||||||
v-model="state.model.newPassword"
|
v-model="state.model.password"
|
||||||
:inputBorder="false"
|
|
||||||
/>
|
|
||||||
</uni-forms-item>
|
|
||||||
|
|
||||||
<uni-forms-item name="reNewPassword" label="确认密码">
|
|
||||||
<uni-easyinput
|
|
||||||
type="password"
|
|
||||||
placeholder="请重新输入您的新密码"
|
|
||||||
v-model="state.model.reNewPassword"
|
|
||||||
:inputBorder="false"
|
:inputBorder="false"
|
||||||
>
|
>
|
||||||
<template v-slot:right>
|
<template v-slot:right>
|
||||||
|
|
@ -50,69 +53,51 @@
|
||||||
</uni-forms-item>
|
</uni-forms-item>
|
||||||
</uni-forms>
|
</uni-forms>
|
||||||
|
|
||||||
<view class="editPwd-btn-box ss-m-t-80">
|
<button class="ss-reset-button type-btn" @tap="closeAuthModal">
|
||||||
<button class="ss-reset-button forgot-btn" @tap="showAuthModal('resetPassword')">
|
取消修改
|
||||||
忘记密码
|
|
||||||
</button>
|
</button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { computed, watch, ref, reactive, unref } from 'vue';
|
import { ref, reactive, unref } from 'vue';
|
||||||
import sheep from '@/sheep';
|
import { code, password } from '@/sheep/validate/form';
|
||||||
import { password } from '@/sheep/validate/form';
|
import { closeAuthModal, getSmsCode, getSmsTimer } from '@/sheep/hooks/useModal';
|
||||||
import { showAuthModal, closeAuthModal } from '@/sheep/hooks/useModal';
|
import UserApi from '@/sheep/api/member/user';
|
||||||
|
|
||||||
const changePasswordRef = ref(null);
|
const changePasswordRef = ref(null);
|
||||||
|
|
||||||
// 数据
|
// 数据
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
isMobileEnd: false, // 手机号输入完毕
|
|
||||||
model: {
|
model: {
|
||||||
oldPassword: '', //旧密码
|
mobile: '', // 手机号
|
||||||
newPassword: '', //新密码
|
code: '', // 验证码
|
||||||
reNewPassword: '', //确认密码
|
password: '', // 密码
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
oldPassword: password,
|
code,
|
||||||
newPassword: password,
|
password,
|
||||||
reNewPassword: {
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
errorMessage: '请确认密码',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
validateFunction: function (rule, value, data, callback) {
|
|
||||||
if (value !== state.model.newPassword) {
|
|
||||||
callback('两次输入的密码不一致');
|
|
||||||
}
|
|
||||||
if (value === state.model.oldPassword) {
|
|
||||||
callback('新密码不能与旧密码相同');
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// 6.更改密码
|
// 更改密码
|
||||||
async function changePasswordSubmit() {
|
async function changePasswordSubmit() {
|
||||||
|
// 参数校验
|
||||||
const validate = await unref(changePasswordRef)
|
const validate = await unref(changePasswordRef)
|
||||||
.validate()
|
.validate()
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log('error: ', error);
|
console.log('error: ', error);
|
||||||
});
|
});
|
||||||
if (!validate) return;
|
if (!validate) {
|
||||||
sheep.$api.user.changePassword(state.model).then((res) => {
|
return;
|
||||||
if (res.error === 0) {
|
|
||||||
sheep.$store('user').getInfo();
|
|
||||||
closeAuthModal();
|
|
||||||
}
|
}
|
||||||
});
|
// 发起请求
|
||||||
|
const { code } = await UserApi.updateUserPassword(state.model);
|
||||||
|
if (code !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 成功后,只需要关闭弹窗
|
||||||
|
closeAuthModal();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<!-- 重置密码 - resetPassword-- -->
|
<!-- 重置密码(未登录时) -->
|
||||||
<template>
|
<template>
|
||||||
<view>
|
<view>
|
||||||
<!-- 标题栏 -->
|
<!-- 标题栏 -->
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ export function closeMenuTools() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发送短信验证码 60秒
|
// 发送短信验证码 60秒
|
||||||
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') {
|
||||||
|
|
@ -72,7 +72,8 @@ export function getSmsCode(event, mobile = '') {
|
||||||
$helper.toast('请稍后再试');
|
$helper.toast('请稍后再试');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!test.mobile(mobile)) {
|
// 只有 mobile 非空时才校验。因为部分场景(修改密码),不需要输入手机
|
||||||
|
if (mobile && !test.mobile(mobile)) {
|
||||||
$helper.toast('手机号码格式不正确');
|
$helper.toast('手机号码格式不正确');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -82,6 +83,10 @@ export function getSmsCode(event, mobile = '') {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case 'resetPassword':
|
case 'resetPassword':
|
||||||
scene = 4;
|
scene = 4;
|
||||||
|
break;
|
||||||
|
case 'changePassword':
|
||||||
|
scene = 3;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
$api.AuthUtil.sendSmsCode(mobile, scene).then((res) => {
|
$api.AuthUtil.sendSmsCode(mobile, scene).then((res) => {
|
||||||
if (res.code === 0) {
|
if (res.code === 0) {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ const modal = defineStore({
|
||||||
smsRegister: 0,
|
smsRegister: 0,
|
||||||
changeMobile: 0,
|
changeMobile: 0,
|
||||||
resetPassword: 0,
|
resetPassword: 0,
|
||||||
|
changePassword: 0,
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
persist: {
|
persist: {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue