文件选择器内置文件筛选完善
This commit is contained in:
@@ -2,12 +2,13 @@ import hashlib
|
|||||||
import mimetypes
|
import mimetypes
|
||||||
|
|
||||||
import django_filters
|
import django_filters
|
||||||
|
from django.db import connection
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
|
|
||||||
from application import dispatch
|
from application import dispatch
|
||||||
from dvadmin.system.models import FileList
|
from dvadmin.system.models import FileList
|
||||||
from dvadmin.utils.json_response import DetailResponse
|
from dvadmin.utils.json_response import DetailResponse, SuccessResponse
|
||||||
from dvadmin.utils.serializers import CustomModelSerializer
|
from dvadmin.utils.serializers import CustomModelSerializer
|
||||||
from dvadmin.utils.viewset import CustomModelViewSet
|
from dvadmin.utils.viewset import CustomModelViewSet
|
||||||
|
|
||||||
@@ -99,13 +100,17 @@ class FileViewSet(CustomModelViewSet):
|
|||||||
|
|
||||||
@action(methods=['GET'], detail=False)
|
@action(methods=['GET'], detail=False)
|
||||||
def get_all(self, request):
|
def get_all(self, request):
|
||||||
return DetailResponse(data=self.get_serializer(self.get_queryset(), many=True).data)
|
data1 = self.get_serializer(self.get_queryset(), many=True).data
|
||||||
|
data2 = []
|
||||||
|
if dispatch.is_tenants_mode():
|
||||||
|
from django_tenants.utils import schema_context
|
||||||
|
with schema_context('public'):
|
||||||
|
data2 = self.get_serializer(FileList.objects.all(), many=True).data
|
||||||
|
return DetailResponse(data=data2+data1)
|
||||||
|
|
||||||
def get_queryset(self):
|
def list(self, request, *args, **kwargs):
|
||||||
if self.request.query_params.get('system', 'False') == 'True' and dispatch.is_tenants_mode():
|
if self.request.query_params.get('system', 'False') == 'True' and dispatch.is_tenants_mode():
|
||||||
from django_tenants.utils import tenant_context, get_tenant_model
|
from django_tenants.utils import schema_context
|
||||||
with tenant_context(get_tenant_model().objects.filter(schema_name='public').first()):
|
with schema_context('public'):
|
||||||
print('系统内置文件')
|
return super().list(request, *args, **kwargs)
|
||||||
return super().get_queryset()
|
return super().list(request, *args, **kwargs)
|
||||||
print('常规文件')
|
|
||||||
return super().get_queryset()
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@
|
|||||||
<div style="padding: 4px;">
|
<div style="padding: 4px;">
|
||||||
<div style="width: 100%; display: flex; justify-content: space-between; gap: 12px;">
|
<div style="width: 100%; display: flex; justify-content: space-between; gap: 12px;">
|
||||||
<el-tabs style="width: 100%;" v-model="tabsActived" :type="props.tabsType" :stretch="true"
|
<el-tabs style="width: 100%;" v-model="tabsActived" :type="props.tabsType" :stretch="true"
|
||||||
@tab-change="handleTabChange">
|
@tab-change="handleTabChange" v-if="!isSuperTenent">
|
||||||
<el-tab-pane v-if="props.tabsShow & SHOW.IMAGE" :name="0" label="图片" />
|
<el-tab-pane v-if="props.tabsShow & SHOW.IMAGE" :name="0" label="图片" />
|
||||||
<el-tab-pane v-if="props.tabsShow & SHOW.VIDEO" :name="1" label="视频" />
|
<el-tab-pane v-if="props.tabsShow & SHOW.VIDEO" :name="1" label="视频" />
|
||||||
<el-tab-pane v-if="props.tabsShow & SHOW.AUDIO" :name="2" label="音频" />
|
<el-tab-pane v-if="props.tabsShow & SHOW.AUDIO" :name="2" label="音频" />
|
||||||
@@ -101,8 +101,9 @@
|
|||||||
<el-button type="default" circle icon="refresh" @click="listRequest" />
|
<el-button type="default" circle icon="refresh" @click="listRequest" />
|
||||||
<!-- 这里 show-file-list 和 clearFiles 一起使用确保不会显示上传列表 -->
|
<!-- 这里 show-file-list 和 clearFiles 一起使用确保不会显示上传列表 -->
|
||||||
<el-upload ref="uploadRef" :action="getBaseURL() + 'api/system/file/'" :multiple="false"
|
<el-upload ref="uploadRef" :action="getBaseURL() + 'api/system/file/'" :multiple="false"
|
||||||
:data="{ upload_method: 1 }" :drag="false" :show-file-list="false" :accept="AcceptList[tabsActived]"
|
:data="{ upload_method: 1 }" :drag="false" :show-file-list="false" :accept="AcceptList[tabsActived % 4]"
|
||||||
:on-success="() => { listRequest(); listRequestAll(); uploadRef.clearFiles(); }">
|
:on-success="() => { listRequest(); listRequestAll(); uploadRef.clearFiles(); }"
|
||||||
|
v-if="tabsActived > 3 ? isSuperTenent : true">
|
||||||
<el-button type="primary" icon="plus">上传{{ TypeLabel[tabsActived % 4] }}</el-button>
|
<el-button type="primary" icon="plus">上传{{ TypeLabel[tabsActived % 4] }}</el-button>
|
||||||
</el-upload>
|
</el-upload>
|
||||||
</el-span>
|
</el-span>
|
||||||
@@ -110,7 +111,7 @@
|
|||||||
<el-empty v-if="!listData.length" description="无内容,请上传"
|
<el-empty v-if="!listData.length" description="无内容,请上传"
|
||||||
style="width: 100%; height: calc(50vh); margin-top: 24px; padding: 4px;" />
|
style="width: 100%; height: calc(50vh); margin-top: 24px; padding: 4px;" />
|
||||||
<div ref="listContainerRef" class="listContainer" v-else>
|
<div ref="listContainerRef" class="listContainer" v-else>
|
||||||
<div v-for="item in listData" :style="{ width: (props.itemSize || 100) + 'px' }" :key="item.id"
|
<div v-for="item,index in listData" :style="{ width: (props.itemSize || 100) + 'px' }" :key="index"
|
||||||
@click="onItemClick($event)" :data-id="item[props.valueKey]">
|
@click="onItemClick($event)" :data-id="item[props.valueKey]">
|
||||||
<FileItem :fileData="item" />
|
<FileItem :fileData="item" />
|
||||||
</div>
|
</div>
|
||||||
@@ -140,8 +141,9 @@ import { pluginsAll } from '/@/views/plugins/index';
|
|||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
import { useUserInfo } from "/@/stores/userInfo";
|
import { useUserInfo } from "/@/stores/userInfo";
|
||||||
|
|
||||||
const isTenentMode = true || pluginsAll && pluginsAll.length && pluginsAll.indexOf('dvadmin3-tenents-web') >= 0;
|
const isTenentMode = pluginsAll && pluginsAll.length && pluginsAll.indexOf('dvadmin3-tenants-web') >= 0;
|
||||||
const isSuperTenent = true || (storeToRefs(useUserInfo())).userInfos.schema_name === 'public';
|
const userInfos = storeToRefs(useUserInfo()).userInfos
|
||||||
|
const isSuperTenent = userInfos.value.schema_name === 'public';
|
||||||
const TypeLabel = ['图片', '视频', '音频', '文件']
|
const TypeLabel = ['图片', '视频', '音频', '文件']
|
||||||
const AcceptList = ['image/*', 'video/*', 'audio/*', ''];
|
const AcceptList = ['image/*', 'video/*', 'audio/*', ''];
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@@ -173,8 +175,8 @@ const props = defineProps({
|
|||||||
// inputType不为selector时生效
|
// inputType不为selector时生效
|
||||||
inputSize: { type: Number, default: 100 },
|
inputSize: { type: Number, default: 100 },
|
||||||
|
|
||||||
// v-model绑定的值是file数据的哪个key,默认是id
|
// v-model绑定的值是file数据的哪个key,默认是url
|
||||||
valueKey: { type: String, default: 'id' },
|
valueKey: { type: String, default: 'url' },
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
const selectVisiable = ref<boolean>(false);
|
const selectVisiable = ref<boolean>(false);
|
||||||
@@ -200,6 +202,8 @@ const listRequest = async () => {
|
|||||||
upload_method: 1,
|
upload_method: 1,
|
||||||
...filterForm
|
...filterForm
|
||||||
});
|
});
|
||||||
|
listData.value = [];
|
||||||
|
await nextTick();
|
||||||
listData.value = res.data;
|
listData.value = res.data;
|
||||||
pageForm.total = res.total;
|
pageForm.total = res.total;
|
||||||
pageForm.page = res.page;
|
pageForm.page = res.page;
|
||||||
|
|||||||
Reference in New Issue
Block a user