diff --git a/src/components/ProTable/ProTableColumn.vue b/src/components/ProTable/ProTableColumn.vue new file mode 100644 index 0000000..cf3c7eb --- /dev/null +++ b/src/components/ProTable/ProTableColumn.vue @@ -0,0 +1,39 @@ + + + + + {{ row[props?.prop] }} + + + + + + + + diff --git a/src/components/ProTable/index.vue b/src/components/ProTable/index.vue new file mode 100644 index 0000000..7ba40bf --- /dev/null +++ b/src/components/ProTable/index.vue @@ -0,0 +1,171 @@ + + + + + + {{ props.createText }} + + + + + + + + + + + + + + + + diff --git a/src/constants/proTable.ts b/src/constants/proTable.ts new file mode 100644 index 0000000..b338790 --- /dev/null +++ b/src/constants/proTable.ts @@ -0,0 +1,8 @@ +// 分页信息 +export const PAGINATION_INFO = 'PAGINATION_INFO' +// 修改表格数据 +export const UPDATE_ROW = 'UPDATE_ROW' +// 删除表格数据 +export const DELETE_ROW = 'DELETE_ROW' +// 添加数据 +export const CREATE_ROW = 'CREATE_ROW' diff --git a/src/interfaces/proTable.ts b/src/interfaces/proTable.ts new file mode 100644 index 0000000..793f636 --- /dev/null +++ b/src/interfaces/proTable.ts @@ -0,0 +1,33 @@ +export interface ITableDataItem { + [key: string]: any +} + +export type IPaginationInfo = { + showPagination: boolean + currentPage: number + pageSize: number + pageSizes: number[] + total: number +} + +/** + * @param record 创建的新数据 + */ +export type ICreateRow = (record: ITableDataItem) => void +/** + * @param index 修改的索引(如果是由插槽获取的该数据则会自动绑定该数据,直接传入修改完后的新数据即可) + * @param newRecord 修改完后的新数据 + */ +export type IUpdateRow = (index: number, newRecord: ITableDataItem) => void +/** + * @param index 同修改的索引 + */ +export type IDeleteRow = (index: number) => void + +export type IOnCreated = (callback: ICreateRow) => void + +export interface IHandleProTableData { + createRow: ICreateRow + updatedRow: IUpdateRow + deleteRow: IDeleteRow +} diff --git a/src/pages/index.vue b/src/pages/index.vue index fa0b493..6f62076 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -1,35 +1,71 @@ { - "name": "index", - "title": "首页" +"name": "index", +"title": "首页" } - - fes & 拉夫德鲁 - 数据字典 - - {{ item.value }}:{{ item.key }} - - - - 计数器 - click me:{{ count }} - - + + + + + + + + Remove + + + update + + + + diff --git a/src/tools/proTable.ts b/src/tools/proTable.ts new file mode 100644 index 0000000..3251968 --- /dev/null +++ b/src/tools/proTable.ts @@ -0,0 +1,49 @@ +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) + } + } +} diff --git a/src/types/auto-imports.d.ts b/src/types/auto-imports.d.ts index db37cc0..56d8eb5 100644 --- a/src/types/auto-imports.d.ts +++ b/src/types/auto-imports.d.ts @@ -9,9 +9,20 @@ declare global { const effectScope: typeof import('vue')['effectScope'] const EffectScope: typeof import('vue')['EffectScope'] const ElButton: typeof import('element-plus/es')['ElButton'] + const ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider'] + const ElDialog: typeof import('element-plus/es')['ElDialog'] + const ElForm: typeof import('element-plus/es')['ElForm'] + const ElFormItem: typeof import('element-plus/es')['ElFormItem'] const ElIcon: typeof import('element-plus/es')['ElIcon'] + const ElInput: typeof import('element-plus/es')['ElInput'] + const ElLoadingDirective: typeof import('element-plus/es')['ElLoadingDirective'] + const ElOption: typeof import('element-plus/es')['ElOption'] + const ElPagination: typeof import('element-plus/es')['ElPagination'] + const ElSelect: typeof import('element-plus/es')['ElSelect'] const ElTable: typeof import('element-plus/es')['ElTable'] const ElTableColumn: typeof import('element-plus/es')['ElTableColumn'] + const ElTabPane: typeof import('element-plus/es')['ElTabPane'] + const ElTabs: typeof import('element-plus/es')['ElTabs'] const getCurrentInstance: typeof import('vue')['getCurrentInstance'] const getCurrentScope: typeof import('vue')['getCurrentScope'] const h: typeof import('vue')['h'] diff --git a/src/types/components.d.ts b/src/types/components.d.ts index e4da71d..8088dc7 100644 --- a/src/types/components.d.ts +++ b/src/types/components.d.ts @@ -5,10 +5,24 @@ declare module 'vue' { export interface GlobalComponents { ElButton: typeof import('element-plus/es')['ElButton'] + ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider'] + ElDialog: typeof import('element-plus/es')['ElDialog'] + ElForm: typeof import('element-plus/es')['ElForm'] + ElFormItem: typeof import('element-plus/es')['ElFormItem'] ElIcon: typeof import('element-plus/es')['ElIcon'] + ElInput: typeof import('element-plus/es')['ElInput'] + ElOption: typeof import('element-plus/es')['ElOption'] + ElPagination: typeof import('element-plus/es')['ElPagination'] + ElSelect: typeof import('element-plus/es')['ElSelect'] ElTable: typeof import('element-plus/es')['ElTable'] ElTableColumn: typeof import('element-plus/es')['ElTableColumn'] + ElTabPane: typeof import('element-plus/es')['ElTabPane'] + ElTabs: typeof import('element-plus/es')['ElTabs'] + 'IBi:questionCircle': typeof import('~icons/bi/question-circle')['default'] + Loading: typeof import('element-plus/es')['ElLoadingDirective'] PageLoading: typeof import('./../components/PageLoading.vue')['default'] + ProTable: typeof import('./../components/ProTable/index.vue')['default'] + ProTableColumn: typeof import('./../components/ProTable/ProTableColumn.vue')['default'] UserCenter: typeof import('./../components/UserCenter.vue')['default'] } }