From 4fd3f8966a779272c869553e40a018f82eaeb393 Mon Sep 17 00:00:00 2001 From: gwbvipvip Date: Thu, 30 Nov 2023 18:44:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/device/deviceInfo/index.jsx | 21 +++-- src/pages/device/deviceInfo/services.js | 2 +- .../deviceVesion/components/CreateForm.jsx | 82 ++++++++++++++++++- src/pages/device/deviceVesion/index.jsx | 23 ++++-- src/pages/device/deviceVesion/services.js | 7 ++ src/pages/goods/goodsInfo/index.jsx | 1 + src/pages/goods/newgoods/index.jsx | 53 ++++++------ 7 files changed, 148 insertions(+), 41 deletions(-) diff --git a/src/pages/device/deviceInfo/index.jsx b/src/pages/device/deviceInfo/index.jsx index 102938f..d169b47 100644 --- a/src/pages/device/deviceInfo/index.jsx +++ b/src/pages/device/deviceInfo/index.jsx @@ -323,14 +323,21 @@ const GoodsTypeManage = () => { key="add" onClick={ async() => { - const response = await TechnologyTemplateExport(record.id); - const blob = new Blob([response]); - const url = URL.createObjectURL(blob); - console.log(blob, url); + const response = await TechnologyTemplateExport(record.id); + if(response==""){ + message.error('当前模板不存在!'); + return; + } + // const blob = new Blob([response]); + // const url = URL.createObjectURL(blob); + // console.log(blob, url); + // const link = document.createElement('a'); + // link.download = `工艺模板_${new Date(Date.now()).toLocaleString()}.xls`; + // link.href = url; + // link.click(); const link = document.createElement('a'); - link.download = `工艺模板_${new Date(Date.now()).toLocaleString()}.xls`; - link.href = url; - link.click(); + link.href = response; + link.click(); }} > 导出工艺模版 diff --git a/src/pages/device/deviceInfo/services.js b/src/pages/device/deviceInfo/services.js index 35bcaed..d5d10e8 100644 --- a/src/pages/device/deviceInfo/services.js +++ b/src/pages/device/deviceInfo/services.js @@ -204,7 +204,7 @@ export async function GetDeviceVesion(TypeCode) { export async function TechnologyTemplateExport(data) { return request(`/kitchen/api/goodes/TechnologyTemplateExport?deviceId=${data}`, { method: 'post', - responseType: 'blob' + // responseType: 'blob' }); } diff --git a/src/pages/device/deviceVesion/components/CreateForm.jsx b/src/pages/device/deviceVesion/components/CreateForm.jsx index c2e5f34..33cab84 100644 --- a/src/pages/device/deviceVesion/components/CreateForm.jsx +++ b/src/pages/device/deviceVesion/components/CreateForm.jsx @@ -1,8 +1,74 @@ import React from 'react'; -import { Modal, Form, Input, Button, Select } from 'antd'; +import { Modal, Form, Input, Button, Select,Upload} from 'antd'; +import { PlusOutlined, UploadOutlined } from '@ant-design/icons'; +import { GetCosRequestURL } from '../services'; +import axios from 'axios'; + const CreateForm = (props) => { + props.form.setFieldsValue(props.values); const { Option, OptGroup } = Select; + const uploadProp = { + name: 'file', + showUploadList: false, + multiple: false, + accept: '.xlsx, .xls', + // 这里需要指定文件上传的content-type + headers: { + 'Content-Type': 'application/octet-stream', + }, + customRequest({ + action, + file, + headers, + onError, + onProgress, + onSuccess, + withCredentials, + }) { + + console.log("上传图片", file); + //覆盖action 上传之前获取上传地址 + var index = file.name.lastIndexOf("."); + var ext = file.name.substr(index + 1); + + let fileData = null; + GetCosRequestURL({ directory: "goods", fileExtension: ext, method: "PUT" }).then((r) => { + action = r.allUrl; + const reader = new FileReader(); + reader.readAsArrayBuffer(file); + reader.onload = (e) => { + //console.log("fdasa","fdsafdsfdsafd"); + // 在文件读取结束后执行的操作 + fileData = e.target.result; + // 使用 axios 进行文件上传的请求 + axios.put(action, fileData, { + withCredentials, + headers, + onUploadProgress: ({ total, loaded }) => { + // 进行上传进度输出,更加直观 + onProgress({ percent: Math.round(loaded / total * 100).toFixed(2) }, file); + }, + }).then(response => { + console.log('onSuccess', response, file); + if (response.status == 200 || response.statusText == 'OK') { + props.form.setFieldsValue({ templatePath: r.seeUrl }); + } + // onSuccess(response, file); + }) + .catch(onError); + }; + }); + return { + abort() { + console.log('upload progress is aborted.'); + }, + }; + }, + //defaultFileList: props.location.query.values ? props.location.query.values : null + + }; + return ( {
+ + + + + + {} + + + +