From 1fa1cfafe6823a806f37596d576e4779dca1be0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=91=9E=E5=AE=81?= <3134191406@qq.com> Date: Fri, 23 Feb 2024 14:00:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/proxy.ts | 2 +- src/pages/M063/PasswordManage/index.tsx | 7 - src/pages/M063/UnifyManage/index.tsx | 203 ++++++++++++++++-- .../MachineRegister/components/AddModal.tsx | 96 ++++++--- .../OffLineManage/ImportStep/index.tsx | 33 +-- src/pages/NodeInitTool/index.tsx | 136 +++++++----- .../OffLineManage/ImportStep/index.tsx | 24 +-- .../SecretManage/ReceiveSecret/index.tsx | 62 ++++-- .../SecretManage/SecretAssemble/index.tsx | 34 +-- src/pages/SecretManage/SecretInfo/index.tsx | 24 ++- src/services/device.ts | 12 ++ src/services/m063.ts | 8 + src/services/secret.ts | 17 ++ src/utils/env/dev.ts | 3 +- src/utils/request.ts | 16 +- 15 files changed, 488 insertions(+), 189 deletions(-) create mode 100644 src/services/device.ts create mode 100644 src/services/m063.ts create mode 100644 src/services/secret.ts diff --git a/config/proxy.ts b/config/proxy.ts index 4020ffc..d16c5cd 100644 --- a/config/proxy.ts +++ b/config/proxy.ts @@ -1,6 +1,6 @@ import GlobalConfig from '../src/utils/env/dev'; const proxy = { - '/xgd': { + '/055': { target: GlobalConfig['PROXY_SERVER'], changeOrigin: true, withCredentials: true, diff --git a/src/pages/M063/PasswordManage/index.tsx b/src/pages/M063/PasswordManage/index.tsx index a1b0a52..c42635e 100644 --- a/src/pages/M063/PasswordManage/index.tsx +++ b/src/pages/M063/PasswordManage/index.tsx @@ -73,41 +73,34 @@ const MachineRegister: FC = ({ }) => { dataIndex: 'school_info', key: 'school_info', ellipsis: true, - render: (text: any, record: any, index: any) => {text.name} }, { title: '设备编号', dataIndex: 'department_info', key: 'department_info', ellipsis: true, - render: (text: any, record: any, index: any) => {text.name} }, { title: '设备名称', dataIndex: 'teacher_count', key: 'teacher_count', width: 90, ellipsis: true, - render: (text: any, record: any) => { history.push(`/colleges/${record?.school_info?.id}/statistics`) }}>{text} }, { title: '工作状态', dataIndex: 'student_count', key: 'student_count', width: 90, ellipsis: true, - render: (text: any, record: any) => { history.push(`/colleges/${record?.school_info?.id}/statistics`) }}>{text} }, { title: '使用单位', dataIndex: 'type_cn', key: 'type_cn', width: 100, ellipsis: true, - render: (text: any) => {text} }, { title: '监控日志', dataIndex: 'service_end_time', key: 'service_end_time', ellipsis: true, - render: (text: any, record: any, index: any) => {(record?.service_start_time && record?.service_end_time) ? `${moment(record?.service_start_time).format('YYYY-MM-DD HH:mm')} - ${moment(record?.service_end_time).format('YYYY-MM-DD HH:mm')}` : '--'} },] // 查找 diff --git a/src/pages/M063/UnifyManage/index.tsx b/src/pages/M063/UnifyManage/index.tsx index 55b54be..f7f9a1f 100644 --- a/src/pages/M063/UnifyManage/index.tsx +++ b/src/pages/M063/UnifyManage/index.tsx @@ -4,7 +4,8 @@ import ButtonComp from '@/components/ButtonComp'; import ClearInfoDialog from '@/components/ClearInfoDialog'; import NodeInitWrap from '@/components/NodeInitWrap'; import ContentWarp from '@/components/ContentWarp'; -import { Button, ConfigProvider, Form, Input, Modal, Radio, Upload,UploadProps, Checkbox, message, Space,Select } from 'antd'; +import { Modal, Radio, Upload, UploadProps, message, Table } from 'antd'; +import { device_keyImport } from '@/services/m063'; interface PageProps { @@ -13,29 +14,192 @@ interface PageProps { const NodeInitTool: FC = ({ }) => { const [fileOpen, setFileOpen] = useState(true); + + const [params, setParams] = useState({ + page: 1, + limit: 10, + mdepart: null, //设备使用单位 + mposition: null,//设备部署地点 + mstate: null,//设备使用状态 + midentifer: null,// 密码实体标识 + mnumber: null,//上级设备编号 + }); + const [clearAll, setclearAll] = useState(false) // 点击复位按钮时所有的chebox都变为false + const [result, setResult] = useState({}) + const [addModalVisible, setAddModalVisible] = useState(false) //控制新增弹窗显隐 + + const urlParams = useParams(); + + let sysInfo = localStorage.getItem(`${urlParams?.fileType}`); + let info = sysInfo ? JSON.parse(sysInfo) : null; + + useEffect(() => { + + }, []) + const uploadprops: UploadProps = { maxCount: 1, beforeUpload: (file: any) => { const formData = new FormData(); - formData.append('file', file, '11'); + formData.append('file', file); console.log("file--", file) console.log("formData--", formData) - // secretInit_loadData(formData).then((res) => { - // if (res?.result == "success" && res?.data.length > 0) { - // message.success('加载数据成功'); - // form.setFieldsValue({ ...res?.data[0] }) - // localStorage.setItem('MMJInit', JSON.stringify(res?.data[0])); - // setDataLoading(true); - // } else { - // message.error(res?.errorMsg); - // } - // }) + const body={ + device:{ + createTime:'11', + deviceEntityIdentifier:'22', + deviceName:'33', + id:'44', + log:'55', + unit:'66', + updateTime:'77', + workStatus:'88', + }, + endDate:'99', + keywords:'01', + orderDirection:'02', + orderField:'03', + pageNumber:'04', + pageSize:'05', + pageStart:'06', + startDate:'07', + } + device_keyImport({...body}).then((res) => { + if (res?.result == "success" && res?.data.length > 0) { + message.success('加载数据成功'); + + // form.setFieldsValue({ ...res?.data[0] }) + // localStorage.setItem('MMJInit', JSON.stringify(res?.data[0])); + // setDataLoading(true); + } else { + message.error(res?.errorMsg); + } + }) } }; + const columns = [{ + title: '序号', + dataIndex: 'name', + key: 'name', + ellipsis: true, + fixed: 'left', + width: 60, + render: (text: any, record: any, index: any) => { + return ( + {params.limit * (params.page - 1) + index + 1} + ) + } + }, { + title: '设备实体标识', + dataIndex: 'school_info', + key: 'school_info', + ellipsis: true, + }, { + title: '设备编号', + dataIndex: 'department_info', + key: 'department_info', + ellipsis: true, + }, { + title: '设备名称', + dataIndex: 'teacher_count', + key: 'teacher_count', + width: 90, + ellipsis: true, + }, { + title: '工作状态', + dataIndex: 'student_count', + key: 'student_count', + width: 90, + ellipsis: true, + }, { + title: '使用单位', + dataIndex: 'type_cn', + key: 'type_cn', + width: 100, + ellipsis: true, + }, { + title: '监控日志', + dataIndex: 'service_end_time', + key: 'service_end_time', + ellipsis: true, + },] + + // 查找 + const handleSearch = () => { + console.log("params-", params) + + } + + // 复位 + const handleClear = () => { + params.mdepart = null; + params.mposition = null; + params.mstate = null; + params.midentifer = null; + params.mnumber = null; + setParams({ ...params }) + setclearAll(true) + } + + const getList = () => { + + } + + // 查询条件改变时设置参数 + const handleChange = (value: any, param: string) => { + params[`${param}`] = value; + setParams({ ...params }) + setclearAll(false) + } + + + return ( -
+
+ +
+ { + params.page = page; + params.limit = pagesize; + setParams({ ...params }); + getList(); + }, + total: result?.count, + showTotal: (total, range) => {total} 条数据 + }} + /> + + +
+
+ { }} /> + { }} /> + { }} /> + { }} /> +
+
+ { setAddModalVisible(true) }} /> + { }} /> + { }} /> + { }} /> +
+
+ = ({ }) => { setFileOpen(false) }} > -
导入类型
-
- - - -
+
导入类型
+
+ + + +
{ @@ -59,6 +223,7 @@ const NodeInitTool: FC = ({ }) => { }} />
+ ) diff --git a/src/pages/MachineManage/MachineRegister/components/AddModal.tsx b/src/pages/MachineManage/MachineRegister/components/AddModal.tsx index fa392d8..32ecc11 100644 --- a/src/pages/MachineManage/MachineRegister/components/AddModal.tsx +++ b/src/pages/MachineManage/MachineRegister/components/AddModal.tsx @@ -1,6 +1,7 @@ import React, { useEffect, useState, useRef } from 'react'; -import { Modal, Form, Input } from 'antd'; +import { Modal, Form, Input,message,DatePicker } from 'antd'; import ButtonComp from '@/components/ButtonComp'; +import { addPasswordDeviceInfo } from '@/services/device'; interface PageProps { title?: string; @@ -17,6 +18,39 @@ const AddModal = ({ ...props }: PageProps) => { const [form] = Form.useForm(); + const passwordDeviceInfo= { + "belongCryptoSystem": "string", + "communicationAddressType": "string", + "createTime": "string", + "deviceAliases": "string", + "equipmentDeploymentLocation": "string", + "equipmentManagementUnit": "string", + "equipmentManufacturer": "string", + "equipmentType": "string", + "equipmentUserUnit": "string", + "id": 0, + "isolatorExternalNetworkIp": "string", + "memo": "string", + "passwordDeviceNumber": "string", + "passwordDeviceSerialNumber": "string", + "passwordEntityIdentifier": "string", + "registrationDate": "string", + "superiorEquipmentNumber": "string", + "sysType": "string", + "updateTime": "string" + }; + + const onFinish = (values: any) => { + values.registrationDate=values['registrationDate'].format('YYYY-MM-DD'), + addPasswordDeviceInfo({...values,passwordDeviceInfo}).then((res) => { + if (res?.result == "success") { + message.success('新增成功'); + form.resetFields(); + } else { + message.error(res?.errorMsg); + } + }) + }; return ( <> @@ -28,63 +62,69 @@ const AddModal = ({ onCancel={onCancel} footer={null} maskClosable={false} - > - + - +
- + - { }} /> + {/* { }} /> */}
- - + +
(如0000001)
- - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - - + + + + +
- + { + form.submit(); + // onOk(); + }} />
diff --git a/src/pages/MachineManage/OffLineManage/ImportStep/index.tsx b/src/pages/MachineManage/OffLineManage/ImportStep/index.tsx index 1ff5dff..dda1ad4 100644 --- a/src/pages/MachineManage/OffLineManage/ImportStep/index.tsx +++ b/src/pages/MachineManage/OffLineManage/ImportStep/index.tsx @@ -5,10 +5,12 @@ import ClearInfoDialog from '@/components/ClearInfoDialog'; import { getPlugCordResult } from '@/services/api'; import { validateNumber } from '@/utils/validate'; import theme from '@/styles/antd.theme'; -import { Radio, Space, Upload, UploadProps, } from 'antd'; +import { Radio, Space, Upload, UploadProps, message,} from 'antd'; import styles from './index.less'; import StepHeader from '@/components/StepHeader'; import ContentWarp from '@/components/ContentWarp'; +import {offlineImport} from '@/services/device'; +import { fileStr, sysType,sysTypeStr } from '@/utils/sysType'; interface PageProps { data: Array<{ @@ -26,23 +28,24 @@ interface PageProps { const ImportStep: FC = ({ }) => { const [step, setStep] = useState(2) - const uploadprops: UploadProps = { + const props: UploadProps = { maxCount: 1, beforeUpload: (file: any) => { + let str: string = sysType[urlParams?.fileType] + fileStr[urlParams?.fileType] const formData = new FormData(); - formData.append('file', file, '11'); - console.log("file--", file) + formData.append('file', file); + formData.append('sysType ', sysTypeStr[str]); console.log("formData--", formData) - // secretInit_loadData(formData).then((res) => { - // if (res?.result == "success" && res?.data.length > 0) { - // message.success('加载数据成功'); - // form.setFieldsValue({ ...res?.data[0] }) - // localStorage.setItem('MMJInit', JSON.stringify(res?.data[0])); - // setDataLoading(true); - // } else { - // message.error(res?.errorMsg); - // } - // }) + offlineImport(formData).then((res) => { + if (res?.result == "success" && res?.data.length > 0) { + message.success('加载数据成功'); + // form.setFieldsValue({ ...res?.data[0] }) + // localStorage.setItem('MMJInit', JSON.stringify(res?.data[0])); + // setDataLoading(true); + } else { + message.error(res?.errorMsg); + } + }) } }; @@ -61,7 +64,7 @@ const ImportStep: FC = ({ }) => {
{ }} /> { history.back() }} /> - + { }} /> diff --git a/src/pages/NodeInitTool/index.tsx b/src/pages/NodeInitTool/index.tsx index 32509e9..0e0cf13 100644 --- a/src/pages/NodeInitTool/index.tsx +++ b/src/pages/NodeInitTool/index.tsx @@ -4,17 +4,17 @@ import ButtonComp from '@/components/ButtonComp'; import ClearInfoDialog from '@/components/ClearInfoDialog'; import NodeInitWrap from '@/components/NodeInitWrap'; import ContentWarp from '@/components/ContentWarp'; -import { - Button, - ConfigProvider, - Form, - Input, - Modal, - Radio, - Checkbox, - message, +import { + Button, + ConfigProvider, + Form, + Input, + Modal, + Radio, + Checkbox, + message, Space, - Select, + Select, UploadProps, Upload, } from 'antd'; @@ -23,6 +23,7 @@ import styles from './index.less'; import DEV from '@/utils/env/dev'; import { countType, fileStr, sysType, sysTypeStr } from '@/utils/sysType'; import { nodeInit_step2, nodeInit_step4 } from '@/services/nodeinit'; +import moment from 'moment' interface PageProps { @@ -32,13 +33,13 @@ const NodeInitTool: FC = ({ }) => { const urlParams = useParams(); const [authOpen, setAuthOpen] = useState(false); - const [stepOpen,setStepOpen] = useState(false); + const [stepOpen, setStepOpen] = useState(false); const [step, setStep] = useState(1) + const [pin, setPin] = useState(''); const [radioValue, setRadioValue] = useState(1) const [configRadio, setConfigRadio] = useState(1) - const [curform] = Form.useForm(); - const [preform] = Form.useForm(); + const [form] = Form.useForm(); const [fileInfo, setFileInfo] = useState({ "secret": "", @@ -66,9 +67,9 @@ const NodeInitTool: FC = ({ }) => { useEffect(() => { installSuccess() - if(info?.auth === 'admin'){ + if (info?.pingLoginStatus) { setStepOpen(true); - }else{ + } else { setAuthOpen(true) } }, []) @@ -80,13 +81,12 @@ const NodeInitTool: FC = ({ }) => { const formData = new FormData(); formData.append('file', file); formData.append('sysType ', sysTypeStr[str]); - console.log("formData--",formData) nodeInit_step2(formData).then((res) => { if (res?.result == "success" && res?.data.length > 0) { message.success('数据加载成功') - console.log("res--",res) + console.log("res--", res) setFileInfo(res?.data[0]); - localStorage.setItem(`${urlParams?.fileType}`, JSON.stringify({ ...info, deviceInit: {data: res?.data[0], install: false} })); + localStorage.setItem(`${urlParams?.fileType}`, JSON.stringify({ ...info, deviceInit: { data: res?.data[0], install: false } })); // setDataLoading(true); } else { message.error(res?.errorMsg); @@ -115,6 +115,21 @@ const NodeInitTool: FC = ({ }) => { } + const onFinish = (values: any) => { + nodeInit_step4({ + ...values, + updateTime: moment().format('YYYY-MM-DD HH:mm:ss') + }).then((res) => { + if (res?.result == "success") { + message.success('初始化成功'); + form.resetFields(); + } else { + message.error(res?.errorMsg); + } + }) + }; + + return (
= ({ }) => { >
口令
-
+
+ setPin(e.target.value)} /> +
@@ -137,8 +154,16 @@ const NodeInitTool: FC = ({ }) => { setAuthOpen(false) }} /> { - setAuthOpen(false) - setStepOpen(true) + if (pin == 'admin') { + setPin('') + setStep(1) + // 记录登陆成功状态 + localStorage.setItem(`${urlParams?.fileType}`, JSON.stringify({ ...info, pingLoginStatus: true, layoutInfo: null })) + setAuthOpen(false) + setStepOpen(true) + } else { + message.error('口令错误,请重新输入') + } }} />
@@ -232,30 +257,34 @@ const NodeInitTool: FC = ({ }) => { prebtn={true} cancelbtn={true} onNext={() => (setStep(4))} - onPre={() => (setStep(2))} + onPre={() => (setStep(3))} + onFinish={() => { + form.submit() + }} >
-
-
-
本级设备基本信息
-
-
+ {/*
*/} +
+ +
+
+
本级设备基本信息
+
- -
-
-
-
上级设备基本信息
-
-
+
+
上级设备基本信息
- - +
-
+
diff --git a/src/pages/SecretManage/OffLineManage/ImportStep/index.tsx b/src/pages/SecretManage/OffLineManage/ImportStep/index.tsx index 1ff5dff..2fc0309 100644 --- a/src/pages/SecretManage/OffLineManage/ImportStep/index.tsx +++ b/src/pages/SecretManage/OffLineManage/ImportStep/index.tsx @@ -5,11 +5,11 @@ import ClearInfoDialog from '@/components/ClearInfoDialog'; import { getPlugCordResult } from '@/services/api'; import { validateNumber } from '@/utils/validate'; import theme from '@/styles/antd.theme'; -import { Radio, Space, Upload, UploadProps, } from 'antd'; +import { Radio, Space, Upload, UploadProps, message} from 'antd'; import styles from './index.less'; import StepHeader from '@/components/StepHeader'; import ContentWarp from '@/components/ContentWarp'; - +import {offlineImport} from '@/services/device'; interface PageProps { data: Array<{ // 菜单名称 @@ -33,16 +33,16 @@ const ImportStep: FC = ({ }) => { formData.append('file', file, '11'); console.log("file--", file) console.log("formData--", formData) - // secretInit_loadData(formData).then((res) => { - // if (res?.result == "success" && res?.data.length > 0) { - // message.success('加载数据成功'); - // form.setFieldsValue({ ...res?.data[0] }) - // localStorage.setItem('MMJInit', JSON.stringify(res?.data[0])); - // setDataLoading(true); - // } else { - // message.error(res?.errorMsg); - // } - // }) + offlineImport(formData).then((res) => { + if (res?.result == "success" && res?.data.length > 0) { + message.success('导入成功'); + // form.setFieldsValue({ ...res?.data[0] }) + localStorage.setItem('MMJInit', JSON.stringify(res?.data[0])); + // setDataLoading(true); + } else { + message.error(res?.errorMsg); + } + }) } }; diff --git a/src/pages/SecretManage/ReceiveSecret/index.tsx b/src/pages/SecretManage/ReceiveSecret/index.tsx index 5fdbe90..e6a90bb 100644 --- a/src/pages/SecretManage/ReceiveSecret/index.tsx +++ b/src/pages/SecretManage/ReceiveSecret/index.tsx @@ -1,8 +1,10 @@ import { FC, useEffect, useState } from 'react'; import { history, useLocation, useParams } from 'umi'; -import { Form, Input, Select, Button, Row, Col } from 'antd'; +import { Form, Input, Select, Button, Row, Col, Upload,message } from 'antd'; // import styles from './index.less'; import ContentWarp from '@/components/ContentWarp'; +import { UploadOutlined } from '@ant-design/icons'; +import {device_keyImport} from '@/services/secret'; interface PageProps { data: Array<{ @@ -21,38 +23,62 @@ const ReceiveSecret: FC = ({ }) => { const [form] = Form.useForm(); const formItemSty = { width: 'auto', marginBottom: 20, marginRight: 30 }; - const onFinish = () => { - + const onFinish = (values: any) => { + device_keyImport({...values}).then((res) => { + if (res?.result == "success") { + message.success('密钥接收成功!'); + form.resetFields(); + } else { + message.error(res?.errorMsg); + } + }) } + const normFile = (e: any) => { + console.log('Upload event:', e); + if (Array.isArray(e)) { + return e; + } + return e?.fileList; + }; + + return (
- - - - - + + + - - - - + + + + + +
请选择从机要局申请的预制密钥体数据文件
- -
= ({ }) => { setParams({ ...params }); getList(); }, - total: result?.count, + total: result?.length, showTotal: (total, range) => {total} 条数据 }} /> diff --git a/src/pages/SecretManage/SecretInfo/index.tsx b/src/pages/SecretManage/SecretInfo/index.tsx index 0aecafe..ad7d0c3 100644 --- a/src/pages/SecretManage/SecretInfo/index.tsx +++ b/src/pages/SecretManage/SecretInfo/index.tsx @@ -1,16 +1,17 @@ import { FC, useEffect, useState } from 'react'; import { history, useLocation, useParams } from 'umi'; -import { Table, Input } from 'antd'; +import { Table, Input, message } from 'antd'; // import styles from './index.less'; import ContentWarp from '@/components/ContentWarp'; import ButtonComp from '@/components/ButtonComp'; +import {device_secretList} from '@/services/secret'; interface PageProps { } const ReceiveSecret: FC = ({ }) => { - const [result, setResult] = useState({}); + const [result, setResult] = useState([]); const [params, setParams] = useState({ page: 1, limit: 10, @@ -33,13 +34,11 @@ const ReceiveSecret: FC = ({ }) => { dataIndex: 'school_info', key: 'school_info', ellipsis: true, - render: (text: any, record: any, index: any) => {text.name} }, { title: '密钥编号', dataIndex: 'department_info', key: 'department_info', ellipsis: true, - render: (text: any, record: any, index: any) => {text.name} }, { title: '密钥组长', dataIndex: 'teacher_count', @@ -61,9 +60,20 @@ const ReceiveSecret: FC = ({ }) => { },] const getList = () => { - + device_secretList({}).then((res) => { + if (res?.result == "success") { + // message.success('密钥接收成功!'); + setResult([...res?.data]) + } else { + message.error(res?.errorMsg); + } + }) } + useEffect(()=>{ + getList() + },[]) + const handleSearch = () => { } @@ -75,7 +85,7 @@ const ReceiveSecret: FC = ({ }) => {
= ({ }) => { setParams({ ...params }); getList(); }, - total: result?.count, + total: result?.length, showTotal: (total, range) => {total} 条数据 }} /> diff --git a/src/services/device.ts b/src/services/device.ts new file mode 100644 index 0000000..8b45c5f --- /dev/null +++ b/src/services/device.ts @@ -0,0 +1,12 @@ +import { getRequest, postRequest, uploadFile } from '@/utils/request'; + +// 设备管理 - 密码设备信息----新增 +export async function addPasswordDeviceInfo(data: any) { + return postRequest(`/055/device/addPasswordDeviceInfo`, data); +} +// 离线管理--导入 +export async function offlineImport(data: any) { + return postRequest(`/055/device/offlineManagement`, data); +} + + diff --git a/src/services/m063.ts b/src/services/m063.ts new file mode 100644 index 0000000..e4073ec --- /dev/null +++ b/src/services/m063.ts @@ -0,0 +1,8 @@ +import { getRequest, postRequest, uploadFile } from '@/utils/request'; + +// 一体化管理- 导入 +export async function device_keyImport(data: any) { + return postRequest(`/063/keyImport`, data); +} + + diff --git a/src/services/secret.ts b/src/services/secret.ts new file mode 100644 index 0000000..92ca801 --- /dev/null +++ b/src/services/secret.ts @@ -0,0 +1,17 @@ +import { getRequest, postRequest, uploadFile } from '@/utils/request'; + +// 接收预制秘钥--导入 +export async function device_keyImport(data: any) { + return postRequest(`/055/device/keyImport`, data); +} + +// 预制秘钥信息列表 +export async function device_secretList(data: any) { + return getRequest(`/055/device/secretList`, data); +} + +// 秘钥装配列表 +export async function device_secretInstallList(data: any) { + return getRequest(`/055/device/secretInstallList`, data); +} + diff --git a/src/utils/env/dev.ts b/src/utils/env/dev.ts index f55cb3b..f8cd2e4 100644 --- a/src/utils/env/dev.ts +++ b/src/utils/env/dev.ts @@ -2,7 +2,8 @@ export const DEV = { PROXY_SERVER: 'http://localhost:8088', // PROXY_SERVER: 'http://127.0.0.1:8088', LOCAL_URL: 'http://localhost:8001', - FILE_URL: 'C:/Users/灯台百合/Desktop' // 快捷方式储存的路径 + FILE_URL: 'C:/Users/灯台百合/Desktop', // 快捷方式储存的路径 + HARD_CODE: false }; export default DEV; diff --git a/src/utils/request.ts b/src/utils/request.ts index d673bbb..1c160ea 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -1,7 +1,5 @@ import { DEV } from './env/dev' -// 是否写死请求地址 -const hardCode = false; /** * GET 请求 @@ -16,7 +14,7 @@ export function getRequest(url: string, params: object) { .join('&'); // 拼接查询字符串到 URL - let urlWithParams = ((hardCode ? DEV.PROXY_SERVER : '')) + url; + let urlWithParams = ((DEV.HARD_CODE ? DEV.PROXY_SERVER : '')) + url; if (queryString) { urlWithParams += `?${queryString}`; } @@ -43,7 +41,7 @@ export function getRequest(url: string, params: object) { * @returns {Promise} - 返回一个 Promise 对象,包含 response 数据或 error 信息 */ export function postRequest(url: string, data: object) { - return fetch(((hardCode ? DEV.PROXY_SERVER : '')) + url, { + return fetch(((DEV.HARD_CODE ? DEV.PROXY_SERVER : '')) + url, { method: 'POST', headers: { 'Content-Type': 'application/json'}, mode: "cors", @@ -69,7 +67,7 @@ export function postFormDataRequest(url: string, data: object) { formData.append(key, data[key]); } - return fetch(((hardCode ? DEV.PROXY_SERVER : '')) + url, { + return fetch(((DEV.HARD_CODE ? DEV.PROXY_SERVER : '')) + url, { method: 'POST', mode: "cors", body: formData @@ -89,7 +87,7 @@ export function postFormDataRequest(url: string, data: object) { */ export function deleteRequest(url: string, params: object) { const searchParams = new URLSearchParams(params); - return fetch(`${((hardCode ? DEV.PROXY_SERVER : '')) + url}?${searchParams.toString()}`, { + return fetch(`${((DEV.HARD_CODE ? DEV.PROXY_SERVER : '')) + url}?${searchParams.toString()}`, { method: 'DELETE', mode: "cors", }) @@ -108,7 +106,7 @@ export function deleteRequest(url: string, params: object) { * @returns {Promise} - 返回一个 Promise 对象,表示请求的结果(成功或失败) */ export function putRequest(url: string, data: object) { - return fetch(((hardCode ? DEV.PROXY_SERVER : '')) + url, { + return fetch(((DEV.HARD_CODE ? DEV.PROXY_SERVER : '')) + url, { method: 'PUT', headers: { 'Content-Type': 'application/json' @@ -131,7 +129,7 @@ export function putRequest(url: string, data: object) { * @returns {Promise} - 返回一个 Promise 对象,包含文件 blob 数据或 error 信息 */ export function downloadFile(url: string, fileName?: string) { - return fetch(((hardCode ? DEV.PROXY_SERVER : '')) + url, { + return fetch(((DEV.HARD_CODE ? DEV.PROXY_SERVER : '')) + url, { method: 'GET', mode: "cors", }) @@ -158,7 +156,7 @@ export function downloadFile(url: string, fileName?: string) { * @returns {Promise} - 返回一个 Promise 对象,表示请求的结果(成功或失败) */ export function uploadFile(url: string, formData: any) { - return fetch(((hardCode ? DEV.PROXY_SERVER : '')) + url, { + return fetch(((DEV.HARD_CODE ? DEV.PROXY_SERVER : '')) + url, { method: 'POST', body: formData, mode: "cors"