import deepcopy from 'deepcopy' import { ElDialog, ElButton, ElTable, ElTableColumn,ElInput } from 'element-plus' import { defineComponent, reactive, createVNode, render } from 'vue' const TableComponent = defineComponent({ props: { option: { type: Object }, }, setup(props, ctx) { const state = reactive({ option: props.option, isShow: false, editData: [], // 编辑的数据 }) const methods = { show(option) { state.option = option // 把用户的配置缓存起来 state.isShow = true // 更改显示状态 state.editData = deepcopy(option.data) // 通过渲染的数据 默认展现 }, } const add = () =>{ state.editData.push({}) } const onCancel = ()=>{ state.isShow = false } const onConfirm = ()=>{ state.option.onConfirm(state.editData) onCancel() } ctx.expose(methods) return () => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore return {{ default: () => (
添加重置
{state.option.config.table.options.map((item,index)=>{ return {{ default:({ row })=> , }} })} 删除
), footer:()=><> 取消 确定 , }}
} }, }) let vm export const $tableDialog = option => { if (!vm) { const el = document.createElement('div') vm = createVNode(TableComponent, { option }) const r = render(vm, el) document.body.appendChild(el) } const { show } = vm.component.exposed show(option) }