mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-02 23:40:24 +08:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22c401f9d8 | ||
|
|
be00b90c1d | ||
|
|
fb3f89c594 | ||
|
|
e7a66378ea | ||
|
|
2f88b48973 | ||
|
|
7761fe0288 | ||
|
|
09e6bdcf7e | ||
|
|
61a4d87f59 | ||
|
|
c219ec33b0 | ||
|
|
fd86f36218 | ||
|
|
efac41f392 | ||
|
|
52df61ae0d |
@@ -19,7 +19,7 @@
|
||||
|
||||
|
||||
### 介绍
|
||||
基于DDD分层实现的web版 **linux(终端 文件 脚本 进程)、数据库(mysql postgres)、redis(单机 哨兵 集群)、mongo统一管理操作平台**
|
||||
web版 **linux(终端[终端回放] 文件 脚本 进程)、数据库(mysql postgres)、redis(单机 哨兵 集群)、mongo统一管理操作平台**
|
||||
|
||||
|
||||
### 开发语言与主要框架
|
||||
|
||||
@@ -95,6 +95,10 @@ function buildWindows() {
|
||||
build "$1/mayfly-go-windows" "windows" "amd64" $2
|
||||
}
|
||||
|
||||
function buildMac() {
|
||||
build "$1/mayfly-go-mac" "darwin" "amd64" $2
|
||||
}
|
||||
|
||||
function runBuild() {
|
||||
# 构建结果的目的路径
|
||||
read -p "请输入构建产物输出目录: " toPath
|
||||
@@ -107,28 +111,33 @@ function runBuild() {
|
||||
toPath=`pwd`
|
||||
|
||||
read -p "是否构建前端[0|其他->否 1->是 2->构建并拷贝至server/static/static]: " runBuildWeb
|
||||
read -p "请选择构建版本[0|其他->全部 1->linux-amd64 2->linux-arm64 3->windows]: " buildType
|
||||
read -p "请选择构建版本[0|其他->全部 1->linux-amd64 2->linux-arm64 3->windows 4->mac]: " buildType
|
||||
|
||||
buildWeb ${runBuildWeb}
|
||||
|
||||
if [ "${buildType}" == "1" ];then
|
||||
buildLinuxAmd64 ${toPath} ${runBuildWeb}
|
||||
exit;
|
||||
|
||||
if [ "${runBuildWeb}" == "1" ] || [ "${runBuildWeb}" == "2" ] ; then
|
||||
buildWeb ${runBuildWeb}
|
||||
fi
|
||||
|
||||
if [ "${buildType}" == "2" ];then
|
||||
buildLinuxArm64 ${toPath} ${runBuildWeb}
|
||||
exit;
|
||||
fi
|
||||
|
||||
if [ "${buildType}" == "3" ];then
|
||||
buildWindows ${toPath} ${runBuildWeb}
|
||||
exit;
|
||||
fi
|
||||
|
||||
buildLinuxAmd64 ${toPath}
|
||||
buildLinuxArm64 ${toPath}
|
||||
buildWindows ${toPath}
|
||||
case ${buildType} in
|
||||
"1")
|
||||
buildLinuxAmd64 ${toPath} ${runBuildWeb}
|
||||
;;
|
||||
"2")
|
||||
buildLinuxArm64 ${toPath} ${runBuildWeb}
|
||||
;;
|
||||
"3")
|
||||
buildWindows ${toPath} ${runBuildWeb}
|
||||
;;
|
||||
"4")
|
||||
buildMac ${toPath} ${runBuildWeb}
|
||||
;;
|
||||
*)
|
||||
buildLinuxAmd64 ${toPath} ${runBuildWeb}
|
||||
buildLinuxArm64 ${toPath} ${runBuildWeb}
|
||||
buildWindows ${toPath} ${runBuildWeb}
|
||||
buildMac ${toPath} ${runBuildWeb}
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
runBuild
|
||||
@@ -13,7 +13,7 @@
|
||||
"countup.js": "^2.0.7",
|
||||
"cropperjs": "^1.5.11",
|
||||
"echarts": "^5.3.3",
|
||||
"element-plus": "^2.2.14",
|
||||
"element-plus": "^2.2.17",
|
||||
"jsencrypt": "^3.2.1",
|
||||
"jsoneditor": "^9.9.0",
|
||||
"lodash": "^4.17.21",
|
||||
@@ -26,8 +26,8 @@
|
||||
"vue-clipboard3": "^1.0.1",
|
||||
"vue-router": "^4.1.2",
|
||||
"vuex": "^4.0.2",
|
||||
"xterm": "^4.19.0",
|
||||
"xterm-addon-fit": "^0.5.0"
|
||||
"xterm": "^5.0.0",
|
||||
"xterm-addon-fit": "^0.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash": "^4.14.178",
|
||||
@@ -38,6 +38,7 @@
|
||||
"@typescript-eslint/parser": "^4.23.0",
|
||||
"@vitejs/plugin-vue": "^2.3.3",
|
||||
"@vue/compiler-sfc": "^3.0.11",
|
||||
"asciinema-player": "^3.0.1",
|
||||
"dotenv": "^10.0.0",
|
||||
"eslint": "^8.5.0",
|
||||
"eslint-plugin-vue": "^8.2.0",
|
||||
|
||||
3
mayfly_go_web/shim.d.ts
vendored
3
mayfly_go_web/shim.d.ts
vendored
@@ -6,4 +6,5 @@ declare module '*.vue' {
|
||||
}
|
||||
declare module 'codemirror';
|
||||
declare module 'sql-formatter';
|
||||
declare module 'jsoneditor';
|
||||
declare module 'jsoneditor';
|
||||
declare module 'asciinema-player';
|
||||
@@ -11,6 +11,8 @@ import { useStore } from '@/store/index.ts';
|
||||
import { getLocal } from '@/common/utils/storage.ts';
|
||||
import LockScreen from '@/views/layout/lockScreen/index.vue';
|
||||
import Setings from '@/views/layout/navBars/breadcrumb/setings.vue';
|
||||
import Watermark from '@/common/utils/wartermark.ts';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'app',
|
||||
components: { LockScreen, Setings },
|
||||
@@ -57,6 +59,8 @@ export default defineComponent({
|
||||
() => route.path,
|
||||
() => {
|
||||
nextTick(() => {
|
||||
// 路由变化更新水印
|
||||
Watermark.use();
|
||||
document.title = `${route.meta.title} - ${getThemeConfig.value.globalTitle}` || getThemeConfig.value.globalTitle;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import request from './request'
|
||||
|
||||
export default {
|
||||
login: (param: any) => request.request('POST', '/sys/accounts/login', param, null),
|
||||
changePwd: (param: any) => request.request('POST', '/sys/accounts/change-pwd', param, null),
|
||||
getPublicKey: () => request.request('GET', '/common/public-key', null, null),
|
||||
captcha: () => request.request('GET', '/sys/captcha', null, null),
|
||||
logout: (param: any) => request.request('POST', '/sys/accounts/logout/{token}', param, null),
|
||||
getMenuRoute: (param: any) => request.request('Get', '/sys/resources/account', param, null)
|
||||
login: (param: any) => request.request('POST', '/sys/accounts/login', param),
|
||||
changePwd: (param: any) => request.request('POST', '/sys/accounts/change-pwd', param),
|
||||
getPublicKey: () => request.request('GET', '/common/public-key'),
|
||||
getConfigValue: (param: any) => request.request('GET', '/sys/configs/value', param),
|
||||
captcha: () => request.request('GET', '/sys/captcha'),
|
||||
logout: (param: any) => request.request('POST', '/sys/accounts/logout/{token}', param),
|
||||
getMenuRoute: (param: any) => request.request('Get', '/sys/resources/account', param)
|
||||
}
|
||||
48
mayfly_go_web/src/common/sysconfig.ts
Normal file
48
mayfly_go_web/src/common/sysconfig.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import openApi from './openApi';
|
||||
|
||||
// 登录是否使用验证码配置key
|
||||
const UseLoginCaptchaConfigKey = "UseLoginCaptcha"
|
||||
const UseWartermarkConfigKey = "UseWartermark"
|
||||
|
||||
/**
|
||||
* 获取系统配置值
|
||||
*
|
||||
* @param key 配置key
|
||||
* @returns 配置值
|
||||
*/
|
||||
export async function getConfigValue(key: string) : Promise<string> {
|
||||
return await openApi.getConfigValue({key}) as string
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取bool类型系统配置值
|
||||
*
|
||||
* @param key 配置key
|
||||
* @param defaultValue 默认值
|
||||
* @returns 是否为ture,1: true;其他: false
|
||||
*/
|
||||
export async function getBoolConfigValue(key :string, defaultValue :boolean) : Promise<boolean> {
|
||||
const value = await getConfigValue(key)
|
||||
if (!value) {
|
||||
return defaultValue;
|
||||
}
|
||||
return value == "1";
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否使用登录验证码
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
export async function useLoginCaptcha() : Promise<boolean> {
|
||||
return await getBoolConfigValue(UseLoginCaptchaConfigKey, true)
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否启用水印
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
export async function useWartermark() : Promise<boolean> {
|
||||
return await getBoolConfigValue(UseWartermarkConfigKey, true)
|
||||
}
|
||||
@@ -35,3 +35,22 @@ export function removeSession(key: string) {
|
||||
export function clearSession() {
|
||||
window.sessionStorage.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function getUserInfo4Session() {
|
||||
return getSession("userInfo")
|
||||
}
|
||||
|
||||
export function setUserInfo2Session(userinfo: any) {
|
||||
setSession("userInfo", userinfo)
|
||||
}
|
||||
|
||||
// 获取是否开启水印
|
||||
export function getUseWatermark4Session() {
|
||||
return getSession("useWatermark")
|
||||
}
|
||||
|
||||
export function setUseWatermark2Session(useWatermark: boolean) {
|
||||
setSession("useWatermark", useWatermark)
|
||||
}
|
||||
@@ -1,21 +1,26 @@
|
||||
import { getUseWatermark4Session, getUserInfo4Session } from '@/common/utils/storage.ts';
|
||||
import { dateFormat } from '@/common/utils/date.ts'
|
||||
|
||||
// 页面添加水印效果
|
||||
const setWatermark = (str: any) => {
|
||||
const id = '1.23452384164.123412416';
|
||||
if (document.getElementById(id) !== null) document.body.removeChild(document.getElementById(id) as any);
|
||||
const can = document.createElement('canvas');
|
||||
can.width = 250;
|
||||
can.height = 180;
|
||||
can.width = 400;
|
||||
can.height = 250;
|
||||
const cans: any = can.getContext('2d');
|
||||
cans.rotate((-20 * Math.PI) / 180);
|
||||
cans.font = '12px Vedana';
|
||||
cans.fillStyle = 'rgba(200, 200, 200, 0.30)';
|
||||
cans.textAlign = 'center';
|
||||
cans.font = '14px Vedana';
|
||||
cans.fillStyle = 'rgba(200, 200, 200, 0.35)';
|
||||
cans.textAlign = 'left';
|
||||
cans.textBaseline = 'Middle';
|
||||
cans.fillText(str, can.width / 10, can.height / 2);
|
||||
// cans.fillText('mayfly go', can.width / 4, can.height )
|
||||
cans.fillText(str, can.width / 8, can.height / 2);
|
||||
|
||||
const div = document.createElement('div');
|
||||
div.id = id;
|
||||
div.style.pointerEvents = 'none';
|
||||
div.style.top = '35px';
|
||||
div.style.top = '30px';
|
||||
div.style.left = '0px';
|
||||
div.style.position = 'fixed';
|
||||
div.style.zIndex = '10000000';
|
||||
@@ -26,16 +31,34 @@ const setWatermark = (str: any) => {
|
||||
return id;
|
||||
};
|
||||
|
||||
function set(str: any) {
|
||||
let id = setWatermark(str);
|
||||
if (document.getElementById(id) === null) id = setWatermark(str);
|
||||
}
|
||||
|
||||
function del() {
|
||||
let id = '1.23452384164.123412416';
|
||||
if (document.getElementById(id) !== null) document.body.removeChild(document.getElementById(id) as any);
|
||||
}
|
||||
|
||||
const watermark = {
|
||||
use: () => {
|
||||
setTimeout(() => {
|
||||
const userinfo = getUserInfo4Session()
|
||||
if (userinfo && getUseWatermark4Session()) {
|
||||
set(`${userinfo.username} ${dateFormat('yyyy-MM-dd HH:mm:ss', new Date())}`)
|
||||
} else {
|
||||
del();
|
||||
}
|
||||
}, 1500)
|
||||
},
|
||||
// 设置水印
|
||||
set: (str: any) => {
|
||||
let id = setWatermark(str);
|
||||
if (document.getElementById(id) === null) id = setWatermark(str);
|
||||
set(str)
|
||||
},
|
||||
// 删除水印
|
||||
del: () => {
|
||||
let id = '1.23452384164.123412416';
|
||||
if (document.getElementById(id) !== null) document.body.removeChild(document.getElementById(id) as any);
|
||||
del();
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import RouterParent from '@/views/layout/routerView/parent.vue';
|
||||
|
||||
export const imports = {
|
||||
'RouterParent': RouterParent,
|
||||
|
||||
"Home": () => import('@/views/home/index.vue'),
|
||||
'Personal': () => import('@/views/personal/index.vue'),
|
||||
// machine
|
||||
@@ -11,6 +12,8 @@ export const imports = {
|
||||
"RoleList": () => import('@/views/system/role'),
|
||||
"AccountList": () => import('@/views/system/account'),
|
||||
"SyslogList": () => import('@/views/system/syslog/SyslogList.vue'),
|
||||
"ConfigList": () => import('@/views/system/config/ConfigList.vue'),
|
||||
|
||||
// project
|
||||
"ProjectList": () => import('@/views/ops/project/ProjectList.vue'),
|
||||
// db
|
||||
|
||||
@@ -163,7 +163,17 @@ export const staticRoutes: Array<RouteRecordRaw> = [
|
||||
title: '终端 | {name}',
|
||||
// 是否根据query对标题名进行参数替换,即最终显示为‘终端_机器名’
|
||||
titleRename: true,
|
||||
icon: 'iconfont icon-caidan',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/machine/terminal-rec',
|
||||
name: 'machineTerminalRec',
|
||||
component: () => import('@/views/ops/machine/MachineRec.vue'),
|
||||
meta: {
|
||||
// 将路径 'xxx?name=名字' 里的name字段值替换到title里
|
||||
title: '终端回放 | {name}',
|
||||
// 是否根据query对标题名进行参数替换,即最终显示为‘终端_机器名’
|
||||
titleRename: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@@ -14,7 +14,7 @@ body,
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-family: Microsoft YaHei, Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, SimSun, sans-serif;
|
||||
font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
|
||||
font-weight: 450;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
|
||||
@@ -273,23 +273,6 @@
|
||||
<el-switch v-model="getThemeConfig.isInvert" @change="onAddFilterChange('invert')"></el-switch>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layout-breadcrumb-seting-bar-flex mt15">
|
||||
<div class="layout-breadcrumb-seting-bar-flex-label">开启水印</div>
|
||||
<div class="layout-breadcrumb-seting-bar-flex-value">
|
||||
<el-switch v-model="getThemeConfig.isWartermark" @change="onWartermarkChange"></el-switch>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layout-breadcrumb-seting-bar-flex mt14">
|
||||
<div class="layout-breadcrumb-seting-bar-flex-label">水印文案</div>
|
||||
<div class="layout-breadcrumb-seting-bar-flex-value">
|
||||
<el-input
|
||||
v-model="getThemeConfig.wartermarkText"
|
||||
size="small"
|
||||
style="width: 90px"
|
||||
@input="onWartermarkTextInput($event)"
|
||||
></el-input>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 其它设置 -->
|
||||
<el-divider content-position="left">其他设置</el-divider>
|
||||
@@ -440,8 +423,6 @@ import { ElMessage } from 'element-plus';
|
||||
import ClipboardJS from 'clipboard';
|
||||
import { useStore } from '@/store/index.ts';
|
||||
import { getLightColor } from '@/common/utils/theme.ts';
|
||||
import Watermark from '@/common/utils/wartermark.ts';
|
||||
import { verifyAndSpace } from '@/common/utils/toolsValidate.ts';
|
||||
import { setLocal, getLocal, removeLocal } from '@/common/utils/storage.ts';
|
||||
export default defineComponent({
|
||||
name: 'layoutBreadcrumbSeting',
|
||||
@@ -572,18 +553,6 @@ export default defineComponent({
|
||||
setLocalThemeConfig();
|
||||
setLocal('appFilterStyle', appEle.style.cssText);
|
||||
};
|
||||
// 4、界面显示 --> 开启水印
|
||||
const onWartermarkChange = () => {
|
||||
getThemeConfig.value.isWartermark ? Watermark.set(getThemeConfig.value.wartermarkText) : Watermark.del();
|
||||
setLocalThemeConfig();
|
||||
};
|
||||
// 4、界面显示 --> 水印文案
|
||||
const onWartermarkTextInput = (val: string) => {
|
||||
getThemeConfig.value.wartermarkText = verifyAndSpace(val);
|
||||
if (getThemeConfig.value.wartermarkText === '') return false;
|
||||
if (getThemeConfig.value.isWartermark) Watermark.set(getThemeConfig.value.wartermarkText);
|
||||
setLocalThemeConfig();
|
||||
};
|
||||
// 5、布局切换
|
||||
const onSetLayout = (layout: string) => {
|
||||
setLocal('oldLayout', layout);
|
||||
@@ -735,8 +704,6 @@ export default defineComponent({
|
||||
const appEl: any = document.querySelector('#app');
|
||||
appEl.style.cssText = getLocal('appFilterStyle');
|
||||
}
|
||||
// 开启水印
|
||||
onWartermarkChange();
|
||||
// // 语言国际化
|
||||
// if (getLocal('themeConfig')) proxy.$i18n.locale = getLocal('themeConfig').globalI18n;
|
||||
}, 1100);
|
||||
@@ -762,8 +729,6 @@ export default defineComponent({
|
||||
getThemeConfig,
|
||||
onDrawerClose,
|
||||
onAddFilterChange,
|
||||
onWartermarkChange,
|
||||
onWartermarkTextInput,
|
||||
onSetLayout,
|
||||
setLocalThemeConfig,
|
||||
onClassicSplitMenuChange,
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<el-input type="password" placeholder="请输入密码" prefix-icon="lock" v-model="loginForm.password" autocomplete="off" show-password>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="captcha">
|
||||
<el-form-item v-if="useLoginCaptcha" prop="captcha">
|
||||
<el-row :gutter="15">
|
||||
<el-col :span="16">
|
||||
<el-input
|
||||
@@ -73,15 +73,16 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { onMounted, ref, toRefs, reactive, defineComponent, computed } from 'vue';
|
||||
import { nextTick, onMounted, ref, toRefs, reactive, defineComponent, computed } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { initBackEndControlRoutesFun } from '@/router/index.ts';
|
||||
import { useStore } from '@/store/index.ts';
|
||||
import { setSession } from '@/common/utils/storage.ts';
|
||||
import { setSession, setUserInfo2Session, setUseWatermark2Session } from '@/common/utils/storage.ts';
|
||||
import { formatAxis } from '@/common/utils/formatTime.ts';
|
||||
import openApi from '@/common/openApi';
|
||||
import { RsaEncrypt } from '@/common/rsa';
|
||||
import { useLoginCaptcha, useWartermark } from '@/common/sysconfig';
|
||||
import { letterAvatar } from '@/common/utils/string';
|
||||
|
||||
export default defineComponent({
|
||||
@@ -94,6 +95,7 @@ export default defineComponent({
|
||||
const changePwdFormRef: any = ref(null);
|
||||
|
||||
const state = reactive({
|
||||
useLoginCaptcha: false,
|
||||
captchaImage: '',
|
||||
loginForm: {
|
||||
username: '',
|
||||
@@ -130,13 +132,19 @@ export default defineComponent({
|
||||
},
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
nextTick(async () => {
|
||||
state.useLoginCaptcha = await useLoginCaptcha();
|
||||
getCaptcha();
|
||||
});
|
||||
// 移除公钥, 方便后续重新获取
|
||||
sessionStorage.removeItem('RsaPublicKey')
|
||||
getCaptcha();
|
||||
sessionStorage.removeItem('RsaPublicKey');
|
||||
});
|
||||
|
||||
const getCaptcha = async () => {
|
||||
if (!state.useLoginCaptcha) {
|
||||
return;
|
||||
}
|
||||
let res: any = await openApi.captcha();
|
||||
state.captchaImage = res.base64Captcha;
|
||||
state.loginForm.cid = res.cid;
|
||||
@@ -198,7 +206,7 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
// 存储用户信息到浏览器缓存
|
||||
setSession('userInfo', userInfos);
|
||||
setUserInfo2Session(userInfos);
|
||||
// 1、请注意执行顺序(存储用户信息到vuex)
|
||||
store.dispatch('userInfos/setUserInfos', userInfos);
|
||||
if (!store.state.themeConfig.themeConfig.isRequestRoutes) {
|
||||
@@ -224,10 +232,13 @@ export default defineComponent({
|
||||
// 如果是复制粘贴的路径,非首页/登录页,那么登录成功后重定向到对应的路径中
|
||||
route.query?.redirect ? router.push(route.query.redirect as string) : router.push('/');
|
||||
// 登录成功提示
|
||||
setTimeout(() => {
|
||||
setTimeout(async () => {
|
||||
// 关闭 loading
|
||||
state.loading.signIn = true;
|
||||
ElMessage.success(`${currentTimeInfo},欢迎回来!`);
|
||||
if (await useWartermark()) {
|
||||
setUseWatermark2Session(true);
|
||||
}
|
||||
}, 300);
|
||||
};
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
</el-form-item>
|
||||
<el-form-item prop="host" label="host:" required>
|
||||
<el-col :span="18">
|
||||
<el-input v-model.trim="form.host" placeholder="请输入主机ip" auto-complete="off"></el-input>
|
||||
<el-input :disabled="form.id" v-model.trim="form.host" placeholder="请输入主机ip" auto-complete="off"></el-input>
|
||||
</el-col>
|
||||
<el-col style="text-align: center" :span="1">:</el-col>
|
||||
<el-col :span="5">
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
>删除</el-button
|
||||
>
|
||||
<div style="float: right">
|
||||
<el-select v-model="query.projectId" placeholder="请选择项目" filterable clearable>
|
||||
<el-select @focus="getProjects" v-model="query.projectId" placeholder="请选择项目" filterable clearable>
|
||||
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
</el-select>
|
||||
<el-button v-waves type="primary" icon="search" @click="search()" class="ml5">查询</el-button>
|
||||
@@ -29,18 +29,23 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="type" label="类型" min-width="90"></el-table-column>
|
||||
<el-table-column prop="database" label="数据库" min-width="160">
|
||||
<el-table-column prop="database" label="数据库" min-width="80">
|
||||
<template #default="scope">
|
||||
<el-tag
|
||||
@click="showTableInfo(scope.row, db)"
|
||||
effect="plain"
|
||||
type="success"
|
||||
size="small"
|
||||
v-for="db in scope.row.dbs"
|
||||
:key="db"
|
||||
style="cursor: pointer; margin-left: 3px"
|
||||
>{{ db }}</el-tag
|
||||
>
|
||||
<el-popover :width="250" placement="right" trigger="click">
|
||||
<template #reference>
|
||||
<el-link type="primary" :underline="false" plain>查看</el-link>
|
||||
</template>
|
||||
<el-tag
|
||||
@click="showTableInfo(scope.row, db)"
|
||||
effect="plain"
|
||||
type="success"
|
||||
size="small"
|
||||
v-for="db in scope.row.dbs"
|
||||
:key="db"
|
||||
style="cursor: pointer; margin-left: 3px; margin-bottom: 3px;"
|
||||
>{{ db }}</el-tag
|
||||
>
|
||||
</el-popover>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="username" label="用户名" min-width="100"></el-table-column>
|
||||
@@ -161,8 +166,10 @@
|
||||
v-model="sqlExecLogDialog.visible"
|
||||
>
|
||||
<div class="toolbar">
|
||||
<el-input v-model="sqlExecLogDialog.query.db" placeholder="请输入数据库名" clearable style="width: 150px" />
|
||||
<el-input v-model="sqlExecLogDialog.query.table" placeholder="请输入表名" clearable class="ml5" style="width: 150px" />
|
||||
<el-select v-model="sqlExecLogDialog.query.db" placeholder="请选择数据库" filterable clearable>
|
||||
<el-option v-for="item in sqlExecLogDialog.dbs" :key="item" :label="`${item}`" :value="item"> </el-option>
|
||||
</el-select>
|
||||
<el-input v-model="sqlExecLogDialog.query.table" placeholder="请输入表名" clearable class="ml5" style="width: 180px" />
|
||||
<el-select v-model="sqlExecLogDialog.query.type" placeholder="请选择操作类型" clearable class="ml5">
|
||||
<el-option v-for="item in enums.DbSqlExecTypeEnum" :key="item.value" :label="item.label" :value="item.value"> </el-option>
|
||||
</el-select>
|
||||
@@ -307,6 +314,7 @@ export default defineComponent({
|
||||
visible: false,
|
||||
data: [],
|
||||
total: 0,
|
||||
dbs: [],
|
||||
query: {
|
||||
dbId: 0,
|
||||
db: '',
|
||||
@@ -398,8 +406,12 @@ export default defineComponent({
|
||||
search();
|
||||
};
|
||||
|
||||
const editDb = async (isAdd = false) => {
|
||||
const getProjects = async () => {
|
||||
state.projects = await projectApi.accountProjects.request(null);
|
||||
};
|
||||
|
||||
const editDb = async (isAdd = false) => {
|
||||
await getProjects();
|
||||
if (isAdd) {
|
||||
state.dbEditDialog.data = null;
|
||||
state.dbEditDialog.title = '新增数据库资源';
|
||||
@@ -434,6 +446,7 @@ export default defineComponent({
|
||||
const onShowSqlExec = async (row: any) => {
|
||||
state.sqlExecLogDialog.title = `${row.name}[${row.host}:${row.port}]`;
|
||||
state.sqlExecLogDialog.query.dbId = row.id;
|
||||
state.sqlExecLogDialog.dbs = row.database.split(' ');
|
||||
searchSqlExecLog();
|
||||
state.sqlExecLogDialog.visible = true;
|
||||
};
|
||||
@@ -441,6 +454,7 @@ export default defineComponent({
|
||||
const onBeforeCloseSqlExecDialog = () => {
|
||||
state.sqlExecLogDialog.visible = false;
|
||||
state.sqlExecLogDialog.data = [];
|
||||
state.sqlExecLogDialog.dbs = [];
|
||||
state.sqlExecLogDialog.total = 0;
|
||||
state.sqlExecLogDialog.query.dbId = 0;
|
||||
state.sqlExecLogDialog.query.pageNum = 1;
|
||||
@@ -602,6 +616,7 @@ export default defineComponent({
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
getProjects,
|
||||
filterTableInfos,
|
||||
enums,
|
||||
search,
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-button-group :style="btnStyle">
|
||||
<el-button @click="onRunSql" type="success" icon="video-play" size="small" plain>执行</el-button>
|
||||
<el-button @click="formatSql" type="primary" icon="magic-stick" size="small" plain>格式化</el-button>
|
||||
</el-button-group>
|
||||
<div class="toolbar">
|
||||
<el-row type="flex" justify="space-between">
|
||||
<el-col :span="24">
|
||||
@@ -58,6 +54,19 @@
|
||||
<div>
|
||||
<div class="toolbar">
|
||||
<div class="fl">
|
||||
<el-link @click="onRunSql" :underline="false" class="ml15" icon="VideoPlay"></el-link>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
|
||||
<el-tooltip class="box-item" effect="dark" content="format sql" placement="top">
|
||||
<el-link @click="formatSql" type="primary" :underline="false" icon="MagicStick"></el-link>
|
||||
</el-tooltip>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
|
||||
<el-tooltip class="box-item" effect="dark" content="commit" placement="top">
|
||||
<el-link @click="onCommit" type="success" :underline="false" icon="CircleCheck"></el-link>
|
||||
</el-tooltip>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
|
||||
<el-upload
|
||||
style="display: inline-block"
|
||||
:before-upload="beforeUpload"
|
||||
@@ -72,11 +81,10 @@
|
||||
multiple
|
||||
:limit="100"
|
||||
>
|
||||
<el-button type="success" icon="video-play" plain size="small">sql脚本执行</el-button>
|
||||
<el-tooltip class="box-item" effect="dark" content="SQL脚本执行" placement="top">
|
||||
<el-link type="success" :underline="false" icon="Document"></el-link>
|
||||
</el-tooltip>
|
||||
</el-upload>
|
||||
<el-button @click="onCommit" class="ml5 mb5" type="success" icon="CircleCheck" plain size="small"
|
||||
>commit</el-button
|
||||
>
|
||||
</div>
|
||||
|
||||
<div style="float: right" class="fl">
|
||||
@@ -101,7 +109,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div @click="closeExecBtns" class="mt5 sqlEditor" @contextmenu="showExecBtns">
|
||||
<div class="mt5 sqlEditor">
|
||||
<textarea ref="codeTextarea"></textarea>
|
||||
</div>
|
||||
|
||||
@@ -145,56 +153,64 @@
|
||||
|
||||
<el-tab-pane closable v-for="dt in dataTabs" :key="dt.name" :label="dt.label" :name="dt.name">
|
||||
<el-row v-if="dbId">
|
||||
<el-link @click="onRefresh(dt.name)" icon="refresh" :underline="false" class="ml5"></el-link>
|
||||
<el-link @click="addRow" class="ml5" type="primary" icon="plus" :underline="false"></el-link>
|
||||
<el-link @click="onDeleteData" class="ml5" type="danger" icon="delete" :underline="false"></el-link>
|
||||
<el-col :span="8">
|
||||
<el-link @click="onRefresh(dt.name)" icon="refresh" :underline="false" class="ml5"></el-link>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
|
||||
<el-tooltip class="box-item" effect="dark" content="commit" placement="top">
|
||||
<el-link @click="onCommit" class="ml5" type="success" icon="check" :underline="false"></el-link>
|
||||
</el-tooltip>
|
||||
<el-link @click="addRow" type="primary" icon="plus" :underline="false"></el-link>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
|
||||
<el-tooltip class="box-item" effect="dark" content="生成insert sql" placement="top">
|
||||
<el-link @click="onGenerateInsertSql" type="success" class="ml20" :underline="false">gi</el-link>
|
||||
</el-tooltip>
|
||||
</el-row>
|
||||
<el-row class="mt5">
|
||||
<el-input
|
||||
v-model="dt.condition"
|
||||
placeholder="若需条件过滤,可选择列并点击对应的字段并输入需要过滤的内容点击查询按钮即可"
|
||||
clearable
|
||||
size="small"
|
||||
>
|
||||
<template #prepend>
|
||||
<el-popover :visible="dt.selectColumnPopoverVisible" :width="320" placement="right">
|
||||
<template #reference>
|
||||
<el-link
|
||||
@click="dt.selectColumnPopoverVisible = !dt.selectColumnPopoverVisible"
|
||||
type="success"
|
||||
:underline="false"
|
||||
>选择列</el-link
|
||||
<el-link @click="onDeleteData" type="danger" icon="delete" :underline="false"></el-link>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
|
||||
<el-tooltip class="box-item" effect="dark" content="commit" placement="top">
|
||||
<el-link @click="onCommit" type="success" icon="CircleCheck" :underline="false"></el-link>
|
||||
</el-tooltip>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
|
||||
<el-tooltip class="box-item" effect="dark" content="生成insert sql" placement="top">
|
||||
<el-link @click="onGenerateInsertSql" type="success" :underline="false">gi</el-link>
|
||||
</el-tooltip>
|
||||
</el-col>
|
||||
<el-col :span="16">
|
||||
<el-input
|
||||
v-model="dt.condition"
|
||||
placeholder="若需条件过滤,可选择列并点击对应的字段并输入需要过滤的内容点击查询按钮即可"
|
||||
clearable
|
||||
size="small"
|
||||
style="width: 100%"
|
||||
>
|
||||
<template #prepend>
|
||||
<el-popover trigger="click" :width="320" placement="right">
|
||||
<template #reference>
|
||||
<el-link
|
||||
type="success"
|
||||
:underline="false"
|
||||
>选择列</el-link
|
||||
>
|
||||
</template>
|
||||
<el-table
|
||||
:data="getColumns4Map(dt.name)"
|
||||
max-height="500"
|
||||
size="small"
|
||||
@row-click="
|
||||
(...event) => {
|
||||
onConditionRowClick(event, dt);
|
||||
}
|
||||
"
|
||||
style="cursor: pointer"
|
||||
>
|
||||
</template>
|
||||
<el-table
|
||||
:data="getColumns4Map(dt.name)"
|
||||
max-height="500"
|
||||
size="small"
|
||||
@row-click="
|
||||
(...event) => {
|
||||
onConditionRowClick(event, dt);
|
||||
}
|
||||
"
|
||||
style="cursor: pointer"
|
||||
>
|
||||
<el-table-column property="columnName" label="列名" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column property="columnComment" label="备注" show-overflow-tooltip> </el-table-column>
|
||||
</el-table>
|
||||
</el-popover>
|
||||
</template>
|
||||
<el-table-column property="columnName" label="列名" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column property="columnComment" label="备注" show-overflow-tooltip> </el-table-column>
|
||||
</el-table>
|
||||
</el-popover>
|
||||
</template>
|
||||
|
||||
<template #append>
|
||||
<el-button @click="selectByCondition(dt.name, dt.condition)" icon="search" size="small"></el-button>
|
||||
</template>
|
||||
</el-input>
|
||||
<template #append>
|
||||
<el-button @click="selectByCondition(dt.name, dt.condition)" icon="search" size="small"></el-button>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-table
|
||||
@cell-dblclick="cellClick"
|
||||
@@ -344,14 +360,6 @@ export default defineComponent({
|
||||
pageSize: 10,
|
||||
envId: null,
|
||||
},
|
||||
btnStyle: {
|
||||
position: 'absolute',
|
||||
zIndex: 1000,
|
||||
display: 'none',
|
||||
left: '',
|
||||
top: '',
|
||||
},
|
||||
selectColumnPopoverVisible: false,
|
||||
conditionDialog: {
|
||||
title: '',
|
||||
placeholder: '',
|
||||
@@ -417,7 +425,7 @@ export default defineComponent({
|
||||
const setHeight = () => {
|
||||
// 默认300px
|
||||
codemirror.setSize('auto', `${window.innerHeight - 538}px`);
|
||||
state.dataTabsTableHeight = window.innerHeight - 258 - 33;
|
||||
state.dataTabsTableHeight = window.innerHeight - 274;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -486,7 +494,6 @@ export default defineComponent({
|
||||
} catch (e: any) {
|
||||
state.queryTab.loading = false;
|
||||
}
|
||||
closeExecBtns();
|
||||
|
||||
// 即只有以该字符串开头的sql才可修改表数据内容
|
||||
if (sql.startsWith('SELECT *') || sql.startsWith('select *') || sql.startsWith('SELECT\n *')) {
|
||||
@@ -729,7 +736,6 @@ export default defineComponent({
|
||||
columnNames: [],
|
||||
pageNum: 1,
|
||||
count: 0,
|
||||
selectColumnPopoverVisible: false,
|
||||
};
|
||||
tab.columnNames = await getColumnNames(tableName);
|
||||
state.dataTabs[tableName] = tab;
|
||||
@@ -769,7 +775,6 @@ export default defineComponent({
|
||||
* 条件查询,点击列信息后显示输入对应的值
|
||||
*/
|
||||
const onConditionRowClick = (event: any, dataTab: any) => {
|
||||
dataTab.selectColumnPopoverVisible = false;
|
||||
const row = event[0];
|
||||
state.conditionDialog.title = `请输入 [${row.columnName}] 的值`;
|
||||
state.conditionDialog.placeholder = `${row.columnType} ${row.columnComment}`;
|
||||
@@ -993,7 +998,6 @@ export default defineComponent({
|
||||
state.queryTab.execRes.tableColumn = [];
|
||||
state.cmOptions.hintOptions.tables = [];
|
||||
tableMap.clear();
|
||||
closeExecBtns();
|
||||
};
|
||||
|
||||
const onDataSelectionChange = (datas: []) => {
|
||||
@@ -1169,7 +1173,6 @@ export default defineComponent({
|
||||
let selectSql = codemirror.getSelection();
|
||||
isTrue(selectSql, '请选中需要格式化的sql');
|
||||
codemirror.replaceSelection(sqlFormatter(selectSql));
|
||||
closeExecBtns();
|
||||
};
|
||||
|
||||
const search = async () => {
|
||||
@@ -1177,31 +1180,6 @@ export default defineComponent({
|
||||
state.dbs = res.list;
|
||||
};
|
||||
|
||||
/**
|
||||
* 显示执行sql和格式化按钮
|
||||
*/
|
||||
const showExecBtns = (event: any) => {
|
||||
if (event.preventDefault) {
|
||||
event.preventDefault();
|
||||
} else {
|
||||
event.returnValue = false;
|
||||
}
|
||||
state.btnStyle.display = 'inline';
|
||||
state.btnStyle.left = event.offsetX + 15 + 'px';
|
||||
state.btnStyle.top = event.clientY - 80 + 'px';
|
||||
};
|
||||
|
||||
/**
|
||||
* 关闭执行sql和格式化按钮
|
||||
*/
|
||||
const closeExecBtns = () => {
|
||||
if (state.btnStyle.left) {
|
||||
state.btnStyle.display = 'none';
|
||||
state.btnStyle.left = '';
|
||||
state.btnStyle.top = '';
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
codeTextarea,
|
||||
@@ -1237,8 +1215,6 @@ export default defineComponent({
|
||||
onDeleteData,
|
||||
onTableSortChange,
|
||||
onGenerateInsertSql,
|
||||
showExecBtns,
|
||||
closeExecBtns,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
</el-row>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog :title="tree.title" v-model="tree.visible" :close-on-click-modal="false" width="50%">
|
||||
<el-dialog :title="tree.title" v-model="tree.visible" :close-on-click-modal="false" width="70%">
|
||||
<el-progress
|
||||
v-if="uploadProgressShow"
|
||||
style="width: 90%; margin-left: 20px"
|
||||
@@ -66,7 +66,7 @@
|
||||
:percentage="progressNum"
|
||||
/>
|
||||
<div style="height: 45vh; overflow: auto">
|
||||
<el-tree v-if="tree.visible" ref="fileTree" :load="loadNode" :props="props" lazy node-key="id" :expand-on-click-node="true">
|
||||
<el-tree v-if="tree.visible" ref="fileTree" :highlight-current="true" :load="loadNode" :props="props" lazy node-key="id" :expand-on-click-node="true">
|
||||
<template #default="{ node, data }">
|
||||
<span class="custom-tree-node">
|
||||
<el-dropdown size="small" @visible-change="getFilePath(data, $event)" trigger="contextmenu">
|
||||
@@ -85,6 +85,10 @@
|
||||
{{ node.label }}
|
||||
<span style="color: #67c23a" v-if="data.type == '-'"> [{{ formatFileSize(data.size) }}]</span>
|
||||
</span>
|
||||
|
||||
<span style="display: inline-block">
|
||||
<span v-if="data.mode" style="color: #67c23a"> [{{ data.mode }} {{ data.modTime }}]</span>
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<template #dropdown>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
</el-form-item>
|
||||
<el-form-item prop="ip" label="ip:" required>
|
||||
<el-col :span="18">
|
||||
<el-input v-model.trim="form.ip" placeholder="主机ip" auto-complete="off"></el-input>
|
||||
<el-input :disabled="form.id" v-model.trim="form.ip" placeholder="主机ip" auto-complete="off"></el-input>
|
||||
</el-col>
|
||||
<el-col style="text-align: center" :span="1">:</el-col>
|
||||
<el-col :span="5">
|
||||
@@ -52,6 +52,10 @@
|
||||
<el-input type="textarea" v-model="form.remark"></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="enableRecorder" label="终端回放:">
|
||||
<el-checkbox v-model="form.enableRecorder" :true-label="1" :false-label="-1"></el-checkbox>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="enableSshTunnel" label="SSH隧道:">
|
||||
<el-col :span="3">
|
||||
<el-checkbox @change="getSshTunnelMachines" v-model="form.enableSshTunnel" :true-label="1" :false-label="-1"></el-checkbox>
|
||||
@@ -122,6 +126,7 @@ export default defineComponent({
|
||||
remark: '',
|
||||
enableSshTunnel: null,
|
||||
sshTunnelMachineId: null,
|
||||
enableRecorder: -1,
|
||||
},
|
||||
pwd: '',
|
||||
btnLoading: false,
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
>删除</el-button
|
||||
>
|
||||
<div style="float: right">
|
||||
<el-select v-model="params.projectId" placeholder="请选择项目" @clear="search" filterable clearable>
|
||||
<el-select @focus="getProjects" v-model="params.projectId" placeholder="请选择项目" @clear="search" filterable clearable>
|
||||
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
</el-select>
|
||||
<el-input
|
||||
@@ -74,30 +74,39 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="creator" label="创建者" min-width="80"></el-table-column>
|
||||
<el-table-column label="操作" min-width="280" fixed="right">
|
||||
<el-table-column label="操作" min-width="335" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-link
|
||||
v-auth="'machine:terminal'"
|
||||
:disabled="scope.row.status == -1"
|
||||
type="primary"
|
||||
@click="showTerminal(scope.row)"
|
||||
plain
|
||||
size="small"
|
||||
:underline="false"
|
||||
>终端</el-link
|
||||
>
|
||||
<el-divider v-auth="'machine:terminal'" direction="vertical" border-style="dashed" />
|
||||
<el-link
|
||||
v-auth="'machine:file'"
|
||||
type="success"
|
||||
:disabled="scope.row.status == -1"
|
||||
@click="fileManage(scope.row)"
|
||||
plain
|
||||
size="small"
|
||||
:underline="false"
|
||||
>文件</el-link
|
||||
>
|
||||
<el-divider v-auth="'machine:file'" direction="vertical" border-style="dashed" />
|
||||
<span v-auth="'machine:terminal'">
|
||||
<el-link
|
||||
:disabled="scope.row.status == -1"
|
||||
type="primary"
|
||||
@click="showTerminal(scope.row)"
|
||||
plain
|
||||
size="small"
|
||||
:underline="false"
|
||||
>终端</el-link
|
||||
>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
</span>
|
||||
|
||||
<span v-auth="'machine:update'" v-if="scope.row.enableRecorder == 1">
|
||||
<el-link @click="showRec(scope.row)" plain :underline="false" size="small">终端回放</el-link>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
</span>
|
||||
|
||||
<span v-auth="'machine:file'">
|
||||
<el-link
|
||||
type="success"
|
||||
:disabled="scope.row.status == -1"
|
||||
@click="fileManage(scope.row)"
|
||||
plain
|
||||
size="small"
|
||||
:underline="false"
|
||||
>文件</el-link
|
||||
>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
</span>
|
||||
|
||||
<el-link
|
||||
:disabled="scope.row.status == -1"
|
||||
type="warning"
|
||||
@@ -108,10 +117,12 @@
|
||||
>脚本</el-link
|
||||
>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
|
||||
<el-link @click="showProcess(scope.row)" :disabled="scope.row.status == -1" plain :underline="false" size="small"
|
||||
>进程</el-link
|
||||
>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
|
||||
<el-link
|
||||
:disabled="!scope.row.hasCli || scope.row.status == -1"
|
||||
type="danger"
|
||||
@@ -223,6 +234,11 @@ export default defineComponent({
|
||||
data: null,
|
||||
title: '新增机器',
|
||||
},
|
||||
machineRecDialog: {
|
||||
visible: false,
|
||||
machineId: 0,
|
||||
title: '',
|
||||
},
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
@@ -259,8 +275,12 @@ export default defineComponent({
|
||||
search();
|
||||
};
|
||||
|
||||
const openFormDialog = async (machine: any) => {
|
||||
const getProjects = async () => {
|
||||
state.projects = await projectApi.accountProjects.request(null);
|
||||
};
|
||||
|
||||
const openFormDialog = async (machine: any) => {
|
||||
await getProjects();
|
||||
let dialogTitle;
|
||||
if (machine) {
|
||||
state.machineEditDialog.data = state.currentData as any;
|
||||
@@ -338,9 +358,21 @@ export default defineComponent({
|
||||
state.processDialog.visible = true;
|
||||
};
|
||||
|
||||
const showRec = (row: any) => {
|
||||
const { href } = router.resolve({
|
||||
path: `/machine/terminal-rec`,
|
||||
query: {
|
||||
id: row.id,
|
||||
name: `${row.name}[${row.ip}]-终端回放记录`,
|
||||
},
|
||||
});
|
||||
window.open(href, '_blank');
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
choose,
|
||||
getProjects,
|
||||
showTerminal,
|
||||
openFormDialog,
|
||||
deleteMachine,
|
||||
@@ -352,6 +384,7 @@ export default defineComponent({
|
||||
submitSuccess,
|
||||
fileManage,
|
||||
search,
|
||||
showRec,
|
||||
handlePageChange,
|
||||
};
|
||||
},
|
||||
|
||||
120
mayfly_go_web/src/views/ops/machine/MachineRec.vue
Normal file
120
mayfly_go_web/src/views/ops/machine/MachineRec.vue
Normal file
@@ -0,0 +1,120 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="toolbar">
|
||||
<span style="dispaly: inline-block" class="ml10">{{ title }}</span>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
<el-select @change="getUsers" v-model="operateDate" placeholder="操作日期" filterable>
|
||||
<el-option v-for="item in operateDates" :key="item" :label="item" :value="item"> </el-option>
|
||||
</el-select>
|
||||
<el-select class="ml10" @change="getRecs" filterable v-model="user" placeholder="请选择操作人">
|
||||
<el-option v-for="item in users" :key="item" :label="item" :value="item"> </el-option>
|
||||
</el-select>
|
||||
<el-select class="ml10" @change="playRec" filterable v-model="rec" placeholder="请选择操作记录">
|
||||
<el-option v-for="item in recs" :key="item" :label="item" :value="item"> </el-option>
|
||||
</el-select>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
快捷键-> space[空格键]: 暂停/播放 | f: 全屏/取消全屏
|
||||
</div>
|
||||
<div ref="playerRef" id="rc-player"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, onMounted, ref, reactive, defineComponent } from 'vue';
|
||||
import { machineApi } from './api';
|
||||
import * as AsciinemaPlayer from 'asciinema-player';
|
||||
import 'asciinema-player/dist/bundle/asciinema-player.css';
|
||||
import { useRoute } from 'vue-router';
|
||||
export default defineComponent({
|
||||
name: 'MachineRec',
|
||||
components: {},
|
||||
props: {
|
||||
visible: { type: Boolean },
|
||||
machineId: { type: Number },
|
||||
title: { type: String },
|
||||
},
|
||||
setup(props: any, context) {
|
||||
const route = useRoute();
|
||||
const playerRef = ref(null);
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
title: '',
|
||||
machineId: 0,
|
||||
operateDates: [],
|
||||
users: [],
|
||||
recs: [],
|
||||
operateDate: '',
|
||||
user: '',
|
||||
rec: '',
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
state.machineId = Number.parseInt(route.query.id as string);
|
||||
state.title = route.query.name as string;
|
||||
getOperateDate();
|
||||
});
|
||||
|
||||
const getOperateDate = async () => {
|
||||
const res = await machineApi.recDirNames.request({ path: state.machineId });
|
||||
state.operateDates = res as any;
|
||||
};
|
||||
|
||||
const getUsers = async (operateDate: string) => {
|
||||
state.users = [];
|
||||
state.user = '';
|
||||
state.recs = [];
|
||||
state.rec = '';
|
||||
const res = await machineApi.recDirNames.request({ path: `${state.machineId}/${operateDate}` });
|
||||
state.users = res as any;
|
||||
};
|
||||
|
||||
const getRecs = async (user: string) => {
|
||||
state.recs = [];
|
||||
state.rec = '';
|
||||
const res = await machineApi.recDirNames.request({ path: `${state.machineId}/${state.operateDate}/${user}` });
|
||||
state.recs = res as any;
|
||||
};
|
||||
|
||||
let player: any = null;
|
||||
|
||||
const playRec = async (rec: string) => {
|
||||
if (player) {
|
||||
player.dispose();
|
||||
}
|
||||
const content = await machineApi.recDirNames.request({
|
||||
isFile: '1',
|
||||
path: `${state.machineId}/${state.operateDate}/${state.user}/${rec}`,
|
||||
});
|
||||
player = AsciinemaPlayer.create(`data:text/plain;base64,${content}`, playerRef.value, {
|
||||
autoPlay: true,
|
||||
speed: 1.0,
|
||||
idleTimeLimit: 2,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 关闭取消按钮触发的事件
|
||||
*/
|
||||
const handleClose = () => {
|
||||
context.emit('update:visible', false);
|
||||
context.emit('update:machineId', null);
|
||||
context.emit('cancel');
|
||||
state.operateDates = [];
|
||||
state.users = [];
|
||||
state.recs = [];
|
||||
state.operateDate = '';
|
||||
state.user = '';
|
||||
state.rec = '';
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
playerRef,
|
||||
getUsers,
|
||||
getRecs,
|
||||
playRec,
|
||||
handleClose,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -33,5 +33,6 @@ export const machineApi = {
|
||||
addConf: Api.create("/machines/{machineId}/files", 'post'),
|
||||
// 删除配置的文件or目录
|
||||
delConf: Api.create("/machines/{machineId}/files/{id}", 'delete'),
|
||||
terminal: Api.create("/api/machines/{id}/terminal", 'get')
|
||||
terminal: Api.create("/api/machines/{id}/terminal", 'get'),
|
||||
recDirNames: Api.create("/machines/rec/names", 'get')
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
<el-button type="primary" icon="edit" :disabled="currentId == null" @click="editMongo(false)" plain>编辑</el-button>
|
||||
<el-button type="danger" icon="delete" :disabled="currentId == null" @click="deleteMongo" plain>删除</el-button>
|
||||
<div style="float: right">
|
||||
<el-select v-model="query.projectId" placeholder="请选择项目" filterable clearable>
|
||||
<el-select @focus="getProjects" v-model="query.projectId" placeholder="请选择项目" filterable clearable>
|
||||
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
</el-select>
|
||||
<el-button class="ml5" @click="search" type="success" icon="search"></el-button>
|
||||
@@ -370,8 +370,12 @@ export default defineComponent({
|
||||
state.total = res.total;
|
||||
};
|
||||
|
||||
const editMongo = async (isAdd = false) => {
|
||||
const getProjects = async () => {
|
||||
state.projects = await projectApi.accountProjects.request(null);
|
||||
};
|
||||
|
||||
const editMongo = async (isAdd = false) => {
|
||||
await getProjects();
|
||||
if (isAdd) {
|
||||
state.mongoEditDialog.data = null;
|
||||
state.mongoEditDialog.title = '新增mongo';
|
||||
@@ -390,6 +394,7 @@ export default defineComponent({
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
getProjects,
|
||||
search,
|
||||
handlePageChange,
|
||||
choose,
|
||||
|
||||
@@ -80,9 +80,18 @@
|
||||
<el-dialog width="500px" :title="showEnvDialog.title" v-model="showEnvDialog.visible">
|
||||
<div class="toolbar">
|
||||
<el-button @click="showAddEnvDialog" v-auth="permissions.saveMember" type="primary" icon="plus">添加</el-button>
|
||||
<!-- <el-button v-auth="'role:update'" :disabled="chooseId == null" type="danger" icon="delete">删除</el-button> -->
|
||||
<el-button @click="deleteEnv" v-auth="permissions.delProject" :disabled="showEnvDialog.chooseId == null" type="danger" icon="delete"
|
||||
>删除</el-button
|
||||
>
|
||||
</div>
|
||||
<el-table border :data="showEnvDialog.envs">
|
||||
<el-table @current-change="chooseEnv" border :data="showEnvDialog.envs">
|
||||
<el-table-column label="选择" width="50px">
|
||||
<template #default="scope">
|
||||
<el-radio v-model="showEnvDialog.chooseId" :label="scope.row.id">
|
||||
<i></i>
|
||||
</el-radio>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column property="name" label="环境名" width="125"></el-table-column>
|
||||
<el-table-column property="remark" label="描述" width="125"></el-table-column>
|
||||
<el-table-column property="createTime" label="创建时间">
|
||||
@@ -207,6 +216,8 @@ export default defineComponent({
|
||||
},
|
||||
showEnvDialog: {
|
||||
visible: false,
|
||||
chooseId: null,
|
||||
chooseData: null,
|
||||
envs: [],
|
||||
title: '',
|
||||
addVisible: false,
|
||||
@@ -340,6 +351,21 @@ export default defineComponent({
|
||||
state.showEnvDialog.visible = true;
|
||||
};
|
||||
|
||||
const chooseEnv = (item: any) => {
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
state.showEnvDialog.chooseData = item;
|
||||
state.showEnvDialog.chooseId = item.id;
|
||||
};
|
||||
|
||||
const deleteEnv = async () => {
|
||||
notNull(state.showEnvDialog.chooseData, '请选选择环境');
|
||||
await projectApi.delProjectEnvs.request({ id: state.showEnvDialog.chooseId });
|
||||
ElMessage.success('删除成功');
|
||||
state.showEnvDialog.envs = await projectApi.projectEnvs.request({ projectId: state.chooseId });
|
||||
};
|
||||
|
||||
const showAddMemberDialog = () => {
|
||||
state.showMemDialog.addVisible = true;
|
||||
};
|
||||
@@ -398,12 +424,14 @@ export default defineComponent({
|
||||
showMembers,
|
||||
setMemebers,
|
||||
showEnv,
|
||||
deleteEnv,
|
||||
showAddMemberDialog,
|
||||
addMember,
|
||||
chooseMember,
|
||||
deleteMember,
|
||||
cancelAddMember,
|
||||
showAddEnvDialog,
|
||||
chooseEnv,
|
||||
addEnv,
|
||||
cancelAddEnv,
|
||||
getAccount,
|
||||
|
||||
@@ -8,6 +8,7 @@ export const projectApi = {
|
||||
delProject: Api.create("/projects", 'delete'),
|
||||
// 获取项目下的环境信息
|
||||
projectEnvs: Api.create("/projects/{projectId}/envs", 'get'),
|
||||
delProjectEnvs: Api.create("/projects/envs", 'delete'),
|
||||
saveProjectEnv: Api.create("/projects/{projectId}/envs", 'post'),
|
||||
// 获取项目下的成员信息
|
||||
projectMems: Api.create("/projects/{projectId}/members", 'get'),
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
<el-tag @click="onAddData('string')" :color="getTypeColor('string')" style="cursor: pointer">string</el-tag>
|
||||
<el-tag @click="onAddData('hash')" :color="getTypeColor('hash')" class="ml5" style="cursor: pointer">hash</el-tag>
|
||||
<el-tag @click="onAddData('set')" :color="getTypeColor('set')" class="ml5" style="cursor: pointer">set</el-tag>
|
||||
<!-- <el-tag @click="onAddData('list')" :color="getTypeColor('list')" class="ml5" style="cursor: pointer">list</el-tag> -->
|
||||
</el-popover>
|
||||
</el-form-item>
|
||||
<div style="float: right">
|
||||
@@ -105,6 +106,16 @@
|
||||
@valChange="searchKey"
|
||||
@cancel="onCancelDataEdit"
|
||||
/>
|
||||
|
||||
<list-value
|
||||
v-model:visible="listValueDialog.visible"
|
||||
:title="dataEdit.title"
|
||||
:keyInfo="dataEdit.keyInfo"
|
||||
:redisId="scanParam.id"
|
||||
:operationType="dataEdit.operationType"
|
||||
@valChange="searchKey"
|
||||
@cancel="onCancelDataEdit"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -116,6 +127,7 @@ import ProjectEnvSelect from '../component/ProjectEnvSelect.vue';
|
||||
import HashValue from './HashValue.vue';
|
||||
import StringValue from './StringValue.vue';
|
||||
import SetValue from './SetValue.vue';
|
||||
import ListValue from './ListValue.vue';
|
||||
import { isTrue, notBlank, notNull } from '@/common/assert';
|
||||
|
||||
export default defineComponent({
|
||||
@@ -124,6 +136,7 @@ export default defineComponent({
|
||||
StringValue,
|
||||
HashValue,
|
||||
SetValue,
|
||||
ListValue,
|
||||
ProjectEnvSelect,
|
||||
},
|
||||
setup() {
|
||||
@@ -158,6 +171,9 @@ export default defineComponent({
|
||||
setValueDialog: {
|
||||
visible: false,
|
||||
},
|
||||
listValueDialog: {
|
||||
visible: false,
|
||||
},
|
||||
keys: [],
|
||||
dbsize: 0,
|
||||
});
|
||||
@@ -253,6 +269,8 @@ export default defineComponent({
|
||||
state.stringValueDialog.visible = true;
|
||||
} else if (type == 'set') {
|
||||
state.setValueDialog.visible = true;
|
||||
} else if (type == 'list') {
|
||||
state.listValueDialog.visible = true;
|
||||
} else {
|
||||
ElMessage.warning('暂不支持该类型');
|
||||
}
|
||||
@@ -270,6 +288,8 @@ export default defineComponent({
|
||||
state.stringValueDialog.visible = true;
|
||||
} else if (type == 'set') {
|
||||
state.setValueDialog.visible = true;
|
||||
} else if (type == 'list') {
|
||||
state.listValueDialog.visible = true;
|
||||
} else {
|
||||
ElMessage.warning('暂不支持该类型');
|
||||
}
|
||||
|
||||
205
mayfly_go_web/src/views/ops/redis/ListValue.vue
Normal file
205
mayfly_go_web/src/views/ops/redis/ListValue.vue
Normal file
@@ -0,0 +1,205 @@
|
||||
<template>
|
||||
<el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" width="800px" :destroy-on-close="true">
|
||||
<el-form label-width="85px">
|
||||
<el-form-item prop="key" label="key:">
|
||||
<el-input :disabled="operationType == 2" v-model="key.key"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="timed" label="过期时间:">
|
||||
<el-input v-model.number="key.timed" type="number"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="dataType" label="数据类型:">
|
||||
<el-input v-model="key.type" disabled></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<!-- <el-button @click="onAddListValue" icon="plus" size="small" plain class="mt10">添加</el-button> -->
|
||||
<div v-if="operationType == 2" class="mt10" style="float: left">
|
||||
<span>len: {{ len }}</span>
|
||||
</div>
|
||||
<el-table :data="value" stripe style="width: 100%">
|
||||
<el-table-column prop="value" label="value" min-width="200">
|
||||
<template #default="scope">
|
||||
<el-input v-model="scope.row.value" clearable type="textarea" :autosize="{ minRows: 2, maxRows: 10 }" size="small"></el-input>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="140">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
v-if="operationType == 2"
|
||||
type="success"
|
||||
@click="lset(scope.row, scope.$index)"
|
||||
icon="check"
|
||||
size="small"
|
||||
plain
|
||||
></el-button>
|
||||
<!-- <el-button type="danger" @click="set.value.splice(scope.$index, 1)" icon="delete" size="small" plain></el-button> -->
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-row style="margin-top: 20px" type="flex" justify="end">
|
||||
<el-pagination
|
||||
style="text-align: right"
|
||||
:total="len"
|
||||
layout="prev, pager, next, total"
|
||||
@current-change="handlePageChange"
|
||||
v-model:current-page="pageNum"
|
||||
:page-size="pageSize"
|
||||
></el-pagination>
|
||||
</el-row>
|
||||
</el-form>
|
||||
<!-- <template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="cancel()">取 消</el-button>
|
||||
<el-button @click="saveValue" type="primary" v-auth="'redis:data:save'">确 定</el-button>
|
||||
</div>
|
||||
</template> -->
|
||||
</el-dialog>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { defineComponent, reactive, watch, toRefs } from 'vue';
|
||||
import { redisApi } from './api';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { isTrue, notEmpty } from '@/common/assert';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ListValue',
|
||||
components: {},
|
||||
props: {
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
redisId: {
|
||||
type: [Number],
|
||||
require: true,
|
||||
},
|
||||
keyInfo: {
|
||||
type: [Object],
|
||||
},
|
||||
// 操作类型,1:新增,2:修改
|
||||
operationType: {
|
||||
type: [Number],
|
||||
},
|
||||
listValue: {
|
||||
type: [Array, Object],
|
||||
},
|
||||
},
|
||||
emits: ['valChange', 'cancel', 'update:visible'],
|
||||
setup(props: any, { emit }) {
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
operationType: 1,
|
||||
redisId: '',
|
||||
key: {
|
||||
key: '',
|
||||
type: 'string',
|
||||
timed: -1,
|
||||
},
|
||||
value: [{ value: '' }],
|
||||
len: 0,
|
||||
start: 0,
|
||||
stop: 0,
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
});
|
||||
|
||||
const cancel = () => {
|
||||
emit('update:visible', false);
|
||||
emit('cancel');
|
||||
setTimeout(() => {
|
||||
state.key = {
|
||||
key: '',
|
||||
type: 'string',
|
||||
timed: -1,
|
||||
};
|
||||
state.value = [];
|
||||
}, 500);
|
||||
};
|
||||
|
||||
watch(props, async (newValue) => {
|
||||
state.dialogVisible = newValue.visible;
|
||||
state.key = newValue.key;
|
||||
state.redisId = newValue.redisId;
|
||||
state.key = newValue.keyInfo;
|
||||
state.operationType = newValue.operationType;
|
||||
// 如果是查看编辑操作,则获取值
|
||||
if (state.dialogVisible && state.operationType == 2) {
|
||||
getListValue();
|
||||
}
|
||||
});
|
||||
|
||||
const getListValue = async () => {
|
||||
const pageNum = state.pageNum;
|
||||
const pageSize = state.pageSize;
|
||||
const res = await redisApi.getListValue.request({
|
||||
id: state.redisId,
|
||||
key: state.key.key,
|
||||
start: (pageNum - 1) * pageSize,
|
||||
stop: pageNum * pageSize - 1,
|
||||
});
|
||||
state.len = res.len;
|
||||
state.value = res.list.map((x: any) => {
|
||||
return {
|
||||
value: x,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const lset = async (row: any, rowIndex: number) => {
|
||||
await redisApi.setListValue.request({
|
||||
id: state.redisId,
|
||||
key: state.key.key,
|
||||
index: (state.pageNum - 1) * state.pageSize + rowIndex,
|
||||
value: row.value,
|
||||
});
|
||||
ElMessage.success('数据保存成功');
|
||||
};
|
||||
|
||||
const saveValue = async () => {
|
||||
notEmpty(state.key.key, 'key不能为空');
|
||||
isTrue(state.value.length > 0, 'list内容不能为空');
|
||||
// const sv = { value: state.value.map((x) => x.value), id: state.redisId };
|
||||
// Object.assign(sv, state.key);
|
||||
// await redisApi.saveSetValue.request(sv);
|
||||
|
||||
ElMessage.success('数据保存成功');
|
||||
cancel();
|
||||
emit('valChange');
|
||||
};
|
||||
|
||||
const onAddListValue = () => {
|
||||
state.value.unshift({ value: '' });
|
||||
};
|
||||
|
||||
const handlePageChange = (curPage: number) => {
|
||||
state.pageNum = curPage;
|
||||
getListValue();
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
saveValue,
|
||||
handlePageChange,
|
||||
cancel,
|
||||
lset,
|
||||
onAddListValue,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
#string-value-text {
|
||||
flex-grow: 1;
|
||||
display: flex;
|
||||
position: relative;
|
||||
|
||||
.text-type-select {
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
right: 10px;
|
||||
top: 10px;
|
||||
max-width: 70px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -5,7 +5,7 @@
|
||||
<el-button type="primary" icon="edit" :disabled="currentId == null" @click="editRedis(false)" plain>编辑</el-button>
|
||||
<el-button type="danger" icon="delete" :disabled="currentId == null" @click="deleteRedis" plain>删除</el-button>
|
||||
<div style="float: right">
|
||||
<el-select v-model="query.projectId" placeholder="请选择项目" filterable clearable>
|
||||
<el-select @focus="getProjects" v-model="query.projectId" placeholder="请选择项目" filterable clearable>
|
||||
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
</el-select>
|
||||
<el-button class="ml5" @click="search" type="success" icon="search"></el-button>
|
||||
@@ -263,8 +263,12 @@ export default defineComponent({
|
||||
state.total = res.total;
|
||||
};
|
||||
|
||||
const editRedis = async (isAdd = false) => {
|
||||
const getProjects = async () => {
|
||||
state.projects = await projectApi.accountProjects.request(null);
|
||||
};
|
||||
|
||||
const editRedis = async (isAdd = false) => {
|
||||
await getProjects();
|
||||
if (isAdd) {
|
||||
state.redisEditDialog.data = null;
|
||||
state.redisEditDialog.title = '新增redis';
|
||||
@@ -283,6 +287,7 @@ export default defineComponent({
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
getProjects,
|
||||
search,
|
||||
handlePageChange,
|
||||
choose,
|
||||
|
||||
@@ -20,4 +20,7 @@ export const redisApi = {
|
||||
saveSetValue: Api.create("/redis/{id}/set-value", 'post'),
|
||||
del: Api.create("/redis/{id}/scan/{cursor}/{count}", 'delete'),
|
||||
delKey: Api.create("/redis/{id}/key", 'delete'),
|
||||
getListValue: Api.create("/redis/{id}/list-value", 'get'),
|
||||
saveListValue: Api.create("/redis/{id}/list-value", 'post'),
|
||||
setListValue: Api.create("/redis/{id}/list-value/lset", 'post'),
|
||||
}
|
||||
@@ -5,12 +5,9 @@
|
||||
<el-form-item prop="username" label="用户名:" required>
|
||||
<el-input :disabled="edit" v-model.trim="form.username" placeholder="请输入账号用户名,密码默认与账号名一致" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<!-- <el-form-item prop="password" label="密码:" required>
|
||||
<el-form-item v-if="edit" prop="password" label="密码:" required>
|
||||
<el-input type="password" v-model.trim="form.password" placeholder="请输入密码" autocomplete="new-password"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="!edit" label="确认密码:" required>
|
||||
<el-input type="password" v-model.trim="form.repassword" placeholder="请输入确认密码" autocomplete="new-password"></el-input>
|
||||
</el-form-item> -->
|
||||
</el-form>
|
||||
|
||||
<template #footer>
|
||||
@@ -74,6 +71,7 @@ export default defineComponent({
|
||||
watch(props, (newValue) => {
|
||||
if (newValue.account) {
|
||||
state.form = { ...newValue.account };
|
||||
state.edit = true;
|
||||
} else {
|
||||
state.form = {} as any;
|
||||
}
|
||||
@@ -81,11 +79,9 @@ export default defineComponent({
|
||||
});
|
||||
|
||||
const btnOk = async () => {
|
||||
let p = state.form.id ? accountApi.update : accountApi.save;
|
||||
|
||||
accountForm.value.validate((valid: boolean) => {
|
||||
if (valid) {
|
||||
p.request(state.form).then(() => {
|
||||
accountApi.save.request(state.form).then(() => {
|
||||
ElMessage.success('操作成功');
|
||||
emit('val-change', state.form);
|
||||
state.btnLoading = true;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="role-list">
|
||||
<el-card>
|
||||
<el-button v-auth="'account:add'" type="primary" icon="plus" @click="editAccount(true)">添加</el-button>
|
||||
<!-- <el-button v-auth="'account:update'" :disabled="chooseId == null" @click="editAccount(false)" type="primary" icon="edit">编辑</el-button> -->
|
||||
<el-button v-auth="'account:add'" :disabled="chooseId == null" @click="editAccount(false)" type="primary" icon="edit">编辑</el-button>
|
||||
<el-button v-auth="'account:saveRoles'" :disabled="chooseId == null" @click="roleEdit()" type="success" icon="setting"
|
||||
>角色分配</el-button
|
||||
>
|
||||
@@ -20,7 +20,7 @@
|
||||
<el-button @click="search()" type="success" icon="search" size="small"></el-button>
|
||||
</div>
|
||||
<el-table :data="datas" ref="table" @current-change="choose" show-overflow-tooltip>
|
||||
<el-table-column label="选择" width="50px">
|
||||
<el-table-column label="选择" width="55px">
|
||||
<template #default="scope">
|
||||
<el-radio v-model="chooseId" :label="scope.row.id">
|
||||
<i></i>
|
||||
@@ -29,20 +29,20 @@
|
||||
</el-table-column>
|
||||
<el-table-column prop="username" label="用户名" min-width="115"></el-table-column>
|
||||
|
||||
<el-table-column align="center" prop="status" label="状态" min-width="63">
|
||||
<el-table-column align="center" prop="status" label="状态" min-width="65">
|
||||
<template #default="scope">
|
||||
<el-tag v-if="scope.row.status == 1" type="success">正常</el-tag>
|
||||
<el-tag v-if="scope.row.status == -1" type="danger">禁用</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column min-width="160" prop="lastLoginTime" label="最后登录时间">
|
||||
<el-table-column min-width="160" prop="lastLoginTime" label="最后登录时间" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.lastLoginTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column min-width="115" prop="creator" label="创建账号"></el-table-column>
|
||||
<el-table-column min-width="160" prop="createTime" label="创建时间">
|
||||
<el-table-column min-width="160" prop="createTime" label="创建时间" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
|
||||
@@ -32,6 +32,12 @@ export const accountApi = {
|
||||
saveRoles: Api.create("/sys/accounts/roles", 'post')
|
||||
}
|
||||
|
||||
export const configApi = {
|
||||
list: Api.create("/sys/configs", 'get'),
|
||||
save: Api.create("/sys/configs", 'post'),
|
||||
getValue: Api.create("/sys/configs/value", 'get'),
|
||||
}
|
||||
|
||||
export const logApi = {
|
||||
list: Api.create("/syslogs", "get")
|
||||
}
|
||||
|
||||
99
mayfly_go_web/src/views/system/config/ConfigEdit.vue
Executable file
99
mayfly_go_web/src/views/system/config/ConfigEdit.vue
Executable file
@@ -0,0 +1,99 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-dialog :title="title" v-model="dvisible" :show-close="false" :before-close="cancel" width="500px" :destroy-on-close="true">
|
||||
<el-form ref="configForm" :model="form" label-width="90px">
|
||||
<el-form-item prop="name" label="配置项:" required>
|
||||
<el-input v-model="form.name"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="key" label="配置key:" required>
|
||||
<el-input :disabled="form.id != null" v-model="form.key"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="value" label="配置值:" required>
|
||||
<el-input v-model="form.value"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注:">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="2"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="cancel()">取 消</el-button>
|
||||
<el-button type="primary" :loading="btnLoading" @click="btnOk">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { ref, toRefs, reactive, watch, defineComponent } from 'vue';
|
||||
import { configApi } from '../api';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ConfigEdit',
|
||||
props: {
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
data: {
|
||||
type: [Boolean, Object],
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
const configForm: any = ref(null);
|
||||
const state = reactive({
|
||||
dvisible: false,
|
||||
form: {
|
||||
id: null,
|
||||
name: '',
|
||||
key: '',
|
||||
value: '',
|
||||
remark: '',
|
||||
},
|
||||
btnLoading: false,
|
||||
});
|
||||
|
||||
watch(props, (newValue) => {
|
||||
state.dvisible = newValue.visible;
|
||||
if (newValue.data) {
|
||||
state.form = { ...newValue.data };
|
||||
} else {
|
||||
state.form = {} as any;
|
||||
}
|
||||
});
|
||||
|
||||
const cancel = () => {
|
||||
// 更新父组件visible prop对应的值为false
|
||||
emit('update:visible', false);
|
||||
// 若父组件有取消事件,则调用
|
||||
emit('cancel');
|
||||
};
|
||||
|
||||
const btnOk = async () => {
|
||||
configForm.value.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
await configApi.save.request(state.form);
|
||||
emit('val-change', state.form);
|
||||
cancel();
|
||||
state.btnLoading = true;
|
||||
setTimeout(() => {
|
||||
state.btnLoading = false;
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
configForm,
|
||||
btnOk,
|
||||
cancel,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
</style>
|
||||
124
mayfly_go_web/src/views/system/config/ConfigList.vue
Executable file
124
mayfly_go_web/src/views/system/config/ConfigList.vue
Executable file
@@ -0,0 +1,124 @@
|
||||
<template>
|
||||
<div class="role-list">
|
||||
<el-card>
|
||||
<el-button type="primary" icon="plus" @click="editConfig(false)">添加</el-button>
|
||||
<el-button :disabled="chooseId == null" @click="editConfig(chooseData)" type="primary" icon="edit">编辑</el-button>
|
||||
|
||||
<el-table :data="configs" @current-change="choose" ref="table" style="width: 100%">
|
||||
<el-table-column label="选择" width="55px">
|
||||
<template #default="scope">
|
||||
<el-radio v-model="chooseId" :label="scope.row.id">
|
||||
<i></i>
|
||||
</el-radio>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="name" label="配置项"></el-table-column>
|
||||
<el-table-column prop="key" label="配置key"></el-table-column>
|
||||
<el-table-column prop="value" label="配置值" min-width="100px" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="remark" label="备注" min-width="100px" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="updateTime" label="更新时间">
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="modifier" label="修改者" show-overflow-tooltip></el-table-column>
|
||||
</el-table>
|
||||
<el-row style="margin-top: 20px" type="flex" justify="end">
|
||||
<el-pagination
|
||||
style="text-align: right"
|
||||
@current-change="handlePageChange"
|
||||
:total="total"
|
||||
layout="prev, pager, next, total, jumper"
|
||||
v-model:current-page="query.pageNum"
|
||||
:page-size="query.pageSize"
|
||||
></el-pagination>
|
||||
</el-row>
|
||||
</el-card>
|
||||
|
||||
<config-edit :title="configEdit.title" v-model:visible="configEdit.visible" :data="configEdit.config" @val-change="configEditChange" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, onMounted, defineComponent } from 'vue';
|
||||
import ConfigEdit from './ConfigEdit.vue';
|
||||
import { configApi } from '../api';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
export default defineComponent({
|
||||
name: 'ConfigList',
|
||||
components: {
|
||||
ConfigEdit,
|
||||
},
|
||||
setup() {
|
||||
const state = reactive({
|
||||
dialogFormVisible: false,
|
||||
currentEditPermissions: false,
|
||||
query: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
name: null,
|
||||
},
|
||||
total: 0,
|
||||
configs: [],
|
||||
chooseId: null,
|
||||
chooseData: null,
|
||||
configEdit: {
|
||||
title: '配置修改',
|
||||
visible: false,
|
||||
config: {},
|
||||
},
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
search();
|
||||
});
|
||||
|
||||
const search = async () => {
|
||||
let res = await configApi.list.request(state.query);
|
||||
state.configs = res.list;
|
||||
state.total = res.total;
|
||||
};
|
||||
|
||||
const handlePageChange = (curPage: number) => {
|
||||
state.query.pageNum = curPage;
|
||||
search();
|
||||
};
|
||||
|
||||
const choose = (item: any) => {
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
state.chooseId = item.id;
|
||||
state.chooseData = item;
|
||||
};
|
||||
|
||||
const configEditChange = () => {
|
||||
ElMessage.success('修改成功!');
|
||||
state.chooseId = null;
|
||||
state.chooseData = null;
|
||||
search();
|
||||
};
|
||||
|
||||
const editConfig = (data: any) => {
|
||||
if (data) {
|
||||
state.configEdit.config = data;
|
||||
} else {
|
||||
state.configEdit.config = false;
|
||||
}
|
||||
|
||||
state.configEdit.visible = true;
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
search,
|
||||
handlePageChange,
|
||||
choose,
|
||||
configEditChange,
|
||||
editConfig,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
</style>
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="role-dialog">
|
||||
<el-dialog :title="title" v-model="dvisible" :show-close="false" :before-close="cancel" width="500px" :destroy-on-close="true">
|
||||
<el-form :model="form" label-width="90px">
|
||||
<el-form ref="roleForm" :model="form" label-width="90px">
|
||||
<el-form-item prop="name" label="角色名称:" required>
|
||||
<el-input v-model="form.name" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
@@ -28,7 +28,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, watch, defineComponent } from 'vue';
|
||||
import { ref, toRefs, reactive, watch, defineComponent } from 'vue';
|
||||
import { roleApi } from '../api';
|
||||
|
||||
export default defineComponent({
|
||||
@@ -45,6 +45,7 @@ export default defineComponent({
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
const roleForm: any = ref(null);
|
||||
const state = reactive({
|
||||
dvisible: false,
|
||||
form: {
|
||||
@@ -73,18 +74,22 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const btnOk = async () => {
|
||||
// let p = state.form.id ? roleApi.update : roleApi.save;
|
||||
await roleApi.save.request(state.form);
|
||||
emit('val-change', state.form);
|
||||
cancel();
|
||||
state.btnLoading = true;
|
||||
setTimeout(() => {
|
||||
state.btnLoading = false;
|
||||
}, 1000);
|
||||
roleForm.value.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
await roleApi.save.request(state.form);
|
||||
emit('val-change', state.form);
|
||||
cancel();
|
||||
state.btnLoading = true;
|
||||
setTimeout(() => {
|
||||
state.btnLoading = false;
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
roleForm,
|
||||
btnOk,
|
||||
cancel,
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<el-button @click="search" type="success" icon="search"></el-button>
|
||||
</div>
|
||||
<el-table :data="roles" @current-change="choose" ref="table" style="width: 100%">
|
||||
<el-table-column label="选择" width="50px">
|
||||
<el-table-column label="选择" width="55px">
|
||||
<template #default="scope">
|
||||
<el-radio v-model="chooseId" :label="scope.row.id">
|
||||
<i></i>
|
||||
|
||||
@@ -7,6 +7,13 @@
|
||||
resolved "https://registry.npmmirror.com/@babel/parser/download/@babel/parser-7.16.6.tgz"
|
||||
integrity sha512-Gr86ujcNuPDnNOY8mi383Hvi8IYrJVJYuf3XcuBM/Dgd+bINn/7tHqsj+tKkoreMbmGsFLsltI/JJd8fOFWGDQ==
|
||||
|
||||
"@babel/runtime@^7.15.4":
|
||||
version "7.18.9"
|
||||
resolved "https://registry.npmmirror.com/@babel/runtime/-/runtime-7.18.9.tgz#b4fcfce55db3d2e5e080d2490f608a3b9f407f4a"
|
||||
integrity sha512-lkqXDcvlFT5rvEjiu6+QYO+1GXrEHRo2LOtS7E4GtX5ESIZOgepqsZBVIj6Pv+a6zqsya9VCgiK1KAK4BvJDAw==
|
||||
dependencies:
|
||||
regenerator-runtime "^0.13.4"
|
||||
|
||||
"@ctrl/tinycolor@^3.4.1":
|
||||
version "3.4.1"
|
||||
resolved "https://registry.npmmirror.com/@ctrl/tinycolor/-/tinycolor-3.4.1.tgz"
|
||||
@@ -37,17 +44,17 @@
|
||||
minimatch "^3.0.4"
|
||||
strip-json-comments "^3.1.1"
|
||||
|
||||
"@floating-ui/core@^0.7.3":
|
||||
version "0.7.3"
|
||||
resolved "https://registry.npmmirror.com/@floating-ui/core/-/core-0.7.3.tgz"
|
||||
integrity sha512-buc8BXHmG9l82+OQXOFU3Kr2XQx9ys01U/Q9HMIrZ300iLc8HLMgh7dcCqgYzAzf4BkoQvDcXf5Y+CuEZ5JBYg==
|
||||
"@floating-ui/core@^1.0.1":
|
||||
version "1.0.1"
|
||||
resolved "https://registry.npmmirror.com/@floating-ui/core/-/core-1.0.1.tgz#00e64d74e911602c8533957af0cce5af6b2e93c8"
|
||||
integrity sha512-bO37brCPfteXQfFY0DyNDGB3+IMe4j150KFQcgJ5aBP295p9nBGeHEs/p0czrRbtlHq4Px/yoPXO/+dOCcF4uA==
|
||||
|
||||
"@floating-ui/dom@^0.5.4":
|
||||
version "0.5.4"
|
||||
resolved "https://registry.npmmirror.com/@floating-ui/dom/-/dom-0.5.4.tgz"
|
||||
integrity sha512-419BMceRLq0RrmTSDxn8hf9R3VCJv2K9PUfugh5JyEFmdjzDo+e8U5EdR8nzKq8Yj1htzLm3b6eQEEam3/rrtg==
|
||||
"@floating-ui/dom@^1.0.1":
|
||||
version "1.0.1"
|
||||
resolved "https://registry.npmmirror.com/@floating-ui/dom/-/dom-1.0.1.tgz#3321d4e799d6ac2503e729131d07ad0e714aabeb"
|
||||
integrity sha512-wBDiLUKWU8QNPNOTAFHiIAkBv1KlHauG2AhqjSeh2H+wR8PX+AArXfz8NkRexH5PgMJMmSOS70YS89AbWYh5dA==
|
||||
dependencies:
|
||||
"@floating-ui/core" "^0.7.3"
|
||||
"@floating-ui/core" "^1.0.1"
|
||||
|
||||
"@humanwhocodes/config-array@^0.9.2":
|
||||
version "0.9.2"
|
||||
@@ -426,7 +433,7 @@ ansi-regex@^5.0.1:
|
||||
resolved "https://registry.nlark.com/ansi-regex/download/ansi-regex-5.0.1.tgz"
|
||||
integrity sha1-CCyyyJyf6GWaMRpTvWpNxTAdswQ=
|
||||
|
||||
ansi-styles@^4.0.0, ansi-styles@^4.1.0:
|
||||
ansi-styles@^4.1.0:
|
||||
version "4.3.0"
|
||||
resolved "https://registry.nlark.com/ansi-styles/download/ansi-styles-4.3.0.tgz"
|
||||
integrity sha1-7dgDYornHATIWuegkG7a00tkiTc=
|
||||
@@ -451,6 +458,14 @@ array-union@^2.1.0:
|
||||
resolved "https://registry.npm.taobao.org/array-union/download/array-union-2.1.0.tgz?cache=0&sync_timestamp=1614624262896&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Farray-union%2Fdownload%2Farray-union-2.1.0.tgz"
|
||||
integrity sha1-t5hCCtvrHego2ErNii4j0+/oXo0=
|
||||
|
||||
asciinema-player@^3.0.1:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.npmmirror.com/asciinema-player/-/asciinema-player-3.0.1.tgz#4ea9e6ee2cc5c1f956bfb562950279dcfad3e737"
|
||||
integrity sha512-plm/C/MhOtZWysrfcT/rzxOuu8vxvvDSvF50pqZS6KpJUDmATedAhO54zktbE/g7RiaaYfzgX8xjRhlQdgISwA==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.15.4"
|
||||
solid-js "^1.3.0"
|
||||
|
||||
async-validator@^4.2.5:
|
||||
version "4.2.5"
|
||||
resolved "https://registry.npmmirror.com/async-validator/-/async-validator-4.2.5.tgz"
|
||||
@@ -531,15 +546,6 @@ clipboard@^2.0.6:
|
||||
select "^1.1.2"
|
||||
tiny-emitter "^2.0.0"
|
||||
|
||||
cliui@^7.0.2:
|
||||
version "7.0.4"
|
||||
resolved "https://registry.npmmirror.com/cliui/-/cliui-7.0.4.tgz#a0265ee655476fc807aea9df3df8df7783808b4f"
|
||||
integrity sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==
|
||||
dependencies:
|
||||
string-width "^4.2.0"
|
||||
strip-ansi "^6.0.0"
|
||||
wrap-ansi "^7.0.0"
|
||||
|
||||
codemirror@^5.65.5:
|
||||
version "5.65.5"
|
||||
resolved "https://registry.npmmirror.com/codemirror/-/codemirror-5.65.5.tgz"
|
||||
@@ -593,6 +599,11 @@ csstype@^2.6.8:
|
||||
resolved "https://registry.npmmirror.com/csstype/download/csstype-2.6.19.tgz?cache=0&sync_timestamp=1637224514674&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Fcsstype%2Fdownload%2Fcsstype-2.6.19.tgz"
|
||||
integrity sha512-ZVxXaNy28/k3kJg0Fou5MiYpp88j7H9hLZp8PDC3jV0WFjfH5E9xHb56L0W59cPbKbcHXeP4qyT8PrHp8t6LcQ==
|
||||
|
||||
csstype@^3.1.0:
|
||||
version "3.1.0"
|
||||
resolved "https://registry.npmmirror.com/csstype/-/csstype-3.1.0.tgz#4ddcac3718d787cf9df0d1b7d15033925c8f29f2"
|
||||
integrity sha512-uX1KG+x9h5hIJsaKR9xHUeUraxf8IODOwq9JLNPq6BwB04a/xgpq3rcx47l5BZu5zBPlgD342tdke3Hom/nJRA==
|
||||
|
||||
dayjs@^1.11.3:
|
||||
version "1.11.3"
|
||||
resolved "https://registry.npmmirror.com/dayjs/-/dayjs-1.11.3.tgz"
|
||||
@@ -610,11 +621,6 @@ deep-is@^0.1.3:
|
||||
resolved "https://registry.nlark.com/deep-is/download/deep-is-0.1.4.tgz"
|
||||
integrity sha1-pvLc5hL63S7x9Rm3NVHxfoUZmDE=
|
||||
|
||||
define-lazy-prop@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.npmmirror.com/define-lazy-prop/-/define-lazy-prop-2.0.0.tgz#3f7ae421129bcaaac9bc74905c98a0009ec9ee7f"
|
||||
integrity sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og==
|
||||
|
||||
delayed-stream@~1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.npmmirror.com/delayed-stream/-/delayed-stream-1.0.0.tgz"
|
||||
@@ -652,14 +658,14 @@ echarts@^5.3.3:
|
||||
tslib "2.3.0"
|
||||
zrender "5.3.2"
|
||||
|
||||
element-plus@^2.2.14:
|
||||
version "2.2.14"
|
||||
resolved "https://registry.npmmirror.com/element-plus/-/element-plus-2.2.14.tgz#161f2cbf2c12608a570af303f8191c7d7eae725b"
|
||||
integrity sha512-V5Pis0OHhePg1RgVogZrcefaVl8vjVn4Pn9Qsh/t2CbFgjg9kKOYFqf/tuP3ObSXGm3X89hpe0W+nLVAsaFnpw==
|
||||
element-plus@^2.2.17:
|
||||
version "2.2.17"
|
||||
resolved "https://registry.npmmirror.com/element-plus/-/element-plus-2.2.17.tgz#abbb12c19dc029c95b0271822ea9a0e635704bc2"
|
||||
integrity sha512-MGwMIE/q+FFD3kgS23x8HIe5043tmD1cTRwjhIX9o6fim1avFnUkrsfYRvybbz4CkyqSb185EheZS5AUPpXh2g==
|
||||
dependencies:
|
||||
"@ctrl/tinycolor" "^3.4.1"
|
||||
"@element-plus/icons-vue" "^2.0.6"
|
||||
"@floating-ui/dom" "^0.5.4"
|
||||
"@floating-ui/dom" "^1.0.1"
|
||||
"@popperjs/core" "npm:@sxzz/popperjs-es@^2.11.7"
|
||||
"@types/lodash" "^4.14.182"
|
||||
"@types/lodash-es" "^4.17.6"
|
||||
@@ -673,11 +679,6 @@ element-plus@^2.2.14:
|
||||
memoize-one "^6.0.0"
|
||||
normalize-wheel-es "^1.2.0"
|
||||
|
||||
emoji-regex@^8.0.0:
|
||||
version "8.0.0"
|
||||
resolved "https://registry.npmmirror.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
|
||||
integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==
|
||||
|
||||
enquirer@^2.3.5:
|
||||
version "2.3.6"
|
||||
resolved "https://registry.npm.taobao.org/enquirer/download/enquirer-2.3.6.tgz"
|
||||
@@ -811,11 +812,6 @@ esbuild@^0.14.27:
|
||||
esbuild-windows-64 "0.14.38"
|
||||
esbuild-windows-arm64 "0.14.38"
|
||||
|
||||
escalade@^3.1.1:
|
||||
version "3.1.1"
|
||||
resolved "https://registry.npmmirror.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40"
|
||||
integrity sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==
|
||||
|
||||
escape-html@^1.0.3:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.npmmirror.com/escape-html/-/escape-html-1.0.3.tgz"
|
||||
@@ -1058,11 +1054,6 @@ functional-red-black-tree@^1.0.1:
|
||||
resolved "https://registry.npm.taobao.org/functional-red-black-tree/download/functional-red-black-tree-1.0.1.tgz?cache=0&sync_timestamp=1577806294691&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Ffunctional-red-black-tree%2Fdownload%2Ffunctional-red-black-tree-1.0.1.tgz"
|
||||
integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=
|
||||
|
||||
get-caller-file@^2.0.5:
|
||||
version "2.0.5"
|
||||
resolved "https://registry.npmmirror.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
|
||||
integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==
|
||||
|
||||
glob-parent@^5.1.2, glob-parent@~5.1.2:
|
||||
version "5.1.2"
|
||||
resolved "https://registry.npmmirror.com/glob-parent/download/glob-parent-5.1.2.tgz"
|
||||
@@ -1182,21 +1173,11 @@ is-core-module@^2.8.1:
|
||||
dependencies:
|
||||
has "^1.0.3"
|
||||
|
||||
is-docker@^2.0.0, is-docker@^2.1.1:
|
||||
version "2.2.1"
|
||||
resolved "https://registry.npmmirror.com/is-docker/-/is-docker-2.2.1.tgz#33eeabe23cfe86f14bde4408a02c0cfb853acdaa"
|
||||
integrity sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==
|
||||
|
||||
is-extglob@^2.1.1:
|
||||
version "2.1.1"
|
||||
resolved "https://registry.npm.taobao.org/is-extglob/download/is-extglob-2.1.1.tgz"
|
||||
integrity sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=
|
||||
|
||||
is-fullwidth-code-point@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.npmmirror.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d"
|
||||
integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==
|
||||
|
||||
is-glob@^4.0.0, is-glob@^4.0.1, is-glob@^4.0.3, is-glob@~4.0.1:
|
||||
version "4.0.3"
|
||||
resolved "https://registry.npmmirror.com/is-glob/download/is-glob-4.0.3.tgz"
|
||||
@@ -1209,13 +1190,6 @@ is-number@^7.0.0:
|
||||
resolved "https://registry.nlark.com/is-number/download/is-number-7.0.0.tgz"
|
||||
integrity sha1-dTU0W4lnNNX4DE0GxQlVUnoU8Ss=
|
||||
|
||||
is-wsl@^2.2.0:
|
||||
version "2.2.0"
|
||||
resolved "https://registry.npmmirror.com/is-wsl/-/is-wsl-2.2.0.tgz#74a4c76e77ca9fd3f932f290c17ea326cd157271"
|
||||
integrity sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==
|
||||
dependencies:
|
||||
is-docker "^2.0.0"
|
||||
|
||||
isexe@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.npm.taobao.org/isexe/download/isexe-2.0.0.tgz"
|
||||
@@ -1419,15 +1393,6 @@ once@^1.3.0:
|
||||
dependencies:
|
||||
wrappy "1"
|
||||
|
||||
open@^8.4.0:
|
||||
version "8.4.0"
|
||||
resolved "https://registry.npmmirror.com/open/-/open-8.4.0.tgz#345321ae18f8138f82565a910fdc6b39e8c244f8"
|
||||
integrity sha512-XgFPPM+B28FtCCgSb9I+s9szOC1vZRSwgWsRUA5ylIxRTgKozqjOCrVOqGsYABPYK5qnfqClxZTFBa8PKt2v6Q==
|
||||
dependencies:
|
||||
define-lazy-prop "^2.0.0"
|
||||
is-docker "^2.1.1"
|
||||
is-wsl "^2.2.0"
|
||||
|
||||
optionator@^0.9.1:
|
||||
version "0.9.1"
|
||||
resolved "https://registry.npm.taobao.org/optionator/download/optionator-0.9.1.tgz"
|
||||
@@ -1532,16 +1497,16 @@ readdirp@~3.6.0:
|
||||
dependencies:
|
||||
picomatch "^2.2.1"
|
||||
|
||||
regenerator-runtime@^0.13.4:
|
||||
version "0.13.9"
|
||||
resolved "https://registry.npmmirror.com/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz#8925742a98ffd90814988d7566ad30ca3b263b52"
|
||||
integrity sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==
|
||||
|
||||
regexpp@^3.1.0, regexpp@^3.2.0:
|
||||
version "3.2.0"
|
||||
resolved "https://registry.nlark.com/regexpp/download/regexpp-3.2.0.tgz?cache=0&sync_timestamp=1623668872577&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fregexpp%2Fdownload%2Fregexpp-3.2.0.tgz"
|
||||
integrity sha1-BCWido2PI7rXDKS5BGH6LxIT4bI=
|
||||
|
||||
require-directory@^2.1.1:
|
||||
version "2.1.1"
|
||||
resolved "https://registry.npmmirror.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
|
||||
integrity sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==
|
||||
|
||||
resolve-from@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.nlark.com/resolve-from/download/resolve-from-4.0.0.tgz"
|
||||
@@ -1568,16 +1533,6 @@ rimraf@^3.0.2:
|
||||
dependencies:
|
||||
glob "^7.1.3"
|
||||
|
||||
rollup-plugin-visualizer@^5.8.0:
|
||||
version "5.8.0"
|
||||
resolved "https://registry.npmmirror.com/rollup-plugin-visualizer/-/rollup-plugin-visualizer-5.8.0.tgz#32f2fe23d4299e977c06c59c07255590354e3445"
|
||||
integrity sha512-pY6j/7qHz5I9rB7d/bQoA5gX+2FbV3MBG055wrsFxDn550bgl0FNViRj6wDHh85PMswv+JVdZjhnMBzz/hdAHA==
|
||||
dependencies:
|
||||
nanoid "^3.3.4"
|
||||
open "^8.4.0"
|
||||
source-map "^0.7.3"
|
||||
yargs "^17.5.1"
|
||||
|
||||
rollup@^2.59.0:
|
||||
version "2.61.1"
|
||||
resolved "https://registry.npmmirror.com/rollup/download/rollup-2.61.1.tgz"
|
||||
@@ -1643,6 +1598,13 @@ slash@^3.0.0:
|
||||
resolved "https://registry.nlark.com/slash/download/slash-3.0.0.tgz"
|
||||
integrity sha1-ZTm+hwwWWtvVJAIg2+Nh8bxNRjQ=
|
||||
|
||||
solid-js@^1.3.0:
|
||||
version "1.5.1"
|
||||
resolved "https://registry.npmmirror.com/solid-js/-/solid-js-1.5.1.tgz#b4281cf92cb00b235e62ef890d87ea996a9b9fa3"
|
||||
integrity sha512-Y6aKystIxnrB0quV5nhqNuJV+l2Fk3/PQy1mMya/bzxlGiMHAym7v1NaqEgqDIvctbkxOi5dBj0ER/ewrH060g==
|
||||
dependencies:
|
||||
csstype "^3.1.0"
|
||||
|
||||
sortablejs@^1.13.0:
|
||||
version "1.14.0"
|
||||
resolved "https://registry.nlark.com/sortablejs/download/sortablejs-1.14.0.tgz?cache=0&sync_timestamp=1625423971526&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fsortablejs%2Fdownload%2Fsortablejs-1.14.0.tgz"
|
||||
@@ -1663,11 +1625,6 @@ source-map@^0.6.1:
|
||||
resolved "https://registry.npm.taobao.org/source-map/download/source-map-0.6.1.tgz"
|
||||
integrity sha1-dHIq8y6WFOnCh6jQu95IteLxomM=
|
||||
|
||||
source-map@^0.7.3:
|
||||
version "0.7.4"
|
||||
resolved "https://registry.npmmirror.com/source-map/-/source-map-0.7.4.tgz#a9bbe705c9d8846f4e08ff6765acf0f1b0898656"
|
||||
integrity sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==
|
||||
|
||||
sourcemap-codec@^1.4.4:
|
||||
version "1.4.8"
|
||||
resolved "https://registry.npm.taobao.org/sourcemap-codec/download/sourcemap-codec-1.4.8.tgz"
|
||||
@@ -1680,16 +1637,7 @@ sql-formatter@^9.2.0:
|
||||
dependencies:
|
||||
argparse "^2.0.1"
|
||||
|
||||
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
|
||||
version "4.2.3"
|
||||
resolved "https://registry.npmmirror.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
|
||||
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
|
||||
dependencies:
|
||||
emoji-regex "^8.0.0"
|
||||
is-fullwidth-code-point "^3.0.0"
|
||||
strip-ansi "^6.0.1"
|
||||
|
||||
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
|
||||
strip-ansi@^6.0.1:
|
||||
version "6.0.1"
|
||||
resolved "https://registry.npmmirror.com/strip-ansi/download/strip-ansi-6.0.1.tgz"
|
||||
integrity sha1-nibGPTD1NEPpSJSVshBdN7Z6hdk=
|
||||
@@ -1857,58 +1805,26 @@ word-wrap@^1.2.3:
|
||||
resolved "https://registry.npm.taobao.org/word-wrap/download/word-wrap-1.2.3.tgz"
|
||||
integrity sha1-YQY29rH3A4kb00dxzLF/uTtHB5w=
|
||||
|
||||
wrap-ansi@^7.0.0:
|
||||
version "7.0.0"
|
||||
resolved "https://registry.npmmirror.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
|
||||
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
|
||||
dependencies:
|
||||
ansi-styles "^4.0.0"
|
||||
string-width "^4.1.0"
|
||||
strip-ansi "^6.0.0"
|
||||
|
||||
wrappy@1:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.nlark.com/wrappy/download/wrappy-1.0.2.tgz?cache=0&sync_timestamp=1619133505879&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fwrappy%2Fdownload%2Fwrappy-1.0.2.tgz"
|
||||
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
|
||||
|
||||
xterm-addon-fit@^0.5.0:
|
||||
version "0.5.0"
|
||||
resolved "https://registry.npmmirror.com/xterm-addon-fit/download/xterm-addon-fit-0.5.0.tgz"
|
||||
integrity sha1-LVG5g7eGqX3NbN6AXnAMf5E7xZY=
|
||||
xterm-addon-fit@^0.6.0:
|
||||
version "0.6.0"
|
||||
resolved "https://registry.npmmirror.com/xterm-addon-fit/-/xterm-addon-fit-0.6.0.tgz#142e1ce181da48763668332593fc440349c88c34"
|
||||
integrity sha512-9/7A+1KEjkFam0yxTaHfuk9LEvvTSBi0PZmEkzJqgafXPEXL9pCMAVV7rB09sX6ATRDXAdBpQhZkhKj7CGvYeg==
|
||||
|
||||
xterm@^4.19.0:
|
||||
version "4.19.0"
|
||||
resolved "https://registry.npmmirror.com/xterm/-/xterm-4.19.0.tgz"
|
||||
integrity sha512-c3Cp4eOVsYY5Q839dR5IejghRPpxciGmLWWaP9g+ppfMeBChMeLa1DCA+pmX/jyDZ+zxFOmlJL/82qVdayVoGQ==
|
||||
|
||||
y18n@^5.0.5:
|
||||
version "5.0.8"
|
||||
resolved "https://registry.npmmirror.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55"
|
||||
integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==
|
||||
xterm@^5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://registry.npmmirror.com/xterm/-/xterm-5.0.0.tgz#0af50509b33d0dc62fde7a4ec17750b8e453cc5c"
|
||||
integrity sha512-tmVsKzZovAYNDIaUinfz+VDclraQpPUnAME+JawosgWRMphInDded/PuY0xmU5dOhyeYZsI0nz5yd8dPYsdLTA==
|
||||
|
||||
yallist@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.nlark.com/yallist/download/yallist-4.0.0.tgz"
|
||||
integrity sha1-m7knkNnA7/7GO+c1GeEaNQGaOnI=
|
||||
|
||||
yargs-parser@^21.0.0:
|
||||
version "21.1.1"
|
||||
resolved "https://registry.npmmirror.com/yargs-parser/-/yargs-parser-21.1.1.tgz#9096bceebf990d21bb31fa9516e0ede294a77d35"
|
||||
integrity sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==
|
||||
|
||||
yargs@^17.5.1:
|
||||
version "17.5.1"
|
||||
resolved "https://registry.npmmirror.com/yargs/-/yargs-17.5.1.tgz#e109900cab6fcb7fd44b1d8249166feb0b36e58e"
|
||||
integrity sha512-t6YAJcxDkNX7NFYiVtKvWUz8l+PaKTLiL63mJYWR2GnHq2gjEWISzsLp9wg3aY36dY1j+gfIEL3pIF+XlJJfbA==
|
||||
dependencies:
|
||||
cliui "^7.0.2"
|
||||
escalade "^3.1.1"
|
||||
get-caller-file "^2.0.5"
|
||||
require-directory "^2.1.1"
|
||||
string-width "^4.2.3"
|
||||
y18n "^5.0.5"
|
||||
yargs-parser "^21.0.0"
|
||||
|
||||
zrender@5.3.2:
|
||||
version "5.3.2"
|
||||
resolved "https://registry.npmmirror.com/zrender/-/zrender-5.3.2.tgz"
|
||||
|
||||
@@ -7,6 +7,8 @@ server:
|
||||
enable: false
|
||||
key-file: ./default.key
|
||||
cert-file: ./default.pem
|
||||
# 机器终端操作回放文件存储路径
|
||||
machine-rec-path: ./rec
|
||||
jwt:
|
||||
# jwt key,不设置默认使用随机字符串
|
||||
key:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module mayfly-go
|
||||
|
||||
go 1.18
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/gin-gonic/gin v1.8.1
|
||||
@@ -15,7 +15,8 @@ require (
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
|
||||
go.mongodb.org/mongo-driver v1.9.1 // mongo
|
||||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // ssh
|
||||
golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0
|
||||
// ssh
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
// gorm
|
||||
gorm.io/driver/mysql v1.3.5
|
||||
|
||||
@@ -4,12 +4,17 @@ import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
common_router "mayfly-go/internal/common/router"
|
||||
devops_router "mayfly-go/internal/devops/router"
|
||||
db_router "mayfly-go/internal/db/router"
|
||||
machine_router "mayfly-go/internal/machine/router"
|
||||
mongo_router "mayfly-go/internal/mongo/router"
|
||||
project_router "mayfly-go/internal/project/router"
|
||||
redis_router "mayfly-go/internal/redis/router"
|
||||
sys_router "mayfly-go/internal/sys/router"
|
||||
"mayfly-go/pkg/config"
|
||||
"mayfly-go/pkg/middleware"
|
||||
"mayfly-go/static"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -17,6 +22,7 @@ import (
|
||||
func WrapStaticHandler(h http.Handler) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.Writer.Header().Set("Cache-Control", `public, max-age=31536000`)
|
||||
c.Request.URL.Path = strings.Split(c.Request.RequestURI, "/mayfly")[1]
|
||||
h.ServeHTTP(c.Writer, c.Request)
|
||||
}
|
||||
}
|
||||
@@ -47,7 +53,7 @@ func InitRouter() *gin.Engine {
|
||||
// 设置静态资源
|
||||
if staticConfs := serverConfig.Static; staticConfs != nil {
|
||||
for _, scs := range *staticConfs {
|
||||
router.Static(scs.RelativePath, scs.Root)
|
||||
router.StaticFS(scs.RelativePath, http.Dir(scs.Root))
|
||||
}
|
||||
}
|
||||
// 设置静态文件
|
||||
@@ -68,21 +74,13 @@ func InitRouter() *gin.Engine {
|
||||
common_router.InitIndexRouter(api)
|
||||
common_router.InitCommonRouter(api)
|
||||
|
||||
sys_router.InitCaptchaRouter(api)
|
||||
sys_router.InitAccountRouter(api) // 注册account路由
|
||||
sys_router.InitResourceRouter(api)
|
||||
sys_router.InitRoleRouter(api)
|
||||
sys_router.InitSystemRouter(api)
|
||||
sys_router.InitSyslogRouter(api)
|
||||
sys_router.Init(api)
|
||||
|
||||
devops_router.InitProjectRouter(api)
|
||||
devops_router.InitDbRouter(api)
|
||||
devops_router.InitDbSqlExecRouter(api)
|
||||
devops_router.InitRedisRouter(api)
|
||||
devops_router.InitMachineRouter(api)
|
||||
devops_router.InitMachineScriptRouter(api)
|
||||
devops_router.InitMachineFileRouter(api)
|
||||
devops_router.InitMongoRouter(api)
|
||||
project_router.Init(api)
|
||||
machine_router.Init(api)
|
||||
db_router.Init(api)
|
||||
redis_router.Init(api)
|
||||
mongo_router.Init(api)
|
||||
}
|
||||
|
||||
return router
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
sys_application "mayfly-go/internal/sys/application"
|
||||
sysapp "mayfly-go/internal/sys/application"
|
||||
"mayfly-go/pkg/ctx"
|
||||
)
|
||||
|
||||
func InitSaveLogFunc() ctx.SaveLogFunc {
|
||||
return sys_application.SyslogApp.SaveFromReq
|
||||
return sysapp.GetSyslogApp().SaveFromReq
|
||||
}
|
||||
|
||||
@@ -1,23 +1,30 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
dbapp "mayfly-go/internal/db/application"
|
||||
dbentity "mayfly-go/internal/db/domain/entity"
|
||||
machineentity "mayfly-go/internal/machine/domain/entity"
|
||||
projectentity "mayfly-go/internal/project/domain/entity"
|
||||
redisentity "mayfly-go/internal/redis/domain/entity"
|
||||
|
||||
machineapp "mayfly-go/internal/machine/application"
|
||||
projectapp "mayfly-go/internal/project/application"
|
||||
redisapp "mayfly-go/internal/redis/application"
|
||||
"mayfly-go/pkg/ctx"
|
||||
)
|
||||
|
||||
type Index struct {
|
||||
ProjectApp application.Project
|
||||
MachineApp application.Machine
|
||||
DbApp application.Db
|
||||
RedisApp application.Redis
|
||||
ProjectApp projectapp.Project
|
||||
MachineApp machineapp.Machine
|
||||
DbApp dbapp.Db
|
||||
RedisApp redisapp.Redis
|
||||
}
|
||||
|
||||
func (i *Index) Count(rc *ctx.ReqCtx) {
|
||||
rc.ResData = map[string]interface{}{
|
||||
"projectNum": i.ProjectApp.Count(new(entity.Project)),
|
||||
"machineNum": i.MachineApp.Count(new(entity.Machine)),
|
||||
"dbNum": i.DbApp.Count(new(entity.Db)),
|
||||
"redisNum": i.RedisApp.Count(new(entity.Redis)),
|
||||
"projectNum": i.ProjectApp.Count(new(projectentity.Project)),
|
||||
"machineNum": i.MachineApp.Count(new(machineentity.Machine)),
|
||||
"dbNum": i.DbApp.Count(new(dbentity.Db)),
|
||||
"redisNum": i.RedisApp.Count(new(redisentity.Redis)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,10 @@ package router
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/common/api"
|
||||
devops_app "mayfly-go/internal/devops/application"
|
||||
dbapp "mayfly-go/internal/db/application"
|
||||
machineapp "mayfly-go/internal/machine/application"
|
||||
projectapp "mayfly-go/internal/project/application"
|
||||
redisapp "mayfly-go/internal/redis/application"
|
||||
"mayfly-go/pkg/ctx"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -11,10 +14,10 @@ import (
|
||||
func InitIndexRouter(router *gin.RouterGroup) {
|
||||
index := router.Group("common/index")
|
||||
i := &api.Index{
|
||||
ProjectApp: devops_app.ProjectApp,
|
||||
MachineApp: devops_app.MachineApp,
|
||||
DbApp: devops_app.DbApp,
|
||||
RedisApp: devops_app.RedisApp,
|
||||
ProjectApp: projectapp.GetProjectApp(),
|
||||
MachineApp: machineapp.GetMachineApp(),
|
||||
DbApp: dbapp.GetDbApp(),
|
||||
RedisApp: redisapp.GetRedisApp(),
|
||||
}
|
||||
{
|
||||
// 首页基本信息统计
|
||||
|
||||
@@ -3,11 +3,12 @@ package api
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"mayfly-go/internal/devops/api/form"
|
||||
"mayfly-go/internal/devops/api/vo"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
sysApplication "mayfly-go/internal/sys/application"
|
||||
"mayfly-go/internal/db/api/form"
|
||||
"mayfly-go/internal/db/api/vo"
|
||||
"mayfly-go/internal/db/application"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
projectapp "mayfly-go/internal/project/application"
|
||||
sysapp "mayfly-go/internal/sys/application"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"mayfly-go/pkg/ginx"
|
||||
@@ -25,8 +26,8 @@ import (
|
||||
type Db struct {
|
||||
DbApp application.Db
|
||||
DbSqlExecApp application.DbSqlExec
|
||||
MsgApp sysApplication.Msg
|
||||
ProjectApp application.Project
|
||||
MsgApp sysapp.Msg
|
||||
ProjectApp projectapp.Project
|
||||
}
|
||||
|
||||
const DEFAULT_COLUMN_SIZE = 500
|
||||
@@ -129,37 +130,21 @@ func (d *Db) ExecSql(rc *ctx.ReqCtx) {
|
||||
})
|
||||
|
||||
rc.ReqParam = fmt.Sprintf("db: %d:%s | sql: %s", id, db, sql)
|
||||
|
||||
biz.NotEmpty(sql, "sql不能为空")
|
||||
if strings.HasPrefix(sql, "SELECT") || strings.HasPrefix(sql, "select") || strings.HasPrefix(sql, "show") || strings.HasPrefix(sql, "explain") {
|
||||
colNames, res, err := dbInstance.SelectData(sql)
|
||||
biz.ErrIsNilAppendErr(err, "查询失败: %s")
|
||||
colAndRes := make(map[string]interface{})
|
||||
colAndRes["colNames"] = colNames
|
||||
colAndRes["res"] = res
|
||||
rc.ResData = colAndRes
|
||||
} else {
|
||||
// 根据执行sql,生成执行记录
|
||||
execRecord := d.DbSqlExecApp.GenExecLog(rc.LoginAccount, id, db, sql, dbInstance)
|
||||
|
||||
rowsAffected, err := dbInstance.Exec(sql)
|
||||
biz.ErrIsNilAppendErr(err, "执行失败: %s")
|
||||
res := make([]map[string]string, 0)
|
||||
resData := make(map[string]string)
|
||||
resData["影响条数"] = fmt.Sprintf("%d", rowsAffected)
|
||||
res = append(res, resData)
|
||||
|
||||
colAndRes := make(map[string]interface{})
|
||||
colAndRes["colNames"] = []string{"影响条数"}
|
||||
colAndRes["res"] = res
|
||||
|
||||
rc.ResData = colAndRes
|
||||
// 保存sql执行记录
|
||||
if res[0]["影响条数"] > "0" {
|
||||
execRecord.Remark = form.Remark
|
||||
d.DbSqlExecApp.Save(execRecord)
|
||||
}
|
||||
}
|
||||
execRes, err := d.DbSqlExecApp.Exec(&application.DbSqlExecReq{
|
||||
DbId: id,
|
||||
Db: db,
|
||||
Sql: sql,
|
||||
Remark: form.Remark,
|
||||
DbInstance: dbInstance,
|
||||
LoginAccount: rc.LoginAccount,
|
||||
})
|
||||
biz.ErrIsNilAppendErr(err, "执行失败: %s")
|
||||
colAndRes := make(map[string]interface{})
|
||||
colAndRes["colNames"] = execRes.ColNames
|
||||
colAndRes["res"] = execRes.Res
|
||||
rc.ResData = colAndRes
|
||||
}
|
||||
|
||||
// 执行sql文件
|
||||
@@ -255,7 +240,13 @@ func (d *Db) DumpSql(rc *ctx.ReqCtx) {
|
||||
countSql := fmt.Sprintf("SELECT COUNT(*) count FROM %s", table)
|
||||
_, countRes, _ := dbInstance.SelectData(countSql)
|
||||
// 查询出所有列信息总数,手动分页获取所有数据
|
||||
maCount := int(countRes[0]["count"].(int64))
|
||||
maCount := 0
|
||||
// 查询出所有列信息总数,手动分页获取所有数据
|
||||
if count64, is64 := countRes[0]["maNum"].(int64); is64 {
|
||||
maCount = int(count64)
|
||||
} else {
|
||||
maCount = countRes[0]["maNum"].(int)
|
||||
}
|
||||
// 计算需要查询的页数
|
||||
pageNum := maCount / DEFAULT_COLUMN_SIZE
|
||||
if maCount%DEFAULT_COLUMN_SIZE > 0 {
|
||||
@@ -264,9 +255,9 @@ func (d *Db) DumpSql(rc *ctx.ReqCtx) {
|
||||
|
||||
var sqlTmp string
|
||||
switch dbInstance.Type {
|
||||
case "mysql":
|
||||
case entity.DbTypeMysql:
|
||||
sqlTmp = "SELECT * FROM %s LIMIT %d, %d"
|
||||
case "postgres":
|
||||
case entity.DbTypePostgres:
|
||||
sqlTmp = "SELECT * FROM %s OFFSET %d LIMIT %d"
|
||||
}
|
||||
for index := 0; index < pageNum; index++ {
|
||||
@@ -1,8 +1,8 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/db/application"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"mayfly-go/pkg/ginx"
|
||||
)
|
||||
16
server/internal/db/application/application.go
Normal file
16
server/internal/db/application/application.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package application
|
||||
|
||||
import "mayfly-go/internal/db/infrastructure/persistence"
|
||||
|
||||
var (
|
||||
dbApp Db = newDbApp(persistence.GetDbRepo(), persistence.GetDbSqlRepo())
|
||||
dbSqlExecApp DbSqlExec = newDbSqlExecApp(persistence.GetDbSqlExecRepo())
|
||||
)
|
||||
|
||||
func GetDbApp() Db {
|
||||
return dbApp
|
||||
}
|
||||
|
||||
func GetDbSqlExecApp() DbSqlExec {
|
||||
return dbSqlExecApp
|
||||
}
|
||||
@@ -3,13 +3,12 @@ package application
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"mayfly-go/internal/constant"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/devops/infrastructure/machine"
|
||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/internal/db/domain/repository"
|
||||
machineapp "mayfly-go/internal/machine/application"
|
||||
"mayfly-go/internal/machine/infrastructure/machine"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/cache"
|
||||
"mayfly-go/pkg/global"
|
||||
@@ -52,16 +51,18 @@ type Db interface {
|
||||
GetDatabases(entity *entity.Db) []string
|
||||
}
|
||||
|
||||
func newDbApp(dbRepo repository.Db, dbSqlRepo repository.DbSql) Db {
|
||||
return &dbAppImpl{
|
||||
dbRepo: dbRepo,
|
||||
dbSqlRepo: dbSqlRepo,
|
||||
}
|
||||
}
|
||||
|
||||
type dbAppImpl struct {
|
||||
dbRepo repository.Db
|
||||
dbSqlRepo repository.DbSql
|
||||
}
|
||||
|
||||
var DbApp Db = &dbAppImpl{
|
||||
dbRepo: persistence.DbDao,
|
||||
dbSqlRepo: persistence.DbSqlDao,
|
||||
}
|
||||
|
||||
// 分页获取数据库信息列表
|
||||
func (d *dbAppImpl) GetPageList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
return d.dbRepo.GetDbList(condition, pageParam, toEntity, orderBy...)
|
||||
@@ -232,7 +233,7 @@ var dbCache = cache.NewTimedCache(constant.DbConnExpireTime, 5*time.Second).
|
||||
|
||||
func init() {
|
||||
machine.AddCheckSshTunnelMachineUseFunc(func(machineId uint64) bool {
|
||||
// 遍历所有db连接实例,若存在redis实例使用该ssh隧道机器,则返回true,表示还在使用中...
|
||||
// 遍历所有db连接实例,若存在db实例使用该ssh隧道机器,则返回true,表示还在使用中...
|
||||
items := dbCache.Items()
|
||||
for _, v := range items {
|
||||
if v.Value.(*DbInstance).sshTunnelMachineId == machineId {
|
||||
@@ -265,7 +266,7 @@ func TestConnection(d *entity.Db) {
|
||||
func GetDbConn(d *entity.Db, db string) (*sql.DB, error) {
|
||||
// SSH Conect
|
||||
if d.EnableSshTunnel == 1 && d.SshTunnelMachineId != 0 {
|
||||
sshTunnelMachine := MachineApp.GetSshTunnelMachine(d.SshTunnelMachineId)
|
||||
sshTunnelMachine := machineapp.GetMachineApp().GetSshTunnelMachine(d.SshTunnelMachineId)
|
||||
if d.Type == entity.DbTypeMysql {
|
||||
mysql.RegisterDialContext(d.Network, func(ctx context.Context, addr string) (net.Conn, error) {
|
||||
return sshTunnelMachine.GetDialConn("tcp", addr)
|
||||
@@ -410,14 +411,6 @@ type DbInstance struct {
|
||||
// 执行查询语句
|
||||
// 依次返回 列名数组,结果map,错误
|
||||
func (d *DbInstance) SelectData(execSql string) ([]string, []map[string]interface{}, error) {
|
||||
execSql = strings.Trim(execSql, " ")
|
||||
isSelect := strings.HasPrefix(execSql, "SELECT") || strings.HasPrefix(execSql, "select")
|
||||
isShow := strings.HasPrefix(execSql, "show")
|
||||
isExplain := strings.HasPrefix(execSql, "explain")
|
||||
|
||||
if !isSelect && !isShow && !isExplain {
|
||||
return nil, nil, errors.New("该sql非查询语句")
|
||||
}
|
||||
return SelectDataByDb(d.db, execSql)
|
||||
}
|
||||
|
||||
@@ -558,8 +551,14 @@ func (mm *MysqlMetadata) GetColumns(tableNames ...string) []map[string]interface
|
||||
if len(tableNames) > 1 {
|
||||
countSql := fmt.Sprintf(MYSQL_COLOUMN_MA_COUNT, tableName)
|
||||
_, countRes, _ := mm.di.SelectData(countSql)
|
||||
maCount := 0
|
||||
// 查询出所有列信息总数,手动分页获取所有数据
|
||||
maCount := int(countRes[0]["maNum"].(int64))
|
||||
if count64, is64 := countRes[0]["maNum"].(int64); is64 {
|
||||
maCount = int(count64)
|
||||
} else {
|
||||
maCount = countRes[0]["maNum"].(int)
|
||||
}
|
||||
|
||||
// 计算需要查询的页数
|
||||
pageNum = maCount / DEFAULT_COLUMN_SIZE
|
||||
if maCount%DEFAULT_COLUMN_SIZE > 0 {
|
||||
@@ -672,8 +671,13 @@ func (pm *PgsqlMetadata) GetColumns(tableNames ...string) []map[string]interface
|
||||
if len(tableNames) > 1 {
|
||||
countSql := fmt.Sprintf(PGSQL_COLUMN_MA_COUNT, tableName)
|
||||
_, countRes, _ := pm.di.SelectData(countSql)
|
||||
maCount := 0
|
||||
// 查询出所有列信息总数,手动分页获取所有数据
|
||||
maCount := int(countRes[0]["maNum"].(int64))
|
||||
if count64, is64 := countRes[0]["maNum"].(int64); is64 {
|
||||
maCount = int(count64)
|
||||
} else {
|
||||
maCount = countRes[0]["maNum"].(int)
|
||||
}
|
||||
// 计算需要查询的页数
|
||||
pageNum = maCount / DEFAULT_COLUMN_SIZE
|
||||
if maCount%DEFAULT_COLUMN_SIZE > 0 {
|
||||
200
server/internal/db/application/db_sql_exec.go
Normal file
200
server/internal/db/application/db_sql_exec.go
Normal file
@@ -0,0 +1,200 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/internal/db/domain/repository"
|
||||
"mayfly-go/pkg/global"
|
||||
"mayfly-go/pkg/model"
|
||||
"strings"
|
||||
|
||||
"github.com/xwb1989/sqlparser"
|
||||
)
|
||||
|
||||
type DbSqlExecReq struct {
|
||||
DbId uint64
|
||||
Db string
|
||||
Sql string
|
||||
Remark string
|
||||
LoginAccount *model.LoginAccount
|
||||
DbInstance *DbInstance
|
||||
}
|
||||
|
||||
type DbSqlExecRes struct {
|
||||
ColNames []string
|
||||
Res []map[string]interface{}
|
||||
}
|
||||
|
||||
type DbSqlExec interface {
|
||||
// 执行sql
|
||||
Exec(execSqlReq *DbSqlExecReq) (*DbSqlExecRes, error)
|
||||
|
||||
// 根据条件删除sql执行记录
|
||||
DeleteBy(condition *entity.DbSqlExec)
|
||||
|
||||
// 分页获取
|
||||
GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
}
|
||||
|
||||
func newDbSqlExecApp(dbExecSqlRepo repository.DbSqlExec) DbSqlExec {
|
||||
return &dbSqlExecAppImpl{
|
||||
dbSqlExecRepo: dbExecSqlRepo,
|
||||
}
|
||||
}
|
||||
|
||||
type dbSqlExecAppImpl struct {
|
||||
dbSqlExecRepo repository.DbSqlExec
|
||||
}
|
||||
|
||||
func (d *dbSqlExecAppImpl) Exec(execSqlReq *DbSqlExecReq) (*DbSqlExecRes, error) {
|
||||
sql := execSqlReq.Sql
|
||||
loginAccount := execSqlReq.LoginAccount
|
||||
|
||||
// 如果是pgsql并且为查询语句,则直接返回,sqlparser不支持解析pgsql select语句
|
||||
if execSqlReq.DbInstance.Type == entity.DbTypePostgres && (strings.HasPrefix(sql, "SELECT") || strings.HasPrefix(sql, "select")) {
|
||||
return doSelect(nil, execSqlReq, nil)
|
||||
}
|
||||
|
||||
stmt, err := sqlparser.Parse(sql)
|
||||
if err != nil {
|
||||
global.Log.Error("sql解析失败: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dbSqlExecRecord := new(entity.DbSqlExec)
|
||||
dbSqlExecRecord.DbId = execSqlReq.DbId
|
||||
dbSqlExecRecord.Db = execSqlReq.Db
|
||||
dbSqlExecRecord.Sql = sql
|
||||
dbSqlExecRecord.Remark = execSqlReq.Remark
|
||||
dbSqlExecRecord.SetBaseInfo(loginAccount)
|
||||
|
||||
var execRes *DbSqlExecRes
|
||||
isSelect := false
|
||||
switch stmt := stmt.(type) {
|
||||
case *sqlparser.Select:
|
||||
isSelect = true
|
||||
execRes, err = doSelect(stmt, execSqlReq, dbSqlExecRecord)
|
||||
case *sqlparser.Show:
|
||||
isSelect = true
|
||||
execRes, err = doSelect(nil, execSqlReq, dbSqlExecRecord)
|
||||
case *sqlparser.OtherRead:
|
||||
isSelect = true
|
||||
execRes, err = doSelect(nil, execSqlReq, dbSqlExecRecord)
|
||||
case *sqlparser.Update:
|
||||
execRes, err = doUpdate(stmt, execSqlReq, dbSqlExecRecord)
|
||||
case *sqlparser.Delete:
|
||||
execRes, err = doDelete(stmt, execSqlReq, dbSqlExecRecord)
|
||||
case *sqlparser.Insert:
|
||||
execRes, err = doInsert(stmt, execSqlReq, dbSqlExecRecord)
|
||||
default:
|
||||
execRes, err = doExec(execSqlReq.Sql, execSqlReq.DbInstance)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !isSelect {
|
||||
// 保存执行记录
|
||||
d.dbSqlExecRepo.Insert(dbSqlExecRecord)
|
||||
}
|
||||
return execRes, nil
|
||||
}
|
||||
|
||||
func (d *dbSqlExecAppImpl) DeleteBy(condition *entity.DbSqlExec) {
|
||||
d.dbSqlExecRepo.DeleteBy(condition)
|
||||
}
|
||||
|
||||
func (d *dbSqlExecAppImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
return d.dbSqlExecRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func doSelect(selectStmt *sqlparser.Select, execSqlReq *DbSqlExecReq, dbSqlExec *entity.DbSqlExec) (*DbSqlExecRes, error) {
|
||||
dbInstance := execSqlReq.DbInstance
|
||||
sql := execSqlReq.Sql
|
||||
colNames, res, err := dbInstance.SelectData(sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &DbSqlExecRes{
|
||||
ColNames: colNames,
|
||||
Res: res,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func doUpdate(update *sqlparser.Update, execSqlReq *DbSqlExecReq, dbSqlExec *entity.DbSqlExec) (*DbSqlExecRes, error) {
|
||||
dbInstance := execSqlReq.DbInstance
|
||||
|
||||
tableStr := sqlparser.String(update.TableExprs)
|
||||
// 可能使用别名,故空格切割
|
||||
tableName := strings.Split(tableStr, " ")[0]
|
||||
where := sqlparser.String(update.Where)
|
||||
|
||||
updateExprs := update.Exprs
|
||||
updateColumns := make([]string, 0)
|
||||
for _, v := range updateExprs {
|
||||
updateColumns = append(updateColumns, v.Name.Name.String())
|
||||
}
|
||||
|
||||
// 获取表主键列名,排除使用别名
|
||||
primaryKey := dbInstance.GetMeta().GetPrimaryKey(tableName)
|
||||
|
||||
updateColumnsAndPrimaryKey := strings.Join(updateColumns, ",") + "," + primaryKey
|
||||
// 查询要更新字段数据的旧值,以及主键值
|
||||
selectSql := fmt.Sprintf("SELECT %s FROM %s %s LIMIT 200", updateColumnsAndPrimaryKey, tableStr, where)
|
||||
_, res, _ := dbInstance.SelectData(selectSql)
|
||||
|
||||
bytes, _ := json.Marshal(res)
|
||||
dbSqlExec.OldValue = string(bytes)
|
||||
dbSqlExec.Table = tableName
|
||||
dbSqlExec.Type = entity.DbSqlExecTypeUpdate
|
||||
|
||||
return doExec(execSqlReq.Sql, dbInstance)
|
||||
}
|
||||
|
||||
func doDelete(delete *sqlparser.Delete, execSqlReq *DbSqlExecReq, dbSqlExec *entity.DbSqlExec) (*DbSqlExecRes, error) {
|
||||
dbInstance := execSqlReq.DbInstance
|
||||
|
||||
tableStr := sqlparser.String(delete.TableExprs)
|
||||
// 可能使用别名,故空格切割
|
||||
table := strings.Split(tableStr, " ")[0]
|
||||
where := sqlparser.String(delete.Where)
|
||||
|
||||
// 查询删除数据
|
||||
selectSql := fmt.Sprintf("SELECT * FROM %s %s LIMIT 200", tableStr, where)
|
||||
_, res, _ := dbInstance.SelectData(selectSql)
|
||||
|
||||
bytes, _ := json.Marshal(res)
|
||||
dbSqlExec.OldValue = string(bytes)
|
||||
dbSqlExec.Table = table
|
||||
dbSqlExec.Type = entity.DbSqlExecTypeDelete
|
||||
|
||||
return doExec(execSqlReq.Sql, dbInstance)
|
||||
}
|
||||
|
||||
func doInsert(insert *sqlparser.Insert, execSqlReq *DbSqlExecReq, dbSqlExec *entity.DbSqlExec) (*DbSqlExecRes, error) {
|
||||
tableStr := sqlparser.String(insert.Table)
|
||||
// 可能使用别名,故空格切割
|
||||
table := strings.Split(tableStr, " ")[0]
|
||||
dbSqlExec.Table = table
|
||||
dbSqlExec.Type = entity.DbSqlExecTypeInsert
|
||||
|
||||
return doExec(execSqlReq.Sql, execSqlReq.DbInstance)
|
||||
}
|
||||
|
||||
func doExec(sql string, dbInstance *DbInstance) (*DbSqlExecRes, error) {
|
||||
rowsAffected, err := dbInstance.Exec(sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res := make([]map[string]interface{}, 0)
|
||||
resData := make(map[string]interface{})
|
||||
resData["影响条数"] = rowsAffected
|
||||
res = append(res, resData)
|
||||
|
||||
return &DbSqlExecRes{
|
||||
ColNames: []string{"影响条数"},
|
||||
Res: res,
|
||||
}, nil
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package repository
|
||||
|
||||
import "mayfly-go/internal/devops/domain/entity"
|
||||
import "mayfly-go/internal/db/domain/entity"
|
||||
|
||||
type DbSql interface {
|
||||
DeleteBy(condition *entity.DbSql)
|
||||
@@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -2,18 +2,20 @@ package persistence
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/internal/db/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type dbRepo struct{}
|
||||
type dbRepoImpl struct{}
|
||||
|
||||
var DbDao repository.Db = &dbRepo{}
|
||||
func newDbRepo() repository.Db {
|
||||
return new(dbRepoImpl)
|
||||
}
|
||||
|
||||
// 分页获取数据库信息列表
|
||||
func (d *dbRepo) GetDbList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (d *dbRepoImpl) GetDbList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
sql := "SELECT d.* FROM t_db d JOIN t_project_member pm ON d.project_id = pm.project_id WHERE 1 = 1 "
|
||||
if condition.CreatorId != 0 {
|
||||
// 使用创建者id模拟项目成员id
|
||||
@@ -35,17 +37,17 @@ func (d *dbRepo) GetDbList(condition *entity.Db, pageParam *model.PageParam, toE
|
||||
return model.GetPageBySql(sql, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (d *dbRepo) Count(condition *entity.Db) int64 {
|
||||
func (d *dbRepoImpl) Count(condition *entity.Db) int64 {
|
||||
return model.CountBy(condition)
|
||||
}
|
||||
|
||||
// 根据条件获取账号信息
|
||||
func (d *dbRepo) GetDb(condition *entity.Db, cols ...string) error {
|
||||
func (d *dbRepoImpl) GetDb(condition *entity.Db, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (d *dbRepo) GetById(id uint64, cols ...string) *entity.Db {
|
||||
func (d *dbRepoImpl) GetById(id uint64, cols ...string) *entity.Db {
|
||||
db := new(entity.Db)
|
||||
if err := model.GetById(db, id, cols...); err != nil {
|
||||
return nil
|
||||
@@ -54,14 +56,14 @@ func (d *dbRepo) GetById(id uint64, cols ...string) *entity.Db {
|
||||
return db
|
||||
}
|
||||
|
||||
func (d *dbRepo) Insert(db *entity.Db) {
|
||||
func (d *dbRepoImpl) Insert(db *entity.Db) {
|
||||
biz.ErrIsNil(model.Insert(db), "新增数据库信息失败")
|
||||
}
|
||||
|
||||
func (d *dbRepo) Update(db *entity.Db) {
|
||||
func (d *dbRepoImpl) Update(db *entity.Db) {
|
||||
biz.ErrIsNil(model.UpdateById(db), "更新数据库信息失败")
|
||||
}
|
||||
|
||||
func (d *dbRepo) Delete(id uint64) {
|
||||
func (d *dbRepoImpl) Delete(id uint64) {
|
||||
model.DeleteById(new(entity.Db), id)
|
||||
}
|
||||
19
server/internal/db/infrastructure/persistence/db_sql.go
Normal file
19
server/internal/db/infrastructure/persistence/db_sql.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/internal/db/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type dbSqlRepoImpl struct{}
|
||||
|
||||
func newDbSqlRepo() repository.DbSql {
|
||||
return new(dbSqlRepoImpl)
|
||||
}
|
||||
|
||||
// 分页获取数据库信息列表
|
||||
func (d *dbSqlRepoImpl) DeleteBy(condition *entity.DbSql) {
|
||||
biz.ErrIsNil(model.DeleteByCondition(condition), "删除sql失败")
|
||||
}
|
||||
27
server/internal/db/infrastructure/persistence/db_sql_exec.go
Normal file
27
server/internal/db/infrastructure/persistence/db_sql_exec.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/internal/db/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type dbSqlExecRepoImpl struct{}
|
||||
|
||||
func newDbSqlExecRepo() repository.DbSqlExec {
|
||||
return new(dbSqlExecRepoImpl)
|
||||
}
|
||||
|
||||
func (d *dbSqlExecRepoImpl) Insert(dse *entity.DbSqlExec) {
|
||||
model.Insert(dse)
|
||||
}
|
||||
|
||||
func (d *dbSqlExecRepoImpl) DeleteBy(condition *entity.DbSqlExec) {
|
||||
biz.ErrIsNil(model.DeleteByCondition(condition), "删除sql执行记录失败")
|
||||
}
|
||||
|
||||
// 分页获取
|
||||
func (d *dbSqlExecRepoImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
||||
}
|
||||
21
server/internal/db/infrastructure/persistence/persistence.go
Normal file
21
server/internal/db/infrastructure/persistence/persistence.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package persistence
|
||||
|
||||
import "mayfly-go/internal/db/domain/repository"
|
||||
|
||||
var (
|
||||
dbRepo repository.Db = newDbRepo()
|
||||
dbSqlRepo repository.DbSql = newDbSqlRepo()
|
||||
dbSqlExecRepo repository.DbSqlExec = newDbSqlExecRepo()
|
||||
)
|
||||
|
||||
func GetDbRepo() repository.Db {
|
||||
return dbRepo
|
||||
}
|
||||
|
||||
func GetDbSqlRepo() repository.DbSql {
|
||||
return dbSqlRepo
|
||||
}
|
||||
|
||||
func GetDbSqlExecRepo() repository.DbSqlExec {
|
||||
return dbSqlExecRepo
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/api"
|
||||
"mayfly-go/internal/devops/application"
|
||||
sysApplication "mayfly-go/internal/sys/application"
|
||||
"mayfly-go/internal/db/api"
|
||||
"mayfly-go/internal/db/application"
|
||||
projectapp "mayfly-go/internal/project/application"
|
||||
sysapp "mayfly-go/internal/sys/application"
|
||||
"mayfly-go/pkg/ctx"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -13,10 +14,10 @@ func InitDbRouter(router *gin.RouterGroup) {
|
||||
db := router.Group("dbs")
|
||||
{
|
||||
d := &api.Db{
|
||||
DbApp: application.DbApp,
|
||||
DbSqlExecApp: application.DbSqlExecApp,
|
||||
MsgApp: sysApplication.MsgApp,
|
||||
ProjectApp: application.ProjectApp,
|
||||
DbApp: application.GetDbApp(),
|
||||
DbSqlExecApp: application.GetDbSqlExecApp(),
|
||||
MsgApp: sysapp.GetMsgApp(),
|
||||
ProjectApp: projectapp.GetProjectApp(),
|
||||
}
|
||||
// 获取所有数据库列表
|
||||
db.GET("", func(c *gin.Context) {
|
||||
@@ -1,8 +1,8 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/api"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/db/api"
|
||||
"mayfly-go/internal/db/application"
|
||||
"mayfly-go/pkg/ctx"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -12,7 +12,7 @@ func InitDbSqlExecRouter(router *gin.RouterGroup) {
|
||||
db := router.Group("/dbs/:dbId/sql-execs")
|
||||
{
|
||||
d := &api.DbSqlExec{
|
||||
DbSqlExecApp: application.DbSqlExecApp,
|
||||
DbSqlExecApp: application.GetDbSqlExecApp(),
|
||||
}
|
||||
// 获取所有数据库sql执行记录列表
|
||||
db.GET("", func(c *gin.Context) {
|
||||
8
server/internal/db/router/router.go
Normal file
8
server/internal/db/router/router.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package router
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func Init(router *gin.RouterGroup) {
|
||||
InitDbRouter(router)
|
||||
InitDbSqlExecRouter(router)
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
||||
"mayfly-go/pkg/global"
|
||||
"mayfly-go/pkg/model"
|
||||
"strings"
|
||||
|
||||
"github.com/xwb1989/sqlparser"
|
||||
)
|
||||
|
||||
type DbSqlExec interface {
|
||||
// 生成sql执行记录
|
||||
GenExecLog(loginAccount *model.LoginAccount, dbId uint64, db string, sql string, dbInstance *DbInstance) *entity.DbSqlExec
|
||||
|
||||
// 保存sql执行记录
|
||||
Save(*entity.DbSqlExec)
|
||||
|
||||
// 根据条件删除sql执行记录
|
||||
DeleteBy(condition *entity.DbSqlExec)
|
||||
|
||||
// 分页获取
|
||||
GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
}
|
||||
|
||||
type dbSqlExecAppImpl struct {
|
||||
dbSqlExecRepo repository.DbSqlExec
|
||||
}
|
||||
|
||||
var DbSqlExecApp DbSqlExec = &dbSqlExecAppImpl{
|
||||
dbSqlExecRepo: persistence.DbSqlExecDao,
|
||||
}
|
||||
|
||||
func (d *dbSqlExecAppImpl) GenExecLog(loginAccount *model.LoginAccount, dbId uint64, db string, sql string, dbInstance *DbInstance) *entity.DbSqlExec {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
global.Log.Error("生成sql执行记录失败", err)
|
||||
}
|
||||
}()
|
||||
stmt, err := sqlparser.Parse(sql)
|
||||
if err != nil {
|
||||
global.Log.Error("记录数据库sql执行记录失败", err)
|
||||
}
|
||||
|
||||
dbSqlExecRecord := new(entity.DbSqlExec)
|
||||
dbSqlExecRecord.DbId = dbId
|
||||
dbSqlExecRecord.Db = db
|
||||
dbSqlExecRecord.Sql = sql
|
||||
dbSqlExecRecord.SetBaseInfo(loginAccount)
|
||||
|
||||
switch stmt := stmt.(type) {
|
||||
case *sqlparser.Update:
|
||||
doUpdate(stmt, dbInstance, dbSqlExecRecord)
|
||||
case *sqlparser.Delete:
|
||||
doDelete(stmt, dbInstance, dbSqlExecRecord)
|
||||
case *sqlparser.Insert:
|
||||
doInsert(stmt, dbSqlExecRecord)
|
||||
}
|
||||
|
||||
return dbSqlExecRecord
|
||||
}
|
||||
|
||||
func (d *dbSqlExecAppImpl) Save(dse *entity.DbSqlExec) {
|
||||
d.dbSqlExecRepo.Insert(dse)
|
||||
}
|
||||
|
||||
func (d *dbSqlExecAppImpl) DeleteBy(condition *entity.DbSqlExec) {
|
||||
d.dbSqlExecRepo.DeleteBy(condition)
|
||||
}
|
||||
|
||||
func (d *dbSqlExecAppImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
return d.dbSqlExecRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func doUpdate(update *sqlparser.Update, dbInstance *DbInstance, dbSqlExec *entity.DbSqlExec) {
|
||||
tableStr := sqlparser.String(update.TableExprs)
|
||||
// 可能使用别名,故空格切割
|
||||
tableName := strings.Split(tableStr, " ")[0]
|
||||
where := sqlparser.String(update.Where)
|
||||
|
||||
updateExprs := update.Exprs
|
||||
updateColumns := make([]string, 0)
|
||||
for _, v := range updateExprs {
|
||||
updateColumns = append(updateColumns, v.Name.Name.String())
|
||||
}
|
||||
|
||||
// 获取表主键列名,排除使用别名
|
||||
primaryKey := dbInstance.GetMeta().GetPrimaryKey(tableName)
|
||||
|
||||
updateColumnsAndPrimaryKey := strings.Join(updateColumns, ",") + "," + primaryKey
|
||||
// 查询要更新字段数据的旧值,以及主键值
|
||||
selectSql := fmt.Sprintf("SELECT %s FROM %s %s LIMIT 200", updateColumnsAndPrimaryKey, tableStr, where)
|
||||
_, res, _ := dbInstance.SelectData(selectSql)
|
||||
|
||||
bytes, _ := json.Marshal(res)
|
||||
dbSqlExec.OldValue = string(bytes)
|
||||
dbSqlExec.Table = tableName
|
||||
dbSqlExec.Type = entity.DbSqlExecTypeUpdate
|
||||
}
|
||||
|
||||
func doDelete(delete *sqlparser.Delete, dbInstance *DbInstance, dbSqlExec *entity.DbSqlExec) {
|
||||
tableStr := sqlparser.String(delete.TableExprs)
|
||||
// 可能使用别名,故空格切割
|
||||
table := strings.Split(tableStr, " ")[0]
|
||||
where := sqlparser.String(delete.Where)
|
||||
|
||||
// 查询删除数据
|
||||
selectSql := fmt.Sprintf("SELECT * FROM %s %s LIMIT 200", tableStr, where)
|
||||
_, res, _ := dbInstance.SelectData(selectSql)
|
||||
|
||||
bytes, _ := json.Marshal(res)
|
||||
dbSqlExec.OldValue = string(bytes)
|
||||
dbSqlExec.Table = table
|
||||
dbSqlExec.Type = entity.DbSqlExecTypeDelete
|
||||
}
|
||||
|
||||
func doInsert(insert *sqlparser.Insert, dbSqlExec *entity.DbSqlExec) {
|
||||
tableStr := sqlparser.String(insert.Table)
|
||||
// 可能使用别名,故空格切割
|
||||
table := strings.Split(tableStr, " ")[0]
|
||||
dbSqlExec.Table = table
|
||||
dbSqlExec.Type = entity.DbSqlExecTypeInsert
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type dbSqlExecRepo struct{}
|
||||
|
||||
var DbSqlExecDao repository.DbSqlExec = &dbSqlExecRepo{}
|
||||
|
||||
func (d *dbSqlExecRepo) Insert(dse *entity.DbSqlExec) {
|
||||
model.Insert(dse)
|
||||
}
|
||||
|
||||
func (d *dbSqlExecRepo) DeleteBy(condition *entity.DbSqlExec) {
|
||||
biz.ErrIsNil(model.DeleteByCondition(condition), "删除sql执行记录失败")
|
||||
}
|
||||
|
||||
// 分页获取
|
||||
func (d *dbSqlExecRepo) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type dbSqlRepo struct{}
|
||||
|
||||
var DbSqlDao repository.DbSql = &dbSqlRepo{}
|
||||
|
||||
// 分页获取数据库信息列表
|
||||
func (d *dbSqlRepo) DeleteBy(condition *entity.DbSql) {
|
||||
biz.ErrIsNil(model.DeleteByCondition(condition), "删除sql失败")
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type machineFileRepo struct{}
|
||||
|
||||
var MachineFileDao repository.MachineFile = &machineFileRepo{}
|
||||
|
||||
// 分页获取机器文件信息列表
|
||||
func (m *machineFileRepo) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
// 根据条件获取账号信息
|
||||
func (m *machineFileRepo) GetMachineFile(condition *entity.MachineFile, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (m *machineFileRepo) GetById(id uint64, cols ...string) *entity.MachineFile {
|
||||
ms := new(entity.MachineFile)
|
||||
if err := model.GetById(ms, id, cols...); err != nil {
|
||||
return nil
|
||||
|
||||
}
|
||||
return ms
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (m *machineFileRepo) Delete(id uint64) {
|
||||
biz.ErrIsNil(model.DeleteById(new(entity.MachineFile), id), "删除失败")
|
||||
}
|
||||
|
||||
func (m *machineFileRepo) Create(entity *entity.MachineFile) {
|
||||
model.Insert(entity)
|
||||
}
|
||||
|
||||
func (m *machineFileRepo) UpdateById(entity *entity.MachineFile) {
|
||||
model.UpdateById(entity)
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type machineScriptRepo struct{}
|
||||
|
||||
var MachineScriptDao repository.MachineScript = &machineScriptRepo{}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (m *machineScriptRepo) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
// 根据条件获取账号信息
|
||||
func (m *machineScriptRepo) GetMachineScript(condition *entity.MachineScript, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (m *machineScriptRepo) GetById(id uint64, cols ...string) *entity.MachineScript {
|
||||
ms := new(entity.MachineScript)
|
||||
if err := model.GetById(ms, id, cols...); err != nil {
|
||||
return nil
|
||||
|
||||
}
|
||||
return ms
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (m *machineScriptRepo) Delete(id uint64) {
|
||||
biz.ErrIsNil(model.DeleteById(new(entity.MachineScript), id), "删除失败")
|
||||
}
|
||||
|
||||
func (m *machineScriptRepo) Create(entity *entity.MachineScript) {
|
||||
model.Insert(entity)
|
||||
}
|
||||
|
||||
func (m *machineScriptRepo) UpdateById(entity *entity.MachineScript) {
|
||||
model.UpdateById(entity)
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type projectEnvRepo struct{}
|
||||
|
||||
var ProjectEnvRepo repository.ProjectEnv = &projectEnvRepo{}
|
||||
|
||||
func (p *projectEnvRepo) ListEnv(condition *entity.ProjectEnv, toEntity interface{}, orderBy ...string) {
|
||||
model.ListByOrder(condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (p *projectEnvRepo) Save(entity *entity.ProjectEnv) {
|
||||
biz.ErrIsNilAppendErr(model.Insert(entity), "保存环境失败:%s")
|
||||
}
|
||||
|
||||
func (p *projectEnvRepo) DeleteEnvs(projectId uint64) {
|
||||
model.DeleteByCondition(&entity.ProjectEnv{ProjectId: projectId})
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type projectMemeberRepo struct{}
|
||||
|
||||
var ProjectMemberRepo repository.ProjectMemeber = &projectMemeberRepo{}
|
||||
|
||||
func (p *projectMemeberRepo) ListMemeber(condition *entity.ProjectMember, toEntity interface{}, orderBy ...string) {
|
||||
model.ListByOrder(condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (p *projectMemeberRepo) Save(pm *entity.ProjectMember) {
|
||||
biz.ErrIsNilAppendErr(model.Insert(pm), "保存项目成员失败:%s")
|
||||
}
|
||||
|
||||
func (p *projectMemeberRepo) GetPageList(condition *entity.ProjectMember, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (p *projectMemeberRepo) DeleteByPidMid(projectId, accountId uint64) {
|
||||
model.DeleteByCondition(&entity.ProjectMember{ProjectId: projectId, AccountId: accountId})
|
||||
}
|
||||
|
||||
func (p *projectMemeberRepo) DeleteMems(projectId uint64) {
|
||||
model.DeleteByCondition(&entity.ProjectMember{ProjectId: projectId})
|
||||
}
|
||||
|
||||
func (p *projectMemeberRepo) IsExist(projectId, accountId uint64) bool {
|
||||
return model.CountBy(&entity.ProjectMember{ProjectId: projectId, AccountId: accountId}) > 0
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type projectRepo struct{}
|
||||
|
||||
var ProjectRepo repository.Project = &projectRepo{}
|
||||
|
||||
func (p *projectRepo) GetPageList(condition *entity.Project, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (p *projectRepo) Count(condition *entity.Project) int64 {
|
||||
return model.CountBy(condition)
|
||||
}
|
||||
|
||||
func (p *projectRepo) GetByIdIn(ids []uint64, toEntity interface{}, orderBy ...string) {
|
||||
model.GetByIdIn(new(entity.Project), toEntity, ids, orderBy...)
|
||||
}
|
||||
|
||||
func (p *projectRepo) Save(project *entity.Project) {
|
||||
biz.ErrIsNil(model.Insert(project), "保存项目失败")
|
||||
}
|
||||
|
||||
func (p *projectRepo) Update(project *entity.Project) {
|
||||
biz.ErrIsNil(model.UpdateById(project), "更新项目信息")
|
||||
}
|
||||
|
||||
func (p *projectRepo) Delete(id uint64) {
|
||||
model.DeleteById(new(entity.Project), id)
|
||||
}
|
||||
@@ -13,6 +13,7 @@ type MachineForm struct {
|
||||
Remark string `json:"remark"`
|
||||
EnableSshTunnel int8 `json:"enableSshTunnel"` // 是否启用ssh隧道
|
||||
SshTunnelMachineId uint64 `json:"sshTunnelMachineId"` // ssh隧道机器id
|
||||
EnableRecorder int8 `json:"enableRecorder"` // 是否启用终端回放记录
|
||||
}
|
||||
|
||||
type MachineRunForm struct {
|
||||
@@ -1,18 +1,25 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"mayfly-go/internal/devops/api/form"
|
||||
"mayfly-go/internal/devops/api/vo"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/infrastructure/machine"
|
||||
"mayfly-go/internal/machine/api/form"
|
||||
"mayfly-go/internal/machine/api/vo"
|
||||
"mayfly-go/internal/machine/application"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/infrastructure/machine"
|
||||
projectapp "mayfly-go/internal/project/application"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/config"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"mayfly-go/pkg/ginx"
|
||||
"mayfly-go/pkg/utils"
|
||||
"mayfly-go/pkg/ws"
|
||||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
@@ -20,7 +27,7 @@ import (
|
||||
|
||||
type Machine struct {
|
||||
MachineApp application.Machine
|
||||
ProjectApp application.Project
|
||||
ProjectApp projectapp.Project
|
||||
}
|
||||
|
||||
func (m *Machine) Machines(rc *ctx.ReqCtx) {
|
||||
@@ -138,22 +145,22 @@ func (m *Machine) KillProcess(rc *ctx.ReqCtx) {
|
||||
cli := m.MachineApp.GetCli(GetMachineId(rc.GinCtx))
|
||||
biz.ErrIsNilAppendErr(m.ProjectApp.CanAccess(rc.LoginAccount.Id, cli.GetMachine().ProjectId), "%s")
|
||||
|
||||
_, err := cli.Run("kill -9 " + pid)
|
||||
_, err := cli.Run("sudo kill -9 " + pid)
|
||||
biz.ErrIsNilAppendErr(err, "终止进程失败: %s")
|
||||
}
|
||||
|
||||
func (m *Machine) WsSSH(g *gin.Context) {
|
||||
wsConn, err := ws.Upgrader.Upgrade(g.Writer, g.Request, nil)
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
wsConn.WriteMessage(websocket.TextMessage, []byte(err.(error).Error()))
|
||||
if wsConn != nil {
|
||||
if err := recover(); err != nil {
|
||||
wsConn.WriteMessage(websocket.TextMessage, []byte(err.(error).Error()))
|
||||
}
|
||||
wsConn.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
if err != nil {
|
||||
panic(biz.NewBizErr("升级websocket失败"))
|
||||
}
|
||||
biz.ErrIsNilAppendErr(err, "升级websocket失败: %s")
|
||||
// 权限校验
|
||||
rc := ctx.NewReqCtxWithGin(g).WithRequiredPermission(ctx.NewPermission("machine:terminal"))
|
||||
if err = ctx.PermissionHandler(rc); err != nil {
|
||||
@@ -166,12 +173,50 @@ func (m *Machine) WsSSH(g *gin.Context) {
|
||||
cols := ginx.QueryInt(g, "cols", 80)
|
||||
rows := ginx.QueryInt(g, "rows", 40)
|
||||
|
||||
mts, err := machine.NewTerminalSession(utils.RandString(16), wsConn, cli, rows, cols)
|
||||
var recorder *machine.Recorder
|
||||
if cli.GetMachine().EnableRecorder == 1 {
|
||||
now := time.Now()
|
||||
// 回放文件路径为: 基础配置路径/机器id/操作日期/操作者账号/操作时间.cast
|
||||
recPath := fmt.Sprintf("%s/%d/%s/%s", config.Conf.Server.GetMachineRecPath(), cli.GetMachine().Id, now.Format("20060102"), rc.LoginAccount.Username)
|
||||
os.MkdirAll(recPath, 0766)
|
||||
fileName := path.Join(recPath, fmt.Sprintf("%s.cast", now.Format("20060102_150405")))
|
||||
f, err := os.OpenFile(fileName, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0766)
|
||||
biz.ErrIsNilAppendErr(err, "创建终端回放记录文件失败: %s")
|
||||
defer f.Close()
|
||||
recorder = machine.NewRecorder(f)
|
||||
}
|
||||
|
||||
mts, err := machine.NewTerminalSession(utils.RandString(16), wsConn, cli, rows, cols, recorder)
|
||||
biz.ErrIsNilAppendErr(err, "\033[1;31m连接失败: %s\033[0m")
|
||||
mts.Start()
|
||||
defer mts.Stop()
|
||||
}
|
||||
|
||||
// 获取机器终端回放记录的相应文件夹名或文件内容
|
||||
func (m *Machine) MachineRecDirNames(rc *ctx.ReqCtx) {
|
||||
readPath := rc.GinCtx.Query("path")
|
||||
biz.NotEmpty(readPath, "path不能为空")
|
||||
path_ := path.Join(config.Conf.Server.GetMachineRecPath(), readPath)
|
||||
|
||||
// 如果是读取文件内容,则读取对应回放记录文件内容,否则读取文件夹名列表。小小偷懒一会不想再加个接口
|
||||
isFile := rc.GinCtx.Query("isFile")
|
||||
if isFile == "1" {
|
||||
bytes, err := os.ReadFile(path_)
|
||||
biz.ErrIsNilAppendErr(err, "还未有相应终端操作记录: %s")
|
||||
rc.ResData = base64.StdEncoding.EncodeToString(bytes)
|
||||
return
|
||||
}
|
||||
|
||||
files, err := os.ReadDir(path_)
|
||||
biz.ErrIsNilAppendErr(err, "还未有相应终端操作记录: %s")
|
||||
var names []string
|
||||
for _, f := range files {
|
||||
names = append(names, f.Name())
|
||||
}
|
||||
sort.Sort(sort.Reverse(sort.StringSlice(names)))
|
||||
rc.ResData = names
|
||||
}
|
||||
|
||||
func GetMachineId(g *gin.Context) uint64 {
|
||||
machineId, _ := strconv.Atoi(g.Param("machineId"))
|
||||
biz.IsTrue(machineId != 0, "machineId错误")
|
||||
@@ -2,12 +2,12 @@ package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"mayfly-go/internal/devops/api/form"
|
||||
"mayfly-go/internal/devops/api/vo"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/machine/api/form"
|
||||
"mayfly-go/internal/machine/api/vo"
|
||||
"mayfly-go/internal/machine/application"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
sysApplication "mayfly-go/internal/sys/application"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/ctx"
|
||||
@@ -98,7 +98,7 @@ func (m *MachineFile) ReadFileContent(rc *ctx.ReqCtx) {
|
||||
path := strings.Split(readPath, "/")
|
||||
rc.Download(sftpFile, path[len(path)-1])
|
||||
} else {
|
||||
datas, err := ioutil.ReadAll(sftpFile)
|
||||
datas, err := io.ReadAll(sftpFile)
|
||||
biz.ErrIsNilAppendErr(err, "读取文件内容失败: %s")
|
||||
rc.ResData = string(datas)
|
||||
}
|
||||
@@ -116,11 +116,12 @@ func (m *MachineFile) GetDirEntry(rc *ctx.ReqCtx) {
|
||||
fisVO := make([]vo.MachineFileInfo, 0)
|
||||
for _, fi := range fis {
|
||||
fisVO = append(fisVO, vo.MachineFileInfo{
|
||||
Name: fi.Name(),
|
||||
Size: fi.Size(),
|
||||
Path: readPath + fi.Name(),
|
||||
Type: getFileType(fi.Mode()),
|
||||
Mode: fi.Mode().String(),
|
||||
Name: fi.Name(),
|
||||
Size: fi.Size(),
|
||||
Path: readPath + fi.Name(),
|
||||
Type: getFileType(fi.Mode()),
|
||||
Mode: fi.Mode().String(),
|
||||
ModTime: fi.ModTime().Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
rc.ResData = fisVO
|
||||
@@ -2,10 +2,11 @@ package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/internal/devops/api/form"
|
||||
"mayfly-go/internal/devops/api/vo"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/machine/api/form"
|
||||
"mayfly-go/internal/machine/api/vo"
|
||||
"mayfly-go/internal/machine/application"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
projectapp "mayfly-go/internal/project/application"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"mayfly-go/pkg/ginx"
|
||||
@@ -18,7 +19,7 @@ import (
|
||||
type MachineScript struct {
|
||||
MachineScriptApp application.MachineScript
|
||||
MachineApp application.Machine
|
||||
ProjectApp application.Project
|
||||
ProjectApp projectapp.Project
|
||||
}
|
||||
|
||||
func (m *MachineScript) MachineScripts(rc *ctx.ReqCtx) {
|
||||
@@ -34,6 +34,7 @@ type MachineVO struct {
|
||||
ModifierId *int64 `json:"modifierId"`
|
||||
HasCli bool `json:"hasCli" gorm:"-"`
|
||||
Remark *string `json:"remark"`
|
||||
EnableRecorder int8 `json:"enableRecorder"`
|
||||
}
|
||||
|
||||
type MachineScriptVO struct {
|
||||
@@ -55,11 +56,12 @@ type MachineFileVO struct {
|
||||
}
|
||||
|
||||
type MachineFileInfo struct {
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
Size int64 `json:"size"`
|
||||
Type string `json:"type"`
|
||||
Mode string `json:"mode"`
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
Size int64 `json:"size"`
|
||||
Type string `json:"type"`
|
||||
Mode string `json:"mode"`
|
||||
ModTime string `json:"modTime"`
|
||||
}
|
||||
|
||||
type RoleVO struct {
|
||||
21
server/internal/machine/application/application.go
Normal file
21
server/internal/machine/application/application.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package application
|
||||
|
||||
import "mayfly-go/internal/machine/infrastructure/persistence"
|
||||
|
||||
var (
|
||||
machineApp Machine = newMachineApp(persistence.GetMachineRepo())
|
||||
machineFileApp MachineFile = newMachineFileApp(persistence.GetMachineFileRepo(), persistence.GetMachineRepo())
|
||||
machineScriptApp MachineScript = newMachineScriptApp(persistence.GetMachineScriptRepo(), persistence.GetMachineRepo())
|
||||
)
|
||||
|
||||
func GetMachineApp() Machine {
|
||||
return machineApp
|
||||
}
|
||||
|
||||
func GetMachineFileApp() MachineFile {
|
||||
return machineFileApp
|
||||
}
|
||||
|
||||
func GetMachineScriptApp() MachineScript {
|
||||
return machineScriptApp
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/devops/infrastructure/machine"
|
||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/internal/machine/infrastructure/machine"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
|
||||
@@ -37,12 +36,15 @@ type Machine interface {
|
||||
GetSshTunnelMachine(id uint64) *machine.SshTunnelMachine
|
||||
}
|
||||
|
||||
func newMachineApp(machineRepo repository.Machine) Machine {
|
||||
return &machineAppImpl{machineRepo: machineRepo}
|
||||
|
||||
}
|
||||
|
||||
type machineAppImpl struct {
|
||||
machineRepo repository.Machine
|
||||
}
|
||||
|
||||
var MachineApp Machine = &machineAppImpl{machineRepo: persistence.MachineDao}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (m *machineAppImpl) GetMachineList(condition *entity.Machine, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
return m.machineRepo.GetMachineList(condition, pageParam, toEntity, orderBy...)
|
||||
@@ -56,7 +58,11 @@ func (m *machineAppImpl) Count(condition *entity.Machine) int64 {
|
||||
func (m *machineAppImpl) Save(me *entity.Machine) {
|
||||
// ’修改机器信息且密码不为空‘ or ‘新增’需要测试是否可连接
|
||||
if (me.Id != 0 && me.Password != "") || me.Id == 0 {
|
||||
biz.ErrIsNilAppendErr(machine.TestConn(*me, func(u uint64) *entity.Machine { return m.GetById(u) }), "该机器无法连接: %s")
|
||||
biz.ErrIsNilAppendErr(machine.TestConn(*me, func(u uint64) *entity.Machine {
|
||||
me := m.GetById(u)
|
||||
me.PwdDecrypt()
|
||||
return me
|
||||
}), "该机器无法连接: %s")
|
||||
}
|
||||
|
||||
oldMachine := &entity.Machine{Ip: me.Ip, Port: me.Port, Username: me.Username}
|
||||
@@ -4,9 +4,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
"os"
|
||||
@@ -53,17 +52,16 @@ type MachineFile interface {
|
||||
RemoveFile(fileId uint64, path string)
|
||||
}
|
||||
|
||||
func newMachineFileApp(machineFileRepo repository.MachineFile, machineRepo repository.Machine) MachineFile {
|
||||
return &machineFileAppImpl{machineRepo: machineRepo, machineFileRepo: machineFileRepo}
|
||||
|
||||
}
|
||||
|
||||
type machineFileAppImpl struct {
|
||||
machineFileRepo repository.MachineFile
|
||||
machineRepo repository.Machine
|
||||
}
|
||||
|
||||
// 实现类单例
|
||||
var MachineFileApp MachineFile = &machineFileAppImpl{
|
||||
machineRepo: persistence.MachineDao,
|
||||
machineFileRepo: persistence.MachineFileDao,
|
||||
}
|
||||
|
||||
// 分页获取机器脚本信息列表
|
||||
func (m *machineFileAppImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
return m.machineFileRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
@@ -176,7 +174,7 @@ func (m *machineFileAppImpl) RemoveFile(fileId uint64, path string) {
|
||||
err = sftpCli.RemoveDirectory(path)
|
||||
// 如果文件夹有内容会删除失败,则使用rm -rf命令删除
|
||||
if err != nil {
|
||||
MachineApp.GetCli(machineId).Run(fmt.Sprintf("rm -rf %s", path))
|
||||
GetMachineApp().GetCli(machineId).Run(fmt.Sprintf("rm -rf %s", path))
|
||||
err = nil
|
||||
}
|
||||
} else {
|
||||
@@ -187,7 +185,7 @@ func (m *machineFileAppImpl) RemoveFile(fileId uint64, path string) {
|
||||
|
||||
// 获取sftp client
|
||||
func (m *machineFileAppImpl) getSftpCli(machineId uint64) *sftp.Client {
|
||||
return MachineApp.GetCli(machineId).GetSftpCli()
|
||||
return GetMachineApp().GetCli(machineId).GetSftpCli()
|
||||
}
|
||||
|
||||
// 校验并返回实际可访问的文件path
|
||||
@@ -1,9 +1,8 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
@@ -23,6 +22,11 @@ type MachineScript interface {
|
||||
Delete(id uint64)
|
||||
}
|
||||
|
||||
func newMachineScriptApp(machineScriptRepo repository.MachineScript, machineRepo repository.Machine) MachineScript {
|
||||
return &machineScriptAppImpl{machineRepo: machineRepo, machineScriptRepo: machineScriptRepo}
|
||||
|
||||
}
|
||||
|
||||
type machineScriptAppImpl struct {
|
||||
machineScriptRepo repository.MachineScript
|
||||
machineRepo repository.Machine
|
||||
@@ -30,10 +34,10 @@ type machineScriptAppImpl struct {
|
||||
|
||||
const Common_Script_Machine_Id = 9999999
|
||||
|
||||
// 实现类单例
|
||||
var MachineScriptApp MachineScript = &machineScriptAppImpl{
|
||||
machineRepo: persistence.MachineDao,
|
||||
machineScriptRepo: persistence.MachineScriptDao}
|
||||
// // 实现类单例
|
||||
// var MachineScriptApp MachineScript = &machineScriptAppImpl{
|
||||
// machineRepo: persistence.MachineDao,
|
||||
// machineScriptRepo: persistence.MachineScriptDao}
|
||||
|
||||
// 分页获取机器脚本信息列表
|
||||
func (m *machineScriptAppImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
@@ -19,6 +19,7 @@ type Machine struct {
|
||||
Remark string `json:"remark"` // 备注
|
||||
EnableSshTunnel int8 `json:"enableSshTunnel"` // 是否启用ssh隧道
|
||||
SshTunnelMachineId uint64 `json:"sshTunnelMachineId"` // ssh隧道机器id
|
||||
EnableRecorder int8 `json:"enableRecorder"` // 是否启用终端回放记录
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"mayfly-go/internal/constant"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/cache"
|
||||
"mayfly-go/pkg/global"
|
||||
@@ -27,7 +27,7 @@ type Cli struct {
|
||||
sshTunnelMachineId uint64
|
||||
}
|
||||
|
||||
//连接
|
||||
// 连接
|
||||
func (c *Cli) connect() error {
|
||||
// 如果已经有client则直接返回
|
||||
if c.client != nil {
|
||||
@@ -90,8 +90,8 @@ func (c *Cli) GetSession() (*ssh.Session, error) {
|
||||
return c.client.NewSession()
|
||||
}
|
||||
|
||||
//执行shell
|
||||
//@param shell shell脚本命令
|
||||
// 执行shell
|
||||
// @param shell shell脚本命令
|
||||
func (c *Cli) Run(shell string) (*string, error) {
|
||||
session, err := c.GetSession()
|
||||
if err != nil {
|
||||
@@ -236,7 +236,7 @@ func GetSshClient(m *entity.Machine) (*ssh.Client, error) {
|
||||
return sshClient, nil
|
||||
}
|
||||
|
||||
//根据机器信息创建客户端对象
|
||||
// 根据机器信息创建客户端对象
|
||||
func newClient(machine *entity.Machine) (*Cli, error) {
|
||||
if machine == nil {
|
||||
return nil, errors.New("机器不存在")
|
||||
67
server/internal/machine/infrastructure/machine/recorder.go
Normal file
67
server/internal/machine/infrastructure/machine/recorder.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package machine
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type RecType string
|
||||
|
||||
const (
|
||||
InputType RecType = "i"
|
||||
OutPutType RecType = "o"
|
||||
)
|
||||
|
||||
type RecHeader struct {
|
||||
Version int `json:"version"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
Env struct {
|
||||
Shell string `json:"SHELL"`
|
||||
Term string `json:"TERM"`
|
||||
} `json:"env"`
|
||||
}
|
||||
|
||||
func defaultRecHeader() *RecHeader {
|
||||
recHeader := new(RecHeader)
|
||||
recHeader.Version = 2
|
||||
recHeader.Env.Shell = "/bin/bash"
|
||||
recHeader.Env.Term = "xterm-256color"
|
||||
return recHeader
|
||||
}
|
||||
|
||||
type Recorder struct {
|
||||
StartTime time.Time
|
||||
Writer io.Writer
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
func NewRecorder(writer io.Writer) *Recorder {
|
||||
return &Recorder{
|
||||
StartTime: time.Now(),
|
||||
Writer: writer,
|
||||
}
|
||||
}
|
||||
|
||||
func (rec *Recorder) WriteHeader(height, width int) {
|
||||
header := defaultRecHeader()
|
||||
header.Timestamp = rec.StartTime.Unix()
|
||||
header.Height = height
|
||||
header.Width = width
|
||||
b, _ := json.Marshal(header)
|
||||
rec.Writer.Write(b)
|
||||
rec.Writer.Write([]byte("\r\n"))
|
||||
}
|
||||
|
||||
func (rec *Recorder) WriteData(rectype RecType, data string) {
|
||||
recData := make([]interface{}, 3)
|
||||
recData[0] = float64(time.Since(rec.StartTime).Microseconds()) / float64(1000000)
|
||||
recData[1] = rectype
|
||||
recData[2] = data
|
||||
b, _ := json.Marshal(recData)
|
||||
rec.Writer.Write(b)
|
||||
rec.Writer.Write([]byte("\r\n"))
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package machine
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/pkg/global"
|
||||
"mayfly-go/pkg/scheduler"
|
||||
"mayfly-go/pkg/utils"
|
||||
@@ -279,16 +279,21 @@ func getCPU(cpuInfo string, stats *Stats) (err error) {
|
||||
value := strings.Split(cpuInfo, ":")[1]
|
||||
values := strings.Split(value, ",")
|
||||
|
||||
us, _ := strconv.ParseFloat(strings.Split(strings.TrimSpace(values[0]), " ")[0], 32)
|
||||
separator := " "
|
||||
// 兼容旧版本使用%的情况
|
||||
if strings.Contains(values[0], "%") {
|
||||
separator = "%"
|
||||
}
|
||||
us, _ := strconv.ParseFloat(strings.Split(strings.TrimSpace(values[0]), separator)[0], 32)
|
||||
stats.CPU.User = float32(us)
|
||||
|
||||
sy, _ := strconv.ParseFloat(strings.Split(strings.TrimSpace(values[1]), " ")[0], 32)
|
||||
sy, _ := strconv.ParseFloat(strings.Split(strings.TrimSpace(values[1]), separator)[0], 32)
|
||||
stats.CPU.System = float32(sy)
|
||||
|
||||
id, _ := strconv.ParseFloat(strings.Split(strings.TrimSpace(values[3]), " ")[0], 32)
|
||||
id, _ := strconv.ParseFloat(strings.Split(strings.TrimSpace(values[3]), separator)[0], 32)
|
||||
stats.CPU.Idle = float32(id)
|
||||
|
||||
wa, _ := strconv.ParseFloat(strings.Split(strings.TrimSpace(values[4]), " ")[0], 32)
|
||||
wa, _ := strconv.ParseFloat(strings.Split(strings.TrimSpace(values[4]), separator)[0], 32)
|
||||
stats.CPU.Iowait = float32(wa)
|
||||
|
||||
return nil
|
||||
@@ -21,13 +21,14 @@ type TerminalSession struct {
|
||||
ID string
|
||||
wsConn *websocket.Conn
|
||||
terminal *Terminal
|
||||
recorder *Recorder
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
dataChan chan rune
|
||||
tick *time.Ticker
|
||||
}
|
||||
|
||||
func NewTerminalSession(sessionId string, ws *websocket.Conn, cli *Cli, rows, cols int) (*TerminalSession, error) {
|
||||
func NewTerminalSession(sessionId string, ws *websocket.Conn, cli *Cli, rows, cols int, recorder *Recorder) (*TerminalSession, error) {
|
||||
terminal, err := NewTerminal(cli)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -41,12 +42,17 @@ func NewTerminalSession(sessionId string, ws *websocket.Conn, cli *Cli, rows, co
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if recorder != nil {
|
||||
recorder.WriteHeader(rows-5, cols)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
tick := time.NewTicker(time.Millisecond * time.Duration(60))
|
||||
ts := &TerminalSession{
|
||||
ID: sessionId,
|
||||
wsConn: ws,
|
||||
terminal: terminal,
|
||||
recorder: recorder,
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
dataChan: make(chan rune),
|
||||
@@ -65,9 +71,6 @@ func (r TerminalSession) Stop() {
|
||||
global.Log.Debug("close machine ssh terminal session")
|
||||
r.tick.Stop()
|
||||
r.cancel()
|
||||
if r.wsConn != nil {
|
||||
r.wsConn.Close()
|
||||
}
|
||||
if r.terminal != nil {
|
||||
if err := r.terminal.Close(); err != nil {
|
||||
global.Log.Errorf("关闭机器ssh终端失败: %s", err.Error())
|
||||
@@ -108,6 +111,12 @@ func (ts TerminalSession) writeToWebsocket() {
|
||||
global.Log.Error("机器ssh终端发送消息至websocket失败: ", err)
|
||||
return
|
||||
}
|
||||
// 如果记录器存在,则记录操作回放信息
|
||||
if ts.recorder != nil {
|
||||
ts.recorder.Lock()
|
||||
ts.recorder.WriteData(OutPutType, s)
|
||||
ts.recorder.Unlock()
|
||||
}
|
||||
buf = []byte{}
|
||||
}
|
||||
case data := <-ts.dataChan:
|
||||
@@ -2,18 +2,20 @@ package persistence
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type machineRepo struct{}
|
||||
type machineRepoImpl struct{}
|
||||
|
||||
var MachineDao repository.Machine = &machineRepo{}
|
||||
func newMachineRepo() repository.Machine {
|
||||
return new(machineRepoImpl)
|
||||
}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (m *machineRepo) GetMachineList(condition *entity.Machine, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (m *machineRepoImpl) GetMachineList(condition *entity.Machine, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
sql := "SELECT m.* FROM t_machine m JOIN t_project_member pm ON m.project_id = pm.project_id WHERE 1 = 1 "
|
||||
if condition.CreatorId != 0 {
|
||||
// 使用创建者id模拟项目成员id
|
||||
@@ -32,17 +34,17 @@ func (m *machineRepo) GetMachineList(condition *entity.Machine, pageParam *model
|
||||
return model.GetPageBySql(sql, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (m *machineRepo) Count(condition *entity.Machine) int64 {
|
||||
func (m *machineRepoImpl) Count(condition *entity.Machine) int64 {
|
||||
return model.CountBy(condition)
|
||||
}
|
||||
|
||||
// 根据条件获取账号信息
|
||||
func (m *machineRepo) GetMachine(condition *entity.Machine, cols ...string) error {
|
||||
func (m *machineRepoImpl) GetMachine(condition *entity.Machine, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (m *machineRepo) GetById(id uint64, cols ...string) *entity.Machine {
|
||||
func (m *machineRepoImpl) GetById(id uint64, cols ...string) *entity.Machine {
|
||||
machine := new(entity.Machine)
|
||||
if err := model.GetById(machine, id, cols...); err != nil {
|
||||
return nil
|
||||
@@ -51,10 +53,10 @@ func (m *machineRepo) GetById(id uint64, cols ...string) *entity.Machine {
|
||||
return machine
|
||||
}
|
||||
|
||||
func (m *machineRepo) Create(entity *entity.Machine) {
|
||||
func (m *machineRepoImpl) Create(entity *entity.Machine) {
|
||||
biz.ErrIsNilAppendErr(model.Insert(entity), "创建机器信息失败: %s")
|
||||
}
|
||||
|
||||
func (m *machineRepo) UpdateById(entity *entity.Machine) {
|
||||
func (m *machineRepoImpl) UpdateById(entity *entity.Machine) {
|
||||
biz.ErrIsNilAppendErr(model.UpdateById(entity), "更新机器信息失败: %s")
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type machineFileRepoImpl struct{}
|
||||
|
||||
func newMachineFileRepo() repository.MachineFile {
|
||||
return new(machineFileRepoImpl)
|
||||
}
|
||||
|
||||
// 分页获取机器文件信息列表
|
||||
func (m *machineFileRepoImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
// 根据条件获取账号信息
|
||||
func (m *machineFileRepoImpl) GetMachineFile(condition *entity.MachineFile, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (m *machineFileRepoImpl) GetById(id uint64, cols ...string) *entity.MachineFile {
|
||||
ms := new(entity.MachineFile)
|
||||
if err := model.GetById(ms, id, cols...); err != nil {
|
||||
return nil
|
||||
|
||||
}
|
||||
return ms
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (m *machineFileRepoImpl) Delete(id uint64) {
|
||||
biz.ErrIsNil(model.DeleteById(new(entity.MachineFile), id), "删除失败")
|
||||
}
|
||||
|
||||
func (m *machineFileRepoImpl) Create(entity *entity.MachineFile) {
|
||||
model.Insert(entity)
|
||||
}
|
||||
|
||||
func (m *machineFileRepoImpl) UpdateById(entity *entity.MachineFile) {
|
||||
model.UpdateById(entity)
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type machineScriptRepoImpl struct{}
|
||||
|
||||
func newMachineScriptRepo() repository.MachineScript {
|
||||
return new(machineScriptRepoImpl)
|
||||
}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (m *machineScriptRepoImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
// 根据条件获取账号信息
|
||||
func (m *machineScriptRepoImpl) GetMachineScript(condition *entity.MachineScript, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (m *machineScriptRepoImpl) GetById(id uint64, cols ...string) *entity.MachineScript {
|
||||
ms := new(entity.MachineScript)
|
||||
if err := model.GetById(ms, id, cols...); err != nil {
|
||||
return nil
|
||||
|
||||
}
|
||||
return ms
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (m *machineScriptRepoImpl) Delete(id uint64) {
|
||||
biz.ErrIsNil(model.DeleteById(new(entity.MachineScript), id), "删除失败")
|
||||
}
|
||||
|
||||
func (m *machineScriptRepoImpl) Create(entity *entity.MachineScript) {
|
||||
model.Insert(entity)
|
||||
}
|
||||
|
||||
func (m *machineScriptRepoImpl) UpdateById(entity *entity.MachineScript) {
|
||||
model.UpdateById(entity)
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package persistence
|
||||
|
||||
import "mayfly-go/internal/machine/domain/repository"
|
||||
|
||||
var (
|
||||
machineRepo repository.Machine = newMachineRepo()
|
||||
machineFileRepo repository.MachineFile = newMachineFileRepo()
|
||||
machineScriptRepo repository.MachineScript = newMachineScriptRepo()
|
||||
)
|
||||
|
||||
func GetMachineRepo() repository.Machine {
|
||||
return machineRepo
|
||||
}
|
||||
|
||||
func GetMachineFileRepo() repository.MachineFile {
|
||||
return machineFileRepo
|
||||
}
|
||||
|
||||
func GetMachineScriptRepo() repository.MachineScript {
|
||||
return machineScriptRepo
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/api"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/machine/api"
|
||||
"mayfly-go/internal/machine/application"
|
||||
projectapp "mayfly-go/internal/project/application"
|
||||
"mayfly-go/pkg/ctx"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -10,8 +11,8 @@ import (
|
||||
|
||||
func InitMachineRouter(router *gin.RouterGroup) {
|
||||
m := &api.Machine{
|
||||
MachineApp: application.MachineApp,
|
||||
ProjectApp: application.ProjectApp,
|
||||
MachineApp: application.GetMachineApp(),
|
||||
ProjectApp: projectapp.GetProjectApp(),
|
||||
}
|
||||
|
||||
machines := router.Group("machines")
|
||||
@@ -43,9 +44,11 @@ func InitMachineRouter(router *gin.RouterGroup) {
|
||||
})
|
||||
|
||||
saveMachine := ctx.NewLogInfo("保存机器信息").WithSave(true)
|
||||
saveMachineP := ctx.NewPermission("machine:update")
|
||||
machines.POST("", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).
|
||||
WithLog(saveMachine).
|
||||
WithRequiredPermission(saveMachineP).
|
||||
Handle(m.SaveMachine)
|
||||
})
|
||||
|
||||
@@ -69,5 +72,12 @@ func InitMachineRouter(router *gin.RouterGroup) {
|
||||
})
|
||||
|
||||
machines.GET(":machineId/terminal", m.WsSSH)
|
||||
|
||||
// 获取机器终端回放记录的相应文件夹名或文件名,目前具有保存机器信息的权限标识才有权限查看终端回放
|
||||
machines.GET("rec/names", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).
|
||||
WithRequiredPermission(saveMachineP).
|
||||
Handle(m.MachineRecDirNames)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/api"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/machine/api"
|
||||
"mayfly-go/internal/machine/application"
|
||||
sysApplication "mayfly-go/internal/sys/application"
|
||||
"mayfly-go/pkg/ctx"
|
||||
|
||||
@@ -13,9 +13,9 @@ func InitMachineFileRouter(router *gin.RouterGroup) {
|
||||
machineFile := router.Group("machines")
|
||||
{
|
||||
mf := &api.MachineFile{
|
||||
MachineFileApp: application.MachineFileApp,
|
||||
MachineApp: application.MachineApp,
|
||||
MsgApp: sysApplication.MsgApp,
|
||||
MachineFileApp: application.GetMachineFileApp(),
|
||||
MachineApp: application.GetMachineApp(),
|
||||
MsgApp: sysApplication.GetMsgApp(),
|
||||
}
|
||||
|
||||
// 获取指定机器文件列表
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user