Signed-off-by: 吴文峰 <kevin@lmve.net>

This commit is contained in:
2026-06-09 18:59:16 +08:00
parent 33469dc746
commit 51f3f917f9
62 changed files with 12690 additions and 1 deletions
+28
View File
@@ -0,0 +1,28 @@
import api from './index.js'
export const customerApi = {
// 客户列表
list(params = {}) {
return api.post('/customer/list', params)
},
// 客户详情
get(id) {
return api.post('/customer/get', { id })
},
// 新增客户
add(data) {
return api.post('/customer/add', data)
},
// 编辑客户
update(data) {
return api.post('/customer/update', data)
},
// 删除客户
delete(id) {
return api.post('/customer/delete', { id })
}
}
+162
View File
@@ -0,0 +1,162 @@
/**
* API 请求封装
* 基于 uni.request,统一处理 Cookie 认证和错误
*/
import { useConfigStore } from '../stores/config'
// Storage Keys
const STORAGE_KEY_COOKIE_SESSION = 'userCookieSession'
// 错误码定义
const ERR_COOKIE_EXPIRED = 'userCookieError'
/**
* 获取 API 基础地址
*/
function getBaseUrl() {
const configStore = useConfigStore()
return configStore.getApiBaseUrl()
}
/**
* 获取保存的 Cookie 值
*/
function getCookie() {
try {
// 优先从 storage 读取(避免 Pinia 初始化时序问题)
const cookieStr = uni.getStorageSync(STORAGE_KEY_COOKIE_SESSION)
if (cookieStr) {
const cookie = JSON.parse(cookieStr)
return cookie?.Value ?? ''
}
} catch {
// ignore
}
return ''
}
/**
* 请求封装 - 统一错误处理
*/
function request(options) {
return new Promise((resolve, reject) => {
const baseUrl = getBaseUrl()
if (!baseUrl) {
reject({ errCode: -1, message: 'API地址未配置' })
return
}
// GET 请求不注入 cookiePOST 请求注入 cookie
let data = options.data || {}
if (options.method === 'POST') {
const cookie = getCookie()
// 后端期望格式: { data: {...业务数据}, userCookieValue: "xxx" }
data = {
data: data, // 业务数据包装在 data 字段
userCookieValue: cookie || undefined
}
}
uni.request({
url: baseUrl + options.path,
method: options.method || 'GET',
data,
header: {
'Content-Type': 'application/json'
},
timeout: options.timeout || 10000,
success: (res) => {
const data = res.data
// 检查 Cookie 过期
if (data?.err_code === ERR_COOKIE_EXPIRED || data?.err_code === -44) {
// 清除存储的 Cookie
uni.removeStorageSync(STORAGE_KEY_COOKIE_SESSION)
uni.showToast({ title: '登录已过期,请重新登录', icon: 'none' })
reject({ errCode: -44, message: '登录已过期' })
return
}
if (res.statusCode === 200) {
resolve({
errCode: data?.err_code === 0 ? 0 : -1,
data: data?.return || null,
raw: data
})
} else {
uni.showToast({ title: '服务异常', icon: 'none' })
reject({ errCode: -1, message: '服务异常' })
}
},
fail: (err) => {
uni.showToast({ title: '网络错误', icon: 'none' })
reject({ errCode: -2, message: '网络错误', detail: err })
}
})
})
}
/**
* API 接口汇总
*/
export const api = {
/**
* GET 请求(不需要认证)
*/
get(path, data = {}) {
return request({
path,
method: 'GET',
data
})
},
/**
* POST JSON 请求(需要认证)
*/
post(path, data = {}) {
return request({
path,
method: 'POST',
data // 业务数据,会被包装成 { data, userCookieValue }
})
},
/**
* POST FormData(文件上传)
*/
upload(path, fileData) {
return new Promise((resolve, reject) => {
const baseUrl = getBaseUrl()
const cookie = getCookie()
uni.uploadFile({
url: baseUrl + path,
filePath: fileData.uri,
name: fileData.name || 'file',
formData: {
cookie: cookie || ''
},
success: (res) => {
try {
const data = JSON.parse(res.data)
resolve({
errCode: data?.err_code === 0 ? 0 : -1,
data: data?.return || null,
raw: data
})
} catch {
reject({ errCode: -1, message: '解析响应失败' })
}
},
fail: (err) => {
uni.showToast({ title: '上传失败', icon: 'none' })
reject({ errCode: -2, message: '上传失败', detail: err })
}
})
})
}
}
export default api
+38
View File
@@ -0,0 +1,38 @@
/**
* 采购订单 API
*/
import api from './index.js'
export const purchaseApi = {
// 获取订单列表
getOrders(data = {}) {
return api.post('/purchase/getorders', data)
},
// 获取订单详情
getOrder(data = {}) {
return api.post('/purchase/getorder', data)
},
// 获取订单数量统计
getOrderCount() {
return api.post('/purchase/getordercount', {})
},
// 更新订单状态
updateOrderStatus(data = {}) {
return api.post('/purchase/updatestatus', data)
},
// 新增订单
addOrder(data = {}) {
return api.post('/purchase/addorder', data)
},
// 更新订单
updateOrder(data = {}) {
return api.post('/purchase/updateorder', data)
}
}
export default purchaseApi
+4
View File
@@ -0,0 +1,4 @@
import { useConfigStore } from '@/stores/config'
const useConfig=useConfigStore()
+28
View File
@@ -0,0 +1,28 @@
/**
* 日程管理 API
*/
import api from './index.js'
export const scheduleApi = {
// 获取日程列表
getEvents(data = {}) {
return api.post('/schedule/getevents', data)
},
// 新增日程
addEvent(data = {}) {
return api.post('/schedule/addevent', data)
},
// 编辑日程
editEvent(data = {}) {
return api.post('/schedule/editevent', data)
},
// 删除日程
deleteEvent(data = {}) {
return api.post('/schedule/deleevent', data)
}
}
export default scheduleApi
+86
View File
@@ -0,0 +1,86 @@
/**
* 用户相关 API
*/
import api from './index'
export const userApi = {
/**
* 用户登录
* @param {string} username - 用户名
* @param {string} password - 密码
* @param {boolean} remember - 是否记住登录
* @returns {Promise<{errCode, data: {cookie}}>}
*/
login(username, password, remember = true) {
return api.post('/users/login', {
username,
password,
remember
})
},
/**
* 用户注册
* @param {string} username - 用户名
* @param {string} email - 邮箱
* @param {string} password - 密码
*/
register(username, email, password) {
return api.post('/users/register', {
username,
useremail: email,
userpass: password
})
},
/**
* 获取当前用户信息
* @returns {Promise<{errCode, data: {user, userInfo}}>}
*/
getUserInfo() {
return api.post('/users/getinfo', {})
},
/**
* 修改密码
* @param {string} oldPass - 旧密码
* @param {string} newPass - 新密码
*/
changePassword(oldPass, newPass) {
return api.post('/users/changePassword', {
oldpass: oldPass,
newpass: newPass
})
},
/**
* 修改邮箱
* @param {string} newEmail - 新邮箱
*/
changeEmail(newEmail) {
return api.post('/users/changeEmail', {
newemail: newEmail
})
},
/**
* 更新用户信息
* @param {Object} data - 用户信息 { username, remark, birthday }
*/
updateInfo(data) {
return api.post('/users/updateInfo', data)
},
/**
* 上传头像
* @param {string} fileUri - 文件本地路径
*/
updateAvatar(fileUri) {
return api.upload('/users/updateAvatar', {
name: 'file',
uri: fileUri
})
}
}
export default userApi
+13
View File
@@ -0,0 +1,13 @@
/**
* 用户信息 API
*/
import api from './index.js'
export const usersApi = {
// 通过用户ID获取用户信息(GET 请求)
getUserInfoFromUserID(userID) {
return api.get('/users/getuserinfo/' + userID)
}
}
export default usersApi
+66
View File
@@ -0,0 +1,66 @@
import api from './index.js'
export const warehouseApi = {
// 获取容器列表
listContainer(params = {}) {
return api.post('/warehouse/list_container', params)
},
// 获取容器详情
getContainer(id) {
return api.post('/warehouse/get_container', { id })
},
// 新增容器
addContainer(data) {
return api.post('/warehouse/add_container', data)
},
// 更新容器
updateContainer(data) {
return api.post('/warehouse/update_container', data)
},
// 删除容器
deleteContainer(id) {
return api.post('/warehouse/delete_container', { id })
},
// 获取物品列表
listItem(params = {}) {
return api.post('/warehouse/list_item', params)
},
// 获取物品详情
getItem(id) {
return api.post('/warehouse/get_item', { id })
},
// 新增物品
addItem(data) {
return api.post('/warehouse/add_item', data)
},
// 更新物品
updateItem(data) {
return api.post('/warehouse/update_item', data)
},
// 删除物品
deleteItem(id) {
return api.post('/warehouse/delete_item', { id })
},
// 移动物品
moveItem(id, containerId) {
return api.post('/warehouse/move_item', {
item_id: id,
new_container: containerId
})
},
// 获取仓库统计
getStats() {
return api.post('/warehouse/get_stats', {})
}
}
+43
View File
@@ -0,0 +1,43 @@
import api from './index.js'
export const workOrderApi = {
// 获取工单列表
list(params = {}) {
return api.post('/work_order/list', params)
},
// 获取工单详情
get(id) {
return api.post('/work_order/get', { id })
},
// 获取工单统计
getCount() {
return api.post('/work_order/count', {})
},
// 新增工单
add(data) {
return api.post('/work_order/add', data)
},
// 更新工单
update(data) {
return api.post('/work_order/update', data)
},
// 删除工单
delete(id) {
return api.post('/work_order/delete', { id })
},
// 提交进度
commit(data) {
return api.post('/work_order/commit', data)
},
// 搜索采购订单
searchPurchaseOrders(query, limit = 10) {
return api.post('/work_order/search_purchase_orders', { search: query, limit })
}
}