修复
This commit is contained in:
@@ -503,7 +503,7 @@ const canDeleteRow = (row) => {
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button @click="closeDetail">关闭</el-button>
|
||||
<el-button type="primary" @click="(() => { const d = currentDetail; closeDetail(); editContract(d) })()" v-if="userInfo.employee_id === currentDetail?.employee_id">编辑</el-button>
|
||||
<el-button type="primary" @click="(() => { const d = currentDetail; closeDetail(); editContract(d) })()" v-if="canUpdate && userInfo.employee_id === currentDetail?.employee_id">编辑</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
import { hasPermission, getUserInfo } from '../store/user'
|
||||
import { formatDateTime, formatDate } from '../utils/date'
|
||||
import { createUser } from '../api/user'
|
||||
import { DEPARTMENT_NAME_LIST } from '../constants/departments'
|
||||
import { DEPARTMENT_NAME_LIST, DEPARTMENT_LIST } from '../constants/departments'
|
||||
|
||||
const form = reactive({
|
||||
name: '',
|
||||
@@ -34,6 +34,7 @@ const form = reactive({
|
||||
const search = ref('')
|
||||
const select = ref('1')
|
||||
const filterStatus = ref('')
|
||||
const filterDepartment = ref('')
|
||||
const searchResults = ref([])
|
||||
const showSearchResults = ref(false)
|
||||
const showAddForm = ref(false)
|
||||
@@ -52,6 +53,7 @@ const totalPages = ref(0)
|
||||
// 新增用户相关状态
|
||||
const showCreateUserForm = ref(false)
|
||||
const justCreatedEmployee = ref(null)
|
||||
const linkedEmployeeId = ref(null) // 独立 ref 追踪关联员工 ID
|
||||
const userForm = reactive({
|
||||
username: '',
|
||||
password: '',
|
||||
@@ -73,7 +75,7 @@ const paginatedData = computed(() => searchResults.value)
|
||||
// onMounted 已在下方合并(同时加载部门列表)
|
||||
|
||||
// 监听筛选变化
|
||||
watch([filterStatus], () => {
|
||||
watch([filterStatus, filterDepartment], () => {
|
||||
currentPage.value = 1
|
||||
handleSearch()
|
||||
})
|
||||
@@ -118,15 +120,14 @@ const handleSearch = async () => {
|
||||
const params = {
|
||||
page: 1,
|
||||
pageSize: pageSize.value,
|
||||
status: filterStatus.value !== '' ? filterStatus.value : undefined
|
||||
status: filterStatus.value !== '' ? filterStatus.value : undefined,
|
||||
department: filterDepartment.value || undefined
|
||||
}
|
||||
if (search.value) {
|
||||
if (select.value === '1') {
|
||||
params.id = Number(search.value)
|
||||
} else if (select.value === '2') {
|
||||
params.name = search.value
|
||||
} else if (select.value === '3') {
|
||||
params.department = search.value
|
||||
}
|
||||
}
|
||||
const res = await getEmployeeList(params)
|
||||
@@ -148,6 +149,7 @@ const handleSearch = async () => {
|
||||
const resetSearch = () => {
|
||||
search.value = ''
|
||||
filterStatus.value = ''
|
||||
filterDepartment.value = ''
|
||||
showSearchResults.value = false
|
||||
showAddForm.value = false
|
||||
currentPage.value = 1
|
||||
@@ -241,11 +243,17 @@ const saveEmployee = async () => {
|
||||
cancelButtonText: '暂不创建',
|
||||
type: 'info'
|
||||
}
|
||||
).then(() => {
|
||||
// 确认:进入用户创建表单
|
||||
openUserForm(res.data)
|
||||
).then((action) => {
|
||||
if (action === 'confirm') {
|
||||
// 确认:进入用户创建表单
|
||||
openUserForm(res.data)
|
||||
} else {
|
||||
// 取消:返回列表
|
||||
cancelAdd()
|
||||
fetchData()
|
||||
}
|
||||
}).catch(() => {
|
||||
// 取消:返回列表
|
||||
// 用户点击了关闭按钮(X):返回列表
|
||||
cancelAdd()
|
||||
fetchData()
|
||||
})
|
||||
@@ -298,15 +306,25 @@ const handleCurrentChange = (val) => {
|
||||
}
|
||||
|
||||
// 打开用户创建表单(从员工新增后调用)
|
||||
const openUserForm = (employee) => {
|
||||
const openUserForm = (emp) => {
|
||||
// 兼容 res.data 嵌套:res.data 可能是 { data: {...} } 或直接 {...}
|
||||
const employee = emp?.data || emp
|
||||
if (!employee || !employee.id) {
|
||||
console.error('[openUserForm] 员工数据异常:', emp)
|
||||
ElMessage.error('员工信息获取失败,请重试')
|
||||
return
|
||||
}
|
||||
showAddForm.value = false
|
||||
showSearchResults.value = false
|
||||
showCreateUserForm.value = true
|
||||
// 自动填充员工信息
|
||||
// 用独立 ref 保存员工 ID,避免 reactive 对象异步问题
|
||||
linkedEmployeeId.value = employee.id
|
||||
// 自动填充员工信息,部门与员工一致
|
||||
const deptMatch = DEPARTMENT_LIST.find(d => d.description === employee.department)
|
||||
userForm.username = ''
|
||||
userForm.password = ''
|
||||
userForm.name = employee.name
|
||||
userForm.department_id = 2
|
||||
userForm.name = employee.name || ''
|
||||
userForm.department_id = deptMatch ? deptMatch.id : 2
|
||||
userForm.is_active = 1
|
||||
userForm.employee_id = employee.id
|
||||
}
|
||||
@@ -330,22 +348,29 @@ const saveUserFromEmployee = async () => {
|
||||
ElMessage.warning('请输入密码')
|
||||
return
|
||||
}
|
||||
await createUser({
|
||||
username: userForm.username,
|
||||
password: userForm.password,
|
||||
department_id: userForm.department_id,
|
||||
employee_id: userForm.employee_id,
|
||||
is_active: userForm.is_active
|
||||
})
|
||||
ElMessage.success('用户创建成功')
|
||||
cancelCreateUser()
|
||||
fetchData()
|
||||
try {
|
||||
const empId = linkedEmployeeId.value || userForm.employee_id
|
||||
const payload = {
|
||||
username: userForm.username,
|
||||
password: userForm.password,
|
||||
department_id: userForm.department_id,
|
||||
employee_id: empId,
|
||||
is_active: userForm.is_active
|
||||
}
|
||||
await createUser(payload)
|
||||
ElMessage.success('用户创建成功')
|
||||
cancelCreateUser()
|
||||
fetchData()
|
||||
} catch (e) {
|
||||
ElMessage.error(e?.response?.data?.message || e?.message || '用户创建失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 取消创建用户
|
||||
const cancelCreateUser = () => {
|
||||
showCreateUserForm.value = false
|
||||
justCreatedEmployee.value = null
|
||||
linkedEmployeeId.value = null
|
||||
userForm.username = ''
|
||||
userForm.password = ''
|
||||
userForm.name = ''
|
||||
@@ -375,7 +400,6 @@ const showSalary = computed(() => ['总经理办公室', '财务部'].includes(g
|
||||
<el-select v-model="select" placeholder="请选择" style="width: 115px">
|
||||
<el-option label="员工编号" value="1" />
|
||||
<el-option label="员工姓名" value="2" />
|
||||
<el-option label="部门" value="3" />
|
||||
</el-select>
|
||||
</template>
|
||||
<template #append>
|
||||
@@ -391,6 +415,9 @@ const showSalary = computed(() => ['总经理办公室', '财务部'].includes(g
|
||||
|
||||
<div class="filter-row">
|
||||
<span class="filter-label">筛选条件:</span>
|
||||
<el-select v-model="filterDepartment" placeholder="所属部门" clearable style="width: 140px; margin-right: 12px;">
|
||||
<el-option v-for="dept in DEPARTMENT_LIST" :key="dept.id" :label="dept.description" :value="dept.description" />
|
||||
</el-select>
|
||||
<el-select v-model="filterStatus" placeholder="在职状态" clearable style="width: 140px;">
|
||||
<el-option label="在职" :value="1" />
|
||||
<el-option label="离职" :value="0" />
|
||||
@@ -506,6 +533,7 @@ const showSalary = computed(() => ['总经理办公室', '财务部'].includes(g
|
||||
<el-select v-model="form.department" placeholder="请选择部门" style="width: 100%;">
|
||||
<el-option v-for="dept in departmentOptions" :key="dept" :label="dept" :value="dept" />
|
||||
</el-select>
|
||||
<div class="field-hint" v-if="isEditMode">修改部门将同步更新关联用户的部门</div>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
@@ -522,7 +550,7 @@ const showSalary = computed(() => ['总经理办公室', '财务部'].includes(g
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="工资">
|
||||
<el-form-item label="工资" v-if="showSalary">
|
||||
<el-input-number v-model="form.salary" :min="0" :step="500" :precision="2" style="width: 100%;" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@@ -566,7 +594,7 @@ const showSalary = computed(() => ['总经理办公室', '财务部'].includes(g
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="关联员工ID">
|
||||
<el-input :model-value="userForm.employee_id" disabled />
|
||||
<el-input :model-value="linkedEmployeeId" disabled />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
@@ -592,13 +620,8 @@ const showSalary = computed(() => ['总经理办公室', '财务部'].includes(g
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="所属部门">
|
||||
<el-select v-model="userForm.department_id" placeholder="请选择部门" style="width: 100%;">
|
||||
<el-option label="信息技术部" :value="1" />
|
||||
<el-option label="总经理办公室" :value="2" />
|
||||
<el-option label="招商部" :value="3" />
|
||||
<el-option label="运营部" :value="4" />
|
||||
<el-option label="采购部" :value="5" />
|
||||
<el-option label="财务部" :value="6" />
|
||||
<el-select v-model="userForm.department_id" placeholder="请选择部门" style="width: 100%;" disabled>
|
||||
<el-option v-for="dept in DEPARTMENT_LIST" :key="dept.id" :label="dept.description" :value="dept.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@@ -632,7 +655,7 @@ const showSalary = computed(() => ['总经理办公室', '财务部'].includes(g
|
||||
<el-descriptions-item label="学历">{{ currentDetail.education }}</el-descriptions-item>
|
||||
<el-descriptions-item label="部门">{{ currentDetail.department }}</el-descriptions-item>
|
||||
<el-descriptions-item label="职务">{{ currentDetail.position }}</el-descriptions-item>
|
||||
<el-descriptions-item label="工资">
|
||||
<el-descriptions-item label="工资" v-if="showSalary">
|
||||
<span class="amount-text">¥{{ currentDetail.salary?.toLocaleString() }}</span>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="入职时间">{{ formatDate(currentDetail.entry_date) }}</el-descriptions-item>
|
||||
@@ -659,6 +682,13 @@ const showSalary = computed(() => ['总经理办公室', '财务部'].includes(g
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.field-hint {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
margin-top: 4px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.employee-container {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
@@ -431,7 +431,7 @@ const canOperate = computed(() => canUpdate.value || canDelete.value)
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button @click="closeDetail">关闭</el-button>
|
||||
<el-button type="primary" @click="(() => { const d = currentDetail; closeDetail(); editProduct(d) })()">编辑</el-button>
|
||||
<el-button type="primary" @click="(() => { const d = currentDetail; closeDetail(); editProduct(d) })()" v-if="canUpdate">编辑</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
|
||||
@@ -435,7 +435,7 @@ const canDeleteRow = (row) => {
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button @click="closeDetail">关闭</el-button>
|
||||
<el-button type="primary" @click="(() => { const d = currentDetail; closeDetail(); editService(d) })()" v-if="getUserInfo()?.employee_id === currentDetail?.employee_id">编辑</el-button>
|
||||
<el-button type="primary" @click="(() => { const d = currentDetail; closeDetail(); editService(d) })()" v-if="canUpdate && getUserInfo()?.employee_id === currentDetail?.employee_id">编辑</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
deleteUserAPI
|
||||
} from '../api/user'
|
||||
import { getSimpleEmployeeList, getDepartmentList } from '../api/employee'
|
||||
import { hasPermission } from '../store/user'
|
||||
import { hasPermission, getUserInfo } from '../store/user'
|
||||
import { formatDateTime } from '../utils/date'
|
||||
import { DEPARTMENT_LIST } from '../constants/departments'
|
||||
|
||||
@@ -267,6 +267,7 @@ const handleCurrentChange = (val) => {
|
||||
|
||||
// 检查权限
|
||||
const canManage = computed(() => hasPermission('user', 'manage'))
|
||||
const isAdmin = computed(() => getUserInfo()?.departmentName === 'admin')
|
||||
|
||||
</script>
|
||||
|
||||
@@ -290,7 +291,7 @@ const canManage = computed(() => hasPermission('user', 'manage'))
|
||||
</el-input>
|
||||
|
||||
<div class="search-buttons">
|
||||
<el-button color="#E60012" @click="addUser" v-if="canManage">新增用户</el-button>
|
||||
<el-button color="#E60012" @click="addUser" v-if="canManage && !isAdmin">新增用户</el-button>
|
||||
<el-button type="default" @click="clearSearch">重置</el-button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -335,6 +336,11 @@ const canManage = computed(() => hasPermission('user', 'manage'))
|
||||
{{ row.dept_desc || '-' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="employee_id" label="关联员工" min-width="140">
|
||||
<template #default="{ row }">
|
||||
{{ row.employee_id ? `${row.employee_id} - ${row.real_name || '-'}` : '-' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="is_active" label="状态" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.is_active === 1 ? 'success' : 'danger'">
|
||||
@@ -350,7 +356,7 @@ const canManage = computed(() => hasPermission('user', 'manage'))
|
||||
<el-table-column label="操作" width="150" fixed="right" v-if="canManage">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" @click="editUser(row)">编辑</el-button>
|
||||
<el-button link type="danger" @click="deleteUser(row.id)">删除</el-button>
|
||||
<el-button link type="danger" @click="deleteUser(row.id)" v-if="!isAdmin">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -393,6 +399,7 @@ const canManage = computed(() => hasPermission('user', 'manage'))
|
||||
<el-select v-model="form.department_id" placeholder="请选择部门" style="width: 100%;">
|
||||
<el-option v-for="dept in deptList" :key="dept.id" :label="dept.description" :value="dept.id" />
|
||||
</el-select>
|
||||
<div class="field-hint" v-if="isEditMode && form.employee_id">修改部门将同步更新关联员工的部门</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="用户状态" required>
|
||||
@@ -418,7 +425,7 @@ const canManage = computed(() => hasPermission('user', 'manage'))
|
||||
<el-descriptions-item label="用户名">{{ currentDetail.username }}</el-descriptions-item>
|
||||
<el-descriptions-item label="真实姓名">{{ currentDetail.real_name || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="部门">{{ currentDetail.dept_desc || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="关联员工">{{ currentDetail.employee_id || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="关联员工">{{ currentDetail.employee_id ? `${currentDetail.employee_id} - ${currentDetail.real_name || '-'}` : '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="状态">
|
||||
<el-tag :type="currentDetail.is_active === 1 ? 'success' : 'danger'">
|
||||
{{ currentDetail.is_active === 1 ? '启用' : '禁用' }}
|
||||
@@ -437,6 +444,13 @@ const canManage = computed(() => hasPermission('user', 'manage'))
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.field-hint {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
margin-top: 4px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.user-container {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ export const DEPARTMENT_LIST = [
|
||||
{ id: 4, name: 'operations_manager', description: '运营部' },
|
||||
{ id: 5, name: 'procurement_manager', description: '采购部' },
|
||||
{ id: 6, name: 'finance', description: '财务部' },
|
||||
{ id: 7, name: 'hr', description: '人力资源部' },
|
||||
]
|
||||
|
||||
/** 描述文本列表(用于 employee 表单的部门下拉选择) */
|
||||
|
||||
Reference in New Issue
Block a user