修改bug

This commit is contained in:
yangjun 2026-02-10 14:59:50 +08:00
parent 3b2bc2cc2e
commit 853454a102
6 changed files with 1308 additions and 4 deletions

View File

@ -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 });
};
/**
*
*/

View File

@ -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]UploadreturnUrlfalse'[object Object]' ------------
if (props.returnUrl) {
parsePathsValue(val);
} else {
val && parseArrayValue(JSON.parse(val));
}
//update-end---author:liusq ---date:20230914 for[issues/5327]UploadreturnUrlfalse'[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;
}
// uploadchange
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---forissues/1273JUploadbeforeUpload
// beforeUpload falsestatus
info.file.status && (fileList.value = fileListTemp);
// update-end--author:liaozhiyang---date:20240628---forissues/1273JUploadbeforeUpload
if (info.file.status === 'done' || info.file.status === 'removed') {
//returnUrltrue
if (props.returnUrl) {
handlePathChange();
} else {
//returnUrlfalse
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]UploadreturnUrlfalse'[object Object]' ------------
emitValue(JSON.stringify(newFileList));
//update-end---author:liusq ---date:20230914 for[issues/5327]UploadreturnUrlfalse'[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>

View File

@ -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]UploadreturnUrlfalse'[object Object]' ------------
if (props.returnUrl) {
parsePathsValue(val);
} else {
val && parseArrayValue(JSON.parse(val));
}
//update-end---author:liusq ---date:20230914 for[issues/5327]UploadreturnUrlfalse'[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;
}
// uploadchange
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---forissues/1273JUploadbeforeUpload
// beforeUpload falsestatus
info.file.status && (fileList.value = fileListTemp);
// update-end--author:liaozhiyang---date:20240628---forissues/1273JUploadbeforeUpload
if (info.file.status === 'done' || info.file.status === 'removed') {
//returnUrltrue
if (props.returnUrl) {
handlePathChange();
} else {
//returnUrlfalse
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]UploadreturnUrlfalse'[object Object]' ------------
emitValue(JSON.stringify(newFileList));
//update-end---author:liusq ---date:20230914 for[issues/5327]UploadreturnUrlfalse'[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>

View File

@ -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: '备注',

View File

@ -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 = '';
};
/**
* 高级查询事件
*/

View File

@ -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';