|
@@ -12,6 +12,7 @@
|
|
|
class="avatar-uploader"
|
|
class="avatar-uploader"
|
|
|
:action="actionUrl"
|
|
:action="actionUrl"
|
|
|
:show-file-list="false"
|
|
:show-file-list="false"
|
|
|
|
|
+ :before-upload="handleBeforeUpload"
|
|
|
:on-success="handleAvatarSuccess"
|
|
:on-success="handleAvatarSuccess"
|
|
|
:with-credentials="true"
|
|
:with-credentials="true"
|
|
|
name="file"
|
|
name="file"
|
|
@@ -126,7 +127,7 @@
|
|
|
const isUploadBg = ref<boolean>(true);
|
|
const isUploadBg = ref<boolean>(true);
|
|
|
|
|
|
|
|
const isMap = ref(false);
|
|
const isMap = ref(false);
|
|
|
- const { urlPrefix } = useGlobSetting();
|
|
|
|
|
|
|
+ const { urlPrefix, minifyImgUrl } = useGlobSetting();
|
|
|
|
|
|
|
|
const actionUrl = computed(() => {
|
|
const actionUrl = computed(() => {
|
|
|
return urlJoin(urlPrefix!, `/admin/minimap/uploadPicture`);
|
|
return urlJoin(urlPrefix!, `/admin/minimap/uploadPicture`);
|
|
@@ -159,12 +160,31 @@
|
|
|
hasBg.value = false;
|
|
hasBg.value = false;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const handleBeforeUpload = () => {
|
|
|
|
|
|
|
+ const handleBeforeUpload = (rawFile) => {
|
|
|
if (!selectedShopId.value) {
|
|
if (!selectedShopId.value) {
|
|
|
ElMessage.error({
|
|
ElMessage.error({
|
|
|
message: '请先选择车间',
|
|
message: '请先选择车间',
|
|
|
});
|
|
});
|
|
|
- return false;
|
|
|
|
|
|
|
+ return Promise.reject();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (rawFile.type !== 'image/jpg' && rawFile.type !== 'image/jpeg' && rawFile.type !== 'image/png') {
|
|
|
|
|
+ ElMessage.error('请上传jpg、jpeg、png格式的图片!');
|
|
|
|
|
+ return Promise.reject();
|
|
|
|
|
+ }
|
|
|
|
|
+ const mSize = 1024 * 1024;
|
|
|
|
|
+ if (rawFile.size > 2 * mSize) {
|
|
|
|
|
+ const realSize = (rawFile.size / mSize).toFixed(2);
|
|
|
|
|
+ ElMessageBox.alert(`<div>当前图片${realSize}M,建议压缩到2M以内。 <div>`, '提示', {
|
|
|
|
|
+ dangerouslyUseHTMLString: true,
|
|
|
|
|
+ confirmButtonText: minifyImgUrl ? '点我去压缩' : '确定',
|
|
|
|
|
+ type: 'warning',
|
|
|
|
|
+ }).then(() => {
|
|
|
|
|
+ if (minifyImgUrl) {
|
|
|
|
|
+ window.open(minifyImgUrl);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ return Promise.reject();
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|