@cmstops/pro-compo 0.3.43 → 0.3.45
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/dist/index.css +38 -2
- package/dist/index.min.css +1 -1
- package/es/hooks/useAttachement.d.ts +5 -0
- package/es/hooks/useLocalStorage.d.ts +8 -0
- package/es/hooks/useLocalStorage.js +31 -0
- package/es/hooks/useUpload.d.ts +2 -1
- package/es/hooks/useUpload.js +48 -11
- package/es/index.css +38 -2
- package/es/selectResourceModal/component.js +176 -43
- package/es/selectResourceModal/components/ListCardWrapper/index.js +9 -7
- package/es/selectResourceModal/components/ListContentLocal/index.js +15 -9
- package/es/selectResourceModal/components/ListSelected/index.js +19 -6
- package/es/selectResourceModal/components/ListTabs/index.js +61 -0
- package/es/selectResourceModal/scripts/useResourceSelect.d.ts +7 -0
- package/es/selectResourceModal/scripts/useResourceSelect.js +25 -0
- package/es/selectResourceModal/style/index.css +30 -1
- package/es/selectResourceModal/style/listCardWrapper.less +25 -1
- package/es/selectResourceModal/style/listSelected.less +9 -0
- package/es/thumbCard/component.js +21 -13
- package/es/thumbCard/style/index.css +8 -1
- package/es/thumbCard/style/index.less +8 -1
- package/es/utils/transcodeMedia.d.ts +13 -0
- package/es/utils/transcodeMedia.js +46 -0
- package/lib/hooks/useLocalStorage.js +34 -0
- package/lib/hooks/useUpload.js +47 -10
- package/lib/index.css +38 -2
- package/lib/selectResourceModal/component.js +174 -41
- package/lib/selectResourceModal/components/ListCardWrapper/index.js +9 -7
- package/lib/selectResourceModal/components/ListContentLocal/index.js +14 -8
- package/lib/selectResourceModal/components/ListSelected/index.js +18 -5
- package/lib/selectResourceModal/components/ListTabs/index.js +62 -0
- package/lib/selectResourceModal/scripts/useResourceSelect.js +27 -0
- package/lib/selectResourceModal/style/index.css +30 -1
- package/lib/selectResourceModal/style/listCardWrapper.less +25 -1
- package/lib/selectResourceModal/style/listSelected.less +9 -0
- package/lib/thumbCard/component.js +19 -11
- package/lib/thumbCard/style/index.css +8 -1
- package/lib/thumbCard/style/index.less +8 -1
- package/lib/utils/transcodeMedia.js +49 -0
- package/package.json +2 -2
- package/es/selectResourceModal/components/Main/index.js +0 -215
- package/lib/selectResourceModal/components/Main/index.js +0 -216
- /package/es/selectResourceModal/components/{Main → ListTabs}/index.d.ts +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ref, computed } from "vue";
|
|
2
|
+
function useResourceSelect(props) {
|
|
3
|
+
const selected = ref([]);
|
|
4
|
+
const selectedKeys = computed(() => selected.value.map((item) => item.id));
|
|
5
|
+
const disableSelect = computed(() => props.maxcount && selected.value.length >= props.maxcount);
|
|
6
|
+
function handleSelect(params) {
|
|
7
|
+
const { id } = params;
|
|
8
|
+
const index = selected.value.findIndex((item) => item.id === id);
|
|
9
|
+
if (index > -1)
|
|
10
|
+
selected.value.splice(index, 1);
|
|
11
|
+
else
|
|
12
|
+
selected.value.push(params);
|
|
13
|
+
}
|
|
14
|
+
function handleClear() {
|
|
15
|
+
selected.value = [];
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
selected,
|
|
19
|
+
selectedKeys,
|
|
20
|
+
disableSelect,
|
|
21
|
+
handleSelect,
|
|
22
|
+
handleClear
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export { useResourceSelect };
|
|
@@ -71,10 +71,18 @@
|
|
|
71
71
|
overflow: hidden;
|
|
72
72
|
}
|
|
73
73
|
.list-panel-wrapper .list-selected-record .list-selected-item .item-thumb {
|
|
74
|
+
position: relative;
|
|
74
75
|
width: 50px;
|
|
75
76
|
height: 38px;
|
|
76
77
|
overflow: hidden;
|
|
77
78
|
}
|
|
79
|
+
.list-panel-wrapper .list-selected-record .list-selected-item .item-thumb .item-tag {
|
|
80
|
+
position: absolute;
|
|
81
|
+
top: 50%;
|
|
82
|
+
left: 50%;
|
|
83
|
+
color: white;
|
|
84
|
+
transform: translate(-50%, -50%);
|
|
85
|
+
}
|
|
78
86
|
.list-panel-wrapper .list-selected-record .list-selected-item .item-alias {
|
|
79
87
|
flex: 1;
|
|
80
88
|
overflow: hidden;
|
|
@@ -104,13 +112,31 @@
|
|
|
104
112
|
.card-wrapper-image {
|
|
105
113
|
position: relative;
|
|
106
114
|
overflow: hidden;
|
|
107
|
-
cursor: pointer;
|
|
108
115
|
}
|
|
109
116
|
.card-wrapper-image .card-wrapper {
|
|
110
117
|
position: relative;
|
|
111
118
|
overflow: hidden;
|
|
119
|
+
border-radius: 2px;
|
|
120
|
+
transition: all 0.3s ease-in-out;
|
|
112
121
|
aspect-ratio: 4 / 3;
|
|
113
122
|
}
|
|
123
|
+
.card-wrapper-image .card-wrapper.disable:not(.active) {
|
|
124
|
+
opacity: 0.4;
|
|
125
|
+
}
|
|
126
|
+
.card-wrapper-image .card-wrapper .mask {
|
|
127
|
+
position: absolute;
|
|
128
|
+
top: 0;
|
|
129
|
+
z-index: 9;
|
|
130
|
+
display: none;
|
|
131
|
+
width: 100%;
|
|
132
|
+
height: 100%;
|
|
133
|
+
font-size: 18px;
|
|
134
|
+
background: rgba(0, 0, 0, 0.3);
|
|
135
|
+
cursor: pointer;
|
|
136
|
+
}
|
|
137
|
+
.card-wrapper-image .card-wrapper.active .mask {
|
|
138
|
+
display: block;
|
|
139
|
+
}
|
|
114
140
|
.card-wrapper-image .card-alias {
|
|
115
141
|
width: 100%;
|
|
116
142
|
margin-top: 6px;
|
|
@@ -120,6 +146,8 @@
|
|
|
120
146
|
line-height: 22px;
|
|
121
147
|
white-space: nowrap;
|
|
122
148
|
text-overflow: ellipsis;
|
|
149
|
+
user-select: none;
|
|
150
|
+
-webkit-user-drag: none;
|
|
123
151
|
}
|
|
124
152
|
.card-wrapper-image:hover .check-box-wrapper .check-box,
|
|
125
153
|
.card-wrapper-image .check-box-wrapper .check-box.active {
|
|
@@ -129,6 +157,7 @@
|
|
|
129
157
|
position: absolute;
|
|
130
158
|
top: 8px;
|
|
131
159
|
left: 8px;
|
|
160
|
+
z-index: 10;
|
|
132
161
|
cursor: pointer;
|
|
133
162
|
}
|
|
134
163
|
.card-wrapper-image .check-box-wrapper .check-box {
|
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
.card-wrapper-image {
|
|
2
2
|
position: relative;
|
|
3
3
|
overflow: hidden;
|
|
4
|
-
cursor: pointer;
|
|
5
4
|
|
|
6
5
|
.card-wrapper {
|
|
7
6
|
position: relative;
|
|
8
7
|
overflow: hidden;
|
|
8
|
+
border-radius: 2px;
|
|
9
|
+
transition: all 0.3s ease-in-out;
|
|
9
10
|
// 宽高:43
|
|
10
11
|
aspect-ratio: 4 / 3;
|
|
12
|
+
|
|
13
|
+
&.disable:not(.active) {
|
|
14
|
+
opacity: 0.4;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.mask {
|
|
18
|
+
position: absolute;
|
|
19
|
+
top: 0;
|
|
20
|
+
z-index: 9;
|
|
21
|
+
display: none;
|
|
22
|
+
width: 100%;
|
|
23
|
+
height: 100%;
|
|
24
|
+
font-size: 18px;
|
|
25
|
+
background: rgba(0, 0, 0, 0.3);
|
|
26
|
+
cursor: pointer;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&.active .mask {
|
|
30
|
+
display: block;
|
|
31
|
+
}
|
|
11
32
|
}
|
|
12
33
|
|
|
13
34
|
.card-alias {
|
|
@@ -19,6 +40,8 @@
|
|
|
19
40
|
line-height: 22px;
|
|
20
41
|
white-space: nowrap;
|
|
21
42
|
text-overflow: ellipsis;
|
|
43
|
+
user-select: none;
|
|
44
|
+
-webkit-user-drag: none;
|
|
22
45
|
}
|
|
23
46
|
|
|
24
47
|
&:hover .check-box-wrapper .check-box,
|
|
@@ -30,6 +53,7 @@
|
|
|
30
53
|
position: absolute;
|
|
31
54
|
top: 8px;
|
|
32
55
|
left: 8px;
|
|
56
|
+
z-index: 10;
|
|
33
57
|
cursor: pointer;
|
|
34
58
|
|
|
35
59
|
.check-box {
|
|
@@ -59,9 +59,18 @@
|
|
|
59
59
|
overflow: hidden;
|
|
60
60
|
|
|
61
61
|
.item-thumb {
|
|
62
|
+
position: relative;
|
|
62
63
|
width: 50px;
|
|
63
64
|
height: 38px;
|
|
64
65
|
overflow: hidden;
|
|
66
|
+
|
|
67
|
+
.item-tag {
|
|
68
|
+
position: absolute;
|
|
69
|
+
top: 50%;
|
|
70
|
+
left: 50%;
|
|
71
|
+
color: white;
|
|
72
|
+
transform: translate(-50%, -50%);
|
|
73
|
+
}
|
|
65
74
|
}
|
|
66
75
|
|
|
67
76
|
.item-alias {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { defineComponent, computed, openBlock, createElementBlock, normalizeClass, normalizeStyle, createVNode, unref,
|
|
1
|
+
import { defineComponent, computed, openBlock, createElementBlock, normalizeClass, normalizeStyle, createVNode, unref, createCommentVNode, Fragment, withCtx, createTextVNode, createElementVNode, createBlock, mergeProps, renderList, withModifiers, toDisplayString } from "vue";
|
|
2
2
|
import { IconPlus } from "@arco-design/web-vue/es/icon";
|
|
3
|
-
import { IconResource, IconComputer } from "@arco-iconbox/vue-cmstop-icons";
|
|
3
|
+
import { IconResource, IconComputer, IconVideoTag, IconAudioTag } from "@arco-iconbox/vue-cmstop-icons";
|
|
4
4
|
import { Progress, Dropdown, Doption, Image } from "@arco-design/web-vue";
|
|
5
5
|
import magic from "./assets/magic.js";
|
|
6
6
|
import { DEFAULT_BASE_API } from "../config.js";
|
|
@@ -9,9 +9,13 @@ const _hoisted_1 = {
|
|
|
9
9
|
key: 0,
|
|
10
10
|
class: "thumb-upload-loading"
|
|
11
11
|
};
|
|
12
|
-
const _hoisted_2 = {
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const _hoisted_2 = {
|
|
13
|
+
key: 0,
|
|
14
|
+
class: "thumb-upload-text"
|
|
15
|
+
};
|
|
16
|
+
const _hoisted_3 = { class: "thumb-handler-list" };
|
|
17
|
+
const _hoisted_4 = ["onClick"];
|
|
18
|
+
const _hoisted_5 = {
|
|
15
19
|
key: 3,
|
|
16
20
|
class: "thumb-select-tag"
|
|
17
21
|
};
|
|
@@ -39,7 +43,7 @@ const _sfc_main = defineComponent({
|
|
|
39
43
|
var _a;
|
|
40
44
|
return ((_a = props.meta) == null ? void 0 : _a.progress) != null;
|
|
41
45
|
});
|
|
42
|
-
const
|
|
46
|
+
const realThumb = computed(() => {
|
|
43
47
|
if (["image", "video"].includes(props.catalog || "")) {
|
|
44
48
|
return props.thumb || props.url || "";
|
|
45
49
|
}
|
|
@@ -75,7 +79,7 @@ const _sfc_main = defineComponent({
|
|
|
75
79
|
emits("edit", { key });
|
|
76
80
|
}
|
|
77
81
|
return (_ctx, _cache) => {
|
|
78
|
-
var _a, _b;
|
|
82
|
+
var _a, _b, _c;
|
|
79
83
|
return openBlock(), createElementBlock("div", {
|
|
80
84
|
class: normalizeClass(["thumb-select-wrapper", classList.value]),
|
|
81
85
|
style: normalizeStyle(styleObject.value)
|
|
@@ -83,8 +87,9 @@ const _sfc_main = defineComponent({
|
|
|
83
87
|
isUploading.value ? (openBlock(), createElementBlock("div", _hoisted_1, [
|
|
84
88
|
createVNode(unref(Progress), {
|
|
85
89
|
type: "circle",
|
|
86
|
-
percent: (
|
|
87
|
-
}, null, 8, ["percent"])
|
|
90
|
+
percent: (_a = _ctx.meta) == null ? void 0 : _a.progress
|
|
91
|
+
}, null, 8, ["percent"]),
|
|
92
|
+
((_b = _ctx.meta) == null ? void 0 : _b.isTrans) ? (openBlock(), createElementBlock("div", _hoisted_2, "\u8F6C\u7801\u4E2D...")) : createCommentVNode("v-if", true)
|
|
88
93
|
])) : _ctx.isEdit && !_ctx.url ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
|
|
89
94
|
createCommentVNode(" \u7F16\u8F91\u6A21\u5F0F\u4E0B\u53EF\u4F7F\u7528\u60AC\u6D6E\u6846\u5FEB\u901F\u63D2\u5165\u7D20\u6750 "),
|
|
90
95
|
createVNode(unref(Dropdown), {
|
|
@@ -123,20 +128,23 @@ const _sfc_main = defineComponent({
|
|
|
123
128
|
_ctx.catalog ? (openBlock(), createBlock(unref(Image), mergeProps({
|
|
124
129
|
key: 0,
|
|
125
130
|
class: "thumb-image",
|
|
126
|
-
src:
|
|
131
|
+
src: realThumb.value
|
|
127
132
|
}, aImageAttr.value), null, 16, ["src"])) : createCommentVNode("v-if", true),
|
|
128
133
|
createCommentVNode(" \u5C55\u793A\u6A21\u5F0F "),
|
|
129
|
-
createElementVNode("div",
|
|
134
|
+
createElementVNode("div", _hoisted_3, [
|
|
130
135
|
(openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.handlersKey, (item) => {
|
|
131
136
|
return openBlock(), createElementBlock("div", {
|
|
132
137
|
key: item.key,
|
|
133
138
|
class: "handler-item",
|
|
134
139
|
onClick: withModifiers(() => handleOption(item.key), ["stop"])
|
|
135
|
-
}, toDisplayString(item.label), 9,
|
|
140
|
+
}, toDisplayString(item.label), 9, _hoisted_4);
|
|
136
141
|
}), 128))
|
|
137
142
|
])
|
|
138
143
|
], 64)) : createCommentVNode("v-if", true),
|
|
139
|
-
["video", "audio"].includes(_ctx.catalog) && _ctx.meta ? (openBlock(), createElementBlock("div",
|
|
144
|
+
["video", "audio"].includes(_ctx.catalog) && _ctx.meta ? (openBlock(), createElementBlock("div", _hoisted_5, [
|
|
145
|
+
_ctx.catalog === "video" ? (openBlock(), createBlock(unref(IconVideoTag), { key: 0 })) : (openBlock(), createBlock(unref(IconAudioTag), { key: 1 })),
|
|
146
|
+
createTextVNode(" " + toDisplayString(unref(mediaTime)((_c = _ctx.meta) == null ? void 0 : _c.length)), 1)
|
|
147
|
+
])) : createCommentVNode("v-if", true)
|
|
140
148
|
], 6);
|
|
141
149
|
};
|
|
142
150
|
}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
}
|
|
12
12
|
.thumb-select-wrapper .thumb-upload-loading {
|
|
13
13
|
display: flex;
|
|
14
|
+
flex-direction: column;
|
|
14
15
|
align-items: center;
|
|
15
16
|
justify-content: center;
|
|
16
17
|
width: 100%;
|
|
@@ -29,6 +30,8 @@
|
|
|
29
30
|
.thumb-select-wrapper .thumb-image img {
|
|
30
31
|
width: 100%;
|
|
31
32
|
height: 100%;
|
|
33
|
+
user-select: none;
|
|
34
|
+
-webkit-user-drag: none;
|
|
32
35
|
}
|
|
33
36
|
.thumb-select-wrapper .thumb-handler-list {
|
|
34
37
|
position: absolute;
|
|
@@ -68,9 +71,13 @@
|
|
|
68
71
|
position: absolute;
|
|
69
72
|
right: 5px;
|
|
70
73
|
bottom: 5px;
|
|
71
|
-
|
|
74
|
+
display: flex;
|
|
75
|
+
gap: 2px;
|
|
76
|
+
align-items: center;
|
|
77
|
+
padding: 2px 5px;
|
|
72
78
|
color: #fff;
|
|
73
79
|
font-size: 12px;
|
|
80
|
+
line-height: 14px;
|
|
74
81
|
background-color: rgba(0, 0, 0, 0.5);
|
|
75
82
|
border-radius: 16px;
|
|
76
83
|
opacity: 1;
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
// loading 模式
|
|
14
14
|
.thumb-upload-loading {
|
|
15
15
|
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
16
17
|
align-items: center;
|
|
17
18
|
justify-content: center;
|
|
18
19
|
width: 100%;
|
|
@@ -37,6 +38,8 @@
|
|
|
37
38
|
img {
|
|
38
39
|
width: 100%;
|
|
39
40
|
height: 100%;
|
|
41
|
+
user-select: none;
|
|
42
|
+
-webkit-user-drag: none;
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
|
|
@@ -89,9 +92,13 @@
|
|
|
89
92
|
position: absolute;
|
|
90
93
|
right: 5px;
|
|
91
94
|
bottom: 5px;
|
|
92
|
-
|
|
95
|
+
display: flex;
|
|
96
|
+
gap: 2px;
|
|
97
|
+
align-items: center;
|
|
98
|
+
padding: 2px 5px;
|
|
93
99
|
color: #fff;
|
|
94
100
|
font-size: 12px;
|
|
101
|
+
line-height: 14px;
|
|
95
102
|
background-color: rgba(0, 0, 0, 0.5);
|
|
96
103
|
border-radius: 16px;
|
|
97
104
|
opacity: 1;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function getTranscodingProgress(BASE_API: string, id: number): import("axios").AxiosPromise<any>;
|
|
2
|
+
/**
|
|
3
|
+
* 转码逻辑
|
|
4
|
+
* @description 转码逻辑抽离,后期所有涉及到转码的地方都可用该方法
|
|
5
|
+
*/
|
|
6
|
+
export declare class TranscodingTask {
|
|
7
|
+
file: any;
|
|
8
|
+
pollCount: number;
|
|
9
|
+
taskInterval: any;
|
|
10
|
+
constructor(file: any);
|
|
11
|
+
start(BASE_API: string, callback: (progress: number) => any): Promise<unknown>;
|
|
12
|
+
abort(): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import request from "./request.js";
|
|
2
|
+
function getTranscodingProgress(BASE_API, id) {
|
|
3
|
+
return request(BASE_API, {
|
|
4
|
+
url: `/poplar/v2/transcoding/progress?id=${id}`,
|
|
5
|
+
method: "get"
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
class TranscodingTask {
|
|
9
|
+
constructor(file) {
|
|
10
|
+
this.file = file;
|
|
11
|
+
this.pollCount = 0;
|
|
12
|
+
}
|
|
13
|
+
start(BASE_API, callback) {
|
|
14
|
+
if (!this.file.id)
|
|
15
|
+
return Promise.reject(new Error("file error"));
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const handleTranscoding = async () => {
|
|
18
|
+
const { code, message } = await getTranscodingProgress(
|
|
19
|
+
BASE_API,
|
|
20
|
+
this.file.id
|
|
21
|
+
);
|
|
22
|
+
if (code !== 0)
|
|
23
|
+
reject(new Error(message));
|
|
24
|
+
if (message.state === 1) {
|
|
25
|
+
callback(message.progress);
|
|
26
|
+
if (message.progress === 1 && ++this.pollCount === 3) {
|
|
27
|
+
this.abort();
|
|
28
|
+
resolve(false);
|
|
29
|
+
}
|
|
30
|
+
} else if (message.state === 2) {
|
|
31
|
+
this.abort();
|
|
32
|
+
resolve(false);
|
|
33
|
+
} else if (message.state === 3) {
|
|
34
|
+
this.abort();
|
|
35
|
+
resolve(true);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
this.taskInterval = setInterval(handleTranscoding, 5e3);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
abort() {
|
|
42
|
+
clearInterval(this.taskInterval);
|
|
43
|
+
this.taskInterval = null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export { TranscodingTask, getTranscodingProgress };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const LOCALSTORAGE_KEYS = {
|
|
4
|
+
LOCAL_RESOURCES: "cmstop-local-resources"
|
|
5
|
+
};
|
|
6
|
+
function useLocalstorage(key) {
|
|
7
|
+
function get() {
|
|
8
|
+
const ret = localStorage.getItem(LOCALSTORAGE_KEYS[key]);
|
|
9
|
+
try {
|
|
10
|
+
if (typeof ret !== "string")
|
|
11
|
+
return ret;
|
|
12
|
+
return JSON.parse(ret);
|
|
13
|
+
} catch (e) {
|
|
14
|
+
return ret;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function set(value) {
|
|
18
|
+
if (typeof value === "object") {
|
|
19
|
+
localStorage.setItem(LOCALSTORAGE_KEYS[key], JSON.stringify(value));
|
|
20
|
+
} else {
|
|
21
|
+
localStorage.setItem(LOCALSTORAGE_KEYS[key], value);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function remove() {
|
|
25
|
+
localStorage.removeItem(LOCALSTORAGE_KEYS[key]);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
get,
|
|
29
|
+
set,
|
|
30
|
+
remove
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
exports.LOCALSTORAGE_KEYS = LOCALSTORAGE_KEYS;
|
|
34
|
+
exports["default"] = useLocalstorage;
|
package/lib/hooks/useUpload.js
CHANGED
|
@@ -4,6 +4,8 @@ var vue = require("vue");
|
|
|
4
4
|
var index = require("../utils/index.js");
|
|
5
5
|
var tusUpload = require("../utils/tusUpload.js");
|
|
6
6
|
var request = require("../utils/request.js");
|
|
7
|
+
var transcodeMedia = require("../utils/transcodeMedia.js");
|
|
8
|
+
var useLocalStorage = require("./useLocalStorage.js");
|
|
7
9
|
function addMedia(BASE_API, params) {
|
|
8
10
|
return request(BASE_API, {
|
|
9
11
|
url: "/poplar/v2/media/add",
|
|
@@ -12,7 +14,8 @@ function addMedia(BASE_API, params) {
|
|
|
12
14
|
});
|
|
13
15
|
}
|
|
14
16
|
function useUpload() {
|
|
15
|
-
const
|
|
17
|
+
const { get, set, remove } = useLocalStorage["default"]("LOCAL_RESOURCES");
|
|
18
|
+
const list = vue.ref(get() || []);
|
|
16
19
|
function uploadSuccess(file) {
|
|
17
20
|
const originList = list.value;
|
|
18
21
|
const taskIndex = originList.findIndex(
|
|
@@ -23,13 +26,15 @@ function useUpload() {
|
|
|
23
26
|
list.value = originList;
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
|
-
function recordTaskStatusChange(file, progress) {
|
|
29
|
+
function recordTaskStatusChange(file, progress, isTrans) {
|
|
27
30
|
const originList = list.value;
|
|
28
31
|
const taskIndex = originList.findIndex((task) => task.id === file.id);
|
|
29
32
|
if (taskIndex !== -1) {
|
|
30
|
-
progress !== -1 && (originList[taskIndex].progress = progress);
|
|
33
|
+
progress !== -1 && (originList[taskIndex].progress = Math.round(progress));
|
|
31
34
|
file.status != null && (originList[taskIndex].status = file.status);
|
|
32
35
|
file.msg != null && (originList[taskIndex].msg = file.msg);
|
|
36
|
+
if (isTrans)
|
|
37
|
+
originList[taskIndex].isTrans = true;
|
|
33
38
|
originList[taskIndex].url = file.url;
|
|
34
39
|
} else {
|
|
35
40
|
file.created_at = new Date().getTime();
|
|
@@ -66,24 +71,56 @@ function useUpload() {
|
|
|
66
71
|
});
|
|
67
72
|
if (code !== 0) {
|
|
68
73
|
console.log("\u{1F525}\u{1F525}\u{1F525}\u{1F525}\u{1F525} \u4E0A\u4F20\u5931\u8D25\uFF1A", newFile.name, code, message);
|
|
69
|
-
recordTaskStatusChange({ ...newFile, status: 2, msg: "\
|
|
74
|
+
recordTaskStatusChange({ ...newFile, status: 2, msg: "\u4E0A\u4F20\u5931\u8D25" }, -1);
|
|
70
75
|
return;
|
|
71
76
|
}
|
|
72
|
-
console.log("\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680} \u4E0A\u4F20\u6210\u529F\uFF1A", url);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
uploadSuccess({ ...message, sig_id: newFile.sig_id });
|
|
76
|
-
}
|
|
77
|
+
console.log("\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680} \u4E0A\u4F20\u6210\u529F\uFF1A", url, message);
|
|
78
|
+
if (!["video", "audio"].includes(message.catalog)) {
|
|
79
|
+
recordTaskStatusChange({ ...newFile, url: message.url, status: 0 }, 1);
|
|
80
|
+
setTimeout(() => uploadSuccess({ ...message, sig_id: newFile.sig_id }), 200);
|
|
81
|
+
} else {
|
|
82
|
+
recordTaskStatusChange(newFile, 0);
|
|
83
|
+
}
|
|
77
84
|
callback && callback({ ...message, sig_id: newFile.sig_id }, "success");
|
|
78
85
|
}).catch((e) => {
|
|
79
86
|
console.log("\u{1F525}\u{1F525}\u{1F525}\u{1F525}\u{1F525} \u4E0A\u4F20\u5931\u8D25\uFF1A", e);
|
|
80
|
-
recordTaskStatusChange({ ...newFile, status: 2, msg: "\
|
|
87
|
+
recordTaskStatusChange({ ...newFile, status: 2, msg: "\u5931\u8D25" }, -1);
|
|
81
88
|
callback && callback(newFile, "fail");
|
|
82
89
|
});
|
|
83
90
|
};
|
|
91
|
+
const transcodingFile = (BASE_API, file) => {
|
|
92
|
+
if (!["video", "audio"].includes(file.catalog))
|
|
93
|
+
return;
|
|
94
|
+
const task = new transcodeMedia.TranscodingTask(file);
|
|
95
|
+
const idx = list.value.findIndex(
|
|
96
|
+
(item2) => item2.sig_id === file.sig_id
|
|
97
|
+
);
|
|
98
|
+
if (idx === -1)
|
|
99
|
+
return;
|
|
100
|
+
const item = list.value[idx];
|
|
101
|
+
recordTaskStatusChange(item, 0, true);
|
|
102
|
+
const progress = (progress2) => recordTaskStatusChange(item, progress2);
|
|
103
|
+
const transing = task.start(BASE_API, progress);
|
|
104
|
+
transing.then((res) => {
|
|
105
|
+
if (res) {
|
|
106
|
+
console.log("\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680} \u8F6C\u7801\u6210\u529F");
|
|
107
|
+
recordTaskStatusChange({ ...item, status: 0 }, 1);
|
|
108
|
+
setTimeout(() => uploadSuccess(file), 200);
|
|
109
|
+
} else {
|
|
110
|
+
console.log("\u{1F525}\u{1F525}\u{1F525}\u{1F525}\u{1F525} \u8F6C\u7801\u5931\u8D25\uFF1A", item);
|
|
111
|
+
recordTaskStatusChange({ ...item, status: 2, msg: "\u8F6C\u7801\u5931\u8D25" }, -1);
|
|
112
|
+
}
|
|
113
|
+
}).catch((e) => {
|
|
114
|
+
console.log("\u{1F525}\u{1F525}\u{1F525}\u{1F525}\u{1F525} \u8F6C\u7801\u5931\u8D25", e);
|
|
115
|
+
recordTaskStatusChange({ ...item, status: 2, msg: "\u8F6C\u7801\u5931\u8D25" }, -1);
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
vue.watch(() => list.value, set, { deep: true });
|
|
119
|
+
window.onbeforeunload = remove;
|
|
84
120
|
return {
|
|
85
121
|
list,
|
|
86
122
|
uploadFile,
|
|
123
|
+
transcodingFile,
|
|
87
124
|
recordTaskStatusChange
|
|
88
125
|
};
|
|
89
126
|
}
|
package/lib/index.css
CHANGED
|
@@ -4256,6 +4256,7 @@
|
|
|
4256
4256
|
}
|
|
4257
4257
|
.thumb-select-wrapper .thumb-upload-loading {
|
|
4258
4258
|
display: flex;
|
|
4259
|
+
flex-direction: column;
|
|
4259
4260
|
align-items: center;
|
|
4260
4261
|
justify-content: center;
|
|
4261
4262
|
width: 100%;
|
|
@@ -4274,6 +4275,8 @@
|
|
|
4274
4275
|
.thumb-select-wrapper .thumb-image img {
|
|
4275
4276
|
width: 100%;
|
|
4276
4277
|
height: 100%;
|
|
4278
|
+
user-select: none;
|
|
4279
|
+
-webkit-user-drag: none;
|
|
4277
4280
|
}
|
|
4278
4281
|
.thumb-select-wrapper .thumb-handler-list {
|
|
4279
4282
|
position: absolute;
|
|
@@ -4313,9 +4316,13 @@
|
|
|
4313
4316
|
position: absolute;
|
|
4314
4317
|
right: 5px;
|
|
4315
4318
|
bottom: 5px;
|
|
4316
|
-
|
|
4319
|
+
display: flex;
|
|
4320
|
+
gap: 2px;
|
|
4321
|
+
align-items: center;
|
|
4322
|
+
padding: 2px 5px;
|
|
4317
4323
|
color: #fff;
|
|
4318
4324
|
font-size: 12px;
|
|
4325
|
+
line-height: 14px;
|
|
4319
4326
|
background-color: rgba(0, 0, 0, 0.5);
|
|
4320
4327
|
border-radius: 16px;
|
|
4321
4328
|
opacity: 1;
|
|
@@ -4400,10 +4407,18 @@
|
|
|
4400
4407
|
overflow: hidden;
|
|
4401
4408
|
}
|
|
4402
4409
|
.list-panel-wrapper .list-selected-record .list-selected-item .item-thumb {
|
|
4410
|
+
position: relative;
|
|
4403
4411
|
width: 50px;
|
|
4404
4412
|
height: 38px;
|
|
4405
4413
|
overflow: hidden;
|
|
4406
4414
|
}
|
|
4415
|
+
.list-panel-wrapper .list-selected-record .list-selected-item .item-thumb .item-tag {
|
|
4416
|
+
position: absolute;
|
|
4417
|
+
top: 50%;
|
|
4418
|
+
left: 50%;
|
|
4419
|
+
color: white;
|
|
4420
|
+
transform: translate(-50%, -50%);
|
|
4421
|
+
}
|
|
4407
4422
|
.list-panel-wrapper .list-selected-record .list-selected-item .item-alias {
|
|
4408
4423
|
flex: 1;
|
|
4409
4424
|
overflow: hidden;
|
|
@@ -4433,13 +4448,31 @@
|
|
|
4433
4448
|
.card-wrapper-image {
|
|
4434
4449
|
position: relative;
|
|
4435
4450
|
overflow: hidden;
|
|
4436
|
-
cursor: pointer;
|
|
4437
4451
|
}
|
|
4438
4452
|
.card-wrapper-image .card-wrapper {
|
|
4439
4453
|
position: relative;
|
|
4440
4454
|
overflow: hidden;
|
|
4455
|
+
border-radius: 2px;
|
|
4456
|
+
transition: all 0.3s ease-in-out;
|
|
4441
4457
|
aspect-ratio: 4 / 3;
|
|
4442
4458
|
}
|
|
4459
|
+
.card-wrapper-image .card-wrapper.disable:not(.active) {
|
|
4460
|
+
opacity: 0.4;
|
|
4461
|
+
}
|
|
4462
|
+
.card-wrapper-image .card-wrapper .mask {
|
|
4463
|
+
position: absolute;
|
|
4464
|
+
top: 0;
|
|
4465
|
+
z-index: 9;
|
|
4466
|
+
display: none;
|
|
4467
|
+
width: 100%;
|
|
4468
|
+
height: 100%;
|
|
4469
|
+
font-size: 18px;
|
|
4470
|
+
background: rgba(0, 0, 0, 0.3);
|
|
4471
|
+
cursor: pointer;
|
|
4472
|
+
}
|
|
4473
|
+
.card-wrapper-image .card-wrapper.active .mask {
|
|
4474
|
+
display: block;
|
|
4475
|
+
}
|
|
4443
4476
|
.card-wrapper-image .card-alias {
|
|
4444
4477
|
width: 100%;
|
|
4445
4478
|
margin-top: 6px;
|
|
@@ -4449,6 +4482,8 @@
|
|
|
4449
4482
|
line-height: 22px;
|
|
4450
4483
|
white-space: nowrap;
|
|
4451
4484
|
text-overflow: ellipsis;
|
|
4485
|
+
user-select: none;
|
|
4486
|
+
-webkit-user-drag: none;
|
|
4452
4487
|
}
|
|
4453
4488
|
.card-wrapper-image:hover .check-box-wrapper .check-box,
|
|
4454
4489
|
.card-wrapper-image .check-box-wrapper .check-box.active {
|
|
@@ -4458,6 +4493,7 @@
|
|
|
4458
4493
|
position: absolute;
|
|
4459
4494
|
top: 8px;
|
|
4460
4495
|
left: 8px;
|
|
4496
|
+
z-index: 10;
|
|
4461
4497
|
cursor: pointer;
|
|
4462
4498
|
}
|
|
4463
4499
|
.card-wrapper-image .check-box-wrapper .check-box {
|