MarketingSystemDataExportTool/web/modules/config.js

322 lines
8.0 KiB
JavaScript

/**
* 配置模块 - 集中管理常量、映射和配置
* @module config
*/
// ==================== 系统常量 ====================
/**
* 系统常量配置
*/
const CONSTANTS = {
// 轮询间隔(毫秒)
JOBS_POLL_INTERVAL: 1000,
// 树形选择器渲染延迟(毫秒)
TREE_RENDER_DELAY: 100,
// 编辑模式树渲染延迟(毫秒)
TREE_EDIT_RENDER_DELAY: 300,
// 对话框最小宽度
DIALOG_MIN_WIDTH: 500,
// 对话框最大宽度
DIALOG_MAX_WIDTH: 1400,
// 默认对话框宽度
DIALOG_DEFAULT_WIDTH: 900,
// 默认编辑对话框宽度
DIALOG_EDIT_DEFAULT_WIDTH: 900
};
// ==================== 数据源配置 ====================
/**
* 数据源定义
* @type {Object<string, {label: string, mainTable: string, orderTypes: Array}>}
*/
const DATASOURCE_CONFIG = {
marketing: {
label: '营销系统',
mainTable: 'order',
orderTypes: [
{ label: '直充卡密', value: 1 },
{ label: '立减金', value: 2 },
{ label: '红包', value: 3 }
],
defaultOrderType: 1
},
ymt: {
label: '易码通',
mainTable: 'order_info',
orderTypes: [
{ label: '直充卡密', value: 2 },
{ label: '立减金', value: 3 },
{ label: '红包', value: 1 }
],
defaultOrderType: 2
}
};
/**
* 获取数据源选项列表
* @returns {Array<{label: string, value: string}>}
*/
const getDatasourceOptions = () => {
return Object.entries(DATASOURCE_CONFIG).map(([value, config]) => ({
label: config.label,
value
}));
};
/**
* 获取数据源标签
* @param {string} datasource - 数据源标识
* @returns {string} 数据源标签
*/
const getDatasourceLabel = (datasource) => {
return DATASOURCE_CONFIG[datasource]?.label || datasource || '';
};
/**
* 获取数据源的主表名
* @param {string} datasource - 数据源标识
* @returns {string} 主表名
*/
const getMainTable = (datasource) => {
return DATASOURCE_CONFIG[datasource]?.mainTable || 'order';
};
/**
* 获取订单类型选项
* @param {string} datasource - 数据源标识
* @returns {Array<{label: string, value: number}>} 订单类型选项
*/
const getOrderTypeOptions = (datasource) => {
return DATASOURCE_CONFIG[datasource]?.orderTypes || [];
};
/**
* 获取默认订单类型
* @param {string} datasource - 数据源标识
* @returns {number} 默认订单类型
*/
const getDefaultOrderType = (datasource) => {
return DATASOURCE_CONFIG[datasource]?.defaultOrderType || 1;
};
/**
* 获取订单类型标签
* @param {string} datasource - 数据源标识
* @param {number} typeValue - 类型值
* @returns {string} 类型标签
*/
const getOrderTypeLabel = (datasource, typeValue) => {
const types = DATASOURCE_CONFIG[datasource]?.orderTypes || [];
const found = types.find(t => t.value === typeValue);
return found?.label || '';
};
// ==================== 表标签映射 ====================
/**
* 默认表标签映射(当后端未返回时使用)
*/
const DEFAULT_TABLE_LABELS = {
order: '订单主表',
order_info: '订单主表',
order_detail: '订单详情',
order_cash: '红包订单',
order_voucher: '立减金订单',
order_digit: '直充卡密订单',
plan: '活动计划',
key_batch: 'key批次',
code_batch: '兑换码批次',
voucher: '立减金',
voucher_batch: '立减金批次',
merchant_key_send: '开放平台发放记录',
merchant: '客户',
activity: '活动',
goods_voucher_batch: '立减金批次表',
goods_voucher_subject_config: '立减金主体配置'
};
// ==================== 表关联配置 ====================
/**
* 营销系统表关联结构
* 定义了从主表到各子表的路径关系
*/
const MARKETING_TABLE_RELATIONS = {
order: { path: [] },
order_detail: { path: ['order_detail'] },
plan: { path: ['plan'] },
key_batch: { path: ['plan', 'key_batch'] },
code_batch: { path: ['plan', 'key_batch', 'code_batch'] },
order_voucher: { path: ['order_voucher'] },
voucher: { path: ['order_voucher', 'voucher'] },
voucher_batch: { path: ['order_voucher', 'voucher', 'voucher_batch'] },
order_cash: { path: ['order_cash'] },
merchant_key_send: { path: ['merchant_key_send'] }
};
/**
* 易码通表关联结构
*/
const YMT_TABLE_RELATIONS = {
order: { path: [] },
order_info: { path: [] },
merchant: { path: ['merchant'] },
activity: { path: ['activity'] },
order_digit: { path: ['order_digit'] },
order_voucher: { path: ['order_voucher'] },
order_cash: { path: ['order_cash'] },
goods_voucher_batch: { path: ['goods_voucher_batch'] },
goods_voucher_subject_config: { path: ['goods_voucher_subject_config'] }
};
/**
* 获取表关联配置
* @param {string} datasource - 数据源标识
* @returns {Object} 表关联配置
*/
const getTableRelations = (datasource) => {
return datasource === 'ymt' ? YMT_TABLE_RELATIONS : MARKETING_TABLE_RELATIONS;
};
// ==================== 默认字段配置 ====================
/**
* 各数据源的默认字段列表
*/
const DEFAULT_FIELDS = {
marketing: [
'order.order_number',
'order.creator',
'order.out_trade_no',
'order.type',
'order.status',
'order.contract_price',
'order.num',
'order.total',
'order.pay_amount',
'order.create_time'
],
ymt: [
'order_info.order_number',
'order_info.creator',
'order_info.out_trade_no',
'order_info.type',
'order_info.status',
'order_info.contract_price',
'order_info.num',
'order_info.pay_amount',
'order_info.create_time'
]
};
/**
* 获取默认字段列表
* @param {string} datasource - 数据源标识
* @returns {string[]} 默认字段列表
*/
const getDefaultFields = (datasource) => {
return DEFAULT_FIELDS[datasource] || DEFAULT_FIELDS.marketing;
};
// ==================== 表单选项配置 ====================
/**
* 可见性选项
*/
const VISIBILITY_OPTIONS = [
{ label: '个人', value: 'private' },
{ label: '公共', value: 'public' }
];
/**
* 文件格式选项
*/
const FORMAT_OPTIONS = [
{ label: 'XLSX', value: 'xlsx' },
{ label: 'CSV', value: 'csv' }
];
/**
* 场景选项(根据数据源动态生成)
* @param {string} datasource - 数据源标识
* @returns {Array<{label: string, value: string}>}
*/
const getSceneOptions = (datasource) => {
const mainTable = getMainTable(datasource);
return [{ label: '订单数据', value: mainTable }];
};
/**
* 获取场景标签
* @param {string} scene - 场景值
* @returns {string} 场景标签
*/
const getSceneLabel = (scene) => {
if (scene === 'order' || scene === 'order_info') return '订单';
return scene || '';
};
// ==================== 订单类型与子表映射 ====================
/**
* 营销系统订单类型对应的子表
*/
const MARKETING_TYPE_TABLES = {
1: ['plan', 'key_batch', 'code_batch', 'merchant_key_send'], // 直充卡密
2: ['order_voucher', 'voucher', 'voucher_batch', 'plan', 'key_batch', 'code_batch'], // 立减金
3: ['order_cash', 'plan', 'key_batch', 'code_batch'] // 红包
};
/**
* 易码通订单类型对应的子表
*/
const YMT_TYPE_TABLES = {
1: ['order_cash'], // 红包
2: ['order_digit'], // 直充卡密
3: ['order_voucher', 'goods_voucher_batch', 'goods_voucher_subject_config'] // 立减金
};
/**
* 获取订单类型对应的可用子表
* @param {string} datasource - 数据源标识
* @param {number} orderType - 订单类型
* @returns {string[]} 可用子表列表
*/
const getAvailableSubTables = (datasource, orderType) => {
if (datasource === 'ymt') {
return YMT_TYPE_TABLES[orderType] || Object.values(YMT_TYPE_TABLES).flat();
}
return MARKETING_TYPE_TABLES[orderType] || Object.values(MARKETING_TYPE_TABLES).flat();
};
// 导出模块
window.AppConfig = {
CONSTANTS,
DATASOURCE_CONFIG,
DEFAULT_TABLE_LABELS,
VISIBILITY_OPTIONS,
FORMAT_OPTIONS,
DEFAULT_FIELDS,
// 数据源相关
getDatasourceOptions,
getDatasourceLabel,
getMainTable,
getOrderTypeOptions,
getDefaultOrderType,
getOrderTypeLabel,
// 表相关
getTableRelations,
getAvailableSubTables,
// 场景相关
getSceneOptions,
getSceneLabel,
// 默认值
getDefaultFields
};