Skip to content

Commit

Permalink
fix: 修复上传问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jianbing.chen committed Aug 9, 2024
1 parent 2868f3c commit 374b95d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 22 deletions.
11 changes: 4 additions & 7 deletions packages/editor/src/components/UploadImages/UploadImages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Upload } from 'antd';
import type { GetProp, UploadFile, UploadProps } from 'antd';
import { PlusOutlined, LoadingOutlined } from '@ant-design/icons';
import { message } from '@/utils/AntdGlobal';
import { uploadImg } from '@/api';
import styles from './index.module.less';

interface UploadImagesProps {
Expand Down Expand Up @@ -77,12 +78,8 @@ const UploadImages: React.FC<UploadImagesProps> = memo(
*/
const uploadRequest = (options: any) => {
setLoading(true);
/*uploadImg({
uploadImg({
file: options.file as File, // File 对象
onProgress(e) {
// 上传进度
console.log(e.percent);
},
})
.then((res) => {
const { name, url = '' } = res;
Expand All @@ -104,9 +101,9 @@ const UploadImages: React.FC<UploadImagesProps> = memo(
})
.catch(() => {
setLoading(false);
onChange('https://static.marsview.cn/image/05892524adf0c112f0e2e39887e7cc3991ec5ae9.png');
onChange('https://marsview.cdn.bcebos.com/mars-logo.png');
message.error('图片上传失败');
});*/
});
};
// 上传按钮
const uploadButton = (
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/layout/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const Header = memo(() => {
const res = await uploadImg({
file: file, // File 对象
});
return res;
return res.url;
} catch (error) {
console.error('封面图上传失败', error);
return '';
Expand Down
8 changes: 2 additions & 6 deletions packages/editor/src/packages/FormItems/Upload/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { UploadOutlined, LoadingOutlined, PlusOutlined } from '@ant-design/icons
import { Form, Button, Upload } from 'antd';
import { useEffect, useState, useImperativeHandle, forwardRef } from 'react';
import type { GetProp, UploadFile, UploadProps } from 'antd';
import { uploadImg } from '@/api';
import { message } from '@/utils/AntdGlobal';

/**
Expand Down Expand Up @@ -107,13 +108,9 @@ const UploadFC = ({ config, value, disabled, onChange }: any, ref: any) => {
*/
const uploadRequest = (options: any) => {
setLoading(true);
/*

uploadImg({
file: options.file as File, // File 对象
onProgress(e) {
// 上传进度
console.log(e.percent);
},
})
.then((res) => {
const { name, url = '' } = res;
Expand All @@ -137,7 +134,6 @@ const UploadFC = ({ config, value, disabled, onChange }: any, ref: any) => {
setLoading(false);
message.error('图片上传失败');
});
*/
};

// 根据listType和上传数量,动态处理上传按钮
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/pages/admin/config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ const Config: React.FC = memo(() => {
</Form.Item>
<h3>基础配置</h3>
<Form.Item label="项目名称" name="name" rules={[{ required: true, message: '请输入项目名称' }]}>
<Input placeholder={'项目名称: OMS'} {...props} />
<Input placeholder={'项目名称: Mars'} {...props} />
</Form.Item>
<Form.Item label="项目描述" name="remark" rules={[{ required: true, message: '请输入项目描述' }]}>
<Input.TextArea autoSize placeholder={'请输入项目描述'} maxLength={20} showCount={type !== 'detail'} {...props} />
</Form.Item>
<Form.Item label="LOGO" name="logo" rules={[{ required: true, message: '请上传项目Logo' }]}>
{/* {type === 'detail' ? <ImageFC /> : <UploadImages />} */}
{type === 'detail' ? <ImageFC /> : <UploadImages />}
<ImageFC />
</Form.Item>
<h3>系统配置</h3>
Expand Down
8 changes: 2 additions & 6 deletions packages/materials/FormItems/Upload/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { UploadOutlined, LoadingOutlined, PlusOutlined } from '@ant-design/icons
import { Form, Button, Upload } from 'antd';
import { useEffect, useState, useImperativeHandle, forwardRef } from 'react';
import type { GetProp, UploadFile, UploadProps } from 'antd';
import { uploadImg } from './../../api';
import { message } from '../../utils/AntdGlobal';

/**
Expand Down Expand Up @@ -106,13 +107,9 @@ const UploadFC = ({ config, value, disabled, onChange }: any) => {
*/
const uploadRequest = (options: any) => {
setLoading(true);
/*

uploadImg({
file: options.file as File, // File 对象
onProgress(e) {
// 上传进度
console.log(e.percent);
},
})
.then((res) => {
const { name, url = '' } = res;
Expand All @@ -136,7 +133,6 @@ const UploadFC = ({ config, value, disabled, onChange }: any) => {
setLoading(false);
message.error('图片上传失败');
});
*/
};

// 根据listType和上传数量,动态处理上传按钮
Expand Down
6 changes: 6 additions & 0 deletions packages/materials/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import request from './../utils/request';

// 图片上传
export const uploadImg = (params: any) => {
return request.post('http://mars-api.marsview.cc/api/upload/files', params, { 'Content-Type': 'multipart/form-data' });
};

0 comments on commit 374b95d

Please sign in to comment.