|
@@ -26,7 +26,7 @@
|
|
|
</el-form>
|
|
</el-form>
|
|
|
<el-table v-loading="dialogLoading" ref="fileTable" :data="fileList" reserve-selection row-key="id"
|
|
<el-table v-loading="dialogLoading" ref="fileTable" :data="fileList" reserve-selection row-key="id"
|
|
|
@selection-change="handleSelectionFile" @select="handleSelect" @select-all="handleSelectAll">
|
|
@selection-change="handleSelectionFile" @select="handleSelect" @select-all="handleSelectAll">
|
|
|
- <el-table-column type="selection" width="55" header-align="center" />
|
|
|
|
|
|
|
+ <el-table-column type="selection" width="55" header-align="center" :selectable="isSelectableRow" />
|
|
|
<el-table-column label="类型" header-align="center" prop="type" width="80">
|
|
<el-table-column label="类型" header-align="center" prop="type" width="80">
|
|
|
<template #default="scope">
|
|
<template #default="scope">
|
|
|
<dict-tag :options="smsb_source_type" :value="scope.row.type" />
|
|
<dict-tag :options="smsb_source_type" :value="scope.row.type" />
|
|
@@ -58,7 +58,7 @@ import { ref, watch, defineProps, defineEmits, nextTick } from 'vue';
|
|
|
import { listMinioData } from '@/api/smsb/source/minioData';
|
|
import { listMinioData } from '@/api/smsb/source/minioData';
|
|
|
import type { MinioDataVO, MinioDataQuery } from '@/api/smsb/source/minioData_type';
|
|
import type { MinioDataVO, MinioDataQuery } from '@/api/smsb/source/minioData_type';
|
|
|
|
|
|
|
|
-const props = defineProps<{ modelValue: string }>();
|
|
|
|
|
|
|
+const props = defineProps<{ modelValue: string; single?: boolean; onlyImage?: boolean }>();
|
|
|
const emit = defineEmits(['update:modelValue']);
|
|
const emit = defineEmits(['update:modelValue']);
|
|
|
|
|
|
|
|
const dialogVisible = ref(false);
|
|
const dialogVisible = ref(false);
|
|
@@ -66,6 +66,11 @@ const dialogLoading = ref(false);
|
|
|
const fileList = ref<MinioDataVO[]>([]);
|
|
const fileList = ref<MinioDataVO[]>([]);
|
|
|
const fileTotal = ref(0);
|
|
const fileTotal = ref(0);
|
|
|
const selectedFiles = ref<any[]>([]);
|
|
const selectedFiles = ref<any[]>([]);
|
|
|
|
|
+// 控制哪些行可选
|
|
|
|
|
+function isSelectableRow(row: any) {
|
|
|
|
|
+ if (props.onlyImage) return row.type === 1;
|
|
|
|
|
+ return true;
|
|
|
|
|
+}
|
|
|
const fileTable = ref();
|
|
const fileTable = ref();
|
|
|
|
|
|
|
|
const queryParams = ref<MinioDataQuery>({
|
|
const queryParams = ref<MinioDataQuery>({
|
|
@@ -124,19 +129,51 @@ const getFileList = async () => {
|
|
|
|
|
|
|
|
// 多选框选中文件数据
|
|
// 多选框选中文件数据
|
|
|
function handleSelectionFile(selection: MinioDataVO[]) {
|
|
function handleSelectionFile(selection: MinioDataVO[]) {
|
|
|
- // 只做新增
|
|
|
|
|
- selection.forEach((item) => {
|
|
|
|
|
- if (!selectedFiles.value.some((f) => String(f.id) === String(item.id))) {
|
|
|
|
|
- selectedFiles.value.push({
|
|
|
|
|
- id: item.id,
|
|
|
|
|
- name: item.originalName,
|
|
|
|
|
- type: item.type,
|
|
|
|
|
- duration: item.type === 1 ? 10 : item.duration,
|
|
|
|
|
- order: 0
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (props.single && props.onlyImage) {
|
|
|
|
|
+ // 单选且仅图片
|
|
|
|
|
+ if (selection.length > 0) {
|
|
|
|
|
+ const img = selection.find((item) => item.type === 1);
|
|
|
|
|
+ if (img) {
|
|
|
|
|
+ selectedFiles.value = [
|
|
|
|
|
+ {
|
|
|
|
|
+ id: img.id,
|
|
|
|
|
+ name: img.originalName,
|
|
|
|
|
+ type: img.type,
|
|
|
|
|
+ duration: 10,
|
|
|
|
|
+ order: 1
|
|
|
|
|
+ }
|
|
|
|
|
+ ];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ selectedFiles.value = [];
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ selectedFiles.value = [];
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
- selectedFiles.value = selectedFiles.value.map((f, idx) => ({ ...f, order: idx + 1 }));
|
|
|
|
|
|
|
+ } else if (props.single) {
|
|
|
|
|
+ // 单选任意类型
|
|
|
|
|
+ if (selection.length > 0) {
|
|
|
|
|
+ selectedFiles.value = [
|
|
|
|
|
+ {
|
|
|
|
|
+ id: selection[0].id,
|
|
|
|
|
+ name: selection[0].originalName,
|
|
|
|
|
+ type: selection[0].type,
|
|
|
|
|
+ duration: selection[0].duration,
|
|
|
|
|
+ order: 1
|
|
|
|
|
+ }
|
|
|
|
|
+ ];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ selectedFiles.value = [];
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 多选多类型
|
|
|
|
|
+ selectedFiles.value = selection.map((item, idx) => ({
|
|
|
|
|
+ id: item.id,
|
|
|
|
|
+ name: item.originalName,
|
|
|
|
|
+ type: item.type,
|
|
|
|
|
+ duration: item.duration,
|
|
|
|
|
+ order: idx + 1
|
|
|
|
|
+ }));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
// 取消单个选中
|
|
// 取消单个选中
|
|
|
function handleSelect(selection: MinioDataVO[], row: MinioDataVO) {
|
|
function handleSelect(selection: MinioDataVO[], row: MinioDataVO) {
|
|
@@ -158,6 +195,12 @@ function removeFile(idx: number) {
|
|
|
emitChange();
|
|
emitChange();
|
|
|
}
|
|
}
|
|
|
function confirmSelect() {
|
|
function confirmSelect() {
|
|
|
|
|
+ if (props.single && props.onlyImage) {
|
|
|
|
|
+ if (selectedFiles.value.length === 0 || selectedFiles.value[0].type !== 1) {
|
|
|
|
|
+ ElMessage.error('只能选择图片文件作为背景');
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
dialogVisible.value = false;
|
|
dialogVisible.value = false;
|
|
|
emitChange();
|
|
emitChange();
|
|
|
}
|
|
}
|