Compare commits
4 Commits
75da20582a
...
1fe792a910
Author | SHA1 | Date | |
---|---|---|---|
1fe792a910 | |||
5d2a017e8f | |||
6ac0146455 | |||
955c9b8262 |
95
src/api/oroqen/OroqenHeritageInheritor.ts
Normal file
95
src/api/oroqen/OroqenHeritageInheritor.ts
Normal 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 [];
|
||||||
|
});
|
||||||
|
};
|
@ -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---for:【issues/7990】图片参数中包含逗号会错误的识别成多张图
|
// update-end--author:liaozhiyang---date:20250325---for:【issues/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 @@
|
|||||||
|
|
||||||
// upload组件change事件
|
// upload组件change事件
|
||||||
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;
|
||||||
file.url = getFileAccessHttpUrl(reUrl);
|
console.log('处理文件URL:', file.url, '是否为blob:', file.url?.startsWith('blob:'));
|
||||||
|
// 如果文件已经有URL且是blob URL(本地预览URL),则保持不变
|
||||||
|
if (!file.url || !file.url.startsWith('blob:')) {
|
||||||
|
file.url = getFileAccessHttpUrl(reUrl);
|
||||||
|
console.log('设置新URL:', file.url);
|
||||||
|
} else {
|
||||||
|
console.log('保持blob URL:', file.url);
|
||||||
|
}
|
||||||
|
// 关键修复:确保response.message也使用blob URL,避免Ant 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;
|
||||||
|
// 如果URL不是blob URL且response中有message,优先使用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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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) {
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
import { defHttp } from '/@/utils/http/axios';
|
||||||
|
import { useMessage } from '/@/hooks/web/useMessage';
|
||||||
|
|
||||||
|
const { createConfirm } = useMessage();
|
||||||
|
|
||||||
|
enum Api {
|
||||||
|
list = '/oroqen/cultureCategory/list',
|
||||||
|
save = '/oroqen/cultureCategory/add',
|
||||||
|
edit = '/oroqen/cultureCategory/edit',
|
||||||
|
deleteOne = '/oroqen/cultureCategory/delete',
|
||||||
|
deleteBatch = '/oroqen/cultureCategory/deleteBatch',
|
||||||
|
importExcel = '/oroqen/cultureCategory/importExcel',
|
||||||
|
exportXls = '/oroqen/cultureCategory/exportXls',
|
||||||
|
queryById = '/oroqen/cultureCategory/queryById',
|
||||||
|
tree = '/oroqen/cultureCategory/tree',
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出api
|
||||||
|
*/
|
||||||
|
export const getExportUrl = Api.exportXls;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入api
|
||||||
|
*/
|
||||||
|
export const getImportUrl = Api.importExcel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表接口
|
||||||
|
*/
|
||||||
|
export const list = (params) => defHttp.get({ url: Api.list, params });
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 树形列表接口
|
||||||
|
*/
|
||||||
|
export const queryTreeList = (params) => defHttp.get({ url: Api.tree, params });
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取分类树
|
||||||
|
*/
|
||||||
|
export const getCategoryTree = () => defHttp.get({ url: Api.tree });
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除单个
|
||||||
|
*/
|
||||||
|
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 });
|
||||||
|
};
|
151
src/views/oroqen/culture-category/OroqenCultureCategory.data.ts
Normal file
151
src/views/oroqen/culture-category/OroqenCultureCategory.data.ts
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
import { BasicColumn } from '/@/components/Table';
|
||||||
|
import { FormSchema } from '/@/components/Table';
|
||||||
|
import { rules } from '/@/utils/helper/validator';
|
||||||
|
import { render } from '/@/utils/common/renderUtils';
|
||||||
|
|
||||||
|
// 列表页面公共参数、方法
|
||||||
|
export const columns: BasicColumn[] = [
|
||||||
|
{
|
||||||
|
title: '分类名称',
|
||||||
|
align: 'left',
|
||||||
|
dataIndex: 'categoryName',
|
||||||
|
width: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '分类编码',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'categoryCode',
|
||||||
|
width: 150,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '排序',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'sortOrder',
|
||||||
|
width: 80,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'status',
|
||||||
|
width: 100,
|
||||||
|
customRender: ({ text }) => {
|
||||||
|
const statusMap = {
|
||||||
|
'1': { text: '启用', color: 'green' },
|
||||||
|
'0': { text: '禁用', color: 'red' }
|
||||||
|
};
|
||||||
|
const status = statusMap[text] || { text: '未知', color: 'gray' };
|
||||||
|
return render.renderTag(status.text, status.color);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '描述',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'description',
|
||||||
|
width: 200,
|
||||||
|
ellipsis: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建时间',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'createTime',
|
||||||
|
width: 150,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// 查询数据
|
||||||
|
export const searchFormSchema: FormSchema[] = [
|
||||||
|
{
|
||||||
|
label: '分类名称',
|
||||||
|
field: 'categoryName',
|
||||||
|
component: 'Input',
|
||||||
|
colProps: { span: 6 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '分类编码',
|
||||||
|
field: 'categoryCode',
|
||||||
|
component: 'Input',
|
||||||
|
colProps: { span: 6 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '状态',
|
||||||
|
field: 'status',
|
||||||
|
component: 'JDictSelectTag',
|
||||||
|
componentProps: {
|
||||||
|
dictCode: 'valid_status',
|
||||||
|
placeholder: '请选择状态',
|
||||||
|
},
|
||||||
|
colProps: { span: 6 },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// 表单数据
|
||||||
|
export const formSchema: FormSchema[] = [
|
||||||
|
{
|
||||||
|
label: '',
|
||||||
|
field: 'id',
|
||||||
|
component: 'Input',
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '上级分类',
|
||||||
|
field: 'parentId',
|
||||||
|
component: 'JTreeSelect',
|
||||||
|
componentProps: {
|
||||||
|
dict: 'oroqen_culture_category,category_name,id',
|
||||||
|
pidField: 'parent_id',
|
||||||
|
pidValue: '',
|
||||||
|
hasChildField: 'has_child',
|
||||||
|
placeholder: '请选择上级分类',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '分类名称',
|
||||||
|
field: 'categoryName',
|
||||||
|
component: 'Input',
|
||||||
|
required: true,
|
||||||
|
dynamicRules: ({ model, schema }) => {
|
||||||
|
return [{ required: true, message: '请输入分类名称!' }];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '分类编码',
|
||||||
|
field: 'categoryCode',
|
||||||
|
component: 'Input',
|
||||||
|
required: true,
|
||||||
|
dynamicRules: ({ model, schema }) => {
|
||||||
|
return [
|
||||||
|
{ required: true, message: '请输入分类编码!' },
|
||||||
|
{ pattern: /^[a-zA-Z0-9_]+$/, message: '编码只能包含字母、数字和下划线!' }
|
||||||
|
];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '排序',
|
||||||
|
field: 'sortOrder',
|
||||||
|
component: 'InputNumber',
|
||||||
|
defaultValue: 0,
|
||||||
|
componentProps: {
|
||||||
|
min: 0,
|
||||||
|
placeholder: '请输入排序值',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '状态',
|
||||||
|
field: 'status',
|
||||||
|
component: 'JDictSelectTag',
|
||||||
|
defaultValue: '1',
|
||||||
|
componentProps: {
|
||||||
|
dictCode: 'valid_status',
|
||||||
|
placeholder: '请选择状态',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '描述',
|
||||||
|
field: 'description',
|
||||||
|
component: 'InputTextArea',
|
||||||
|
componentProps: {
|
||||||
|
rows: 3,
|
||||||
|
placeholder: '请输入分类描述',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
156
src/views/oroqen/culture-category/OroqenCultureCategoryList.vue
Normal file
156
src/views/oroqen/culture-category/OroqenCultureCategoryList.vue
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
<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"></Icon>
|
||||||
|
删除
|
||||||
|
</a-menu-item>
|
||||||
|
</a-menu>
|
||||||
|
</template>
|
||||||
|
<a-button>批量操作
|
||||||
|
<Icon icon="mdi:chevron-down"></Icon>
|
||||||
|
</a-button>
|
||||||
|
</a-dropdown>
|
||||||
|
</template>
|
||||||
|
<!--操作栏-->
|
||||||
|
<template #action="{ record }">
|
||||||
|
<TableAction :actions="getTableAction(record)" />
|
||||||
|
</template>
|
||||||
|
<!--字段回显插槽-->
|
||||||
|
<template #htmlSlot="{text}">
|
||||||
|
<div v-html="text"></div>
|
||||||
|
</template>
|
||||||
|
<!--省市区字段回显插槽-->
|
||||||
|
<template #pcaSlot="{text}">
|
||||||
|
{{ getAreaTextByCode(text) }}
|
||||||
|
</template>
|
||||||
|
<template #fileSlot="{text}">
|
||||||
|
<span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
|
||||||
|
<a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small" @click="downloadFile(text)">下载</a-button>
|
||||||
|
</template>
|
||||||
|
</BasicTable>
|
||||||
|
<!-- 表单区域 -->
|
||||||
|
<OroqenCultureCategoryModal @register="registerModal" @success="handleSuccess"></OroqenCultureCategoryModal>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" name="oroqen-culture-category" setup>
|
||||||
|
import { ref, computed, unref } from 'vue';
|
||||||
|
import { BasicTable, useTable, TableAction } from '/@/components/Table';
|
||||||
|
import { useModal } from '/@/components/Modal';
|
||||||
|
import { useListPage } from '/@/hooks/system/useListPage';
|
||||||
|
import OroqenCultureCategoryModal from './components/OroqenCultureCategoryModal.vue';
|
||||||
|
import { columns, searchFormSchema } from './OroqenCultureCategory.data';
|
||||||
|
import { queryTreeList, deleteOne, batchDelete, getImportUrl, getExportUrl } from './OroqenCultureCategory.api';
|
||||||
|
import { downloadFile } from '/@/utils/common/renderUtils';
|
||||||
|
import { getAreaTextByCode } from '/@/components/Form/src/utils/Area';
|
||||||
|
|
||||||
|
const checkedKeys = ref<Array<string | number>>([]);
|
||||||
|
const [registerModal, { openModal }] = useModal();
|
||||||
|
const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
|
||||||
|
tableProps: {
|
||||||
|
title: '文化分类',
|
||||||
|
api: queryTreeList,
|
||||||
|
columns,
|
||||||
|
canResize: false,
|
||||||
|
isTreeTable: true,
|
||||||
|
pagination: false,
|
||||||
|
striped: false,
|
||||||
|
useSearchForm: true,
|
||||||
|
showTableSetting: true,
|
||||||
|
bordered: true,
|
||||||
|
showIndexColumn: false,
|
||||||
|
formConfig: {
|
||||||
|
labelWidth: 120,
|
||||||
|
schemas: searchFormSchema,
|
||||||
|
autoSubmitOnEnter: true,
|
||||||
|
},
|
||||||
|
actionColumn: {
|
||||||
|
width: 120,
|
||||||
|
fixed: 'right'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
exportApi: getExportUrl,
|
||||||
|
importApi: getImportUrl,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增事件
|
||||||
|
*/
|
||||||
|
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: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除事件
|
||||||
|
*/
|
||||||
|
async function handleDelete(record) {
|
||||||
|
await deleteOne({ id: record.id }, handleSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除事件
|
||||||
|
*/
|
||||||
|
async function batchHandleDelete() {
|
||||||
|
await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功回调
|
||||||
|
*/
|
||||||
|
function handleSuccess() {
|
||||||
|
(selectedRowKeys.value = []) && reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作栏
|
||||||
|
*/
|
||||||
|
function getTableAction(record) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
label: '编辑',
|
||||||
|
onClick: handleEdit.bind(null, record),
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
@ -0,0 +1,44 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<BasicForm @register="registerForm" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { BasicForm, useForm } from '/@/components/Form/index';
|
||||||
|
import { formSchema } from '../OroqenCultureCategory.data';
|
||||||
|
import { saveOrUpdate } from '../OroqenCultureCategory.api';
|
||||||
|
|
||||||
|
// Emits
|
||||||
|
const emit = defineEmits(['success', 'register']);
|
||||||
|
|
||||||
|
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
|
||||||
|
labelWidth: 100,
|
||||||
|
schemas: formSchema,
|
||||||
|
showActionButtonGroup: false,
|
||||||
|
actionColOptions: {
|
||||||
|
span: 23,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// 暴露内部方法
|
||||||
|
defineExpose({
|
||||||
|
setFieldsValue,
|
||||||
|
resetFields,
|
||||||
|
validate,
|
||||||
|
handleSubmit,
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交表单
|
||||||
|
*/
|
||||||
|
async function handleSubmit() {
|
||||||
|
try {
|
||||||
|
const values = await validate();
|
||||||
|
await saveOrUpdate(values, values.id);
|
||||||
|
emit('success');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('表单提交失败:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
@ -0,0 +1,84 @@
|
|||||||
|
<template>
|
||||||
|
<BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="getTitle" :width="800" @ok="handleSubmit">
|
||||||
|
<BasicForm @register="registerForm" name="OroqenCultureCategoryForm" />
|
||||||
|
</BasicModal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { ref, computed, unref } from 'vue';
|
||||||
|
import { BasicModal, useModalInner } from '/@/components/Modal';
|
||||||
|
import { BasicForm, useForm } from '/@/components/Form/index';
|
||||||
|
import { formSchema } from '../OroqenCultureCategory.data';
|
||||||
|
import { saveOrUpdate } from '../OroqenCultureCategory.api';
|
||||||
|
|
||||||
|
// Emits
|
||||||
|
const emit = defineEmits(['success', 'register']);
|
||||||
|
|
||||||
|
const isUpdate = ref(true);
|
||||||
|
const rowId = ref('');
|
||||||
|
|
||||||
|
// 表单配置
|
||||||
|
const [registerForm, { setProps, resetFields, setFieldsValue, validate }] = useForm({
|
||||||
|
labelWidth: 100,
|
||||||
|
baseColProps: { span: 24 },
|
||||||
|
schemas: formSchema,
|
||||||
|
showActionButtonGroup: false,
|
||||||
|
autoSubmitOnEnter: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// 表单赋值
|
||||||
|
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
||||||
|
// 重置表单
|
||||||
|
await resetFields();
|
||||||
|
setModalProps({ confirmLoading: false, showCancelBtn: !!data?.showFooter, showOkBtn: !!data?.showFooter });
|
||||||
|
isUpdate.value = !!data?.isUpdate;
|
||||||
|
|
||||||
|
if (unref(isUpdate)) {
|
||||||
|
rowId.value = data.record.id;
|
||||||
|
// 表单赋值
|
||||||
|
await setFieldsValue({
|
||||||
|
...data.record,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 隐藏底部时禁用整个表单
|
||||||
|
setProps({ disabled: !data?.showFooter });
|
||||||
|
});
|
||||||
|
|
||||||
|
// 表单标题
|
||||||
|
const getTitle = computed(() => (!unref(isUpdate) ? '新增' : '编辑'));
|
||||||
|
|
||||||
|
// 表单提交
|
||||||
|
async function handleSubmit() {
|
||||||
|
try {
|
||||||
|
const values = await validate();
|
||||||
|
setModalProps({ confirmLoading: true });
|
||||||
|
|
||||||
|
// 提交表单
|
||||||
|
await saveOrUpdate(values, unref(isUpdate));
|
||||||
|
// 关闭弹窗
|
||||||
|
closeModal();
|
||||||
|
// 刷新列表
|
||||||
|
emit('success');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('表单提交失败:', error);
|
||||||
|
if (error?.errorFields) {
|
||||||
|
console.log('验证错误字段:', error.errorFields);
|
||||||
|
// 滚动到第一个错误字段
|
||||||
|
const firstError = error.errorFields[0];
|
||||||
|
if (firstError?.name?.[0]) {
|
||||||
|
const fieldElement = document.querySelector(`[data-field="${firstError.name[0]}"]`);
|
||||||
|
if (fieldElement) {
|
||||||
|
fieldElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 显示具体的验证错误信息
|
||||||
|
const errorMessages = error.errorFields.map(field => field.errors.join(', ')).join('; ');
|
||||||
|
console.error('验证错误:', errorMessages);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setModalProps({ confirmLoading: false });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
75
src/views/oroqen/culture-content/OroqenCultureContent.api.ts
Normal file
75
src/views/oroqen/culture-content/OroqenCultureContent.api.ts
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
import { defHttp } from '/@/utils/http/axios';
|
||||||
|
import { useMessage } from '/@/hooks/web/useMessage';
|
||||||
|
|
||||||
|
const { createConfirm } = useMessage();
|
||||||
|
|
||||||
|
enum Api {
|
||||||
|
list = '/oroqen/cultureContent/list',
|
||||||
|
save = '/oroqen/cultureContent/add',
|
||||||
|
edit = '/oroqen/cultureContent/edit',
|
||||||
|
deleteOne = '/oroqen/cultureContent/delete',
|
||||||
|
deleteBatch = '/oroqen/cultureContent/deleteBatch',
|
||||||
|
importExcel = '/oroqen/cultureContent/importExcel',
|
||||||
|
exportXls = '/oroqen/cultureContent/exportXls',
|
||||||
|
queryById = '/oroqen/cultureContent/queryById',
|
||||||
|
recommend = '/oroqen/cultureContent/recommend',
|
||||||
|
cancelRecommend = '/oroqen/cultureContent/cancelRecommend',
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出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 toggleRecommend = (id: string, isRecommend: boolean) => {
|
||||||
|
const url = isRecommend ? Api.recommend : Api.cancelRecommend;
|
||||||
|
return defHttp.post({ url: `${url}/${id}` });
|
||||||
|
};
|
294
src/views/oroqen/culture-content/OroqenCultureContent.data.ts
Normal file
294
src/views/oroqen/culture-content/OroqenCultureContent.data.ts
Normal file
@ -0,0 +1,294 @@
|
|||||||
|
import { BasicColumn } from '/@/components/Table';
|
||||||
|
import { FormSchema } from '/@/components/Table';
|
||||||
|
import { rules } from '/@/utils/helper/validator';
|
||||||
|
import { render } from '/@/utils/common/renderUtils';
|
||||||
|
import { JVxeTypes, JVxeColumn } from '/@/components/jeecg/JVxeTable/types';
|
||||||
|
import { getFileAccessHttpUrl } from '/@/utils/common/compUtils';
|
||||||
|
|
||||||
|
// 列表页面公共参数、方法
|
||||||
|
export const columns: BasicColumn[] = [
|
||||||
|
{
|
||||||
|
title: '标题',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'title',
|
||||||
|
width: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '分类',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'categoryName',
|
||||||
|
width: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '封面图片',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'coverImage',
|
||||||
|
width: 120,
|
||||||
|
customRender: ({ text }) => {
|
||||||
|
if (!text) return '';
|
||||||
|
const imgUrl = getFileAccessHttpUrl(text);
|
||||||
|
return render.renderImage(imgUrl, {
|
||||||
|
style: { width: '60px', height: '40px', objectFit: 'cover' },
|
||||||
|
preview: true,
|
||||||
|
fallback: '/src/assets/images/no-image.png'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '作者',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'author',
|
||||||
|
width: 100,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '发布状态',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'status',
|
||||||
|
width: 100,
|
||||||
|
customRender: ({ text }) => {
|
||||||
|
const statusMap = {
|
||||||
|
'0': { text: '草稿', color: 'orange' },
|
||||||
|
'1': { text: '已发布', color: 'green' },
|
||||||
|
'2': { text: '已下线', color: 'red' }
|
||||||
|
};
|
||||||
|
const status = statusMap[text] || { text: '未知', color: 'gray' };
|
||||||
|
return render.renderTag(status.text, status.color);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '是否推荐',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'isRecommended',
|
||||||
|
width: 100,
|
||||||
|
customRender: ({ text }) => {
|
||||||
|
return render.renderSwitch(text, [
|
||||||
|
{ text: '是', value: '1' },
|
||||||
|
{ text: '否', value: '0' }
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '浏览量',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'viewCount',
|
||||||
|
width: 100,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '点赞数',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'likeCount',
|
||||||
|
width: 100,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建时间',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'createTime',
|
||||||
|
width: 150,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// 查询数据
|
||||||
|
export const searchFormSchema: FormSchema[] = [
|
||||||
|
{
|
||||||
|
label: '标题',
|
||||||
|
field: 'title',
|
||||||
|
component: 'Input',
|
||||||
|
colProps: { span: 6 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '分类',
|
||||||
|
field: 'categoryId',
|
||||||
|
component: 'JTreeSelect',
|
||||||
|
componentProps: {
|
||||||
|
dict: 'oroqen_culture_category,category_name,id',
|
||||||
|
pidField: 'parent_id',
|
||||||
|
pidValue: '0',
|
||||||
|
hasChildField: 'has_child',
|
||||||
|
placeholder: '请选择分类',
|
||||||
|
},
|
||||||
|
colProps: { span: 6 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '发布状态',
|
||||||
|
field: 'status',
|
||||||
|
component: 'JDictSelectTag',
|
||||||
|
componentProps: {
|
||||||
|
dictCode: 'content_status',
|
||||||
|
placeholder: '请选择状态',
|
||||||
|
},
|
||||||
|
colProps: { span: 6 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '是否推荐',
|
||||||
|
field: 'isRecommended',
|
||||||
|
component: 'JDictSelectTag',
|
||||||
|
componentProps: {
|
||||||
|
dictCode: 'yes_no',
|
||||||
|
placeholder: '请选择',
|
||||||
|
},
|
||||||
|
colProps: { span: 6 },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// 表单数据
|
||||||
|
export const formSchema: FormSchema[] = [
|
||||||
|
{
|
||||||
|
label: '',
|
||||||
|
field: 'id',
|
||||||
|
component: 'Input',
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '标题',
|
||||||
|
field: 'title',
|
||||||
|
component: 'Input',
|
||||||
|
required: true,
|
||||||
|
dynamicRules: ({ model, schema }) => {
|
||||||
|
return [{ required: true, message: '请输入标题!' }];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '分类',
|
||||||
|
field: 'categoryId',
|
||||||
|
component: 'JTreeSelect',
|
||||||
|
required: true,
|
||||||
|
componentProps: {
|
||||||
|
dict: 'oroqen_culture_category,category_name,id',
|
||||||
|
pidField: 'parent_id',
|
||||||
|
pidValue: '0',
|
||||||
|
hasChildField: 'has_child',
|
||||||
|
placeholder: '请选择分类',
|
||||||
|
},
|
||||||
|
dynamicRules: ({ model, schema }) => {
|
||||||
|
return [{ required: true, message: '请选择分类!' }];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '封面图片',
|
||||||
|
field: 'coverImage',
|
||||||
|
component: 'JUpload',
|
||||||
|
componentProps: {
|
||||||
|
fileType: 'image',
|
||||||
|
maxSize: 5,
|
||||||
|
maxCount: 1,
|
||||||
|
bizPath: 'culture/cover',
|
||||||
|
customRequest: (options) => {
|
||||||
|
const { file, onSuccess, onError } = options;
|
||||||
|
|
||||||
|
// 验证文件类型
|
||||||
|
const isImage = file.type.startsWith('image/');
|
||||||
|
if (!isImage) {
|
||||||
|
onError(new Error('只能上传图片文件!'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证文件大小
|
||||||
|
const isLt5M = file.size / 1024 / 1024 < 5;
|
||||||
|
if (!isLt5M) {
|
||||||
|
onError(new Error('图片大小不能超过5MB!'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建本地预览URL
|
||||||
|
const blobUrl = URL.createObjectURL(file);
|
||||||
|
|
||||||
|
// 模拟上传成功响应
|
||||||
|
setTimeout(() => {
|
||||||
|
onSuccess({
|
||||||
|
status: 'done',
|
||||||
|
url: blobUrl,
|
||||||
|
message: blobUrl,
|
||||||
|
response: {
|
||||||
|
success: true,
|
||||||
|
message: '上传成功',
|
||||||
|
result: {
|
||||||
|
url: blobUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '作者',
|
||||||
|
field: 'author',
|
||||||
|
component: 'Input',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '摘要',
|
||||||
|
field: 'summary',
|
||||||
|
component: 'InputTextArea',
|
||||||
|
componentProps: {
|
||||||
|
rows: 3,
|
||||||
|
placeholder: '请输入内容摘要',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '内容',
|
||||||
|
field: 'content',
|
||||||
|
component: 'JEditor',
|
||||||
|
required: true,
|
||||||
|
componentProps: {
|
||||||
|
height: 400,
|
||||||
|
placeholder: '请输入内容',
|
||||||
|
},
|
||||||
|
dynamicRules: ({ model, schema }) => {
|
||||||
|
return [{ required: true, message: '请输入内容!' }];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '发布状态',
|
||||||
|
field: 'status',
|
||||||
|
component: 'JDictSelectTag',
|
||||||
|
defaultValue: '0',
|
||||||
|
componentProps: {
|
||||||
|
dictCode: 'content_status',
|
||||||
|
placeholder: '请选择状态',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '是否推荐',
|
||||||
|
field: 'isRecommended',
|
||||||
|
component: 'JSwitch',
|
||||||
|
defaultValue: '0',
|
||||||
|
componentProps: {
|
||||||
|
options: ['0', '1'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '排序',
|
||||||
|
field: 'sortOrder',
|
||||||
|
component: 'InputNumber',
|
||||||
|
defaultValue: 0,
|
||||||
|
componentProps: {
|
||||||
|
min: 0,
|
||||||
|
placeholder: '请输入排序值',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '标签',
|
||||||
|
field: 'tags',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '多个标签用逗号分隔',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '关键词',
|
||||||
|
field: 'keywords',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '多个关键词用逗号分隔',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '备注',
|
||||||
|
field: 'remark',
|
||||||
|
component: 'InputTextArea',
|
||||||
|
componentProps: {
|
||||||
|
rows: 2,
|
||||||
|
placeholder: '请输入备注',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
162
src/views/oroqen/culture-content/OroqenCultureContentList.vue
Normal file
162
src/views/oroqen/culture-content/OroqenCultureContentList.vue
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
<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>
|
||||||
|
</template>
|
||||||
|
<!--操作栏-->
|
||||||
|
<template #action="{ record }">
|
||||||
|
<TableAction :actions="getTableAction(record)" />
|
||||||
|
</template>
|
||||||
|
<!--字段回显插槽-->
|
||||||
|
<template #htmlSlot="{ text }">
|
||||||
|
<div v-html="text"></div>
|
||||||
|
</template>
|
||||||
|
<!--省市区字段回显插槽-->
|
||||||
|
<template #pcaSlot="{ text }">
|
||||||
|
{{ getAreaTextByCode(text) }}
|
||||||
|
</template>
|
||||||
|
<template #fileSlot="{ text }">
|
||||||
|
<span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
|
||||||
|
<a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small" @click="downloadFile(text)">下载</a-button>
|
||||||
|
</template>
|
||||||
|
</BasicTable>
|
||||||
|
<!-- 表单区域 -->
|
||||||
|
<OroqenCultureContentModal @register="registerModal" @success="handleSuccess" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" name="oroqen-culture-content" setup>
|
||||||
|
import { ref, computed, unref } from 'vue';
|
||||||
|
import { BasicTable, useTable, TableAction } from '/@/components/Table';
|
||||||
|
import { useModal } from '/@/components/Modal';
|
||||||
|
import { useListPage } from '/@/hooks/system/useListPage';
|
||||||
|
import OroqenCultureContentModal from './components/OroqenCultureContentModal.vue';
|
||||||
|
import { columns, searchFormSchema } from './OroqenCultureContent.data';
|
||||||
|
import { list, deleteOne, batchDelete, getImportUrl, getExportUrl, toggleRecommend } from './OroqenCultureContent.api';
|
||||||
|
import { downloadFile } from '/@/utils/common/renderUtils';
|
||||||
|
import { getAreaTextByCode } from '/@/components/Form/src/utils/Area';
|
||||||
|
|
||||||
|
const checkedKeys = ref<Array<string | number>>([]);
|
||||||
|
const [registerModal, { openModal }] = useModal();
|
||||||
|
const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
|
||||||
|
tableProps: {
|
||||||
|
title: '文化内容',
|
||||||
|
api: list,
|
||||||
|
columns,
|
||||||
|
canResize: false,
|
||||||
|
formConfig: {
|
||||||
|
labelWidth: 120,
|
||||||
|
schemas: searchFormSchema,
|
||||||
|
autoSubmitOnEnter: true,
|
||||||
|
},
|
||||||
|
actionColumn: {
|
||||||
|
width: 120,
|
||||||
|
fixed: 'right',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
exportApi: getExportUrl,
|
||||||
|
importApi: getImportUrl,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增事件
|
||||||
|
*/
|
||||||
|
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: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除事件
|
||||||
|
*/
|
||||||
|
async function handleDelete(record) {
|
||||||
|
await deleteOne({ id: record.id }, handleSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除事件
|
||||||
|
*/
|
||||||
|
async function batchHandleDelete() {
|
||||||
|
await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 推荐/取消推荐
|
||||||
|
*/
|
||||||
|
async function handleToggleRecommend(record) {
|
||||||
|
const isRecommend = record.isRecommended === '0';
|
||||||
|
await toggleRecommend(record.id, isRecommend);
|
||||||
|
handleSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功回调
|
||||||
|
*/
|
||||||
|
function handleSuccess() {
|
||||||
|
(selectedRowKeys.value = []) && reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作栏
|
||||||
|
*/
|
||||||
|
function getTableAction(record) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
label: '编辑',
|
||||||
|
onClick: handleEdit.bind(null, record),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: record.isRecommended === '1' ? '取消推荐' : '推荐',
|
||||||
|
color: record.isRecommended === '1' ? 'warning' : 'success',
|
||||||
|
onClick: handleToggleRecommend.bind(null, record),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped></style>
|
@ -0,0 +1,44 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<BasicForm @register="registerForm" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { BasicForm, useForm } from '/@/components/Form/index';
|
||||||
|
import { formSchema } from '../OroqenCultureContent.data';
|
||||||
|
import { saveOrUpdate } from '../OroqenCultureContent.api';
|
||||||
|
|
||||||
|
// Emits
|
||||||
|
const emit = defineEmits(['success', 'register']);
|
||||||
|
|
||||||
|
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
|
||||||
|
labelWidth: 100,
|
||||||
|
schemas: formSchema,
|
||||||
|
showActionButtonGroup: false,
|
||||||
|
actionColOptions: {
|
||||||
|
span: 23,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// 暴露内部方法
|
||||||
|
defineExpose({
|
||||||
|
setFieldsValue,
|
||||||
|
resetFields,
|
||||||
|
validate,
|
||||||
|
handleSubmit,
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交表单
|
||||||
|
*/
|
||||||
|
async function handleSubmit() {
|
||||||
|
try {
|
||||||
|
const values = await validate();
|
||||||
|
await saveOrUpdate(values, values.id);
|
||||||
|
emit('success');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('表单提交失败:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
@ -0,0 +1,186 @@
|
|||||||
|
<template>
|
||||||
|
<BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="getTitle" :width="1024" @ok="handleSubmit">
|
||||||
|
<BasicForm @register="registerForm" name="OroqenCultureContentForm" />
|
||||||
|
</BasicModal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { ref, computed, unref } from 'vue';
|
||||||
|
import { BasicModal, useModalInner } from '/@/components/Modal';
|
||||||
|
import { BasicForm, useForm } from '/@/components/Form/index';
|
||||||
|
import { formSchema } from '../OroqenCultureContent.data';
|
||||||
|
import { saveOrUpdate } from '../OroqenCultureContent.api';
|
||||||
|
|
||||||
|
|
||||||
|
// Emits
|
||||||
|
const emit = defineEmits(['success', 'register']);
|
||||||
|
|
||||||
|
const isUpdate = ref(true);
|
||||||
|
const rowId = ref('');
|
||||||
|
|
||||||
|
// 表单配置
|
||||||
|
const [registerForm, { setProps, resetFields, setFieldsValue, validate }] = useForm({
|
||||||
|
labelWidth: 100,
|
||||||
|
baseColProps: { span: 24 },
|
||||||
|
schemas: formSchema,
|
||||||
|
showActionButtonGroup: false,
|
||||||
|
autoSubmitOnEnter: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// 表单赋值
|
||||||
|
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
||||||
|
// 重置表单
|
||||||
|
await resetFields();
|
||||||
|
setModalProps({ confirmLoading: false, showCancelBtn: !!data?.showFooter, showOkBtn: !!data?.showFooter });
|
||||||
|
isUpdate.value = !!data?.isUpdate;
|
||||||
|
|
||||||
|
if (unref(isUpdate)) {
|
||||||
|
rowId.value = data.record.id;
|
||||||
|
// 表单赋值
|
||||||
|
await setFieldsValue({
|
||||||
|
...data.record,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 隐藏底部时禁用整个表单
|
||||||
|
setProps({ disabled: !data?.showFooter });
|
||||||
|
});
|
||||||
|
|
||||||
|
// 表单标题
|
||||||
|
const getTitle = computed(() => (!unref(isUpdate) ? '新增' : '编辑'));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传blob文件
|
||||||
|
* @param filePath 文件路径或blob URL
|
||||||
|
* @param fieldName 字段名
|
||||||
|
* @returns 上传后的文件路径
|
||||||
|
*/
|
||||||
|
async function uploadBlobFile(filePath, fieldName) {
|
||||||
|
try {
|
||||||
|
console.log('处理文件:', filePath, '字段:', fieldName);
|
||||||
|
|
||||||
|
let file;
|
||||||
|
let fileName;
|
||||||
|
|
||||||
|
if (filePath.startsWith('blob:')) {
|
||||||
|
// 从blob URL获取文件
|
||||||
|
console.log('从blob URL获取文件');
|
||||||
|
const response = await fetch(filePath);
|
||||||
|
const blob = await response.blob();
|
||||||
|
fileName = `${fieldName}_${Date.now()}.${blob.type.split('/')[1] || 'jpg'}`;
|
||||||
|
file = new File([blob], fileName, { type: blob.type });
|
||||||
|
|
||||||
|
console.log('从blob URL创建的文件:', file);
|
||||||
|
} else {
|
||||||
|
console.log('非blob URL,可能是已存在的文件路径');
|
||||||
|
return filePath; // 返回原路径,可能是已存在的文件
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
throw new Error('无法获取文件对象');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确定业务路径
|
||||||
|
let bizPath = 'culture/temp';
|
||||||
|
if (fieldName === 'coverImage') {
|
||||||
|
bizPath = 'culture/cover';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 上传文件参数
|
||||||
|
const uploadParams = {
|
||||||
|
file: file,
|
||||||
|
name: 'file',
|
||||||
|
filename: fileName,
|
||||||
|
data: {
|
||||||
|
biz: bizPath
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('上传参数:', uploadParams);
|
||||||
|
|
||||||
|
// 上传文件
|
||||||
|
const uploadResult = await defHttp.uploadFile(
|
||||||
|
{
|
||||||
|
url: '/sys/common/upload',
|
||||||
|
timeout: 30000
|
||||||
|
},
|
||||||
|
uploadParams,
|
||||||
|
{
|
||||||
|
isReturnResponse: true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log('上传结果完整信息:', uploadResult);
|
||||||
|
|
||||||
|
// 处理可能的undefined情况
|
||||||
|
if (!uploadResult) {
|
||||||
|
console.error('上传结果为空或undefined');
|
||||||
|
throw new Error('上传失败:服务器未返回结果');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查上传结果 - 兼容不同的返回格式
|
||||||
|
const isSuccess = uploadResult && (
|
||||||
|
uploadResult.success === true ||
|
||||||
|
uploadResult.code === 0 ||
|
||||||
|
uploadResult.code === 200
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isSuccess) {
|
||||||
|
const filePath = uploadResult.message || uploadResult.result || uploadResult.data;
|
||||||
|
console.log('上传成功,文件路径:', filePath);
|
||||||
|
return filePath;
|
||||||
|
} else {
|
||||||
|
console.error('上传失败详细信息:', uploadResult);
|
||||||
|
throw new Error(uploadResult?.message || uploadResult?.error || '上传失败,请检查网络连接或联系管理员');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('上传文件失败:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交表单
|
||||||
|
*/
|
||||||
|
async function handleSubmit() {
|
||||||
|
try {
|
||||||
|
setModalProps({ confirmLoading: true });
|
||||||
|
const values = await validate();
|
||||||
|
|
||||||
|
// 处理封面图片上传
|
||||||
|
if (values.coverImage && typeof values.coverImage === 'string' && values.coverImage.startsWith('blob:')) {
|
||||||
|
try {
|
||||||
|
const uploadResult = await uploadBlobFile(values.coverImage, 'coverImage');
|
||||||
|
values.coverImage = uploadResult;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('封面图片上传失败:', error);
|
||||||
|
throw new Error('封面图片上传失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await saveOrUpdate(values, values.id);
|
||||||
|
emit('success');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('表单提交失败:', error);
|
||||||
|
createMessage.error(error.message || '操作失败');
|
||||||
|
} finally {
|
||||||
|
setModalProps({ confirmLoading: false });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理文件上传
|
||||||
|
*/
|
||||||
|
async function handleFileUploads(values) {
|
||||||
|
// 处理封面图片上传
|
||||||
|
if (values.coverImage && typeof values.coverImage === 'string' && values.coverImage.startsWith('blob:')) {
|
||||||
|
try {
|
||||||
|
const uploadResult = await uploadBlobFile(values.coverImage, 'culture/cover');
|
||||||
|
values.coverImage = uploadResult;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('封面图片上传失败:', error);
|
||||||
|
throw new Error('封面图片上传失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
@ -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();
|
||||||
|
});
|
||||||
|
}
|
599
src/views/oroqen/heritage-project/OroqenHeritageProject.data.ts
Normal file
599
src/views/oroqen/heritage-project/OroqenHeritageProject.data.ts
Normal 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;
|
||||||
|
}
|
219
src/views/oroqen/heritage-project/OroqenHeritageProjectList.vue
Normal file
219
src/views/oroqen/heritage-project/OroqenHeritageProjectList.vue
Normal 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: false,
|
||||||
|
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>
|
@ -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>
|
@ -0,0 +1,273 @@
|
|||||||
|
<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';
|
||||||
|
import { uploadFile } from '/@/api/common/api';
|
||||||
|
import { defHttp } from '/@/utils/http/axios';
|
||||||
|
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 handleFileUploads(values);
|
||||||
|
|
||||||
|
//提交表单
|
||||||
|
await saveOrUpdate(values, isUpdate.value);
|
||||||
|
//关闭弹窗
|
||||||
|
closeModal();
|
||||||
|
//刷新列表
|
||||||
|
emit('success');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('表单提交失败:', error);
|
||||||
|
|
||||||
|
// 处理表单验证错误
|
||||||
|
if (error && error.errorFields) {
|
||||||
|
const firstField = error.errorFields[0];
|
||||||
|
if (firstField) {
|
||||||
|
scrollToField(firstField.name, { behavior: 'smooth', block: 'center' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 显示错误消息
|
||||||
|
if (error && error.message) {
|
||||||
|
createMessage.error(error.message);
|
||||||
|
} else if (typeof error === 'string') {
|
||||||
|
createMessage.error(error);
|
||||||
|
} else {
|
||||||
|
createMessage.error('操作失败,请重试');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重要:必须抛出错误,否则会导致未处理的Promise拒绝
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
setModalProps({ confirmLoading: false });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理文件上传
|
||||||
|
* @param formData 表单数据
|
||||||
|
*/
|
||||||
|
async function handleFileUploads(formData) {
|
||||||
|
console.log('开始处理文件上传,表单数据:', formData);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 查找所有需要处理文件上传的字段
|
||||||
|
const fileFields = ['coverImage', 'images', 'videoUrl'];
|
||||||
|
|
||||||
|
for (const field of fileFields) {
|
||||||
|
// 如果字段有值且包含blob URL,说明有新文件需要上传
|
||||||
|
if (formData[field] && typeof formData[field] === 'string') {
|
||||||
|
const fieldValue = formData[field];
|
||||||
|
const filePaths = fieldValue.split(',').filter(path => path.trim());
|
||||||
|
|
||||||
|
for (const path of filePaths) {
|
||||||
|
if (path.startsWith('blob:')) {
|
||||||
|
// 这是一个需要处理的blob文件
|
||||||
|
console.log(`发现需要处理的blob文件: ${field} -> ${path}`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const uploadedPath = await uploadBlobFile(path, field);
|
||||||
|
// 替换表单数据中的blob URL为服务器路径
|
||||||
|
formData[field] = formData[field].replace(path, uploadedPath);
|
||||||
|
console.log(`文件上传成功,更新路径: ${path} -> ${uploadedPath}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`上传文件失败 (${field}):`, error);
|
||||||
|
createMessage.error(`上传文件失败: ${error.message}`);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('所有文件处理完成,最终表单数据:', formData);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('文件上传处理失败:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传blob文件
|
||||||
|
* @param filePath 文件路径或blob URL
|
||||||
|
* @param fieldName 字段名
|
||||||
|
* @returns 上传后的文件路径
|
||||||
|
*/
|
||||||
|
async function uploadBlobFile(filePath, fieldName) {
|
||||||
|
try {
|
||||||
|
console.log('处理文件:', filePath, '字段:', fieldName);
|
||||||
|
|
||||||
|
let file;
|
||||||
|
let fileName;
|
||||||
|
|
||||||
|
if (filePath.startsWith('blob:')) {
|
||||||
|
// 从blob URL获取文件
|
||||||
|
console.log('从blob URL获取文件');
|
||||||
|
const response = await fetch(filePath);
|
||||||
|
const blob = await response.blob();
|
||||||
|
fileName = `${fieldName}_${Date.now()}.${blob.type.split('/')[1] || 'jpg'}`;
|
||||||
|
file = new File([blob], fileName, { type: blob.type });
|
||||||
|
|
||||||
|
console.log('从blob URL创建的文件:', file);
|
||||||
|
} else {
|
||||||
|
console.log('非blob URL,可能是已存在的文件路径');
|
||||||
|
return filePath; // 返回原路径,可能是已存在的文件
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
throw new Error('无法获取文件对象');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确定业务路径
|
||||||
|
let bizPath = 'heritage-project/temp';
|
||||||
|
if (fieldName === 'coverImage') {
|
||||||
|
bizPath = 'heritage-project/cover';
|
||||||
|
} else if (fieldName === 'images') {
|
||||||
|
bizPath = 'heritage-project/images';
|
||||||
|
} else if (fieldName === 'videoUrl') {
|
||||||
|
bizPath = 'heritage-project/video';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 上传文件参数
|
||||||
|
const uploadParams = {
|
||||||
|
file: file,
|
||||||
|
name: 'file',
|
||||||
|
filename: fileName,
|
||||||
|
data: {
|
||||||
|
biz: bizPath
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('上传参数:', uploadParams);
|
||||||
|
console.log('上传参数详细信息:');
|
||||||
|
console.log('- file对象:', file);
|
||||||
|
console.log('- file.name:', file.name);
|
||||||
|
console.log('- file.size:', file.size);
|
||||||
|
console.log('- file.type:', file.type);
|
||||||
|
console.log('- bizPath:', bizPath);
|
||||||
|
|
||||||
|
// 上传文件
|
||||||
|
const uploadResult = await defHttp.uploadFile(
|
||||||
|
{
|
||||||
|
url: '/sys/common/upload',
|
||||||
|
timeout: 30000
|
||||||
|
},
|
||||||
|
uploadParams,
|
||||||
|
{
|
||||||
|
isReturnResponse: true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log('上传结果完整信息:', uploadResult);
|
||||||
|
console.log('上传结果类型:', typeof uploadResult);
|
||||||
|
|
||||||
|
// 处理可能的undefined情况
|
||||||
|
if (!uploadResult) {
|
||||||
|
console.error('上传结果为空或undefined');
|
||||||
|
throw new Error('上传失败:服务器未返回结果');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('上传结果success字段:', uploadResult?.success);
|
||||||
|
console.log('上传结果message字段:', uploadResult?.message);
|
||||||
|
console.log('上传结果code字段:', uploadResult?.code);
|
||||||
|
|
||||||
|
// 检查上传结果 - 兼容不同的返回格式
|
||||||
|
const isSuccess = uploadResult && (
|
||||||
|
uploadResult.success === true ||
|
||||||
|
uploadResult.code === 0 ||
|
||||||
|
uploadResult.code === 200
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isSuccess) {
|
||||||
|
const filePath = uploadResult.message || uploadResult.result || uploadResult.data;
|
||||||
|
console.log('上传成功,文件路径:', filePath);
|
||||||
|
return filePath;
|
||||||
|
} else {
|
||||||
|
console.error('上传失败详细信息:', {
|
||||||
|
result: uploadResult,
|
||||||
|
success: uploadResult?.success,
|
||||||
|
message: uploadResult?.message,
|
||||||
|
code: uploadResult?.code,
|
||||||
|
error: uploadResult?.error
|
||||||
|
});
|
||||||
|
throw new Error(uploadResult?.message || uploadResult?.error || '上传失败,请检查网络连接或联系管理员');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('上传文件失败:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理日期值
|
||||||
|
* @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>
|
72
src/views/oroqen/inheritor/OroqenInheritor.api.ts
Normal file
72
src/views/oroqen/inheritor/OroqenInheritor.api.ts
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
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',
|
||||||
|
queryById = '/oroqen/heritageInheritor/queryById',
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出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) => {
|
||||||
|
const url = isUpdate ? Api.edit : Api.save;
|
||||||
|
return defHttp.post({ url: url, params }, { isTransformResponse: false });
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
*/
|
||||||
|
export const queryById = (params) => {
|
||||||
|
return defHttp.get({ url: Api.queryById, params });
|
||||||
|
};
|
395
src/views/oroqen/inheritor/OroqenInheritor.data.ts
Normal file
395
src/views/oroqen/inheritor/OroqenInheritor.data.ts
Normal file
@ -0,0 +1,395 @@
|
|||||||
|
import { BasicColumn } from '/@/components/Table';
|
||||||
|
import { FormSchema } from '/@/components/Table';
|
||||||
|
import { h } from 'vue';
|
||||||
|
import { Image, Tag } from 'ant-design-vue';
|
||||||
|
import { render } from '/@/utils/common/renderUtils';
|
||||||
|
import { getFileAccessHttpUrl } from '/@/utils/common/compUtils';
|
||||||
|
|
||||||
|
//列表数据
|
||||||
|
export const columns: BasicColumn[] = [
|
||||||
|
{
|
||||||
|
title: '头像',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'avatar',
|
||||||
|
width: 80,
|
||||||
|
customRender: ({ text, record }) => {
|
||||||
|
if (!text) return '-';
|
||||||
|
const imageUrl = getFileAccessHttpUrl(text);
|
||||||
|
|
||||||
|
return h(Image, {
|
||||||
|
src: imageUrl,
|
||||||
|
alt: record?.name || '传承人头像',
|
||||||
|
width: 50,
|
||||||
|
height: 50,
|
||||||
|
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: '姓名',
|
||||||
|
dataIndex: 'name',
|
||||||
|
width: 120,
|
||||||
|
align: 'left',
|
||||||
|
ellipsis: true,
|
||||||
|
fixed: 'left',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '性别',
|
||||||
|
dataIndex: 'gender',
|
||||||
|
width: 80,
|
||||||
|
align: 'center',
|
||||||
|
customRender: ({ text }) => {
|
||||||
|
const genderMap = {
|
||||||
|
1: { text: '男', color: 'blue' },
|
||||||
|
2: { text: '女', color: 'pink' },
|
||||||
|
};
|
||||||
|
const gender = genderMap[text] || { text: '未知', color: 'default' };
|
||||||
|
return render.renderTag(gender.text, gender.color);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '年龄',
|
||||||
|
dataIndex: 'age',
|
||||||
|
width: 80,
|
||||||
|
align: 'center',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '民族',
|
||||||
|
dataIndex: 'ethnicity',
|
||||||
|
width: 100,
|
||||||
|
align: 'center',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '传承项目',
|
||||||
|
dataIndex: 'heritageProject',
|
||||||
|
width: 150,
|
||||||
|
align: 'left',
|
||||||
|
ellipsis: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '传承级别',
|
||||||
|
dataIndex: 'heritageLevel',
|
||||||
|
width: 120,
|
||||||
|
align: 'center',
|
||||||
|
customRender: ({ text }) => {
|
||||||
|
const levelMap = {
|
||||||
|
'national': { text: '国家级', color: 'red' },
|
||||||
|
'provincial': { text: '省级', color: 'orange' },
|
||||||
|
'municipal': { text: '市级', color: 'blue' },
|
||||||
|
'county': { text: '县级', color: 'green' },
|
||||||
|
};
|
||||||
|
const level = levelMap[text] || { text: text || '未知', color: 'default' };
|
||||||
|
return render.renderTag(level.text, level.color);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '认定年份',
|
||||||
|
dataIndex: 'recognitionYear',
|
||||||
|
width: 100,
|
||||||
|
align: 'center',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '联系电话',
|
||||||
|
dataIndex: 'phone',
|
||||||
|
width: 120,
|
||||||
|
align: 'center',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
width: 100,
|
||||||
|
align: 'center',
|
||||||
|
customRender: ({ text }) => {
|
||||||
|
const statusMap = {
|
||||||
|
1: { text: '活跃', color: 'green' },
|
||||||
|
0: { text: '停用', color: 'red' },
|
||||||
|
};
|
||||||
|
const status = statusMap[text] || { text: '未知', color: 'default' };
|
||||||
|
return render.renderTag(status.text, status.color);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建时间',
|
||||||
|
dataIndex: 'createTime',
|
||||||
|
width: 150,
|
||||||
|
align: 'center',
|
||||||
|
sorter: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
//查询数据
|
||||||
|
export const searchFormSchema: FormSchema[] = [
|
||||||
|
{
|
||||||
|
label: '姓名',
|
||||||
|
field: 'name',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入传承人姓名',
|
||||||
|
},
|
||||||
|
colProps: { span: 6 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '性别',
|
||||||
|
field: 'gender',
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择性别',
|
||||||
|
options: [
|
||||||
|
{ label: '男', value: 1 },
|
||||||
|
{ label: '女', value: 2 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
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: 'status',
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择状态',
|
||||||
|
options: [
|
||||||
|
{ label: '活跃', value: 1 },
|
||||||
|
{ label: '停用', value: 0 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
colProps: { span: 6 },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
//表单数据
|
||||||
|
export const formSchema: FormSchema[] = [
|
||||||
|
{
|
||||||
|
label: '',
|
||||||
|
field: 'id',
|
||||||
|
component: 'Input',
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '姓名',
|
||||||
|
field: 'name',
|
||||||
|
component: 'Input',
|
||||||
|
required: true,
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入传承人姓名',
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '性别',
|
||||||
|
field: 'gender',
|
||||||
|
component: 'Select',
|
||||||
|
required: true,
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择性别',
|
||||||
|
options: [
|
||||||
|
{ label: '男', value: 1 },
|
||||||
|
{ label: '女', value: 2 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '年龄',
|
||||||
|
field: 'age',
|
||||||
|
component: 'InputNumber',
|
||||||
|
componentProps: {
|
||||||
|
min: 1,
|
||||||
|
max: 120,
|
||||||
|
placeholder: '请输入年龄',
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '民族',
|
||||||
|
field: 'ethnicity',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入民族',
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '传承项目',
|
||||||
|
field: 'heritageProject',
|
||||||
|
component: 'Input',
|
||||||
|
required: true,
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入传承项目',
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '传承级别',
|
||||||
|
field: 'heritageLevel',
|
||||||
|
component: 'Select',
|
||||||
|
required: true,
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择传承级别',
|
||||||
|
options: [
|
||||||
|
{ label: '国家级', value: 'national' },
|
||||||
|
{ label: '省级', value: 'provincial' },
|
||||||
|
{ label: '市级', value: 'municipal' },
|
||||||
|
{ label: '县级', value: 'county' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '认定年份',
|
||||||
|
field: 'recognitionYear',
|
||||||
|
component: 'InputNumber',
|
||||||
|
componentProps: {
|
||||||
|
min: 1900,
|
||||||
|
max: new Date().getFullYear(),
|
||||||
|
placeholder: '请输入认定年份',
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '联系电话',
|
||||||
|
field: 'phone',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入联系电话',
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
// {
|
||||||
|
// label: '身份证号',
|
||||||
|
// field: 'idCard',
|
||||||
|
// component: 'Input',
|
||||||
|
// componentProps: {
|
||||||
|
// placeholder: '请输入身份证号',
|
||||||
|
// },
|
||||||
|
// colProps: { span: 12 },
|
||||||
|
// },
|
||||||
|
{
|
||||||
|
label: '地址',
|
||||||
|
field: 'address',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入地址',
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '状态',
|
||||||
|
field: 'status',
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择状态',
|
||||||
|
options: [
|
||||||
|
{ label: '活跃', value: 1 },
|
||||||
|
{ label: '停用', value: 0 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '排序',
|
||||||
|
field: 'sortOrder',
|
||||||
|
component: 'InputNumber',
|
||||||
|
componentProps: {
|
||||||
|
min: 0,
|
||||||
|
placeholder: '请输入排序值',
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '传承技艺描述',
|
||||||
|
field: 'skillDescription',
|
||||||
|
component: 'InputTextArea',
|
||||||
|
componentProps: {
|
||||||
|
rows: 4,
|
||||||
|
placeholder: '请输入传承技艺描述',
|
||||||
|
},
|
||||||
|
colProps: { span: 24 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '个人简介',
|
||||||
|
field: 'biography',
|
||||||
|
component: 'InputTextArea',
|
||||||
|
componentProps: {
|
||||||
|
rows: 4,
|
||||||
|
placeholder: '请输入个人简介',
|
||||||
|
},
|
||||||
|
colProps: { span: 24 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '传承经历',
|
||||||
|
field: 'heritageExperience',
|
||||||
|
component: 'InputTextArea',
|
||||||
|
componentProps: {
|
||||||
|
rows: 4,
|
||||||
|
placeholder: '请输入传承经历',
|
||||||
|
},
|
||||||
|
colProps: { span: 24 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '获奖情况',
|
||||||
|
field: 'awards',
|
||||||
|
component: 'InputTextArea',
|
||||||
|
componentProps: {
|
||||||
|
rows: 3,
|
||||||
|
placeholder: '请输入获奖情况',
|
||||||
|
},
|
||||||
|
colProps: { span: 24 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '头像',
|
||||||
|
field: 'avatar',
|
||||||
|
component: 'JUpload',
|
||||||
|
componentProps: {
|
||||||
|
fileType: 'image',
|
||||||
|
maxCount: 1,
|
||||||
|
maxSize: 5,
|
||||||
|
bizPath: 'inheritor/portrait',
|
||||||
|
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;
|
||||||
|
|
||||||
|
// 模拟上传成功响应,返回blob URL作为message
|
||||||
|
setTimeout(() => {
|
||||||
|
options.onSuccess({
|
||||||
|
success: true,
|
||||||
|
message: localUrl, // 返回blob URL
|
||||||
|
}, file);
|
||||||
|
}, 100);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
colProps: { span: 24 },
|
||||||
|
},
|
||||||
|
];
|
156
src/views/oroqen/inheritor/OroqenInheritorList.vue
Normal file
156
src/views/oroqen/inheritor/OroqenInheritorList.vue
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
<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"></Icon>
|
||||||
|
删除
|
||||||
|
</a-menu-item>
|
||||||
|
</a-menu>
|
||||||
|
</template>
|
||||||
|
<a-button>批量操作
|
||||||
|
<Icon icon="mdi:chevron-down"></Icon>
|
||||||
|
</a-button>
|
||||||
|
</a-dropdown>
|
||||||
|
</template>
|
||||||
|
<!--操作栏-->
|
||||||
|
<template #action="{ record }">
|
||||||
|
<TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)"/>
|
||||||
|
</template>
|
||||||
|
<!--字段回显插槽-->
|
||||||
|
<template #htmlSlot="{text}">
|
||||||
|
<div v-html="text"></div>
|
||||||
|
</template>
|
||||||
|
</BasicTable>
|
||||||
|
<!-- 表单区域 -->
|
||||||
|
<OroqenInheritorModal @register="registerModal" @success="handleSuccess"></OroqenInheritorModal>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" name="oroqen-inheritor" setup>
|
||||||
|
import {ref, computed, unref} from 'vue';
|
||||||
|
import {BasicTable, useTable, TableAction} from '/@/components/Table';
|
||||||
|
import {useModal} from '/@/components/Modal';
|
||||||
|
import {useListPage} from '/@/hooks/system/useListPage';
|
||||||
|
import OroqenInheritorModal from './components/OroqenInheritorModal.vue'
|
||||||
|
import {columns, searchFormSchema} from './OroqenInheritor.data';
|
||||||
|
import {list, deleteOne, batchDelete, getImportUrl, getExportUrl} from './OroqenInheritor.api';
|
||||||
|
import {downloadByOnlineUrl} from '/@/utils/common/renderUtils';
|
||||||
|
import {useUserStore} from '/@/store/modules/user';
|
||||||
|
|
||||||
|
const checkedKeys = ref<Array<string | number>>([]);
|
||||||
|
const userStore = useUserStore();
|
||||||
|
//注册model
|
||||||
|
const [registerModal, {openModal}] = useModal();
|
||||||
|
//注册table数据
|
||||||
|
const {prefixCls, tableContext, onExportXls, onImportXls} = useListPage({
|
||||||
|
tableProps: {
|
||||||
|
title: '传承人',
|
||||||
|
api: list,
|
||||||
|
columns,
|
||||||
|
canResize:false,
|
||||||
|
formConfig: {
|
||||||
|
//labelWidth: 120,
|
||||||
|
schemas: searchFormSchema,
|
||||||
|
autoSubmitOnEnter: true,
|
||||||
|
},
|
||||||
|
actionColumn: {
|
||||||
|
width: 120,
|
||||||
|
fixed: 'right'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
exportApi: getExportUrl,
|
||||||
|
importApi: getImportUrl,
|
||||||
|
})
|
||||||
|
|
||||||
|
const [registerTable, {reload}, {rowSelection, selectedRowKeys}] = tableContext
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增事件
|
||||||
|
*/
|
||||||
|
function handleAdd() {
|
||||||
|
openModal(true, {
|
||||||
|
isUpdate: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 编辑事件
|
||||||
|
*/
|
||||||
|
function handleEdit(record: Recordable) {
|
||||||
|
openModal(true, {
|
||||||
|
record,
|
||||||
|
isUpdate: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 详情
|
||||||
|
*/
|
||||||
|
function handleDetail(record: Recordable) {
|
||||||
|
openModal(true, {
|
||||||
|
record,
|
||||||
|
isUpdate: true,
|
||||||
|
mode: 'detail',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 删除事件
|
||||||
|
*/
|
||||||
|
async function handleDelete(record) {
|
||||||
|
await deleteOne({id: record.id}, handleSuccess);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 批量删除事件
|
||||||
|
*/
|
||||||
|
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: '删除',
|
||||||
|
color: 'error',
|
||||||
|
popConfirm: {
|
||||||
|
title: '是否确认删除',
|
||||||
|
placement: 'topLeft',
|
||||||
|
confirm: handleDelete.bind(null, record),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
@ -0,0 +1,97 @@
|
|||||||
|
<template>
|
||||||
|
<div class="jeecg-basic-table-form-container">
|
||||||
|
<a-form ref="formRef" @keyup.enter.native="searchQuery" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||||
|
<a-row :gutter="24">
|
||||||
|
<a-col :lg="6" :md="8" :sm="24">
|
||||||
|
<a-form-item label="姓名">
|
||||||
|
<a-input placeholder="请输入传承人姓名" v-model:value="queryParam.name"></a-input>
|
||||||
|
</a-form-item>
|
||||||
|
</a-col>
|
||||||
|
<a-col :lg="6" :md="8" :sm="24">
|
||||||
|
<a-form-item label="性别">
|
||||||
|
<j-dict-select-tag type="list" v-model:value="queryParam.gender" dictCode="sex" placeholder="请选择性别" />
|
||||||
|
</a-form-item>
|
||||||
|
</a-col>
|
||||||
|
<a-col :lg="6" :md="8" :sm="24">
|
||||||
|
<a-form-item label="传承级别">
|
||||||
|
<a-select placeholder="请选择传承级别" v-model:value="queryParam.heritageLevel">
|
||||||
|
<a-select-option value="national">国家级</a-select-option>
|
||||||
|
<a-select-option value="provincial">省级</a-select-option>
|
||||||
|
<a-select-option value="municipal">市级</a-select-option>
|
||||||
|
<a-select-option value="county">县级</a-select-option>
|
||||||
|
</a-select>
|
||||||
|
</a-form-item>
|
||||||
|
</a-col>
|
||||||
|
<a-col :lg="6" :md="8" :sm="24">
|
||||||
|
<a-form-item label="状态">
|
||||||
|
<j-dict-select-tag type="list" v-model:value="queryParam.status" dictCode="valid_status" placeholder="请选择状态" />
|
||||||
|
</a-form-item>
|
||||||
|
</a-col>
|
||||||
|
<a-col :lg="6" :md="8" :sm="24">
|
||||||
|
<span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
|
||||||
|
<a-col :lg="6">
|
||||||
|
<a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
|
||||||
|
<a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
|
||||||
|
</a-col>
|
||||||
|
</span>
|
||||||
|
</a-col>
|
||||||
|
</a-row>
|
||||||
|
</a-form>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import {defineComponent, reactive} from 'vue';
|
||||||
|
import {Form} from 'ant-design-vue';
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: "OroqenInheritorForm",
|
||||||
|
components:{
|
||||||
|
//JDictSelectTag,
|
||||||
|
},
|
||||||
|
emits:['searchReset','searchQuery'],
|
||||||
|
setup(props,{emit}){
|
||||||
|
const formRef = reactive(Form);
|
||||||
|
const queryParam = reactive({});
|
||||||
|
const labelCol = reactive({
|
||||||
|
xs: { span: 24 },
|
||||||
|
sm: { span: 5 },
|
||||||
|
});
|
||||||
|
const wrapperCol = reactive({
|
||||||
|
xs: { span: 24 },
|
||||||
|
sm: { span: 16 },
|
||||||
|
});
|
||||||
|
|
||||||
|
function searchQuery(){
|
||||||
|
emit('searchQuery',queryParam)
|
||||||
|
}
|
||||||
|
function searchReset(){
|
||||||
|
emit('searchReset',queryParam)
|
||||||
|
}
|
||||||
|
return{
|
||||||
|
formRef,
|
||||||
|
queryParam,
|
||||||
|
labelCol,
|
||||||
|
wrapperCol,
|
||||||
|
searchQuery,
|
||||||
|
searchReset,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.jeecg-basic-table-form-container{
|
||||||
|
padding: 20px 10px 0px 10px;
|
||||||
|
background-color: #fff;
|
||||||
|
border: 1px solid #e8e8e8;
|
||||||
|
border-radius: 6px;
|
||||||
|
margin-bottom:10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-page-search-submitButtons {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 24px;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
</style>
|
265
src/views/oroqen/inheritor/components/OroqenInheritorModal.vue
Normal file
265
src/views/oroqen/inheritor/components/OroqenInheritorModal.vue
Normal file
@ -0,0 +1,265 @@
|
|||||||
|
<template>
|
||||||
|
<BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit">
|
||||||
|
<BasicForm @register="registerForm" />
|
||||||
|
</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 '../OroqenInheritor.data';
|
||||||
|
import { saveOrUpdate } from '../OroqenInheritor.api';
|
||||||
|
import { useMessage } from '/@/hooks/web/useMessage';
|
||||||
|
import { getDateByPicker } from '/@/utils';
|
||||||
|
import { uploadFile } from '/@/api/common/api';
|
||||||
|
import { defHttp } from '/@/utils/http/axios';
|
||||||
|
|
||||||
|
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, width: "800px" });
|
||||||
|
isUpdate.value = !!data?.isUpdate;
|
||||||
|
isDetail.value = data?.mode === 'detail';
|
||||||
|
|
||||||
|
if (unref(isUpdate)) {
|
||||||
|
//表单赋值
|
||||||
|
await setFieldsValue({
|
||||||
|
...data.record,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// 详情模式时禁用整个表单
|
||||||
|
setProps({ disabled: unref(isDetail) });
|
||||||
|
});
|
||||||
|
//日期个性化选择
|
||||||
|
const fieldPickers = reactive({});
|
||||||
|
|
||||||
|
const getTitle = computed(() => (!unref(isUpdate) ? '新增' : unref(isDetail) ? '详情' : '编辑'));
|
||||||
|
|
||||||
|
//表单提交事件
|
||||||
|
async function handleSubmit(v) {
|
||||||
|
try {
|
||||||
|
let values = await validate();
|
||||||
|
console.log('表单验证通过,提交数据:', values);
|
||||||
|
|
||||||
|
// 预处理日期数据
|
||||||
|
changeDateValue(values);
|
||||||
|
setModalProps({ confirmLoading: true });
|
||||||
|
|
||||||
|
// 处理文件上传
|
||||||
|
await handleFileUploads(values);
|
||||||
|
|
||||||
|
//提交表单
|
||||||
|
await saveOrUpdate(values, isUpdate.value);
|
||||||
|
//关闭弹窗
|
||||||
|
closeModal();
|
||||||
|
//刷新列表
|
||||||
|
emit('success');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('表单提交失败:', error);
|
||||||
|
|
||||||
|
// 处理表单验证错误
|
||||||
|
if (error && error.errorFields) {
|
||||||
|
console.error('表单验证错误字段:', error.errorFields);
|
||||||
|
const firstField = error.errorFields[0];
|
||||||
|
if (firstField) {
|
||||||
|
console.error('第一个错误字段:', firstField);
|
||||||
|
scrollToField(firstField.name, { behavior: 'smooth', block: 'center' });
|
||||||
|
|
||||||
|
// 显示具体的验证错误信息
|
||||||
|
const fieldName = firstField.name[0] || firstField.name;
|
||||||
|
const errorMessage = firstField.errors?.[0] || '字段验证失败';
|
||||||
|
createMessage.error(`${fieldName}: ${errorMessage}`);
|
||||||
|
}
|
||||||
|
} else if (error && error.message) {
|
||||||
|
createMessage.error(error.message);
|
||||||
|
} else if (typeof error === 'string') {
|
||||||
|
createMessage.error(error);
|
||||||
|
} else {
|
||||||
|
createMessage.error('操作失败,请重试');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 不要抛出错误,避免未处理的Promise拒绝
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
setModalProps({ confirmLoading: false });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理文件上传
|
||||||
|
* @param formData 表单数据
|
||||||
|
*/
|
||||||
|
async function handleFileUploads(formData) {
|
||||||
|
console.log('开始处理文件上传,表单数据:', formData);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 传承人模块只有一个头像字段
|
||||||
|
const fileFields = ['avatar'];
|
||||||
|
|
||||||
|
for (const field of fileFields) {
|
||||||
|
// 如果字段有值且包含blob URL,说明有新文件需要上传
|
||||||
|
if (formData[field] && typeof formData[field] === 'string') {
|
||||||
|
const fieldValue = formData[field];
|
||||||
|
const filePaths = fieldValue.split(',').filter(path => path.trim());
|
||||||
|
|
||||||
|
for (const path of filePaths) {
|
||||||
|
if (path.startsWith('blob:')) {
|
||||||
|
// 这是一个需要处理的blob文件
|
||||||
|
console.log(`发现需要处理的blob文件: ${field} -> ${path}`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const uploadedPath = await uploadBlobFile(path, field);
|
||||||
|
// 替换表单数据中的blob URL为服务器路径
|
||||||
|
formData[field] = formData[field].replace(path, uploadedPath);
|
||||||
|
console.log(`文件上传成功,更新路径: ${path} -> ${uploadedPath}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`上传文件失败 (${field}):`, error);
|
||||||
|
createMessage.error(`上传文件失败: ${error.message}`);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('所有文件处理完成,最终表单数据:', formData);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('文件上传处理失败:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传blob文件
|
||||||
|
* @param filePath 文件路径或blob URL
|
||||||
|
* @param fieldName 字段名
|
||||||
|
* @returns 上传后的文件路径
|
||||||
|
*/
|
||||||
|
async function uploadBlobFile(filePath, fieldName) {
|
||||||
|
try {
|
||||||
|
console.log('处理文件:', filePath, '字段:', fieldName);
|
||||||
|
|
||||||
|
let file;
|
||||||
|
let fileName;
|
||||||
|
|
||||||
|
if (filePath.startsWith('blob:')) {
|
||||||
|
// 从blob URL获取文件
|
||||||
|
console.log('从blob URL获取文件');
|
||||||
|
const response = await fetch(filePath);
|
||||||
|
const blob = await response.blob();
|
||||||
|
fileName = `${fieldName}_${Date.now()}.${blob.type.split('/')[1] || 'jpg'}`;
|
||||||
|
file = new File([blob], fileName, { type: blob.type });
|
||||||
|
|
||||||
|
console.log('从blob URL创建的文件:', file);
|
||||||
|
} else {
|
||||||
|
console.log('非blob URL,可能是已存在的文件路径');
|
||||||
|
return filePath; // 返回原路径,可能是已存在的文件
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
throw new Error('无法获取文件对象');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确定业务路径 - 传承人模块只有头像
|
||||||
|
let bizPath = 'inheritor/avatar';
|
||||||
|
|
||||||
|
// 上传文件参数
|
||||||
|
const uploadParams = {
|
||||||
|
file: file,
|
||||||
|
name: 'file',
|
||||||
|
filename: fileName,
|
||||||
|
data: {
|
||||||
|
biz: bizPath
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('上传参数:', uploadParams);
|
||||||
|
console.log('上传参数详细信息:');
|
||||||
|
console.log('- file对象:', file);
|
||||||
|
console.log('- file.name:', file.name);
|
||||||
|
console.log('- file.size:', file.size);
|
||||||
|
console.log('- file.type:', file.type);
|
||||||
|
console.log('- bizPath:', bizPath);
|
||||||
|
|
||||||
|
// 上传文件
|
||||||
|
const uploadResult = await defHttp.uploadFile(
|
||||||
|
{
|
||||||
|
url: '/sys/common/upload',
|
||||||
|
timeout: 30000
|
||||||
|
},
|
||||||
|
uploadParams,
|
||||||
|
{
|
||||||
|
isReturnResponse: true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log('上传结果完整信息:', uploadResult);
|
||||||
|
console.log('上传结果类型:', typeof uploadResult);
|
||||||
|
|
||||||
|
// 处理可能的undefined情况
|
||||||
|
if (!uploadResult) {
|
||||||
|
console.error('上传结果为空或undefined');
|
||||||
|
throw new Error('上传失败:服务器未返回结果');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('上传结果success字段:', uploadResult?.success);
|
||||||
|
console.log('上传结果message字段:', uploadResult?.message);
|
||||||
|
console.log('上传结果code字段:', uploadResult?.code);
|
||||||
|
|
||||||
|
// 检查上传结果 - 兼容不同的返回格式
|
||||||
|
const isSuccess = uploadResult && (
|
||||||
|
uploadResult.success === true ||
|
||||||
|
uploadResult.code === 0 ||
|
||||||
|
uploadResult.code === 200
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isSuccess) {
|
||||||
|
const filePath = uploadResult.message || uploadResult.result || uploadResult.data;
|
||||||
|
console.log('上传成功,文件路径:', filePath);
|
||||||
|
return filePath;
|
||||||
|
} else {
|
||||||
|
console.error('上传失败详细信息:', {
|
||||||
|
result: uploadResult,
|
||||||
|
success: uploadResult?.success,
|
||||||
|
message: uploadResult?.message,
|
||||||
|
code: uploadResult?.code,
|
||||||
|
error: uploadResult?.error
|
||||||
|
});
|
||||||
|
throw new Error(uploadResult?.message || uploadResult?.error || '上传失败,请检查网络连接或联系管理员');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('上传文件失败:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理日期值
|
||||||
|
* @param formData 表单数据
|
||||||
|
*/
|
||||||
|
const changeDateValue = (formData) => {
|
||||||
|
if (formData && fieldPickers) {
|
||||||
|
for (let key in fieldPickers) {
|
||||||
|
if (formData[key]) {
|
||||||
|
formData[key] = getDateByPicker(formData[key], fieldPickers[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
@ -0,0 +1,76 @@
|
|||||||
|
import { defHttp } from '/@/utils/http/axios';
|
||||||
|
import { useMessage } from '/@/hooks/web/useMessage';
|
||||||
|
|
||||||
|
const { createConfirm } = useMessage();
|
||||||
|
|
||||||
|
enum Api {
|
||||||
|
list = '/oroqen/productCategory/list',
|
||||||
|
save = '/oroqen/productCategory/add',
|
||||||
|
edit = '/oroqen/productCategory/edit',
|
||||||
|
deleteOne = '/oroqen/productCategory/delete',
|
||||||
|
deleteBatch = '/oroqen/productCategory/deleteBatch',
|
||||||
|
importExcel = '/oroqen/productCategory/importExcel',
|
||||||
|
exportXls = '/oroqen/productCategory/exportXls',
|
||||||
|
queryById = '/oroqen/productCategory/queryById',
|
||||||
|
tree = '/oroqen/productCategory/tree',
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出api
|
||||||
|
*/
|
||||||
|
export const getExportUrl = Api.exportXls;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入api
|
||||||
|
*/
|
||||||
|
export const getImportUrl = Api.importExcel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表接口
|
||||||
|
*/
|
||||||
|
export const list = (params) => defHttp.get({ url: Api.list, params });
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 树形列表接口
|
||||||
|
*/
|
||||||
|
export const queryTreeList = (params) => defHttp.get({ url: Api.tree, params });
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取分类树
|
||||||
|
*/
|
||||||
|
export const getCategoryTree = () => defHttp.get({ url: Api.tree });
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除单个
|
||||||
|
*/
|
||||||
|
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 });
|
||||||
|
};
|
214
src/views/oroqen/product-category/OroqenProductCategory.data.ts
Normal file
214
src/views/oroqen/product-category/OroqenProductCategory.data.ts
Normal file
@ -0,0 +1,214 @@
|
|||||||
|
import { BasicColumn } from '/@/components/Table';
|
||||||
|
import { FormSchema } from '/@/components/Table';
|
||||||
|
import { rules } from '/@/utils/helper/validator';
|
||||||
|
import { render } from '/@/utils/common/renderUtils';
|
||||||
|
import { getFileAccessHttpUrl } from '/@/utils/common/compUtils';
|
||||||
|
|
||||||
|
// 列表页面公共参数、方法
|
||||||
|
export const columns: BasicColumn[] = [
|
||||||
|
{
|
||||||
|
title: '分类名称',
|
||||||
|
align: 'left',
|
||||||
|
dataIndex: 'categoryName',
|
||||||
|
width: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '分类编码',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'categoryCode',
|
||||||
|
width: 150,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '分类图标',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'icon',
|
||||||
|
width: 100,
|
||||||
|
customRender: ({ text }) => {
|
||||||
|
if (!text) return '';
|
||||||
|
const imgUrl = getFileAccessHttpUrl(text);
|
||||||
|
return render.renderImage(imgUrl, {
|
||||||
|
style: { width: '40px', height: '40px', objectFit: 'cover' },
|
||||||
|
preview: true,
|
||||||
|
fallback: '/src/assets/images/no-image.png'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '排序',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'sortOrder',
|
||||||
|
width: 80,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'status',
|
||||||
|
width: 100,
|
||||||
|
customRender: ({ text }) => {
|
||||||
|
const statusMap = {
|
||||||
|
'1': { text: '启用', color: 'green' },
|
||||||
|
'0': { text: '禁用', color: 'red' }
|
||||||
|
};
|
||||||
|
const status = statusMap[text] || { text: '未知', color: 'gray' };
|
||||||
|
return render.renderTag(status.text, status.color);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '描述',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'description',
|
||||||
|
width: 200,
|
||||||
|
ellipsis: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建时间',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'createTime',
|
||||||
|
width: 150,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// 查询数据
|
||||||
|
export const searchFormSchema: FormSchema[] = [
|
||||||
|
{
|
||||||
|
label: '分类名称',
|
||||||
|
field: 'categoryName',
|
||||||
|
component: 'Input',
|
||||||
|
colProps: { span: 6 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '分类编码',
|
||||||
|
field: 'categoryCode',
|
||||||
|
component: 'Input',
|
||||||
|
colProps: { span: 6 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '状态',
|
||||||
|
field: 'status',
|
||||||
|
component: 'JDictSelectTag',
|
||||||
|
componentProps: {
|
||||||
|
dictCode: 'valid_status',
|
||||||
|
placeholder: '请选择状态',
|
||||||
|
},
|
||||||
|
colProps: { span: 6 },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// 表单数据
|
||||||
|
export const formSchema: FormSchema[] = [
|
||||||
|
{
|
||||||
|
label: '',
|
||||||
|
field: 'id',
|
||||||
|
component: 'Input',
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '上级分类',
|
||||||
|
field: 'parentId',
|
||||||
|
component: 'JTreeSelect',
|
||||||
|
componentProps: {
|
||||||
|
dict: 'oroqen_product_category,category_name,id',
|
||||||
|
pidField: 'parent_id',
|
||||||
|
pidValue: '',
|
||||||
|
hasChildField: 'has_child',
|
||||||
|
placeholder: '请选择上级分类',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '分类名称',
|
||||||
|
field: 'categoryName',
|
||||||
|
component: 'Input',
|
||||||
|
required: true,
|
||||||
|
dynamicRules: ({ model, schema }) => {
|
||||||
|
return [{ required: true, message: '请输入分类名称!' }];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '分类编码',
|
||||||
|
field: 'categoryCode',
|
||||||
|
component: 'Input',
|
||||||
|
required: true,
|
||||||
|
dynamicRules: ({ model, schema }) => {
|
||||||
|
return [
|
||||||
|
{ required: true, message: '请输入分类编码!' },
|
||||||
|
{ pattern: /^[a-zA-Z0-9_]+$/, message: '编码只能包含字母、数字和下划线!' }
|
||||||
|
];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '分类图标',
|
||||||
|
field: 'icon',
|
||||||
|
component: 'JUpload',
|
||||||
|
componentProps: {
|
||||||
|
fileType: 'image',
|
||||||
|
maxSize: 2,
|
||||||
|
maxCount: 1,
|
||||||
|
bizPath: 'product/category/icon',
|
||||||
|
customRequest: (options) => {
|
||||||
|
const { file, onSuccess, onError } = options;
|
||||||
|
|
||||||
|
// 验证文件类型
|
||||||
|
const isImage = file.type.startsWith('image/');
|
||||||
|
if (!isImage) {
|
||||||
|
onError(new Error('只能上传图片文件!'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证文件大小
|
||||||
|
const isLt2M = file.size / 1024 / 1024 < 2;
|
||||||
|
if (!isLt2M) {
|
||||||
|
onError(new Error('图片大小不能超过2MB!'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建本地预览URL
|
||||||
|
const blobUrl = URL.createObjectURL(file);
|
||||||
|
|
||||||
|
// 模拟上传成功响应
|
||||||
|
setTimeout(() => {
|
||||||
|
onSuccess({
|
||||||
|
status: 'done',
|
||||||
|
url: blobUrl,
|
||||||
|
message: blobUrl,
|
||||||
|
response: {
|
||||||
|
success: true,
|
||||||
|
message: '上传成功',
|
||||||
|
result: {
|
||||||
|
url: blobUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '排序',
|
||||||
|
field: 'sortOrder',
|
||||||
|
component: 'InputNumber',
|
||||||
|
defaultValue: 0,
|
||||||
|
componentProps: {
|
||||||
|
min: 0,
|
||||||
|
placeholder: '请输入排序值',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '状态',
|
||||||
|
field: 'status',
|
||||||
|
component: 'JDictSelectTag',
|
||||||
|
defaultValue: '1',
|
||||||
|
componentProps: {
|
||||||
|
dictCode: 'valid_status',
|
||||||
|
placeholder: '请选择状态',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '描述',
|
||||||
|
field: 'description',
|
||||||
|
component: 'InputTextArea',
|
||||||
|
componentProps: {
|
||||||
|
rows: 3,
|
||||||
|
placeholder: '请输入分类描述',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
156
src/views/oroqen/product-category/OroqenProductCategoryList.vue
Normal file
156
src/views/oroqen/product-category/OroqenProductCategoryList.vue
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
<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"></Icon>
|
||||||
|
删除
|
||||||
|
</a-menu-item>
|
||||||
|
</a-menu>
|
||||||
|
</template>
|
||||||
|
<a-button>批量操作
|
||||||
|
<Icon icon="mdi:chevron-down"></Icon>
|
||||||
|
</a-button>
|
||||||
|
</a-dropdown>
|
||||||
|
</template>
|
||||||
|
<!--操作栏-->
|
||||||
|
<template #action="{ record }">
|
||||||
|
<TableAction :actions="getTableAction(record)" />
|
||||||
|
</template>
|
||||||
|
<!--字段回显插槽-->
|
||||||
|
<template #htmlSlot="{text}">
|
||||||
|
<div v-html="text"></div>
|
||||||
|
</template>
|
||||||
|
<!--省市区字段回显插槽-->
|
||||||
|
<template #pcaSlot="{text}">
|
||||||
|
{{ getAreaTextByCode(text) }}
|
||||||
|
</template>
|
||||||
|
<template #fileSlot="{text}">
|
||||||
|
<span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
|
||||||
|
<a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small" @click="downloadFile(text)">下载</a-button>
|
||||||
|
</template>
|
||||||
|
</BasicTable>
|
||||||
|
<!-- 表单区域 -->
|
||||||
|
<OroqenProductCategoryModal @register="registerModal" @success="handleSuccess"></OroqenProductCategoryModal>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" name="oroqen-product-category" setup>
|
||||||
|
import { ref, computed, unref } from 'vue';
|
||||||
|
import { BasicTable, useTable, TableAction } from '/@/components/Table';
|
||||||
|
import { useModal } from '/@/components/Modal';
|
||||||
|
import { useListPage } from '/@/hooks/system/useListPage';
|
||||||
|
import OroqenProductCategoryModal from './components/OroqenProductCategoryModal.vue';
|
||||||
|
import { columns, searchFormSchema } from './OroqenProductCategory.data';
|
||||||
|
import { queryTreeList, deleteOne, batchDelete, getImportUrl, getExportUrl } from './OroqenProductCategory.api';
|
||||||
|
import { downloadFile } from '/@/utils/common/renderUtils';
|
||||||
|
import { getAreaTextByCode } from '/@/components/Form/src/utils/Area';
|
||||||
|
|
||||||
|
const checkedKeys = ref<Array<string | number>>([]);
|
||||||
|
const [registerModal, { openModal }] = useModal();
|
||||||
|
const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
|
||||||
|
tableProps: {
|
||||||
|
title: '产品分类',
|
||||||
|
api: queryTreeList,
|
||||||
|
columns,
|
||||||
|
canResize: false,
|
||||||
|
isTreeTable: true,
|
||||||
|
pagination: false,
|
||||||
|
striped: false,
|
||||||
|
useSearchForm: true,
|
||||||
|
showTableSetting: true,
|
||||||
|
bordered: true,
|
||||||
|
showIndexColumn: false,
|
||||||
|
formConfig: {
|
||||||
|
labelWidth: 120,
|
||||||
|
schemas: searchFormSchema,
|
||||||
|
autoSubmitOnEnter: true,
|
||||||
|
},
|
||||||
|
actionColumn: {
|
||||||
|
width: 120,
|
||||||
|
fixed: 'right'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
exportApi: getExportUrl,
|
||||||
|
importApi: getImportUrl,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增事件
|
||||||
|
*/
|
||||||
|
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: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除事件
|
||||||
|
*/
|
||||||
|
async function handleDelete(record) {
|
||||||
|
await deleteOne({ id: record.id }, handleSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除事件
|
||||||
|
*/
|
||||||
|
async function batchHandleDelete() {
|
||||||
|
await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功回调
|
||||||
|
*/
|
||||||
|
function handleSuccess() {
|
||||||
|
(selectedRowKeys.value = []) && reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作栏
|
||||||
|
*/
|
||||||
|
function getTableAction(record) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
label: '编辑',
|
||||||
|
onClick: handleEdit.bind(null, record),
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
@ -0,0 +1,44 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<BasicForm @register="registerForm" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { BasicForm, useForm } from '/@/components/Form/index';
|
||||||
|
import { formSchema } from '../OroqenProductCategory.data';
|
||||||
|
import { saveOrUpdate } from '../OroqenProductCategory.api';
|
||||||
|
|
||||||
|
// Emits
|
||||||
|
const emit = defineEmits(['success', 'register']);
|
||||||
|
|
||||||
|
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
|
||||||
|
labelWidth: 100,
|
||||||
|
schemas: formSchema,
|
||||||
|
showActionButtonGroup: false,
|
||||||
|
actionColOptions: {
|
||||||
|
span: 23,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// 暴露内部方法
|
||||||
|
defineExpose({
|
||||||
|
setFieldsValue,
|
||||||
|
resetFields,
|
||||||
|
validate,
|
||||||
|
handleSubmit,
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交表单
|
||||||
|
*/
|
||||||
|
async function handleSubmit() {
|
||||||
|
try {
|
||||||
|
const values = await validate();
|
||||||
|
await saveOrUpdate(values, values.id);
|
||||||
|
emit('success');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('表单提交失败:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
@ -0,0 +1,172 @@
|
|||||||
|
<template>
|
||||||
|
<BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="getTitle" :width="800" @ok="handleSubmit">
|
||||||
|
<BasicForm @register="registerForm" name="OroqenProductCategoryForm" />
|
||||||
|
</BasicModal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { ref, computed, unref } from 'vue';
|
||||||
|
import { BasicModal, useModalInner } from '/@/components/Modal';
|
||||||
|
import { BasicForm, useForm } from '/@/components/Form/index';
|
||||||
|
import { formSchema } from '../OroqenProductCategory.data';
|
||||||
|
import { saveOrUpdate } from '../OroqenProductCategory.api';
|
||||||
|
import { defHttp } from '/@/utils/http/axios';
|
||||||
|
import { useMessage } from '/@/hooks/web/useMessage';
|
||||||
|
|
||||||
|
const { createMessage } = useMessage();
|
||||||
|
|
||||||
|
// Emits
|
||||||
|
const emit = defineEmits(['success', 'register']);
|
||||||
|
|
||||||
|
const isUpdate = ref(true);
|
||||||
|
const rowId = ref('');
|
||||||
|
|
||||||
|
// 表单配置
|
||||||
|
const [registerForm, { setProps, resetFields, setFieldsValue, validate }] = useForm({
|
||||||
|
labelWidth: 100,
|
||||||
|
baseColProps: { span: 24 },
|
||||||
|
schemas: formSchema,
|
||||||
|
showActionButtonGroup: false,
|
||||||
|
autoSubmitOnEnter: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// 表单赋值
|
||||||
|
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
||||||
|
// 重置表单
|
||||||
|
await resetFields();
|
||||||
|
setModalProps({ confirmLoading: false, showCancelBtn: !!data?.showFooter, showOkBtn: !!data?.showFooter });
|
||||||
|
isUpdate.value = !!data?.isUpdate;
|
||||||
|
|
||||||
|
if (unref(isUpdate)) {
|
||||||
|
rowId.value = data.record.id;
|
||||||
|
// 表单赋值
|
||||||
|
await setFieldsValue({
|
||||||
|
...data.record,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 隐藏底部时禁用整个表单
|
||||||
|
setProps({ disabled: !data?.showFooter });
|
||||||
|
});
|
||||||
|
|
||||||
|
// 表单标题
|
||||||
|
const getTitle = computed(() => (!unref(isUpdate) ? '新增' : '编辑'));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传blob文件
|
||||||
|
* @param filePath 文件路径或blob URL
|
||||||
|
* @param fieldName 字段名
|
||||||
|
* @returns 上传后的文件路径
|
||||||
|
*/
|
||||||
|
async function uploadBlobFile(filePath, fieldName) {
|
||||||
|
try {
|
||||||
|
console.log('处理文件:', filePath, '字段:', fieldName);
|
||||||
|
|
||||||
|
let file;
|
||||||
|
let fileName;
|
||||||
|
|
||||||
|
if (filePath.startsWith('blob:')) {
|
||||||
|
// 从blob URL获取文件
|
||||||
|
console.log('从blob URL获取文件');
|
||||||
|
const response = await fetch(filePath);
|
||||||
|
const blob = await response.blob();
|
||||||
|
fileName = `${fieldName}_${Date.now()}.${blob.type.split('/')[1] || 'jpg'}`;
|
||||||
|
file = new File([blob], fileName, { type: blob.type });
|
||||||
|
|
||||||
|
console.log('从blob URL创建的文件:', file);
|
||||||
|
} else {
|
||||||
|
console.log('非blob URL,可能是已存在的文件路径');
|
||||||
|
return filePath; // 返回原路径,可能是已存在的文件
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
throw new Error('无法获取文件对象');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确定业务路径
|
||||||
|
let bizPath = 'product-category/temp';
|
||||||
|
if (fieldName === 'icon') {
|
||||||
|
bizPath = 'product-category/icon';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 上传文件参数
|
||||||
|
const uploadParams = {
|
||||||
|
file: file,
|
||||||
|
name: 'file',
|
||||||
|
filename: fileName,
|
||||||
|
data: {
|
||||||
|
biz: bizPath
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('上传参数:', uploadParams);
|
||||||
|
|
||||||
|
// 上传文件
|
||||||
|
const uploadResult = await defHttp.uploadFile(
|
||||||
|
{
|
||||||
|
url: '/sys/common/upload',
|
||||||
|
timeout: 30000
|
||||||
|
},
|
||||||
|
uploadParams,
|
||||||
|
{
|
||||||
|
isReturnResponse: true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log('上传结果完整信息:', uploadResult);
|
||||||
|
|
||||||
|
// 处理可能的undefined情况
|
||||||
|
if (!uploadResult) {
|
||||||
|
console.error('上传结果为空或undefined');
|
||||||
|
throw new Error('上传失败:服务器未返回结果');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查上传结果 - 兼容不同的返回格式
|
||||||
|
const isSuccess = uploadResult && (
|
||||||
|
uploadResult.success === true ||
|
||||||
|
uploadResult.code === 0 ||
|
||||||
|
uploadResult.code === 200
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isSuccess) {
|
||||||
|
const filePath = uploadResult.message || uploadResult.result || uploadResult.data;
|
||||||
|
console.log('上传成功,文件路径:', filePath);
|
||||||
|
return filePath;
|
||||||
|
} else {
|
||||||
|
console.error('上传失败详细信息:', uploadResult);
|
||||||
|
throw new Error(uploadResult?.message || uploadResult?.error || '上传失败,请检查网络连接或联系管理员');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('上传文件失败:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 表单提交
|
||||||
|
async function handleSubmit() {
|
||||||
|
try {
|
||||||
|
setModalProps({ confirmLoading: true });
|
||||||
|
const values = await validate();
|
||||||
|
|
||||||
|
// 处理分类图标上传
|
||||||
|
if (values.icon && typeof values.icon === 'string' && values.icon.startsWith('blob:')) {
|
||||||
|
try {
|
||||||
|
const uploadResult = await uploadBlobFile(values.icon, 'icon');
|
||||||
|
values.icon = uploadResult;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('分类图标上传失败:', error);
|
||||||
|
throw new Error('分类图标上传失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await saveOrUpdate(values, values.id);
|
||||||
|
emit('success');
|
||||||
|
closeModal();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('表单提交失败:', error);
|
||||||
|
createMessage.error(error.message || '操作失败');
|
||||||
|
} finally {
|
||||||
|
setModalProps({ confirmLoading: false });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
104
src/views/oroqen/product/OroqenProduct.api.ts
Normal file
104
src/views/oroqen/product/OroqenProduct.api.ts
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
import { defHttp } from '/@/utils/http/axios';
|
||||||
|
import { useMessage } from '/@/hooks/web/useMessage';
|
||||||
|
|
||||||
|
const { createConfirm } = useMessage();
|
||||||
|
|
||||||
|
enum Api {
|
||||||
|
list = '/oroqen/product/list',
|
||||||
|
save = '/oroqen/product/add',
|
||||||
|
edit = '/oroqen/product/edit',
|
||||||
|
deleteOne = '/oroqen/product/delete',
|
||||||
|
deleteBatch = '/oroqen/product/deleteBatch',
|
||||||
|
importExcel = '/oroqen/product/importExcel',
|
||||||
|
exportXls = '/oroqen/product/exportXls',
|
||||||
|
queryById = '/oroqen/product/queryById',
|
||||||
|
listByCategory = '/oroqen/product/listByCategory',
|
||||||
|
featured = '/oroqen/product/featured',
|
||||||
|
hot = '/oroqen/product/hot',
|
||||||
|
checkStock = '/oroqen/product/checkStock',
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出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) => {
|
||||||
|
const url = isUpdate ? Api.edit : Api.save;
|
||||||
|
return defHttp.post({ url: url, params }, { isTransformResponse: false });
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
*/
|
||||||
|
export const queryById = (params) => {
|
||||||
|
return defHttp.get({ url: Api.queryById, params });
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据分类ID查询产品列表
|
||||||
|
*/
|
||||||
|
export const listByCategory = (params) => {
|
||||||
|
return defHttp.get({ url: Api.listByCategory, params });
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询推荐产品
|
||||||
|
*/
|
||||||
|
export const getFeaturedProducts = (params) => {
|
||||||
|
return defHttp.get({ url: Api.featured, params });
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询热销产品
|
||||||
|
*/
|
||||||
|
export const getHotProducts = (params) => {
|
||||||
|
return defHttp.get({ url: Api.hot, params });
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查库存
|
||||||
|
*/
|
||||||
|
export const checkStock = (params) => {
|
||||||
|
return defHttp.get({ url: Api.checkStock, params });
|
||||||
|
};
|
494
src/views/oroqen/product/OroqenProduct.data.ts
Normal file
494
src/views/oroqen/product/OroqenProduct.data.ts
Normal file
@ -0,0 +1,494 @@
|
|||||||
|
import { BasicColumn } from '/@/components/Table';
|
||||||
|
import { FormSchema } from '/@/components/Table';
|
||||||
|
import { h } from 'vue';
|
||||||
|
import { Image, Tag } from 'ant-design-vue';
|
||||||
|
import { render } from '/@/utils/common/renderUtils';
|
||||||
|
import { getFileAccessHttpUrl } from '/@/utils/common/compUtils';
|
||||||
|
|
||||||
|
//列表数据
|
||||||
|
export const columns: BasicColumn[] = [
|
||||||
|
{
|
||||||
|
title: '主图',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'mainImage',
|
||||||
|
width: 80,
|
||||||
|
customRender: ({ text, record }) => {
|
||||||
|
if (!text) return '-';
|
||||||
|
const imageUrl = getFileAccessHttpUrl(text);
|
||||||
|
|
||||||
|
return h(Image, {
|
||||||
|
src: imageUrl,
|
||||||
|
alt: record?.productName || '产品主图',
|
||||||
|
width: 50,
|
||||||
|
height: 50,
|
||||||
|
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: '产品名称',
|
||||||
|
dataIndex: 'productName',
|
||||||
|
width: 150,
|
||||||
|
align: 'left',
|
||||||
|
ellipsis: true,
|
||||||
|
fixed: 'left',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '产品编码',
|
||||||
|
dataIndex: 'productCode',
|
||||||
|
width: 120,
|
||||||
|
align: 'center',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '产品分类',
|
||||||
|
dataIndex: 'categoryId',
|
||||||
|
width: 120,
|
||||||
|
align: 'center',
|
||||||
|
// TODO: 这里可以关联分类表显示分类名称
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '价格',
|
||||||
|
dataIndex: 'price',
|
||||||
|
width: 100,
|
||||||
|
align: 'center',
|
||||||
|
customRender: ({ text }) => {
|
||||||
|
return text ? `¥${text}` : '-';
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '库存数量',
|
||||||
|
dataIndex: 'stock',
|
||||||
|
width: 100,
|
||||||
|
align: 'center',
|
||||||
|
customRender: ({ text }) => {
|
||||||
|
const color = text > 10 ? 'green' : text > 0 ? 'orange' : 'red';
|
||||||
|
return h(Tag, { color }, text || 0);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '销量',
|
||||||
|
dataIndex: 'salesCount',
|
||||||
|
width: 80,
|
||||||
|
align: 'center',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '产品状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
width: 100,
|
||||||
|
align: 'center',
|
||||||
|
customRender: ({ text }) => {
|
||||||
|
const statusMap = {
|
||||||
|
1: { text: '上架', color: 'green' },
|
||||||
|
0: { text: '下架', color: 'red' },
|
||||||
|
};
|
||||||
|
const status = statusMap[text] || { text: '未知', color: 'default' };
|
||||||
|
return render.renderTag(status.text, status.color);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '是否推荐',
|
||||||
|
dataIndex: 'isFeatured',
|
||||||
|
width: 100,
|
||||||
|
align: 'center',
|
||||||
|
customRender: ({ text }) => {
|
||||||
|
return text === 1 ? render.renderTag('推荐', 'blue') : render.renderTag('普通', 'default');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '是否热销',
|
||||||
|
dataIndex: 'isHot',
|
||||||
|
width: 100,
|
||||||
|
align: 'center',
|
||||||
|
customRender: ({ text }) => {
|
||||||
|
return text === 1 ? render.renderTag('热销', 'orange') : render.renderTag('普通', 'default');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建时间',
|
||||||
|
dataIndex: 'createTime',
|
||||||
|
width: 150,
|
||||||
|
align: 'center',
|
||||||
|
sorter: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
//查询数据
|
||||||
|
export const searchFormSchema: FormSchema[] = [
|
||||||
|
{
|
||||||
|
label: '产品名称',
|
||||||
|
field: 'productName',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入产品名称',
|
||||||
|
},
|
||||||
|
colProps: { span: 6 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '产品编码',
|
||||||
|
field: 'productCode',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入产品编码',
|
||||||
|
},
|
||||||
|
colProps: { span: 6 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '产品状态',
|
||||||
|
field: 'status',
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择产品状态',
|
||||||
|
options: [
|
||||||
|
{ label: '上架', value: 1 },
|
||||||
|
{ label: '下架', value: 0 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
colProps: { span: 6 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '是否推荐',
|
||||||
|
field: 'isFeatured',
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择是否推荐',
|
||||||
|
options: [
|
||||||
|
{ label: '推荐', value: 1 },
|
||||||
|
{ label: '普通', value: 0 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
colProps: { span: 6 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '是否热销',
|
||||||
|
field: 'isHot',
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择是否热销',
|
||||||
|
options: [
|
||||||
|
{ label: '热销', value: 1 },
|
||||||
|
{ label: '普通', value: 0 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
colProps: { span: 6 },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
//表单数据
|
||||||
|
export const formSchema: FormSchema[] = [
|
||||||
|
{
|
||||||
|
label: '',
|
||||||
|
field: 'id',
|
||||||
|
component: 'Input',
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '产品名称',
|
||||||
|
field: 'productName',
|
||||||
|
component: 'Input',
|
||||||
|
required: true,
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入产品名称',
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '产品编码',
|
||||||
|
field: 'productCode',
|
||||||
|
component: 'Input',
|
||||||
|
required: true,
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入产品编码',
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '分类ID',
|
||||||
|
field: 'categoryId',
|
||||||
|
component: 'Input',
|
||||||
|
required: true,
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入分类ID',
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '价格',
|
||||||
|
field: 'price',
|
||||||
|
component: 'InputNumber',
|
||||||
|
componentProps: {
|
||||||
|
min: 0,
|
||||||
|
precision: 2,
|
||||||
|
addonBefore: '¥',
|
||||||
|
placeholder: '请输入价格',
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '库存数量',
|
||||||
|
field: 'stock',
|
||||||
|
component: 'InputNumber',
|
||||||
|
componentProps: {
|
||||||
|
min: 0,
|
||||||
|
placeholder: '请输入库存数量',
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '销量',
|
||||||
|
field: 'salesCount',
|
||||||
|
component: 'InputNumber',
|
||||||
|
componentProps: {
|
||||||
|
min: 0,
|
||||||
|
placeholder: '请输入销量',
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '排序',
|
||||||
|
field: 'sortOrder',
|
||||||
|
component: 'InputNumber',
|
||||||
|
componentProps: {
|
||||||
|
min: 0,
|
||||||
|
placeholder: '请输入排序值',
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '产品状态',
|
||||||
|
field: 'status',
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择产品状态',
|
||||||
|
options: [
|
||||||
|
{ label: '上架', value: 1 },
|
||||||
|
{ label: '下架', value: 0 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '是否推荐',
|
||||||
|
field: 'isFeatured',
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择是否推荐',
|
||||||
|
options: [
|
||||||
|
{ label: '推荐', value: 1 },
|
||||||
|
{ label: '普通', value: 0 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '是否热销',
|
||||||
|
field: 'isHot',
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择是否热销',
|
||||||
|
options: [
|
||||||
|
{ label: '热销', value: 1 },
|
||||||
|
{ label: '普通', value: 0 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '材质',
|
||||||
|
field: 'material',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入材质',
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '规格参数',
|
||||||
|
field: 'specifications',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入规格参数',
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '重量(克)',
|
||||||
|
field: 'weight',
|
||||||
|
component: 'InputNumber',
|
||||||
|
componentProps: {
|
||||||
|
min: 0,
|
||||||
|
placeholder: '请输入重量',
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '尺寸',
|
||||||
|
field: 'dimensions',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入尺寸',
|
||||||
|
},
|
||||||
|
colProps: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '标签',
|
||||||
|
field: 'tags',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入标签,多个标签用逗号分隔',
|
||||||
|
},
|
||||||
|
colProps: { span: 24 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '产品描述',
|
||||||
|
field: 'description',
|
||||||
|
component: 'InputTextArea',
|
||||||
|
componentProps: {
|
||||||
|
rows: 4,
|
||||||
|
placeholder: '请输入产品描述',
|
||||||
|
},
|
||||||
|
colProps: { span: 24 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '文化故事',
|
||||||
|
field: 'culturalStory',
|
||||||
|
component: 'InputTextArea',
|
||||||
|
componentProps: {
|
||||||
|
rows: 3,
|
||||||
|
placeholder: '请输入文化故事',
|
||||||
|
},
|
||||||
|
colProps: { span: 24 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '工匠信息',
|
||||||
|
field: 'craftsmanInfo',
|
||||||
|
component: 'InputTextArea',
|
||||||
|
componentProps: {
|
||||||
|
rows: 3,
|
||||||
|
placeholder: '请输入工匠信息',
|
||||||
|
},
|
||||||
|
colProps: { span: 24 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '主图',
|
||||||
|
field: 'mainImage',
|
||||||
|
component: 'JUpload',
|
||||||
|
componentProps: {
|
||||||
|
fileType: 'image',
|
||||||
|
maxCount: 1,
|
||||||
|
maxSize: 5,
|
||||||
|
bizPath: 'product/main',
|
||||||
|
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: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '产品图片',
|
||||||
|
field: 'images',
|
||||||
|
component: 'JUpload',
|
||||||
|
componentProps: {
|
||||||
|
fileType: 'image',
|
||||||
|
maxCount: 8,
|
||||||
|
maxSize: 5,
|
||||||
|
bizPath: 'product/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: { span: 12 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '产品视频',
|
||||||
|
field: 'productVideo',
|
||||||
|
component: 'JUpload',
|
||||||
|
componentProps: {
|
||||||
|
fileType: 'video',
|
||||||
|
maxCount: 1,
|
||||||
|
maxSize: 50,
|
||||||
|
bizPath: 'product/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: { span: 24 },
|
||||||
|
},
|
||||||
|
];
|
168
src/views/oroqen/product/OroqenProductList.vue
Normal file
168
src/views/oroqen/product/OroqenProductList.vue
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
<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"></Icon>
|
||||||
|
删除
|
||||||
|
</a-menu-item>
|
||||||
|
</a-menu>
|
||||||
|
</template>
|
||||||
|
<a-button>批量操作
|
||||||
|
<Icon icon="mdi:chevron-down"></Icon>
|
||||||
|
</a-button>
|
||||||
|
</a-dropdown>
|
||||||
|
</template>
|
||||||
|
<!--操作栏-->
|
||||||
|
<template #action="{ record }">
|
||||||
|
<TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" />
|
||||||
|
</template>
|
||||||
|
<!--字段回显插槽-->
|
||||||
|
<template #htmlSlot="{text}">
|
||||||
|
<div v-html="text"></div>
|
||||||
|
</template>
|
||||||
|
</BasicTable>
|
||||||
|
<!-- 表单区域 -->
|
||||||
|
<OroqenProductModal @register="registerModal" @success="handleSuccess"></OroqenProductModal>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" name="oroqen-product" setup>
|
||||||
|
import { ref, computed, unref } from 'vue';
|
||||||
|
import { BasicTable, useTable, TableAction } from '/@/components/Table';
|
||||||
|
import { useModal } from '/@/components/Modal';
|
||||||
|
import { useListPage } from '/@/hooks/system/useListPage';
|
||||||
|
import OroqenProductModal from './components/OroqenProductModal.vue';
|
||||||
|
import { columns, searchFormSchema } from './OroqenProduct.data';
|
||||||
|
import { list, deleteOne, batchDelete, getImportUrl, getExportUrl } from './OroqenProduct.api';
|
||||||
|
import { downloadByOnlineUrl } from '/@/utils/file/download';
|
||||||
|
import { useMessage } from '/@/hooks/web/useMessage';
|
||||||
|
|
||||||
|
const checkedKeys = ref<Array<string | number>>([]);
|
||||||
|
const { createMessage } = useMessage();
|
||||||
|
|
||||||
|
//注册model
|
||||||
|
const [registerModal, { openModal }] = useModal();
|
||||||
|
//注册table数据
|
||||||
|
const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
|
||||||
|
tableProps: {
|
||||||
|
title: '产品',
|
||||||
|
api: list,
|
||||||
|
columns,
|
||||||
|
canResize: false,
|
||||||
|
formConfig: {
|
||||||
|
//labelWidth: 120,
|
||||||
|
schemas: searchFormSchema,
|
||||||
|
autoSubmitOnEnter: true,
|
||||||
|
showAdvancedButton: true,
|
||||||
|
fieldMapToNumber: [],
|
||||||
|
fieldMapToTime: [],
|
||||||
|
},
|
||||||
|
actionColumn: {
|
||||||
|
width: 120,
|
||||||
|
fixed: 'right'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
exportConfig: {
|
||||||
|
name: "产品",
|
||||||
|
url: getExportUrl,
|
||||||
|
},
|
||||||
|
importConfig: {
|
||||||
|
url: getImportUrl,
|
||||||
|
success: handleSuccess
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增事件
|
||||||
|
*/
|
||||||
|
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 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: '删除',
|
||||||
|
color: 'error',
|
||||||
|
popConfirm: {
|
||||||
|
title: '是否确认删除',
|
||||||
|
placement: 'topLeft',
|
||||||
|
confirm: handleDelete.bind(null, record),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
47
src/views/oroqen/product/components/OroqenProductForm.vue
Normal file
47
src/views/oroqen/product/components/OroqenProductForm.vue
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<template>
|
||||||
|
<div class="oroqen-product-form">
|
||||||
|
<BasicForm @register="registerForm" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { watch } from 'vue';
|
||||||
|
import { BasicForm, useForm } from '/@/components/Form/index';
|
||||||
|
import { formSchema } from '../OroqenProduct.data';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
formData: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const emit = defineEmits(['submit']);
|
||||||
|
|
||||||
|
//表单配置
|
||||||
|
const [registerForm, { setFieldsValue, validate, resetFields }] = useForm({
|
||||||
|
schemas: formSchema,
|
||||||
|
showActionButtonGroup: false,
|
||||||
|
baseColProps: { span: 24 }
|
||||||
|
});
|
||||||
|
|
||||||
|
// 监听表单数据变化
|
||||||
|
watch(() => props.formData, (newData) => {
|
||||||
|
if (newData && Object.keys(newData).length > 0) {
|
||||||
|
setFieldsValue(newData);
|
||||||
|
}
|
||||||
|
}, { immediate: true, deep: true });
|
||||||
|
|
||||||
|
// 暴露方法给父组件
|
||||||
|
defineExpose({
|
||||||
|
validate,
|
||||||
|
resetFields,
|
||||||
|
setFieldsValue
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.oroqen-product-form {
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
</style>
|
266
src/views/oroqen/product/components/OroqenProductModal.vue
Normal file
266
src/views/oroqen/product/components/OroqenProductModal.vue
Normal file
@ -0,0 +1,266 @@
|
|||||||
|
<template>
|
||||||
|
<BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit">
|
||||||
|
<BasicForm @register="registerForm" />
|
||||||
|
</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 '../OroqenProduct.data';
|
||||||
|
import { saveOrUpdate } from '../OroqenProduct.api';
|
||||||
|
import { useMessage } from '/@/hooks/web/useMessage';
|
||||||
|
import { getDateByPicker } from '/@/utils';
|
||||||
|
import { uploadFile } from '/@/api/common/api';
|
||||||
|
import { defHttp } from '/@/utils/http/axios';
|
||||||
|
|
||||||
|
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, width: "800px", 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 getTitle = computed(() => (!unref(isUpdate) ? '新增' : !unref(isDetail) ? '详情' : '编辑'));
|
||||||
|
|
||||||
|
//表单提交事件
|
||||||
|
async function handleSubmit(v) {
|
||||||
|
try {
|
||||||
|
let values = await validate();
|
||||||
|
// 预处理日期数据
|
||||||
|
changeDateValue(values);
|
||||||
|
setModalProps({ confirmLoading: true });
|
||||||
|
|
||||||
|
// 处理文件上传
|
||||||
|
await handleFileUploads(values);
|
||||||
|
|
||||||
|
//提交表单
|
||||||
|
await saveOrUpdate(values, isUpdate.value);
|
||||||
|
//关闭弹窗
|
||||||
|
closeModal();
|
||||||
|
//刷新列表
|
||||||
|
emit('success');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('表单提交失败:', error);
|
||||||
|
|
||||||
|
// 处理表单验证错误
|
||||||
|
if (error && error.errorFields) {
|
||||||
|
const firstField = error.errorFields[0];
|
||||||
|
if (firstField) {
|
||||||
|
scrollToField(firstField.name, { behavior: 'smooth', block: 'center' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 显示错误消息
|
||||||
|
if (error && error.message) {
|
||||||
|
createMessage.error(error.message);
|
||||||
|
} else if (typeof error === 'string') {
|
||||||
|
createMessage.error(error);
|
||||||
|
} else {
|
||||||
|
createMessage.error('操作失败,请重试');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重要:必须抛出错误,否则会导致未处理的Promise拒绝
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
setModalProps({ confirmLoading: false });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理文件上传
|
||||||
|
* @param formData 表单数据
|
||||||
|
*/
|
||||||
|
async function handleFileUploads(formData) {
|
||||||
|
console.log('开始处理文件上传,表单数据:', formData);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 查找所有需要处理文件上传的字段
|
||||||
|
const fileFields = ['mainImage', 'images', 'productVideo'];
|
||||||
|
|
||||||
|
for (const field of fileFields) {
|
||||||
|
// 如果字段有值且包含blob URL,说明有新文件需要上传
|
||||||
|
if (formData[field] && typeof formData[field] === 'string') {
|
||||||
|
const fieldValue = formData[field];
|
||||||
|
const filePaths = fieldValue.split(',').filter(path => path.trim());
|
||||||
|
|
||||||
|
for (const path of filePaths) {
|
||||||
|
if (path.startsWith('blob:')) {
|
||||||
|
// 这是一个需要处理的blob文件
|
||||||
|
console.log(`发现需要处理的blob文件: ${field} -> ${path}`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const uploadedPath = await uploadBlobFile(path, field);
|
||||||
|
// 替换表单数据中的blob URL为服务器路径
|
||||||
|
formData[field] = formData[field].replace(path, uploadedPath);
|
||||||
|
console.log(`文件上传成功,更新路径: ${path} -> ${uploadedPath}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`上传文件失败 (${field}):`, error);
|
||||||
|
createMessage.error(`上传文件失败: ${error.message}`);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('所有文件处理完成,最终表单数据:', formData);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('文件上传处理失败:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传blob文件
|
||||||
|
* @param filePath 文件路径或blob URL
|
||||||
|
* @param fieldName 字段名
|
||||||
|
* @returns 上传后的文件路径
|
||||||
|
*/
|
||||||
|
async function uploadBlobFile(filePath, fieldName) {
|
||||||
|
try {
|
||||||
|
console.log('处理文件:', filePath, '字段:', fieldName);
|
||||||
|
|
||||||
|
let file;
|
||||||
|
let fileName;
|
||||||
|
|
||||||
|
if (filePath.startsWith('blob:')) {
|
||||||
|
// 从blob URL获取文件
|
||||||
|
console.log('从blob URL获取文件');
|
||||||
|
const response = await fetch(filePath);
|
||||||
|
const blob = await response.blob();
|
||||||
|
fileName = `${fieldName}_${Date.now()}.${blob.type.split('/')[1] || 'jpg'}`;
|
||||||
|
file = new File([blob], fileName, { type: blob.type });
|
||||||
|
|
||||||
|
console.log('从blob URL创建的文件:', file);
|
||||||
|
} else {
|
||||||
|
console.log('非blob URL,可能是已存在的文件路径');
|
||||||
|
return filePath; // 返回原路径,可能是已存在的文件
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
throw new Error('无法获取文件对象');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确定业务路径
|
||||||
|
let bizPath = 'product/temp';
|
||||||
|
if (fieldName === 'mainImage') {
|
||||||
|
bizPath = 'product/main';
|
||||||
|
} else if (fieldName === 'images') {
|
||||||
|
bizPath = 'product/images';
|
||||||
|
} else if (fieldName === 'productVideo') {
|
||||||
|
bizPath = 'product/video';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 上传文件参数
|
||||||
|
const uploadParams = {
|
||||||
|
file: file,
|
||||||
|
name: 'file',
|
||||||
|
filename: fileName,
|
||||||
|
data: {
|
||||||
|
biz: bizPath
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('上传参数:', uploadParams);
|
||||||
|
console.log('上传参数详细信息:');
|
||||||
|
console.log('- file对象:', file);
|
||||||
|
console.log('- file.name:', file.name);
|
||||||
|
console.log('- file.size:', file.size);
|
||||||
|
console.log('- file.type:', file.type);
|
||||||
|
console.log('- bizPath:', bizPath);
|
||||||
|
|
||||||
|
// 上传文件
|
||||||
|
const uploadResult = await defHttp.uploadFile(
|
||||||
|
{
|
||||||
|
url: '/sys/common/upload',
|
||||||
|
timeout: 30000
|
||||||
|
},
|
||||||
|
uploadParams,
|
||||||
|
{
|
||||||
|
isReturnResponse: true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log('上传结果完整信息:', uploadResult);
|
||||||
|
console.log('上传结果类型:', typeof uploadResult);
|
||||||
|
|
||||||
|
// 处理可能的undefined情况
|
||||||
|
if (!uploadResult) {
|
||||||
|
console.error('上传结果为空或undefined');
|
||||||
|
throw new Error('上传失败:服务器未返回结果');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('上传结果success字段:', uploadResult?.success);
|
||||||
|
console.log('上传结果message字段:', uploadResult?.message);
|
||||||
|
console.log('上传结果code字段:', uploadResult?.code);
|
||||||
|
|
||||||
|
// 检查上传结果 - 兼容不同的返回格式
|
||||||
|
const isSuccess = uploadResult && (
|
||||||
|
uploadResult.success === true ||
|
||||||
|
uploadResult.code === 0 ||
|
||||||
|
uploadResult.code === 200
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isSuccess) {
|
||||||
|
const filePath = uploadResult.message || uploadResult.result || uploadResult.data;
|
||||||
|
console.log('上传成功,文件路径:', filePath);
|
||||||
|
return filePath;
|
||||||
|
} else {
|
||||||
|
console.error('上传失败详细信息:', {
|
||||||
|
result: uploadResult,
|
||||||
|
success: uploadResult?.success,
|
||||||
|
message: uploadResult?.message,
|
||||||
|
code: uploadResult?.code,
|
||||||
|
error: uploadResult?.error
|
||||||
|
});
|
||||||
|
throw new Error(uploadResult?.message || uploadResult?.error || '上传失败,请检查网络连接或联系管理员');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('上传文件失败:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理日期值
|
||||||
|
* @param formData 表单数据
|
||||||
|
*/
|
||||||
|
const changeDateValue = (formData) => {
|
||||||
|
if (formData && fieldPickers) {
|
||||||
|
for (let key in fieldPickers) {
|
||||||
|
if (formData[key]) {
|
||||||
|
formData[key] = getDateByPicker(formData[key], fieldPickers[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
Loading…
Reference in New Issue
Block a user