import {reactive} from "@peryl/react-compose"; import {iTableOptionCacheData, iTableOptionCacheItemData} from "../use/useTableOption.cache.utils"; import {defer} from "@peryl/utils/defer"; import {$message} from "../../$message"; import {$dialog} from "../../$dialog"; import {deepcopy} from "@peryl/utils/deepcopy"; import {eTableOptionSettingView} from "./useTableOption.setting.utils"; import {Button} from "../../Button"; import {Tooltip} from "../../Tooltip"; import {Table} from "../../Table"; import {Plc} from "../../Plc"; import {Radio} from "../../Radio"; import {iTableInnerOperationConfig} from "../../Table/standard/PlcOperation/PlcOperation.utils"; import {PlcOperation} from "../../Table/standard/PlcOperation/PlcOperation"; import {PlcIndex} from "../../Table/standard/PlcIndex"; import {PlcTextarea} from "../../Table/editor/PlcTextarea"; import '../utils/TableOption.space'; import i18n from "../../i18n"; import {AutoModule} from "../utils/AutoModule"; declare module '../utils/TableOption.space' { namespace TableOptionSpace { interface iTableOption { settingCache: ReturnType; } } } export const useTableOptionSettingCache = AutoModule.createRegistration(( { setting, cache, config, } ) => { const state = reactive({ editCacheData: {} as iTableOptionCacheData }); const getConfigName = (initialName?: string) => { const dfd = defer(); $dialog({ editType: 'input', status: null, editValue: initialName, title: i18n.$it('table.pleaseInputThConfigurationName').d('请输入配置名称'), confirmButton: true, cancelButton: true, size: config.size, handleConfirm: async ({ editValue }) => { if (editValue == null || String(editValue).trim().length === 0) { $message(i18n.$it('table.pleaseEnterNewConfigName').d('请输入新配置名称')); return Promise.reject('invalid value!'); } else { dfd.resolve(String(editValue)); } }, }); return dfd.promise; }; const newCache = async () => { const cacheName = await getConfigName(); cache.createCache(cacheName); state.editCacheData = deepcopy(cache.state.cacheData); }; const renameCache = async (cacheItemData: iTableOptionCacheItemData) => { const newCacheName = await getConfigName(cacheItemData.title); cache.renameCache(cacheItemData.id, newCacheName); state.editCacheData = deepcopy(cache.state.cacheData); }; const deleteCache = async (cacheItemData: iTableOptionCacheItemData) => { cache.deleteCache(cacheItemData.id); state.editCacheData = deepcopy(cache.state.cacheData); }; const copyConfig = async (cacheItemData: iTableOptionCacheItemData) => { cache.copyCache(cacheItemData.id, await getConfigName(cacheItemData.title + '.' + i18n.$it('table.bak').d('副本'))); state.editCacheData = deepcopy(cache.state.cacheData); }; const overrideCache = async (cacheItemData: iTableOptionCacheItemData) => { await $dialog.confirm({ message: i18n.$it('table.areYouSureToOverrideTheConfiguration', { title: cacheItemData.title }).d('确定要覆盖配置"{title}"为当前最新的配置吗?') }, { size: config.size }); cache.overrideCache(cacheItemData.id); state.editCacheData = deepcopy(cache.state.cacheData); }; const applyCache = async (cacheItemData?: iTableOptionCacheItemData) => { cache.applyCache(cacheItemData?.id); state.editCacheData = deepcopy(cache.state.cacheData); }; const innerOperationConfigs: iTableInnerOperationConfig[] = [ { label: i18n.$it('base.edit.apply').d('应用'), position: 'inner', handler: ({ row }) => {applyCache(row as any);} }, { label: i18n.$it('base.edit.rename').d('重命名'), position: 'inner', handler: ({ row }) => {renameCache(row as any);} }, { label: i18n.$it('base.edit.remove').d('删除'), position: 'inner', handler: ({ row }) => {deleteCache(row as any);} }, { label: i18n.$it('base.edit.override').d('覆盖'), position: 'inner', handler: ({ row }) => {overrideCache(row as any);} }, { label: i18n.$it('base.edit.copy').d('复制'), position: 'inner', handler: ({ row }) => {copyConfig(row as any);} }, ]; setting.useTableOptionSettingInner({ key: eTableOptionSettingView.cache, title: i18n.$it('table.cacheSetting').d('缓存设置'), seq: 4, beforeOpen: () => { state.editCacheData = deepcopy(cache.state.cacheData); }, render: () => { return (
{ return applyCache(row as any)}/>; } }}/>
); }, }); });