This commit is contained in:
2025-09-16 22:11:19 +08:00
parent 562ec4abf9
commit 46c5682960
65 changed files with 1997 additions and 56 deletions

View File

@@ -12,3 +12,16 @@ const storageShopId = typeof uni !== 'undefined' ? (uni.getStorageSync('SHOP_ID'
export const SHOP_ID = Number(envShopId || storageShopId || 1);
// 默认用户(可移除):
// - 用途:开发/演示环境自动将用户固定为“张老板”id=2
// - 开关优先级:环境变量 > 本地存储 > 默认值
// - 生产默认关闭false开发可通过本地存储或环境变量开启
const envEnableDefaultUser = (typeof process !== 'undefined' && process.env && (process.env.VITE_APP_ENABLE_DEFAULT_USER || process.env.ENABLE_DEFAULT_USER)) || '';
const storageEnableDefaultUser = typeof uni !== 'undefined' ? (uni.getStorageSync('ENABLE_DEFAULT_USER') || '') : '';
export const ENABLE_DEFAULT_USER = String(envEnableDefaultUser || storageEnableDefaultUser || 'false').toLowerCase() === 'true';
const envDefaultUserId = (typeof process !== 'undefined' && process.env && (process.env.VITE_APP_DEFAULT_USER_ID || process.env.DEFAULT_USER_ID)) || '';
const storageDefaultUserId = typeof uni !== 'undefined' ? (uni.getStorageSync('DEFAULT_USER_ID') || '') : '';
export const DEFAULT_USER_ID = Number(envDefaultUserId || storageDefaultUserId || 2);

View File

@@ -0,0 +1,18 @@
// 统一常量配置:其他收入/支出分类,禁止在业务中硬编码
export const INCOME_CATEGORIES = [
{ key: 'sale_income', label: '销售收入' },
{ key: 'operation_income', label: '经营所得' },
{ key: 'interest_income', label: '利息收入' },
{ key: 'investment_income', label: '投资收入' },
{ key: 'other_income', label: '其它收入' }
]
export const EXPENSE_CATEGORIES = [
{ key: 'operation_expense', label: '经营支出' },
{ key: 'office_supplies', label: '办公用品' },
{ key: 'rent', label: '房租' },
{ key: 'interest_expense', label: '利息支出' },
{ key: 'other_expense', label: '其它支出' }
]

View File

@@ -1,4 +1,4 @@
import { API_BASE_URL, SHOP_ID } from './config.js'
import { API_BASE_URL, SHOP_ID, ENABLE_DEFAULT_USER, DEFAULT_USER_ID } from './config.js'
function buildUrl(path) {
if (!path) return API_BASE_URL
@@ -8,11 +8,33 @@ function buildUrl(path) {
export function get(path, params = {}) {
return new Promise((resolve, reject) => {
const headers = { 'X-Shop-Id': SHOP_ID }
if (ENABLE_DEFAULT_USER && DEFAULT_USER_ID) headers['X-User-Id'] = DEFAULT_USER_ID
uni.request({
url: buildUrl(path),
method: 'GET',
data: params,
header: { 'X-Shop-Id': SHOP_ID },
header: headers,
success: (res) => {
const { statusCode, data } = res
if (statusCode >= 200 && statusCode < 300) return resolve(data)
reject(new Error('HTTP ' + statusCode))
},
fail: (err) => reject(err)
})
})
}
export function post(path, body = {}) {
return new Promise((resolve, reject) => {
const headers = { 'Content-Type': 'application/json', 'X-Shop-Id': SHOP_ID }
if (ENABLE_DEFAULT_USER && DEFAULT_USER_ID) headers['X-User-Id'] = DEFAULT_USER_ID
uni.request({
url: buildUrl(path),
method: 'POST',
data: body,
header: headers,
success: (res) => {
const { statusCode, data } = res
if (statusCode >= 200 && statusCode < 300) return resolve(data)