Merge branch 'master' of http://47.99.164.66:3000/hzdyjs-xg/all-project
This commit is contained in:
commit
3b99209548
36 files changed
+5167
-249
No files matched your search
@@ -0,0 +1,124 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
/**
|
||||
* 重置bucket访问密码
|
||||
* @param bucketName bucket名称
|
||||
* @param newPassword 新密码
|
||||
* @returns 操作结果
|
||||
*/
|
||||
export function resetBucketPassword(bucketName: string, newPassword: string) {
|
||||
return request({
|
||||
url: '/system/bucket-password/reset',
|
||||
method: 'post',
|
||||
params: { bucketName, newPassword }
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取bucket密码信息
|
||||
* @param bucketName bucket名称
|
||||
* @returns bucket密码信息
|
||||
*/
|
||||
export function getBucketPasswordInfo(bucketName: string) {
|
||||
return request({
|
||||
url: `/system/bucket-password/info/${bucketName}`,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取bucket访问记录
|
||||
* @param bucketName bucket名称
|
||||
* @param limit 限制数量,默认10条
|
||||
* @returns 访问记录列表
|
||||
*/
|
||||
export function getBucketAccessRecords(bucketName: string, limit: number = 10) {
|
||||
return request({
|
||||
url: `/system/bucket-password/records/${bucketName}`,
|
||||
method: 'get',
|
||||
params: { limit }
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证bucket密码
|
||||
* @param bucketName bucket名称
|
||||
* @param password 密码
|
||||
* @returns 验证结果
|
||||
*/
|
||||
export function validateBucketPassword(bucketName: string, password: string) {
|
||||
return request({
|
||||
url: '/system/bucket-password/validate',
|
||||
method: 'post',
|
||||
params: { bucketName, password }
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成强密码
|
||||
* @param length 密码长度,默认12位
|
||||
* @returns 生成的密码
|
||||
*/
|
||||
export function generateStrongPassword(length: number = 12): string {
|
||||
const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*'
|
||||
let password = ''
|
||||
for (let i = 0; i < length; i++) {
|
||||
password += charset.charAt(Math.floor(Math.random() * charset.length))
|
||||
}
|
||||
return password
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证密码强度
|
||||
* @param password 密码
|
||||
* @returns 密码强度评估
|
||||
*/
|
||||
export function validatePasswordStrength(password: string): {
|
||||
isValid: boolean
|
||||
score: number
|
||||
suggestions: string[]
|
||||
} {
|
||||
const suggestions: string[] = []
|
||||
let score = 0
|
||||
|
||||
// 长度检查
|
||||
if (password.length >= 8) {
|
||||
score += 1
|
||||
} else {
|
||||
suggestions.push('密码长度至少8位')
|
||||
}
|
||||
|
||||
// 包含大写字母
|
||||
if (/[A-Z]/.test(password)) {
|
||||
score += 1
|
||||
} else {
|
||||
suggestions.push('包含大写字母')
|
||||
}
|
||||
|
||||
// 包含小写字母
|
||||
if (/[a-z]/.test(password)) {
|
||||
score += 1
|
||||
} else {
|
||||
suggestions.push('包含小写字母')
|
||||
}
|
||||
|
||||
// 包含数字
|
||||
if (/\d/.test(password)) {
|
||||
score += 1
|
||||
} else {
|
||||
suggestions.push('包含数字')
|
||||
}
|
||||
|
||||
// 包含特殊字符
|
||||
if (/[!@#$%^&*]/.test(password)) {
|
||||
score += 1
|
||||
} else {
|
||||
suggestions.push('包含特殊字符')
|
||||
}
|
||||
|
||||
return {
|
||||
isValid: score >= 4,
|
||||
score,
|
||||
suggestions
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
/**
|
||||
* 获取文件临时访问URL
|
||||
* @param ossId 文件ID
|
||||
* @param bucketPassword bucket访问密码
|
||||
* @param expireSeconds 过期时间(秒),默认300秒
|
||||
* @returns 临时访问URL
|
||||
*/
|
||||
export function getFileAccessUrl(ossId: number, bucketPassword?: string, expireSeconds: number = 300) {
|
||||
return request({
|
||||
url: `/resource/file/access/${ossId}`,
|
||||
method: 'get',
|
||||
params: {
|
||||
bucketPassword,
|
||||
expireSeconds
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量获取文件临时访问URL
|
||||
* @param ossIds 文件ID列表
|
||||
* @param bucketPassword bucket访问密码
|
||||
* @param expireSeconds 过期时间(秒),默认300秒
|
||||
* @returns 文件ID与临时URL的映射
|
||||
*/
|
||||
export function getBatchFileAccessUrl(ossIds: number[], bucketPassword?: string, expireSeconds: number = 300) {
|
||||
return request({
|
||||
url: '/resource/file/access/batch',
|
||||
method: 'post',
|
||||
data: ossIds,
|
||||
params: {
|
||||
bucketPassword,
|
||||
expireSeconds
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件下载URL(带权限检查)
|
||||
* @param ossId 文件ID
|
||||
* @param bucketPassword bucket访问密码
|
||||
* @param expireSeconds 过期时间(秒),默认300秒
|
||||
* @returns 下载URL
|
||||
*/
|
||||
export function getFileDownloadUrl(ossId: number, bucketPassword?: string, expireSeconds: number = 300) {
|
||||
return request({
|
||||
url: `/resource/file/download/${ossId}`,
|
||||
method: 'get',
|
||||
params: {
|
||||
bucketPassword,
|
||||
expireSeconds
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件预览URL(带权限检查)
|
||||
* @param ossId 文件ID
|
||||
* @param bucketPassword bucket访问密码
|
||||
* @param expireSeconds 过期时间(秒),默认300秒
|
||||
* @returns 预览URL
|
||||
*/
|
||||
export function getFilePreviewUrl(ossId: number, bucketPassword?: string, expireSeconds: number = 300) {
|
||||
return request({
|
||||
url: `/resource/file/preview/${ossId}`,
|
||||
method: 'get',
|
||||
params: {
|
||||
bucketPassword,
|
||||
expireSeconds
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全下载文件(带bucket密码验证)
|
||||
* @param ossId 文件ID
|
||||
* @param fileName 文件名
|
||||
* @param bucketPassword bucket访问密码
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
export async function secureDownloadFile(ossId: number, fileName: string, bucketPassword?: string) {
|
||||
try {
|
||||
// 获取临时下载URL
|
||||
const { data: downloadUrl } = await getFileDownloadUrl(ossId, bucketPassword)
|
||||
|
||||
// 使用fetch下载文件
|
||||
const response = await fetch(downloadUrl)
|
||||
if (!response.ok) {
|
||||
throw new Error('下载失败')
|
||||
}
|
||||
|
||||
const blob = await response.blob()
|
||||
|
||||
// 创建下载链接
|
||||
const url = URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = fileName
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
|
||||
// 释放内存
|
||||
URL.revokeObjectURL(url)
|
||||
|
||||
return Promise.resolve()
|
||||
} catch (error) {
|
||||
console.error('文件下载失败:', error)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全预览文件(带bucket密码验证)
|
||||
* @param ossId 文件ID
|
||||
* @param contentType 文件类型
|
||||
* @param bucketPassword bucket访问密码
|
||||
* @returns Promise<string> 预览URL
|
||||
*/
|
||||
export async function securePreviewFile(ossId: number, contentType?: string, bucketPassword?: string) {
|
||||
try {
|
||||
// 获取临时预览URL
|
||||
const { data: previewUrl } = await getFilePreviewUrl(ossId, bucketPassword)
|
||||
|
||||
// 根据文件类型选择预览方式
|
||||
if (contentType?.startsWith('image/')) {
|
||||
// 图片直接返回URL用于预览
|
||||
return Promise.resolve(previewUrl)
|
||||
} else {
|
||||
// 其他文件在新窗口打开
|
||||
window.open(previewUrl, '_blank')
|
||||
return Promise.resolve(previewUrl)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('文件预览失败:', error)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取bucket访问密码提示
|
||||
* @param bucketName bucket名称
|
||||
* @returns 密码提示信息
|
||||
*/
|
||||
export function getBucketPasswordHint(bucketName: string) {
|
||||
// 这里可以根据bucket名称返回相应的密码提示
|
||||
// 例如:从配置中获取密码提示信息
|
||||
return `请输入 ${bucketName} bucket 的访问密码`
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证bucket密码格式
|
||||
* @param password 密码
|
||||
* @returns 验证结果
|
||||
*/
|
||||
export function validateBucketPassword(password: string): boolean {
|
||||
// 简单的密码格式验证
|
||||
return password && password.length >= 6
|
||||
}
|
||||
@@ -1,5 +1,12 @@
|
||||
<template>
|
||||
<el-image :src="`${realSrc}`" fit="cover" :style="`width:${realWidth};height:${realHeight};`" :preview-src-list="realSrcList" preview-teleported>
|
||||
<el-image
|
||||
:src="realSrc"
|
||||
fit="cover"
|
||||
:style="`width:${realWidth};height:${realHeight};`"
|
||||
:preview-src-list="realSrcList"
|
||||
preview-teleported
|
||||
v-loading="loading"
|
||||
>
|
||||
<template #error>
|
||||
<div class="image-slot">
|
||||
<el-icon><picture-filled /></el-icon>
|
||||
@@ -9,10 +16,15 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { propTypes } from '@/utils/propTypes';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { listByIds } from '@/api/system/oss';
|
||||
import type { OssVO } from '@/api/system/oss/types';
|
||||
|
||||
const props = defineProps({
|
||||
src: propTypes.string.def(''),
|
||||
src: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
width: {
|
||||
type: [Number, String],
|
||||
default: ''
|
||||
@@ -20,31 +32,100 @@ const props = defineProps({
|
||||
height: {
|
||||
type: [Number, String],
|
||||
default: ''
|
||||
},
|
||||
// 是否为ossid模式
|
||||
isOssId: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
});
|
||||
|
||||
const realSrc = computed(() => {
|
||||
if (!props.src) {
|
||||
return;
|
||||
}
|
||||
const real_src = props.src.split(',')[0];
|
||||
return real_src;
|
||||
});
|
||||
const loading = ref(false);
|
||||
const urlCache = ref<Map<string, string>>(new Map());
|
||||
|
||||
const realSrcList = computed(() => {
|
||||
if (!props.src) {
|
||||
return [];
|
||||
// 通过ossid获取真实URL
|
||||
const getUrlByOssId = async (ossId: string): Promise<string> => {
|
||||
// 检查缓存
|
||||
if (urlCache.value.has(ossId)) {
|
||||
return urlCache.value.get(ossId)!;
|
||||
}
|
||||
const real_src_list = props.src.split(',');
|
||||
const srcList: string[] = [];
|
||||
real_src_list.forEach((item: string) => {
|
||||
if (item.trim() === '') {
|
||||
|
||||
try {
|
||||
loading.value = true;
|
||||
const response = await listByIds(ossId);
|
||||
const ossList: OssVO[] = response.data;
|
||||
|
||||
if (ossList && ossList.length > 0) {
|
||||
const url = ossList[0].url;
|
||||
// 缓存结果
|
||||
urlCache.value.set(ossId, url);
|
||||
return url;
|
||||
}
|
||||
return '';
|
||||
} catch (error) {
|
||||
console.error('获取OSS URL失败:', error);
|
||||
return '';
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 处理多个ossid的情况
|
||||
const getUrlsByOssIds = async (ossIds: string[]): Promise<string[]> => {
|
||||
const urls: string[] = [];
|
||||
|
||||
for (const ossId of ossIds) {
|
||||
if (ossId.trim()) {
|
||||
const url = await getUrlByOssId(ossId.trim());
|
||||
if (url) {
|
||||
urls.push(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return urls;
|
||||
};
|
||||
|
||||
const realSrc = ref('');
|
||||
|
||||
const realSrcList = ref<string[]>([]);
|
||||
|
||||
// 处理src变化
|
||||
watch(
|
||||
() => props.src,
|
||||
async (newSrc) => {
|
||||
if (!newSrc) {
|
||||
realSrc.value = '';
|
||||
realSrcList.value = [];
|
||||
return;
|
||||
}
|
||||
return srcList.push(item);
|
||||
});
|
||||
return srcList;
|
||||
});
|
||||
|
||||
if (props.isOssId) {
|
||||
// ossid模式:通过接口获取真实URL
|
||||
const ossIds = newSrc.split(',');
|
||||
const urls = await getUrlsByOssIds(ossIds);
|
||||
|
||||
if (urls.length > 0) {
|
||||
realSrc.value = urls[0];
|
||||
realSrcList.value = urls;
|
||||
} else {
|
||||
realSrc.value = '';
|
||||
realSrcList.value = [];
|
||||
}
|
||||
} else {
|
||||
// 普通模式:直接使用src作为URL
|
||||
const urls = newSrc.split(',').filter((url) => url.trim());
|
||||
if (urls.length > 0) {
|
||||
realSrc.value = urls[0];
|
||||
realSrcList.value = urls;
|
||||
} else {
|
||||
realSrc.value = '';
|
||||
realSrcList.value = [];
|
||||
}
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
const realWidth = computed(() => (typeof props.width == 'string' ? props.width : `${props.width}px`));
|
||||
|
||||
|
||||
@@ -0,0 +1,409 @@
|
||||
<template>
|
||||
<div class="component-upload-image">
|
||||
<el-upload
|
||||
ref="imageUploadRef"
|
||||
multiple
|
||||
:action="uploadImgUrl"
|
||||
list-type="picture-card"
|
||||
:on-success="handleUploadSuccess"
|
||||
:before-upload="handleBeforeUpload"
|
||||
:limit="limit"
|
||||
:accept="fileAccept"
|
||||
:on-error="handleUploadError"
|
||||
:on-exceed="handleExceed"
|
||||
:before-remove="handleDelete"
|
||||
:show-file-list="true"
|
||||
:headers="headers"
|
||||
:file-list="fileList"
|
||||
:on-preview="handlePictureCardPreview"
|
||||
:class="{ hide: fileList.length >= limit }"
|
||||
:http-request="customUpload"
|
||||
>
|
||||
<el-icon class="avatar-uploader-icon">
|
||||
<plus />
|
||||
</el-icon>
|
||||
</el-upload>
|
||||
<!-- 上传提示 -->
|
||||
<div v-if="showTip" class="el-upload__tip">
|
||||
请上传
|
||||
<template v-if="fileSize">
|
||||
大小不超过 <b style="color: #f56c6c">{{ fileSize }}MB</b>
|
||||
</template>
|
||||
<template v-if="fileType">
|
||||
格式为 <b style="color: #f56c6c">{{ fileType.join('/') }}</b>
|
||||
</template>
|
||||
的文件
|
||||
</div>
|
||||
|
||||
<el-dialog v-model="dialogVisible" title="预览" width="800px" append-to-body>
|
||||
<img :src="dialogImageUrl" style="display: block; max-width: 100%; margin: 0 auto" />
|
||||
</el-dialog>
|
||||
|
||||
<!-- Bucket密码输入对话框 -->
|
||||
<el-dialog v-model="passwordDialogVisible" title="Bucket访问密码" width="400px" append-to-body>
|
||||
<el-form :model="passwordForm" label-width="100px">
|
||||
<el-form-item label="Bucket密码" required>
|
||||
<el-input
|
||||
v-model="passwordForm.bucketPassword"
|
||||
type="password"
|
||||
placeholder="请输入bucket访问密码"
|
||||
show-password
|
||||
@keyup.enter="confirmPassword"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
<el-button @click="passwordDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="confirmPassword">确认</el-button>
|
||||
</span>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch, getCurrentInstance } from 'vue';
|
||||
import { compressAccurately } from 'image-conversion';
|
||||
import request from '@/utils/request';
|
||||
|
||||
// 定义props类型
|
||||
interface Props {
|
||||
modelValue?: string | any[] | any;
|
||||
limit?: number;
|
||||
fileSize?: number;
|
||||
fileType?: string[];
|
||||
isShowTip?: boolean;
|
||||
compressSupport?: boolean;
|
||||
compressTargetSize?: number;
|
||||
bucketPassword?: string;
|
||||
enablePasswordValidation?: boolean;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
modelValue: () => [],
|
||||
limit: 15,
|
||||
fileSize: 10,
|
||||
fileType: () => ['png', 'jpg', 'jpeg'],
|
||||
isShowTip: true,
|
||||
compressSupport: false,
|
||||
compressTargetSize: 300,
|
||||
bucketPassword: '',
|
||||
enablePasswordValidation: false
|
||||
});
|
||||
|
||||
const { proxy } = getCurrentInstance() as any;
|
||||
const emit = defineEmits(['update:modelValue']);
|
||||
const number = ref(0);
|
||||
const uploadList = ref<any[]>([]);
|
||||
const dialogImageUrl = ref('');
|
||||
const dialogVisible = ref(false);
|
||||
|
||||
// 密码相关
|
||||
const passwordDialogVisible = ref(false);
|
||||
const passwordForm = ref({
|
||||
bucketPassword: ''
|
||||
});
|
||||
const pendingUploadFile = ref<any>(null);
|
||||
|
||||
// 上传的图片服务器地址(用于el-upload组件的action属性)
|
||||
const uploadImgUrl = ref(import.meta.env.VITE_APP_BASE_API + '/resource/oss/upload');
|
||||
|
||||
// 设置正确的headers(用于el-upload组件)
|
||||
const headers = ref({
|
||||
'Authorization': 'Bearer ' + (localStorage.getItem('token') || ''),
|
||||
'clientid': import.meta.env.VITE_APP_CLIENT_ID || 'e5cd7e4891bf95d1d19206ce24a7b32e',
|
||||
'Content-Language': localStorage.getItem('language') || 'zh-CN',
|
||||
'referer': window.location.origin + '/login?redirect=' + encodeURIComponent(window.location.pathname)
|
||||
});
|
||||
|
||||
const fileList = ref<any[]>([]);
|
||||
const showTip = computed(() => props.isShowTip && (props.fileType || props.fileSize));
|
||||
|
||||
const imageUploadRef = ref();
|
||||
|
||||
// 监听 fileType 变化,更新 fileAccept
|
||||
const fileAccept = computed(() => props.fileType.map((type) => `.${type}`).join(','));
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
async (val: any) => {
|
||||
if (val) {
|
||||
// 首先将值转为数组
|
||||
let list: any[] = [];
|
||||
if (Array.isArray(val)) {
|
||||
list = val;
|
||||
} else if (typeof val === 'string') {
|
||||
// 检查是否包含逗号分隔的URL
|
||||
if (val.includes(',')) {
|
||||
// 多个URL用逗号分隔
|
||||
const urls = val.split(',').filter((url) => url.trim());
|
||||
list = urls.map((url, index) => ({
|
||||
ossId: url,
|
||||
url: url.trim(),
|
||||
originalName: `image_${index + 1}`
|
||||
}));
|
||||
} else if (val.startsWith('http://') || val.startsWith('https://')) {
|
||||
// 单个URL
|
||||
list = [{ ossId: val, url: val, originalName: 'image' }];
|
||||
} else {
|
||||
// 如果是OSS ID,暂时跳过接口调用
|
||||
list = [{ ossId: val, url: val, originalName: 'image' }];
|
||||
}
|
||||
}
|
||||
// 然后将数组转为对象数组
|
||||
fileList.value = list.map((item, index) => {
|
||||
// 字符串回显处理 如果此处存的是url可直接回显 如果存的是id需要调用接口查出来
|
||||
let itemData;
|
||||
if (typeof item === 'string') {
|
||||
itemData = { name: item, url: item };
|
||||
} else {
|
||||
// 此处name使用url 防止删除出现重名,对于URL格式使用url_index的格式
|
||||
const name = item.url && (item.url.startsWith('http://') || item.url.startsWith('https://')) ? `${item.url}_${index}` : item.ossId;
|
||||
itemData = { name: name, url: item.url, ossId: item.ossId };
|
||||
}
|
||||
return itemData;
|
||||
});
|
||||
} else {
|
||||
fileList.value = [];
|
||||
return [];
|
||||
}
|
||||
},
|
||||
{ deep: true, immediate: true }
|
||||
);
|
||||
|
||||
/** 上传前loading加载 */
|
||||
const handleBeforeUpload = (file: any) => {
|
||||
let isImg = false;
|
||||
if (props.fileType.length) {
|
||||
let fileExtension = '';
|
||||
if (file.name.lastIndexOf('.') > -1) {
|
||||
fileExtension = file.name.slice(file.name.lastIndexOf('.') + 1);
|
||||
}
|
||||
isImg = props.fileType.some((type: any) => {
|
||||
if (file.type.indexOf(type) > -1) return true;
|
||||
if (fileExtension && fileExtension.indexOf(type) > -1) return true;
|
||||
return false;
|
||||
});
|
||||
} else {
|
||||
isImg = file.type.indexOf('image') > -1;
|
||||
}
|
||||
if (!isImg) {
|
||||
proxy?.$modal.msgError(`文件格式不正确, 请上传${props.fileType.join('/')}图片格式文件!`);
|
||||
return false;
|
||||
}
|
||||
if (file.name.includes(',')) {
|
||||
proxy?.$modal.msgError('文件名不正确,不能包含英文逗号!');
|
||||
return false;
|
||||
}
|
||||
if (props.fileSize) {
|
||||
const isLt = file.size / 1024 / 1024 < props.fileSize;
|
||||
if (!isLt) {
|
||||
proxy?.$modal.msgError(`上传头像图片大小不能超过 ${props.fileSize} MB!`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//压缩图片,开启压缩并且大于指定的压缩大小时才压缩
|
||||
if (props.compressSupport && file.size / 1024 > props.compressTargetSize) {
|
||||
proxy?.$modal.loading('正在上传图片,请稍候...');
|
||||
number.value++;
|
||||
return compressAccurately(file, props.compressTargetSize);
|
||||
} else {
|
||||
proxy?.$modal.loading('正在上传图片,请稍候...');
|
||||
number.value++;
|
||||
}
|
||||
};
|
||||
|
||||
// 文件个数超出
|
||||
const handleExceed = () => {
|
||||
proxy?.$modal.msgError(`上传文件数量不能超过 ${props.limit} 个!`);
|
||||
};
|
||||
|
||||
// 自定义上传方法
|
||||
const customUpload = async (options: any) => {
|
||||
try {
|
||||
// 检查是否需要bucket密码验证
|
||||
if (props.enablePasswordValidation && !props.bucketPassword) {
|
||||
// 显示密码输入对话框
|
||||
pendingUploadFile.value = options;
|
||||
passwordDialogVisible.value = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加小延迟,避免并发请求冲突
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
// 直接上传
|
||||
await performUpload(options);
|
||||
} catch (error) {
|
||||
console.error('上传失败6:', error);
|
||||
proxy?.$modal.msgError('上传失败7');
|
||||
proxy?.$modal.closeLoading();
|
||||
}
|
||||
};
|
||||
|
||||
// 确认密码
|
||||
const confirmPassword = async () => {
|
||||
if (!passwordForm.value.bucketPassword) {
|
||||
proxy?.$modal.msgError('请输入bucket访问密码');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 密码验证成功,执行上传
|
||||
if (pendingUploadFile.value) {
|
||||
await performUpload(pendingUploadFile.value);
|
||||
}
|
||||
|
||||
// 关闭对话框
|
||||
passwordDialogVisible.value = false;
|
||||
passwordForm.value.bucketPassword = '';
|
||||
pendingUploadFile.value = null;
|
||||
} catch (error) {
|
||||
console.error('密码验证失败:', error);
|
||||
proxy?.$modal.msgError('密码验证失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 执行上传
|
||||
const performUpload = async (options: any) => {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', options.file);
|
||||
|
||||
// 添加bucket密码到FormData中
|
||||
if (props.bucketPassword || passwordForm.value.bucketPassword) {
|
||||
formData.append('bucket-password', props.bucketPassword || passwordForm.value.bucketPassword || '');
|
||||
}
|
||||
|
||||
// 使用request方式调用接口,禁用防重复提交检查
|
||||
const result = await request.post('/resource/oss/upload', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
'repeatSubmit': false // 禁用防重复提交检查
|
||||
}
|
||||
});
|
||||
|
||||
if (result.code === 200) {
|
||||
// 上传成功
|
||||
const uploadResult = {
|
||||
name: result.data.fileName,
|
||||
url: result.data.url,
|
||||
ossId: result.data.ossId
|
||||
};
|
||||
|
||||
uploadList.value.push(uploadResult);
|
||||
uploadedSuccessfully();
|
||||
} else {
|
||||
throw new Error(result.msg || '上传失败1');
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('上传失败2:', error);
|
||||
// 处理防重复提交错误
|
||||
if (error.message && error.message.includes('数据正在处理,请勿重复提交')) {
|
||||
proxy?.$modal.msgError('上传过于频繁,请稍后再试');
|
||||
} else {
|
||||
proxy?.$modal.msgError(error.message || '上传失败3');
|
||||
}
|
||||
proxy?.$modal.closeLoading();
|
||||
}
|
||||
};
|
||||
|
||||
// 上传成功回调
|
||||
const handleUploadSuccess = (res: any, file: any) => {
|
||||
|
||||
|
||||
// 确保res存在且有正确的结构
|
||||
if (res && res.code === 200) {
|
||||
// 避免重复添加,检查是否已经存在
|
||||
const existingIndex = uploadList.value.findIndex((item) => item.name === res.data.fileName || item.ossId === res.data.ossId);
|
||||
|
||||
if (existingIndex === -1) {
|
||||
uploadList.value.push({ name: res.data.fileName, url: res.data.url, ossId: res.data.ossId });
|
||||
uploadedSuccessfully();
|
||||
}
|
||||
} else {
|
||||
number.value--;
|
||||
proxy?.$modal.closeLoading();
|
||||
proxy?.$modal.msgError(res?.msg || '上传失败4');
|
||||
if (file && imageUploadRef.value) {
|
||||
imageUploadRef.value?.handleRemove(file);
|
||||
}
|
||||
uploadedSuccessfully();
|
||||
}
|
||||
};
|
||||
|
||||
// 删除图片
|
||||
const handleDelete = (file: any): boolean => {
|
||||
const findex = fileList.value.map((f) => f.name).indexOf(file.name);
|
||||
if (findex > -1 && uploadList.value.length === number.value) {
|
||||
const ossId = fileList.value[findex].ossId;
|
||||
// 这里可以调用删除接口
|
||||
fileList.value.splice(findex, 1);
|
||||
emit('update:modelValue', listToString(fileList.value));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
// 上传结束处理
|
||||
const uploadedSuccessfully = () => {
|
||||
if (number.value > 0 && uploadList.value.length === number.value) {
|
||||
fileList.value = fileList.value.filter((f) => f.ossId !== undefined).concat(uploadList.value);
|
||||
uploadList.value = [];
|
||||
number.value = 0;
|
||||
emit('update:modelValue', listToString(fileList.value));
|
||||
proxy?.$modal.closeLoading();
|
||||
}
|
||||
};
|
||||
|
||||
// 上传失败5
|
||||
const handleUploadError = () => {
|
||||
proxy?.$modal.msgError('上传图片失败');
|
||||
proxy?.$modal.closeLoading();
|
||||
};
|
||||
|
||||
// 预览 - 使用安全预览
|
||||
const handlePictureCardPreview = async (file: any) => {
|
||||
try {
|
||||
if (file.ossId) {
|
||||
// 使用安全预览,这里简化处理
|
||||
dialogImageUrl.value = file.url;
|
||||
} else {
|
||||
// 直接使用URL预览
|
||||
dialogImageUrl.value = file.url;
|
||||
}
|
||||
dialogVisible.value = true;
|
||||
} catch (error) {
|
||||
console.error('预览失败:', error);
|
||||
proxy?.$modal.msgError('预览失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 对象转成指定字符串分隔
|
||||
const listToString = (list: any[], separator?: string) => {
|
||||
let strs = '';
|
||||
separator = separator || ',';
|
||||
for (const i in list) {
|
||||
if (undefined !== list[i].ossId && list[i].ossId.indexOf('blob:') !== 0) {
|
||||
// 返回ossId
|
||||
strs += list[i].ossId + separator;
|
||||
}
|
||||
}
|
||||
return strs != '' ? strs.substring(0, strs.length - 1) : '';
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
// .el-upload--picture-card 控制加号部分
|
||||
:deep(.hide .el-upload--picture-card) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
}
|
||||
</style>
|
||||
@@ -41,6 +41,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch, nextTick, getCurrentInstance, type ComponentInternalInstance } from 'vue';
|
||||
import { listByIds, delOss } from '@/api/system/oss';
|
||||
import { OssVO } from '@/api/system/oss/types';
|
||||
import { propTypes } from '@/utils/propTypes';
|
||||
@@ -79,14 +80,18 @@ const uploadList = ref<any[]>([]);
|
||||
const dialogImageUrl = ref('');
|
||||
const dialogVisible = ref(false);
|
||||
|
||||
const baseUrl = import.meta.env.VITE_APP_BASE_API;
|
||||
// 使用环境变量,添加类型断言
|
||||
const baseUrl = (import.meta as any).env?.VITE_APP_BASE_API || '';
|
||||
const uploadImgUrl = ref(baseUrl + '/resource/oss/upload'); // 上传的图片服务器地址
|
||||
const headers = ref(globalHeaders());
|
||||
|
||||
const fileList = ref<any[]>([]);
|
||||
const showTip = computed(() => props.isShowTip && (props.fileType || props.fileSize));
|
||||
|
||||
const imageUploadRef = ref<ElUploadInstance>();
|
||||
const imageUploadRef = ref<any>();
|
||||
|
||||
// 添加标志位,避免上传成功后重复处理
|
||||
const isInternalUpdate = ref(false);
|
||||
|
||||
// 监听 fileType 变化,更新 fileAccept
|
||||
const fileAccept = computed(() => props.fileType.map((type) => `.${type}`).join(','));
|
||||
@@ -94,6 +99,11 @@ const fileAccept = computed(() => props.fileType.map((type) => `.${type}`).join(
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
async (val: string) => {
|
||||
// 如果是内部更新触发的,跳过处理
|
||||
if (isInternalUpdate.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (val) {
|
||||
// 首先将值转为数组
|
||||
let list: OssVO[] = [];
|
||||
@@ -101,20 +111,22 @@ watch(
|
||||
list = val as OssVO[];
|
||||
} else if (typeof val === 'string') {
|
||||
console.log('val', val);
|
||||
// 检查是否包含逗号分隔的URL
|
||||
// 检查是否包含逗号分隔的OSS ID
|
||||
if (val.includes(',')) {
|
||||
// 多个URL用逗号分隔
|
||||
const urls = val.split(',').filter((url) => url.trim());
|
||||
list = urls.map((url, index) => ({
|
||||
ossId: url,
|
||||
url: url.trim(),
|
||||
originalName: `image_${index + 1}`
|
||||
})) as any;
|
||||
// 多个OSS ID用逗号分隔,需要调用接口获取详细信息
|
||||
const ossIds = val.split(',').filter((id) => id.trim());
|
||||
try {
|
||||
const res = await listByIds(ossIds.join(','));
|
||||
list = res.data;
|
||||
} catch (error) {
|
||||
console.error('调用listByIds接口失败:', error);
|
||||
list = [];
|
||||
}
|
||||
} else if (val.startsWith('http://') || val.startsWith('https://')) {
|
||||
// 单个URL
|
||||
list = [{ ossId: val, url: val, originalName: 'image' }] as any;
|
||||
} else {
|
||||
// 如果是OSS ID,调用接口获取详细信息
|
||||
// 单个OSS ID,调用接口获取详细信息
|
||||
try {
|
||||
const res = await listByIds(val);
|
||||
list = res.data;
|
||||
@@ -163,59 +175,66 @@ const handleBeforeUpload = (file: any) => {
|
||||
isImg = file.type.indexOf('image') > -1;
|
||||
}
|
||||
if (!isImg) {
|
||||
proxy?.$modal.msgError(`文件格式不正确, 请上传${props.fileType.join('/')}图片格式文件!`);
|
||||
(proxy as any)?.$modal.msgError(`文件格式不正确, 请上传${props.fileType.join('/')}图片格式文件!`);
|
||||
return false;
|
||||
}
|
||||
if (file.name.includes(',')) {
|
||||
proxy?.$modal.msgError('文件名不正确,不能包含英文逗号!');
|
||||
(proxy as any)?.$modal.msgError('文件名不正确,不能包含英文逗号!');
|
||||
return false;
|
||||
}
|
||||
if (props.fileSize) {
|
||||
const isLt = file.size / 1024 / 1024 < props.fileSize;
|
||||
if (!isLt) {
|
||||
proxy?.$modal.msgError(`上传头像图片大小不能超过 ${props.fileSize} MB!`);
|
||||
(proxy as any)?.$modal.msgError(`上传头像图片大小不能超过 ${props.fileSize} MB!`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//压缩图片,开启压缩并且大于指定的压缩大小时才压缩
|
||||
if (props.compressSupport && file.size / 1024 > props.compressTargetSize) {
|
||||
proxy?.$modal.loading('正在上传图片,请稍候...');
|
||||
(proxy as any)?.$modal.loading('正在上传图片,请稍候...');
|
||||
number.value++;
|
||||
return compressAccurately(file, props.compressTargetSize);
|
||||
} else {
|
||||
proxy?.$modal.loading('正在上传图片,请稍候...');
|
||||
(proxy as any)?.$modal.loading('正在上传图片,请稍候...');
|
||||
number.value++;
|
||||
}
|
||||
};
|
||||
|
||||
// 文件个数超出
|
||||
const handleExceed = () => {
|
||||
proxy?.$modal.msgError(`上传文件数量不能超过 ${props.limit} 个!`);
|
||||
(proxy as any)?.$modal.msgError(`上传文件数量不能超过 ${props.limit} 个!`);
|
||||
};
|
||||
|
||||
// 上传成功回调
|
||||
const handleUploadSuccess = (res: any, file: UploadFile) => {
|
||||
const handleUploadSuccess = (res: any, file: any) => {
|
||||
console.log('handleUploadSuccess:res', res);
|
||||
if (res.code === 200) {
|
||||
uploadList.value.push({ name: res.data.fileName, url: res.data.url, ossId: res.data.ossId });
|
||||
uploadedSuccessfully();
|
||||
} else {
|
||||
number.value--;
|
||||
proxy?.$modal.closeLoading();
|
||||
proxy?.$modal.msgError(res.msg);
|
||||
(proxy as any)?.$modal.closeLoading();
|
||||
(proxy as any)?.$modal.msgError(res.msg);
|
||||
imageUploadRef.value?.handleRemove(file);
|
||||
uploadedSuccessfully();
|
||||
}
|
||||
};
|
||||
|
||||
// 删除图片
|
||||
const handleDelete = (file: UploadFile): boolean => {
|
||||
const handleDelete = (file: any): boolean => {
|
||||
const findex = fileList.value.map((f) => f.name).indexOf(file.name);
|
||||
if (findex > -1 && uploadList.value.length === number.value) {
|
||||
const ossId = fileList.value[findex].ossId;
|
||||
delOss(ossId);
|
||||
fileList.value.splice(findex, 1);
|
||||
// 设置内部更新标志
|
||||
isInternalUpdate.value = true;
|
||||
emit('update:modelValue', listToString(fileList.value));
|
||||
// 重置标志
|
||||
nextTick(() => {
|
||||
isInternalUpdate.value = false;
|
||||
});
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -227,15 +246,21 @@ const uploadedSuccessfully = () => {
|
||||
fileList.value = fileList.value.filter((f) => f.url !== undefined).concat(uploadList.value);
|
||||
uploadList.value = [];
|
||||
number.value = 0;
|
||||
// 设置内部更新标志
|
||||
isInternalUpdate.value = true;
|
||||
emit('update:modelValue', listToString(fileList.value));
|
||||
proxy?.$modal.closeLoading();
|
||||
// 重置标志
|
||||
nextTick(() => {
|
||||
isInternalUpdate.value = false;
|
||||
});
|
||||
(proxy as any)?.$modal.closeLoading();
|
||||
}
|
||||
};
|
||||
|
||||
// 上传失败
|
||||
const handleUploadError = () => {
|
||||
proxy?.$modal.msgError('上传图片失败');
|
||||
proxy?.$modal.closeLoading();
|
||||
(proxy as any)?.$modal.msgError('上传图片失败');
|
||||
(proxy as any)?.$modal.closeLoading();
|
||||
};
|
||||
|
||||
// 预览
|
||||
|
||||
@@ -418,6 +418,8 @@ import { listHallInfo } from '@/api/hq/hallInfo';
|
||||
import { HallReservationVO, HallReservationQuery, HallReservationForm } from '@/api/hq/hallReservation/types';
|
||||
import { HallInfoVO } from '@/api/hq/hallInfo/types';
|
||||
import { useUserStore } from '@/store/modules/user';
|
||||
import { listByIds } from '@/api/system/oss';
|
||||
import { OssVO } from '@/api/system/oss/types';
|
||||
|
||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||
const { hall_reserv_status } = toRefs<any>(proxy?.useDict('hall_reserv_status'));
|
||||
@@ -426,6 +428,7 @@ const userStore = useUserStore();
|
||||
const hallReservationList = ref<HallReservationVO[]>([]);
|
||||
const hallList = ref<HallInfoVO[]>([]);
|
||||
const viewHallImages = ref<string[]>([]);
|
||||
const hallImagesCache = ref<Map<string, string[]>>(new Map()); // 缓存报告厅图片URL
|
||||
const loading = ref(true);
|
||||
const showSearch = ref(true);
|
||||
const ids = ref<Array<string | number>>([]);
|
||||
@@ -510,49 +513,75 @@ const getHallList = async () => {
|
||||
|
||||
// 调试信息:检查每个报告厅的图片信息
|
||||
console.log('报告厅列表数据:', hallList.value);
|
||||
hallList.value.forEach((hall, index) => {
|
||||
console.log(`报告厅 ${index + 1} - ${hall.hallName}:`, {
|
||||
id: hall.id,
|
||||
hallImage: hall.hallImage,
|
||||
images: getHallImages(hall.hallImage || '')
|
||||
});
|
||||
});
|
||||
|
||||
// 异步加载所有报告厅的图片URL
|
||||
await loadAllHallImages();
|
||||
} catch (error) {
|
||||
console.error('获取报告厅列表失败:', error);
|
||||
hallList.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
/** 处理报告厅图片 - 可能有多张图片,用逗号分隔 */
|
||||
const getHallImages = (imageUrl: string): string[] => {
|
||||
if (!imageUrl || imageUrl.trim() === '') return [];
|
||||
// 支持多种分隔符:逗号、分号、空格
|
||||
const separators = /[,;|\\s]+/;
|
||||
const images = imageUrl
|
||||
.split(separators)
|
||||
.map((url) => url.trim())
|
||||
.filter((url) => url && url !== 'null' && url !== 'undefined');
|
||||
/** 加载所有报告厅的图片URL */
|
||||
const loadAllHallImages = async () => {
|
||||
const imagePromises = hallList.value.map(async (hall) => {
|
||||
if (hall.hallImage) {
|
||||
try {
|
||||
const images = await getHallImages(hall.hallImage);
|
||||
hallImagesCache.value.set(hall.hallName, images);
|
||||
console.log(`报告厅 ${hall.hallName} 图片加载完成:`, images);
|
||||
} catch (error) {
|
||||
console.error(`报告厅 ${hall.hallName} 图片加载失败:`, error);
|
||||
hallImagesCache.value.set(hall.hallName, []);
|
||||
}
|
||||
} else {
|
||||
hallImagesCache.value.set(hall.hallName, []);
|
||||
}
|
||||
});
|
||||
|
||||
console.log('处理图片URL:', imageUrl, '结果:', images);
|
||||
return images;
|
||||
await Promise.all(imagePromises);
|
||||
console.log('所有报告厅图片加载完成');
|
||||
};
|
||||
|
||||
/** 处理报告厅图片 - 通过OSS ID获取真实URL */
|
||||
const getHallImages = async (ossIds: string): Promise<string[]> => {
|
||||
if (!ossIds || ossIds.trim() === '') return [];
|
||||
|
||||
try {
|
||||
// 支持多种分隔符:逗号、分号、空格
|
||||
const separators = /[,;|\\s]+/;
|
||||
const idArray = ossIds
|
||||
.split(separators)
|
||||
.map((id) => id.trim())
|
||||
.filter((id) => id && id !== 'null' && id !== 'undefined');
|
||||
|
||||
if (idArray.length === 0) return [];
|
||||
|
||||
console.log('处理OSS ID:', ossIds, 'ID数组:', idArray);
|
||||
|
||||
// 调用API获取真实的图片URL
|
||||
const response = await listByIds(idArray.join(','));
|
||||
const ossList: OssVO[] = response.data || [];
|
||||
|
||||
// 提取URL列表
|
||||
const urls = ossList.map((oss) => oss.url).filter((url) => url);
|
||||
|
||||
console.log('获取到的图片URL:', urls);
|
||||
return urls;
|
||||
} catch (error) {
|
||||
console.error('获取图片URL失败:', error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
/** 获取记录对应的报告厅图片 */
|
||||
const getRecordHallImages = (record: HallReservationVO): string[] => {
|
||||
const selectedHall = hallList.value.find((hall) => hall.hallName === record.hallName);
|
||||
if (selectedHall && selectedHall.hallImage) {
|
||||
return getHallImages(selectedHall.hallImage);
|
||||
}
|
||||
return [];
|
||||
return hallImagesCache.value.get(record.hallName) || [];
|
||||
};
|
||||
|
||||
/** 根据报告厅名称获取图片 */
|
||||
const getHallImagesByName = (hallName: string): string[] => {
|
||||
const selectedHall = hallList.value.find((hall) => hall.hallName === hallName);
|
||||
if (selectedHall && selectedHall.hallImage) {
|
||||
return getHallImages(selectedHall.hallImage);
|
||||
}
|
||||
return [];
|
||||
return hallImagesCache.value.get(hallName) || [];
|
||||
};
|
||||
|
||||
/** 获取选中记录中的唯一报告厅名称 */
|
||||
@@ -698,12 +727,7 @@ const handleView = async (row: HallReservationVO) => {
|
||||
|
||||
// 查找对应的报告厅并显示图片
|
||||
if (viewForm.value.hallName) {
|
||||
const selectedHall = hallList.value.find((hall) => hall.hallName === viewForm.value.hallName);
|
||||
if (selectedHall && selectedHall.hallImage) {
|
||||
viewHallImages.value = getHallImages(selectedHall.hallImage);
|
||||
} else {
|
||||
viewHallImages.value = [];
|
||||
}
|
||||
viewHallImages.value = hallImagesCache.value.get(viewForm.value.hallName) || [];
|
||||
} else {
|
||||
viewHallImages.value = [];
|
||||
}
|
||||
|
||||
@@ -210,9 +210,9 @@
|
||||
{{ displayHallDescription(hall.hallDescription) }}
|
||||
</div>
|
||||
<div class="hall-images">
|
||||
<template v-if="getHallImages(hall.hallImage || '').length > 0">
|
||||
<template v-if="hall.imageUrls && hall.imageUrls.length > 0">
|
||||
<img
|
||||
v-for="(image, index) in getHallImages(hall.hallImage || '')"
|
||||
v-for="(image, index) in hall.imageUrls"
|
||||
:key="index"
|
||||
:src="image"
|
||||
class="hall-image"
|
||||
@@ -338,7 +338,7 @@
|
||||
<el-avatar :size="32" :src="auditor.avatar">{{ auditor.nickName?.substring(0, 1) }}</el-avatar>
|
||||
<div class="auditor-info">
|
||||
<div class="auditor-name">{{ auditor.nickName || auditor.userName }}</div>
|
||||
<div class="auditor-dept">{{ auditor.dept?.deptName }}</div>
|
||||
<div class="auditor-dept">{{ auditor?.phonenumber }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="auditorList.length === 0" class="no-auditor">暂无可审核人员</div>
|
||||
@@ -526,13 +526,28 @@ const getHallList = async () => {
|
||||
}); // 获取正常状态的报告厅
|
||||
hallList.value = res.rows || [];
|
||||
|
||||
// 为每个报告厅获取图片URL
|
||||
for (const hall of hallList.value) {
|
||||
if (hall.hallImage) {
|
||||
try {
|
||||
const imageUrls = await getHallImages(hall.hallImage);
|
||||
hall.imageUrls = imageUrls;
|
||||
} catch (error) {
|
||||
console.error(`获取报告厅 ${hall.hallName} 图片失败:`, error);
|
||||
hall.imageUrls = [];
|
||||
}
|
||||
} else {
|
||||
hall.imageUrls = [];
|
||||
}
|
||||
}
|
||||
|
||||
// 调试信息:检查每个报告厅的图片信息
|
||||
console.log('报告厅列表数据:', hallList.value);
|
||||
hallList.value.forEach((hall, index) => {
|
||||
console.log(`报告厅 ${index + 1} - ${hall.hallName}:`, {
|
||||
id: hall.id,
|
||||
hallImage: hall.hallImage,
|
||||
images: getHallImages(hall.hallImage || '')
|
||||
imageUrls: hall.imageUrls
|
||||
});
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -547,24 +562,62 @@ const handleHallChange = (hallName: string) => {
|
||||
if (selectedHall) {
|
||||
form.value.hallId = selectedHall.id;
|
||||
// 更新选中的报告厅图片
|
||||
selectedHallImages.value = getHallImages(selectedHall.hallImage || '');
|
||||
selectedHallImages.value = selectedHall.imageUrls || [];
|
||||
} else {
|
||||
selectedHallImages.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
/** 处理报告厅图片 - 可能有多张图片,用逗号分隔 */
|
||||
const getHallImages = (imageUrl: string): string[] => {
|
||||
/** 处理报告厅图片 - 支持OSS ID和直接URL格式 */
|
||||
const getHallImages = async (imageUrl: string): Promise<string[]> => {
|
||||
if (!imageUrl || imageUrl.trim() === '') return [];
|
||||
|
||||
// 支持多种分隔符:逗号、分号、空格
|
||||
const separators = /[,;|\s]+/;
|
||||
const images = imageUrl
|
||||
const items = imageUrl
|
||||
.split(separators)
|
||||
.map((url) => url.trim())
|
||||
.filter((url) => url && url !== 'null' && url !== 'undefined');
|
||||
.map((item) => item.trim())
|
||||
.filter((item) => item && item !== 'null' && item !== 'undefined');
|
||||
|
||||
console.log('处理图片URL:', imageUrl, '结果:', images);
|
||||
return images;
|
||||
console.log('处理图片信息:', imageUrl, '结果:', items);
|
||||
|
||||
if (items.length === 0) return [];
|
||||
|
||||
// 判断是否为数字(OSS ID)还是URL
|
||||
const isOssId = items.every((item) => /^\d+$/.test(item));
|
||||
|
||||
if (isOssId) {
|
||||
// 如果是OSS ID,需要调用接口获取URL
|
||||
console.log('检测到OSS ID格式,需要调用接口获取URL');
|
||||
try {
|
||||
// 动态导入OSS模块
|
||||
const { listByIds } = await import('@/api/system/oss');
|
||||
|
||||
// 批量获取OSS信息
|
||||
const ossIdsParam = items.join(',');
|
||||
const res = await listByIds(ossIdsParam);
|
||||
const ossList = res.data || [];
|
||||
|
||||
// 获取图片URL列表
|
||||
const imageUrls: string[] = [];
|
||||
|
||||
for (const ossInfo of ossList) {
|
||||
if (ossInfo.url) {
|
||||
imageUrls.push(ossInfo.url);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('获取到的图片URL:', imageUrls);
|
||||
return imageUrls;
|
||||
} catch (error) {
|
||||
console.error('获取OSS信息失败:', error);
|
||||
return [];
|
||||
}
|
||||
} else {
|
||||
// 如果是URL格式,直接返回
|
||||
console.log('检测到URL格式,直接使用');
|
||||
return items;
|
||||
}
|
||||
};
|
||||
|
||||
/** 处理图片加载成功 */
|
||||
@@ -743,8 +796,8 @@ const handleView = async (row: HallReservationVO) => {
|
||||
// 查找对应的报告厅并显示图片
|
||||
if (viewForm.value.hallName) {
|
||||
const selectedHall = hallList.value.find((hall) => hall.hallName === viewForm.value.hallName);
|
||||
if (selectedHall && selectedHall.hallImage) {
|
||||
viewHallImages.value = getHallImages(selectedHall.hallImage);
|
||||
if (selectedHall && selectedHall.imageUrls) {
|
||||
viewHallImages.value = selectedHall.imageUrls;
|
||||
} else {
|
||||
viewHallImages.value = [];
|
||||
}
|
||||
@@ -787,8 +840,8 @@ const handleUpdate = async (row?: HallReservationVO) => {
|
||||
// 如果有报告厅名称,找到对应的报告厅并显示图片
|
||||
if (form.value.hallName) {
|
||||
const selectedHall = hallList.value.find((hall) => hall.hallName === form.value.hallName);
|
||||
if (selectedHall && selectedHall.hallImage) {
|
||||
selectedHallImages.value = getHallImages(selectedHall.hallImage);
|
||||
if (selectedHall && selectedHall.imageUrls) {
|
||||
selectedHallImages.value = selectedHall.imageUrls;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user