完善店务员工默认密码提示
This commit is contained in:
+12
-1
@@ -90,12 +90,23 @@ public class SystemParameterConfigController {
|
||||
@RequirePermission("user:create")
|
||||
public Result<Map<String, String>> getUserDefaultPassword(HttpServletRequest request) {
|
||||
adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(buildUserDefaultPasswordResult());
|
||||
}
|
||||
|
||||
@GetMapping("/admin/user-default-password/reset")
|
||||
@RequirePermission("user:reset_password")
|
||||
public Result<Map<String, String>> getUserDefaultPasswordForReset(HttpServletRequest request) {
|
||||
adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(buildUserDefaultPasswordResult());
|
||||
}
|
||||
|
||||
private Map<String, String> buildUserDefaultPasswordResult() {
|
||||
Map<String, String> result = new HashMap<>();
|
||||
String configuredDefaultPassword = configService.getEnabledValue(
|
||||
AdminDefaultPasswordSupport.CONFIG_GROUP,
|
||||
AdminDefaultPasswordSupport.CONFIG_KEY
|
||||
);
|
||||
result.put("password", AdminDefaultPasswordSupport.resolveDefaultPassword(configuredDefaultPassword));
|
||||
return Result.success(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@ import type {
|
||||
EmployeeCreateRequest
|
||||
} from '@/types/manager'
|
||||
|
||||
export interface ManagerDefaultPasswordResponse {
|
||||
password: string
|
||||
}
|
||||
|
||||
export const managerEmployeesApi = {
|
||||
list(): Promise<Artist[]> {
|
||||
return adminApi.get('/manager/employees')
|
||||
@@ -25,6 +29,12 @@ export const managerEmployeesApi = {
|
||||
createUser(data: EmployeeCreateRequest): Promise<IdType> {
|
||||
return adminApi.post('/manager/employees/users', data)
|
||||
},
|
||||
getCreateDefaultPassword(): Promise<ManagerDefaultPasswordResponse> {
|
||||
return adminApi.get('/system-parameter-config/admin/user-default-password')
|
||||
},
|
||||
getResetDefaultPassword(): Promise<ManagerDefaultPasswordResponse> {
|
||||
return adminApi.get('/system-parameter-config/admin/user-default-password/reset')
|
||||
},
|
||||
deleteUser(userId: IdType): Promise<boolean> {
|
||||
return adminApi.delete(`/manager/employees/${userId}`)
|
||||
},
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
<template>
|
||||
<BaseModal :model-value="modelValue" :title="title" @update:model-value="updateModelValue">
|
||||
<div class="default-password-notice">
|
||||
<p>{{ message }}</p>
|
||||
<div class="default-password-notice__value">{{ password }}</div>
|
||||
<button class="primary-btn default-password-notice__copy" type="button" @click="copyPassword">
|
||||
<Copy :size="16" aria-hidden="true" />
|
||||
<span>一键复制密码</span>
|
||||
</button>
|
||||
<button class="secondary-btn" type="button" @click="close">我知道了</button>
|
||||
</div>
|
||||
</BaseModal>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { Copy } from 'lucide-vue-next'
|
||||
import BaseModal from '@/components/BaseModal.vue'
|
||||
import { useToastStore } from '@/stores/toast'
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: boolean
|
||||
title: string
|
||||
message: string
|
||||
password: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: boolean]
|
||||
}>()
|
||||
|
||||
const toast = useToastStore()
|
||||
|
||||
const updateModelValue = (value: boolean): void => {
|
||||
emit('update:modelValue', value)
|
||||
}
|
||||
|
||||
const close = (): void => {
|
||||
emit('update:modelValue', false)
|
||||
}
|
||||
|
||||
const copyWithTextarea = (value: string): void => {
|
||||
const textarea = document.createElement('textarea')
|
||||
textarea.value = value
|
||||
textarea.setAttribute('readonly', 'readonly')
|
||||
textarea.style.position = 'fixed'
|
||||
textarea.style.left = '-9999px'
|
||||
document.body.appendChild(textarea)
|
||||
textarea.select()
|
||||
const copied = document.execCommand('copy')
|
||||
document.body.removeChild(textarea)
|
||||
if (!copied) {
|
||||
throw new Error('浏览器拒绝复制')
|
||||
}
|
||||
}
|
||||
|
||||
const copyPassword = async (): Promise<void> => {
|
||||
try {
|
||||
if (navigator.clipboard?.writeText) {
|
||||
await navigator.clipboard.writeText(props.password)
|
||||
} else {
|
||||
copyWithTextarea(props.password)
|
||||
}
|
||||
toast.success('默认密码已复制')
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : '复制失败,请手动复制')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.default-password-notice {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.default-password-notice p {
|
||||
margin: 0;
|
||||
color: #625c55;
|
||||
font-size: 14px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.default-password-notice__value {
|
||||
min-height: 46px;
|
||||
padding: 12px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
background: var(--subtle);
|
||||
color: var(--ink);
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
font-size: 16px;
|
||||
font-weight: 800;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.default-password-notice__copy {
|
||||
gap: 8px;
|
||||
}
|
||||
</style>
|
||||
@@ -200,7 +200,7 @@ export interface EmployeeCreateRequest {
|
||||
nickname: string
|
||||
phone: string
|
||||
account: string
|
||||
password: string
|
||||
password?: string
|
||||
contactPhone?: string
|
||||
wechatId?: string
|
||||
avatar?: string
|
||||
|
||||
@@ -119,6 +119,13 @@
|
||||
</button>
|
||||
</div>
|
||||
</BaseModal>
|
||||
|
||||
<DefaultPasswordNoticeModal
|
||||
v-model="defaultPasswordNoticeVisible"
|
||||
title="密码已重置"
|
||||
message="该员工密码已重置为系统默认密码。请提醒员工首次登录后修改。"
|
||||
:password="defaultPasswordNoticePassword"
|
||||
/>
|
||||
</MobileShell>
|
||||
</template>
|
||||
|
||||
@@ -127,6 +134,7 @@ import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { KeyRound, Pencil, Trash2, Upload } from 'lucide-vue-next'
|
||||
import BaseModal from '@/components/BaseModal.vue'
|
||||
import DefaultPasswordNoticeModal from '@/components/DefaultPasswordNoticeModal.vue'
|
||||
import EmptyState from '@/components/EmptyState.vue'
|
||||
import LoadingState from '@/components/LoadingState.vue'
|
||||
import MobileShell from '@/components/MobileShell.vue'
|
||||
@@ -161,6 +169,8 @@ const resettingPassword = ref(false)
|
||||
const deletingEmployee = ref(false)
|
||||
const resetConfirmVisible = ref(false)
|
||||
const deleteConfirmVisible = ref(false)
|
||||
const defaultPasswordNoticeVisible = ref(false)
|
||||
const defaultPasswordNoticePassword = ref('')
|
||||
const employee = ref<Artist | null>(null)
|
||||
const editModalVisible = ref(false)
|
||||
const employeeId = computed(() => String(route.params.id))
|
||||
@@ -298,6 +308,20 @@ function errorMessage(error: { message?: string } | null, fallback: string): str
|
||||
return error?.message ? error.message : fallback
|
||||
}
|
||||
|
||||
async function resolveResetDefaultPassword(): Promise<string> {
|
||||
const response = await managerEmployeesApi.getResetDefaultPassword()
|
||||
const password = response.password.trim()
|
||||
if (!password) {
|
||||
throw new Error('默认密码为空,请先检查系统参数配置')
|
||||
}
|
||||
return password
|
||||
}
|
||||
|
||||
function showDefaultPasswordNotice(password: string): void {
|
||||
defaultPasswordNoticePassword.value = password
|
||||
defaultPasswordNoticeVisible.value = true
|
||||
}
|
||||
|
||||
const loadEmployee = async (): Promise<void> => {
|
||||
loading.value = true
|
||||
try {
|
||||
@@ -387,7 +411,11 @@ const confirmResetPassword = async (): Promise<void> => {
|
||||
try {
|
||||
await managerEmployeesApi.resetPassword(employee.value.userId || employeeId.value)
|
||||
resetConfirmVisible.value = false
|
||||
toast.success('密码已重置为系统默认密码')
|
||||
try {
|
||||
showDefaultPasswordNotice(await resolveResetDefaultPassword())
|
||||
} catch (error) {
|
||||
toast.error(errorMessage(error as { message?: string } | null, '密码已重置,但默认密码获取失败'))
|
||||
}
|
||||
} catch (error) {
|
||||
toast.error(errorMessage(error as { message?: string } | null, '密码重置失败,请稍后重试'))
|
||||
} finally {
|
||||
|
||||
@@ -31,11 +31,18 @@
|
||||
<div class="field"><label class="required">姓名</label><input v-model.trim="createForm.nickname" placeholder="请输入姓名" /></div>
|
||||
<div class="field"><label class="required">手机号</label><input v-model.trim="createForm.phone" inputmode="numeric" placeholder="请输入手机号" /></div>
|
||||
<div class="field"><label class="required">登录账号</label><input v-model.trim="createForm.account" placeholder="请输入登录账号" /></div>
|
||||
<div class="field"><label class="required">初始密码</label><input v-model="createForm.password" type="password" placeholder="请输入初始密码" /></div>
|
||||
<div class="field"><label>初始密码</label><input v-model="createForm.password" type="password" placeholder="不填则使用默认密码" /></div>
|
||||
<div class="field"><label>微信号</label><input v-model.trim="createForm.wechatId" placeholder="请输入微信号" /></div>
|
||||
<button class="primary-btn" type="button" :disabled="creating" @click="createEmployee">{{ creating ? '新增中...' : '保存员工' }}</button>
|
||||
</div>
|
||||
</BaseModal>
|
||||
|
||||
<DefaultPasswordNoticeModal
|
||||
v-model="defaultPasswordNoticeVisible"
|
||||
title="员工已新增"
|
||||
message="本次未输入密码,系统已使用默认密码。请提醒员工首次登录后修改。"
|
||||
:password="defaultPasswordNoticePassword"
|
||||
/>
|
||||
</MobileShell>
|
||||
</template>
|
||||
|
||||
@@ -43,11 +50,12 @@
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import BaseModal from '@/components/BaseModal.vue'
|
||||
import DefaultPasswordNoticeModal from '@/components/DefaultPasswordNoticeModal.vue'
|
||||
import EmptyState from '@/components/EmptyState.vue'
|
||||
import LoadingState from '@/components/LoadingState.vue'
|
||||
import MobileShell from '@/components/MobileShell.vue'
|
||||
import { managerEmployeesApi } from '@/api/managerEmployees'
|
||||
import type { Artist } from '@/types/manager'
|
||||
import type { Artist, EmployeeCreateRequest } from '@/types/manager'
|
||||
import { useSessionStore } from '@/stores/session'
|
||||
import { useToastStore } from '@/stores/toast'
|
||||
import { readFormModalDraft, removeFormModalDraft, writeFormModalDraft } from '@/utils/form-modal-draft'
|
||||
@@ -69,6 +77,8 @@ const loading = ref(false)
|
||||
const employees = ref<Artist[]>([])
|
||||
const createModalVisible = ref(false)
|
||||
const creating = ref(false)
|
||||
const defaultPasswordNoticeVisible = ref(false)
|
||||
const defaultPasswordNoticePassword = ref('')
|
||||
const buildEmptyCreateForm = (): CreateEmployeeForm => ({
|
||||
nickname: '',
|
||||
phone: '',
|
||||
@@ -129,6 +139,24 @@ const updateCreateModalVisible = (value: boolean): void => {
|
||||
}
|
||||
}
|
||||
|
||||
const errorMessage = (error: { message?: string } | null, fallback: string): string => {
|
||||
return error?.message ? error.message : fallback
|
||||
}
|
||||
|
||||
const resolveCreateDefaultPassword = async (): Promise<string> => {
|
||||
const response = await managerEmployeesApi.getCreateDefaultPassword()
|
||||
const password = response.password.trim()
|
||||
if (!password) {
|
||||
throw new Error('默认密码为空,请先检查系统参数配置')
|
||||
}
|
||||
return password
|
||||
}
|
||||
|
||||
const showDefaultPasswordNotice = (password: string): void => {
|
||||
defaultPasswordNoticePassword.value = password
|
||||
defaultPasswordNoticeVisible.value = true
|
||||
}
|
||||
|
||||
const loadEmployees = async (): Promise<void> => {
|
||||
loading.value = true
|
||||
try {
|
||||
@@ -148,24 +176,36 @@ const createEmployee = async (): Promise<void> => {
|
||||
const nickname = createForm.nickname.trim()
|
||||
const phone = createForm.phone.trim()
|
||||
const account = createForm.account.trim()
|
||||
const password = createForm.password
|
||||
const password = createForm.password.trim()
|
||||
const wechatId = createForm.wechatId.trim() || phone
|
||||
if (!nickname || !phone || !account || !password) {
|
||||
if (!nickname || !phone || !account) {
|
||||
toast.error('请补全美甲师信息')
|
||||
return
|
||||
}
|
||||
creating.value = true
|
||||
try {
|
||||
await managerEmployeesApi.createUser({
|
||||
const requestData: EmployeeCreateRequest = {
|
||||
nickname,
|
||||
phone,
|
||||
account,
|
||||
password,
|
||||
contactPhone: phone,
|
||||
wechatId
|
||||
})
|
||||
toast.success('美甲师已新增')
|
||||
}
|
||||
if (password) {
|
||||
requestData.password = password
|
||||
}
|
||||
const usedDefaultPassword = !password
|
||||
await managerEmployeesApi.createUser(requestData)
|
||||
updateCreateModalVisible(false)
|
||||
if (usedDefaultPassword) {
|
||||
try {
|
||||
showDefaultPasswordNotice(await resolveCreateDefaultPassword())
|
||||
} catch (error) {
|
||||
toast.error(errorMessage(error as { message?: string } | null, '员工已新增,但默认密码获取失败'))
|
||||
}
|
||||
} else {
|
||||
toast.success('美甲师已新增')
|
||||
}
|
||||
await loadEmployees()
|
||||
} finally {
|
||||
creating.value = false
|
||||
|
||||
Reference in New Issue
Block a user