zzz-pc-view 0.0.149 → 0.0.151

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.149",
3
+ "version": "0.0.151",
4
4
  "main": "src/index.umd.js",
5
5
  "module": "src/index.es.js",
6
6
  "types": "src/index.d.ts",
@@ -31,7 +31,14 @@ export interface TableColumnParam extends BaseParam {
31
31
  /**
32
32
  * 表单项参数接口,继承自基础参数接口,用于定义表单项的特定参数。
33
33
  */
34
- export interface FormItemParam extends BaseParam {
34
+ export interface FormItemParam<T extends object = object> extends BaseParam {
35
+ setDefaultValue?: (param: {
36
+ createType: CreateTypeEnum;
37
+ model: T;
38
+ data?: T;
39
+ query?: T;
40
+ options?: unknown[];
41
+ }) => void;
35
42
  formItemProps?: ComponentProps;
36
43
  stepIndex?: number;
37
44
  rowGroup?: string;
@@ -40,10 +47,10 @@ export interface FormItemParam extends BaseParam {
40
47
  /**
41
48
  * 响应参数接口,用于定义返回数据的结构。
42
49
  */
43
- export interface ResponseParam {
50
+ export interface ResponseParam<T extends object = object> {
44
51
  label?: string;
45
52
  tableColumn?: TableColumnParam;
46
- formItem?: FormItemParam;
53
+ formItem?: FormItemParam<T>;
47
54
  }
48
55
  /**
49
56
  * 定义一个参数接口,用于创建 CurdHandler 实例时传递参数。
@@ -52,7 +59,7 @@ export interface ResponseParam {
52
59
  * @returns {ResponseParam} - 返回一个 ResponseParam 对象。
53
60
  */
54
61
  export interface Param<T extends object = object, H extends CurdHandler<T> = CurdHandler<T>> {
55
- (this: H): ResponseParam;
62
+ (this: H): ResponseParam<T>;
56
63
  }
57
64
  /**
58
65
  * 定义一个配置接口,继承自 BasePropertyConfig。
@@ -70,7 +77,7 @@ export interface Config<T extends object = object> extends BasePropertyConfig {
70
77
  * @extends {BasePropertyConfig} - 继承自 BasePropertyConfig。
71
78
  * @extends {ReturnType<Param>} - 包含 Param 函数的返回类型。
72
79
  */
73
- interface HandlerConfig extends BasePropertyConfig, ReturnType<Param> {
80
+ interface HandlerConfig<T extends object = object> extends BasePropertyConfig, ReturnType<Param<T>> {
74
81
  }
75
82
  /**
76
83
  * 定义一个分页请求的接口。
@@ -170,27 +177,20 @@ declare const classCurdKey: unique symbol;
170
177
  * @description 它包含了 FILTER、CREATE 和 CONTINUE_CREATE 三个成员,分别表示过滤、创建和继续创建操作。
171
178
  */
172
179
  export declare enum CreateTypeEnum {
173
- /**
174
- * 表示过滤操作,用于查询数据记录。
175
- * @type {number}
176
- * @description 这个成员的值是 1。
177
- * @description 它通常用于在表格中显示过滤条件,或者在表单中显示查询条件。
178
- */
179
- FILTER = 1,
180
180
  /**
181
181
  * 表示创建操作,用于创建新的数据记录。
182
182
  * @type {number}
183
- * @description 这个成员的值是 2
183
+ * @description 这个成员的值是 1
184
184
  * @description 它通常用于在表单中显示创建表单,或者在模态框中显示创建对话框。
185
185
  */
186
- CREATE = 2,
186
+ CREATE = 1,
187
187
  /**
188
188
  * 表示继续创建操作,用于在创建操作完成后继续创建新的数据记录。
189
189
  * @type {number}
190
- * @description 这个成员的值是 6
190
+ * @description 这个成员的值是 4
191
191
  * @description 它通常用于在创建表单中显示继续创建按钮,或者在模态框中显示继续创建对话框。
192
192
  */
193
- CONTINUE_CREATE = 6
193
+ CONTINUE_CREATE = 2
194
194
  }
195
195
  /**
196
196
  * 定义一个接口,用于描述 CURD 模型的构造函数。
@@ -203,7 +203,7 @@ export declare enum CreateTypeEnum {
203
203
  * @property {CurdHandler<T>} [classCurdKey] - 一个可选的属性,用于存储 CurdHandler 实例。
204
204
  */
205
205
  export interface CurdModelConstructor<T extends object = object, P extends PaginationResponse<T> = PaginationResponse<T>> extends TypeWithPrototype, CombineClass {
206
- new (createType: CreateTypeEnum, ...args: any[]): T;
206
+ new (...args: any[]): T;
207
207
  [classCurdKey]?: CurdHandler<T, P>;
208
208
  }
209
209
  export declare abstract class CurdHandler<T extends object = object, P extends PaginationResponse<T> = PaginationResponse<T>> extends FilterHandler<T> {
@@ -238,7 +238,7 @@ export declare abstract class CurdHandler<T extends object = object, P extends P
238
238
  * @description 这个引用是浅的,意味着它不会递归地观察嵌套对象的变化。
239
239
  * @description 这对于性能优化很重要,因为它避免了不必要的更新。
240
240
  */
241
- protected readonly curdConfigsRef: import('vue').ShallowRef<HandlerConfig[] | undefined, HandlerConfig[] | undefined>;
241
+ protected readonly curdConfigsRef: import('vue').ShallowRef<HandlerConfig<T>[] | undefined, HandlerConfig<T>[] | undefined>;
242
242
  /**
243
243
  * 根据指定的键获取并返回配置项数组。
244
244
  * 这个方法从 curdConfigsRef 中获取配置项,并根据 orderNo 对其进行排序。
@@ -248,7 +248,7 @@ export declare abstract class CurdHandler<T extends object = object, P extends P
248
248
  * @param {K} key - 要获取配置项的键。
249
249
  * @returns {Required<HandlerConfig>[K][]} - 一个包含排序后的配置项的数组。
250
250
  */
251
- protected getItemConfigs<K extends KeyMatch<Required<HandlerConfig>, BaseParam>>(key: K): (Required<HandlerConfig>[K] & {
251
+ protected getItemConfigs<K extends KeyMatch<Required<HandlerConfig>, BaseParam>>(key: K): (Required<HandlerConfig<object>>[K] & {
252
252
  propertyKey: KeyMatch<T, unknown>;
253
253
  })[];
254
254
  /**
@@ -286,7 +286,7 @@ export declare abstract class CurdHandler<T extends object = object, P extends P
286
286
  * @description 这个计算属性是只读的,意味着它不能被直接修改。
287
287
  * @description 它会在依赖项发生变化时自动更新。
288
288
  */
289
- protected readonly formItemsComputed: import('vue').ComputedRef<(FormItemParam & {
289
+ protected readonly formItemsComputed: import('vue').ComputedRef<(FormItemParam<object> & {
290
290
  propertyKey: KeyMatch<T, unknown>;
291
291
  })[]>;
292
292
  /**
@@ -296,7 +296,7 @@ export declare abstract class CurdHandler<T extends object = object, P extends P
296
296
  * @description 这个计算属性是只读的,意味着它不能被直接修改。
297
297
  * @description 它会在依赖项发生变化时自动更新。
298
298
  */
299
- protected readonly displayFormItemsComputed: import('vue').ComputedRef<(FormItemParam & {
299
+ protected readonly displayFormItemsComputed: import('vue').ComputedRef<(FormItemParam<object> & {
300
300
  propertyKey: KeyMatch<T, unknown>;
301
301
  })[]>;
302
302
  /**
@@ -749,6 +749,7 @@ export declare abstract class CurdHandler<T extends object = object, P extends P
749
749
  * @returns {void}
750
750
  */
751
751
  saveEditorData(callback?: (data: T) => void): void;
752
+ protected getCreateData(createType: CreateTypeEnum, data?: T): any;
752
753
  /**
753
754
  * 保存编辑器数据并继续创建新数据。
754
755
  * 此方法会调用 `saveEditorData` 方法保存当前编辑器中的数据,
package/src/index.es.js CHANGED
@@ -5443,9 +5443,8 @@ const useCurdMock = (option) => {
5443
5443
  const key = Symbol("CurdKey");
5444
5444
  const classCurdKey = Symbol("ClassCurdKey");
5445
5445
  var CreateTypeEnum = /* @__PURE__ */ ((CreateTypeEnum2) => {
5446
- CreateTypeEnum2[CreateTypeEnum2["FILTER"] = 1] = "FILTER";
5447
- CreateTypeEnum2[CreateTypeEnum2["CREATE"] = 2] = "CREATE";
5448
- CreateTypeEnum2[CreateTypeEnum2["CONTINUE_CREATE"] = 6] = "CONTINUE_CREATE";
5446
+ CreateTypeEnum2[CreateTypeEnum2["CREATE"] = 1] = "CREATE";
5447
+ CreateTypeEnum2[CreateTypeEnum2["CONTINUE_CREATE"] = 2] = "CONTINUE_CREATE";
5449
5448
  return CreateTypeEnum2;
5450
5449
  })(CreateTypeEnum || {});
5451
5450
  class CurdHandler extends FilterHandler {
@@ -5988,7 +5987,7 @@ class CurdHandler extends FilterHandler {
5988
5987
  * @param {number} total - 列表数据的总数。
5989
5988
  */
5990
5989
  setList(list2, total) {
5991
- this.listRef.value = list2.length > 0 && list2[0] instanceof this.CurdTarget ? this.CurdTarget.bindList(list2) : list2;
5990
+ this.listRef.value = list2.length > 0 && !(list2[0] instanceof this.CurdTarget) ? this.CurdTarget.bindList(list2) : list2;
5992
5991
  this.totalRef.value = total;
5993
5992
  }
5994
5993
  /**
@@ -6228,6 +6227,26 @@ class CurdHandler extends FilterHandler {
6228
6227
  }).catch(() => {
6229
6228
  });
6230
6229
  }
6230
+ getCreateData(createType, data) {
6231
+ const editorData = Object.setPrototypeOf({}, this.CurdTarget.prototype);
6232
+ const { filterConfigMap } = this;
6233
+ const formItems = this.formItemsComputed.value;
6234
+ formItems.forEach(({ propertyKey, setDefaultValue }) => {
6235
+ var _a2, _b2;
6236
+ if (typeof setDefaultValue === "function") {
6237
+ const mapping = (_a2 = filterConfigMap[propertyKey]) == null ? void 0 : _a2.mapping;
6238
+ setDefaultValue({
6239
+ createType: 2,
6240
+ model: editorData,
6241
+ data,
6242
+ query: this.searchQueryRef.value,
6243
+ // options?: unknown[]
6244
+ options: (mapping == null ? void 0 : mapping.Target) ? (_b2 = getData(mapping.Target)) == null ? void 0 : _b2.listRef.value : void 0
6245
+ });
6246
+ }
6247
+ });
6248
+ return editorData;
6249
+ }
6231
6250
  /**
6232
6251
  * 保存编辑器数据并继续创建新数据。
6233
6252
  * 此方法会调用 `saveEditorData` 方法保存当前编辑器中的数据,
@@ -6238,7 +6257,7 @@ class CurdHandler extends FilterHandler {
6238
6257
  editorDataSaveAndContinue() {
6239
6258
  this.saveEditorData(() => {
6240
6259
  this.formStepIndex = 0;
6241
- this.setEditorData(new this.CurdTarget(6, this.editorData));
6260
+ this.setEditorData(this.getCreateData(2, this.editorData));
6242
6261
  });
6243
6262
  }
6244
6263
  /**
@@ -12029,7 +12048,7 @@ class CurdViewHandler extends CurdHandler {
12029
12048
  __publicField(this, "onCreateBtnClick", (data) => {
12030
12049
  this.openEditor(
12031
12050
  EditTypeEnum.CREATE,
12032
- new this.CurdTarget(CreateTypeEnum.CREATE, data)
12051
+ this.getCreateData(CreateTypeEnum.CREATE, data)
12033
12052
  );
12034
12053
  });
12035
12054
  /**