mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-02 15:30:25 +08:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5271bd21e8 | ||
|
|
db554ebdc9 | ||
|
|
1c18a01bf6 | ||
|
|
729a3d7028 | ||
|
|
b88923a128 | ||
|
|
fe8cd93c78 | ||
|
|
64b49dae2e | ||
|
|
edbbbca5f9 | ||
|
|
5ad0d90038 | ||
|
|
9b9173dea7 | ||
|
|
f58331c1c1 | ||
|
|
b2dc9dff0b | ||
|
|
51d06ab206 | ||
|
|
799e0ac9fc |
18
.vscode/launch.json
vendored
18
.vscode/launch.json
vendored
@@ -1,18 +0,0 @@
|
||||
{
|
||||
// 使用 IntelliSense 了解相关属性。
|
||||
// 悬停以查看现有属性的描述。
|
||||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
|
||||
{
|
||||
"name": "mayfly-go",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"program": "${fileDirname}/main.go",
|
||||
"env": {},
|
||||
"args": []
|
||||
},
|
||||
]
|
||||
}
|
||||
51
README.md
51
README.md
@@ -1,7 +1,8 @@
|
||||
# mayfly-go
|
||||
# 🌈mayfly-go
|
||||
|
||||
### 介绍
|
||||
简单基于DDD(领域驱动设计)分层架构实现的web版 **linux、数据库(mysql postgres)、redis(单机 集群)、mongo统一管理操作平台**
|
||||
|
||||
#### 介绍
|
||||
简单基于DDD(领域驱动设计)分层架构实现web版mysql,redis,linux统一操作管理平台
|
||||
|
||||
### 开发语言与主要框架
|
||||
- 前端:typescript、vue3、element-plus
|
||||
@@ -11,23 +12,55 @@
|
||||
### 交流及问题反馈加 QQ 群
|
||||
<a target="_blank" href="https://qm.qq.com/cgi-bin/qm/qr?jump_from=webapi">119699946</a>
|
||||
|
||||
|
||||
### 系统相关资料
|
||||
- 项目文档: https://objs.gitee.io/mayfly-go-docs
|
||||
- 系统操作视频: https://space.bilibili.com/484091081/channel/collectiondetail?sid=392854
|
||||
- 安装包下载:https://gitee.com/objs/mayfly-go/releases
|
||||
|
||||
### 系统功能
|
||||
|
||||
记录操作记录
|
||||
### 系统核心功能截图
|
||||
|
||||
##### 记录操作记录
|
||||

|
||||
|
||||
#### 系统管理
|
||||
账号管理
|
||||
#### 机器操作
|
||||
##### 状态查看
|
||||

|
||||
|
||||
##### ssh终端
|
||||

|
||||
|
||||
##### 文件操作
|
||||

|
||||

|
||||
|
||||
|
||||
#### 数据库操作
|
||||
##### sql编辑器
|
||||

|
||||
|
||||
##### 在线增删改查数据
|
||||

|
||||
|
||||
|
||||
#### Redis操作
|
||||

|
||||
|
||||
|
||||
#### Mongo操作
|
||||

|
||||
|
||||
|
||||
##### 系统管理
|
||||
##### 账号管理
|
||||

|
||||
|
||||
角色管理
|
||||
##### 角色管理
|
||||

|
||||
|
||||
资源管理
|
||||
##### 资源管理
|
||||

|
||||
|
||||
|
||||
**其他更多功能&操作指南可查看在线文档**: https://objs.gitee.io/mayfly-go-docs
|
||||
@@ -1,34 +0,0 @@
|
||||
package biz
|
||||
|
||||
// 业务错误
|
||||
type BizError struct {
|
||||
code int16
|
||||
err string
|
||||
}
|
||||
|
||||
var (
|
||||
Success *BizError = NewBizErrCode(200, "success")
|
||||
BizErr *BizError = NewBizErrCode(400, "biz error")
|
||||
ServerError *BizError = NewBizErrCode(500, "server error")
|
||||
PermissionErr *BizError = NewBizErrCode(501, "token error")
|
||||
)
|
||||
|
||||
// 错误消息
|
||||
func (e *BizError) Error() string {
|
||||
return e.err
|
||||
}
|
||||
|
||||
// 错误码
|
||||
func (e *BizError) Code() int16 {
|
||||
return e.code
|
||||
}
|
||||
|
||||
// 创建业务逻辑错误结构体,默认为业务逻辑错误
|
||||
func NewBizErr(msg string) *BizError {
|
||||
return &BizError{code: BizErr.code, err: msg}
|
||||
}
|
||||
|
||||
// 创建业务逻辑错误结构体,可设置指定错误code
|
||||
func NewBizErrCode(code int16, msg string) *BizError {
|
||||
return &BizError{code: code, err: msg}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
// md5
|
||||
func Md5(str string) string {
|
||||
h := md5.New()
|
||||
h.Write([]byte(str))
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
136
build_release.sh
Executable file
136
build_release.sh
Executable file
@@ -0,0 +1,136 @@
|
||||
#bin/bash
|
||||
|
||||
#----------------------------------------------
|
||||
# 前后端打包编译至指定目录,即快速制作发行版
|
||||
#----------------------------------------------
|
||||
|
||||
project_path=`pwd`
|
||||
# 构建后的二进制执行文件名
|
||||
exec_file_name="mayfly-go"
|
||||
# web项目目录
|
||||
web_folder="${project_path}/mayfly_go_web"
|
||||
# server目录
|
||||
server_folder="${project_path}/server"
|
||||
|
||||
function echo_red() {
|
||||
echo -e "\033[1;31m$1\033[0m"
|
||||
}
|
||||
|
||||
function echo_green() {
|
||||
echo -e "\033[1;32m$1\033[0m"
|
||||
}
|
||||
|
||||
function echo_yellow() {
|
||||
echo -e "\033[1;33m$1\033[0m"
|
||||
}
|
||||
|
||||
function buildWeb() {
|
||||
cd ${web_folder}
|
||||
copy2Server=$1
|
||||
|
||||
echo_yellow "-------------------打包前端开始-------------------"
|
||||
yarn run build
|
||||
if [ "${copy2Server}" == "1" ] ; then
|
||||
echo_green '将打包后的静态文件拷贝至server/static'
|
||||
rm -rf ${server_folder}/static && mkdir -p ${server_folder}/static && cp -r ${web_folder}/dist/* ${server_folder}/static
|
||||
fi
|
||||
echo_yellow ">>>>>>>>>>>>>>>>>>>打包前端结束<<<<<<<<<<<<<<<<<<<<\n"
|
||||
}
|
||||
|
||||
function build() {
|
||||
cd ${project_path}
|
||||
|
||||
# 打包产物的输出目录
|
||||
toFolder=$1
|
||||
os=$2
|
||||
arch=$3
|
||||
|
||||
echo_yellow "-------------------${os}-${arch}打包构建开始-------------------"
|
||||
|
||||
cd ${server_folder}
|
||||
echo_green "打包构建可执行文件..."
|
||||
|
||||
execFileName=${exec_file_name}
|
||||
# 如果是windows系统,可执行文件需要添加.exe结尾
|
||||
if [ "${os}" == "windows" ];then
|
||||
execFileName="${execFileName}.exe"
|
||||
fi
|
||||
CGO_ENABLE=0 GOOS=${os} GOARCH=${arch} go build -o ${execFileName} main.go
|
||||
|
||||
if [ -d ${toFolder} ] ; then
|
||||
echo_green "目标文件夹已存在,清空文件夹"
|
||||
sudo rm -rf ${toFolder}
|
||||
fi
|
||||
echo_green "创建'${toFolder}'目录"
|
||||
mkdir ${toFolder}
|
||||
|
||||
echo_green "移动二进制文件至'${toFolder}'"
|
||||
mv ${server_folder}/${execFileName} ${toFolder}
|
||||
|
||||
echo_green "拷贝前端静态页面至'${toFolder}/static'"
|
||||
mkdir -p ${toFolder}/static && cp -r ${web_folder}/dist/* ${toFolder}/static
|
||||
|
||||
echo_green "拷贝脚本等资源文件[config.yml、mayfly-go.sql、readme.txt、startup.sh、shutdown.sh]"
|
||||
cp ${server_folder}/config.yml ${toFolder}
|
||||
cp ${server_folder}/mayfly-go.sql ${toFolder}
|
||||
cp ${server_folder}/readme.txt ${toFolder}
|
||||
cp ${server_folder}/startup.sh ${toFolder}
|
||||
cp ${server_folder}/shutdown.sh ${toFolder}
|
||||
|
||||
echo_yellow ">>>>>>>>>>>>>>>>>>>${os}-${arch}打包构建完成<<<<<<<<<<<<<<<<<<<<\n"
|
||||
}
|
||||
|
||||
function buildLinuxAmd64() {
|
||||
build "$1/mayfly-go-linux-amd64" "linux" "amd64"
|
||||
}
|
||||
|
||||
function buildLinuxArm64() {
|
||||
build "$1/mayfly-go-linux-arm64" "linux" "arm64"
|
||||
}
|
||||
|
||||
function buildWindows() {
|
||||
build "$1/mayfly-go-windows" "windows" "amd64"
|
||||
}
|
||||
|
||||
function runBuild() {
|
||||
# 构建结果的目的路径
|
||||
read -p "请输入构建产物输出目录: " toPath
|
||||
if [ ! -d ${toPath} ] ; then
|
||||
echo_red "构建产物输出目录不存在!"
|
||||
exit;
|
||||
fi
|
||||
# 进入目标路径,并赋值全路径
|
||||
cd ${toPath}
|
||||
toPath=`pwd`
|
||||
|
||||
read -p "是否构建前端[0|其他->否 1->是 2->构建并拷贝至server/static]: " runBuildWeb
|
||||
read -p "请选择构建版本[0|其他->全部 1->linux-amd64 2->linux-arm64 3->windows]: " buildType
|
||||
|
||||
if [ "${runBuildWeb}" == "1" ];then
|
||||
buildWeb
|
||||
fi
|
||||
if [ "${runBuildWeb}" == "2" ];then
|
||||
buildWeb 1
|
||||
fi
|
||||
|
||||
if [ "${buildType}" == "1" ];then
|
||||
buildLinuxAmd64 ${toPath}
|
||||
exit;
|
||||
fi
|
||||
|
||||
if [ "${buildType}" == "2" ];then
|
||||
buildLinuxArm64 ${toPath}
|
||||
exit;
|
||||
fi
|
||||
|
||||
if [ "${buildType}" == "3" ];then
|
||||
buildWindows ${toPath}
|
||||
exit;
|
||||
fi
|
||||
|
||||
buildLinuxAmd64 ${toPath}
|
||||
buildLinuxArm64 ${toPath}
|
||||
buildWindows ${toPath}
|
||||
}
|
||||
|
||||
runBuild
|
||||
220
go.sum
220
go.sum
@@ -1,220 +0,0 @@
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||
github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs=
|
||||
github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U=
|
||||
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
|
||||
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
|
||||
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
|
||||
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
|
||||
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
|
||||
github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
|
||||
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
|
||||
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
|
||||
github.com/go-playground/validator/v10 v10.10.1 h1:uA0+amWMiglNZKZ9FJRKUAe9U3RX91eVn1JYXMWt7ig=
|
||||
github.com/go-playground/validator/v10 v10.10.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
|
||||
github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg=
|
||||
github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
|
||||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
|
||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.1.4 h1:tHnRBy1i5F2Dh8BAFxqFzxKqqvezXrL2OW1TnX+Mlas=
|
||||
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8=
|
||||
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
||||
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
|
||||
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
|
||||
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/mojocn/base64Captcha v1.3.5 h1:Qeilr7Ta6eDtG4S+tQuZ5+hO+QHbiGAJdi4PfoagaA0=
|
||||
github.com/mojocn/base64Captcha v1.3.5/go.mod h1:/tTTXn4WTpX9CfrmipqRytCpJ27Uw3G6I7NcP2WwcmY=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
||||
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
|
||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
|
||||
github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
|
||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
|
||||
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
||||
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
|
||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||
github.com/pkg/sftp v1.13.4 h1:Lb0RYJCmgUcBgZosfoi9Y9sbl6+LJgOIgk/2Y4YjMFg=
|
||||
github.com/pkg/sftp v1.13.4/go.mod h1:LzqnAvaD5TWeNBsZpfKxSYn1MbjWwOsCIAFFJbpIsK8=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
|
||||
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
|
||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
|
||||
github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo=
|
||||
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
|
||||
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
||||
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
|
||||
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220314234724-5d542ad81a58 h1:L8CkJyVoa0/NslN3RUMLgasK5+KatNvyRGQ9QyCYAfc=
|
||||
golang.org/x/crypto v0.0.0-20220314234724-5d542ad81a58/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/image v0.0.0-20190501045829-6d32002ffd75/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/image v0.0.0-20220302094943-723b81ca9867 h1:TcHcE0vrmgzNH1v3ppjcMGbhG5+9fMuvOmUYwNEF4q4=
|
||||
golang.org/x/image v0.0.0-20220302094943-723b81ca9867/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng=
|
||||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gorm.io/driver/mysql v1.3.2 h1:QJryWiqQ91EvZ0jZL48NOpdlPdMjdip1hQ8bTgo4H7I=
|
||||
gorm.io/driver/mysql v1.3.2/go.mod h1:ChK6AHbHgDCFZyJp0F+BmVGb06PSIoh9uVYKAlRbb2U=
|
||||
gorm.io/gorm v1.23.1/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
|
||||
gorm.io/gorm v1.23.2 h1:xmq9QRMWL8HTJyhAUBXy8FqIIQCYESeKfJL4DoGKiWQ=
|
||||
gorm.io/gorm v1.23.2/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
|
||||
5116
mayfly_go_web/package-lock.json
generated
Normal file
5116
mayfly_go_web/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -7,25 +7,26 @@
|
||||
"lint-fix": "eslint --fix --ext .js --ext .jsx --ext .vue src/"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.26.1",
|
||||
"codemirror": "^5.65.2",
|
||||
"@element-plus/icons-vue": "^2.0.6",
|
||||
"axios": "^0.27.2",
|
||||
"codemirror": "^5.65.5",
|
||||
"countup.js": "^2.0.7",
|
||||
"cropperjs": "^1.5.11",
|
||||
"echarts": "^5.3.2",
|
||||
"element-plus": "^2.1.11",
|
||||
"@element-plus/icons-vue": "^1.1.3",
|
||||
"jsonlint": "^1.6.3",
|
||||
"echarts": "^5.3.3",
|
||||
"element-plus": "^2.2.9",
|
||||
"jsencrypt": "^3.2.1",
|
||||
"jsoneditor": "^9.9.0",
|
||||
"lodash": "^4.17.21",
|
||||
"mitt": "^3.0.0",
|
||||
"nprogress": "^0.2.0",
|
||||
"screenfull": "^5.1.0",
|
||||
"sortablejs": "^1.13.0",
|
||||
"sql-formatter": "^7.0.3",
|
||||
"vue": "^3.2.37",
|
||||
"vue-clipboard3": "^1.0.1",
|
||||
"sql-formatter": "^4.0.2",
|
||||
"vue": "^3.2.30",
|
||||
"vue-router": "^4.0.12",
|
||||
"vue-router": "^4.1.2",
|
||||
"vuex": "^4.0.2",
|
||||
"xterm": "^4.18.0",
|
||||
"xterm": "^4.19.0",
|
||||
"xterm-addon-fit": "^0.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -35,7 +36,7 @@
|
||||
"@types/sortablejs": "^1.10.6",
|
||||
"@typescript-eslint/eslint-plugin": "^4.23.0",
|
||||
"@typescript-eslint/parser": "^4.23.0",
|
||||
"@vitejs/plugin-vue": "^1.2.2",
|
||||
"@vitejs/plugin-vue": "^2.3.3",
|
||||
"@vue/compiler-sfc": "^3.0.11",
|
||||
"dotenv": "^10.0.0",
|
||||
"eslint": "^8.5.0",
|
||||
@@ -43,8 +44,8 @@
|
||||
"prettier": "^2.3.0",
|
||||
"sass": "^1.45.1",
|
||||
"sass-loader": "^12.4.0",
|
||||
"typescript": "^4.2.4",
|
||||
"vite": "^2.8.6",
|
||||
"typescript": "^4.7.4",
|
||||
"vite": "^2.9.13",
|
||||
"vue-eslint-parser": "^8.0.1"
|
||||
},
|
||||
"browserslist": [
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
window.globalConfig = {
|
||||
"BaseApiUrl": "http://localhost:8888",
|
||||
"BaseWsUrl": "ws://localhost:8888"
|
||||
// 默认为空,以访问根目录为api请求地址。若前后端分离部署可单独配置该后端api请求地址
|
||||
"BaseApiUrl": "",
|
||||
"BaseWsUrl": ""
|
||||
}
|
||||
3
mayfly_go_web/shim.d.ts
vendored
3
mayfly_go_web/shim.d.ts
vendored
@@ -5,4 +5,5 @@ declare module '*.vue' {
|
||||
export default component;
|
||||
}
|
||||
declare module 'codemirror';
|
||||
declare module 'sql-formatter';
|
||||
declare module 'sql-formatter';
|
||||
declare module 'jsoneditor';
|
||||
@@ -1,6 +1,6 @@
|
||||
const config = {
|
||||
baseApiUrl: `${(window as any).globalConfig.BaseApiUrl}/api`,
|
||||
baseWsUrl: `${(window as any).globalConfig.BaseWsUrl}/api`
|
||||
baseApiUrl: `${(window as any).globalConfig.BaseApiUrl}/api`,
|
||||
baseWsUrl: `${(window as any).globalConfig.BaseWsUrl || `${location.protocol == 'https:' ? 'wss:' : 'ws:'}//${location.host}`}/api`
|
||||
}
|
||||
|
||||
export default config
|
||||
@@ -2,6 +2,8 @@ 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)
|
||||
|
||||
37
mayfly_go_web/src/common/rsa.ts
Normal file
37
mayfly_go_web/src/common/rsa.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import openApi from './openApi';
|
||||
import JSEncrypt from 'jsencrypt'
|
||||
import { notBlank } from './assert';
|
||||
|
||||
var encryptor: any = null
|
||||
|
||||
export async function getRsaPublicKey() {
|
||||
let publicKey = sessionStorage.getItem('RsaPublicKey')
|
||||
if (publicKey) {
|
||||
return publicKey
|
||||
}
|
||||
publicKey = await openApi.getPublicKey() as string
|
||||
sessionStorage.setItem('RsaPublicKey', publicKey)
|
||||
return publicKey
|
||||
}
|
||||
|
||||
/**
|
||||
* 公钥加密指定值
|
||||
*
|
||||
* @param value value
|
||||
* @returns 加密后的值
|
||||
*/
|
||||
export async function RsaEncrypt(value: any) {
|
||||
// 不存在则返回空值
|
||||
if (!value) {
|
||||
return ""
|
||||
}
|
||||
if (encryptor != null) {
|
||||
return encryptor.encrypt(value)
|
||||
}
|
||||
console.log(value)
|
||||
encryptor = new JSEncrypt()
|
||||
const publicKey = await getRsaPublicKey() as string;
|
||||
notBlank(publicKey, "获取公钥失败")
|
||||
encryptor.setPublicKey(publicKey)//设置公钥
|
||||
return encryptor.encrypt(value)
|
||||
}
|
||||
133
mayfly_go_web/src/components/jsonedit/index.vue
Normal file
133
mayfly_go_web/src/components/jsonedit/index.vue
Normal file
@@ -0,0 +1,133 @@
|
||||
<template>
|
||||
<div>
|
||||
<div ref="jsoneditorVue" :style="{ height: height, width: width }"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { ref, toRefs, reactive, nextTick, watch, onMounted, onUnmounted, defineComponent } from 'vue';
|
||||
import JSONEditor from 'jsoneditor';
|
||||
import 'jsoneditor/dist/jsoneditor.min.css';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'JsonEdit',
|
||||
components: {},
|
||||
props: {
|
||||
modelValue: {
|
||||
type: [String, Object],
|
||||
},
|
||||
height: {
|
||||
type: String,
|
||||
default: '500px',
|
||||
},
|
||||
width: {
|
||||
type: String,
|
||||
default: 'auto',
|
||||
},
|
||||
options: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
currentMode: {
|
||||
type: String,
|
||||
default: 'tree',
|
||||
},
|
||||
modeList: {
|
||||
type: Array,
|
||||
default() {
|
||||
return ['tree', 'code', 'form', 'text', 'view'];
|
||||
},
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
let { modelValue, options, modeList, currentMode } = toRefs(props);
|
||||
|
||||
const jsoneditorVue = ref(null)
|
||||
// 编辑器实例
|
||||
let editor = null as any;
|
||||
// 值类型
|
||||
let valueType = 'string';
|
||||
// 是否内部改变(即onChange事件双向绑定),内部改变则不需要重新赋值给editor
|
||||
let internalChange = false;
|
||||
|
||||
const state = reactive({
|
||||
height: '500px',
|
||||
width: 'auto',
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
state.width = props.width;
|
||||
state.height = props.height;
|
||||
|
||||
init();
|
||||
setJson(modelValue.value);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
editor?.destroy();
|
||||
editor = null;
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(newValue) => {
|
||||
if (!editor) {
|
||||
init();
|
||||
}
|
||||
setJson(newValue);
|
||||
}
|
||||
);
|
||||
|
||||
const setJson = (value: any) => {
|
||||
if (internalChange) {
|
||||
return;
|
||||
}
|
||||
if (typeof value == 'string') {
|
||||
valueType = 'string';
|
||||
editor.set(JSON.parse(value));
|
||||
} else {
|
||||
valueType = 'object';
|
||||
editor.set(value);
|
||||
}
|
||||
};
|
||||
|
||||
const onChange = () => {
|
||||
try {
|
||||
const json = editor.get();
|
||||
if (valueType == 'string') {
|
||||
emit('update:modelValue', JSON.stringify(json));
|
||||
} else {
|
||||
emit('update:modelValue', json);
|
||||
}
|
||||
emit('onChange', json);
|
||||
internalChange = true;
|
||||
nextTick(() => {
|
||||
internalChange = false;
|
||||
});
|
||||
} catch (error) {}
|
||||
};
|
||||
|
||||
const init = () => {
|
||||
console.log('init json editor');
|
||||
const finalOptions = {
|
||||
...options.value,
|
||||
mode: currentMode.value,
|
||||
modes: modeList.value,
|
||||
onChange,
|
||||
};
|
||||
editor = new JSONEditor(jsoneditorVue.value, finalOptions);
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
jsoneditorVue,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
div.jsoneditor-menu a.jsoneditor-poweredBy {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
@@ -10,6 +10,7 @@ export const imports = {
|
||||
"ResourceList": () => import('@/views/system/resource'),
|
||||
"RoleList": () => import('@/views/system/role'),
|
||||
"AccountList": () => import('@/views/system/account'),
|
||||
"SyslogList": () => import('@/views/system/syslog/SyslogList.vue'),
|
||||
// project
|
||||
"ProjectList": () => import('@/views/ops/project/ProjectList.vue'),
|
||||
// db
|
||||
|
||||
@@ -239,16 +239,6 @@
|
||||
color: set-color(primary);
|
||||
}
|
||||
|
||||
/* Switch 开关
|
||||
------------------------------- */
|
||||
.el-switch.is-checked .el-switch__core {
|
||||
border-color: set-color(primary);
|
||||
background-color: set-color(primary);
|
||||
}
|
||||
.el-switch__label.is-active {
|
||||
color: set-color(primary);
|
||||
}
|
||||
|
||||
/* Slider 滑块
|
||||
------------------------------- */
|
||||
.el-slider__bar {
|
||||
@@ -993,4 +983,15 @@
|
||||
}
|
||||
.el-drawer-fade-leave-active .el-drawer.ltr {
|
||||
animation: ltr-drawer-animation 0.3s ease !important;
|
||||
}
|
||||
}
|
||||
|
||||
// el-tooltip使用自定义主题时的样式
|
||||
.el-popper.is-customized {
|
||||
/* Set padding to ensure the height is 32px */
|
||||
// padding: 6px 12px;
|
||||
background: linear-gradient(90deg, rgb(159, 229, 151), rgb(204, 229, 129));
|
||||
}
|
||||
.el-popper.is-customized .el-popper__arrow::before {
|
||||
background: linear-gradient(45deg, #b2e68d, #bce689);
|
||||
right: 0;
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import { useStore } from '@/store/index.ts';
|
||||
export default defineComponent({
|
||||
name: 'layoutBreadcrumbSearch',
|
||||
setup() {
|
||||
const layoutMenuAutocompleteRef = ref();
|
||||
const layoutMenuAutocompleteRef: any = ref(null);
|
||||
const store = useStore();
|
||||
const router = useRouter();
|
||||
const state: any = reactive({
|
||||
@@ -44,7 +44,9 @@ export default defineComponent({
|
||||
state.isShowSearch = true;
|
||||
initTageView();
|
||||
nextTick(() => {
|
||||
layoutMenuAutocompleteRef.value.focus();
|
||||
setTimeout(() => {
|
||||
layoutMenuAutocompleteRef.value.focus();
|
||||
});
|
||||
});
|
||||
};
|
||||
// 搜索弹窗关闭
|
||||
@@ -68,7 +70,6 @@ export default defineComponent({
|
||||
// 初始化菜单数据
|
||||
const initTageView = () => {
|
||||
if (state.tagsViewList.length > 0) return false;
|
||||
console.log(getRoutes(store.state.routesList.routesList));
|
||||
getRoutes(store.state.routesList.routesList).map((v: any) => {
|
||||
if (!v.meta.isHide) {
|
||||
state.tagsViewList.push({ ...v });
|
||||
|
||||
@@ -1,54 +1,75 @@
|
||||
<template>
|
||||
<el-form ref="loginFormRef" :model="loginForm" :rules="rules" class="login-content-form" size="large">
|
||||
<el-form-item prop="username">
|
||||
<el-input type="text" placeholder="请输入用户名" prefix-icon="user" v-model="loginForm.username" clearable autocomplete="off">
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password">
|
||||
<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-row :gutter="15">
|
||||
<el-col :span="16">
|
||||
<div>
|
||||
<el-form ref="loginFormRef" :model="loginForm" :rules="rules" class="login-content-form" size="large">
|
||||
<el-form-item prop="username">
|
||||
<el-input type="text" placeholder="请输入用户名" prefix-icon="user" v-model="loginForm.username" clearable autocomplete="off">
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password">
|
||||
<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-row :gutter="15">
|
||||
<el-col :span="16">
|
||||
<el-input
|
||||
type="text"
|
||||
maxlength="6"
|
||||
placeholder="请输入验证码"
|
||||
prefix-icon="position"
|
||||
v-model="loginForm.captcha"
|
||||
clearable
|
||||
autocomplete="off"
|
||||
@keyup.enter="login"
|
||||
></el-input>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<div class="login-content-code">
|
||||
<img
|
||||
class="login-content-code-img"
|
||||
@click="getCaptcha"
|
||||
width="130px"
|
||||
height="40px"
|
||||
:src="captchaImage"
|
||||
style="cursor: pointer"
|
||||
/>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" class="login-content-submit" round @click="login" :loading="loading.signIn">
|
||||
<span>登 录</span>
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-dialog title="修改密码" v-model="changePwdDialog.visible" :close-on-click-modal="false" width="450px" :destroy-on-close="true">
|
||||
<el-form :model="changePwdDialog.form" :rules="changePwdDialog.rules" ref="changePwdFormRef" label-width="65px">
|
||||
<el-form-item prop="username" label="用户名" required>
|
||||
<el-input v-model.trim="changePwdDialog.form.username" disabled></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="oldPassword" label="旧密码" required>
|
||||
<el-input v-model.trim="changePwdDialog.form.oldPassword" autocomplete="new-password" type="password"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="newPassword" label="新密码" required>
|
||||
<el-input
|
||||
type="text"
|
||||
maxlength="6"
|
||||
placeholder="请输入验证码"
|
||||
prefix-icon="position"
|
||||
v-model="loginForm.captcha"
|
||||
clearable
|
||||
autocomplete="off"
|
||||
@keyup.enter="login"
|
||||
v-model.trim="changePwdDialog.form.newPassword"
|
||||
placeholder="须为8位以上且包含字⺟⼤⼩写+数字+特殊符号"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
></el-input>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<div class="login-content-code">
|
||||
<img
|
||||
class="login-content-code-img"
|
||||
@click="getCaptcha"
|
||||
width="130px"
|
||||
height="40px"
|
||||
:src="captchaImage"
|
||||
style="cursor: pointer"
|
||||
/>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" class="login-content-submit" round @click="login" :loading="loading.signIn">
|
||||
<span>登 录</span>
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="cancelChangePwd">取 消</el-button>
|
||||
<el-button @click="changePwd" type="primary" :loading="loading.changePwd">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
@@ -60,7 +81,9 @@ import { useStore } from '@/store/index.ts';
|
||||
import { setSession } from '@/common/utils/storage.ts';
|
||||
import { formatAxis } from '@/common/utils/formatTime.ts';
|
||||
import openApi from '@/common/openApi';
|
||||
import { RsaEncrypt } from '@/common/rsa';
|
||||
import { letterAvatar } from '@/common/utils/string';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'AccountLogin',
|
||||
setup() {
|
||||
@@ -68,6 +91,8 @@ export default defineComponent({
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const loginFormRef: any = ref(null);
|
||||
const changePwdFormRef: any = ref(null);
|
||||
|
||||
const state = reactive({
|
||||
captchaImage: '',
|
||||
loginForm: {
|
||||
@@ -76,6 +101,24 @@ export default defineComponent({
|
||||
captcha: '',
|
||||
cid: '',
|
||||
},
|
||||
changePwdDialog: {
|
||||
visible: false,
|
||||
form: {
|
||||
username: '',
|
||||
oldPassword: '',
|
||||
newPassword: '',
|
||||
},
|
||||
rules: {
|
||||
newPassword: [
|
||||
{ required: true, message: '请输入新密码', trigger: 'blur' },
|
||||
{
|
||||
pattern: /^(?=.*[A-Za-z])(?=.*\d)(?=.*[`~!@#$%^&*()_+<>?:"{},.\/\\;'[\]])[A-Za-z\d`~!@#$%^&*()_+<>?:"{},.\/\\;'[\]]{8,}$/,
|
||||
message: '须为8位以上且包含字⺟⼤⼩写+数字+特殊符号',
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
@@ -83,6 +126,7 @@ export default defineComponent({
|
||||
},
|
||||
loading: {
|
||||
signIn: false,
|
||||
changePwd: false,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -116,15 +160,26 @@ export default defineComponent({
|
||||
const onSignIn = async () => {
|
||||
state.loading.signIn = true;
|
||||
let loginRes;
|
||||
const originPwd = state.loginForm.password;
|
||||
try {
|
||||
loginRes = await openApi.login(state.loginForm);
|
||||
// // 存储 token 到浏览器缓存
|
||||
const loginReq = { ...state.loginForm };
|
||||
loginReq.password = await RsaEncrypt(originPwd);
|
||||
loginRes = await openApi.login(loginReq);
|
||||
// 存储 token 到浏览器缓存
|
||||
setSession('token', loginRes.token);
|
||||
setSession('menus', loginRes.menus);
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
state.loading.signIn = false;
|
||||
state.loginForm.captcha = '';
|
||||
getCaptcha();
|
||||
// 密码强度不足
|
||||
if (e.code && e.code == 401) {
|
||||
state.changePwdDialog.form.username = state.loginForm.username;
|
||||
state.changePwdDialog.form.oldPassword = originPwd;
|
||||
state.changePwdDialog.form.newPassword = '';
|
||||
state.changePwdDialog.visible = true;
|
||||
} else {
|
||||
getCaptcha();
|
||||
}
|
||||
return;
|
||||
}
|
||||
// 用户信息
|
||||
@@ -174,11 +229,44 @@ export default defineComponent({
|
||||
}, 300);
|
||||
};
|
||||
|
||||
const changePwd = () => {
|
||||
changePwdFormRef.value.validate(async (valid: boolean) => {
|
||||
if (!valid) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
state.loading.changePwd = true;
|
||||
const form = state.changePwdDialog.form;
|
||||
const changePwdReq: any = { ...form };
|
||||
changePwdReq.oldPassword = await RsaEncrypt(form.oldPassword);
|
||||
changePwdReq.newPassword = await RsaEncrypt(form.newPassword);
|
||||
await openApi.changePwd(changePwdReq);
|
||||
ElMessage.success('密码修改成功, 新密码已填充至登录密码框');
|
||||
state.loginForm.password = state.changePwdDialog.form.newPassword;
|
||||
state.changePwdDialog.visible = false;
|
||||
getCaptcha();
|
||||
} finally {
|
||||
state.loading.changePwd = false;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const cancelChangePwd = () => {
|
||||
state.changePwdDialog.visible = false;
|
||||
state.changePwdDialog.form.newPassword = '';
|
||||
state.changePwdDialog.form.oldPassword = '';
|
||||
state.changePwdDialog.form.username = '';
|
||||
getCaptcha();
|
||||
};
|
||||
|
||||
return {
|
||||
getCaptcha,
|
||||
currentTime,
|
||||
loginFormRef,
|
||||
changePwdFormRef,
|
||||
login,
|
||||
changePwd,
|
||||
cancelChangePwd,
|
||||
...toRefs(state),
|
||||
};
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :close-on-click-modal="false" :destroy-on-close="true" width="35%">
|
||||
<el-form :model="form" ref="dbForm" :rules="rules" label-width="85px">
|
||||
<el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :close-on-click-modal="false" :destroy-on-close="true" width="38%">
|
||||
<el-form :model="form" ref="dbForm" :rules="rules" label-width="95px">
|
||||
<el-form-item prop="projectId" label="项目:" required>
|
||||
<el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
|
||||
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
@@ -19,13 +19,14 @@
|
||||
<el-form-item prop="type" label="类型:" required>
|
||||
<el-select style="width: 100%" v-model="form.type" placeholder="请选择数据库类型">
|
||||
<el-option key="item.id" label="mysql" value="mysql"> </el-option>
|
||||
<el-option key="item.id" label="postgres" value="postgres"> </el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item prop="host" label="host:" required>
|
||||
<el-input v-model.trim="form.host" placeholder="请输入主机ip" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="port" label="port:" required>
|
||||
<el-input type="number" v-model.trim="form.port" placeholder="请输入端口"></el-input>
|
||||
<el-input type="number" v-model.number="form.port" placeholder="请输入端口"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="username" label="用户名:" required>
|
||||
<el-input v-model.trim="form.username" placeholder="请输入用户名"></el-input>
|
||||
@@ -39,6 +40,9 @@
|
||||
autocomplete="new-password"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="params" label="连接参数:">
|
||||
<el-input v-model="form.params" placeholder="其他连接参数,形如: key1=value1&key2=value2"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="database" label="数据库名:" required>
|
||||
<el-tag
|
||||
v-for="db in databaseList"
|
||||
@@ -82,6 +86,7 @@ import { projectApi } from '../project/api.ts';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import type { ElInput } from 'element-plus';
|
||||
import { notBlank } from '@/common/assert';
|
||||
import { RsaEncrypt } from '@/common/rsa';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'DbEdit',
|
||||
@@ -116,6 +121,7 @@ export default defineComponent({
|
||||
port: 3306,
|
||||
username: null,
|
||||
password: null,
|
||||
params: null,
|
||||
database: '',
|
||||
project: null,
|
||||
projectId: null,
|
||||
@@ -173,13 +179,6 @@ export default defineComponent({
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
// password: [
|
||||
// {
|
||||
// required: true,
|
||||
// message: '请输入密码',
|
||||
// trigger: ['change', 'blur'],
|
||||
// },
|
||||
// ],
|
||||
database: [
|
||||
{
|
||||
required: true,
|
||||
@@ -261,10 +260,11 @@ export default defineComponent({
|
||||
if (!state.form.id) {
|
||||
notBlank(state.form.password, '新增操作,密码不可为空');
|
||||
}
|
||||
dbForm.value.validate((valid: boolean) => {
|
||||
dbForm.value.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
state.form.port = Number.parseInt(state.form.port as any);
|
||||
dbApi.saveDb.request(state.form).then(() => {
|
||||
const reqForm = { ...state.form };
|
||||
reqForm.password = await RsaEncrypt(reqForm.password);
|
||||
dbApi.saveDb.request(reqForm).then(() => {
|
||||
ElMessage.success('保存成功');
|
||||
emit('val-change', state.form);
|
||||
state.btnLoading = true;
|
||||
@@ -292,10 +292,7 @@ export default defineComponent({
|
||||
emit('cancel');
|
||||
setTimeout(() => {
|
||||
resetInputDb();
|
||||
dbForm.value.resetFields();
|
||||
// 重置对象属性为null
|
||||
state.form = {} as any;
|
||||
}, 200);
|
||||
}, 500);
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@@ -7,17 +7,10 @@
|
||||
>删除</el-button
|
||||
>
|
||||
<div style="float: right">
|
||||
<el-form class="search-form" label-position="right" :inline="true" label-width="60px">
|
||||
<el-form-item prop="project">
|
||||
<el-select 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-form-item>
|
||||
|
||||
<el-form-item>
|
||||
<el-button v-waves type="primary" icon="search" @click="search()">查询</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-select 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>
|
||||
</div>
|
||||
<el-table :data="datas" ref="table" @current-change="choose" show-overflow-tooltip stripe>
|
||||
<el-table-column label="选择" width="60px">
|
||||
@@ -27,15 +20,15 @@
|
||||
</el-radio>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="project" label="项目" min-width="100"></el-table-column>
|
||||
<el-table-column prop="project" label="项目" min-width="100" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="env" label="环境" min-width="100"></el-table-column>
|
||||
<el-table-column prop="name" label="名称" min-width="200"></el-table-column>
|
||||
<el-table-column min-width="160" label="host:port">
|
||||
<el-table-column prop="name" label="名称" min-width="160" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column min-width="170" label="host:port" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
{{ `${scope.row.host}:${scope.row.port}` }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="type" label="类型" min-width="80"></el-table-column>
|
||||
<el-table-column prop="type" label="类型" min-width="90"></el-table-column>
|
||||
<el-table-column prop="database" label="数据库" min-width="160">
|
||||
<template #default="scope">
|
||||
<el-tag
|
||||
@@ -59,8 +52,11 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<!-- <el-table-column fixed="right" label="更多信息" min-width="100">
|
||||
</el-table-column> -->
|
||||
<el-table-column label="操作" min-width="120" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-link type="primary" plain size="small" :underline="false" @click="onShowSqlExec(scope.row)">SQL执行记录</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-row style="margin-top: 20px" type="flex" justify="end">
|
||||
<el-pagination
|
||||
@@ -76,9 +72,35 @@
|
||||
|
||||
<el-dialog width="75%" :title="`${db} 表信息`" :before-close="closeTableInfo" v-model="tableInfoDialog.visible">
|
||||
<el-row class="mb10">
|
||||
<el-popover v-model:visible="showDumpInfo" :width="470" placement="right">
|
||||
<template #reference>
|
||||
<el-button class="ml5" type="success" size="small" @click="showDumpInfo = !showDumpInfo">导出</el-button>
|
||||
</template>
|
||||
<el-form-item label="导出内容: ">
|
||||
<el-radio-group v-model="dumpInfo.type">
|
||||
<el-radio :label="1" size="small">结构</el-radio>
|
||||
<el-radio :label="2" size="small">数据</el-radio>
|
||||
<el-radio :label="3" size="small">结构+数据</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="导出表: ">
|
||||
<el-table @selection-change="handleDumpTableSelectionChange" max-height="300" size="small" :data="tableInfoDialog.infos">
|
||||
<el-table-column type="selection" width="45" />
|
||||
<el-table-column property="tableName" label="表名" min-width="150" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column property="tableComment" label="备注" min-width="150" show-overflow-tooltip></el-table-column>
|
||||
</el-table>
|
||||
</el-form-item>
|
||||
|
||||
<div style="text-align: right">
|
||||
<el-button @click="showDumpInfo = false" size="small">取消</el-button>
|
||||
<el-button @click="dump(db)" type="success" size="small">确定</el-button>
|
||||
</div>
|
||||
</el-popover>
|
||||
|
||||
<el-button type="primary" size="small" @click="tableCreateDialog.visible = true">创建表</el-button>
|
||||
</el-row>
|
||||
<el-table border stripe :data="tableInfoDialog.infos" size="small">
|
||||
<el-table v-loading="tableInfoDialog.loading" border stripe :data="tableInfoDialog.infos" size="small">
|
||||
<el-table-column property="tableName" label="表名" min-width="150" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column property="tableComment" label="备注" min-width="150" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column
|
||||
@@ -124,6 +146,69 @@
|
||||
</el-table>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
width="90%"
|
||||
:title="`${sqlExecLogDialog.title} - SQL执行记录`"
|
||||
:before-close="onBeforeCloseSqlExecDialog"
|
||||
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.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>
|
||||
<el-button class="ml5" @click="searchSqlExecLog" type="success" icon="search"></el-button>
|
||||
</div>
|
||||
<el-table border stripe :data="sqlExecLogDialog.data" size="small">
|
||||
<el-table-column prop="db" label="数据库" min-width="60" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column prop="table" label="表" min-width="60" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column prop="type" label="类型" width="85" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
<el-tag v-if="scope.row.type == enums.DbSqlExecTypeEnum.UPDATE.value" color="#E4F5EB" size="small">UPDATE</el-tag>
|
||||
<el-tag v-if="scope.row.type == enums.DbSqlExecTypeEnum.DELETE.value" color="#F9E2AE" size="small">DELETE</el-tag>
|
||||
<el-tag v-if="scope.row.type == enums.DbSqlExecTypeEnum.INSERT.value" color="#A8DEE0" size="small">INSERT</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="sql" label="SQL" min-width="230" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column prop="oldValue" label="原值" min-width="150" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column prop="creator" label="执行人" min-width="60" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column prop="createTime" label="执行时间" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="remark" label="备注" min-width="60" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column label="操作" min-width="50" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-link
|
||||
v-if="scope.row.type == enums.DbSqlExecTypeEnum.UPDATE.value || scope.row.type == enums.DbSqlExecTypeEnum.DELETE.value"
|
||||
type="primary"
|
||||
plain
|
||||
size="small"
|
||||
:underline="false"
|
||||
@click="onShowRollbackSql(scope.row)"
|
||||
>还原SQL</el-link
|
||||
>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-row style="margin-top: 20px" type="flex" justify="end">
|
||||
<el-pagination
|
||||
style="text-align: right"
|
||||
@current-change="handleSqlExecPageChange"
|
||||
:total="sqlExecLogDialog.total"
|
||||
layout="prev, pager, next, total, jumper"
|
||||
v-model:current-page="sqlExecLogDialog.query.pageNum"
|
||||
:page-size="sqlExecLogDialog.query.pageSize"
|
||||
></el-pagination>
|
||||
</el-row>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog width="55%" :title="`还原SQL`" v-model="rollbackSqlDialog.visible">
|
||||
<el-input type="textarea" :autosize="{ minRows: 15, maxRows: 30 }" v-model="rollbackSqlDialog.sql" size="small"> </el-input>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog width="40%" :title="`${chooseTableName} 字段信息`" v-model="columnDialog.visible">
|
||||
<el-table border stripe :data="columnDialog.columns" size="small">
|
||||
<el-table-column prop="columnName" label="名称" show-overflow-tooltip> </el-table-column>
|
||||
@@ -139,6 +224,7 @@
|
||||
<el-table-column prop="columnName" label="列名" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column prop="seqInIndex" label="列序列号" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column prop="indexType" label="类型"> </el-table-column>
|
||||
<el-table-column prop="indexComment" label="备注" min-width="230" show-overflow-tooltip> </el-table-column>
|
||||
</el-table>
|
||||
</el-dialog>
|
||||
|
||||
@@ -164,8 +250,13 @@ import { formatByteSize } from '@/common/utils/format';
|
||||
import DbEdit from './DbEdit.vue';
|
||||
import CreateTable from './CreateTable.vue';
|
||||
import { dbApi } from './api';
|
||||
import enums from './enums';
|
||||
import { projectApi } from '../project/api.ts';
|
||||
import SqlExecBox from './component/SqlExecBox.ts';
|
||||
import config from '@/common/config';
|
||||
import { getSession } from '@/common/utils/storage';
|
||||
import { isTrue } from '@/common/assert';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'DbList',
|
||||
components: {
|
||||
@@ -195,9 +286,35 @@ export default defineComponent({
|
||||
},
|
||||
datas: [],
|
||||
total: 0,
|
||||
|
||||
showDumpInfo: false,
|
||||
dumpInfo: {
|
||||
id: 0,
|
||||
db: '',
|
||||
type: 3,
|
||||
tables: [],
|
||||
},
|
||||
// sql执行记录弹框
|
||||
sqlExecLogDialog: {
|
||||
title: '',
|
||||
visible: false,
|
||||
data: [],
|
||||
total: 0,
|
||||
query: {
|
||||
dbId: 0,
|
||||
db: '',
|
||||
table: '',
|
||||
type: null,
|
||||
pageNum: 1,
|
||||
pageSize: 12,
|
||||
},
|
||||
},
|
||||
rollbackSqlDialog: {
|
||||
visible: false,
|
||||
sql: '',
|
||||
},
|
||||
chooseTableName: '',
|
||||
tableInfoDialog: {
|
||||
loading: false,
|
||||
visible: false,
|
||||
infos: [],
|
||||
},
|
||||
@@ -225,7 +342,7 @@ export default defineComponent({
|
||||
|
||||
onMounted(async () => {
|
||||
search();
|
||||
state.projects = (await projectApi.projects.request({ pageNum: 1, pageSize: 100 })).list;
|
||||
state.projects = await projectApi.accountProjects.request(null);
|
||||
});
|
||||
|
||||
const choose = (item: any) => {
|
||||
@@ -284,14 +401,114 @@ export default defineComponent({
|
||||
} catch (err) {}
|
||||
};
|
||||
|
||||
const onShowSqlExec = async (row: any) => {
|
||||
state.sqlExecLogDialog.title = `${row.name}[${row.host}:${row.port}]`;
|
||||
state.sqlExecLogDialog.query.dbId = row.id;
|
||||
searchSqlExecLog();
|
||||
state.sqlExecLogDialog.visible = true;
|
||||
};
|
||||
|
||||
const onBeforeCloseSqlExecDialog = () => {
|
||||
state.sqlExecLogDialog.visible = false;
|
||||
state.sqlExecLogDialog.data = [];
|
||||
state.sqlExecLogDialog.total = 0;
|
||||
state.sqlExecLogDialog.query.dbId = 0;
|
||||
state.sqlExecLogDialog.query.pageNum = 1;
|
||||
state.sqlExecLogDialog.query.table = '';
|
||||
state.sqlExecLogDialog.query.db = '';
|
||||
state.sqlExecLogDialog.query.type = null;
|
||||
};
|
||||
|
||||
const searchSqlExecLog = async () => {
|
||||
const res = await dbApi.getSqlExecs.request(state.sqlExecLogDialog.query);
|
||||
state.sqlExecLogDialog.data = res.list;
|
||||
state.sqlExecLogDialog.total = res.total;
|
||||
};
|
||||
|
||||
const handleSqlExecPageChange = (curPage: number) => {
|
||||
state.sqlExecLogDialog.query.pageNum = curPage;
|
||||
searchSqlExecLog();
|
||||
};
|
||||
|
||||
/**
|
||||
* 选择导出数据库表
|
||||
*/
|
||||
const handleDumpTableSelectionChange = (vals: any) => {
|
||||
state.dumpInfo.tables = vals.map((x: any) => x.tableName);
|
||||
};
|
||||
|
||||
/**
|
||||
* 数据库信息导出
|
||||
*/
|
||||
const dump = (db: string) => {
|
||||
isTrue(state.dumpInfo.tables.length > 0, '请选择要导出的表');
|
||||
const a = document.createElement('a');
|
||||
a.setAttribute(
|
||||
'href',
|
||||
`${config.baseApiUrl}/dbs/${state.dbId}/dump?db=${db}&type=${state.dumpInfo.type}&tables=${state.dumpInfo.tables.join(
|
||||
','
|
||||
)}&token=${getSession('token')}`
|
||||
);
|
||||
a.click();
|
||||
state.showDumpInfo = false;
|
||||
};
|
||||
|
||||
const onShowRollbackSql = async (sqlExecLog: any) => {
|
||||
const columns = await dbApi.columnMetadata.request({ id: sqlExecLog.dbId, db: sqlExecLog.db, tableName: sqlExecLog.table });
|
||||
const primaryKey = columns[0].columnName;
|
||||
const oldValue = JSON.parse(sqlExecLog.oldValue);
|
||||
|
||||
const rollbackSqls = [];
|
||||
if (sqlExecLog.type == enums.DbSqlExecTypeEnum['UPDATE'].value) {
|
||||
for (let ov of oldValue) {
|
||||
const setItems = [];
|
||||
for (let key in ov) {
|
||||
if (key == primaryKey) {
|
||||
continue;
|
||||
}
|
||||
setItems.push(`${key} = ${wrapValue(ov[key])}`);
|
||||
}
|
||||
rollbackSqls.push(`UPDATE ${sqlExecLog.table} SET ${setItems.join(', ')} WHERE ${primaryKey} = ${wrapValue(ov[primaryKey])};`);
|
||||
}
|
||||
} else if (sqlExecLog.type == enums.DbSqlExecTypeEnum['DELETE'].value) {
|
||||
const columnNames = columns.map((c: any) => c.columnName);
|
||||
for (let ov of oldValue) {
|
||||
const values = [];
|
||||
for (let column of columnNames) {
|
||||
values.push(wrapValue(ov[column]));
|
||||
}
|
||||
rollbackSqls.push(`INSERT INTO ${sqlExecLog.table} (${columnNames.join(', ')}) VALUES (${values.join(', ')});`);
|
||||
}
|
||||
}
|
||||
|
||||
state.rollbackSqlDialog.sql = rollbackSqls.join('\n');
|
||||
state.rollbackSqlDialog.visible = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 包装值,如果值类型为number则直接返回,其他则需要使用''包装
|
||||
*/
|
||||
const wrapValue = (val: any) => {
|
||||
if (typeof val == 'number') {
|
||||
return val;
|
||||
}
|
||||
return `'${val}'`;
|
||||
};
|
||||
|
||||
const showTableInfo = async (row: any, db: string) => {
|
||||
state.tableInfoDialog.infos = await dbApi.tableInfos.request({ id: row.id, db });
|
||||
state.dbId = row.id;
|
||||
state.db = db;
|
||||
state.tableInfoDialog.loading = true;
|
||||
state.tableInfoDialog.visible = true;
|
||||
try {
|
||||
state.tableInfoDialog.infos = await dbApi.tableInfos.request({ id: row.id, db });
|
||||
state.dbId = row.id;
|
||||
state.db = db;
|
||||
} finally {
|
||||
state.tableInfoDialog.loading = false;
|
||||
}
|
||||
};
|
||||
|
||||
const closeTableInfo = () => {
|
||||
state.showDumpInfo = false;
|
||||
state.tableInfoDialog.visible = false;
|
||||
state.tableInfoDialog.infos = [];
|
||||
};
|
||||
@@ -353,13 +570,20 @@ export default defineComponent({
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
// enums,
|
||||
enums,
|
||||
search,
|
||||
choose,
|
||||
handlePageChange,
|
||||
editDb,
|
||||
valChange,
|
||||
deleteDb,
|
||||
onShowSqlExec,
|
||||
handleDumpTableSelectionChange,
|
||||
dump,
|
||||
onBeforeCloseSqlExecDialog,
|
||||
handleSqlExecPageChange,
|
||||
searchSqlExecLog,
|
||||
onShowRollbackSql,
|
||||
showTableInfo,
|
||||
closeTableInfo,
|
||||
showColumns,
|
||||
|
||||
@@ -10,13 +10,7 @@
|
||||
<project-env-select @changeProjectEnv="changeProjectEnv">
|
||||
<template #default>
|
||||
<el-form-item label="资源">
|
||||
<el-select
|
||||
v-model="dbId"
|
||||
placeholder="请选择资源实例"
|
||||
@change="changeDbInstance"
|
||||
filterable
|
||||
style="width: 150px"
|
||||
>
|
||||
<el-select v-model="dbId" placeholder="请选择资源实例" @change="changeDbInstance" filterable style="width: 150px">
|
||||
<el-option v-for="item in dbs" :key="item.id" :label="item.name" :value="item.id">
|
||||
<span style="float: left">{{ item.name }}</span>
|
||||
<span style="float: right; color: #8492a6; margin-left: 6px; font-size: 13px">{{
|
||||
@@ -27,7 +21,15 @@
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="数据库">
|
||||
<el-select v-model="db" placeholder="请选择数据库" @change="changeDb" @clear="clearDb" clearable filterable style="width: 150px">
|
||||
<el-select
|
||||
v-model="db"
|
||||
placeholder="请选择数据库"
|
||||
@change="changeDb"
|
||||
@clear="clearDb"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 150px"
|
||||
>
|
||||
<el-option v-for="item in databaseList" :key="item" :label="item" :value="item"> </el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
@@ -188,7 +190,7 @@
|
||||
@cell-dblclick="cellClick"
|
||||
@sort-change="onTableSortChange"
|
||||
@selection-change="onDataSelectionChange"
|
||||
:data="dt.execRes.data"
|
||||
:data="dt.datas"
|
||||
size="small"
|
||||
:max-height="dataTabsTableHeight"
|
||||
v-loading="dt.loading"
|
||||
@@ -198,12 +200,12 @@
|
||||
border
|
||||
class="mt5"
|
||||
>
|
||||
<el-table-column v-if="dt.execRes.tableColumn.length > 0" type="selection" width="35" />
|
||||
<el-table-column v-if="dt.datas.length > 0" type="selection" width="35" />
|
||||
<el-table-column
|
||||
min-width="100"
|
||||
:width="flexColumnWidth(item, dt.execRes.data)"
|
||||
:width="flexColumnWidth(item, dt.datas)"
|
||||
align="center"
|
||||
v-for="item in dt.execRes.tableColumn"
|
||||
v-for="item in dt.columnNames"
|
||||
:key="item"
|
||||
:prop="item"
|
||||
:label="item"
|
||||
@@ -211,14 +213,23 @@
|
||||
:sortable="nowTableName != '' ? 'custom' : false"
|
||||
>
|
||||
<template #header>
|
||||
<el-tooltip raw-content effect="dark" placement="top">
|
||||
<el-tooltip raw-content placement="top" effect="customized">
|
||||
<template #content> {{ getColumnTip(dt.name, item) }} </template>
|
||||
<el-icon><question-filled /></el-icon>
|
||||
{{ item }}
|
||||
</el-tooltip>
|
||||
{{ item }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-row type="flex" class="mt5" justify="center">
|
||||
<el-pagination
|
||||
small
|
||||
:total="dt.count"
|
||||
@current-change="handlePageChange(dt)"
|
||||
layout="prev, pager, next, total, jumper"
|
||||
v-model:current-page="dt.pageNum"
|
||||
:page-size="defalutLimit"
|
||||
></el-pagination>
|
||||
</el-row>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-container>
|
||||
@@ -237,7 +248,6 @@ import 'codemirror/theme/base16-light.css';
|
||||
|
||||
import 'codemirror/addon/selection/active-line';
|
||||
import _CodeMirror from 'codemirror';
|
||||
// import 'codemirror/mode/sql/sql.js';
|
||||
import 'codemirror/addon/hint/show-hint.js';
|
||||
import 'codemirror/addon/hint/sql-hint.js';
|
||||
|
||||
@@ -262,15 +272,15 @@ export default defineComponent({
|
||||
|
||||
const state = reactive({
|
||||
token: token,
|
||||
defalutLimit: 25, // 默认查询数量
|
||||
defalutLimit: 20, // 默认查询数量
|
||||
dbs: [], // 数据库实例列表
|
||||
databaseList: [], // 数据库实例拥有的数据库列表,1数据库实例 -> 多数据库
|
||||
db: '', // 当前操作的数据库
|
||||
dbType: '',
|
||||
tables: [],
|
||||
dbId: null, // 当前选中操作的数据库实例
|
||||
tableName: '',
|
||||
tableMetadata: [],
|
||||
columnMetadata: [],
|
||||
sqlName: '', // 当前sql模板名
|
||||
sqlNames: [], // 所有sql模板名
|
||||
activeName: 'Query',
|
||||
@@ -355,7 +365,7 @@ export default defineComponent({
|
||||
const setHeight = () => {
|
||||
// 默认300px
|
||||
codemirror.setSize('auto', `${window.innerHeight - 538}px`);
|
||||
state.dataTabsTableHeight = window.innerHeight - 258;
|
||||
state.dataTabsTableHeight = window.innerHeight - 258 - 33;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -388,7 +398,44 @@ export default defineComponent({
|
||||
let sql = getSql();
|
||||
isTrue(sql && sql.trim(), '请选中需要执行的sql');
|
||||
|
||||
state.queryTab.loading = true;
|
||||
// 去除字符串前的空格、换行等
|
||||
sql = sql.replace(/(^\s*)/g, '');
|
||||
let execRemark = '';
|
||||
let canRun = true;
|
||||
if (
|
||||
sql.startsWith('update') ||
|
||||
sql.startsWith('UPDATE') ||
|
||||
sql.startsWith('INSERT') ||
|
||||
sql.startsWith('insert') ||
|
||||
sql.startsWith('DELETE') ||
|
||||
sql.startsWith('delete')
|
||||
) {
|
||||
const res: any = await ElMessageBox.prompt('请输入备注', 'Tip', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
|
||||
inputErrorMessage: '请输入执行该sql的备注信息',
|
||||
});
|
||||
execRemark = res.value;
|
||||
if (!execRemark) {
|
||||
canRun = false;
|
||||
}
|
||||
}
|
||||
if (!canRun) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
state.queryTab.loading = true;
|
||||
const colAndData: any = await runSql(sql, execRemark);
|
||||
state.queryTab.execRes.data = colAndData.res;
|
||||
state.queryTab.execRes.tableColumn = colAndData.colNames;
|
||||
state.queryTab.loading = false;
|
||||
} catch (e: any) {
|
||||
state.queryTab.loading = false;
|
||||
}
|
||||
closeExecBtns();
|
||||
|
||||
// 即只有以该字符串开头的sql才可修改表数据内容
|
||||
if (sql.startsWith('SELECT *') || sql.startsWith('select *') || sql.startsWith('SELECT\n *')) {
|
||||
state.queryTab.selectionDatas = [];
|
||||
@@ -405,16 +452,6 @@ export default defineComponent({
|
||||
state.queryTab.nowTableName = '';
|
||||
state.nowTableName = '';
|
||||
}
|
||||
|
||||
try {
|
||||
const colAndData: any = await runSql(sql);
|
||||
state.queryTab.execRes.data = colAndData.res;
|
||||
state.queryTab.execRes.tableColumn = colAndData.colNames;
|
||||
state.queryTab.loading = false;
|
||||
} catch (e: any) {
|
||||
state.queryTab.loading = false;
|
||||
}
|
||||
closeExecBtns();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -422,11 +459,12 @@ export default defineComponent({
|
||||
*
|
||||
* @param sql 执行的sql
|
||||
*/
|
||||
const runSql = (sql: string) => {
|
||||
return dbApi.sqlExec.request({
|
||||
const runSql = async (sql: string, remark: string = '') => {
|
||||
return await dbApi.sqlExec.request({
|
||||
id: state.dbId,
|
||||
db: state.db,
|
||||
sql: sql.trim(),
|
||||
remark,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -477,7 +515,7 @@ export default defineComponent({
|
||||
|
||||
// 获取sql文件上传执行url
|
||||
const getUploadSqlFileUrl = () => {
|
||||
return `${config.baseApiUrl}/dbs/${state.dbId}/exec-sql-file`;
|
||||
return `${config.baseApiUrl}/dbs/${state.dbId}/exec-sql-file?db=${state.db}`;
|
||||
};
|
||||
|
||||
const flexColumnWidth = (str: any, tableData: any, flag = 'equal') => {
|
||||
@@ -495,8 +533,9 @@ export default defineComponent({
|
||||
if (flag === 'equal') {
|
||||
// 获取该列中第一个不为空的数据(内容)
|
||||
for (let i = 0; i < tableData.length; i++) {
|
||||
if (tableData[i][str].length > 0) {
|
||||
columnContent = tableData[i][str];
|
||||
// 转为字符串后比较
|
||||
if ((tableData[i][str] + '').length > 0) {
|
||||
columnContent = tableData[i][str] + '';
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -513,31 +552,47 @@ export default defineComponent({
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
columnContent = tableData[index][str];
|
||||
columnContent = tableData[index][str] + '';
|
||||
}
|
||||
const contentWidth: number = getContentWidth(columnContent);
|
||||
// 获取列名称的长度 加上排序图标长度
|
||||
const columnWidth: number = getContentWidth(str) + 43;
|
||||
const flexWidth: number = contentWidth > columnWidth ? contentWidth : columnWidth;
|
||||
return flexWidth + 'px';
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取内容所需要占用的宽度
|
||||
*/
|
||||
const getContentWidth = (content: any): number => {
|
||||
// 以下分配的单位长度可根据实际需求进行调整
|
||||
let flexWidth = 0;
|
||||
for (const char of columnContent) {
|
||||
if ((char >= 'A' && char <= 'Z') || (char >= 'a' && char <= 'z')) {
|
||||
// 如果是英文字符,为字符分配8个单位宽度
|
||||
flexWidth += 8;
|
||||
} else if (char >= '\u4e00' && char <= '\u9fa5') {
|
||||
// 如果是中文字符,为字符分配15个单位宽度
|
||||
for (const char of content) {
|
||||
if (flexWidth > 500) {
|
||||
break;
|
||||
}
|
||||
if ((char >= '0' && char <= '9') || (char >= 'a' && char <= 'z')) {
|
||||
// 如果是小写字母、数字字符,分配8个单位宽度
|
||||
flexWidth += 8.5;
|
||||
continue;
|
||||
}
|
||||
if (char >= 'A' && char <= 'Z') {
|
||||
flexWidth += 9;
|
||||
continue;
|
||||
}
|
||||
if (char >= '\u4e00' && char <= '\u9fa5') {
|
||||
// 如果是中文字符,为字符分配16个单位宽度
|
||||
flexWidth += 16;
|
||||
} else {
|
||||
// 其他种类字符,为字符分配10个单位宽度
|
||||
flexWidth += 10;
|
||||
// 其他种类字符,为字符分配9个单位宽度
|
||||
flexWidth += 8;
|
||||
}
|
||||
}
|
||||
if (flexWidth < 80) {
|
||||
// 设置最小宽度
|
||||
flexWidth = 80;
|
||||
}
|
||||
if (flexWidth > 500) {
|
||||
// 设置最大宽度
|
||||
flexWidth = 500;
|
||||
}
|
||||
return flexWidth + 'px';
|
||||
return flexWidth;
|
||||
};
|
||||
|
||||
const getColumnTip = (tableName: string, columnName: string) => {
|
||||
@@ -568,7 +623,9 @@ export default defineComponent({
|
||||
*/
|
||||
const changeDbInstance = (dbId: any) => {
|
||||
state.db = '';
|
||||
state.databaseList = (state.dbs.find((e: any) => e.id == dbId) as any).database.split(' ');
|
||||
const dbInfo = state.dbs.find((e: any) => e.id == dbId) as any;
|
||||
state.dbType = dbInfo.type;
|
||||
state.databaseList = dbInfo.database.split(' ');
|
||||
clearDb();
|
||||
};
|
||||
|
||||
@@ -600,8 +657,6 @@ export default defineComponent({
|
||||
if (tableName == '') {
|
||||
return;
|
||||
}
|
||||
state.columnMetadata = (await getColumns(tableName)) as any;
|
||||
|
||||
if (!execSelectSql) {
|
||||
return;
|
||||
}
|
||||
@@ -618,40 +673,17 @@ export default defineComponent({
|
||||
tab = {
|
||||
label: tableName,
|
||||
name: tableName,
|
||||
execRes: {
|
||||
tableColumn: [],
|
||||
data: [],
|
||||
},
|
||||
querySql: getDefaultSelectSql(tableName),
|
||||
datas: [],
|
||||
columnNames: [],
|
||||
pageNum: 1,
|
||||
count: 0,
|
||||
};
|
||||
tab.columnNames = await getColumnNames(tableName);
|
||||
state.dataTabs[tableName] = tab;
|
||||
|
||||
state.dataTabs[tableName].execRes.tableColumn = [];
|
||||
state.dataTabs[tableName].execRes.data = [];
|
||||
|
||||
onRefresh(tableName);
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取默认查询语句
|
||||
*/
|
||||
const getDefaultSelectSql = (tableName: string, where: string = '', orderBy: string = '') => {
|
||||
return `SELECT * FROM \`${tableName}\` ${where ? 'WHERE ' + where : ''} ${orderBy ? orderBy : ''} LIMIT ${state.defalutLimit}`;
|
||||
};
|
||||
|
||||
const selectByCondition = async (tableName: string, condition: string) => {
|
||||
notEmpty(condition, '条件不能为空');
|
||||
state.dataTabs[tableName].loading = true;
|
||||
try {
|
||||
const colAndData: any = await runSql(getDefaultSelectSql(tableName, condition));
|
||||
state.dataTabs[tableName].execRes.tableColumn = colAndData.colNames;
|
||||
state.dataTabs[tableName].execRes.data = colAndData.res;
|
||||
state.dataTabs[tableName].loading = false;
|
||||
} catch (err) {
|
||||
state.dataTabs[tableName].loading = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取表的所有列信息
|
||||
*/
|
||||
@@ -675,6 +707,11 @@ export default defineComponent({
|
||||
return tableMap.get(tableName);
|
||||
};
|
||||
|
||||
const getColumnNames = async (tableName: string) => {
|
||||
const columns = await getColumns(tableName);
|
||||
return columns.map((t: any) => t.columnName);
|
||||
};
|
||||
|
||||
/**
|
||||
* 条件查询,点击列信息后显示输入对应的值
|
||||
*/
|
||||
@@ -700,13 +737,75 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const onRefresh = async (tableName: string) => {
|
||||
const dataTab = state.dataTabs[tableName];
|
||||
// 查询条件置空
|
||||
state.dataTabs[tableName].condition = '';
|
||||
state.dataTabs[tableName].loading = true;
|
||||
const colAndData: any = await runSql(state.dataTabs[tableName].querySql);
|
||||
state.dataTabs[tableName].execRes.tableColumn = colAndData.colNames;
|
||||
state.dataTabs[tableName].execRes.data = colAndData.res;
|
||||
state.dataTabs[tableName].loading = false;
|
||||
dataTab.condition = '';
|
||||
dataTab.pageNum = 1;
|
||||
setDataTabDatas(dataTab);
|
||||
};
|
||||
|
||||
/**
|
||||
* 数据tab修改页数
|
||||
*/
|
||||
const handlePageChange = async (dataTab: any) => {
|
||||
setDataTabDatas(dataTab);
|
||||
};
|
||||
|
||||
/**
|
||||
* 根据条件查询数据
|
||||
*/
|
||||
const selectByCondition = async (tableName: string, condition: string) => {
|
||||
notEmpty(condition, '条件不能为空');
|
||||
const dataTab = state.dataTabs[tableName];
|
||||
dataTab.pageNum = 1;
|
||||
setDataTabDatas(dataTab);
|
||||
};
|
||||
|
||||
/**
|
||||
* 设置data tab的表数据
|
||||
*/
|
||||
const setDataTabDatas = async (dataTab: any) => {
|
||||
dataTab.loading = true;
|
||||
try {
|
||||
dataTab.count = await getTableCount(dataTab.name, dataTab.condition);
|
||||
if (dataTab.count > 0) {
|
||||
const colAndData: any = await runSql(getDefaultSelectSql(dataTab.name, dataTab.condition, dataTab.orderBy, dataTab.pageNum));
|
||||
dataTab.datas = colAndData.res;
|
||||
} else {
|
||||
dataTab.datas = [];
|
||||
}
|
||||
} finally {
|
||||
dataTab.loading = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取表的统计数量
|
||||
*/
|
||||
const getTableCount = async (tableName: string, condition: string = '') => {
|
||||
const countRes = await runSql(getDefaultCountSql(tableName, condition));
|
||||
return countRes.res[0].count;
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取默认查询语句
|
||||
*/
|
||||
const getDefaultSelectSql = (tableName: string, where: string = '', orderBy: string = '', pageNum: number = 1) => {
|
||||
const baseSql = `SELECT * FROM ${tableName} ${where ? 'WHERE ' + where : ''} ${orderBy ? orderBy : ''}`;
|
||||
if (state.dbType == 'mysql') {
|
||||
return `${baseSql} LIMIT ${(pageNum - 1) * state.defalutLimit}, ${state.defalutLimit};`
|
||||
}
|
||||
if (state.dbType == 'postgres') {
|
||||
return `${baseSql} OFFSET ${(pageNum - 1) * state.defalutLimit} LIMIT ${state.defalutLimit};`
|
||||
}
|
||||
return baseSql;
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取默认查询统计语句
|
||||
*/
|
||||
const getDefaultCountSql = (tableName: string, where: string = '') => {
|
||||
return `SELECT COUNT(*) count FROM ${tableName} ${where ? 'WHERE ' + where : ''}`;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -728,7 +827,8 @@ export default defineComponent({
|
||||
const tableName = state.activeName;
|
||||
const sortType = sort.order == 'descending' ? 'DESC' : 'ASC';
|
||||
|
||||
state.dataTabs[state.activeName].querySql = getDefaultSelectSql(tableName, '', `ORDER BY \`${sort.prop}\` ${sortType}`);
|
||||
const orderBy = `ORDER BY ${sort.prop} ${sortType}`;
|
||||
state.dataTabs[state.activeName].orderBy = orderBy;
|
||||
|
||||
onRefresh(tableName);
|
||||
};
|
||||
@@ -819,7 +919,6 @@ export default defineComponent({
|
||||
state.tableName = '';
|
||||
state.nowTableName = '';
|
||||
state.tableMetadata = [];
|
||||
state.columnMetadata = [];
|
||||
state.dataTabs = {};
|
||||
setCodermirrorValue('');
|
||||
state.sqlNames = [];
|
||||
@@ -854,10 +953,7 @@ export default defineComponent({
|
||||
|
||||
promptExeSql(sql, null, () => {
|
||||
if (!queryTab) {
|
||||
state.dataTabs[state.activeName].execRes.data = state.dataTabs[state.activeName].execRes.data.filter(
|
||||
(d: any) => !(deleteDatas.findIndex((x: any) => x[primaryKeyColumnName] == d[primaryKeyColumnName]) != -1)
|
||||
);
|
||||
state.dataTabs[state.activeName].selectionDatas = [];
|
||||
onRefresh(state.activeName);
|
||||
} else {
|
||||
state.queryTab.execRes.data = state.queryTab.execRes.data.filter(
|
||||
(d: any) => !(deleteDatas.findIndex((x: any) => x[primaryKeyColumnName] == d[primaryKeyColumnName]) != -1)
|
||||
@@ -881,7 +977,8 @@ export default defineComponent({
|
||||
if (!state.nowTableName || !property) {
|
||||
return;
|
||||
}
|
||||
let text = row[property];
|
||||
// 转为字符串比较,可能存在数字等
|
||||
let text = (row[property] ? row[property] : '') + '';
|
||||
let div = cell.children[0];
|
||||
if (div) {
|
||||
let input = document.createElement('input');
|
||||
@@ -1033,6 +1130,7 @@ export default defineComponent({
|
||||
formatSql,
|
||||
onBeforeChange,
|
||||
onRefresh,
|
||||
handlePageChange,
|
||||
selectByCondition,
|
||||
onCommit,
|
||||
addRow,
|
||||
|
||||
@@ -5,6 +5,7 @@ export const dbApi = {
|
||||
dbs: Api.create("/dbs", 'get'),
|
||||
saveDb: Api.create("/dbs", 'post'),
|
||||
deleteDb: Api.create("/dbs/{id}", 'delete'),
|
||||
dumpDb: Api.create("/dbs/{id}/dump", 'post'),
|
||||
tableInfos: Api.create("/dbs/{id}/t-infos", 'get'),
|
||||
tableIndex: Api.create("/dbs/{id}/t-index", 'get'),
|
||||
tableDdl: Api.create("/dbs/{id}/t-create-ddl", 'get'),
|
||||
@@ -12,7 +13,7 @@ export const dbApi = {
|
||||
columnMetadata: Api.create("/dbs/{id}/c-metadata", 'get'),
|
||||
// 获取表即列提示
|
||||
hintTables: Api.create("/dbs/{id}/hint-tables", 'get'),
|
||||
sqlExec: Api.create("/dbs/{id}/exec-sql", 'get'),
|
||||
sqlExec: Api.create("/dbs/{id}/exec-sql", 'post'),
|
||||
// 保存sql
|
||||
saveSql: Api.create("/dbs/{id}/sql", 'post'),
|
||||
// 获取保存的sql
|
||||
@@ -20,4 +21,6 @@ export const dbApi = {
|
||||
// 获取保存的sql names
|
||||
getSqlNames: Api.create("/dbs/{id}/sql-names", 'get'),
|
||||
deleteDbSql: Api.create("/dbs/{id}/sql", 'delete'),
|
||||
// 获取数据库sql执行记录
|
||||
getSqlExecs: Api.create("/dbs/{dbId}/sql-execs", 'get'),
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
<div>
|
||||
<el-dialog title="待执行SQL" v-model="dialogVisible" :show-close="false" width="600px">
|
||||
<codemirror height="350px" class="codesql" ref="cmEditor" language="sql" v-model="sqlValue" :options="cmOptions" />
|
||||
<el-input ref="remarkInputRef" v-model="remark" placeholder="请输入执行备注" class="mt5" />
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
@@ -13,9 +14,9 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, defineComponent } from 'vue';
|
||||
import { toRefs, ref, nextTick, reactive, defineComponent } from 'vue';
|
||||
import { dbApi } from '../api';
|
||||
import { ElDialog, ElButton } from 'element-plus';
|
||||
import { ElDialog, ElButton, ElInput, ElMessage, InputInstance } from 'element-plus';
|
||||
// import base style
|
||||
import 'codemirror/lib/codemirror.css';
|
||||
// 引入主题后还需要在 options 中指定主题才会生效
|
||||
@@ -32,6 +33,7 @@ export default defineComponent({
|
||||
codemirror,
|
||||
ElButton,
|
||||
ElDialog,
|
||||
ElInput,
|
||||
},
|
||||
props: {
|
||||
visible: {
|
||||
@@ -48,11 +50,13 @@ export default defineComponent({
|
||||
},
|
||||
},
|
||||
setup(props: any) {
|
||||
const remarkInputRef = ref<InputInstance>();
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
sqlValue: '',
|
||||
dbId: 0,
|
||||
db: '',
|
||||
remark: '',
|
||||
btnLoading: false,
|
||||
cmOptions: {
|
||||
tabSize: 4,
|
||||
@@ -77,14 +81,26 @@ export default defineComponent({
|
||||
* 执行sql
|
||||
*/
|
||||
const runSql = async () => {
|
||||
if (!state.remark) {
|
||||
ElMessage.error('请输入执行的备注信息');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
state.btnLoading = true;
|
||||
await dbApi.sqlExec.request({
|
||||
const res = await dbApi.sqlExec.request({
|
||||
id: state.dbId,
|
||||
db: state.db,
|
||||
remark: state.remark,
|
||||
sql: state.sqlValue.trim(),
|
||||
});
|
||||
runSuccess = true;
|
||||
if (parseInt(res.res[0].影响条数) >= 1) {
|
||||
ElMessage.success('执行成功');
|
||||
runSuccess = true;
|
||||
} else {
|
||||
ElMessage.error('执行失败');
|
||||
runSuccess = false;
|
||||
}
|
||||
} catch (e) {
|
||||
runSuccess = false;
|
||||
}
|
||||
@@ -104,6 +120,7 @@ export default defineComponent({
|
||||
setTimeout(() => {
|
||||
state.dbId = 0;
|
||||
state.sqlValue = '';
|
||||
state.remark = '';
|
||||
runSuccessCallback = null;
|
||||
cancelCallback = null;
|
||||
runSuccess = false;
|
||||
@@ -117,10 +134,16 @@ export default defineComponent({
|
||||
state.dbId = props.dbId;
|
||||
state.db = props.db;
|
||||
state.dialogVisible = true;
|
||||
nextTick(() => {
|
||||
setTimeout(() => {
|
||||
remarkInputRef.value?.focus();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
remarkInputRef,
|
||||
open,
|
||||
runSql,
|
||||
cancel,
|
||||
@@ -133,7 +156,4 @@ export default defineComponent({
|
||||
font-size: 9pt;
|
||||
font-weight: 600;
|
||||
}
|
||||
.footer {
|
||||
float: right;
|
||||
}
|
||||
</style>
|
||||
|
||||
11
mayfly_go_web/src/views/ops/db/enums.ts
Normal file
11
mayfly_go_web/src/views/ops/db/enums.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Enum } from '@/common/Enum'
|
||||
|
||||
/**
|
||||
* 枚举类
|
||||
*/
|
||||
export default {
|
||||
// 数据库sql执行类型
|
||||
DbSqlExecTypeEnum: new Enum().add('UPDATE', 'UPDATE', 1)
|
||||
.add('DELETE', 'DELETE', 2)
|
||||
.add('INSERT', 'INSERT', 3),
|
||||
}
|
||||
@@ -89,17 +89,19 @@
|
||||
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item v-if="data.type == '-' && data.size < 1 * 1024 * 1024">
|
||||
<el-link
|
||||
@click.prevent="getFileContent(tree.folder.id, data.path)"
|
||||
type="info"
|
||||
icon="view"
|
||||
:underline="false"
|
||||
>
|
||||
查看
|
||||
</el-link>
|
||||
<el-dropdown-item
|
||||
@click="getFileContent(tree.folder.id, data.path)"
|
||||
v-if="data.type == '-' && data.size < 1 * 1024 * 1024"
|
||||
>
|
||||
<el-link type="info" icon="view" :underline="false">查看</el-link>
|
||||
</el-dropdown-item>
|
||||
|
||||
<span v-auth="'machine:file:write'">
|
||||
<el-dropdown-item @click="showCreateFileDialog(node, data)" v-if="data.type == 'd'">
|
||||
<el-link type="primary" icon="document" :underline="false" style="margin-left: 2px">新建</el-link>
|
||||
</el-dropdown-item>
|
||||
</span>
|
||||
|
||||
<span v-auth="'machine:file:upload'">
|
||||
<el-dropdown-item v-if="data.type == 'd'">
|
||||
<el-upload
|
||||
@@ -112,34 +114,20 @@
|
||||
name="file"
|
||||
style="display: inline-block; margin-left: 2px"
|
||||
>
|
||||
<el-link icon="upload" :underline="false"> 上传 </el-link>
|
||||
<el-link icon="upload" :underline="false">上传</el-link>
|
||||
</el-upload>
|
||||
</el-dropdown-item>
|
||||
</span>
|
||||
|
||||
<span v-auth="'machine:file:write'">
|
||||
<el-dropdown-item v-if="data.type == '-'">
|
||||
<el-link
|
||||
@click.prevent="downloadFile(node, data)"
|
||||
type="primary"
|
||||
icon="download"
|
||||
:underline="false"
|
||||
style="margin-left: 2px"
|
||||
>下载</el-link
|
||||
>
|
||||
<el-dropdown-item @click="downloadFile(node, data)" v-if="data.type == '-'">
|
||||
<el-link type="primary" icon="download" :underline="false" style="margin-left: 2px">下载</el-link>
|
||||
</el-dropdown-item>
|
||||
</span>
|
||||
|
||||
<span v-auth="'machine:file:rm'">
|
||||
<el-dropdown-item v-if="!dontOperate(data)">
|
||||
<el-link
|
||||
@click.prevent="deleteFile(node, data)"
|
||||
type="danger"
|
||||
icon="delete"
|
||||
:underline="false"
|
||||
style="margin-left: 2px"
|
||||
>删除
|
||||
</el-link>
|
||||
<el-dropdown-item @click="deleteFile(node, data)" v-if="!dontOperate(data)">
|
||||
<el-link type="danger" icon="delete" :underline="false" style="margin-left: 2px">删除</el-link>
|
||||
</el-dropdown-item>
|
||||
</span>
|
||||
</el-dropdown-menu>
|
||||
@@ -151,6 +139,35 @@
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
:destroy-on-close="true"
|
||||
title="新建文件"
|
||||
v-model="createFileDialog.visible"
|
||||
:before-close="closeCreateFileDialog"
|
||||
:close-on-click-modal="false"
|
||||
top="5vh"
|
||||
width="400px"
|
||||
>
|
||||
<div>
|
||||
<el-form-item prop="name" label="名称:">
|
||||
<el-input v-model.trim="createFileDialog.name" placeholder="请输入名称" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="type" label="类型:">
|
||||
<el-radio-group v-model="createFileDialog.type">
|
||||
<el-radio label="d" size="small">文件夹</el-radio>
|
||||
<el-radio label="-" size="small">文件</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="closeCreateFileDialog">关闭</el-button>
|
||||
<el-button v-auth="'machine:file:write'" type="primary" @click="createFile">确定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
:destroy-on-close="true"
|
||||
:title="fileContent.dialogTitle"
|
||||
@@ -182,6 +199,7 @@ import { codemirror } from '@/components/codemirror';
|
||||
import { getSession } from '@/common/utils/storage';
|
||||
import enums from './enums';
|
||||
import config from '@/common/config';
|
||||
import { isTrue } from '@/common/assert';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'FileManage',
|
||||
@@ -202,26 +220,8 @@ export default defineComponent({
|
||||
const fileTree: any = ref(null);
|
||||
const token = getSession('token');
|
||||
|
||||
const cmOptions = {
|
||||
tabSize: 2,
|
||||
mode: 'text/x-sh',
|
||||
theme: 'panda-syntax',
|
||||
line: true,
|
||||
// 开启校验
|
||||
lint: true,
|
||||
gutters: ['CodeMirror-lint-markers'],
|
||||
indentWithTabs: true,
|
||||
smartIndent: true,
|
||||
matchBrackets: true,
|
||||
autofocus: true,
|
||||
styleSelectedText: true,
|
||||
styleActiveLine: true, // 高亮选中行
|
||||
foldGutter: true, // 块槽
|
||||
hintOptions: {
|
||||
// 当匹配只有一项的时候是否自动补全
|
||||
completeSingle: true,
|
||||
},
|
||||
};
|
||||
const folderType = 'd';
|
||||
const fileType = '-';
|
||||
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
@@ -268,6 +268,12 @@ export default defineComponent({
|
||||
path: '',
|
||||
type: '',
|
||||
},
|
||||
createFileDialog: {
|
||||
visible: false,
|
||||
name: '',
|
||||
type: folderType,
|
||||
node: null as any,
|
||||
},
|
||||
file: null as any,
|
||||
});
|
||||
|
||||
@@ -290,18 +296,6 @@ export default defineComponent({
|
||||
getFiles();
|
||||
};
|
||||
|
||||
/**
|
||||
* tab切换触发事件
|
||||
* @param {Object} tab
|
||||
* @param {Object} event
|
||||
*/
|
||||
// handleClick(tab, event) {
|
||||
// // if (tab.name == 'file-manage') {
|
||||
// // this.fileManage.node.childNodes = [];
|
||||
// // this.loadNode(this.fileManage.node, this.fileManage.resolve);
|
||||
// // }
|
||||
// }
|
||||
|
||||
const add = () => {
|
||||
// 往数组头部添加元素
|
||||
state.fileTable = [{}].concat(state.fileTable);
|
||||
@@ -329,7 +323,6 @@ export default defineComponent({
|
||||
})
|
||||
.then(() => {
|
||||
getFiles();
|
||||
// state.fileTable.splice(idx, 1);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
@@ -406,7 +399,6 @@ export default defineComponent({
|
||||
emit('update:visible', false);
|
||||
emit('update:machineId', null);
|
||||
emit('cancel');
|
||||
// state.activeName = 'conf-file'
|
||||
state.fileTable = [];
|
||||
state.tree.folder = { id: 0 };
|
||||
};
|
||||
@@ -431,7 +423,7 @@ export default defineComponent({
|
||||
return resolve([
|
||||
{
|
||||
name: path,
|
||||
type: 'd',
|
||||
type: folderType,
|
||||
path: path,
|
||||
},
|
||||
]);
|
||||
@@ -453,13 +445,42 @@ export default defineComponent({
|
||||
});
|
||||
for (const file of res) {
|
||||
const type = file.type;
|
||||
if (type != 'd') {
|
||||
if (type == fileType) {
|
||||
file.leaf = true;
|
||||
}
|
||||
}
|
||||
return resolve(res);
|
||||
};
|
||||
|
||||
const showCreateFileDialog = (node: any) => {
|
||||
isTrue(node.expanded, '请先点击展开该节点后再创建');
|
||||
state.createFileDialog.node = node;
|
||||
state.createFileDialog.visible = true;
|
||||
};
|
||||
|
||||
const createFile = async () => {
|
||||
const node = state.createFileDialog.node;
|
||||
console.log(node.data);
|
||||
const name = state.createFileDialog.name;
|
||||
const type = state.createFileDialog.type;
|
||||
const path = node.data.path + '/' + name;
|
||||
await machineApi.createFile.request({
|
||||
machineId: props.machineId,
|
||||
id: state.tree.folder.id,
|
||||
path,
|
||||
type,
|
||||
});
|
||||
fileTree.value.append({ name: name, path: path, type: type, leaf: type === fileType, size: 0 }, node);
|
||||
closeCreateFileDialog();
|
||||
};
|
||||
|
||||
const closeCreateFileDialog = () => {
|
||||
state.createFileDialog.visible = false;
|
||||
state.createFileDialog.node = null;
|
||||
state.createFileDialog.name = '';
|
||||
state.createFileDialog.type = folderType;
|
||||
};
|
||||
|
||||
const deleteFile = (node: any, data: any) => {
|
||||
const file = data.path;
|
||||
ElMessageBox.confirm(`此操作将删除 [${file}], 是否继续?`, '提示', {
|
||||
@@ -486,7 +507,6 @@ export default defineComponent({
|
||||
|
||||
const downloadFile = (node: any, data: any) => {
|
||||
const a = document.createElement('a');
|
||||
// a.setAttribute('target', '_blank')
|
||||
a.setAttribute(
|
||||
'href',
|
||||
`${config.baseApiUrl}/machines/${props.machineId}/files/${state.tree.folder.id}/read?type=1&path=${data.path}&token=${token}`
|
||||
@@ -534,7 +554,6 @@ export default defineComponent({
|
||||
|
||||
const beforeUpload = (file: File) => {
|
||||
state.file = file;
|
||||
// ElMessage.success(`'${file.name}' 上传中,请关注结果通知`);
|
||||
};
|
||||
const getFilePath = (data: object, visible: boolean) => {
|
||||
if (visible) {
|
||||
@@ -590,7 +609,6 @@ export default defineComponent({
|
||||
fileTree,
|
||||
enums,
|
||||
token,
|
||||
cmOptions,
|
||||
add,
|
||||
getFiles,
|
||||
handlePageChange,
|
||||
@@ -601,6 +619,9 @@ export default defineComponent({
|
||||
updateContent,
|
||||
handleClose,
|
||||
loadNode,
|
||||
showCreateFileDialog,
|
||||
closeCreateFileDialog,
|
||||
createFile,
|
||||
deleteFile,
|
||||
downloadFile,
|
||||
getUploadFile,
|
||||
|
||||
@@ -48,6 +48,7 @@ import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
|
||||
import { machineApi } from './api';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { notBlank } from '@/common/assert';
|
||||
import { RsaEncrypt } from '@/common/rsa';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'MachineEdit',
|
||||
@@ -76,8 +77,8 @@ export default defineComponent({
|
||||
projectName: null,
|
||||
name: null,
|
||||
port: 22,
|
||||
username: null,
|
||||
password: null,
|
||||
username: "",
|
||||
password: "",
|
||||
remark: '',
|
||||
},
|
||||
btnLoading: false,
|
||||
@@ -149,9 +150,11 @@ export default defineComponent({
|
||||
if (!state.form.id) {
|
||||
notBlank(state.form.password, '新增操作,密码不可为空');
|
||||
}
|
||||
machineForm.value.validate((valid: boolean) => {
|
||||
machineForm.value.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
machineApi.saveMachine.request(state.form).then(() => {
|
||||
const reqForm = { ...state.form };
|
||||
reqForm.password = await RsaEncrypt(state.form.password);
|
||||
machineApi.saveMachine.request(reqForm).then(() => {
|
||||
ElMessage.success('保存成功');
|
||||
emit('val-change', state.form);
|
||||
state.btnLoading = true;
|
||||
@@ -171,11 +174,6 @@ export default defineComponent({
|
||||
const cancel = () => {
|
||||
emit('update:visible', false);
|
||||
emit('cancel');
|
||||
setTimeout(() => {
|
||||
machineForm.value.resetFields();
|
||||
// 重置对象属性为null
|
||||
state.form = {} as any;
|
||||
}, 200);
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@@ -57,11 +57,10 @@
|
||||
v-model="scope.row.status"
|
||||
:active-value="1"
|
||||
:inactive-value="-1"
|
||||
active-color="#13ce66"
|
||||
inactive-color="#ff4949"
|
||||
inline-prompt
|
||||
active-text="启用"
|
||||
inactive-text="停用"
|
||||
style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
|
||||
@change="changeStatus(scope.row)"
|
||||
></el-switch>
|
||||
</template>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="params" label="参数">
|
||||
<el-input v-model.trim="form.params" placeholder="参数数组json,若无可不填"></el-input>
|
||||
<el-input v-model="form.params" placeholder="参数数组json,若无可不填"></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="script" label="内容" id="content">
|
||||
|
||||
@@ -25,6 +25,7 @@ export const machineApi = {
|
||||
rmFile: Api.create("/machines/{machineId}/files/{fileId}/remove", 'delete'),
|
||||
uploadFile: Api.create("/machines/{machineId}/files/{fileId}/upload?token={token}", 'post'),
|
||||
fileContent: Api.create("/machines/{machineId}/files/{fileId}/read", 'get'),
|
||||
createFile: Api.create("/machines/{machineId}/files/{id}/create-file", 'post'),
|
||||
// 修改文件内容
|
||||
updateFileContent: Api.create("/machines/{machineId}/files/{id}/write", 'post'),
|
||||
// 添加文件or目录
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="库" label-width="20px">
|
||||
<el-select v-model="database" placeholder="请选择库" @change="changeDatabase">
|
||||
<el-select v-model="database" placeholder="请选择库" @change="changeDatabase" filterable>
|
||||
<el-option v-for="item in databases" :key="item.Name" :label="item.Name" :value="item.Name">
|
||||
<span style="float: left">{{ item.Name }}</span>
|
||||
<span style="float: right; color: #8492a6; margin-left: 4px; font-size: 13px">{{
|
||||
@@ -26,12 +26,8 @@
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="集合" label-width="40px">
|
||||
<el-select v-model="collection" placeholder="请选择集合" @change="changeCollection">
|
||||
<el-select v-model="collection" placeholder="请选择集合" @change="changeCollection" filterable>
|
||||
<el-option v-for="item in collections" :key="item" :label="item" :value="item">
|
||||
<!-- <span style="float: left">{{ item.uri }}</span>
|
||||
<span style="float: right; color: #8492a6; margin-left: 6px; font-size: 13px">{{
|
||||
` [${item.name}]`
|
||||
}}</span> -->
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
@@ -64,10 +60,22 @@
|
||||
<el-input type="textarea" v-model="item.value" :rows="12" />
|
||||
<div style="padding: 3px; float: right" class="mr5 mongo-doc-btns">
|
||||
<div>
|
||||
<el-button @click="onSaveDoc(item.value)" type="warning" plain size="small">保存</el-button>
|
||||
<el-link @click="onJsonEditor(item)" :underline="false" type="success" icon="MagicStick"></el-link>
|
||||
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
|
||||
<el-link
|
||||
@click="onSaveDoc(item.value)"
|
||||
:underline="false"
|
||||
type="warning"
|
||||
icon="DocumentChecked"
|
||||
></el-link>
|
||||
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
|
||||
<el-popconfirm @confirm="onDeleteDoc(item.value)" title="确定删除该文档?">
|
||||
<template #reference>
|
||||
<el-button type="danger" plain size="small">删除</el-button>
|
||||
<el-link :underline="false" type="danger" icon="DocumentDelete"></el-link>
|
||||
</template>
|
||||
</el-popconfirm>
|
||||
</div>
|
||||
@@ -79,7 +87,7 @@
|
||||
</el-tabs>
|
||||
</el-container>
|
||||
|
||||
<el-dialog width="400px" title="find参数" v-model="findDialog.visible">
|
||||
<el-dialog width="600px" title="find参数" v-model="findDialog.visible">
|
||||
<el-form label-width="70px">
|
||||
<el-form-item label="filter">
|
||||
<el-input v-model="findDialog.findParam.filter" type="textarea" :rows="6" clearable auto-complete="off"></el-input>
|
||||
@@ -102,8 +110,8 @@
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog width="600px" :title="`新增'${activeName}'集合文档`" v-model="insertDocDialog.visible" :close-on-click-modal="false">
|
||||
<el-input v-model="insertDocDialog.doc" type="textarea" :rows="12" clearable auto-complete="off"></el-input>
|
||||
<el-dialog width="800px" :title="`新增'${activeName}'集合文档`" v-model="insertDocDialog.visible" :close-on-click-modal="false">
|
||||
<json-edit currentMode="code" v-model="insertDocDialog.doc" />
|
||||
<template #footer>
|
||||
<div>
|
||||
<el-button @click="insertDocDialog.visible = false">取 消</el-button>
|
||||
@@ -112,6 +120,10 @@
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog width="800px" title="json编辑器" v-model="jsoneditorDialog.visible" @close="onCloseJsonEditDialog" :close-on-click-modal="false">
|
||||
<json-edit v-model="jsoneditorDialog.doc" />
|
||||
</el-dialog>
|
||||
|
||||
<div style="text-align: center; margin-top: 10px"></div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -123,12 +135,14 @@ import { ElMessage } from 'element-plus';
|
||||
import ProjectEnvSelect from '../component/ProjectEnvSelect.vue';
|
||||
|
||||
import { isTrue, notBlank, notNull } from '@/common/assert';
|
||||
import { formatByteSize, formatJsonString } from '@/common/utils/format';
|
||||
import { formatByteSize } from '@/common/utils/format';
|
||||
import JsonEdit from '@/components/jsonedit/index.vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'MongoDataOp',
|
||||
components: {
|
||||
ProjectEnvSelect,
|
||||
JsonEdit,
|
||||
},
|
||||
setup() {
|
||||
const findParamInputRef: any = ref(null);
|
||||
@@ -156,6 +170,11 @@ export default defineComponent({
|
||||
visible: false,
|
||||
doc: '',
|
||||
},
|
||||
jsoneditorDialog: {
|
||||
visible: false,
|
||||
doc: '',
|
||||
item: {} as any,
|
||||
},
|
||||
});
|
||||
|
||||
const searchMongo = async () => {
|
||||
@@ -275,7 +294,7 @@ export default defineComponent({
|
||||
return wrapDatas;
|
||||
}
|
||||
for (let data of datas) {
|
||||
wrapDatas.push({ value: formatJsonString(JSON.stringify(data), false) });
|
||||
wrapDatas.push({ value: JSON.stringify(data, null, 4) });
|
||||
}
|
||||
return wrapDatas;
|
||||
};
|
||||
@@ -288,7 +307,7 @@ export default defineComponent({
|
||||
// 移除_id字段,因为新增无需该字段
|
||||
const docObj = JSON.parse(datasFirstDoc.value);
|
||||
delete docObj['_id'];
|
||||
doc = formatJsonString(JSON.stringify(docObj), false);
|
||||
doc = JSON.stringify(docObj, null, 4);
|
||||
}
|
||||
state.insertDocDialog.doc = doc;
|
||||
state.insertDocDialog.visible = true;
|
||||
@@ -313,6 +332,16 @@ export default defineComponent({
|
||||
state.insertDocDialog.visible = false;
|
||||
};
|
||||
|
||||
const onJsonEditor = (item: any) => {
|
||||
state.jsoneditorDialog.item = item;
|
||||
state.jsoneditorDialog.doc = item.value;
|
||||
state.jsoneditorDialog.visible = true;
|
||||
};
|
||||
|
||||
const onCloseJsonEditDialog = () => {
|
||||
state.jsoneditorDialog.item.value = JSON.stringify(JSON.parse(state.jsoneditorDialog.doc), null, 4);
|
||||
};
|
||||
|
||||
const onSaveDoc = async (doc: string) => {
|
||||
const docObj = parseDocJsonString(doc);
|
||||
const id = docObj._id;
|
||||
@@ -403,6 +432,8 @@ export default defineComponent({
|
||||
onInsertDoc,
|
||||
onSaveDoc,
|
||||
onDeleteDoc,
|
||||
onJsonEditor,
|
||||
onCloseJsonEditDialog,
|
||||
formatByteSize,
|
||||
};
|
||||
},
|
||||
@@ -415,6 +446,6 @@ export default defineComponent({
|
||||
z-index: 2;
|
||||
right: 3px;
|
||||
top: 2px;
|
||||
max-width: 130px;
|
||||
max-width: 120px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -42,6 +42,7 @@ import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
|
||||
import { mongoApi } from './api';
|
||||
import { projectApi } from '../project/api.ts';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { RsaEncrypt } from '@/common/rsa';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'MongoEdit',
|
||||
@@ -144,9 +145,11 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const btnOk = async () => {
|
||||
mongoForm.value.validate((valid: boolean) => {
|
||||
mongoForm.value.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
mongoApi.saveMongo.request(state.form).then(() => {
|
||||
const reqForm = { ...state.form };
|
||||
reqForm.uri = await RsaEncrypt(reqForm.uri);
|
||||
mongoApi.saveMongo.request(reqForm).then(() => {
|
||||
ElMessage.success('保存成功');
|
||||
emit('val-change', state.form);
|
||||
state.btnLoading = true;
|
||||
@@ -166,11 +169,6 @@ export default defineComponent({
|
||||
const cancel = () => {
|
||||
emit('update:visible', false);
|
||||
emit('cancel');
|
||||
setTimeout(() => {
|
||||
mongoForm.value.resetFields();
|
||||
// 重置对象属性为null
|
||||
state.form = {} as any;
|
||||
}, 200);
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
{{ collectionsDialog.statsDialog.data.count }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="avgObjSize" label-align="right" align="center">
|
||||
{{ collectionsDialog.statsDialog.data.avgObjSize }}
|
||||
{{ formatByteSize(collectionsDialog.statsDialog.data.avgObjSize) }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="nindexes" label-align="right" align="center">
|
||||
{{ collectionsDialog.statsDialog.data.nindexes }}
|
||||
@@ -250,7 +250,7 @@ export default defineComponent({
|
||||
|
||||
onMounted(async () => {
|
||||
search();
|
||||
state.projects = (await projectApi.projects.request({ pageNum: 1, pageSize: 100 })).list;
|
||||
state.projects = await projectApi.accountProjects.request(null);
|
||||
});
|
||||
|
||||
const handlePageChange = (curPage: number) => {
|
||||
@@ -266,12 +266,6 @@ export default defineComponent({
|
||||
state.currentData = item;
|
||||
};
|
||||
|
||||
// connect() {
|
||||
// Req.post('/open/redis/connect', this.form, res => {
|
||||
// this.redisInfo = res
|
||||
// })
|
||||
// }
|
||||
|
||||
const showDatabases = async (id: number) => {
|
||||
state.databaseDialog.data = (await mongoApi.databases.request({ id })).Databases;
|
||||
state.databaseDialog.title = `数据库列表`;
|
||||
@@ -371,14 +365,6 @@ export default defineComponent({
|
||||
} catch (err) {}
|
||||
};
|
||||
|
||||
// const info = (redis: any) => {
|
||||
// redisApi.redisInfo.request({ id: redis.id }).then((res: any) => {
|
||||
// state.infoDialog.info = res;
|
||||
// state.infoDialog.title = `'${redis.host}' info`;
|
||||
// state.infoDialog.visible = true;
|
||||
// });
|
||||
// };
|
||||
|
||||
const search = async () => {
|
||||
const res = await mongoApi.mongoList.request(state.query);
|
||||
state.list = res.list;
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="count" label-width="60px">
|
||||
<el-input placeholder="count" style="width: 62px" v-model="scanParam.count"></el-input>
|
||||
<el-input placeholder="count" style="width: 62px" v-model.number="scanParam.count"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button @click="searchKey()" type="success" icon="search" plain></el-button>
|
||||
@@ -92,7 +92,7 @@ import { toRefs, reactive, defineComponent } from 'vue';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import ProjectEnvSelect from '../component/ProjectEnvSelect.vue';
|
||||
import DataEdit from './DataEdit.vue';
|
||||
import { isTrue, notNull } from '@/common/assert';
|
||||
import { isTrue, notBlank, notNull } from '@/common/assert';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'DataOperation',
|
||||
@@ -103,18 +103,15 @@ export default defineComponent({
|
||||
setup() {
|
||||
const state = reactive({
|
||||
loading: false,
|
||||
cluster: 0,
|
||||
redisList: [],
|
||||
query: {
|
||||
envId: 0,
|
||||
},
|
||||
scanParam: {
|
||||
id: null,
|
||||
cluster: 0,
|
||||
match: null,
|
||||
count: 10,
|
||||
cursor: 0,
|
||||
prevCursor: null,
|
||||
cursor: {},
|
||||
},
|
||||
valueDialog: {
|
||||
visible: false,
|
||||
@@ -151,31 +148,33 @@ export default defineComponent({
|
||||
}
|
||||
};
|
||||
|
||||
const changeRedis = () => {
|
||||
resetScanParam();
|
||||
const changeRedis = (id: number) => {
|
||||
resetScanParam(id);
|
||||
state.keys = [];
|
||||
state.dbsize = 0;
|
||||
searchKey();
|
||||
};
|
||||
|
||||
const scan = () => {
|
||||
const scan = async () => {
|
||||
isTrue(state.scanParam.id != null, '请先选择redis');
|
||||
notBlank(state.scanParam.count, 'count不能为空');
|
||||
isTrue(state.scanParam.count < 20001, 'count不能超过20000');
|
||||
|
||||
state.loading = true;
|
||||
state.scanParam.cluster = state.cluster == 0 ? 0 : 1;
|
||||
|
||||
redisApi.scan.request(state.scanParam).then((res) => {
|
||||
try {
|
||||
const res = await redisApi.scan.request(state.scanParam);
|
||||
state.keys = res.keys;
|
||||
state.dbsize = res.dbSize;
|
||||
state.scanParam.cursor = res.cursor;
|
||||
} finally {
|
||||
state.loading = false;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const searchKey = () => {
|
||||
state.scanParam.cursor = 0;
|
||||
scan();
|
||||
const searchKey = async () => {
|
||||
state.scanParam.cursor = {};
|
||||
await scan();
|
||||
};
|
||||
|
||||
const clearRedis = () => {
|
||||
@@ -193,10 +192,17 @@ export default defineComponent({
|
||||
}
|
||||
};
|
||||
|
||||
const resetScanParam = () => {
|
||||
state.scanParam.match = null;
|
||||
state.scanParam.cursor = 0;
|
||||
const resetScanParam = (id: number = 0) => {
|
||||
state.scanParam.count = 10;
|
||||
if (id != 0) {
|
||||
const redis: any = state.redisList.find((x: any) => x.id == id);
|
||||
// 集群模式count设小点,因为后端会从所有master节点scan一遍然后合并结果
|
||||
if (redis && redis.mode == 'cluster') {
|
||||
state.scanParam.count = 5;
|
||||
}
|
||||
}
|
||||
state.scanParam.match = null;
|
||||
state.scanParam.cursor = {};
|
||||
};
|
||||
|
||||
const getValue = async (row: any) => {
|
||||
@@ -204,11 +210,9 @@ export default defineComponent({
|
||||
const key = row.key;
|
||||
|
||||
let res: any;
|
||||
const id = state.cluster == 0 ? state.scanParam.id : state.cluster;
|
||||
const reqParam = {
|
||||
cluster: state.cluster,
|
||||
key: row.key,
|
||||
id,
|
||||
id: state.scanParam.id,
|
||||
};
|
||||
switch (type) {
|
||||
case 'string':
|
||||
@@ -260,29 +264,27 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const del = (key: string) => {
|
||||
ElMessageBox.confirm(`此操作将删除对应的key , 是否继续?`, '提示', {
|
||||
ElMessageBox.confirm(`确定删除[ ${key} ] 该key?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
.then(() => {
|
||||
let id = state.cluster == 0 ? state.scanParam.id : state.cluster;
|
||||
redisApi.delKey
|
||||
.request({
|
||||
cluster: state.cluster,
|
||||
key,
|
||||
id,
|
||||
id: state.scanParam.id,
|
||||
})
|
||||
.then(() => {
|
||||
ElMessage.success('删除成功!');
|
||||
scan();
|
||||
searchKey();
|
||||
});
|
||||
})
|
||||
.catch(() => {});
|
||||
};
|
||||
|
||||
const ttlConveter = (ttl: any) => {
|
||||
if (ttl == -1) {
|
||||
if (ttl == -1 || ttl == 0) {
|
||||
return '永久';
|
||||
}
|
||||
if (!ttl) {
|
||||
|
||||
@@ -13,27 +13,41 @@
|
||||
<el-option v-for="item in envs" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item prop="mode" label="mode:" required>
|
||||
<el-select style="width: 100%" v-model="form.mode" placeholder="请选择模式">
|
||||
<el-option label="standalone" value="standalone"> </el-option>
|
||||
<el-option label="cluster" value="cluster"> </el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item prop="host" label="host:" required>
|
||||
<el-input v-model.trim="form.host" placeholder="请输入host:port" auto-complete="off"></el-input>
|
||||
<el-input
|
||||
v-model.trim="form.host"
|
||||
placeholder="请输入host:port,集群模式用','分割"
|
||||
auto-complete="off"
|
||||
type="textarea"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password" label="密码:">
|
||||
<el-input
|
||||
type="password"
|
||||
show-password
|
||||
v-model.trim="form.password"
|
||||
placeholder="请输入密码"
|
||||
placeholder="请输入密码, 修改操作可不填"
|
||||
autocomplete="new-password"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="db" label="库号:" required>
|
||||
<el-input v-model.number="form.db" placeholder="请输入库号"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="remark" label="备注:">
|
||||
<el-input v-model.trim="form.remark" auto-complete="off" type="textarea"></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>
|
||||
<el-button type="primary" :loading="btnLoading" @click="btnOk">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
@@ -45,6 +59,7 @@ import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
|
||||
import { redisApi } from './api';
|
||||
import { projectApi } from '../project/api.ts';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { RsaEncrypt } from '@/common/rsa';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'RedisEdit',
|
||||
@@ -71,12 +86,14 @@ export default defineComponent({
|
||||
form: {
|
||||
id: null,
|
||||
name: null,
|
||||
mode: 'standalone',
|
||||
host: null,
|
||||
password: null,
|
||||
project: null,
|
||||
projectId: null,
|
||||
envId: null,
|
||||
env: null,
|
||||
remark: '',
|
||||
},
|
||||
btnLoading: false,
|
||||
rules: {
|
||||
@@ -108,6 +125,13 @@ export default defineComponent({
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
mode: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入模式',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -148,9 +172,11 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const btnOk = async () => {
|
||||
redisForm.value.validate((valid: boolean) => {
|
||||
redisForm.value.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
redisApi.saveRedis.request(state.form).then(() => {
|
||||
const reqForm = { ...state.form };
|
||||
reqForm.password = await RsaEncrypt(reqForm.password);
|
||||
redisApi.saveRedis.request(reqForm).then(() => {
|
||||
ElMessage.success('保存成功');
|
||||
emit('val-change', state.form);
|
||||
state.btnLoading = true;
|
||||
@@ -170,11 +196,6 @@ export default defineComponent({
|
||||
const cancel = () => {
|
||||
emit('update:visible', false);
|
||||
emit('cancel');
|
||||
setTimeout(() => {
|
||||
redisForm.value.resetFields();
|
||||
// 重置对象属性为null
|
||||
state.form = {} as any;
|
||||
}, 200);
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@@ -5,16 +5,12 @@
|
||||
<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-input placeholder="host" style="width: 140px" v-model="query.host" @clear="search" plain clearable></el-input>
|
||||
<el-select v-model="params.clusterId" clearable placeholder="集群选择">
|
||||
<el-option v-for="item in clusters" :key="item.id" :value="item.id" :label="item.name"></el-option>
|
||||
</el-select> -->
|
||||
<el-select 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>
|
||||
</div>
|
||||
<el-table :data="redisTable" style="width: 100%" @current-change="choose" stripe>
|
||||
<el-table :data="redisTable" @current-change="choose" stripe>
|
||||
<el-table-column label="选择" width="60px">
|
||||
<template #default="scope">
|
||||
<el-radio v-model="currentId" :label="scope.row.id">
|
||||
@@ -22,19 +18,23 @@
|
||||
</el-radio>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="project" label="项目" width></el-table-column>
|
||||
<el-table-column prop="env" label="环境" width></el-table-column>
|
||||
<el-table-column prop="host" label="host:port" width></el-table-column>
|
||||
<el-table-column prop="createTime" label="创建时间">
|
||||
<el-table-column prop="project" label="项目" min-width="100"></el-table-column>
|
||||
<el-table-column prop="env" label="环境" min-width="100"></el-table-column>
|
||||
<el-table-column prop="host" label="host:port" min-width="150" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column prop="mode" label="mode" min-width="100"></el-table-column>
|
||||
<el-table-column prop="remark" label="备注" min-width="120" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="createTime" label="创建时间" min-width="160">
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="creator" label="创建人"></el-table-column>
|
||||
<el-table-column label="操作" width>
|
||||
<el-table-column prop="creator" label="创建人" min-width="100"></el-table-column>
|
||||
<el-table-column label="更多" min-width="130" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button type="primary" @click="info(scope.row)" icon="tickets" plain size="small">info</el-button>
|
||||
<!-- <el-button type="success" @click="manage(scope.row)" :ref="scope.row" plain>数据管理</el-button> -->
|
||||
<el-link v-if="scope.row.mode == 'standalone'" type="primary" @click="info(scope.row)" :underline="false">单机信息</el-link>
|
||||
<el-link @click="onShowClusterInfo(scope.row)" v-if="scope.row.mode == 'cluster'" type="success" :underline="false"
|
||||
>集群信息</el-link
|
||||
>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -52,6 +52,84 @@
|
||||
|
||||
<info v-model:visible="infoDialog.visible" :title="infoDialog.title" :info="infoDialog.info"></info>
|
||||
|
||||
<el-dialog width="1000px" title="集群信息" v-model="clusterInfoDialog.visible">
|
||||
<el-input type="textarea" :autosize="{ minRows: 12, maxRows: 12 }" v-model="clusterInfoDialog.info"> </el-input>
|
||||
|
||||
<el-divider content-position="left">节点信息</el-divider>
|
||||
<el-table :data="clusterInfoDialog.nodes" stripe size="small" border>
|
||||
<el-table-column prop="nodeId" label="nodeId" min-width="300">
|
||||
<template #header>
|
||||
nodeId
|
||||
<el-tooltip class="box-item" effect="dark" content="节点id" placement="top">
|
||||
<el-icon><question-filled /></el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="ip" label="ip" min-width="180">
|
||||
<template #header>
|
||||
ip
|
||||
<el-tooltip
|
||||
class="box-item"
|
||||
effect="dark"
|
||||
content="ip:port1@port2:port1指redis服务器与客户端通信的端口,port2则是集群内部节点间通信的端口"
|
||||
placement="top"
|
||||
>
|
||||
<el-icon><question-filled /></el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<template #default="scope">
|
||||
<el-tag
|
||||
@click="info({ id: clusterInfoDialog.redisId, ip: scope.row.ip })"
|
||||
effect="plain"
|
||||
type="success"
|
||||
size="small"
|
||||
style="cursor: pointer"
|
||||
>{{ scope.row.ip }}</el-tag
|
||||
>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="flags" label="flags" min-width="110"></el-table-column>
|
||||
<el-table-column prop="masterSlaveRelation" label="masterSlaveRelation" min-width="300">
|
||||
<template #header>
|
||||
masterSlaveRelation
|
||||
<el-tooltip
|
||||
class="box-item"
|
||||
effect="dark"
|
||||
content="如果节点是slave,并且已知master节点,则为master节点ID;否则为符号'-'"
|
||||
placement="top"
|
||||
>
|
||||
<el-icon><question-filled /></el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="pingSent" label="pingSent" min-width="130" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
{{ scope.row.pingSent == 0 ? 0 : new Date(parseInt(scope.row.pingSent)).toLocaleString() }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="pongRecv" label="pongRecv" min-width="130" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
{{ scope.row.pongRecv == 0 ? 0 : new Date(parseInt(scope.row.pongRecv)).toLocaleString() }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="configEpoch" label="configEpoch" min-width="130">
|
||||
<template #header>
|
||||
configEpoch
|
||||
<el-tooltip
|
||||
class="box-item"
|
||||
effect="dark"
|
||||
content="节点的epoch值(如果该节点是从节点,则为其主节点的epoch值)。每当节点发生失败切换时,都会创建一个新的,独特的,递增的epoch。"
|
||||
placement="top"
|
||||
>
|
||||
<el-icon><question-filled /></el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="linkState" label="linkState" min-width="100"></el-table-column>
|
||||
<el-table-column prop="slot" label="slot" min-width="100"></el-table-column>
|
||||
</el-table>
|
||||
</el-dialog>
|
||||
|
||||
<redis-edit
|
||||
@val-change="valChange"
|
||||
:projects="projects"
|
||||
@@ -92,6 +170,12 @@ export default defineComponent({
|
||||
redisInfo: {
|
||||
url: '',
|
||||
},
|
||||
clusterInfoDialog: {
|
||||
visible: false,
|
||||
redisId: 0,
|
||||
info: '',
|
||||
nodes: [],
|
||||
},
|
||||
clusters: [
|
||||
{
|
||||
id: 0,
|
||||
@@ -118,7 +202,7 @@ export default defineComponent({
|
||||
|
||||
onMounted(async () => {
|
||||
search();
|
||||
state.projects = (await projectApi.projects.request({ pageNum: 1, pageSize: 100 })).list;
|
||||
state.projects = await projectApi.accountProjects.request(null);
|
||||
});
|
||||
|
||||
const handlePageChange = (curPage: number) => {
|
||||
@@ -134,12 +218,6 @@ export default defineComponent({
|
||||
state.currentData = item;
|
||||
};
|
||||
|
||||
// connect() {
|
||||
// Req.post('/open/redis/connect', this.form, res => {
|
||||
// this.redisInfo = res
|
||||
// })
|
||||
// }
|
||||
|
||||
const deleteRedis = async () => {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定删除该redis?`, '提示', {
|
||||
@@ -155,12 +233,23 @@ export default defineComponent({
|
||||
} catch (err) {}
|
||||
};
|
||||
|
||||
const info = (redis: any) => {
|
||||
redisApi.redisInfo.request({ id: redis.id }).then((res: any) => {
|
||||
state.infoDialog.info = res;
|
||||
state.infoDialog.title = `'${redis.host}' info`;
|
||||
state.infoDialog.visible = true;
|
||||
});
|
||||
const info = async (redis: any) => {
|
||||
var host = redis.host;
|
||||
if (redis.ip) {
|
||||
host = redis.ip.split('@')[0];
|
||||
}
|
||||
const res = await redisApi.redisInfo.request({ id: redis.id, host });
|
||||
state.infoDialog.info = res;
|
||||
state.infoDialog.title = `'${host}' info`;
|
||||
state.infoDialog.visible = true;
|
||||
};
|
||||
|
||||
const onShowClusterInfo = async (redis: any) => {
|
||||
const ci = await redisApi.clusterInfo.request({ id: redis.id });
|
||||
state.clusterInfoDialog.info = ci.clusterInfo;
|
||||
state.clusterInfoDialog.nodes = ci.clusterNodes;
|
||||
state.clusterInfoDialog.redisId = redis.id;
|
||||
state.clusterInfoDialog.visible = true;
|
||||
};
|
||||
|
||||
const search = async () => {
|
||||
@@ -192,6 +281,7 @@ export default defineComponent({
|
||||
handlePageChange,
|
||||
choose,
|
||||
info,
|
||||
onShowClusterInfo,
|
||||
deleteRedis,
|
||||
editRedis,
|
||||
valChange,
|
||||
|
||||
@@ -3,10 +3,11 @@ import Api from '@/common/Api';
|
||||
export const redisApi = {
|
||||
redisList : Api.create("/redis", 'get'),
|
||||
redisInfo: Api.create("/redis/{id}/info", 'get'),
|
||||
clusterInfo: Api.create("/redis/{id}/cluster-info", 'get'),
|
||||
saveRedis: Api.create("/redis", 'post'),
|
||||
delRedis: Api.create("/redis/{id}", 'delete'),
|
||||
// 获取权限列表
|
||||
scan: Api.create("/redis/{id}/scan/{cursor}/{count}", 'get'),
|
||||
scan: Api.create("/redis/{id}/scan", 'post'),
|
||||
getStringValue: Api.create("/redis/{id}/string-value", 'get'),
|
||||
saveStringValue: Api.create("/redis/{id}/string-value", 'post'),
|
||||
getHashValue: Api.create("/redis/{id}/hash-value", 'get'),
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<template>
|
||||
<div class="account-dialog">
|
||||
<el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :show-close="false" width="35%">
|
||||
<el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :show-close="false" width="35%" :destroy-on-close="true">
|
||||
<el-form :model="form" ref="accountForm" :rules="rules" label-width="85px">
|
||||
<el-form-item prop="username" label="用户名:" required>
|
||||
<el-input :disabled="edit" v-model.trim="form.username" placeholder="请输入账号用户名" auto-complete="off"></el-input>
|
||||
<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-input type="password" v-model.trim="form.password" placeholder="请输入密码" autocomplete="new-password"></el-input>
|
||||
@@ -105,15 +105,7 @@ export default defineComponent({
|
||||
|
||||
const cancel = () => {
|
||||
emit('update:visible', false);
|
||||
setTimeout(() => {
|
||||
emit('update:account', null);
|
||||
}, 800);
|
||||
emit('cancel');
|
||||
setTimeout(() => {
|
||||
accountForm.value.resetFields();
|
||||
// 重置对象属性为null
|
||||
state.form = {} as any;
|
||||
}, 200);
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@@ -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:update'" :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
|
||||
>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="account-dialog">
|
||||
<el-dialog
|
||||
:title="account == null ? '' : '分配“' + account.username + '”的角色'"
|
||||
v-model="visible"
|
||||
v-model="dialogVisible"
|
||||
:before-close="cancel"
|
||||
:show-close="false"
|
||||
>
|
||||
@@ -15,7 +15,7 @@
|
||||
<el-table :data="allRole" border ref="roleTable" @select="select" style="width: 100%">
|
||||
<el-table-column :selectable="selectable" type="selection" width="40"></el-table-column>
|
||||
<el-table-column prop="name" label="角色名称"></el-table-column>
|
||||
<el-table-column prop="code" label="角色code"></el-table-column>
|
||||
<el-table-column prop="code" label="角色code"></el-table-column>
|
||||
<el-table-column prop="remark" label="角色描述">
|
||||
<template #default="scope">
|
||||
{{ scope.row.remark ? scope.row.remark : '暂无描述' }}
|
||||
@@ -59,7 +59,7 @@ export default defineComponent({
|
||||
setup(props: any, { emit }) {
|
||||
const roleTable: any = ref(null);
|
||||
const state = reactive({
|
||||
visible: false,
|
||||
dialogVisible: false,
|
||||
btnLoading: false,
|
||||
// 所有角色
|
||||
allRole: [] as any,
|
||||
@@ -73,8 +73,8 @@ export default defineComponent({
|
||||
total: 0,
|
||||
});
|
||||
|
||||
watch(props, (newValue, oldValue) => {
|
||||
state.visible = newValue.visible;
|
||||
watch(props, (newValue) => {
|
||||
state.dialogVisible = newValue.visible;
|
||||
if (newValue.account && newValue.account.id != 0) {
|
||||
accountApi.roleIds
|
||||
.request({
|
||||
|
||||
@@ -33,5 +33,5 @@ export const accountApi = {
|
||||
}
|
||||
|
||||
export const logApi = {
|
||||
list: Api.create("/sys/logs", "get")
|
||||
list: Api.create("/syslogs", "get")
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<el-row :gutter="10">
|
||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb10">
|
||||
<el-form-item prop="type" label="类型" required>
|
||||
<el-select v-model="form.type" :disabled="typeDisabled" placeholder="请选择" width="w100">
|
||||
<el-select v-model="form.type" :disabled="typeDisabled" placeholder="请选择" >
|
||||
<el-option v-for="item in enums.ResourceTypeEnum" :key="item.value" :label="item.label" :value="item.value">
|
||||
</el-option>
|
||||
</el-select>
|
||||
@@ -83,7 +83,7 @@
|
||||
</el-form>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer mt10">
|
||||
<div>
|
||||
<el-button @click="cancel()">取 消</el-button>
|
||||
<el-button type="primary" :loading="btnLoading" @click="btnOk">确 定</el-button>
|
||||
</div>
|
||||
@@ -284,11 +284,6 @@ export default defineComponent({
|
||||
const cancel = () => {
|
||||
emit('update:visible', false);
|
||||
emit('cancel');
|
||||
setTimeout(() => {
|
||||
menuForm.value.resetFields();
|
||||
// 重置对象属性为null
|
||||
state.form = {} as any;
|
||||
}, 200);
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@@ -109,9 +109,7 @@ export default defineComponent({
|
||||
const cancel = () => {
|
||||
// 更新父组件visible prop对应的值为false
|
||||
emit('update:visible', false);
|
||||
setTimeout(() => {
|
||||
emit('cancel');
|
||||
}, 700);
|
||||
emit('cancel');
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
<template>
|
||||
<div class="role-dialog">
|
||||
<el-dialog :title="title" v-model="dvisible" :show-close="false" :before-close="cancel" width="500px">
|
||||
<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-item prop="name" label="角色名称:" required>
|
||||
<el-input v-model="form.name" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="code" label="角色code:" required>
|
||||
<el-input :disabled="form.id != null" v-model="form.code" placeholder="COMMON开头则为所有账号共有角色" auto-complete="off"></el-input>
|
||||
<el-input
|
||||
:disabled="form.id != null"
|
||||
v-model="form.code"
|
||||
placeholder="COMMON开头则为所有账号共有角色"
|
||||
auto-complete="off"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="角色描述:">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="3" placeholder="请输入角色描述"></el-input>
|
||||
|
||||
@@ -10,15 +10,14 @@
|
||||
|
||||
<div style="float: right">
|
||||
<el-input
|
||||
placeholder="请输入角色名称!"
|
||||
placeholder="请输入角色名称"
|
||||
class="mr2"
|
||||
size="small"
|
||||
style="width: 300px"
|
||||
style="width: 200px"
|
||||
v-model="query.name"
|
||||
@clear="search"
|
||||
clearable
|
||||
></el-input>
|
||||
<el-button @click="search" type="success" icon="search" size="small"></el-button>
|
||||
<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">
|
||||
|
||||
103
mayfly_go_web/src/views/system/syslog/SyslogList.vue
Executable file
103
mayfly_go_web/src/views/system/syslog/SyslogList.vue
Executable file
@@ -0,0 +1,103 @@
|
||||
<template>
|
||||
<div class="role-list">
|
||||
<el-card>
|
||||
<div style="float: right">
|
||||
<el-select
|
||||
remote
|
||||
:remote-method="getAccount"
|
||||
v-model="query.creatorId"
|
||||
filterable
|
||||
placeholder="请输入并选择账号"
|
||||
clearable
|
||||
class="mr5"
|
||||
>
|
||||
<el-option v-for="item in accounts" :key="item.id" :label="item.username" :value="item.id"> </el-option>
|
||||
</el-select>
|
||||
<el-select v-model="query.type" filterable placeholder="请选择操作结果" clearable class="mr5">
|
||||
<el-option label="成功" :value="1"> </el-option>
|
||||
<el-option label="失败" :value="2"> </el-option>
|
||||
</el-select>
|
||||
<el-button @click="search" type="success" icon="search"></el-button>
|
||||
</div>
|
||||
<el-table :data="logs" style="width: 100%">
|
||||
<el-table-column prop="creator" label="操作人" min-width="100" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="createTime" label="操作时间" min-width="160">
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="type" label="结果" min-width="65">
|
||||
<template #default="scope">
|
||||
<el-tag v-if="scope.row.type == 1" type="success" size="small">成功</el-tag>
|
||||
<el-tag v-if="scope.row.type == 2" type="danger" size="small">失败</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="description" label="描述" min-width="160" show-overflow-tooltip></el-table-column>
|
||||
|
||||
<el-table-column prop="reqParam" label="请求信息" min-width="300" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="resp" label="响应信息" min-width="200" 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>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, onMounted, defineComponent } from 'vue';
|
||||
import { logApi, accountApi } from '../api';
|
||||
export default defineComponent({
|
||||
name: 'SyslogList',
|
||||
components: {},
|
||||
setup() {
|
||||
const state = reactive({
|
||||
query: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
name: null,
|
||||
},
|
||||
total: 0,
|
||||
logs: [],
|
||||
accounts: [],
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
search();
|
||||
});
|
||||
|
||||
const search = async () => {
|
||||
let res = await logApi.list.request(state.query);
|
||||
state.logs = res.list;
|
||||
state.total = res.total;
|
||||
};
|
||||
|
||||
const handlePageChange = (curPage: number) => {
|
||||
state.query.pageNum = curPage;
|
||||
search();
|
||||
};
|
||||
|
||||
const getAccount = (username: any) => {
|
||||
accountApi.list.request({ username }).then((res) => {
|
||||
state.accounts = res.list;
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
search,
|
||||
handlePageChange,
|
||||
getAccount,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
</style>
|
||||
@@ -30,7 +30,6 @@ const viteConfig: UserConfig = {
|
||||
target: 'http://localhost:8888',
|
||||
ws: true,
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/api/, '/'),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
app:
|
||||
name: mayfly-go
|
||||
version: 1.0.0
|
||||
version: 1.2.0
|
||||
|
||||
server:
|
||||
# debug release test
|
||||
@@ -29,10 +29,6 @@ jwt:
|
||||
# 过期时间单位分钟
|
||||
expire-time: 1440
|
||||
|
||||
redis:
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
|
||||
mysql:
|
||||
host: localhost:3306
|
||||
username: root
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEpgIBAAKCAQEA0CsawvEZl42Vf+0BlTuZ3Dp10yW8Oty1tjimxUj3s0WPeKil
|
||||
6+TehnQELS8vGJfek+yT99nyrt+bkRmg1kxZ57FtQFEuthG4OQZoaMDUz6Ab+8P1
|
||||
PQ9VH0XimnnYabxztJiQjl8HdJt6N4WP35kGlcul7qQ+Qc7iwjhSadfAhXVycqVI
|
||||
cGQyHiPPfbmYRjueAIC4czmMUxwFKCwjepGYkwzWuGkpMD0hg/SIXpFJE2dcqYPR
|
||||
2nCah1gxZZG00lHU1X2pehNmmgeHRkB5S7mrsCdyyV/33SAYk6T6PT7dOqY54bfn
|
||||
h3C0k+T7IzvKTXKG76eG63STmxVa6luVoKMvxwIDAQABAoIBAQCI2Y2CUpYMd9us
|
||||
edbskH4ZtaT35nrUB3y+Cog4cjvE8xnarKRHa/KOWX7VZYuEk3KTtJeh/Pn51K6k
|
||||
uUBvIUqJcq7r9XLL5uJBOuEw3HQK+qrq3GxAc+/12y+Zdji7alR2iUWfEwIHup6i
|
||||
GX/38tXNbE/tjrQO9z9Dh1tGkbvS/66tPn/T/oMxsRvZB6mCjB7yuOlEIwYTomYB
|
||||
pUFemELt8T5RtfxRa8T1VoITbfuj7zvecqlThW0H8UizsFxvrOCUaga7jtsJOCHo
|
||||
bcW5WvWwazoOfQ2BGpksKkBDf1N6pj85e4kOoYcVG9UN03ZwDvAGfQPWUlHB4YzW
|
||||
PybMwIQBAoGBAPfuOQ+ukVmkiEKj6wCBe3Z0pYeNqBGec9aj62bKFh79BCE3ZopS
|
||||
7JtGs8VfBKkBAaOy+MDuvJ2fvRNRtHT4BYe1U6ZRsmVFqHScACOaO/7TR0tz0ihL
|
||||
0QLCkbSwsXExG6bYbwP4jMHkhHArT7Hy8WXvup8PffjSiEs1A1uGvYSBAoGBANbx
|
||||
lHo+39nsc1OO8TUAWZChIQUib2hFIwzQYngSzINdfXQaGFT/omOsudAtfdjvp+qO
|
||||
Tr7WpwgFEFveDFsdJfZ2Kc2x9a3ty7IYIWaAjK2ghkAKz3Tt4gClreB6qG2SBycP
|
||||
4C2ImbY6hMaFHz3ENtTEzzTMdD1ByxQVMvoem3BHAoGBAJdaTmtMXl8jGivUdXnx
|
||||
kbVWsFZ4G8nluUGm/+XYKHjybLr6XxbCWL7SApzSzL1/Z8jPURw2od53za0li8x8
|
||||
PKQEBfTamtVIGPZW5Z7WYRnHURa2tezzm7zbmqd71lcLa54HMn5yFTuojVEMn7I6
|
||||
ZTOdjYfcpUJpA9slmc8eCkQBAoGBAJEIbxRRaoBEQMkH8Y++zbB+WKZ7RssHo4/Y
|
||||
6Ch3HtIg+i6mEPcBitRQzww+NeV0SExHe7Dfa9NIf3JNkO7F60CzGJ/3zXtvsftY
|
||||
tujQIpxhbVS3NqaCgPXI1VtbyFwupW7hEnYG7xj7wW2mk578z7afmeTZdDGFPH8v
|
||||
krccgeuvAoGBAPAwiqbZlXNx+ueI1B3T8VpXnG0ozKxG+l5B71kssZWa7xcv9yRd
|
||||
c15l2PSXNtnoT/mBID7+dqQOmfYxsDHAkUdd/BrxhXtdi9FR3AfHSEQz+VKsogAD
|
||||
uLyRd7jWTYqqGa2UToF/CBV+c6QyMB+6pzFNk5DmUEm4Gd6jcHDITYeI
|
||||
-----END RSA PRIVATE KEY-----
|
||||
@@ -1,21 +0,0 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDejCCAmICCQDQU4ZRt2G46TANBgkqhkiG9w0BAQsFADB/MQswCQYDVQQGEwJ6
|
||||
aDEPMA0GA1UECAwGbWF5Zmx5MQswCQYDVQQHDAJ4bTEPMA0GA1UECgwGbWF5Zmx5
|
||||
MQ8wDQYDVQQLDAZtYXlmbHkxDzANBgNVBAMMBm1heWZseTEfMB0GCSqGSIb3DQEJ
|
||||
ARYQOTU0NTM3NDczQHFxLmNvbTAeFw0yMTA2MjQwMzI2MzBaFw0zMTA2MjIwMzI2
|
||||
MzBaMH8xCzAJBgNVBAYTAnpoMQ8wDQYDVQQIDAZtYXlmbHkxCzAJBgNVBAcMAnht
|
||||
MQ8wDQYDVQQKDAZtYXlmbHkxDzANBgNVBAsMBm1heWZseTEPMA0GA1UEAwwGbWF5
|
||||
Zmx5MR8wHQYJKoZIhvcNAQkBFhA5NTQ1Mzc0NzNAcXEuY29tMIIBIjANBgkqhkiG
|
||||
9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0CsawvEZl42Vf+0BlTuZ3Dp10yW8Oty1tjim
|
||||
xUj3s0WPeKil6+TehnQELS8vGJfek+yT99nyrt+bkRmg1kxZ57FtQFEuthG4OQZo
|
||||
aMDUz6Ab+8P1PQ9VH0XimnnYabxztJiQjl8HdJt6N4WP35kGlcul7qQ+Qc7iwjhS
|
||||
adfAhXVycqVIcGQyHiPPfbmYRjueAIC4czmMUxwFKCwjepGYkwzWuGkpMD0hg/SI
|
||||
XpFJE2dcqYPR2nCah1gxZZG00lHU1X2pehNmmgeHRkB5S7mrsCdyyV/33SAYk6T6
|
||||
PT7dOqY54bfnh3C0k+T7IzvKTXKG76eG63STmxVa6luVoKMvxwIDAQABMA0GCSqG
|
||||
SIb3DQEBCwUAA4IBAQB/e8EO2XEtkYBxebR1w6i50vaegLsxQJR3l5qm7rsHu3Cr
|
||||
smJXGsc56axKCAqJ4XvSI65BT51FghAoGn62QNyiQgc0YoS99nwCCGFtnhZ2lmSe
|
||||
pfhUHegN/Qo4I8FemEMD+o9kGeAzwrnaIVIT/cNOEQgm+RzrgHHJh5QBn2XgJalU
|
||||
NeFTWaimyefwSezSa/vPbyMoAl9HkT6kdvnms/yOth4AOle6+5pM2StWjmMi4yx4
|
||||
16y3NvLTku6nAUazaHTOOu/MCqLWL2/qYTk3r7OCop2jr9Rp+HLbg5AfKLUIVXjG
|
||||
/1fnXJIuD+2u9qgDLN5PZNgz4MlU86ugtmYPFkVt
|
||||
-----END CERTIFICATE-----
|
||||
@@ -1,216 +0,0 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/base/ginx"
|
||||
"mayfly-go/base/utils"
|
||||
"mayfly-go/server/devops/api/form"
|
||||
"mayfly-go/server/devops/api/vo"
|
||||
"mayfly-go/server/devops/application"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Redis struct {
|
||||
RedisApp application.Redis
|
||||
ProjectApp application.Project
|
||||
}
|
||||
|
||||
func (r *Redis) RedisList(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
m := &entity.Redis{EnvId: uint64(ginx.QueryInt(g, "envId", 0)),
|
||||
ProjectId: uint64(ginx.QueryInt(g, "projectId", 0)),
|
||||
}
|
||||
m.CreatorId = rc.LoginAccount.Id
|
||||
rc.ResData = r.RedisApp.GetPageList(m, ginx.GetPageParam(rc.GinCtx), new([]vo.Redis))
|
||||
}
|
||||
|
||||
func (r *Redis) Save(rc *ctx.ReqCtx) {
|
||||
form := &form.Redis{}
|
||||
ginx.BindJsonAndValid(rc.GinCtx, form)
|
||||
|
||||
rc.ReqParam = form
|
||||
|
||||
redis := new(entity.Redis)
|
||||
utils.Copy(redis, form)
|
||||
redis.SetBaseInfo(rc.LoginAccount)
|
||||
r.RedisApp.Save(redis)
|
||||
}
|
||||
|
||||
func (r *Redis) DeleteRedis(rc *ctx.ReqCtx) {
|
||||
r.RedisApp.Delete(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
|
||||
}
|
||||
|
||||
func (r *Redis) RedisInfo(rc *ctx.ReqCtx) {
|
||||
res, _ := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(rc.GinCtx, "id"))).Cli.Info().Result()
|
||||
|
||||
datas := strings.Split(res, "\r\n")
|
||||
i := 0
|
||||
length := len(datas)
|
||||
|
||||
parseMap := make(map[string]map[string]string)
|
||||
for {
|
||||
if i >= length {
|
||||
break
|
||||
}
|
||||
if strings.Contains(datas[i], "#") {
|
||||
key := utils.SubString(datas[i], strings.Index(datas[i], "#")+1, utils.StrLen(datas[i]))
|
||||
i++
|
||||
key = strings.Trim(key, " ")
|
||||
|
||||
sectionMap := make(map[string]string)
|
||||
for {
|
||||
if i >= length || !strings.Contains(datas[i], ":") {
|
||||
break
|
||||
}
|
||||
pair := strings.Split(datas[i], ":")
|
||||
i++
|
||||
if len(pair) != 2 {
|
||||
continue
|
||||
}
|
||||
sectionMap[pair[0]] = pair[1]
|
||||
}
|
||||
parseMap[key] = sectionMap
|
||||
} else {
|
||||
i++
|
||||
}
|
||||
}
|
||||
rc.ResData = parseMap
|
||||
}
|
||||
|
||||
// scan获取redis的key列表信息
|
||||
func (r *Redis) Scan(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
|
||||
ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")))
|
||||
biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
|
||||
|
||||
keys, cursor := ri.Scan(uint64(ginx.PathParamInt(g, "cursor")), g.Query("match"), int64(ginx.PathParamInt(g, "count")))
|
||||
|
||||
var keyInfoSplit []string
|
||||
if len(keys) > 0 {
|
||||
keyInfoLua := `
|
||||
local result = {}
|
||||
-- KEYS[1]为第1个参数,lua数组下标从1开始
|
||||
local ttl = redis.call('ttl', KEYS[1]);
|
||||
local keyType = redis.call('type', KEYS[1]);
|
||||
for i = 1, #KEYS do
|
||||
local ttl = redis.call('ttl', KEYS[i]);
|
||||
local keyType = redis.call('type', KEYS[i]);
|
||||
table.insert(result, string.format("%d,%s", ttl, keyType['ok']));
|
||||
end;
|
||||
return table.concat(result, ".");`
|
||||
// 通过lua获取 ttl,type.ttl2,type2格式,以便下面切割获取ttl和type。避免多次调用ttl和type函数
|
||||
keyInfos, _ := ri.Cli.Eval(keyInfoLua, keys).Result()
|
||||
keyInfoSplit = strings.Split(keyInfos.(string), ".")
|
||||
}
|
||||
|
||||
kis := make([]*vo.KeyInfo, 0)
|
||||
for i, k := range keys {
|
||||
ttlType := strings.Split(keyInfoSplit[i], ",")
|
||||
ttl, _ := strconv.Atoi(ttlType[0])
|
||||
ki := &vo.KeyInfo{Key: k, Type: ttlType[1], Ttl: int64(ttl)}
|
||||
kis = append(kis, ki)
|
||||
}
|
||||
|
||||
size, _ := ri.Cli.DBSize().Result()
|
||||
rc.ResData = &vo.Keys{Cursor: cursor, Keys: kis, DbSize: size}
|
||||
}
|
||||
|
||||
func (r *Redis) DeleteKey(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
key := g.Query("key")
|
||||
biz.NotEmpty(key, "key不能为空")
|
||||
|
||||
ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")))
|
||||
biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
|
||||
|
||||
rc.ReqParam = key
|
||||
ri.Cli.Del(key)
|
||||
}
|
||||
|
||||
func (r *Redis) checkKey(rc *ctx.ReqCtx) (*application.RedisInstance, string) {
|
||||
g := rc.GinCtx
|
||||
key := g.Query("key")
|
||||
biz.NotEmpty(key, "key不能为空")
|
||||
|
||||
ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")))
|
||||
biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
|
||||
|
||||
return ri, key
|
||||
}
|
||||
|
||||
func (r *Redis) GetStringValue(rc *ctx.ReqCtx) {
|
||||
ri, key := r.checkKey(rc)
|
||||
str, err := ri.Cli.Get(key).Result()
|
||||
biz.ErrIsNilAppendErr(err, "获取字符串值失败: %s")
|
||||
rc.ResData = str
|
||||
}
|
||||
|
||||
func (r *Redis) GetHashValue(rc *ctx.ReqCtx) {
|
||||
ri, key := r.checkKey(rc)
|
||||
res, err := ri.Cli.HGetAll(key).Result()
|
||||
biz.ErrIsNilAppendErr(err, "获取hash值失败: %s")
|
||||
rc.ResData = res
|
||||
}
|
||||
|
||||
func (r *Redis) SetStringValue(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
keyValue := new(form.StringValue)
|
||||
ginx.BindJsonAndValid(g, keyValue)
|
||||
|
||||
ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")))
|
||||
biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
|
||||
|
||||
str, err := ri.Cli.Set(keyValue.Key, keyValue.Value, time.Second*time.Duration(keyValue.Timed)).Result()
|
||||
biz.ErrIsNilAppendErr(err, "保存字符串值失败: %s")
|
||||
rc.ResData = str
|
||||
}
|
||||
|
||||
func (r *Redis) SetHashValue(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
hashValue := new(form.HashValue)
|
||||
ginx.BindJsonAndValid(g, hashValue)
|
||||
|
||||
ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")))
|
||||
biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
|
||||
|
||||
key := hashValue.Key
|
||||
// 简单处理->先删除,后新增
|
||||
ri.Cli.Del(key)
|
||||
for _, v := range hashValue.Value {
|
||||
res := ri.Cli.HSet(key, v["key"].(string), v["value"])
|
||||
biz.ErrIsNilAppendErr(res.Err(), "保存hash值失败: %s")
|
||||
}
|
||||
if hashValue.Timed != -1 {
|
||||
ri.Cli.Expire(key, time.Second*time.Duration(hashValue.Timed))
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Redis) GetSetValue(rc *ctx.ReqCtx) {
|
||||
ri, key := r.checkKey(rc)
|
||||
res, err := ri.Cli.SMembers(key).Result()
|
||||
biz.ErrIsNilAppendErr(err, "获取set值失败: %s")
|
||||
rc.ResData = res
|
||||
}
|
||||
|
||||
func (r *Redis) SetSetValue(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
keyvalue := new(form.SetValue)
|
||||
ginx.BindJsonAndValid(g, keyvalue)
|
||||
|
||||
ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")))
|
||||
biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
|
||||
|
||||
key := keyvalue.Key
|
||||
// 简单处理->先删除,后新增
|
||||
ri.Cli.Del(key)
|
||||
ri.Cli.SAdd(key, keyvalue.Value...)
|
||||
|
||||
if keyvalue.Timed != -1 {
|
||||
ri.Cli.Expire(key, time.Second*time.Duration(keyvalue.Timed))
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,37 @@
|
||||
module mayfly-go
|
||||
|
||||
go 1.17
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible // jwt
|
||||
github.com/gin-gonic/gin v1.7.7
|
||||
github.com/go-redis/redis v6.15.9+incompatible
|
||||
github.com/gin-gonic/gin v1.8.1
|
||||
github.com/go-redis/redis/v8 v8.11.5
|
||||
github.com/gorilla/websocket v1.5.0
|
||||
github.com/lib/pq v1.10.6
|
||||
github.com/mojocn/base64Captcha v1.3.5 // 验证码
|
||||
github.com/pkg/sftp v1.13.4
|
||||
github.com/pkg/sftp v1.13.5
|
||||
github.com/robfig/cron/v3 v3.0.1 // 定时任务
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
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-20220314234724-5d542ad81a58 // ssh
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // ssh
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
||||
// gorm
|
||||
gorm.io/driver/mysql v1.3.2
|
||||
gorm.io/gorm v1.23.2
|
||||
gorm.io/driver/mysql v1.3.4
|
||||
gorm.io/gorm v1.23.5
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-playground/locales v0.14.0 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||
github.com/go-playground/validator/v10 v10.10.1 // indirect
|
||||
github.com/go-sql-driver/mysql v1.6.0 // indirect
|
||||
github.com/go-stack/stack v1.8.0 // indirect
|
||||
github.com/goccy/go-json v0.9.7 // indirect
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/golang/snappy v0.0.1 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.4 // indirect
|
||||
@@ -38,8 +42,7 @@ require (
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/onsi/ginkgo v1.16.5 // indirect
|
||||
github.com/onsi/gomega v1.18.1 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.7 // indirect
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||
@@ -47,9 +50,11 @@ require (
|
||||
github.com/xdg-go/stringprep v1.0.2 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
||||
golang.org/x/image v0.0.0-20220302094943-723b81ca9867 // indirect
|
||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 // indirect
|
||||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
google.golang.org/protobuf v1.27.1 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
google.golang.org/protobuf v1.28.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
@@ -2,11 +2,11 @@ package initialize
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/base/config"
|
||||
"mayfly-go/base/middleware"
|
||||
common_index_router "mayfly-go/server/common/router"
|
||||
devops_router "mayfly-go/server/devops/router"
|
||||
sys_router "mayfly-go/server/sys/router"
|
||||
common_router "mayfly-go/internal/common/router"
|
||||
devops_router "mayfly-go/internal/devops/router"
|
||||
sys_router "mayfly-go/internal/sys/router"
|
||||
"mayfly-go/pkg/config"
|
||||
"mayfly-go/pkg/middleware"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -46,16 +46,19 @@ func InitRouter() *gin.Engine {
|
||||
// 设置路由组
|
||||
api := router.Group("/api")
|
||||
{
|
||||
common_index_router.InitIndexRouter(api)
|
||||
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)
|
||||
|
||||
devops_router.InitProjectRouter(api)
|
||||
devops_router.InitDbRouter(api)
|
||||
devops_router.InitDbSqlExecRouter(api)
|
||||
devops_router.InitRedisRouter(api)
|
||||
devops_router.InitMachineRouter(api)
|
||||
devops_router.InitMachineScriptRouter(api)
|
||||
|
||||
10
server/initialize/savelog.go
Normal file
10
server/initialize/savelog.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
sys_application "mayfly-go/internal/sys/application"
|
||||
"mayfly-go/pkg/ctx"
|
||||
)
|
||||
|
||||
func InitSaveLogFunc() ctx.SaveLogFunc {
|
||||
return sys_application.SyslogApp.SaveFromReq
|
||||
}
|
||||
16
server/internal/common/api/common.go
Normal file
16
server/internal/common/api/common.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"mayfly-go/pkg/utils"
|
||||
)
|
||||
|
||||
type Common struct {
|
||||
}
|
||||
|
||||
func (i *Common) RasPublicKey(rc *ctx.ReqCtx) {
|
||||
publicKeyStr, err := utils.GetRsaPublicKey()
|
||||
biz.ErrIsNilAppendErr(err, "rsa生成公私钥失败")
|
||||
rc.ResData = publicKeyStr
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/server/devops/application"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/pkg/ctx"
|
||||
)
|
||||
|
||||
type Index struct {
|
||||
21
server/internal/common/router/common.go
Normal file
21
server/internal/common/router/common.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/common/api"
|
||||
"mayfly-go/pkg/ctx"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func InitCommonRouter(router *gin.RouterGroup) {
|
||||
common := router.Group("common")
|
||||
c := &api.Common{}
|
||||
{
|
||||
// 获取公钥
|
||||
common.GET("public-key", func(g *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(g).
|
||||
WithNeedToken(false).
|
||||
Handle(c.RasPublicKey)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/server/common/api"
|
||||
devops_app "mayfly-go/server/devops/application"
|
||||
"mayfly-go/internal/common/api"
|
||||
devops_app "mayfly-go/internal/devops/application"
|
||||
"mayfly-go/pkg/ctx"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -2,30 +2,35 @@ package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/base/ginx"
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/base/utils"
|
||||
"mayfly-go/base/ws"
|
||||
"mayfly-go/server/devops/api/form"
|
||||
"mayfly-go/server/devops/api/vo"
|
||||
"mayfly-go/server/devops/application"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
sysApplication "mayfly-go/server/sys/application"
|
||||
"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/pkg/biz"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"mayfly-go/pkg/ginx"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/utils"
|
||||
"mayfly-go/pkg/ws"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/xwb1989/sqlparser"
|
||||
)
|
||||
|
||||
type Db struct {
|
||||
DbApp application.Db
|
||||
MsgApp sysApplication.Msg
|
||||
ProjectApp application.Project
|
||||
DbApp application.Db
|
||||
DbSqlExecApp application.DbSqlExec
|
||||
MsgApp sysApplication.Msg
|
||||
ProjectApp application.Project
|
||||
}
|
||||
|
||||
const DEFAULT_COLUMN_SIZE = 500
|
||||
|
||||
// @router /api/dbs [get]
|
||||
func (d *Db) Dbs(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
@@ -40,16 +45,27 @@ func (d *Db) Save(rc *ctx.ReqCtx) {
|
||||
form := &form.DbForm{}
|
||||
ginx.BindJsonAndValid(rc.GinCtx, form)
|
||||
|
||||
rc.ReqParam = form
|
||||
|
||||
db := new(entity.Db)
|
||||
utils.Copy(db, form)
|
||||
|
||||
// 密码解密,并使用解密后的赋值
|
||||
originPwd, err := utils.DefaultRsaDecrypt(form.Password, true)
|
||||
biz.ErrIsNilAppendErr(err, "解密密码错误: %s")
|
||||
db.Password = originPwd
|
||||
|
||||
// 密码脱敏记录日志
|
||||
form.Password = "****"
|
||||
rc.ReqParam = form
|
||||
|
||||
db.SetBaseInfo(rc.LoginAccount)
|
||||
d.DbApp.Save(db)
|
||||
}
|
||||
|
||||
func (d *Db) DeleteDb(rc *ctx.ReqCtx) {
|
||||
d.DbApp.Delete(GetDbId(rc.GinCtx))
|
||||
dbId := GetDbId(rc.GinCtx)
|
||||
d.DbApp.Delete(dbId)
|
||||
// 删除该库的sql执行记录
|
||||
d.DbSqlExecApp.DeleteBy(&entity.DbSqlExec{DbId: dbId})
|
||||
}
|
||||
|
||||
func (d *Db) TableInfos(rc *ctx.ReqCtx) {
|
||||
@@ -68,23 +84,26 @@ func (d *Db) GetCreateTableDdl(rc *ctx.ReqCtx) {
|
||||
rc.ResData = d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx)).GetCreateTableDdl(tn)
|
||||
}
|
||||
|
||||
// @router /api/db/:dbId/exec-sql [get]
|
||||
func (d *Db) ExecSql(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
form := &form.DbSqlExecForm{}
|
||||
ginx.BindJsonAndValid(g, form)
|
||||
|
||||
id, db := GetIdAndDb(g)
|
||||
id := GetDbId(g)
|
||||
db := form.Db
|
||||
dbInstance := d.DbApp.GetDbInstance(id, db)
|
||||
biz.ErrIsNilAppendErr(d.ProjectApp.CanAccess(rc.LoginAccount.Id, dbInstance.ProjectId), "%s")
|
||||
|
||||
// 去除前后空格及换行符
|
||||
sql := strings.TrimFunc(g.Query("sql"), func(r rune) bool {
|
||||
sql := strings.TrimFunc(form.Sql, func(r rune) bool {
|
||||
s := string(r)
|
||||
return s == " " || s == "\n"
|
||||
})
|
||||
|
||||
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") {
|
||||
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{})
|
||||
@@ -92,6 +111,9 @@ func (d *Db) ExecSql(rc *ctx.ReqCtx) {
|
||||
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)
|
||||
@@ -104,6 +126,11 @@ func (d *Db) ExecSql(rc *ctx.ReqCtx) {
|
||||
colAndRes["res"] = res
|
||||
|
||||
rc.ResData = colAndRes
|
||||
// 保存sql执行记录
|
||||
if res[0]["影响条数"] > "0" {
|
||||
execRecord.Remark = form.Remark
|
||||
d.DbSqlExecApp.Save(execRecord)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,14 +140,12 @@ func (d *Db) ExecSqlFile(rc *ctx.ReqCtx) {
|
||||
fileheader, err := g.FormFile("file")
|
||||
biz.ErrIsNilAppendErr(err, "读取sql文件失败: %s")
|
||||
|
||||
// 读取sql文件并根据;切割sql语句
|
||||
file, _ := fileheader.Open()
|
||||
filename := fileheader.Filename
|
||||
bytes, _ := ioutil.ReadAll(file)
|
||||
sqlContent := string(bytes)
|
||||
sqls := strings.Split(sqlContent, ";")
|
||||
dbId, db := GetIdAndDb(g)
|
||||
|
||||
rc.ReqParam = fmt.Sprintf("dbId: %d, db: %s, filename: %s", dbId, db, filename)
|
||||
|
||||
go func() {
|
||||
db := d.DbApp.GetDbInstance(dbId, db)
|
||||
|
||||
@@ -138,12 +163,14 @@ func (d *Db) ExecSqlFile(rc *ctx.ReqCtx) {
|
||||
|
||||
biz.ErrIsNilAppendErr(d.ProjectApp.CanAccess(rc.LoginAccount.Id, db.ProjectId), "%s")
|
||||
|
||||
for _, sql := range sqls {
|
||||
sql = strings.Trim(sql, " ")
|
||||
if sql == "" || sql == "\n" {
|
||||
continue
|
||||
tokens := sqlparser.NewTokenizer(file)
|
||||
for {
|
||||
stmt, err := sqlparser.ParseNext(tokens)
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
_, err := db.Exec(sql)
|
||||
sql := sqlparser.String(stmt)
|
||||
_, err = db.Exec(sql)
|
||||
if err != nil {
|
||||
d.MsgApp.CreateAndSend(rc.LoginAccount, ws.ErrMsg("sql脚本执行失败", fmt.Sprintf("[%s]%s执行失败: [%s]", filename, dbInfo, err.Error())))
|
||||
return
|
||||
@@ -153,6 +180,97 @@ func (d *Db) ExecSqlFile(rc *ctx.ReqCtx) {
|
||||
}()
|
||||
}
|
||||
|
||||
// 数据库dump
|
||||
func (d *Db) DumpSql(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
dbId, db := GetIdAndDb(g)
|
||||
dumpType := g.Query("type")
|
||||
tablesStr := g.Query("tables")
|
||||
biz.NotEmpty(tablesStr, "请选择要导出的表")
|
||||
tables := strings.Split(tablesStr, ",")
|
||||
|
||||
// 是否需要导出表结构
|
||||
needStruct := dumpType == "1" || dumpType == "3"
|
||||
// 是否需要导出数据
|
||||
needData := dumpType == "2" || dumpType == "3"
|
||||
|
||||
dbInstance := d.DbApp.GetDbInstance(dbId, db)
|
||||
biz.ErrIsNilAppendErr(d.ProjectApp.CanAccess(rc.LoginAccount.Id, dbInstance.ProjectId), "%s")
|
||||
|
||||
now := time.Now()
|
||||
filename := fmt.Sprintf("%s.%s.sql", db, now.Format("200601021504"))
|
||||
g.Header("Content-Type", "application/octet-stream")
|
||||
g.Header("Content-Disposition", "attachment; filename="+filename)
|
||||
|
||||
writer := g.Writer
|
||||
writer.WriteString("-- ----------------------------")
|
||||
writer.WriteString("\n-- 导出平台: mayfly-go")
|
||||
writer.WriteString(fmt.Sprintf("\n-- 导出时间: %s ", now.Format("2006-01-02 15:04:05")))
|
||||
writer.WriteString(fmt.Sprintf("\n-- 导出数据库: %s ", db))
|
||||
writer.WriteString("\n-- ----------------------------\n")
|
||||
|
||||
for _, table := range tables {
|
||||
if needStruct {
|
||||
writer.WriteString(fmt.Sprintf("\n-- ----------------------------\n-- 表结构: %s \n-- ----------------------------\n", table))
|
||||
writer.WriteString(fmt.Sprintf("DROP TABLE IF EXISTS `%s`;\n", table))
|
||||
writer.WriteString(dbInstance.GetCreateTableDdl(table)[0]["Create Table"].(string) + ";\n")
|
||||
}
|
||||
|
||||
if !needData {
|
||||
continue
|
||||
}
|
||||
|
||||
writer.WriteString(fmt.Sprintf("\n-- ----------------------------\n-- 表记录: %s \n-- ----------------------------\n", table))
|
||||
writer.WriteString("BEGIN;\n")
|
||||
|
||||
countSql := fmt.Sprintf("SELECT COUNT(*) count FROM %s", table)
|
||||
_, countRes, _ := dbInstance.SelectData(countSql)
|
||||
// 查询出所有列信息总数,手动分页获取所有数据
|
||||
maCount := int(countRes[0]["count"].(int64))
|
||||
// 计算需要查询的页数
|
||||
pageNum := maCount / DEFAULT_COLUMN_SIZE
|
||||
if maCount%DEFAULT_COLUMN_SIZE > 0 {
|
||||
pageNum++
|
||||
}
|
||||
|
||||
var sqlTmp string
|
||||
switch dbInstance.Type {
|
||||
case "mysql":
|
||||
sqlTmp = "SELECT * FROM %s LIMIT %d, %d"
|
||||
case "postgres":
|
||||
sqlTmp = "SELECT * FROM %s OFFSET %d LIMIT %d"
|
||||
}
|
||||
for index := 0; index < pageNum; index++ {
|
||||
sql := fmt.Sprintf(sqlTmp, table, index*DEFAULT_COLUMN_SIZE, DEFAULT_COLUMN_SIZE)
|
||||
columns, result, _ := dbInstance.SelectData(sql)
|
||||
|
||||
insertSql := "INSERT INTO `%s` VALUES (%s);\n"
|
||||
for _, res := range result {
|
||||
var values []string
|
||||
for _, column := range columns {
|
||||
value := res[column]
|
||||
if value == nil {
|
||||
values = append(values, "NULL")
|
||||
continue
|
||||
}
|
||||
strValue, ok := value.(string)
|
||||
if ok {
|
||||
values = append(values, fmt.Sprintf("%#v", strValue))
|
||||
} else {
|
||||
values = append(values, utils.ToString(value))
|
||||
}
|
||||
}
|
||||
writer.WriteString(fmt.Sprintf(insertSql, table, strings.Join(values, ", ")))
|
||||
}
|
||||
}
|
||||
|
||||
writer.WriteString("COMMIT;\n")
|
||||
}
|
||||
rc.NoRes = true
|
||||
|
||||
rc.ReqParam = fmt.Sprintf("dbId: %d, db: %s, tables: %s, dumpType: %s", dbId, db, tablesStr, dumpType)
|
||||
}
|
||||
|
||||
// @router /api/db/:dbId/t-metadata [get]
|
||||
func (d *Db) TableMA(rc *ctx.ReqCtx) {
|
||||
dbi := d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx))
|
||||
@@ -180,7 +298,7 @@ func (d *Db) HintTables(rc *ctx.ReqCtx) {
|
||||
|
||||
tableNames := make([]string, 0)
|
||||
for _, v := range tables {
|
||||
tableNames = append(tableNames, v["tableName"])
|
||||
tableNames = append(tableNames, v["tableName"].(string))
|
||||
}
|
||||
// key = 表名,value = 列名数组
|
||||
res := make(map[string][]string)
|
||||
@@ -194,7 +312,7 @@ func (d *Db) HintTables(rc *ctx.ReqCtx) {
|
||||
// 获取所有表下的所有列信息
|
||||
columnMds := dbi.GetColumnMetadatas(tableNames...)
|
||||
for _, v := range columnMds {
|
||||
tName := v["tableName"]
|
||||
tName := v["tableName"].(string)
|
||||
if res[tName] == nil {
|
||||
res[tName] = make([]string, 0)
|
||||
}
|
||||
@@ -202,7 +320,7 @@ func (d *Db) HintTables(rc *ctx.ReqCtx) {
|
||||
columnName := fmt.Sprintf("%s [%s]", v["columnName"], v["columnType"])
|
||||
comment := v["columnComment"]
|
||||
// 如果字段备注不为空,则加上备注信息
|
||||
if comment != "" {
|
||||
if comment != nil && comment != "" {
|
||||
columnName = fmt.Sprintf("%s[%s]", columnName, comment)
|
||||
}
|
||||
|
||||
23
server/internal/devops/api/db_sql_exec.go
Normal file
23
server/internal/devops/api/db_sql_exec.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"mayfly-go/pkg/ginx"
|
||||
)
|
||||
|
||||
type DbSqlExec struct {
|
||||
DbSqlExecApp application.DbSqlExec
|
||||
}
|
||||
|
||||
func (d *DbSqlExec) DbSqlExecs(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
m := &entity.DbSqlExec{DbId: uint64(ginx.QueryInt(g, "dbId", 0)),
|
||||
Db: g.Query("db"),
|
||||
Table: g.Query("table"),
|
||||
Type: int8(ginx.QueryInt(g, "type", 0)),
|
||||
}
|
||||
m.CreatorId = rc.LoginAccount.Id
|
||||
rc.ResData = d.DbSqlExecApp.GetPageList(m, ginx.GetPageParam(rc.GinCtx), new([]entity.DbSqlExec))
|
||||
}
|
||||
@@ -8,9 +8,24 @@ type DbForm struct {
|
||||
Port int `binding:"required" json:"port"`
|
||||
Username string `binding:"required" json:"username"`
|
||||
Password string `json:"password"`
|
||||
Params string `json:"params"`
|
||||
Database string `binding:"required" json:"database"`
|
||||
ProjectId uint64 `binding:"required" json:"projectId"`
|
||||
Project string `json:"project"`
|
||||
Env string `json:"env"`
|
||||
EnvId uint64 `binding:"required" json:"envId"`
|
||||
}
|
||||
|
||||
type DbSqlSaveForm struct {
|
||||
Name string
|
||||
Sql string `binding:"required"`
|
||||
Type int `binding:"required"`
|
||||
Db string `binding:"required"`
|
||||
}
|
||||
|
||||
// 数据库SQL执行表单
|
||||
type DbSqlExecForm struct {
|
||||
Db string `binding:"required" json:"db"` //数据库名
|
||||
Sql string `binding:"required" json:"sql"` // 执行sql
|
||||
Remark string `json:"remark"` // 执行备注
|
||||
}
|
||||
@@ -38,11 +38,9 @@ type MachineScriptForm struct {
|
||||
Script string `binding:"required"`
|
||||
}
|
||||
|
||||
type DbSqlSaveForm struct {
|
||||
Name string
|
||||
Sql string `binding:"required"`
|
||||
Type int `binding:"required"`
|
||||
Db string `binding:"required"`
|
||||
type MachineCreateFileForm struct {
|
||||
Path string `binding:"required"`
|
||||
Type string `binding:"required"`
|
||||
}
|
||||
|
||||
type MachineFileUpdateForm struct {
|
||||
@@ -4,11 +4,13 @@ type Redis struct {
|
||||
Id uint64
|
||||
Host string `binding:"required" json:"host"`
|
||||
Password string `json:"password"`
|
||||
Mode string `json:"mode"`
|
||||
Db int `json:"db"`
|
||||
ProjectId uint64 `binding:"required" json:"projectId"`
|
||||
Project string `json:"project"`
|
||||
Env string `json:"env"`
|
||||
EnvId uint64 `binding:"required" json:"envId"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
|
||||
type KeyInfo struct {
|
||||
@@ -30,3 +32,9 @@ type SetValue struct {
|
||||
KeyInfo
|
||||
Value []interface{} `binding:"required" json:"value"`
|
||||
}
|
||||
|
||||
type RedisScanForm struct {
|
||||
Cursor map[string]uint64 `json:"cursor"`
|
||||
Match string `json:"match"`
|
||||
Count int64 `json:"count"`
|
||||
}
|
||||
@@ -2,16 +2,16 @@ package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/base/ginx"
|
||||
"mayfly-go/base/utils"
|
||||
"mayfly-go/base/ws"
|
||||
"mayfly-go/server/devops/api/form"
|
||||
"mayfly-go/server/devops/api/vo"
|
||||
"mayfly-go/server/devops/application"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"mayfly-go/server/devops/infrastructure/machine"
|
||||
"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/pkg/biz"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"mayfly-go/pkg/ginx"
|
||||
"mayfly-go/pkg/utils"
|
||||
"mayfly-go/pkg/ws"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -57,6 +57,15 @@ func (m *Machine) SaveMachine(rc *ctx.ReqCtx) {
|
||||
entity := new(entity.Machine)
|
||||
utils.Copy(entity, machineForm)
|
||||
|
||||
// 密码解密,并使用解密后的赋值
|
||||
originPwd, err := utils.DefaultRsaDecrypt(machineForm.Password, true)
|
||||
biz.ErrIsNilAppendErr(err, "解密密码错误: %s")
|
||||
entity.Password = originPwd
|
||||
|
||||
// 密码脱敏记录日志
|
||||
machineForm.Password = "****"
|
||||
rc.ReqParam = machineForm
|
||||
|
||||
entity.SetBaseInfo(rc.LoginAccount)
|
||||
m.MachineApp.Save(entity)
|
||||
}
|
||||
@@ -138,7 +147,7 @@ func (m *Machine) WsSSH(g *gin.Context) {
|
||||
// 权限校验
|
||||
rc := ctx.NewReqCtxWithGin(g).WithRequiredPermission(ctx.NewPermission("machine:terminal"))
|
||||
if err = ctx.PermissionHandler(rc); err != nil {
|
||||
panic(biz.NewBizErr("没有权限"))
|
||||
panic(biz.NewBizErr("\033[1;31m您没有权限操作该机器终端,请重新登录后再试~\033[0m"))
|
||||
}
|
||||
|
||||
cols := ginx.QueryInt(g, "cols", 80)
|
||||
@@ -148,7 +157,7 @@ func (m *Machine) WsSSH(g *gin.Context) {
|
||||
biz.ErrIsNilAppendErr(m.ProjectApp.CanAccess(rc.LoginAccount.Id, cli.GetMachine().ProjectId), "%s")
|
||||
|
||||
sws, err := machine.NewLogicSshWsSession(cols, rows, cli, wsConn)
|
||||
biz.ErrIsNilAppendErr(err, "连接失败:%s")
|
||||
biz.ErrIsNilAppendErr(err, "\033[1;31m连接失败:%s\033[0m")
|
||||
defer sws.Close()
|
||||
|
||||
quitChan := make(chan bool, 3)
|
||||
@@ -4,16 +4,16 @@ import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/base/ginx"
|
||||
"mayfly-go/base/utils"
|
||||
"mayfly-go/base/ws"
|
||||
"mayfly-go/server/devops/api/form"
|
||||
"mayfly-go/server/devops/api/vo"
|
||||
"mayfly-go/server/devops/application"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
sysApplication "mayfly-go/server/sys/application"
|
||||
"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/pkg/biz"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"mayfly-go/pkg/ginx"
|
||||
"mayfly-go/pkg/utils"
|
||||
"mayfly-go/pkg/ws"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -60,6 +60,22 @@ func (m *MachineFile) DeleteFile(rc *ctx.ReqCtx) {
|
||||
|
||||
/*** sftp相关操作 */
|
||||
|
||||
func (m *MachineFile) CreateFile(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
fid := GetMachineFileId(g)
|
||||
|
||||
form := new(form.MachineCreateFileForm)
|
||||
ginx.BindJsonAndValid(g, form)
|
||||
path := form.Path
|
||||
|
||||
if form.Type == dir {
|
||||
m.MachineFileApp.MkDir(fid, form.Path)
|
||||
} else {
|
||||
m.MachineFileApp.CreateFile(fid, form.Path)
|
||||
}
|
||||
rc.ReqParam = fmt.Sprintf("path: %s, type: %s", path, form.Type)
|
||||
}
|
||||
|
||||
func (m *MachineFile) ReadFileContent(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
fid := GetMachineFileId(g)
|
||||
@@ -104,6 +120,7 @@ func (m *MachineFile) GetDirEntry(rc *ctx.ReqCtx) {
|
||||
Size: fi.Size(),
|
||||
Path: readPath + fi.Name(),
|
||||
Type: getFileType(fi.Mode()),
|
||||
Mode: fi.Mode().String(),
|
||||
})
|
||||
}
|
||||
rc.ResData = fisVO
|
||||
@@ -155,7 +172,6 @@ func (m *MachineFile) UploadFile(rc *ctx.ReqCtx) {
|
||||
func (m *MachineFile) RemoveFile(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
fid := GetMachineFileId(g)
|
||||
// mid := GetMachineId(g)
|
||||
path := g.Query("path")
|
||||
|
||||
m.MachineFileApp.RemoveFile(fid, path)
|
||||
@@ -167,7 +183,10 @@ func getFileType(fm fs.FileMode) string {
|
||||
if fm.IsDir() {
|
||||
return dir
|
||||
}
|
||||
return file
|
||||
if fm.IsRegular() {
|
||||
return file
|
||||
}
|
||||
return dir
|
||||
}
|
||||
|
||||
func GetMachineFileId(g *gin.Context) uint64 {
|
||||
@@ -2,14 +2,14 @@ package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/base/ginx"
|
||||
"mayfly-go/base/utils"
|
||||
"mayfly-go/server/devops/api/form"
|
||||
"mayfly-go/server/devops/api/vo"
|
||||
"mayfly-go/server/devops/application"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"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/pkg/biz"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"mayfly-go/pkg/ginx"
|
||||
"mayfly-go/pkg/utils"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -2,13 +2,13 @@ package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/base/ginx"
|
||||
"mayfly-go/base/utils"
|
||||
"mayfly-go/server/devops/api/form"
|
||||
"mayfly-go/server/devops/application"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/api/form"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"mayfly-go/pkg/ginx"
|
||||
"mayfly-go/pkg/utils"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -38,6 +38,11 @@ func (m *Mongo) Save(rc *ctx.ReqCtx) {
|
||||
|
||||
mongo := new(entity.Mongo)
|
||||
utils.Copy(mongo, form)
|
||||
// 解密uri,并使用解密后的赋值
|
||||
originUri, err := utils.DefaultRsaDecrypt(form.Uri, true)
|
||||
biz.ErrIsNilAppendErr(err, "解密uri错误: %s")
|
||||
mongo.Uri = originUri
|
||||
|
||||
mongo.SetBaseInfo(rc.LoginAccount)
|
||||
m.MongoApp.Save(mongo)
|
||||
}
|
||||
@@ -93,6 +98,17 @@ func (m *Mongo) FindCommand(rc *ctx.ReqCtx) {
|
||||
SetSkip(commandForm.Skip).
|
||||
SetLimit(limit)
|
||||
ctx := context.TODO()
|
||||
|
||||
filter := commandForm.Filter
|
||||
// 处理_id查询字段,使用ObjectId函数包装
|
||||
id, ok := filter["_id"].(string)
|
||||
if ok && id != "" {
|
||||
objId, err := primitive.ObjectIDFromHex(id)
|
||||
if err == nil {
|
||||
filter["_id"] = objId
|
||||
}
|
||||
}
|
||||
|
||||
cur, err := cli.Database(commandForm.Database).Collection(commandForm.Collection).Find(ctx, commandForm.Filter, opts)
|
||||
biz.ErrIsNilAppendErr(err, "命令执行失败: %s")
|
||||
|
||||
@@ -2,14 +2,14 @@ package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/base/ginx"
|
||||
"mayfly-go/server/devops/api/vo"
|
||||
"mayfly-go/server/devops/application"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
sys_applicaiton "mayfly-go/server/sys/application"
|
||||
sys_entity "mayfly-go/server/sys/domain/entity"
|
||||
"mayfly-go/internal/devops/api/vo"
|
||||
"mayfly-go/internal/devops/application"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
sys_applicaiton "mayfly-go/internal/sys/application"
|
||||
sys_entity "mayfly-go/internal/sys/domain/entity"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"mayfly-go/pkg/ginx"
|
||||
)
|
||||
|
||||
type Project struct {
|
||||
@@ -43,7 +43,8 @@ func (p *Project) GetProjects(rc *ctx.ReqCtx) {
|
||||
func (p *Project) SaveProject(rc *ctx.ReqCtx) {
|
||||
project := &entity.Project{}
|
||||
ginx.BindJsonAndValid(rc.GinCtx, project)
|
||||
rc.ReqParam = project
|
||||
|
||||
rc.ReqParam = fmt.Sprintf("projectId: %d, projectName: %s, remark: %s", project.Id, project.Name, project.Remark)
|
||||
|
||||
project.SetBaseInfo(rc.LoginAccount)
|
||||
p.ProjectApp.SaveProject(project)
|
||||
@@ -81,7 +82,8 @@ func (p *Project) GetProjectMembers(rc *ctx.ReqCtx) {
|
||||
func (p *Project) SaveProjectMember(rc *ctx.ReqCtx) {
|
||||
projectMem := &entity.ProjectMember{}
|
||||
ginx.BindJsonAndValid(rc.GinCtx, projectMem)
|
||||
rc.ReqParam = projectMem
|
||||
|
||||
rc.ReqParam = fmt.Sprintf("projectId: %d, username: %s", projectMem.ProjectId, projectMem.Username)
|
||||
|
||||
// 校验账号,并赋值username
|
||||
account := &sys_entity.Account{}
|
||||
345
server/internal/devops/api/redis.go
Normal file
345
server/internal/devops/api/redis.go
Normal file
@@ -0,0 +1,345 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"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/pkg/biz"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"mayfly-go/pkg/ginx"
|
||||
"mayfly-go/pkg/utils"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
)
|
||||
|
||||
type Redis struct {
|
||||
RedisApp application.Redis
|
||||
ProjectApp application.Project
|
||||
}
|
||||
|
||||
func (r *Redis) RedisList(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
m := &entity.Redis{EnvId: uint64(ginx.QueryInt(g, "envId", 0)),
|
||||
ProjectId: uint64(ginx.QueryInt(g, "projectId", 0)),
|
||||
}
|
||||
m.CreatorId = rc.LoginAccount.Id
|
||||
rc.ResData = r.RedisApp.GetPageList(m, ginx.GetPageParam(rc.GinCtx), new([]vo.Redis))
|
||||
}
|
||||
|
||||
func (r *Redis) Save(rc *ctx.ReqCtx) {
|
||||
form := &form.Redis{}
|
||||
ginx.BindJsonAndValid(rc.GinCtx, form)
|
||||
|
||||
redis := new(entity.Redis)
|
||||
utils.Copy(redis, form)
|
||||
|
||||
// 密码解密,并使用解密后的赋值
|
||||
originPwd, err := utils.DefaultRsaDecrypt(redis.Password, true)
|
||||
biz.ErrIsNilAppendErr(err, "解密密码错误: %s")
|
||||
redis.Password = originPwd
|
||||
|
||||
// 密码脱敏记录日志
|
||||
form.Password = "****"
|
||||
rc.ReqParam = form
|
||||
|
||||
redis.SetBaseInfo(rc.LoginAccount)
|
||||
r.RedisApp.Save(redis)
|
||||
}
|
||||
|
||||
func (r *Redis) DeleteRedis(rc *ctx.ReqCtx) {
|
||||
r.RedisApp.Delete(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
|
||||
}
|
||||
|
||||
func (r *Redis) RedisInfo(rc *ctx.ReqCtx) {
|
||||
ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
|
||||
|
||||
var res string
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
if ri.Mode == "" || ri.Mode == entity.RedisModeStandalone {
|
||||
res, err = ri.Cli.Info(ctx).Result()
|
||||
} else if ri.Mode == entity.RedisModeCluster {
|
||||
host := rc.GinCtx.Query("host")
|
||||
biz.NotEmpty(host, "集群模式host信息不能为空")
|
||||
clusterClient := ri.ClusterCli
|
||||
var redisClient *redis.Client
|
||||
// 遍历集群的master节点找到该redis client
|
||||
clusterClient.ForEachMaster(ctx, func(ctx context.Context, client *redis.Client) error {
|
||||
if host == client.Options().Addr {
|
||||
redisClient = client
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if redisClient == nil {
|
||||
// 遍历集群的slave节点找到该redis client
|
||||
clusterClient.ForEachSlave(ctx, func(ctx context.Context, client *redis.Client) error {
|
||||
if host == client.Options().Addr {
|
||||
redisClient = client
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
biz.NotNil(redisClient, "该实例不在该集群中")
|
||||
res, err = redisClient.Info(ctx).Result()
|
||||
}
|
||||
|
||||
biz.ErrIsNilAppendErr(err, "获取redis info失败: %s")
|
||||
|
||||
datas := strings.Split(res, "\r\n")
|
||||
i := 0
|
||||
length := len(datas)
|
||||
|
||||
parseMap := make(map[string]map[string]string)
|
||||
for {
|
||||
if i >= length {
|
||||
break
|
||||
}
|
||||
if strings.Contains(datas[i], "#") {
|
||||
key := utils.SubString(datas[i], strings.Index(datas[i], "#")+1, utils.StrLen(datas[i]))
|
||||
i++
|
||||
key = strings.Trim(key, " ")
|
||||
|
||||
sectionMap := make(map[string]string)
|
||||
for {
|
||||
if i >= length || !strings.Contains(datas[i], ":") {
|
||||
break
|
||||
}
|
||||
pair := strings.Split(datas[i], ":")
|
||||
i++
|
||||
if len(pair) != 2 {
|
||||
continue
|
||||
}
|
||||
sectionMap[pair[0]] = pair[1]
|
||||
}
|
||||
parseMap[key] = sectionMap
|
||||
} else {
|
||||
i++
|
||||
}
|
||||
}
|
||||
rc.ResData = parseMap
|
||||
}
|
||||
|
||||
func (r *Redis) ClusterInfo(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")))
|
||||
biz.IsEquals(ri.Mode, entity.RedisModeCluster, "非集群模式")
|
||||
info, _ := ri.ClusterCli.ClusterInfo(context.Background()).Result()
|
||||
nodesStr, _ := ri.ClusterCli.ClusterNodes(context.Background()).Result()
|
||||
|
||||
nodesRes := make([]map[string]string, 0)
|
||||
nodes := strings.Split(nodesStr, "\n")
|
||||
for _, node := range nodes {
|
||||
if node == "" {
|
||||
continue
|
||||
}
|
||||
nodeInfos := strings.Split(node, " ")
|
||||
node := make(map[string]string)
|
||||
node["nodeId"] = nodeInfos[0]
|
||||
// ip:port1@port2:port1指redis服务器与客户端通信的端口,port2则是集群内部节点间通信的端口
|
||||
node["ip"] = nodeInfos[1]
|
||||
node["flags"] = nodeInfos[2]
|
||||
// 如果节点是slave,并且已知master节点,则为master节点ID;否则为符号"-"
|
||||
node["masterSlaveRelation"] = nodeInfos[3]
|
||||
// 最近一次发送ping的时间,这个时间是一个unix毫秒时间戳,0代表没有发送过
|
||||
node["pingSent"] = nodeInfos[4]
|
||||
// 最近一次收到pong的时间,使用unix时间戳表示
|
||||
node["pongRecv"] = nodeInfos[5]
|
||||
// 节点的epoch值(如果该节点是从节点,则为其主节点的epoch值)。每当节点发生失败切换时,都会创建一个新的,独特的,递增的epoch。
|
||||
// 如果多个节点竞争同一个哈希槽时,epoch值更高的节点会抢夺到
|
||||
node["configEpoch"] = nodeInfos[6]
|
||||
// node-to-node集群总线使用的链接的状态,我们使用这个链接与集群中其他节点进行通信.值可以是 connected 和 disconnected
|
||||
node["linkState"] = nodeInfos[7]
|
||||
// slave节点没有插槽信息
|
||||
if len(nodeInfos) > 8 {
|
||||
// slot:master节点第9位为哈希槽值或者一个哈希槽范围,代表当前节点可以提供服务的所有哈希槽值。如果只是一个值,那就是只有一个槽会被使用。
|
||||
// 如果是一个范围,这个值表示为起始槽-结束槽,节点将处理包括起始槽和结束槽在内的所有哈希槽。
|
||||
node["slot"] = nodeInfos[8]
|
||||
}
|
||||
nodesRes = append(nodesRes, node)
|
||||
}
|
||||
rc.ResData = map[string]interface{}{
|
||||
"clusterInfo": info,
|
||||
"clusterNodes": nodesRes,
|
||||
}
|
||||
}
|
||||
|
||||
// scan获取redis的key列表信息
|
||||
func (r *Redis) Scan(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")))
|
||||
biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
|
||||
|
||||
form := &form.RedisScanForm{}
|
||||
ginx.BindJsonAndValid(rc.GinCtx, form)
|
||||
|
||||
cmd := ri.GetCmdable()
|
||||
ctx := context.Background()
|
||||
|
||||
kis := make([]*vo.KeyInfo, 0)
|
||||
var cursorRes map[string]uint64 = make(map[string]uint64)
|
||||
|
||||
if ri.Mode == "" || ri.Mode == entity.RedisModeStandalone {
|
||||
redisAddr := ri.Cli.Options().Addr
|
||||
keys, cursor := ri.Scan(form.Cursor[redisAddr], form.Match, form.Count)
|
||||
cursorRes[redisAddr] = cursor
|
||||
|
||||
var keyInfoSplit []string
|
||||
if len(keys) > 0 {
|
||||
keyInfosLua := `local result = {}
|
||||
-- KEYS[1]为第1个参数,lua数组下标从1开始
|
||||
for i = 1, #KEYS do
|
||||
local ttl = redis.call('ttl', KEYS[i]);
|
||||
local keyType = redis.call('type', KEYS[i]);
|
||||
table.insert(result, string.format("%d,%s", ttl, keyType['ok']));
|
||||
end;
|
||||
return table.concat(result, ".");`
|
||||
// 通过lua获取 ttl,type.ttl2,type2格式,以便下面切割获取ttl和type。避免多次调用ttl和type函数
|
||||
keyInfos, err := cmd.Eval(ctx, keyInfosLua, keys).Result()
|
||||
biz.ErrIsNilAppendErr(err, "执行lua脚本获取key信息失败: %s")
|
||||
keyInfoSplit = strings.Split(keyInfos.(string), ".")
|
||||
}
|
||||
|
||||
for i, k := range keys {
|
||||
ttlType := strings.Split(keyInfoSplit[i], ",")
|
||||
ttl, _ := strconv.Atoi(ttlType[0])
|
||||
ki := &vo.KeyInfo{Key: k, Type: ttlType[1], Ttl: int64(ttl)}
|
||||
kis = append(kis, ki)
|
||||
}
|
||||
} else if ri.Mode == entity.RedisModeCluster {
|
||||
var keys []string
|
||||
|
||||
mu := &sync.Mutex{}
|
||||
// 遍历所有master节点,并执行scan命令,合并keys
|
||||
ri.ClusterCli.ForEachMaster(ctx, func(ctx context.Context, client *redis.Client) error {
|
||||
redisAddr := client.Options().Addr
|
||||
ks, cursor, _ := client.Scan(ctx, form.Cursor[redisAddr], form.Match, form.Count).Result()
|
||||
// 遍历节点的内部回调函数使用异步调用,如不加锁会导致集合并发错误
|
||||
mu.Lock()
|
||||
cursorRes[redisAddr] = cursor
|
||||
keys = append(keys, ks...)
|
||||
mu.Unlock()
|
||||
return nil
|
||||
})
|
||||
|
||||
// 因为redis集群模式执行lua脚本key必须位于同一slot中,故单机获取的方式不适合
|
||||
// 使用lua获取key的ttl以及类型,减少网络调用
|
||||
keyInfoLua := `local ttl = redis.call('ttl', KEYS[1]);
|
||||
local keyType = redis.call('type', KEYS[1]);
|
||||
return string.format("%d,%s", ttl, keyType['ok'])`
|
||||
for _, k := range keys {
|
||||
keyInfo, err := cmd.Eval(ctx, keyInfoLua, []string{k}).Result()
|
||||
biz.ErrIsNilAppendErr(err, "执行lua脚本获取key信息失败: %s")
|
||||
ttlType := strings.Split(keyInfo.(string), ",")
|
||||
ttl, _ := strconv.Atoi(ttlType[0])
|
||||
ki := &vo.KeyInfo{Key: k, Type: ttlType[1], Ttl: int64(ttl)}
|
||||
kis = append(kis, ki)
|
||||
}
|
||||
}
|
||||
|
||||
size, _ := cmd.DBSize(context.TODO()).Result()
|
||||
rc.ResData = &vo.Keys{Cursor: cursorRes, Keys: kis, DbSize: size}
|
||||
}
|
||||
|
||||
func (r *Redis) DeleteKey(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
key := g.Query("key")
|
||||
biz.NotEmpty(key, "key不能为空")
|
||||
|
||||
ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")))
|
||||
biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
|
||||
|
||||
rc.ReqParam = key
|
||||
ri.GetCmdable().Del(context.Background(), key)
|
||||
}
|
||||
|
||||
func (r *Redis) checkKey(rc *ctx.ReqCtx) (*application.RedisInstance, string) {
|
||||
g := rc.GinCtx
|
||||
key := g.Query("key")
|
||||
biz.NotEmpty(key, "key不能为空")
|
||||
|
||||
ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")))
|
||||
biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
|
||||
|
||||
return ri, key
|
||||
}
|
||||
|
||||
func (r *Redis) GetStringValue(rc *ctx.ReqCtx) {
|
||||
ri, key := r.checkKey(rc)
|
||||
str, err := ri.GetCmdable().Get(context.TODO(), key).Result()
|
||||
biz.ErrIsNilAppendErr(err, "获取字符串值失败: %s")
|
||||
rc.ResData = str
|
||||
}
|
||||
|
||||
func (r *Redis) GetHashValue(rc *ctx.ReqCtx) {
|
||||
ri, key := r.checkKey(rc)
|
||||
res, err := ri.GetCmdable().HGetAll(context.TODO(), key).Result()
|
||||
biz.ErrIsNilAppendErr(err, "获取hash值失败: %s")
|
||||
rc.ResData = res
|
||||
}
|
||||
|
||||
func (r *Redis) SetStringValue(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
keyValue := new(form.StringValue)
|
||||
ginx.BindJsonAndValid(g, keyValue)
|
||||
|
||||
ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")))
|
||||
biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
|
||||
|
||||
str, err := ri.GetCmdable().Set(context.TODO(), keyValue.Key, keyValue.Value, time.Second*time.Duration(keyValue.Timed)).Result()
|
||||
biz.ErrIsNilAppendErr(err, "保存字符串值失败: %s")
|
||||
rc.ResData = str
|
||||
}
|
||||
|
||||
func (r *Redis) SetHashValue(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
hashValue := new(form.HashValue)
|
||||
ginx.BindJsonAndValid(g, hashValue)
|
||||
|
||||
ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")))
|
||||
biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
|
||||
|
||||
cmd := ri.GetCmdable()
|
||||
key := hashValue.Key
|
||||
// 简单处理->先删除,后新增
|
||||
cmd.Del(context.TODO(), key)
|
||||
for _, v := range hashValue.Value {
|
||||
res := cmd.HSet(context.TODO(), key, v["key"].(string), v["value"])
|
||||
biz.ErrIsNilAppendErr(res.Err(), "保存hash值失败: %s")
|
||||
}
|
||||
if hashValue.Timed != -1 {
|
||||
cmd.Expire(context.TODO(), key, time.Second*time.Duration(hashValue.Timed))
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Redis) GetSetValue(rc *ctx.ReqCtx) {
|
||||
ri, key := r.checkKey(rc)
|
||||
res, err := ri.GetCmdable().SMembers(context.TODO(), key).Result()
|
||||
biz.ErrIsNilAppendErr(err, "获取set值失败: %s")
|
||||
rc.ResData = res
|
||||
}
|
||||
|
||||
func (r *Redis) SetSetValue(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
keyvalue := new(form.SetValue)
|
||||
ginx.BindJsonAndValid(g, keyvalue)
|
||||
|
||||
ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")))
|
||||
biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
|
||||
cmd := ri.GetCmdable()
|
||||
|
||||
key := keyvalue.Key
|
||||
// 简单处理->先删除,后新增
|
||||
cmd.Del(context.TODO(), key)
|
||||
cmd.SAdd(context.TODO(), key, keyvalue.Value...)
|
||||
|
||||
if keyvalue.Timed != -1 {
|
||||
cmd.Expire(context.TODO(), key, time.Second*time.Duration(keyvalue.Timed))
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ type SelectDataDbVO struct {
|
||||
Host *string `json:"host"`
|
||||
Port *int `json:"port"`
|
||||
Type *string `json:"type"`
|
||||
Params *string `json:"params"`
|
||||
Database *string `json:"database"`
|
||||
Username *string `json:"username"`
|
||||
ProjectId *int64 `json:"projectId"`
|
||||
@@ -9,6 +9,8 @@ type Redis struct {
|
||||
Db int `json:"db"`
|
||||
ProjectId *int64 `json:"projectId"`
|
||||
Project *string `json:"project"`
|
||||
Mode *string `json:"mode"`
|
||||
Remark *string `json:"remark"`
|
||||
Env *string `json:"env"`
|
||||
EnvId *int64 `json:"envId"`
|
||||
CreateTime *time.Time `json:"createTime"`
|
||||
@@ -17,9 +19,9 @@ type Redis struct {
|
||||
}
|
||||
|
||||
type Keys struct {
|
||||
Cursor uint64 `json:"cursor"`
|
||||
Keys []*KeyInfo `json:"keys"`
|
||||
DbSize int64 `json:"dbSize"`
|
||||
Cursor map[string]uint64 `json:"cursor"`
|
||||
Keys []*KeyInfo `json:"keys"`
|
||||
DbSize int64 `json:"dbSize"`
|
||||
}
|
||||
|
||||
type KeyInfo struct {
|
||||
@@ -56,6 +56,7 @@ type MachineFileInfo struct {
|
||||
Path string `json:"path"`
|
||||
Size int64 `json:"size"`
|
||||
Type string `json:"type"`
|
||||
Mode string `json:"mode"`
|
||||
}
|
||||
|
||||
type RoleVO struct {
|
||||
@@ -4,22 +4,25 @@ import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/cache"
|
||||
"mayfly-go/base/global"
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/base/utils"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"mayfly-go/server/devops/domain/repository"
|
||||
"mayfly-go/server/devops/infrastructure/persistence"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/cache"
|
||||
"mayfly-go/pkg/global"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/utils"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
type Db interface {
|
||||
// 分页获取机器脚本信息列表
|
||||
// 分页获取
|
||||
GetPageList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
|
||||
Count(condition *entity.Db) int64
|
||||
@@ -158,6 +161,7 @@ func (da *dbAppImpl) GetDbInstance(id uint64, db string) *DbInstance {
|
||||
biz.ErrIsNil(err, fmt.Sprintf("Open %s failed, err:%v\n", d.Type, err))
|
||||
perr := DB.Ping()
|
||||
if perr != nil {
|
||||
global.Log.Errorf("连接db失败: %s:%d/%s", d.Host, d.Port, db)
|
||||
panic(biz.NewBizErr(fmt.Sprintf("数据库连接失败: %s", perr.Error())))
|
||||
}
|
||||
|
||||
@@ -217,20 +221,17 @@ type DbInstance struct {
|
||||
|
||||
// 执行查询语句
|
||||
// 依次返回 列名数组,结果map,错误
|
||||
func (d *DbInstance) SelectData(sql string) ([]string, []map[string]string, error) {
|
||||
sql = strings.Trim(sql, " ")
|
||||
isSelect := strings.HasPrefix(sql, "SELECT") || strings.HasPrefix(sql, "select")
|
||||
isShow := strings.HasPrefix(sql, "show")
|
||||
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 {
|
||||
if !isSelect && !isShow && !isExplain {
|
||||
return nil, nil, errors.New("该sql非查询语句")
|
||||
}
|
||||
// 没加limit,则默认限制50条
|
||||
if isSelect && !strings.Contains(sql, "limit") && !strings.Contains(sql, "LIMIT") {
|
||||
sql = sql + " LIMIT 50"
|
||||
}
|
||||
|
||||
rows, err := d.db.Query(sql)
|
||||
rows, err := d.db.Query(execSql)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -241,18 +242,18 @@ func (d *DbInstance) SelectData(sql string) ([]string, []map[string]string, erro
|
||||
rows.Close()
|
||||
}
|
||||
}()
|
||||
cols, _ := rows.Columns()
|
||||
colTypes, _ := rows.ColumnTypes()
|
||||
// 这里表示一行填充数据
|
||||
scans := make([]interface{}, len(cols))
|
||||
scans := make([]interface{}, len(colTypes))
|
||||
// 这里表示一行所有列的值,用[]byte表示
|
||||
vals := make([][]byte, len(cols))
|
||||
vals := make([][]byte, len(colTypes))
|
||||
// 这里scans引用vals,把数据填充到[]byte里
|
||||
for k := range vals {
|
||||
scans[k] = &vals[k]
|
||||
}
|
||||
|
||||
result := make([]map[string]string, 0)
|
||||
// 列名
|
||||
result := make([]map[string]interface{}, 0)
|
||||
// 列名用于前端表头名称按照数据库与查询字段顺序显示
|
||||
colNames := make([]string, 0)
|
||||
// 是否第一次遍历,列名数组只需第一次遍历时加入
|
||||
isFirst := true
|
||||
@@ -263,21 +264,52 @@ func (d *DbInstance) SelectData(sql string) ([]string, []map[string]string, erro
|
||||
return nil, nil, err
|
||||
}
|
||||
// 每行数据
|
||||
rowData := make(map[string]string)
|
||||
rowData := make(map[string]interface{})
|
||||
// 把vals中的数据复制到row中
|
||||
for k, v := range vals {
|
||||
key := cols[k]
|
||||
// 如果是密码字段,则脱敏显示
|
||||
if key == "password" {
|
||||
v = []byte("******")
|
||||
}
|
||||
for i, v := range vals {
|
||||
colType := colTypes[i]
|
||||
colName := colType.Name()
|
||||
// 字段类型名
|
||||
colScanType := colType.ScanType().Name()
|
||||
if isFirst {
|
||||
colNames = append(colNames, key)
|
||||
colNames = append(colNames, colName)
|
||||
}
|
||||
if v == nil {
|
||||
rowData[colName] = nil
|
||||
continue
|
||||
}
|
||||
// 这里把[]byte数据转成string
|
||||
rowData[key] = string(v)
|
||||
stringV := string(v)
|
||||
if stringV == "" {
|
||||
rowData[colName] = stringV
|
||||
continue
|
||||
}
|
||||
if strings.Contains(colScanType, "int") || strings.Contains(colScanType, "Int") {
|
||||
intV, _ := strconv.Atoi(stringV)
|
||||
switch colType.ScanType().Kind() {
|
||||
case reflect.Int8:
|
||||
rowData[colName] = int8(intV)
|
||||
case reflect.Uint8:
|
||||
rowData[colName] = uint8(intV)
|
||||
case reflect.Int64:
|
||||
rowData[colName] = int64(intV)
|
||||
case reflect.Uint64:
|
||||
rowData[colName] = uint64(intV)
|
||||
case reflect.Uint:
|
||||
rowData[colName] = uint(intV)
|
||||
default:
|
||||
rowData[colName] = intV
|
||||
}
|
||||
continue
|
||||
}
|
||||
if strings.Contains(colScanType, "float") || strings.Contains(colScanType, "Float") {
|
||||
floatV, _ := strconv.ParseFloat(stringV, 64)
|
||||
rowData[colName] = floatV
|
||||
} else {
|
||||
rowData[colName] = stringV
|
||||
}
|
||||
}
|
||||
//放入结果集
|
||||
// 放入结果集
|
||||
result = append(result, rowData)
|
||||
isFirst = false
|
||||
}
|
||||
@@ -301,8 +333,21 @@ func (d *DbInstance) Close() {
|
||||
|
||||
// 获取dataSourceName
|
||||
func getDsn(d *entity.Db) string {
|
||||
var dsn string
|
||||
if d.Type == "mysql" {
|
||||
return fmt.Sprintf("%s:%s@%s(%s:%d)/%s", d.Username, d.Password, d.Network, d.Host, d.Port, d.Database)
|
||||
dsn = fmt.Sprintf("%s:%s@%s(%s:%d)/%s?timeout=8s", d.Username, d.Password, d.Network, d.Host, d.Port, d.Database)
|
||||
if d.Params != "" {
|
||||
dsn = fmt.Sprintf("%s&%s", dsn, d.Params)
|
||||
}
|
||||
return dsn
|
||||
}
|
||||
|
||||
if d.Type == "postgres" {
|
||||
dsn = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", d.Host, d.Port, d.Username, d.Password, d.Database)
|
||||
if d.Params != "" {
|
||||
dsn = fmt.Sprintf("%s %s", dsn, strings.Join(strings.Split(d.Params, "&"), " "))
|
||||
}
|
||||
return dsn
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -318,43 +363,91 @@ const (
|
||||
// mysql 表信息元数据
|
||||
MYSQL_TABLE_MA = `SELECT table_name tableName, engine, table_comment tableComment,
|
||||
create_time createTime from information_schema.tables
|
||||
WHERE table_schema = (SELECT database())`
|
||||
WHERE table_schema = (SELECT database()) LIMIT 2000`
|
||||
|
||||
// mysql 表信息
|
||||
MYSQL_TABLE_INFO = `SELECT table_name tableName, table_comment tableComment, table_rows tableRows,
|
||||
data_length dataLength, index_length indexLength, create_time createTime
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = (SELECT database())`
|
||||
WHERE table_schema = (SELECT database()) LIMIT 2000`
|
||||
|
||||
// mysql 索引信息
|
||||
MYSQL_INDEX_INFO = `SELECT index_name indexName, column_name columnName, index_type indexType,
|
||||
SEQ_IN_INDEX seqInIndex, INDEX_COMMENT indexComment
|
||||
FROM information_schema.STATISTICS
|
||||
WHERE table_schema = (SELECT database()) AND table_name = '%s'`
|
||||
WHERE table_schema = (SELECT database()) AND table_name = '%s' LIMIT 500`
|
||||
|
||||
// 默认每次查询列元信息数量
|
||||
DEFAULT_COLUMN_SIZE = 2000
|
||||
|
||||
// mysql 列信息元数据
|
||||
MYSQL_COLOUMN_MA = `SELECT table_name tableName, column_name columnName, column_type columnType,
|
||||
MYSQL_COLUMN_MA = `SELECT table_name tableName, column_name columnName, column_type columnType,
|
||||
column_comment columnComment, column_key columnKey, extra, is_nullable nullable from information_schema.columns
|
||||
WHERE table_name in (%s) AND table_schema = (SELECT database()) ORDER BY tableName, ordinal_position limit %d, %d`
|
||||
WHERE table_name in (%s) AND table_schema = (SELECT database()) ORDER BY tableName, ordinal_position LIMIT %d, %d`
|
||||
|
||||
// mysql 列信息元数据总数
|
||||
MYSQL_COLOUMN_MA_COUNT = `SELECT COUNT(*) maNum from information_schema.columns
|
||||
WHERE table_name in (%s) AND table_schema = (SELECT database())`
|
||||
)
|
||||
|
||||
func (d *DbInstance) GetTableMetedatas() []map[string]string {
|
||||
const (
|
||||
// postgres 表信息元数据
|
||||
PGSQL_TABLE_MA = `SELECT obj_description(c.oid) AS "tableComment", c.relname AS "tableName" FROM pg_class c
|
||||
JOIN pg_namespace n ON c.relnamespace = n.oid WHERE n.nspname = (select current_schema()) AND c.reltype > 0`
|
||||
|
||||
PGSQL_TABLE_INFO = `SELECT obj_description(c.oid) AS "tableComment", c.relname AS "tableName" FROM pg_class c
|
||||
JOIN pg_namespace n ON c.relnamespace = n.oid WHERE n.nspname = (select current_schema()) AND c.reltype > 0`
|
||||
|
||||
PGSQL_INDEX_INFO = `SELECT indexname AS "indexName", indexdef AS "indexComment"
|
||||
FROM pg_indexes WHERE schemaname = (select current_schema()) AND tablename = '%s'`
|
||||
|
||||
PGSQL_COLUMN_MA = `SELECT
|
||||
C.relname AS "tableName",
|
||||
A.attname AS "columnName",
|
||||
concat_ws ( '', t.typname, SUBSTRING ( format_type ( a.atttypid, a.atttypmod ) FROM '\(.*\)' ) ) AS "columnType",
|
||||
d.description AS "columnComment"
|
||||
FROM
|
||||
pg_attribute a LEFT JOIN pg_description d ON d.objoid = a.attrelid
|
||||
AND d.objsubid = A.attnum
|
||||
LEFT JOIN pg_class c ON A.attrelid = c.oid
|
||||
LEFT JOIN pg_namespace pn ON c.relnamespace = pn.oid
|
||||
LEFT JOIN pg_type t ON a.atttypid = t.oid
|
||||
WHERE
|
||||
A.attnum >= 0
|
||||
AND pn.nspname = (select current_schema())
|
||||
AND C.relname in (%s)
|
||||
ORDER BY
|
||||
C.relname DESC,
|
||||
A.attnum ASC
|
||||
OFFSET %d LIMIT %d
|
||||
`
|
||||
|
||||
PGSQL_COLUMN_MA_COUNT = `SELECT COUNT(*) "maNum"
|
||||
FROM
|
||||
pg_attribute a LEFT JOIN pg_description d ON d.objoid = a.attrelid
|
||||
AND d.objsubid = A.attnum
|
||||
LEFT JOIN pg_class c ON A.attrelid = c.oid
|
||||
LEFT JOIN pg_namespace pn ON c.relnamespace = pn.oid
|
||||
LEFT JOIN pg_type t ON a.atttypid = t.oid
|
||||
WHERE
|
||||
A.attnum >= 0
|
||||
AND pn.nspname = (select current_schema())
|
||||
AND C.relname in (%s)
|
||||
`
|
||||
)
|
||||
|
||||
func (d *DbInstance) GetTableMetedatas() []map[string]interface{} {
|
||||
var sql string
|
||||
if d.Type == "mysql" {
|
||||
sql = MYSQL_TABLE_MA
|
||||
} else if d.Type == "postgres" {
|
||||
sql = PGSQL_TABLE_MA
|
||||
}
|
||||
_, res, _ := d.SelectData(sql)
|
||||
return res
|
||||
}
|
||||
|
||||
func (d *DbInstance) GetColumnMetadatas(tableNames ...string) []map[string]string {
|
||||
func (d *DbInstance) GetColumnMetadatas(tableNames ...string) []map[string]interface{} {
|
||||
var sql, tableName string
|
||||
for i := 0; i < len(tableNames); i++ {
|
||||
if i != 0 {
|
||||
@@ -367,20 +460,23 @@ func (d *DbInstance) GetColumnMetadatas(tableNames ...string) []map[string]strin
|
||||
var sqlTmp string
|
||||
if d.Type == "mysql" {
|
||||
countSqlTmp = MYSQL_COLOUMN_MA_COUNT
|
||||
sqlTmp = MYSQL_COLOUMN_MA
|
||||
sqlTmp = MYSQL_COLUMN_MA
|
||||
} else if d.Type == "postgres" {
|
||||
countSqlTmp = PGSQL_COLUMN_MA_COUNT
|
||||
sqlTmp = PGSQL_COLUMN_MA
|
||||
}
|
||||
|
||||
countSql := fmt.Sprintf(countSqlTmp, tableName)
|
||||
_, countRes, _ := d.SelectData(countSql)
|
||||
// 查询出所有列信息总数,手动分页获取所有数据
|
||||
maCount, _ := strconv.Atoi(countRes[0]["maNum"])
|
||||
maCount := int(countRes[0]["maNum"].(int64))
|
||||
// 计算需要查询的页数
|
||||
pageNum := maCount / DEFAULT_COLUMN_SIZE
|
||||
if maCount%DEFAULT_COLUMN_SIZE > 0 {
|
||||
pageNum++
|
||||
}
|
||||
|
||||
res := make([]map[string]string, 0)
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for index := 0; index < pageNum; index++ {
|
||||
sql = fmt.Sprintf(sqlTmp, tableName, index*DEFAULT_COLUMN_SIZE, DEFAULT_COLUMN_SIZE)
|
||||
_, result, err := d.SelectData(sql)
|
||||
@@ -390,25 +486,34 @@ func (d *DbInstance) GetColumnMetadatas(tableNames ...string) []map[string]strin
|
||||
return res
|
||||
}
|
||||
|
||||
func (d *DbInstance) GetTableInfos() []map[string]string {
|
||||
// 获取表的主键,目前默认第一列为主键
|
||||
func (d *DbInstance) GetPrimaryKey(tablename string) string {
|
||||
return d.GetColumnMetadatas(tablename)[0]["columnName"].(string)
|
||||
}
|
||||
|
||||
func (d *DbInstance) GetTableInfos() []map[string]interface{} {
|
||||
var sql string
|
||||
if d.Type == "mysql" {
|
||||
sql = MYSQL_TABLE_INFO
|
||||
} else if d.Type == "postgres" {
|
||||
sql = PGSQL_TABLE_INFO
|
||||
}
|
||||
_, res, _ := d.SelectData(sql)
|
||||
return res
|
||||
}
|
||||
|
||||
func (d *DbInstance) GetTableIndex(tableName string) []map[string]string {
|
||||
func (d *DbInstance) GetTableIndex(tableName string) []map[string]interface{} {
|
||||
var sql string
|
||||
if d.Type == "mysql" {
|
||||
sql = fmt.Sprintf(MYSQL_INDEX_INFO, tableName)
|
||||
} else if d.Type == "postgres" {
|
||||
sql = fmt.Sprintf(PGSQL_INDEX_INFO, tableName)
|
||||
}
|
||||
_, res, _ := d.SelectData(sql)
|
||||
return res
|
||||
}
|
||||
|
||||
func (d *DbInstance) GetCreateTableDdl(tableName string) []map[string]string {
|
||||
func (d *DbInstance) GetCreateTableDdl(tableName string) []map[string]interface{} {
|
||||
var sql string
|
||||
if d.Type == "mysql" {
|
||||
sql = fmt.Sprintf("show create table %s ", tableName)
|
||||
127
server/internal/devops/application/db_sql_exec_app.go
Normal file
127
server/internal/devops/application/db_sql_exec_app.go
Normal file
@@ -0,0 +1,127 @@
|
||||
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.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,12 +1,12 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"mayfly-go/server/devops/domain/repository"
|
||||
"mayfly-go/server/devops/infrastructure/machine"
|
||||
"mayfly-go/server/devops/infrastructure/persistence"
|
||||
"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/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -1,13 +1,14 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"mayfly-go/server/devops/domain/repository"
|
||||
"mayfly-go/server/devops/infrastructure/persistence"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -30,6 +31,12 @@ type MachineFile interface {
|
||||
|
||||
/** sftp 相关操作 **/
|
||||
|
||||
// 创建目录
|
||||
MkDir(fid uint64, path string)
|
||||
|
||||
// 创建文件
|
||||
CreateFile(fid uint64, path string)
|
||||
|
||||
// 读取目录
|
||||
ReadDir(fid uint64, path string) []fs.FileInfo
|
||||
|
||||
@@ -100,6 +107,25 @@ func (m *machineFileAppImpl) ReadDir(fid uint64, path string) []fs.FileInfo {
|
||||
return fis
|
||||
}
|
||||
|
||||
func (m *machineFileAppImpl) MkDir(fid uint64, path string) {
|
||||
path, machineId := m.checkAndReturnPathMid(fid, path)
|
||||
if !strings.HasSuffix(path, "/") {
|
||||
path = path + "/"
|
||||
}
|
||||
|
||||
sftpCli := m.getSftpCli(machineId)
|
||||
err := sftpCli.Mkdir(path)
|
||||
biz.ErrIsNilAppendErr(err, "创建目录失败: %s")
|
||||
}
|
||||
|
||||
func (m *machineFileAppImpl) CreateFile(fid uint64, path string) {
|
||||
path, machineId := m.checkAndReturnPathMid(fid, path)
|
||||
sftpCli := m.getSftpCli(machineId)
|
||||
file, err := sftpCli.Create(path)
|
||||
biz.ErrIsNilAppendErr(err, "创建文件失败: %s")
|
||||
defer file.Close()
|
||||
}
|
||||
|
||||
func (m *machineFileAppImpl) ReadFile(fileId uint64, path string) *sftp.File {
|
||||
path, machineId := m.checkAndReturnPathMid(fileId, path)
|
||||
sftpCli := m.getSftpCli(machineId)
|
||||
@@ -148,6 +174,11 @@ func (m *machineFileAppImpl) RemoveFile(fileId uint64, path string) {
|
||||
fi, _ := file.Stat()
|
||||
if fi.IsDir() {
|
||||
err = sftpCli.RemoveDirectory(path)
|
||||
// 如果文件夹有内容会删除失败,则使用rm -rf命令删除
|
||||
if err != nil {
|
||||
MachineApp.GetCli(machineId).Run(fmt.Sprintf("rm -rf %s", path))
|
||||
err = nil
|
||||
}
|
||||
} else {
|
||||
err = sftpCli.Remove(path)
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"mayfly-go/server/devops/domain/repository"
|
||||
"mayfly-go/server/devops/infrastructure/persistence"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type MachineScript interface {
|
||||
@@ -2,13 +2,13 @@ package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/cache"
|
||||
"mayfly-go/base/global"
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"mayfly-go/server/devops/domain/repository"
|
||||
"mayfly-go/server/devops/infrastructure/persistence"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/cache"
|
||||
"mayfly-go/pkg/global"
|
||||
"mayfly-go/pkg/model"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
@@ -1,11 +1,11 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"mayfly-go/server/devops/domain/repository"
|
||||
"mayfly-go/server/devops/infrastructure/persistence"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type Project interface {
|
||||
@@ -1,17 +1,19 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/cache"
|
||||
"mayfly-go/base/global"
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"mayfly-go/server/devops/domain/repository"
|
||||
"mayfly-go/server/devops/infrastructure/persistence"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/repository"
|
||||
"mayfly-go/internal/devops/infrastructure/persistence"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/cache"
|
||||
"mayfly-go/pkg/global"
|
||||
"mayfly-go/pkg/model"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis"
|
||||
"github.com/go-redis/redis/v8"
|
||||
)
|
||||
|
||||
type Redis interface {
|
||||
@@ -63,7 +65,10 @@ func (r *redisAppImpl) GetRedisBy(condition *entity.Redis, cols ...string) error
|
||||
}
|
||||
|
||||
func (r *redisAppImpl) Save(re *entity.Redis) {
|
||||
TestRedisConnection(re)
|
||||
// ’修改信息且密码不为空‘ or ‘新增’需要测试是否可连接
|
||||
if (re.Id != 0 && re.Password != "") || re.Id == 0 {
|
||||
TestRedisConnection(re)
|
||||
}
|
||||
|
||||
// 查找是否存在该库
|
||||
oldRedis := &entity.Redis{Host: re.Host, Db: re.Db}
|
||||
@@ -102,24 +107,53 @@ func (r *redisAppImpl) GetRedisInstance(id uint64) *RedisInstance {
|
||||
// 缓存不存在,则回调获取redis信息
|
||||
re := r.GetById(id)
|
||||
biz.NotNil(re, "redis信息不存在")
|
||||
|
||||
redisMode := re.Mode
|
||||
ri := &RedisInstance{Id: id, ProjectId: re.ProjectId, Mode: redisMode}
|
||||
if redisMode == "" || redisMode == entity.RedisModeStandalone {
|
||||
rcli := getRedisCient(re)
|
||||
// 测试连接
|
||||
_, e := rcli.Ping(context.Background()).Result()
|
||||
if e != nil {
|
||||
rcli.Close()
|
||||
panic(biz.NewBizErr(fmt.Sprintf("redis连接失败: %s", e.Error())))
|
||||
}
|
||||
ri.Cli = rcli
|
||||
} else if redisMode == entity.RedisModeCluster {
|
||||
ccli := getRedisClusterClient(re)
|
||||
// 测试连接
|
||||
_, e := ccli.Ping(context.Background()).Result()
|
||||
if e != nil {
|
||||
ccli.Close()
|
||||
panic(biz.NewBizErr(fmt.Sprintf("redis集群连接失败: %s", e.Error())))
|
||||
}
|
||||
ri.ClusterCli = ccli
|
||||
}
|
||||
|
||||
global.Log.Infof("连接redis: %s", re.Host)
|
||||
|
||||
rcli := redis.NewClient(&redis.Options{
|
||||
Addr: re.Host,
|
||||
Password: re.Password, // no password set
|
||||
DB: re.Db, // use default DB
|
||||
})
|
||||
// 测试连接
|
||||
_, e := rcli.Ping().Result()
|
||||
biz.ErrIsNilAppendErr(e, "redis连接失败: %s")
|
||||
|
||||
ri := &RedisInstance{Id: id, ProjectId: re.ProjectId, Cli: rcli}
|
||||
if needCache {
|
||||
redisCache.Put(re.Id, ri)
|
||||
}
|
||||
return ri
|
||||
}
|
||||
|
||||
func getRedisCient(re *entity.Redis) *redis.Client {
|
||||
return redis.NewClient(&redis.Options{
|
||||
Addr: re.Host,
|
||||
Password: re.Password, // no password set
|
||||
DB: re.Db, // use default DB
|
||||
DialTimeout: 8 * time.Second,
|
||||
})
|
||||
}
|
||||
|
||||
func getRedisClusterClient(re *entity.Redis) *redis.ClusterClient {
|
||||
return redis.NewClusterClient(&redis.ClusterOptions{
|
||||
Addrs: strings.Split(re.Host, ","),
|
||||
Password: re.Password,
|
||||
DialTimeout: 8 * time.Second,
|
||||
})
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// redis客户端连接缓存,30分钟内没有访问则会被关闭
|
||||
@@ -127,35 +161,64 @@ var redisCache = cache.NewTimedCache(30*time.Minute, 5*time.Second).
|
||||
WithUpdateAccessTime(true).
|
||||
OnEvicted(func(key interface{}, value interface{}) {
|
||||
global.Log.Info(fmt.Sprintf("删除redis连接缓存 id = %d", key))
|
||||
value.(*RedisInstance).Cli.Close()
|
||||
value.(*RedisInstance).Close()
|
||||
})
|
||||
|
||||
// redis实例
|
||||
type RedisInstance struct {
|
||||
Id uint64
|
||||
ProjectId uint64
|
||||
Cli *redis.Client
|
||||
}
|
||||
|
||||
// 移除redis连接缓存并关闭redis连接
|
||||
func CloseRedis(id uint64) {
|
||||
redisCache.Delete(id)
|
||||
}
|
||||
|
||||
func TestRedisConnection(re *entity.Redis) {
|
||||
rcli := redis.NewClient(&redis.Options{
|
||||
Addr: re.Host,
|
||||
Password: re.Password, // no password set
|
||||
DB: re.Db, // use default DB
|
||||
})
|
||||
defer rcli.Close()
|
||||
var cmd redis.Cmdable
|
||||
if re.Mode == "" || re.Mode == entity.RedisModeStandalone {
|
||||
rcli := getRedisCient(re)
|
||||
defer rcli.Close()
|
||||
cmd = rcli
|
||||
} else if re.Mode == entity.RedisModeCluster {
|
||||
ccli := getRedisClusterClient(re)
|
||||
defer ccli.Close()
|
||||
cmd = ccli
|
||||
}
|
||||
|
||||
// 测试连接
|
||||
_, e := rcli.Ping().Result()
|
||||
_, e := cmd.Ping(context.Background()).Result()
|
||||
biz.ErrIsNilAppendErr(e, "Redis连接失败: %s")
|
||||
}
|
||||
|
||||
// redis实例
|
||||
type RedisInstance struct {
|
||||
Id uint64
|
||||
ProjectId uint64
|
||||
Mode string
|
||||
Cli *redis.Client
|
||||
ClusterCli *redis.ClusterClient
|
||||
}
|
||||
|
||||
// 获取命令执行接口的具体实现
|
||||
func (r *RedisInstance) GetCmdable() redis.Cmdable {
|
||||
redisMode := r.Mode
|
||||
if redisMode == "" || redisMode == entity.RedisModeStandalone {
|
||||
return r.Cli
|
||||
}
|
||||
if r.Mode == entity.RedisModeCluster {
|
||||
return r.ClusterCli
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RedisInstance) Scan(cursor uint64, match string, count int64) ([]string, uint64) {
|
||||
keys, newcursor, err := r.Cli.Scan(cursor, match, count).Result()
|
||||
keys, newcursor, err := r.GetCmdable().Scan(context.Background(), cursor, match, count).Result()
|
||||
biz.ErrIsNilAppendErr(err, "scan失败: %s")
|
||||
return keys, newcursor
|
||||
}
|
||||
|
||||
func (r *RedisInstance) Close() {
|
||||
if r.Mode == entity.RedisModeStandalone {
|
||||
r.Cli.Close()
|
||||
return
|
||||
}
|
||||
if r.Mode == entity.RedisModeCluster {
|
||||
r.ClusterCli.Close()
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type Db struct {
|
||||
@@ -15,6 +15,7 @@ type Db struct {
|
||||
Username string `orm:"column(username)" json:"username"`
|
||||
Password string `orm:"column(password)" json:"-"`
|
||||
Database string `orm:"column(database)" json:"database"`
|
||||
Params string `json:"params"`
|
||||
ProjectId uint64
|
||||
Project string
|
||||
EnvId uint64
|
||||
@@ -1,7 +1,7 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type DbSql struct {
|
||||
22
server/internal/devops/domain/entity/db_sql_exec.go
Normal file
22
server/internal/devops/domain/entity/db_sql_exec.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package entity
|
||||
|
||||
import "mayfly-go/pkg/model"
|
||||
|
||||
// 数据库sql执行记录
|
||||
type DbSqlExec struct {
|
||||
model.Model `orm:"-"`
|
||||
|
||||
DbId uint64 `json:"dbId"`
|
||||
Db string `json:"db"`
|
||||
Table string `json:"table"`
|
||||
Type int8 `json:"type"` // 类型
|
||||
Sql string `json:"sql"` // 执行的sql
|
||||
OldValue string `json:"oldValue"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
|
||||
const (
|
||||
DbSqlExecTypeUpdate int8 = 1 // 更新类型
|
||||
DbSqlExecTypeDelete int8 = 2 // 删除类型
|
||||
DbSqlExecTypeInsert int8 = 3 // 插入类型
|
||||
)
|
||||
@@ -1,7 +1,7 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type Machine struct {
|
||||
@@ -1,6 +1,6 @@
|
||||
package entity
|
||||
|
||||
import "mayfly-go/base/model"
|
||||
import "mayfly-go/pkg/model"
|
||||
|
||||
type MachineFile struct {
|
||||
model.Model
|
||||
@@ -1,6 +1,6 @@
|
||||
package entity
|
||||
|
||||
import "mayfly-go/base/model"
|
||||
import "mayfly-go/pkg/model"
|
||||
|
||||
type MachineScript struct {
|
||||
model.Model
|
||||
@@ -1,6 +1,6 @@
|
||||
package entity
|
||||
|
||||
import "mayfly-go/base/model"
|
||||
import "mayfly-go/pkg/model"
|
||||
|
||||
type Mongo struct {
|
||||
model.Model
|
||||
@@ -1,6 +1,6 @@
|
||||
package entity
|
||||
|
||||
import "mayfly-go/base/model"
|
||||
import "mayfly-go/pkg/model"
|
||||
|
||||
// 项目
|
||||
type Project struct {
|
||||
@@ -1,6 +1,6 @@
|
||||
package entity
|
||||
|
||||
import "mayfly-go/base/model"
|
||||
import "mayfly-go/pkg/model"
|
||||
|
||||
// 项目环境
|
||||
type ProjectEnv struct {
|
||||
@@ -1,6 +1,6 @@
|
||||
package entity
|
||||
|
||||
import "mayfly-go/base/model"
|
||||
import "mayfly-go/pkg/model"
|
||||
|
||||
// 项目成员,用于对项目下组件的访问控制
|
||||
type ProjectMember struct {
|
||||
@@ -1,17 +1,24 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type Redis struct {
|
||||
model.Model
|
||||
|
||||
Host string `orm:"column(host)" json:"host"`
|
||||
Mode string `json:"mode"`
|
||||
Password string `orm:"column(password)" json:"-"`
|
||||
Db int `orm:"column(database)" json:"db"`
|
||||
Remark string
|
||||
ProjectId uint64
|
||||
Project string
|
||||
EnvId uint64
|
||||
Env string
|
||||
}
|
||||
|
||||
const (
|
||||
RedisModeStandalone = "standalone"
|
||||
RedisModeCluster = "cluster"
|
||||
)
|
||||
@@ -1,8 +1,8 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type Db interface {
|
||||
@@ -1,6 +1,6 @@
|
||||
package repository
|
||||
|
||||
import "mayfly-go/server/devops/domain/entity"
|
||||
import "mayfly-go/internal/devops/domain/entity"
|
||||
|
||||
type DbSql interface {
|
||||
DeleteBy(condition *entity.DbSql)
|
||||
15
server/internal/devops/domain/repository/db_sql_exec.go
Normal file
15
server/internal/devops/domain/repository/db_sql_exec.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type DbSqlExec interface {
|
||||
Insert(d *entity.DbSqlExec)
|
||||
|
||||
DeleteBy(condition *entity.DbSqlExec)
|
||||
|
||||
// 分页获取
|
||||
GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type Machine interface {
|
||||
@@ -1,8 +1,8 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"mayfly-go/internal/devops/domain/entity"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type MachineFile interface {
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user