2026-06-25 21:49:55 +08:00
|
|
|
|
// 模拟员工数据(单一数据源,同时包含用户字段)
|
|
|
|
|
|
export const mockEmployees = [
|
2026-06-24 16:42:13 +08:00
|
|
|
|
{
|
|
|
|
|
|
id: 1,
|
|
|
|
|
|
name: '张伟',
|
|
|
|
|
|
gender: '男',
|
|
|
|
|
|
age: 28,
|
|
|
|
|
|
education: '本科',
|
|
|
|
|
|
department: '运营部',
|
|
|
|
|
|
entry_date: '2023-03-15',
|
|
|
|
|
|
position: '运营主管',
|
|
|
|
|
|
salary: 8500.00,
|
|
|
|
|
|
phone: '13800138001',
|
|
|
|
|
|
email: 'zhangwei@mxbc.com',
|
|
|
|
|
|
status: 1,
|
|
|
|
|
|
remark: '负责门店日常运营',
|
2026-06-25 21:49:55 +08:00
|
|
|
|
// 用户字段
|
|
|
|
|
|
username: 'zhangwei',
|
|
|
|
|
|
password: '123456',
|
|
|
|
|
|
user_type: 'admin',
|
|
|
|
|
|
user_status: '1',
|
2026-06-24 16:42:13 +08:00
|
|
|
|
created_at: '2023-03-15 09:00:00',
|
|
|
|
|
|
updated_at: '2023-03-15 09:00:00'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 2,
|
|
|
|
|
|
name: '李娜',
|
|
|
|
|
|
gender: '女',
|
|
|
|
|
|
age: 25,
|
|
|
|
|
|
education: '专科',
|
|
|
|
|
|
department: '销售部',
|
|
|
|
|
|
entry_date: '2023-06-01',
|
|
|
|
|
|
position: '销售专员',
|
|
|
|
|
|
salary: 6000.00,
|
|
|
|
|
|
phone: '13800138002',
|
|
|
|
|
|
email: 'lina@mxbc.com',
|
|
|
|
|
|
status: 1,
|
|
|
|
|
|
remark: '',
|
2026-06-25 21:49:55 +08:00
|
|
|
|
// 用户字段
|
|
|
|
|
|
username: 'lina',
|
|
|
|
|
|
password: '123456',
|
|
|
|
|
|
user_type: 'user',
|
|
|
|
|
|
user_status: '1',
|
2026-06-24 16:42:13 +08:00
|
|
|
|
created_at: '2023-06-01 09:00:00',
|
|
|
|
|
|
updated_at: '2023-06-01 09:00:00'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 3,
|
|
|
|
|
|
name: '王强',
|
|
|
|
|
|
gender: '男',
|
|
|
|
|
|
age: 32,
|
|
|
|
|
|
education: '硕士',
|
|
|
|
|
|
department: '技术部',
|
|
|
|
|
|
entry_date: '2022-11-10',
|
|
|
|
|
|
position: '技术总监',
|
|
|
|
|
|
salary: 15000.00,
|
|
|
|
|
|
phone: '13800138003',
|
|
|
|
|
|
email: 'wangqiang@mxbc.com',
|
|
|
|
|
|
status: 1,
|
|
|
|
|
|
remark: '负责系统架构设计',
|
2026-06-25 21:49:55 +08:00
|
|
|
|
// 用户字段(无用户账号)
|
|
|
|
|
|
username: null,
|
|
|
|
|
|
password: null,
|
|
|
|
|
|
user_type: null,
|
|
|
|
|
|
user_status: null,
|
2026-06-24 16:42:13 +08:00
|
|
|
|
created_at: '2022-11-10 09:00:00',
|
|
|
|
|
|
updated_at: '2022-11-10 09:00:00'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 4,
|
|
|
|
|
|
name: '刘洋',
|
|
|
|
|
|
gender: '女',
|
|
|
|
|
|
age: 23,
|
|
|
|
|
|
education: '本科',
|
|
|
|
|
|
department: '市场部',
|
|
|
|
|
|
entry_date: '2024-01-20',
|
|
|
|
|
|
position: '市场专员',
|
|
|
|
|
|
salary: 5500.00,
|
|
|
|
|
|
phone: '13800138004',
|
|
|
|
|
|
email: 'liuyang@mxbc.com',
|
|
|
|
|
|
status: 0,
|
|
|
|
|
|
remark: '已离职',
|
2026-06-25 21:49:55 +08:00
|
|
|
|
// 用户字段(无用户账号)
|
|
|
|
|
|
username: null,
|
|
|
|
|
|
password: null,
|
|
|
|
|
|
user_type: null,
|
|
|
|
|
|
user_status: null,
|
2026-06-24 16:42:13 +08:00
|
|
|
|
created_at: '2024-01-20 09:00:00',
|
|
|
|
|
|
updated_at: '2025-03-01 17:00:00'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 5,
|
|
|
|
|
|
name: '赵敏',
|
|
|
|
|
|
gender: '女',
|
|
|
|
|
|
age: 27,
|
|
|
|
|
|
education: '本科',
|
|
|
|
|
|
department: '财务部',
|
|
|
|
|
|
entry_date: '2023-09-05',
|
|
|
|
|
|
position: '财务会计',
|
|
|
|
|
|
salary: 7000.00,
|
|
|
|
|
|
phone: '13800138005',
|
|
|
|
|
|
email: 'zhaomin@mxbc.com',
|
|
|
|
|
|
status: 1,
|
|
|
|
|
|
remark: '',
|
2026-06-25 21:49:55 +08:00
|
|
|
|
// 用户字段
|
|
|
|
|
|
username: 'zhaomin',
|
|
|
|
|
|
password: '123456',
|
|
|
|
|
|
user_type: 'user',
|
|
|
|
|
|
user_status: '0',
|
2026-06-24 16:42:13 +08:00
|
|
|
|
created_at: '2023-09-05 09:00:00',
|
|
|
|
|
|
updated_at: '2023-09-05 09:00:00'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 6,
|
|
|
|
|
|
name: '陈刚',
|
|
|
|
|
|
gender: '男',
|
|
|
|
|
|
age: 35,
|
|
|
|
|
|
education: '高中',
|
|
|
|
|
|
department: '仓储部',
|
|
|
|
|
|
entry_date: '2022-04-12',
|
|
|
|
|
|
position: '仓库管理员',
|
|
|
|
|
|
salary: 5000.00,
|
|
|
|
|
|
phone: '13800138006',
|
|
|
|
|
|
email: 'chengang@mxbc.com',
|
|
|
|
|
|
status: 1,
|
|
|
|
|
|
remark: '负责原料入库出库',
|
2026-06-25 21:49:55 +08:00
|
|
|
|
// 用户字段(无用户账号)
|
|
|
|
|
|
username: null,
|
|
|
|
|
|
password: null,
|
|
|
|
|
|
user_type: null,
|
|
|
|
|
|
user_status: null,
|
2026-06-24 16:42:13 +08:00
|
|
|
|
created_at: '2022-04-12 09:00:00',
|
|
|
|
|
|
updated_at: '2022-04-12 09:00:00'
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
// 模拟网络延迟
|
|
|
|
|
|
const delay = (ms = 300) => new Promise(r => setTimeout(r, ms))
|
|
|
|
|
|
|
|
|
|
|
|
// Mock API
|
|
|
|
|
|
export const mockEmployeeAPI = {
|
|
|
|
|
|
// 获取列表
|
|
|
|
|
|
async getList(params = {}) {
|
|
|
|
|
|
await delay()
|
|
|
|
|
|
let result = [...mockEmployees]
|
|
|
|
|
|
|
|
|
|
|
|
// 关键词搜索
|
|
|
|
|
|
if (params.keyword) {
|
|
|
|
|
|
const keyword = params.keyword.toLowerCase()
|
|
|
|
|
|
const searchField = params.searchField || '1'
|
|
|
|
|
|
|
|
|
|
|
|
if (searchField === '1') {
|
|
|
|
|
|
// ID:精确匹配
|
|
|
|
|
|
result = result.filter(item => String(item.id) === keyword)
|
|
|
|
|
|
} else if (searchField === '2') {
|
|
|
|
|
|
// 姓名:模糊匹配
|
|
|
|
|
|
result = result.filter(item => item.name.toLowerCase().includes(keyword))
|
|
|
|
|
|
} else if (searchField === '3') {
|
|
|
|
|
|
// 部门:模糊匹配
|
|
|
|
|
|
result = result.filter(item => item.department.toLowerCase().includes(keyword))
|
|
|
|
|
|
} else {
|
|
|
|
|
|
result = result.filter(item =>
|
|
|
|
|
|
String(item.id).includes(keyword) ||
|
|
|
|
|
|
item.name.toLowerCase().includes(keyword) ||
|
|
|
|
|
|
item.department.toLowerCase().includes(keyword)
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 在职状态筛选
|
|
|
|
|
|
if (params.status !== undefined && params.status !== '') {
|
|
|
|
|
|
result = result.filter(item => item.status === Number(params.status))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 部门筛选
|
|
|
|
|
|
if (params.department) {
|
|
|
|
|
|
result = result.filter(item => item.department === params.department)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return { code: 200, data: result, total: result.length }
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 获取详情
|
|
|
|
|
|
async getDetail(id) {
|
|
|
|
|
|
await delay()
|
|
|
|
|
|
const employee = mockEmployees.find(item => item.id === id)
|
|
|
|
|
|
if (employee) {
|
|
|
|
|
|
return { code: 200, data: employee }
|
|
|
|
|
|
}
|
|
|
|
|
|
return { code: 404, message: '员工不存在' }
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 新增
|
|
|
|
|
|
async create(data) {
|
|
|
|
|
|
await delay()
|
|
|
|
|
|
const maxId = mockEmployees.length > 0 ? Math.max(...mockEmployees.map(item => item.id)) : 0
|
|
|
|
|
|
const now = new Date().toISOString().replace('T', ' ').slice(0, 19)
|
|
|
|
|
|
const newEmployee = {
|
|
|
|
|
|
id: maxId + 1,
|
|
|
|
|
|
status: 1,
|
|
|
|
|
|
...data,
|
2026-06-25 21:49:55 +08:00
|
|
|
|
// 用户字段初始为空
|
|
|
|
|
|
username: null,
|
|
|
|
|
|
password: null,
|
|
|
|
|
|
user_type: null,
|
|
|
|
|
|
user_status: null,
|
2026-06-24 16:42:13 +08:00
|
|
|
|
created_at: now,
|
|
|
|
|
|
updated_at: now
|
|
|
|
|
|
}
|
|
|
|
|
|
mockEmployees.push(newEmployee)
|
|
|
|
|
|
return { code: 200, data: newEmployee, message: '新增成功' }
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 更新
|
|
|
|
|
|
async update(id, data) {
|
|
|
|
|
|
await delay()
|
|
|
|
|
|
const index = mockEmployees.findIndex(item => item.id === id)
|
|
|
|
|
|
if (index !== -1) {
|
|
|
|
|
|
mockEmployees[index] = {
|
|
|
|
|
|
...mockEmployees[index],
|
|
|
|
|
|
...data,
|
|
|
|
|
|
updated_at: new Date().toISOString().replace('T', ' ').slice(0, 19)
|
|
|
|
|
|
}
|
|
|
|
|
|
return { code: 200, data: mockEmployees[index], message: '更新成功' }
|
|
|
|
|
|
}
|
|
|
|
|
|
return { code: 404, message: '员工不存在' }
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 删除
|
|
|
|
|
|
async delete(id) {
|
|
|
|
|
|
await delay()
|
|
|
|
|
|
const index = mockEmployees.findIndex(item => item.id === id)
|
|
|
|
|
|
if (index !== -1) {
|
|
|
|
|
|
mockEmployees.splice(index, 1)
|
|
|
|
|
|
return { code: 200, message: '删除成功' }
|
|
|
|
|
|
}
|
|
|
|
|
|
return { code: 404, message: '员工不存在' }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|