feat(api): 修改模板列表查询排序规则为按数据源和ID降序

refactor(web): 重构字段元数据加载逻辑,支持传入订单类型参数
fix(web): 修复订单类型变化时字段加载不更新的问题
feat(web): 新增对order_digit等表的字段路径映射支持
This commit is contained in:
zhouyonggao 2025-11-27 16:39:06 +08:00
parent 5980ee19a8
commit 00ebfdd24f
4 changed files with 115 additions and 7 deletions

Binary file not shown.

View File

@ -98,7 +98,7 @@ func (a *TemplatesAPI) listTemplates(w http.ResponseWriter, r *http.Request) {
sqlText += " WHERE owner_id IN (0, ?)" sqlText += " WHERE owner_id IN (0, ?)"
args = append(args, uidStr) args = append(args, uidStr)
} }
sqlText += " ORDER BY updated_at DESC LIMIT 200" sqlText += " ORDER BY datasource ASC, id DESC LIMIT 200"
rows, err := a.meta.Query(sqlText, args...) rows, err := a.meta.Query(sqlText, args...)
if err != nil { if err != nil {
fail(w, r, http.StatusInternalServerError, err.Error()) fail(w, r, http.StatusInternalServerError, err.Error())

File diff suppressed because one or more lines are too long

View File

@ -345,9 +345,9 @@ const { createApp, reactive } = Vue;
FIELDS_MAP.marketing = {} FIELDS_MAP.marketing = {}
FIELDS_MAP.ymt = {} FIELDS_MAP.ymt = {}
const metaFM = Vue.ref({}) const metaFM = Vue.ref({})
const loadFieldsMeta = async (ds)=>{ const loadFieldsMeta = async (ds, type)=>{
try{ try{
const res = await fetch(API_BASE + '/api/metadata/fields?datasource=' + encodeURIComponent(ds) + '&order_type=' + encodeURIComponent(String(state.form.orderType||0))) const res = await fetch(API_BASE + '/api/metadata/fields?datasource=' + encodeURIComponent(ds) + '&order_type=' + encodeURIComponent(String(type||0)))
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 = {}
@ -607,7 +607,7 @@ const { createApp, reactive } = Vue;
state.form.fieldsSel = [] state.form.fieldsSel = []
state.form.main_table = (ds==='ymt' ? 'order_info' : 'order') state.form.main_table = (ds==='ymt' ? 'order_info' : 'order')
state.form.orderType = 1 state.form.orderType = 1
await loadFieldsMeta(ds) await loadFieldsMeta(ds, state.form.orderType)
recommendedMeta.value = [] recommendedMeta.value = []
try{ try{
const res = await fetch(API_BASE + '/api/metadata/fields?datasource=' + encodeURIComponent(ds) + '&order_type=' + encodeURIComponent(String(state.form.orderType||0))) const res = await fetch(API_BASE + '/api/metadata/fields?datasource=' + encodeURIComponent(ds) + '&order_type=' + encodeURIComponent(String(state.form.orderType||0)))
@ -622,6 +622,7 @@ const { createApp, reactive } = Vue;
state.form.fieldsSel = [] state.form.fieldsSel = []
// 订单类型变化,刷新推荐字段 // 订单类型变化,刷新推荐字段
const ds = state.form.datasource const ds = state.form.datasource
await loadFieldsMeta(ds, state.form.orderType)
try{ try{
const res = await fetch(API_BASE + '/api/metadata/fields?datasource=' + encodeURIComponent(ds) + '&order_type=' + encodeURIComponent(String(state.form.orderType||0))) const res = await fetch(API_BASE + '/api/metadata/fields?datasource=' + encodeURIComponent(ds) + '&order_type=' + encodeURIComponent(String(state.form.orderType||0)))
const data = await res.json() const data = await res.json()
@ -634,10 +635,11 @@ const { createApp, reactive } = Vue;
Vue.watch(()=>state.edit.datasource, async (ds)=>{ Vue.watch(()=>state.edit.datasource, async (ds)=>{
state.edit.fieldsSel = [] state.edit.fieldsSel = []
state.edit.main_table = (ds==='ymt' ? 'order_info' : 'order') state.edit.main_table = (ds==='ymt' ? 'order_info' : 'order')
await loadFieldsMeta(ds) await loadFieldsMeta(ds, state.edit.orderType)
}) })
Vue.watch(()=>state.edit.orderType, ()=>{ Vue.watch(()=>state.edit.orderType, async ()=>{
state.edit.fieldsSel = [] state.edit.fieldsSel = []
await loadFieldsMeta(state.edit.datasource, state.edit.orderType)
}) })
const orderLeafPaths = (ds)=>{ const orderLeafPaths = (ds)=>{
const FM = FM_OF(ds) const FM = FM_OF(ds)
@ -1076,6 +1078,7 @@ const { createApp, reactive } = Vue;
} else { } else {
state.edit.orderType = 1 state.edit.orderType = 1
} }
await loadFieldsMeta(state.edit.datasource, state.edit.orderType)
const fields = Array.isArray(tpl.fields) ? tpl.fields : [] const fields = Array.isArray(tpl.fields) ? tpl.fields : []
const toPath = (tf)=>{ const toPath = (tf)=>{
const parts = String(tf||'').split('.') const parts = String(tf||'').split('.')
@ -1092,6 +1095,11 @@ const { createApp, reactive } = Vue;
if(table==='voucher_batch') return ['order','order_voucher','voucher','voucher_batch',field] if(table==='voucher_batch') return ['order','order_voucher','voucher','voucher_batch',field]
if(table==='merchant_key_send') return ['order','merchant_key_send',field] if(table==='merchant_key_send') return ['order','merchant_key_send',field]
if(table==='order_cash') return ['order','order_cash',field] if(table==='order_cash') return ['order','order_cash',field]
if(table==='order_digit') return ['order','order_digit',field]
if(table==='goods_voucher_batch') return ['order','goods_voucher_batch',field]
if(table==='goods_voucher_subject_config') return ['order','goods_voucher_subject_config',field]
if(table==='merchant') return ['order','merchant',field]
if(table==='activity') return ['order','activity',field]
return null return null
} }
state.edit.fieldsSel = fields.map(toPath).filter(p=>Array.isArray(p) && p.length>=2) state.edit.fieldsSel = fields.map(toPath).filter(p=>Array.isArray(p) && p.length>=2)
@ -1166,7 +1174,7 @@ const { createApp, reactive } = Vue;
}catch(_e){ state.sqlText=''; state.sqlVisible=false; msg('加载SQL失败','error') } }catch(_e){ state.sqlText=''; state.sqlVisible=false; msg('加载SQL失败','error') }
} }
loadTemplates() loadTemplates()
loadFieldsMeta(state.form.datasource) loadFieldsMeta(state.form.datasource, state.form.orderType)
return { ...Vue.toRefs(state), visibilityOptions, formatOptions, datasourceOptions, fieldOptionsDynamic, editFieldOptionsDynamic, sceneOptions, editSceneOptions, loadTemplates, createTemplate, openExport, submitExport, loadJob, loadJobs, openJobs, closeJobs, download, openSQL, openEdit, saveEdit, removeTemplate, resizeDialog, createRules, exportRules, editRules, createFormRef, exportFormRef, editFormRef, dsLabel, exportType, isOrder, exportTitle, creatorOptions, resellerOptions, planOptions, hasCreators, hasReseller, hasPlan, hasKeyBatch, hasCodeBatch, jobPercent, fmtDT, fieldsCascader, editFieldsCascader, createCascaderRoot, editCascaderRoot, onCascaderVisible, onFieldsSelChange, hasUserId, currentUserId } return { ...Vue.toRefs(state), visibilityOptions, formatOptions, datasourceOptions, fieldOptionsDynamic, editFieldOptionsDynamic, sceneOptions, editSceneOptions, loadTemplates, createTemplate, openExport, submitExport, loadJob, loadJobs, openJobs, closeJobs, download, openSQL, openEdit, saveEdit, removeTemplate, resizeDialog, createRules, exportRules, editRules, createFormRef, exportFormRef, editFormRef, dsLabel, exportType, isOrder, exportTitle, creatorOptions, resellerOptions, planOptions, hasCreators, hasReseller, hasPlan, hasKeyBatch, hasCodeBatch, jobPercent, fmtDT, fieldsCascader, editFieldsCascader, createCascaderRoot, editCascaderRoot, onCascaderVisible, onFieldsSelChange, hasUserId, currentUserId }
} }