diff --git a/src/app.tsx b/src/app.tsx index 04903e1..ecc45a7 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -218,12 +218,12 @@ export async function render(oldRender: () => void) { const checkRegion = 5 * 60 * 1000; export const request = { ...errorConfig, - baseURL: process.env.NODE_ENV === 'development' ? '' : 'https://qd.zhaopinzao8dian.com/api', + // baseURL: process.env.NODE_ENV === 'development' ? '' : 'https://qd.zhaopinzao8dian.com/api', // baseURL: 'http://39.98.44.136:8080', - // baseURL: - // process.env.NODE_ENV === 'development' - // ? 'http://10.213.6.207:19010' - // : 'http://10.213.6.207:19010/api', + baseURL: + process.env.NODE_ENV === 'development' + ? 'http://10.213.6.207:19010' + : 'http://10.213.6.207:19010/api', requestInterceptors: [ (url: any, options: { headers: any; data?: any; params?: any; method?: string }) => { const headers = options.headers ? options.headers : {}; diff --git a/src/pages/Management/List/edit.tsx b/src/pages/Management/List/edit.tsx index 15e0870..ded2c45 100644 --- a/src/pages/Management/List/edit.tsx +++ b/src/pages/Management/List/edit.tsx @@ -6,11 +6,14 @@ import { ProFormText, ProFormTextArea, ProDescriptions, + ProFormUploadButton, + ProFormRadio, } from '@ant-design/pro-components'; import { Form } from 'antd'; import React, { useEffect } from 'react'; import { DictValueEnumObj } from '@/components/DictTag'; import { getCmsCompanyList } from '@/services/company/list'; +import { cmsfileupload } from '@/services/Management/list'; export type ListFormProps = { onCancel: (flag?: boolean, formVals?: unknown) => void; @@ -20,15 +23,7 @@ export type ListFormProps = { educationEnum: DictValueEnumObj; experienceEnum: DictValueEnumObj; areaEnum: DictValueEnumObj; - mode?: 'view' | 'edit' | 'create'; -}; - -const waitTime = (time: number = 100) => { - return new Promise((resolve) => { - setTimeout(() => { - resolve(true); - }, time); - }); + mode?: 'view' | 'edit' | 'create'; }; const listEdit: React.FC = (props) => { @@ -36,16 +31,23 @@ const listEdit: React.FC = (props) => { const { educationEnum, experienceEnum, areaEnum } = props; const { mode = props.values ? 'edit' : 'create' } = props; useEffect(() => { - if(props.open){ + if (props.open) { form.resetFields(); - if (props.values) { - form.setFieldsValue({ - ...props.values, - jobLocationAreaCode: String(props.values.jobLocationAreaCode || ''), - }); + if (props.values) { + console.log('Setting form values:', props.values); + form.setFieldsValue({ + ...props.values, + jobLocationAreaCode: String(props.values.jobLocationAreaCode || ''), + isExplain: Number(props.values.isExplain ?? 0), + }); + } else { + // console.log('Setting default form values'); + // form.setFieldsValue({ + // isExplain: 0, + // }); + } } - } - }, [form, props.values?.jobId,props.open]); + }, [form, props.values, props.open]); const handleCancel = () => { props.onCancel(); @@ -53,12 +55,58 @@ const listEdit: React.FC = (props) => { }; const handleFinish = async (values: Record) => { - props.onSubmit(values as API.ManagementList.Manage); + const submitValues = { + ...values, + isExplain: values.isExplain ?? 0, + }; + props.onSubmit(submitValues as API.ManagementList.Manage); }; const handleChange = (_: string, value: any) => { form.setFieldValue('companyName', value.label); }; + + const customUpload = async (options: any) => { + const { file, onSuccess, onError } = options; + + if (!file) { + onError(new Error('文件不能为空')); + return; + } + + const formData = new FormData(); + formData.append('file', file); + + try { + const response = await cmsfileupload(formData); + + // Validate response structure + if (!response || typeof response !== 'object') { + throw new Error('上传响应格式错误'); + } + + if (response.code === 200) { + const fileUrl = typeof response.msg === 'string' ? response.msg : ''; + const coverUrl = typeof response.coverUrl === 'string' ? response.coverUrl : ''; + + if (fileUrl) { + (form as any).setFieldValue('explainUrl', fileUrl); + } + if (coverUrl) { + (form as any).setFieldValue('cover', coverUrl); + } + + onSuccess(response); + } else { + const errorMessage = typeof response.message === 'string' ? response.message : '上传失败'; + throw new Error(errorMessage); + } + } catch (error) { + console.error('File upload error:', error); + const errorMessage = error instanceof Error ? error.message : '上传过程中发生未知错误'; + onError(new Error(errorMessage)); + } + }; if (mode === 'view') { return ( = (props) => { modalProps={{ destroyOnClose: true, onCancel: () => handleCancel(), - footer: null, + footer: null, }} submitter={false} > - - column={2} - dataSource={props.values || {}} - > + column={2} dataSource={props.values || {}}> - - + - - + + + + + + + @@ -108,7 +164,6 @@ const listEdit: React.FC = (props) => { } return ( - title={mode === 'edit' ? '编辑岗位' : '新建岗位'} form={form} autoFocusFirstInput @@ -119,8 +174,13 @@ const listEdit: React.FC = (props) => { }} submitTimeout={2000} onFinish={handleFinish} + initialValues={{ + isExplain: 0, + }} > + + + + + + + ); }; diff --git a/src/pages/Management/List/index.tsx b/src/pages/Management/List/index.tsx index 17fbe12..d935617 100644 --- a/src/pages/Management/List/index.tsx +++ b/src/pages/Management/List/index.tsx @@ -220,6 +220,7 @@ function ManagementList() { onClick={() => { setModalVisible(true); setCurrentRow(record); + setMode('edit'); }} > 编辑 diff --git a/src/services/Management/list.ts b/src/services/Management/list.ts index 9015726..0dffb8c 100644 --- a/src/services/Management/list.ts +++ b/src/services/Management/list.ts @@ -57,3 +57,10 @@ export async function getJobTrend(params) { params: params }); } + +export async function cmsfileupload(params) { + return request(`/api/cms/file/upload`, { + method: 'POST', + data: params + }); +} diff --git a/src/types/Management/list.d.ts b/src/types/Management/list.d.ts index 2f5dd52..2a84233 100644 --- a/src/types/Management/list.d.ts +++ b/src/types/Management/list.d.ts @@ -7,6 +7,7 @@ declare namespace API.ManagementList { experience?: string; isApply?: number; isCollection?: number; + isExplain?: number; isHot?: number; jobId?: number; jobLocation?: string; @@ -31,6 +32,7 @@ declare namespace API.ManagementList { experience?: string; isApply?: number; isCollection?: number; + isExplain?: number; isHot?: number; jobId?: number; jobLocation?: string;