wkjp-list-page 1.0.10 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Vue 2 + Element UI 通用列表页组件 **`CommonListPage`**(标签 `common-list-page`):搜索区、表格、分页;列表数据由组件通过 **`api`** 拉取并在内部维护分页与加载状态。
4
4
 
5
- **npm 当前版本:`2.2.0`**(`2.x` 起 **`api` 为必填**;**`auto-request` 默认 `false`**,首屏需自行 `fetchList` 或设为 `true`。)
5
+ **npm 包:`wkjp-list-page`**(**`api` 为必填**;**`block-list-request` 默认 `false`** 时组件会正常发起列表请求;设为 **`true`** 则**拦截本组件内所有**对 `api` 的列表请求,需由父页面在适当时机 **`this.$refs.xxx.fetchList({ force: true })`** 主动拉表。)
6
6
 
7
7
  ## 环境
8
8
 
@@ -47,7 +47,6 @@ Vue.use(CommonListPage);
47
47
  :search-option="deviceListSearchOption"
48
48
  :columns="deviceListColumns"
49
49
  :api="deviceListApi"
50
- :auto-request="true"
51
50
  />
52
51
  ```
53
52
 
@@ -73,7 +72,7 @@ deviceListApi(params) {
73
72
 
74
73
  - 发请求时带什么参数:不写 `build-params` 时,会把 **`filters` 里所有条件** 再加上 **当前第几页、每页几条**(字段名是 `currentPage`、`pageSize`,也会写回 `filters`)。若写了 `build-params`,则由你 **自己 return 整包参数**,既可改分页字段名,也可在 `filters` 之外 **单独加** 路由、父级状态等条件。
75
74
  - 接口返回怎么用:不写 `api-adapter` 时,认为列表在 **`res.object.list`**,总条数在 **`res.object.num`**。
76
- - **首屏列表**:默认 **`auto-request` 为 `false`**,进入页面**不会**自动调 `api`;需要一进页就查表时请加 **`:auto-request="true"`**,或在 `mounted` **`this.$refs.deviceListRef.fetchList()`**。
75
+ - **首屏列表**:默认 **`block-list-request` 为 `false`**,组件会照常 **`fetchList`**(含 `created`、查询、分页等)。若 **`block-list-request` 为 `true`**,上述内部调用**一律不请求** `api`;需要数据时请 **`this.$refs.xxx.fetchList({ force: true })`**(可带 **`resetPage: true`**)。
77
76
 
78
77
  下面这些是 **可选**:先照 §1 能跑起来,遇到对应场景再往组件上 **多绑一个属性** 即可。
79
78
 
@@ -204,13 +203,15 @@ deviceListTransformList(list) {
204
203
  }
205
204
  ```
206
205
 
207
- ### 2.10 一进页面就要自动查一次
206
+ ### 2.10 完全由父页面控制列表请求(`block-list-request`)
208
207
 
209
- **情况:** 希望打开页面就和以前一样立刻拉列表(`created` 里自动 `fetchList`)。
210
- **加:** `:auto-request="true"`
211
- **说明:** 默认 **`auto-request` 为 `false`**,进页不请求;可在 `mounted` 里 `this.$refs.xxx.fetchList()`,或打开本开关。
208
+ > **迁移:** 旧版曾使用 **`auto-request`** / **`autoRequest`**,已更名为 **`block-list-request`** / **`blockListRequest`**(为 **`true`** 时内部不调 `api`)。
212
209
 
213
- **补充:** `fetchList({ resetPage: true })` 会从第 1 页重新查;`false` 表示保持当前页。
210
+ **情况:** 不希望列表组件在 **`created`、点查询、分页、`autoQuery`** 等场景里自动调 `api`,由外层统一请求或延后请求。
211
+ **加:** `:block-list-request="true"`
212
+ **说明:** 默认 **`block-list-request` 为 `false`**:不拦截,与往常一样。为 **`true`** 时,组件内部所有 **`fetchList` 都不会真正请求** `api`(**一次都不会**)。需要拉表时请 **`this.$refs.xxx.fetchList({ force: true })`**;从第一页重查可 **`fetchList({ force: true, resetPage: true })`**。
213
+
214
+ **补充:** 带 **`force: true`** 时,仍可用 **`resetPage: true`** 从第一页重查;不带 `force` 且 `block-list-request` 为 `true` 时调用 `fetchList` 仍不会请求。
214
215
 
215
216
  ### 2.11 不想要「清除查询」,或想改按钮上的字
216
217
 
@@ -235,7 +236,7 @@ deviceListTransformList(list) {
235
236
  **情况:** 下拉只要 10、20、50,不要默认一长串。
236
237
  **加:** `:pagination="{ pSizes: [10, 20, 50] }"`
237
238
  **说明:** 这里的 **`pagination` 只用来合并进组件内部分页**(改 `pSizes` 等),不是让你自己维护当前第几页、总条数——那些仍是组件内部根据接口结果在管。
238
- **隐藏分页条:** 当 **`total` 不大于 `pSizes` 中的最小值**(例如共 3 条、最小每页 10 条)时,不再渲染底部分页器,避免无意义的「每页条数」与翻页。
239
+ **分页 `layout`:** 当 **`total` 不大于 `pSizes` 中的最小值**(例如共 3 条、最小每页 10 条)时,**不显示「每页条数」下拉与「前往页」**,只保留总数与翻页;数据超过一页时再显示完整分页控件。
239
240
 
240
241
  ---
241
242
 
@@ -264,7 +265,7 @@ deviceListTransformList(list) {
264
265
  | `buildParams` | `null` | 自定义整包请求参数;可改分页字段名,也可在 `filters` 外追加条件。 |
265
266
  | `apiAdapter` | `null` | `(res) => ({ list, total })`。 |
266
267
  | `transformList` | `null` | 入表前改 `list`。 |
267
- | `autoRequest` | `false` | 为 `true` 时在 `created` 自动请求一次;默认不请求,需自行 `fetchList` 或打开本项。 |
268
+ | `blockListRequest` | `false` | **`true`**:拦截组件内所有列表请求(`fetchList` 不调 `api`);拉表用 **`fetchList({ force: true })`**。**`false`**:不拦截,照常请求。 |
268
269
  | `enableColumnConfig` | `false` | `true` 显示「配置表单」弹窗。 |
269
270
  | `showExport` | `false` | 为 `true` 且提供 `exportApi` 时,在搜索区右侧显示内置 **`exportFile`** 导出按钮。 |
270
271
  | `exportApi` | `null` | `(params, headers?) => Promise`,导出请求;成功返回需含 `success`、`object`(下载链接),与内置导出组件约定一致。 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wkjp-list-page",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "Vue2 + ElementUI CommonListPage component",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -137,15 +137,15 @@
137
137
  </el-table>
138
138
 
139
139
  <el-pagination
140
- v-if="showPaginationBar"
140
+ v-if="innerPagination"
141
141
  background
142
142
  :total="innerPagination.total"
143
143
  :current-page="innerPagination.page"
144
144
  :page-size="innerPagination.pageSize"
145
145
  :page-sizes="innerPagination.pSizes || [10, 50, 100, 200]"
146
+ :layout="paginationLayout"
146
147
  @size-change="handleSizeChange"
147
148
  @current-change="handlePageChange"
148
- layout="total, sizes, prev, pager, next, jumper"
149
149
  ></el-pagination>
150
150
 
151
151
  <el-dialog
@@ -210,8 +210,12 @@ export default {
210
210
  apiAdapter: { type: Function, default: null },
211
211
  /** 写入表格前:`(list, rawRes) => list`,须返回数组 */
212
212
  transformList: { type: Function, default: null },
213
- /** 是否在 `created` 时自动请求一次;默认不请求,需自行 `fetchList` 或设 `true` */
214
- autoRequest: { type: Boolean, default: false },
213
+ /**
214
+ * **`true`** 时:**阻止本组件发起的所有列表请求**(`created`、查询、分页、`autoQuery` 等内部 `fetchList` 均不调 `api`)。
215
+ * 父页面需要拉表时,请 **`this.$refs.xxx.fetchList({ force: true })`**(可配合 **`resetPage: true`**)。
216
+ * 为 **`false`**(默认):不拦截,行为与往常一样。
217
+ */
218
+ blockListRequest: { type: Boolean, default: false },
215
219
  /**
216
220
  * 可选:与内部分页合并,用于覆盖 `pSizes`、`pageSize` 等(如 `{ pSizes: [10, 20, 50] }`)。
217
221
  * 不传则使用组件内默认分页配置。
@@ -346,10 +350,15 @@ export default {
346
350
  const nums = sizes.map((n) => Number(n)).filter((n) => Number.isFinite(n) && n > 0);
347
351
  return nums.length ? Math.min.apply(null, nums) : 10;
348
352
  },
349
- /** 总数不超过「每页条数」选项里的最小值时,不展示分页条(单页即可看完) */
350
- showPaginationBar() {
351
- if (!this.innerPagination) return false;
352
- return this.innerPagination.total > this.paginationMinPageSize;
353
+ /**
354
+ * 当 **`total` 不大于 `pSizes` 最小值**(单页即可装下)时,从 `layout` 去掉 **`sizes`**(每页条数)与 **`jumper`**(前往页),
355
+ * 仍保留 **总数、上一页、页码、下一页**;多页时再显示完整布局。
356
+ */
357
+ paginationLayout() {
358
+ if (!this.innerPagination) return "total, prev, pager, next";
359
+ const full = "total, sizes, prev, pager, next, jumper";
360
+ if (this.innerPagination.total > this.paginationMinPageSize) return full;
361
+ return "total, prev, pager, next";
353
362
  },
354
363
  exportQuerys() {
355
364
  return this.filters && typeof this.filters === "object" ? this.filters : {};
@@ -411,7 +420,7 @@ export default {
411
420
  created() {
412
421
  this.captureInitialFilters();
413
422
  this.applyInnerPaginationConfig();
414
- if (this.autoRequest) this.fetchList();
423
+ this.fetchList();
415
424
  },
416
425
  methods: {
417
426
  forwardSelectionChange(selection) {
@@ -616,7 +625,13 @@ export default {
616
625
  }
617
626
  return { list: [], total: 0 };
618
627
  },
619
- fetchList({ resetPage = false } = {}) {
628
+ fetchList(opts) {
629
+ const o = opts && typeof opts === "object" ? opts : {};
630
+ const resetPage = o.resetPage === true;
631
+ const force = o.force === true;
632
+ if (this.blockListRequest && !force) {
633
+ return Promise.resolve();
634
+ }
620
635
  if (resetPage) this.innerPagination.page = 1;
621
636
  this.syncPaginationToFilters();
622
637
  const params = this.buildRequestParams();