@vunk/form 1.1.63 → 1.1.64

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.
@@ -1,10 +1,11 @@
1
1
  import { _VkfFormItemCtx, VkfFormItem } from '@vunk/form/components/form-item';
2
- import { openBlock, createElementBlock, createElementVNode, defineComponent, reactive, ref, computed, watchEffect, resolveComponent, createBlock, mergeProps, withCtx, createVNode, normalizeClass, createCommentVNode, Fragment, renderList, normalizeStyle, createTextVNode } from 'vue';
2
+ import { openBlock, createElementBlock, createElementVNode, defineComponent, watch, ref, computed, watchEffect, onBeforeUnmount, resolveComponent, createBlock, mergeProps, withCtx, createVNode, normalizeClass, createCommentVNode, Fragment, renderList, normalizeStyle, createTextVNode } from 'vue';
3
3
  import { ElMessage, ElInput, ElButtonGroup, ElButton, ElIcon } 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
  import '@vunk/core/shared/utils-promise';
7
7
  import { isPlainObject as isPlainObject$1 } from '@vunk/core/shared/utils-object';
8
+ import { useModelComputed } from '@vunk/core/composables';
8
9
 
9
10
  var __defProp = Object.defineProperty;
10
11
  var __defProps = Object.defineProperties;
@@ -45,15 +46,27 @@ const props = __spreadProps(__spreadValues({}, _VkfFormItemCtx.props), {
45
46
  fileServiceType: {
46
47
  type: String,
47
48
  default: void 0
49
+ },
50
+ file: {
51
+ type: Object,
52
+ default: void 0
53
+ },
54
+ fileStatus: {
55
+ type: String,
56
+ default: void 0
48
57
  }
49
58
  });
50
59
  const emits = {
60
+ "update:file": null,
61
+ "update:fileStatus": null,
51
62
  success: (file) => file
52
63
  };
53
64
 
54
65
  var Status = /* @__PURE__ */ ((Status2) => {
55
66
  Status2["wait"] = "wait";
67
+ Status2["doPause"] = "doPause";
56
68
  Status2["pause"] = "pause";
69
+ Status2["doUpload"] = "doUpload";
57
70
  Status2["uploading"] = "uploading";
58
71
  Status2["error"] = "error";
59
72
  Status2["done"] = "done";
@@ -18173,6 +18186,9 @@ const merge = async (data) => {
18173
18186
  data,
18174
18187
  setRequestInit: setDefaultHeader
18175
18188
  }).then((res) => {
18189
+ if (res.code !== 200) {
18190
+ throw new Error(res.message);
18191
+ }
18176
18192
  return res.datas;
18177
18193
  });
18178
18194
  };
@@ -18290,8 +18306,27 @@ const _sfc_main = defineComponent({
18290
18306
  setup(props2, { emit }) {
18291
18307
  const formItemBindProps = _VkfFormItemCtx.createBindProps(props2);
18292
18308
  const uuid = Math.random().toString(36).slice(-8);
18293
- const container = reactive({});
18294
- const fileStatus = ref(Status.wait);
18309
+ const containerFile = useModelComputed({
18310
+ default: null,
18311
+ key: "file"
18312
+ }, props2, emit);
18313
+ const fileStatus = useModelComputed({
18314
+ default: Status.wait,
18315
+ key: "fileStatus"
18316
+ }, props2, emit);
18317
+ watch(() => fileStatus.value, (v, ov) => {
18318
+ if (v === Status.doUpload) {
18319
+ handleUpload();
18320
+ }
18321
+ if (v === Status.doPause) {
18322
+ if (ov === Status.uploading) {
18323
+ handlePause();
18324
+ } else {
18325
+ fileStatus.value = ov;
18326
+ }
18327
+ }
18328
+ });
18329
+ const containerHash = ref("");
18295
18330
  const chunks = ref([]);
18296
18331
  const uploadingXhrs = ref([]);
18297
18332
  const filePrefixIcon = computed(() => {
@@ -18312,17 +18347,17 @@ const _sfc_main = defineComponent({
18312
18347
  const target = e.target;
18313
18348
  const file = target.files?.[0];
18314
18349
  if (file) {
18315
- container.file = file;
18350
+ containerFile.value = file;
18316
18351
  fileStatus.value = Status.wait;
18317
18352
  }
18318
18353
  };
18319
18354
  const handleUpload = async () => {
18320
- if (!container.file)
18355
+ if (!containerFile.value)
18321
18356
  return;
18322
18357
  fileStatus.value = Status.uploading;
18323
- const chunkFiles = createFileChunk(container.file, props2.size);
18324
- const hash = await calculateFileHashSample(container.file);
18325
- container.hash = hash;
18358
+ const chunkFiles = createFileChunk(containerFile.value, props2.size);
18359
+ const hash = await calculateFileHashSample(containerFile.value);
18360
+ containerHash.value = hash;
18326
18361
  const { uploadedList, uploaded } = await verify({
18327
18362
  identifier: hash
18328
18363
  });
@@ -18335,12 +18370,11 @@ const _sfc_main = defineComponent({
18335
18370
  }
18336
18371
  const sliceSize = chunkFiles[0].size;
18337
18372
  chunks.value = chunkFiles.map((chunk, index) => {
18338
- const _container = container;
18339
- const chunkHash = _container.hash + "-" + index;
18373
+ const chunkHash = containerHash.value + "-" + index;
18340
18374
  return {
18341
- fileName: _container.file.name,
18342
- fileHash: _container.hash,
18343
- fileSize: _container.file.size,
18375
+ fileName: containerFile.value.name,
18376
+ fileHash: containerHash.value,
18377
+ fileSize: containerFile.value.size,
18344
18378
  chunk,
18345
18379
  hash: chunkHash,
18346
18380
  index,
@@ -18422,13 +18456,13 @@ const _sfc_main = defineComponent({
18422
18456
  });
18423
18457
  }
18424
18458
  function cFile() {
18425
- if (!container.file)
18459
+ if (!containerFile.value)
18426
18460
  return;
18427
- if (!container.hash)
18461
+ if (!containerHash.value)
18428
18462
  return;
18429
18463
  return merge({
18430
- filename: container.file.name,
18431
- identifier: container.hash,
18464
+ filename: containerFile.value.name,
18465
+ identifier: containerHash.value,
18432
18466
  fileServiceType: props2.fileServiceType,
18433
18467
  dictId: props2.dictId
18434
18468
  }).then((res) => {
@@ -18439,13 +18473,17 @@ const _sfc_main = defineComponent({
18439
18473
  type: "error",
18440
18474
  message: "\u5408\u5E76\u5931\u8D25"
18441
18475
  });
18476
+ throw err;
18442
18477
  });
18443
18478
  }
18479
+ onBeforeUnmount(() => {
18480
+ handlePause();
18481
+ });
18444
18482
  return {
18445
18483
  formItemBindProps,
18446
18484
  handleFileChange,
18447
18485
  uuid,
18448
- container,
18486
+ containerFile,
18449
18487
  handleUpload,
18450
18488
  fileStatus,
18451
18489
  chunks,
@@ -18487,7 +18525,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
18487
18525
  "is-success": _ctx.fileStatus === _ctx.Status.done,
18488
18526
  "is-error": _ctx.fileStatus === _ctx.Status.error
18489
18527
  }),
18490
- modelValue: _ctx.container.file?.name,
18528
+ modelValue: _ctx.containerFile?.name,
18491
18529
  prefixIcon: _ctx.filePrefixIcon,
18492
18530
  placeholder: "\u8BF7\u9009\u62E9\u6587\u4EF6"
18493
18531
  }, null, 8, ["class", "modelValue", "prefixIcon"]),
@@ -18542,10 +18580,19 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
18542
18580
  createTextVNode(" \u6682\u505C ")
18543
18581
  ]),
18544
18582
  _: 1
18545
- }, 8, ["onClick"])) : (openBlock(), createBlock(_component_el_button, {
18583
+ }, 8, ["onClick"])) : _ctx.fileStatus === _ctx.Status.done ? (openBlock(), createBlock(_component_ElButton, {
18546
18584
  key: 1,
18585
+ type: "success",
18586
+ disabled: ""
18587
+ }, {
18588
+ default: withCtx(() => [
18589
+ createTextVNode(" \u5DF2\u4F20 ")
18590
+ ]),
18591
+ _: 1
18592
+ })) : (openBlock(), createBlock(_component_el_button, {
18593
+ key: 2,
18547
18594
  type: "primary",
18548
- disabled: !_ctx.container.file,
18595
+ disabled: !_ctx.containerFile,
18549
18596
  onClick: _ctx.handleUpload
18550
18597
  }, {
18551
18598
  default: withCtx(() => [
@@ -18111,6 +18111,9 @@ const merge = async (data) => {
18111
18111
  data,
18112
18112
  setRequestInit: setDefaultHeader
18113
18113
  }).then((res) => {
18114
+ if (res.code !== 200) {
18115
+ throw new Error(res.message);
18116
+ }
18114
18117
  return res.datas;
18115
18118
  });
18116
18119
  };
@@ -1,6 +1,8 @@
1
1
  export declare enum Status {
2
2
  wait = "wait",
3
+ doPause = "doPause",
3
4
  pause = "pause",
5
+ doUpload = "doUpload",
4
6
  uploading = "uploading",
5
7
  error = "error",
6
8
  done = "done"
@@ -1,6 +1,8 @@
1
1
  var Status = /* @__PURE__ */ ((Status2) => {
2
2
  Status2["wait"] = "wait";
3
+ Status2["doPause"] = "doPause";
3
4
  Status2["pause"] = "pause";
5
+ Status2["doUpload"] = "doUpload";
4
6
  Status2["uploading"] = "uploading";
5
7
  Status2["error"] = "error";
6
8
  Status2["done"] = "done";
@@ -1,5 +1,6 @@
1
1
  import { FileInfo, FileServiceType } from './types';
2
2
  import { PropType } from 'vue';
3
+ import { Status } from './const';
3
4
  export declare const props: {
4
5
  size: {
5
6
  type: NumberConstructor;
@@ -24,6 +25,14 @@ export declare const props: {
24
25
  type: PropType<FileServiceType>;
25
26
  default: undefined;
26
27
  };
28
+ file: {
29
+ type: PropType<File>;
30
+ default: undefined;
31
+ };
32
+ fileStatus: {
33
+ type: PropType<Status>;
34
+ default: undefined;
35
+ };
27
36
  required: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, undefined, boolean>;
28
37
  label: StringConstructor;
29
38
  labelWidth: import("element-plus/es/utils").EpPropFinalized<readonly [StringConstructor, NumberConstructor], unknown, unknown, "", boolean>;
@@ -75,5 +84,7 @@ export declare const props: {
75
84
  };
76
85
  };
77
86
  export declare const emits: {
87
+ 'update:file': null;
88
+ 'update:fileStatus': null;
78
89
  success: (file: FileInfo) => FileInfo;
79
90
  };
@@ -39,9 +39,19 @@ const props = __spreadProps(__spreadValues({}, _VkfFormItemCtx.props), {
39
39
  fileServiceType: {
40
40
  type: String,
41
41
  default: void 0
42
+ },
43
+ file: {
44
+ type: Object,
45
+ default: void 0
46
+ },
47
+ fileStatus: {
48
+ type: String,
49
+ default: void 0
42
50
  }
43
51
  });
44
52
  const emits = {
53
+ "update:file": null,
54
+ "update:fileStatus": null,
45
55
  success: (file) => file
46
56
  };
47
57
 
@@ -20,6 +20,14 @@ declare const _default: import("vue").DefineComponent<{
20
20
  type: import("vue").PropType<import("./types").FileServiceType>;
21
21
  default: undefined;
22
22
  };
23
+ file: {
24
+ type: import("vue").PropType<File>;
25
+ default: undefined;
26
+ };
27
+ fileStatus: {
28
+ type: import("vue").PropType<Status>;
29
+ default: undefined;
30
+ };
23
31
  required: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, undefined, boolean>;
24
32
  label: StringConstructor;
25
33
  labelWidth: import("element-plus/es/utils").EpPropFinalized<readonly [StringConstructor, NumberConstructor], unknown, unknown, "", boolean>;
@@ -90,12 +98,9 @@ declare const _default: import("vue").DefineComponent<{
90
98
  }>;
91
99
  handleFileChange: (e: Event) => void;
92
100
  uuid: string;
93
- container: {
94
- file?: File | undefined;
95
- hash?: string | undefined;
96
- };
101
+ containerFile: import("vue").WritableComputedRef<File>;
97
102
  handleUpload: () => Promise<void>;
98
- fileStatus: import("vue").Ref<Status>;
103
+ fileStatus: import("vue").WritableComputedRef<Status>;
99
104
  chunks: import("vue").Ref<{
100
105
  fileName: string;
101
106
  fileHash: string;
@@ -112,6 +117,8 @@ declare const _default: import("vue").DefineComponent<{
112
117
  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<{}>>, {}>>;
113
118
  handlePause: () => void;
114
119
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
120
+ 'update:file': null;
121
+ 'update:fileStatus': null;
115
122
  success: (file: import("./types").FileInfo) => import("./types").FileInfo;
116
123
  }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
117
124
  size: {
@@ -134,6 +141,14 @@ declare const _default: import("vue").DefineComponent<{
134
141
  type: import("vue").PropType<import("./types").FileServiceType>;
135
142
  default: undefined;
136
143
  };
144
+ file: {
145
+ type: import("vue").PropType<File>;
146
+ default: undefined;
147
+ };
148
+ fileStatus: {
149
+ type: import("vue").PropType<Status>;
150
+ default: undefined;
151
+ };
137
152
  required: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, undefined, boolean>;
138
153
  label: StringConstructor;
139
154
  labelWidth: import("element-plus/es/utils").EpPropFinalized<readonly [StringConstructor, NumberConstructor], unknown, unknown, "", boolean>;
@@ -185,6 +200,8 @@ declare const _default: import("vue").DefineComponent<{
185
200
  };
186
201
  }>> & {
187
202
  onSuccess?: ((file: import("./types").FileInfo) => any) | undefined;
203
+ "onUpdate:file"?: ((...args: any[]) => any) | undefined;
204
+ "onUpdate:fileStatus"?: ((...args: any[]) => any) | undefined;
188
205
  }, {
189
206
  required: import("element-plus/es/utils").EpPropMergeType<BooleanConstructor, unknown, unknown>;
190
207
  labelWidth: import("element-plus/es/utils").EpPropMergeType<readonly [StringConstructor, NumberConstructor], unknown, unknown>;
@@ -197,8 +214,10 @@ declare const _default: import("vue").DefineComponent<{
197
214
  readonly: boolean;
198
215
  labelPosition: "right";
199
216
  accept: string;
217
+ file: File;
200
218
  url: string;
201
219
  fileServiceType: import("./types").FileServiceType;
202
220
  dictId: string;
221
+ fileStatus: Status;
203
222
  }>;
204
223
  export default _default;
@@ -1,9 +1,5 @@
1
1
  import { Status } from './const';
2
2
  export declare type FileServiceType = 'mongodb' | 'local' | 'obs' | 'oss';
3
- export interface FileContainer {
4
- file?: File;
5
- hash?: string;
6
- }
7
3
  export interface Chunk {
8
4
  fileName: string;
9
5
  fileHash: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vunk/form",
3
- "version": "1.1.63",
3
+ "version": "1.1.64",
4
4
  "description": "",
5
5
  "main": "index.esm.js",
6
6
  "scripts": {