zzz-pc-view 0.0.5 → 0.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zzz-pc-view",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "main": "src/index.umd.js",
5
5
  "module": "src/index.es.js",
6
6
  "types": "src/index.d.ts",
@@ -4,7 +4,7 @@ import { FilterHandler } from '../FilterKey';
4
4
  import { EditTypeEnum, CurdApi, EditType, PaginationResponseConstructor } from './CurdApi';
5
5
  import { Config as PrimaryKeyConfig } from './../PrimaryKey';
6
6
  import { Config as NameKeyConfig } from './../NameKey';
7
- import { RequestUtilResponse } from './RequestUtil';
7
+ import { RequestUtilResponse } from '../useRequestUtil';
8
8
  export * from './CurdApi';
9
9
  /**
10
10
  * 基础参数接口,用于定义通用的参数属性。
@@ -1,6 +1,7 @@
1
1
  export * from './DeclareType';
2
2
  export * from './loadUtil';
3
3
  export * from './loadStore';
4
+ export * from './useRequestUtil';
4
5
  export * from './api';
5
6
  export * from './Decorators';
6
7
  export { combineDecorator } from './decoratorStoreUtil';
@@ -1,5 +1,5 @@
1
- import { httpRequest } from '../../utils';
2
- import { LoadUtilResponse } from '../loadUtil';
1
+ import { httpRequest } from '../utils';
2
+ import { LoadUtilResponse } from './loadUtil';
3
3
  /**
4
4
  * 定义一个接口,描述请求工具的方法。
5
5
  * 这个接口包含取消请求和发送请求的方法。
package/src/index.es.js CHANGED
@@ -2151,6 +2151,59 @@ const useLoadUtil = () => {
2151
2151
  };
2152
2152
  const loadStore$1 = useLoadUtil();
2153
2153
  const useLoadStore = () => loadStore$1;
2154
+ const useRequestUtil = (endableLoadStatus) => {
2155
+ let request;
2156
+ let setLoadStatus = fn;
2157
+ const abort = () => {
2158
+ if (request) {
2159
+ request.ajaxSource.cancel();
2160
+ request = void 0;
2161
+ }
2162
+ };
2163
+ const response2 = {
2164
+ // 将 abort 方法添加到响应对象中
2165
+ abort,
2166
+ /**
2167
+ * 定义一个方法,用于发送请求并处理响应。
2168
+ * 这个方法会发送一个 HTTP 请求,并根据请求的结果调用相应的回调函数。
2169
+ * @method requestData
2170
+ * @param {T} httpRequest - 一个继承自 httpRequest.HttpRequestPromise 的泛型类型,表示 HTTP 请求对象。
2171
+ * @param {Function} [final] - 一个可选的函数,用于在请求完成后执行最终操作。
2172
+ * @returns {Promise<T extends httpRequest.HttpRequestPromise<infer R> ? R : never>} - 一个返回值为请求结果的 Promise。
2173
+ * @description 这个方法会在请求开始时调用 abort 方法,以取消之前的请求。
2174
+ * @description 它会在请求过程中更新加载状态,并在请求完成后重置加载状态。
2175
+ * @description 如果请求成功,它会返回请求的结果。
2176
+ * @description 如果请求失败,它会抛出错误。
2177
+ * @description 在请求完成后,它会调用 final 方法,并传递一个布尔值表示请求是否被取消。
2178
+ */
2179
+ async requestData(httpRequestPromise, final) {
2180
+ abort();
2181
+ setLoadStatus(true);
2182
+ request = httpRequestPromise;
2183
+ try {
2184
+ return await request;
2185
+ } catch (err) {
2186
+ throw err;
2187
+ } finally {
2188
+ setLoadStatus(false);
2189
+ let isAbort = false;
2190
+ if (request) {
2191
+ request = void 0;
2192
+ isAbort = true;
2193
+ }
2194
+ final == null ? void 0 : final(isAbort);
2195
+ }
2196
+ }
2197
+ };
2198
+ if (endableLoadStatus) {
2199
+ const loadStore2 = useLoadUtil();
2200
+ setLoadStatus = (status) => {
2201
+ loadStore2.setLoadStatus(status);
2202
+ };
2203
+ Object.defineProperties(response2, Object.getOwnPropertyDescriptors(loadStore2));
2204
+ }
2205
+ return response2;
2206
+ };
2154
2207
  let api;
2155
2208
  const setApi = (...args) => {
2156
2209
  api = create(...args);
@@ -3054,49 +3107,6 @@ class CurdApi {
3054
3107
  URL.revokeObjectURL(a.href);
3055
3108
  }
3056
3109
  }
3057
- const useRequestUtil = (endableLoadStatus) => {
3058
- let request;
3059
- const abort = () => {
3060
- if (request) {
3061
- request.ajaxSource.cancel();
3062
- request = void 0;
3063
- }
3064
- };
3065
- const response2 = {
3066
- // 将 abort 方法添加到响应对象中
3067
- abort,
3068
- /**
3069
- * 定义一个方法,用于发送请求并处理响应。
3070
- * 这个方法会发送一个 HTTP 请求,并根据请求的结果调用相应的回调函数。
3071
- * @method requestData
3072
- * @param {T} httpRequest - 一个继承自 httpRequest.HttpRequestPromise 的泛型类型,表示 HTTP 请求对象。
3073
- * @param {Function} [final] - 一个可选的函数,用于在请求完成后执行最终操作。
3074
- * @returns {Promise<T extends httpRequest.HttpRequestPromise<infer R> ? R : never>} - 一个返回值为请求结果的 Promise。
3075
- * @description 这个方法会在请求开始时调用 abort 方法,以取消之前的请求。
3076
- * @description 它会在请求过程中更新加载状态,并在请求完成后重置加载状态。
3077
- * @description 如果请求成功,它会返回请求的结果。
3078
- * @description 如果请求失败,它会抛出错误。
3079
- * @description 在请求完成后,它会调用 final 方法,并传递一个布尔值表示请求是否被取消。
3080
- */
3081
- async requestData(httpRequestPromise, final) {
3082
- abort();
3083
- request = httpRequestPromise;
3084
- try {
3085
- return await request;
3086
- } catch (err) {
3087
- throw err;
3088
- } finally {
3089
- let isAbort = false;
3090
- if (request) {
3091
- request = void 0;
3092
- isAbort = true;
3093
- }
3094
- final == null ? void 0 : final(isAbort);
3095
- }
3096
- }
3097
- };
3098
- return response2;
3099
- };
3100
3110
  const key = Symbol("CurdKey");
3101
3111
  const classCurdKey = Symbol("ClassCurdKey");
3102
3112
  var CreateTypeEnum = /* @__PURE__ */ ((CreateTypeEnum2) => {
@@ -3881,7 +3891,8 @@ const ZDecorators = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineP
3881
3891
  combineDecorator,
3882
3892
  setApi,
3883
3893
  useLoadStore,
3884
- useLoadUtil
3894
+ useLoadUtil,
3895
+ useRequestUtil
3885
3896
  }, Symbol.toStringTag, { value: "Module" }));
3886
3897
  var zhCn = {
3887
3898
  name: "zh-cn",