@minilo/ui 0.0.2 → 0.0.3
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/minilo/dist/index.css +1 -1
- package/minilo/dist/index.full.js +2570 -111
- package/minilo/dist/index.full.min.js +7 -1
- package/minilo/dist/index.full.min.js.map +1 -1
- package/minilo/dist/index.full.min.mjs +7 -1
- package/minilo/dist/index.full.min.mjs.map +1 -1
- package/minilo/dist/index.full.mjs +2565 -113
- package/minilo/es/components/button/index.d.ts +4 -4
- package/minilo/es/components/button/index.vue.d.ts +2 -2
- package/minilo/es/components/chart/index.d.ts +4 -4
- package/minilo/es/components/chart/index.vue.d.ts +2 -2
- package/minilo/es/components/chart/index.vue2.mjs +2 -2
- package/minilo/es/components/detail/index.vue2.mjs +1 -1
- package/minilo/es/components/image-upload-pro/index.d.ts +146 -0
- package/minilo/es/components/image-upload-pro/index.mjs +7 -0
- package/minilo/es/components/image-upload-pro/index.vue.d.ts +146 -0
- package/minilo/es/components/image-upload-pro/index.vue.mjs +5 -0
- package/minilo/es/components/image-upload-pro/index.vue2.mjs +667 -0
- package/minilo/es/components/image-upload-pro/type.d.ts +146 -0
- package/minilo/es/components/image-upload-pro/type.mjs +81 -0
- package/minilo/es/components/index.d.ts +4 -0
- package/minilo/es/components/index.mjs +7 -0
- package/minilo/es/components/number-range-input/index.d.ts +3 -3
- package/minilo/es/components/number-range-input/index.vue.d.ts +1 -1
- package/minilo/es/components/search/index.d.ts +26 -26
- package/minilo/es/components/search/index.vue.d.ts +23 -23
- package/minilo/es/components/search/props.d.ts +2 -2
- package/minilo/es/components/search-table/index.d.ts +18 -18
- package/minilo/es/components/search-table/index.vue.d.ts +9 -9
- package/minilo/es/components/search-table/index.vue2.mjs +2 -2
- package/minilo/es/components/search-table/props.d.ts +3 -3
- package/minilo/es/components/tree-select/index.d.ts +32 -0
- package/minilo/es/components/tree-select/index.mjs +6 -0
- package/minilo/es/components/tree-select/index.vue.d.ts +20 -0
- package/minilo/es/components/tree-select/index.vue.mjs +5 -0
- package/minilo/es/components/tree-select/index.vue2.mjs +226 -0
- package/minilo/es/components/tree-select/type.d.ts +34 -0
- package/minilo/es/components/tree-select/type.mjs +1 -0
- package/minilo/es/components/tree-select-dialog/index.d.ts +60 -0
- package/minilo/es/components/tree-select-dialog/index.mjs +7 -0
- package/minilo/es/components/tree-select-dialog/index.vue.d.ts +23 -0
- package/minilo/es/components/tree-select-dialog/index.vue.mjs +5 -0
- package/minilo/es/components/tree-select-dialog/index.vue2.mjs +135 -0
- package/minilo/es/components/tree-select-dialog/type.d.ts +9 -0
- package/minilo/es/components/tree-select-dialog/type.mjs +24 -0
- package/minilo/es/components/tree-select-drawer/index.d.ts +64 -0
- package/minilo/es/components/tree-select-drawer/index.mjs +7 -0
- package/minilo/es/components/tree-select-drawer/index.vue.d.ts +23 -0
- package/minilo/es/components/tree-select-drawer/index.vue.mjs +5 -0
- package/minilo/es/components/tree-select-drawer/index.vue2.mjs +140 -0
- package/minilo/es/components/tree-select-drawer/type.d.ts +10 -0
- package/minilo/es/components/tree-select-drawer/type.mjs +20 -0
- package/minilo/es/components/virtual-list/index.d.ts +4 -4
- package/minilo/es/components/virtual-list/index.vue.d.ts +2 -2
- package/minilo/es/index.d.ts +393 -61
- package/minilo/es/node_modules/.pnpm/{@element-plus_icons-vue@2.3.1_vue@3.5.17_typescript@5.8.3_ → @element-plus_icons-vue@2.3.1_vue@3.5.26_typescript@5.9.3_}/node_modules/@element-plus/icons-vue/dist/index.mjs +17 -1
- package/minilo/es/node_modules/.pnpm/{@vueuse_core@13.6.0_vue@3.5.17_typescript@5.9.3_ → @vueuse_core@13.9.0_vue@3.5.26_typescript@5.9.3_}/node_modules/@vueuse/core/index.mjs +2 -2
- package/minilo/es/resolver/index.d.ts +1 -1
- package/minilo/lib/components/button/index.d.ts +4 -4
- package/minilo/lib/components/button/index.vue.d.ts +2 -2
- package/minilo/lib/components/chart/index.d.ts +4 -4
- package/minilo/lib/components/chart/index.vue.d.ts +2 -2
- package/minilo/lib/components/chart/index.vue2.js +2 -2
- package/minilo/lib/components/detail/index.vue2.js +1 -1
- package/minilo/lib/components/image-upload-pro/index.d.ts +146 -0
- package/minilo/lib/components/image-upload-pro/index.js +13 -0
- package/minilo/lib/components/image-upload-pro/index.vue.d.ts +146 -0
- package/minilo/lib/components/image-upload-pro/index.vue.js +9 -0
- package/minilo/lib/components/image-upload-pro/index.vue2.js +671 -0
- package/minilo/lib/components/image-upload-pro/type.d.ts +146 -0
- package/minilo/lib/components/image-upload-pro/type.js +83 -0
- package/minilo/lib/components/index.d.ts +4 -0
- package/minilo/lib/components/index.js +14 -0
- package/minilo/lib/components/number-range-input/index.d.ts +3 -3
- package/minilo/lib/components/number-range-input/index.vue.d.ts +1 -1
- package/minilo/lib/components/search/index.d.ts +26 -26
- package/minilo/lib/components/search/index.vue.d.ts +23 -23
- package/minilo/lib/components/search/props.d.ts +2 -2
- package/minilo/lib/components/search-table/index.d.ts +18 -18
- package/minilo/lib/components/search-table/index.vue.d.ts +9 -9
- package/minilo/lib/components/search-table/index.vue2.js +2 -2
- package/minilo/lib/components/search-table/props.d.ts +3 -3
- package/minilo/lib/components/tree-select/index.d.ts +32 -0
- package/minilo/lib/components/tree-select/index.js +11 -0
- package/minilo/lib/components/tree-select/index.vue.d.ts +20 -0
- package/minilo/lib/components/tree-select/index.vue.js +9 -0
- package/minilo/lib/components/tree-select/index.vue2.js +230 -0
- package/minilo/lib/components/tree-select/type.d.ts +34 -0
- package/minilo/lib/components/tree-select/type.js +2 -0
- package/minilo/lib/components/tree-select-dialog/index.d.ts +60 -0
- package/minilo/lib/components/tree-select-dialog/index.js +13 -0
- package/minilo/lib/components/tree-select-dialog/index.vue.d.ts +23 -0
- package/minilo/lib/components/tree-select-dialog/index.vue.js +9 -0
- package/minilo/lib/components/tree-select-dialog/index.vue2.js +139 -0
- package/minilo/lib/components/tree-select-dialog/type.d.ts +9 -0
- package/minilo/lib/components/tree-select-dialog/type.js +26 -0
- package/minilo/lib/components/tree-select-drawer/index.d.ts +64 -0
- package/minilo/lib/components/tree-select-drawer/index.js +13 -0
- package/minilo/lib/components/tree-select-drawer/index.vue.d.ts +23 -0
- package/minilo/lib/components/tree-select-drawer/index.vue.js +9 -0
- package/minilo/lib/components/tree-select-drawer/index.vue2.js +144 -0
- package/minilo/lib/components/tree-select-drawer/type.d.ts +10 -0
- package/minilo/lib/components/tree-select-drawer/type.js +22 -0
- package/minilo/lib/components/virtual-list/index.d.ts +4 -4
- package/minilo/lib/components/virtual-list/index.vue.d.ts +2 -2
- package/minilo/lib/index.d.ts +393 -61
- package/minilo/lib/node_modules/.pnpm/{@element-plus_icons-vue@2.3.1_vue@3.5.17_typescript@5.8.3_ → @element-plus_icons-vue@2.3.1_vue@3.5.26_typescript@5.9.3_}/node_modules/@element-plus/icons-vue/dist/index.js +17 -0
- package/minilo/lib/node_modules/.pnpm/{@vueuse_core@13.6.0_vue@3.5.17_typescript@5.9.3_ → @vueuse_core@13.9.0_vue@3.5.26_typescript@5.9.3_}/node_modules/@vueuse/core/index.js +1 -1
- package/minilo/lib/resolver/index.d.ts +1 -1
- package/minilo/theme-chalk/index.css +1 -1
- package/minilo/theme-chalk/ml-image-upload-pro.css +1 -0
- package/minilo/theme-chalk/ml-tree-select-dialog.css +0 -0
- package/minilo/theme-chalk/ml-tree-select-drawer.css +0 -0
- package/minilo/theme-chalk/ml-tree-select.css +1 -0
- package/minilo/theme-chalk/src/image-upload-pro.scss +70 -0
- package/minilo/theme-chalk/src/index.scss +2 -0
- package/minilo/theme-chalk/src/tree-select-dialog.scss +0 -0
- package/minilo/theme-chalk/src/tree-select-drawer.scss +0 -0
- package/minilo/theme-chalk/src/tree-select.scss +47 -0
- package/package.json +18 -5
- /package/minilo/es/{packages → node_modules/.pnpm/@minilo_utils@0.0.2_vue@3.5.26_typescript@5.9.3_/node_modules/@minilo}/utils/dist/func/common.mjs +0 -0
- /package/minilo/es/{packages → node_modules/.pnpm/@minilo_utils@0.0.2_vue@3.5.26_typescript@5.9.3_/node_modules/@minilo}/utils/dist/request/index.mjs +0 -0
- /package/minilo/es/node_modules/.pnpm/{@vueuse_shared@13.6.0_vue@3.5.17_typescript@5.9.3_ → @vueuse_shared@13.9.0_vue@3.5.26_typescript@5.9.3_}/node_modules/@vueuse/shared/index.mjs +0 -0
- /package/minilo/lib/{packages → node_modules/.pnpm/@minilo_utils@0.0.2_vue@3.5.26_typescript@5.9.3_/node_modules/@minilo}/utils/dist/func/common.js +0 -0
- /package/minilo/lib/{packages → node_modules/.pnpm/@minilo_utils@0.0.2_vue@3.5.26_typescript@5.9.3_/node_modules/@minilo}/utils/dist/request/index.js +0 -0
- /package/minilo/lib/node_modules/.pnpm/{@vueuse_shared@13.6.0_vue@3.5.17_typescript@5.9.3_ → @vueuse_shared@13.9.0_vue@3.5.26_typescript@5.9.3_}/node_modules/@vueuse/shared/index.js +0 -0
|
@@ -0,0 +1,667 @@
|
|
|
1
|
+
import { defineComponent, ref, reactive, computed, watch, resolveComponent, createElementBlock, openBlock, normalizeClass, unref, createCommentVNode, createVNode, withCtx, createTextVNode, createElementVNode, toDisplayString, Fragment, renderList, nextTick } from 'vue';
|
|
2
|
+
import { ElMessage, ElMessageBox } from 'element-plus';
|
|
3
|
+
import { VueCropper } from 'vue-cropper';
|
|
4
|
+
import { imageUploadProProps } from './type.mjs';
|
|
5
|
+
import { bem } from '../../utils/index.mjs';
|
|
6
|
+
import { initRequestInstance } from '../../node_modules/.pnpm/@minilo_utils@0.0.2_vue@3.5.26_typescript@5.9.3_/node_modules/@minilo/utils/dist/request/index.mjs';
|
|
7
|
+
import { getNestedValue } from '../../node_modules/.pnpm/@minilo_utils@0.0.2_vue@3.5.26_typescript@5.9.3_/node_modules/@minilo/utils/dist/func/common.mjs';
|
|
8
|
+
|
|
9
|
+
const _hoisted_1 = { key: 0 };
|
|
10
|
+
const _hoisted_2 = ["onDragstart", "onDrop"];
|
|
11
|
+
var _sfc_main = /* @__PURE__ */ defineComponent({
|
|
12
|
+
...{
|
|
13
|
+
name: "MlImageUploadPro"
|
|
14
|
+
},
|
|
15
|
+
__name: "index",
|
|
16
|
+
props: imageUploadProProps,
|
|
17
|
+
emits: ["update:modelValue", "change", "upload"],
|
|
18
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
19
|
+
const ASPECT_RATIO_OPTIONS = [
|
|
20
|
+
{ label: "\u81EA\u7531\u6BD4\u4F8B", value: "free" },
|
|
21
|
+
{ label: "1:1", value: "1:1" },
|
|
22
|
+
{ label: "4:3", value: "4:3" },
|
|
23
|
+
{ label: "16:9", value: "16:9" }
|
|
24
|
+
];
|
|
25
|
+
const props = __props;
|
|
26
|
+
const uploadRef = ref();
|
|
27
|
+
const cropperRef = ref();
|
|
28
|
+
const fileList = ref([]);
|
|
29
|
+
const previewList = ref([]);
|
|
30
|
+
const cropDialogVisible = ref(false);
|
|
31
|
+
const cropImageUrl = ref("");
|
|
32
|
+
const cropTargetItem = ref();
|
|
33
|
+
const dragIndex = ref(-1);
|
|
34
|
+
const cropForm = reactive({
|
|
35
|
+
aspectRatio: "free"
|
|
36
|
+
// 裁剪比例
|
|
37
|
+
});
|
|
38
|
+
const cropWidth = ref(props.sizeLimit.width || 400);
|
|
39
|
+
const cropHeight = ref(props.sizeLimit.height || 400);
|
|
40
|
+
const displayWidth = ref(props.sizeLimit.width || 400);
|
|
41
|
+
const displayHeight = ref(props.sizeLimit.height || 400);
|
|
42
|
+
const aspectRatio = reactive({
|
|
43
|
+
fixed: false,
|
|
44
|
+
value: [1, 1]
|
|
45
|
+
});
|
|
46
|
+
const axios = computed(() => {
|
|
47
|
+
if (!props.uploadApi) return null;
|
|
48
|
+
return initRequestInstance({
|
|
49
|
+
baseURL: "",
|
|
50
|
+
headers: props.uploadApi.headers || {}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
const acceptDesc = computed(() => {
|
|
54
|
+
return props.acceptType.split(",").map((type) => type.replace("image/", ".")).join("\u3001");
|
|
55
|
+
});
|
|
56
|
+
watch(
|
|
57
|
+
() => props.modelValue,
|
|
58
|
+
(val) => {
|
|
59
|
+
if (val.length) {
|
|
60
|
+
previewList.value = val.map((item) => ({
|
|
61
|
+
...item,
|
|
62
|
+
url: item.url || item.response?.url || ""
|
|
63
|
+
}));
|
|
64
|
+
fileList.value = val;
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{ immediate: true, deep: true }
|
|
68
|
+
);
|
|
69
|
+
const uploadSingleFile = async (file) => {
|
|
70
|
+
if (!props.uploadApi || !axios.value) {
|
|
71
|
+
throw new Error("\u672A\u914D\u7F6E\u4E0A\u4F20 API");
|
|
72
|
+
}
|
|
73
|
+
const formData = new FormData();
|
|
74
|
+
formData.append(props.uploadApi.fieldName || "file", file);
|
|
75
|
+
if (props.uploadApi.data) {
|
|
76
|
+
Object.keys(props.uploadApi.data).forEach((key) => {
|
|
77
|
+
formData.append(key, props.uploadApi.data[key]);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
const method = props.uploadApi.method || "post";
|
|
81
|
+
const response = await axios.value[method](props.uploadApi.url, formData, {
|
|
82
|
+
headers: {
|
|
83
|
+
"Content-Type": "multipart/form-data"
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
const urlField = props.uploadApi.responseUrlField || "data.url";
|
|
87
|
+
return getNestedValue(response, urlField);
|
|
88
|
+
};
|
|
89
|
+
const handleBeforeUpload = (file) => {
|
|
90
|
+
const isAccept = props.acceptType.includes(file.type);
|
|
91
|
+
if (!isAccept) {
|
|
92
|
+
ElMessage.error(`\u4EC5\u652F\u6301\u4E0A\u4F20${acceptDesc.value}\u683C\u5F0F\u7684\u56FE\u7247`);
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
const isOverSize = file.size / 1024 / 1024 > props.sizeLimit.size;
|
|
96
|
+
if (isOverSize) {
|
|
97
|
+
ElMessage.error(`\u5355\u6587\u4EF6\u5927\u5C0F\u4E0D\u80FD\u8D85\u8FC7${props.sizeLimit.size}MB`);
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
if (previewList.value.length >= props.maxCount) {
|
|
101
|
+
ElMessage.error(`\u6700\u591A\u53EA\u80FD\u4E0A\u4F20${props.maxCount}\u5F20\u56FE\u7247`);
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
if (props.sizeLimit.width || props.sizeLimit.height) {
|
|
105
|
+
return new Promise((resolve) => {
|
|
106
|
+
const img = new Image();
|
|
107
|
+
img.onload = () => {
|
|
108
|
+
const isOverWidth = props.sizeLimit.width && img.width < props.sizeLimit.width;
|
|
109
|
+
const isOverHeight = props.sizeLimit.height && img.height < props.sizeLimit.height;
|
|
110
|
+
if (isOverWidth || isOverHeight) {
|
|
111
|
+
ElMessage.error(
|
|
112
|
+
`\u56FE\u7247\u5C3A\u5BF8\u8981\u6C42\uFF1A\u5BBD\u2265${props.sizeLimit.width}px \u9AD8\u2265${props.sizeLimit.height}px\uFF0C\u5F53\u524D\u56FE\u7247\u5BBD${img.width}px \u9AD8${img.height}px`
|
|
113
|
+
);
|
|
114
|
+
resolve(false);
|
|
115
|
+
} else {
|
|
116
|
+
resolve(true);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
img.src = URL.createObjectURL(file);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return true;
|
|
123
|
+
};
|
|
124
|
+
const handleFileChange = async (file, files) => {
|
|
125
|
+
if (file.status === "ready") {
|
|
126
|
+
const blobUrl = URL.createObjectURL(file.raw);
|
|
127
|
+
const newItem = {
|
|
128
|
+
...file,
|
|
129
|
+
rawFile: file.raw,
|
|
130
|
+
blobUrl,
|
|
131
|
+
// 保存 blob URL 用于裁剪
|
|
132
|
+
url: blobUrl
|
|
133
|
+
// 初始显示使用 blob URL
|
|
134
|
+
};
|
|
135
|
+
if (props.allowCrop) {
|
|
136
|
+
ElMessageBox.confirm("\u662F\u5426\u9700\u8981\u88C1\u526A\u8BE5\u56FE\u7247\uFF1F", "\u63D0\u793A", {
|
|
137
|
+
type: "info",
|
|
138
|
+
confirmButtonText: "\u88C1\u526A",
|
|
139
|
+
cancelButtonText: "\u76F4\u63A5\u4E0A\u4F20"
|
|
140
|
+
}).then(() => {
|
|
141
|
+
handleCropImage(newItem);
|
|
142
|
+
}).catch(async () => {
|
|
143
|
+
if (props.autoUpload && props.uploadApi) {
|
|
144
|
+
try {
|
|
145
|
+
const uploadedUrl = await uploadSingleFile(file.raw);
|
|
146
|
+
newItem.serverUrl = uploadedUrl;
|
|
147
|
+
newItem.url = uploadedUrl;
|
|
148
|
+
ElMessage.success("\u56FE\u7247\u4E0A\u4F20\u6210\u529F");
|
|
149
|
+
} catch (error) {
|
|
150
|
+
ElMessage.error("\u56FE\u7247\u4E0A\u4F20\u5931\u8D25");
|
|
151
|
+
console.error(error);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
previewList.value.push(newItem);
|
|
156
|
+
syncModelValue();
|
|
157
|
+
});
|
|
158
|
+
} else {
|
|
159
|
+
if (props.autoUpload && props.uploadApi) {
|
|
160
|
+
try {
|
|
161
|
+
const uploadedUrl = await uploadSingleFile(file.raw);
|
|
162
|
+
newItem.serverUrl = uploadedUrl;
|
|
163
|
+
newItem.url = uploadedUrl;
|
|
164
|
+
ElMessage.success("\u56FE\u7247\u4E0A\u4F20\u6210\u529F");
|
|
165
|
+
} catch (error) {
|
|
166
|
+
ElMessage.error("\u56FE\u7247\u4E0A\u4F20\u5931\u8D25");
|
|
167
|
+
console.error(error);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
previewList.value.push(newItem);
|
|
172
|
+
syncModelValue();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
fileList.value = files;
|
|
176
|
+
};
|
|
177
|
+
const handleFileRemove = (file) => {
|
|
178
|
+
previewList.value = previewList.value.filter((item) => item.uid !== file.uid);
|
|
179
|
+
syncModelValue();
|
|
180
|
+
};
|
|
181
|
+
const handleCropImage = (item) => {
|
|
182
|
+
console.log(item);
|
|
183
|
+
if (!props.allowCrop) return;
|
|
184
|
+
cropTargetItem.value = item;
|
|
185
|
+
cropImageUrl.value = item.blobUrl || item.url || "";
|
|
186
|
+
cropDialogVisible.value = true;
|
|
187
|
+
nextTick(() => {
|
|
188
|
+
cropForm.aspectRatio = "free";
|
|
189
|
+
cropWidth.value = props.sizeLimit.width || 400;
|
|
190
|
+
cropHeight.value = props.sizeLimit.height || 400;
|
|
191
|
+
displayWidth.value = props.sizeLimit.width || 400;
|
|
192
|
+
displayHeight.value = props.sizeLimit.height || 400;
|
|
193
|
+
aspectRatio.fixed = false;
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
const handleAspectRatioChange = (val) => {
|
|
197
|
+
if (val === "free") {
|
|
198
|
+
aspectRatio.fixed = false;
|
|
199
|
+
} else {
|
|
200
|
+
aspectRatio.fixed = true;
|
|
201
|
+
const parts = val.split(":").map(Number);
|
|
202
|
+
const w = parts[0] ?? 1;
|
|
203
|
+
const h = parts[1] ?? 1;
|
|
204
|
+
aspectRatio.value = [w, h];
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
const handleCropRealTime = (data) => {
|
|
208
|
+
if (data && data.w && data.h) {
|
|
209
|
+
displayWidth.value = Math.round(data.w);
|
|
210
|
+
displayHeight.value = Math.round(data.h);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
const handleSizeChange = () => {
|
|
214
|
+
cropWidth.value = displayWidth.value;
|
|
215
|
+
cropHeight.value = displayHeight.value;
|
|
216
|
+
};
|
|
217
|
+
const handleCropConfirm = () => {
|
|
218
|
+
if (!cropperRef.value || !cropTargetItem.value) return;
|
|
219
|
+
cropperRef.value.getCropBlob(async (blob) => {
|
|
220
|
+
const croppedFile = new File([blob], cropTargetItem.value.name || "cropped.jpg", {
|
|
221
|
+
type: cropTargetItem.value.rawFile?.type || "image/jpeg"
|
|
222
|
+
});
|
|
223
|
+
const newBlobUrl = URL.createObjectURL(croppedFile);
|
|
224
|
+
let displayUrl = newBlobUrl;
|
|
225
|
+
if (props.autoUpload && props.uploadApi) {
|
|
226
|
+
try {
|
|
227
|
+
const serverUrl = await uploadSingleFile(croppedFile);
|
|
228
|
+
displayUrl = serverUrl;
|
|
229
|
+
ElMessage.success("\u56FE\u7247\u4E0A\u4F20\u6210\u529F");
|
|
230
|
+
const index = previewList.value.findIndex((item) => item.uid === cropTargetItem.value.uid);
|
|
231
|
+
const targetItem = previewList.value[index];
|
|
232
|
+
if (index > -1 && targetItem) {
|
|
233
|
+
targetItem.url = displayUrl;
|
|
234
|
+
targetItem.blobUrl = newBlobUrl;
|
|
235
|
+
targetItem.serverUrl = serverUrl;
|
|
236
|
+
targetItem.rawFile = croppedFile;
|
|
237
|
+
} else {
|
|
238
|
+
previewList.value.push({
|
|
239
|
+
...cropTargetItem.value,
|
|
240
|
+
name: cropTargetItem.value.name ?? "cropped.jpg",
|
|
241
|
+
url: displayUrl,
|
|
242
|
+
blobUrl: newBlobUrl,
|
|
243
|
+
serverUrl,
|
|
244
|
+
rawFile: croppedFile
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
} catch (error) {
|
|
248
|
+
ElMessage.error("\u56FE\u7247\u4E0A\u4F20\u5931\u8D25");
|
|
249
|
+
console.error(error);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
} else {
|
|
253
|
+
const index = previewList.value.findIndex((item) => item.uid === cropTargetItem.value.uid);
|
|
254
|
+
const targetItem = previewList.value[index];
|
|
255
|
+
if (index > -1 && targetItem) {
|
|
256
|
+
targetItem.url = newBlobUrl;
|
|
257
|
+
targetItem.blobUrl = newBlobUrl;
|
|
258
|
+
targetItem.rawFile = croppedFile;
|
|
259
|
+
} else {
|
|
260
|
+
previewList.value.push({
|
|
261
|
+
...cropTargetItem.value,
|
|
262
|
+
name: cropTargetItem.value.name ?? "cropped.jpg",
|
|
263
|
+
url: newBlobUrl,
|
|
264
|
+
blobUrl: newBlobUrl,
|
|
265
|
+
rawFile: croppedFile
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
syncModelValue();
|
|
270
|
+
cropDialogVisible.value = false;
|
|
271
|
+
ElMessage.success("\u56FE\u7247\u88C1\u526A\u6210\u529F");
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
const resetCropper = () => {
|
|
275
|
+
cropTargetItem.value = void 0;
|
|
276
|
+
cropImageUrl.value = "";
|
|
277
|
+
};
|
|
278
|
+
const handleRemovePreview = (item) => {
|
|
279
|
+
ElMessageBox.confirm("\u786E\u5B9A\u8981\u5220\u9664\u8BE5\u56FE\u7247\u5417\uFF1F", "\u63D0\u793A", {
|
|
280
|
+
type: "warning",
|
|
281
|
+
confirmButtonText: "\u786E\u5B9A",
|
|
282
|
+
cancelButtonText: "\u53D6\u6D88"
|
|
283
|
+
}).then(() => {
|
|
284
|
+
previewList.value = previewList.value.filter((i) => i.uid !== item.uid);
|
|
285
|
+
fileList.value = fileList.value.filter((i) => i.uid !== item.uid);
|
|
286
|
+
syncModelValue();
|
|
287
|
+
ElMessage.success("\u56FE\u7247\u5220\u9664\u6210\u529F");
|
|
288
|
+
});
|
|
289
|
+
};
|
|
290
|
+
const handleDragStart = (index) => {
|
|
291
|
+
if (!props.allowSort) return;
|
|
292
|
+
dragIndex.value = index;
|
|
293
|
+
};
|
|
294
|
+
const handleDragOver = (e) => {
|
|
295
|
+
e.preventDefault();
|
|
296
|
+
};
|
|
297
|
+
const handleDrop = (index) => {
|
|
298
|
+
if (!props.allowSort || dragIndex.value === -1 || dragIndex.value === index) return;
|
|
299
|
+
const temp = previewList.value[dragIndex.value];
|
|
300
|
+
if (!temp) return;
|
|
301
|
+
previewList.value.splice(dragIndex.value, 1);
|
|
302
|
+
previewList.value.splice(index, 0, temp);
|
|
303
|
+
dragIndex.value = -1;
|
|
304
|
+
syncModelValue();
|
|
305
|
+
};
|
|
306
|
+
const syncModelValue = () => {
|
|
307
|
+
emit("update:modelValue", [...previewList.value]);
|
|
308
|
+
emit("change", [...previewList.value]);
|
|
309
|
+
};
|
|
310
|
+
const emit = __emit;
|
|
311
|
+
const uploadToServer = async (uploadApi) => {
|
|
312
|
+
const uploadPromises = previewList.value.map(async (item) => {
|
|
313
|
+
if (item.rawFile) {
|
|
314
|
+
const url = await uploadApi(item.rawFile);
|
|
315
|
+
item.url = url;
|
|
316
|
+
return item;
|
|
317
|
+
}
|
|
318
|
+
return item;
|
|
319
|
+
});
|
|
320
|
+
const result = await Promise.all(uploadPromises);
|
|
321
|
+
previewList.value = result;
|
|
322
|
+
syncModelValue();
|
|
323
|
+
return result;
|
|
324
|
+
};
|
|
325
|
+
__expose({
|
|
326
|
+
uploadToServer,
|
|
327
|
+
// 暴露上传到服务器的方法
|
|
328
|
+
clear: () => {
|
|
329
|
+
previewList.value = [];
|
|
330
|
+
fileList.value = [];
|
|
331
|
+
syncModelValue();
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
return (_ctx, _cache) => {
|
|
335
|
+
const _component_el_button = resolveComponent("el-button");
|
|
336
|
+
const _component_el_upload = resolveComponent("el-upload");
|
|
337
|
+
const _component_el_image = resolveComponent("el-image");
|
|
338
|
+
const _component_el_option = resolveComponent("el-option");
|
|
339
|
+
const _component_el_select = resolveComponent("el-select");
|
|
340
|
+
const _component_el_form_item = resolveComponent("el-form-item");
|
|
341
|
+
const _component_el_col = resolveComponent("el-col");
|
|
342
|
+
const _component_el_input_number = resolveComponent("el-input-number");
|
|
343
|
+
const _component_el_row = resolveComponent("el-row");
|
|
344
|
+
const _component_el_form = resolveComponent("el-form");
|
|
345
|
+
const _component_el_dialog = resolveComponent("el-dialog");
|
|
346
|
+
return openBlock(), createElementBlock(
|
|
347
|
+
"div",
|
|
348
|
+
{
|
|
349
|
+
class: normalizeClass(unref(bem)("image-upload-pro"))
|
|
350
|
+
},
|
|
351
|
+
[
|
|
352
|
+
createCommentVNode(" \u6838\u5FC3\u4E0A\u4F20\u533A\u57DF "),
|
|
353
|
+
createVNode(_component_el_upload, {
|
|
354
|
+
ref_key: "uploadRef",
|
|
355
|
+
ref: uploadRef,
|
|
356
|
+
class: normalizeClass(unref(bem)("image-upload-pro", "upload-container")),
|
|
357
|
+
action: "",
|
|
358
|
+
"auto-upload": false,
|
|
359
|
+
"file-list": fileList.value,
|
|
360
|
+
"before-upload": handleBeforeUpload,
|
|
361
|
+
"on-change": handleFileChange,
|
|
362
|
+
"on-remove": handleFileRemove,
|
|
363
|
+
accept: _ctx.acceptType,
|
|
364
|
+
"show-file-list": false
|
|
365
|
+
}, {
|
|
366
|
+
tip: withCtx(() => [
|
|
367
|
+
createElementVNode(
|
|
368
|
+
"div",
|
|
369
|
+
{
|
|
370
|
+
class: normalizeClass(unref(bem)("image-upload-pro", "upload-text"))
|
|
371
|
+
},
|
|
372
|
+
[
|
|
373
|
+
createTextVNode(
|
|
374
|
+
" \u652F\u6301\u683C\u5F0F\uFF1A" + toDisplayString(acceptDesc.value) + " | \u5355\u6587\u4EF6\u5927\u5C0F\u2264" + toDisplayString(props.sizeLimit.size) + "MB ",
|
|
375
|
+
1
|
|
376
|
+
/* TEXT */
|
|
377
|
+
),
|
|
378
|
+
props.sizeLimit.width || props.sizeLimit.height ? (openBlock(), createElementBlock(
|
|
379
|
+
"span",
|
|
380
|
+
_hoisted_1,
|
|
381
|
+
" | \u5C3A\u5BF8\u8981\u6C42\uFF1A\u5BBD\u2265" + toDisplayString(props.sizeLimit.width) + "px \u9AD8\u2265" + toDisplayString(props.sizeLimit.height) + "px ",
|
|
382
|
+
1
|
|
383
|
+
/* TEXT */
|
|
384
|
+
)) : createCommentVNode("v-if", true)
|
|
385
|
+
],
|
|
386
|
+
2
|
|
387
|
+
/* CLASS */
|
|
388
|
+
)
|
|
389
|
+
]),
|
|
390
|
+
default: withCtx(() => [
|
|
391
|
+
createVNode(_component_el_button, {
|
|
392
|
+
disabled: fileList.value.length === props.maxCount,
|
|
393
|
+
type: "primary"
|
|
394
|
+
}, {
|
|
395
|
+
default: withCtx(() => [..._cache[6] || (_cache[6] = [
|
|
396
|
+
createTextVNode(
|
|
397
|
+
"\u9009\u62E9\u56FE\u7247",
|
|
398
|
+
-1
|
|
399
|
+
/* CACHED */
|
|
400
|
+
)
|
|
401
|
+
])]),
|
|
402
|
+
_: 1
|
|
403
|
+
/* STABLE */
|
|
404
|
+
}, 8, ["disabled"])
|
|
405
|
+
]),
|
|
406
|
+
_: 1
|
|
407
|
+
/* STABLE */
|
|
408
|
+
}, 8, ["class", "file-list", "accept"]),
|
|
409
|
+
createCommentVNode(" \u5DF2\u4E0A\u4F20\u56FE\u7247\u9884\u89C8\u5217\u8868 "),
|
|
410
|
+
previewList.value.length ? (openBlock(), createElementBlock(
|
|
411
|
+
"div",
|
|
412
|
+
{
|
|
413
|
+
key: 0,
|
|
414
|
+
class: normalizeClass(unref(bem)("image-upload-pro", "preview-list"))
|
|
415
|
+
},
|
|
416
|
+
[
|
|
417
|
+
(openBlock(true), createElementBlock(
|
|
418
|
+
Fragment,
|
|
419
|
+
null,
|
|
420
|
+
renderList(previewList.value, (item, index) => {
|
|
421
|
+
return openBlock(), createElementBlock("div", {
|
|
422
|
+
class: normalizeClass([unref(bem)("image-upload-pro", "preview-item"), { active: item.isCover }]),
|
|
423
|
+
key: item.uid,
|
|
424
|
+
draggable: "true",
|
|
425
|
+
onDragstart: ($event) => handleDragStart(index),
|
|
426
|
+
onDragover: _cache[0] || (_cache[0] = ($event) => handleDragOver($event)),
|
|
427
|
+
onDrop: ($event) => handleDrop(index)
|
|
428
|
+
}, [
|
|
429
|
+
createCommentVNode(" \u56FE\u7247\u9884\u89C8 "),
|
|
430
|
+
createElementVNode(
|
|
431
|
+
"div",
|
|
432
|
+
{
|
|
433
|
+
class: normalizeClass(unref(bem)("image-upload-pro", "preview-img"))
|
|
434
|
+
},
|
|
435
|
+
[
|
|
436
|
+
createVNode(_component_el_image, {
|
|
437
|
+
src: item.url,
|
|
438
|
+
"preview-src-list": previewList.value.map((i) => i.url),
|
|
439
|
+
"preview-current-index": index,
|
|
440
|
+
fit: "cover"
|
|
441
|
+
}, null, 8, ["src", "preview-src-list", "preview-current-index"])
|
|
442
|
+
],
|
|
443
|
+
2
|
|
444
|
+
/* CLASS */
|
|
445
|
+
),
|
|
446
|
+
createCommentVNode(" \u64CD\u4F5C\u6309\u94AE\u7EC4 "),
|
|
447
|
+
createElementVNode(
|
|
448
|
+
"div",
|
|
449
|
+
{
|
|
450
|
+
class: normalizeClass(unref(bem)("image-upload-pro", "preview-actions"))
|
|
451
|
+
},
|
|
452
|
+
[
|
|
453
|
+
createVNode(_component_el_button, {
|
|
454
|
+
type: "primary",
|
|
455
|
+
text: "",
|
|
456
|
+
size: "small",
|
|
457
|
+
onClick: ($event) => handleCropImage(item)
|
|
458
|
+
}, {
|
|
459
|
+
default: withCtx(() => [..._cache[7] || (_cache[7] = [
|
|
460
|
+
createTextVNode(
|
|
461
|
+
"\u88C1\u526A",
|
|
462
|
+
-1
|
|
463
|
+
/* CACHED */
|
|
464
|
+
)
|
|
465
|
+
])]),
|
|
466
|
+
_: 1
|
|
467
|
+
/* STABLE */
|
|
468
|
+
}, 8, ["onClick"]),
|
|
469
|
+
createVNode(_component_el_button, {
|
|
470
|
+
text: "",
|
|
471
|
+
size: "small",
|
|
472
|
+
type: "danger",
|
|
473
|
+
onClick: ($event) => handleRemovePreview(item)
|
|
474
|
+
}, {
|
|
475
|
+
default: withCtx(() => [..._cache[8] || (_cache[8] = [
|
|
476
|
+
createTextVNode(
|
|
477
|
+
"\u5220\u9664",
|
|
478
|
+
-1
|
|
479
|
+
/* CACHED */
|
|
480
|
+
)
|
|
481
|
+
])]),
|
|
482
|
+
_: 1
|
|
483
|
+
/* STABLE */
|
|
484
|
+
}, 8, ["onClick"])
|
|
485
|
+
],
|
|
486
|
+
2
|
|
487
|
+
/* CLASS */
|
|
488
|
+
)
|
|
489
|
+
], 42, _hoisted_2);
|
|
490
|
+
}),
|
|
491
|
+
128
|
|
492
|
+
/* KEYED_FRAGMENT */
|
|
493
|
+
))
|
|
494
|
+
],
|
|
495
|
+
2
|
|
496
|
+
/* CLASS */
|
|
497
|
+
)) : createCommentVNode("v-if", true),
|
|
498
|
+
createCommentVNode(" \u88C1\u526A\u5F39\u7A97 "),
|
|
499
|
+
createVNode(_component_el_dialog, {
|
|
500
|
+
modelValue: cropDialogVisible.value,
|
|
501
|
+
"onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => cropDialogVisible.value = $event),
|
|
502
|
+
title: "\u56FE\u7247\u88C1\u526A",
|
|
503
|
+
width: "900px",
|
|
504
|
+
"close-on-click-modal": false,
|
|
505
|
+
"destroy-on-close": "",
|
|
506
|
+
onClose: resetCropper
|
|
507
|
+
}, {
|
|
508
|
+
footer: withCtx(() => [
|
|
509
|
+
createVNode(_component_el_button, {
|
|
510
|
+
onClick: _cache[4] || (_cache[4] = ($event) => cropDialogVisible.value = false)
|
|
511
|
+
}, {
|
|
512
|
+
default: withCtx(() => [..._cache[10] || (_cache[10] = [
|
|
513
|
+
createTextVNode(
|
|
514
|
+
"\u53D6\u6D88",
|
|
515
|
+
-1
|
|
516
|
+
/* CACHED */
|
|
517
|
+
)
|
|
518
|
+
])]),
|
|
519
|
+
_: 1
|
|
520
|
+
/* STABLE */
|
|
521
|
+
}),
|
|
522
|
+
createVNode(_component_el_button, {
|
|
523
|
+
type: "primary",
|
|
524
|
+
onClick: handleCropConfirm
|
|
525
|
+
}, {
|
|
526
|
+
default: withCtx(() => [..._cache[11] || (_cache[11] = [
|
|
527
|
+
createTextVNode(
|
|
528
|
+
"\u786E\u8BA4\u88C1\u526A",
|
|
529
|
+
-1
|
|
530
|
+
/* CACHED */
|
|
531
|
+
)
|
|
532
|
+
])]),
|
|
533
|
+
_: 1
|
|
534
|
+
/* STABLE */
|
|
535
|
+
})
|
|
536
|
+
]),
|
|
537
|
+
default: withCtx(() => [
|
|
538
|
+
createElementVNode(
|
|
539
|
+
"div",
|
|
540
|
+
{
|
|
541
|
+
class: normalizeClass(unref(bem)("image-upload-pro", "cropper-container"))
|
|
542
|
+
},
|
|
543
|
+
[
|
|
544
|
+
createCommentVNode(" \u88C1\u526A\u533A\u57DF "),
|
|
545
|
+
createVNode(unref(VueCropper), {
|
|
546
|
+
ref_key: "cropperRef",
|
|
547
|
+
ref: cropperRef,
|
|
548
|
+
img: cropImageUrl.value,
|
|
549
|
+
info: true,
|
|
550
|
+
"auto-crop": true,
|
|
551
|
+
"auto-crop-width": cropWidth.value,
|
|
552
|
+
"auto-crop-height": cropHeight.value,
|
|
553
|
+
fixed: aspectRatio.fixed,
|
|
554
|
+
"fixed-number": aspectRatio.value,
|
|
555
|
+
"can-move": true,
|
|
556
|
+
"can-scale": true,
|
|
557
|
+
"can-rotate": false,
|
|
558
|
+
onRealTime: handleCropRealTime
|
|
559
|
+
}, null, 8, ["img", "auto-crop-width", "auto-crop-height", "fixed", "fixed-number"])
|
|
560
|
+
],
|
|
561
|
+
2
|
|
562
|
+
/* CLASS */
|
|
563
|
+
),
|
|
564
|
+
createElementVNode(
|
|
565
|
+
"div",
|
|
566
|
+
{
|
|
567
|
+
class: normalizeClass(unref(bem)("image-upload-pro", "cropper-config"))
|
|
568
|
+
},
|
|
569
|
+
[
|
|
570
|
+
createVNode(_component_el_form, { model: cropForm }, {
|
|
571
|
+
default: withCtx(() => [
|
|
572
|
+
createVNode(_component_el_row, { gutter: 10 }, {
|
|
573
|
+
default: withCtx(() => [
|
|
574
|
+
createVNode(_component_el_col, { span: 8 }, {
|
|
575
|
+
default: withCtx(() => [
|
|
576
|
+
createVNode(_component_el_form_item, { label: "\u88C1\u526A\u6BD4\u4F8B" }, {
|
|
577
|
+
default: withCtx(() => [
|
|
578
|
+
createVNode(_component_el_select, {
|
|
579
|
+
style: { "width": "100%" },
|
|
580
|
+
modelValue: cropForm.aspectRatio,
|
|
581
|
+
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => cropForm.aspectRatio = $event),
|
|
582
|
+
onChange: handleAspectRatioChange
|
|
583
|
+
}, {
|
|
584
|
+
default: withCtx(() => [
|
|
585
|
+
(openBlock(), createElementBlock(
|
|
586
|
+
Fragment,
|
|
587
|
+
null,
|
|
588
|
+
renderList(ASPECT_RATIO_OPTIONS, (option) => {
|
|
589
|
+
return createVNode(_component_el_option, {
|
|
590
|
+
key: option.value,
|
|
591
|
+
label: option.label,
|
|
592
|
+
value: option.value
|
|
593
|
+
}, null, 8, ["label", "value"]);
|
|
594
|
+
}),
|
|
595
|
+
64
|
|
596
|
+
/* STABLE_FRAGMENT */
|
|
597
|
+
))
|
|
598
|
+
]),
|
|
599
|
+
_: 1
|
|
600
|
+
/* STABLE */
|
|
601
|
+
}, 8, ["modelValue"])
|
|
602
|
+
]),
|
|
603
|
+
_: 1
|
|
604
|
+
/* STABLE */
|
|
605
|
+
})
|
|
606
|
+
]),
|
|
607
|
+
_: 1
|
|
608
|
+
/* STABLE */
|
|
609
|
+
}),
|
|
610
|
+
createVNode(_component_el_col, { span: 16 }, {
|
|
611
|
+
default: withCtx(() => [
|
|
612
|
+
createVNode(_component_el_form_item, { label: "\u88C1\u526A\u5C3A\u5BF8" }, {
|
|
613
|
+
default: withCtx(() => [
|
|
614
|
+
createVNode(_component_el_input_number, {
|
|
615
|
+
modelValue: displayWidth.value,
|
|
616
|
+
"onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => displayWidth.value = $event),
|
|
617
|
+
placeholder: "\u5BBD\u5EA6",
|
|
618
|
+
min: props.sizeLimit.width || 100,
|
|
619
|
+
onChange: handleSizeChange
|
|
620
|
+
}, null, 8, ["modelValue", "min"]),
|
|
621
|
+
_cache[9] || (_cache[9] = createElementVNode(
|
|
622
|
+
"span",
|
|
623
|
+
{ style: { "margin": "0 8px" } },
|
|
624
|
+
"*",
|
|
625
|
+
-1
|
|
626
|
+
/* CACHED */
|
|
627
|
+
)),
|
|
628
|
+
createVNode(_component_el_input_number, {
|
|
629
|
+
modelValue: displayHeight.value,
|
|
630
|
+
"onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => displayHeight.value = $event),
|
|
631
|
+
placeholder: "\u9AD8\u5EA6",
|
|
632
|
+
min: props.sizeLimit.height || 100,
|
|
633
|
+
onChange: handleSizeChange
|
|
634
|
+
}, null, 8, ["modelValue", "min"])
|
|
635
|
+
]),
|
|
636
|
+
_: 1
|
|
637
|
+
/* STABLE */
|
|
638
|
+
})
|
|
639
|
+
]),
|
|
640
|
+
_: 1
|
|
641
|
+
/* STABLE */
|
|
642
|
+
})
|
|
643
|
+
]),
|
|
644
|
+
_: 1
|
|
645
|
+
/* STABLE */
|
|
646
|
+
})
|
|
647
|
+
]),
|
|
648
|
+
_: 1
|
|
649
|
+
/* STABLE */
|
|
650
|
+
}, 8, ["model"])
|
|
651
|
+
],
|
|
652
|
+
2
|
|
653
|
+
/* CLASS */
|
|
654
|
+
)
|
|
655
|
+
]),
|
|
656
|
+
_: 1
|
|
657
|
+
/* STABLE */
|
|
658
|
+
}, 8, ["modelValue"])
|
|
659
|
+
],
|
|
660
|
+
2
|
|
661
|
+
/* CLASS */
|
|
662
|
+
);
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
export { _sfc_main as default };
|