实现阻止图片、视频自动上传

This commit is contained in:
Qi 2025-08-09 15:38:40 +08:00
parent 75da20582a
commit 955c9b8262
8 changed files with 1198 additions and 9 deletions

View File

@ -0,0 +1,95 @@
import { defHttp } from '/@/utils/http/axios';
import { useMessage } from '/@/hooks/web/useMessage';
const { createConfirm } = useMessage();
enum Api {
list = '/oroqen/heritageInheritor/list',
save = '/oroqen/heritageInheritor/add',
edit = '/oroqen/heritageInheritor/edit',
deleteOne = '/oroqen/heritageInheritor/delete',
deleteBatch = '/oroqen/heritageInheritor/deleteBatch',
importExcel = '/oroqen/heritageInheritor/importExcel',
exportXls = '/oroqen/heritageInheritor/exportXls',
}
/**
* api
*/
export const getExportUrl = Api.exportXls;
/**
* api
*/
export const getImportUrl = Api.importExcel;
/**
*
*/
export const list = (params) => defHttp.get({ url: Api.list, params });
/**
*
*/
export const deleteOne = (params, handleSuccess) => {
return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
handleSuccess();
});
};
/**
*
*/
export const batchDelete = (params, handleSuccess) => {
createConfirm({
iconType: 'warning',
title: '确认删除',
content: '是否删除选中数据',
okText: '确认',
cancelText: '取消',
onOk: () => {
return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
handleSuccess();
});
}
});
};
/**
*
*/
export const saveOrUpdate = (params, isUpdate) => {
let url = isUpdate ? Api.edit : Api.save;
return defHttp.post({ url: url, params });
};
/**
*
*/
export const getInheritorOptions = () => {
return defHttp.get({
url: Api.list,
params: {
pageNo: 1,
pageSize: 1000,
status: 1 // 只获取启用状态的传承人
}
}).then(res => {
console.log('传承人API响应:', res);
// 修正数据结构判断,直接使用 res.records
if (res && res.records && Array.isArray(res.records)) {
const options = res.records.map(item => ({
label: item.name,
value: item.id,
key: item.id
}));
console.log('传承人选项数据:', options);
return options;
}
console.log('传承人数据为空或格式错误');
return [];
}).catch(error => {
console.error('获取传承人数据失败:', error);
return [];
});
};

View File

@ -163,10 +163,12 @@
// //
function onAddActionsButton(event) { function onAddActionsButton(event) {
const getUploadItem = () => { const getUploadItem = () => {
for (const path of event.path) { //
if (path.classList.contains(antUploadItemCls)) { const path = event.path || (event.composedPath && event.composedPath()) || [];
return path; for (const element of path) {
} else if (path.classList.contains(`${prefixCls}-container`)) { if (element.classList && element.classList.contains(antUploadItemCls)) {
return element;
} else if (element.classList && element.classList.contains(`${prefixCls}-container`)) {
return null; return null;
} }
} }
@ -206,7 +208,8 @@
const result = split(paths); const result = split(paths);
// update-end--author:liaozhiyang---date:20250325---forissues/7990 // update-end--author:liaozhiyang---date:20250325---forissues/7990
for (const item of result) { for (const item of result) {
let url = getFileAccessHttpUrl(item); // blob URL使getFileAccessHttpUrl
let url = item.startsWith('blob:') ? item : getFileAccessHttpUrl(item);
list.push({ list.push({
uid: uidGenerator(), uid: uidGenerator(),
name: getFileName(item), name: getFileName(item),
@ -226,7 +229,8 @@
} }
let list: any[] = []; let list: any[] = [];
for (const item of array) { for (const item of array) {
let url = getFileAccessHttpUrl(item.filePath); // blob URL使getFileAccessHttpUrl
let url = item.filePath.startsWith('blob:') ? item.filePath : getFileAccessHttpUrl(item.filePath);
list.push({ list.push({
uid: uidGenerator(), uid: uidGenerator(),
name: item.fileName, name: item.fileName,
@ -273,6 +277,7 @@
// uploadchange // uploadchange
function onFileChange(info) { function onFileChange(info) {
console.log('onFileChange 被调用:', info.file.status, info.file.url);
if (!info.file.status && uploadGoOn.value === false) { if (!info.file.status && uploadGoOn.value === false) {
info.fileList.pop(); info.fileList.pop();
} }
@ -295,7 +300,19 @@
successFileList = fileListTemp.map((file) => { successFileList = fileListTemp.map((file) => {
if (file.response) { if (file.response) {
let reUrl = file.response.message; let reUrl = file.response.message;
console.log('处理文件URL:', file.url, '是否为blob:', file.url?.startsWith('blob:'));
// URLblob URLURL
if (!file.url || !file.url.startsWith('blob:')) {
file.url = getFileAccessHttpUrl(reUrl); file.url = getFileAccessHttpUrl(reUrl);
console.log('设置新URL:', file.url);
} else {
console.log('保持blob URL:', file.url);
}
// response.message使blob URLAnt Design Upload使src
if (file.url && file.url.startsWith('blob:')) {
file.response.message = file.url;
console.log('同步response.message为blob URL:', file.response.message);
}
} }
return file; return file;
}); });
@ -361,10 +378,23 @@
// //
function onFilePreview(file) { function onFilePreview(file) {
console.log('预览文件URL:', file.url);
// 使URL
let previewUrl = file.url;
// URLblob URLresponsemessage使blob URL
if (!previewUrl.startsWith('blob:') && file.response && file.response.message) {
// URL
const fileInList = fileList.value.find(f => f.uid === file.uid);
if (fileInList && fileInList.url && fileInList.url.startsWith('blob:')) {
previewUrl = fileInList.url;
console.log('使用本地预览URL:', previewUrl);
}
}
if (isImageMode.value) { if (isImageMode.value) {
createImgPreview({ imageList: [file.url], maskClosable: true }); createImgPreview({ imageList: [previewUrl], maskClosable: true });
} else { } else {
window.open(file.url); window.open(previewUrl);
} }
} }

View File

@ -23,6 +23,10 @@ export const getFileAccessHttpUrl = (fileUrl, prefix = 'http') => {
let result = fileUrl; let result = fileUrl;
try { try {
if (fileUrl && fileUrl.length > 0 && !fileUrl.startsWith(prefix)) { if (fileUrl && fileUrl.length > 0 && !fileUrl.startsWith(prefix)) {
// 检查是否是blob URL如果是则直接返回
if (fileUrl.startsWith('blob:')) {
return fileUrl;
}
//判断是否是数组格式 //判断是否是数组格式
let isArray = fileUrl.indexOf('[') != -1; let isArray = fileUrl.indexOf('[') != -1;
if (!isArray) { if (!isArray) {

View File

@ -0,0 +1,75 @@
import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";
const { createConfirm } = useMessage();
enum Api {
list = '/oroqen/heritageProject/list',
save='/oroqen/heritageProject/add',
edit='/oroqen/heritageProject/edit',
deleteOne = '/oroqen/heritageProject/delete',
deleteBatch = '/oroqen/heritageProject/deleteBatch',
importExcel = '/oroqen/heritageProject/importExcel',
exportXls = '/oroqen/heritageProject/exportXls',
recommend = '/oroqen/heritageProject/recommend',
}
/**
* api
* @param params
*/
export const getExportUrl = Api.exportXls;
/**
* api
*/
export const getImportUrl = Api.importExcel;
/**
*
* @param params
*/
export const list = (params) =>
defHttp.get({url: Api.list, params});
/**
*
*/
export const deleteOne = (params,handleSuccess) => {
return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
handleSuccess();
});
}
/**
*
* @param params
*/
export const batchDelete = (params, handleSuccess) => {
createConfirm({
iconType: 'warning',
title: '确认删除',
content: '是否删除选中数据',
okText: '确认',
cancelText: '取消',
onOk: () => {
return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
handleSuccess();
});
}
});
}
/**
*
* @param params
*/
export const saveOrUpdate = (params, isUpdate) => {
let url = isUpdate ? Api.edit : Api.save;
return defHttp.post({url: url, params});
}
/**
* /
* @param params
*/
export const toggleRecommend = (params, handleSuccess) => {
return defHttp.put({url: Api.recommend, params}, { joinParamsToUrl: true }).then(() => {
handleSuccess();
});
}

View File

@ -0,0 +1,599 @@
import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { h } from 'vue';
import { Image } from 'ant-design-vue';
import { getInheritorOptions } from '/@/api/oroqen/OroqenHeritageInheritor';
import { getFileAccessHttpUrl } from '/@/utils/common/compUtils';
//列表数据
export const columns: BasicColumn[] = [
{
title: '项目名称',
align:"left",
dataIndex: 'projectName',
ellipsis: true,
fixed: 'left',
},
{
title: '封面图片',
align:"center",
dataIndex: 'coverImage',
customRender: ({ text, record }) => {
if (!text) return '-';
// 使用 getFileAccessHttpUrl 函数来正确处理图片URL
const imageUrl = getFileAccessHttpUrl(text);
return h(Image, {
src: imageUrl,
alt: record?.projectName || '封面图片',
width: 60,
height: 60,
style: { objectFit: 'cover', borderRadius: '4px' },
preview: true,
fallback: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMIAAADDCAYAAADQvc6UAAABRWlDQ1BJQ0MgUHJvZmlsZQAAKJFjYGASSSwoyGFhYGDIzSspCnJ3UoiIjFJgf8LAwSDCIMogwMCcmFxc4BgQ4ANUwgCjUcG3awyMIPqyLsis7PPOq3QdDFcvjV3jOD1boQVTPQrgSkktTgbSf4A4LbmgqISBgTEFyFYuLykAsTuAbJEioKOA7DkgdjqEvQHEToKwj4DVhAQ5A9k3gGyB5IxEoBmML4BsnSQk8XQkNtReEOBxcfXxUQg1Mjc0dyHgXNJBSWpFCYh2zi+oLMpMzyhRcASGUqqCZ16yno6CkYGRAQMDKMwhqj/fAIcloxgHQqxAjIHBEugw5sUIsSQpBobtQPdLciLEVJYzMPBHMDBsayhILEqEO4DxG0txmrERhM29nYGBddr//5/DGRjYNRkY/l7////39v///y4Dmn+LgeHANwDrkl1AuO+pmgAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAwqADAAQAAAABAAAAwwAAAAD9b/HnAAAHlklEQVR4Ae3dP3Ik1RnG4W+FgYxN'
});
}
},
{
title: '项目编码',
align:"center",
dataIndex: 'projectCode',
},
{
title: '项目类别',
align:"center",
dataIndex: 'category',
customRender: ({ text }) => {
const categoryMap = {
'TRADITIONAL_CRAFT': '传统技艺',
'FOLK_CUSTOM': '民俗',
'TRADITIONAL_MUSIC': '传统音乐',
'TRADITIONAL_DANCE': '传统舞蹈',
'TRADITIONAL_DRAMA': '传统戏剧',
'QUYI': '曲艺',
'TRADITIONAL_SPORTS': '传统体育',
'TRADITIONAL_ART': '传统美术',
'TRADITIONAL_MEDICINE': '传统医药',
'LITERATURE': '文学'
};
return categoryMap[text] || text;
}
},
{
title: '非遗级别',
align:"center",
dataIndex: 'heritageLevel',
customRender: ({ text }) => {
const levelMap = {
'NATIONAL': '国家级',
'PROVINCIAL': '省级',
'MUNICIPAL': '市级',
'COUNTY': '县级'
};
const level = levelMap[text] || text;
const colorMap = {
'国家级': '#cf1322',
'省级': '#fa541c',
'市级': '#fa8c16',
'县级': '#52c41a'
};
return h('span', {
style: {
color: colorMap[level] || '#666',
fontWeight: '500'
}
}, level);
}
},
{
title: '批准年份',
align:"center",
dataIndex: 'approvalYear',
},
{
title: '保护单位',
align:"center",
dataIndex: 'protectionUnit',
ellipsis: true,
},
{
title: '浏览次数',
align:"center",
dataIndex: 'viewCount',
},
{
title: '状态',
align:"center",
dataIndex: 'status',
customRender: ({ text }) => {
return text === 1 ?
h('span', { style: { color: '#52c41a', fontWeight: '500' } }, '启用') :
h('span', { style: { color: '#ff4d4f', fontWeight: '500' } }, '禁用');
}
},
{
title: '推荐状态',
align:"center",
dataIndex: 'isRecommended',
customRender: ({ text }) => {
return text === 1 ?
h('span', { style: { color: '#1890ff', fontWeight: '500' } }, '已推荐') :
h('span', { style: { color: '#999', fontWeight: '500' } }, '未推荐');
}
},
];
//查询数据
export const searchFormSchema: FormSchema[] = [
{
label: '项目名称',
field: 'projectName',
component: 'Input',
componentProps: {
placeholder: '请输入项目名称',
},
colProps: { span: 6 },
},
{
label: '项目编码',
field: 'projectCode',
component: 'Input',
componentProps: {
placeholder: '请输入项目编码',
},
colProps: { span: 6 },
},
{
label: '项目类别',
field: 'category',
component: 'Select',
componentProps: {
placeholder: '请选择项目类别',
options: [
{ label: '传统技艺', value: 'TRADITIONAL_CRAFT' },
{ label: '民俗', value: 'FOLK_CUSTOM' },
{ label: '传统音乐', value: 'TRADITIONAL_MUSIC' },
{ label: '传统舞蹈', value: 'TRADITIONAL_DANCE' },
{ label: '传统戏剧', value: 'TRADITIONAL_DRAMA' },
{ label: '曲艺', value: 'QUYI' },
{ label: '传统体育', value: 'TRADITIONAL_SPORTS' },
{ label: '传统美术', value: 'TRADITIONAL_ART' },
{ label: '传统医药', value: 'TRADITIONAL_MEDICINE' },
{ label: '文学', value: 'LITERATURE' },
]
},
colProps: { span: 6 },
},
{
label: '非遗级别',
field: 'heritageLevel',
component: 'Select',
componentProps: {
placeholder: '请选择非遗级别',
options: [
{ label: '国家级', value: 'NATIONAL' },
{ label: '省级', value: 'PROVINCIAL' },
{ label: '市级', value: 'MUNICIPAL' },
{ label: '县级', value: 'COUNTY' },
]
},
colProps: { span: 6 },
},
{
label: '保护单位',
field: 'protectionUnit',
component: 'Input',
componentProps: {
placeholder: '请输入保护单位',
},
colProps: { span: 6 },
},
{
label: '状态',
field: 'status',
component: 'Select',
componentProps: {
placeholder: '请选择状态',
options: [
{ label: '启用', value: 1 },
{ label: '禁用', value: 0 },
]
},
colProps: { span: 6 },
},
];
//表单数据
export const formSchema: FormSchema[] = [
{
label: '项目名称',
field: 'projectName',
component: 'Input',
componentProps: {
placeholder: '请输入项目名称',
},
dynamicRules: ({model,schema}) => {
return [
{ required: true, message: '请输入项目名称!'},
];
},
},
{
label: '项目编码',
field: 'projectCode',
component: 'Input',
componentProps: {
placeholder: '请输入项目编码',
},
dynamicRules: ({model,schema}) => {
return [
{ required: true, message: '请输入项目编码!'},
];
},
},
{
label: '项目类别',
field: 'category',
component: 'Select',
componentProps: {
placeholder: '请选择项目类别',
options: [
{ label: '传统技艺', value: 'TRADITIONAL_CRAFT' },
{ label: '民俗', value: 'FOLK_CUSTOM' },
{ label: '传统音乐', value: 'TRADITIONAL_MUSIC' },
{ label: '传统舞蹈', value: 'TRADITIONAL_DANCE' },
{ label: '传统戏剧', value: 'TRADITIONAL_DRAMA' },
{ label: '曲艺', value: 'QUYI' },
{ label: '传统体育', value: 'TRADITIONAL_SPORTS' },
{ label: '传统美术', value: 'TRADITIONAL_ART' },
{ label: '传统医药', value: 'TRADITIONAL_MEDICINE' },
{ label: '文学', value: 'LITERATURE' },
]
},
dynamicRules: ({model,schema}) => {
return [
{ required: true, message: '请选择项目类别!'},
];
},
},
{
label: '非遗级别',
field: 'heritageLevel',
component: 'Select',
componentProps: {
placeholder: '请选择非遗级别',
options: [
{ label: '国家级', value: 'NATIONAL' },
{ label: '省级', value: 'PROVINCIAL' },
{ label: '市级', value: 'MUNICIPAL' },
{ label: '县级', value: 'COUNTY' },
]
},
dynamicRules: ({model,schema}) => {
return [
{ required: true, message: '请选择非遗级别!'},
];
},
},
{
label: '批准年份',
field: 'approvalYear',
component: 'InputNumber',
componentProps: {
placeholder: '请输入批准年份',
min: 1900,
max: new Date().getFullYear(),
},
},
{
label: '批准文号',
field: 'approvalNumber',
component: 'Input',
componentProps: {
placeholder: '请输入批准文号',
},
},
{
label: '项目描述',
field: 'description',
component: 'InputTextArea',
componentProps: {
placeholder: '请输入项目描述',
rows: 3,
maxlength: 500,
showCount: true,
},
dynamicRules: ({model,schema}) => {
return [
{ required: true, message: '请输入项目描述!'},
];
},
},
{
label: '详细描述',
field: 'fullDescription',
component: 'InputTextArea',
componentProps: {
placeholder: '请输入详细描述',
rows: 4,
maxlength: 2000,
showCount: true,
},
},
{
label: '历史渊源',
field: 'history',
component: 'InputTextArea',
componentProps: {
placeholder: '请输入历史渊源',
rows: 4,
maxlength: 2000,
showCount: true,
},
},
{
label: '技艺特点',
field: 'features',
component: 'InputTextArea',
componentProps: {
placeholder: '请输入技艺特点',
rows: 4,
maxlength: 2000,
showCount: true,
},
},
{
label: '传承价值',
field: 'value',
component: 'InputTextArea',
componentProps: {
placeholder: '请输入传承价值',
rows: 4,
maxlength: 2000,
showCount: true,
},
},
{
label: '封面图片',
field: 'coverImage',
component: 'JUpload',
componentProps: {
fileType: 'image',
maxCount: 1,
maxSize: 5,
bizPath: 'heritage-project/cover',
customRequest: (options) => {
// 验证文件类型和大小
const { file } = options;
const isImage = file.type.startsWith('image/');
if (!isImage) {
console.error('只能上传图片文件!');
return;
}
const isLt5M = file.size / 1024 / 1024 < 5;
if (!isLt5M) {
console.error('图片大小不能超过5MB!');
return;
}
// 创建本地预览URL
const localUrl = URL.createObjectURL(file);
// 直接设置文件的url为本地预览URL
file.url = localUrl;
// 模拟上传成功响应但不返回local:前缀,避免被解析
setTimeout(() => {
options.onSuccess({
success: true,
message: file.name, // 仅使用文件名不使用local:前缀
}, file);
}, 100);
},
},
colProps: { lg: 12, md: 12 },
},
{
label: '图片集',
field: 'images',
component: 'JUpload',
componentProps: {
fileType: 'image',
maxCount: 10,
maxSize: 5,
bizPath: 'heritage-project/images',
customRequest: (options) => {
// 验证文件类型和大小
const { file } = options;
const isImage = file.type.startsWith('image/');
if (!isImage) {
console.error('只能上传图片文件!');
return;
}
const isLt5M = file.size / 1024 / 1024 < 5;
if (!isLt5M) {
console.error('图片大小不能超过5MB!');
return;
}
// 创建本地预览URL
const localUrl = URL.createObjectURL(file);
// 直接设置文件的url为本地预览URL
file.url = localUrl;
// 模拟上传成功响应但不返回local:前缀,避免被解析
setTimeout(() => {
options.onSuccess({
success: true,
message: file.name, // 仅使用文件名不使用local:前缀
}, file);
}, 100);
},
},
colProps: { lg: 12, md: 12 },
},
{
label: '视频链接',
field: 'videoUrl',
component: 'JUpload',
componentProps: {
fileType: 'video',
maxCount: 1,
maxSize: 50,
bizPath: 'heritage-project/video',
customRequest: (options) => {
// 验证文件类型和大小
const { file } = options;
const isVideo = file.type.startsWith('video/');
if (!isVideo) {
console.error('只能上传视频文件!');
return;
}
const isLt50M = file.size / 1024 / 1024 < 50;
if (!isLt50M) {
console.error('视频大小不能超过50MB!');
return;
}
// 创建本地预览URL
const localUrl = URL.createObjectURL(file);
// 直接设置文件的url为本地预览URL
file.url = localUrl;
// 模拟上传成功响应但不返回local:前缀,避免被解析
setTimeout(() => {
options.onSuccess({
success: true,
message: file.name, // 仅使用文件名不使用local:前缀
}, file);
}, 100);
},
},
colProps: { lg: 24, md: 24 },
},
// {
// label: '音频链接',
// field: 'audioUrl',
// component: 'JUpload',
// componentProps: {
// fileType: 'audio',
// maxCount: 1,
// maxSize: 20,
// bizPath: 'heritage-project/audio',
// },
// },
{
label: '标签',
field: 'tags',
component: 'Input',
componentProps: {
placeholder: '请输入标签,多个标签用逗号分隔',
},
},
{
label: '关联传承人',
field: 'inheritorIds',
component: 'ApiSelect',
componentProps: {
placeholder: '请选择关联传承人',
mode: 'multiple',
allowClear: true,
showSearch: true,
api: getInheritorOptions,
immediate: true,
resultField: '',
labelField: 'label',
valueField: 'value',
},
},
{
label: '保护单位',
field: 'protectionUnit',
component: 'Input',
componentProps: {
placeholder: '请输入保护单位',
},
},
{
label: '保护措施',
field: 'protectionMeasures',
component: 'InputTextArea',
componentProps: {
placeholder: '请输入保护措施',
rows: 3,
maxlength: 1000,
showCount: true,
},
},
{
label: '保护现状',
field: 'currentStatus',
component: 'InputTextArea',
componentProps: {
placeholder: '请输入保护现状',
rows: 3,
maxlength: 1000,
showCount: true,
},
},
{
label: '状态',
field: 'status',
component: 'RadioGroup',
componentProps: {
options: [
{ label: '禁用', value: 0 },
{ label: '启用', value: 1 },
]
},
defaultValue: 1,
ifShow: ({ values }) => {
// 新增时隐藏状态字段,编辑时显示
return !!values.id;
},
},
// TODO 主键隐藏字段目前写死为ID
{
label: '',
field: 'id',
component: 'Input',
show: false
},
];
// 高级查询数据
export const superQuerySchema = {
projectName: {title: '项目名称',order: 0,view: 'text', type: 'string',},
projectCode: {title: '项目编码',order: 1,view: 'text', type: 'string',},
category: {title: '项目类别',order: 2,view: 'text', type: 'string',},
heritageLevel: {title: '非遗级别',order: 3,view: 'text', type: 'string',},
approvalYear: {title: '批准年份',order: 4,view: 'number', type: 'number',},
approvalNumber: {title: '批准文号',order: 5,view: 'text', type: 'string',},
description: {title: '项目描述',order: 6,view: 'text', type: 'string',},
fullDescription: {title: '详细描述',order: 7,view: 'textarea', type: 'string',},
history: {title: '历史渊源',order: 8,view: 'textarea', type: 'string',},
features: {title: '技艺特点',order: 9,view: 'textarea', type: 'string',},
value: {title: '传承价值',order: 10,view: 'textarea', type: 'string',},
coverImage: {title: '封面图片',order: 11,view: 'text', type: 'string',},
images: {title: '图片集',order: 12,view: 'textarea', type: 'string',},
videoUrl: {title: '视频链接',order: 13,view: 'text', type: 'string',},
audioUrl: {title: '音频链接',order: 14,view: 'text', type: 'string',},
tags: {title: '标签',order: 15,view: 'text', type: 'string',},
inheritorIds: {title: '关联传承人ID',order: 16,view: 'textarea', type: 'string',},
protectionUnit: {title: '保护单位',order: 17,view: 'text', type: 'string',},
protectionMeasures: {title: '保护措施',order: 18,view: 'text', type: 'string',},
currentStatus: {title: '保护现状',order: 19,view: 'text', type: 'string',},
isRecommended: {title: '是否推荐',order: 20,view: 'number', type: 'number',},
viewCount: {title: '浏览次数',order: 21,view: 'number', type: 'number',},
likeCount: {title: '点赞次数',order: 22,view: 'number', type: 'number',},
status: {title: '状态',order: 23,view: 'number', type: 'number',},
};
/**
* formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
// 默认和原始表单保持一致 如果流程中配置了权限数据这里需要单独处理formSchema
return formSchema;
}

View File

@ -0,0 +1,219 @@
<template>
<div>
<!--引用表格-->
<BasicTable @register="registerTable" :rowSelection="rowSelection">
<!--插槽:table标题-->
<template #tableTitle>
<a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button>
<a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls">
导出</a-button
>
<j-upload-button
type="primary"
preIcon="ant-design:import-outlined"
@click="onImportXls"
>导入</j-upload-button
>
<a-dropdown v-if="selectedRowKeys.length > 0">
<template #overlay>
<a-menu>
<a-menu-item key="1" @click="batchHandleDelete">
<Icon icon="ant-design:delete-outlined" />
删除
</a-menu-item>
</a-menu>
</template>
<a-button>批量操作
<Icon icon="mdi:chevron-down" />
</a-button>
</a-dropdown>
<!-- 高级查询 -->
<super-query :config="superQueryConfig" @search="handleSuperQuery" />
</template>
<!--操作栏-->
<template #action="{ record }">
<TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" />
</template>
<!--字段回显插槽-->
<template #bodyCell="{ column, record, index, text }">
<!-- 这里可以添加自定义渲染逻辑 -->
</template>
</BasicTable>
<!-- 表单区域 -->
<OroqenHeritageProjectModal @register="registerModal" @success="handleSuccess" />
</div>
</template>
<script lang="ts" name="oroqen-oroqenHeritageProject" setup>
import { ref, reactive } from 'vue';
import { BasicTable, TableAction } from '/@/components/Table';
import { useModal } from '/@/components/Modal';
import { useListPage } from '/@/hooks/system/useListPage';
import OroqenHeritageProjectModal from './components/OroqenHeritageProjectModal.vue';
import { columns, searchFormSchema, superQuerySchema } from './OroqenHeritageProject.data';
import { list, deleteOne, batchDelete, getImportUrl, getExportUrl, toggleRecommend } from './OroqenHeritageProject.api';
import { useMessage } from '/@/hooks/web/useMessage';
import { getDateByPicker } from '/@/utils';
//
const fieldPickers = reactive({});
const queryParam = reactive<any>({});
const { createMessage } = useMessage();
//model
const [registerModal, { openModal }] = useModal();
//table
const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
tableProps: {
title: 'oroqen_heritage_project',
api: list,
columns,
canResize: true,
formConfig: {
//labelWidth: 120,
schemas: searchFormSchema,
autoSubmitOnEnter: true,
showAdvancedButton: true,
fieldMapToNumber: [],
fieldMapToTime: [],
},
actionColumn: {
width: 120,
fixed: 'right',
},
beforeFetch: (params) => {
if (params && fieldPickers) {
for (let key in fieldPickers) {
if (params[key]) {
params[key] = getDateByPicker(params[key], fieldPickers[key]);
}
}
}
return Object.assign(params, queryParam);
},
},
exportConfig: {
name: 'oroqen_heritage_project',
url: getExportUrl,
params: queryParam,
},
importConfig: {
url: getImportUrl,
success: handleSuccess,
},
});
const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
//
const superQueryConfig = reactive(superQuerySchema);
/**
* 高级查询事件
*/
function handleSuperQuery(params) {
Object.keys(params).map((k) => {
queryParam[k] = params[k];
});
reload();
}
/**
* 新增事件
*/
function handleAdd() {
openModal(true, {
isUpdate: false,
showFooter: true,
});
}
/**
* 编辑事件
*/
function handleEdit(record: Recordable) {
openModal(true, {
record,
isUpdate: true,
showFooter: true,
});
}
/**
* 详情
*/
function handleDetail(record: Recordable) {
openModal(true, {
record,
isUpdate: true,
showFooter: false,
});
}
/**
* 删除事件
*/
async function handleDelete(record) {
await deleteOne({ id: record.id }, handleSuccess);
}
/**
* 推荐/取消推荐事件
*/
async function handleRecommend(record) {
const action = record.isRecommended === 1 ? '取消推荐' : '推荐';
createMessage.loading(`正在${action}...`, 1);
await toggleRecommend({
id: record.id,
isRecommended: record.isRecommended === 1 ? 0 : 1
}, handleSuccess);
createMessage.success(`${action}成功!`);
}
/**
* 批量删除事件
*/
async function batchHandleDelete() {
await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
}
/**
* 成功回调
*/
function handleSuccess() {
(selectedRowKeys.value = []) && reload();
}
/**
* 操作栏
*/
function getTableAction(record) {
return [
{
label: '编辑',
onClick: handleEdit.bind(null, record),
},
];
}
/**
* 下拉操作栏
*/
function getDropDownAction(record) {
return [
{
label: '详情',
onClick: handleDetail.bind(null, record),
},
{
label: record.isRecommended === 1 ? '取消推荐' : '推荐',
onClick: handleRecommend.bind(null, record),
},
{
label: '删除',
popConfirm: {
title: '是否确认删除',
confirm: handleDelete.bind(null, record),
placement: 'topLeft',
},
},
];
}
</script>
<style lang="less" scoped>
:deep(.ant-picker),
:deep(.ant-input-number) {
width: 100%;
}
</style>

View File

@ -0,0 +1,70 @@
<template>
<div style="min-height: 400px">
<BasicForm @register="registerForm" />
<div style="width: 100%; text-align: center" v-if="!formDisabled">
<a-button @click="submitForm" pre-icon="ant-design:check" type="primary"> </a-button>
</div>
</div>
</template>
<script lang="ts">
import { BasicForm, useForm } from '/@/components/Form/index';
import { computed, defineComponent } from 'vue';
import { defHttp } from '/@/utils/http/axios';
import { propTypes } from '/@/utils/propTypes';
import { getBpmFormSchema } from '../OroqenHeritageProject.data';
import { saveOrUpdate } from '../OroqenHeritageProject.api';
export default defineComponent({
name: 'OroqenHeritageProjectForm',
components: {
BasicForm,
},
props: {
formData: propTypes.object.def({}),
formBpm: propTypes.bool.def(true),
},
setup(props) {
const [registerForm, { setFieldsValue, setProps, getFieldsValue }] = useForm({
labelWidth: 150,
schemas: getBpmFormSchema(props.formData),
showActionButtonGroup: false,
baseColProps: { span: 24 },
});
const formDisabled = computed(() => {
if (props.formData.disabled === false) {
return false;
}
return true;
});
let formData = {};
const queryByIdUrl = '/oroqen/oroqenHeritageProject/queryById';
async function initFormData() {
let params = { id: props.formData.dataId };
const data = await defHttp.get({ url: queryByIdUrl, params });
formData = { ...data };
//
await setFieldsValue(formData);
//
await setProps({ disabled: formDisabled.value });
}
async function submitForm() {
let data = getFieldsValue();
let params = Object.assign({}, formData, data);
console.log('表单数据', params);
await saveOrUpdate(params, true);
}
initFormData();
return {
registerForm,
formDisabled,
submitForm,
};
},
});
</script>

View File

@ -0,0 +1,97 @@
<template>
<BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="800" @ok="handleSubmit">
<BasicForm @register="registerForm" name="OroqenHeritageProjectForm" />
</BasicModal>
</template>
<script lang="ts" setup>
import { ref, computed, unref, reactive } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicForm, useForm } from '/@/components/Form/index';
import { formSchema } from '../OroqenHeritageProject.data';
import { saveOrUpdate } from '../OroqenHeritageProject.api';
import { useMessage } from '/@/hooks/web/useMessage';
import { getDateByPicker } from '/@/utils';
const { createMessage } = useMessage();
// Emits
const emit = defineEmits(['register', 'success']);
const isUpdate = ref(true);
const isDetail = ref(false);
//
const [registerForm, { setProps, resetFields, setFieldsValue, validate, scrollToField }] = useForm({
labelWidth: 150,
schemas: formSchema,
showActionButtonGroup: false,
baseColProps: { span: 24 },
});
//
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
//
await resetFields();
setModalProps({ confirmLoading: false, showCancelBtn: !!data?.showFooter, showOkBtn: !!data?.showFooter });
isUpdate.value = !!data?.isUpdate;
isDetail.value = !!data?.showFooter;
if (unref(isUpdate)) {
//
await setFieldsValue({
...data.record,
});
}
//
setProps({ disabled: !data?.showFooter });
});
//
const fieldPickers = reactive({});
//
const title = computed(() => (!unref(isUpdate) ? '新增' : !unref(isDetail) ? '详情' : '编辑'));
//
async function handleSubmit(v) {
try {
let values = await validate();
//
changeDateValue(values);
setModalProps({ confirmLoading: true });
//
await saveOrUpdate(values, isUpdate.value);
//
closeModal();
//
emit('success');
} catch ({ errorFields }) {
if (errorFields) {
const firstField = errorFields[0];
if (firstField) {
scrollToField(firstField.name, { behavior: 'smooth', block: 'center' });
}
}
return Promise.reject(errorFields);
} finally {
setModalProps({ confirmLoading: false });
}
}
/**
* 处理日期值
* @param formData 表单数据
*/
const changeDateValue = (formData) => {
if (formData && fieldPickers) {
for (let key in fieldPickers) {
if (formData[key]) {
formData[key] = getDateByPicker(formData[key], fieldPickers[key]);
}
}
}
};
</script>
<style lang="less" scoped>
/** 时间和数字输入框样式 */
:deep(.ant-input-number) {
width: 100%;
}
:deep(.ant-calendar-picker) {
width: 100%;
}
</style>