From 75012189c34d619eb3975eb1599409f3121053d5 Mon Sep 17 00:00:00 2001 From: langren1353 <1353464539@qq.com> Date: Tue, 8 Mar 2022 21:32:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E6=89=B9=E9=87=8F=E5=AF=BC=E5=85=A5=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/env/index.tsx | 277 ++++++++++++++++++++++++++++++++++------ 1 file changed, 240 insertions(+), 37 deletions(-) diff --git a/src/pages/env/index.tsx b/src/pages/env/index.tsx index c3dd1e37..82ba046b 100644 --- a/src/pages/env/index.tsx +++ b/src/pages/env/index.tsx @@ -9,11 +9,15 @@ import { Typography, Tooltip, Input, + Form, + notification, } from 'antd'; import { EditOutlined, DeleteOutlined, SyncOutlined, + ClockCircleOutlined, + CloseCircleOutlined, CheckCircleOutlined, StopOutlined, } from '@ant-design/icons'; @@ -26,9 +30,10 @@ import { DndProvider, useDrag, useDrop } from 'react-dnd'; import { HTML5Backend } from 'react-dnd-html5-backend'; import './index.less'; import { getTableScroll } from '@/utils/index'; +import { doc } from 'prettier'; const { Text } = Typography; -const { Search } = Input; +const { Search, TextArea } = Input; enum Status { '已启用', @@ -462,6 +467,188 @@ const Env = ({ headerStyle, isPhone, theme }: any) => { }); }; + const [importForm] = Form.useForm(); + + const operateImport = () => { + const importList: Array = [ + // { + // index: 1, + // name: '', + // icon: '', + // color: '' + // } + ]; + let importRes: any; + + const insertOneEnv = async (values: any) => { + const { value, split, name, remarks } = values; + const method = 'post'; + let payload; + if (split === '1') { + const symbol = value.includes('&') ? '&' : '\n'; + payload = value.split(symbol).map((x: any) => { + return { + name: name, + value: x, + remarks: remarks, + }; + }); + } else { + payload = [{ value, name, remarks }]; + } + const { code, data } = await request[method](`${config.apiPrefix}envs`, { + data: payload, + }); + return { code, data }; + }; + + const submitImport = async (value: string) => { + let now_at: any = ''; + try { + setLoading(true); + const dataList = JSON.parse(value); // 是一个数组 + + for (const [index, item] of dataList.entries()) { + importList.push({ + index: index, + name: item.name, + icon: , + color: 'default', + text: '等待中', + }); + } + + for (const [index, item] of dataList.entries()) { + Object.assign(importList[index], { + icon: , + color: 'processing', + text: '进行中', + }); + now_at = importList[index]; + const { code = 0 } = await insertOneEnv(item); + if (code === 200) { + Object.assign(importList[index], { + icon: , + color: 'success', + text: '成功', + }); + } else { + Object.assign(importList[index], { + icon: , + color: 'error', + text: '失败', + }); + } + } + importRes = importList.map((one) => { + return ( +
+ 第${one.index + 1}个变量 - ${one.name}{' '} + + 更新成功 + +
+ ); + }); + + const count_success = importList.filter( + (one) => one.color === 'success', + ).length; + const count_failed = importList.filter( + (one) => one.color === 'error', + ).length; + + notification.success({ + message: '导入完成', + description: `成功导入${count_success}个,失败${count_failed}个`, + }); + return true; + } catch (e) { + if (e.message.includes('JSON')) { + message.error('数据格式有问题,请检查并更正json格式'); + } else { + message.error( + `导入第 ${now_at.index + 1} 个数据 ${ + now_at.name + } 失败,请检查是否存在相同变量`, + ); + console.log(e); + } + } finally { + setLoading(false); + } + return false; + }; + Modal.confirm({ + title: `环境变量配置数据-导入-请手动粘贴`, + okText: '导入', + content: ( +
+
+ + + +
+
+ ), + async onOk() { + const values = await importForm.validateFields(); + const { envs }: { envs: string } = values; + const isOk = await submitImport(envs); + if (isOk) { + setTimeout(() => { + location.reload(); + }, 1000); + return Promise.resolve(); + } + return Promise.reject(''); + }, + onCancel() { + importForm.resetFields(); + }, + }); + }; + + const operateExport = () => { + const result = [...value]; + const selectItems = result + .filter((one) => selectedRowIds.includes(one.id)) + .map((one) => { + return { + name: one.name, + value: one.value, + split: one.split, + remarks: one.remarks, + }; + }); + + const resJson = JSON.stringify(selectItems, function (key: any, val: any) { + console.log(val); + if (val) return val; + }); + + Modal.confirm({ + title: `环境变量配置数据-导出-请手动复制`, + content: ( + + ), + onOk() { + console.log('Ok'); + }, + onCancel() { + console.log('Cancel'); + }, + }); + }; + const modifyName = () => { setIsEditNameModalVisible(true); }; @@ -500,42 +687,58 @@ const Env = ({ headerStyle, isPhone, theme }: any) => { style: headerStyle, }} > - {selectedRowIds.length > 0 && ( -
- - - - - - 已选择 - {selectedRowIds?.length}项 - -
- )} +
+ + {selectedRowIds.length > 0 && ( +
+ + + + + + + 已选择 + {selectedRowIds?.length}项 + +
+ )} +