import React, { useState } from 'react'; import { SplitButtonGroup, CnBalloon, Button, Icon, Dropdown, Tree, MenuButton, CnTooltip, } from '@cainiaofe/cn-ui'; import { ImportField } from './import-field'; import isPlainObject from 'lodash/isPlainObject'; import { handleI18nLabel } from '@/common/util/util'; const { CodeControl } = window?.VisualEngineUtils || {}; export const TableAddOneBtn = (props) => { const [importVisible, setImportVisible] = useState(false); const [visible, setVisible] = useState(false); const [code, setCode] = useState(''); const { onAdd, prop, dataPrimaryKey, handleFieldList } = props; const currentId = prop?.getNode?.()?.id; const allInsert = () => { let result = getNewList(); if (typeof handleFieldList === 'function') { result = handleFieldList(result); } if (result.length > 0) { props?.prop?.setValue(result); const sel = window?.AliLowCodeEngine?.project?.currentDocument?.selection; if (sel) { sel?.select?.(); setTimeout(() => { sel?.select?.(currentId); }); } } }; const addInsert = () => { const primaryKey = dataPrimaryKey || 'dataIndex'; const existColumns = props?.prop?.getValue() || []; const existMap = {}; existColumns.forEach((item) => { if (item[primaryKey]) { existMap[item[primaryKey]] = true; } }); let result = getNewList(); if (typeof handleFieldList === 'function') { result = handleFieldList(result); } const toAddList = [...existColumns]; if (result.length > 0) { result.forEach((item) => { if (item[primaryKey] && existMap[item[primaryKey]]) { } else { toAddList.push(item); } }); if (toAddList.length > 0) { props?.prop?.setValue(toAddList); const sel = window?.AliLowCodeEngine?.project?.currentDocument?.selection; if (sel) { sel?.select?.(); setTimeout(() => { sel?.select?.(currentId); }); } } } setVisible(false); }; const getNewList = () => { const list = []; try { const originList = JSON.parse(code); if (originList.length > 0) { originList.forEach((item = {}) => { let title; let dataIndex; const originTitle = handleI18nLabel(item.title); if (typeof originTitle === 'string') { title = originTitle; } else if (isPlainObject(originTitle) && originTitle?.zh_CN) { title = originTitle?.zh_CN; } title = handleI18nLabel(title); if (item.dataIndex) { dataIndex = item.dataIndex; } else if (item.dataKey) { dataIndex = item.dataKey; } if (dataIndex && title) { list.push({ dataIndex, title, format: 'text', }); } }); } } catch (e) {} return list; }; return ( setImportVisible(true)}> 选择其他组件的字段并导入 setVisible(true)}> 导入老Cone搭建的表格列配置 { setVisible(v); }} closable triggerType={'click'} title={
粘贴要导入的表格列JSON{' '} 使用文档
} trigger={' '} >
请到老cone{' '} 表头JSON}>
中复制,并粘贴到代码框中
{ setCode(code); }} // // 如果为 false 或者 0 则不启动节流阀 throttle={600} lineNumbers={'off'} enableOutline={false} // enableSuggestion // defaultSuggestion // enableBlurChange // diyWordSuggestion // checkSyntax // 是否开启预编译检查(限js) // // customeSuggestion={getSuggestion} // onEditorDidMount={(editor, monaco) => { // console.log('editor, monaco:::>>>', editor, monaco); // }} // 编辑器初始化完成 />
  
} />
); };