提交 b0989f58 authored 作者: 钟是志's avatar 钟是志

优化代码

上级 95131f6d
...@@ -5,90 +5,88 @@ import { getInfo } from '@/highOrderComponent/Service'; ...@@ -5,90 +5,88 @@ import { getInfo } from '@/highOrderComponent/Service';
import { Divider } from 'antd'; import { Divider } from 'antd';
import config from '@/config/config'; import config from '@/config/config';
import { import {
setSysConfig, setSysConfig,
getSysConfig as getSysConfigLocalStorage, getSysConfig as getSysConfigLocalStorage,
} from '@/webPublic/zyd_private/utils/basiclayout'; } from '@/webPublic/zyd_private/utils/basiclayout';
import { getOneStopConfig } from '@/webPublic/zyd_public/utils/utils'; import { getOneStopConfig } from '@/webPublic/zyd_public/utils/utils';
function formatUploadFile(fileList) {
if (!fileList || !Array.isArray(fileList)) return [];
return JSON.stringify(
fileList.map((i) => ({
uid: i.uid,
name: i.name,
status: i.status,
url: i.filePath || i.response.filePath,
})),
);
}
export const valueTypes = { export const valueTypes = {
0: { 0: {
name: '文本', name: '文本',
inputComponent: 'input', inputComponent: 'input',
}, },
1: { 1: {
name: '文件', name: '文件',
inputComponent: 'upload', inputComponent: 'upload',
formatToServer: formatUploadFile, // 新增或保存时候转换格式 formatToServer: formatUploadFile, // 新增或保存时候转换格式
formatToEdit: (str) => { formatToEdit: (str) => {
const fileArr = JSON.parse(str); const fileArr = JSON.parse(str);
if (!Array.isArray(fileArr)) return []; if (!Array.isArray(fileArr)) return [];
return fileArr; return fileArr;
}, // 编辑时,转换成可以在表单回显的格式 }, // 编辑时,转换成可以在表单回显的格式
render: (val) => { render: (val) => {
// 在列表上的显示方式 // 在列表上的显示方式
return JSON.parse(val) return JSON.parse(val).map((item, i) => (
.map((item, i) => ( <>
<> {i > 0 && <Divider type="vertical" />}
{i > 0 && <Divider type="vertical"/>} <a
<a target="_blank"
target="_blank" rel="noopener noreferrer"
rel="noopener noreferrer" key={item.uid}
key={item.uid} href={item.url && (item.url.startsWith('http') ? item.url : config.dfs + item.url)}>
href={item.url && (item.url.startsWith('http') ? item.url : config.dfs + item.url)}> {item.name}
{item.name} </a>
</a> </>
</> ));
)); },
}, },
}, 2: {
2: { name: '富文本',
name: '富文本', inputComponent: 'input',
inputComponent: 'input', },
},
}; };
export function getSysConfig() { export function getSysConfig() {
return getInfo({ pageSize: 10000 }, '/WebConfigApi/getPage?oauthPub=true') return getInfo({ pageSize: 10000 }, '/WebConfigApi/getPage?oauthPub=true').then((res) => {
.then((res) => { if (res && res.rows && res.rows.length) {
if (res && res.rows && res.rows.length) { const formattered = res.rows.reduce((acc, cur) => {
const formattered = res.rows.reduce((acc, cur) => { console.log(valueTypes, cur.valueType);
const { formatToEdit } = valueTypes[cur.valueType]; let index = cur.valueType || '0';
let { value } = cur; const { formatToEdit } = valueTypes[index];
if (formatToEdit && typeof formatToEdit === 'function') { let { value } = cur;
value = formatToEdit(value); if (formatToEdit && typeof formatToEdit === 'function') {
} value = formatToEdit(value);
return { }
...acc, return {
[cur.dictCode]: value ...acc,
}; [cur.dictCode]: value,
}, {}); };
setSysConfig(formattered); }, {});
return formattered; setSysConfig(formattered);
} return formattered;
}); }
});
} }
export default function setTokenAndInitSystem() { export default function setTokenAndInitSystem() {
let token = getUrlInfo().token; let token = getUrlInfo().token;
if (token && token.length > 10 && getToken() !== token) { if (token && token.length > 10 && getToken() !== token) {
setToken(token); setToken(token);
} }
if (!getSysConfigLocalStorage()) { if (!getSysConfigLocalStorage()) {
getSysConfig(); getSysConfig();
} }
getOneStopConfig(); getOneStopConfig();
}
function formatUploadFile(fileList) {
if (!fileList || !Array.isArray(fileList)) return [];
return JSON.stringify(
fileList.map((i) => ({
uid: i.uid,
name: i.name,
status: i.status,
url: i.filePath || i.response.filePath,
})),
);
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论