From 9fea29454f172ec0eefcd45a8d3b045f1ac45f6a Mon Sep 17 00:00:00 2001 From: guochunsi <1595020186@qq.com> Date: Thu, 29 Jan 2026 11:56:37 +0800 Subject: [PATCH 1/7] a --- docs/hooks-table使用检查.md | 103 ++++++++++++++++++ .../professionalpartychange/index.vue | 7 +- .../index.vue | 3 +- .../index.vue | 3 +- .../index.vue | 37 ++----- .../professionalteacherhonor/index.vue | 49 +++------ .../index.vue | 7 +- .../professionalteachertype/index.vue | 27 +---- .../index.vue | 25 +---- .../professionaltitlelevelconfig/index.vue | 24 +--- .../professionaltitlerelation/form.vue | 2 +- .../professionaltitlerelation/index.vue | 39 +++---- .../professionaltopiclevelconfig/index.vue | 26 +---- .../professionaltopicsourceconfig/index.vue | 26 +---- .../professionalworktype/index.vue | 26 +---- .../professionalyearbounds/index.vue | 27 +---- .../professional/salaryexportrecord/index.vue | 21 +--- .../teacherawardtax/importAwardTax.vue | 17 +-- .../professional/teacherawardtax/index.vue | 21 +--- src/views/professional/teacherbase/index.vue | 2 +- .../professional/teacherpayslip/index.vue | 34 ++---- .../professional/teachersalary/index.vue | 39 ++----- .../professional/teachersalary/salaryInfo.vue | 2 +- .../professional/typeofworkconfig/index.vue | 27 +---- .../recruit/recruitstudentplan/index.vue | 6 +- .../index.vue | 6 +- .../recruit/recruitstudentplangroup/index.vue | 2 +- .../index.vue | 6 +- 28 files changed, 230 insertions(+), 384 deletions(-) create mode 100644 docs/hooks-table使用检查.md diff --git a/docs/hooks-table使用检查.md b/docs/hooks-table使用检查.md new file mode 100644 index 0000000..ca60f16 --- /dev/null +++ b/docs/hooks-table使用检查.md @@ -0,0 +1,103 @@ +# hooks/table 使用方法检查 + +## 一、useTable 源码要点(`src/hooks/table.ts`) + +### 1. 入参 `BasicTableProps` + +| 属性 | 类型 | 默认值 | 说明 | +|------|------|--------|------| +| `createdIsNeed` | `boolean` | **true** | 是否在 `onMounted` 时自动请求列表 | +| `isPage` | `boolean` | true | 是否分页 | +| `queryForm` | `any` | `{}` | 查询条件,会合并到请求参数 | +| `pageList` | `(...arg: any) => Promise` | - | **必填**,分页接口方法 | +| `props` | `object` | `{ item: 'records', totalCount: 'total' }` | 列表/总数的数据路径 | +| `validate` | `Function` | - | 请求前校验,不通过则不请求 | +| `onLoaded` | `Function` | - | 请求成功、写入 `dataList` 后的回调 | +| `onCascaded` | `Function` | - | 级联回调 | +| `pagination` | `Pagination` | 见源码 | 分页配置 | + +### 2. 内部逻辑 + +- **请求参数**:`query()` 调用 `state.pageList({ ...state.queryForm, current, size, descs, ascs })`。 +- **响应处理**:用 `state.props.item`、`state.props.totalCount` 从 `res.data` 取列表和总数,写入 `state.dataList`、`state.pagination.total`。 +- **首次加载**:在 **hooks 内部的 `onMounted`** 里,若 `state.createdIsNeed === true` 则执行一次 `query()`。 +- **注意**:`useTable` **不 return state**,调用方需要自己持有一份 `state`(通常用 `reactive`)并传给 `useTable(state)`,表格数据、分页、loading 都写在这份 `state` 上。 + +### 3. 返回值 + +```ts +{ + getDataList, // (refresh?: any) => void,默认重置到第 1 页再请求;getDataList(false) 不重置页码 + currentChangeHandle, // 页码变化时调用 + sizeChangeHandle, // 每页条数变化时调用 + sortChangeHandle, // 排序变化时调用(若表格支持 sortable="custom") + tableStyle, // { cellStyle, headerCellStyle } + downBlobFile // 下载文件 +} +``` + +--- + +## 二、推荐用法(与 search-form 配合) + +### 1. 定义 state 并传入 useTable + +```ts +import { BasicTableProps, useTable } from '/@/hooks/table' + +const search = reactive({ deptCode: '', realName: '', teacherNo: '' }) + +const state = reactive({ + queryForm: search, // 与 search-form 的 :model 同一对象 + pageList: fetchList, // 或自定义方法合并额外参数 + // createdIsNeed 不写则默认为 true,首屏自动请求 +}) + +const { getDataList, currentChangeHandle, sizeChangeHandle, tableStyle } = useTable(state) +``` + +- **state 由调用方定义并传入**,不要在解构时期望 `useTable` 返回 `state`(源码未返回)。 + +### 2. 模板绑定 + +- 表格:`:data="state.dataList"`、`v-loading="state.loading"`,`tableStyle` 用于 `cell-style` / `header-cell-style`。 +- 分页:`v-bind="state.pagination"` 或分别绑定 `current`/`size`/`total`,事件用 `@current-change="currentChangeHandle"`、`@size-change="sizeChangeHandle"`。 + +### 3. 查询 / 重置 / 刷新 + +- 点击「查询」:先更新 `search`(或额外参数),再 `getDataList()`(会回到第 1 页)。 +- 重置:清空 `search`(及 ref 里的额外参数),可选 `searchFormRef?.resetFields()`,再 `getDataList()`。 +- 只刷新当前页:`getDataList(false)`。 + +### 4. 与 createdIsNeed 的关系 + +- **createdIsNeed: true(默认)**:hooks 内部 onMounted 会自动调一次 `query()`,**页面里不需要再在 onMounted 里调 getDataList()**,否则会重复请求。 +- **createdIsNeed: false**:不在挂载时请求,需要自己在合适时机(例如 onMounted 或某个条件满足后)调用 `getDataList()`。 + +--- + +## 三、professionaltitlerelation/index.vue 检查结果 + +| 检查项 | 状态 | 说明 | +|--------|------|------| +| queryForm 使用 search | ✅ | 与 search-form 的 model 一致 | +| pageList 返回结构 | ✅ | 返回 `{ data: { records, total } }`,与默认 props 一致 | +| createdIsNeed | ✅ | 未配置即默认 true,首屏由 useTable 自动请求 | +| onMounted 不重复请求 | ✅ | 仅 `loadDictData()`,未再调 getDataList | +| 表格绑定 state.dataList / state.loading | ✅ | 正确 | +| 分页绑定 state.pagination + currentChangeHandle/sizeChangeHandle | ✅ | 正确 | +| 查询 handleFilter → getDataList() | ✅ | 正确 | +| 重置 resetQuery → 清空 search + getDataList() | ✅ | 正确 | +| 删除/审核后 getDataList() | ✅ | 正确 | +| tableStyle 用于 el-table | ✅ | 正确 | + +**结论**:当前 `professionaltitlerelation/index.vue` 对 hooks/table 的使用符合上述规范,无需修改。 + +--- + +## 四、常见注意点 + +1. **不要从 useTable 解构 state**:源码未返回 state,应自己在页面里 `const state = reactive({...})` 并传给 `useTable(state)`。 +2. **文档中若写 `const { state } = useTable(state)`**:属于文档笔误,实际应使用调用方定义的 `state`。 +3. **自定义 pageList 时**:返回结构需与 `props` 一致,默认即 `res.data.records`、`res.data.total`;若后端字段不同,可同时配置 `props: { item: 'xxx', totalCount: 'yyy' }`。 +4. **需要额外请求参数时**:在 `pageList` 里对入参做合并,例如 `return await fetchList({ ...queryParams, ...params.value })`。 diff --git a/src/views/professional/professionalpartychange/index.vue b/src/views/professional/professionalpartychange/index.vue index c5a6170..76651b9 100755 --- a/src/views/professional/professionalpartychange/index.vue +++ b/src/views/professional/professionalpartychange/index.vue @@ -82,7 +82,7 @@ + + diff --git a/src/views/professional/professionaltitlerelation/index.vue b/src/views/professional/professionaltitlerelation/index.vue index 2b82b73..b038cce 100755 --- a/src/views/professional/professionaltitlerelation/index.vue +++ b/src/views/professional/professionaltitlerelation/index.vue @@ -172,16 +172,30 @@ type="success" link icon="CircleCheck" - v-if="permissions.professional_professionaltitlerelation_exam && scope.row.state === '0'" + v-if="permissions.professional_professionaltitlerelation_exam && scope.row.canExam" @click="changeState(scope.row, 1)">通过 + 部门通过 + 驳回 + 部门驳回 + Date: Thu, 29 Jan 2026 14:04:20 +0800 Subject: [PATCH 3/7] 1 --- src/views/professional/professionalteacherhonor/index.vue | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/views/professional/professionalteacherhonor/index.vue b/src/views/professional/professionalteacherhonor/index.vue index d78e635..9484580 100755 --- a/src/views/professional/professionalteacherhonor/index.vue +++ b/src/views/professional/professionalteacherhonor/index.vue @@ -136,8 +136,9 @@ 部门通过 部门驳回 Date: Thu, 29 Jan 2026 14:06:56 +0800 Subject: [PATCH 4/7] 1 --- .../professionalteachercertificaterelation/index.vue | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/views/professional/professionalteachercertificaterelation/index.vue b/src/views/professional/professionalteachercertificaterelation/index.vue index 84be1ba..b1d13ee 100755 --- a/src/views/professional/professionalteachercertificaterelation/index.vue +++ b/src/views/professional/professionalteachercertificaterelation/index.vue @@ -141,8 +141,9 @@ 部门通过 部门驳回 Date: Thu, 29 Jan 2026 14:12:30 +0800 Subject: [PATCH 5/7] 1 --- src/views/basic/basicstudent/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/basic/basicstudent/index.vue b/src/views/basic/basicstudent/index.vue index 2cffe8c..8cbe62f 100644 --- a/src/views/basic/basicstudent/index.vue +++ b/src/views/basic/basicstudent/index.vue @@ -139,7 +139,7 @@ 重置 - + From 682af86d80ad40f2854a41b3aae890364271e1d2 Mon Sep 17 00:00:00 2001 From: guochunsi <1595020186@qq.com> Date: Thu, 29 Jan 2026 17:51:30 +0800 Subject: [PATCH 6/7] a --- .../common/commonSmallMultiPicUpload.vue | 5 ++-- .../professional/common/showEvidence.vue | 4 +-- .../professional/common/showHonorEdvince.vue | 4 +-- .../outercompanyemployee/index.vue | 7 ++++- .../outercompanyemployee/indexTrain.vue | 29 +++++-------------- .../teacherpayslip/importBaseSalary.vue | 17 +---------- .../teacherpayslip/importTaxSalary.vue | 17 +---------- .../teachersalary/importBaseSalary.vue | 17 +---------- .../teachersalary/importTaxSalary.vue | 17 +---------- .../recruit/backSchoolCheckin/statistics.vue | 17 +---------- .../recruit/newstucheckin/statistics.vue | 19 ++---------- src/views/recruit/recruitexampeople/index.vue | 21 ++------------ .../recruit/recruitstudentplan/index.vue | 23 +++------------ .../index.vue | 23 +++------------ .../recruit/recruitstudentsignup/update.vue | 22 +++++--------- .../index.vue | 23 +++------------ 16 files changed, 48 insertions(+), 217 deletions(-) diff --git a/src/views/professional/common/commonSmallMultiPicUpload.vue b/src/views/professional/common/commonSmallMultiPicUpload.vue index 736d8d1..678297b 100644 --- a/src/views/professional/common/commonSmallMultiPicUpload.vue +++ b/src/views/professional/common/commonSmallMultiPicUpload.vue @@ -13,9 +13,8 @@