wkjp-list-page 1.0.11 → 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
 
@@ -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.11",
3
+ "version": "1.0.12",
4
4
  "description": "Vue2 + ElementUI CommonListPage component",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -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
  * 不传则使用组件内默认分页配置。
@@ -416,7 +420,7 @@ export default {
416
420
  created() {
417
421
  this.captureInitialFilters();
418
422
  this.applyInnerPaginationConfig();
419
- if (this.autoRequest) this.fetchList();
423
+ this.fetchList();
420
424
  },
421
425
  methods: {
422
426
  forwardSelectionChange(selection) {
@@ -621,7 +625,13 @@ export default {
621
625
  }
622
626
  return { list: [], total: 0 };
623
627
  },
624
- 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
+ }
625
635
  if (resetPage) this.innerPagination.page = 1;
626
636
  this.syncPaginationToFilters();
627
637
  const params = this.buildRequestParams();