2026-06-29 20:58:39 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<MobileShell title="员工详情">
|
|
|
|
|
|
<LoadingState v-if="loading" text="正在加载员工" />
|
|
|
|
|
|
<template v-else-if="employee">
|
|
|
|
|
|
<section class="card employee-hero">
|
|
|
|
|
|
<div class="employee-avatar" :style="{ backgroundColor: employee.color || '#e5eee9' }">
|
|
|
|
|
|
<img v-if="employee.avatar" :src="employee.avatar" alt="" />
|
|
|
|
|
|
<span v-else>{{ (employee.name || employee.nickname || '员').slice(0, 1) }}</span>
|
|
|
|
|
|
</div>
|
2026-07-01 13:44:59 +08:00
|
|
|
|
<div class="employee-hero__body">
|
2026-06-29 20:58:39 +08:00
|
|
|
|
<h2>{{ employee.name || employee.nickname || '未命名员工' }}</h2>
|
2026-07-01 14:24:46 +08:00
|
|
|
|
<p>{{ employee.phone || '未填写登录手机号' }}</p>
|
2026-06-29 20:58:39 +08:00
|
|
|
|
</div>
|
2026-07-01 13:44:59 +08:00
|
|
|
|
<button class="edit-btn" type="button" @click="openEdit">
|
|
|
|
|
|
<Pencil :size="15" aria-hidden="true" />
|
|
|
|
|
|
<span>编辑</span>
|
|
|
|
|
|
</button>
|
2026-06-29 20:58:39 +08:00
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
|
|
<section class="card form-card section">
|
|
|
|
|
|
<div class="field"><label>员工编号</label><div class="field-value">{{ employee.userId || employee.id }}</div></div>
|
2026-07-01 13:44:59 +08:00
|
|
|
|
<div class="field"><label>身份/级别</label><div class="field-value">{{ employee.identity || employee.level || '美甲师' }}</div></div>
|
|
|
|
|
|
<div class="field"><label>状态</label><div class="field-value">{{ employee.status === 0 ? '休息中' : '可预约' }}</div></div>
|
2026-07-01 14:24:46 +08:00
|
|
|
|
<div class="field"><label>登录手机号</label><div class="field-value">{{ employee.phone || '未填写' }}</div></div>
|
|
|
|
|
|
<div class="field"><label>联系电话</label><div class="field-value">{{ employee.contactPhone || '未填写' }}</div></div>
|
|
|
|
|
|
<div class="field"><label>微信号</label><div class="field-value">{{ employee.wechatId || '未填写' }}</div></div>
|
2026-06-29 20:58:39 +08:00
|
|
|
|
<div class="field"><label>预约颜色</label><div class="field-value color-line"><span class="color-dot" :style="{ backgroundColor: employee.color || '#b8b0a6' }"></span>{{ employee.color || '未设置' }}</div></div>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
|
|
<section class="card menu-list section">
|
|
|
|
|
|
<button v-for="item in menus" :key="item.path" class="menu-row" type="button" @click="router.push(item.path)">
|
|
|
|
|
|
<span>{{ item.title }}</span>
|
|
|
|
|
|
<span>›</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<EmptyState v-else title="员工不存在" />
|
2026-07-01 13:44:59 +08:00
|
|
|
|
|
|
|
|
|
|
<BaseModal
|
|
|
|
|
|
:model-value="editModalVisible"
|
|
|
|
|
|
title="编辑员工"
|
2026-07-01 14:24:46 +08:00
|
|
|
|
:close-disabled="closeDisabled"
|
2026-07-01 13:44:59 +08:00
|
|
|
|
:has-unsaved-changes="editFormChanged"
|
|
|
|
|
|
@update:model-value="updateEditModalVisible"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div class="modal-form">
|
2026-07-01 14:24:46 +08:00
|
|
|
|
<div class="avatar-field">
|
|
|
|
|
|
<div class="avatar-preview" :style="{ backgroundColor: employee?.color || '#e5eee9' }">
|
|
|
|
|
|
<img v-if="editForm.avatar" :src="editForm.avatar" alt="" />
|
|
|
|
|
|
<span v-else>{{ (editForm.nickname || '员').slice(0, 1) }}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="avatar-actions">
|
|
|
|
|
|
<label class="secondary-btn avatar-upload" :class="{ 'is-disabled': avatarUploading }">
|
|
|
|
|
|
<Upload :size="15" aria-hidden="true" />
|
|
|
|
|
|
<span>{{ avatarUploading ? '上传中' : '上传头像' }}</span>
|
|
|
|
|
|
<input type="file" accept="image/*" :disabled="avatarUploading" @change="uploadAvatar" />
|
|
|
|
|
|
</label>
|
|
|
|
|
|
<button class="secondary-btn" type="button" :disabled="avatarUploading || !editForm.avatar" @click="clearAvatar">
|
|
|
|
|
|
<Trash2 :size="15" aria-hidden="true" />
|
|
|
|
|
|
<span>清除</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="field"><label class="required">昵称</label><input v-model.trim="editForm.nickname" placeholder="请输入昵称" /></div>
|
|
|
|
|
|
<div class="field"><label class="required">登录手机号</label><input v-model.trim="editForm.phone" inputmode="tel" placeholder="请输入登录手机号" /></div>
|
|
|
|
|
|
<div class="field"><label>联系电话</label><input v-model.trim="editForm.contactPhone" inputmode="tel" placeholder="请输入联系电话" /></div>
|
|
|
|
|
|
<div class="field"><label class="required">微信号</label><input v-model.trim="editForm.wechatId" placeholder="请输入微信号" /></div>
|
2026-07-01 13:44:59 +08:00
|
|
|
|
<div class="field"><label>身份/级别</label><input v-model.trim="editForm.identity" placeholder="例如:高级美甲师" /></div>
|
|
|
|
|
|
<div class="field">
|
|
|
|
|
|
<label>状态</label>
|
|
|
|
|
|
<select v-model.number="editForm.status">
|
|
|
|
|
|
<option :value="1">可预约</option>
|
|
|
|
|
|
<option :value="0">休息中</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
2026-07-01 14:24:46 +08:00
|
|
|
|
|
|
|
|
|
|
<div class="reset-panel">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<strong>重置登录密码</strong>
|
|
|
|
|
|
<p>重置后员工可使用系统默认密码登录。</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<button class="secondary-btn reset-btn" type="button" :disabled="resettingPassword" @click="requestResetPassword">
|
|
|
|
|
|
<KeyRound :size="15" aria-hidden="true" />
|
|
|
|
|
|
<span>重置密码</span>
|
|
|
|
|
|
</button>
|
2026-07-01 13:44:59 +08:00
|
|
|
|
</div>
|
2026-07-01 14:24:46 +08:00
|
|
|
|
<div v-if="resetConfirmVisible" class="reset-confirm">
|
|
|
|
|
|
<p>确定要把该员工密码重置为系统默认密码吗?</p>
|
|
|
|
|
|
<div class="reset-confirm__actions">
|
|
|
|
|
|
<button class="secondary-btn" type="button" :disabled="resettingPassword" @click="resetConfirmVisible = false">取消</button>
|
|
|
|
|
|
<button class="danger-btn" type="button" :disabled="resettingPassword" @click="confirmResetPassword">
|
|
|
|
|
|
{{ resettingPassword ? '重置中...' : '确认重置' }}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<button class="primary-btn" type="button" :disabled="saving || avatarUploading" @click="saveEdit">
|
|
|
|
|
|
{{ saving ? '保存中...' : '保存员工' }}
|
|
|
|
|
|
</button>
|
2026-07-01 13:44:59 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</BaseModal>
|
2026-06-29 20:58:39 +08:00
|
|
|
|
</MobileShell>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2026-07-01 13:44:59 +08:00
|
|
|
|
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
2026-06-29 20:58:39 +08:00
|
|
|
|
import { useRoute, useRouter } from 'vue-router'
|
2026-07-01 14:24:46 +08:00
|
|
|
|
import { KeyRound, Pencil, Trash2, Upload } from 'lucide-vue-next'
|
2026-07-01 13:44:59 +08:00
|
|
|
|
import BaseModal from '@/components/BaseModal.vue'
|
2026-06-29 20:58:39 +08:00
|
|
|
|
import EmptyState from '@/components/EmptyState.vue'
|
|
|
|
|
|
import LoadingState from '@/components/LoadingState.vue'
|
|
|
|
|
|
import MobileShell from '@/components/MobileShell.vue'
|
2026-07-01 14:24:46 +08:00
|
|
|
|
import { fileApi } from '@/api/file'
|
2026-06-29 20:58:39 +08:00
|
|
|
|
import { managerEmployeesApi } from '@/api/managerEmployees'
|
2026-07-01 13:44:59 +08:00
|
|
|
|
import { useSessionStore } from '@/stores/session'
|
|
|
|
|
|
import { useToastStore } from '@/stores/toast'
|
2026-06-29 20:58:39 +08:00
|
|
|
|
import type { Artist } from '@/types/manager'
|
2026-07-01 13:44:59 +08:00
|
|
|
|
import { readFormModalDraft, removeFormModalDraft, writeFormModalDraft } from '@/utils/form-modal-draft'
|
|
|
|
|
|
|
|
|
|
|
|
interface EditEmployeeForm {
|
2026-07-01 14:24:46 +08:00
|
|
|
|
avatar: string
|
2026-07-01 13:44:59 +08:00
|
|
|
|
nickname: string
|
2026-07-01 14:24:46 +08:00
|
|
|
|
phone: string
|
|
|
|
|
|
contactPhone: string
|
|
|
|
|
|
wechatId: string
|
2026-07-01 13:44:59 +08:00
|
|
|
|
identity: string
|
|
|
|
|
|
status: number
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const EDIT_EMPLOYEE_DRAFT_NAME_PREFIX = 'employee-edit'
|
2026-07-01 14:24:46 +08:00
|
|
|
|
const phonePattern = /^1[3-9]\d{9}$/
|
2026-06-29 20:58:39 +08:00
|
|
|
|
|
|
|
|
|
|
const route = useRoute()
|
|
|
|
|
|
const router = useRouter()
|
2026-07-01 13:44:59 +08:00
|
|
|
|
const session = useSessionStore()
|
|
|
|
|
|
const toast = useToastStore()
|
2026-06-29 20:58:39 +08:00
|
|
|
|
const loading = ref(false)
|
2026-07-01 13:44:59 +08:00
|
|
|
|
const saving = ref(false)
|
2026-07-01 14:24:46 +08:00
|
|
|
|
const avatarUploading = ref(false)
|
|
|
|
|
|
const resettingPassword = ref(false)
|
|
|
|
|
|
const resetConfirmVisible = ref(false)
|
2026-06-29 20:58:39 +08:00
|
|
|
|
const employee = ref<Artist | null>(null)
|
2026-07-01 13:44:59 +08:00
|
|
|
|
const editModalVisible = ref(false)
|
2026-06-29 20:58:39 +08:00
|
|
|
|
const employeeId = computed(() => String(route.params.id))
|
2026-07-01 13:44:59 +08:00
|
|
|
|
const editDraftName = computed(() => `${EDIT_EMPLOYEE_DRAFT_NAME_PREFIX}-${employeeId.value}`)
|
2026-06-29 20:58:39 +08:00
|
|
|
|
const menus = computed(() => [
|
|
|
|
|
|
{ title: '排班设置', path: `/employees/${employeeId.value}/schedule` },
|
|
|
|
|
|
{ title: '请假管理', path: `/employees/${employeeId.value}/leave` },
|
|
|
|
|
|
{ title: '颜色设置', path: `/employees/${employeeId.value}/color` },
|
|
|
|
|
|
{ title: '员工作品/订单', path: `/employees/${employeeId.value}/orders` }
|
|
|
|
|
|
])
|
2026-07-01 13:44:59 +08:00
|
|
|
|
const buildEmptyEditForm = (): EditEmployeeForm => ({
|
2026-07-01 14:24:46 +08:00
|
|
|
|
avatar: '',
|
2026-07-01 13:44:59 +08:00
|
|
|
|
nickname: '',
|
2026-07-01 14:24:46 +08:00
|
|
|
|
phone: '',
|
|
|
|
|
|
contactPhone: '',
|
|
|
|
|
|
wechatId: '',
|
2026-07-01 13:44:59 +08:00
|
|
|
|
identity: '',
|
2026-07-01 14:24:46 +08:00
|
|
|
|
status: 1
|
2026-07-01 13:44:59 +08:00
|
|
|
|
})
|
|
|
|
|
|
const editForm = reactive<EditEmployeeForm>(buildEmptyEditForm())
|
|
|
|
|
|
const originalEditForm = ref<EditEmployeeForm>(buildEmptyEditForm())
|
|
|
|
|
|
const editFormChanged = computed(() => !sameEditForm(editForm, originalEditForm.value))
|
2026-07-01 14:24:46 +08:00
|
|
|
|
const closeDisabled = computed(() => saving.value || avatarUploading.value || resettingPassword.value)
|
2026-07-01 13:44:59 +08:00
|
|
|
|
|
|
|
|
|
|
function buildEditFormFromEmployee(value: Artist): EditEmployeeForm {
|
|
|
|
|
|
return {
|
2026-07-01 14:24:46 +08:00
|
|
|
|
avatar: value.avatar || '',
|
2026-07-01 13:44:59 +08:00
|
|
|
|
nickname: value.nickname || value.name || '',
|
2026-07-01 14:24:46 +08:00
|
|
|
|
phone: value.phone || '',
|
|
|
|
|
|
contactPhone: value.contactPhone || '',
|
|
|
|
|
|
wechatId: value.wechatId || '',
|
2026-07-01 13:44:59 +08:00
|
|
|
|
identity: value.identity || value.level || '',
|
2026-07-01 14:24:46 +08:00
|
|
|
|
status: value.status === 0 ? 0 : 1
|
2026-07-01 13:44:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function sameEditForm(left: EditEmployeeForm, right: EditEmployeeForm): boolean {
|
2026-07-01 14:24:46 +08:00
|
|
|
|
return left.avatar === right.avatar
|
|
|
|
|
|
&& left.nickname === right.nickname
|
|
|
|
|
|
&& left.phone === right.phone
|
|
|
|
|
|
&& left.contactPhone === right.contactPhone
|
|
|
|
|
|
&& left.wechatId === right.wechatId
|
2026-07-01 13:44:59 +08:00
|
|
|
|
&& left.identity === right.identity
|
|
|
|
|
|
&& left.status === right.status
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function snapshotEditForm(): EditEmployeeForm {
|
|
|
|
|
|
return {
|
2026-07-01 14:24:46 +08:00
|
|
|
|
avatar: editForm.avatar,
|
2026-07-01 13:44:59 +08:00
|
|
|
|
nickname: editForm.nickname,
|
2026-07-01 14:24:46 +08:00
|
|
|
|
phone: editForm.phone,
|
|
|
|
|
|
contactPhone: editForm.contactPhone,
|
|
|
|
|
|
wechatId: editForm.wechatId,
|
2026-07-01 13:44:59 +08:00
|
|
|
|
identity: editForm.identity,
|
2026-07-01 14:24:46 +08:00
|
|
|
|
status: editForm.status
|
2026-07-01 13:44:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function normalizeEditForm(form: EditEmployeeForm): EditEmployeeForm {
|
|
|
|
|
|
return {
|
2026-07-01 14:24:46 +08:00
|
|
|
|
avatar: String(form.avatar || ''),
|
2026-07-01 13:44:59 +08:00
|
|
|
|
nickname: String(form.nickname || ''),
|
2026-07-01 14:24:46 +08:00
|
|
|
|
phone: String(form.phone || ''),
|
|
|
|
|
|
contactPhone: String(form.contactPhone || ''),
|
|
|
|
|
|
wechatId: String(form.wechatId || ''),
|
2026-07-01 13:44:59 +08:00
|
|
|
|
identity: String(form.identity || ''),
|
2026-07-01 14:24:46 +08:00
|
|
|
|
status: Number(form.status) === 0 ? 0 : 1
|
2026-07-01 13:44:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function applyEditForm(form: EditEmployeeForm): void {
|
|
|
|
|
|
const normalizedForm = normalizeEditForm(form)
|
2026-07-01 14:24:46 +08:00
|
|
|
|
editForm.avatar = normalizedForm.avatar
|
2026-07-01 13:44:59 +08:00
|
|
|
|
editForm.nickname = normalizedForm.nickname
|
2026-07-01 14:24:46 +08:00
|
|
|
|
editForm.phone = normalizedForm.phone
|
|
|
|
|
|
editForm.contactPhone = normalizedForm.contactPhone
|
|
|
|
|
|
editForm.wechatId = normalizedForm.wechatId
|
2026-07-01 13:44:59 +08:00
|
|
|
|
editForm.identity = normalizedForm.identity
|
|
|
|
|
|
editForm.status = normalizedForm.status
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function resetEditForm(): void {
|
|
|
|
|
|
const emptyForm = buildEmptyEditForm()
|
|
|
|
|
|
applyEditForm(emptyForm)
|
|
|
|
|
|
originalEditForm.value = emptyForm
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function syncEditDraft(): void {
|
|
|
|
|
|
if (!editModalVisible.value || !editFormChanged.value) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
writeFormModalDraft(session.userInfo, editDraftName.value, snapshotEditForm(), editModalVisible.value)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function restoreEditDraft(): void {
|
|
|
|
|
|
if (!employee.value) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
const draft = readFormModalDraft<EditEmployeeForm>(session.userInfo, editDraftName.value)
|
|
|
|
|
|
if (!draft?.open) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
const baseForm = buildEditFormFromEmployee(employee.value)
|
|
|
|
|
|
originalEditForm.value = baseForm
|
|
|
|
|
|
applyEditForm(draft.form)
|
|
|
|
|
|
editModalVisible.value = true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function clearEditDraft(): void {
|
|
|
|
|
|
removeFormModalDraft(session.userInfo, editDraftName.value)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function updateEditModalVisible(value: boolean): void {
|
|
|
|
|
|
editModalVisible.value = value
|
|
|
|
|
|
if (!value) {
|
2026-07-01 14:24:46 +08:00
|
|
|
|
resetConfirmVisible.value = false
|
2026-07-01 13:44:59 +08:00
|
|
|
|
clearEditDraft()
|
|
|
|
|
|
resetEditForm()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function openEdit(): void {
|
|
|
|
|
|
if (!employee.value) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
clearEditDraft()
|
2026-07-01 14:24:46 +08:00
|
|
|
|
resetConfirmVisible.value = false
|
2026-07-01 13:44:59 +08:00
|
|
|
|
const form = buildEditFormFromEmployee(employee.value)
|
|
|
|
|
|
applyEditForm(form)
|
|
|
|
|
|
originalEditForm.value = snapshotEditForm()
|
|
|
|
|
|
editModalVisible.value = true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-01 14:24:46 +08:00
|
|
|
|
function errorMessage(error: { message?: string } | null, fallback: string): string {
|
|
|
|
|
|
return error?.message ? error.message : fallback
|
2026-07-01 13:44:59 +08:00
|
|
|
|
}
|
2026-06-29 20:58:39 +08:00
|
|
|
|
|
|
|
|
|
|
const loadEmployee = async (): Promise<void> => {
|
|
|
|
|
|
loading.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
employee.value = await managerEmployeesApi.detail(employeeId.value)
|
2026-07-01 14:24:46 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
|
toast.error(errorMessage(error as { message?: string } | null, '员工详情加载失败,请稍后重试'))
|
|
|
|
|
|
employee.value = null
|
2026-06-29 20:58:39 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-01 14:24:46 +08:00
|
|
|
|
const uploadAvatar = async (event: Event): Promise<void> => {
|
|
|
|
|
|
const target = event.target as HTMLInputElement
|
|
|
|
|
|
const file = target.files?.[0]
|
|
|
|
|
|
target.value = ''
|
|
|
|
|
|
if (!file) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
avatarUploading.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
editForm.avatar = await fileApi.uploadProfileImage(file)
|
|
|
|
|
|
toast.success('头像已上传')
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
toast.error(errorMessage(error as { message?: string } | null, '头像上传失败,请稍后重试'))
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
avatarUploading.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const clearAvatar = (): void => {
|
|
|
|
|
|
editForm.avatar = ''
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-01 13:44:59 +08:00
|
|
|
|
const validateEditForm = (): boolean => {
|
|
|
|
|
|
if (!editForm.nickname.trim()) {
|
2026-07-01 14:24:46 +08:00
|
|
|
|
toast.error('请输入员工昵称')
|
2026-07-01 13:44:59 +08:00
|
|
|
|
return false
|
|
|
|
|
|
}
|
2026-07-01 14:24:46 +08:00
|
|
|
|
if (!phonePattern.test(editForm.phone.trim())) {
|
|
|
|
|
|
toast.error('请输入正确的登录手机号')
|
2026-07-01 13:44:59 +08:00
|
|
|
|
return false
|
|
|
|
|
|
}
|
2026-07-01 14:24:46 +08:00
|
|
|
|
if (!editForm.wechatId.trim()) {
|
|
|
|
|
|
toast.error('请输入微信号')
|
2026-07-01 13:44:59 +08:00
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
return true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const saveEdit = async (): Promise<void> => {
|
|
|
|
|
|
if (!employee.value || !validateEditForm()) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
saving.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
await managerEmployeesApi.save({
|
2026-07-01 14:24:46 +08:00
|
|
|
|
id: employee.value.id,
|
2026-07-01 13:44:59 +08:00
|
|
|
|
userId: employee.value.userId || employeeId.value,
|
2026-07-01 14:24:46 +08:00
|
|
|
|
avatar: editForm.avatar.trim(),
|
2026-07-01 13:44:59 +08:00
|
|
|
|
nickname: editForm.nickname.trim(),
|
2026-07-01 14:24:46 +08:00
|
|
|
|
phone: editForm.phone.trim(),
|
|
|
|
|
|
contactPhone: editForm.contactPhone.trim(),
|
|
|
|
|
|
wechatId: editForm.wechatId.trim(),
|
2026-07-01 13:44:59 +08:00
|
|
|
|
identity: editForm.identity.trim(),
|
2026-07-01 14:24:46 +08:00
|
|
|
|
status: editForm.status
|
2026-07-01 13:44:59 +08:00
|
|
|
|
})
|
|
|
|
|
|
toast.success('员工信息已保存')
|
|
|
|
|
|
updateEditModalVisible(false)
|
|
|
|
|
|
await loadEmployee()
|
|
|
|
|
|
} catch (error) {
|
2026-07-01 14:24:46 +08:00
|
|
|
|
toast.error(errorMessage(error as { message?: string } | null, '员工信息保存失败,请稍后重试'))
|
2026-07-01 13:44:59 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
saving.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-01 14:24:46 +08:00
|
|
|
|
const requestResetPassword = (): void => {
|
|
|
|
|
|
resetConfirmVisible.value = true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const confirmResetPassword = async (): Promise<void> => {
|
|
|
|
|
|
if (!employee.value) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
resettingPassword.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
await managerEmployeesApi.resetPassword(employee.value.userId || employeeId.value)
|
|
|
|
|
|
resetConfirmVisible.value = false
|
|
|
|
|
|
toast.success('密码已重置为系统默认密码')
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
toast.error(errorMessage(error as { message?: string } | null, '密码重置失败,请稍后重试'))
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
resettingPassword.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-01 13:44:59 +08:00
|
|
|
|
onMounted(async () => {
|
|
|
|
|
|
await loadEmployee()
|
|
|
|
|
|
restoreEditDraft()
|
2026-06-29 20:58:39 +08:00
|
|
|
|
})
|
2026-07-01 13:44:59 +08:00
|
|
|
|
|
|
|
|
|
|
watch(editForm, syncEditDraft, { deep: true })
|
|
|
|
|
|
watch(editModalVisible, syncEditDraft)
|
2026-06-29 20:58:39 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.employee-hero {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 14px;
|
|
|
|
|
|
padding: 18px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.employee-avatar {
|
|
|
|
|
|
display: grid;
|
|
|
|
|
|
place-items: center;
|
|
|
|
|
|
width: 62px;
|
|
|
|
|
|
height: 62px;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
border-radius: 22px;
|
|
|
|
|
|
color: var(--accent);
|
|
|
|
|
|
font-size: 24px;
|
|
|
|
|
|
font-weight: 900;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-01 13:44:59 +08:00
|
|
|
|
.employee-hero__body {
|
|
|
|
|
|
min-width: 0;
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-01 14:24:46 +08:00
|
|
|
|
.employee-avatar img,
|
|
|
|
|
|
.avatar-preview img {
|
2026-06-29 20:58:39 +08:00
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
object-fit: cover;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.employee-hero h2,
|
|
|
|
|
|
.employee-hero p {
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.employee-hero p {
|
|
|
|
|
|
margin-top: 4px;
|
|
|
|
|
|
color: var(--muted);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-01 13:44:59 +08:00
|
|
|
|
.edit-btn {
|
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 4px;
|
|
|
|
|
|
min-height: 34px;
|
|
|
|
|
|
padding: 0 12px;
|
|
|
|
|
|
border: 1px solid var(--border);
|
|
|
|
|
|
border-radius: 999px;
|
|
|
|
|
|
background: var(--card-bg);
|
|
|
|
|
|
color: var(--accent);
|
|
|
|
|
|
font-size: 13px;
|
|
|
|
|
|
font-weight: 800;
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-29 20:58:39 +08:00
|
|
|
|
.color-line {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 8px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.color-dot {
|
|
|
|
|
|
width: 16px;
|
|
|
|
|
|
height: 16px;
|
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.menu-list {
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.menu-row {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
min-height: 54px;
|
|
|
|
|
|
padding: 0 14px;
|
|
|
|
|
|
border-bottom: 1px solid var(--border);
|
|
|
|
|
|
color: var(--ink);
|
|
|
|
|
|
font-weight: 800;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.menu-row:last-child {
|
|
|
|
|
|
border-bottom: 0;
|
|
|
|
|
|
}
|
2026-07-01 13:44:59 +08:00
|
|
|
|
|
|
|
|
|
|
.modal-form {
|
|
|
|
|
|
display: grid;
|
|
|
|
|
|
gap: 12px;
|
|
|
|
|
|
padding: 14px;
|
|
|
|
|
|
}
|
2026-07-01 14:24:46 +08:00
|
|
|
|
|
|
|
|
|
|
.avatar-field {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 14px;
|
|
|
|
|
|
padding: 6px 0 10px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.avatar-preview {
|
|
|
|
|
|
display: grid;
|
|
|
|
|
|
place-items: center;
|
|
|
|
|
|
width: 64px;
|
|
|
|
|
|
height: 64px;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
border-radius: 22px;
|
|
|
|
|
|
color: var(--accent);
|
|
|
|
|
|
font-size: 24px;
|
|
|
|
|
|
font-weight: 900;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.avatar-actions {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
|
gap: 8px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.avatar-actions .secondary-btn,
|
|
|
|
|
|
.reset-btn {
|
|
|
|
|
|
gap: 6px;
|
|
|
|
|
|
min-height: 36px;
|
|
|
|
|
|
padding: 0 12px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.avatar-upload {
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.avatar-upload input {
|
|
|
|
|
|
display: none;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.avatar-upload.is-disabled {
|
|
|
|
|
|
cursor: not-allowed;
|
|
|
|
|
|
opacity: 0.65;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.reset-panel {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
gap: 12px;
|
|
|
|
|
|
padding: 12px;
|
|
|
|
|
|
border: 1px solid var(--border);
|
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
|
background: rgba(255, 255, 255, 0.7);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.reset-panel strong,
|
|
|
|
|
|
.reset-panel p,
|
|
|
|
|
|
.reset-confirm p {
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.reset-panel strong {
|
|
|
|
|
|
display: block;
|
|
|
|
|
|
color: var(--ink);
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.reset-panel p,
|
|
|
|
|
|
.reset-confirm p {
|
|
|
|
|
|
margin-top: 4px;
|
|
|
|
|
|
color: var(--muted);
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
line-height: 1.5;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.reset-confirm {
|
|
|
|
|
|
display: grid;
|
|
|
|
|
|
gap: 10px;
|
|
|
|
|
|
padding: 12px;
|
|
|
|
|
|
border: 1px solid rgba(191, 73, 73, 0.22);
|
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
|
background: rgba(191, 73, 73, 0.08);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.reset-confirm__actions {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: flex-end;
|
|
|
|
|
|
gap: 8px;
|
|
|
|
|
|
}
|
2026-06-29 20:58:39 +08:00
|
|
|
|
</style>
|