@cmstops/pro-compo 3.9.2-alpha.8 → 3.9.2-alpha.9

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.
@@ -7,24 +7,72 @@ export declare type TypeAddMediaParam = {
7
7
  directory_id: number;
8
8
  size: number;
9
9
  };
10
+ declare type WaterMark = {
11
+ id: string;
12
+ position: string;
13
+ url: string;
14
+ title: string;
15
+ };
16
+ declare type UploadTemplate = {
17
+ watermark?: {
18
+ default?: WaterMark;
19
+ images: WaterMark[];
20
+ };
21
+ };
10
22
  export declare function getSize(value: number): string;
11
23
  export declare function addMedia(BASE_API: string, params: TypeAddMediaParam): Promise<import("axios").AxiosResponse<any, any>>;
12
24
  export declare function getMediaDetails(BASE_API: string, repoId: number, id: number): Promise<import("axios").AxiosResponse<any, any>>;
13
25
  export declare function reTranscodeMedia(BASE_API: string, media_id: number): Promise<import("axios").AxiosResponse<any, any>>;
14
26
  declare type UploadOptions = {
15
- noAddMedia: boolean;
27
+ noAddMedia?: boolean;
28
+ };
29
+ declare type UploadFileOptions = {
30
+ template?: UploadTemplate;
16
31
  };
17
32
  export default function useUpload(options?: UploadOptions): {
18
33
  list: import("vue").Ref<any[], any[]>;
19
- uploadFile: (BASE_API: string, file: any, dir: number | undefined, repoId: number, callback?: CallbackFunc | undefined) => void;
34
+ uploadFile: (BASE_API: string, file: any, dir: number | undefined, repoId: number, callback?: CallbackFunc | undefined, upOptions?: UploadFileOptions | undefined) => void;
20
35
  reTranscode: (BASE_API: string, file: any) => Promise<boolean>;
21
36
  transcodingFile: (BASE_API: string, file: any, repoId: number) => void;
22
37
  recordTaskStatusChange: (file: any, progress: number, isTrans?: boolean | undefined) => void;
23
38
  removeRecord: (file: any) => void;
24
39
  };
40
+ export declare function getWatermarkTemplate(BASE_API: string): Promise<import("axios").AxiosResponse<any, any>>;
25
41
  export declare function useUploadConfig(): {
26
42
  config: import("vue").Ref<any, any>;
43
+ template: import("vue").Ref<{
44
+ watermark?: {
45
+ default?: {
46
+ id: string;
47
+ position: string;
48
+ url: string;
49
+ title: string;
50
+ } | undefined;
51
+ images: {
52
+ id: string;
53
+ position: string;
54
+ url: string;
55
+ title: string;
56
+ }[];
57
+ } | undefined;
58
+ }, UploadTemplate | {
59
+ watermark?: {
60
+ default?: {
61
+ id: string;
62
+ position: string;
63
+ url: string;
64
+ title: string;
65
+ } | undefined;
66
+ images: {
67
+ id: string;
68
+ position: string;
69
+ url: string;
70
+ title: string;
71
+ }[];
72
+ } | undefined;
73
+ }>;
27
74
  checkFileSizeOutLimit: (file: File, callback: (msg: string) => void) => boolean;
28
75
  initUploadConfig: (BASE_API: string, domainId: number) => Promise<void>;
76
+ initTemplate: (BASE_API: string) => Promise<void>;
29
77
  };
30
78
  export {};
@@ -73,7 +73,7 @@ function useUpload(options) {
73
73
  list.value = originList;
74
74
  }
75
75
  };
76
- const uploadFile = (BASE_API, file, dir = 0, repoId, callback) => {
76
+ const uploadFile = (BASE_API, file, dir = 0, repoId, callback, upOptions) => {
77
77
  const newFile = {
78
78
  id: file.id || generateUUID(),
79
79
  sig_id: file.sig_id || generateUUID(),
@@ -93,18 +93,24 @@ function useUpload(options) {
93
93
  };
94
94
  const uploading = upload.start(progress);
95
95
  uploading.then(async (url) => {
96
+ var _a;
96
97
  if (options == null ? void 0 : options.noAddMedia) {
97
98
  recordTaskStatusChange({ ...newFile, status: 0, url }, 1);
98
99
  callback && callback({ ...newFile, url }, "success");
99
100
  return;
100
101
  }
102
+ const params = {};
103
+ if ((_a = upOptions == null ? void 0 : upOptions.template) == null ? void 0 : _a.watermark) {
104
+ params.watermark = upOptions.template.watermark.default;
105
+ }
101
106
  const { code, message } = await addMedia(BASE_API, {
102
107
  url,
103
108
  size: newFile.size,
104
109
  directory_id: dir,
105
110
  repository_id: repoId,
106
111
  catalog: newFile.type,
107
- alias: newFile.name
112
+ alias: newFile.name,
113
+ ...params
108
114
  });
109
115
  if (code !== 0) {
110
116
  console.log("\u{1F525}\u{1F525}\u{1F525}\u{1F525}\u{1F525} \u4E0A\u4F20\u5931\u8D25\uFF1A", newFile.name, code, message);
@@ -194,9 +200,16 @@ function getConfiguration(BASE_API, params) {
194
200
  params
195
201
  });
196
202
  }
203
+ function getWatermarkTemplate(BASE_API) {
204
+ return request(BASE_API, {
205
+ url: `/poplar/v2/material/image/watermark`,
206
+ method: "get"
207
+ });
208
+ }
197
209
  function useUploadConfig() {
198
210
  const { get, set, remove } = useLocalstorage("LOCAL_UPLOAD_CONFIG");
199
211
  const config = ref(get() || {});
212
+ const template = ref({});
200
213
  async function initUploadConfig(BASE_API, domainId) {
201
214
  if (config.value.size_config_enabled != null)
202
215
  return;
@@ -245,11 +258,37 @@ function useUploadConfig() {
245
258
  );
246
259
  return false;
247
260
  }
261
+ async function initTemplate(BASE_API) {
262
+ try {
263
+ const { code, message } = await getWatermarkTemplate(BASE_API);
264
+ if (code !== 0)
265
+ return;
266
+ if (message) {
267
+ let defaultWaterMark;
268
+ if (Array.isArray(message.images)) {
269
+ message.images.forEach((item) => {
270
+ if (message.default === item.id)
271
+ defaultWaterMark = item;
272
+ });
273
+ }
274
+ template.value = {
275
+ watermark: {
276
+ default: defaultWaterMark,
277
+ images: message.images
278
+ }
279
+ };
280
+ }
281
+ } catch (e) {
282
+ console.error(e);
283
+ }
284
+ }
248
285
  window.addEventListener("beforeunload", remove, false);
249
286
  return {
250
287
  config,
288
+ template,
251
289
  checkFileSizeOutLimit,
252
- initUploadConfig
290
+ initUploadConfig,
291
+ initTemplate
253
292
  };
254
293
  }
255
- export { addMedia, useUpload as default, getMediaDetails, getSize, reTranscodeMedia, useUploadConfig };
294
+ export { addMedia, useUpload as default, getMediaDetails, getSize, getWatermarkTemplate, reTranscodeMedia, useUploadConfig };
@@ -1,6 +1,6 @@
1
- import { defineComponent, inject, computed, openBlock, createBlock, withCtx, renderSlot, createElementVNode, createVNode, unref, createElementBlock, toDisplayString, createCommentVNode, Fragment, renderList } from "vue";
1
+ import { defineComponent, inject, computed, onMounted, openBlock, createBlock, withCtx, renderSlot, createElementVNode, createVNode, unref, createElementBlock, toDisplayString, createCommentVNode, Fragment, renderList } from "vue";
2
2
  import _sfc_main$2 from "./Upload.js";
3
- import useUpload from "../../../../hooks/useUpload.js";
3
+ import useUpload, { useUploadConfig } from "../../../../hooks/useUpload.js";
4
4
  import _sfc_main$1 from "../ListWraper.js";
5
5
  const _hoisted_1 = { class: "list-upload" };
6
6
  const _hoisted_2 = { class: "list-content" };
@@ -22,6 +22,7 @@ const _sfc_main = defineComponent({
22
22
  var _a;
23
23
  return (_a = userInfo == null ? void 0 : userInfo.value) == null ? void 0 : _a.repository_id;
24
24
  });
25
+ const { template, initTemplate } = useUploadConfig();
25
26
  const { list, uploadFile, reTranscode, transcodingFile, removeRecord } = useUpload();
26
27
  function handleChange(file) {
27
28
  if (!baseAPI || !repoId.value)
@@ -31,7 +32,8 @@ const _sfc_main = defineComponent({
31
32
  file.file,
32
33
  0,
33
34
  repoId.value,
34
- (media) => transcodingFile(baseAPI, media, repoId.value)
35
+ (media) => transcodingFile(baseAPI, media, repoId.value),
36
+ { template: template.value }
35
37
  );
36
38
  }
37
39
  async function handleOptions(e) {
@@ -54,6 +56,9 @@ const _sfc_main = defineComponent({
54
56
  removeRecord(e.item);
55
57
  }
56
58
  }
59
+ onMounted(() => {
60
+ initTemplate(baseAPI);
61
+ });
57
62
  return (_ctx, _cache) => {
58
63
  return openBlock(), createBlock(_sfc_main$1, null, {
59
64
  "footer-extra": withCtx(() => [
@@ -75,7 +75,7 @@ function useUpload(options) {
75
75
  list.value = originList;
76
76
  }
77
77
  };
78
- const uploadFile = (BASE_API, file, dir = 0, repoId, callback) => {
78
+ const uploadFile = (BASE_API, file, dir = 0, repoId, callback, upOptions) => {
79
79
  const newFile = {
80
80
  id: file.id || index.generateUUID(),
81
81
  sig_id: file.sig_id || index.generateUUID(),
@@ -95,18 +95,24 @@ function useUpload(options) {
95
95
  };
96
96
  const uploading = upload.start(progress);
97
97
  uploading.then(async (url) => {
98
+ var _a;
98
99
  if (options == null ? void 0 : options.noAddMedia) {
99
100
  recordTaskStatusChange({ ...newFile, status: 0, url }, 1);
100
101
  callback && callback({ ...newFile, url }, "success");
101
102
  return;
102
103
  }
104
+ const params = {};
105
+ if ((_a = upOptions == null ? void 0 : upOptions.template) == null ? void 0 : _a.watermark) {
106
+ params.watermark = upOptions.template.watermark.default;
107
+ }
103
108
  const { code, message } = await addMedia(BASE_API, {
104
109
  url,
105
110
  size: newFile.size,
106
111
  directory_id: dir,
107
112
  repository_id: repoId,
108
113
  catalog: newFile.type,
109
- alias: newFile.name
114
+ alias: newFile.name,
115
+ ...params
110
116
  });
111
117
  if (code !== 0) {
112
118
  console.log("\u{1F525}\u{1F525}\u{1F525}\u{1F525}\u{1F525} \u4E0A\u4F20\u5931\u8D25\uFF1A", newFile.name, code, message);
@@ -196,9 +202,16 @@ function getConfiguration(BASE_API, params) {
196
202
  params
197
203
  });
198
204
  }
205
+ function getWatermarkTemplate(BASE_API) {
206
+ return request(BASE_API, {
207
+ url: `/poplar/v2/material/image/watermark`,
208
+ method: "get"
209
+ });
210
+ }
199
211
  function useUploadConfig() {
200
212
  const { get, set, remove } = useLocalStorage["default"]("LOCAL_UPLOAD_CONFIG");
201
213
  const config = vue.ref(get() || {});
214
+ const template = vue.ref({});
202
215
  async function initUploadConfig(BASE_API, domainId) {
203
216
  if (config.value.size_config_enabled != null)
204
217
  return;
@@ -247,16 +260,43 @@ function useUploadConfig() {
247
260
  );
248
261
  return false;
249
262
  }
263
+ async function initTemplate(BASE_API) {
264
+ try {
265
+ const { code, message } = await getWatermarkTemplate(BASE_API);
266
+ if (code !== 0)
267
+ return;
268
+ if (message) {
269
+ let defaultWaterMark;
270
+ if (Array.isArray(message.images)) {
271
+ message.images.forEach((item) => {
272
+ if (message.default === item.id)
273
+ defaultWaterMark = item;
274
+ });
275
+ }
276
+ template.value = {
277
+ watermark: {
278
+ default: defaultWaterMark,
279
+ images: message.images
280
+ }
281
+ };
282
+ }
283
+ } catch (e) {
284
+ console.error(e);
285
+ }
286
+ }
250
287
  window.addEventListener("beforeunload", remove, false);
251
288
  return {
252
289
  config,
290
+ template,
253
291
  checkFileSizeOutLimit,
254
- initUploadConfig
292
+ initUploadConfig,
293
+ initTemplate
255
294
  };
256
295
  }
257
296
  exports.addMedia = addMedia;
258
297
  exports["default"] = useUpload;
259
298
  exports.getMediaDetails = getMediaDetails;
260
299
  exports.getSize = getSize;
300
+ exports.getWatermarkTemplate = getWatermarkTemplate;
261
301
  exports.reTranscodeMedia = reTranscodeMedia;
262
302
  exports.useUploadConfig = useUploadConfig;
@@ -23,6 +23,7 @@ const _sfc_main = vue.defineComponent({
23
23
  var _a;
24
24
  return (_a = userInfo == null ? void 0 : userInfo.value) == null ? void 0 : _a.repository_id;
25
25
  });
26
+ const { template, initTemplate } = useUpload.useUploadConfig();
26
27
  const { list, uploadFile, reTranscode, transcodingFile, removeRecord } = useUpload["default"]();
27
28
  function handleChange(file) {
28
29
  if (!baseAPI || !repoId.value)
@@ -32,7 +33,8 @@ const _sfc_main = vue.defineComponent({
32
33
  file.file,
33
34
  0,
34
35
  repoId.value,
35
- (media) => transcodingFile(baseAPI, media, repoId.value)
36
+ (media) => transcodingFile(baseAPI, media, repoId.value),
37
+ { template: template.value }
36
38
  );
37
39
  }
38
40
  async function handleOptions(e) {
@@ -55,6 +57,9 @@ const _sfc_main = vue.defineComponent({
55
57
  removeRecord(e.item);
56
58
  }
57
59
  }
60
+ vue.onMounted(() => {
61
+ initTemplate(baseAPI);
62
+ });
58
63
  return (_ctx, _cache) => {
59
64
  return vue.openBlock(), vue.createBlock(ListWraper, null, {
60
65
  "footer-extra": vue.withCtx(() => [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmstops/pro-compo",
3
- "version": "3.9.2-alpha.8",
3
+ "version": "3.9.2-alpha.9",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "vue",