forked from iod/cpnode-front
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
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<ITableDataItem[]>
|
|
|
|
constructor(updateTheView: () => void, tableData: Ref<ITableDataItem[]>) {
|
|
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)
|
|
}
|
|
}
|
|
}
|