import { ITableDataItem, IHandleProTableData } from '~/interfaces/proTable' import { ElNotification } from 'element-plus/es' import { Ref } from 'vue' export class HandleProTableData implements IHandleProTableData { updateTheView: () => void tableData: Ref constructor(updateTheView: () => void, tableData: Ref) { this.updateTheView = updateTheView this.tableData = tableData } handleError(e: unknown) { ElNotification({ title: '提示', message: (e as Error).message, type: 'error', }) } createRow = (record: ITableDataItem) => { try { this.tableData.value.push(record) this.updateTheView() } catch (e) { this.handleError(e) } } updatedRow = (index: number, newRecord: ITableDataItem) => { try { this.tableData.value.splice(index, 1, newRecord) this.updateTheView() } catch (e) { this.handleError(e) } } deleteRow = (index: number) => { try { this.tableData.value.splice(index, 1) this.updateTheView() } catch (e) { console.log(this) this.handleError(e) } } }