修改bug
This commit is contained in:
parent
3b2bc2cc2e
commit
853454a102
|
|
@ -18,6 +18,7 @@ enum Api {
|
|||
getNuList = '/iot/tplink/cameraInfo/nuList', //后期调整
|
||||
getOrgInfo = '/api/common/getOrgInfo',//根据机构编码获取机构信息
|
||||
queryUpBizPrefix = '/api/sysUtils/queryUpBizPrefix',
|
||||
uploadPre = '/sys/common/upload/pre',
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -28,6 +29,9 @@ export const getNuList = (params) => {
|
|||
return defHttp.get({ url: Api.getNuList, params });
|
||||
};
|
||||
|
||||
export const uploadPre = (params) => {
|
||||
return defHttp.post({ url: Api.uploadPre, params }, { isTransformResponse: false });
|
||||
};
|
||||
/**
|
||||
* 上传父路径
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,601 @@
|
|||
<template>
|
||||
<div ref="containerRef" :class="`${prefixCls}-container`">
|
||||
<a-upload-dragger accept="audio/mp3" :headers="headers" :multiple="multiple" :action="currentUploadUrl"
|
||||
:data="{ biz: bizPath, ...extraUploadData }" :fileList="fileList" :disabled="disabled" v-bind="bindProps"
|
||||
:beforeUpload="beforeUpload" :showUploadList="false" @remove="onRemove" @change="onFileChange"
|
||||
@preview="onFilePreview">
|
||||
<template v-if="isImageMode">
|
||||
<div v-if="!isMaxCount">
|
||||
<Icon icon="ant-design:plus-outlined" />
|
||||
<div class="ant-upload-text">{{ text }}</div>
|
||||
</div>
|
||||
</template>
|
||||
<div class="upload-area" style="padding: 20px;" v-else-if="uploadVisible" :disabled="buttonDisabled">
|
||||
<p class="upload-hint">
|
||||
<div class="upload-icon">
|
||||
<img src="../../../../../../assets/upload/mp3.png" style="width: 40px; height: 40px;" />
|
||||
</div>
|
||||
<span class="divider">文件大小不超过10MB</span>
|
||||
</p>
|
||||
</div>
|
||||
</a-upload-dragger>
|
||||
<!-- 文件回显 -->
|
||||
<div class="custom-upload-list noDisabled" v-if="fileList.length > 0">
|
||||
<div v-for="(file, index) in fileList" :key="file.uid">
|
||||
<div style="margin-top: 20px;" >
|
||||
<audio ref="audioPlayer" controls v-if="!!file?.response?.message" :src="getFileAccessHttpUrl(file?.response?.message)" :disabled="false" ></audio>
|
||||
<audio ref="audioPlayer" controls v-else :src="getFileAccessHttpUrl(file.url)" :disabled="false"></audio>
|
||||
</div>
|
||||
<div style="margin-top: 20px;" v-if="!props.disabled">
|
||||
<a-button type="link" danger @click="removeFile(index)">删除</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive, computed, watch, nextTick, createApp, unref } from 'vue';
|
||||
import { Icon } from '/@/components/Icon';
|
||||
import { getToken } from '/@/utils/auth';
|
||||
import { uploadUrl, uploadPre } from '/@/api/common/api';
|
||||
import { propTypes } from '/@/utils/propTypes';
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
import { createImgPreview } from '/@/components/Preview/index';
|
||||
import { useAttrs } from '/@/hooks/core/useAttrs';
|
||||
import { useDesign } from '/@/hooks/web/useDesign';
|
||||
import { UploadTypeEnum } from './upload.data';
|
||||
import { getFileAccessHttpUrl, getHeaders } from '/@/utils/common/compUtils';
|
||||
import UploadItemActions from './components/UploadItemActions.vue';
|
||||
import { InboxOutlined } from '@ant-design/icons-vue';
|
||||
import { Upload } from 'ant-design-vue';
|
||||
|
||||
const opeMediaAddress = import.meta.env.VITE_OPE_MEDIA_ADDRESS
|
||||
const { createMessage, createConfirm } = useMessage();
|
||||
const { prefixCls } = useDesign('j-upload');
|
||||
const attrs = useAttrs();
|
||||
const emit = defineEmits(['change', 'update:value']);
|
||||
const props = defineProps({
|
||||
value: propTypes.oneOfType([propTypes.string, propTypes.array]),
|
||||
text: propTypes.string.def('上传'),
|
||||
fileType: propTypes.string.def(UploadTypeEnum.all),
|
||||
/*这个属性用于控制文件上传的业务路径*/
|
||||
bizPath: propTypes.string.def('temp'),
|
||||
/**
|
||||
* 是否返回url,
|
||||
* true:仅返回url
|
||||
* false:返回fileName filePath fileSize
|
||||
*/
|
||||
returnUrl: propTypes.bool.def(true),
|
||||
// 最大上传数量
|
||||
maxCount: propTypes.number.def(0),
|
||||
buttonVisible: propTypes.bool.def(true),
|
||||
multiple: propTypes.bool.def(true),
|
||||
// 是否显示左右移动按钮
|
||||
mover: propTypes.bool.def(true),
|
||||
// 是否显示下载按钮
|
||||
download: propTypes.bool.def(true),
|
||||
// 删除时是否显示确认框
|
||||
removeConfirm: propTypes.bool.def(false),
|
||||
beforeUpload: propTypes.func,
|
||||
disabled: propTypes.bool.def(false),
|
||||
// 替换前一个文件,用于超出最大数量依然允许上传
|
||||
replaceLastOne: propTypes.bool.def(false),
|
||||
// 是否上传至管理平台
|
||||
toOpe: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
default: false,
|
||||
}
|
||||
});
|
||||
|
||||
const headers = getHeaders();
|
||||
const fileList = ref<any[]>([]);
|
||||
const uploadGoOn = ref<boolean>(true);
|
||||
const currentUploadUrl = ref(uploadUrl);
|
||||
const extraUploadData = ref<Record<string, any>>({});
|
||||
// refs
|
||||
const containerRef = ref();
|
||||
// 是否达到了最大上传数量
|
||||
const isMaxCount = computed(() => props.maxCount > 0 && fileList.value.length >= props.maxCount);
|
||||
// 当前是否是上传图片模式
|
||||
const isImageMode = computed(() => props.fileType === UploadTypeEnum.image);
|
||||
// 上传按钮是否禁用
|
||||
const buttonDisabled = computed(() => {
|
||||
if (props.disabled === true) {
|
||||
return true;
|
||||
}
|
||||
if (isMaxCount.value === true) {
|
||||
if (props.replaceLastOne === true) {
|
||||
return false
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false
|
||||
});
|
||||
// 合并 props 和 attrs
|
||||
const bindProps = computed(() => {
|
||||
//update-begin-author:liusq date:20220411 for: [issue/455]上传组件传入accept限制上传文件类型无效
|
||||
const bind: any = Object.assign({}, props, unref(attrs));
|
||||
//update-end-author:liusq date:20220411 for: [issue/455]上传组件传入accept限制上传文件类型无效
|
||||
|
||||
bind.name = 'file';
|
||||
bind.listType = isImageMode.value ? 'picture-card' : 'text';
|
||||
bind.class = [bind.class, { 'upload-disabled': props.disabled }];
|
||||
bind.data = { biz: props.bizPath, ...bind.data, ...extraUploadData.value };
|
||||
//update-begin-author:taoyan date:20220407 for: 自定义beforeUpload return false,并不能中断上传过程
|
||||
if (!bind.beforeUpload) {
|
||||
bind.beforeUpload = onBeforeUpload;
|
||||
}
|
||||
//update-end-author:taoyan date:20220407 for: 自定义beforeUpload return false,并不能中断上传过程
|
||||
// 如果当前是图片上传模式,就只能上传图片
|
||||
if (isImageMode.value && !bind.accept) {
|
||||
bind.accept = 'image/*';
|
||||
}
|
||||
return bind;
|
||||
});
|
||||
function removeFile(index) {
|
||||
fileList.value.splice(index, 1);
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.value,
|
||||
(val) => {
|
||||
if (Array.isArray(val)) {
|
||||
if (props.returnUrl) {
|
||||
parsePathsValue(val.join(','));
|
||||
} else {
|
||||
parseArrayValue(val);
|
||||
}
|
||||
} else {
|
||||
//update-begin---author:liusq ---date:20230914 for:[issues/5327]Upload组件returnUrl为false时上传的字段值返回了一个'[object Object]' ------------
|
||||
if (props.returnUrl) {
|
||||
parsePathsValue(val);
|
||||
} else {
|
||||
val && parseArrayValue(JSON.parse(val));
|
||||
}
|
||||
//update-end---author:liusq ---date:20230914 for:[issues/5327]Upload组件returnUrl为false时上传的字段值返回了一个'[object Object]' ------------
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
watch(fileList, () => nextTick(() => addActionsListener()), { immediate: true });
|
||||
|
||||
const antUploadItemCls = 'ant-upload-list-item';
|
||||
|
||||
// Listener
|
||||
function addActionsListener() {
|
||||
if (!isImageMode.value) {
|
||||
return;
|
||||
}
|
||||
const uploadItems = containerRef.value ? containerRef.value.getElementsByClassName(antUploadItemCls) : null;
|
||||
if (!uploadItems || uploadItems.length === 0) {
|
||||
return;
|
||||
}
|
||||
for (const uploadItem of uploadItems) {
|
||||
let hasActions = uploadItem.getAttribute('data-has-actions') === 'true';
|
||||
if (!hasActions) {
|
||||
uploadItem.addEventListener('mouseover', onAddActionsButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 添加可左右移动的按钮
|
||||
function onAddActionsButton(event) {
|
||||
const getUploadItem = () => {
|
||||
for (const path of event.path) {
|
||||
if (path.classList.contains(antUploadItemCls)) {
|
||||
return path;
|
||||
} else if (path.classList.contains(`${prefixCls}-container`)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
const uploadItem = getUploadItem();
|
||||
if (!uploadItem) {
|
||||
return;
|
||||
}
|
||||
const actions = uploadItem.getElementsByClassName('ant-upload-list-item-actions');
|
||||
if (!actions || actions.length === 0) {
|
||||
return;
|
||||
}
|
||||
// 添加操作按钮
|
||||
const div = document.createElement('div');
|
||||
div.className = 'upload-actions-container';
|
||||
createApp(UploadItemActions, {
|
||||
element: uploadItem,
|
||||
fileList: fileList,
|
||||
mover: props.mover,
|
||||
download: props.download,
|
||||
emitValue: emitValue,
|
||||
}).mount(div);
|
||||
actions[0].appendChild(div);
|
||||
uploadItem.setAttribute('data-has-actions', 'true');
|
||||
uploadItem.removeEventListener('mouseover', onAddActionsButton);
|
||||
}
|
||||
|
||||
// 解析数据库存储的逗号分割
|
||||
function parsePathsValue(paths) {
|
||||
if (!paths || paths.length == 0) {
|
||||
fileList.value = [];
|
||||
return;
|
||||
}
|
||||
let list: any[] = [];
|
||||
for (const item of paths.split(',')) {
|
||||
let url = getFileAccessHttpUrl(item);
|
||||
list.push({
|
||||
uid: uidGenerator(),
|
||||
name: getFileName(item),
|
||||
status: 'done',
|
||||
url: url,
|
||||
response: { status: 'history', message: item },
|
||||
});
|
||||
}
|
||||
fileList.value = list;
|
||||
}
|
||||
|
||||
// 解析数组值
|
||||
function parseArrayValue(array) {
|
||||
if (!array || array.length == 0) {
|
||||
fileList.value = [];
|
||||
return;
|
||||
}
|
||||
let list: any[] = [];
|
||||
for (const item of array) {
|
||||
let url = getFileAccessHttpUrl(item.filePath);
|
||||
list.push({
|
||||
uid: uidGenerator(),
|
||||
name: item.fileName,
|
||||
url: url,
|
||||
status: 'done',
|
||||
response: { status: 'history', message: item.filePath },
|
||||
});
|
||||
}
|
||||
fileList.value = list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传前校验
|
||||
*/
|
||||
async function beforeUpload(file) {
|
||||
let fileType = file.type;
|
||||
console.log("🚀 ~ beforeUpload ~ file:", file)
|
||||
if (fileType.indexOf('audio') < 0) {
|
||||
createMessage.info('请上传MP3文件');
|
||||
fileList.value = [];
|
||||
return false;
|
||||
}
|
||||
if (props.toOpe) {
|
||||
let res = await uploadPre({ fileName: file.name, fileSize: file.size });
|
||||
if (res.result == 500) {
|
||||
createMessage.info('服务暂时不可用,请稍后重试');
|
||||
return Upload.LIST_IGNORE;
|
||||
} else {
|
||||
// 切换上传地址和参数
|
||||
currentUploadUrl.value = '/opeexup/sys/common/static/upload/export';
|
||||
extraUploadData.value = { biz: props.bizPath, name: res.result, size: file.size };
|
||||
console.log("🌊 ~ beforeUpload ~ extraUploadData.value:", extraUploadData.value)
|
||||
}
|
||||
} else {
|
||||
// 恢复默认
|
||||
currentUploadUrl.value = uploadUrl;
|
||||
extraUploadData.value = { biz: props.bizPath };
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// 文件上传之前的操作
|
||||
function onBeforeUpload(file) {
|
||||
uploadGoOn.value = true;
|
||||
if (isImageMode.value) {
|
||||
if (file.type.indexOf('image') < 0) {
|
||||
createMessage.warning('请上传图片');
|
||||
uploadGoOn.value = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 扩展 beforeUpload 验证
|
||||
if (typeof props.beforeUpload === 'function') {
|
||||
return props.beforeUpload(file);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 删除处理事件
|
||||
function onRemove() {
|
||||
if (props.removeConfirm) {
|
||||
return new Promise((resolve) => {
|
||||
createConfirm({
|
||||
title: '删除',
|
||||
content: `确定要删除这${isImageMode.value ? '张图片' : '个文件'}吗?`,
|
||||
iconType: 'warning',
|
||||
onOk: () => resolve(true),
|
||||
onCancel: () => resolve(false),
|
||||
});
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// upload组件change事件
|
||||
function onFileChange(info) {
|
||||
console.log("🚀 ~ onFileChange ~ info:", info.file)
|
||||
var file = info.file;
|
||||
let fileType = file.type;
|
||||
if (fileType.indexOf('audio') < 0) {
|
||||
fileList.value = [];
|
||||
return false;
|
||||
}
|
||||
if (!info.file.status && uploadGoOn.value === false) {
|
||||
info.fileList.pop();
|
||||
}
|
||||
let fileListTemp = info.fileList;
|
||||
// 限制最大上传数
|
||||
if (props.maxCount > 0) {
|
||||
let count = fileListTemp.length;
|
||||
if (count >= props.maxCount) {
|
||||
let diffNum = props.maxCount - fileListTemp.length;
|
||||
if (diffNum >= 0) {
|
||||
fileListTemp = fileListTemp.slice(-props.maxCount);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (info.file.status === 'done') {
|
||||
let successFileList = [];
|
||||
if (info.file.response.success) {
|
||||
successFileList = fileListTemp.map((file) => {
|
||||
if (file.response) {
|
||||
let reUrl = file.response.message;
|
||||
file.url = getFileAccessHttpUrl(reUrl);
|
||||
}
|
||||
return file;
|
||||
});
|
||||
} else {
|
||||
successFileList = fileListTemp.filter(item => {
|
||||
return item.uid != info.file.uid;
|
||||
});
|
||||
createMessage.error(`${info.file.name} 上传失败.`);
|
||||
}
|
||||
fileListTemp = successFileList;
|
||||
} else if (info.file.status === 'error') {
|
||||
createMessage.error(`${info.file.name} 上传失败.`);
|
||||
}
|
||||
// update-begin--author:liaozhiyang---date:20240628---for:【issues/1273】上传组件JUpload配置beforeUpload阻止了上传,前端页面中还是显示缩略图
|
||||
// beforeUpload 返回false,则没有status
|
||||
info.file.status && (fileList.value = fileListTemp);
|
||||
// update-end--author:liaozhiyang---date:20240628---for:【issues/1273】上传组件JUpload配置beforeUpload阻止了上传,前端页面中还是显示缩略图
|
||||
if (info.file.status === 'done' || info.file.status === 'removed') {
|
||||
//returnUrl为true时仅返回文件路径
|
||||
if (props.returnUrl) {
|
||||
handlePathChange();
|
||||
} else {
|
||||
//returnUrl为false时返回文件名称、文件路径及文件大小
|
||||
let newFileList: any[] = [];
|
||||
for (const item of fileListTemp) {
|
||||
if (item.status === 'done') {
|
||||
let fileJson = {
|
||||
fileName: item.name,
|
||||
filePath: item.response.message,
|
||||
fileSize: item.size,
|
||||
};
|
||||
newFileList.push(fileJson);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
//update-begin---author:liusq ---date:20230914 for:[issues/5327]Upload组件returnUrl为false时上传的字段值返回了一个'[object Object]' ------------
|
||||
emitValue(JSON.stringify(newFileList));
|
||||
//update-end---author:liusq ---date:20230914 for:[issues/5327]Upload组件returnUrl为false时上传的字段值返回了一个'[object Object]' ------------
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handlePathChange() {
|
||||
let uploadFiles = fileList.value;
|
||||
let path = '';
|
||||
if (!uploadFiles || uploadFiles.length == 0) {
|
||||
path = '';
|
||||
}
|
||||
let pathList: string[] = [];
|
||||
for (const item of uploadFiles) {
|
||||
if (item.status === 'done') {
|
||||
pathList.push(item.response.message);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (pathList.length > 0) {
|
||||
path = pathList.join(',');
|
||||
}
|
||||
emitValue(path);
|
||||
}
|
||||
|
||||
// 预览文件、图片
|
||||
function onFilePreview(file) {
|
||||
if (isImageMode.value) {
|
||||
createImgPreview({ imageList: [file.url], maskClosable: true });
|
||||
} else {
|
||||
window.open(file.url);
|
||||
}
|
||||
}
|
||||
|
||||
function emitValue(value) {
|
||||
emit('change', value);
|
||||
emit('update:value', value);
|
||||
}
|
||||
|
||||
function uidGenerator() {
|
||||
return '-' + parseInt(Math.random() * 10000 + 1, 10);
|
||||
}
|
||||
|
||||
function getFileName(path) {
|
||||
if (path.lastIndexOf('\\') >= 0) {
|
||||
let reg = new RegExp('\\\\', 'g');
|
||||
path = path.replace(reg, '/');
|
||||
}
|
||||
return path.substring(path.lastIndexOf('/') + 1);
|
||||
}
|
||||
//计算是否可以继续上传
|
||||
const uploadVisible = computed(() => {
|
||||
if (props['maxCount'] === 0) {
|
||||
return true;
|
||||
}
|
||||
return fileList.value.length < props['maxCount'];
|
||||
});
|
||||
|
||||
defineExpose({
|
||||
addActionsListener,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
//noinspection LessUnresolvedVariable
|
||||
@prefix-cls: ~'@{namespace}-j-upload';
|
||||
|
||||
.@{prefix-cls} {
|
||||
&-container {
|
||||
position: relative;
|
||||
|
||||
.upload-disabled {
|
||||
.ant-upload-list-item {
|
||||
.anticon-close {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.anticon-delete {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* update-begin-author:taoyan date:2022-5-24 for:VUEN-1093详情界面 图片下载按钮显示不全*/
|
||||
.upload-download-handler {
|
||||
right: 6px !important;
|
||||
}
|
||||
|
||||
/* update-end-author:taoyan date:2022-5-24 for:VUEN-1093详情界面 图片下载按钮显示不全*/
|
||||
}
|
||||
|
||||
.ant-upload-text-icon {
|
||||
color: @primary-color;
|
||||
}
|
||||
|
||||
.ant-upload-list-item {
|
||||
.upload-actions-container {
|
||||
position: absolute;
|
||||
top: -31px;
|
||||
left: -18px;
|
||||
z-index: 11;
|
||||
width: 84px;
|
||||
height: 84px;
|
||||
line-height: 28px;
|
||||
text-align: center;
|
||||
pointer-events: none;
|
||||
|
||||
a {
|
||||
opacity: 0.9;
|
||||
margin: 0 5px;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.3s;
|
||||
|
||||
.anticon {
|
||||
color: #fff;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.upload-mover-handler,
|
||||
.upload-download-handler {
|
||||
position: absolute;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.upload-mover-handler {
|
||||
width: 100%;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.upload-download-handler {
|
||||
top: -4px;
|
||||
right: -4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ant-upload-wrapper .ant-upload-drag .ant-upload {
|
||||
padding: 0px !important;
|
||||
}
|
||||
|
||||
.ant-upload-drag {
|
||||
border: 0px !important;
|
||||
}
|
||||
|
||||
.upload-text {
|
||||
font-size: 16px;
|
||||
color: rgba(74, 69, 69, 0.85);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.upload-icon {
|
||||
margin: 16px;
|
||||
}
|
||||
|
||||
.divider {
|
||||
font-size: 12px;
|
||||
color: rgb(189, 189, 189);
|
||||
}
|
||||
|
||||
:deep(.ant-upload-wrapper .ant-upload-list.ant-upload-list-picture-card .ant-upload-list-item) {
|
||||
position: relative;
|
||||
height: 240px !important;
|
||||
padding: 8px;
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 4px;
|
||||
text-align: center;
|
||||
background: #f1f7ff;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
:deep(.ant-upload-wrapper .ant-upload-list.ant-upload-list-picture-card .ant-upload-list-item .ant-upload-list-item-thumbnail) {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
width: 200px !important;
|
||||
height: 200px !important;
|
||||
line-height: 60px;
|
||||
text-align: center;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
:deep(.ant-upload-wrapper .ant-upload-list .ant-upload-list-item .ant-upload-list-item-name) {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
line-height: 1.5714285714285714;
|
||||
transition: all 0.3s;
|
||||
margin-top: -20px;
|
||||
}
|
||||
|
||||
.custom-upload-list {
|
||||
border: 0px dashed #d9d9d9;
|
||||
border-radius: 6px;
|
||||
padding: 10px;
|
||||
background: #f1f7ff;
|
||||
text-align: center;
|
||||
}
|
||||
.noDisabled{
|
||||
pointer-events: auto !important;
|
||||
cursor: pointer !important;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,626 @@
|
|||
<template>
|
||||
<div ref="containerRef" :class="`${prefixCls}-container`">
|
||||
<a-upload-dragger accept="video/mp4" :headers="headers" :multiple="multiple" :action="currentUploadUrl"
|
||||
:data="{ biz: bizPath, ...extraUploadData }" :fileList="fileList" :disabled="disabled" v-bind="bindProps"
|
||||
:beforeUpload="beforeUpload" :showUploadList="false" @remove="onRemove" @change="onFileChange"
|
||||
@preview="onFilePreview">
|
||||
<template v-if="isImageMode">
|
||||
<div v-if="!isMaxCount">
|
||||
<Icon icon="ant-design:plus-outlined" />
|
||||
<div class="ant-upload-text">{{ text }}</div>
|
||||
</div>
|
||||
</template>
|
||||
<div class="upload-area" style="padding: 20px;" v-else-if="uploadVisible" :disabled="buttonDisabled">
|
||||
<!-- <p class="upload-text">点击或者拖拽上传</p> -->
|
||||
<p class="upload-hint">
|
||||
<div class="upload-icon">
|
||||
<img src="../../../../../../assets/upload/mp4.png" style="width: 40px; height: 40px;" />
|
||||
</div>
|
||||
<span class="divider">文件大小不超过10MB</span>
|
||||
<!-- <span class="divider">|</span>
|
||||
<a-tooltip placement="top">
|
||||
<template #title>
|
||||
请上传相应格式类型的文件
|
||||
</template>
|
||||
<span class="divider">
|
||||
<QuestionCircleOutlined style="margin-right: 0px;" />
|
||||
格式说明
|
||||
</span>
|
||||
</a-tooltip> -->
|
||||
</p>
|
||||
</div>
|
||||
</a-upload-dragger>
|
||||
<!-- 文件回显 -->
|
||||
<div class="custom-upload-list noDisabled" v-if="fileList.length > 0">
|
||||
<div v-for="(file, index) in fileList" :key="file.uid">
|
||||
<div style="margin-top: 20px;">
|
||||
<video controls style="max-width: 100%; max-height: 300px;">
|
||||
{{opeMediaAddress}}
|
||||
<source v-if="!!file?.response?.message" :src="getFileAccessHttpUrl(file?.response?.message)" type="video/mp4">
|
||||
<source v-else :src="getFileAccessHttpUrl(file.url)" type="video/mp4">
|
||||
您的浏览器不支持视频播放
|
||||
</video>
|
||||
</div>
|
||||
<!-- <div style="margin-top: 20px;">
|
||||
{{ file.name }}
|
||||
</div> -->
|
||||
<div style="margin-top: 20px;" v-if="!props.disabled">
|
||||
<a-button type="link" danger @click="removeFile(index)">删除</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive, computed, watch, nextTick, createApp, unref } from 'vue';
|
||||
import { Icon } from '/@/components/Icon';
|
||||
import { getToken } from '/@/utils/auth';
|
||||
import { uploadUrl, uploadPre } from '/@/api/common/api';
|
||||
import { propTypes } from '/@/utils/propTypes';
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
import { createImgPreview } from '/@/components/Preview/index';
|
||||
import { useAttrs } from '/@/hooks/core/useAttrs';
|
||||
import { useDesign } from '/@/hooks/web/useDesign';
|
||||
import { UploadTypeEnum } from './upload.data';
|
||||
import { getFileAccessHttpUrl, getHeaders } from '/@/utils/common/compUtils';
|
||||
import UploadItemActions from './components/UploadItemActions.vue';
|
||||
import { InboxOutlined } from '@ant-design/icons-vue';
|
||||
import { Upload } from 'ant-design-vue';
|
||||
|
||||
const opeMediaAddress = import.meta.env.VITE_OPE_MEDIA_ADDRESS
|
||||
const { createMessage, createConfirm } = useMessage();
|
||||
const { prefixCls } = useDesign('j-upload');
|
||||
const attrs = useAttrs();
|
||||
const emit = defineEmits(['change', 'update:value']);
|
||||
const props = defineProps({
|
||||
value: propTypes.oneOfType([propTypes.string, propTypes.array]),
|
||||
text: propTypes.string.def('上传'),
|
||||
fileType: propTypes.string.def(UploadTypeEnum.all),
|
||||
/*这个属性用于控制文件上传的业务路径*/
|
||||
bizPath: propTypes.string.def('temp'),
|
||||
/**
|
||||
* 是否返回url,
|
||||
* true:仅返回url
|
||||
* false:返回fileName filePath fileSize
|
||||
*/
|
||||
returnUrl: propTypes.bool.def(true),
|
||||
// 最大上传数量
|
||||
maxCount: propTypes.number.def(0),
|
||||
buttonVisible: propTypes.bool.def(true),
|
||||
multiple: propTypes.bool.def(true),
|
||||
// 是否显示左右移动按钮
|
||||
mover: propTypes.bool.def(true),
|
||||
// 是否显示下载按钮
|
||||
download: propTypes.bool.def(true),
|
||||
// 删除时是否显示确认框
|
||||
removeConfirm: propTypes.bool.def(false),
|
||||
beforeUpload: propTypes.func,
|
||||
disabled: propTypes.bool.def(false),
|
||||
// 替换前一个文件,用于超出最大数量依然允许上传
|
||||
replaceLastOne: propTypes.bool.def(false),
|
||||
// 是否上传至管理平台
|
||||
toOpe: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
default: false,
|
||||
}
|
||||
});
|
||||
|
||||
const headers = getHeaders();
|
||||
const fileList = ref<any[]>([]);
|
||||
const uploadGoOn = ref<boolean>(true);
|
||||
const currentUploadUrl = ref(uploadUrl);
|
||||
const extraUploadData = ref<Record<string, any>>({});
|
||||
// refs
|
||||
const containerRef = ref();
|
||||
// 是否达到了最大上传数量
|
||||
const isMaxCount = computed(() => props.maxCount > 0 && fileList.value.length >= props.maxCount);
|
||||
// 当前是否是上传图片模式
|
||||
const isImageMode = computed(() => props.fileType === UploadTypeEnum.image);
|
||||
// 上传按钮是否禁用
|
||||
const buttonDisabled = computed(() => {
|
||||
if (props.disabled === true) {
|
||||
return true;
|
||||
}
|
||||
if (isMaxCount.value === true) {
|
||||
if (props.replaceLastOne === true) {
|
||||
return false
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false
|
||||
});
|
||||
// 合并 props 和 attrs
|
||||
const bindProps = computed(() => {
|
||||
//update-begin-author:liusq date:20220411 for: [issue/455]上传组件传入accept限制上传文件类型无效
|
||||
const bind: any = Object.assign({}, props, unref(attrs));
|
||||
//update-end-author:liusq date:20220411 for: [issue/455]上传组件传入accept限制上传文件类型无效
|
||||
|
||||
bind.name = 'file';
|
||||
bind.listType = isImageMode.value ? 'picture-card' : 'text';
|
||||
bind.class = [bind.class, { 'upload-disabled': props.disabled }];
|
||||
bind.data = { biz: props.bizPath, ...bind.data, ...extraUploadData.value };
|
||||
//update-begin-author:taoyan date:20220407 for: 自定义beforeUpload return false,并不能中断上传过程
|
||||
if (!bind.beforeUpload) {
|
||||
bind.beforeUpload = onBeforeUpload;
|
||||
}
|
||||
//update-end-author:taoyan date:20220407 for: 自定义beforeUpload return false,并不能中断上传过程
|
||||
// 如果当前是图片上传模式,就只能上传图片
|
||||
if (isImageMode.value && !bind.accept) {
|
||||
bind.accept = 'image/*';
|
||||
}
|
||||
return bind;
|
||||
});
|
||||
function removeFile(index) {
|
||||
fileList.value.splice(index, 1);
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.value,
|
||||
(val) => {
|
||||
if (Array.isArray(val)) {
|
||||
if (props.returnUrl) {
|
||||
parsePathsValue(val.join(','));
|
||||
} else {
|
||||
parseArrayValue(val);
|
||||
}
|
||||
} else {
|
||||
//update-begin---author:liusq ---date:20230914 for:[issues/5327]Upload组件returnUrl为false时上传的字段值返回了一个'[object Object]' ------------
|
||||
if (props.returnUrl) {
|
||||
parsePathsValue(val);
|
||||
} else {
|
||||
val && parseArrayValue(JSON.parse(val));
|
||||
}
|
||||
//update-end---author:liusq ---date:20230914 for:[issues/5327]Upload组件returnUrl为false时上传的字段值返回了一个'[object Object]' ------------
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
watch(fileList, () => nextTick(() => addActionsListener()), { immediate: true });
|
||||
|
||||
const antUploadItemCls = 'ant-upload-list-item';
|
||||
|
||||
// Listener
|
||||
function addActionsListener() {
|
||||
if (!isImageMode.value) {
|
||||
return;
|
||||
}
|
||||
const uploadItems = containerRef.value ? containerRef.value.getElementsByClassName(antUploadItemCls) : null;
|
||||
if (!uploadItems || uploadItems.length === 0) {
|
||||
return;
|
||||
}
|
||||
for (const uploadItem of uploadItems) {
|
||||
let hasActions = uploadItem.getAttribute('data-has-actions') === 'true';
|
||||
if (!hasActions) {
|
||||
uploadItem.addEventListener('mouseover', onAddActionsButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传前校验
|
||||
*/
|
||||
async function beforeUpload(file) {
|
||||
let fileType = file.type;
|
||||
console.log("🚀 ~ beforeUpload ~ fileType:", fileType)
|
||||
if (fileType.indexOf('video') < 0) {
|
||||
createMessage.info('请上传MP4文件');
|
||||
fileList.value = [];
|
||||
return false;
|
||||
}
|
||||
if (props.toOpe) {
|
||||
let res = await uploadPre({ fileName: file.name, fileSize: file.size });
|
||||
if (res.result == 500) {
|
||||
createMessage.info('服务暂时不可用,请稍后重试');
|
||||
return Upload.LIST_IGNORE;
|
||||
} else {
|
||||
// 切换上传地址和参数
|
||||
currentUploadUrl.value = '/opeexup/sys/common/static/upload/export';
|
||||
extraUploadData.value = { biz: props.bizPath, name: res.result, size: file.size };
|
||||
console.log("🌊 ~ beforeUpload ~ extraUploadData.value:", extraUploadData.value)
|
||||
}
|
||||
} else {
|
||||
// 恢复默认
|
||||
currentUploadUrl.value = uploadUrl;
|
||||
extraUploadData.value = { biz: props.bizPath };
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// 添加可左右移动的按钮
|
||||
function onAddActionsButton(event) {
|
||||
const getUploadItem = () => {
|
||||
for (const path of event.path) {
|
||||
if (path.classList.contains(antUploadItemCls)) {
|
||||
return path;
|
||||
} else if (path.classList.contains(`${prefixCls}-container`)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
const uploadItem = getUploadItem();
|
||||
if (!uploadItem) {
|
||||
return;
|
||||
}
|
||||
const actions = uploadItem.getElementsByClassName('ant-upload-list-item-actions');
|
||||
if (!actions || actions.length === 0) {
|
||||
return;
|
||||
}
|
||||
// 添加操作按钮
|
||||
const div = document.createElement('div');
|
||||
div.className = 'upload-actions-container';
|
||||
createApp(UploadItemActions, {
|
||||
element: uploadItem,
|
||||
fileList: fileList,
|
||||
mover: props.mover,
|
||||
download: props.download,
|
||||
emitValue: emitValue,
|
||||
}).mount(div);
|
||||
actions[0].appendChild(div);
|
||||
uploadItem.setAttribute('data-has-actions', 'true');
|
||||
uploadItem.removeEventListener('mouseover', onAddActionsButton);
|
||||
}
|
||||
|
||||
// 解析数据库存储的逗号分割
|
||||
function parsePathsValue(paths) {
|
||||
if (!paths || paths.length == 0) {
|
||||
fileList.value = [];
|
||||
return;
|
||||
}
|
||||
let list: any[] = [];
|
||||
for (const item of paths.split(',')) {
|
||||
let url = getFileAccessHttpUrl(item);
|
||||
list.push({
|
||||
uid: uidGenerator(),
|
||||
name: getFileName(item),
|
||||
status: 'done',
|
||||
url: url,
|
||||
response: { status: 'history', message: item },
|
||||
});
|
||||
}
|
||||
fileList.value = list;
|
||||
}
|
||||
|
||||
function transUrl(record) {
|
||||
console.log("🚀 ~ transUrl ~ record:", record)
|
||||
if (record == 'local') {
|
||||
return getFileAccessHttpUrl(record)
|
||||
} else {
|
||||
return record
|
||||
}
|
||||
}
|
||||
// 解析数组值
|
||||
function parseArrayValue(array) {
|
||||
if (!array || array.length == 0) {
|
||||
fileList.value = [];
|
||||
return;
|
||||
}
|
||||
let list: any[] = [];
|
||||
for (const item of array) {
|
||||
let url = getFileAccessHttpUrl(item.filePath);
|
||||
list.push({
|
||||
uid: uidGenerator(),
|
||||
name: item.fileName,
|
||||
url: url,
|
||||
status: 'done',
|
||||
response: { status: 'history', message: item.filePath },
|
||||
});
|
||||
}
|
||||
fileList.value = list;
|
||||
}
|
||||
|
||||
// 文件上传之前的操作
|
||||
function onBeforeUpload(file) {
|
||||
uploadGoOn.value = true;
|
||||
if (isImageMode.value) {
|
||||
if (file.type.indexOf('image') < 0) {
|
||||
createMessage.warning('请上传图片');
|
||||
uploadGoOn.value = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 扩展 beforeUpload 验证
|
||||
if (typeof props.beforeUpload === 'function') {
|
||||
return props.beforeUpload(file);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 删除处理事件
|
||||
function onRemove() {
|
||||
if (props.removeConfirm) {
|
||||
return new Promise((resolve) => {
|
||||
createConfirm({
|
||||
title: '删除',
|
||||
content: `确定要删除这${isImageMode.value ? '张图片' : '个文件'}吗?`,
|
||||
iconType: 'warning',
|
||||
onOk: () => resolve(true),
|
||||
onCancel: () => resolve(false),
|
||||
});
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// upload组件change事件
|
||||
function onFileChange(info) {
|
||||
var file = info.file;
|
||||
let fileType = file.type;
|
||||
if (fileType.indexOf('video') < 0) {
|
||||
fileList.value = [];
|
||||
return false;
|
||||
}
|
||||
if (!info.file.status && uploadGoOn.value === false) {
|
||||
info.fileList.pop();
|
||||
}
|
||||
let fileListTemp = info.fileList;
|
||||
// 限制最大上传数
|
||||
if (props.maxCount > 0) {
|
||||
let count = fileListTemp.length;
|
||||
if (count >= props.maxCount) {
|
||||
let diffNum = props.maxCount - fileListTemp.length;
|
||||
if (diffNum >= 0) {
|
||||
fileListTemp = fileListTemp.slice(-props.maxCount);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (info.file.status === 'done') {
|
||||
let successFileList = [];
|
||||
if (info.file.response.success) {
|
||||
successFileList = fileListTemp.map((file) => {
|
||||
if (file.response) {
|
||||
let reUrl = file.response.message;
|
||||
file.url = getFileAccessHttpUrl(reUrl);
|
||||
}
|
||||
return file;
|
||||
});
|
||||
} else {
|
||||
successFileList = fileListTemp.filter(item => {
|
||||
return item.uid != info.file.uid;
|
||||
});
|
||||
createMessage.error(`${info.file.name} 上传失败.`);
|
||||
}
|
||||
fileListTemp = successFileList;
|
||||
} else if (info.file.status === 'error') {
|
||||
createMessage.error(`${info.file.name} 上传失败.`);
|
||||
}
|
||||
// update-begin--author:liaozhiyang---date:20240628---for:【issues/1273】上传组件JUpload配置beforeUpload阻止了上传,前端页面中还是显示缩略图
|
||||
// beforeUpload 返回false,则没有status
|
||||
info.file.status && (fileList.value = fileListTemp);
|
||||
// update-end--author:liaozhiyang---date:20240628---for:【issues/1273】上传组件JUpload配置beforeUpload阻止了上传,前端页面中还是显示缩略图
|
||||
if (info.file.status === 'done' || info.file.status === 'removed') {
|
||||
//returnUrl为true时仅返回文件路径
|
||||
if (props.returnUrl) {
|
||||
handlePathChange();
|
||||
} else {
|
||||
//returnUrl为false时返回文件名称、文件路径及文件大小
|
||||
let newFileList: any[] = [];
|
||||
for (const item of fileListTemp) {
|
||||
if (item.status === 'done') {
|
||||
let fileJson = {
|
||||
fileName: item.name,
|
||||
filePath: item.response.message,
|
||||
fileSize: item.size,
|
||||
};
|
||||
newFileList.push(fileJson);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
//update-begin---author:liusq ---date:20230914 for:[issues/5327]Upload组件returnUrl为false时上传的字段值返回了一个'[object Object]' ------------
|
||||
emitValue(JSON.stringify(newFileList));
|
||||
//update-end---author:liusq ---date:20230914 for:[issues/5327]Upload组件returnUrl为false时上传的字段值返回了一个'[object Object]' ------------
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handlePathChange() {
|
||||
let uploadFiles = fileList.value;
|
||||
let path = '';
|
||||
if (!uploadFiles || uploadFiles.length == 0) {
|
||||
path = '';
|
||||
}
|
||||
let pathList: string[] = [];
|
||||
for (const item of uploadFiles) {
|
||||
if (item.status === 'done') {
|
||||
pathList.push(item.response.message);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (pathList.length > 0) {
|
||||
path = pathList.join(',');
|
||||
}
|
||||
emitValue(path);
|
||||
}
|
||||
|
||||
// 预览文件、图片
|
||||
function onFilePreview(file) {
|
||||
if (isImageMode.value) {
|
||||
createImgPreview({ imageList: [file.url], maskClosable: true });
|
||||
} else {
|
||||
window.open(file.url);
|
||||
}
|
||||
}
|
||||
|
||||
function emitValue(value) {
|
||||
emit('change', value);
|
||||
emit('update:value', value);
|
||||
}
|
||||
|
||||
function uidGenerator() {
|
||||
return '-' + parseInt(Math.random() * 10000 + 1, 10);
|
||||
}
|
||||
|
||||
function getFileName(path) {
|
||||
if (path.lastIndexOf('\\') >= 0) {
|
||||
let reg = new RegExp('\\\\', 'g');
|
||||
path = path.replace(reg, '/');
|
||||
}
|
||||
return path.substring(path.lastIndexOf('/') + 1);
|
||||
}
|
||||
//计算是否可以继续上传
|
||||
const uploadVisible = computed(() => {
|
||||
if (props['maxCount'] === 0) {
|
||||
return true;
|
||||
}
|
||||
return fileList.value.length < props['maxCount'];
|
||||
});
|
||||
|
||||
defineExpose({
|
||||
addActionsListener,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
//noinspection LessUnresolvedVariable
|
||||
@prefix-cls: ~'@{namespace}-j-upload';
|
||||
|
||||
.@{prefix-cls} {
|
||||
&-container {
|
||||
position: relative;
|
||||
|
||||
.upload-disabled {
|
||||
.ant-upload-list-item {
|
||||
.anticon-close {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.anticon-delete {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* update-begin-author:taoyan date:2022-5-24 for:VUEN-1093详情界面 图片下载按钮显示不全*/
|
||||
.upload-download-handler {
|
||||
right: 6px !important;
|
||||
}
|
||||
|
||||
/* update-end-author:taoyan date:2022-5-24 for:VUEN-1093详情界面 图片下载按钮显示不全*/
|
||||
}
|
||||
|
||||
.ant-upload-text-icon {
|
||||
color: @primary-color;
|
||||
}
|
||||
|
||||
.ant-upload-list-item {
|
||||
.upload-actions-container {
|
||||
position: absolute;
|
||||
top: -31px;
|
||||
left: -18px;
|
||||
z-index: 11;
|
||||
width: 84px;
|
||||
height: 84px;
|
||||
line-height: 28px;
|
||||
text-align: center;
|
||||
pointer-events: none;
|
||||
|
||||
a {
|
||||
opacity: 0.9;
|
||||
margin: 0 5px;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.3s;
|
||||
|
||||
.anticon {
|
||||
color: #fff;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.upload-mover-handler,
|
||||
.upload-download-handler {
|
||||
position: absolute;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.upload-mover-handler {
|
||||
width: 100%;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.upload-download-handler {
|
||||
top: -4px;
|
||||
right: -4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ant-upload-wrapper .ant-upload-drag .ant-upload {
|
||||
padding: 0px !important;
|
||||
}
|
||||
|
||||
.ant-upload-drag {
|
||||
border: 0px !important;
|
||||
}
|
||||
|
||||
.upload-text {
|
||||
font-size: 16px;
|
||||
color: rgba(74, 69, 69, 0.85);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.upload-icon {
|
||||
margin: 16px;
|
||||
}
|
||||
|
||||
.divider {
|
||||
font-size: 12px;
|
||||
color: rgb(189, 189, 189);
|
||||
}
|
||||
|
||||
:deep(.ant-upload-wrapper .ant-upload-list.ant-upload-list-picture-card .ant-upload-list-item) {
|
||||
position: relative;
|
||||
height: 240px !important;
|
||||
padding: 8px;
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 4px;
|
||||
text-align: center;
|
||||
background: #f1f7ff;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
:deep(.ant-upload-wrapper .ant-upload-list.ant-upload-list-picture-card .ant-upload-list-item .ant-upload-list-item-thumbnail) {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
width: 200px !important;
|
||||
height: 200px !important;
|
||||
line-height: 60px;
|
||||
text-align: center;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
:deep(.ant-upload-wrapper .ant-upload-list .ant-upload-list-item .ant-upload-list-item-name) {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
line-height: 1.5714285714285714;
|
||||
transition: all 0.3s;
|
||||
margin-top: -20px;
|
||||
}
|
||||
|
||||
.custom-upload-list {
|
||||
border: 0px dashed #d9d9d9;
|
||||
border-radius: 6px;
|
||||
padding: 10px;
|
||||
background: #f1f7ff;
|
||||
text-align: center;
|
||||
}
|
||||
.noDisabled{
|
||||
pointer-events: auto !important;
|
||||
cursor: pointer !important;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -24,13 +24,13 @@ export const columns: BasicColumn[] = [
|
|||
title: '附件',
|
||||
align: "center",
|
||||
dataIndex: 'filePath',
|
||||
customRender: render.renderImage,
|
||||
// customRender: render.renderImage,
|
||||
},
|
||||
{
|
||||
title: '选中图片',
|
||||
align: "center",
|
||||
dataIndex: 'checkPicPath',
|
||||
customRender: render.renderImage,
|
||||
// customRender: render.renderImage,
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
|
|
|
|||
|
|
@ -44,8 +44,43 @@
|
|||
<TableAction :actions="getTableAction(record)" />
|
||||
</template>
|
||||
<template v-slot:bodyCell="{ column, record, index, text }">
|
||||
|
||||
<template v-if="column.dataIndex === 'filePath'">
|
||||
<span v-if="!text" style="font-size: 12px;font-style: italic;">无</span>
|
||||
<span v-else>
|
||||
<img :src="getFileAccessHttpUrl(text)" width="30" height="30" v-if="record.fileType === 'image'">
|
||||
<a-button v-else-if="record.fileType === 'video'" type="link" class="btnPrivate" @click="openVideoModal(text)">播放</a-button>
|
||||
<a-button v-else-if="record.fileType === 'audio'" type="link" class="btnPrivate" @click="openAudioModal(text)">播放</a-button>
|
||||
<a-button v-else-if="record.fileType === 'document'" type="link" class="btnPrivate" @click="downloadFile(text)">下载</a-button>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template v-if="column.dataIndex === 'checkPicPath'">
|
||||
<span v-if="!text" style="font-size: 12px;font-style: italic;">无</span>
|
||||
<span v-else>
|
||||
<img :src="getFileAccessHttpUrl(text)" width="30" height="30" >
|
||||
</span>
|
||||
</template>
|
||||
</template>
|
||||
</BasicTable>
|
||||
|
||||
<!-- 音频播放 -->
|
||||
<a-modal v-model:visible="showAudioModal" title="音频播放" :footer="null" @cancel="closeAudioModal"
|
||||
:bodyStyle="{ padding: '0', maxHeight: '80vh', overflow: 'auto' }" :keyboard="true">
|
||||
<audio ref="audioPlayer" controls style="width: 100%; display: block; margin: 20px auto;">
|
||||
<source :src="getFileAccessHttpUrl(audioUrl)">
|
||||
您的浏览器不支持音频播放。
|
||||
</audio>
|
||||
</a-modal>
|
||||
|
||||
<!-- 视频播放 -->
|
||||
<a-modal v-model:visible="showVideoModal" title="视频播放" :footer="null" @cancel="closeVideoModal"
|
||||
:bodyStyle="{ padding: '0', maxHeight: '80vh', overflow: 'auto' }">
|
||||
<video ref="videoPlayer" controls style="width: 100%; max-height: 70vh; display: block; margin: 0 auto;">
|
||||
<source :src="getFileAccessHttpUrl(videoUrl)">
|
||||
您的浏览器不支持视频播放。
|
||||
</video>
|
||||
</a-modal>
|
||||
<!-- 表单区域 -->
|
||||
<NuResourcesManagementModal ref="registerModal" @success="handleSuccess"></NuResourcesManagementModal>
|
||||
</div>
|
||||
|
|
@ -62,6 +97,7 @@
|
|||
import { useUserStore } from '/@/store/modules/user';
|
||||
import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
|
||||
import JSelectMultiple from '/@/components/Form/src/jeecg/components/JSelectMultiple.vue';
|
||||
import { getFileAccessHttpUrl } from '/@/utils/common/compUtils';
|
||||
|
||||
const formRef = ref();
|
||||
const queryParam = reactive<any>({});
|
||||
|
|
@ -109,6 +145,41 @@
|
|||
// 高级查询配置
|
||||
const superQueryConfig = reactive(superQuerySchema);
|
||||
|
||||
const showVideoModal = ref(false); // 控制模态框显示
|
||||
const videoUrl = ref(''); // 视频 URL
|
||||
const videoPlayer = ref(null);
|
||||
const openVideoModal = (url) => {
|
||||
videoUrl.value = url;
|
||||
showVideoModal.value = true;
|
||||
};
|
||||
// 关闭视频模态框
|
||||
const closeVideoModal = () => {
|
||||
if (videoPlayer.value) {
|
||||
videoPlayer.value.pause(); // 暂停视频播放
|
||||
videoPlayer.value.currentTime = 0; // 可选:将播放进度重置到开始
|
||||
}
|
||||
showVideoModal.value = false;
|
||||
videoUrl.value = '';
|
||||
};
|
||||
|
||||
const showAudioModal = ref(false); // 控制音频模态框显示
|
||||
const audioUrl = ref(''); // 音频 URL
|
||||
const audioPlayer = ref(null);
|
||||
|
||||
// 打开音频模态框
|
||||
const openAudioModal = (url) => {
|
||||
audioUrl.value = url;
|
||||
showAudioModal.value = true;
|
||||
};
|
||||
// 关闭音频模态框
|
||||
const closeAudioModal = () => {
|
||||
if (audioPlayer.value) {
|
||||
audioPlayer.value.pause(); // 暂停音频播放
|
||||
audioPlayer.value.currentTime = 0; // 可选:重置播放进度
|
||||
}
|
||||
showAudioModal.value = false;
|
||||
audioUrl.value = '';
|
||||
};
|
||||
/**
|
||||
* 高级查询事件
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -31,12 +31,12 @@
|
|||
</a-col>
|
||||
<a-col :span="24" v-if="formData.fileType == 'video'">
|
||||
<a-form-item label="视频" v-bind="validateInfos.filePath" id="NuResourcesManagementForm-filePath" name="filePath">
|
||||
<j-upload :fileMax="1" v-model:value="formData.filePath" ></j-upload>
|
||||
<JUploadMp4 maxCount="1" bizPath="/zzbq" v-model:value="formData.filePath" fileType="mp4" :disabled="disabled"/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="24" v-if="formData.fileType == 'audio'">
|
||||
<a-form-item label="音频" v-bind="validateInfos.filePath" id="NuResourcesManagementForm-filePath" name="filePath">
|
||||
<j-upload :fileMax="1" v-model:value="formData.filePath" ></j-upload>
|
||||
<JUploadMp3 maxCount="1" bizPath="/zzbq" v-model:value="formData.filePath" fileType="mp3" :disabled="disabled"/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="24" v-if="formData.fileType == 'document'">
|
||||
|
|
@ -63,6 +63,8 @@
|
|||
import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
|
||||
import JImageUpload from '/@/components/Form/src/jeecg/components/JImageUpload.vue';
|
||||
import JUpload from '/@/components/Form/src/jeecg/components/JUpload/JUpload.vue';
|
||||
import JUploadMp3 from '/@/components/Form/src/jeecg/components/JUpload/JUploadMp3.vue';
|
||||
import JUploadMp4 from '/@/components/Form/src/jeecg/components/JUpload/JUploadMp4.vue';
|
||||
import { getValueType } from '/@/utils';
|
||||
import { saveOrUpdate } from '../NuResourcesManagement.api';
|
||||
import { Form } from 'ant-design-vue';
|
||||
|
|
|
|||
Loading…
Reference in New Issue