文件选择器删除功能
This commit is contained in:
@@ -2,6 +2,11 @@
|
||||
<div ref="itemRef" class="file-item" :title="data.name" @mouseenter="isShow = true" @mouseleave="isShow = false">
|
||||
<div class="file-name" :class="{ show: isShow }">{{ data.name }}</div>
|
||||
<component :is="FileTypes[data.file_type].tag" v-bind="FileTypes[data.file_type].attr" />
|
||||
<div class="file-del" :class="{ show: isShow }">
|
||||
<el-icon :size="24" color="white" @click.stop="delFileHandle">
|
||||
<CircleClose style="mix-blend-mode: difference;" />
|
||||
</el-icon>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
@@ -9,6 +14,7 @@ import { defineComponent, nextTick } from 'vue';
|
||||
import { ref, defineProps, PropType, watch, onMounted, h } from 'vue';
|
||||
const props = defineProps({
|
||||
fileData: { type: Object as PropType<any>, required: true },
|
||||
api: { type: Object as PropType<any>, required: true },
|
||||
});
|
||||
const _OtherFileComponent = defineComponent({ template: '<el-icon><Files /></el-icon>' });
|
||||
const FileTypes = [
|
||||
@@ -18,9 +24,11 @@ const FileTypes = [
|
||||
{ tag: _OtherFileComponent, attr: { style: { fontSize: '2rem' } } },
|
||||
];
|
||||
const isShow = ref<boolean>(false);
|
||||
const itemRef = ref<HTMLDivElement | null>(null);
|
||||
const itemRef = ref<HTMLDivElement>();
|
||||
const data = ref<any>(null);
|
||||
const delFileHandle = () => props.api.DelObj(props.fileData.id).then(() => emit('onDelFile'));
|
||||
watch(props.fileData, (nVal) => data.value = nVal, { immediate: true, deep: true });
|
||||
const emit = defineEmits(['onDelFile']);
|
||||
defineExpose({});
|
||||
onMounted(() => { });
|
||||
</script>
|
||||
@@ -55,6 +63,14 @@ onMounted(() => { });
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.file-del {
|
||||
display: none;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.show {
|
||||
display: flex !important;
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@
|
||||
<div ref="listContainerRef" class="listContainer" v-else>
|
||||
<div v-for="item, index in listData" :style="{ width: (props.itemSize || 100) + 'px' }" :key="index"
|
||||
@click="onItemClick($event)" :data-id="item[props.valueKey]">
|
||||
<FileItem :fileData="item" />
|
||||
<FileItem :fileData="item" :api="fileApi" @onDelFile="listRequest(); listRequestAll();" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="listPaginator">
|
||||
@@ -185,6 +185,7 @@ const tabsActived = ref<number>([3, 2, 1, 0][((props.tabsShow & (props.tabsShow
|
||||
const fileApiPrefix = '/api/system/file/';
|
||||
const fileApi = {
|
||||
GetList: (query: UserPageQuery) => request({ url: fileApiPrefix, method: 'get', params: query }),
|
||||
DelObj: (id: DelReq) => request({ url: fileApiPrefix + id + '/', method: 'delete', data: { id } }),
|
||||
GetAll: () => request({ url: fileApiPrefix + 'get_all/' }),
|
||||
};
|
||||
// 过滤表单
|
||||
|
||||
Reference in New Issue
Block a user