@vunk/form 1.1.47 → 1.1.49

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.
@@ -8,6 +8,7 @@ import { getValue } from '@vunk/core/shared/helper';
8
8
  import { VkfTemplatesDefault } from '@vunk/form/components/templates-default';
9
9
  import { VkfTemplatesLayout } from '@vunk/form/components/templates-layout';
10
10
  import { pickObject } from '@vunk/core/shared/utils-object';
11
+ import { genTemplateIfFunc } from '@vunk/form/shared/form';
11
12
 
12
13
  var __defProp$1 = Object.defineProperty;
13
14
  var __defProps$1 = Object.defineProperties;
@@ -163,6 +164,13 @@ const _sfc_main = defineComponent({
163
164
  a.push(c);
164
165
  return a;
165
166
  }
167
+ if (Reflect.has(c, "templateIf")) {
168
+ const templateIfFunc = genTemplateIfFunc(c.templateIf);
169
+ const flag = templateIfFunc(props2.data);
170
+ if (!flag) {
171
+ return a;
172
+ }
173
+ }
166
174
  const colItem = genColItem(c, props2.colSource);
167
175
  if (!lastRow || getRowEmptySpan(lastRow) < itemSpan) {
168
176
  a.push(genRowItem(colItem, props2.rowSource));
@@ -1,4 +1,5 @@
1
1
  import { defineComponent, shallowReactive, provide, h, nextTick } from 'vue';
2
+ import { genTemplateIfFunc } from '@vunk/form/shared/form';
2
3
 
3
4
  const props = {
4
5
  source: {
@@ -56,25 +57,13 @@ const VkfFormItemRenderer = defineComponent({
56
57
  Reflect.deleteProperty(slotData, "templateType");
57
58
  Reflect.deleteProperty(slotData, "templateSlots");
58
59
  Reflect.deleteProperty(slotData, "templateIf");
59
- const createTemplateIf = () => {
60
- if (typeof c.templateIf === "boolean") {
61
- const flag = c.templateIf;
62
- return () => flag;
63
- } else if (typeof c.templateIf === "string") {
64
- const templateIf = new Function("data", c.templateIf);
65
- return templateIf;
66
- } else if (typeof c.templateIf === "function") {
67
- return c.templateIf;
68
- }
69
- return () => true;
70
- };
71
60
  const nodes = templateInstances[c.templateType].slots.default?.({
72
61
  data: slotData,
73
62
  raw: c,
74
63
  Renderer,
75
64
  k: currentK,
76
65
  key: currentK.join(",") + "-" + c.templateType + "-" + c?.prop || "no-prop",
77
- templateIf: createTemplateIf()
66
+ templateIf: genTemplateIfFunc(c.templateIf)
78
67
  });
79
68
  nodes && a.push(nodes);
80
69
  } else if (c.templateSlots?.default) {
@@ -256,8 +256,8 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
256
256
  _: 1
257
257
  }),
258
258
  createVNode(_component_VkfFormItemRendererTemplate, { type: "Component" }, {
259
- default: withCtx(({ data, raw, templateIf }) => [
260
- templateIf(data) ? (openBlock(), createBlock(resolveDynamicComponent(typeof data.is === "function" ? data.is(raw) : data.is), normalizeProps(mergeProps({ key: 0 }, _ctx.pickObject(data, { excludes: ["is"] }))), null, 16)) : createCommentVNode("v-if", true)
259
+ default: withCtx(({ data: props2, raw, templateIf }) => [
260
+ templateIf(_ctx.data) ? (openBlock(), createBlock(resolveDynamicComponent(typeof raw.is === "function" ? raw.is(raw) : raw.is), normalizeProps(mergeProps({ key: 0 }, _ctx.pickObject(props2, { excludes: ["is"] }))), null, 16)) : createCommentVNode("v-if", true)
261
261
  ]),
262
262
  _: 1
263
263
  })
@@ -1,6 +1,6 @@
1
1
  import { _VkfFormItemCtx, VkfFormItem } from '@vunk/form/components/form-item';
2
2
  import { openBlock, createElementBlock, createElementVNode, defineComponent, reactive, ref, computed, watchEffect, resolveComponent, createBlock, mergeProps, withCtx, createVNode, normalizeClass, createCommentVNode, Fragment, renderList, normalizeStyle, createTextVNode } from 'vue';
3
- import { ElInput, ElButtonGroup, ElButton, ElIcon } from 'element-plus';
3
+ import { ElInput, ElButtonGroup, ElButton, ElIcon, ElMessage } from 'element-plus';
4
4
  import { createFileChunk, calculateFileHashSample } from '@vunk/form/shared/upload';
5
5
  import { RestFetch } from '@vunk/core/shared/utils-fetch';
6
6
 
@@ -37,7 +37,9 @@ const props = __spreadProps(__spreadValues({}, _VkfFormItemCtx.props), {
37
37
  default: ""
38
38
  }
39
39
  });
40
- const emits = {};
40
+ const emits = {
41
+ success: (file) => file
42
+ };
41
43
 
42
44
  var Status = /* @__PURE__ */ ((Status2) => {
43
45
  Status2["wait"] = "wait";
@@ -111,7 +113,7 @@ const merge = async (data) => {
111
113
  url: "/dict/nfs/chunk/merge",
112
114
  data
113
115
  }).then((res) => {
114
- return res.datas;
116
+ return res.data;
115
117
  });
116
118
  };
117
119
 
@@ -360,6 +362,13 @@ const _sfc_main = defineComponent({
360
362
  filename: container.file.name,
361
363
  identifier: container.hash,
362
364
  dictId: props2.dictId
365
+ }).then((res) => {
366
+ emit("success", res);
367
+ }).catch(() => {
368
+ ElMessage({
369
+ type: "error",
370
+ message: "\u5408\u5E76\u5931\u8D25"
371
+ });
363
372
  });
364
373
  }
365
374
  return {
@@ -1,5 +1,5 @@
1
1
  import { RestFetch } from '@vunk/core/shared/utils-fetch';
2
- import { Chunk } from './types';
2
+ import { Chunk, FileInfo } from './types';
3
3
  export declare const restFetch: RestFetch;
4
4
  /**
5
5
  * https://app.apifox.com/link/project/2335162/apis/api-92811427
@@ -28,4 +28,4 @@ export declare const merge: (data: {
28
28
  identifier: string;
29
29
  filename: string;
30
30
  dictId?: string;
31
- }) => Promise<any>;
31
+ }) => Promise<FileInfo>;
@@ -58,7 +58,7 @@ const merge = async (data) => {
58
58
  url: "/dict/nfs/chunk/merge",
59
59
  data
60
60
  }).then((res) => {
61
- return res.datas;
61
+ return res.data;
62
62
  });
63
63
  };
64
64
 
@@ -1,3 +1,4 @@
1
+ import { FileInfo } from './types';
1
2
  export declare const props: {
2
3
  size: {
3
4
  type: NumberConstructor;
@@ -40,6 +41,9 @@ export declare const props: {
40
41
  inlineMessage: import("element-plus/es/utils").EpPropFinalized<readonly [StringConstructor, BooleanConstructor], unknown, unknown, "", boolean>;
41
42
  showMessage: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, true, boolean>;
42
43
  formItemSize: {
44
+ /**
45
+ * 上传目录
46
+ */
43
47
  type: import("vue").PropType<"default" | "small" | "large">;
44
48
  default: string;
45
49
  };
@@ -64,4 +68,6 @@ export declare const props: {
64
68
  default: string;
65
69
  };
66
70
  };
67
- export declare const emits: {};
71
+ export declare const emits: {
72
+ success: (file: FileInfo) => FileInfo;
73
+ };
@@ -33,6 +33,8 @@ const props = __spreadProps(__spreadValues({}, _VkfFormItemCtx.props), {
33
33
  default: ""
34
34
  }
35
35
  });
36
- const emits = {};
36
+ const emits = {
37
+ success: (file) => file
38
+ };
37
39
 
38
40
  export { emits, props };
@@ -103,7 +103,9 @@ declare const _default: import("vue").DefineComponent<{
103
103
  Status: typeof Status;
104
104
  filePrefixIcon: import("vue").ComputedRef<import("vue").DefineComponent<{}, {}, {}, import("vue").ComputedOptions, import("vue").MethodOptions, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}>>;
105
105
  handlePause: () => void;
106
- }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
106
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
107
+ success: (file: import("./types").FileInfo) => import("./types").FileInfo;
108
+ }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
107
109
  size: {
108
110
  type: NumberConstructor;
109
111
  default: number;
@@ -165,7 +167,9 @@ declare const _default: import("vue").DefineComponent<{
165
167
  type: import("vue").PropType<"right">;
166
168
  default: string;
167
169
  };
168
- }>>, {
170
+ }>> & {
171
+ onSuccess?: ((file: import("./types").FileInfo) => any) | undefined;
172
+ }, {
169
173
  required: import("element-plus/es/utils").EpPropMergeType<BooleanConstructor, unknown, unknown>;
170
174
  labelWidth: import("element-plus/es/utils").EpPropMergeType<readonly [StringConstructor, NumberConstructor], unknown, unknown>;
171
175
  inlineMessage: import("element-plus/es/utils").EpPropMergeType<readonly [StringConstructor, BooleanConstructor], unknown, unknown>;
@@ -21,4 +21,15 @@ export interface Chunk {
21
21
  sliceSize: number;
22
22
  status: Status;
23
23
  }
24
+ /**
25
+ * @example
26
+ * "filePath": "/raster/07b93085a0a5145cb09d9a1d39f43c07_微信图片_20211017140156.png",
27
+ "fileName": "微信图片_20211017140156.png",
28
+ "fileId": "/raster/07b93085a0a5145cb09d9a1d39f43c07_微信图片_20211017140156.png"
29
+ */
30
+ export interface FileInfo {
31
+ filePath: string;
32
+ fileName: string;
33
+ fileId: string;
34
+ }
24
35
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vunk/form",
3
- "version": "1.1.47",
3
+ "version": "1.1.49",
4
4
  "description": "",
5
5
  "main": "index.esm.js",
6
6
  "scripts": {
@@ -1,3 +1,4 @@
1
+ import { Func, NormalObject } from '@vunk/core';
1
2
  /**
2
3
  * 表单验证失败, 处理方式
3
4
  * 消息提示
@@ -7,3 +8,11 @@ export declare const validateCatch: (err: any, init?: {
7
8
  prefix?: string;
8
9
  suffix?: string;
9
10
  }) => void;
11
+ /**
12
+ * 根据 templateIf 生成 显隐函数
13
+ * @param templateIfRaw
14
+ * @returns
15
+ */
16
+ export declare const genTemplateIfFunc: Func<[
17
+ any
18
+ ], (e?: NormalObject) => boolean>;
@@ -14,5 +14,17 @@ const validateCatch = (err, init = {}) => {
14
14
  message: msg
15
15
  });
16
16
  };
17
+ const genTemplateIfFunc = (templateIfRaw) => {
18
+ if (typeof templateIfRaw === "boolean") {
19
+ const flag = templateIfRaw;
20
+ return () => flag;
21
+ } else if (typeof templateIfRaw === "string") {
22
+ const templateIf = new Function("data", templateIfRaw);
23
+ return templateIf;
24
+ } else if (typeof templateIfRaw === "function") {
25
+ return templateIfRaw;
26
+ }
27
+ return () => true;
28
+ };
17
29
 
18
- export { validateCatch };
30
+ export { genTemplateIfFunc, validateCatch };