import { show } from "@/api/system/customForm"; import { listCommondepartment, listCommonuser } from "@/api/common"; import { primaryColor } from "@/styles/variables.scss" import { download } from "@/utils/downloadRequest"; function down (url) { download(url) } function preview (url) { let codeUri = `${process.env.VUE_APP_PREVIEW_API}?url=${encodeURIComponent( new Buffer(url).toString("base64") )}` window.open(codeUri,'_blank') } const baseTable = new Map([ ['departments', async () => { return (await listCommondepartment()) }], ['admins',async () => { return (await listCommonuser()) }] ]) export async function getForm (customFormId) { let selectItemMap = new Map(); if (!customFormId) { console.warn("customFormId is required!") return } const res = await show({ id: customFormId }, false); const { fields, relation } = res; let fieldRes = fields.sort((a,b) => a.sort - b.sort); if ( !fields || !relation || !fields instanceof Array || !relation instanceof Array ) { throw new Error("fields或relation参数错误"); } fieldRes?.forEach((i, index) => { i._relations = relation.find((j) => j.custom_form_field === i.field); if (i.select_item && typeof i.select_item === 'object') { let keys = Object.keys(i.select_item) if (keys.length > 0) { i._params = keys.map((key) => { return { key, value: /^\d*$/.test(i.select_item[key]) ? Number(i.select_item[key]) : i.select_item[key], }; }); selectItemMap.set(i.field, i._params); //有select,radio i.edit_input = 'radio' } } }) return { fieldRes, selectItemMap }; } export function getRenderTable (ctx, fields, replaces) { const h = ctx.$createElement; if (replaces && !(replaces instanceof Map)) { throw new Error("replaces参数错误,需要Map类型"); } return fields.map((field, index) => { console.log("fields",fields) // //自定义替换 if (replaces instanceof Map && replaces.get(field.field)) { return replaces.get(field.field) } //文件 if (field.edit_input === 'file' || field.edit_input === 'files') { let renderFn = () => {} const { link_relation, foreign_key, link_with_name } = field._relations; if (link_relation === 'hasOne' || link_relation === 'newHasOne') { renderFn = row => { if (!row[link_with_name]?.url) { return '' } return (
{o?.name || o?.title || o?.no || o?.value || o?.biaoti || o?.mingcheng}
))}