feat(metadata): 添加表标签支持并调整字段可见性

添加 metaTableLabels 用于存储表标签,优化字段显示逻辑
在 metadata.go 中设置所有字段 hidden 为 false 由前端控制
调整部分营销表字段的 hidden 值为 false 以显示重要字段
This commit is contained in:
zhouyonggao 2025-12-08 16:12:28 +08:00
parent b19b05f873
commit 1aec9c6660
3 changed files with 22 additions and 4 deletions

View File

@ -17,6 +17,7 @@ func MetadataHandler(meta, marketing, ymt *sql.DB) http.Handler {
} else { } else {
tables = marketingMetadataTables() tables = marketingMetadataTables()
} }
setAllHiddenFalse(tables)
sort.Slice(tables, func(i, j int) bool { return tables[i].Table < tables[j].Table }) sort.Slice(tables, func(i, j int) bool { return tables[i].Table < tables[j].Table })
rec := recommendedDefaults(ds, ot) rec := recommendedDefaults(ds, ot)
@ -37,6 +38,15 @@ type fieldInfo struct {
Hidden bool `json:"hidden"` Hidden bool `json:"hidden"`
} }
// setAllHiddenFalse sets every field hidden flag to false for client-side control.
func setAllHiddenFalse(tables []tableInfo) {
for ti := range tables {
for fi := range tables[ti].Fields {
tables[ti].Fields[fi].Hidden = false
}
}
}
// marketingMetadataTables 静态列出 Marketing 库的所有表字段hidden 默认 true // marketingMetadataTables 静态列出 Marketing 库的所有表字段hidden 默认 true
func marketingMetadataTables() []tableInfo { func marketingMetadataTables() []tableInfo {
return []tableInfo{ return []tableInfo{
@ -152,11 +162,11 @@ func marketingMetadataTables() []tableInfo {
{Key: "order.status", Field: "status", Label: "状态", Hidden: true}, {Key: "order.status", Field: "status", Label: "状态", Hidden: true},
{Key: "order.account", Field: "account", Label: "账号", Hidden: true}, {Key: "order.account", Field: "account", Label: "账号", Hidden: true},
{Key: "order.product_id", Field: "product_id", Label: "商品id", Hidden: true}, {Key: "order.product_id", Field: "product_id", Label: "商品id", Hidden: true},
{Key: "order.reseller_id", Field: "reseller_id", Label: "所属分销商ID冗余", Hidden: true}, {Key: "order.reseller_id", Field: "reseller_id", Label: "所属分销商ID冗余", Hidden: false},
{Key: "order.plan_id", Field: "plan_id", Label: "所属营销计划ID冗余", Hidden: false}, {Key: "order.plan_id", Field: "plan_id", Label: "所属营销计划ID冗余", Hidden: false},
{Key: "order.key_batch_id", Field: "key_batch_id", Label: "所属KEY批次ID冗余", Hidden: false}, {Key: "order.key_batch_id", Field: "key_batch_id", Label: "所属KEY批次ID冗余", Hidden: false},
{Key: "order.code_batch_id", Field: "code_batch_id", Label: "Code批次ID(冗余)", Hidden: false}, {Key: "order.code_batch_id", Field: "code_batch_id", Label: "Code批次ID(冗余)", Hidden: false},
{Key: "order.contract_price", Field: "contract_price", Label: "合同单价(冗余)", Hidden: true}, {Key: "order.contract_price", Field: "contract_price", Label: "合同单价(冗余)", Hidden: false},
{Key: "order.total", Field: "total", Label: "总价", Hidden: true}, {Key: "order.total", Field: "total", Label: "总价", Hidden: true},
{Key: "order.num", Field: "num", Label: "购买数量", Hidden: true}, {Key: "order.num", Field: "num", Label: "购买数量", Hidden: true},
{Key: "order.pay_amount", Field: "pay_amount", Label: "支付金额", Hidden: true}, {Key: "order.pay_amount", Field: "pay_amount", Label: "支付金额", Hidden: true},

Binary file not shown.

View File

@ -107,6 +107,7 @@ const app = createApp({
// ==================== 字段元数据管理 ==================== // ==================== 字段元数据管理 ====================
const metaFM = Vue.ref({}); const metaFM = Vue.ref({});
const metaTableLabels = Vue.ref({});
const recommendedMeta = Vue.ref([]); const recommendedMeta = Vue.ref([]);
const loadFieldsMeta = async (ds, type) => { const loadFieldsMeta = async (ds, type) => {
@ -115,13 +116,18 @@ const app = createApp({
const data = await res.json(); const data = await res.json();
const tables = Array.isArray(data?.data?.tables) ? data.data.tables : (Array.isArray(data?.tables) ? data.tables : []); const tables = Array.isArray(data?.data?.tables) ? data.data.tables : (Array.isArray(data?.tables) ? data.tables : []);
const m = {}; const m = {};
const tblLabels = {};
tables.forEach(t => { tables.forEach(t => {
const arr = Array.isArray(t.fields) ? t.fields : []; const arr = Array.isArray(t.fields) ? t.fields : [];
m[t.table] = arr.map(it => ({ value: it.field, label: it.label })); const visibleFields = arr.filter(it => !it.hidden);
m[t.table] = visibleFields.map(it => ({ value: it.field, label: it.label }));
if (t.label) tblLabels[t.table] = t.label;
}); });
metaFM.value = m; metaFM.value = m;
metaTableLabels.value = tblLabels;
} catch (_e) { } catch (_e) {
metaFM.value = {}; metaFM.value = {};
metaTableLabels.value = {};
} }
}; };
@ -159,10 +165,12 @@ const app = createApp({
goods_voucher_subject_config: '立减金主体配置' goods_voucher_subject_config: '立减金主体配置'
}; };
const tableLabel = (table) => metaTableLabels.value[table] || TABLE_LABELS[table] || table;
// ==================== 字段选项构建 ==================== // ==================== 字段选项构建 ====================
const buildFieldNode = (table, children = []) => ({ const buildFieldNode = (table, children = []) => ({
value: table, value: table,
label: TABLE_LABELS[table] || table, label: tableLabel(table),
children children
}); });