员工和用户整合前暂存
This commit is contained in:
41
src/api/employee.js
Normal file
41
src/api/employee.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import axios from 'axios'
|
||||
import { mockEmployeeAPI } from './mock/employee'
|
||||
|
||||
// 开关:true 用 mock,false 用真实接口
|
||||
const USE_MOCK = true
|
||||
|
||||
// axios 实例
|
||||
const request = axios.create({
|
||||
baseURL: '/api',
|
||||
timeout: 5000
|
||||
})
|
||||
|
||||
// 获取员工列表
|
||||
export const getEmployeeList = (params) => {
|
||||
if (USE_MOCK) return mockEmployeeAPI.getList(params)
|
||||
return request.get('/employees', { params }).then(r => r.data)
|
||||
}
|
||||
|
||||
// 获取员工详情
|
||||
export const getEmployeeDetail = (id) => {
|
||||
if (USE_MOCK) return mockEmployeeAPI.getDetail(id)
|
||||
return request.get(`/employees/${id}`).then(r => r.data)
|
||||
}
|
||||
|
||||
// 新增员工
|
||||
export const createEmployee = (data) => {
|
||||
if (USE_MOCK) return mockEmployeeAPI.create(data)
|
||||
return request.post('/employees', data).then(r => r.data)
|
||||
}
|
||||
|
||||
// 更新员工
|
||||
export const updateEmployee = (id, data) => {
|
||||
if (USE_MOCK) return mockEmployeeAPI.update(id, data)
|
||||
return request.put(`/employees/${id}`, data).then(r => r.data)
|
||||
}
|
||||
|
||||
// 删除员工
|
||||
export const deleteEmployeeAPI = (id) => {
|
||||
if (USE_MOCK) return mockEmployeeAPI.delete(id)
|
||||
return request.delete(`/employees/${id}`).then(r => r.data)
|
||||
}
|
||||
@@ -93,6 +93,17 @@ export const mockCustomerAPI = {
|
||||
result = result.filter(item => item.customer_type === params.customer_type)
|
||||
}
|
||||
|
||||
// 地区筛选(省/市/区)
|
||||
if (params.province) {
|
||||
result = result.filter(item => item.province === params.province)
|
||||
}
|
||||
if (params.city) {
|
||||
result = result.filter(item => item.city === params.city)
|
||||
}
|
||||
if (params.district) {
|
||||
result = result.filter(item => item.district === params.district)
|
||||
}
|
||||
|
||||
return { code: 200, data: result, total: result.length }
|
||||
},
|
||||
|
||||
|
||||
204
src/api/mock/employee.js
Normal file
204
src/api/mock/employee.js
Normal file
@@ -0,0 +1,204 @@
|
||||
// 模拟员工数据
|
||||
const mockEmployees = [
|
||||
{
|
||||
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: '负责门店日常运营',
|
||||
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: '',
|
||||
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: '负责系统架构设计',
|
||||
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: '已离职',
|
||||
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: '',
|
||||
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: '负责原料入库出库',
|
||||
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,
|
||||
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: '员工不存在' }
|
||||
}
|
||||
}
|
||||
174
src/api/mock/products.js
Normal file
174
src/api/mock/products.js
Normal file
@@ -0,0 +1,174 @@
|
||||
// 模拟产品数据
|
||||
const mockProducts = [
|
||||
{
|
||||
id: 1,
|
||||
name: '红茶茶叶',
|
||||
type: 'raw_material',
|
||||
quantity: 500,
|
||||
price: 45.00,
|
||||
unit: '斤',
|
||||
specification: '特级红茶 500g/袋',
|
||||
supplier: '福建茶业有限公司',
|
||||
remark: '常温保存,防潮',
|
||||
created_at: '2025-01-10 08:00:00',
|
||||
updated_at: '2025-01-10 08:00:00'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: '奶茶杯',
|
||||
type: 'packaging',
|
||||
quantity: 10000,
|
||||
price: 0.15,
|
||||
unit: '个',
|
||||
specification: '500ml PP材质 透明',
|
||||
supplier: '广州包装制品厂',
|
||||
remark: '',
|
||||
created_at: '2025-02-15 10:30:00',
|
||||
updated_at: '2025-02-15 10:30:00'
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: '制冰机',
|
||||
type: 'equipment',
|
||||
quantity: 5,
|
||||
price: 3500.00,
|
||||
unit: '台',
|
||||
specification: 'SM-50 商用日产50kg',
|
||||
supplier: '深圳冰雪设备有限公司',
|
||||
remark: '含一年保修',
|
||||
created_at: '2025-03-20 14:00:00',
|
||||
updated_at: '2025-03-20 14:00:00'
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: '食品级清洁剂',
|
||||
type: 'cleaning',
|
||||
quantity: 30,
|
||||
price: 28.50,
|
||||
unit: '瓶',
|
||||
specification: '500ml/瓶',
|
||||
supplier: '洁康日化有限公司',
|
||||
remark: '适用于设备表面清洁',
|
||||
created_at: '2025-04-05 09:15:00',
|
||||
updated_at: '2025-04-05 09:15:00'
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
name: '吸管',
|
||||
type: 'packaging',
|
||||
quantity: 20000,
|
||||
price: 0.03,
|
||||
unit: '根',
|
||||
specification: '可降解 250mm',
|
||||
supplier: '广州包装制品厂',
|
||||
remark: '环保可降解材质',
|
||||
created_at: '2025-05-10 16:45:00',
|
||||
updated_at: '2025-05-10 16:45:00'
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
name: '果糖糖浆',
|
||||
type: 'raw_material',
|
||||
quantity: 200,
|
||||
price: 32.00,
|
||||
unit: '瓶',
|
||||
specification: '2.5L/瓶',
|
||||
supplier: '上海糖业贸易有限公司',
|
||||
remark: '开封后冷藏保存',
|
||||
created_at: '2025-06-01 11:00:00',
|
||||
updated_at: '2025-06-01 11:00:00'
|
||||
}
|
||||
]
|
||||
|
||||
// 模拟网络延迟
|
||||
const delay = (ms = 300) => new Promise(r => setTimeout(r, ms))
|
||||
|
||||
// Mock API
|
||||
export const mockProductsAPI = {
|
||||
// 获取列表
|
||||
async getList(params = {}) {
|
||||
await delay()
|
||||
let result = [...mockProducts]
|
||||
|
||||
// 关键词搜索
|
||||
if (params.keyword) {
|
||||
const keyword = params.keyword.toLowerCase()
|
||||
const searchField = params.searchField || '2'
|
||||
|
||||
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.supplier.toLowerCase().includes(keyword))
|
||||
} else {
|
||||
result = result.filter(item =>
|
||||
String(item.id).includes(keyword) ||
|
||||
item.name.toLowerCase().includes(keyword) ||
|
||||
item.supplier.toLowerCase().includes(keyword)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 产品类型筛选
|
||||
if (params.type) {
|
||||
result = result.filter(item => item.type === params.type)
|
||||
}
|
||||
|
||||
return { code: 200, data: result, total: result.length }
|
||||
},
|
||||
|
||||
// 获取详情
|
||||
async getDetail(id) {
|
||||
await delay()
|
||||
const product = mockProducts.find(item => item.id === id)
|
||||
if (product) {
|
||||
return { code: 200, data: product }
|
||||
}
|
||||
return { code: 404, message: '产品不存在' }
|
||||
},
|
||||
|
||||
// 新增
|
||||
async create(data) {
|
||||
await delay()
|
||||
const maxId = mockProducts.length > 0 ? Math.max(...mockProducts.map(item => item.id)) : 0
|
||||
const now = new Date().toISOString().replace('T', ' ').slice(0, 19)
|
||||
const newProduct = {
|
||||
id: maxId + 1,
|
||||
...data,
|
||||
created_at: now,
|
||||
updated_at: now
|
||||
}
|
||||
mockProducts.push(newProduct)
|
||||
return { code: 200, data: newProduct, message: '新增成功' }
|
||||
},
|
||||
|
||||
// 更新
|
||||
async update(id, data) {
|
||||
await delay()
|
||||
const index = mockProducts.findIndex(item => item.id === id)
|
||||
if (index !== -1) {
|
||||
mockProducts[index] = {
|
||||
...mockProducts[index],
|
||||
...data,
|
||||
updated_at: new Date().toISOString().replace('T', ' ').slice(0, 19)
|
||||
}
|
||||
return { code: 200, data: mockProducts[index], message: '更新成功' }
|
||||
}
|
||||
return { code: 404, message: '产品不存在' }
|
||||
},
|
||||
|
||||
// 删除
|
||||
async delete(id) {
|
||||
await delay()
|
||||
const index = mockProducts.findIndex(item => item.id === id)
|
||||
if (index !== -1) {
|
||||
mockProducts.splice(index, 1)
|
||||
return { code: 200, message: '删除成功' }
|
||||
}
|
||||
return { code: 404, message: '产品不存在' }
|
||||
}
|
||||
}
|
||||
145
src/api/mock/service.js
Normal file
145
src/api/mock/service.js
Normal file
@@ -0,0 +1,145 @@
|
||||
// 模拟售后数据
|
||||
const mockServices = [
|
||||
{
|
||||
id: 1,
|
||||
customer_id: 1,
|
||||
feedback: '收到的奶茶杯有破损,需要更换',
|
||||
employee_id: 2,
|
||||
handle_method: '同意补发,已安排快递寄出新品',
|
||||
handle_status: '已完成',
|
||||
service_date: '2025-03-15',
|
||||
remark: '客户态度良好',
|
||||
created_at: '2025-03-15 10:30:00',
|
||||
updated_at: '2025-03-16 14:00:00'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
customer_id: 3,
|
||||
feedback: '制冰机出现异响,疑似零件松动',
|
||||
employee_id: null,
|
||||
handle_method: null,
|
||||
handle_status: '待处理',
|
||||
service_date: '2025-05-20',
|
||||
remark: '紧急,客户反映影响营业',
|
||||
created_at: '2025-05-20 09:00:00',
|
||||
updated_at: '2025-05-20 09:00:00'
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
customer_id: 2,
|
||||
feedback: '订购的红茶茶叶与样品不符,颜色偏深',
|
||||
employee_id: 3,
|
||||
handle_method: '已联系供应商核实,确认为新批次色差,品质无问题',
|
||||
handle_status: '处理中',
|
||||
service_date: '2025-06-01',
|
||||
remark: '等待供应商书面说明',
|
||||
created_at: '2025-06-01 14:20:00',
|
||||
updated_at: '2025-06-02 10:00:00'
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
customer_id: 4,
|
||||
feedback: '果糖糖浆保质期标注模糊,要求退换',
|
||||
employee_id: 1,
|
||||
handle_method: '已同意退货,安排换货处理',
|
||||
handle_status: '已完成',
|
||||
service_date: '2025-06-10',
|
||||
remark: '',
|
||||
created_at: '2025-06-10 11:00:00',
|
||||
updated_at: '2025-06-12 16:30:00'
|
||||
}
|
||||
]
|
||||
|
||||
// 模拟网络延迟
|
||||
const delay = (ms = 300) => new Promise(r => setTimeout(r, ms))
|
||||
|
||||
// Mock API
|
||||
export const mockServiceAPI = {
|
||||
// 获取列表
|
||||
async getList(params = {}) {
|
||||
await delay()
|
||||
let result = [...mockServices]
|
||||
|
||||
// 关键词搜索
|
||||
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') {
|
||||
// 客户ID:精确匹配
|
||||
result = result.filter(item => String(item.customer_id) === keyword)
|
||||
} else if (searchField === '3') {
|
||||
// 反馈内容:模糊匹配
|
||||
result = result.filter(item => item.feedback.toLowerCase().includes(keyword))
|
||||
} else {
|
||||
result = result.filter(item =>
|
||||
String(item.id).includes(keyword) ||
|
||||
String(item.customer_id).includes(keyword) ||
|
||||
item.feedback.toLowerCase().includes(keyword)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 处理状态筛选
|
||||
if (params.handle_status) {
|
||||
result = result.filter(item => item.handle_status === params.handle_status)
|
||||
}
|
||||
|
||||
return { code: 200, data: result, total: result.length }
|
||||
},
|
||||
|
||||
// 获取详情
|
||||
async getDetail(id) {
|
||||
await delay()
|
||||
const service = mockServices.find(item => item.id === id)
|
||||
if (service) {
|
||||
return { code: 200, data: service }
|
||||
}
|
||||
return { code: 404, message: '售后记录不存在' }
|
||||
},
|
||||
|
||||
// 新增
|
||||
async create(data) {
|
||||
await delay()
|
||||
const maxId = mockServices.length > 0 ? Math.max(...mockServices.map(item => item.id)) : 0
|
||||
const now = new Date().toISOString().replace('T', ' ').slice(0, 19)
|
||||
const newService = {
|
||||
id: maxId + 1,
|
||||
handle_status: '待处理',
|
||||
...data,
|
||||
created_at: now,
|
||||
updated_at: now
|
||||
}
|
||||
mockServices.push(newService)
|
||||
return { code: 200, data: newService, message: '新增成功' }
|
||||
},
|
||||
|
||||
// 更新
|
||||
async update(id, data) {
|
||||
await delay()
|
||||
const index = mockServices.findIndex(item => item.id === id)
|
||||
if (index !== -1) {
|
||||
mockServices[index] = {
|
||||
...mockServices[index],
|
||||
...data,
|
||||
updated_at: new Date().toISOString().replace('T', ' ').slice(0, 19)
|
||||
}
|
||||
return { code: 200, data: mockServices[index], message: '更新成功' }
|
||||
}
|
||||
return { code: 404, message: '售后记录不存在' }
|
||||
},
|
||||
|
||||
// 删除
|
||||
async delete(id) {
|
||||
await delay()
|
||||
const index = mockServices.findIndex(item => item.id === id)
|
||||
if (index !== -1) {
|
||||
mockServices.splice(index, 1)
|
||||
return { code: 200, message: '删除成功' }
|
||||
}
|
||||
return { code: 404, message: '售后记录不存在' }
|
||||
}
|
||||
}
|
||||
141
src/api/mock/user.js
Normal file
141
src/api/mock/user.js
Normal file
@@ -0,0 +1,141 @@
|
||||
// 模拟用户数据
|
||||
const mockUsers = [
|
||||
{
|
||||
id: 1,
|
||||
username: 'admin',
|
||||
password: '123456',
|
||||
name: '系统管理员',
|
||||
user_type: 'admin',
|
||||
status: '1',
|
||||
createdate: '2025-01-10 08:00:00'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
username: 'zhangsan',
|
||||
password: '123456',
|
||||
name: '张三',
|
||||
user_type: 'user',
|
||||
status: '1',
|
||||
createdate: '2025-02-15 10:30:00'
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
username: 'lisi',
|
||||
password: '123456',
|
||||
name: '李四',
|
||||
user_type: 'user',
|
||||
status: '0',
|
||||
createdate: '2025-03-20 14:00:00'
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
username: 'wangwu',
|
||||
password: '123456',
|
||||
name: '王五',
|
||||
user_type: 'admin',
|
||||
status: '1',
|
||||
createdate: '2025-04-05 09:15:00'
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
username: 'zhaoliu',
|
||||
password: '123456',
|
||||
name: '赵六',
|
||||
user_type: 'user',
|
||||
status: '0',
|
||||
createdate: '2025-05-10 16:45:00'
|
||||
}
|
||||
]
|
||||
|
||||
// 模拟网络延迟
|
||||
const delay = (ms = 300) => new Promise(r => setTimeout(r, ms))
|
||||
|
||||
// Mock API
|
||||
export const mockUserAPI = {
|
||||
// 获取列表
|
||||
async getList(params = {}) {
|
||||
await delay()
|
||||
let result = [...mockUsers]
|
||||
|
||||
// 关键词搜索
|
||||
if (params.keyword) {
|
||||
const keyword = params.keyword.toLowerCase()
|
||||
const searchField = params.searchField || '1'
|
||||
|
||||
if (searchField === '2') {
|
||||
// 编号:精确匹配
|
||||
result = result.filter(item => String(item.id) === keyword)
|
||||
} else if (searchField === '1') {
|
||||
// 用户名:模糊匹配
|
||||
result = result.filter(item => item.username.includes(keyword))
|
||||
} else if (searchField === '3') {
|
||||
// 真实姓名:模糊匹配
|
||||
result = result.filter(item => item.name.includes(keyword))
|
||||
} else {
|
||||
// 默认:模糊匹配所有字段
|
||||
result = result.filter(item =>
|
||||
String(item.id).includes(keyword) ||
|
||||
item.username.includes(keyword) ||
|
||||
item.name.includes(keyword)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 用户类型筛选
|
||||
if (params.user_type) {
|
||||
result = result.filter(item => item.user_type === params.user_type)
|
||||
}
|
||||
|
||||
// 用户状态筛选
|
||||
if (params.status) {
|
||||
result = result.filter(item => item.status === params.status)
|
||||
}
|
||||
|
||||
return { code: 200, data: result, total: result.length }
|
||||
},
|
||||
|
||||
// 获取详情
|
||||
async getDetail(id) {
|
||||
await delay()
|
||||
const user = mockUsers.find(item => item.id === id)
|
||||
if (user) {
|
||||
return { code: 200, data: user }
|
||||
}
|
||||
return { code: 404, message: '用户不存在' }
|
||||
},
|
||||
|
||||
// 新增
|
||||
async create(data) {
|
||||
await delay()
|
||||
const maxId = mockUsers.length > 0 ? Math.max(...mockUsers.map(item => item.id)) : 0
|
||||
const newUser = {
|
||||
id: maxId + 1,
|
||||
...data,
|
||||
createdate: new Date().toISOString().replace('T', ' ').slice(0, 19)
|
||||
}
|
||||
mockUsers.push(newUser)
|
||||
return { code: 200, data: newUser, message: '新增成功' }
|
||||
},
|
||||
|
||||
// 更新
|
||||
async update(id, data) {
|
||||
await delay()
|
||||
const index = mockUsers.findIndex(item => item.id === id)
|
||||
if (index !== -1) {
|
||||
mockUsers[index] = { ...mockUsers[index], ...data }
|
||||
return { code: 200, data: mockUsers[index], message: '更新成功' }
|
||||
}
|
||||
return { code: 404, message: '用户不存在' }
|
||||
},
|
||||
|
||||
// 删除
|
||||
async delete(id) {
|
||||
await delay()
|
||||
const index = mockUsers.findIndex(item => item.id === id)
|
||||
if (index !== -1) {
|
||||
mockUsers.splice(index, 1)
|
||||
return { code: 200, message: '删除成功' }
|
||||
}
|
||||
return { code: 404, message: '用户不存在' }
|
||||
}
|
||||
}
|
||||
41
src/api/products.js
Normal file
41
src/api/products.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import axios from 'axios'
|
||||
import { mockProductsAPI } from './mock/products'
|
||||
|
||||
// 开关:true 用 mock,false 用真实接口
|
||||
const USE_MOCK = true
|
||||
|
||||
// axios 实例
|
||||
const request = axios.create({
|
||||
baseURL: '/api',
|
||||
timeout: 5000
|
||||
})
|
||||
|
||||
// 获取产品列表
|
||||
export const getProductsList = (params) => {
|
||||
if (USE_MOCK) return mockProductsAPI.getList(params)
|
||||
return request.get('/products', { params }).then(r => r.data)
|
||||
}
|
||||
|
||||
// 获取产品详情
|
||||
export const getProductsDetail = (id) => {
|
||||
if (USE_MOCK) return mockProductsAPI.getDetail(id)
|
||||
return request.get(`/products/${id}`).then(r => r.data)
|
||||
}
|
||||
|
||||
// 新增产品
|
||||
export const createProducts = (data) => {
|
||||
if (USE_MOCK) return mockProductsAPI.create(data)
|
||||
return request.post('/products', data).then(r => r.data)
|
||||
}
|
||||
|
||||
// 更新产品
|
||||
export const updateProducts = (id, data) => {
|
||||
if (USE_MOCK) return mockProductsAPI.update(id, data)
|
||||
return request.put(`/products/${id}`, data).then(r => r.data)
|
||||
}
|
||||
|
||||
// 删除产品
|
||||
export const deleteProductsAPI = (id) => {
|
||||
if (USE_MOCK) return mockProductsAPI.delete(id)
|
||||
return request.delete(`/products/${id}`).then(r => r.data)
|
||||
}
|
||||
41
src/api/service.js
Normal file
41
src/api/service.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import axios from 'axios'
|
||||
import { mockServiceAPI } from './mock/service'
|
||||
|
||||
// 开关:true 用 mock,false 用真实接口
|
||||
const USE_MOCK = true
|
||||
|
||||
// axios 实例
|
||||
const request = axios.create({
|
||||
baseURL: '/api',
|
||||
timeout: 5000
|
||||
})
|
||||
|
||||
// 获取售后列表
|
||||
export const getServiceList = (params) => {
|
||||
if (USE_MOCK) return mockServiceAPI.getList(params)
|
||||
return request.get('/after-sales', { params }).then(r => r.data)
|
||||
}
|
||||
|
||||
// 获取售后详情
|
||||
export const getServiceDetail = (id) => {
|
||||
if (USE_MOCK) return mockServiceAPI.getDetail(id)
|
||||
return request.get(`/after-sales/${id}`).then(r => r.data)
|
||||
}
|
||||
|
||||
// 新增售后
|
||||
export const createService = (data) => {
|
||||
if (USE_MOCK) return mockServiceAPI.create(data)
|
||||
return request.post('/after-sales', data).then(r => r.data)
|
||||
}
|
||||
|
||||
// 更新售后
|
||||
export const updateService = (id, data) => {
|
||||
if (USE_MOCK) return mockServiceAPI.update(id, data)
|
||||
return request.put(`/after-sales/${id}`, data).then(r => r.data)
|
||||
}
|
||||
|
||||
// 删除售后
|
||||
export const deleteServiceAPI = (id) => {
|
||||
if (USE_MOCK) return mockServiceAPI.delete(id)
|
||||
return request.delete(`/after-sales/${id}`).then(r => r.data)
|
||||
}
|
||||
41
src/api/user.js
Normal file
41
src/api/user.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import axios from 'axios'
|
||||
import { mockUserAPI } from './mock/user'
|
||||
|
||||
// 开关:true 用 mock,false 用真实接口
|
||||
const USE_MOCK = true
|
||||
|
||||
// axios 实例
|
||||
const request = axios.create({
|
||||
baseURL: '/api',
|
||||
timeout: 5000
|
||||
})
|
||||
|
||||
// 获取用户列表
|
||||
export const getUserList = (params) => {
|
||||
if (USE_MOCK) return mockUserAPI.getList(params)
|
||||
return request.get('/users', { params }).then(r => r.data)
|
||||
}
|
||||
|
||||
// 获取用户详情
|
||||
export const getUserDetail = (id) => {
|
||||
if (USE_MOCK) return mockUserAPI.getDetail(id)
|
||||
return request.get(`/users/${id}`).then(r => r.data)
|
||||
}
|
||||
|
||||
// 新增用户
|
||||
export const createUser = (data) => {
|
||||
if (USE_MOCK) return mockUserAPI.create(data)
|
||||
return request.post('/users', data).then(r => r.data)
|
||||
}
|
||||
|
||||
// 更新用户
|
||||
export const updateUser = (id, data) => {
|
||||
if (USE_MOCK) return mockUserAPI.update(id, data)
|
||||
return request.put(`/users/${id}`, data).then(r => r.data)
|
||||
}
|
||||
|
||||
// 删除用户
|
||||
export const deleteUserAPI = (id) => {
|
||||
if (USE_MOCK) return mockUserAPI.delete(id)
|
||||
return request.delete(`/users/${id}`).then(r => r.data)
|
||||
}
|
||||
Reference in New Issue
Block a user