|
|
|
@ -1,15 +1,5 @@
|
|
|
|
|
<template>
|
|
|
|
|
<div class="upload-box">
|
|
|
|
|
<div :class="sortable && 'upload-box__sortable'">
|
|
|
|
|
<ul v-if="sortable" ref="sortableRef" class="sortable">
|
|
|
|
|
<li v-for="(item, idx) in imgList" :key="item.uid" class="sortable--item">
|
|
|
|
|
<img :src="item.url" />
|
|
|
|
|
<span class="sortable--item-hover">
|
|
|
|
|
<el-icon class="sortable--item-icon" name="ZoomIn" @click="handlePreview(item)" />
|
|
|
|
|
<el-icon class="sortable--item-icon" name="Delete" @click="handleRemove(idx)" />
|
|
|
|
|
</span>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
<el-upload
|
|
|
|
|
v-bind="props"
|
|
|
|
|
action="none"
|
|
|
|
@ -26,8 +16,6 @@
|
|
|
|
|
<span>上传文件</span>
|
|
|
|
|
</el-button>
|
|
|
|
|
</el-upload>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="el-upload__tip">支持小于 {{ fmtSize }} 的 文件</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
@ -35,16 +23,11 @@
|
|
|
|
|
import { upload } from '@/api/file';
|
|
|
|
|
import { ElMessage } from '@/plugins/element-plus';
|
|
|
|
|
import 'element-plus/es/components/image/style/css';
|
|
|
|
|
import Sortable from 'sortablejs';
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
configId: {
|
|
|
|
|
type: String,
|
|
|
|
|
required: true,
|
|
|
|
|
},
|
|
|
|
|
sortable: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false,
|
|
|
|
|
},
|
|
|
|
|
serviceName: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: 'mall-product',
|
|
|
|
@ -110,9 +93,6 @@
|
|
|
|
|
},
|
|
|
|
|
{ deep: true }
|
|
|
|
|
);
|
|
|
|
|
const handleRemove = (idx) => {
|
|
|
|
|
imgList.value.splice(idx, 1);
|
|
|
|
|
};
|
|
|
|
|
const handleExceed = (list) => {
|
|
|
|
|
console.info('[upload] exceed', list);
|
|
|
|
|
ElMessage.error('超出最大上传数量');
|
|
|
|
@ -144,80 +124,11 @@
|
|
|
|
|
}
|
|
|
|
|
return res + units[unit];
|
|
|
|
|
});
|
|
|
|
|
const sortableRef = ref(null);
|
|
|
|
|
const sortableInit = () => {
|
|
|
|
|
new Sortable(sortableRef.value, {
|
|
|
|
|
animation: 150,
|
|
|
|
|
// swapThreshold: 1,
|
|
|
|
|
// fallbackOnBody: true,
|
|
|
|
|
onUpdate({ newIndex, oldIndex }) {
|
|
|
|
|
const newData = imgList.value[newIndex];
|
|
|
|
|
const oldData = imgList.value[oldIndex];
|
|
|
|
|
imgList.value[newIndex] = oldData;
|
|
|
|
|
imgList.value[oldIndex] = newData;
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
if (props.sortable) {
|
|
|
|
|
sortableInit();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
<style lang="less" scoped>
|
|
|
|
|
.max {
|
|
|
|
|
:deep(.el-upload) {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.upload-box__sortable {
|
|
|
|
|
display: flex;
|
|
|
|
|
}
|
|
|
|
|
.sortable {
|
|
|
|
|
--img-size: 148px;
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
margin: 0;
|
|
|
|
|
&--item {
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
background-color: var(--el-fill-color-blank);
|
|
|
|
|
border: 1px solid #c0ccda;
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
width: var(--img-size);
|
|
|
|
|
height: var(--img-size);
|
|
|
|
|
margin: 0 8px 8px 0;
|
|
|
|
|
padding: 0;
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
position: relative;
|
|
|
|
|
img {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
object-fit: contain;
|
|
|
|
|
}
|
|
|
|
|
&-icon {
|
|
|
|
|
margin: 0 10px;
|
|
|
|
|
font-size: 20px;
|
|
|
|
|
}
|
|
|
|
|
&-hover {
|
|
|
|
|
background: rgba(0, 0, 0, 0.5);
|
|
|
|
|
position: absolute;
|
|
|
|
|
left: 0;
|
|
|
|
|
top: 0;
|
|
|
|
|
right: 0;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
color: #fff;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
opacity: 0;
|
|
|
|
|
display: flex;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
}
|
|
|
|
|
&:hover {
|
|
|
|
|
.sortable--item-hover {
|
|
|
|
|
opacity: 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.upload-box {
|
|
|
|
|
:deep(.el-upload-list__item-name) {
|
|
|
|
|
padding-right: 20px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|