mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-12-02 11:58:01 +08:00
feat 新增全局工作空间变量
This commit is contained in:
parent
7fab5a43e9
commit
0c7f880572
10
CHANGELOG.md
10
CHANGELOG.md
@ -1,5 +1,15 @@
|
||||
# 🚀 版本日志
|
||||
|
||||
## 2.9.10
|
||||
|
||||
### 🐣 新增功能
|
||||
|
||||
1. 【server】新增全局工作空间变量
|
||||
|
||||
### 🐞 解决BUG、优化功能
|
||||
|
||||
------
|
||||
|
||||
## 2.9.9 (2022-08-22)
|
||||
|
||||
### 🐣 新增功能
|
||||
|
@ -27,64 +27,68 @@ package io.jpom.common;
|
||||
* Const class
|
||||
*/
|
||||
public class Const {
|
||||
/**
|
||||
* String const
|
||||
*/
|
||||
public static final String ID_STR = "id";
|
||||
public static final String GROUP_STR = "group";
|
||||
/**
|
||||
* String const
|
||||
*/
|
||||
public static final String ID_STR = "id";
|
||||
public static final String GROUP_STR = "group";
|
||||
|
||||
/**
|
||||
* 应用程序类型的配置 key
|
||||
*/
|
||||
public static final String APPLICATION_NAME = "spring.application.name";
|
||||
/**
|
||||
* 应用程序类型的配置 key
|
||||
*/
|
||||
public static final String APPLICATION_NAME = "spring.application.name";
|
||||
|
||||
/**
|
||||
* String get
|
||||
*/
|
||||
public static final String GET_STR = "get";
|
||||
/**
|
||||
* String get
|
||||
*/
|
||||
public static final String GET_STR = "get";
|
||||
|
||||
|
||||
/**
|
||||
* id_rsa
|
||||
*/
|
||||
public static final String ID_RSA = "_id_rsa";
|
||||
/**
|
||||
* sshkey
|
||||
*/
|
||||
public static final String SSH_KEY = "sshkey";
|
||||
/**
|
||||
* id_rsa
|
||||
*/
|
||||
public static final String ID_RSA = "_id_rsa";
|
||||
/**
|
||||
* sshkey
|
||||
*/
|
||||
public static final String SSH_KEY = "sshkey";
|
||||
|
||||
/**
|
||||
* SQL backup default directory name
|
||||
* 数据库备份默认目录名称
|
||||
*/
|
||||
public static final String BACKUP_DIRECTORY_NAME = "backup";
|
||||
/**
|
||||
* h2 数据库表名字段
|
||||
*/
|
||||
public static final String TABLE_NAME = "TABLE_NAME";
|
||||
/**
|
||||
* 备份 SQL 文件 后缀
|
||||
*/
|
||||
public static final String SQL_FILE_SUFFIX = ".sql";
|
||||
/**
|
||||
* 升级提示语
|
||||
*/
|
||||
public static final String UPGRADE_MSG = "升级(重启)中大约需要30秒~2分钟左右";
|
||||
/**
|
||||
* SQL backup default directory name
|
||||
* 数据库备份默认目录名称
|
||||
*/
|
||||
public static final String BACKUP_DIRECTORY_NAME = "backup";
|
||||
/**
|
||||
* h2 数据库表名字段
|
||||
*/
|
||||
public static final String TABLE_NAME = "TABLE_NAME";
|
||||
/**
|
||||
* 备份 SQL 文件 后缀
|
||||
*/
|
||||
public static final String SQL_FILE_SUFFIX = ".sql";
|
||||
/**
|
||||
* 升级提示语
|
||||
*/
|
||||
public static final String UPGRADE_MSG = "升级(重启)中大约需要30秒~2分钟左右";
|
||||
|
||||
/**
|
||||
* 请求 header
|
||||
*/
|
||||
public static final String WORKSPACEID_REQ_HEADER = "workspaceId";
|
||||
/**
|
||||
* 默认的工作空间
|
||||
*/
|
||||
public static final String WORKSPACE_DEFAULT_ID = "DEFAULT";
|
||||
/**
|
||||
* websocket 传输 agent 包 buffer size
|
||||
*/
|
||||
public static final int DEFAULT_BUFFER_SIZE = 1024 * 1024;
|
||||
/**
|
||||
* id 最大长度
|
||||
*/
|
||||
public static final int ID_MAX_LEN = 50;
|
||||
/**
|
||||
* 请求 header
|
||||
*/
|
||||
public static final String WORKSPACEID_REQ_HEADER = "workspaceId";
|
||||
/**
|
||||
* 工作空间全局
|
||||
*/
|
||||
public static final String WORKSPACE_GLOBAL = "GLOBAL";
|
||||
/**
|
||||
* 默认的工作空间
|
||||
*/
|
||||
public static final String WORKSPACE_DEFAULT_ID = "DEFAULT";
|
||||
/**
|
||||
* websocket 传输 agent 包 buffer size
|
||||
*/
|
||||
public static final int DEFAULT_BUFFER_SIZE = 1024 * 1024;
|
||||
/**
|
||||
* id 最大长度
|
||||
*/
|
||||
public static final int ID_MAX_LEN = 50;
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import cn.jiangzeyin.common.validator.ValidatorItem;
|
||||
import cn.jiangzeyin.common.validator.ValidatorRule;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.jpom.common.BaseServerController;
|
||||
import io.jpom.common.Const;
|
||||
import io.jpom.common.forward.NodeForward;
|
||||
import io.jpom.common.forward.NodeUrl;
|
||||
import io.jpom.model.PageResultDto;
|
||||
@ -78,7 +79,6 @@ public class WorkspaceEnvVarController extends BaseServerController {
|
||||
@PostMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Feature(method = MethodFeature.LIST)
|
||||
public String list() {
|
||||
workspaceEnvVarService.getCheckUserWorkspace(getRequest());
|
||||
PageResultDto<WorkspaceEnvVarModel> listPage = workspaceEnvVarService.listPage(getRequest());
|
||||
listPage.each(workspaceEnvVarModel -> {
|
||||
Integer privacy = workspaceEnvVarModel.getPrivacy();
|
||||
@ -192,7 +192,7 @@ public class WorkspaceEnvVarController extends BaseServerController {
|
||||
//
|
||||
Entity entity = Entity.create();
|
||||
entity.set("name", name);
|
||||
entity.set("workspaceId", workspaceId);
|
||||
entity.set("workspaceId", CollUtil.newArrayList(workspaceId, Const.WORKSPACE_GLOBAL));
|
||||
if (StrUtil.isNotEmpty(id)) {
|
||||
entity.set("id", StrUtil.format(" <> {}", id));
|
||||
}
|
||||
|
@ -148,29 +148,24 @@ public abstract class BaseWorkspaceService<T extends BaseWorkspaceModel> extends
|
||||
public PageResultDto<T> listPage(HttpServletRequest request) {
|
||||
// 验证工作空间权限
|
||||
Map<String, String> paramMap = ServletUtil.getParamMap(request);
|
||||
String workspaceId = request.getParameter("workspaceId");
|
||||
if (StrUtil.isEmpty(workspaceId)) {
|
||||
workspaceId = this.getCheckUserWorkspace(request);
|
||||
}
|
||||
Assert.hasText(workspaceId, "此接口需要传workspaceId!");
|
||||
String workspaceId = this.getCheckUserWorkspace(request);
|
||||
//Assert.hasText(workspaceId, "此接口需要传workspaceId!");
|
||||
paramMap.put("workspaceId", workspaceId);
|
||||
return super.listPage(paramMap);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据 workspaceId获取空间变量列表
|
||||
*
|
||||
* @param workspaceId
|
||||
* @return
|
||||
*/
|
||||
public List<T> listByWorkspaceId(String workspaceId) {
|
||||
Entity entity = Entity.create();
|
||||
entity.set("workspaceId", workspaceId);
|
||||
List<Entity> entities = super.queryList(entity);
|
||||
return super.entityToBeanList(entities);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 根据 workspaceId获取空间变量列表
|
||||
// *
|
||||
// * @param workspaceId
|
||||
// * @return
|
||||
// */
|
||||
// public List<T> listByWorkspaceId(String workspaceId) {
|
||||
// Entity entity = Entity.create();
|
||||
// entity.set("workspaceId", workspaceId);
|
||||
// List<Entity> entities = super.queryList(entity);
|
||||
// return super.entityToBeanList(entities);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 删除
|
||||
@ -202,9 +197,9 @@ public abstract class BaseWorkspaceService<T extends BaseWorkspaceModel> extends
|
||||
}
|
||||
|
||||
public static String getWorkspaceId(HttpServletRequest request) {
|
||||
String workspaceId = ServletUtil.getHeader(request, Const.WORKSPACEID_REQ_HEADER, CharsetUtil.CHARSET_UTF_8);
|
||||
String workspaceId = request.getParameter(Const.WORKSPACEID_REQ_HEADER);
|
||||
if (StrUtil.isEmpty(workspaceId)) {
|
||||
workspaceId = request.getParameter(Const.WORKSPACEID_REQ_HEADER);
|
||||
workspaceId = ServletUtil.getHeader(request, Const.WORKSPACEID_REQ_HEADER, CharsetUtil.CHARSET_UTF_8);
|
||||
}
|
||||
return StrUtil.emptyToDefault(workspaceId, Const.WORKSPACE_DEFAULT_ID);
|
||||
}
|
||||
@ -248,6 +243,10 @@ public abstract class BaseWorkspaceService<T extends BaseWorkspaceModel> extends
|
||||
// 超级管理员
|
||||
return;
|
||||
}
|
||||
if (StrUtil.equals(workspaceId, Const.WORKSPACE_GLOBAL)) {
|
||||
// 全局 ID 忽略
|
||||
return;
|
||||
}
|
||||
// 查询绑定的权限
|
||||
UserBindWorkspaceService userBindWorkspaceService = SpringUtil.getBean(UserBindWorkspaceService.class);
|
||||
boolean exists = userBindWorkspaceService.exists(userModel, workspaceId);
|
||||
|
@ -24,6 +24,8 @@ package io.jpom.service.system;
|
||||
|
||||
import cn.hutool.core.collection.CollStreamUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.db.Entity;
|
||||
import io.jpom.common.Const;
|
||||
import io.jpom.model.data.WorkspaceEnvVarModel;
|
||||
import io.jpom.service.h2db.BaseWorkspaceService;
|
||||
import io.jpom.util.StringUtil;
|
||||
@ -41,9 +43,9 @@ import java.util.Map;
|
||||
public class WorkspaceEnvVarService extends BaseWorkspaceService<WorkspaceEnvVarModel> {
|
||||
|
||||
public Map<String, String> getEnv(String workspaceId) {
|
||||
WorkspaceEnvVarModel workspaceEnvVarModel = new WorkspaceEnvVarModel();
|
||||
workspaceEnvVarModel.setWorkspaceId(workspaceId);
|
||||
List<WorkspaceEnvVarModel> list = super.listByBean(workspaceEnvVarModel);
|
||||
Entity entity = Entity.create();
|
||||
entity.set("workspaceId", CollUtil.newArrayList(workspaceId, Const.WORKSPACE_GLOBAL));
|
||||
List<WorkspaceEnvVarModel> list = super.listByEntity(entity);
|
||||
Map<String, String> map = CollStreamUtil.toMap(list, WorkspaceEnvVarModel::getName, WorkspaceEnvVarModel::getValue);
|
||||
// java.lang.UnsupportedOperationException
|
||||
HashMap<String, String> hashMap = new HashMap<>(CollUtil.size(list) + 10);
|
||||
|
@ -169,6 +169,11 @@
|
||||
"title": "工作空间",
|
||||
"role": "system"
|
||||
},
|
||||
{
|
||||
"id": "globalEnv",
|
||||
"title": "全局变量",
|
||||
"role": "system"
|
||||
},
|
||||
{
|
||||
"id": "cacheManage",
|
||||
"title": "缓存管理",
|
||||
|
14
web-vue/src/pages/system/global-env.vue
Normal file
14
web-vue/src/pages/system/global-env.vue
Normal file
@ -0,0 +1,14 @@
|
||||
<template>
|
||||
<div>
|
||||
<workspaceEnv workspaceId="GLOBAL" />
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import workspaceEnv from "./workspace-env.vue";
|
||||
|
||||
export default {
|
||||
components: {
|
||||
workspaceEnv,
|
||||
},
|
||||
};
|
||||
</script>
|
242
web-vue/src/pages/system/workspace-env.vue
Normal file
242
web-vue/src/pages/system/workspace-env.vue
Normal file
@ -0,0 +1,242 @@
|
||||
<template>
|
||||
<div>
|
||||
<div ref="filter" class="filter">
|
||||
<a-space>
|
||||
<a-input v-model="envVarListQuery['%name%']" placeholder="名称" @pressEnter="loadDataEnvVar" allowClear class="search-input-item" />
|
||||
<a-input v-model="envVarListQuery['%value%']" placeholder="值" @pressEnter="loadDataEnvVar" allowClear class="search-input-item" />
|
||||
<a-input v-model="envVarListQuery['%description%']" placeholder="描述" @pressEnter="loadDataEnvVar" allowClear class="search-input-item" />
|
||||
<a-button type="primary" @click="loadDataEnvVar">搜索</a-button>
|
||||
<a-button type="primary" @click="addEnvVar">新增</a-button>
|
||||
</a-space>
|
||||
</div>
|
||||
<!-- 数据表格 -->
|
||||
<a-table
|
||||
:data-source="envVarList"
|
||||
size="middle"
|
||||
:loading="envVarLoading"
|
||||
:columns="envVarColumns"
|
||||
:pagination="envVarPagination"
|
||||
@change="changeListeEnvVar"
|
||||
bordered
|
||||
:rowKey="(record, index) => index"
|
||||
>
|
||||
<a-tooltip slot="value" slot-scope="text, item" placement="topLeft" :title="item.privacy === 1 ? '隐私字段' : text">
|
||||
<a-icon v-if="item.privacy === 1" type="eye-invisible" />
|
||||
<span v-else>{{ text }}</span>
|
||||
</a-tooltip>
|
||||
<a-tooltip slot="name" slot-scope="text" placement="topLeft" :title="text">
|
||||
<span>{{ text }}</span>
|
||||
</a-tooltip>
|
||||
<a-tooltip slot="description" slot-scope="text" placement="topLeft" :title="text">
|
||||
<span>{{ text }}</span>
|
||||
</a-tooltip>
|
||||
<template slot="operation" slot-scope="text, record">
|
||||
<a-space>
|
||||
<a-button size="small" type="primary" @click="handleEnvEdit(record)">编辑</a-button>
|
||||
<a-button size="small" type="danger" @click="handleEnvDelete(record)">删除</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<!-- 环境变量编辑区 -->
|
||||
<a-modal v-model="editEnvVisible" title="编辑环境变量" width="50vw" @ok="handleEnvEditOk" :maskClosable="false">
|
||||
<a-form-model ref="editEnvForm" :rules="rulesEnv" :model="envTemp" :label-col="{ span: 4 }" :wrapper-col="{ span: 18 }">
|
||||
<a-form-model-item label="名称" prop="name">
|
||||
<a-input v-model="envTemp.name" :maxLength="50" placeholder="变量名称" />
|
||||
</a-form-model-item>
|
||||
<a-form-model-item label="值" :prop="`${envTemp.privacy === 1 ? '' : 'value'}`">
|
||||
<a-input v-model="envTemp.value" type="textarea" :rows="5" placeholder="变量值" />
|
||||
</a-form-model-item>
|
||||
<a-form-model-item label="描述" prop="description">
|
||||
<a-input v-model="envTemp.description" :maxLength="200" type="textarea" :rows="5" placeholder="变量描述" />
|
||||
</a-form-model-item>
|
||||
<a-form-model-item prop="privacy">
|
||||
<template slot="label">
|
||||
隐私变量
|
||||
<a-tooltip v-show="!envTemp.id">
|
||||
<template slot="title"> 隐私变量是指一些密码字段或者关键密钥等重要信息,隐私字段只能修改不能查看(编辑弹窗中无法看到对应值)。 隐私字段一旦创建后将不能切换为非隐私字段 </template>
|
||||
<a-icon type="question-circle" theme="filled" />
|
||||
</a-tooltip>
|
||||
</template>
|
||||
<a-switch
|
||||
:checked="envTemp.privacy === 1"
|
||||
@change="
|
||||
(checked) => {
|
||||
envTemp = { ...envTemp, privacy: checked ? 1 : 0 };
|
||||
}
|
||||
"
|
||||
:disabled="envTemp.id !== undefined"
|
||||
checked-children="隐私"
|
||||
un-checked-children="非隐私"
|
||||
/>
|
||||
</a-form-model-item>
|
||||
<a-form-model-item>
|
||||
<template slot="label">
|
||||
分发节点
|
||||
<a-tooltip v-show="!envTemp.id">
|
||||
<template slot="title"> 分发节点是指将变量同步到对应节点,在节点脚本中也可以使用当前变量</template>
|
||||
<a-icon type="question-circle" theme="filled" />
|
||||
</a-tooltip>
|
||||
</template>
|
||||
<a-select
|
||||
:getPopupContainer="
|
||||
(triggerNode) => {
|
||||
return triggerNode.parentNode || document.body;
|
||||
}
|
||||
"
|
||||
show-search
|
||||
option-filter-prop="children"
|
||||
placeholder="请选择分发到的节点"
|
||||
mode="multiple"
|
||||
v-model="envTemp.chooseNode"
|
||||
>
|
||||
<a-select-option v-for="item in nodeList" :key="item.id" :value="item.id">
|
||||
{{ item.name }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-model-item>
|
||||
</a-form-model>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { deleteWorkspaceEnv, editWorkspaceEnv, getWorkspaceEnvList } from "@/api/workspace";
|
||||
import { getNodeListByWorkspace } from "@/api/node";
|
||||
import { CHANGE_PAGE, COMPUTED_PAGINATION, PAGE_DEFAULT_LIST_QUERY } from "@/utils/const";
|
||||
import { parseTime } from "@/utils/time";
|
||||
|
||||
export default {
|
||||
props: {
|
||||
workspaceId: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
envVarLoading: false,
|
||||
envVarList: [],
|
||||
nodeList: [],
|
||||
envVarListQuery: Object.assign({}, PAGE_DEFAULT_LIST_QUERY),
|
||||
editEnvVisible: false,
|
||||
envTemp: {},
|
||||
envVarColumns: [
|
||||
{ title: "名称", dataIndex: "name", ellipsis: true, scopedSlots: { customRender: "name" } },
|
||||
{ title: "值", dataIndex: "value", ellipsis: true, scopedSlots: { customRender: "value" } },
|
||||
{ title: "描述", dataIndex: "description", ellipsis: true, scopedSlots: { customRender: "description" } },
|
||||
{ title: "修改人", dataIndex: "modifyUser", ellipsis: true, scopedSlots: { customRender: "modifyUser" }, width: 120 },
|
||||
{
|
||||
title: "修改时间",
|
||||
dataIndex: "modifyTimeMillis",
|
||||
customRender: (text) => {
|
||||
if (!text) {
|
||||
return "";
|
||||
}
|
||||
return parseTime(text);
|
||||
},
|
||||
sorter: true,
|
||||
width: 180,
|
||||
},
|
||||
{ title: "操作", dataIndex: "operation", align: "center", scopedSlots: { customRender: "operation" }, width: 120 },
|
||||
],
|
||||
// 表单校验规则
|
||||
rulesEnv: {
|
||||
name: [{ required: true, message: "请输入变量名称", trigger: "blur" }],
|
||||
description: [{ required: true, message: "请输入变量描述", trigger: "blur" }],
|
||||
value: [{ required: true, message: "请输入变量值", trigger: "blur" }],
|
||||
},
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
envVarPagination() {
|
||||
return COMPUTED_PAGINATION(this.envVarListQuery);
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
loadDataEnvVar(pointerEvent) {
|
||||
this.envVarLoading = true;
|
||||
|
||||
this.envVarListQuery.workspaceId = this.workspaceId;
|
||||
this.envVarListQuery.page = pointerEvent?.altKey || pointerEvent?.ctrlKey ? 1 : this.envVarListQuery.page;
|
||||
getWorkspaceEnvList(this.envVarListQuery).then((res) => {
|
||||
if (res.code === 200) {
|
||||
this.envVarList = res.data.result;
|
||||
this.envVarListQuery.total = res.data.total;
|
||||
}
|
||||
this.envVarLoading = false;
|
||||
});
|
||||
},
|
||||
addEnvVar() {
|
||||
this.envTemp = {
|
||||
workspaceId: this.workspaceId,
|
||||
};
|
||||
|
||||
this.editEnvVisible = true;
|
||||
this.$refs["editEnvForm"] && this.$refs["editEnvForm"].resetFields();
|
||||
this.getAllNodeList(this.envTemp.workspaceId);
|
||||
},
|
||||
handleEnvEdit(record) {
|
||||
this.envTemp = record;
|
||||
this.envTemp.workspaceId = this.workspaceId;
|
||||
this.envTemp = { ...this.envTemp, chooseNode: record.nodeIds ? record.nodeIds.split(",") : [] };
|
||||
this.editEnvVisible = true;
|
||||
this.getAllNodeList(this.envTemp.workspaceId);
|
||||
},
|
||||
handleEnvEditOk() {
|
||||
this.$refs["editEnvForm"].validate((valid) => {
|
||||
if (!valid) {
|
||||
return false;
|
||||
}
|
||||
this.envTemp.nodeIds = this.envTemp?.chooseNode?.join(",");
|
||||
editWorkspaceEnv(this.envTemp).then((res) => {
|
||||
if (res.code === 200) {
|
||||
// 成功
|
||||
this.$notification.success({
|
||||
message: res.msg,
|
||||
});
|
||||
this.$refs["editEnvForm"].resetFields();
|
||||
this.editEnvVisible = false;
|
||||
this.loadDataEnvVar();
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
//
|
||||
handleEnvDelete(record) {
|
||||
this.$confirm({
|
||||
title: "系统提示",
|
||||
content: "真的删除当前变量吗?",
|
||||
okText: "确认",
|
||||
cancelText: "取消",
|
||||
onOk: () => {
|
||||
// 删除
|
||||
deleteWorkspaceEnv({
|
||||
id: record.id,
|
||||
workspaceId: this.workspaceId,
|
||||
}).then((res) => {
|
||||
if (res.code === 200) {
|
||||
this.$notification.success({
|
||||
message: res.msg,
|
||||
});
|
||||
this.loadDataEnvVar();
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
// 获取所有节点
|
||||
getAllNodeList(workspaceId) {
|
||||
getNodeListByWorkspace({
|
||||
workspaceId: workspaceId,
|
||||
}).then((res) => {
|
||||
this.nodeList = res.data || [];
|
||||
});
|
||||
},
|
||||
changeListeEnvVar(pagination, filters, sorter) {
|
||||
this.envVarListQuery = CHANGE_PAGE(this.envVarListQuery, { pagination, sorter });
|
||||
|
||||
this.loadDataEnvVar();
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
@ -49,116 +49,28 @@
|
||||
</a-modal>
|
||||
<!-- 环境变量 -->
|
||||
<a-modal v-model="envVarListVisible" :title="`${temp.name} 工作空间环境变量`" width="80vw" :footer="null" :maskClosable="false">
|
||||
<div ref="filter" class="filter">
|
||||
<a-space>
|
||||
<a-input v-model="envVarListQuery['%name%']" placeholder="名称" @pressEnter="loadDataEnvVar" allowClear class="search-input-item" />
|
||||
<a-input v-model="envVarListQuery['%value%']" placeholder="值" @pressEnter="loadDataEnvVar" allowClear class="search-input-item" />
|
||||
<a-input v-model="envVarListQuery['%description%']" placeholder="描述" @pressEnter="loadDataEnvVar" allowClear class="search-input-item" />
|
||||
<a-button type="primary" @click="loadDataEnvVar">搜索</a-button>
|
||||
<a-button type="primary" @click="addEnvVar">新增</a-button>
|
||||
</a-space>
|
||||
</div>
|
||||
<!-- 数据表格 -->
|
||||
<a-table
|
||||
:data-source="envVarList"
|
||||
size="middle"
|
||||
:loading="envVarLoading"
|
||||
:columns="envVarColumns"
|
||||
:pagination="envVarPagination"
|
||||
@change="changeListeEnvVar"
|
||||
bordered
|
||||
:rowKey="(record, index) => index"
|
||||
>
|
||||
<a-tooltip slot="value" slot-scope="text, item" placement="topLeft" :title="item.privacy === 1 ? '隐私字段' : text">
|
||||
<a-icon v-if="item.privacy === 1" type="eye-invisible" />
|
||||
<span v-else>{{ text }}</span>
|
||||
</a-tooltip>
|
||||
<a-tooltip slot="name" slot-scope="text" placement="topLeft" :title="text">
|
||||
<span>{{ text }}</span>
|
||||
</a-tooltip>
|
||||
<a-tooltip slot="description" slot-scope="text" placement="topLeft" :title="text">
|
||||
<span>{{ text }}</span>
|
||||
</a-tooltip>
|
||||
<template slot="operation" slot-scope="text, record">
|
||||
<a-space>
|
||||
<a-button size="small" type="primary" @click="handleEnvEdit(record)">编辑</a-button>
|
||||
<a-button size="small" type="danger" @click="handleEnvDelete(record)">删除</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</a-table>
|
||||
</a-modal>
|
||||
<!-- 环境变量编辑区 -->
|
||||
<a-modal v-model="editEnvVisible" title="编辑环境变量" width="50vw" @ok="handleEnvEditOk" :maskClosable="false">
|
||||
<a-form-model ref="editEnvForm" :rules="rulesEnv" :model="envTemp" :label-col="{ span: 4 }" :wrapper-col="{ span: 18 }">
|
||||
<a-form-model-item label="名称" prop="name">
|
||||
<a-input v-model="envTemp.name" :maxLength="50" placeholder="变量名称" />
|
||||
</a-form-model-item>
|
||||
<a-form-model-item label="值" :prop="`${envTemp.privacy === 1 ? '' : 'value'}`">
|
||||
<a-input v-model="envTemp.value" type="textarea" :rows="5" placeholder="变量值" />
|
||||
</a-form-model-item>
|
||||
<a-form-model-item label="描述" prop="description">
|
||||
<a-input v-model="envTemp.description" :maxLength="200" type="textarea" :rows="5" placeholder="变量描述" />
|
||||
</a-form-model-item>
|
||||
<a-form-model-item prop="privacy">
|
||||
<template slot="label">
|
||||
隐私变量
|
||||
<a-tooltip v-show="!envTemp.id">
|
||||
<template slot="title"> 隐私变量是指一些密码字段或者关键密钥等重要信息,隐私字段只能修改不能查看(编辑弹窗中无法看到对应值)。 隐私字段一旦创建后将不能切换为非隐私字段 </template>
|
||||
<a-icon type="question-circle" theme="filled" />
|
||||
</a-tooltip>
|
||||
</template>
|
||||
<a-switch v-model="envTemp.privacy" :disabled="envTemp.id" checked-children="隐私" un-checked-children="非隐私" />
|
||||
</a-form-model-item>
|
||||
<a-form-model-item>
|
||||
<template slot="label">
|
||||
分发节点
|
||||
<a-tooltip v-show="!envTemp.id">
|
||||
<template slot="title"> 分发节点是指将变量同步到对应节点,在节点脚本中也可以使用当前变量</template>
|
||||
<a-icon type="question-circle" theme="filled" />
|
||||
</a-tooltip>
|
||||
</template>
|
||||
<a-select
|
||||
:getPopupContainer="
|
||||
(triggerNode) => {
|
||||
return triggerNode.parentNode || document.body;
|
||||
}
|
||||
"
|
||||
show-search
|
||||
option-filter-prop="children"
|
||||
placeholder="请选择分发到的节点"
|
||||
mode="multiple"
|
||||
v-model="envTemp.chooseNode"
|
||||
>
|
||||
<a-select-option v-for="item in nodeList" :key="item.id" :value="item.id">
|
||||
{{ item.name }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-model-item>
|
||||
</a-form-model>
|
||||
<workspaceEnv ref="workspaceEnv" :workspaceId="temp.id" />
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { deleteWorkspace, deleteWorkspaceEnv, editWorkSpace, editWorkspaceEnv, getWorkspaceEnvList, getWorkSpaceList } from "@/api/workspace";
|
||||
import { deleteWorkspace, editWorkSpace, getWorkSpaceList } from "@/api/workspace";
|
||||
import { parseTime } from "@/utils/time";
|
||||
import { CHANGE_PAGE, COMPUTED_PAGINATION, PAGE_DEFAULT_LIST_QUERY } from "@/utils/const";
|
||||
import { getNodeListByWorkspace } from "@/api/node";
|
||||
import workspaceEnv from "./workspace-env.vue";
|
||||
|
||||
export default {
|
||||
components: {
|
||||
workspaceEnv,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
loading: false,
|
||||
envVarLoading: false,
|
||||
list: [],
|
||||
envVarList: [],
|
||||
nodeList: [],
|
||||
envVarListQuery: Object.assign({}, PAGE_DEFAULT_LIST_QUERY),
|
||||
listQuery: Object.assign({}, PAGE_DEFAULT_LIST_QUERY),
|
||||
editVisible: false,
|
||||
envVarListVisible: false,
|
||||
editEnvVisible: false,
|
||||
temp: {},
|
||||
envTemp: {},
|
||||
columns: [
|
||||
{ title: "名称", dataIndex: "name", ellipsis: true, scopedSlots: { customRender: "name" } },
|
||||
{ title: "描述", dataIndex: "description", ellipsis: true, scopedSlots: { customRender: "description" } },
|
||||
@ -188,45 +100,18 @@ export default {
|
||||
},
|
||||
{ title: "操作", dataIndex: "operation", align: "center", scopedSlots: { customRender: "operation" }, width: 180 },
|
||||
],
|
||||
envVarColumns: [
|
||||
{ title: "名称", dataIndex: "name", ellipsis: true, scopedSlots: { customRender: "name" } },
|
||||
{ title: "值", dataIndex: "value", ellipsis: true, scopedSlots: { customRender: "value" } },
|
||||
{ title: "描述", dataIndex: "description", ellipsis: true, scopedSlots: { customRender: "description" } },
|
||||
{ title: "修改人", dataIndex: "modifyUser", ellipsis: true, scopedSlots: { customRender: "modifyUser" }, width: 120 },
|
||||
{
|
||||
title: "修改时间",
|
||||
dataIndex: "modifyTimeMillis",
|
||||
customRender: (text) => {
|
||||
if (!text) {
|
||||
return "";
|
||||
}
|
||||
return parseTime(text);
|
||||
},
|
||||
sorter: true,
|
||||
width: 180,
|
||||
},
|
||||
{ title: "操作", dataIndex: "operation", align: "center", scopedSlots: { customRender: "operation" }, width: 120 },
|
||||
],
|
||||
|
||||
// 表单校验规则
|
||||
rules: {
|
||||
name: [{ required: true, message: "请输入工作空间名称", trigger: "blur" }],
|
||||
description: [{ required: true, message: "请输入工作空间描述", trigger: "blur" }],
|
||||
},
|
||||
// 表单校验规则
|
||||
rulesEnv: {
|
||||
name: [{ required: true, message: "请输入变量名称", trigger: "blur" }],
|
||||
description: [{ required: true, message: "请输入变量描述", trigger: "blur" }],
|
||||
value: [{ required: true, message: "请输入变量值", trigger: "blur" }],
|
||||
},
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
pagination() {
|
||||
return COMPUTED_PAGINATION(this.listQuery);
|
||||
},
|
||||
envVarPagination() {
|
||||
return COMPUTED_PAGINATION(this.envVarListQuery);
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.loadData();
|
||||
@ -244,34 +129,17 @@ export default {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
loadDataEnvVar(pointerEvent) {
|
||||
this.envVarLoading = true;
|
||||
this.envVarListQuery.page = pointerEvent?.altKey || pointerEvent?.ctrlKey ? 1 : this.envVarListQuery.page;
|
||||
getWorkspaceEnvList(this.envVarListQuery).then((res) => {
|
||||
if (res.code === 200) {
|
||||
this.envVarList = res.data.result;
|
||||
this.envVarListQuery.total = res.data.total;
|
||||
}
|
||||
this.envVarLoading = false;
|
||||
});
|
||||
},
|
||||
|
||||
viewEnvVar(record) {
|
||||
this.temp = record;
|
||||
this.envTemp = {
|
||||
workspaceId: this.temp.id,
|
||||
};
|
||||
this.envVarListQuery.workspaceId = record.id;
|
||||
// this.envTemp = {
|
||||
// workspaceId: this.temp.id,
|
||||
// };
|
||||
// this.envVarListQuery.workspaceId = record.id;
|
||||
this.envVarListVisible = true;
|
||||
this.loadDataEnvVar();
|
||||
},
|
||||
addEnvVar() {
|
||||
this.envTemp = {
|
||||
workspaceId: this.temp.id,
|
||||
};
|
||||
|
||||
this.editEnvVisible = true;
|
||||
this.$refs["editEnvForm"] && this.$refs["editEnvForm"].resetFields();
|
||||
this.getAllNodeList(this.envTemp.workspaceId);
|
||||
this.$nextTick(() => {
|
||||
this.$refs.workspaceEnv.loadDataEnvVar();
|
||||
});
|
||||
},
|
||||
handleAdd() {
|
||||
this.temp = {};
|
||||
@ -282,13 +150,6 @@ export default {
|
||||
this.temp = record;
|
||||
this.editVisible = true;
|
||||
},
|
||||
handleEnvEdit(record) {
|
||||
this.envTemp = record;
|
||||
this.envTemp.workspaceId = this.temp.id;
|
||||
this.envTemp = { ...this.envTemp, chooseNode: record.nodeIds ? record.nodeIds.split(",") : [] };
|
||||
this.editEnvVisible = true;
|
||||
this.getAllNodeList(this.envTemp.workspaceId);
|
||||
},
|
||||
handleEditOk() {
|
||||
this.$refs["editForm"].validate((valid) => {
|
||||
if (!valid) {
|
||||
@ -307,58 +168,11 @@ export default {
|
||||
});
|
||||
});
|
||||
},
|
||||
handleEnvEditOk() {
|
||||
this.$refs["editEnvForm"].validate((valid) => {
|
||||
if (!valid) {
|
||||
return false;
|
||||
}
|
||||
this.envTemp.nodeIds = this.envTemp?.chooseNode?.join(",");
|
||||
editWorkspaceEnv(this.envTemp).then((res) => {
|
||||
if (res.code === 200) {
|
||||
// 成功
|
||||
this.$notification.success({
|
||||
message: res.msg,
|
||||
});
|
||||
this.$refs["editEnvForm"].resetFields();
|
||||
this.editEnvVisible = false;
|
||||
this.loadDataEnvVar();
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
// 分页、排序、筛选变化时触发
|
||||
changePage(pagination, filters, sorter) {
|
||||
this.listQuery = CHANGE_PAGE(this.listQuery, { pagination, sorter });
|
||||
this.loadData();
|
||||
},
|
||||
changeListeEnvVar(pagination, filters, sorter) {
|
||||
this.envVarListQuery = CHANGE_PAGE(this.envVarListQuery, { pagination, sorter });
|
||||
|
||||
this.loadDataEnvVar();
|
||||
},
|
||||
//
|
||||
handleEnvDelete(record) {
|
||||
this.$confirm({
|
||||
title: "系统提示",
|
||||
content: "真的当前工作空间么,删除前需要将关联数据都删除后才能删除当前工作空间?",
|
||||
okText: "确认",
|
||||
cancelText: "取消",
|
||||
onOk: () => {
|
||||
// 删除
|
||||
deleteWorkspaceEnv({
|
||||
id: record.id,
|
||||
workspaceId: this.temp.id,
|
||||
}).then((res) => {
|
||||
if (res.code === 200) {
|
||||
this.$notification.success({
|
||||
message: res.msg,
|
||||
});
|
||||
this.loadDataEnvVar();
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
// 删除
|
||||
handleDelete(record) {
|
||||
this.$confirm({
|
||||
@ -379,14 +193,6 @@ export default {
|
||||
},
|
||||
});
|
||||
},
|
||||
// 获取所有节点
|
||||
getAllNodeList(workspaceId) {
|
||||
getNodeListByWorkspace({
|
||||
workspaceId: workspaceId,
|
||||
}).then((res) => {
|
||||
this.nodeList = res.data || [];
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
@ -180,6 +180,11 @@ const children = [
|
||||
name: "system-workspace",
|
||||
component: () => import("../pages/system/workspace"),
|
||||
},
|
||||
{
|
||||
path: "/system/global-env",
|
||||
name: "global-env",
|
||||
component: () => import("../pages/system/global-env"),
|
||||
},
|
||||
];
|
||||
|
||||
const router = new Router({
|
||||
|
@ -41,6 +41,7 @@ const routeMenuMap = {
|
||||
// 数据库备份
|
||||
backup: "/system/backup",
|
||||
workspace: "/system/workspace",
|
||||
globalEnv: "/system/global-env",
|
||||
};
|
||||
|
||||
export default routeMenuMap;
|
||||
|
Loading…
Reference in New Issue
Block a user