diff --git a/src/auto-imports.d.ts b/src/auto-imports.d.ts index e766c82..2d9827e 100644 --- a/src/auto-imports.d.ts +++ b/src/auto-imports.d.ts @@ -7,8 +7,10 @@ export {} declare global { const EffectScope: typeof import('vue').EffectScope + const ElButton: typeof import('element-plus/es').ElButton const ElMessage: typeof import('element-plus/es').ElMessage const ElMessageBox: typeof import('element-plus/es').ElMessageBox + const ElTag: typeof import('element-plus/es').ElTag const acceptHMRUpdate: typeof import('pinia').acceptHMRUpdate const computed: typeof import('vue').computed const createApp: typeof import('vue').createApp diff --git a/src/components/proTable/proTablev2.vue b/src/components/proTable/proTablev2.vue index ef18452..f3124b0 100644 --- a/src/components/proTable/proTablev2.vue +++ b/src/components/proTable/proTablev2.vue @@ -4,123 +4,368 @@ ref="tableRef" v-bind="$attrs" :columns="adaptedColumns" - :data="data" + :data="innerData" :width="tableSize.width" :height="tableSize.height" :fixed="true" @rows-rendered="handleRowsRendered" > - \ No newline at end of file +const handleRowsRendered = ({ endRowIndex }: any) => { + // 阈值调大一点(10),保证滚动流畅,用户无感知加载 + if (endRowIndex >= innerData.value.length - 10) { + fetchTableData(); + } +}; + +const handleResize = debounce(updateSize, 200); + +onMounted(() => { + updateSize(); + window.addEventListener("resize", handleResize); + fetchTableData(true); +}); + +onUnmounted(() => window.removeEventListener("resize", handleResize)); + +// 暴露 API +defineExpose({ + refresh: () => fetchTableData(true), + updateRow, + removeRow, + addRow, + getCurrentParams: () => ({ + pageNo: pageNo.value - 1, // 因为 fetch 完后 pageNo 会自增,所以要减 1 才是当前页 + pageSize: props.pageSize, + ...props.initParam + }), + innerData +}); + + + diff --git a/src/hooks/useTableAction.ts b/src/hooks/useTableAction.ts new file mode 100644 index 0000000..7421b88 --- /dev/null +++ b/src/hooks/useTableAction.ts @@ -0,0 +1,65 @@ +import { ElMessage } from "element-plus"; + +/** + * @param tableRef ProTableV2 的组件实例引用 + */ + +interface ActionOptions { + showMsg?: boolean; // 是否显示操作成功提示 +} +export const useTableAction = (tableRef: any) => { + /** + * 执行操作并静默更新单行数据 + * @param apiPromise 调用的操作接口(如状态切换、编辑提交) + * @param id 当前行 ID + * @param fetchDataApi 可选:列表请求函数,若传入则在成功后自动拉取最新行数据 + */ + const handleAction = async ( + api: Promise | (() => Promise), + id?: string | number, + fetchDataApi?: Function, + options = { showMsg: true } + ) => { + try { + const res = typeof api === 'function' ? await api() : await api; + if (options.showMsg) ElMessage.success("操作成功"); + + // 局部更新逻辑... (同上) + if (id && fetchDataApi) { + const currentParams = tableRef.value?.getCurrentParams(); + const listRes = await fetchDataApi(currentParams); + const records = listRes?.records || listRes?.data?.records || []; + const latestRowData = records.find((item: any) => item.id == id); + if (latestRowData) tableRef.value.updateRow(id, latestRowData); + } + return res; + } catch (error) { + console.error(error); + throw error; // 抛出错误让外部 catch + } + }; + + /** + * 封装删除逻辑 + * @param id 行 ID + * @param deleteApi 删除接口函数 + */ + const handleDelete = async ( + id: string | number, + deleteApi: (id: any) => Promise + ) => { + try { + const res = await deleteApi(id); + tableRef.value?.removeRow(id); + return res; + } catch (error) { + // 捕获取消行为或接口错误 + throw error; + } + }; + + return { + handleAction, + handleDelete, + }; +}; diff --git a/src/pages/businessManage/businessOpport/index.vue b/src/pages/businessManage/businessOpport/index.vue new file mode 100644 index 0000000..586353f --- /dev/null +++ b/src/pages/businessManage/businessOpport/index.vue @@ -0,0 +1,13 @@ + + + \ No newline at end of file diff --git a/src/pages/businessManage/customer/index.vue b/src/pages/businessManage/customer/index.vue new file mode 100644 index 0000000..1407565 --- /dev/null +++ b/src/pages/businessManage/customer/index.vue @@ -0,0 +1,13 @@ + + + \ No newline at end of file diff --git a/src/pages/businessManage/gameStudios/index.vue b/src/pages/businessManage/gameStudios/index.vue new file mode 100644 index 0000000..5cc7a5f --- /dev/null +++ b/src/pages/businessManage/gameStudios/index.vue @@ -0,0 +1,13 @@ + + + \ No newline at end of file diff --git a/src/pages/stage/dict/dictManage.vue b/src/pages/stage/dict/dictManage.vue index 662437f..9eb5857 100644 --- a/src/pages/stage/dict/dictManage.vue +++ b/src/pages/stage/dict/dictManage.vue @@ -115,7 +115,7 @@ const onConfirm = async (formEl: FormInstance | undefined) => { onCancel(); emit('confirm-success'); } catch (error) { - console.log('error',error); + console.log('error',row.id); } finally{ loading.value = false; } diff --git a/src/pages/stage/dict/index.vue b/src/pages/stage/dict/index.vue index 765f525..800cea6 100644 --- a/src/pages/stage/dict/index.vue +++ b/src/pages/stage/dict/index.vue @@ -33,7 +33,9 @@ @@ -64,34 +66,10 @@ - - - - - - - @@ -106,7 +84,8 @@