plain-design 1.0.0-beta.103 → 1.0.0-beta.104

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": "plain-design",
3
- "version": "1.0.0-beta.103",
3
+ "version": "1.0.0-beta.104",
4
4
  "description": "",
5
5
  "main": "dist/plain-design.min.js",
6
6
  "module": "dist/plain-design.commonjs.min.js",
@@ -2,11 +2,12 @@ import {iHttp} from "../createHttp";
2
2
  import {PlainObject} from "plain-utils/utils/event";
3
3
 
4
4
  export interface iUploadServiceConfig {
5
- http: iHttp,
6
- action: string,
7
- filename: string,
8
- prefix?: string,
9
- process?: (uploadData: iUploadData) => void | iUploadData | Promise<iUploadData | void>
5
+ http: iHttp, // 上传的http请求服务对象
6
+ action: string, // 默认上传路径
7
+ filename: string, // 上传文件名
8
+ getFilePathFromResponse: (resp: any) => string, // 从返回值中获取上传返回的图片路径
9
+ prefix?: string, // 默认图片路径前缀
10
+ process?: (uploadData: iUploadData) => void | iUploadData | Promise<iUploadData | void> // 处理请求参数uploadData拦截器
10
11
  }
11
12
 
12
13
  export interface iUploadData {
@@ -100,6 +100,7 @@ export const Image = designComponent({
100
100
  emit.onSuccess(state.src!);
101
101
  };
102
102
  image.onerror = (e) => {
103
+ console.error(`load image error: ${image.src}`, e, props.urlPrefix);
103
104
  state.status = eImageStatus.error;
104
105
  emit.onError(e);
105
106
  };
@@ -12,6 +12,7 @@ import {$file, FileServiceDefaultAccept, FileServiceUploadConfig} from "../$file
12
12
  import $configuration from "../$configuration";
13
13
  import {iUploadService} from "../$upload/createUploadService";
14
14
  import i18n from "../i18n";
15
+ import {iUploadServiceConfig} from "../$upload/upload.utils";
15
16
 
16
17
  /**
17
18
  * ImageUploader的状态
@@ -40,17 +41,21 @@ export const ImageUploader = designComponent({
40
41
  handleDelete: { type: Function as PropType<() => void | Promise<void>> }, // 自定义删除图片逻辑
41
42
  handleUpload: { type: Function as PropType<(file: File) => void | Promise<void>> }, // 自定义上传图片逻辑
42
43
  handlePreview: { type: Function as PropType<(url?: string) => void> }, // 自定义预览逻辑
43
- urlPrefix: { type: String },
44
- service: { type: Object as PropType<iUploadService> },
44
+ urlPrefix: { type: String }, // 图片路径前缀
45
+ service: { type: Object as PropType<iUploadService> }, // 文件上传服务
46
+ emitBase64: { type: Boolean }, // 当选择文件之后,是否将 base64 值更新到绑定值
47
+ getFilePathFromResponse: { type: Function as PropType<iUploadServiceConfig['getFilePathFromResponse']> },// 从上传结果中获取图片访问地址
45
48
  },
46
49
  inheritPropsType: HTMLDivElement,
47
50
  emits: {
48
51
  onUpdateModelValue: (val?: string) => true,
49
52
  onLoadSuccess: (url: string) => true,
50
53
  onLoadError: (e: string | Event) => true,
54
+ onLoadComplete: () => true,
51
55
  onUploadSuccess: (resp: PlainObject | string) => true,
52
56
  onUploadProgress: (percent: number, e: ProgressEvent) => true,
53
57
  onUploadFail: (e: any) => true,
58
+ onUploadComplete: () => true,
54
59
  },
55
60
  setup({ props, event: { emit } }) {
56
61
 
@@ -59,7 +64,8 @@ export const ImageUploader = designComponent({
59
64
  const urlPrefix = computed(() => props.urlPrefix || upload?.config.prefix);
60
65
 
61
66
  const { refs, onRef } = useRefs({ el: HTMLDivElement });
62
- const model = useModel(() => props.modelValue, emit.onUpdateModelValue, { autoWatch: false });
67
+
68
+ const model = useModel(() => props.modelValue, emit.onUpdateModelValue);
63
69
 
64
70
  const { editComputed } = useEdit();
65
71
 
@@ -70,7 +76,6 @@ export const ImageUploader = designComponent({
70
76
  });
71
77
 
72
78
  watch(() => props.modelValue, val => {
73
- model.value = Image.formatImagePath(val, urlPrefix.value);
74
79
  state.chooseBase64 = undefined;
75
80
  if (!model.value) {
76
81
  return state.status = eImageUploaderStatus.empty;
@@ -80,12 +85,14 @@ export const ImageUploader = designComponent({
80
85
  image.onload = () => {
81
86
  state.status = eImageUploaderStatus.success;
82
87
  emit.onLoadSuccess(model.value!);
88
+ emit.onLoadComplete();
83
89
  };
84
90
  image.onerror = (e) => {
85
91
  state.status = eImageUploaderStatus.error;
86
92
  emit.onLoadError(e);
93
+ emit.onLoadComplete();
87
94
  };
88
- image.src = model.value;
95
+ image.src = Image.formatImagePath(val, urlPrefix.value);
89
96
  }, { immediate: true });
90
97
 
91
98
  const classes = useClasses(() => [
@@ -125,10 +132,16 @@ export const ImageUploader = designComponent({
125
132
  onSuccess: (resp) => {
126
133
  if (!!config?.onSuccess) config.onSuccess(resp);
127
134
  console.log('upload success, resp:', resp);
128
- model.value = String(state.chooseBase64);
135
+ // model.value = String(state.chooseBase64);
136
+ const getFilePathFromResponse: iUploadServiceConfig['getFilePathFromResponse'] | undefined =
137
+ props.getFilePathFromResponse ||
138
+ upload?.config.getFilePathFromResponse;
139
+
140
+ model.value = getFilePathFromResponse?.(resp);
129
141
  state.chooseBase64 = undefined;
130
142
  state.status = eImageUploaderStatus.success;
131
143
  emit.onUploadSuccess(resp);
144
+ emit.onUploadComplete();
132
145
  dfd.resolve(resp);
133
146
  },
134
147
  onError: (e) => {
@@ -136,6 +149,7 @@ export const ImageUploader = designComponent({
136
149
  console.log('upload fail, e:', e);
137
150
  state.status = eImageUploaderStatus.fail;
138
151
  emit.onUploadFail(e);
152
+ emit.onUploadComplete();
139
153
  dfd.reject(e);
140
154
  },
141
155
  };
@@ -181,10 +195,12 @@ export const ImageUploader = designComponent({
181
195
  };
182
196
 
183
197
  const imageAttrs = computed(() => {
184
- return Object.keys(ImagePropsOptions).reduce((prev, key) => {
198
+ const ret = Object.keys(ImagePropsOptions).reduce((prev, key) => {
185
199
  prev[key] = (props as any)[key];
186
200
  return prev;
187
201
  }, {} as any);
202
+ ret.urlPrefix = urlPrefix.value;
203
+ return ret;
188
204
  });
189
205
 
190
206
  return {