修改用户密码.
This commit is contained in:
@@ -63,4 +63,6 @@ public interface ErrorMessage {
|
|||||||
|
|
||||||
String PASSWORD_MISSING = "请输入密码";
|
String PASSWORD_MISSING = "请输入密码";
|
||||||
|
|
||||||
|
String BEFORE_PASSWORD_ERROR = "原密码错误";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ import com.orion.lang.define.wrapper.HttpWrapper;
|
|||||||
import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
|
import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
|
||||||
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
|
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
|
||||||
import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
|
import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
|
||||||
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
|
||||||
import com.orion.ops.framework.web.core.annotation.RestWrapper;
|
import com.orion.ops.framework.web.core.annotation.RestWrapper;
|
||||||
import com.orion.ops.module.infra.define.operator.AuthenticationOperatorType;
|
import com.orion.ops.module.infra.define.operator.AuthenticationOperatorType;
|
||||||
import com.orion.ops.module.infra.entity.request.user.UserLoginRequest;
|
import com.orion.ops.module.infra.entity.request.user.UserLoginRequest;
|
||||||
import com.orion.ops.module.infra.entity.request.user.UserResetPasswordRequest;
|
import com.orion.ops.module.infra.entity.request.user.UserUpdatePasswordRequest;
|
||||||
import com.orion.ops.module.infra.entity.vo.UserLoginVO;
|
import com.orion.ops.module.infra.entity.vo.UserLoginVO;
|
||||||
import com.orion.ops.module.infra.service.AuthenticationService;
|
import com.orion.ops.module.infra.service.AuthenticationService;
|
||||||
import com.orion.ops.module.infra.service.SystemUserService;
|
import com.orion.ops.module.infra.service.SystemUserService;
|
||||||
@@ -66,10 +65,8 @@ public class AuthenticationController {
|
|||||||
@OperatorLog(AuthenticationOperatorType.UPDATE_PASSWORD)
|
@OperatorLog(AuthenticationOperatorType.UPDATE_PASSWORD)
|
||||||
@Operation(summary = "修改密码")
|
@Operation(summary = "修改密码")
|
||||||
@PutMapping("/update-password")
|
@PutMapping("/update-password")
|
||||||
public HttpWrapper<?> updatePassword(@Validated @RequestBody UserResetPasswordRequest request) {
|
public HttpWrapper<?> updatePassword(@Validated @RequestBody UserUpdatePasswordRequest request) {
|
||||||
// 当前用户id
|
authenticationService.updatePassword(request);
|
||||||
request.setId(SecurityUtils.getLoginUserId());
|
|
||||||
systemUserService.resetPassword(request);
|
|
||||||
return HttpWrapper.ok();
|
return HttpWrapper.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重置密码请求
|
* 重置密码请求
|
||||||
@@ -16,6 +17,7 @@ import javax.validation.constraints.NotEmpty;
|
|||||||
@Schema(name = "UserResetPasswordRequest", description = "重置密码请求")
|
@Schema(name = "UserResetPasswordRequest", description = "重置密码请求")
|
||||||
public class UserResetPasswordRequest {
|
public class UserResetPasswordRequest {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Schema(description = "id")
|
@Schema(description = "id")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.orion.ops.module.infra.entity.request.user;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改密码请求
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023/7/17 12:19
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Schema(name = "UserUpdatePasswordRequest", description = "修改密码请求")
|
||||||
|
public class UserUpdatePasswordRequest {
|
||||||
|
|
||||||
|
@NotEmpty
|
||||||
|
@Schema(description = "原密码")
|
||||||
|
private String beforePassword;
|
||||||
|
|
||||||
|
@NotEmpty
|
||||||
|
@Schema(description = "新密码")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package com.orion.ops.module.infra.service;
|
|||||||
import com.orion.ops.framework.common.security.LoginUser;
|
import com.orion.ops.framework.common.security.LoginUser;
|
||||||
import com.orion.ops.module.infra.entity.dto.LoginTokenDTO;
|
import com.orion.ops.module.infra.entity.dto.LoginTokenDTO;
|
||||||
import com.orion.ops.module.infra.entity.request.user.UserLoginRequest;
|
import com.orion.ops.module.infra.entity.request.user.UserLoginRequest;
|
||||||
|
import com.orion.ops.module.infra.entity.request.user.UserUpdatePasswordRequest;
|
||||||
import com.orion.ops.module.infra.entity.vo.UserLoginVO;
|
import com.orion.ops.module.infra.entity.vo.UserLoginVO;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -42,6 +43,13 @@ public interface AuthenticationService {
|
|||||||
*/
|
*/
|
||||||
void logout(HttpServletRequest servletRequest);
|
void logout(HttpServletRequest servletRequest);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改密码
|
||||||
|
*
|
||||||
|
* @param request request
|
||||||
|
*/
|
||||||
|
void updatePassword(UserUpdatePasswordRequest request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取登陆用户信息
|
* 获取登陆用户信息
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public interface SystemUserService {
|
|||||||
/**
|
/**
|
||||||
* 删除 id 删除用户拓展信息
|
* 删除 id 删除用户拓展信息
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id id
|
||||||
*/
|
*/
|
||||||
void deleteSystemUserRel(Long id);
|
void deleteSystemUserRel(Long id);
|
||||||
|
|
||||||
|
|||||||
@@ -24,11 +24,14 @@ import com.orion.ops.module.infra.entity.domain.SystemRoleDO;
|
|||||||
import com.orion.ops.module.infra.entity.domain.SystemUserDO;
|
import com.orion.ops.module.infra.entity.domain.SystemUserDO;
|
||||||
import com.orion.ops.module.infra.entity.dto.LoginTokenDTO;
|
import com.orion.ops.module.infra.entity.dto.LoginTokenDTO;
|
||||||
import com.orion.ops.module.infra.entity.request.user.UserLoginRequest;
|
import com.orion.ops.module.infra.entity.request.user.UserLoginRequest;
|
||||||
|
import com.orion.ops.module.infra.entity.request.user.UserResetPasswordRequest;
|
||||||
|
import com.orion.ops.module.infra.entity.request.user.UserUpdatePasswordRequest;
|
||||||
import com.orion.ops.module.infra.entity.vo.UserLoginVO;
|
import com.orion.ops.module.infra.entity.vo.UserLoginVO;
|
||||||
import com.orion.ops.module.infra.enums.LoginTokenStatusEnum;
|
import com.orion.ops.module.infra.enums.LoginTokenStatusEnum;
|
||||||
import com.orion.ops.module.infra.enums.UserStatusEnum;
|
import com.orion.ops.module.infra.enums.UserStatusEnum;
|
||||||
import com.orion.ops.module.infra.service.AuthenticationService;
|
import com.orion.ops.module.infra.service.AuthenticationService;
|
||||||
import com.orion.ops.module.infra.service.PermissionService;
|
import com.orion.ops.module.infra.service.PermissionService;
|
||||||
|
import com.orion.ops.module.infra.service.SystemUserService;
|
||||||
import com.orion.web.servlet.web.Servlets;
|
import com.orion.web.servlet.web.Servlets;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -57,6 +60,9 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
|||||||
@Resource
|
@Resource
|
||||||
private SystemUserRoleDAO systemUserRoleDAO;
|
private SystemUserRoleDAO systemUserRoleDAO;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SystemUserService systemUserService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private PermissionService permissionService;
|
private PermissionService permissionService;
|
||||||
|
|
||||||
@@ -120,6 +126,22 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
|||||||
redisTemplate.delete(Lists.of(loginKey, refreshKey));
|
redisTemplate.delete(Lists.of(loginKey, refreshKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePassword(UserUpdatePasswordRequest request) {
|
||||||
|
Long userId = SecurityUtils.getLoginUserId();
|
||||||
|
// 查询用户信息
|
||||||
|
SystemUserDO record = systemUserDAO.selectById(userId);
|
||||||
|
Valid.notNull(record, ErrorMessage.USER_ABSENT);
|
||||||
|
// 对比原始密码
|
||||||
|
String beforePassword = Signatures.md5(request.getBeforePassword());
|
||||||
|
Valid.eq(beforePassword, record.getPassword(), ErrorMessage.BEFORE_PASSWORD_ERROR);
|
||||||
|
// 重置密码
|
||||||
|
UserResetPasswordRequest reset = new UserResetPasswordRequest();
|
||||||
|
reset.setId(userId);
|
||||||
|
reset.setPassword(request.getPassword());
|
||||||
|
systemUserService.resetPassword(reset);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LoginUser getLoginUser(Long id) {
|
public LoginUser getLoginUser(Long id) {
|
||||||
String userInfoKey = UserCacheKeyDefine.USER_INFO.format(id);
|
String userInfoKey = UserCacheKeyDefine.USER_INFO.format(id);
|
||||||
|
|||||||
@@ -15,6 +15,14 @@ export interface LoginResponse {
|
|||||||
token: string;
|
token: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改密码请求
|
||||||
|
*/
|
||||||
|
export interface UserUpdatePasswordRequest {
|
||||||
|
beforePassword?: string;
|
||||||
|
password?: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登陆
|
* 登陆
|
||||||
*/
|
*/
|
||||||
@@ -29,6 +37,13 @@ export function logout() {
|
|||||||
return axios.get('/infra/auth/logout');
|
return axios.get('/infra/auth/logout');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改密码
|
||||||
|
*/
|
||||||
|
export function updatePassword(request: UserUpdatePasswordRequest) {
|
||||||
|
return axios.put('/infra/auth/update-password', request);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户信息
|
* 获取用户信息
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -38,15 +38,15 @@
|
|||||||
<a-tooltip content="语言">
|
<a-tooltip content="语言">
|
||||||
<a-button class="nav-btn"
|
<a-button class="nav-btn"
|
||||||
type="outline"
|
type="outline"
|
||||||
:shape="'circle'"
|
shape="circle"
|
||||||
@click="setUserInfoVisible">
|
@click="setLocalesVisible">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<icon-language />
|
<icon-language />
|
||||||
</template>
|
</template>
|
||||||
</a-button>
|
</a-button>
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
<a-dropdown trigger="click" @select="changeLocale">
|
<a-dropdown trigger="click" @select="changeLocale">
|
||||||
<div ref="refUserInfoTrigger" class="trigger-btn" />
|
<div ref="localeRef" class="trigger-btn" />
|
||||||
<template #content>
|
<template #content>
|
||||||
<a-doption v-for="item in locales"
|
<a-doption v-for="item in locales"
|
||||||
:key="item.value"
|
:key="item.value"
|
||||||
@@ -66,7 +66,7 @@
|
|||||||
: '点击切换为亮色模式'">
|
: '点击切换为亮色模式'">
|
||||||
<a-button class="nav-btn"
|
<a-button class="nav-btn"
|
||||||
type="outline"
|
type="outline"
|
||||||
:shape="'circle'"
|
shape="circle"
|
||||||
@click="handleToggleTheme">
|
@click="handleToggleTheme">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<icon-moon-fill v-if="theme === 'dark'" />
|
<icon-moon-fill v-if="theme === 'dark'" />
|
||||||
@@ -82,7 +82,7 @@
|
|||||||
<a-badge :count="9" dot>
|
<a-badge :count="9" dot>
|
||||||
<a-button class="nav-btn"
|
<a-button class="nav-btn"
|
||||||
type="outline"
|
type="outline"
|
||||||
:shape="'circle'"
|
shape="circle"
|
||||||
@click="setMessageBoxVisible">
|
@click="setMessageBoxVisible">
|
||||||
<icon-notification />
|
<icon-notification />
|
||||||
</a-button>
|
</a-button>
|
||||||
@@ -93,7 +93,7 @@
|
|||||||
:arrow-style="{ display: 'none' }"
|
:arrow-style="{ display: 'none' }"
|
||||||
:content-style="{ padding: 0, minWidth: '400px' }"
|
:content-style="{ padding: 0, minWidth: '400px' }"
|
||||||
content-class="message-popover">
|
content-class="message-popover">
|
||||||
<div ref="refMessageBoxTrigger" class="ref-btn" />
|
<div ref="messageRef" class="ref-btn" />
|
||||||
<template #content>
|
<template #content>
|
||||||
<message-box />
|
<message-box />
|
||||||
</template>
|
</template>
|
||||||
@@ -161,7 +161,7 @@
|
|||||||
</a-doption>
|
</a-doption>
|
||||||
<!-- 修改密码 -->
|
<!-- 修改密码 -->
|
||||||
<a-doption>
|
<a-doption>
|
||||||
<a-space @click="$router.push({ name: 'userMine' })">
|
<a-space @click="() => updatePasswordRef.open()">
|
||||||
<icon-lock />
|
<icon-lock />
|
||||||
<span>修改密码</span>
|
<span>修改密码</span>
|
||||||
</a-space>
|
</a-space>
|
||||||
@@ -177,6 +177,8 @@
|
|||||||
</a-dropdown>
|
</a-dropdown>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<!-- 修改密码模态框-->
|
||||||
|
<update-password-modal ref="updatePasswordRef" @updated="handleLogout" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -192,25 +194,14 @@
|
|||||||
import MessageBox from '@/components/system/message-box/index.vue';
|
import MessageBox from '@/components/system/message-box/index.vue';
|
||||||
import { openAppSettingKey, toggleDrawerMenuKey } from '@/types/symbol';
|
import { openAppSettingKey, toggleDrawerMenuKey } from '@/types/symbol';
|
||||||
import { preferenceTipsKey } from './const';
|
import { preferenceTipsKey } from './const';
|
||||||
|
import UpdatePasswordModal from '@/components/user/role/update-password-modal.vue';
|
||||||
|
|
||||||
const tipsStore = useTipsStore();
|
const tipsStore = useTipsStore();
|
||||||
const tippedPreference = ref(tipsStore.isNotTipped(preferenceTipsKey));
|
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const { logout } = useUser();
|
const { logout } = useUser();
|
||||||
const { changeLocale, currentLocale } = useLocale();
|
const { changeLocale, currentLocale } = useLocale();
|
||||||
const { isFullscreen, toggle: toggleFullScreen } = useFullscreen();
|
const { isFullscreen, toggle: toggleFullScreen } = useFullscreen();
|
||||||
const locales = [...LOCALE_OPTIONS];
|
|
||||||
const nickname = computed(() => {
|
|
||||||
return userStore.nickname?.substring(0, 1);
|
|
||||||
});
|
|
||||||
const topMenu = computed(() => appStore.topMenu && appStore.menu);
|
|
||||||
|
|
||||||
// 当前主题
|
|
||||||
const theme = computed(() => {
|
|
||||||
return appStore.theme;
|
|
||||||
});
|
|
||||||
|
|
||||||
// 主题
|
// 主题
|
||||||
const darkTheme = useDark({
|
const darkTheme = useDark({
|
||||||
selector: 'body',
|
selector: 'body',
|
||||||
@@ -225,24 +216,42 @@
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 用户名
|
||||||
|
const nickname = computed(() => userStore.nickname?.substring(0, 1));
|
||||||
|
// 是否展示顶部菜单
|
||||||
|
const topMenu = computed(() => appStore.topMenu && appStore.menu);
|
||||||
|
// 当前主题
|
||||||
|
const theme = computed(() => appStore.theme);
|
||||||
|
|
||||||
|
const locales = [...LOCALE_OPTIONS];
|
||||||
|
// 偏好提示
|
||||||
|
const tippedPreference = ref(tipsStore.isNotTipped(preferenceTipsKey));
|
||||||
|
// 修改密码
|
||||||
|
const updatePasswordRef = ref();
|
||||||
|
// 消息
|
||||||
|
const messageRef = ref();
|
||||||
|
// 语言
|
||||||
|
const localeRef = ref();
|
||||||
|
|
||||||
|
// 打开应用设置
|
||||||
|
const openAppSetting = inject(openAppSettingKey) as () => void;
|
||||||
|
|
||||||
|
// 注入收缩菜单
|
||||||
|
const toggleDrawerMenu = inject(toggleDrawerMenuKey) as () => void;
|
||||||
|
|
||||||
// 切换主题
|
// 切换主题
|
||||||
const handleToggleTheme = () => {
|
const handleToggleTheme = () => {
|
||||||
useToggle(darkTheme)();
|
useToggle(darkTheme)();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 打开应用设置
|
// 打开消息
|
||||||
const openAppSetting = inject(openAppSettingKey) as () => void;
|
|
||||||
|
|
||||||
// 消息触发器 ref
|
|
||||||
const refMessageBoxTrigger = ref();
|
|
||||||
const setMessageBoxVisible = () => {
|
const setMessageBoxVisible = () => {
|
||||||
triggerMouseEvent(refMessageBoxTrigger);
|
triggerMouseEvent(messageRef);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 个人信息触发器 ref
|
// 打开语言切换
|
||||||
const refUserInfoTrigger = ref();
|
const setLocalesVisible = () => {
|
||||||
const setUserInfoVisible = () => {
|
triggerMouseEvent(localeRef);
|
||||||
triggerMouseEvent(refUserInfoTrigger);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 退出登录
|
// 退出登录
|
||||||
@@ -250,9 +259,6 @@
|
|||||||
logout();
|
logout();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 注入收缩菜单
|
|
||||||
const toggleDrawerMenu = inject(toggleDrawerMenuKey) as () => void;
|
|
||||||
|
|
||||||
// 关闭偏好提示
|
// 关闭偏好提示
|
||||||
const closePreferenceTip = (ack: boolean) => {
|
const closePreferenceTip = (ack: boolean) => {
|
||||||
tippedPreference.value = false;
|
tippedPreference.value = false;
|
||||||
|
|||||||
@@ -80,10 +80,11 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { TableColumnData } from '@arco-design/web-vue/es/table/interface';
|
import type { TableColumnData } from '@arco-design/web-vue/es/table/interface';
|
||||||
|
import type { HistoryValueQueryRequest, HistoryValueQueryResponse } from '@/api/meta/history-value';
|
||||||
import { reactive, ref } from 'vue';
|
import { reactive, ref } from 'vue';
|
||||||
import useLoading from '@/hooks/loading';
|
import useLoading from '@/hooks/loading';
|
||||||
import useVisible from '@/hooks/visible';
|
import useVisible from '@/hooks/visible';
|
||||||
import { getHistoryValuePage, HistoryValueQueryRequest, HistoryValueQueryResponse } from '@/api/meta/history-value';
|
import { getHistoryValuePage } from '@/api/meta/history-value';
|
||||||
import { usePagination } from '@/types/table';
|
import { usePagination } from '@/types/table';
|
||||||
import useCopy from '@/hooks/copy';
|
import useCopy from '@/hooks/copy';
|
||||||
import { dateFormat } from '@/utils';
|
import { dateFormat } from '@/utils';
|
||||||
|
|||||||
135
orion-ops-ui/src/components/user/role/update-password-modal.vue
Normal file
135
orion-ops-ui/src/components/user/role/update-password-modal.vue
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
<template>
|
||||||
|
<a-modal v-model:visible="visible"
|
||||||
|
body-class="modal-form"
|
||||||
|
title-align="start"
|
||||||
|
title="重置密码"
|
||||||
|
:top="120"
|
||||||
|
:align-center="false"
|
||||||
|
:draggable="true"
|
||||||
|
:mask-closable="false"
|
||||||
|
:unmount-on-close="true"
|
||||||
|
:ok-button-props="{ disabled: loading }"
|
||||||
|
:cancel-button-props="{ disabled: loading }"
|
||||||
|
:on-before-ok="handlerOk"
|
||||||
|
@close="handleClose">
|
||||||
|
<a-spin :loading="loading">
|
||||||
|
<a-form :model="formModel"
|
||||||
|
ref="formRef"
|
||||||
|
label-align="right"
|
||||||
|
:rules="rules"
|
||||||
|
:style="{ width: '460px' }"
|
||||||
|
:label-col-props="{ span: 6 }"
|
||||||
|
:wrapper-col-props="{ span: 18 }">
|
||||||
|
<!-- 密码 -->
|
||||||
|
<a-form-item field="beforePassword" label="原始密码">
|
||||||
|
<a-input-password v-model="formModel.beforePassword" placeholder="请输入原始密码" />
|
||||||
|
</a-form-item>
|
||||||
|
<!-- 密码 -->
|
||||||
|
<a-form-item field="password" label="新密码">
|
||||||
|
<a-input-password v-model="formModel.password" placeholder="请输入新密码" />
|
||||||
|
</a-form-item>
|
||||||
|
</a-form>
|
||||||
|
</a-spin>
|
||||||
|
</a-modal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
export default {
|
||||||
|
name: 'update-password-modal'
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { UserUpdatePasswordRequest } from '@/api/user/auth';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import useLoading from '@/hooks/loading';
|
||||||
|
import useVisible from '@/hooks/visible';
|
||||||
|
import { Message } from '@arco-design/web-vue';
|
||||||
|
import { md5 } from '@/utils';
|
||||||
|
import { updatePassword } from '@/api/user/auth';
|
||||||
|
|
||||||
|
const emits = defineEmits(['updated']);
|
||||||
|
|
||||||
|
const { visible, setVisible } = useVisible();
|
||||||
|
const { loading, setLoading } = useLoading();
|
||||||
|
|
||||||
|
const rules = {
|
||||||
|
beforePassword: [{
|
||||||
|
required: true,
|
||||||
|
message: '请输入原始密码'
|
||||||
|
}],
|
||||||
|
password: [{
|
||||||
|
required: true,
|
||||||
|
message: '请输入新密码'
|
||||||
|
}, {
|
||||||
|
minLength: 8,
|
||||||
|
maxLength: 32,
|
||||||
|
message: '新密码长度需要在 8-32 位之间'
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
|
||||||
|
const formRef = ref();
|
||||||
|
const formModel = ref<UserUpdatePasswordRequest>({});
|
||||||
|
|
||||||
|
// 打开
|
||||||
|
const open = () => {
|
||||||
|
formModel.value = {
|
||||||
|
beforePassword: undefined,
|
||||||
|
password: undefined
|
||||||
|
};
|
||||||
|
setVisible(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
defineExpose({ open });
|
||||||
|
|
||||||
|
// 确定
|
||||||
|
const handlerOk = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
// 验证参数
|
||||||
|
const error = await formRef.value.validate();
|
||||||
|
if (error) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 相同校验
|
||||||
|
if (formModel.value.beforePassword === formModel.value.password) {
|
||||||
|
formRef.value.setFields({
|
||||||
|
password: {
|
||||||
|
status: 'error',
|
||||||
|
message: '新密码不能和原始密码相同'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 修改
|
||||||
|
await updatePassword({
|
||||||
|
beforePassword: md5(formModel.value.beforePassword as string),
|
||||||
|
password: md5(formModel.value.password as string)
|
||||||
|
});
|
||||||
|
Message.success('修改成功');
|
||||||
|
// 清空
|
||||||
|
handlerClear();
|
||||||
|
emits('updated');
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 关闭
|
||||||
|
const handleClose = () => {
|
||||||
|
handlerClear();
|
||||||
|
};
|
||||||
|
|
||||||
|
// 清空
|
||||||
|
const handlerClear = () => {
|
||||||
|
setLoading(false);
|
||||||
|
setVisible(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped>
|
||||||
|
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user