Commit 92ee2ad6 authored by 杨子龙's avatar 杨子龙

优化字段类型判断

parent bfbde65b
......@@ -852,3 +852,10 @@ export function GetDeviceTypes () {
method: 'GET'
});
}
export function GetTableFieldsByTableName(params) {
return request(`/PandaOMS/OMS/CaseManage/GetTableFieldsByTableName` , {
method: "GET",
params
})
}
import React, { Fragment, useEffect , useState } from 'react';
import {Button, Empty, Table, Space, Input} from 'antd';
import {CheckOutlined} from "@ant-design/icons";
import * as AntdIcon from '@ant-design/icons';
import FileView from '../../../Account/components/TablePack/components/FileView';
import TagPack from '../../../components/TagPack'
......@@ -26,6 +25,7 @@ const DataTable = props => {
const [dataSource , setDataSource] = useState([]);
const [visible , setVisible] = useState(true);
const [columns , setColumns] = useState([]);
const hasHash = (url) => {
return url.includes('#');
......@@ -168,11 +168,11 @@ const DataTable = props => {
</Fragment>;
};
// 字段栏渲染
// 字段栏显示模式渲染
const getFieldRender = (_, row, index , item) => {
let ele;
switch (item.type) {
case "text":
case "文本":
if(!item.isMapped){
ele = <span style={{color: item.color}}>{_}</span>
} else {
......@@ -197,6 +197,11 @@ const DataTable = props => {
}
break;
case "FileUpload":
ele = <FileView value={_}
download={true}
preview={true} />;
break;
}
return ele
......@@ -204,7 +209,8 @@ const DataTable = props => {
const getColumns = () => {
const arr = [];
const list = statusOption?.length !== 0 ? statusOption : fieldList;
const list = statusOption;
let isGIS = false;
list?.forEach(item => {
if(item.fieldType === "gis"){
......@@ -213,38 +219,26 @@ const DataTable = props => {
})
list?.forEach(item => {
if (item.fieldType === '台账' && schema?.widget === 'FileUpload') {
arr.push({
title: item.fieldAliasName,
dataIndex: !isGIS ? item.fieldName : `${item.fieldType}-${item.fieldName}`,
key: !isGIS ? item.fieldName : `${item.fieldType}-${item.fieldName}`,
width: item.width || 120,
render: (_, row) => {
return <FileView value={row[`${item.fieldType}-${item.fieldName}`]} {...schema} />;
},
});
} else {
const dataIndex = !isGIS ? item.fieldName : `${item.fieldType}-${item.fieldName}`;
arr.push({
title: item.fieldAliasName,
dataIndex,
key: dataIndex,
width: item.width || 120,
render: (_, row , index) => {
return (
<Fragment>
{
row.isEditable ? (
<Input value={_}
onChange={e => changeValue(e.target.value , index , dataIndex)} />
) : getFieldRender(_, row, index , item)
}
</Fragment>
)
}
});
}
const dataIndex = !isGIS ? item.fieldName : `${item.fieldType}-${item.fieldName}`;
arr.push({
title: item.fieldAliasName,
dataIndex,
key: dataIndex,
width: item.width || 120,
render: (_, row , index) => {
return (
<Fragment>
{
row.isEditable ? (
<Input value={_}
onChange={e => changeValue(e.target.value , index , dataIndex)} />
) : getFieldRender(_, row, index , item)
}
</Fragment>
)
}
});
});
if (!disabled) {
......@@ -259,7 +253,7 @@ const DataTable = props => {
});
}
return arr
setColumns(arr);
};
const initRelationForm = () => {
......@@ -313,9 +307,9 @@ const DataTable = props => {
window.relationForm.data = data;
}
const columns = getColumns();
useEffect(() => {
eventEmitter.removeAllListeners(addons?.dataPath);
let list = [...dataSource];
eventEmitter.on(addons?.dataPath , (res) => {
......@@ -335,8 +329,16 @@ const DataTable = props => {
setVisible(true);
onChange(res.length)
})
return () => {
eventEmitter.removeAllListeners(addons?.dataPath)
}
}, []);
useEffect(() => {
getColumns()
} , [fieldList])
useEffect(() => {
initRelationForm();
......
......@@ -221,10 +221,6 @@ const OptionRender = (props) => {
label: "删除",
value: "delete"
},
{
label: "编辑",
value: "update"
},
{
label: "自定义事件",
value: "selfEvent"
......
......@@ -7,13 +7,12 @@ import { colors } from '../../../../../constant'
import { getNanoid } from '../../../../../utils'
import { SketchPicker } from 'react-color'
import Drag from "../../../../components/Drag";
import {GetTableFieldsByTableName} from "../../../../../apis/process";
function getTableData(list , optionList) {
async function getTableData(list , optionList) {
if(list){
const arr = [...list];
console.log("optionList" , optionList);
list?.forEach((item) => {
item.type = "text";
})
......@@ -34,18 +33,39 @@ const StatusOption = (props) => {
const [visible , setVisible] = useState(false);
const [parseObj , setParseObj] = useState(`{"key": {"color": "" , "label": ""}}`);
const data = value?.length ? value : getTableData(fieldList);
const showType = (t) => {
const arr = ["FileUpload" , "tag" , "文本"]
return arr.includes(t);
}
const initData = async () => {
const fields = [];
const initData = () => {
fieldList.forEach(item => {
const currentItem = value.find(v => item.fieldName === v.fieldName)
if(item.fieldType !== "gis"){
fields.push(item.fieldName)
}
});
const { data , code } = await GetTableFieldsByTableName({
tableName: addons.formData.tableName,
fields: fields.join(",")
});
fieldList.forEach(item => {
const currentItem = value.find(v => item.fieldName === v.fieldName);
const current = data.find(d => d.FieldName === item.fieldName);
if(currentItem){
item.color = currentItem.color;
item.type = currentItem.type;
item.width = currentItem.width;
item.parseStr = currentItem.parseStr;
item.type = showType(current?.Widget) ? current?.Widget : "文本";
item.editType = current?.Widget || "文本";
item.isMapped = currentItem?.isMapped || false;
item.width = currentItem.width || 120;
} else {
item.type = "text";
item.type = "文本";
item.editType = "文本";
item.color = "rgb(65,68,69)";
item.isMapped = false;
item.width = 120;
......@@ -64,9 +84,7 @@ const StatusOption = (props) => {
}, [isMultiple])
useEffect(() => {
if(value?.length !== fieldList?.length){
initData()
}
initData()
} , [fieldList])
useEffect(() => {
......@@ -76,15 +94,15 @@ const StatusOption = (props) => {
}, [])
const onPressEnter = (i) => {
let length = [...data].length
let array = [...data]
let length = [...value].length
let array = [...value]
array.splice(i + 1, 0, { key: getNanoid(), index: length + 1, color: colors[length % 10], value: '' })
onChange(array)
}
const inputChange = (val, i , key , item) => {
let array = []
data.forEach((v, index) => {
value.forEach((v, index) => {
if (index === i) {
v[key] = val;
}
......@@ -96,7 +114,7 @@ const StatusOption = (props) => {
const confirm = (index) => {
let array = []
data.forEach((v, i) => {
value.forEach((v, i) => {
if (i !== index) {
array.push({ ...v })
}
......@@ -106,7 +124,7 @@ const StatusOption = (props) => {
const colorClick = (item, i) => {
let array = []
data.forEach((v, index) => {
value.forEach((v, index) => {
if (index === i) {
v.color = item
}
......@@ -118,7 +136,7 @@ const StatusOption = (props) => {
const rest = (index) => {
let array = []
data.forEach((v, i) => {
value.forEach((v, i) => {
if (index === i) {
v.color = colors[index % 10]
}
......@@ -151,13 +169,17 @@ const StatusOption = (props) => {
return (
<Select options={[
{
label: "文",
value: "text"
label: "文",
value: "文本"
},
{
label: "标签",
value: "tag"
},
{
label: "照片",
value: "FileUpload"
}
]}
value={r}
style={{
......@@ -277,14 +299,14 @@ const StatusOption = (props) => {
return columns.filter(v => v.dataIndex !== 'color')
}
return columns
}, [data, color, currentColor])
}, [value, color, currentColor])
const switchChange = (checked) => {
addons.setValue('color', checked)
if (checked) {
if (Array.isArray(data)) {
if (Array.isArray(value)) {
let array = []
data.forEach((v, i) => {
value.forEach((v, i) => {
if(!i.color){
array.push({ ...v, color: colors[i % 10] })
}
......@@ -294,7 +316,7 @@ const StatusOption = (props) => {
}
} else{
let array = []
data.forEach((v, i) => {
value.forEach((v, i) => {
if(i.color){
delete i.color
}
......@@ -315,8 +337,8 @@ const StatusOption = (props) => {
}
const add = () => {
let length = [...data].length
let array = [...data]
let length = [...value].length
let array = [...value]
array.push({ key: getNanoid(), index: length + 1, color: colors[length % 10], value: '' })
onChange(array)
}
......@@ -340,8 +362,8 @@ const StatusOption = (props) => {
{loading ? null : (
<DragTable
dataSource={
Array.isArray(data)
? data.map((v, i) => {
Array.isArray(value)
? value.map((v, i) => {
return {key: `${i}`, index: i, ...v};
})
: []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment