You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
172 lines
3.8 KiB
172 lines
3.8 KiB
2 months ago
|
import type { FormSchema } from '@/components/core/schema-form/';
|
||
|
import { TableListItem } from './columns';
|
||
|
import { commonUpload } from '@/api/upload';
|
||
|
import { message, Button } from 'ant-design-vue';
|
||
|
import { getFileExtension } from '@/utils/fileUtils';
|
||
|
import { UploadOutlined } from '@ant-design/icons-vue';
|
||
|
import { stateTypeList } from './data';
|
||
|
import { url } from 'inspector';
|
||
|
import component from '@/locales/lang/en-US/component';
|
||
|
// 编辑页字段
|
||
|
export const getEditFormSchema: (
|
||
|
row?: Partial<TableListItem>,
|
||
|
isDetail?: boolean,
|
||
|
) => FormSchema[] = (record = {}, isDetail = false) => {
|
||
|
return [
|
||
|
{
|
||
|
field: 'title',
|
||
|
component: 'Input',
|
||
|
label: '问题标题',
|
||
|
colProps: {
|
||
|
span: 12,
|
||
|
},
|
||
|
rules: [{ required: true }],
|
||
|
},
|
||
|
|
||
|
{
|
||
|
field: 'billcode',
|
||
|
component: 'Input',
|
||
|
label: '问题号',
|
||
|
colProps: {
|
||
|
span: 12,
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
field: 'customer',
|
||
|
component: 'Input',
|
||
|
label: '客户',
|
||
|
colProps: {
|
||
|
span: 12,
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
field: 'product',
|
||
|
component: 'Input',
|
||
|
label: '产品',
|
||
|
colProps: {
|
||
|
span: 12,
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
field: 'agent',
|
||
|
component: 'Input',
|
||
|
label: '代理商',
|
||
|
colProps: {
|
||
|
span: 12,
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
field: 'attribute',
|
||
|
component: 'Input',
|
||
|
label: '问题属性',
|
||
|
colProps: {
|
||
|
span: 12,
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
field: 'serviceNumber',
|
||
|
component: 'Input',
|
||
|
label: '服务号',
|
||
|
colProps: {
|
||
|
span: 12,
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
field: 'contacts',
|
||
|
component: 'Input',
|
||
|
label: '联系人',
|
||
|
colProps: {
|
||
|
span: 12,
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
field: 'contactsEmail',
|
||
|
component: 'Input',
|
||
|
label: '联系人邮箱',
|
||
|
colProps: {
|
||
|
span: 12,
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
field: 'contactsMobile',
|
||
|
component: 'Input',
|
||
|
label: '联系人手机号',
|
||
|
colProps: {
|
||
|
span: 12,
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
field: 'state',
|
||
|
component: 'Select',
|
||
|
label: '状态',
|
||
|
colProps: {
|
||
|
span: 12,
|
||
|
},
|
||
|
componentProps: {
|
||
|
options: stateTypeList,
|
||
|
},
|
||
|
rules: [{ required: true, type: 'number' }],
|
||
|
},
|
||
|
{
|
||
|
field: 'description',
|
||
|
component: 'InputTextArea',
|
||
|
componentProps: {
|
||
|
rows: 4,
|
||
|
placeholder: '请输入问题描述',
|
||
|
},
|
||
|
label: '问题描述',
|
||
|
colProps: {
|
||
|
span: 24,
|
||
|
},
|
||
|
rules: [{ required: true }],
|
||
|
},
|
||
|
{
|
||
|
label: '描述附件',
|
||
|
field: 'fileList',
|
||
|
component: 'Upload',
|
||
|
componentProps: {
|
||
|
disabled: isDetail,
|
||
|
customRequest: async (data) => {
|
||
|
console.log('data: ', data);
|
||
|
const formData = new FormData();
|
||
|
formData.append('file', data.file);
|
||
|
const res = await commonUpload(formData);
|
||
|
console.log('res: ', res);
|
||
|
data?.onSuccess && data?.onSuccess(res, data.file as any);
|
||
|
},
|
||
|
beforeUpload: (file) => {
|
||
|
console.log('file: ', file);
|
||
|
|
||
|
// 限制允许上传的文件类型
|
||
|
const allowedTypes = ['xlsx', 'xls', 'doc', 'docx', 'pdf'];
|
||
|
|
||
|
// 检查文件类型
|
||
|
const fileType = getFileExtension(file.name) || 'unknown';
|
||
|
if (!allowedTypes.includes(fileType)) {
|
||
|
// 文件类型不在允许列表中,拒绝上传
|
||
|
// 可以在这里展示错误信息
|
||
|
message.warning('文件类型不正确');
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
// 其他验证逻辑...
|
||
|
|
||
|
// 允许上传
|
||
|
return true;
|
||
|
},
|
||
|
},
|
||
|
componentSlots: {
|
||
|
default: () => (
|
||
|
<Button>
|
||
|
<UploadOutlined /> 点击上传
|
||
|
</Button>
|
||
|
),
|
||
|
},
|
||
|
colProps: {
|
||
|
span: 24,
|
||
|
},
|
||
|
rules: [{ required: false }],
|
||
|
},
|
||
|
] as any;
|
||
|
};
|