Skip to content

Commit 5d7f813

Browse files
committed
feat: optimize env management
1 parent 6e105f4 commit 5d7f813

File tree

9 files changed

+101
-16
lines changed

9 files changed

+101
-16
lines changed

app/controller/envManagement.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ class EnvManagementController extends Controller {
1212
// 新增环境
1313
async addEnv() {
1414
const { ctx, app } = this;
15-
const { envName, hostIp, url, remark, tagIds } = ctx.request.body;
15+
const { envName, hostIp, uicUsername, uicPasswd, url, remark, tagIds } = ctx.request.body;
1616
if (_.isNil(envName)) throw new Error('缺少必要参数 envName');
1717
if (_.isNil(url)) throw new Error('缺少必要参数 url');
1818
const result = await ctx.service.envManagement.addEnv({
1919
envName,
2020
hostIp,
21+
uicUsername,
22+
uicPasswd,
2123
url,
2224
remark,
2325
tags: tagIds.join(','),
@@ -32,11 +34,14 @@ class EnvManagementController extends Controller {
3234
// 编辑环境
3335
async editEnv() {
3436
const { ctx, app } = this;
35-
const { id, envName, hostIp, url, remark, tagIds } = ctx.request.body;
37+
const { id, envName, hostIp, uicUsername, uicPasswd, url, remark, tagIds } =
38+
ctx.request.body;
3639
if (_.isNil(id)) throw new Error('缺少必要参数id');
3740
await ctx.service.envManagement.editEnv({
3841
id,
3942
envName,
43+
uicUsername,
44+
uicPasswd,
4045
hostIp,
4146
url,
4247
remark,

app/model/env_management.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ module.exports = (app) => {
66
id: { type: INTEGER, primaryKey: true, autoIncrement: true },
77
envName: { type: STRING(255), field: 'env_name' },
88
hostIp: { type: STRING(20), field: 'host_ip' },
9+
uicUsername: { type: STRING(255), field: 'uic_username' },
10+
uicPasswd: { type: STRING(255), field: 'uic_passwd' },
911
url: { type: STRING(2048), field: 'url' },
1012
remark: STRING(255),
1113
tags: { type: STRING(60), field: 'tag_ids' },

app/service/envManagement.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ class EnvManagementService extends Service {
66
const { ctx } = this;
77
const { tags = '', search = '' } = params;
88
const envResult = await ctx.model.EnvManagement.findAll({
9-
attributes: ['id', 'envName', 'hostIp', 'url', 'remark', 'tags'],
9+
attributes: [
10+
'id',
11+
'envName',
12+
'hostIp',
13+
'uicUsername',
14+
'uicPasswd',
15+
'url',
16+
'remark',
17+
'tags',
18+
],
1019
where: {
1120
status: 1,
1221
$or: [
@@ -43,10 +52,12 @@ class EnvManagementService extends Service {
4352
}
4453
editEnv(env) {
4554
const { ctx } = this;
46-
const { id, envName, hostIp, url, remark, tags } = env;
55+
const { id, envName, hostIp, uicUsername, uicPasswd, url, remark, tags } = env;
4756
const newEnv = {};
4857
if (!_.isNil(envName)) newEnv.envName = envName;
4958
if (!_.isNil(hostIp)) newEnv.hostIp = hostIp;
59+
if (!_.isNil(uicUsername)) newEnv.uicUsername = uicUsername;
60+
if (!_.isNil(uicPasswd)) newEnv.uicPasswd = uicPasswd;
5061
if (!_.isNil(url)) newEnv.url = url;
5162
if (!_.isNil(remark)) newEnv.remark = remark;
5263
if (!_.isNil(tags)) newEnv.tags = tags;

app/web/pages/envManagement/components/envModal/index.tsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import { Form, Input, message as Message, Modal, Select, Spin } from 'antd';
33
import { isEmpty, isFunction, isNull } from 'lodash';
44

55
import { API } from '@/api';
6+
import { urlReg } from '@/utils/reg';
67
const FormItem = Form.Item;
78
const { TextArea } = Input;
89
const { Option } = Select;
910

1011
const EnvForm = (props: any) => {
1112
const { value, tagList = [], forwardRef } = props;
12-
const { envName, hostIp, url, remark, tags = [] } = value;
13+
const { envName, hostIp, uicUsername, uicPasswd, url, remark, tags = [] } = value;
1314
const tagIds = tags.map((item: any) => Number(item.id));
1415
return (
1516
<Form
@@ -19,6 +20,8 @@ const EnvForm = (props: any) => {
1920
initialValues={{
2021
envName,
2122
hostIp,
23+
uicUsername,
24+
uicPasswd,
2225
url,
2326
tagIds,
2427
remark,
@@ -30,24 +33,37 @@ const EnvForm = (props: any) => {
3033
rules={[{ required: true, message: '请输入环境名称' }]}
3134
hasFeedback
3235
>
33-
<Input placeholder="请输入环境名称" />
36+
<Input placeholder="请输入环境名称" maxLength={255} />
3437
</FormItem>
3538
<FormItem
3639
label="主机IP"
3740
name="hostIp"
3841
rules={[{ required: true, message: '请输入主机IP' }]}
3942
hasFeedback
4043
>
41-
<Input placeholder="请输入主机IP" />
44+
<Input placeholder="请输入主机IP" maxLength={255} />
45+
</FormItem>
46+
<FormItem label="UIC用户名" name="uicUsername" hasFeedback>
47+
<Input placeholder="请输入UIC用户名" maxLength={255} />
48+
</FormItem>
49+
<FormItem label="UIC密码" name="uicPasswd" hasFeedback>
50+
<Input type="password" placeholder="请输入UIC密码" maxLength={255} />
4251
</FormItem>
4352
<Fragment>
4453
<FormItem
4554
label="访问地址"
4655
name="url"
47-
rules={[{ required: true, message: '请输入访问地址' }]}
56+
rules={[
57+
{ required: true, message: '请输入访问地址' },
58+
{
59+
required: true,
60+
pattern: urlReg,
61+
message: '请输入正确格式的访问地址,以 http(s):// 开头',
62+
},
63+
]}
4864
hasFeedback
4965
>
50-
<TextArea placeholder="请输入访问地址" rows={2} maxLength={2000} />
66+
<Input placeholder="请输入访问地址" maxLength={2000} />
5167
</FormItem>
5268
</Fragment>
5369
<FormItem
@@ -59,6 +75,14 @@ const EnvForm = (props: any) => {
5975
required: true,
6076
message: '请选择标签',
6177
},
78+
{
79+
validator: (rule, value = [], callback) => {
80+
if (value?.length > 3) {
81+
callback('最多选择三个标签');
82+
}
83+
callback();
84+
},
85+
},
6286
]}
6387
hasFeedback
6488
>

app/web/pages/envManagement/index.tsx

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import React, { useEffect, useState } from 'react';
22
import { PlusCircleOutlined } from '@ant-design/icons';
3-
import { Button, Divider, Input, message as Message, Popconfirm, Table, Typography } from 'antd';
3+
import {
4+
Button,
5+
Divider,
6+
Input,
7+
message as Message,
8+
Popconfirm,
9+
Table,
10+
Tooltip,
11+
Typography,
12+
} from 'antd';
413

514
import { API } from '@/api';
615
import DtTag from '@/components/dtTag';
@@ -50,15 +59,42 @@ export default (props: any) => {
5059
{
5160
title: '环境名称',
5261
key: 'envName',
53-
width: 220,
5462
dataIndex: 'envName',
5563
},
5664
{
5765
title: '主机IP',
5866
key: 'hostIp',
59-
width: 160,
6067
dataIndex: 'hostIp',
6168
},
69+
{
70+
title: 'UIC用户名密码',
71+
key: 'hostIp',
72+
dataIndex: 'hostIp',
73+
ellipsis: true,
74+
render: (value: any, record: any) => {
75+
const { uicUsername, uicPasswd } = record;
76+
return !uicUsername && !uicPasswd ? (
77+
'--'
78+
) : (
79+
<>
80+
{uicUsername ? (
81+
<Paragraph copyable ellipsis>
82+
{uicUsername}
83+
</Paragraph>
84+
) : (
85+
'--'
86+
)}
87+
{uicPasswd ? (
88+
<Paragraph copyable ellipsis>
89+
{uicPasswd}
90+
</Paragraph>
91+
) : (
92+
'--'
93+
)}
94+
</>
95+
);
96+
},
97+
},
6298
{
6399
title: '访问地址',
64100
key: 'url',
@@ -81,7 +117,6 @@ export default (props: any) => {
81117
title: '标签',
82118
key: 'tags',
83119
dataIndex: 'tags',
84-
width: 160,
85120
filterMultiple: true,
86121
filters: tagList.map((item: any) => {
87122
return {
@@ -102,7 +137,11 @@ export default (props: any) => {
102137
key: 'remark',
103138
dataIndex: 'remark',
104139
ellipsis: true,
105-
render: (text) => <pre className="remark-content">{text || '--'}</pre>,
140+
render: (text) => (
141+
<Tooltip title={text} placement="top">
142+
<pre className="remark-content">{text || '--'}</pre>
143+
</Tooltip>
144+
),
106145
},
107146
{
108147
title: '操作',
@@ -179,7 +218,7 @@ export default (props: any) => {
179218
<div className="page-env-management">
180219
<div className="title_wrap">
181220
<Search
182-
placeholder="请输入环境名称或IP搜索"
221+
placeholder="请输入环境名称或主机IP搜索"
183222
value={searchStr}
184223
onChange={(e) => setSearchStr(e.target.value)}
185224
onSearch={() => loadTableData({ search: searchStr })}
@@ -192,6 +231,7 @@ export default (props: any) => {
192231
</div>
193232
<Table
194233
rowKey="id"
234+
size="middle"
195235
columns={getColumns()}
196236
className="dt-table-fixed-base"
197237
scroll={{ y: 'calc(100vh - 64px - 40px - 44px - 44px)' }}

app/web/pages/envManagement/style.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
}
1111

1212
.remark-content {
13+
margin-bottom: 0;
1314
// white-space: normal;
1415
overflow: hidden; // 超出的文本隐藏
1516
text-overflow: ellipsis; // 溢出用省略号显示
1617
display: -webkit-box; // 将对象作为弹性伸缩盒子模型显示。
1718
-webkit-box-orient: vertical; // 从上到下垂直排列子元素(设置伸缩盒子的子元素排列方式)
18-
-webkit-line-clamp: 3; // 这个属性不是css的规范属性,需要组合上面两个属性,表示显示的行数。
19+
-webkit-line-clamp: 4; // 这个属性不是css的规范属性,需要组合上面两个属性,表示显示的行数。
1920
}

docs/docsify/imgs/add_env.png

6.66 KB
Loading
35.5 KB
Loading

sql/doraemon.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ CREATE TABLE `env_management` (
159159
`id` int NOT NULL AUTO_INCREMENT,
160160
`env_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
161161
`host_ip` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
162+
`uic_username` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin,
163+
`uic_passwd` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin,
162164
`url` varchar(2048) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
163165
`status` tinyint NOT NULL DEFAULT '1',
164166
`remark` varchar(2048) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,

0 commit comments

Comments
 (0)