|
@@ -1,14 +1,15 @@
|
|
<!--
|
|
<!--
|
|
* @Author: Gui
|
|
* @Author: Gui
|
|
* @Date: 2023-05-12 11:36:28
|
|
* @Date: 2023-05-12 11:36:28
|
|
- * @LastEditors: guicheng 1625811865@qq.com
|
|
|
|
- * @LastEditTime: 2024-06-20 16:14:29
|
|
|
|
|
|
+ * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
|
|
|
|
+ * @LastEditTime: 2025-03-25 18:13:49
|
|
* @Description: kxs files
|
|
* @Description: kxs files
|
|
* @filePath:
|
|
* @filePath:
|
|
-->
|
|
-->
|
|
<template lang="pug">
|
|
<template lang="pug">
|
|
el-upload(
|
|
el-upload(
|
|
ref="uploadRef"
|
|
ref="uploadRef"
|
|
|
|
+:class="props.limit && fileList.length >= props.limit ? 'hide' : 'show'"
|
|
v-model:file-list="fileList"
|
|
v-model:file-list="fileList"
|
|
action="http://oss.kexiaoshuang.com"
|
|
action="http://oss.kexiaoshuang.com"
|
|
list-type="picture-card"
|
|
list-type="picture-card"
|
|
@@ -18,12 +19,13 @@ list-type="picture-card"
|
|
:on-remove="handleRemove"
|
|
:on-remove="handleRemove"
|
|
:limit="props.limit"
|
|
:limit="props.limit"
|
|
)
|
|
)
|
|
- IconifyIconOnline( icon="material-symbols:add-rounded" width="60px" height="60px" style="margin:0 auto;color:#999")
|
|
|
|
|
|
+ IconifyIconOnline( icon="material-symbols:add-rounded" width="60px" height="60px" style="margin:0 auto;color:#999" )
|
|
template(#tip)
|
|
template(#tip)
|
|
- .el-upload__tip.text-red 最多上传{{props.limit}}张图片
|
|
|
|
-el-dialog( v-model="dialogVisible" title="图片预览" width="80%" draggable :destroy-on-close="true")
|
|
|
|
- div(class="flex justify-center align-middle" )
|
|
|
|
- img.preview(w-full :src="dialogImageUrl" alt="Preview Image" style="width:100%;height:100%;")
|
|
|
|
|
|
+ .el-upload__tip.text-red 最多上传{{ props.limit }}张图片
|
|
|
|
+//- el-dialog( v-model="dialogVisible" title="图片预览" width="80%" draggable :destroy-on-close="true")
|
|
|
|
+div(class="flex justify-center align-middle dialogImageUrl" v-if='dialogVisible' @click.stop='dialogVisible=false')
|
|
|
|
+ div(class='imgbox')
|
|
|
|
+ img.preview(w-full :src="dialogImageUrl" alt="Preview Image" )
|
|
|
|
|
|
el-dialog(v-model="clipPhoto" title="裁剪图片" :destroy-on-close="true" draggable width="30vw")
|
|
el-dialog(v-model="clipPhoto" title="裁剪图片" :destroy-on-close="true" draggable width="30vw")
|
|
|
|
|
|
@@ -31,12 +33,12 @@ el-dialog(v-model="clipPhoto" title="裁剪图片" :destroy-on-close="true" drag
|
|
ref="refCropper"
|
|
ref="refCropper"
|
|
class="w-[30vw] h-[30vh]"
|
|
class="w-[30vw] h-[30vh]"
|
|
:src="selectImg"
|
|
:src="selectImg"
|
|
- :options={aspectRatio:aspectRatio}
|
|
|
|
|
|
+ :options={ aspectRatio: aspectRatio }
|
|
)
|
|
)
|
|
template( #footer="")
|
|
template( #footer="")
|
|
.flex
|
|
.flex
|
|
el-button( @click="clipPhoto = false") 取消
|
|
el-button( @click="clipPhoto = false") 取消
|
|
- el-button( type="primary" @click="confirmAdd") 确定
|
|
|
|
|
|
+ el-button( type="primary" @click=" confirmAdd ") 确定
|
|
|
|
|
|
</template>
|
|
</template>
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
@@ -46,10 +48,12 @@ import Ossupload from "@/utils/OSSupload";
|
|
import type { UploadProps, UploadUserFile } from "element-plus";
|
|
import type { UploadProps, UploadUserFile } from "element-plus";
|
|
import { ElMessage } from "element-plus";
|
|
import { ElMessage } from "element-plus";
|
|
import ReCropper from "@/components/ReCropper";
|
|
import ReCropper from "@/components/ReCropper";
|
|
-
|
|
|
|
|
|
+import { string } from "vue-types";
|
|
|
|
+const emits = defineEmits(["upok", "removeimg"]);
|
|
type Res = {
|
|
type Res = {
|
|
uploadurl?: string; // 上传地址
|
|
uploadurl?: string; // 上传地址
|
|
url?: string; // 上传地址(+域名)
|
|
url?: string; // 上传地址(+域名)
|
|
|
|
+ saveurl: string; // 上传URL
|
|
};
|
|
};
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
limit: {
|
|
limit: {
|
|
@@ -62,47 +66,27 @@ const props = defineProps({
|
|
},
|
|
},
|
|
callBack: {
|
|
callBack: {
|
|
type: Function,
|
|
type: Function,
|
|
- default: () => { }
|
|
|
|
|
|
+ default: () => {}
|
|
},
|
|
},
|
|
imgList: {
|
|
imgList: {
|
|
type: Object,
|
|
type: Object,
|
|
default: []
|
|
default: []
|
|
},
|
|
},
|
|
-
|
|
|
|
-});
|
|
|
|
-onMounted(() => {
|
|
|
|
- console.log(props.imgList, 12312)
|
|
|
|
- if (props.imgList && props.imgList.length > 0) {
|
|
|
|
- props.imgList.forEach(item => {
|
|
|
|
- fileList.value.push({ name: "1", url: item });
|
|
|
|
- UrlList.value.push(item.split(getConfig().UploadUrl + '/')[1]);
|
|
|
|
- })
|
|
|
|
|
|
+ image: {
|
|
|
|
+ type: String,
|
|
|
|
+ default: ""
|
|
}
|
|
}
|
|
- console.log(fileList.value, 'fileList', UrlList.value)
|
|
|
|
-})
|
|
|
|
-// watch(
|
|
|
|
-// () => props.imgList,
|
|
|
|
-// newValue => {
|
|
|
|
-// console.log(newValue)
|
|
|
|
-// if (newValue) {
|
|
|
|
-// initImg()
|
|
|
|
-// newValue.forEach(item => {
|
|
|
|
-// fileList.value.push({ name: "1", url: item });
|
|
|
|
-// UrlList.value.push(item.split(getConfig().UploadUrl + '/')[1]);
|
|
|
|
-// })
|
|
|
|
-// } else {
|
|
|
|
-// initImg()
|
|
|
|
-// }
|
|
|
|
-// console.log(fileList.value, 'fileList', UrlList.value)
|
|
|
|
-// }
|
|
|
|
-// );
|
|
|
|
|
|
+});
|
|
|
|
+onMounted(() => {});
|
|
|
|
+
|
|
const aspectRatio = ref(1);
|
|
const aspectRatio = ref(1);
|
|
// 文件列表
|
|
// 文件列表
|
|
-const fileList = ref<UploadUserFile[]>([]);
|
|
|
|
|
|
+const fileList: any = ref<UploadUserFile[]>([]);
|
|
// 上传路径列表
|
|
// 上传路径列表
|
|
const UrlList = ref<UploadUserFile[]>([]);
|
|
const UrlList = ref<UploadUserFile[]>([]);
|
|
// 图片上传、预览、裁剪
|
|
// 图片上传、预览、裁剪
|
|
const dialogImageUrl = ref("");
|
|
const dialogImageUrl = ref("");
|
|
|
|
+const ischange = ref(false);
|
|
// 是否预览
|
|
// 是否预览
|
|
const dialogVisible = ref(false);
|
|
const dialogVisible = ref(false);
|
|
// 是否裁剪图片
|
|
// 是否裁剪图片
|
|
@@ -113,11 +97,40 @@ const selectImg = ref("");
|
|
const cropperImgName = ref("");
|
|
const cropperImgName = ref("");
|
|
const uploadRef = ref();
|
|
const uploadRef = ref();
|
|
const refCropper = ref();
|
|
const refCropper = ref();
|
|
|
|
+//仅监听一张图的有效 仅用于商品新增编辑sku
|
|
|
|
+watch(
|
|
|
|
+ () => props.image,
|
|
|
|
+ (newValue, oldValue) => {
|
|
|
|
+ console.log(ischange.value);
|
|
|
|
+ if (ischange.value) {
|
|
|
|
+ ischange.value = false;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (newValue) {
|
|
|
|
+ fileList.value = [
|
|
|
|
+ {
|
|
|
|
+ name: newValue,
|
|
|
|
+ url: getConfig().UploadUrl + "/" + newValue,
|
|
|
|
+ saveurl: newValue
|
|
|
|
+ }
|
|
|
|
+ ];
|
|
|
|
|
|
|
|
+ UrlList.value = [newValue];
|
|
|
|
+ } else {
|
|
|
|
+ fileList.value = [];
|
|
|
|
+ UrlList.value = [];
|
|
|
|
+ }
|
|
|
|
+ // console.log('workOrder变化了',newValue,'+',oldValue)
|
|
|
|
+ },
|
|
|
|
+ { immediate: true, deep: true }
|
|
|
|
+);
|
|
const onChange = (file: any) => {
|
|
const onChange = (file: any) => {
|
|
|
|
+ console.log(file.raw.type);
|
|
if (
|
|
if (
|
|
|
|
+ file.raw.type == "image/gif" ||
|
|
file.raw.type == "image/webp" ||
|
|
file.raw.type == "image/webp" ||
|
|
file.raw.type == "image/png" ||
|
|
file.raw.type == "image/png" ||
|
|
|
|
+ file.raw.type == "image/jpg" ||
|
|
file.raw.type == "image/jpeg"
|
|
file.raw.type == "image/jpeg"
|
|
) {
|
|
) {
|
|
if (file.status == "ready") {
|
|
if (file.status == "ready") {
|
|
@@ -133,7 +146,7 @@ const onChange = (file: any) => {
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
ElMessage({
|
|
ElMessage({
|
|
- message: "仅支持png/jpg/webp 格式的图片文件",
|
|
|
|
|
|
+ message: "仅支持png/jpg/webp/gif/jpeg 格式的图片文件",
|
|
type: "error"
|
|
type: "error"
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -146,22 +159,37 @@ const handlePictureCardPreview: UploadProps["onPreview"] = uploadFile => {
|
|
dialogVisible.value = true;
|
|
dialogVisible.value = true;
|
|
};
|
|
};
|
|
const handleRemove: UploadProps["onRemove"] = (uploadFile, uploadFiles) => {
|
|
const handleRemove: UploadProps["onRemove"] = (uploadFile, uploadFiles) => {
|
|
|
|
+ console.log(uploadFiles, "-----9999999---");
|
|
fileList.value = uploadFiles;
|
|
fileList.value = uploadFiles;
|
|
- // console.log(uploadFiles, '--删除', uploadFile)
|
|
|
|
- let uploadFilesdata = []
|
|
|
|
|
|
+ let uploadFilesdata = [];
|
|
uploadFiles.forEach((item: any) => {
|
|
uploadFiles.forEach((item: any) => {
|
|
- uploadFilesdata.push(item.url.split(getConfig().UploadUrl + '/')[1])
|
|
|
|
- })
|
|
|
|
- UrlList.value = uploadFilesdata
|
|
|
|
|
|
+ uploadFilesdata.push(item.saveurl);
|
|
|
|
+ });
|
|
|
|
+ UrlList.value = uploadFilesdata;
|
|
|
|
+ emits("removeimg"); //方法没细写 只支持单张删除 多张上面的就行 用于商品sku删除
|
|
|
|
+};
|
|
|
|
+const initImg = e => {
|
|
|
|
+ console.log(e, "ttttt");
|
|
|
|
+ ischange.value = true;
|
|
|
|
+ if (e) {
|
|
|
|
+ fileList.value = [];
|
|
|
|
+ UrlList.value = [];
|
|
|
|
+ console.log(e);
|
|
|
|
+ e.split(",").map((item: any) => {
|
|
|
|
+ UrlList.value.push(item);
|
|
|
|
+ fileList.value.push({
|
|
|
|
+ name: item,
|
|
|
|
+ url: getConfig().UploadUrl + "/" + item,
|
|
|
|
+ saveurl: item
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ fileList.value = [];
|
|
|
|
+ UrlList.value = [];
|
|
|
|
+ }
|
|
|
|
+ console.log(111, getConfig().UploadUrl, fileList.value);
|
|
};
|
|
};
|
|
-const initImg = () => {
|
|
|
|
-
|
|
|
|
- fileList.value = []
|
|
|
|
- UrlList.value = []
|
|
|
|
- // fileList.value.push({ name: cropperImgName.value, url: res.url });
|
|
|
|
- // UrlList.value.push(res.uploadurl);
|
|
|
|
|
|
|
|
-}
|
|
|
|
const confirmAdd = (): void => {
|
|
const confirmAdd = (): void => {
|
|
nextTick(() => {
|
|
nextTick(() => {
|
|
refCropper.value.cropper.getCroppedCanvas().toBlob(blob => {
|
|
refCropper.value.cropper.getCroppedCanvas().toBlob(blob => {
|
|
@@ -176,11 +204,62 @@ const confirmAdd = (): void => {
|
|
};
|
|
};
|
|
const OssUp = file => {
|
|
const OssUp = file => {
|
|
Ossupload(file, "KxsAdmin/UploadImg").then((res: Res) => {
|
|
Ossupload(file, "KxsAdmin/UploadImg").then((res: Res) => {
|
|
- fileList.value.push({ name: cropperImgName.value, url: res.url });
|
|
|
|
- UrlList.value.push(res.uploadurl);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- props.callBack(UrlList.value.join(","));
|
|
|
|
|
|
+ console.log(res, "----res------");
|
|
|
|
+ fileList.value.push({
|
|
|
|
+ name: cropperImgName.value,
|
|
|
|
+ url: res.uploadurl,
|
|
|
|
+ saveurl: "/" + res.saveurl
|
|
|
|
+ });
|
|
|
|
+ console.log(cropperImgName.value);
|
|
|
|
+ UrlList.value.push("/" + res.saveurl);
|
|
|
|
+ emits("upok", res.saveurl);
|
|
|
|
+ ischange.value = true;
|
|
|
|
+ // props.callBack(UrlList.value.join(","));
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
+defineExpose({
|
|
|
|
+ initImg,
|
|
|
|
+ UrlList
|
|
|
|
+});
|
|
</script>
|
|
</script>
|
|
|
|
+<style lang="scss" scoped>
|
|
|
|
+.hide {
|
|
|
|
+ position: relative;
|
|
|
|
+ float: left;
|
|
|
|
+
|
|
|
|
+ ::v-deep {
|
|
|
|
+ .el-upload--picture-card {
|
|
|
|
+ display: none;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ .el-upload-list item {
|
|
|
|
+ border: 0;
|
|
|
|
+ border-radius: 0;
|
|
|
|
+ margin: 0 30px 0 0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+.dialogImageUrl {
|
|
|
|
+ position: fixed !important;
|
|
|
|
+ z-index: 1000;
|
|
|
|
+ width: 100%;
|
|
|
|
+ justify-content: center;
|
|
|
|
+ align-items: center;
|
|
|
|
+ background-color: rgba(0, 0, 0, 0.5);
|
|
|
|
+ left: 0;
|
|
|
|
+ top: 0;
|
|
|
|
+ right: 0;
|
|
|
|
+ bottom: 0;
|
|
|
|
+ height: 100vh;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+.imgbox {
|
|
|
|
+ justify-content: center;
|
|
|
|
+ // align-items: center;
|
|
|
|
+ display: flex;
|
|
|
|
+ width: 100%;
|
|
|
|
+ height: 80vh;
|
|
|
|
+ overflow: auto;
|
|
|
|
+}
|
|
|
|
+</style>
|