forked from Qi/Oroqen-Manage
数据管理基本实现
This commit is contained in:
parent
5d2a017e8f
commit
1fe792a910
@ -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>
|
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>
|
Loading…
Reference in New Issue
Block a user