mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 08:20:25 +08:00 
			
		
		
		
	Compare commits
	
		
			34 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					22c401f9d8 | ||
| 
						 | 
					be00b90c1d | ||
| 
						 | 
					fb3f89c594 | ||
| 
						 | 
					e7a66378ea | ||
| 
						 | 
					2f88b48973 | ||
| 
						 | 
					7761fe0288 | ||
| 
						 | 
					09e6bdcf7e | ||
| 
						 | 
					61a4d87f59 | ||
| 
						 | 
					c219ec33b0 | ||
| 
						 | 
					fd86f36218 | ||
| 
						 | 
					efac41f392 | ||
| 
						 | 
					52df61ae0d | ||
| 
						 | 
					cf2bc6785c | ||
| 
						 | 
					98a4c92576 | ||
| 
						 | 
					b1ee9b65ff | ||
| 
						 | 
					99cc4c5e5e | ||
| 
						 | 
					226bb8f089 | ||
| 
						 | 
					37ed5134e8 | ||
| 
						 | 
					0f54d4a472 | ||
| 
						 | 
					64805360d6 | ||
| 
						 | 
					7f69fe2ad9 | ||
| 
						 | 
					f913510d3c | ||
| 
						 | 
					f2d9e7786d | ||
| 
						 | 
					e1afb1ed54 | ||
| 
						 | 
					12f8cf0111 | ||
| 
						 | 
					daa2ef5203 | ||
| 
						 | 
					1e3e183930 | ||
| 
						 | 
					366563a0fe | ||
| 
						 | 
					577802e5ad | ||
| 
						 | 
					76d6fc3ba5 | ||
| 
						 | 
					f0540559bb | ||
| 
						 | 
					802e379f60 | ||
| 
						 | 
					8c9253da80 | ||
| 
						 | 
					5271bd21e8 | 
							
								
								
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							@@ -1,6 +1,6 @@
 | 
				
			|||||||
                                 Apache License
 | 
					                                 Apache License
 | 
				
			||||||
                           Version 2.0, January 2004
 | 
					                           Version 2.0, January 2004
 | 
				
			||||||
                        http://www.apache.org/licenses/
 | 
					                        http://www.apache.org/licenses/ 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
 | 
					   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										36
									
								
								README.en.md
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								README.en.md
									
									
									
									
									
								
							@@ -1,36 +0,0 @@
 | 
				
			|||||||
# mayfly-go
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#### Description
 | 
					 | 
				
			||||||
golang实现linux运维等
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#### Software Architecture
 | 
					 | 
				
			||||||
Software architecture description
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#### Installation
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
1.  xxxx
 | 
					 | 
				
			||||||
2.  xxxx
 | 
					 | 
				
			||||||
3.  xxxx
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#### Instructions
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
1.  xxxx
 | 
					 | 
				
			||||||
2.  xxxx
 | 
					 | 
				
			||||||
3.  xxxx
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#### Contribution
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
1.  Fork the repository
 | 
					 | 
				
			||||||
2.  Create Feat_xxx branch
 | 
					 | 
				
			||||||
3.  Commit your code
 | 
					 | 
				
			||||||
4.  Create Pull Request
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#### Gitee Feature
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
1.  You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
 | 
					 | 
				
			||||||
2.  Gitee blog [blog.gitee.com](https://blog.gitee.com)
 | 
					 | 
				
			||||||
3.  Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
 | 
					 | 
				
			||||||
4.  The most valuable open source project [GVP](https://gitee.com/gvp)
 | 
					 | 
				
			||||||
5.  The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
 | 
					 | 
				
			||||||
6.  The most popular members  [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
 | 
					 | 
				
			||||||
							
								
								
									
										22
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								README.md
									
									
									
									
									
								
							@@ -1,7 +1,25 @@
 | 
				
			|||||||
# 🌈mayfly-go
 | 
					# 🌈mayfly-go
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<p align="center">
 | 
				
			||||||
 | 
					  <a href="https://gitee.com/objs/mayfly-go" target="_blank">
 | 
				
			||||||
 | 
					    <img src="https://gitee.com/objs/mayfly-go/badge/star.svg?theme=white" alt="star"/>
 | 
				
			||||||
 | 
					    <img src="https://gitee.com/objs/mayfly-go/badge/fork.svg" alt="fork"/>
 | 
				
			||||||
 | 
					  </a>
 | 
				
			||||||
 | 
					  <a href="https://github.com/may-fly/mayfly-go" target="_blank">
 | 
				
			||||||
 | 
					    <img src="https://img.shields.io/github/stars/may-fly/mayfly-go.svg?style=social" alt="github star"/>
 | 
				
			||||||
 | 
					    <img src="https://img.shields.io/github/forks/may-fly/mayfly-go.svg?style=social" alt="github fork"/>
 | 
				
			||||||
 | 
					  </a>
 | 
				
			||||||
 | 
					  <a href="https://github.com/golang/go" target="_blank">
 | 
				
			||||||
 | 
					    <img src="https://img.shields.io/badge/Golang-1.18%2B-yellow.svg" alt="golang"/>
 | 
				
			||||||
 | 
					  </a>
 | 
				
			||||||
 | 
					  <a href="https://cn.vuejs.org" target="_blank">
 | 
				
			||||||
 | 
					    <img src="https://img.shields.io/badge/Vue-3.x-green.svg" alt="vue">
 | 
				
			||||||
 | 
					  </a>
 | 
				
			||||||
 | 
					</p>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 介绍
 | 
					### 介绍
 | 
				
			||||||
简单基于DDD(领域驱动设计)分层架构实现的web版 **linux、数据库(mysql postgres)、redis(单机 集群)、mongo统一管理操作平台**
 | 
					web版 **linux(终端[终端回放] 文件 脚本 进程)、数据库(mysql postgres)、redis(单机 哨兵 集群)、mongo统一管理操作平台**
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 开发语言与主要框架
 | 
					### 开发语言与主要框架
 | 
				
			||||||
@@ -10,7 +28,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 交流及问题反馈加 QQ 群
 | 
					### 交流及问题反馈加 QQ 群
 | 
				
			||||||
<a target="_blank" href="https://qm.qq.com/cgi-bin/qm/qr?jump_from=webapi">119699946</a>
 | 
					<a target="_blank" href="https://qm.qq.com/cgi-bin/qm/qr?k=IdJSHW0jTMhmWFHBUS9a83wxtrxDDhFj&jump_from=webapi">119699946</a>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 系统相关资料
 | 
					### 系统相关资料
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,9 +30,9 @@ function buildWeb() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    echo_yellow "-------------------打包前端开始-------------------"
 | 
					    echo_yellow "-------------------打包前端开始-------------------"
 | 
				
			||||||
    yarn run build
 | 
					    yarn run build
 | 
				
			||||||
    if [ "${copy2Server}" == "1" ] ; then
 | 
					    if [ "${copy2Server}" == "2" ] ; then
 | 
				
			||||||
        echo_green '将打包后的静态文件拷贝至server/static'
 | 
					        echo_green '将打包后的静态文件拷贝至server/static/static'
 | 
				
			||||||
        rm -rf ${server_folder}/static && mkdir -p ${server_folder}/static && cp -r ${web_folder}/dist/* ${server_folder}/static
 | 
					        rm -rf ${server_folder}/static/static && mkdir -p ${server_folder}/static/static && cp -r ${web_folder}/dist/* ${server_folder}/static/static
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
    echo_yellow ">>>>>>>>>>>>>>>>>>>打包前端结束<<<<<<<<<<<<<<<<<<<<\n"
 | 
					    echo_yellow ">>>>>>>>>>>>>>>>>>>打包前端结束<<<<<<<<<<<<<<<<<<<<\n"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -44,6 +44,7 @@ function build() {
 | 
				
			|||||||
    toFolder=$1
 | 
					    toFolder=$1
 | 
				
			||||||
    os=$2
 | 
					    os=$2
 | 
				
			||||||
    arch=$3
 | 
					    arch=$3
 | 
				
			||||||
 | 
					    copyStatic=$4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    echo_yellow "-------------------${os}-${arch}打包构建开始-------------------"
 | 
					    echo_yellow "-------------------${os}-${arch}打包构建开始-------------------"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -67,8 +68,10 @@ function build() {
 | 
				
			|||||||
    echo_green "移动二进制文件至'${toFolder}'"
 | 
					    echo_green "移动二进制文件至'${toFolder}'"
 | 
				
			||||||
    mv ${server_folder}/${execFileName} ${toFolder}
 | 
					    mv ${server_folder}/${execFileName} ${toFolder}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    echo_green "拷贝前端静态页面至'${toFolder}/static'"
 | 
					    if [ "${copy2Server}" == "1" ] ; then
 | 
				
			||||||
    mkdir -p ${toFolder}/static && cp -r ${web_folder}/dist/* ${toFolder}/static
 | 
					        echo_green "拷贝前端静态页面至'${toFolder}/static'"
 | 
				
			||||||
 | 
					        mkdir -p ${toFolder}/static && cp -r ${web_folder}/dist/* ${toFolder}/static
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    echo_green "拷贝脚本等资源文件[config.yml、mayfly-go.sql、readme.txt、startup.sh、shutdown.sh]"
 | 
					    echo_green "拷贝脚本等资源文件[config.yml、mayfly-go.sql、readme.txt、startup.sh、shutdown.sh]"
 | 
				
			||||||
    cp ${server_folder}/config.yml ${toFolder}
 | 
					    cp ${server_folder}/config.yml ${toFolder}
 | 
				
			||||||
@@ -81,15 +84,19 @@ function build() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function buildLinuxAmd64() {
 | 
					function buildLinuxAmd64() {
 | 
				
			||||||
    build "$1/mayfly-go-linux-amd64" "linux" "amd64"
 | 
					    build "$1/mayfly-go-linux-amd64" "linux" "amd64" $2
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function buildLinuxArm64() {
 | 
					function buildLinuxArm64() {
 | 
				
			||||||
    build "$1/mayfly-go-linux-arm64" "linux" "arm64"
 | 
					    build "$1/mayfly-go-linux-arm64" "linux" "arm64" $2
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function buildWindows() {
 | 
					function buildWindows() {
 | 
				
			||||||
    build "$1/mayfly-go-windows" "windows" "amd64"
 | 
					    build "$1/mayfly-go-windows" "windows" "amd64" $2
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function buildMac() {
 | 
				
			||||||
 | 
					    build "$1/mayfly-go-mac" "darwin" "amd64" $2
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function runBuild() {
 | 
					function runBuild() {
 | 
				
			||||||
@@ -103,34 +110,34 @@ function runBuild() {
 | 
				
			|||||||
    cd ${toPath}
 | 
					    cd ${toPath}
 | 
				
			||||||
    toPath=`pwd`
 | 
					    toPath=`pwd`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    read -p "是否构建前端[0|其他->否 1->是 2->构建并拷贝至server/static]: " runBuildWeb
 | 
					    read -p "是否构建前端[0|其他->否 1->是 2->构建并拷贝至server/static/static]: " runBuildWeb
 | 
				
			||||||
    read -p "请选择构建版本[0|其他->全部 1->linux-amd64 2->linux-arm64 3->windows]: " buildType
 | 
					    read -p "请选择构建版本[0|其他->全部 1->linux-amd64 2->linux-arm64 3->windows 4->mac]: " buildType
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    if [ "${runBuildWeb}" == "1" ];then
 | 
					    
 | 
				
			||||||
        buildWeb
 | 
					    if [ "${runBuildWeb}" == "1" ] || [ "${runBuildWeb}" == "2" ] ; then
 | 
				
			||||||
    fi
 | 
					        buildWeb ${runBuildWeb}
 | 
				
			||||||
    if [ "${runBuildWeb}" == "2" ];then
 | 
					 | 
				
			||||||
        buildWeb 1
 | 
					 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if [ "${buildType}" == "1" ];then
 | 
					    case ${buildType} in
 | 
				
			||||||
        buildLinuxAmd64 ${toPath}
 | 
					         "1")
 | 
				
			||||||
        exit;
 | 
					            buildLinuxAmd64 ${toPath} ${runBuildWeb}
 | 
				
			||||||
    fi
 | 
					        ;;
 | 
				
			||||||
 | 
					         "2")
 | 
				
			||||||
    if [ "${buildType}" == "2" ];then
 | 
					            buildLinuxArm64 ${toPath} ${runBuildWeb}
 | 
				
			||||||
        buildLinuxArm64 ${toPath}
 | 
					        ;;
 | 
				
			||||||
        exit;
 | 
					        "3")
 | 
				
			||||||
    fi
 | 
					            buildWindows ${toPath} ${runBuildWeb}
 | 
				
			||||||
 | 
					        ;;
 | 
				
			||||||
    if [ "${buildType}" == "3" ];then
 | 
					        "4")
 | 
				
			||||||
        buildWindows ${toPath}
 | 
					            buildMac ${toPath} ${runBuildWeb}
 | 
				
			||||||
        exit;
 | 
					        ;;
 | 
				
			||||||
    fi
 | 
					        *)
 | 
				
			||||||
 | 
					            buildLinuxAmd64 ${toPath} ${runBuildWeb}
 | 
				
			||||||
    buildLinuxAmd64 ${toPath}
 | 
					            buildLinuxArm64 ${toPath} ${runBuildWeb}
 | 
				
			||||||
    buildLinuxArm64 ${toPath}
 | 
					            buildWindows ${toPath} ${runBuildWeb}
 | 
				
			||||||
    buildWindows ${toPath}
 | 
					            buildMac ${toPath} ${runBuildWeb}
 | 
				
			||||||
 | 
					        ;;
 | 
				
			||||||
 | 
					    esac
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
runBuild
 | 
					runBuild
 | 
				
			||||||
@@ -18,8 +18,7 @@
 | 
				
			|||||||
	</head>
 | 
						</head>
 | 
				
			||||||
	<body>
 | 
						<body>
 | 
				
			||||||
		<div id="app"></div>
 | 
							<div id="app"></div>
 | 
				
			||||||
        <script type="text/javascript" src="./config.js"></script>
 | 
					        <script type="application/javascript" src="./config.js"></script>
 | 
				
			||||||
		<script type="module" src="/src/main.ts"></script>
 | 
							<script type="module" src="/src/main.ts"></script>
 | 
				
			||||||
		<!-- <script type="text/javascript" src="https://api.map.baidu.com/api?v=3.0&ak=wsijQt8sLXrCW71YesmispvYHitfG9gv&s=1"></script> -->
 | 
					 | 
				
			||||||
	</body>
 | 
						</body>
 | 
				
			||||||
</html>
 | 
					</html>
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										33
									
								
								mayfly_go_web/package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										33
									
								
								mayfly_go_web/package-lock.json
									
									
									
										generated
									
									
									
								
							@@ -15,6 +15,7 @@
 | 
				
			|||||||
        "cropperjs": "^1.5.11",
 | 
					        "cropperjs": "^1.5.11",
 | 
				
			||||||
        "echarts": "^5.3.3",
 | 
					        "echarts": "^5.3.3",
 | 
				
			||||||
        "element-plus": "^2.2.9",
 | 
					        "element-plus": "^2.2.9",
 | 
				
			||||||
 | 
					        "jsencrypt": "^3.2.1",
 | 
				
			||||||
        "jsoneditor": "^9.9.0",
 | 
					        "jsoneditor": "^9.9.0",
 | 
				
			||||||
        "lodash": "^4.17.21",
 | 
					        "lodash": "^4.17.21",
 | 
				
			||||||
        "mitt": "^3.0.0",
 | 
					        "mitt": "^3.0.0",
 | 
				
			||||||
@@ -24,7 +25,7 @@
 | 
				
			|||||||
        "sql-formatter": "^7.0.3",
 | 
					        "sql-formatter": "^7.0.3",
 | 
				
			||||||
        "vue": "^3.2.37",
 | 
					        "vue": "^3.2.37",
 | 
				
			||||||
        "vue-clipboard3": "^1.0.1",
 | 
					        "vue-clipboard3": "^1.0.1",
 | 
				
			||||||
        "vue-router": "^4.0.16",
 | 
					        "vue-router": "^4.1.2",
 | 
				
			||||||
        "vuex": "^4.0.2",
 | 
					        "vuex": "^4.0.2",
 | 
				
			||||||
        "xterm": "^4.19.0",
 | 
					        "xterm": "^4.19.0",
 | 
				
			||||||
        "xterm-addon-fit": "^0.5.0"
 | 
					        "xterm-addon-fit": "^0.5.0"
 | 
				
			||||||
@@ -1880,6 +1881,11 @@
 | 
				
			|||||||
        "js-yaml": "bin/js-yaml.js"
 | 
					        "js-yaml": "bin/js-yaml.js"
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    "node_modules/jsencrypt": {
 | 
				
			||||||
 | 
					      "version": "3.2.1",
 | 
				
			||||||
 | 
					      "resolved": "https://registry.npmmirror.com/jsencrypt/-/jsencrypt-3.2.1.tgz",
 | 
				
			||||||
 | 
					      "integrity": "sha512-k1sD5QV0KPn+D8uG9AdGzTQuamt82QZ3A3l6f7TRwMU6Oi2Vg0BsL+wZIQBONcraO1pc78ExMdvmBBJ8WhNYUA=="
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    "node_modules/json-schema-traverse": {
 | 
					    "node_modules/json-schema-traverse": {
 | 
				
			||||||
      "version": "0.4.1",
 | 
					      "version": "0.4.1",
 | 
				
			||||||
      "resolved": "https://registry.npm.taobao.org/json-schema-traverse/download/json-schema-traverse-0.4.1.tgz",
 | 
					      "resolved": "https://registry.npm.taobao.org/json-schema-traverse/download/json-schema-traverse-0.4.1.tgz",
 | 
				
			||||||
@@ -2931,15 +2937,11 @@
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "node_modules/vue-router": {
 | 
					    "node_modules/vue-router": {
 | 
				
			||||||
      "version": "4.0.16",
 | 
					      "version": "4.1.2",
 | 
				
			||||||
      "resolved": "https://registry.npmmirror.com/vue-router/-/vue-router-4.0.16.tgz",
 | 
					      "resolved": "https://registry.npmmirror.com/vue-router/-/vue-router-4.1.2.tgz",
 | 
				
			||||||
      "integrity": "sha512-JcO7cb8QJLBWE+DfxGUL3xUDOae/8nhM1KVdnudadTAORbuxIC/xAydC5Zr/VLHUDQi1ppuTF5/rjBGzgzrJNA==",
 | 
					      "integrity": "sha512-5BP1qXFncVRwgV/XnqzsKApdMjQPqWIpoUBdL1ynz8HyLxIX/UDAx7Ql2BjmA5CXT/p61JfZvkpiFWFpaqcfag==",
 | 
				
			||||||
      "license": "MIT",
 | 
					 | 
				
			||||||
      "dependencies": {
 | 
					      "dependencies": {
 | 
				
			||||||
        "@vue/devtools-api": "^6.0.0"
 | 
					        "@vue/devtools-api": "^6.1.4"
 | 
				
			||||||
      },
 | 
					 | 
				
			||||||
      "funding": {
 | 
					 | 
				
			||||||
        "url": "https://github.com/sponsors/posva"
 | 
					 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      "peerDependencies": {
 | 
					      "peerDependencies": {
 | 
				
			||||||
        "vue": "^3.2.0"
 | 
					        "vue": "^3.2.0"
 | 
				
			||||||
@@ -4358,6 +4360,11 @@
 | 
				
			|||||||
        "argparse": "^2.0.1"
 | 
					        "argparse": "^2.0.1"
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    "jsencrypt": {
 | 
				
			||||||
 | 
					      "version": "3.2.1",
 | 
				
			||||||
 | 
					      "resolved": "https://registry.npmmirror.com/jsencrypt/-/jsencrypt-3.2.1.tgz",
 | 
				
			||||||
 | 
					      "integrity": "sha512-k1sD5QV0KPn+D8uG9AdGzTQuamt82QZ3A3l6f7TRwMU6Oi2Vg0BsL+wZIQBONcraO1pc78ExMdvmBBJ8WhNYUA=="
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    "json-schema-traverse": {
 | 
					    "json-schema-traverse": {
 | 
				
			||||||
      "version": "0.4.1",
 | 
					      "version": "0.4.1",
 | 
				
			||||||
      "resolved": "https://registry.npm.taobao.org/json-schema-traverse/download/json-schema-traverse-0.4.1.tgz",
 | 
					      "resolved": "https://registry.npm.taobao.org/json-schema-traverse/download/json-schema-traverse-0.4.1.tgz",
 | 
				
			||||||
@@ -5044,11 +5051,11 @@
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "vue-router": {
 | 
					    "vue-router": {
 | 
				
			||||||
      "version": "4.0.16",
 | 
					      "version": "4.1.2",
 | 
				
			||||||
      "resolved": "https://registry.npmmirror.com/vue-router/-/vue-router-4.0.16.tgz",
 | 
					      "resolved": "https://registry.npmmirror.com/vue-router/-/vue-router-4.1.2.tgz",
 | 
				
			||||||
      "integrity": "sha512-JcO7cb8QJLBWE+DfxGUL3xUDOae/8nhM1KVdnudadTAORbuxIC/xAydC5Zr/VLHUDQi1ppuTF5/rjBGzgzrJNA==",
 | 
					      "integrity": "sha512-5BP1qXFncVRwgV/XnqzsKApdMjQPqWIpoUBdL1ynz8HyLxIX/UDAx7Ql2BjmA5CXT/p61JfZvkpiFWFpaqcfag==",
 | 
				
			||||||
      "requires": {
 | 
					      "requires": {
 | 
				
			||||||
        "@vue/devtools-api": "^6.0.0"
 | 
					        "@vue/devtools-api": "^6.1.4"
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "vuex": {
 | 
					    "vuex": {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,26 +7,27 @@
 | 
				
			|||||||
    "lint-fix": "eslint --fix --ext .js --ext .jsx --ext .vue src/"
 | 
					    "lint-fix": "eslint --fix --ext .js --ext .jsx --ext .vue src/"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "dependencies": {
 | 
					  "dependencies": {
 | 
				
			||||||
    "@element-plus/icons-vue": "^2.0.6",
 | 
					    "@element-plus/icons-vue": "^2.0.9",
 | 
				
			||||||
    "axios": "^0.27.2",
 | 
					    "axios": "^0.27.2",
 | 
				
			||||||
    "codemirror": "^5.65.5",
 | 
					    "codemirror": "^5.65.5",
 | 
				
			||||||
    "countup.js": "^2.0.7",
 | 
					    "countup.js": "^2.0.7",
 | 
				
			||||||
    "cropperjs": "^1.5.11",
 | 
					    "cropperjs": "^1.5.11",
 | 
				
			||||||
    "echarts": "^5.3.3",
 | 
					    "echarts": "^5.3.3",
 | 
				
			||||||
    "element-plus": "^2.2.9",
 | 
					    "element-plus": "^2.2.17",
 | 
				
			||||||
 | 
					    "jsencrypt": "^3.2.1",
 | 
				
			||||||
    "jsoneditor": "^9.9.0",
 | 
					    "jsoneditor": "^9.9.0",
 | 
				
			||||||
    "lodash": "^4.17.21",
 | 
					    "lodash": "^4.17.21",
 | 
				
			||||||
    "mitt": "^3.0.0",
 | 
					    "mitt": "^3.0.0",
 | 
				
			||||||
    "nprogress": "^0.2.0",
 | 
					    "nprogress": "^0.2.0",
 | 
				
			||||||
    "screenfull": "^5.1.0",
 | 
					    "screenfull": "^6.0.2",
 | 
				
			||||||
    "sortablejs": "^1.13.0",
 | 
					    "sortablejs": "^1.13.0",
 | 
				
			||||||
    "sql-formatter": "^7.0.3",
 | 
					    "sql-formatter": "^9.2.0",
 | 
				
			||||||
    "vue": "^3.2.37",
 | 
					    "vue": "^3.2.37",
 | 
				
			||||||
    "vue-clipboard3": "^1.0.1",
 | 
					    "vue-clipboard3": "^1.0.1",
 | 
				
			||||||
    "vue-router": "^4.0.16",
 | 
					    "vue-router": "^4.1.2",
 | 
				
			||||||
    "vuex": "^4.0.2",
 | 
					    "vuex": "^4.0.2",
 | 
				
			||||||
    "xterm": "^4.19.0",
 | 
					    "xterm": "^5.0.0",
 | 
				
			||||||
    "xterm-addon-fit": "^0.5.0"
 | 
					    "xterm-addon-fit": "^0.6.0"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "devDependencies": {
 | 
					  "devDependencies": {
 | 
				
			||||||
    "@types/lodash": "^4.14.178",
 | 
					    "@types/lodash": "^4.14.178",
 | 
				
			||||||
@@ -37,6 +38,7 @@
 | 
				
			|||||||
    "@typescript-eslint/parser": "^4.23.0",
 | 
					    "@typescript-eslint/parser": "^4.23.0",
 | 
				
			||||||
    "@vitejs/plugin-vue": "^2.3.3",
 | 
					    "@vitejs/plugin-vue": "^2.3.3",
 | 
				
			||||||
    "@vue/compiler-sfc": "^3.0.11",
 | 
					    "@vue/compiler-sfc": "^3.0.11",
 | 
				
			||||||
 | 
					    "asciinema-player": "^3.0.1",
 | 
				
			||||||
    "dotenv": "^10.0.0",
 | 
					    "dotenv": "^10.0.0",
 | 
				
			||||||
    "eslint": "^8.5.0",
 | 
					    "eslint": "^8.5.0",
 | 
				
			||||||
    "eslint-plugin-vue": "^8.2.0",
 | 
					    "eslint-plugin-vue": "^8.2.0",
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										3
									
								
								mayfly_go_web/shim.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								mayfly_go_web/shim.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -6,4 +6,5 @@ declare module '*.vue' {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
declare module 'codemirror';
 | 
					declare module 'codemirror';
 | 
				
			||||||
declare module 'sql-formatter';
 | 
					declare module 'sql-formatter';
 | 
				
			||||||
declare module 'jsoneditor';
 | 
					declare module 'jsoneditor';
 | 
				
			||||||
 | 
					declare module 'asciinema-player';
 | 
				
			||||||
@@ -11,6 +11,8 @@ import { useStore } from '@/store/index.ts';
 | 
				
			|||||||
import { getLocal } from '@/common/utils/storage.ts';
 | 
					import { getLocal } from '@/common/utils/storage.ts';
 | 
				
			||||||
import LockScreen from '@/views/layout/lockScreen/index.vue';
 | 
					import LockScreen from '@/views/layout/lockScreen/index.vue';
 | 
				
			||||||
import Setings from '@/views/layout/navBars/breadcrumb/setings.vue';
 | 
					import Setings from '@/views/layout/navBars/breadcrumb/setings.vue';
 | 
				
			||||||
 | 
					import Watermark from '@/common/utils/wartermark.ts';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'app',
 | 
					    name: 'app',
 | 
				
			||||||
    components: { LockScreen, Setings },
 | 
					    components: { LockScreen, Setings },
 | 
				
			||||||
@@ -57,6 +59,8 @@ export default defineComponent({
 | 
				
			|||||||
            () => route.path,
 | 
					            () => route.path,
 | 
				
			||||||
            () => {
 | 
					            () => {
 | 
				
			||||||
                nextTick(() => {
 | 
					                nextTick(() => {
 | 
				
			||||||
 | 
					                    // 路由变化更新水印
 | 
				
			||||||
 | 
					                    Watermark.use();
 | 
				
			||||||
                    document.title = `${route.meta.title} - ${getThemeConfig.value.globalTitle}` || getThemeConfig.value.globalTitle;
 | 
					                    document.title = `${route.meta.title} - ${getThemeConfig.value.globalTitle}` || getThemeConfig.value.globalTitle;
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,11 @@
 | 
				
			|||||||
import request from './request'
 | 
					import request from './request'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default {
 | 
					export default {
 | 
				
			||||||
    login: (param: any) => request.request('POST', '/sys/accounts/login', param, null),
 | 
					    login: (param: any) => request.request('POST', '/sys/accounts/login', param),
 | 
				
			||||||
    captcha: () => request.request('GET', '/sys/captcha', null, null),
 | 
					    changePwd: (param: any) => request.request('POST', '/sys/accounts/change-pwd', param),
 | 
				
			||||||
    logout: (param: any) => request.request('POST', '/sys/accounts/logout/{token}', param, null),
 | 
					    getPublicKey: () => request.request('GET', '/common/public-key'),
 | 
				
			||||||
    getMenuRoute: (param: any) => request.request('Get', '/sys/resources/account', param, null)
 | 
					    getConfigValue: (param: any) => request.request('GET', '/sys/configs/value', param),
 | 
				
			||||||
 | 
					    captcha: () => request.request('GET', '/sys/captcha'),
 | 
				
			||||||
 | 
					    logout: (param: any) => request.request('POST', '/sys/accounts/logout/{token}', param),
 | 
				
			||||||
 | 
					    getMenuRoute: (param: any) => request.request('Get', '/sys/resources/account', param)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										36
									
								
								mayfly_go_web/src/common/rsa.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								mayfly_go_web/src/common/rsa.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
				
			|||||||
 | 
					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)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    encryptor = new JSEncrypt()
 | 
				
			||||||
 | 
					    const publicKey = await getRsaPublicKey() as string;
 | 
				
			||||||
 | 
					    notBlank(publicKey, "获取公钥失败")
 | 
				
			||||||
 | 
					    encryptor.setPublicKey(publicKey)//设置公钥
 | 
				
			||||||
 | 
					    return encryptor.encrypt(value)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										48
									
								
								mayfly_go_web/src/common/sysconfig.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								mayfly_go_web/src/common/sysconfig.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,48 @@
 | 
				
			|||||||
 | 
					import openApi from './openApi';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 登录是否使用验证码配置key
 | 
				
			||||||
 | 
					const UseLoginCaptchaConfigKey = "UseLoginCaptcha"
 | 
				
			||||||
 | 
					const UseWartermarkConfigKey = "UseWartermark"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 获取系统配置值
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * @param key 配置key
 | 
				
			||||||
 | 
					 * @returns 配置值
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export async function getConfigValue(key: string) : Promise<string> {
 | 
				
			||||||
 | 
					    return await openApi.getConfigValue({key}) as string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 获取bool类型系统配置值
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * @param key 配置key
 | 
				
			||||||
 | 
					 * @param defaultValue 默认值
 | 
				
			||||||
 | 
					 * @returns 是否为ture,1: true;其他: false
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export async function getBoolConfigValue(key :string, defaultValue :boolean) : Promise<boolean> {
 | 
				
			||||||
 | 
					    const value = await getConfigValue(key)
 | 
				
			||||||
 | 
					    if (!value) {
 | 
				
			||||||
 | 
					        return defaultValue;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return value == "1";
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 是否使用登录验证码
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * @returns 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export async function useLoginCaptcha() : Promise<boolean> {
 | 
				
			||||||
 | 
					    return await getBoolConfigValue(UseLoginCaptchaConfigKey, true)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 是否启用水印
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * @returns 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					 export async function useWartermark() : Promise<boolean> {
 | 
				
			||||||
 | 
					    return await getBoolConfigValue(UseWartermarkConfigKey, true)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -35,3 +35,22 @@ export function removeSession(key: string) {
 | 
				
			|||||||
export function clearSession() {
 | 
					export function clearSession() {
 | 
				
			||||||
    window.sessionStorage.clear();
 | 
					    window.sessionStorage.clear();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function getUserInfo4Session() {
 | 
				
			||||||
 | 
					    return getSession("userInfo")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function setUserInfo2Session(userinfo: any) {
 | 
				
			||||||
 | 
					    setSession("userInfo", userinfo)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取是否开启水印
 | 
				
			||||||
 | 
					export function getUseWatermark4Session() {
 | 
				
			||||||
 | 
					    return getSession("useWatermark")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function setUseWatermark2Session(useWatermark: boolean) {
 | 
				
			||||||
 | 
					    setSession("useWatermark", useWatermark)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,21 +1,26 @@
 | 
				
			|||||||
 | 
					import { getUseWatermark4Session, getUserInfo4Session } from '@/common/utils/storage.ts';
 | 
				
			||||||
 | 
					import { dateFormat } from '@/common/utils/date.ts'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 页面添加水印效果
 | 
					// 页面添加水印效果
 | 
				
			||||||
const setWatermark = (str: any) => {
 | 
					const setWatermark = (str: any) => {
 | 
				
			||||||
    const id = '1.23452384164.123412416';
 | 
					    const id = '1.23452384164.123412416';
 | 
				
			||||||
    if (document.getElementById(id) !== null) document.body.removeChild(document.getElementById(id) as any);
 | 
					    if (document.getElementById(id) !== null) document.body.removeChild(document.getElementById(id) as any);
 | 
				
			||||||
    const can = document.createElement('canvas');
 | 
					    const can = document.createElement('canvas');
 | 
				
			||||||
    can.width = 250;
 | 
					    can.width = 400;
 | 
				
			||||||
    can.height = 180;
 | 
					    can.height = 250;
 | 
				
			||||||
    const cans: any = can.getContext('2d');
 | 
					    const cans: any = can.getContext('2d');
 | 
				
			||||||
    cans.rotate((-20 * Math.PI) / 180);
 | 
					    cans.rotate((-20 * Math.PI) / 180);
 | 
				
			||||||
    cans.font = '12px Vedana';
 | 
					    cans.font = '14px Vedana';
 | 
				
			||||||
    cans.fillStyle = 'rgba(200, 200, 200, 0.30)';
 | 
					    cans.fillStyle = 'rgba(200, 200, 200, 0.35)';
 | 
				
			||||||
    cans.textAlign = 'center';
 | 
					    cans.textAlign = 'left';
 | 
				
			||||||
    cans.textBaseline = 'Middle';
 | 
					    cans.textBaseline = 'Middle';
 | 
				
			||||||
    cans.fillText(str, can.width / 10, can.height / 2);
 | 
					    // cans.fillText('mayfly go', can.width / 4, can.height )
 | 
				
			||||||
 | 
					    cans.fillText(str, can.width / 8, can.height / 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const div = document.createElement('div');
 | 
					    const div = document.createElement('div');
 | 
				
			||||||
    div.id = id;
 | 
					    div.id = id;
 | 
				
			||||||
    div.style.pointerEvents = 'none';
 | 
					    div.style.pointerEvents = 'none';
 | 
				
			||||||
    div.style.top = '35px';
 | 
					    div.style.top = '30px';
 | 
				
			||||||
    div.style.left = '0px';
 | 
					    div.style.left = '0px';
 | 
				
			||||||
    div.style.position = 'fixed';
 | 
					    div.style.position = 'fixed';
 | 
				
			||||||
    div.style.zIndex = '10000000';
 | 
					    div.style.zIndex = '10000000';
 | 
				
			||||||
@@ -26,16 +31,34 @@ const setWatermark = (str: any) => {
 | 
				
			|||||||
    return id;
 | 
					    return id;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function set(str: any) {
 | 
				
			||||||
 | 
					    let id = setWatermark(str);
 | 
				
			||||||
 | 
					    if (document.getElementById(id) === null) id = setWatermark(str);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function del() {
 | 
				
			||||||
 | 
					    let id = '1.23452384164.123412416';
 | 
				
			||||||
 | 
					    if (document.getElementById(id) !== null) document.body.removeChild(document.getElementById(id) as any);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const watermark = {
 | 
					const watermark = {
 | 
				
			||||||
 | 
					    use: () => {
 | 
				
			||||||
 | 
					        setTimeout(() => {
 | 
				
			||||||
 | 
					            const userinfo = getUserInfo4Session()
 | 
				
			||||||
 | 
					            if (userinfo && getUseWatermark4Session()) {
 | 
				
			||||||
 | 
					                set(`${userinfo.username} ${dateFormat('yyyy-MM-dd HH:mm:ss', new Date())}`)
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                del();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }, 1500)
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    // 设置水印
 | 
					    // 设置水印
 | 
				
			||||||
    set: (str: any) => {
 | 
					    set: (str: any) => {
 | 
				
			||||||
        let id = setWatermark(str);
 | 
					        set(str)
 | 
				
			||||||
        if (document.getElementById(id) === null) id = setWatermark(str);
 | 
					 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    // 删除水印
 | 
					    // 删除水印
 | 
				
			||||||
    del: () => {
 | 
					    del: () => {
 | 
				
			||||||
        let id = '1.23452384164.123412416';
 | 
					        del();
 | 
				
			||||||
        if (document.getElementById(id) !== null) document.body.removeChild(document.getElementById(id) as any);
 | 
					 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@ import RouterParent from '@/views/layout/routerView/parent.vue';
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export const imports = {
 | 
					export const imports = {
 | 
				
			||||||
    'RouterParent': RouterParent,
 | 
					    'RouterParent': RouterParent,
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    "Home": () => import('@/views/home/index.vue'),
 | 
					    "Home": () => import('@/views/home/index.vue'),
 | 
				
			||||||
    'Personal': () => import('@/views/personal/index.vue'),
 | 
					    'Personal': () => import('@/views/personal/index.vue'),
 | 
				
			||||||
    // machine
 | 
					    // machine
 | 
				
			||||||
@@ -11,6 +12,8 @@ export const imports = {
 | 
				
			|||||||
    "RoleList": () => import('@/views/system/role'),
 | 
					    "RoleList": () => import('@/views/system/role'),
 | 
				
			||||||
    "AccountList": () => import('@/views/system/account'),
 | 
					    "AccountList": () => import('@/views/system/account'),
 | 
				
			||||||
    "SyslogList": () => import('@/views/system/syslog/SyslogList.vue'),
 | 
					    "SyslogList": () => import('@/views/system/syslog/SyslogList.vue'),
 | 
				
			||||||
 | 
					    "ConfigList": () => import('@/views/system/config/ConfigList.vue'),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // project
 | 
					    // project
 | 
				
			||||||
    "ProjectList": () => import('@/views/ops/project/ProjectList.vue'),
 | 
					    "ProjectList": () => import('@/views/ops/project/ProjectList.vue'),
 | 
				
			||||||
    // db
 | 
					    // db
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -163,7 +163,17 @@ export const staticRoutes: Array<RouteRecordRaw> = [
 | 
				
			|||||||
            title: '终端 | {name}',
 | 
					            title: '终端 | {name}',
 | 
				
			||||||
            // 是否根据query对标题名进行参数替换,即最终显示为‘终端_机器名’
 | 
					            // 是否根据query对标题名进行参数替换,即最终显示为‘终端_机器名’
 | 
				
			||||||
            titleRename: true,
 | 
					            titleRename: true,
 | 
				
			||||||
            icon: 'iconfont icon-caidan',
 | 
					        },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        path: '/machine/terminal-rec',
 | 
				
			||||||
 | 
					        name: 'machineTerminalRec',
 | 
				
			||||||
 | 
					        component: () => import('@/views/ops/machine/MachineRec.vue'),
 | 
				
			||||||
 | 
					        meta: {
 | 
				
			||||||
 | 
					            // 将路径 'xxx?name=名字' 里的name字段值替换到title里
 | 
				
			||||||
 | 
					            title: '终端回放 | {name}',
 | 
				
			||||||
 | 
					            // 是否根据query对标题名进行参数替换,即最终显示为‘终端_机器名’
 | 
				
			||||||
 | 
					            titleRename: true,
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
];
 | 
					];
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -52,6 +52,7 @@ export interface ThemeConfigState {
 | 
				
			|||||||
        terminalBackground: string;
 | 
					        terminalBackground: string;
 | 
				
			||||||
        terminalCursor: string;
 | 
					        terminalCursor: string;
 | 
				
			||||||
        terminalFontSize: number;
 | 
					        terminalFontSize: number;
 | 
				
			||||||
 | 
					        terminalFontWeight: string;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -113,6 +113,7 @@ const themeConfigModule: Module<ThemeConfigState, RootStateTypes> = {
 | 
				
			|||||||
            // ssh终端cursor色
 | 
					            // ssh终端cursor色
 | 
				
			||||||
            terminalCursor: '#268F81',
 | 
					            terminalCursor: '#268F81',
 | 
				
			||||||
            terminalFontSize: 15,
 | 
					            terminalFontSize: 15,
 | 
				
			||||||
 | 
					            terminalFontWeight: 'normal',
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /* 后端控制路由
 | 
					            /* 后端控制路由
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,7 +14,7 @@ body,
 | 
				
			|||||||
	padding: 0;
 | 
						padding: 0;
 | 
				
			||||||
	width: 100%;
 | 
						width: 100%;
 | 
				
			||||||
	height: 100%;
 | 
						height: 100%;
 | 
				
			||||||
	font-family: Microsoft YaHei, Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, SimSun, sans-serif;
 | 
						font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
 | 
				
			||||||
	font-weight: 450;
 | 
						font-weight: 450;
 | 
				
			||||||
	-webkit-font-smoothing: antialiased;
 | 
						-webkit-font-smoothing: antialiased;
 | 
				
			||||||
	-webkit-tap-highlight-color: transparent;
 | 
						-webkit-tap-highlight-color: transparent;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -947,12 +947,6 @@
 | 
				
			|||||||
.el-select-dropdown .el-scrollbar__wrap {
 | 
					.el-select-dropdown .el-scrollbar__wrap {
 | 
				
			||||||
	overflow-x: scroll !important;
 | 
						overflow-x: scroll !important;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
.el-select-dropdown__wrap {
 | 
					 | 
				
			||||||
	max-height: 274px !important; /*修复Select 选择器高度问题*/
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
.el-cascader-menu__wrap.el-scrollbar__wrap {
 | 
					 | 
				
			||||||
	height: 204px !important; /*修复Cascader 级联选择器高度问题*/
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Drawer 抽屉
 | 
					/* Drawer 抽屉
 | 
				
			||||||
------------------------------- */
 | 
					------------------------------- */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,7 +40,7 @@
 | 
				
			|||||||
                        </el-input-number>
 | 
					                        </el-input-number>
 | 
				
			||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
                <!-- <div class="layout-breadcrumb-seting-bar-flex mt15">
 | 
					                <div class="layout-breadcrumb-seting-bar-flex mt15">
 | 
				
			||||||
                    <div class="layout-breadcrumb-seting-bar-flex-label">字体粗细</div>
 | 
					                    <div class="layout-breadcrumb-seting-bar-flex-label">字体粗细</div>
 | 
				
			||||||
                    <div class="layout-breadcrumb-seting-bar-flex-value">
 | 
					                    <div class="layout-breadcrumb-seting-bar-flex-value">
 | 
				
			||||||
                        <el-select @change="setLocalThemeConfig" v-model="getThemeConfig.terminalFontWeight" size="small" style="width: 90px">
 | 
					                        <el-select @change="setLocalThemeConfig" v-model="getThemeConfig.terminalFontWeight" size="small" style="width: 90px">
 | 
				
			||||||
@@ -48,7 +48,7 @@
 | 
				
			|||||||
                            <el-option label="bold" value="bold"> </el-option>
 | 
					                            <el-option label="bold" value="bold"> </el-option>
 | 
				
			||||||
                        </el-select>
 | 
					                        </el-select>
 | 
				
			||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
                </div> -->
 | 
					                </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                <!-- 全局主题 -->
 | 
					                <!-- 全局主题 -->
 | 
				
			||||||
                <el-divider content-position="left">全局主题</el-divider>
 | 
					                <el-divider content-position="left">全局主题</el-divider>
 | 
				
			||||||
@@ -273,23 +273,6 @@
 | 
				
			|||||||
                        <el-switch v-model="getThemeConfig.isInvert" @change="onAddFilterChange('invert')"></el-switch>
 | 
					                        <el-switch v-model="getThemeConfig.isInvert" @change="onAddFilterChange('invert')"></el-switch>
 | 
				
			||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
                <div class="layout-breadcrumb-seting-bar-flex mt15">
 | 
					 | 
				
			||||||
                    <div class="layout-breadcrumb-seting-bar-flex-label">开启水印</div>
 | 
					 | 
				
			||||||
                    <div class="layout-breadcrumb-seting-bar-flex-value">
 | 
					 | 
				
			||||||
                        <el-switch v-model="getThemeConfig.isWartermark" @change="onWartermarkChange"></el-switch>
 | 
					 | 
				
			||||||
                    </div>
 | 
					 | 
				
			||||||
                </div>
 | 
					 | 
				
			||||||
                <div class="layout-breadcrumb-seting-bar-flex mt14">
 | 
					 | 
				
			||||||
                    <div class="layout-breadcrumb-seting-bar-flex-label">水印文案</div>
 | 
					 | 
				
			||||||
                    <div class="layout-breadcrumb-seting-bar-flex-value">
 | 
					 | 
				
			||||||
                        <el-input
 | 
					 | 
				
			||||||
                            v-model="getThemeConfig.wartermarkText"
 | 
					 | 
				
			||||||
                            size="small"
 | 
					 | 
				
			||||||
                            style="width: 90px"
 | 
					 | 
				
			||||||
                            @input="onWartermarkTextInput($event)"
 | 
					 | 
				
			||||||
                        ></el-input>
 | 
					 | 
				
			||||||
                    </div>
 | 
					 | 
				
			||||||
                </div>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                <!-- 其它设置 -->
 | 
					                <!-- 其它设置 -->
 | 
				
			||||||
                <el-divider content-position="left">其他设置</el-divider>
 | 
					                <el-divider content-position="left">其他设置</el-divider>
 | 
				
			||||||
@@ -440,8 +423,6 @@ import { ElMessage } from 'element-plus';
 | 
				
			|||||||
import ClipboardJS from 'clipboard';
 | 
					import ClipboardJS from 'clipboard';
 | 
				
			||||||
import { useStore } from '@/store/index.ts';
 | 
					import { useStore } from '@/store/index.ts';
 | 
				
			||||||
import { getLightColor } from '@/common/utils/theme.ts';
 | 
					import { getLightColor } from '@/common/utils/theme.ts';
 | 
				
			||||||
import Watermark from '@/common/utils/wartermark.ts';
 | 
					 | 
				
			||||||
import { verifyAndSpace } from '@/common/utils/toolsValidate.ts';
 | 
					 | 
				
			||||||
import { setLocal, getLocal, removeLocal } from '@/common/utils/storage.ts';
 | 
					import { setLocal, getLocal, removeLocal } from '@/common/utils/storage.ts';
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'layoutBreadcrumbSeting',
 | 
					    name: 'layoutBreadcrumbSeting',
 | 
				
			||||||
@@ -572,18 +553,6 @@ export default defineComponent({
 | 
				
			|||||||
            setLocalThemeConfig();
 | 
					            setLocalThemeConfig();
 | 
				
			||||||
            setLocal('appFilterStyle', appEle.style.cssText);
 | 
					            setLocal('appFilterStyle', appEle.style.cssText);
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
        // 4、界面显示 --> 开启水印
 | 
					 | 
				
			||||||
        const onWartermarkChange = () => {
 | 
					 | 
				
			||||||
            getThemeConfig.value.isWartermark ? Watermark.set(getThemeConfig.value.wartermarkText) : Watermark.del();
 | 
					 | 
				
			||||||
            setLocalThemeConfig();
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
        // 4、界面显示 --> 水印文案
 | 
					 | 
				
			||||||
        const onWartermarkTextInput = (val: string) => {
 | 
					 | 
				
			||||||
            getThemeConfig.value.wartermarkText = verifyAndSpace(val);
 | 
					 | 
				
			||||||
            if (getThemeConfig.value.wartermarkText === '') return false;
 | 
					 | 
				
			||||||
            if (getThemeConfig.value.isWartermark) Watermark.set(getThemeConfig.value.wartermarkText);
 | 
					 | 
				
			||||||
            setLocalThemeConfig();
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
        // 5、布局切换
 | 
					        // 5、布局切换
 | 
				
			||||||
        const onSetLayout = (layout: string) => {
 | 
					        const onSetLayout = (layout: string) => {
 | 
				
			||||||
            setLocal('oldLayout', layout);
 | 
					            setLocal('oldLayout', layout);
 | 
				
			||||||
@@ -735,8 +704,6 @@ export default defineComponent({
 | 
				
			|||||||
                            const appEl: any = document.querySelector('#app');
 | 
					                            const appEl: any = document.querySelector('#app');
 | 
				
			||||||
                            appEl.style.cssText = getLocal('appFilterStyle');
 | 
					                            appEl.style.cssText = getLocal('appFilterStyle');
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        // 开启水印
 | 
					 | 
				
			||||||
                        onWartermarkChange();
 | 
					 | 
				
			||||||
                        // // 语言国际化
 | 
					                        // // 语言国际化
 | 
				
			||||||
                        // if (getLocal('themeConfig')) proxy.$i18n.locale = getLocal('themeConfig').globalI18n;
 | 
					                        // if (getLocal('themeConfig')) proxy.$i18n.locale = getLocal('themeConfig').globalI18n;
 | 
				
			||||||
                    }, 1100);
 | 
					                    }, 1100);
 | 
				
			||||||
@@ -762,8 +729,6 @@ export default defineComponent({
 | 
				
			|||||||
            getThemeConfig,
 | 
					            getThemeConfig,
 | 
				
			||||||
            onDrawerClose,
 | 
					            onDrawerClose,
 | 
				
			||||||
            onAddFilterChange,
 | 
					            onAddFilterChange,
 | 
				
			||||||
            onWartermarkChange,
 | 
					 | 
				
			||||||
            onWartermarkTextInput,
 | 
					 | 
				
			||||||
            onSetLayout,
 | 
					            onSetLayout,
 | 
				
			||||||
            setLocalThemeConfig,
 | 
					            setLocalThemeConfig,
 | 
				
			||||||
            onClassicSplitMenuChange,
 | 
					            onClassicSplitMenuChange,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,11 +14,11 @@
 | 
				
			|||||||
                </el-dropdown-menu>
 | 
					                </el-dropdown-menu>
 | 
				
			||||||
            </template>
 | 
					            </template>
 | 
				
			||||||
        </el-dropdown>
 | 
					        </el-dropdown>
 | 
				
			||||||
        <div class="layout-navbars-breadcrumb-user-icon" @click="onSearchClick">
 | 
					        <!-- <div class="layout-navbars-breadcrumb-user-icon" @click="onSearchClick">
 | 
				
			||||||
            <el-icon title="菜单搜索">
 | 
					            <el-icon title="菜单搜索">
 | 
				
			||||||
                <search />
 | 
					                <search />
 | 
				
			||||||
            </el-icon>
 | 
					            </el-icon>
 | 
				
			||||||
        </div>
 | 
					        </div> -->
 | 
				
			||||||
        <div class="layout-navbars-breadcrumb-user-icon" @click="onLayoutSetingClick">
 | 
					        <div class="layout-navbars-breadcrumb-user-icon" @click="onLayoutSetingClick">
 | 
				
			||||||
            <el-icon title="布局设置">
 | 
					            <el-icon title="布局设置">
 | 
				
			||||||
                <setting />
 | 
					                <setting />
 | 
				
			||||||
@@ -28,7 +28,7 @@
 | 
				
			|||||||
            <el-popover
 | 
					            <el-popover
 | 
				
			||||||
                placement="bottom"
 | 
					                placement="bottom"
 | 
				
			||||||
                trigger="click"
 | 
					                trigger="click"
 | 
				
			||||||
                v-model:visible="isShowUserNewsPopover"
 | 
					                :visible="isShowUserNewsPopover"
 | 
				
			||||||
                :width="300"
 | 
					                :width="300"
 | 
				
			||||||
                popper-class="el-popover-pupop-user-news"
 | 
					                popper-class="el-popover-pupop-user-news"
 | 
				
			||||||
            >
 | 
					            >
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,66 +1,90 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
    <el-form ref="loginFormRef" :model="loginForm" :rules="rules" class="login-content-form" size="large">
 | 
					    <div>
 | 
				
			||||||
        <el-form-item prop="username">
 | 
					        <el-form ref="loginFormRef" :model="loginForm" :rules="rules" class="login-content-form" size="large">
 | 
				
			||||||
            <el-input type="text" placeholder="请输入用户名" prefix-icon="user" v-model="loginForm.username" clearable autocomplete="off">
 | 
					            <el-form-item prop="username">
 | 
				
			||||||
            </el-input>
 | 
					                <el-input type="text" placeholder="请输入用户名" prefix-icon="user" v-model="loginForm.username" clearable autocomplete="off">
 | 
				
			||||||
        </el-form-item>
 | 
					                </el-input>
 | 
				
			||||||
        <el-form-item prop="password">
 | 
					            </el-form-item>
 | 
				
			||||||
            <el-input
 | 
					            <el-form-item prop="password">
 | 
				
			||||||
                type="password"
 | 
					                <el-input type="password" placeholder="请输入密码" prefix-icon="lock" v-model="loginForm.password" autocomplete="off" show-password>
 | 
				
			||||||
                placeholder="请输入密码"
 | 
					                </el-input>
 | 
				
			||||||
                prefix-icon="lock"
 | 
					            </el-form-item>
 | 
				
			||||||
                v-model="loginForm.password"
 | 
					            <el-form-item v-if="useLoginCaptcha" prop="captcha">
 | 
				
			||||||
                autocomplete="off"
 | 
					                <el-row :gutter="15">
 | 
				
			||||||
                show-password
 | 
					                    <el-col :span="16">
 | 
				
			||||||
            >
 | 
					                        <el-input
 | 
				
			||||||
            </el-input>
 | 
					                            type="text"
 | 
				
			||||||
        </el-form-item>
 | 
					                            maxlength="6"
 | 
				
			||||||
        <el-form-item prop="captcha">
 | 
					                            placeholder="请输入验证码"
 | 
				
			||||||
            <el-row :gutter="15">
 | 
					                            prefix-icon="position"
 | 
				
			||||||
                <el-col :span="16">
 | 
					                            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
 | 
					                    <el-input
 | 
				
			||||||
                        type="text"
 | 
					                        v-model.trim="changePwdDialog.form.newPassword"
 | 
				
			||||||
                        maxlength="6"
 | 
					                        placeholder="须为8位以上且包含字⺟⼤⼩写+数字+特殊符号"
 | 
				
			||||||
                        placeholder="请输入验证码"
 | 
					                        type="password"
 | 
				
			||||||
                        prefix-icon="position"
 | 
					                        autocomplete="new-password"
 | 
				
			||||||
                        v-model="loginForm.captcha"
 | 
					 | 
				
			||||||
                        clearable
 | 
					 | 
				
			||||||
                        autocomplete="off"
 | 
					 | 
				
			||||||
                        @keyup.enter="login"
 | 
					 | 
				
			||||||
                    ></el-input>
 | 
					                    ></el-input>
 | 
				
			||||||
                </el-col>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-col :span="8">
 | 
					            </el-form>
 | 
				
			||||||
                    <div class="login-content-code">
 | 
					
 | 
				
			||||||
                        <img
 | 
					            <template #footer>
 | 
				
			||||||
                            class="login-content-code-img"
 | 
					                <div class="dialog-footer">
 | 
				
			||||||
                            @click="getCaptcha"
 | 
					                    <el-button @click="cancelChangePwd">取 消</el-button>
 | 
				
			||||||
                            width="130px"
 | 
					                    <el-button @click="changePwd" type="primary" :loading="loading.changePwd">确 定</el-button>
 | 
				
			||||||
                            height="40px"
 | 
					                </div>
 | 
				
			||||||
                            :src="captchaImage"
 | 
					            </template>
 | 
				
			||||||
                            style="cursor: pointer"
 | 
					        </el-dialog>
 | 
				
			||||||
                        />
 | 
					    </div>
 | 
				
			||||||
                    </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>
 | 
					 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script lang="ts">
 | 
					<script lang="ts">
 | 
				
			||||||
import { onMounted, ref, toRefs, reactive, defineComponent, computed } from 'vue';
 | 
					import { nextTick, onMounted, ref, toRefs, reactive, defineComponent, computed } from 'vue';
 | 
				
			||||||
import { useRoute, useRouter } from 'vue-router';
 | 
					import { useRoute, useRouter } from 'vue-router';
 | 
				
			||||||
import { ElMessage } from 'element-plus';
 | 
					import { ElMessage } from 'element-plus';
 | 
				
			||||||
import { initBackEndControlRoutesFun } from '@/router/index.ts';
 | 
					import { initBackEndControlRoutesFun } from '@/router/index.ts';
 | 
				
			||||||
import { useStore } from '@/store/index.ts';
 | 
					import { useStore } from '@/store/index.ts';
 | 
				
			||||||
import { setSession } from '@/common/utils/storage.ts';
 | 
					import { setSession, setUserInfo2Session, setUseWatermark2Session } from '@/common/utils/storage.ts';
 | 
				
			||||||
import { formatAxis } from '@/common/utils/formatTime.ts';
 | 
					import { formatAxis } from '@/common/utils/formatTime.ts';
 | 
				
			||||||
import openApi from '@/common/openApi';
 | 
					import openApi from '@/common/openApi';
 | 
				
			||||||
 | 
					import { RsaEncrypt } from '@/common/rsa';
 | 
				
			||||||
 | 
					import { useLoginCaptcha, useWartermark } from '@/common/sysconfig';
 | 
				
			||||||
import { letterAvatar } from '@/common/utils/string';
 | 
					import { letterAvatar } from '@/common/utils/string';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'AccountLogin',
 | 
					    name: 'AccountLogin',
 | 
				
			||||||
    setup() {
 | 
					    setup() {
 | 
				
			||||||
@@ -68,7 +92,10 @@ export default defineComponent({
 | 
				
			|||||||
        const route = useRoute();
 | 
					        const route = useRoute();
 | 
				
			||||||
        const router = useRouter();
 | 
					        const router = useRouter();
 | 
				
			||||||
        const loginFormRef: any = ref(null);
 | 
					        const loginFormRef: any = ref(null);
 | 
				
			||||||
 | 
					        const changePwdFormRef: any = ref(null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const state = reactive({
 | 
					        const state = reactive({
 | 
				
			||||||
 | 
					            useLoginCaptcha: false,
 | 
				
			||||||
            captchaImage: '',
 | 
					            captchaImage: '',
 | 
				
			||||||
            loginForm: {
 | 
					            loginForm: {
 | 
				
			||||||
                username: '',
 | 
					                username: '',
 | 
				
			||||||
@@ -76,6 +103,24 @@ export default defineComponent({
 | 
				
			|||||||
                captcha: '',
 | 
					                captcha: '',
 | 
				
			||||||
                cid: '',
 | 
					                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: {
 | 
					            rules: {
 | 
				
			||||||
                username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
 | 
					                username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
 | 
				
			||||||
                password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
 | 
					                password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
 | 
				
			||||||
@@ -83,14 +128,23 @@ export default defineComponent({
 | 
				
			|||||||
            },
 | 
					            },
 | 
				
			||||||
            loading: {
 | 
					            loading: {
 | 
				
			||||||
                signIn: false,
 | 
					                signIn: false,
 | 
				
			||||||
 | 
					                changePwd: false,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        onMounted(() => {
 | 
					        onMounted(async () => {
 | 
				
			||||||
            getCaptcha();
 | 
					            nextTick(async () => {
 | 
				
			||||||
 | 
					                state.useLoginCaptcha = await useLoginCaptcha();
 | 
				
			||||||
 | 
					                getCaptcha();
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            // 移除公钥, 方便后续重新获取
 | 
				
			||||||
 | 
					            sessionStorage.removeItem('RsaPublicKey');
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const getCaptcha = async () => {
 | 
					        const getCaptcha = async () => {
 | 
				
			||||||
 | 
					            if (!state.useLoginCaptcha) {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            let res: any = await openApi.captcha();
 | 
					            let res: any = await openApi.captcha();
 | 
				
			||||||
            state.captchaImage = res.base64Captcha;
 | 
					            state.captchaImage = res.base64Captcha;
 | 
				
			||||||
            state.loginForm.cid = res.cid;
 | 
					            state.loginForm.cid = res.cid;
 | 
				
			||||||
@@ -116,15 +170,26 @@ export default defineComponent({
 | 
				
			|||||||
        const onSignIn = async () => {
 | 
					        const onSignIn = async () => {
 | 
				
			||||||
            state.loading.signIn = true;
 | 
					            state.loading.signIn = true;
 | 
				
			||||||
            let loginRes;
 | 
					            let loginRes;
 | 
				
			||||||
 | 
					            const originPwd = state.loginForm.password;
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                loginRes = await openApi.login(state.loginForm);
 | 
					                const loginReq = { ...state.loginForm };
 | 
				
			||||||
                // // 存储 token 到浏览器缓存
 | 
					                loginReq.password = await RsaEncrypt(originPwd);
 | 
				
			||||||
 | 
					                loginRes = await openApi.login(loginReq);
 | 
				
			||||||
 | 
					                // 存储 token 到浏览器缓存
 | 
				
			||||||
                setSession('token', loginRes.token);
 | 
					                setSession('token', loginRes.token);
 | 
				
			||||||
                setSession('menus', loginRes.menus);
 | 
					                setSession('menus', loginRes.menus);
 | 
				
			||||||
            } catch (e) {
 | 
					            } catch (e: any) {
 | 
				
			||||||
                state.loading.signIn = false;
 | 
					                state.loading.signIn = false;
 | 
				
			||||||
                state.loginForm.captcha = '';
 | 
					                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;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            // 用户信息
 | 
					            // 用户信息
 | 
				
			||||||
@@ -141,7 +206,7 @@ export default defineComponent({
 | 
				
			|||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // 存储用户信息到浏览器缓存
 | 
					            // 存储用户信息到浏览器缓存
 | 
				
			||||||
            setSession('userInfo', userInfos);
 | 
					            setUserInfo2Session(userInfos);
 | 
				
			||||||
            // 1、请注意执行顺序(存储用户信息到vuex)
 | 
					            // 1、请注意执行顺序(存储用户信息到vuex)
 | 
				
			||||||
            store.dispatch('userInfos/setUserInfos', userInfos);
 | 
					            store.dispatch('userInfos/setUserInfos', userInfos);
 | 
				
			||||||
            if (!store.state.themeConfig.themeConfig.isRequestRoutes) {
 | 
					            if (!store.state.themeConfig.themeConfig.isRequestRoutes) {
 | 
				
			||||||
@@ -167,18 +232,54 @@ export default defineComponent({
 | 
				
			|||||||
            // 如果是复制粘贴的路径,非首页/登录页,那么登录成功后重定向到对应的路径中
 | 
					            // 如果是复制粘贴的路径,非首页/登录页,那么登录成功后重定向到对应的路径中
 | 
				
			||||||
            route.query?.redirect ? router.push(route.query.redirect as string) : router.push('/');
 | 
					            route.query?.redirect ? router.push(route.query.redirect as string) : router.push('/');
 | 
				
			||||||
            // 登录成功提示
 | 
					            // 登录成功提示
 | 
				
			||||||
            setTimeout(() => {
 | 
					            setTimeout(async () => {
 | 
				
			||||||
                // 关闭 loading
 | 
					                // 关闭 loading
 | 
				
			||||||
                state.loading.signIn = true;
 | 
					                state.loading.signIn = true;
 | 
				
			||||||
                ElMessage.success(`${currentTimeInfo},欢迎回来!`);
 | 
					                ElMessage.success(`${currentTimeInfo},欢迎回来!`);
 | 
				
			||||||
 | 
					                if (await useWartermark()) {
 | 
				
			||||||
 | 
					                    setUseWatermark2Session(true);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }, 300);
 | 
					            }, 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 {
 | 
					        return {
 | 
				
			||||||
            getCaptcha,
 | 
					            getCaptcha,
 | 
				
			||||||
            currentTime,
 | 
					            currentTime,
 | 
				
			||||||
            loginFormRef,
 | 
					            loginFormRef,
 | 
				
			||||||
 | 
					            changePwdFormRef,
 | 
				
			||||||
            login,
 | 
					            login,
 | 
				
			||||||
 | 
					            changePwd,
 | 
				
			||||||
 | 
					            cancelChangePwd,
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,10 +23,13 @@
 | 
				
			|||||||
                    </el-select>
 | 
					                    </el-select>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="host" label="host:" required>
 | 
					                <el-form-item prop="host" label="host:" required>
 | 
				
			||||||
                    <el-input v-model.trim="form.host" placeholder="请输入主机ip" auto-complete="off"></el-input>
 | 
					                    <el-col :span="18">
 | 
				
			||||||
                </el-form-item>
 | 
					                        <el-input :disabled="form.id" v-model.trim="form.host" placeholder="请输入主机ip" auto-complete="off"></el-input>
 | 
				
			||||||
                <el-form-item prop="port" label="port:" required>
 | 
					                    </el-col>
 | 
				
			||||||
                    <el-input type="number" v-model.trim="form.port" placeholder="请输入端口"></el-input>
 | 
					                    <el-col style="text-align: center" :span="1">:</el-col>
 | 
				
			||||||
 | 
					                    <el-col :span="5">
 | 
				
			||||||
 | 
					                        <el-input type="number" v-model.number="form.port" placeholder="请输入端口"></el-input>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="username" label="用户名:" required>
 | 
					                <el-form-item prop="username" label="用户名:" required>
 | 
				
			||||||
                    <el-input v-model.trim="form.username" placeholder="请输入用户名"></el-input>
 | 
					                    <el-input v-model.trim="form.username" placeholder="请输入用户名"></el-input>
 | 
				
			||||||
@@ -38,34 +41,57 @@
 | 
				
			|||||||
                        v-model.trim="form.password"
 | 
					                        v-model.trim="form.password"
 | 
				
			||||||
                        placeholder="请输入密码,修改操作可不填"
 | 
					                        placeholder="请输入密码,修改操作可不填"
 | 
				
			||||||
                        autocomplete="new-password"
 | 
					                        autocomplete="new-password"
 | 
				
			||||||
                    ></el-input>
 | 
					                    >
 | 
				
			||||||
 | 
					                        <template v-if="form.id && form.id != 0" #suffix>
 | 
				
			||||||
 | 
					                            <el-popover @hide="pwd = ''" placement="right" title="原密码" :width="200" trigger="click" :content="pwd">
 | 
				
			||||||
 | 
					                                <template #reference>
 | 
				
			||||||
 | 
					                                    <el-link @click="getDbPwd" :underline="false" type="primary" class="mr5">原密码</el-link>
 | 
				
			||||||
 | 
					                                </template>
 | 
				
			||||||
 | 
					                            </el-popover>
 | 
				
			||||||
 | 
					                        </template>
 | 
				
			||||||
 | 
					                    </el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="params" label="连接参数:">
 | 
					                <el-form-item prop="params" label="连接参数:">
 | 
				
			||||||
                    <el-input v-model="form.params" placeholder="其他连接参数,形如: key1=value1&key2=value2"></el-input>
 | 
					                    <el-input v-model="form.params" placeholder="其他连接参数,形如: key1=value1&key2=value2"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="database" label="数据库名:" required>
 | 
					                <el-form-item prop="database" label="数据库名:" required>
 | 
				
			||||||
                    <el-tag
 | 
					                    <el-col :span="19">
 | 
				
			||||||
                        v-for="db in databaseList"
 | 
					                        <el-select
 | 
				
			||||||
                        :key="db"
 | 
					                            @change="changeDatabase"
 | 
				
			||||||
                        class="ml5 mt5"
 | 
					                            v-model="databaseList"
 | 
				
			||||||
                        type="success"
 | 
					                            multiple
 | 
				
			||||||
                        effect="plain"
 | 
					                            collapse-tags
 | 
				
			||||||
                        closable
 | 
					                            collapse-tags-tooltip
 | 
				
			||||||
                        :disable-transitions="false"
 | 
					                            filterable
 | 
				
			||||||
                        @close="handleClose(db)"
 | 
					                            allow-create
 | 
				
			||||||
                    >
 | 
					                            placeholder="请确保数据库实例信息填写完整后获取库名"
 | 
				
			||||||
                        {{ db }}
 | 
					                            style="width: 100%"
 | 
				
			||||||
                    </el-tag>
 | 
					                        >
 | 
				
			||||||
                    <el-input
 | 
					                            <el-option v-for="db in allDatabases" :key="db" :label="db" :value="db" />
 | 
				
			||||||
                        v-if="inputDbVisible"
 | 
					                        </el-select>
 | 
				
			||||||
                        ref="InputDbRef"
 | 
					                    </el-col>
 | 
				
			||||||
                        v-model="inputDbValue"
 | 
					                    <el-col style="text-align: center" :span="1"><el-divider direction="vertical" border-style="dashed" /></el-col>
 | 
				
			||||||
                        style="width: 120px; margin-left: 5px; margin-top: 5px"
 | 
					                    <el-col :span="4">
 | 
				
			||||||
                        size="small"
 | 
					                        <el-link @click="getAllDatabase" :underline="false" type="success">获取库名</el-link>
 | 
				
			||||||
                        @keyup.enter="handleInputDbConfirm"
 | 
					                    </el-col>
 | 
				
			||||||
                        @blur="handleInputDbConfirm"
 | 
					                </el-form-item>
 | 
				
			||||||
                    />
 | 
					
 | 
				
			||||||
                    <el-button v-else class="ml5 mt5" size="small" @click="showInputDb"> + 添加数据库 </el-button>
 | 
					                <el-form-item prop="enableSshTunnel" label="SSH隧道:">
 | 
				
			||||||
 | 
					                    <el-col :span="3">
 | 
				
			||||||
 | 
					                        <el-checkbox @change="getSshTunnelMachines" v-model="form.enableSshTunnel" :true-label="1" :false-label="-1"></el-checkbox>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
 | 
					                    <el-col :span="2" v-if="form.enableSshTunnel == 1"> 机器: </el-col>
 | 
				
			||||||
 | 
					                    <el-col :span="19" v-if="form.enableSshTunnel == 1">
 | 
				
			||||||
 | 
					                        <el-select style="width: 100%" v-model="form.sshTunnelMachineId" placeholder="请选择SSH隧道机器">
 | 
				
			||||||
 | 
					                            <el-option
 | 
				
			||||||
 | 
					                                v-for="item in sshTunnelMachineList"
 | 
				
			||||||
 | 
					                                :key="item.id"
 | 
				
			||||||
 | 
					                                :label="`${item.ip}:${item.port} [${item.name}]`"
 | 
				
			||||||
 | 
					                                :value="item.id"
 | 
				
			||||||
 | 
					                            >
 | 
				
			||||||
 | 
					                            </el-option>
 | 
				
			||||||
 | 
					                        </el-select>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
            </el-form>
 | 
					            </el-form>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -80,12 +106,13 @@
 | 
				
			|||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script lang="ts">
 | 
					<script lang="ts">
 | 
				
			||||||
import { toRefs, reactive, nextTick, watch, defineComponent, ref } from 'vue';
 | 
					import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
 | 
				
			||||||
import { dbApi } from './api';
 | 
					import { dbApi } from './api';
 | 
				
			||||||
import { projectApi } from '../project/api.ts';
 | 
					import { projectApi } from '../project/api.ts';
 | 
				
			||||||
 | 
					import { machineApi } from '../machine/api.ts';
 | 
				
			||||||
import { ElMessage } from 'element-plus';
 | 
					import { ElMessage } from 'element-plus';
 | 
				
			||||||
import type { ElInput } from 'element-plus';
 | 
					 | 
				
			||||||
import { notBlank } from '@/common/assert';
 | 
					import { notBlank } from '@/common/assert';
 | 
				
			||||||
 | 
					import { RsaEncrypt } from '@/common/rsa';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'DbEdit',
 | 
					    name: 'DbEdit',
 | 
				
			||||||
@@ -105,15 +132,14 @@ export default defineComponent({
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
    setup(props: any, { emit }) {
 | 
					    setup(props: any, { emit }) {
 | 
				
			||||||
        const dbForm: any = ref(null);
 | 
					        const dbForm: any = ref(null);
 | 
				
			||||||
        const InputDbRef = ref<InstanceType<typeof ElInput>>();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const state = reactive({
 | 
					        const state = reactive({
 | 
				
			||||||
            dialogVisible: false,
 | 
					            dialogVisible: false,
 | 
				
			||||||
            projects: [],
 | 
					            projects: [],
 | 
				
			||||||
            envs: [],
 | 
					            envs: [],
 | 
				
			||||||
 | 
					            allDatabases: [] as any,
 | 
				
			||||||
            databaseList: [] as any,
 | 
					            databaseList: [] as any,
 | 
				
			||||||
            inputDbVisible: false,
 | 
					            sshTunnelMachineList: [],
 | 
				
			||||||
            inputDbValue: '',
 | 
					 | 
				
			||||||
            form: {
 | 
					            form: {
 | 
				
			||||||
                id: null,
 | 
					                id: null,
 | 
				
			||||||
                name: null,
 | 
					                name: null,
 | 
				
			||||||
@@ -126,7 +152,11 @@ export default defineComponent({
 | 
				
			|||||||
                projectId: null,
 | 
					                projectId: null,
 | 
				
			||||||
                envId: null,
 | 
					                envId: null,
 | 
				
			||||||
                env: null,
 | 
					                env: null,
 | 
				
			||||||
 | 
					                enableSshTunnel: null,
 | 
				
			||||||
 | 
					                sshTunnelMachineId: null,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
 | 
					            // 原密码
 | 
				
			||||||
 | 
					            pwd: '',
 | 
				
			||||||
            btnLoading: false,
 | 
					            btnLoading: false,
 | 
				
			||||||
            rules: {
 | 
					            rules: {
 | 
				
			||||||
                projectId: [
 | 
					                projectId: [
 | 
				
			||||||
@@ -160,14 +190,7 @@ export default defineComponent({
 | 
				
			|||||||
                host: [
 | 
					                host: [
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        required: true,
 | 
					                        required: true,
 | 
				
			||||||
                        message: '请输入主机ip',
 | 
					                        message: '请输入主机ip和port',
 | 
				
			||||||
                        trigger: ['change', 'blur'],
 | 
					 | 
				
			||||||
                    },
 | 
					 | 
				
			||||||
                ],
 | 
					 | 
				
			||||||
                port: [
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        required: true,
 | 
					 | 
				
			||||||
                        message: '请输入端口',
 | 
					 | 
				
			||||||
                        trigger: ['change', 'blur'],
 | 
					                        trigger: ['change', 'blur'],
 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
                ],
 | 
					                ],
 | 
				
			||||||
@@ -189,6 +212,10 @@ export default defineComponent({
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        watch(props, (newValue) => {
 | 
					        watch(props, (newValue) => {
 | 
				
			||||||
 | 
					            state.dialogVisible = newValue.visible;
 | 
				
			||||||
 | 
					            if (!state.dialogVisible) {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            state.projects = newValue.projects;
 | 
					            state.projects = newValue.projects;
 | 
				
			||||||
            if (newValue.db) {
 | 
					            if (newValue.db) {
 | 
				
			||||||
                getEnvs(newValue.db.projectId);
 | 
					                getEnvs(newValue.db.projectId);
 | 
				
			||||||
@@ -197,33 +224,12 @@ export default defineComponent({
 | 
				
			|||||||
                state.databaseList = newValue.db.database.split(' ');
 | 
					                state.databaseList = newValue.db.database.split(' ');
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                state.envs = [];
 | 
					                state.envs = [];
 | 
				
			||||||
                state.form = { port: 3306 } as any;
 | 
					                state.form = { port: 3306, enableSshTunnel: -1 } as any;
 | 
				
			||||||
                state.databaseList = [];
 | 
					                state.databaseList = [];
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            state.dialogVisible = newValue.visible;
 | 
					            getSshTunnelMachines();
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const handleClose = (db: string) => {
 | 
					 | 
				
			||||||
            state.databaseList.splice(state.databaseList.indexOf(db), 1);
 | 
					 | 
				
			||||||
            changeDatabase();
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const showInputDb = () => {
 | 
					 | 
				
			||||||
            state.inputDbVisible = true;
 | 
					 | 
				
			||||||
            nextTick(() => {
 | 
					 | 
				
			||||||
                InputDbRef.value!.input!.focus();
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const handleInputDbConfirm = () => {
 | 
					 | 
				
			||||||
            if (state.inputDbValue) {
 | 
					 | 
				
			||||||
                state.databaseList.push(state.inputDbValue);
 | 
					 | 
				
			||||||
                changeDatabase();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            state.inputDbVisible = false;
 | 
					 | 
				
			||||||
            state.inputDbValue = '';
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        /**
 | 
					        /**
 | 
				
			||||||
         * 改变表单中的数据库字段,方便表单错误提示。如全部删光,可提示请添加数据库
 | 
					         * 改变表单中的数据库字段,方便表单错误提示。如全部删光,可提示请添加数据库
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
@@ -231,6 +237,13 @@ export default defineComponent({
 | 
				
			|||||||
            state.form.database = state.databaseList.length == 0 ? '' : state.databaseList.join(' ');
 | 
					            state.form.database = state.databaseList.length == 0 ? '' : state.databaseList.join(' ');
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getSshTunnelMachines = async () => {
 | 
				
			||||||
 | 
					            if (state.form.enableSshTunnel == 1 && state.sshTunnelMachineList.length == 0) {
 | 
				
			||||||
 | 
					                const res = await machineApi.list.request({ pageNum: 1, pageSize: 100 });
 | 
				
			||||||
 | 
					                state.sshTunnelMachineList = res.list;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const getEnvs = async (projectId: any) => {
 | 
					        const getEnvs = async (projectId: any) => {
 | 
				
			||||||
            state.envs = await projectApi.projectEnvs.request({ projectId });
 | 
					            state.envs = await projectApi.projectEnvs.request({ projectId });
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
@@ -255,14 +268,26 @@ export default defineComponent({
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getAllDatabase = async () => {
 | 
				
			||||||
 | 
					            const reqForm = { ...state.form };
 | 
				
			||||||
 | 
					            reqForm.password = await RsaEncrypt(reqForm.password);
 | 
				
			||||||
 | 
					            state.allDatabases = await dbApi.getAllDatabase.request(reqForm);
 | 
				
			||||||
 | 
					            ElMessage.success('获取成功, 请选择需要管理操作的数据库')
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getDbPwd = async () => {
 | 
				
			||||||
 | 
					            state.pwd = await dbApi.getDbPwd.request({ id: state.form.id });
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const btnOk = async () => {
 | 
					        const btnOk = async () => {
 | 
				
			||||||
            if (!state.form.id) {
 | 
					            if (!state.form.id) {
 | 
				
			||||||
                notBlank(state.form.password, '新增操作,密码不可为空');
 | 
					                notBlank(state.form.password, '新增操作,密码不可为空');
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            dbForm.value.validate((valid: boolean) => {
 | 
					            dbForm.value.validate(async (valid: boolean) => {
 | 
				
			||||||
                if (valid) {
 | 
					                if (valid) {
 | 
				
			||||||
                    state.form.port = Number.parseInt(state.form.port as any);
 | 
					                    const reqForm = { ...state.form };
 | 
				
			||||||
                    dbApi.saveDb.request(state.form).then(() => {
 | 
					                    reqForm.password = await RsaEncrypt(reqForm.password);
 | 
				
			||||||
 | 
					                    dbApi.saveDb.request(reqForm).then(() => {
 | 
				
			||||||
                        ElMessage.success('保存成功');
 | 
					                        ElMessage.success('保存成功');
 | 
				
			||||||
                        emit('val-change', state.form);
 | 
					                        emit('val-change', state.form);
 | 
				
			||||||
                        state.btnLoading = true;
 | 
					                        state.btnLoading = true;
 | 
				
			||||||
@@ -280,9 +305,8 @@ export default defineComponent({
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const resetInputDb = () => {
 | 
					        const resetInputDb = () => {
 | 
				
			||||||
            state.inputDbVisible = false;
 | 
					 | 
				
			||||||
            state.databaseList = [];
 | 
					            state.databaseList = [];
 | 
				
			||||||
            state.inputDbValue = '';
 | 
					            state.allDatabases = [];
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const cancel = () => {
 | 
					        const cancel = () => {
 | 
				
			||||||
@@ -296,10 +320,10 @@ export default defineComponent({
 | 
				
			|||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
            dbForm,
 | 
					            dbForm,
 | 
				
			||||||
            InputDbRef,
 | 
					            getAllDatabase,
 | 
				
			||||||
            handleClose,
 | 
					            getDbPwd,
 | 
				
			||||||
            showInputDb,
 | 
					            changeDatabase,
 | 
				
			||||||
            handleInputDbConfirm,
 | 
					            getSshTunnelMachines,
 | 
				
			||||||
            changeProject,
 | 
					            changeProject,
 | 
				
			||||||
            changeEnv,
 | 
					            changeEnv,
 | 
				
			||||||
            btnOk,
 | 
					            btnOk,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,7 +7,7 @@
 | 
				
			|||||||
                >删除</el-button
 | 
					                >删除</el-button
 | 
				
			||||||
            >
 | 
					            >
 | 
				
			||||||
            <div style="float: right">
 | 
					            <div style="float: right">
 | 
				
			||||||
                <el-select v-model="query.projectId" placeholder="请选择项目" filterable clearable>
 | 
					                <el-select @focus="getProjects" v-model="query.projectId" placeholder="请选择项目" filterable clearable>
 | 
				
			||||||
                    <el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
 | 
					                    <el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
 | 
				
			||||||
                </el-select>
 | 
					                </el-select>
 | 
				
			||||||
                <el-button v-waves type="primary" icon="search" @click="search()" class="ml5">查询</el-button>
 | 
					                <el-button v-waves type="primary" icon="search" @click="search()" class="ml5">查询</el-button>
 | 
				
			||||||
@@ -29,24 +29,29 @@
 | 
				
			|||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
                </el-table-column>
 | 
					                </el-table-column>
 | 
				
			||||||
                <el-table-column prop="type" label="类型" min-width="90"></el-table-column>
 | 
					                <el-table-column prop="type" label="类型" min-width="90"></el-table-column>
 | 
				
			||||||
                <el-table-column prop="database" label="数据库" min-width="160">
 | 
					                <el-table-column prop="database" label="数据库" min-width="80">
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        <el-tag
 | 
					                        <el-popover :width="250" placement="right" trigger="click">
 | 
				
			||||||
                            @click="showTableInfo(scope.row, db)"
 | 
					                            <template #reference>
 | 
				
			||||||
                            effect="plain"
 | 
					                                <el-link type="primary" :underline="false" plain>查看</el-link>
 | 
				
			||||||
                            type="success"
 | 
					                            </template>
 | 
				
			||||||
                            size="small"
 | 
					                            <el-tag
 | 
				
			||||||
                            v-for="db in scope.row.dbs"
 | 
					                                @click="showTableInfo(scope.row, db)"
 | 
				
			||||||
                            :key="db"
 | 
					                                effect="plain"
 | 
				
			||||||
                            style="cursor: pointer; margin-left: 3px"
 | 
					                                type="success"
 | 
				
			||||||
                            >{{ db }}</el-tag
 | 
					                                size="small"
 | 
				
			||||||
                        >
 | 
					                                v-for="db in scope.row.dbs"
 | 
				
			||||||
 | 
					                                :key="db"
 | 
				
			||||||
 | 
					                                style="cursor: pointer; margin-left: 3px; margin-bottom: 3px;"
 | 
				
			||||||
 | 
					                                >{{ db }}</el-tag
 | 
				
			||||||
 | 
					                            >
 | 
				
			||||||
 | 
					                        </el-popover>
 | 
				
			||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
                </el-table-column>
 | 
					                </el-table-column>
 | 
				
			||||||
                <el-table-column prop="username" label="用户名" min-width="100"></el-table-column>
 | 
					                <el-table-column prop="username" label="用户名" min-width="100"></el-table-column>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                <el-table-column min-width="115" prop="creator" label="创建账号"></el-table-column>
 | 
					                <el-table-column min-width="115" prop="creator" label="创建账号"></el-table-column>
 | 
				
			||||||
                <el-table-column min-width="160" prop="createTime" label="创建时间">
 | 
					                <el-table-column min-width="160" prop="createTime" label="创建时间" show-overflow-tooltip>
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        {{ $filters.dateFormat(scope.row.createTime) }}
 | 
					                        {{ $filters.dateFormat(scope.row.createTime) }}
 | 
				
			||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
@@ -100,9 +105,17 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                <el-button type="primary" size="small" @click="tableCreateDialog.visible = true">创建表</el-button>
 | 
					                <el-button type="primary" size="small" @click="tableCreateDialog.visible = true">创建表</el-button>
 | 
				
			||||||
            </el-row>
 | 
					            </el-row>
 | 
				
			||||||
            <el-table v-loading="tableInfoDialog.loading" border stripe :data="tableInfoDialog.infos" size="small">
 | 
					            <el-table v-loading="tableInfoDialog.loading" border stripe :data="filterTableInfos" size="small">
 | 
				
			||||||
                <el-table-column property="tableName" label="表名" min-width="150" show-overflow-tooltip></el-table-column>
 | 
					                <el-table-column property="tableName" label="表名" min-width="150" show-overflow-tooltip>
 | 
				
			||||||
                <el-table-column property="tableComment" label="备注" min-width="150" show-overflow-tooltip></el-table-column>
 | 
					                    <template #header>
 | 
				
			||||||
 | 
					                        <el-input v-model="tableInfoDialog.tableNameSearch" size="small" placeholder="表名: 输入可过滤" clearable />
 | 
				
			||||||
 | 
					                    </template>
 | 
				
			||||||
 | 
					                </el-table-column>
 | 
				
			||||||
 | 
					                <el-table-column property="tableComment" label="备注" min-width="150" show-overflow-tooltip>
 | 
				
			||||||
 | 
					                    <template #header>
 | 
				
			||||||
 | 
					                        <el-input v-model="tableInfoDialog.tableCommentSearch" size="small" placeholder="备注: 输入可过滤" clearable />
 | 
				
			||||||
 | 
					                    </template>
 | 
				
			||||||
 | 
					                </el-table-column>
 | 
				
			||||||
                <el-table-column
 | 
					                <el-table-column
 | 
				
			||||||
                    prop="tableRows"
 | 
					                    prop="tableRows"
 | 
				
			||||||
                    label="Rows"
 | 
					                    label="Rows"
 | 
				
			||||||
@@ -153,8 +166,10 @@
 | 
				
			|||||||
            v-model="sqlExecLogDialog.visible"
 | 
					            v-model="sqlExecLogDialog.visible"
 | 
				
			||||||
        >
 | 
					        >
 | 
				
			||||||
            <div class="toolbar">
 | 
					            <div class="toolbar">
 | 
				
			||||||
                <el-input v-model="sqlExecLogDialog.query.db" placeholder="请输入数据库名" clearable style="width: 150px" />
 | 
					                <el-select v-model="sqlExecLogDialog.query.db" placeholder="请选择数据库" filterable clearable>
 | 
				
			||||||
                <el-input v-model="sqlExecLogDialog.query.table" placeholder="请输入表名" clearable class="ml5" style="width: 150px" />
 | 
					                    <el-option v-for="item in sqlExecLogDialog.dbs" :key="item" :label="`${item}`" :value="item"> </el-option>
 | 
				
			||||||
 | 
					                </el-select>
 | 
				
			||||||
 | 
					                <el-input v-model="sqlExecLogDialog.query.table" placeholder="请输入表名" clearable class="ml5" style="width: 180px" />
 | 
				
			||||||
                <el-select v-model="sqlExecLogDialog.query.type" placeholder="请选择操作类型" clearable class="ml5">
 | 
					                <el-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-option v-for="item in enums.DbSqlExecTypeEnum" :key="item.value" :label="item.label" :value="item.value"> </el-option>
 | 
				
			||||||
                </el-select>
 | 
					                </el-select>
 | 
				
			||||||
@@ -244,7 +259,7 @@
 | 
				
			|||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script lang='ts'>
 | 
					<script lang='ts'>
 | 
				
			||||||
import { toRefs, reactive, onMounted, defineComponent } from 'vue';
 | 
					import { toRefs, reactive, computed, onMounted, defineComponent } from 'vue';
 | 
				
			||||||
import { ElMessage, ElMessageBox } from 'element-plus';
 | 
					import { ElMessage, ElMessageBox } from 'element-plus';
 | 
				
			||||||
import { formatByteSize } from '@/common/utils/format';
 | 
					import { formatByteSize } from '@/common/utils/format';
 | 
				
			||||||
import DbEdit from './DbEdit.vue';
 | 
					import DbEdit from './DbEdit.vue';
 | 
				
			||||||
@@ -299,6 +314,7 @@ export default defineComponent({
 | 
				
			|||||||
                visible: false,
 | 
					                visible: false,
 | 
				
			||||||
                data: [],
 | 
					                data: [],
 | 
				
			||||||
                total: 0,
 | 
					                total: 0,
 | 
				
			||||||
 | 
					                dbs: [],
 | 
				
			||||||
                query: {
 | 
					                query: {
 | 
				
			||||||
                    dbId: 0,
 | 
					                    dbId: 0,
 | 
				
			||||||
                    db: '',
 | 
					                    db: '',
 | 
				
			||||||
@@ -317,6 +333,8 @@ export default defineComponent({
 | 
				
			|||||||
                loading: false,
 | 
					                loading: false,
 | 
				
			||||||
                visible: false,
 | 
					                visible: false,
 | 
				
			||||||
                infos: [],
 | 
					                infos: [],
 | 
				
			||||||
 | 
					                tableNameSearch: '',
 | 
				
			||||||
 | 
					                tableCommentSearch: '',
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            columnDialog: {
 | 
					            columnDialog: {
 | 
				
			||||||
                visible: false,
 | 
					                visible: false,
 | 
				
			||||||
@@ -342,7 +360,26 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        onMounted(async () => {
 | 
					        onMounted(async () => {
 | 
				
			||||||
            search();
 | 
					            search();
 | 
				
			||||||
            state.projects = await projectApi.accountProjects.request(null);
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const filterTableInfos = computed(() => {
 | 
				
			||||||
 | 
					            const infos = state.tableInfoDialog.infos;
 | 
				
			||||||
 | 
					            const tableNameSearch = state.tableInfoDialog.tableNameSearch;
 | 
				
			||||||
 | 
					            const tableCommentSearch = state.tableInfoDialog.tableCommentSearch;
 | 
				
			||||||
 | 
					            if (!tableNameSearch && !tableCommentSearch) {
 | 
				
			||||||
 | 
					                return infos;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return infos.filter((data: any) => {
 | 
				
			||||||
 | 
					                let tnMatch = true;
 | 
				
			||||||
 | 
					                let tcMatch = true;
 | 
				
			||||||
 | 
					                if (tableNameSearch) {
 | 
				
			||||||
 | 
					                    tnMatch = data.tableName.toLowerCase().includes(tableNameSearch.toLowerCase());
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                if (tableCommentSearch) {
 | 
				
			||||||
 | 
					                    tcMatch = data.tableComment.includes(tableCommentSearch);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                return tnMatch && tcMatch;
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const choose = (item: any) => {
 | 
					        const choose = (item: any) => {
 | 
				
			||||||
@@ -369,7 +406,12 @@ export default defineComponent({
 | 
				
			|||||||
            search();
 | 
					            search();
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const editDb = (isAdd = false) => {
 | 
					        const getProjects = async () => {
 | 
				
			||||||
 | 
					            state.projects = await projectApi.accountProjects.request(null);
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const editDb = async (isAdd = false) => {
 | 
				
			||||||
 | 
					            await getProjects();
 | 
				
			||||||
            if (isAdd) {
 | 
					            if (isAdd) {
 | 
				
			||||||
                state.dbEditDialog.data = null;
 | 
					                state.dbEditDialog.data = null;
 | 
				
			||||||
                state.dbEditDialog.title = '新增数据库资源';
 | 
					                state.dbEditDialog.title = '新增数据库资源';
 | 
				
			||||||
@@ -404,6 +446,7 @@ export default defineComponent({
 | 
				
			|||||||
        const onShowSqlExec = async (row: any) => {
 | 
					        const onShowSqlExec = async (row: any) => {
 | 
				
			||||||
            state.sqlExecLogDialog.title = `${row.name}[${row.host}:${row.port}]`;
 | 
					            state.sqlExecLogDialog.title = `${row.name}[${row.host}:${row.port}]`;
 | 
				
			||||||
            state.sqlExecLogDialog.query.dbId = row.id;
 | 
					            state.sqlExecLogDialog.query.dbId = row.id;
 | 
				
			||||||
 | 
					            state.sqlExecLogDialog.dbs = row.database.split(' ');
 | 
				
			||||||
            searchSqlExecLog();
 | 
					            searchSqlExecLog();
 | 
				
			||||||
            state.sqlExecLogDialog.visible = true;
 | 
					            state.sqlExecLogDialog.visible = true;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
@@ -411,6 +454,7 @@ export default defineComponent({
 | 
				
			|||||||
        const onBeforeCloseSqlExecDialog = () => {
 | 
					        const onBeforeCloseSqlExecDialog = () => {
 | 
				
			||||||
            state.sqlExecLogDialog.visible = false;
 | 
					            state.sqlExecLogDialog.visible = false;
 | 
				
			||||||
            state.sqlExecLogDialog.data = [];
 | 
					            state.sqlExecLogDialog.data = [];
 | 
				
			||||||
 | 
					            state.sqlExecLogDialog.dbs = [];
 | 
				
			||||||
            state.sqlExecLogDialog.total = 0;
 | 
					            state.sqlExecLogDialog.total = 0;
 | 
				
			||||||
            state.sqlExecLogDialog.query.dbId = 0;
 | 
					            state.sqlExecLogDialog.query.dbId = 0;
 | 
				
			||||||
            state.sqlExecLogDialog.query.pageNum = 1;
 | 
					            state.sqlExecLogDialog.query.pageNum = 1;
 | 
				
			||||||
@@ -502,6 +546,8 @@ export default defineComponent({
 | 
				
			|||||||
                state.tableInfoDialog.infos = await dbApi.tableInfos.request({ id: row.id, db });
 | 
					                state.tableInfoDialog.infos = await dbApi.tableInfos.request({ id: row.id, db });
 | 
				
			||||||
                state.dbId = row.id;
 | 
					                state.dbId = row.id;
 | 
				
			||||||
                state.db = db;
 | 
					                state.db = db;
 | 
				
			||||||
 | 
					            } catch (e) {
 | 
				
			||||||
 | 
					                state.tableInfoDialog.visible = false;
 | 
				
			||||||
            } finally {
 | 
					            } finally {
 | 
				
			||||||
                state.tableInfoDialog.loading = false;
 | 
					                state.tableInfoDialog.loading = false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -570,6 +616,8 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
 | 
					            getProjects,
 | 
				
			||||||
 | 
					            filterTableInfos,
 | 
				
			||||||
            enums,
 | 
					            enums,
 | 
				
			||||||
            search,
 | 
					            search,
 | 
				
			||||||
            choose,
 | 
					            choose,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,5 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
    <div>
 | 
					    <div>
 | 
				
			||||||
        <el-button-group :style="btnStyle">
 | 
					 | 
				
			||||||
            <el-button @click="onRunSql" type="success" icon="video-play" size="small" plain>执行</el-button>
 | 
					 | 
				
			||||||
            <el-button @click="formatSql" type="primary" icon="magic-stick" size="small" plain>格式化</el-button>
 | 
					 | 
				
			||||||
        </el-button-group>
 | 
					 | 
				
			||||||
        <div class="toolbar">
 | 
					        <div class="toolbar">
 | 
				
			||||||
            <el-row type="flex" justify="space-between">
 | 
					            <el-row type="flex" justify="space-between">
 | 
				
			||||||
                <el-col :span="24">
 | 
					                <el-col :span="24">
 | 
				
			||||||
@@ -58,6 +54,19 @@
 | 
				
			|||||||
                        <div>
 | 
					                        <div>
 | 
				
			||||||
                            <div class="toolbar">
 | 
					                            <div class="toolbar">
 | 
				
			||||||
                                <div class="fl">
 | 
					                                <div class="fl">
 | 
				
			||||||
 | 
					                                    <el-link @click="onRunSql" :underline="false" class="ml15" icon="VideoPlay"></el-link>
 | 
				
			||||||
 | 
					                                    <el-divider direction="vertical" border-style="dashed" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                    <el-tooltip class="box-item" effect="dark" content="format sql" placement="top">
 | 
				
			||||||
 | 
					                                        <el-link @click="formatSql" type="primary" :underline="false" icon="MagicStick"></el-link>
 | 
				
			||||||
 | 
					                                    </el-tooltip>
 | 
				
			||||||
 | 
					                                    <el-divider direction="vertical" border-style="dashed" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                    <el-tooltip class="box-item" effect="dark" content="commit" placement="top">
 | 
				
			||||||
 | 
					                                        <el-link @click="onCommit" type="success" :underline="false" icon="CircleCheck"></el-link>
 | 
				
			||||||
 | 
					                                    </el-tooltip>
 | 
				
			||||||
 | 
					                                    <el-divider direction="vertical" border-style="dashed" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                    <el-upload
 | 
					                                    <el-upload
 | 
				
			||||||
                                        style="display: inline-block"
 | 
					                                        style="display: inline-block"
 | 
				
			||||||
                                        :before-upload="beforeUpload"
 | 
					                                        :before-upload="beforeUpload"
 | 
				
			||||||
@@ -72,11 +81,10 @@
 | 
				
			|||||||
                                        multiple
 | 
					                                        multiple
 | 
				
			||||||
                                        :limit="100"
 | 
					                                        :limit="100"
 | 
				
			||||||
                                    >
 | 
					                                    >
 | 
				
			||||||
                                        <el-button type="success" icon="video-play" plain size="small">sql脚本执行</el-button>
 | 
					                                        <el-tooltip class="box-item" effect="dark" content="SQL脚本执行" placement="top">
 | 
				
			||||||
 | 
					                                            <el-link type="success" :underline="false" icon="Document"></el-link>
 | 
				
			||||||
 | 
					                                        </el-tooltip>
 | 
				
			||||||
                                    </el-upload>
 | 
					                                    </el-upload>
 | 
				
			||||||
                                    <el-button @click="onCommit" class="ml5 mb5" type="success" icon="CircleCheck" plain size="small"
 | 
					 | 
				
			||||||
                                        >commit</el-button
 | 
					 | 
				
			||||||
                                    >
 | 
					 | 
				
			||||||
                                </div>
 | 
					                                </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                <div style="float: right" class="fl">
 | 
					                                <div style="float: right" class="fl">
 | 
				
			||||||
@@ -101,7 +109,7 @@
 | 
				
			|||||||
                            </div>
 | 
					                            </div>
 | 
				
			||||||
                        </div>
 | 
					                        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        <div @click="closeExecBtns" class="mt5 sqlEditor" @contextmenu="showExecBtns">
 | 
					                        <div class="mt5 sqlEditor">
 | 
				
			||||||
                            <textarea ref="codeTextarea"></textarea>
 | 
					                            <textarea ref="codeTextarea"></textarea>
 | 
				
			||||||
                        </div>
 | 
					                        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -145,46 +153,64 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                <el-tab-pane closable v-for="dt in dataTabs" :key="dt.name" :label="dt.label" :name="dt.name">
 | 
					                <el-tab-pane closable v-for="dt in dataTabs" :key="dt.name" :label="dt.label" :name="dt.name">
 | 
				
			||||||
                    <el-row v-if="dbId">
 | 
					                    <el-row v-if="dbId">
 | 
				
			||||||
                        <el-link @click="onRefresh(dt.name)" icon="refresh" :underline="false" class="ml5"></el-link>
 | 
					                        <el-col :span="8">
 | 
				
			||||||
                        <el-link @click="addRow" class="ml5" type="primary" icon="plus" :underline="false"></el-link>
 | 
					                            <el-link @click="onRefresh(dt.name)" icon="refresh" :underline="false" class="ml5"></el-link>
 | 
				
			||||||
                        <el-link @click="onDeleteData" class="ml5" type="danger" icon="delete" :underline="false"></el-link>
 | 
					                            <el-divider direction="vertical" border-style="dashed" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        <el-tooltip class="box-item" effect="dark" content="commit" placement="top">
 | 
					                            <el-link @click="addRow" type="primary" icon="plus" :underline="false"></el-link>
 | 
				
			||||||
                            <el-link @click="onCommit" class="ml5" type="success" icon="check" :underline="false"></el-link>
 | 
					                            <el-divider direction="vertical" border-style="dashed" />
 | 
				
			||||||
                        </el-tooltip>
 | 
					 | 
				
			||||||
                    </el-row>
 | 
					 | 
				
			||||||
                    <el-row class="mt5">
 | 
					 | 
				
			||||||
                        <el-input
 | 
					 | 
				
			||||||
                            v-model="dt.condition"
 | 
					 | 
				
			||||||
                            placeholder="若需条件过滤,可选择列并点击对应的字段并输入需要过滤的内容点击查询按钮即可"
 | 
					 | 
				
			||||||
                            clearable
 | 
					 | 
				
			||||||
                            size="small"
 | 
					 | 
				
			||||||
                        >
 | 
					 | 
				
			||||||
                            <template #prepend>
 | 
					 | 
				
			||||||
                                <el-popover trigger="click" :width="270" placement="right">
 | 
					 | 
				
			||||||
                                    <template #reference>
 | 
					 | 
				
			||||||
                                        <el-link type="success" :underline="false">选择列</el-link>
 | 
					 | 
				
			||||||
                                    </template>
 | 
					 | 
				
			||||||
                                    <el-table
 | 
					 | 
				
			||||||
                                        :data="getColumns4Map(dt.name)"
 | 
					 | 
				
			||||||
                                        max-height="500"
 | 
					 | 
				
			||||||
                                        size="small"
 | 
					 | 
				
			||||||
                                        @row-click="
 | 
					 | 
				
			||||||
                                            (...event) => {
 | 
					 | 
				
			||||||
                                                onConditionRowClick(event, dt);
 | 
					 | 
				
			||||||
                                            }
 | 
					 | 
				
			||||||
                                        "
 | 
					 | 
				
			||||||
                                    >
 | 
					 | 
				
			||||||
                                        <el-table-column property="columnName" label="列名" show-overflow-tooltip> </el-table-column>
 | 
					 | 
				
			||||||
                                        <el-table-column property="columnComment" label="备注" show-overflow-tooltip> </el-table-column>
 | 
					 | 
				
			||||||
                                    </el-table>
 | 
					 | 
				
			||||||
                                </el-popover>
 | 
					 | 
				
			||||||
                            </template>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            <template #append>
 | 
					                            <el-link @click="onDeleteData" type="danger" icon="delete" :underline="false"></el-link>
 | 
				
			||||||
                                <el-button @click="selectByCondition(dt.name, dt.condition)" icon="search" size="small"></el-button>
 | 
					                            <el-divider direction="vertical" border-style="dashed" />
 | 
				
			||||||
                            </template>
 | 
					
 | 
				
			||||||
                        </el-input>
 | 
					                            <el-tooltip class="box-item" effect="dark" content="commit" placement="top">
 | 
				
			||||||
 | 
					                                <el-link @click="onCommit" type="success" icon="CircleCheck" :underline="false"></el-link>
 | 
				
			||||||
 | 
					                            </el-tooltip>
 | 
				
			||||||
 | 
					                            <el-divider direction="vertical" border-style="dashed" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            <el-tooltip class="box-item" effect="dark" content="生成insert sql" placement="top">
 | 
				
			||||||
 | 
					                                <el-link @click="onGenerateInsertSql" type="success" :underline="false">gi</el-link>
 | 
				
			||||||
 | 
					                            </el-tooltip>
 | 
				
			||||||
 | 
					                        </el-col>
 | 
				
			||||||
 | 
					                        <el-col :span="16">
 | 
				
			||||||
 | 
					                            <el-input
 | 
				
			||||||
 | 
					                                v-model="dt.condition"
 | 
				
			||||||
 | 
					                                placeholder="若需条件过滤,可选择列并点击对应的字段并输入需要过滤的内容点击查询按钮即可"
 | 
				
			||||||
 | 
					                                clearable
 | 
				
			||||||
 | 
					                                size="small"
 | 
				
			||||||
 | 
					                                style="width: 100%"
 | 
				
			||||||
 | 
					                            >
 | 
				
			||||||
 | 
					                                <template #prepend>
 | 
				
			||||||
 | 
					                                    <el-popover trigger="click" :width="320" placement="right">
 | 
				
			||||||
 | 
					                                        <template #reference>
 | 
				
			||||||
 | 
					                                            <el-link
 | 
				
			||||||
 | 
					                                                type="success"
 | 
				
			||||||
 | 
					                                                :underline="false"
 | 
				
			||||||
 | 
					                                                >选择列</el-link
 | 
				
			||||||
 | 
					                                            >
 | 
				
			||||||
 | 
					                                        </template>
 | 
				
			||||||
 | 
					                                        <el-table
 | 
				
			||||||
 | 
					                                            :data="getColumns4Map(dt.name)"
 | 
				
			||||||
 | 
					                                            max-height="500"
 | 
				
			||||||
 | 
					                                            size="small"
 | 
				
			||||||
 | 
					                                            @row-click="
 | 
				
			||||||
 | 
					                                                (...event) => {
 | 
				
			||||||
 | 
					                                                    onConditionRowClick(event, dt);
 | 
				
			||||||
 | 
					                                                }
 | 
				
			||||||
 | 
					                                            "
 | 
				
			||||||
 | 
					                                            style="cursor: pointer"
 | 
				
			||||||
 | 
					                                        >
 | 
				
			||||||
 | 
					                                            <el-table-column property="columnName" label="列名" show-overflow-tooltip> </el-table-column>
 | 
				
			||||||
 | 
					                                            <el-table-column property="columnComment" label="备注" show-overflow-tooltip> </el-table-column>
 | 
				
			||||||
 | 
					                                        </el-table>
 | 
				
			||||||
 | 
					                                    </el-popover>
 | 
				
			||||||
 | 
					                                </template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                <template #append>
 | 
				
			||||||
 | 
					                                    <el-button @click="selectByCondition(dt.name, dt.condition)" icon="search" size="small"></el-button>
 | 
				
			||||||
 | 
					                                </template>
 | 
				
			||||||
 | 
					                            </el-input>
 | 
				
			||||||
 | 
					                        </el-col>
 | 
				
			||||||
                    </el-row>
 | 
					                    </el-row>
 | 
				
			||||||
                    <el-table
 | 
					                    <el-table
 | 
				
			||||||
                        @cell-dblclick="cellClick"
 | 
					                        @cell-dblclick="cellClick"
 | 
				
			||||||
@@ -233,6 +259,34 @@
 | 
				
			|||||||
                </el-tab-pane>
 | 
					                </el-tab-pane>
 | 
				
			||||||
            </el-tabs>
 | 
					            </el-tabs>
 | 
				
			||||||
        </el-container>
 | 
					        </el-container>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <el-dialog v-model="conditionDialog.visible" :title="conditionDialog.title" width="420px">
 | 
				
			||||||
 | 
					            <el-row>
 | 
				
			||||||
 | 
					                <el-col :span="5">
 | 
				
			||||||
 | 
					                    <el-select v-model="conditionDialog.condition">
 | 
				
			||||||
 | 
					                        <el-option label="=" value="="> </el-option>
 | 
				
			||||||
 | 
					                        <el-option label="LIKE" value="LIKE"> </el-option>
 | 
				
			||||||
 | 
					                        <el-option label=">" value=">"> </el-option>
 | 
				
			||||||
 | 
					                        <el-option label=">=" value=">="> </el-option>
 | 
				
			||||||
 | 
					                        <el-option label="<" value="<"> </el-option>
 | 
				
			||||||
 | 
					                        <el-option label="<=" value="<="> </el-option>
 | 
				
			||||||
 | 
					                    </el-select>
 | 
				
			||||||
 | 
					                </el-col>
 | 
				
			||||||
 | 
					                <el-col :span="19">
 | 
				
			||||||
 | 
					                    <el-input v-model="conditionDialog.value" :placeholder="conditionDialog.placeholder" />
 | 
				
			||||||
 | 
					                </el-col>
 | 
				
			||||||
 | 
					            </el-row>
 | 
				
			||||||
 | 
					            <template #footer>
 | 
				
			||||||
 | 
					                <span class="dialog-footer">
 | 
				
			||||||
 | 
					                    <el-button @click="onCancelCondition">取消</el-button>
 | 
				
			||||||
 | 
					                    <el-button type="primary" @click="onConfirmCondition">确定</el-button>
 | 
				
			||||||
 | 
					                </span>
 | 
				
			||||||
 | 
					            </template>
 | 
				
			||||||
 | 
					        </el-dialog>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <el-dialog @close="genSqlDialog.visible = false" v-model="genSqlDialog.visible" title="SQL" width="1000px">
 | 
				
			||||||
 | 
					            <el-input v-model="genSqlDialog.sql" type="textarea" rows="20" />
 | 
				
			||||||
 | 
					        </el-dialog>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -306,12 +360,18 @@ export default defineComponent({
 | 
				
			|||||||
                pageSize: 10,
 | 
					                pageSize: 10,
 | 
				
			||||||
                envId: null,
 | 
					                envId: null,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            btnStyle: {
 | 
					            conditionDialog: {
 | 
				
			||||||
                position: 'absolute',
 | 
					                title: '',
 | 
				
			||||||
                zIndex: 1000,
 | 
					                placeholder: '',
 | 
				
			||||||
                display: 'none',
 | 
					                columnRow: null,
 | 
				
			||||||
                left: '',
 | 
					                dataTab: null,
 | 
				
			||||||
                top: '',
 | 
					                visible: false,
 | 
				
			||||||
 | 
					                condition: '=',
 | 
				
			||||||
 | 
					                value: null,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            genSqlDialog: {
 | 
				
			||||||
 | 
					                visible: false,
 | 
				
			||||||
 | 
					                sql: '',
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            cmOptions: {
 | 
					            cmOptions: {
 | 
				
			||||||
                tabSize: 4,
 | 
					                tabSize: 4,
 | 
				
			||||||
@@ -365,7 +425,7 @@ export default defineComponent({
 | 
				
			|||||||
        const setHeight = () => {
 | 
					        const setHeight = () => {
 | 
				
			||||||
            // 默认300px
 | 
					            // 默认300px
 | 
				
			||||||
            codemirror.setSize('auto', `${window.innerHeight - 538}px`);
 | 
					            codemirror.setSize('auto', `${window.innerHeight - 538}px`);
 | 
				
			||||||
            state.dataTabsTableHeight = window.innerHeight - 258 - 33;
 | 
					            state.dataTabsTableHeight = window.innerHeight - 274;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /**
 | 
					        /**
 | 
				
			||||||
@@ -434,7 +494,6 @@ export default defineComponent({
 | 
				
			|||||||
            } catch (e: any) {
 | 
					            } catch (e: any) {
 | 
				
			||||||
                state.queryTab.loading = false;
 | 
					                state.queryTab.loading = false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            closeExecBtns();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // 即只有以该字符串开头的sql才可修改表数据内容
 | 
					            // 即只有以该字符串开头的sql才可修改表数据内容
 | 
				
			||||||
            if (sql.startsWith('SELECT *') || sql.startsWith('select *') || sql.startsWith('SELECT\n  *')) {
 | 
					            if (sql.startsWith('SELECT *') || sql.startsWith('select *') || sql.startsWith('SELECT\n  *')) {
 | 
				
			||||||
@@ -717,23 +776,34 @@ export default defineComponent({
 | 
				
			|||||||
         */
 | 
					         */
 | 
				
			||||||
        const onConditionRowClick = (event: any, dataTab: any) => {
 | 
					        const onConditionRowClick = (event: any, dataTab: any) => {
 | 
				
			||||||
            const row = event[0];
 | 
					            const row = event[0];
 | 
				
			||||||
            ElMessageBox.prompt(`请输入 [${row.columnName}] 的值`, '查询条件', {
 | 
					            state.conditionDialog.title = `请输入 [${row.columnName}] 的值`;
 | 
				
			||||||
                confirmButtonText: '确定',
 | 
					            state.conditionDialog.placeholder = `${row.columnType}  ${row.columnComment}`;
 | 
				
			||||||
                cancelButtonText: '取消',
 | 
					            state.conditionDialog.columnRow = row;
 | 
				
			||||||
                inputPlaceholder: `${row.columnType}  ${row.columnComment}`,
 | 
					            state.conditionDialog.dataTab = dataTab;
 | 
				
			||||||
            })
 | 
					            state.conditionDialog.visible = true;
 | 
				
			||||||
                .then(({ value }) => {
 | 
					        };
 | 
				
			||||||
                    if (!value) {
 | 
					
 | 
				
			||||||
                        value = '';
 | 
					        // 确认条件
 | 
				
			||||||
                    }
 | 
					        const onConfirmCondition = () => {
 | 
				
			||||||
                    let condition = dataTab.condition;
 | 
					            const conditionDialog = state.conditionDialog;
 | 
				
			||||||
                    if (condition) {
 | 
					            const dataTab = state.conditionDialog.dataTab as any;
 | 
				
			||||||
                        condition += ` AND `;
 | 
					            let condition = dataTab.condition;
 | 
				
			||||||
                    }
 | 
					            if (condition) {
 | 
				
			||||||
                    condition += `${row.columnName} = `;
 | 
					                condition += ` AND `;
 | 
				
			||||||
                    dataTab.condition = condition + wrapColumnValue(row, value);
 | 
					            }
 | 
				
			||||||
                })
 | 
					            const row = conditionDialog.columnRow as any;
 | 
				
			||||||
                .catch(() => {});
 | 
					            condition += `${row.columnName} ${conditionDialog.condition} `;
 | 
				
			||||||
 | 
					            dataTab.condition = condition + wrapColumnValue(row, conditionDialog.value);
 | 
				
			||||||
 | 
					            onCancelCondition();
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const onCancelCondition = () => {
 | 
				
			||||||
 | 
					            state.conditionDialog.visible = false;
 | 
				
			||||||
 | 
					            state.conditionDialog.title = ``;
 | 
				
			||||||
 | 
					            state.conditionDialog.placeholder = ``;
 | 
				
			||||||
 | 
					            state.conditionDialog.value = null;
 | 
				
			||||||
 | 
					            state.conditionDialog.columnRow = null;
 | 
				
			||||||
 | 
					            state.conditionDialog.dataTab = null;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const onRefresh = async (tableName: string) => {
 | 
					        const onRefresh = async (tableName: string) => {
 | 
				
			||||||
@@ -793,10 +863,10 @@ export default defineComponent({
 | 
				
			|||||||
        const getDefaultSelectSql = (tableName: string, where: string = '', orderBy: string = '', pageNum: number = 1) => {
 | 
					        const getDefaultSelectSql = (tableName: string, where: string = '', orderBy: string = '', pageNum: number = 1) => {
 | 
				
			||||||
            const baseSql = `SELECT * FROM ${tableName} ${where ? 'WHERE ' + where : ''} ${orderBy ? orderBy : ''}`;
 | 
					            const baseSql = `SELECT * FROM ${tableName} ${where ? 'WHERE ' + where : ''} ${orderBy ? orderBy : ''}`;
 | 
				
			||||||
            if (state.dbType == 'mysql') {
 | 
					            if (state.dbType == 'mysql') {
 | 
				
			||||||
                 return `${baseSql} LIMIT ${(pageNum - 1) * state.defalutLimit}, ${state.defalutLimit};`
 | 
					                return `${baseSql} LIMIT ${(pageNum - 1) * state.defalutLimit}, ${state.defalutLimit};`;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (state.dbType == 'postgres') {
 | 
					            if (state.dbType == 'postgres') {
 | 
				
			||||||
                return `${baseSql} OFFSET ${(pageNum - 1) * state.defalutLimit} LIMIT ${state.defalutLimit};`
 | 
					                return `${baseSql} OFFSET ${(pageNum - 1) * state.defalutLimit} LIMIT ${state.defalutLimit};`;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            return baseSql;
 | 
					            return baseSql;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
@@ -928,7 +998,6 @@ export default defineComponent({
 | 
				
			|||||||
            state.queryTab.execRes.tableColumn = [];
 | 
					            state.queryTab.execRes.tableColumn = [];
 | 
				
			||||||
            state.cmOptions.hintOptions.tables = [];
 | 
					            state.cmOptions.hintOptions.tables = [];
 | 
				
			||||||
            tableMap.clear();
 | 
					            tableMap.clear();
 | 
				
			||||||
            closeExecBtns();
 | 
					 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const onDataSelectionChange = (datas: []) => {
 | 
					        const onDataSelectionChange = (datas: []) => {
 | 
				
			||||||
@@ -963,6 +1032,38 @@ export default defineComponent({
 | 
				
			|||||||
            });
 | 
					            });
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const onGenerateInsertSql = async () => {
 | 
				
			||||||
 | 
					            const queryTab = isQueryTab();
 | 
				
			||||||
 | 
					            const datas = queryTab ? state.queryTab.selectionDatas : state.dataTabs[state.activeName].selectionDatas;
 | 
				
			||||||
 | 
					            isTrue(datas && datas.length > 0, '请先选择要生成insert语句的数据');
 | 
				
			||||||
 | 
					            const tableName = state.nowTableName;
 | 
				
			||||||
 | 
					            const columns: any = await getColumns(tableName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            const sqls = [];
 | 
				
			||||||
 | 
					            for (let data of datas) {
 | 
				
			||||||
 | 
					                let colNames = [];
 | 
				
			||||||
 | 
					                let values = [];
 | 
				
			||||||
 | 
					                for (let column of columns) {
 | 
				
			||||||
 | 
					                    const colName = column.columnName;
 | 
				
			||||||
 | 
					                    colNames.push(colName);
 | 
				
			||||||
 | 
					                    values.push(wrapValueByType(data[colName]));
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                sqls.push(`INSERT INTO ${tableName} (${colNames.join(', ')}) VALUES(${values.join(', ')})`);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            state.genSqlDialog.sql = sqls.join(';\n') + ';';
 | 
				
			||||||
 | 
					            state.genSqlDialog.visible = true;
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const wrapValueByType = (val: any) => {
 | 
				
			||||||
 | 
					            if (val == null) {
 | 
				
			||||||
 | 
					                return 'NULL';
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (typeof val == 'number') {
 | 
				
			||||||
 | 
					                return val;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return `'${val}'`;
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /**
 | 
					        /**
 | 
				
			||||||
         * 是否为查询tab
 | 
					         * 是否为查询tab
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
@@ -1072,7 +1173,6 @@ export default defineComponent({
 | 
				
			|||||||
            let selectSql = codemirror.getSelection();
 | 
					            let selectSql = codemirror.getSelection();
 | 
				
			||||||
            isTrue(selectSql, '请选中需要格式化的sql');
 | 
					            isTrue(selectSql, '请选中需要格式化的sql');
 | 
				
			||||||
            codemirror.replaceSelection(sqlFormatter(selectSql));
 | 
					            codemirror.replaceSelection(sqlFormatter(selectSql));
 | 
				
			||||||
            closeExecBtns();
 | 
					 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const search = async () => {
 | 
					        const search = async () => {
 | 
				
			||||||
@@ -1080,31 +1180,6 @@ export default defineComponent({
 | 
				
			|||||||
            state.dbs = res.list;
 | 
					            state.dbs = res.list;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /**
 | 
					 | 
				
			||||||
         * 显示执行sql和格式化按钮
 | 
					 | 
				
			||||||
         */
 | 
					 | 
				
			||||||
        const showExecBtns = (event: any) => {
 | 
					 | 
				
			||||||
            if (event.preventDefault) {
 | 
					 | 
				
			||||||
                event.preventDefault();
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                event.returnValue = false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            state.btnStyle.display = 'inline';
 | 
					 | 
				
			||||||
            state.btnStyle.left = event.offsetX + 15 + 'px';
 | 
					 | 
				
			||||||
            state.btnStyle.top = event.clientY - 80 + 'px';
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        /**
 | 
					 | 
				
			||||||
         * 关闭执行sql和格式化按钮
 | 
					 | 
				
			||||||
         */
 | 
					 | 
				
			||||||
        const closeExecBtns = () => {
 | 
					 | 
				
			||||||
            if (state.btnStyle.left) {
 | 
					 | 
				
			||||||
                state.btnStyle.display = 'none';
 | 
					 | 
				
			||||||
                state.btnStyle.left = '';
 | 
					 | 
				
			||||||
                state.btnStyle.top = '';
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
            codeTextarea,
 | 
					            codeTextarea,
 | 
				
			||||||
@@ -1121,6 +1196,8 @@ export default defineComponent({
 | 
				
			|||||||
            getColumnTip,
 | 
					            getColumnTip,
 | 
				
			||||||
            getColumns4Map,
 | 
					            getColumns4Map,
 | 
				
			||||||
            onConditionRowClick,
 | 
					            onConditionRowClick,
 | 
				
			||||||
 | 
					            onConfirmCondition,
 | 
				
			||||||
 | 
					            onCancelCondition,
 | 
				
			||||||
            changeSqlTemplate,
 | 
					            changeSqlTemplate,
 | 
				
			||||||
            deleteSql,
 | 
					            deleteSql,
 | 
				
			||||||
            saveSql,
 | 
					            saveSql,
 | 
				
			||||||
@@ -1137,8 +1214,7 @@ export default defineComponent({
 | 
				
			|||||||
            onDataSelectionChange,
 | 
					            onDataSelectionChange,
 | 
				
			||||||
            onDeleteData,
 | 
					            onDeleteData,
 | 
				
			||||||
            onTableSortChange,
 | 
					            onTableSortChange,
 | 
				
			||||||
            showExecBtns,
 | 
					            onGenerateInsertSql,
 | 
				
			||||||
            closeExecBtns,
 | 
					 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,8 @@ export const dbApi = {
 | 
				
			|||||||
    // 获取权限列表
 | 
					    // 获取权限列表
 | 
				
			||||||
    dbs: Api.create("/dbs", 'get'),
 | 
					    dbs: Api.create("/dbs", 'get'),
 | 
				
			||||||
    saveDb: Api.create("/dbs", 'post'),
 | 
					    saveDb: Api.create("/dbs", 'post'),
 | 
				
			||||||
 | 
					    getAllDatabase: Api.create("/dbs/databases", 'post'),
 | 
				
			||||||
 | 
					    getDbPwd: Api.create("/dbs/{id}/pwd", 'get'),
 | 
				
			||||||
    deleteDb: Api.create("/dbs/{id}", 'delete'),
 | 
					    deleteDb: Api.create("/dbs/{id}", 'delete'),
 | 
				
			||||||
    dumpDb: Api.create("/dbs/{id}/dump", 'post'),
 | 
					    dumpDb: Api.create("/dbs/{id}/dump", 'post'),
 | 
				
			||||||
    tableInfos: Api.create("/dbs/{id}/t-infos", 'get'),
 | 
					    tableInfos: Api.create("/dbs/{id}/t-infos", 'get'),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -57,7 +57,7 @@
 | 
				
			|||||||
            </el-row>
 | 
					            </el-row>
 | 
				
			||||||
        </el-dialog>
 | 
					        </el-dialog>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <el-dialog :title="tree.title" v-model="tree.visible" :close-on-click-modal="false" width="680px">
 | 
					        <el-dialog :title="tree.title" v-model="tree.visible" :close-on-click-modal="false" width="70%">
 | 
				
			||||||
            <el-progress
 | 
					            <el-progress
 | 
				
			||||||
                v-if="uploadProgressShow"
 | 
					                v-if="uploadProgressShow"
 | 
				
			||||||
                style="width: 90%; margin-left: 20px"
 | 
					                style="width: 90%; margin-left: 20px"
 | 
				
			||||||
@@ -66,7 +66,7 @@
 | 
				
			|||||||
                :percentage="progressNum"
 | 
					                :percentage="progressNum"
 | 
				
			||||||
            />
 | 
					            />
 | 
				
			||||||
            <div style="height: 45vh; overflow: auto">
 | 
					            <div style="height: 45vh; overflow: auto">
 | 
				
			||||||
                <el-tree v-if="tree.visible" ref="fileTree" :load="loadNode" :props="props" lazy node-key="id" :expand-on-click-node="true">
 | 
					                <el-tree v-if="tree.visible" ref="fileTree" :highlight-current="true" :load="loadNode" :props="props" lazy node-key="id" :expand-on-click-node="true">
 | 
				
			||||||
                    <template #default="{ node, data }">
 | 
					                    <template #default="{ node, data }">
 | 
				
			||||||
                        <span class="custom-tree-node">
 | 
					                        <span class="custom-tree-node">
 | 
				
			||||||
                            <el-dropdown size="small" @visible-change="getFilePath(data, $event)" trigger="contextmenu">
 | 
					                            <el-dropdown size="small" @visible-change="getFilePath(data, $event)" trigger="contextmenu">
 | 
				
			||||||
@@ -85,6 +85,10 @@
 | 
				
			|||||||
                                        {{ node.label }}
 | 
					                                        {{ node.label }}
 | 
				
			||||||
                                        <span style="color: #67c23a" v-if="data.type == '-'">  [{{ formatFileSize(data.size) }}]</span>
 | 
					                                        <span style="color: #67c23a" v-if="data.type == '-'">  [{{ formatFileSize(data.size) }}]</span>
 | 
				
			||||||
                                    </span>
 | 
					                                    </span>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                     <span style="display: inline-block">
 | 
				
			||||||
 | 
					                                        <span v-if="data.mode" style="color: #67c23a">  [{{ data.mode }} {{ data.modTime }}]</span>
 | 
				
			||||||
 | 
					                                    </span>
 | 
				
			||||||
                                </span>
 | 
					                                </span>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                <template #dropdown>
 | 
					                                <template #dropdown>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
    <div>
 | 
					    <div>
 | 
				
			||||||
        <el-dialog :title="title" v-model="dialogVisible" :close-on-click-modal="false" :destroy-on-close="true" :before-close="cancel" width="35%">
 | 
					        <el-dialog :title="title" v-model="dialogVisible" :close-on-click-modal="false" :destroy-on-close="true" :before-close="cancel" width="38%">
 | 
				
			||||||
            <el-form :model="form" ref="machineForm" :rules="rules" label-width="85px">
 | 
					            <el-form :model="form" ref="machineForm" :rules="rules" label-width="85px">
 | 
				
			||||||
                <el-form-item prop="projectId" label="项目:" required>
 | 
					                <el-form-item prop="projectId" label="项目:" required>
 | 
				
			||||||
                    <el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
 | 
					                    <el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
 | 
				
			||||||
@@ -11,26 +11,68 @@
 | 
				
			|||||||
                    <el-input v-model.trim="form.name" placeholder="请输入机器别名" auto-complete="off"></el-input>
 | 
					                    <el-input v-model.trim="form.name" placeholder="请输入机器别名" auto-complete="off"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="ip" label="ip:" required>
 | 
					                <el-form-item prop="ip" label="ip:" required>
 | 
				
			||||||
                    <el-input v-model.trim="form.ip" placeholder="请输入主机ip" auto-complete="off"></el-input>
 | 
					                    <el-col :span="18">
 | 
				
			||||||
                </el-form-item>
 | 
					                        <el-input :disabled="form.id" v-model.trim="form.ip" placeholder="主机ip" auto-complete="off"></el-input>
 | 
				
			||||||
                <el-form-item prop="port" label="port:" required>
 | 
					                    </el-col>
 | 
				
			||||||
                    <el-input type="number" v-model.number="form.port" placeholder="请输入端口"></el-input>
 | 
					                    <el-col style="text-align: center" :span="1">:</el-col>
 | 
				
			||||||
 | 
					                    <el-col :span="5">
 | 
				
			||||||
 | 
					                        <el-input type="number" v-model.number="form.port" placeholder="端口"></el-input>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="username" label="用户名:" required>
 | 
					                <el-form-item prop="username" label="用户名:" required>
 | 
				
			||||||
                    <el-input v-model.trim="form.username" placeholder="请输入用户名"></el-input>
 | 
					                    <el-input v-model.trim="form.username" placeholder="请输入用户名"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="password" label="密码:">
 | 
					                <el-form-item prop="authMethod" label="认证方式:" required>
 | 
				
			||||||
 | 
					                    <el-select style="width: 100%" v-model="form.authMethod" placeholder="请选择认证方式">
 | 
				
			||||||
 | 
					                        <el-option key="1" label="Password" :value="1"> </el-option>
 | 
				
			||||||
 | 
					                        <el-option key="2" label="PublicKey" :value="2"> </el-option>
 | 
				
			||||||
 | 
					                    </el-select>
 | 
				
			||||||
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					                <el-form-item v-if="form.authMethod == 1" prop="password" label="密码:">
 | 
				
			||||||
                    <el-input
 | 
					                    <el-input
 | 
				
			||||||
                        type="password"
 | 
					                        type="password"
 | 
				
			||||||
                        show-password
 | 
					                        show-password
 | 
				
			||||||
                        v-model.trim="form.password"
 | 
					                        v-model.trim="form.password"
 | 
				
			||||||
                        placeholder="请输入密码,修改操作可不填"
 | 
					                        placeholder="请输入密码,修改操作可不填"
 | 
				
			||||||
                        autocomplete="new-password"
 | 
					                        autocomplete="new-password"
 | 
				
			||||||
                    ></el-input>
 | 
					                    >
 | 
				
			||||||
 | 
					                        <template v-if="form.id && form.id != 0" #suffix>
 | 
				
			||||||
 | 
					                            <el-popover @hide="pwd = ''" placement="right" title="原密码" :width="200" trigger="click" :content="pwd">
 | 
				
			||||||
 | 
					                                <template #reference>
 | 
				
			||||||
 | 
					                                    <el-link @click="getPwd" :underline="false" type="primary" class="mr5">原密码</el-link>
 | 
				
			||||||
 | 
					                                </template>
 | 
				
			||||||
 | 
					                            </el-popover>
 | 
				
			||||||
 | 
					                        </template>
 | 
				
			||||||
 | 
					                    </el-input>
 | 
				
			||||||
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					                <el-form-item v-if="form.authMethod == 2" prop="password" label="秘钥:">
 | 
				
			||||||
 | 
					                    <el-input type="textarea" :rows="3" v-model="form.password" placeholder="请将私钥文件内容拷贝至此,修改操作可不填"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="remark" label="备注:">
 | 
					                <el-form-item prop="remark" label="备注:">
 | 
				
			||||||
                    <el-input type="textarea" v-model="form.remark"></el-input>
 | 
					                    <el-input type="textarea" v-model="form.remark"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                <el-form-item prop="enableRecorder" label="终端回放:">
 | 
				
			||||||
 | 
					                    <el-checkbox v-model="form.enableRecorder" :true-label="1" :false-label="-1"></el-checkbox>
 | 
				
			||||||
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                <el-form-item prop="enableSshTunnel" label="SSH隧道:">
 | 
				
			||||||
 | 
					                    <el-col :span="3">
 | 
				
			||||||
 | 
					                        <el-checkbox @change="getSshTunnelMachines" v-model="form.enableSshTunnel" :true-label="1" :false-label="-1"></el-checkbox>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
 | 
					                    <el-col :span="2" v-if="form.enableSshTunnel == 1"> 机器: </el-col>
 | 
				
			||||||
 | 
					                    <el-col :span="19" v-if="form.enableSshTunnel == 1">
 | 
				
			||||||
 | 
					                        <el-select style="width: 100%" v-model="form.sshTunnelMachineId" placeholder="请选择SSH隧道机器">
 | 
				
			||||||
 | 
					                            <el-option
 | 
				
			||||||
 | 
					                                v-for="item in sshTunnelMachineList"
 | 
				
			||||||
 | 
					                                :key="item.id"
 | 
				
			||||||
 | 
					                                :label="`${item.ip}:${item.port} [${item.name}]`"
 | 
				
			||||||
 | 
					                                :value="item.id"
 | 
				
			||||||
 | 
					                            >
 | 
				
			||||||
 | 
					                            </el-option>
 | 
				
			||||||
 | 
					                        </el-select>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
 | 
					                </el-form-item>
 | 
				
			||||||
            </el-form>
 | 
					            </el-form>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            <template #footer>
 | 
					            <template #footer>
 | 
				
			||||||
@@ -48,6 +90,7 @@ import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
 | 
				
			|||||||
import { machineApi } from './api';
 | 
					import { machineApi } from './api';
 | 
				
			||||||
import { ElMessage } from 'element-plus';
 | 
					import { ElMessage } from 'element-plus';
 | 
				
			||||||
import { notBlank } from '@/common/assert';
 | 
					import { notBlank } from '@/common/assert';
 | 
				
			||||||
 | 
					import { RsaEncrypt } from '@/common/rsa';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'MachineEdit',
 | 
					    name: 'MachineEdit',
 | 
				
			||||||
@@ -70,16 +113,22 @@ export default defineComponent({
 | 
				
			|||||||
        const state = reactive({
 | 
					        const state = reactive({
 | 
				
			||||||
            dialogVisible: false,
 | 
					            dialogVisible: false,
 | 
				
			||||||
            projects: [],
 | 
					            projects: [],
 | 
				
			||||||
 | 
					            sshTunnelMachineList: [],
 | 
				
			||||||
            form: {
 | 
					            form: {
 | 
				
			||||||
                id: null,
 | 
					                id: null,
 | 
				
			||||||
                projectId: null,
 | 
					                projectId: null,
 | 
				
			||||||
                projectName: null,
 | 
					                projectName: null,
 | 
				
			||||||
                name: null,
 | 
					                name: null,
 | 
				
			||||||
 | 
					                authMethod: 1,
 | 
				
			||||||
                port: 22,
 | 
					                port: 22,
 | 
				
			||||||
                username: null,
 | 
					                username: '',
 | 
				
			||||||
                password: null,
 | 
					                password: '',
 | 
				
			||||||
                remark: '',
 | 
					                remark: '',
 | 
				
			||||||
 | 
					                enableSshTunnel: null,
 | 
				
			||||||
 | 
					                sshTunnelMachineId: null,
 | 
				
			||||||
 | 
					                enableRecorder: -1,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
 | 
					            pwd: '',
 | 
				
			||||||
            btnLoading: false,
 | 
					            btnLoading: false,
 | 
				
			||||||
            rules: {
 | 
					            rules: {
 | 
				
			||||||
                projectId: [
 | 
					                projectId: [
 | 
				
			||||||
@@ -106,14 +155,7 @@ export default defineComponent({
 | 
				
			|||||||
                ip: [
 | 
					                ip: [
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        required: true,
 | 
					                        required: true,
 | 
				
			||||||
                        message: '请输入主机ip',
 | 
					                        message: '请输入主机ip和端口',
 | 
				
			||||||
                        trigger: ['change', 'blur'],
 | 
					 | 
				
			||||||
                    },
 | 
					 | 
				
			||||||
                ],
 | 
					 | 
				
			||||||
                port: [
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        required: true,
 | 
					 | 
				
			||||||
                        message: '请输入端口',
 | 
					 | 
				
			||||||
                        trigger: ['change', 'blur'],
 | 
					                        trigger: ['change', 'blur'],
 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
                ],
 | 
					                ],
 | 
				
			||||||
@@ -124,19 +166,45 @@ export default defineComponent({
 | 
				
			|||||||
                        trigger: ['change', 'blur'],
 | 
					                        trigger: ['change', 'blur'],
 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
                ],
 | 
					                ],
 | 
				
			||||||
 | 
					                authMethod: [
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        required: true,
 | 
				
			||||||
 | 
					                        message: '请选择认证方式',
 | 
				
			||||||
 | 
					                        trigger: ['change', 'blur'],
 | 
				
			||||||
 | 
					                    },
 | 
				
			||||||
 | 
					                ],
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        watch(props, async (newValue) => {
 | 
					        watch(props, async (newValue) => {
 | 
				
			||||||
            state.dialogVisible = newValue.visible;
 | 
					            state.dialogVisible = newValue.visible;
 | 
				
			||||||
 | 
					            if (!state.dialogVisible) {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            state.projects = newValue.projects;
 | 
					            state.projects = newValue.projects;
 | 
				
			||||||
            if (newValue.machine) {
 | 
					            if (newValue.machine) {
 | 
				
			||||||
                state.form = { ...newValue.machine };
 | 
					                state.form = { ...newValue.machine };
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                state.form = { port: 22 } as any;
 | 
					                state.form = { port: 22, authMethod: 1 } as any;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            getSshTunnelMachines();
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getSshTunnelMachines = async () => {
 | 
				
			||||||
 | 
					            if (state.form.enableSshTunnel == 1 && state.sshTunnelMachineList.length == 0) {
 | 
				
			||||||
 | 
					                const res = await machineApi.list.request({ pageNum: 1, pageSize: 100 });
 | 
				
			||||||
 | 
					                state.sshTunnelMachineList = res.list;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getSshTunnelMachine = (machineId: any) => {
 | 
				
			||||||
 | 
					            return state.sshTunnelMachineList.find((x: any) => x.id == machineId);
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getPwd = async () => {
 | 
				
			||||||
 | 
					            state.pwd = await machineApi.getMachinePwd.request({ id: state.form.id });
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const changeProject = (projectId: number) => {
 | 
					        const changeProject = (projectId: number) => {
 | 
				
			||||||
            for (let p of state.projects as any) {
 | 
					            for (let p of state.projects as any) {
 | 
				
			||||||
                if (p.id == projectId) {
 | 
					                if (p.id == projectId) {
 | 
				
			||||||
@@ -149,18 +217,29 @@ export default defineComponent({
 | 
				
			|||||||
            if (!state.form.id) {
 | 
					            if (!state.form.id) {
 | 
				
			||||||
                notBlank(state.form.password, '新增操作,密码不可为空');
 | 
					                notBlank(state.form.password, '新增操作,密码不可为空');
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            machineForm.value.validate((valid: boolean) => {
 | 
					            machineForm.value.validate(async (valid: boolean) => {
 | 
				
			||||||
                if (valid) {
 | 
					                if (valid) {
 | 
				
			||||||
                    machineApi.saveMachine.request(state.form).then(() => {
 | 
					                    const form: any = state.form;
 | 
				
			||||||
 | 
					                    if (form.enableSshTunnel == 1) {
 | 
				
			||||||
 | 
					                        const tunnelMachine: any = getSshTunnelMachine(form.sshTunnelMachineId);
 | 
				
			||||||
 | 
					                        if (tunnelMachine.ip == form.ip && tunnelMachine.port == form.port) {
 | 
				
			||||||
 | 
					                            ElMessage.error('隧道机器不能与本机器一致');
 | 
				
			||||||
 | 
					                            return;
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    const reqForm: any = { ...form };
 | 
				
			||||||
 | 
					                    if (reqForm.authMethod == 1) {
 | 
				
			||||||
 | 
					                        reqForm.password = await RsaEncrypt(state.form.password);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    state.btnLoading = true;
 | 
				
			||||||
 | 
					                    try {
 | 
				
			||||||
 | 
					                        await machineApi.saveMachine.request(reqForm);
 | 
				
			||||||
                        ElMessage.success('保存成功');
 | 
					                        ElMessage.success('保存成功');
 | 
				
			||||||
                        emit('val-change', state.form);
 | 
					                        emit('val-change', state.form);
 | 
				
			||||||
                        state.btnLoading = true;
 | 
					 | 
				
			||||||
                        setTimeout(() => {
 | 
					 | 
				
			||||||
                            state.btnLoading = false;
 | 
					 | 
				
			||||||
                        }, 1000);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                        cancel();
 | 
					                        cancel();
 | 
				
			||||||
                    });
 | 
					                    } finally {
 | 
				
			||||||
 | 
					                        state.btnLoading = false;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    ElMessage.error('请正确填写信息');
 | 
					                    ElMessage.error('请正确填写信息');
 | 
				
			||||||
                    return false;
 | 
					                    return false;
 | 
				
			||||||
@@ -176,6 +255,8 @@ export default defineComponent({
 | 
				
			|||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
            machineForm,
 | 
					            machineForm,
 | 
				
			||||||
 | 
					            getSshTunnelMachines,
 | 
				
			||||||
 | 
					            getPwd,
 | 
				
			||||||
            changeProject,
 | 
					            changeProject,
 | 
				
			||||||
            btnOk,
 | 
					            btnOk,
 | 
				
			||||||
            cancel,
 | 
					            cancel,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,7 +16,7 @@
 | 
				
			|||||||
                    >删除</el-button
 | 
					                    >删除</el-button
 | 
				
			||||||
                >
 | 
					                >
 | 
				
			||||||
                <div style="float: right">
 | 
					                <div style="float: right">
 | 
				
			||||||
                    <el-select v-model="params.projectId" placeholder="请选择项目" @clear="search" filterable clearable>
 | 
					                    <el-select @focus="getProjects" v-model="params.projectId" placeholder="请选择项目" @clear="search" filterable clearable>
 | 
				
			||||||
                        <el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
 | 
					                        <el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
 | 
				
			||||||
                    </el-select>
 | 
					                    </el-select>
 | 
				
			||||||
                    <el-input
 | 
					                    <el-input
 | 
				
			||||||
@@ -42,7 +42,7 @@
 | 
				
			|||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
                </el-table-column>
 | 
					                </el-table-column>
 | 
				
			||||||
                <el-table-column prop="name" label="名称" min-width="140" show-overflow-tooltip></el-table-column>
 | 
					                <el-table-column prop="name" label="名称" min-width="140" show-overflow-tooltip></el-table-column>
 | 
				
			||||||
                <el-table-column prop="ip" label="ip:port" min-width="140">
 | 
					                <el-table-column prop="ip" label="ip:port" min-width="150">
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        <el-link :disabled="scope.row.status == -1" @click="showMachineStats(scope.row)" type="primary" :underline="false">{{
 | 
					                        <el-link :disabled="scope.row.status == -1" @click="showMachineStats(scope.row)" type="primary" :underline="false">{{
 | 
				
			||||||
                            `${scope.row.ip}:${scope.row.port}`
 | 
					                            `${scope.row.ip}:${scope.row.port}`
 | 
				
			||||||
@@ -68,41 +68,45 @@
 | 
				
			|||||||
                <el-table-column prop="username" label="用户名" min-width="90"></el-table-column>
 | 
					                <el-table-column prop="username" label="用户名" min-width="90"></el-table-column>
 | 
				
			||||||
                <el-table-column prop="projectName" label="项目" min-width="120"></el-table-column>
 | 
					                <el-table-column prop="projectName" label="项目" min-width="120"></el-table-column>
 | 
				
			||||||
                <el-table-column prop="remark" label="备注" min-width="250" show-overflow-tooltip></el-table-column>
 | 
					                <el-table-column prop="remark" label="备注" min-width="250" show-overflow-tooltip></el-table-column>
 | 
				
			||||||
                <el-table-column prop="ip" label="hasCli" width="70">
 | 
					 | 
				
			||||||
                    <template #default="scope">
 | 
					 | 
				
			||||||
                        {{ `${scope.row.hasCli ? '是' : '否'}` }}
 | 
					 | 
				
			||||||
                    </template>
 | 
					 | 
				
			||||||
                </el-table-column>
 | 
					 | 
				
			||||||
                <el-table-column prop="createTime" label="创建时间" min-width="165">
 | 
					                <el-table-column prop="createTime" label="创建时间" min-width="165">
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        {{ $filters.dateFormat(scope.row.createTime) }}
 | 
					                        {{ $filters.dateFormat(scope.row.createTime) }}
 | 
				
			||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
                </el-table-column>
 | 
					                </el-table-column>
 | 
				
			||||||
                <el-table-column prop="creator" label="创建者" min-width="80"></el-table-column>
 | 
					                <el-table-column prop="creator" label="创建者" min-width="80"></el-table-column>
 | 
				
			||||||
                <el-table-column label="操作" min-width="280" fixed="right">
 | 
					                <el-table-column label="操作" min-width="335" fixed="right">
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        <el-link
 | 
					                        <span v-auth="'machine:terminal'">
 | 
				
			||||||
                            v-auth="'machine:terminal'"
 | 
					                            <el-link
 | 
				
			||||||
                            :disabled="scope.row.status == -1"
 | 
					                                :disabled="scope.row.status == -1"
 | 
				
			||||||
                            type="primary"
 | 
					                                type="primary"
 | 
				
			||||||
                            @click="showTerminal(scope.row)"
 | 
					                                @click="showTerminal(scope.row)"
 | 
				
			||||||
                            plain
 | 
					                                plain
 | 
				
			||||||
                            size="small"
 | 
					                                size="small"
 | 
				
			||||||
                            :underline="false"
 | 
					                                :underline="false"
 | 
				
			||||||
                            >终端</el-link
 | 
					                                >终端</el-link
 | 
				
			||||||
                        >
 | 
					                            >
 | 
				
			||||||
                        <el-divider v-auth="'machine:terminal'" direction="vertical" border-style="dashed" />
 | 
					                            <el-divider direction="vertical" border-style="dashed" />
 | 
				
			||||||
                        <el-link
 | 
					                        </span>
 | 
				
			||||||
                            v-auth="'machine:file'"
 | 
					
 | 
				
			||||||
                            type="success"
 | 
					                        <span v-auth="'machine:update'" v-if="scope.row.enableRecorder == 1">
 | 
				
			||||||
                            :disabled="scope.row.status == -1"
 | 
					                            <el-link @click="showRec(scope.row)" plain :underline="false" size="small">终端回放</el-link>
 | 
				
			||||||
                            @click="fileManage(scope.row)"
 | 
					                            <el-divider direction="vertical" border-style="dashed" />
 | 
				
			||||||
                            plain
 | 
					                        </span>
 | 
				
			||||||
                            size="small"
 | 
					
 | 
				
			||||||
                            :underline="false"
 | 
					                        <span v-auth="'machine:file'">
 | 
				
			||||||
                            >文件</el-link
 | 
					                            <el-link
 | 
				
			||||||
                        >
 | 
					                                type="success"
 | 
				
			||||||
                        <el-divider v-auth="'machine:file'" direction="vertical" border-style="dashed" />
 | 
					                                :disabled="scope.row.status == -1"
 | 
				
			||||||
 | 
					                                @click="fileManage(scope.row)"
 | 
				
			||||||
 | 
					                                plain
 | 
				
			||||||
 | 
					                                size="small"
 | 
				
			||||||
 | 
					                                :underline="false"
 | 
				
			||||||
 | 
					                                >文件</el-link
 | 
				
			||||||
 | 
					                            >
 | 
				
			||||||
 | 
					                            <el-divider direction="vertical" border-style="dashed" />
 | 
				
			||||||
 | 
					                        </span>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        <el-link
 | 
					                        <el-link
 | 
				
			||||||
                            :disabled="scope.row.status == -1"
 | 
					                            :disabled="scope.row.status == -1"
 | 
				
			||||||
                            type="warning"
 | 
					                            type="warning"
 | 
				
			||||||
@@ -113,10 +117,12 @@
 | 
				
			|||||||
                            >脚本</el-link
 | 
					                            >脚本</el-link
 | 
				
			||||||
                        >
 | 
					                        >
 | 
				
			||||||
                        <el-divider direction="vertical" border-style="dashed" />
 | 
					                        <el-divider direction="vertical" border-style="dashed" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        <el-link @click="showProcess(scope.row)" :disabled="scope.row.status == -1" plain :underline="false" size="small"
 | 
					                        <el-link @click="showProcess(scope.row)" :disabled="scope.row.status == -1" plain :underline="false" size="small"
 | 
				
			||||||
                            >进程</el-link
 | 
					                            >进程</el-link
 | 
				
			||||||
                        >
 | 
					                        >
 | 
				
			||||||
                        <el-divider direction="vertical" border-style="dashed" />
 | 
					                        <el-divider direction="vertical" border-style="dashed" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        <el-link
 | 
					                        <el-link
 | 
				
			||||||
                            :disabled="!scope.row.hasCli || scope.row.status == -1"
 | 
					                            :disabled="!scope.row.hasCli || scope.row.status == -1"
 | 
				
			||||||
                            type="danger"
 | 
					                            type="danger"
 | 
				
			||||||
@@ -228,11 +234,15 @@ export default defineComponent({
 | 
				
			|||||||
                data: null,
 | 
					                data: null,
 | 
				
			||||||
                title: '新增机器',
 | 
					                title: '新增机器',
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
 | 
					            machineRecDialog: {
 | 
				
			||||||
 | 
					                visible: false,
 | 
				
			||||||
 | 
					                machineId: 0,
 | 
				
			||||||
 | 
					                title: '',
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        onMounted(async () => {
 | 
					        onMounted(async () => {
 | 
				
			||||||
            search();
 | 
					            search();
 | 
				
			||||||
            state.projects = await projectApi.accountProjects.request(null);
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const choose = (item: any) => {
 | 
					        const choose = (item: any) => {
 | 
				
			||||||
@@ -255,18 +265,28 @@ export default defineComponent({
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const closeCli = async (row: any) => {
 | 
					        const closeCli = async (row: any) => {
 | 
				
			||||||
 | 
					            await ElMessageBox.confirm(`确定关闭该机器客户端连接?`, '提示', {
 | 
				
			||||||
 | 
					                confirmButtonText: '确定',
 | 
				
			||||||
 | 
					                cancelButtonText: '取消',
 | 
				
			||||||
 | 
					                type: 'warning',
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
            await machineApi.closeCli.request({ id: row.id });
 | 
					            await machineApi.closeCli.request({ id: row.id });
 | 
				
			||||||
            ElMessage.success('关闭成功');
 | 
					            ElMessage.success('关闭成功');
 | 
				
			||||||
            search();
 | 
					            search();
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const openFormDialog = (redis: any) => {
 | 
					        const getProjects = async () => {
 | 
				
			||||||
 | 
					            state.projects = await projectApi.accountProjects.request(null);
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const openFormDialog = async (machine: any) => {
 | 
				
			||||||
 | 
					            await getProjects();
 | 
				
			||||||
            let dialogTitle;
 | 
					            let dialogTitle;
 | 
				
			||||||
            if (redis) {
 | 
					            if (machine) {
 | 
				
			||||||
                state.machineEditDialog.data = state.currentData as any;
 | 
					                state.machineEditDialog.data = state.currentData as any;
 | 
				
			||||||
                dialogTitle = '编辑机器';
 | 
					                dialogTitle = '编辑机器';
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                state.machineEditDialog.data = { port: 22 } as any;
 | 
					                state.machineEditDialog.data = null;
 | 
				
			||||||
                dialogTitle = '添加机器';
 | 
					                dialogTitle = '添加机器';
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -338,9 +358,21 @@ export default defineComponent({
 | 
				
			|||||||
            state.processDialog.visible = true;
 | 
					            state.processDialog.visible = true;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const showRec = (row: any) => {
 | 
				
			||||||
 | 
					            const { href } = router.resolve({
 | 
				
			||||||
 | 
					                path: `/machine/terminal-rec`,
 | 
				
			||||||
 | 
					                query: {
 | 
				
			||||||
 | 
					                    id: row.id,
 | 
				
			||||||
 | 
					                    name: `${row.name}[${row.ip}]-终端回放记录`,
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            window.open(href, '_blank');
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
            choose,
 | 
					            choose,
 | 
				
			||||||
 | 
					            getProjects,
 | 
				
			||||||
            showTerminal,
 | 
					            showTerminal,
 | 
				
			||||||
            openFormDialog,
 | 
					            openFormDialog,
 | 
				
			||||||
            deleteMachine,
 | 
					            deleteMachine,
 | 
				
			||||||
@@ -352,6 +384,7 @@ export default defineComponent({
 | 
				
			|||||||
            submitSuccess,
 | 
					            submitSuccess,
 | 
				
			||||||
            fileManage,
 | 
					            fileManage,
 | 
				
			||||||
            search,
 | 
					            search,
 | 
				
			||||||
 | 
					            showRec,
 | 
				
			||||||
            handlePageChange,
 | 
					            handlePageChange,
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										120
									
								
								mayfly_go_web/src/views/ops/machine/MachineRec.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										120
									
								
								mayfly_go_web/src/views/ops/machine/MachineRec.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,120 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					    <div>
 | 
				
			||||||
 | 
					        <div class="toolbar">
 | 
				
			||||||
 | 
					            <span style="dispaly: inline-block" class="ml10">{{ title }}</span>
 | 
				
			||||||
 | 
					            <el-divider direction="vertical" border-style="dashed" />
 | 
				
			||||||
 | 
					            <el-select @change="getUsers" v-model="operateDate" placeholder="操作日期" filterable>
 | 
				
			||||||
 | 
					                <el-option v-for="item in operateDates" :key="item" :label="item" :value="item"> </el-option>
 | 
				
			||||||
 | 
					            </el-select>
 | 
				
			||||||
 | 
					            <el-select class="ml10" @change="getRecs" filterable v-model="user" placeholder="请选择操作人">
 | 
				
			||||||
 | 
					                <el-option v-for="item in users" :key="item" :label="item" :value="item"> </el-option>
 | 
				
			||||||
 | 
					            </el-select>
 | 
				
			||||||
 | 
					            <el-select class="ml10" @change="playRec" filterable v-model="rec" placeholder="请选择操作记录">
 | 
				
			||||||
 | 
					                <el-option v-for="item in recs" :key="item" :label="item" :value="item"> </el-option>
 | 
				
			||||||
 | 
					            </el-select>
 | 
				
			||||||
 | 
					            <el-divider direction="vertical" border-style="dashed" />
 | 
				
			||||||
 | 
					            快捷键-> space[空格键]: 暂停/播放  |  f: 全屏/取消全屏
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					        <div ref="playerRef" id="rc-player"></div>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script lang="ts">
 | 
				
			||||||
 | 
					import { toRefs, onMounted, ref, reactive, defineComponent } from 'vue';
 | 
				
			||||||
 | 
					import { machineApi } from './api';
 | 
				
			||||||
 | 
					import * as AsciinemaPlayer from 'asciinema-player';
 | 
				
			||||||
 | 
					import 'asciinema-player/dist/bundle/asciinema-player.css';
 | 
				
			||||||
 | 
					import { useRoute } from 'vue-router';
 | 
				
			||||||
 | 
					export default defineComponent({
 | 
				
			||||||
 | 
					    name: 'MachineRec',
 | 
				
			||||||
 | 
					    components: {},
 | 
				
			||||||
 | 
					    props: {
 | 
				
			||||||
 | 
					        visible: { type: Boolean },
 | 
				
			||||||
 | 
					        machineId: { type: Number },
 | 
				
			||||||
 | 
					        title: { type: String },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    setup(props: any, context) {
 | 
				
			||||||
 | 
					        const route = useRoute();
 | 
				
			||||||
 | 
					        const playerRef = ref(null);
 | 
				
			||||||
 | 
					        const state = reactive({
 | 
				
			||||||
 | 
					            dialogVisible: false,
 | 
				
			||||||
 | 
					            title: '',
 | 
				
			||||||
 | 
					            machineId: 0,
 | 
				
			||||||
 | 
					            operateDates: [],
 | 
				
			||||||
 | 
					            users: [],
 | 
				
			||||||
 | 
					            recs: [],
 | 
				
			||||||
 | 
					            operateDate: '',
 | 
				
			||||||
 | 
					            user: '',
 | 
				
			||||||
 | 
					            rec: '',
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        onMounted(() => {
 | 
				
			||||||
 | 
					            state.machineId = Number.parseInt(route.query.id as string);
 | 
				
			||||||
 | 
					            state.title = route.query.name as string;
 | 
				
			||||||
 | 
					            getOperateDate();
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getOperateDate = async () => {
 | 
				
			||||||
 | 
					            const res = await machineApi.recDirNames.request({ path: state.machineId });
 | 
				
			||||||
 | 
					            state.operateDates = res as any;
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getUsers = async (operateDate: string) => {
 | 
				
			||||||
 | 
					            state.users = [];
 | 
				
			||||||
 | 
					            state.user = '';
 | 
				
			||||||
 | 
					            state.recs = [];
 | 
				
			||||||
 | 
					            state.rec = '';
 | 
				
			||||||
 | 
					            const res = await machineApi.recDirNames.request({ path: `${state.machineId}/${operateDate}` });
 | 
				
			||||||
 | 
					            state.users = res as any;
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getRecs = async (user: string) => {
 | 
				
			||||||
 | 
					            state.recs = [];
 | 
				
			||||||
 | 
					            state.rec = '';
 | 
				
			||||||
 | 
					            const res = await machineApi.recDirNames.request({ path: `${state.machineId}/${state.operateDate}/${user}` });
 | 
				
			||||||
 | 
					            state.recs = res as any;
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let player: any = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const playRec = async (rec: string) => {
 | 
				
			||||||
 | 
					            if (player) {
 | 
				
			||||||
 | 
					                player.dispose();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            const content = await machineApi.recDirNames.request({
 | 
				
			||||||
 | 
					                isFile: '1',
 | 
				
			||||||
 | 
					                path: `${state.machineId}/${state.operateDate}/${state.user}/${rec}`,
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            player = AsciinemaPlayer.create(`data:text/plain;base64,${content}`, playerRef.value, {
 | 
				
			||||||
 | 
					                autoPlay: true,
 | 
				
			||||||
 | 
					                speed: 1.0,
 | 
				
			||||||
 | 
					                idleTimeLimit: 2,
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         * 关闭取消按钮触发的事件
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        const handleClose = () => {
 | 
				
			||||||
 | 
					            context.emit('update:visible', false);
 | 
				
			||||||
 | 
					            context.emit('update:machineId', null);
 | 
				
			||||||
 | 
					            context.emit('cancel');
 | 
				
			||||||
 | 
					            state.operateDates = [];
 | 
				
			||||||
 | 
					            state.users = [];
 | 
				
			||||||
 | 
					            state.recs = [];
 | 
				
			||||||
 | 
					            state.operateDate = '';
 | 
				
			||||||
 | 
					            state.user = '';
 | 
				
			||||||
 | 
					            state.rec = '';
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            ...toRefs(state),
 | 
				
			||||||
 | 
					            playerRef,
 | 
				
			||||||
 | 
					            getUsers,
 | 
				
			||||||
 | 
					            getRecs,
 | 
				
			||||||
 | 
					            playRec,
 | 
				
			||||||
 | 
					            handleClose,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
@@ -7,9 +7,9 @@
 | 
				
			|||||||
            :before-close="cancel"
 | 
					            :before-close="cancel"
 | 
				
			||||||
            :show-close="true"
 | 
					            :show-close="true"
 | 
				
			||||||
            :destroy-on-close="true"
 | 
					            :destroy-on-close="true"
 | 
				
			||||||
            width="800px"
 | 
					            width="900px"
 | 
				
			||||||
        >
 | 
					        >
 | 
				
			||||||
            <el-form :model="form" ref="mockDataForm" label-width="70px">
 | 
					            <el-form :model="form" ref="scriptForm" label-width="70px" size="small">
 | 
				
			||||||
                <el-form-item prop="method" label="名称">
 | 
					                <el-form-item prop="method" label="名称">
 | 
				
			||||||
                    <el-input v-model.trim="form.name" placeholder="请输入名称"></el-input>
 | 
					                    <el-input v-model.trim="form.name" placeholder="请输入名称"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
@@ -24,8 +24,23 @@
 | 
				
			|||||||
                    </el-select>
 | 
					                    </el-select>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                <el-form-item prop="params" label="参数">
 | 
					                <el-row style="margin-left: 30px; margin-bottom: 5px">
 | 
				
			||||||
                    <el-input v-model="form.params" placeholder="参数数组json,若无可不填"></el-input>
 | 
					                    <el-button @click="onAddParam" size="small" type="success">新增占位符参数</el-button>
 | 
				
			||||||
 | 
					                </el-row>
 | 
				
			||||||
 | 
					                <el-form-item :key="param" v-for="(param, index) in params" prop="params" :label="`参数${index + 1}`">
 | 
				
			||||||
 | 
					                    <el-row>
 | 
				
			||||||
 | 
					                        <el-col :span="5"><el-input v-model="param.model" placeholder="内容中用{{.model}}替换"></el-input></el-col>
 | 
				
			||||||
 | 
					                        <el-divider :span="1" direction="vertical" border-style="dashed" />
 | 
				
			||||||
 | 
					                        <el-col :span="4"><el-input v-model="param.name" placeholder="字段名"></el-input></el-col>
 | 
				
			||||||
 | 
					                        <el-divider :span="1" direction="vertical" border-style="dashed" />
 | 
				
			||||||
 | 
					                        <el-col :span="4"><el-input v-model="param.placeholder" placeholder="字段说明"></el-input></el-col>
 | 
				
			||||||
 | 
					                        <el-divider :span="1" direction="vertical" border-style="dashed" />
 | 
				
			||||||
 | 
					                        <el-col :span="4">
 | 
				
			||||||
 | 
					                            <el-input v-model="param.options" placeholder="可选值 ,分割"></el-input>
 | 
				
			||||||
 | 
					                        </el-col>
 | 
				
			||||||
 | 
					                        <el-divider :span="1" direction="vertical" border-style="dashed" />
 | 
				
			||||||
 | 
					                        <el-col :span="2"><el-button @click="onDeleteParam(index)" size="small" type="danger">删除</el-button></el-col>
 | 
				
			||||||
 | 
					                    </el-row>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                <el-form-item prop="script" label="内容" id="content">
 | 
					                <el-form-item prop="script" label="内容" id="content">
 | 
				
			||||||
@@ -35,13 +50,12 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            <template #footer>
 | 
					            <template #footer>
 | 
				
			||||||
                <div class="dialog-footer">
 | 
					                <div class="dialog-footer">
 | 
				
			||||||
                    <el-button @click="cancel()" :disabled="submitDisabled" size="small">关 闭</el-button>
 | 
					                    <el-button @click="cancel()" :disabled="submitDisabled">关 闭</el-button>
 | 
				
			||||||
                    <el-button
 | 
					                    <el-button
 | 
				
			||||||
                        v-auth="'machine:script:save'"
 | 
					                        v-auth="'machine:script:save'"
 | 
				
			||||||
                        type="primary"
 | 
					                        type="primary"
 | 
				
			||||||
                        :loading="btnLoading"
 | 
					                        :loading="btnLoading"
 | 
				
			||||||
                        @click="btnOk"
 | 
					                        @click="btnOk"
 | 
				
			||||||
                        size="small"
 | 
					 | 
				
			||||||
                        :disabled="submitDisabled"
 | 
					                        :disabled="submitDisabled"
 | 
				
			||||||
                        >保 存</el-button
 | 
					                        >保 存</el-button
 | 
				
			||||||
                    >
 | 
					                    >
 | 
				
			||||||
@@ -84,41 +98,59 @@ export default defineComponent({
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
    setup(props: any, { emit }) {
 | 
					    setup(props: any, { emit }) {
 | 
				
			||||||
        const { isCommon, machineId } = toRefs(props);
 | 
					        const { isCommon, machineId } = toRefs(props);
 | 
				
			||||||
        const mockDataForm: any = ref(null);
 | 
					        const scriptForm: any = ref(null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const state = reactive({
 | 
					        const state = reactive({
 | 
				
			||||||
            dialogVisible: false,
 | 
					            dialogVisible: false,
 | 
				
			||||||
            submitDisabled: false,
 | 
					            submitDisabled: false,
 | 
				
			||||||
 | 
					            params: [] as any,
 | 
				
			||||||
            form: {
 | 
					            form: {
 | 
				
			||||||
                id: null,
 | 
					                id: null,
 | 
				
			||||||
                name: '',
 | 
					                name: '',
 | 
				
			||||||
                machineId: 0,
 | 
					                machineId: 0,
 | 
				
			||||||
                description: '',
 | 
					                description: '',
 | 
				
			||||||
                script: '',
 | 
					                script: '',
 | 
				
			||||||
                params: null,
 | 
					                params: '',
 | 
				
			||||||
                type: null,
 | 
					                type: null,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            btnLoading: false,
 | 
					            btnLoading: false,
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        watch(props, (newValue) => {
 | 
					        watch(props, (newValue) => {
 | 
				
			||||||
 | 
					            state.dialogVisible = newValue.visible;
 | 
				
			||||||
 | 
					            if (!newValue.visible) {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            if (newValue.data) {
 | 
					            if (newValue.data) {
 | 
				
			||||||
                state.form = { ...newValue.data };
 | 
					                state.form = { ...newValue.data };
 | 
				
			||||||
 | 
					                if (state.form.params) {
 | 
				
			||||||
 | 
					                    state.params = JSON.parse(state.form.params);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                state.form = {} as any;
 | 
					                state.form = {} as any;
 | 
				
			||||||
                state.form.script = '';
 | 
					                state.form.script = '';
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            state.dialogVisible = newValue.visible;
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const onAddParam = () => {
 | 
				
			||||||
 | 
					            state.params.push({ name: '', model: '', placeholder: '' });
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const onDeleteParam = (idx: number) => {
 | 
				
			||||||
 | 
					            state.params.splice(idx, 1);
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const btnOk = () => {
 | 
					        const btnOk = () => {
 | 
				
			||||||
            state.form.machineId = isCommon.value ? 9999999 : (machineId.value as any);
 | 
					            state.form.machineId = isCommon.value ? 9999999 : (machineId.value as any);
 | 
				
			||||||
            console.log('machineid:', machineId);
 | 
					            console.log('machineid:', machineId);
 | 
				
			||||||
            mockDataForm.value.validate((valid: any) => {
 | 
					            scriptForm.value.validate((valid: any) => {
 | 
				
			||||||
                if (valid) {
 | 
					                if (valid) {
 | 
				
			||||||
                    notEmpty(state.form.name, '名称不能为空');
 | 
					                    notEmpty(state.form.name, '名称不能为空');
 | 
				
			||||||
                    notEmpty(state.form.description, '描述不能为空');
 | 
					                    notEmpty(state.form.description, '描述不能为空');
 | 
				
			||||||
                    notEmpty(state.form.script, '内容不能为空');
 | 
					                    notEmpty(state.form.script, '内容不能为空');
 | 
				
			||||||
 | 
					                    if (state.params) {
 | 
				
			||||||
 | 
					                        state.form.params = JSON.stringify(state.params);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                    machineApi.saveScript.request(state.form).then(
 | 
					                    machineApi.saveScript.request(state.form).then(
 | 
				
			||||||
                        () => {
 | 
					                        () => {
 | 
				
			||||||
                            ElMessage.success('保存成功');
 | 
					                            ElMessage.success('保存成功');
 | 
				
			||||||
@@ -139,12 +171,15 @@ export default defineComponent({
 | 
				
			|||||||
        const cancel = () => {
 | 
					        const cancel = () => {
 | 
				
			||||||
            emit('update:visible', false);
 | 
					            emit('update:visible', false);
 | 
				
			||||||
            emit('cancel');
 | 
					            emit('cancel');
 | 
				
			||||||
 | 
					            state.params = [];
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
            enums,
 | 
					            enums,
 | 
				
			||||||
            mockDataForm,
 | 
					            onAddParam,
 | 
				
			||||||
 | 
					            onDeleteParam,
 | 
				
			||||||
 | 
					            scriptForm,
 | 
				
			||||||
            btnOk,
 | 
					            btnOk,
 | 
				
			||||||
            cancel,
 | 
					            cancel,
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -76,7 +76,24 @@
 | 
				
			|||||||
        <el-dialog title="脚本参数" v-model="scriptParamsDialog.visible" width="400px">
 | 
					        <el-dialog title="脚本参数" v-model="scriptParamsDialog.visible" width="400px">
 | 
				
			||||||
            <el-form ref="paramsForm" :model="scriptParamsDialog.params" label-width="70px" size="small">
 | 
					            <el-form ref="paramsForm" :model="scriptParamsDialog.params" label-width="70px" size="small">
 | 
				
			||||||
                <el-form-item v-for="item in scriptParamsDialog.paramsFormItem" :key="item.name" :prop="item.model" :label="item.name" required>
 | 
					                <el-form-item v-for="item in scriptParamsDialog.paramsFormItem" :key="item.name" :prop="item.model" :label="item.name" required>
 | 
				
			||||||
                    <el-input v-model="scriptParamsDialog.params[item.model]" :placeholder="item.placeholder" autocomplete="off"></el-input>
 | 
					                    <el-input
 | 
				
			||||||
 | 
					                        v-if="!item.options"
 | 
				
			||||||
 | 
					                        v-model="scriptParamsDialog.params[item.model]"
 | 
				
			||||||
 | 
					                        :placeholder="item.placeholder"
 | 
				
			||||||
 | 
					                        autocomplete="off"
 | 
				
			||||||
 | 
					                        clearable
 | 
				
			||||||
 | 
					                    ></el-input>
 | 
				
			||||||
 | 
					                    <el-select
 | 
				
			||||||
 | 
					                        v-else
 | 
				
			||||||
 | 
					                        v-model="scriptParamsDialog.params[item.model]"
 | 
				
			||||||
 | 
					                        :placeholder="item.placeholder"
 | 
				
			||||||
 | 
					                        filterable
 | 
				
			||||||
 | 
					                        autocomplete="off"
 | 
				
			||||||
 | 
					                        clearable
 | 
				
			||||||
 | 
					                        style="width: 100%"
 | 
				
			||||||
 | 
					                    >
 | 
				
			||||||
 | 
					                        <el-option v-for="option in item.options.split(',')" :key="option" :label="option" :value="option" />
 | 
				
			||||||
 | 
					                    </el-select>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
            </el-form>
 | 
					            </el-form>
 | 
				
			||||||
            <template #footer>
 | 
					            <template #footer>
 | 
				
			||||||
@@ -88,7 +105,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        <el-dialog title="执行结果" v-model="resultDialog.visible" width="50%">
 | 
					        <el-dialog title="执行结果" v-model="resultDialog.visible" width="50%">
 | 
				
			||||||
            <div style="white-space: pre-line; padding: 10px; color: #000000">
 | 
					            <div style="white-space: pre-line; padding: 10px; color: #000000">
 | 
				
			||||||
                <!-- {{ resultDialog.result }} -->
 | 
					 | 
				
			||||||
                <el-input v-model="resultDialog.result" :rows="20" type="textarea" />
 | 
					                <el-input v-model="resultDialog.result" :rows="20" type="textarea" />
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
        </el-dialog>
 | 
					        </el-dialog>
 | 
				
			||||||
@@ -97,12 +113,12 @@
 | 
				
			|||||||
            v-if="terminalDialog.visible"
 | 
					            v-if="terminalDialog.visible"
 | 
				
			||||||
            title="终端"
 | 
					            title="终端"
 | 
				
			||||||
            v-model="terminalDialog.visible"
 | 
					            v-model="terminalDialog.visible"
 | 
				
			||||||
            width="70%"
 | 
					            width="80%"
 | 
				
			||||||
            :close-on-click-modal="false"
 | 
					            :close-on-click-modal="false"
 | 
				
			||||||
            :modal="false"
 | 
					            :modal="false"
 | 
				
			||||||
            @close="closeTermnial"
 | 
					            @close="closeTermnial"
 | 
				
			||||||
        >
 | 
					        >
 | 
				
			||||||
            <ssh-terminal ref="terminal" :cmd="terminalDialog.cmd" :machineId="terminalDialog.machineId" height="600px" />
 | 
					            <ssh-terminal ref="terminal" :cmd="terminalDialog.cmd" :machineId="terminalDialog.machineId" height="560px" />
 | 
				
			||||||
        </el-dialog>
 | 
					        </el-dialog>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <script-edit
 | 
					        <script-edit
 | 
				
			||||||
@@ -196,8 +212,10 @@ export default defineComponent({
 | 
				
			|||||||
            // 如果存在参数,则弹窗输入参数后执行
 | 
					            // 如果存在参数,则弹窗输入参数后执行
 | 
				
			||||||
            if (script.params) {
 | 
					            if (script.params) {
 | 
				
			||||||
                state.scriptParamsDialog.paramsFormItem = JSON.parse(script.params);
 | 
					                state.scriptParamsDialog.paramsFormItem = JSON.parse(script.params);
 | 
				
			||||||
                state.scriptParamsDialog.visible = true;
 | 
					                if (state.scriptParamsDialog.paramsFormItem && state.scriptParamsDialog.paramsFormItem.length > 0) {
 | 
				
			||||||
                return;
 | 
					                    state.scriptParamsDialog.visible = true;
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            run(script);
 | 
					            run(script);
 | 
				
			||||||
@@ -268,8 +286,6 @@ export default defineComponent({
 | 
				
			|||||||
        const closeTermnial = () => {
 | 
					        const closeTermnial = () => {
 | 
				
			||||||
            state.terminalDialog.visible = false;
 | 
					            state.terminalDialog.visible = false;
 | 
				
			||||||
            state.terminalDialog.machineId = 0;
 | 
					            state.terminalDialog.machineId = 0;
 | 
				
			||||||
            // const t: any = this.$refs['terminal']
 | 
					 | 
				
			||||||
            // t.closeAll()
 | 
					 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /**
 | 
					        /**
 | 
				
			||||||
@@ -295,8 +311,6 @@ export default defineComponent({
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const submitSuccess = () => {
 | 
					        const submitSuccess = () => {
 | 
				
			||||||
            // this.delChoose()
 | 
					 | 
				
			||||||
            // this.search()
 | 
					 | 
				
			||||||
            getScripts();
 | 
					            getScripts();
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -326,6 +340,7 @@ export default defineComponent({
 | 
				
			|||||||
            context.emit('update:machineId', null);
 | 
					            context.emit('update:machineId', null);
 | 
				
			||||||
            context.emit('cancel');
 | 
					            context.emit('cancel');
 | 
				
			||||||
            state.scriptTable = [];
 | 
					            state.scriptTable = [];
 | 
				
			||||||
 | 
					            state.scriptParamsDialog.paramsFormItem = [];
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,7 +9,7 @@ import { FitAddon } from 'xterm-addon-fit';
 | 
				
			|||||||
import { getSession } from '@/common/utils/storage.ts';
 | 
					import { getSession } from '@/common/utils/storage.ts';
 | 
				
			||||||
import config from '@/common/config';
 | 
					import config from '@/common/config';
 | 
				
			||||||
import { useStore } from '@/store/index.ts';
 | 
					import { useStore } from '@/store/index.ts';
 | 
				
			||||||
import { toRefs, watch, computed, reactive, defineComponent, onMounted, onBeforeUnmount } from 'vue';
 | 
					import { nextTick, toRefs, watch, computed, reactive, defineComponent, onMounted, onBeforeUnmount } from 'vue';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'SshTerminal',
 | 
					    name: 'SshTerminal',
 | 
				
			||||||
@@ -27,22 +27,20 @@ export default defineComponent({
 | 
				
			|||||||
            socket: null as any,
 | 
					            socket: null as any,
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const resize = 1;
 | 
				
			||||||
 | 
					        const data = 2;
 | 
				
			||||||
 | 
					        const ping = 3;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        watch(props, (newValue) => {
 | 
					        watch(props, (newValue) => {
 | 
				
			||||||
            state.machineId = newValue.machineId;
 | 
					            state.machineId = newValue.machineId;
 | 
				
			||||||
            state.cmd = newValue.cmd;
 | 
					            state.cmd = newValue.cmd;
 | 
				
			||||||
            state.height = newValue.height;
 | 
					            state.height = newValue.height;
 | 
				
			||||||
            if (state.machineId) {
 | 
					 | 
				
			||||||
                initSocket();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        onMounted(() => {
 | 
					        onMounted(() => {
 | 
				
			||||||
            state.machineId = props.machineId;
 | 
					            state.machineId = props.machineId;
 | 
				
			||||||
            state.height = props.height;
 | 
					            state.height = props.height;
 | 
				
			||||||
            state.cmd = props.cmd;
 | 
					            state.cmd = props.cmd;
 | 
				
			||||||
            if (state.machineId) {
 | 
					 | 
				
			||||||
                initSocket();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        onBeforeUnmount(() => {
 | 
					        onBeforeUnmount(() => {
 | 
				
			||||||
@@ -56,13 +54,17 @@ export default defineComponent({
 | 
				
			|||||||
            return store.state.themeConfig.themeConfig;
 | 
					            return store.state.themeConfig.themeConfig;
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        nextTick(() => {
 | 
				
			||||||
 | 
					            initXterm();
 | 
				
			||||||
 | 
					            initSocket();
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        function initXterm() {
 | 
					        function initXterm() {
 | 
				
			||||||
            const term: any = new Terminal({
 | 
					            const term: any = new Terminal({
 | 
				
			||||||
                fontSize: getThemeConfig.value.terminalFontSize || 15,
 | 
					                fontSize: getThemeConfig.value.terminalFontSize || 15,
 | 
				
			||||||
                // fontWeight: getThemeConfig.value.terminalFontWeight || 'normal',
 | 
					                fontWeight: getThemeConfig.value.terminalFontWeight || 'normal',
 | 
				
			||||||
                fontFamily: 'JetBrainsMono, Consolas, Menlo, Monaco',
 | 
					                fontFamily: 'JetBrainsMono, monaco, Consolas, Lucida Console, monospace',
 | 
				
			||||||
                cursorBlink: true,
 | 
					                cursorBlink: true,
 | 
				
			||||||
                // cursorStyle: 'underline', //光标样式
 | 
					 | 
				
			||||||
                disableStdin: false,
 | 
					                disableStdin: false,
 | 
				
			||||||
                theme: {
 | 
					                theme: {
 | 
				
			||||||
                    foreground: getThemeConfig.value.terminalForeground || '#7e9192', //字体
 | 
					                    foreground: getThemeConfig.value.terminalForeground || '#7e9192', //字体
 | 
				
			||||||
@@ -82,6 +84,14 @@ export default defineComponent({
 | 
				
			|||||||
                try {
 | 
					                try {
 | 
				
			||||||
                    // 窗口大小改变时,触发xterm的resize方法使自适应
 | 
					                    // 窗口大小改变时,触发xterm的resize方法使自适应
 | 
				
			||||||
                    fitAddon.fit();
 | 
					                    fitAddon.fit();
 | 
				
			||||||
 | 
					                    if (state.term) {
 | 
				
			||||||
 | 
					                        state.term.focus();
 | 
				
			||||||
 | 
					                        send({
 | 
				
			||||||
 | 
					                            type: resize,
 | 
				
			||||||
 | 
					                            Cols: parseInt(state.term.cols),
 | 
				
			||||||
 | 
					                            Rows: parseInt(state.term.rows),
 | 
				
			||||||
 | 
					                        });
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                } catch (e) {
 | 
					                } catch (e) {
 | 
				
			||||||
                    console.log(e);
 | 
					                    console.log(e);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@@ -104,69 +114,52 @@ export default defineComponent({
 | 
				
			|||||||
            term.onData((key: any) => {
 | 
					            term.onData((key: any) => {
 | 
				
			||||||
                sendCmd(key);
 | 
					                sendCmd(key);
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
            // 为解决窗体resize方法才会向后端发送列数和行数,所以页面加载时也要触发此方法
 | 
					 | 
				
			||||||
            send({
 | 
					 | 
				
			||||||
                type: 'resize',
 | 
					 | 
				
			||||||
                Cols: parseInt(term.cols),
 | 
					 | 
				
			||||||
                Rows: parseInt(term.rows),
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
            // 如果有初始要执行的命令,则发送执行命令
 | 
					 | 
				
			||||||
            if (state.cmd) {
 | 
					 | 
				
			||||||
                sendCmd(state.cmd + ' \r');
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let pingInterval: any;
 | 
				
			||||||
        function initSocket() {
 | 
					        function initSocket() {
 | 
				
			||||||
            state.socket = new WebSocket(`${config.baseWsUrl}/machines/${state.machineId}/terminal?token=${getSession('token')}`);
 | 
					            state.socket = new WebSocket(
 | 
				
			||||||
 | 
					                `${config.baseWsUrl}/machines/${state.machineId}/terminal?token=${getSession('token')}&cols=${state.term.cols}&rows=${
 | 
				
			||||||
 | 
					                    state.term.rows
 | 
				
			||||||
 | 
					                }`
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // 监听socket连接
 | 
					            // 监听socket连接
 | 
				
			||||||
            state.socket.onopen = open;
 | 
					            state.socket.onopen = () => {
 | 
				
			||||||
 | 
					                // 如果有初始要执行的命令,则发送执行命令
 | 
				
			||||||
 | 
					                if (state.cmd) {
 | 
				
			||||||
 | 
					                    sendCmd(state.cmd + ' \r');
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                // 开启心跳
 | 
				
			||||||
 | 
					                pingInterval = setInterval(() => {
 | 
				
			||||||
 | 
					                    send({ type: ping, msg: 'ping' });
 | 
				
			||||||
 | 
					                }, 8000);
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // 监听socket错误信息
 | 
					            // 监听socket错误信息
 | 
				
			||||||
            state.socket.onerror = error;
 | 
					            state.socket.onerror = (e: any) => {
 | 
				
			||||||
            // 监听socket消息
 | 
					                console.log('连接错误', e);
 | 
				
			||||||
            state.socket.onmessage = getMessage;
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            state.socket.onclose = () => {
 | 
				
			||||||
 | 
					                if (state.term) {
 | 
				
			||||||
 | 
					                    state.term.writeln('\r\n\x1b[31m提示: 连接已关闭...');
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                if (pingInterval) {
 | 
				
			||||||
 | 
					                    clearInterval(pingInterval);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // 发送socket消息
 | 
					            // 发送socket消息
 | 
				
			||||||
            state.socket.onsend = send;
 | 
					            state.socket.onsend = send;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // 监听socket消息
 | 
				
			||||||
 | 
					            state.socket.onmessage = getMessage;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        function open() {
 | 
					        function getMessage(msg: any) {
 | 
				
			||||||
            console.log('socket连接成功');
 | 
					            // msg.data是真正后端返回的数据
 | 
				
			||||||
            initXterm();
 | 
					            state.term.write(msg.data);
 | 
				
			||||||
            //开启心跳
 | 
					 | 
				
			||||||
            //   this.start();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        function error() {
 | 
					 | 
				
			||||||
            console.log('连接错误');
 | 
					 | 
				
			||||||
            //重连
 | 
					 | 
				
			||||||
            // reconnect();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        function close() {
 | 
					 | 
				
			||||||
            if (state.socket) {
 | 
					 | 
				
			||||||
                state.socket.close();
 | 
					 | 
				
			||||||
                console.log('socket关闭');
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            //重连
 | 
					 | 
				
			||||||
            //   this.reconnect()
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        function getMessage(msg: string) {
 | 
					 | 
				
			||||||
            //   console.log(msg)
 | 
					 | 
				
			||||||
            state.term.write(msg['data']);
 | 
					 | 
				
			||||||
            //msg是返回的数据
 | 
					 | 
				
			||||||
            //   msg = JSON.parse(msg.data);
 | 
					 | 
				
			||||||
            //   this.socket.send("ping");//有事没事ping一下,看看ws还活着没
 | 
					 | 
				
			||||||
            //   //switch用于处理返回的数据,根据返回数据的格式去判断
 | 
					 | 
				
			||||||
            //   switch (msg["operation"]) {
 | 
					 | 
				
			||||||
            //     case "stdout":
 | 
					 | 
				
			||||||
            //       this.term.write(msg["data"]);//这里write也许不是固定的,失败后找后端看一下该怎么往term里面write
 | 
					 | 
				
			||||||
            //       break;
 | 
					 | 
				
			||||||
            //     default:
 | 
					 | 
				
			||||||
            //       console.error("Unexpected message type:", msg);//但是错误是固定的。。。。
 | 
					 | 
				
			||||||
            //   }
 | 
					 | 
				
			||||||
            //收到服务器信息,心跳重置
 | 
					 | 
				
			||||||
            //   this.reset();
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        function send(msg: any) {
 | 
					        function send(msg: any) {
 | 
				
			||||||
@@ -175,11 +168,18 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        function sendCmd(key: any) {
 | 
					        function sendCmd(key: any) {
 | 
				
			||||||
            send({
 | 
					            send({
 | 
				
			||||||
                type: 'cmd',
 | 
					                type: data,
 | 
				
			||||||
                msg: key,
 | 
					                msg: key,
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        function close() {
 | 
				
			||||||
 | 
					            if (state.socket) {
 | 
				
			||||||
 | 
					                state.socket.close();
 | 
				
			||||||
 | 
					                console.log('socket关闭');
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        function closeAll() {
 | 
					        function closeAll() {
 | 
				
			||||||
            close();
 | 
					            close();
 | 
				
			||||||
            if (state.term) {
 | 
					            if (state.term) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,7 @@ import Api from '@/common/Api';
 | 
				
			|||||||
export const machineApi = {
 | 
					export const machineApi = {
 | 
				
			||||||
    // 获取权限列表
 | 
					    // 获取权限列表
 | 
				
			||||||
    list: Api.create("/machines", 'get'),
 | 
					    list: Api.create("/machines", 'get'),
 | 
				
			||||||
 | 
					    getMachinePwd: Api.create("/machines/{id}/pwd", 'get'),
 | 
				
			||||||
    info: Api.create("/machines/{id}/sysinfo", 'get'),
 | 
					    info: Api.create("/machines/{id}/sysinfo", 'get'),
 | 
				
			||||||
    stats: Api.create("/machines/{id}/stats", 'get'),
 | 
					    stats: Api.create("/machines/{id}/stats", 'get'),
 | 
				
			||||||
    process: Api.create("/machines/{id}/process", 'get'),
 | 
					    process: Api.create("/machines/{id}/process", 'get'),
 | 
				
			||||||
@@ -32,5 +33,6 @@ export const machineApi = {
 | 
				
			|||||||
    addConf: Api.create("/machines/{machineId}/files", 'post'),
 | 
					    addConf: Api.create("/machines/{machineId}/files", 'post'),
 | 
				
			||||||
    // 删除配置的文件or目录
 | 
					    // 删除配置的文件or目录
 | 
				
			||||||
    delConf: Api.create("/machines/{machineId}/files/{id}", 'delete'),
 | 
					    delConf: Api.create("/machines/{machineId}/files/{id}", 'delete'),
 | 
				
			||||||
    terminal: Api.create("/api/machines/{id}/terminal", 'get')
 | 
					    terminal: Api.create("/api/machines/{id}/terminal", 'get'),
 | 
				
			||||||
 | 
					    recDirNames: Api.create("/machines/rec/names", 'get')
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -15,7 +15,7 @@
 | 
				
			|||||||
                            </el-form-item>
 | 
					                            </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            <el-form-item label="库" label-width="20px">
 | 
					                            <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">
 | 
					                                    <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: left">{{ item.Name }}</span>
 | 
				
			||||||
                                        <span style="float: right; color: #8492a6; margin-left: 4px; font-size: 13px">{{
 | 
					                                        <span style="float: right; color: #8492a6; margin-left: 4px; font-size: 13px">{{
 | 
				
			||||||
@@ -26,12 +26,8 @@
 | 
				
			|||||||
                            </el-form-item>
 | 
					                            </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            <el-form-item label="集合" label-width="40px">
 | 
					                            <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">
 | 
					                                    <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-option>
 | 
				
			||||||
                                </el-select>
 | 
					                                </el-select>
 | 
				
			||||||
                            </el-form-item>
 | 
					                            </el-form-item>
 | 
				
			||||||
@@ -124,7 +120,7 @@
 | 
				
			|||||||
            </template>
 | 
					            </template>
 | 
				
			||||||
        </el-dialog>
 | 
					        </el-dialog>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <el-dialog width="800px" title="json编辑器" v-model="jsoneditorDialog.visible" @close="onCloseJsonEditDialog" :close-on-click-modal="false">
 | 
					        <el-dialog width="70%" title="json编辑器" v-model="jsoneditorDialog.visible" @close="onCloseJsonEditDialog" :close-on-click-modal="false">
 | 
				
			||||||
            <json-edit v-model="jsoneditorDialog.doc" />
 | 
					            <json-edit v-model="jsoneditorDialog.doc" />
 | 
				
			||||||
        </el-dialog>
 | 
					        </el-dialog>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
    <div>
 | 
					    <div>
 | 
				
			||||||
        <el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :close-on-click-modal="false" width="35%" :destroy-on-close="true">
 | 
					        <el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :close-on-click-modal="false" width="38%" :destroy-on-close="true">
 | 
				
			||||||
            <el-form :model="form" ref="mongoForm" :rules="rules" label-width="65px">
 | 
					            <el-form :model="form" ref="mongoForm" :rules="rules" label-width="85px">
 | 
				
			||||||
                <el-form-item prop="projectId" label="项目" required>
 | 
					                <el-form-item prop="projectId" label="项目" required>
 | 
				
			||||||
                    <el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
 | 
					                    <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>
 | 
					                        <el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
 | 
				
			||||||
@@ -25,6 +25,24 @@
 | 
				
			|||||||
                        auto-complete="off"
 | 
					                        auto-complete="off"
 | 
				
			||||||
                    ></el-input>
 | 
					                    ></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                <el-form-item prop="enableSshTunnel" label="SSH隧道:">
 | 
				
			||||||
 | 
					                    <el-col :span="3">
 | 
				
			||||||
 | 
					                        <el-checkbox @change="getSshTunnelMachines" v-model="form.enableSshTunnel" :true-label="1" :false-label="-1"></el-checkbox>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
 | 
					                    <el-col :span="2" v-if="form.enableSshTunnel == 1"> 机器: </el-col>
 | 
				
			||||||
 | 
					                    <el-col :span="19" v-if="form.enableSshTunnel == 1">
 | 
				
			||||||
 | 
					                        <el-select style="width: 100%" v-model="form.sshTunnelMachineId" placeholder="请选择SSH隧道机器">
 | 
				
			||||||
 | 
					                            <el-option
 | 
				
			||||||
 | 
					                                v-for="item in sshTunnelMachineList"
 | 
				
			||||||
 | 
					                                :key="item.id"
 | 
				
			||||||
 | 
					                                :label="`${item.ip}:${item.port} [${item.name}]`"
 | 
				
			||||||
 | 
					                                :value="item.id"
 | 
				
			||||||
 | 
					                            >
 | 
				
			||||||
 | 
					                            </el-option>
 | 
				
			||||||
 | 
					                        </el-select>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
 | 
					                </el-form-item>
 | 
				
			||||||
            </el-form>
 | 
					            </el-form>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            <template #footer>
 | 
					            <template #footer>
 | 
				
			||||||
@@ -41,6 +59,7 @@
 | 
				
			|||||||
import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
 | 
					import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
 | 
				
			||||||
import { mongoApi } from './api';
 | 
					import { mongoApi } from './api';
 | 
				
			||||||
import { projectApi } from '../project/api.ts';
 | 
					import { projectApi } from '../project/api.ts';
 | 
				
			||||||
 | 
					import { machineApi } from '../machine/api.ts';
 | 
				
			||||||
import { ElMessage } from 'element-plus';
 | 
					import { ElMessage } from 'element-plus';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
@@ -65,10 +84,13 @@ export default defineComponent({
 | 
				
			|||||||
            dialogVisible: false,
 | 
					            dialogVisible: false,
 | 
				
			||||||
            projects: [],
 | 
					            projects: [],
 | 
				
			||||||
            envs: [],
 | 
					            envs: [],
 | 
				
			||||||
 | 
					            sshTunnelMachineList: [],
 | 
				
			||||||
            form: {
 | 
					            form: {
 | 
				
			||||||
                id: null,
 | 
					                id: null,
 | 
				
			||||||
                name: null,
 | 
					                name: null,
 | 
				
			||||||
                uri: null,
 | 
					                uri: null,
 | 
				
			||||||
 | 
					                enableSshTunnel: -1,
 | 
				
			||||||
 | 
					                sshTunnelMachineId: null,
 | 
				
			||||||
                project: null,
 | 
					                project: null,
 | 
				
			||||||
                projectId: null,
 | 
					                projectId: null,
 | 
				
			||||||
                envId: null,
 | 
					                envId: null,
 | 
				
			||||||
@@ -109,6 +131,9 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        watch(props, async (newValue) => {
 | 
					        watch(props, async (newValue) => {
 | 
				
			||||||
            state.dialogVisible = newValue.visible;
 | 
					            state.dialogVisible = newValue.visible;
 | 
				
			||||||
 | 
					            if (!state.dialogVisible) {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            state.projects = newValue.projects;
 | 
					            state.projects = newValue.projects;
 | 
				
			||||||
            if (newValue.mongo) {
 | 
					            if (newValue.mongo) {
 | 
				
			||||||
                getEnvs(newValue.mongo.projectId);
 | 
					                getEnvs(newValue.mongo.projectId);
 | 
				
			||||||
@@ -117,8 +142,16 @@ export default defineComponent({
 | 
				
			|||||||
                state.envs = [];
 | 
					                state.envs = [];
 | 
				
			||||||
                state.form = { db: 0 } as any;
 | 
					                state.form = { db: 0 } as any;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            getSshTunnelMachines();
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getSshTunnelMachines = async () => {
 | 
				
			||||||
 | 
					            if (state.form.enableSshTunnel == 1 && state.sshTunnelMachineList.length == 0) {
 | 
				
			||||||
 | 
					                const res = await machineApi.list.request({ pageNum: 1, pageSize: 100 });
 | 
				
			||||||
 | 
					                state.sshTunnelMachineList = res.list;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const getEnvs = async (projectId: any) => {
 | 
					        const getEnvs = async (projectId: any) => {
 | 
				
			||||||
            state.envs = await projectApi.projectEnvs.request({ projectId });
 | 
					            state.envs = await projectApi.projectEnvs.request({ projectId });
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
@@ -144,9 +177,11 @@ export default defineComponent({
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const btnOk = async () => {
 | 
					        const btnOk = async () => {
 | 
				
			||||||
            mongoForm.value.validate((valid: boolean) => {
 | 
					            mongoForm.value.validate(async (valid: boolean) => {
 | 
				
			||||||
                if (valid) {
 | 
					                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('保存成功');
 | 
					                        ElMessage.success('保存成功');
 | 
				
			||||||
                        emit('val-change', state.form);
 | 
					                        emit('val-change', state.form);
 | 
				
			||||||
                        state.btnLoading = true;
 | 
					                        state.btnLoading = true;
 | 
				
			||||||
@@ -172,6 +207,7 @@ export default defineComponent({
 | 
				
			|||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
            mongoForm,
 | 
					            mongoForm,
 | 
				
			||||||
            changeProject,
 | 
					            changeProject,
 | 
				
			||||||
 | 
					            getSshTunnelMachines,
 | 
				
			||||||
            changeEnv,
 | 
					            changeEnv,
 | 
				
			||||||
            btnOk,
 | 
					            btnOk,
 | 
				
			||||||
            cancel,
 | 
					            cancel,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,7 @@
 | 
				
			|||||||
            <el-button type="primary" icon="edit" :disabled="currentId == null" @click="editMongo(false)" plain>编辑</el-button>
 | 
					            <el-button type="primary" icon="edit" :disabled="currentId == null" @click="editMongo(false)" plain>编辑</el-button>
 | 
				
			||||||
            <el-button type="danger" icon="delete" :disabled="currentId == null" @click="deleteMongo" plain>删除</el-button>
 | 
					            <el-button type="danger" icon="delete" :disabled="currentId == null" @click="deleteMongo" plain>删除</el-button>
 | 
				
			||||||
            <div style="float: right">
 | 
					            <div style="float: right">
 | 
				
			||||||
                <el-select v-model="query.projectId" placeholder="请选择项目" filterable clearable>
 | 
					                <el-select @focus="getProjects" v-model="query.projectId" placeholder="请选择项目" filterable clearable>
 | 
				
			||||||
                    <el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
 | 
					                    <el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
 | 
				
			||||||
                </el-select>
 | 
					                </el-select>
 | 
				
			||||||
                <el-button class="ml5" @click="search" type="success" icon="search"></el-button>
 | 
					                <el-button class="ml5" @click="search" type="success" icon="search"></el-button>
 | 
				
			||||||
@@ -250,7 +250,6 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        onMounted(async () => {
 | 
					        onMounted(async () => {
 | 
				
			||||||
            search();
 | 
					            search();
 | 
				
			||||||
            state.projects = await projectApi.accountProjects.request(null);
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const handlePageChange = (curPage: number) => {
 | 
					        const handlePageChange = (curPage: number) => {
 | 
				
			||||||
@@ -371,7 +370,12 @@ export default defineComponent({
 | 
				
			|||||||
            state.total = res.total;
 | 
					            state.total = res.total;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const editMongo = (isAdd = false) => {
 | 
					        const getProjects = async () => {
 | 
				
			||||||
 | 
					            state.projects = await projectApi.accountProjects.request(null);
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const editMongo = async (isAdd = false) => {
 | 
				
			||||||
 | 
					            await getProjects();
 | 
				
			||||||
            if (isAdd) {
 | 
					            if (isAdd) {
 | 
				
			||||||
                state.mongoEditDialog.data = null;
 | 
					                state.mongoEditDialog.data = null;
 | 
				
			||||||
                state.mongoEditDialog.title = '新增mongo';
 | 
					                state.mongoEditDialog.title = '新增mongo';
 | 
				
			||||||
@@ -390,6 +394,7 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
 | 
					            getProjects,
 | 
				
			||||||
            search,
 | 
					            search,
 | 
				
			||||||
            handlePageChange,
 | 
					            handlePageChange,
 | 
				
			||||||
            choose,
 | 
					            choose,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,7 +25,7 @@
 | 
				
			|||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
            <el-table :data="projects" @current-change="choose" ref="table" style="width: 100%">
 | 
					            <el-table :data="projects" @current-change="choose" ref="table" style="width: 100%">
 | 
				
			||||||
                <el-table-column label="选择" width="50px">
 | 
					                <el-table-column label="选择" width="55px">
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        <el-radio v-model="chooseId" :label="scope.row.id">
 | 
					                        <el-radio v-model="chooseId" :label="scope.row.id">
 | 
				
			||||||
                            <i></i>
 | 
					                            <i></i>
 | 
				
			||||||
@@ -80,9 +80,18 @@
 | 
				
			|||||||
        <el-dialog width="500px" :title="showEnvDialog.title" v-model="showEnvDialog.visible">
 | 
					        <el-dialog width="500px" :title="showEnvDialog.title" v-model="showEnvDialog.visible">
 | 
				
			||||||
            <div class="toolbar">
 | 
					            <div class="toolbar">
 | 
				
			||||||
                <el-button @click="showAddEnvDialog" v-auth="permissions.saveMember" type="primary" icon="plus">添加</el-button>
 | 
					                <el-button @click="showAddEnvDialog" v-auth="permissions.saveMember" type="primary" icon="plus">添加</el-button>
 | 
				
			||||||
                <!-- <el-button v-auth="'role:update'" :disabled="chooseId == null" type="danger" icon="delete">删除</el-button> -->
 | 
					                <el-button @click="deleteEnv" v-auth="permissions.delProject" :disabled="showEnvDialog.chooseId == null" type="danger" icon="delete"
 | 
				
			||||||
 | 
					                    >删除</el-button
 | 
				
			||||||
 | 
					                >
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
            <el-table border :data="showEnvDialog.envs">
 | 
					            <el-table @current-change="chooseEnv" border :data="showEnvDialog.envs">
 | 
				
			||||||
 | 
					                <el-table-column label="选择" width="50px">
 | 
				
			||||||
 | 
					                    <template #default="scope">
 | 
				
			||||||
 | 
					                        <el-radio v-model="showEnvDialog.chooseId" :label="scope.row.id">
 | 
				
			||||||
 | 
					                            <i></i>
 | 
				
			||||||
 | 
					                        </el-radio>
 | 
				
			||||||
 | 
					                    </template>
 | 
				
			||||||
 | 
					                </el-table-column>
 | 
				
			||||||
                <el-table-column property="name" label="环境名" width="125"></el-table-column>
 | 
					                <el-table-column property="name" label="环境名" width="125"></el-table-column>
 | 
				
			||||||
                <el-table-column property="remark" label="描述" width="125"></el-table-column>
 | 
					                <el-table-column property="remark" label="描述" width="125"></el-table-column>
 | 
				
			||||||
                <el-table-column property="createTime" label="创建时间">
 | 
					                <el-table-column property="createTime" label="创建时间">
 | 
				
			||||||
@@ -152,7 +161,7 @@
 | 
				
			|||||||
                            :remote-method="getAccount"
 | 
					                            :remote-method="getAccount"
 | 
				
			||||||
                            v-model="showMemDialog.memForm.accountId"
 | 
					                            v-model="showMemDialog.memForm.accountId"
 | 
				
			||||||
                            filterable
 | 
					                            filterable
 | 
				
			||||||
                            placeholder="请选择"
 | 
					                            placeholder="请输入账号模糊搜索并选择"
 | 
				
			||||||
                        >
 | 
					                        >
 | 
				
			||||||
                            <el-option v-for="item in showMemDialog.accounts" :key="item.id" :label="item.username" :value="item.id"> </el-option>
 | 
					                            <el-option v-for="item in showMemDialog.accounts" :key="item.id" :label="item.username" :value="item.id"> </el-option>
 | 
				
			||||||
                        </el-select>
 | 
					                        </el-select>
 | 
				
			||||||
@@ -207,6 +216,8 @@ export default defineComponent({
 | 
				
			|||||||
            },
 | 
					            },
 | 
				
			||||||
            showEnvDialog: {
 | 
					            showEnvDialog: {
 | 
				
			||||||
                visible: false,
 | 
					                visible: false,
 | 
				
			||||||
 | 
					                chooseId: null,
 | 
				
			||||||
 | 
					                chooseData: null,
 | 
				
			||||||
                envs: [],
 | 
					                envs: [],
 | 
				
			||||||
                title: '',
 | 
					                title: '',
 | 
				
			||||||
                addVisible: false,
 | 
					                addVisible: false,
 | 
				
			||||||
@@ -340,6 +351,21 @@ export default defineComponent({
 | 
				
			|||||||
            state.showEnvDialog.visible = true;
 | 
					            state.showEnvDialog.visible = true;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const chooseEnv = (item: any) => {
 | 
				
			||||||
 | 
					            if (!item) {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            state.showEnvDialog.chooseData = item;
 | 
				
			||||||
 | 
					            state.showEnvDialog.chooseId = item.id;
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const deleteEnv = async () => {
 | 
				
			||||||
 | 
					            notNull(state.showEnvDialog.chooseData, '请选选择环境');
 | 
				
			||||||
 | 
					            await projectApi.delProjectEnvs.request({ id: state.showEnvDialog.chooseId });
 | 
				
			||||||
 | 
					            ElMessage.success('删除成功');
 | 
				
			||||||
 | 
					            state.showEnvDialog.envs = await projectApi.projectEnvs.request({ projectId: state.chooseId });
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const showAddMemberDialog = () => {
 | 
					        const showAddMemberDialog = () => {
 | 
				
			||||||
            state.showMemDialog.addVisible = true;
 | 
					            state.showMemDialog.addVisible = true;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
@@ -398,12 +424,14 @@ export default defineComponent({
 | 
				
			|||||||
            showMembers,
 | 
					            showMembers,
 | 
				
			||||||
            setMemebers,
 | 
					            setMemebers,
 | 
				
			||||||
            showEnv,
 | 
					            showEnv,
 | 
				
			||||||
 | 
					            deleteEnv,
 | 
				
			||||||
            showAddMemberDialog,
 | 
					            showAddMemberDialog,
 | 
				
			||||||
            addMember,
 | 
					            addMember,
 | 
				
			||||||
            chooseMember,
 | 
					            chooseMember,
 | 
				
			||||||
            deleteMember,
 | 
					            deleteMember,
 | 
				
			||||||
            cancelAddMember,
 | 
					            cancelAddMember,
 | 
				
			||||||
            showAddEnvDialog,
 | 
					            showAddEnvDialog,
 | 
				
			||||||
 | 
					            chooseEnv,
 | 
				
			||||||
            addEnv,
 | 
					            addEnv,
 | 
				
			||||||
            cancelAddEnv,
 | 
					            cancelAddEnv,
 | 
				
			||||||
            getAccount,
 | 
					            getAccount,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,6 +8,7 @@ export const projectApi = {
 | 
				
			|||||||
    delProject: Api.create("/projects", 'delete'),
 | 
					    delProject: Api.create("/projects", 'delete'),
 | 
				
			||||||
    // 获取项目下的环境信息
 | 
					    // 获取项目下的环境信息
 | 
				
			||||||
    projectEnvs:  Api.create("/projects/{projectId}/envs", 'get'),
 | 
					    projectEnvs:  Api.create("/projects/{projectId}/envs", 'get'),
 | 
				
			||||||
 | 
					    delProjectEnvs:  Api.create("/projects/envs", 'delete'),
 | 
				
			||||||
    saveProjectEnv:  Api.create("/projects/{projectId}/envs", 'post'),
 | 
					    saveProjectEnv:  Api.create("/projects/{projectId}/envs", 'post'),
 | 
				
			||||||
    // 获取项目下的成员信息
 | 
					    // 获取项目下的成员信息
 | 
				
			||||||
    projectMems:  Api.create("/projects/{projectId}/members", 'get'),
 | 
					    projectMems:  Api.create("/projects/{projectId}/members", 'get'),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,313 +0,0 @@
 | 
				
			|||||||
<template>
 | 
					 | 
				
			||||||
    <el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :show-close="false" width="750px" :destroy-on-close="true">
 | 
					 | 
				
			||||||
        <el-form label-width="85px">
 | 
					 | 
				
			||||||
            <el-form-item prop="key" label="key:">
 | 
					 | 
				
			||||||
                <el-input :disabled="operationType == 2" v-model="key.key"></el-input>
 | 
					 | 
				
			||||||
            </el-form-item>
 | 
					 | 
				
			||||||
            <el-form-item prop="timed" label="过期时间:">
 | 
					 | 
				
			||||||
                <el-input v-model.number="key.timed" type="number"></el-input>
 | 
					 | 
				
			||||||
            </el-form-item>
 | 
					 | 
				
			||||||
            <el-form-item prop="dataType" label="数据类型:">
 | 
					 | 
				
			||||||
                <el-select :disabled="operationType == 2" style="width: 100%" v-model="key.type" placeholder="请选择数据类型">
 | 
					 | 
				
			||||||
                    <el-option key="string" label="string" value="string"> </el-option>
 | 
					 | 
				
			||||||
                    <el-option key="hash" label="hash" value="hash"> </el-option>
 | 
					 | 
				
			||||||
                    <el-option key="set" label="set" value="set"> </el-option>
 | 
					 | 
				
			||||||
                </el-select>
 | 
					 | 
				
			||||||
            </el-form-item>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            <el-form-item v-if="key.type == 'string'" prop="value" label="内容:">
 | 
					 | 
				
			||||||
                <div id="string-value-text" style="width: 100%">
 | 
					 | 
				
			||||||
                    <el-input class="json-text" v-model="string.value" type="textarea" :autosize="{ minRows: 10, maxRows: 20 }"></el-input>
 | 
					 | 
				
			||||||
                    <el-select class="text-type-select" @change="onChangeTextType" v-model="string.type">
 | 
					 | 
				
			||||||
                        <el-option key="text" label="text" value="text"> </el-option>
 | 
					 | 
				
			||||||
                        <el-option key="json" label="json" value="json"> </el-option>
 | 
					 | 
				
			||||||
                    </el-select>
 | 
					 | 
				
			||||||
                </div>
 | 
					 | 
				
			||||||
            </el-form-item>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            <span v-if="key.type == 'hash'">
 | 
					 | 
				
			||||||
                <el-button @click="onAddHashValue" icon="plus" size="small" plain class="mt10">添加</el-button>
 | 
					 | 
				
			||||||
                <el-table :data="hash.value" stripe style="width: 100%">
 | 
					 | 
				
			||||||
                    <el-table-column prop="key" label="key" width>
 | 
					 | 
				
			||||||
                        <template #default="scope">
 | 
					 | 
				
			||||||
                            <el-input v-model="scope.row.key" clearable size="small"></el-input>
 | 
					 | 
				
			||||||
                        </template>
 | 
					 | 
				
			||||||
                    </el-table-column>
 | 
					 | 
				
			||||||
                    <el-table-column prop="value" label="value" min-width="200">
 | 
					 | 
				
			||||||
                        <template #default="scope">
 | 
					 | 
				
			||||||
                            <el-input
 | 
					 | 
				
			||||||
                                v-model="scope.row.value"
 | 
					 | 
				
			||||||
                                clearable
 | 
					 | 
				
			||||||
                                type="textarea"
 | 
					 | 
				
			||||||
                                :autosize="{ minRows: 2, maxRows: 10 }"
 | 
					 | 
				
			||||||
                                size="small"
 | 
					 | 
				
			||||||
                            ></el-input>
 | 
					 | 
				
			||||||
                        </template>
 | 
					 | 
				
			||||||
                    </el-table-column>
 | 
					 | 
				
			||||||
                    <el-table-column label="操作" width="90">
 | 
					 | 
				
			||||||
                        <template #default="scope">
 | 
					 | 
				
			||||||
                            <el-button type="danger" @click="hash.value.splice(scope.$index, 1)" icon="delete" size="small" plain>删除</el-button>
 | 
					 | 
				
			||||||
                        </template>
 | 
					 | 
				
			||||||
                    </el-table-column>
 | 
					 | 
				
			||||||
                </el-table>
 | 
					 | 
				
			||||||
            </span>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            <span v-if="key.type == 'set'">
 | 
					 | 
				
			||||||
                <el-button @click="onAddSetValue" icon="plus" size="small" plain class="mt10">添加</el-button>
 | 
					 | 
				
			||||||
                <el-table :data="set.value" stripe style="width: 100%">
 | 
					 | 
				
			||||||
                    <el-table-column prop="value" label="value" min-width="200">
 | 
					 | 
				
			||||||
                        <template #default="scope">
 | 
					 | 
				
			||||||
                            <el-input
 | 
					 | 
				
			||||||
                                v-model="scope.row.value"
 | 
					 | 
				
			||||||
                                clearable
 | 
					 | 
				
			||||||
                                type="textarea"
 | 
					 | 
				
			||||||
                                :autosize="{ minRows: 2, maxRows: 10 }"
 | 
					 | 
				
			||||||
                                size="small"
 | 
					 | 
				
			||||||
                            ></el-input>
 | 
					 | 
				
			||||||
                        </template>
 | 
					 | 
				
			||||||
                    </el-table-column>
 | 
					 | 
				
			||||||
                    <el-table-column label="操作" width="90">
 | 
					 | 
				
			||||||
                        <template #default="scope">
 | 
					 | 
				
			||||||
                            <el-button type="danger" @click="set.value.splice(scope.$index, 1)" icon="delete" size="small" plain>删除</el-button>
 | 
					 | 
				
			||||||
                        </template>
 | 
					 | 
				
			||||||
                    </el-table-column>
 | 
					 | 
				
			||||||
                </el-table>
 | 
					 | 
				
			||||||
            </span>
 | 
					 | 
				
			||||||
        </el-form>
 | 
					 | 
				
			||||||
        <template #footer>
 | 
					 | 
				
			||||||
            <div class="dialog-footer">
 | 
					 | 
				
			||||||
                <el-button @click="cancel()">取 消</el-button>
 | 
					 | 
				
			||||||
                <el-button @click="saveValue" type="primary" v-auth="'redis:data:save'">确 定</el-button>
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
        </template>
 | 
					 | 
				
			||||||
    </el-dialog>
 | 
					 | 
				
			||||||
</template>
 | 
					 | 
				
			||||||
<script lang="ts">
 | 
					 | 
				
			||||||
import { defineComponent, reactive, watch, toRefs } from 'vue';
 | 
					 | 
				
			||||||
import { redisApi } from './api';
 | 
					 | 
				
			||||||
import { ElMessage } from 'element-plus';
 | 
					 | 
				
			||||||
import { isTrue, notEmpty } from '@/common/assert';
 | 
					 | 
				
			||||||
import { formatJsonString } from '@/common/utils/format';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export default defineComponent({
 | 
					 | 
				
			||||||
    name: 'DateEdit',
 | 
					 | 
				
			||||||
    components: {},
 | 
					 | 
				
			||||||
    props: {
 | 
					 | 
				
			||||||
        visible: {
 | 
					 | 
				
			||||||
            type: Boolean,
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        title: {
 | 
					 | 
				
			||||||
            type: String,
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        redisId: {
 | 
					 | 
				
			||||||
            type: [Number],
 | 
					 | 
				
			||||||
            require: true,
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        keyInfo: {
 | 
					 | 
				
			||||||
            type: [Object],
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        // 操作类型,1:新增,2:修改
 | 
					 | 
				
			||||||
        operationType: {
 | 
					 | 
				
			||||||
            type: [Number],
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        stringValue: {
 | 
					 | 
				
			||||||
            type: [String],
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        setValue: {
 | 
					 | 
				
			||||||
            type: [Array, Object],
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        hashValue: {
 | 
					 | 
				
			||||||
            type: [Array, Object],
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    emits: ['valChange', 'cancel', 'update:visible'],
 | 
					 | 
				
			||||||
    setup(props: any, { emit }) {
 | 
					 | 
				
			||||||
        const state = reactive({
 | 
					 | 
				
			||||||
            dialogVisible: false,
 | 
					 | 
				
			||||||
            operationType: 1,
 | 
					 | 
				
			||||||
            redisId: '',
 | 
					 | 
				
			||||||
            key: {
 | 
					 | 
				
			||||||
                key: '',
 | 
					 | 
				
			||||||
                type: 'string',
 | 
					 | 
				
			||||||
                timed: -1,
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            string: {
 | 
					 | 
				
			||||||
                type: 'text',
 | 
					 | 
				
			||||||
                value: '',
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            hash: {
 | 
					 | 
				
			||||||
                value: [
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        key: '',
 | 
					 | 
				
			||||||
                        value: '',
 | 
					 | 
				
			||||||
                    },
 | 
					 | 
				
			||||||
                ],
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            set: {
 | 
					 | 
				
			||||||
                value: [{ value: '' }],
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const cancel = () => {
 | 
					 | 
				
			||||||
            emit('update:visible', false);
 | 
					 | 
				
			||||||
            emit('cancel');
 | 
					 | 
				
			||||||
            setTimeout(() => {
 | 
					 | 
				
			||||||
                state.key = {
 | 
					 | 
				
			||||||
                    key: '',
 | 
					 | 
				
			||||||
                    type: 'string',
 | 
					 | 
				
			||||||
                    timed: -1,
 | 
					 | 
				
			||||||
                };
 | 
					 | 
				
			||||||
                state.string.value = '';
 | 
					 | 
				
			||||||
                state.string.type = 'text';
 | 
					 | 
				
			||||||
                state.hash.value = [
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        key: '',
 | 
					 | 
				
			||||||
                        value: '',
 | 
					 | 
				
			||||||
                    },
 | 
					 | 
				
			||||||
                ];
 | 
					 | 
				
			||||||
            }, 500);
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        watch(
 | 
					 | 
				
			||||||
            () => props.visible,
 | 
					 | 
				
			||||||
            (val) => {
 | 
					 | 
				
			||||||
                state.dialogVisible = val;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        watch(
 | 
					 | 
				
			||||||
            () => props.redisId,
 | 
					 | 
				
			||||||
            (val) => {
 | 
					 | 
				
			||||||
                state.redisId = val;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        watch(
 | 
					 | 
				
			||||||
            () => props.operationType,
 | 
					 | 
				
			||||||
            (val) => {
 | 
					 | 
				
			||||||
                state.operationType = val;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        watch(
 | 
					 | 
				
			||||||
            () => props.keyInfo,
 | 
					 | 
				
			||||||
            (val) => {
 | 
					 | 
				
			||||||
                if (val) {
 | 
					 | 
				
			||||||
                    state.key = { ...val };
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                deep: true, // 深度监听的参数
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        watch(
 | 
					 | 
				
			||||||
            () => props.stringValue,
 | 
					 | 
				
			||||||
            (val) => {
 | 
					 | 
				
			||||||
                if (val) {
 | 
					 | 
				
			||||||
                    state.string.value = val;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                deep: true, // 深度监听的参数
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        watch(
 | 
					 | 
				
			||||||
            () => props.setValue,
 | 
					 | 
				
			||||||
            (val) => {
 | 
					 | 
				
			||||||
                if (val) {
 | 
					 | 
				
			||||||
                    state.set.value = val;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                deep: true, // 深度监听的参数
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        watch(
 | 
					 | 
				
			||||||
            () => props.hashValue,
 | 
					 | 
				
			||||||
            (val) => {
 | 
					 | 
				
			||||||
                if (val) {
 | 
					 | 
				
			||||||
                    state.hash.value = val;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                deep: true, // 深度监听的参数
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const saveValue = async () => {
 | 
					 | 
				
			||||||
            notEmpty(state.key.key, 'key不能为空');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (state.key.type == 'string') {
 | 
					 | 
				
			||||||
                notEmpty(state.string.value, 'value不能为空');
 | 
					 | 
				
			||||||
                const sv = { value: formatJsonString(state.string.value, true), id: state.redisId };
 | 
					 | 
				
			||||||
                Object.assign(sv, state.key);
 | 
					 | 
				
			||||||
                await redisApi.saveStringValue.request(sv);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (state.key.type == 'hash') {
 | 
					 | 
				
			||||||
                isTrue(state.hash.value.length > 0, 'hash内容不能为空');
 | 
					 | 
				
			||||||
                const sv = { value: state.hash.value, id: state.redisId };
 | 
					 | 
				
			||||||
                Object.assign(sv, state.key);
 | 
					 | 
				
			||||||
                await redisApi.saveHashValue.request(sv);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (state.key.type == 'set') {
 | 
					 | 
				
			||||||
                isTrue(state.set.value.length > 0, 'set内容不能为空');
 | 
					 | 
				
			||||||
                const sv = { value: state.set.value.map((x) => x.value), id: state.redisId };
 | 
					 | 
				
			||||||
                Object.assign(sv, state.key);
 | 
					 | 
				
			||||||
                await redisApi.saveSetValue.request(sv);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            ElMessage.success('数据保存成功');
 | 
					 | 
				
			||||||
            cancel();
 | 
					 | 
				
			||||||
            emit('valChange');
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const onAddHashValue = () => {
 | 
					 | 
				
			||||||
            state.hash.value.push({ key: '', value: '' });
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const onAddSetValue = () => {
 | 
					 | 
				
			||||||
            state.set.value.push({ value: '' });
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // 更改文本类型
 | 
					 | 
				
			||||||
        const onChangeTextType = (val: string) => {
 | 
					 | 
				
			||||||
            if (val == 'json') {
 | 
					 | 
				
			||||||
                state.string.value = formatJsonString(state.string.value, false);
 | 
					 | 
				
			||||||
                return;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (val == 'text') {
 | 
					 | 
				
			||||||
                state.string.value = formatJsonString(state.string.value, true);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return {
 | 
					 | 
				
			||||||
            ...toRefs(state),
 | 
					 | 
				
			||||||
            saveValue,
 | 
					 | 
				
			||||||
            cancel,
 | 
					 | 
				
			||||||
            onAddHashValue,
 | 
					 | 
				
			||||||
            onAddSetValue,
 | 
					 | 
				
			||||||
            onChangeTextType,
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
</script>
 | 
					 | 
				
			||||||
<style lang="scss">
 | 
					 | 
				
			||||||
#string-value-text {
 | 
					 | 
				
			||||||
    flex-grow: 1;
 | 
					 | 
				
			||||||
    display: flex;
 | 
					 | 
				
			||||||
    position: relative;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    .text-type-select {
 | 
					 | 
				
			||||||
        position: absolute;
 | 
					 | 
				
			||||||
        z-index: 2;
 | 
					 | 
				
			||||||
        right: 10px;
 | 
					 | 
				
			||||||
        top: 10px;
 | 
					 | 
				
			||||||
        max-width: 70px;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
</style>
 | 
					 | 
				
			||||||
@@ -23,7 +23,7 @@
 | 
				
			|||||||
                        <el-form class="search-form" label-position="right" :inline="true" label-width="60px">
 | 
					                        <el-form class="search-form" label-position="right" :inline="true" label-width="60px">
 | 
				
			||||||
                            <el-form-item label="key" label-width="40px">
 | 
					                            <el-form-item label="key" label-width="40px">
 | 
				
			||||||
                                <el-input
 | 
					                                <el-input
 | 
				
			||||||
                                    placeholder="支持*模糊key"
 | 
					                                    placeholder="match 支持*模糊key"
 | 
				
			||||||
                                    style="width: 240px"
 | 
					                                    style="width: 240px"
 | 
				
			||||||
                                    v-model="scanParam.match"
 | 
					                                    v-model="scanParam.match"
 | 
				
			||||||
                                    @clear="clear()"
 | 
					                                    @clear="clear()"
 | 
				
			||||||
@@ -36,7 +36,15 @@
 | 
				
			|||||||
                            <el-form-item>
 | 
					                            <el-form-item>
 | 
				
			||||||
                                <el-button @click="searchKey()" type="success" icon="search" plain></el-button>
 | 
					                                <el-button @click="searchKey()" type="success" icon="search" plain></el-button>
 | 
				
			||||||
                                <el-button @click="scan()" icon="bottom" plain>scan</el-button>
 | 
					                                <el-button @click="scan()" icon="bottom" plain>scan</el-button>
 | 
				
			||||||
                                <el-button type="primary" icon="plus" @click="onAddData(false)" plain></el-button>
 | 
					                                <el-popover placement="right" :width="200" trigger="click">
 | 
				
			||||||
 | 
					                                    <template #reference>
 | 
				
			||||||
 | 
					                                        <el-button type="primary" icon="plus" plain></el-button>
 | 
				
			||||||
 | 
					                                    </template>
 | 
				
			||||||
 | 
					                                    <el-tag @click="onAddData('string')" :color="getTypeColor('string')" style="cursor: pointer">string</el-tag>
 | 
				
			||||||
 | 
					                                    <el-tag @click="onAddData('hash')" :color="getTypeColor('hash')" class="ml5" style="cursor: pointer">hash</el-tag>
 | 
				
			||||||
 | 
					                                    <el-tag @click="onAddData('set')" :color="getTypeColor('set')" class="ml5" style="cursor: pointer">set</el-tag>
 | 
				
			||||||
 | 
					                                    <!-- <el-tag @click="onAddData('list')" :color="getTypeColor('list')" class="ml5" style="cursor: pointer">list</el-tag> -->
 | 
				
			||||||
 | 
					                                </el-popover>
 | 
				
			||||||
                            </el-form-item>
 | 
					                            </el-form-item>
 | 
				
			||||||
                            <div style="float: right">
 | 
					                            <div style="float: right">
 | 
				
			||||||
                                <span>keys: {{ dbsize }}</span>
 | 
					                                <span>keys: {{ dbsize }}</span>
 | 
				
			||||||
@@ -69,17 +77,42 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        <div style="text-align: center; margin-top: 10px"></div>
 | 
					        <div style="text-align: center; margin-top: 10px"></div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <!-- <value-dialog v-model:visible="valueDialog.visible" :keyValue="valueDialog.value" /> -->
 | 
					        <hash-value
 | 
				
			||||||
 | 
					            v-model:visible="hashValueDialog.visible"
 | 
				
			||||||
 | 
					            :operationType="dataEdit.operationType"
 | 
				
			||||||
 | 
					            :title="dataEdit.title"
 | 
				
			||||||
 | 
					            :keyInfo="dataEdit.keyInfo"
 | 
				
			||||||
 | 
					            :redisId="scanParam.id"
 | 
				
			||||||
 | 
					            @cancel="onCancelDataEdit"
 | 
				
			||||||
 | 
					            @valChange="searchKey"
 | 
				
			||||||
 | 
					        />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <data-edit
 | 
					        <string-value
 | 
				
			||||||
            v-model:visible="dataEdit.visible"
 | 
					            v-model:visible="stringValueDialog.visible"
 | 
				
			||||||
 | 
					            :operationType="dataEdit.operationType"
 | 
				
			||||||
 | 
					            :title="dataEdit.title"
 | 
				
			||||||
 | 
					            :keyInfo="dataEdit.keyInfo"
 | 
				
			||||||
 | 
					            :redisId="scanParam.id"
 | 
				
			||||||
 | 
					            @cancel="onCancelDataEdit"
 | 
				
			||||||
 | 
					            @valChange="searchKey"
 | 
				
			||||||
 | 
					        />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <set-value
 | 
				
			||||||
 | 
					            v-model:visible="setValueDialog.visible"
 | 
				
			||||||
 | 
					            :title="dataEdit.title"
 | 
				
			||||||
 | 
					            :keyInfo="dataEdit.keyInfo"
 | 
				
			||||||
 | 
					            :redisId="scanParam.id"
 | 
				
			||||||
 | 
					            :operationType="dataEdit.operationType"
 | 
				
			||||||
 | 
					            @valChange="searchKey"
 | 
				
			||||||
 | 
					            @cancel="onCancelDataEdit"
 | 
				
			||||||
 | 
					        />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <list-value
 | 
				
			||||||
 | 
					            v-model:visible="listValueDialog.visible"
 | 
				
			||||||
            :title="dataEdit.title"
 | 
					            :title="dataEdit.title"
 | 
				
			||||||
            :keyInfo="dataEdit.keyInfo"
 | 
					            :keyInfo="dataEdit.keyInfo"
 | 
				
			||||||
            :redisId="scanParam.id"
 | 
					            :redisId="scanParam.id"
 | 
				
			||||||
            :operationType="dataEdit.operationType"
 | 
					            :operationType="dataEdit.operationType"
 | 
				
			||||||
            :stringValue="dataEdit.stringValue"
 | 
					 | 
				
			||||||
            :setValue="dataEdit.setValue"
 | 
					 | 
				
			||||||
            :hashValue="dataEdit.hashValue"
 | 
					 | 
				
			||||||
            @valChange="searchKey"
 | 
					            @valChange="searchKey"
 | 
				
			||||||
            @cancel="onCancelDataEdit"
 | 
					            @cancel="onCancelDataEdit"
 | 
				
			||||||
        />
 | 
					        />
 | 
				
			||||||
@@ -91,13 +124,19 @@ import { redisApi } from './api';
 | 
				
			|||||||
import { toRefs, reactive, defineComponent } from 'vue';
 | 
					import { toRefs, reactive, defineComponent } from 'vue';
 | 
				
			||||||
import { ElMessage, ElMessageBox } from 'element-plus';
 | 
					import { ElMessage, ElMessageBox } from 'element-plus';
 | 
				
			||||||
import ProjectEnvSelect from '../component/ProjectEnvSelect.vue';
 | 
					import ProjectEnvSelect from '../component/ProjectEnvSelect.vue';
 | 
				
			||||||
import DataEdit from './DataEdit.vue';
 | 
					import HashValue from './HashValue.vue';
 | 
				
			||||||
 | 
					import StringValue from './StringValue.vue';
 | 
				
			||||||
 | 
					import SetValue from './SetValue.vue';
 | 
				
			||||||
 | 
					import ListValue from './ListValue.vue';
 | 
				
			||||||
import { isTrue, notBlank, notNull } from '@/common/assert';
 | 
					import { isTrue, notBlank, notNull } from '@/common/assert';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'DataOperation',
 | 
					    name: 'DataOperation',
 | 
				
			||||||
    components: {
 | 
					    components: {
 | 
				
			||||||
        DataEdit,
 | 
					        StringValue,
 | 
				
			||||||
 | 
					        HashValue,
 | 
				
			||||||
 | 
					        SetValue,
 | 
				
			||||||
 | 
					        ListValue,
 | 
				
			||||||
        ProjectEnvSelect,
 | 
					        ProjectEnvSelect,
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    setup() {
 | 
					    setup() {
 | 
				
			||||||
@@ -113,10 +152,6 @@ export default defineComponent({
 | 
				
			|||||||
                count: 10,
 | 
					                count: 10,
 | 
				
			||||||
                cursor: {},
 | 
					                cursor: {},
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            valueDialog: {
 | 
					 | 
				
			||||||
                visible: false,
 | 
					 | 
				
			||||||
                value: {},
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            dataEdit: {
 | 
					            dataEdit: {
 | 
				
			||||||
                visible: false,
 | 
					                visible: false,
 | 
				
			||||||
                title: '新增数据',
 | 
					                title: '新增数据',
 | 
				
			||||||
@@ -126,9 +161,18 @@ export default defineComponent({
 | 
				
			|||||||
                    timed: -1,
 | 
					                    timed: -1,
 | 
				
			||||||
                    key: '',
 | 
					                    key: '',
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                stringValue: '',
 | 
					            },
 | 
				
			||||||
                hashValue: [{ key: '', value: '' }],
 | 
					            hashValueDialog: {
 | 
				
			||||||
                setValue: [{ value: '' }],
 | 
					                visible: false,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            stringValueDialog: {
 | 
				
			||||||
 | 
					                visible: false,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            setValueDialog: {
 | 
				
			||||||
 | 
					                visible: false,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            listValueDialog: {
 | 
				
			||||||
 | 
					                visible: false,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            keys: [],
 | 
					            keys: [],
 | 
				
			||||||
            dbsize: 0,
 | 
					            dbsize: 0,
 | 
				
			||||||
@@ -158,10 +202,15 @@ export default defineComponent({
 | 
				
			|||||||
        const scan = async () => {
 | 
					        const scan = async () => {
 | 
				
			||||||
            isTrue(state.scanParam.id != null, '请先选择redis');
 | 
					            isTrue(state.scanParam.id != null, '请先选择redis');
 | 
				
			||||||
            notBlank(state.scanParam.count, 'count不能为空');
 | 
					            notBlank(state.scanParam.count, 'count不能为空');
 | 
				
			||||||
            isTrue(state.scanParam.count < 20001, 'count不能超过20000');
 | 
					
 | 
				
			||||||
 | 
					            const match = state.scanParam.match;
 | 
				
			||||||
 | 
					            if (!match || match == '*') {
 | 
				
			||||||
 | 
					                isTrue(state.scanParam.count <= 200, 'match为空或者*时, count不能超过200');
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                isTrue(state.scanParam.count <= 20000, 'count不能超过20000');
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            state.loading = true;
 | 
					            state.loading = true;
 | 
				
			||||||
 | 
					 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                const res = await redisApi.scan.request(state.scanParam);
 | 
					                const res = await redisApi.scan.request(state.scanParam);
 | 
				
			||||||
                state.keys = res.keys;
 | 
					                state.keys = res.keys;
 | 
				
			||||||
@@ -207,60 +256,47 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        const getValue = async (row: any) => {
 | 
					        const getValue = async (row: any) => {
 | 
				
			||||||
            const type = row.type;
 | 
					            const type = row.type;
 | 
				
			||||||
            const key = row.key;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            let res: any;
 | 
					 | 
				
			||||||
            const reqParam = {
 | 
					 | 
				
			||||||
                key: row.key,
 | 
					 | 
				
			||||||
                id: state.scanParam.id,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
            switch (type) {
 | 
					 | 
				
			||||||
                case 'string':
 | 
					 | 
				
			||||||
                    res = await redisApi.getStringValue.request(reqParam);
 | 
					 | 
				
			||||||
                    break;
 | 
					 | 
				
			||||||
                case 'hash':
 | 
					 | 
				
			||||||
                    res = await redisApi.getHashValue.request(reqParam);
 | 
					 | 
				
			||||||
                    break;
 | 
					 | 
				
			||||||
                case 'set':
 | 
					 | 
				
			||||||
                    res = await redisApi.getSetValue.request(reqParam);
 | 
					 | 
				
			||||||
                    break;
 | 
					 | 
				
			||||||
                default:
 | 
					 | 
				
			||||||
                    res = null;
 | 
					 | 
				
			||||||
                    break;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            notNull(res, '暂不支持该类型数据查看');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (type == 'string') {
 | 
					 | 
				
			||||||
                state.dataEdit.stringValue = res;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (type == 'set') {
 | 
					 | 
				
			||||||
                state.dataEdit.setValue = res.map((x: any) => {
 | 
					 | 
				
			||||||
                    return {
 | 
					 | 
				
			||||||
                        value: x,
 | 
					 | 
				
			||||||
                    };
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (type == 'hash') {
 | 
					 | 
				
			||||||
                const hash = [];
 | 
					 | 
				
			||||||
                //遍历key和value
 | 
					 | 
				
			||||||
                const keys = Object.keys(res);
 | 
					 | 
				
			||||||
                for (let i = 0; i < keys.length; i++) {
 | 
					 | 
				
			||||||
                    const key = keys[i];
 | 
					 | 
				
			||||||
                    const value = res[key];
 | 
					 | 
				
			||||||
                    hash.push({
 | 
					 | 
				
			||||||
                        key,
 | 
					 | 
				
			||||||
                        value,
 | 
					 | 
				
			||||||
                    });
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                state.dataEdit.hashValue = hash;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            state.dataEdit.keyInfo.type = type;
 | 
					            state.dataEdit.keyInfo.type = type;
 | 
				
			||||||
            state.dataEdit.keyInfo.timed = row.ttl;
 | 
					            state.dataEdit.keyInfo.timed = row.ttl;
 | 
				
			||||||
            state.dataEdit.keyInfo.key = key;
 | 
					            state.dataEdit.keyInfo.key = row.key;
 | 
				
			||||||
            state.dataEdit.operationType = 2;
 | 
					            state.dataEdit.operationType = 2;
 | 
				
			||||||
            state.dataEdit.title = '修改数据';
 | 
					            state.dataEdit.title = '查看数据';
 | 
				
			||||||
            state.dataEdit.visible = true;
 | 
					
 | 
				
			||||||
 | 
					            if (type == 'hash') {
 | 
				
			||||||
 | 
					                state.hashValueDialog.visible = true;
 | 
				
			||||||
 | 
					            } else if (type == 'string') {
 | 
				
			||||||
 | 
					                state.stringValueDialog.visible = true;
 | 
				
			||||||
 | 
					            } else if (type == 'set') {
 | 
				
			||||||
 | 
					                state.setValueDialog.visible = true;
 | 
				
			||||||
 | 
					            } else if (type == 'list') {
 | 
				
			||||||
 | 
					                state.listValueDialog.visible = true;
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                ElMessage.warning('暂不支持该类型');
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const onAddData = (type: string) => {
 | 
				
			||||||
 | 
					            notNull(state.scanParam.id, '请先选择redis');
 | 
				
			||||||
 | 
					            state.dataEdit.operationType = 1;
 | 
				
			||||||
 | 
					            state.dataEdit.title = '新增数据';
 | 
				
			||||||
 | 
					            state.dataEdit.keyInfo.type = type;
 | 
				
			||||||
 | 
					            state.dataEdit.keyInfo.timed = -1;
 | 
				
			||||||
 | 
					            if (type == 'hash') {
 | 
				
			||||||
 | 
					                state.hashValueDialog.visible = true;
 | 
				
			||||||
 | 
					            } else if (type == 'string') {
 | 
				
			||||||
 | 
					                state.stringValueDialog.visible = true;
 | 
				
			||||||
 | 
					            } else if (type == 'set') {
 | 
				
			||||||
 | 
					                state.setValueDialog.visible = true;
 | 
				
			||||||
 | 
					            } else if (type == 'list') {
 | 
				
			||||||
 | 
					                state.listValueDialog.visible = true;
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                ElMessage.warning('暂不支持该类型');
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const onCancelDataEdit = () => {
 | 
				
			||||||
 | 
					            state.dataEdit.keyInfo = {} as any;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const del = (key: string) => {
 | 
					        const del = (key: string) => {
 | 
				
			||||||
@@ -331,20 +367,6 @@ export default defineComponent({
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const onAddData = () => {
 | 
					 | 
				
			||||||
            notNull(state.scanParam.id, '请先选择redis');
 | 
					 | 
				
			||||||
            state.dataEdit.operationType = 1;
 | 
					 | 
				
			||||||
            state.dataEdit.title = '新增数据';
 | 
					 | 
				
			||||||
            state.dataEdit.visible = true;
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const onCancelDataEdit = () => {
 | 
					 | 
				
			||||||
            state.dataEdit.keyInfo = {} as any;
 | 
					 | 
				
			||||||
            state.dataEdit.stringValue = '';
 | 
					 | 
				
			||||||
            state.dataEdit.setValue = [];
 | 
					 | 
				
			||||||
            state.dataEdit.hashValue = [];
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
            changeProjectEnv,
 | 
					            changeProjectEnv,
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										254
									
								
								mayfly_go_web/src/views/ops/redis/HashValue.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										254
									
								
								mayfly_go_web/src/views/ops/redis/HashValue.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,254 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					    <el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" width="800px" :destroy-on-close="true">
 | 
				
			||||||
 | 
					        <el-form label-width="85px">
 | 
				
			||||||
 | 
					            <el-form-item prop="key" label="key:">
 | 
				
			||||||
 | 
					                <el-input :disabled="operationType == 2" v-model="key.key"></el-input>
 | 
				
			||||||
 | 
					            </el-form-item>
 | 
				
			||||||
 | 
					            <el-form-item prop="timed" label="过期时间:">
 | 
				
			||||||
 | 
					                <el-input v-model.number="key.timed" type="number"></el-input>
 | 
				
			||||||
 | 
					            </el-form-item>
 | 
				
			||||||
 | 
					            <el-form-item prop="dataType" label="数据类型:">
 | 
				
			||||||
 | 
					                <el-input v-model="key.type" disabled></el-input>
 | 
				
			||||||
 | 
					            </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <el-row class="mt10">
 | 
				
			||||||
 | 
					                <el-form label-position="right" :inline="true">
 | 
				
			||||||
 | 
					                    <el-form-item label="field" label-width="40px" v-if="operationType == 2">
 | 
				
			||||||
 | 
					                        <el-input placeholder="支持*模糊field" style="width: 140px" v-model="scanParam.match" clearable size="small"></el-input>
 | 
				
			||||||
 | 
					                    </el-form-item>
 | 
				
			||||||
 | 
					                    <el-form-item label="count" v-if="operationType == 2">
 | 
				
			||||||
 | 
					                        <el-input placeholder="count" style="width: 62px" v-model.number="scanParam.count" size="small"></el-input>
 | 
				
			||||||
 | 
					                    </el-form-item>
 | 
				
			||||||
 | 
					                    <el-form-item>
 | 
				
			||||||
 | 
					                        <el-button v-if="operationType == 2" @click="reHscan()" type="success" icon="search" plain size="small"></el-button>
 | 
				
			||||||
 | 
					                        <el-button v-if="operationType == 2" @click="hscan()" icon="bottom" plain size="small">scan</el-button>
 | 
				
			||||||
 | 
					                        <el-button @click="onAddHashValue" icon="plus" size="small" plain>添加</el-button>
 | 
				
			||||||
 | 
					                    </el-form-item>
 | 
				
			||||||
 | 
					                    <div v-if="operationType == 2" class="mt10" style="float: right">
 | 
				
			||||||
 | 
					                        <span>fieldSize: {{ keySize }}</span>
 | 
				
			||||||
 | 
					                    </div>
 | 
				
			||||||
 | 
					                </el-form>
 | 
				
			||||||
 | 
					            </el-row>
 | 
				
			||||||
 | 
					            <el-table :data="hashValues" stripe style="width: 100%">
 | 
				
			||||||
 | 
					                <el-table-column prop="field" label="field" width>
 | 
				
			||||||
 | 
					                    <template #default="scope">
 | 
				
			||||||
 | 
					                        <el-input v-model="scope.row.field" clearable size="small"></el-input>
 | 
				
			||||||
 | 
					                    </template>
 | 
				
			||||||
 | 
					                </el-table-column>
 | 
				
			||||||
 | 
					                <el-table-column prop="value" label="value" min-width="200">
 | 
				
			||||||
 | 
					                    <template #default="scope">
 | 
				
			||||||
 | 
					                        <el-input v-model="scope.row.value" clearable type="textarea" :autosize="{ minRows: 2, maxRows: 10 }" size="small"></el-input>
 | 
				
			||||||
 | 
					                    </template>
 | 
				
			||||||
 | 
					                </el-table-column>
 | 
				
			||||||
 | 
					                <el-table-column label="操作" width="120">
 | 
				
			||||||
 | 
					                    <template #default="scope">
 | 
				
			||||||
 | 
					                        <el-button v-if="operationType == 2" type="success" @click="hset(scope.row)" icon="check" size="small" plain></el-button>
 | 
				
			||||||
 | 
					                        <el-button type="danger" @click="hdel(scope.row.field, scope.$index)" icon="delete" size="small" plain></el-button>
 | 
				
			||||||
 | 
					                    </template>
 | 
				
			||||||
 | 
					                </el-table-column>
 | 
				
			||||||
 | 
					            </el-table>
 | 
				
			||||||
 | 
					        </el-form>
 | 
				
			||||||
 | 
					        <template #footer v-if="operationType == 1">
 | 
				
			||||||
 | 
					            <div class="dialog-footer">
 | 
				
			||||||
 | 
					                <el-button @click="cancel()">取 消</el-button>
 | 
				
			||||||
 | 
					                <el-button @click="saveValue" type="primary" v-auth="'redis:data:save'">确 定</el-button>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					        </template>
 | 
				
			||||||
 | 
					    </el-dialog>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					<script lang="ts">
 | 
				
			||||||
 | 
					import { defineComponent, reactive, watch, toRefs } from 'vue';
 | 
				
			||||||
 | 
					import { redisApi } from './api';
 | 
				
			||||||
 | 
					import { ElMessage, ElMessageBox } from 'element-plus';
 | 
				
			||||||
 | 
					import { isTrue, notEmpty } from '@/common/assert';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default defineComponent({
 | 
				
			||||||
 | 
					    name: 'HashValue',
 | 
				
			||||||
 | 
					    components: {},
 | 
				
			||||||
 | 
					    props: {
 | 
				
			||||||
 | 
					        visible: {
 | 
				
			||||||
 | 
					            type: Boolean,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        title: {
 | 
				
			||||||
 | 
					            type: String,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        // 操作类型,1:新增,2:修改
 | 
				
			||||||
 | 
					        operationType: {
 | 
				
			||||||
 | 
					            type: [Number],
 | 
				
			||||||
 | 
					            require: true,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        redisId: {
 | 
				
			||||||
 | 
					            type: [Number],
 | 
				
			||||||
 | 
					            require: true,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        keyInfo: {
 | 
				
			||||||
 | 
					            type: [Object],
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        hashValue: {
 | 
				
			||||||
 | 
					            type: [Array, Object],
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    emits: ['valChange', 'cancel', 'update:visible'],
 | 
				
			||||||
 | 
					    setup(props: any, { emit }) {
 | 
				
			||||||
 | 
					        const state = reactive({
 | 
				
			||||||
 | 
					            dialogVisible: false,
 | 
				
			||||||
 | 
					            operationType: 1,
 | 
				
			||||||
 | 
					            redisId: 0,
 | 
				
			||||||
 | 
					            key: {
 | 
				
			||||||
 | 
					                key: '',
 | 
				
			||||||
 | 
					                type: 'hash',
 | 
				
			||||||
 | 
					                timed: -1,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            scanParam: {
 | 
				
			||||||
 | 
					                key: '',
 | 
				
			||||||
 | 
					                id: 0,
 | 
				
			||||||
 | 
					                cursor: 0,
 | 
				
			||||||
 | 
					                match: '',
 | 
				
			||||||
 | 
					                count: 10,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            keySize: 0,
 | 
				
			||||||
 | 
					            hashValues: [
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    field: '',
 | 
				
			||||||
 | 
					                    value: '',
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const cancel = () => {
 | 
				
			||||||
 | 
					            emit('update:visible', false);
 | 
				
			||||||
 | 
					            emit('cancel');
 | 
				
			||||||
 | 
					            setTimeout(() => {
 | 
				
			||||||
 | 
					                state.hashValues = [];
 | 
				
			||||||
 | 
					                state.key = {} as any;
 | 
				
			||||||
 | 
					            }, 500);
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        watch(props, async (newValue) => {
 | 
				
			||||||
 | 
					            const visible = newValue.visible;
 | 
				
			||||||
 | 
					            state.redisId = newValue.redisId;
 | 
				
			||||||
 | 
					            state.key = newValue.keyInfo;
 | 
				
			||||||
 | 
					            state.operationType = newValue.operationType;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (visible && state.operationType == 2) {
 | 
				
			||||||
 | 
					                state.scanParam.id = props.redisId;
 | 
				
			||||||
 | 
					                state.scanParam.key = state.key.key;
 | 
				
			||||||
 | 
					                await reHscan();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            state.dialogVisible = visible;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const reHscan = async () => {
 | 
				
			||||||
 | 
					            state.scanParam.id = state.redisId;
 | 
				
			||||||
 | 
					            state.scanParam.cursor = 0;
 | 
				
			||||||
 | 
					            hscan();
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const hscan = async () => {
 | 
				
			||||||
 | 
					            const match = state.scanParam.match;
 | 
				
			||||||
 | 
					            if (!match || match == '' || match == '*') {
 | 
				
			||||||
 | 
					                if (state.scanParam.count > 100) {
 | 
				
			||||||
 | 
					                    ElMessage.error('match为空或者*时, count不能超过100');
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                if (state.scanParam.count > 1000) {
 | 
				
			||||||
 | 
					                    ElMessage.error('count不能超过1000');
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            const scanRes = await redisApi.hscan.request(state.scanParam);
 | 
				
			||||||
 | 
					            state.scanParam.cursor = scanRes.cursor;
 | 
				
			||||||
 | 
					            state.keySize = scanRes.keySize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            const keys = scanRes.keys;
 | 
				
			||||||
 | 
					            const hashValue = [];
 | 
				
			||||||
 | 
					            const fieldCount = keys.length / 2;
 | 
				
			||||||
 | 
					            let nextFieldIndex = 0;
 | 
				
			||||||
 | 
					            for (let i = 0; i < fieldCount; i++) {
 | 
				
			||||||
 | 
					                hashValue.push({ field: keys[nextFieldIndex++], value: keys[nextFieldIndex++] });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            state.hashValues = hashValue;
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const hdel = async (field: any, index: any) => {
 | 
				
			||||||
 | 
					            // 如果是新增操作,则直接数组移除即可
 | 
				
			||||||
 | 
					            if (state.operationType == 1) {
 | 
				
			||||||
 | 
					                state.hashValues.splice(index, 1);
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            await ElMessageBox.confirm(`确定删除[${field}]?`, '提示', {
 | 
				
			||||||
 | 
					                confirmButtonText: '确定',
 | 
				
			||||||
 | 
					                cancelButtonText: '取消',
 | 
				
			||||||
 | 
					                type: 'warning',
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            await redisApi.hdel.request({
 | 
				
			||||||
 | 
					                id: state.redisId,
 | 
				
			||||||
 | 
					                key: state.key.key,
 | 
				
			||||||
 | 
					                field,
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            ElMessage.success('删除成功');
 | 
				
			||||||
 | 
					            reHscan();
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const hset = async (row: any) => {
 | 
				
			||||||
 | 
					            await redisApi.saveHashValue.request({
 | 
				
			||||||
 | 
					                id: state.redisId,
 | 
				
			||||||
 | 
					                key: state.key.key,
 | 
				
			||||||
 | 
					                timed: state.key.timed,
 | 
				
			||||||
 | 
					                value: [
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        field: row.field,
 | 
				
			||||||
 | 
					                        value: row.value,
 | 
				
			||||||
 | 
					                    },
 | 
				
			||||||
 | 
					                ],
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            ElMessage.success('保存成功');
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const onAddHashValue = () => {
 | 
				
			||||||
 | 
					            state.hashValues.unshift({ field: '', value: '' });
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const saveValue = async () => {
 | 
				
			||||||
 | 
					            notEmpty(state.key.key, 'key不能为空');
 | 
				
			||||||
 | 
					            isTrue(state.hashValues.length > 0, 'hash内容不能为空');
 | 
				
			||||||
 | 
					            const sv = { value: state.hashValues, id: state.redisId };
 | 
				
			||||||
 | 
					            Object.assign(sv, state.key);
 | 
				
			||||||
 | 
					            await redisApi.saveHashValue.request(sv);
 | 
				
			||||||
 | 
					            ElMessage.success('保存成功');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            cancel();
 | 
				
			||||||
 | 
					            emit('valChange');
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            ...toRefs(state),
 | 
				
			||||||
 | 
					            reHscan,
 | 
				
			||||||
 | 
					            hscan,
 | 
				
			||||||
 | 
					            cancel,
 | 
				
			||||||
 | 
					            hdel,
 | 
				
			||||||
 | 
					            hset,
 | 
				
			||||||
 | 
					            onAddHashValue,
 | 
				
			||||||
 | 
					            saveValue,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					<style lang="scss">
 | 
				
			||||||
 | 
					#string-value-text {
 | 
				
			||||||
 | 
					    flex-grow: 1;
 | 
				
			||||||
 | 
					    display: flex;
 | 
				
			||||||
 | 
					    position: relative;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .text-type-select {
 | 
				
			||||||
 | 
					        position: absolute;
 | 
				
			||||||
 | 
					        z-index: 2;
 | 
				
			||||||
 | 
					        right: 10px;
 | 
				
			||||||
 | 
					        top: 10px;
 | 
				
			||||||
 | 
					        max-width: 70px;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					</style>
 | 
				
			||||||
							
								
								
									
										205
									
								
								mayfly_go_web/src/views/ops/redis/ListValue.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										205
									
								
								mayfly_go_web/src/views/ops/redis/ListValue.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,205 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					    <el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" width="800px" :destroy-on-close="true">
 | 
				
			||||||
 | 
					        <el-form label-width="85px">
 | 
				
			||||||
 | 
					            <el-form-item prop="key" label="key:">
 | 
				
			||||||
 | 
					                <el-input :disabled="operationType == 2" v-model="key.key"></el-input>
 | 
				
			||||||
 | 
					            </el-form-item>
 | 
				
			||||||
 | 
					            <el-form-item prop="timed" label="过期时间:">
 | 
				
			||||||
 | 
					                <el-input v-model.number="key.timed" type="number"></el-input>
 | 
				
			||||||
 | 
					            </el-form-item>
 | 
				
			||||||
 | 
					            <el-form-item prop="dataType" label="数据类型:">
 | 
				
			||||||
 | 
					                <el-input v-model="key.type" disabled></el-input>
 | 
				
			||||||
 | 
					            </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <!-- <el-button @click="onAddListValue" icon="plus" size="small" plain class="mt10">添加</el-button> -->
 | 
				
			||||||
 | 
					            <div v-if="operationType == 2" class="mt10" style="float: left">
 | 
				
			||||||
 | 
					                <span>len: {{ len }}</span>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					            <el-table :data="value" stripe style="width: 100%">
 | 
				
			||||||
 | 
					                <el-table-column prop="value" label="value" min-width="200">
 | 
				
			||||||
 | 
					                    <template #default="scope">
 | 
				
			||||||
 | 
					                        <el-input v-model="scope.row.value" clearable type="textarea" :autosize="{ minRows: 2, maxRows: 10 }" size="small"></el-input>
 | 
				
			||||||
 | 
					                    </template>
 | 
				
			||||||
 | 
					                </el-table-column>
 | 
				
			||||||
 | 
					                <el-table-column label="操作" width="140">
 | 
				
			||||||
 | 
					                    <template #default="scope">
 | 
				
			||||||
 | 
					                        <el-button
 | 
				
			||||||
 | 
					                            v-if="operationType == 2"
 | 
				
			||||||
 | 
					                            type="success"
 | 
				
			||||||
 | 
					                            @click="lset(scope.row, scope.$index)"
 | 
				
			||||||
 | 
					                            icon="check"
 | 
				
			||||||
 | 
					                            size="small"
 | 
				
			||||||
 | 
					                            plain
 | 
				
			||||||
 | 
					                        ></el-button>
 | 
				
			||||||
 | 
					                        <!-- <el-button type="danger" @click="set.value.splice(scope.$index, 1)" icon="delete" size="small" plain></el-button> -->
 | 
				
			||||||
 | 
					                    </template>
 | 
				
			||||||
 | 
					                </el-table-column>
 | 
				
			||||||
 | 
					            </el-table>
 | 
				
			||||||
 | 
					            <el-row style="margin-top: 20px" type="flex" justify="end">
 | 
				
			||||||
 | 
					                <el-pagination
 | 
				
			||||||
 | 
					                    style="text-align: right"
 | 
				
			||||||
 | 
					                    :total="len"
 | 
				
			||||||
 | 
					                    layout="prev, pager, next, total"
 | 
				
			||||||
 | 
					                    @current-change="handlePageChange"
 | 
				
			||||||
 | 
					                    v-model:current-page="pageNum"
 | 
				
			||||||
 | 
					                    :page-size="pageSize"
 | 
				
			||||||
 | 
					                ></el-pagination>
 | 
				
			||||||
 | 
					            </el-row>
 | 
				
			||||||
 | 
					        </el-form>
 | 
				
			||||||
 | 
					        <!-- <template #footer>
 | 
				
			||||||
 | 
					            <div class="dialog-footer">
 | 
				
			||||||
 | 
					                <el-button @click="cancel()">取 消</el-button>
 | 
				
			||||||
 | 
					                <el-button @click="saveValue" type="primary" v-auth="'redis:data:save'">确 定</el-button>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					        </template> -->
 | 
				
			||||||
 | 
					    </el-dialog>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					<script lang="ts">
 | 
				
			||||||
 | 
					import { defineComponent, reactive, watch, toRefs } from 'vue';
 | 
				
			||||||
 | 
					import { redisApi } from './api';
 | 
				
			||||||
 | 
					import { ElMessage } from 'element-plus';
 | 
				
			||||||
 | 
					import { isTrue, notEmpty } from '@/common/assert';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default defineComponent({
 | 
				
			||||||
 | 
					    name: 'ListValue',
 | 
				
			||||||
 | 
					    components: {},
 | 
				
			||||||
 | 
					    props: {
 | 
				
			||||||
 | 
					        visible: {
 | 
				
			||||||
 | 
					            type: Boolean,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        title: {
 | 
				
			||||||
 | 
					            type: String,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        redisId: {
 | 
				
			||||||
 | 
					            type: [Number],
 | 
				
			||||||
 | 
					            require: true,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        keyInfo: {
 | 
				
			||||||
 | 
					            type: [Object],
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        // 操作类型,1:新增,2:修改
 | 
				
			||||||
 | 
					        operationType: {
 | 
				
			||||||
 | 
					            type: [Number],
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        listValue: {
 | 
				
			||||||
 | 
					            type: [Array, Object],
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    emits: ['valChange', 'cancel', 'update:visible'],
 | 
				
			||||||
 | 
					    setup(props: any, { emit }) {
 | 
				
			||||||
 | 
					        const state = reactive({
 | 
				
			||||||
 | 
					            dialogVisible: false,
 | 
				
			||||||
 | 
					            operationType: 1,
 | 
				
			||||||
 | 
					            redisId: '',
 | 
				
			||||||
 | 
					            key: {
 | 
				
			||||||
 | 
					                key: '',
 | 
				
			||||||
 | 
					                type: 'string',
 | 
				
			||||||
 | 
					                timed: -1,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            value: [{ value: '' }],
 | 
				
			||||||
 | 
					            len: 0,
 | 
				
			||||||
 | 
					            start: 0,
 | 
				
			||||||
 | 
					            stop: 0,
 | 
				
			||||||
 | 
					            pageNum: 1,
 | 
				
			||||||
 | 
					            pageSize: 10,
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const cancel = () => {
 | 
				
			||||||
 | 
					            emit('update:visible', false);
 | 
				
			||||||
 | 
					            emit('cancel');
 | 
				
			||||||
 | 
					            setTimeout(() => {
 | 
				
			||||||
 | 
					                state.key = {
 | 
				
			||||||
 | 
					                    key: '',
 | 
				
			||||||
 | 
					                    type: 'string',
 | 
				
			||||||
 | 
					                    timed: -1,
 | 
				
			||||||
 | 
					                };
 | 
				
			||||||
 | 
					                state.value = [];
 | 
				
			||||||
 | 
					            }, 500);
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        watch(props, async (newValue) => {
 | 
				
			||||||
 | 
					            state.dialogVisible = newValue.visible;
 | 
				
			||||||
 | 
					            state.key = newValue.key;
 | 
				
			||||||
 | 
					            state.redisId = newValue.redisId;
 | 
				
			||||||
 | 
					            state.key = newValue.keyInfo;
 | 
				
			||||||
 | 
					            state.operationType = newValue.operationType;
 | 
				
			||||||
 | 
					            // 如果是查看编辑操作,则获取值
 | 
				
			||||||
 | 
					            if (state.dialogVisible && state.operationType == 2) {
 | 
				
			||||||
 | 
					                getListValue();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getListValue = async () => {
 | 
				
			||||||
 | 
					            const pageNum = state.pageNum;
 | 
				
			||||||
 | 
					            const pageSize = state.pageSize;
 | 
				
			||||||
 | 
					            const res = await redisApi.getListValue.request({
 | 
				
			||||||
 | 
					                id: state.redisId,
 | 
				
			||||||
 | 
					                key: state.key.key,
 | 
				
			||||||
 | 
					                start: (pageNum - 1) * pageSize,
 | 
				
			||||||
 | 
					                stop: pageNum * pageSize - 1,
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            state.len = res.len;
 | 
				
			||||||
 | 
					            state.value = res.list.map((x: any) => {
 | 
				
			||||||
 | 
					                return {
 | 
				
			||||||
 | 
					                    value: x,
 | 
				
			||||||
 | 
					                };
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const lset = async (row: any, rowIndex: number) => {
 | 
				
			||||||
 | 
					            await redisApi.setListValue.request({
 | 
				
			||||||
 | 
					                id: state.redisId,
 | 
				
			||||||
 | 
					                key: state.key.key,
 | 
				
			||||||
 | 
					                index: (state.pageNum - 1) * state.pageSize + rowIndex,
 | 
				
			||||||
 | 
					                value: row.value,
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            ElMessage.success('数据保存成功');
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const saveValue = async () => {
 | 
				
			||||||
 | 
					            notEmpty(state.key.key, 'key不能为空');
 | 
				
			||||||
 | 
					            isTrue(state.value.length > 0, 'list内容不能为空');
 | 
				
			||||||
 | 
					            // const sv = { value: state.value.map((x) => x.value), id: state.redisId };
 | 
				
			||||||
 | 
					            // Object.assign(sv, state.key);
 | 
				
			||||||
 | 
					            // await redisApi.saveSetValue.request(sv);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            ElMessage.success('数据保存成功');
 | 
				
			||||||
 | 
					            cancel();
 | 
				
			||||||
 | 
					            emit('valChange');
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const onAddListValue = () => {
 | 
				
			||||||
 | 
					            state.value.unshift({ value: '' });
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const handlePageChange = (curPage: number) => {
 | 
				
			||||||
 | 
					            state.pageNum = curPage;
 | 
				
			||||||
 | 
					            getListValue();
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            ...toRefs(state),
 | 
				
			||||||
 | 
					            saveValue,
 | 
				
			||||||
 | 
					            handlePageChange,
 | 
				
			||||||
 | 
					            cancel,
 | 
				
			||||||
 | 
					            lset,
 | 
				
			||||||
 | 
					            onAddListValue,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					<style lang="scss">
 | 
				
			||||||
 | 
					#string-value-text {
 | 
				
			||||||
 | 
					    flex-grow: 1;
 | 
				
			||||||
 | 
					    display: flex;
 | 
				
			||||||
 | 
					    position: relative;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .text-type-select {
 | 
				
			||||||
 | 
					        position: absolute;
 | 
				
			||||||
 | 
					        z-index: 2;
 | 
				
			||||||
 | 
					        right: 10px;
 | 
				
			||||||
 | 
					        top: 10px;
 | 
				
			||||||
 | 
					        max-width: 70px;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					</style>
 | 
				
			||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
    <div>
 | 
					    <div>
 | 
				
			||||||
        <el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :close-on-click-modal="false" :destroy-on-close="true" width="35%">
 | 
					        <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="redisForm" :rules="rules" label-width="85px">
 | 
					            <el-form :model="form" ref="redisForm" :rules="rules" label-width="85px">
 | 
				
			||||||
                <el-form-item prop="projectId" label="项目:" required>
 | 
					                <el-form-item prop="projectId" label="项目:" required>
 | 
				
			||||||
                    <el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
 | 
					                    <el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
 | 
				
			||||||
@@ -17,19 +17,32 @@
 | 
				
			|||||||
                    <el-select style="width: 100%" v-model="form.mode" placeholder="请选择模式">
 | 
					                    <el-select style="width: 100%" v-model="form.mode" placeholder="请选择模式">
 | 
				
			||||||
                        <el-option label="standalone" value="standalone"> </el-option>
 | 
					                        <el-option label="standalone" value="standalone"> </el-option>
 | 
				
			||||||
                        <el-option label="cluster" value="cluster"> </el-option>
 | 
					                        <el-option label="cluster" value="cluster"> </el-option>
 | 
				
			||||||
 | 
					                        <el-option label="sentinel" value="sentinel"> </el-option>
 | 
				
			||||||
                    </el-select>
 | 
					                    </el-select>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="host" label="host:" required>
 | 
					                <el-form-item prop="host" label="host:" required>
 | 
				
			||||||
                    <el-input v-model.trim="form.host" placeholder="请输入host:port,集群模式用','分割" auto-complete="off" type="textarea"></el-input>
 | 
					                    <el-input
 | 
				
			||||||
 | 
					                        v-model.trim="form.host"
 | 
				
			||||||
 | 
					                        placeholder="请输入host:port;sentinel模式为: mastername=sentinelhost:port,若集群或哨兵需设多个节点可使用','分割"
 | 
				
			||||||
 | 
					                        auto-complete="off"
 | 
				
			||||||
 | 
					                        type="textarea"
 | 
				
			||||||
 | 
					                    ></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="password" label="密码:">
 | 
					                <el-form-item prop="password" label="密码:">
 | 
				
			||||||
                    <el-input
 | 
					                    <el-input
 | 
				
			||||||
                        type="password"
 | 
					                        type="password"
 | 
				
			||||||
                        show-password
 | 
					                        show-password
 | 
				
			||||||
                        v-model.trim="form.password"
 | 
					                        v-model.trim="form.password"
 | 
				
			||||||
                        placeholder="请输入密码"
 | 
					                        placeholder="请输入密码, 修改操作可不填"
 | 
				
			||||||
                        autocomplete="new-password"
 | 
					                        autocomplete="new-password"
 | 
				
			||||||
                    ></el-input>
 | 
					                        ><template v-if="form.id && form.id != 0" #suffix>
 | 
				
			||||||
 | 
					                            <el-popover @hide="pwd = ''" placement="right" title="原密码" :width="200" trigger="click" :content="pwd">
 | 
				
			||||||
 | 
					                                <template #reference>
 | 
				
			||||||
 | 
					                                    <el-link @click="getPwd" :underline="false" type="primary" class="mr5">原密码</el-link>
 | 
				
			||||||
 | 
					                                </template>
 | 
				
			||||||
 | 
					                            </el-popover>
 | 
				
			||||||
 | 
					                        </template></el-input
 | 
				
			||||||
 | 
					                    >
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="db" label="库号:" required>
 | 
					                <el-form-item prop="db" label="库号:" required>
 | 
				
			||||||
                    <el-input v-model.number="form.db" placeholder="请输入库号"></el-input>
 | 
					                    <el-input v-model.number="form.db" placeholder="请输入库号"></el-input>
 | 
				
			||||||
@@ -37,12 +50,29 @@
 | 
				
			|||||||
                <el-form-item prop="remark" label="备注:">
 | 
					                <el-form-item prop="remark" label="备注:">
 | 
				
			||||||
                    <el-input v-model.trim="form.remark" auto-complete="off" type="textarea"></el-input>
 | 
					                    <el-input v-model.trim="form.remark" auto-complete="off" type="textarea"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					                <el-form-item prop="enableSshTunnel" label="SSH隧道:">
 | 
				
			||||||
 | 
					                    <el-col :span="3">
 | 
				
			||||||
 | 
					                        <el-checkbox @change="getSshTunnelMachines" v-model="form.enableSshTunnel" :true-label="1" :false-label="-1"></el-checkbox>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
 | 
					                    <el-col :span="2" v-if="form.enableSshTunnel == 1"> 机器: </el-col>
 | 
				
			||||||
 | 
					                    <el-col :span="19" v-if="form.enableSshTunnel == 1">
 | 
				
			||||||
 | 
					                        <el-select style="width: 100%" v-model="form.sshTunnelMachineId" placeholder="请选择SSH隧道机器">
 | 
				
			||||||
 | 
					                            <el-option
 | 
				
			||||||
 | 
					                                v-for="item in sshTunnelMachineList"
 | 
				
			||||||
 | 
					                                :key="item.id"
 | 
				
			||||||
 | 
					                                :label="`${item.ip}:${item.port} [${item.name}]`"
 | 
				
			||||||
 | 
					                                :value="item.id"
 | 
				
			||||||
 | 
					                            >
 | 
				
			||||||
 | 
					                            </el-option>
 | 
				
			||||||
 | 
					                        </el-select>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
 | 
					                </el-form-item>
 | 
				
			||||||
            </el-form>
 | 
					            </el-form>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            <template #footer>
 | 
					            <template #footer>
 | 
				
			||||||
                <div class="dialog-footer">
 | 
					                <div class="dialog-footer">
 | 
				
			||||||
                    <el-button @click="cancel()">取 消</el-button>
 | 
					                    <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>
 | 
					                </div>
 | 
				
			||||||
            </template>
 | 
					            </template>
 | 
				
			||||||
        </el-dialog>
 | 
					        </el-dialog>
 | 
				
			||||||
@@ -53,7 +83,9 @@
 | 
				
			|||||||
import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
 | 
					import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
 | 
				
			||||||
import { redisApi } from './api';
 | 
					import { redisApi } from './api';
 | 
				
			||||||
import { projectApi } from '../project/api.ts';
 | 
					import { projectApi } from '../project/api.ts';
 | 
				
			||||||
 | 
					import { machineApi } from '../machine/api.ts';
 | 
				
			||||||
import { ElMessage } from 'element-plus';
 | 
					import { ElMessage } from 'element-plus';
 | 
				
			||||||
 | 
					import { RsaEncrypt } from '@/common/rsa';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'RedisEdit',
 | 
					    name: 'RedisEdit',
 | 
				
			||||||
@@ -77,18 +109,22 @@ export default defineComponent({
 | 
				
			|||||||
            dialogVisible: false,
 | 
					            dialogVisible: false,
 | 
				
			||||||
            projects: [],
 | 
					            projects: [],
 | 
				
			||||||
            envs: [],
 | 
					            envs: [],
 | 
				
			||||||
 | 
					            sshTunnelMachineList: [],
 | 
				
			||||||
            form: {
 | 
					            form: {
 | 
				
			||||||
                id: null,
 | 
					                id: null,
 | 
				
			||||||
                name: null,
 | 
					                name: null,
 | 
				
			||||||
                mode: "standalone",
 | 
					                mode: 'standalone',
 | 
				
			||||||
                host: null,
 | 
					                host: '',
 | 
				
			||||||
                password: null,
 | 
					                password: null,
 | 
				
			||||||
                project: null,
 | 
					                project: null,
 | 
				
			||||||
                projectId: null,
 | 
					                projectId: null,
 | 
				
			||||||
                envId: null,
 | 
					                envId: null,
 | 
				
			||||||
                env: null,
 | 
					                env: null,
 | 
				
			||||||
                remark: "",
 | 
					                remark: '',
 | 
				
			||||||
 | 
					                enableSshTunnel: null,
 | 
				
			||||||
 | 
					                sshTunnelMachineId: null,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
 | 
					            pwd: '',
 | 
				
			||||||
            btnLoading: false,
 | 
					            btnLoading: false,
 | 
				
			||||||
            rules: {
 | 
					            rules: {
 | 
				
			||||||
                projectId: [
 | 
					                projectId: [
 | 
				
			||||||
@@ -131,20 +167,35 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        watch(props, async (newValue) => {
 | 
					        watch(props, async (newValue) => {
 | 
				
			||||||
            state.dialogVisible = newValue.visible;
 | 
					            state.dialogVisible = newValue.visible;
 | 
				
			||||||
 | 
					            if (!state.dialogVisible) {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            state.projects = newValue.projects;
 | 
					            state.projects = newValue.projects;
 | 
				
			||||||
            if (newValue.redis) {
 | 
					            if (newValue.redis) {
 | 
				
			||||||
                getEnvs(newValue.redis.projectId);
 | 
					                getEnvs(newValue.redis.projectId);
 | 
				
			||||||
                state.form = { ...newValue.redis };
 | 
					                state.form = { ...newValue.redis };
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                state.envs = [];
 | 
					                state.envs = [];
 | 
				
			||||||
                state.form = { db: 0 } as any;
 | 
					                state.form = { db: 0, enableSshTunnel: -1 } as any;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            getSshTunnelMachines();
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getSshTunnelMachines = async () => {
 | 
				
			||||||
 | 
					            if (state.form.enableSshTunnel == 1 && state.sshTunnelMachineList.length == 0) {
 | 
				
			||||||
 | 
					                const res = await machineApi.list.request({ pageNum: 1, pageSize: 100 });
 | 
				
			||||||
 | 
					                state.sshTunnelMachineList = res.list;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const getEnvs = async (projectId: any) => {
 | 
					        const getEnvs = async (projectId: any) => {
 | 
				
			||||||
            state.envs = await projectApi.projectEnvs.request({ projectId });
 | 
					            state.envs = await projectApi.projectEnvs.request({ projectId });
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getPwd = async () => {
 | 
				
			||||||
 | 
					            state.pwd = await redisApi.getRedisPwd.request({ id: state.form.id });
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const changeProject = (projectId: number) => {
 | 
					        const changeProject = (projectId: number) => {
 | 
				
			||||||
            for (let p of state.projects as any) {
 | 
					            for (let p of state.projects as any) {
 | 
				
			||||||
                if (p.id == projectId) {
 | 
					                if (p.id == projectId) {
 | 
				
			||||||
@@ -166,9 +217,15 @@ export default defineComponent({
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const btnOk = async () => {
 | 
					        const btnOk = async () => {
 | 
				
			||||||
            redisForm.value.validate((valid: boolean) => {
 | 
					            redisForm.value.validate(async (valid: boolean) => {
 | 
				
			||||||
                if (valid) {
 | 
					                if (valid) {
 | 
				
			||||||
                    redisApi.saveRedis.request(state.form).then(() => {
 | 
					                    const reqForm = { ...state.form };
 | 
				
			||||||
 | 
					                    if (reqForm.mode == 'sentinel' && reqForm.host.split('=').length != 2) {
 | 
				
			||||||
 | 
					                        ElMessage.error('sentinel模式host需为: mastername=sentinelhost:sentinelport模式');
 | 
				
			||||||
 | 
					                        return;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    reqForm.password = await RsaEncrypt(reqForm.password);
 | 
				
			||||||
 | 
					                    redisApi.saveRedis.request(reqForm).then(() => {
 | 
				
			||||||
                        ElMessage.success('保存成功');
 | 
					                        ElMessage.success('保存成功');
 | 
				
			||||||
                        emit('val-change', state.form);
 | 
					                        emit('val-change', state.form);
 | 
				
			||||||
                        state.btnLoading = true;
 | 
					                        state.btnLoading = true;
 | 
				
			||||||
@@ -193,6 +250,8 @@ export default defineComponent({
 | 
				
			|||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
            redisForm,
 | 
					            redisForm,
 | 
				
			||||||
 | 
					            getSshTunnelMachines,
 | 
				
			||||||
 | 
					            getPwd,
 | 
				
			||||||
            changeProject,
 | 
					            changeProject,
 | 
				
			||||||
            changeEnv,
 | 
					            changeEnv,
 | 
				
			||||||
            btnOk,
 | 
					            btnOk,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,7 @@
 | 
				
			|||||||
            <el-button type="primary" icon="edit" :disabled="currentId == null" @click="editRedis(false)" plain>编辑</el-button>
 | 
					            <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>
 | 
					            <el-button type="danger" icon="delete" :disabled="currentId == null" @click="deleteRedis" plain>删除</el-button>
 | 
				
			||||||
            <div style="float: right">
 | 
					            <div style="float: right">
 | 
				
			||||||
                <el-select v-model="query.projectId" placeholder="请选择项目" filterable clearable>
 | 
					                <el-select @focus="getProjects" v-model="query.projectId" placeholder="请选择项目" filterable clearable>
 | 
				
			||||||
                    <el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
 | 
					                    <el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
 | 
				
			||||||
                </el-select>
 | 
					                </el-select>
 | 
				
			||||||
                <el-button class="ml5" @click="search" type="success" icon="search"></el-button>
 | 
					                <el-button class="ml5" @click="search" type="success" icon="search"></el-button>
 | 
				
			||||||
@@ -22,7 +22,7 @@
 | 
				
			|||||||
                <el-table-column prop="env" 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="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="mode" label="mode" min-width="100"></el-table-column>
 | 
				
			||||||
                <el-table-column prop="remark" label="备注" 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">
 | 
					                <el-table-column prop="createTime" label="创建时间" min-width="160">
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        {{ $filters.dateFormat(scope.row.createTime) }}
 | 
					                        {{ $filters.dateFormat(scope.row.createTime) }}
 | 
				
			||||||
@@ -31,7 +31,13 @@
 | 
				
			|||||||
                <el-table-column prop="creator" label="创建人" min-width="100"></el-table-column>
 | 
					                <el-table-column prop="creator" label="创建人" min-width="100"></el-table-column>
 | 
				
			||||||
                <el-table-column label="更多" min-width="130" fixed="right">
 | 
					                <el-table-column label="更多" min-width="130" fixed="right">
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        <el-link v-if="scope.row.mode == 'standalone'" type="primary" @click="info(scope.row)" :underline="false">单机信息</el-link>
 | 
					                        <el-link
 | 
				
			||||||
 | 
					                            v-if="scope.row.mode == 'standalone' || scope.row.mode == 'sentinel'"
 | 
				
			||||||
 | 
					                            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 @click="onShowClusterInfo(scope.row)" v-if="scope.row.mode == 'cluster'" type="success" :underline="false"
 | 
				
			||||||
                            >集群信息</el-link
 | 
					                            >集群信息</el-link
 | 
				
			||||||
                        >
 | 
					                        >
 | 
				
			||||||
@@ -202,7 +208,6 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        onMounted(async () => {
 | 
					        onMounted(async () => {
 | 
				
			||||||
            search();
 | 
					            search();
 | 
				
			||||||
            state.projects = await projectApi.accountProjects.request(null);
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const handlePageChange = (curPage: number) => {
 | 
					        const handlePageChange = (curPage: number) => {
 | 
				
			||||||
@@ -258,7 +263,12 @@ export default defineComponent({
 | 
				
			|||||||
            state.total = res.total;
 | 
					            state.total = res.total;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const editRedis = (isAdd = false) => {
 | 
					        const getProjects = async () => {
 | 
				
			||||||
 | 
					            state.projects = await projectApi.accountProjects.request(null);
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const editRedis = async (isAdd = false) => {
 | 
				
			||||||
 | 
					            await getProjects();
 | 
				
			||||||
            if (isAdd) {
 | 
					            if (isAdd) {
 | 
				
			||||||
                state.redisEditDialog.data = null;
 | 
					                state.redisEditDialog.data = null;
 | 
				
			||||||
                state.redisEditDialog.title = '新增redis';
 | 
					                state.redisEditDialog.title = '新增redis';
 | 
				
			||||||
@@ -277,6 +287,7 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
 | 
					            getProjects,
 | 
				
			||||||
            search,
 | 
					            search,
 | 
				
			||||||
            handlePageChange,
 | 
					            handlePageChange,
 | 
				
			||||||
            choose,
 | 
					            choose,
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										157
									
								
								mayfly_go_web/src/views/ops/redis/SetValue.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										157
									
								
								mayfly_go_web/src/views/ops/redis/SetValue.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,157 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					    <el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" width="800px" :destroy-on-close="true">
 | 
				
			||||||
 | 
					        <el-form label-width="85px">
 | 
				
			||||||
 | 
					            <el-form-item prop="key" label="key:">
 | 
				
			||||||
 | 
					                <el-input :disabled="operationType == 2" v-model="key.key"></el-input>
 | 
				
			||||||
 | 
					            </el-form-item>
 | 
				
			||||||
 | 
					            <el-form-item prop="timed" label="过期时间:">
 | 
				
			||||||
 | 
					                <el-input v-model.number="key.timed" type="number"></el-input>
 | 
				
			||||||
 | 
					            </el-form-item>
 | 
				
			||||||
 | 
					            <el-form-item prop="dataType" label="数据类型:">
 | 
				
			||||||
 | 
					                <el-input v-model="key.type" disabled></el-input>
 | 
				
			||||||
 | 
					            </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <el-button @click="onAddSetValue" icon="plus" size="small" plain class="mt10">添加</el-button>
 | 
				
			||||||
 | 
					            <el-table :data="value" stripe style="width: 100%">
 | 
				
			||||||
 | 
					                <el-table-column prop="value" label="value" min-width="200">
 | 
				
			||||||
 | 
					                    <template #default="scope">
 | 
				
			||||||
 | 
					                        <el-input v-model="scope.row.value" clearable type="textarea" :autosize="{ minRows: 2, maxRows: 10 }" size="small"></el-input>
 | 
				
			||||||
 | 
					                    </template>
 | 
				
			||||||
 | 
					                </el-table-column>
 | 
				
			||||||
 | 
					                <el-table-column label="操作" width="90">
 | 
				
			||||||
 | 
					                    <template #default="scope">
 | 
				
			||||||
 | 
					                        <el-button type="danger" @click="set.value.splice(scope.$index, 1)" icon="delete" size="small" plain>删除</el-button>
 | 
				
			||||||
 | 
					                    </template>
 | 
				
			||||||
 | 
					                </el-table-column>
 | 
				
			||||||
 | 
					            </el-table>
 | 
				
			||||||
 | 
					        </el-form>
 | 
				
			||||||
 | 
					        <template #footer>
 | 
				
			||||||
 | 
					            <div class="dialog-footer">
 | 
				
			||||||
 | 
					                <el-button @click="cancel()">取 消</el-button>
 | 
				
			||||||
 | 
					                <el-button @click="saveValue" type="primary" v-auth="'redis:data:save'">确 定</el-button>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					        </template>
 | 
				
			||||||
 | 
					    </el-dialog>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					<script lang="ts">
 | 
				
			||||||
 | 
					import { defineComponent, reactive, watch, toRefs } from 'vue';
 | 
				
			||||||
 | 
					import { redisApi } from './api';
 | 
				
			||||||
 | 
					import { ElMessage } from 'element-plus';
 | 
				
			||||||
 | 
					import { isTrue, notEmpty } from '@/common/assert';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default defineComponent({
 | 
				
			||||||
 | 
					    name: 'SetValue',
 | 
				
			||||||
 | 
					    components: {},
 | 
				
			||||||
 | 
					    props: {
 | 
				
			||||||
 | 
					        visible: {
 | 
				
			||||||
 | 
					            type: Boolean,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        title: {
 | 
				
			||||||
 | 
					            type: String,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        redisId: {
 | 
				
			||||||
 | 
					            type: [Number],
 | 
				
			||||||
 | 
					            require: true,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        keyInfo: {
 | 
				
			||||||
 | 
					            type: [Object],
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        // 操作类型,1:新增,2:修改
 | 
				
			||||||
 | 
					        operationType: {
 | 
				
			||||||
 | 
					            type: [Number],
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        setValue: {
 | 
				
			||||||
 | 
					            type: [Array, Object],
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    emits: ['valChange', 'cancel', 'update:visible'],
 | 
				
			||||||
 | 
					    setup(props: any, { emit }) {
 | 
				
			||||||
 | 
					        const state = reactive({
 | 
				
			||||||
 | 
					            dialogVisible: false,
 | 
				
			||||||
 | 
					            operationType: 1,
 | 
				
			||||||
 | 
					            redisId: '',
 | 
				
			||||||
 | 
					            key: {
 | 
				
			||||||
 | 
					                key: '',
 | 
				
			||||||
 | 
					                type: 'string',
 | 
				
			||||||
 | 
					                timed: -1,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            value: [{ value: '' }],
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const cancel = () => {
 | 
				
			||||||
 | 
					            emit('update:visible', false);
 | 
				
			||||||
 | 
					            emit('cancel');
 | 
				
			||||||
 | 
					            setTimeout(() => {
 | 
				
			||||||
 | 
					                state.key = {
 | 
				
			||||||
 | 
					                    key: '',
 | 
				
			||||||
 | 
					                    type: 'string',
 | 
				
			||||||
 | 
					                    timed: -1,
 | 
				
			||||||
 | 
					                };
 | 
				
			||||||
 | 
					                state.value = [];
 | 
				
			||||||
 | 
					            }, 500);
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        watch(props, async (newValue) => {
 | 
				
			||||||
 | 
					            state.dialogVisible = newValue.visible;
 | 
				
			||||||
 | 
					            state.key = newValue.key;
 | 
				
			||||||
 | 
					            state.redisId = newValue.redisId;
 | 
				
			||||||
 | 
					            state.key = newValue.keyInfo;
 | 
				
			||||||
 | 
					            state.operationType = newValue.operationType;
 | 
				
			||||||
 | 
					            // 如果是查看编辑操作,则获取值
 | 
				
			||||||
 | 
					            if (state.dialogVisible && state.operationType == 2) {
 | 
				
			||||||
 | 
					                getSetValue();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getSetValue = async () => {
 | 
				
			||||||
 | 
					            const res = await redisApi.getSetValue.request({
 | 
				
			||||||
 | 
					                id: state.redisId,
 | 
				
			||||||
 | 
					                key: state.key.key,
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            state.value = res.map((x: any) => {
 | 
				
			||||||
 | 
					                return {
 | 
				
			||||||
 | 
					                    value: x,
 | 
				
			||||||
 | 
					                };
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const saveValue = async () => {
 | 
				
			||||||
 | 
					            notEmpty(state.key.key, 'key不能为空');
 | 
				
			||||||
 | 
					            isTrue(state.value.length > 0, 'set内容不能为空');
 | 
				
			||||||
 | 
					            const sv = { value: state.value.map((x) => x.value), id: state.redisId };
 | 
				
			||||||
 | 
					            Object.assign(sv, state.key);
 | 
				
			||||||
 | 
					            await redisApi.saveSetValue.request(sv);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            ElMessage.success('数据保存成功');
 | 
				
			||||||
 | 
					            cancel();
 | 
				
			||||||
 | 
					            emit('valChange');
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const onAddSetValue = () => {
 | 
				
			||||||
 | 
					            state.value.unshift({ value: '' });
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            ...toRefs(state),
 | 
				
			||||||
 | 
					            saveValue,
 | 
				
			||||||
 | 
					            cancel,
 | 
				
			||||||
 | 
					            onAddSetValue,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					<style lang="scss">
 | 
				
			||||||
 | 
					#string-value-text {
 | 
				
			||||||
 | 
					    flex-grow: 1;
 | 
				
			||||||
 | 
					    display: flex;
 | 
				
			||||||
 | 
					    position: relative;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .text-type-select {
 | 
				
			||||||
 | 
					        position: absolute;
 | 
				
			||||||
 | 
					        z-index: 2;
 | 
				
			||||||
 | 
					        right: 10px;
 | 
				
			||||||
 | 
					        top: 10px;
 | 
				
			||||||
 | 
					        max-width: 70px;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					</style>
 | 
				
			||||||
							
								
								
									
										169
									
								
								mayfly_go_web/src/views/ops/redis/StringValue.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										169
									
								
								mayfly_go_web/src/views/ops/redis/StringValue.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,169 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					    <el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" width="800px" :destroy-on-close="true">
 | 
				
			||||||
 | 
					        <el-form label-width="85px">
 | 
				
			||||||
 | 
					            <el-form-item prop="key" label="key:">
 | 
				
			||||||
 | 
					                <el-input :disabled="operationType == 2" v-model="key.key"></el-input>
 | 
				
			||||||
 | 
					            </el-form-item>
 | 
				
			||||||
 | 
					            <el-form-item prop="timed" label="过期时间:">
 | 
				
			||||||
 | 
					                <el-input v-model.number="key.timed" type="number"></el-input>
 | 
				
			||||||
 | 
					            </el-form-item>
 | 
				
			||||||
 | 
					            <el-form-item prop="dataType" label="数据类型:">
 | 
				
			||||||
 | 
					                <el-input v-model="key.type" disabled></el-input>
 | 
				
			||||||
 | 
					            </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <div id="string-value-text" style="width: 100%">
 | 
				
			||||||
 | 
					                <el-input class="json-text" v-model="string.value" type="textarea" :autosize="{ minRows: 10, maxRows: 20 }"></el-input>
 | 
				
			||||||
 | 
					                <el-select class="text-type-select" @change="onChangeTextType" v-model="string.type">
 | 
				
			||||||
 | 
					                    <el-option key="text" label="text" value="text"> </el-option>
 | 
				
			||||||
 | 
					                    <el-option key="json" label="json" value="json"> </el-option>
 | 
				
			||||||
 | 
					                </el-select>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					        </el-form>
 | 
				
			||||||
 | 
					        <template #footer>
 | 
				
			||||||
 | 
					            <div class="dialog-footer">
 | 
				
			||||||
 | 
					                <el-button @click="cancel()">取 消</el-button>
 | 
				
			||||||
 | 
					                <el-button @click="saveValue" type="primary" v-auth="'redis:data:save'">确 定</el-button>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					        </template>
 | 
				
			||||||
 | 
					    </el-dialog>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					<script lang="ts">
 | 
				
			||||||
 | 
					import { defineComponent, reactive, watch, toRefs } from 'vue';
 | 
				
			||||||
 | 
					import { redisApi } from './api';
 | 
				
			||||||
 | 
					import { ElMessage } from 'element-plus';
 | 
				
			||||||
 | 
					import { notEmpty } from '@/common/assert';
 | 
				
			||||||
 | 
					import { formatJsonString } from '@/common/utils/format';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default defineComponent({
 | 
				
			||||||
 | 
					    name: 'StringValue',
 | 
				
			||||||
 | 
					    components: {},
 | 
				
			||||||
 | 
					    props: {
 | 
				
			||||||
 | 
					        visible: {
 | 
				
			||||||
 | 
					            type: Boolean,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        title: {
 | 
				
			||||||
 | 
					            type: String,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        redisId: {
 | 
				
			||||||
 | 
					            type: [Number],
 | 
				
			||||||
 | 
					            require: true,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        keyInfo: {
 | 
				
			||||||
 | 
					            type: [Object],
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        // 操作类型,1:新增,2:修改
 | 
				
			||||||
 | 
					        operationType: {
 | 
				
			||||||
 | 
					            type: [Number],
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    emits: ['valChange', 'cancel', 'update:visible'],
 | 
				
			||||||
 | 
					    setup(props: any, { emit }) {
 | 
				
			||||||
 | 
					        const state = reactive({
 | 
				
			||||||
 | 
					            dialogVisible: false,
 | 
				
			||||||
 | 
					            operationType: 1,
 | 
				
			||||||
 | 
					            redisId: '',
 | 
				
			||||||
 | 
					            key: {
 | 
				
			||||||
 | 
					                key: '',
 | 
				
			||||||
 | 
					                type: 'string',
 | 
				
			||||||
 | 
					                timed: -1,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            string: {
 | 
				
			||||||
 | 
					                type: 'text',
 | 
				
			||||||
 | 
					                value: '',
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const cancel = () => {
 | 
				
			||||||
 | 
					            emit('update:visible', false);
 | 
				
			||||||
 | 
					            emit('cancel');
 | 
				
			||||||
 | 
					            setTimeout(() => {
 | 
				
			||||||
 | 
					                state.key = {
 | 
				
			||||||
 | 
					                    key: '',
 | 
				
			||||||
 | 
					                    type: 'string',
 | 
				
			||||||
 | 
					                    timed: -1,
 | 
				
			||||||
 | 
					                };
 | 
				
			||||||
 | 
					                state.string.value = '';
 | 
				
			||||||
 | 
					                state.string.type = 'text';
 | 
				
			||||||
 | 
					            }, 500);
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        watch(
 | 
				
			||||||
 | 
					            () => props.visible,
 | 
				
			||||||
 | 
					            (val) => {
 | 
				
			||||||
 | 
					                state.dialogVisible = val;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        watch(
 | 
				
			||||||
 | 
					            () => props.redisId,
 | 
				
			||||||
 | 
					            (val) => {
 | 
				
			||||||
 | 
					                state.redisId = val;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        watch(props, async (newValue) => {
 | 
				
			||||||
 | 
					            state.dialogVisible = newValue.visible;
 | 
				
			||||||
 | 
					            state.key = newValue.key;
 | 
				
			||||||
 | 
					            state.redisId = newValue.redisId;
 | 
				
			||||||
 | 
					            state.key = newValue.keyInfo;
 | 
				
			||||||
 | 
					            state.operationType = newValue.operationType
 | 
				
			||||||
 | 
					            // 如果是查看编辑操作,则获取值
 | 
				
			||||||
 | 
					            if (state.dialogVisible && state.operationType == 2) {
 | 
				
			||||||
 | 
					                getStringValue();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getStringValue = async () => {
 | 
				
			||||||
 | 
					            state.string.value = await redisApi.getStringValue.request({
 | 
				
			||||||
 | 
					                id: state.redisId,
 | 
				
			||||||
 | 
					                key: state.key.key,
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const saveValue = async () => {
 | 
				
			||||||
 | 
					            notEmpty(state.key.key, 'key不能为空');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            notEmpty(state.string.value, 'value不能为空');
 | 
				
			||||||
 | 
					            const sv = { value: formatJsonString(state.string.value, true), id: state.redisId };
 | 
				
			||||||
 | 
					            Object.assign(sv, state.key);
 | 
				
			||||||
 | 
					            await redisApi.saveStringValue.request(sv);
 | 
				
			||||||
 | 
					            ElMessage.success('数据保存成功');
 | 
				
			||||||
 | 
					            cancel();
 | 
				
			||||||
 | 
					            emit('valChange');
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // 更改文本类型
 | 
				
			||||||
 | 
					        const onChangeTextType = (val: string) => {
 | 
				
			||||||
 | 
					            if (val == 'json') {
 | 
				
			||||||
 | 
					                state.string.value = formatJsonString(state.string.value, false);
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (val == 'text') {
 | 
				
			||||||
 | 
					                state.string.value = formatJsonString(state.string.value, true);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            ...toRefs(state),
 | 
				
			||||||
 | 
					            saveValue,
 | 
				
			||||||
 | 
					            cancel,
 | 
				
			||||||
 | 
					            onChangeTextType,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					<style lang="scss">
 | 
				
			||||||
 | 
					#string-value-text {
 | 
				
			||||||
 | 
					    flex-grow: 1;
 | 
				
			||||||
 | 
					    display: flex;
 | 
				
			||||||
 | 
					    position: relative;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .text-type-select {
 | 
				
			||||||
 | 
					        position: absolute;
 | 
				
			||||||
 | 
					        z-index: 2;
 | 
				
			||||||
 | 
					        right: 10px;
 | 
				
			||||||
 | 
					        top: 10px;
 | 
				
			||||||
 | 
					        max-width: 70px;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					</style>
 | 
				
			||||||
@@ -2,6 +2,7 @@ import Api from '@/common/Api';
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export const redisApi = {
 | 
					export const redisApi = {
 | 
				
			||||||
    redisList : Api.create("/redis", 'get'),
 | 
					    redisList : Api.create("/redis", 'get'),
 | 
				
			||||||
 | 
					    getRedisPwd: Api.create("/redis/{id}/pwd", 'get'),
 | 
				
			||||||
    redisInfo: Api.create("/redis/{id}/info", 'get'),
 | 
					    redisInfo: Api.create("/redis/{id}/info", 'get'),
 | 
				
			||||||
    clusterInfo: Api.create("/redis/{id}/cluster-info", 'get'),
 | 
					    clusterInfo: Api.create("/redis/{id}/cluster-info", 'get'),
 | 
				
			||||||
    saveRedis: Api.create("/redis", 'post'),
 | 
					    saveRedis: Api.create("/redis", 'post'),
 | 
				
			||||||
@@ -11,9 +12,15 @@ export const redisApi = {
 | 
				
			|||||||
    getStringValue: Api.create("/redis/{id}/string-value", 'get'),
 | 
					    getStringValue: Api.create("/redis/{id}/string-value", 'get'),
 | 
				
			||||||
    saveStringValue: Api.create("/redis/{id}/string-value", 'post'),
 | 
					    saveStringValue: Api.create("/redis/{id}/string-value", 'post'),
 | 
				
			||||||
    getHashValue: Api.create("/redis/{id}/hash-value", 'get'),
 | 
					    getHashValue: Api.create("/redis/{id}/hash-value", 'get'),
 | 
				
			||||||
 | 
					    hscan: Api.create("/redis/{id}/hscan", 'get'),
 | 
				
			||||||
 | 
					    hget: Api.create("/redis/{id}/hget", 'get'),
 | 
				
			||||||
 | 
					    hdel: Api.create("/redis/{id}/hdel", 'delete'),
 | 
				
			||||||
    saveHashValue: Api.create("/redis/{id}/hash-value", 'post'),
 | 
					    saveHashValue: Api.create("/redis/{id}/hash-value", 'post'),
 | 
				
			||||||
    getSetValue: Api.create("/redis/{id}/set-value", 'get'),
 | 
					    getSetValue: Api.create("/redis/{id}/set-value", 'get'),
 | 
				
			||||||
    saveSetValue: Api.create("/redis/{id}/set-value", 'post'),
 | 
					    saveSetValue: Api.create("/redis/{id}/set-value", 'post'),
 | 
				
			||||||
    del: Api.create("/redis/{id}/scan/{cursor}/{count}", 'delete'),
 | 
					    del: Api.create("/redis/{id}/scan/{cursor}/{count}", 'delete'),
 | 
				
			||||||
    delKey: Api.create("/redis/{id}/key", 'delete'),
 | 
					    delKey: Api.create("/redis/{id}/key", 'delete'),
 | 
				
			||||||
 | 
					    getListValue: Api.create("/redis/{id}/list-value", 'get'),
 | 
				
			||||||
 | 
					    saveListValue: Api.create("/redis/{id}/list-value", 'post'),
 | 
				
			||||||
 | 
					    setListValue: Api.create("/redis/{id}/list-value/lset", 'post'),
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -5,12 +5,9 @@
 | 
				
			|||||||
                <el-form-item prop="username" label="用户名:" required>
 | 
					                <el-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>
 | 
				
			||||||
                <!-- <el-form-item prop="password" label="密码:" required>
 | 
					                <el-form-item v-if="edit" prop="password" label="密码:" required>
 | 
				
			||||||
                    <el-input type="password" v-model.trim="form.password" placeholder="请输入密码" autocomplete="new-password"></el-input>
 | 
					                    <el-input type="password" v-model.trim="form.password" placeholder="请输入密码" autocomplete="new-password"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item v-if="!edit" label="确认密码:" required>
 | 
					 | 
				
			||||||
                    <el-input type="password" v-model.trim="form.repassword" placeholder="请输入确认密码" autocomplete="new-password"></el-input>
 | 
					 | 
				
			||||||
                </el-form-item> -->
 | 
					 | 
				
			||||||
            </el-form>
 | 
					            </el-form>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            <template #footer>
 | 
					            <template #footer>
 | 
				
			||||||
@@ -74,6 +71,7 @@ export default defineComponent({
 | 
				
			|||||||
        watch(props, (newValue) => {
 | 
					        watch(props, (newValue) => {
 | 
				
			||||||
            if (newValue.account) {
 | 
					            if (newValue.account) {
 | 
				
			||||||
                state.form = { ...newValue.account };
 | 
					                state.form = { ...newValue.account };
 | 
				
			||||||
 | 
					                state.edit = true;
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                state.form = {} as any;
 | 
					                state.form = {} as any;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -81,11 +79,9 @@ export default defineComponent({
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const btnOk = async () => {
 | 
					        const btnOk = async () => {
 | 
				
			||||||
            let p = state.form.id ? accountApi.update : accountApi.save;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            accountForm.value.validate((valid: boolean) => {
 | 
					            accountForm.value.validate((valid: boolean) => {
 | 
				
			||||||
                if (valid) {
 | 
					                if (valid) {
 | 
				
			||||||
                    p.request(state.form).then(() => {
 | 
					                    accountApi.save.request(state.form).then(() => {
 | 
				
			||||||
                        ElMessage.success('操作成功');
 | 
					                        ElMessage.success('操作成功');
 | 
				
			||||||
                        emit('val-change', state.form);
 | 
					                        emit('val-change', state.form);
 | 
				
			||||||
                        state.btnLoading = true;
 | 
					                        state.btnLoading = true;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,7 +2,7 @@
 | 
				
			|||||||
    <div class="role-list">
 | 
					    <div class="role-list">
 | 
				
			||||||
        <el-card>
 | 
					        <el-card>
 | 
				
			||||||
            <el-button v-auth="'account:add'" type="primary" icon="plus" @click="editAccount(true)">添加</el-button>
 | 
					            <el-button v-auth="'account:add'" type="primary" icon="plus" @click="editAccount(true)">添加</el-button>
 | 
				
			||||||
            <!-- <el-button v-auth="'account:update'" :disabled="chooseId == null" @click="editAccount(false)" type="primary" icon="edit">编辑</el-button> -->
 | 
					            <el-button v-auth="'account:add'" :disabled="chooseId == null" @click="editAccount(false)" type="primary" icon="edit">编辑</el-button>
 | 
				
			||||||
            <el-button v-auth="'account:saveRoles'" :disabled="chooseId == null" @click="roleEdit()" type="success" icon="setting"
 | 
					            <el-button v-auth="'account:saveRoles'" :disabled="chooseId == null" @click="roleEdit()" type="success" icon="setting"
 | 
				
			||||||
                >角色分配</el-button
 | 
					                >角色分配</el-button
 | 
				
			||||||
            >
 | 
					            >
 | 
				
			||||||
@@ -20,7 +20,7 @@
 | 
				
			|||||||
                <el-button @click="search()" type="success" icon="search" size="small"></el-button>
 | 
					                <el-button @click="search()" type="success" icon="search" size="small"></el-button>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
            <el-table :data="datas" ref="table" @current-change="choose" show-overflow-tooltip>
 | 
					            <el-table :data="datas" ref="table" @current-change="choose" show-overflow-tooltip>
 | 
				
			||||||
                <el-table-column label="选择" width="50px">
 | 
					                <el-table-column label="选择" width="55px">
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        <el-radio v-model="chooseId" :label="scope.row.id">
 | 
					                        <el-radio v-model="chooseId" :label="scope.row.id">
 | 
				
			||||||
                            <i></i>
 | 
					                            <i></i>
 | 
				
			||||||
@@ -29,20 +29,20 @@
 | 
				
			|||||||
                </el-table-column>
 | 
					                </el-table-column>
 | 
				
			||||||
                <el-table-column prop="username" label="用户名" min-width="115"></el-table-column>
 | 
					                <el-table-column prop="username" label="用户名" min-width="115"></el-table-column>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                <el-table-column align="center" prop="status" label="状态" min-width="63">
 | 
					                <el-table-column align="center" prop="status" label="状态" min-width="65">
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        <el-tag v-if="scope.row.status == 1" type="success">正常</el-tag>
 | 
					                        <el-tag v-if="scope.row.status == 1" type="success">正常</el-tag>
 | 
				
			||||||
                        <el-tag v-if="scope.row.status == -1" type="danger">禁用</el-tag>
 | 
					                        <el-tag v-if="scope.row.status == -1" type="danger">禁用</el-tag>
 | 
				
			||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
                </el-table-column>
 | 
					                </el-table-column>
 | 
				
			||||||
                <el-table-column min-width="160" prop="lastLoginTime" label="最后登录时间">
 | 
					                <el-table-column min-width="160" prop="lastLoginTime" label="最后登录时间" show-overflow-tooltip>
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        {{ $filters.dateFormat(scope.row.lastLoginTime) }}
 | 
					                        {{ $filters.dateFormat(scope.row.lastLoginTime) }}
 | 
				
			||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
                </el-table-column>
 | 
					                </el-table-column>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                <el-table-column min-width="115" prop="creator" label="创建账号"></el-table-column>
 | 
					                <el-table-column min-width="115" prop="creator" label="创建账号"></el-table-column>
 | 
				
			||||||
                <el-table-column min-width="160" prop="createTime" label="创建时间">
 | 
					                <el-table-column min-width="160" prop="createTime" label="创建时间" show-overflow-tooltip>
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        {{ $filters.dateFormat(scope.row.createTime) }}
 | 
					                        {{ $filters.dateFormat(scope.row.createTime) }}
 | 
				
			||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,6 +32,12 @@ export const accountApi = {
 | 
				
			|||||||
    saveRoles: Api.create("/sys/accounts/roles", 'post')
 | 
					    saveRoles: Api.create("/sys/accounts/roles", 'post')
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const configApi = {
 | 
				
			||||||
 | 
					    list: Api.create("/sys/configs", 'get'),
 | 
				
			||||||
 | 
					    save: Api.create("/sys/configs", 'post'),
 | 
				
			||||||
 | 
					    getValue: Api.create("/sys/configs/value", 'get'),
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const logApi = {
 | 
					export const logApi = {
 | 
				
			||||||
    list: Api.create("/syslogs", "get")
 | 
					    list: Api.create("/syslogs", "get")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										99
									
								
								mayfly_go_web/src/views/system/config/ConfigEdit.vue
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										99
									
								
								mayfly_go_web/src/views/system/config/ConfigEdit.vue
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,99 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					    <div>
 | 
				
			||||||
 | 
					        <el-dialog :title="title" v-model="dvisible" :show-close="false" :before-close="cancel" width="500px" :destroy-on-close="true">
 | 
				
			||||||
 | 
					            <el-form ref="configForm" :model="form" label-width="90px">
 | 
				
			||||||
 | 
					                <el-form-item prop="name" label="配置项:" required>
 | 
				
			||||||
 | 
					                    <el-input v-model="form.name"></el-input>
 | 
				
			||||||
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					                <el-form-item prop="key" label="配置key:" required>
 | 
				
			||||||
 | 
					                    <el-input :disabled="form.id != null" v-model="form.key"></el-input>
 | 
				
			||||||
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					                <el-form-item prop="value" label="配置值:" required>
 | 
				
			||||||
 | 
					                    <el-input v-model="form.value"></el-input>
 | 
				
			||||||
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					                <el-form-item label="备注:">
 | 
				
			||||||
 | 
					                    <el-input v-model="form.remark" type="textarea" :rows="2"></el-input>
 | 
				
			||||||
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					            </el-form>
 | 
				
			||||||
 | 
					            <template #footer>
 | 
				
			||||||
 | 
					                <div class="dialog-footer">
 | 
				
			||||||
 | 
					                    <el-button @click="cancel()">取 消</el-button>
 | 
				
			||||||
 | 
					                    <el-button type="primary" :loading="btnLoading" @click="btnOk">确 定</el-button>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					            </template>
 | 
				
			||||||
 | 
					        </el-dialog>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script lang="ts">
 | 
				
			||||||
 | 
					import { ref, toRefs, reactive, watch, defineComponent } from 'vue';
 | 
				
			||||||
 | 
					import { configApi } from '../api';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default defineComponent({
 | 
				
			||||||
 | 
					    name: 'ConfigEdit',
 | 
				
			||||||
 | 
					    props: {
 | 
				
			||||||
 | 
					        visible: {
 | 
				
			||||||
 | 
					            type: Boolean,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        data: {
 | 
				
			||||||
 | 
					            type: [Boolean, Object],
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        title: {
 | 
				
			||||||
 | 
					            type: String,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    setup(props: any, { emit }) {
 | 
				
			||||||
 | 
					        const configForm: any = ref(null);
 | 
				
			||||||
 | 
					        const state = reactive({
 | 
				
			||||||
 | 
					            dvisible: false,
 | 
				
			||||||
 | 
					            form: {
 | 
				
			||||||
 | 
					                id: null,
 | 
				
			||||||
 | 
					                name: '',
 | 
				
			||||||
 | 
					                key: '',
 | 
				
			||||||
 | 
					                value: '',
 | 
				
			||||||
 | 
					                remark: '',
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            btnLoading: false,
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        watch(props, (newValue) => {
 | 
				
			||||||
 | 
					            state.dvisible = newValue.visible;
 | 
				
			||||||
 | 
					            if (newValue.data) {
 | 
				
			||||||
 | 
					                state.form = { ...newValue.data };
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                state.form = {} as any;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const cancel = () => {
 | 
				
			||||||
 | 
					            // 更新父组件visible prop对应的值为false
 | 
				
			||||||
 | 
					            emit('update:visible', false);
 | 
				
			||||||
 | 
					            // 若父组件有取消事件,则调用
 | 
				
			||||||
 | 
					            emit('cancel');
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const btnOk = async () => {
 | 
				
			||||||
 | 
					            configForm.value.validate(async (valid: boolean) => {
 | 
				
			||||||
 | 
					                if (valid) {
 | 
				
			||||||
 | 
					                    await configApi.save.request(state.form);
 | 
				
			||||||
 | 
					                    emit('val-change', state.form);
 | 
				
			||||||
 | 
					                    cancel();
 | 
				
			||||||
 | 
					                    state.btnLoading = true;
 | 
				
			||||||
 | 
					                    setTimeout(() => {
 | 
				
			||||||
 | 
					                        state.btnLoading = false;
 | 
				
			||||||
 | 
					                    }, 1000);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            ...toRefs(state),
 | 
				
			||||||
 | 
					            configForm,
 | 
				
			||||||
 | 
					            btnOk,
 | 
				
			||||||
 | 
					            cancel,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					<style lang="scss">
 | 
				
			||||||
 | 
					</style>
 | 
				
			||||||
							
								
								
									
										124
									
								
								mayfly_go_web/src/views/system/config/ConfigList.vue
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										124
									
								
								mayfly_go_web/src/views/system/config/ConfigList.vue
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,124 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					    <div class="role-list">
 | 
				
			||||||
 | 
					        <el-card>
 | 
				
			||||||
 | 
					            <el-button type="primary" icon="plus" @click="editConfig(false)">添加</el-button>
 | 
				
			||||||
 | 
					            <el-button :disabled="chooseId == null" @click="editConfig(chooseData)" type="primary" icon="edit">编辑</el-button>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <el-table :data="configs" @current-change="choose" ref="table" style="width: 100%">
 | 
				
			||||||
 | 
					                <el-table-column label="选择" width="55px">
 | 
				
			||||||
 | 
					                    <template #default="scope">
 | 
				
			||||||
 | 
					                        <el-radio v-model="chooseId" :label="scope.row.id">
 | 
				
			||||||
 | 
					                            <i></i>
 | 
				
			||||||
 | 
					                        </el-radio>
 | 
				
			||||||
 | 
					                    </template>
 | 
				
			||||||
 | 
					                </el-table-column>
 | 
				
			||||||
 | 
					                <el-table-column prop="name" label="配置项"></el-table-column>
 | 
				
			||||||
 | 
					                <el-table-column prop="key" label="配置key"></el-table-column>
 | 
				
			||||||
 | 
					                <el-table-column prop="value" label="配置值" min-width="100px" show-overflow-tooltip></el-table-column>
 | 
				
			||||||
 | 
					                <el-table-column prop="remark" label="备注" min-width="100px" show-overflow-tooltip></el-table-column>
 | 
				
			||||||
 | 
					                <el-table-column prop="updateTime" label="更新时间">
 | 
				
			||||||
 | 
					                    <template #default="scope">
 | 
				
			||||||
 | 
					                        {{ $filters.dateFormat(scope.row.createTime) }}
 | 
				
			||||||
 | 
					                    </template>
 | 
				
			||||||
 | 
					                </el-table-column>
 | 
				
			||||||
 | 
					                <el-table-column prop="modifier" label="修改者" show-overflow-tooltip></el-table-column>
 | 
				
			||||||
 | 
					            </el-table>
 | 
				
			||||||
 | 
					            <el-row style="margin-top: 20px" type="flex" justify="end">
 | 
				
			||||||
 | 
					                <el-pagination
 | 
				
			||||||
 | 
					                    style="text-align: right"
 | 
				
			||||||
 | 
					                    @current-change="handlePageChange"
 | 
				
			||||||
 | 
					                    :total="total"
 | 
				
			||||||
 | 
					                    layout="prev, pager, next, total, jumper"
 | 
				
			||||||
 | 
					                    v-model:current-page="query.pageNum"
 | 
				
			||||||
 | 
					                    :page-size="query.pageSize"
 | 
				
			||||||
 | 
					                ></el-pagination>
 | 
				
			||||||
 | 
					            </el-row>
 | 
				
			||||||
 | 
					        </el-card>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <config-edit :title="configEdit.title" v-model:visible="configEdit.visible" :data="configEdit.config" @val-change="configEditChange" />
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script lang="ts">
 | 
				
			||||||
 | 
					import { toRefs, reactive, onMounted, defineComponent } from 'vue';
 | 
				
			||||||
 | 
					import ConfigEdit from './ConfigEdit.vue';
 | 
				
			||||||
 | 
					import { configApi } from '../api';
 | 
				
			||||||
 | 
					import { ElMessage, ElMessageBox } from 'element-plus';
 | 
				
			||||||
 | 
					export default defineComponent({
 | 
				
			||||||
 | 
					    name: 'ConfigList',
 | 
				
			||||||
 | 
					    components: {
 | 
				
			||||||
 | 
					        ConfigEdit,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    setup() {
 | 
				
			||||||
 | 
					        const state = reactive({
 | 
				
			||||||
 | 
					            dialogFormVisible: false,
 | 
				
			||||||
 | 
					            currentEditPermissions: false,
 | 
				
			||||||
 | 
					            query: {
 | 
				
			||||||
 | 
					                pageNum: 1,
 | 
				
			||||||
 | 
					                pageSize: 10,
 | 
				
			||||||
 | 
					                name: null,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            total: 0,
 | 
				
			||||||
 | 
					            configs: [],
 | 
				
			||||||
 | 
					            chooseId: null,
 | 
				
			||||||
 | 
					            chooseData: null,
 | 
				
			||||||
 | 
					            configEdit: {
 | 
				
			||||||
 | 
					                title: '配置修改',
 | 
				
			||||||
 | 
					                visible: false,
 | 
				
			||||||
 | 
					                config: {},
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        onMounted(() => {
 | 
				
			||||||
 | 
					            search();
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const search = async () => {
 | 
				
			||||||
 | 
					            let res = await configApi.list.request(state.query);
 | 
				
			||||||
 | 
					            state.configs = res.list;
 | 
				
			||||||
 | 
					            state.total = res.total;
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const handlePageChange = (curPage: number) => {
 | 
				
			||||||
 | 
					            state.query.pageNum = curPage;
 | 
				
			||||||
 | 
					            search();
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const choose = (item: any) => {
 | 
				
			||||||
 | 
					            if (!item) {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            state.chooseId = item.id;
 | 
				
			||||||
 | 
					            state.chooseData = item;
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const configEditChange = () => {
 | 
				
			||||||
 | 
					            ElMessage.success('修改成功!');
 | 
				
			||||||
 | 
					            state.chooseId = null;
 | 
				
			||||||
 | 
					            state.chooseData = null;
 | 
				
			||||||
 | 
					            search();
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const editConfig = (data: any) => {
 | 
				
			||||||
 | 
					            if (data) {
 | 
				
			||||||
 | 
					                state.configEdit.config = data;
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                state.configEdit.config = false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            state.configEdit.visible = true;
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            ...toRefs(state),
 | 
				
			||||||
 | 
					            search,
 | 
				
			||||||
 | 
					            handlePageChange,
 | 
				
			||||||
 | 
					            choose,
 | 
				
			||||||
 | 
					            configEditChange,
 | 
				
			||||||
 | 
					            editConfig,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					<style lang="scss">
 | 
				
			||||||
 | 
					</style>
 | 
				
			||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
    <div class="role-dialog">
 | 
					    <div class="role-dialog">
 | 
				
			||||||
        <el-dialog :title="title" v-model="dvisible" :show-close="false" :before-close="cancel" width="500px" :destroy-on-close="true">
 | 
					        <el-dialog :title="title" v-model="dvisible" :show-close="false" :before-close="cancel" width="500px" :destroy-on-close="true">
 | 
				
			||||||
            <el-form :model="form" label-width="90px">
 | 
					            <el-form ref="roleForm" :model="form" label-width="90px">
 | 
				
			||||||
                <el-form-item prop="name" label="角色名称:" required>
 | 
					                <el-form-item prop="name" label="角色名称:" required>
 | 
				
			||||||
                    <el-input v-model="form.name" auto-complete="off"></el-input>
 | 
					                    <el-input v-model="form.name" auto-complete="off"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
@@ -28,7 +28,7 @@
 | 
				
			|||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script lang="ts">
 | 
					<script lang="ts">
 | 
				
			||||||
import { toRefs, reactive, watch, defineComponent } from 'vue';
 | 
					import { ref, toRefs, reactive, watch, defineComponent } from 'vue';
 | 
				
			||||||
import { roleApi } from '../api';
 | 
					import { roleApi } from '../api';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
@@ -45,6 +45,7 @@ export default defineComponent({
 | 
				
			|||||||
        },
 | 
					        },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    setup(props: any, { emit }) {
 | 
					    setup(props: any, { emit }) {
 | 
				
			||||||
 | 
					        const roleForm: any = ref(null);
 | 
				
			||||||
        const state = reactive({
 | 
					        const state = reactive({
 | 
				
			||||||
            dvisible: false,
 | 
					            dvisible: false,
 | 
				
			||||||
            form: {
 | 
					            form: {
 | 
				
			||||||
@@ -73,18 +74,22 @@ export default defineComponent({
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const btnOk = async () => {
 | 
					        const btnOk = async () => {
 | 
				
			||||||
            // let p = state.form.id ? roleApi.update : roleApi.save;
 | 
					            roleForm.value.validate(async (valid: boolean) => {
 | 
				
			||||||
            await roleApi.save.request(state.form);
 | 
					                if (valid) {
 | 
				
			||||||
            emit('val-change', state.form);
 | 
					                    await roleApi.save.request(state.form);
 | 
				
			||||||
            cancel();
 | 
					                    emit('val-change', state.form);
 | 
				
			||||||
            state.btnLoading = true;
 | 
					                    cancel();
 | 
				
			||||||
            setTimeout(() => {
 | 
					                    state.btnLoading = true;
 | 
				
			||||||
                state.btnLoading = false;
 | 
					                    setTimeout(() => {
 | 
				
			||||||
            }, 1000);
 | 
					                        state.btnLoading = false;
 | 
				
			||||||
 | 
					                    }, 1000);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
 | 
					            roleForm,
 | 
				
			||||||
            btnOk,
 | 
					            btnOk,
 | 
				
			||||||
            cancel,
 | 
					            cancel,
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,7 @@
 | 
				
			|||||||
                <el-button @click="search" type="success" icon="search"></el-button>
 | 
					                <el-button @click="search" type="success" icon="search"></el-button>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
            <el-table :data="roles" @current-change="choose" ref="table" style="width: 100%">
 | 
					            <el-table :data="roles" @current-change="choose" ref="table" style="width: 100%">
 | 
				
			||||||
                <el-table-column label="选择" width="50px">
 | 
					                <el-table-column label="选择" width="55px">
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        <el-radio v-model="chooseId" :label="scope.row.id">
 | 
					                        <el-radio v-model="chooseId" :label="scope.row.id">
 | 
				
			||||||
                            <i></i>
 | 
					                            <i></i>
 | 
				
			||||||
 
 | 
				
			|||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -1,7 +1,3 @@
 | 
				
			|||||||
app:
 | 
					 | 
				
			||||||
  name: mayfly-go
 | 
					 | 
				
			||||||
  version: 1.2.0
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
server:
 | 
					server:
 | 
				
			||||||
  # debug release test
 | 
					  # debug release test
 | 
				
			||||||
  model: release
 | 
					  model: release
 | 
				
			||||||
@@ -11,24 +7,16 @@ server:
 | 
				
			|||||||
    enable: false
 | 
					    enable: false
 | 
				
			||||||
    key-file: ./default.key
 | 
					    key-file: ./default.key
 | 
				
			||||||
    cert-file: ./default.pem
 | 
					    cert-file: ./default.pem
 | 
				
			||||||
  # 静态资源
 | 
					  # 机器终端操作回放文件存储路径
 | 
				
			||||||
  static:
 | 
					  machine-rec-path: ./rec
 | 
				
			||||||
    - relative-path: /assets
 | 
					 | 
				
			||||||
      root: ./static/assets
 | 
					 | 
				
			||||||
  # 静态文件
 | 
					 | 
				
			||||||
  static-file:
 | 
					 | 
				
			||||||
    - relative-path: /
 | 
					 | 
				
			||||||
      filepath: ./static/index.html
 | 
					 | 
				
			||||||
    - relative-path: /favicon.ico
 | 
					 | 
				
			||||||
      filepath: ./static/favicon.ico
 | 
					 | 
				
			||||||
    - relative-path: /config.js
 | 
					 | 
				
			||||||
      filepath: ./static/config.js
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
jwt:
 | 
					jwt:
 | 
				
			||||||
  key: mykey
 | 
					  # jwt key,不设置默认使用随机字符串
 | 
				
			||||||
 | 
					  key: 
 | 
				
			||||||
  # 过期时间单位分钟
 | 
					  # 过期时间单位分钟
 | 
				
			||||||
  expire-time: 1440
 | 
					  expire-time: 1440
 | 
				
			||||||
 | 
					# 资源密码aes加密key
 | 
				
			||||||
 | 
					aes:
 | 
				
			||||||
 | 
					  key: 1111111111111111
 | 
				
			||||||
mysql:
 | 
					mysql:
 | 
				
			||||||
  host: localhost:3306
 | 
					  host: localhost:3306
 | 
				
			||||||
  username: root
 | 
					  username: root
 | 
				
			||||||
@@ -36,7 +24,6 @@ mysql:
 | 
				
			|||||||
  db-name: mayfly-go
 | 
					  db-name: mayfly-go
 | 
				
			||||||
  config: charset=utf8&loc=Local&parseTime=true
 | 
					  config: charset=utf8&loc=Local&parseTime=true
 | 
				
			||||||
  max-idle-conns: 5
 | 
					  max-idle-conns: 5
 | 
				
			||||||
 | 
					 | 
				
			||||||
log:
 | 
					log:
 | 
				
			||||||
   # 日志等级, trace, debug, info, warn, error, fatal
 | 
					   # 日志等级, trace, debug, info, warn, error, fatal
 | 
				
			||||||
  level: info
 | 
					  level: info
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,24 +1,26 @@
 | 
				
			|||||||
module mayfly-go
 | 
					module mayfly-go
 | 
				
			||||||
 | 
					
 | 
				
			||||||
go 1.18
 | 
					go 1.19
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	github.com/dgrijalva/jwt-go v3.2.0+incompatible // jwt
 | 
					 | 
				
			||||||
	github.com/gin-gonic/gin v1.8.1
 | 
						github.com/gin-gonic/gin v1.8.1
 | 
				
			||||||
	github.com/go-redis/redis/v8 v8.11.5
 | 
						github.com/go-redis/redis/v8 v8.11.5
 | 
				
			||||||
 | 
						github.com/go-sql-driver/mysql v1.6.0
 | 
				
			||||||
 | 
						github.com/golang-jwt/jwt/v4 v4.4.2
 | 
				
			||||||
	github.com/gorilla/websocket v1.5.0
 | 
						github.com/gorilla/websocket v1.5.0
 | 
				
			||||||
	github.com/lib/pq v1.10.6
 | 
						github.com/lib/pq v1.10.6
 | 
				
			||||||
	github.com/mojocn/base64Captcha v1.3.5 // 验证码
 | 
						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/robfig/cron/v3 v3.0.1 // 定时任务
 | 
				
			||||||
	github.com/sirupsen/logrus v1.8.1
 | 
						github.com/sirupsen/logrus v1.9.0
 | 
				
			||||||
	github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
 | 
						github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
 | 
				
			||||||
	go.mongodb.org/mongo-driver v1.9.1 // mongo
 | 
						go.mongodb.org/mongo-driver v1.9.1 // mongo
 | 
				
			||||||
	golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // ssh
 | 
						golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0
 | 
				
			||||||
	gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
 | 
						// ssh
 | 
				
			||||||
 | 
						gopkg.in/yaml.v3 v3.0.1
 | 
				
			||||||
	// gorm
 | 
						// gorm
 | 
				
			||||||
	gorm.io/driver/mysql v1.3.4
 | 
						gorm.io/driver/mysql v1.3.5
 | 
				
			||||||
	gorm.io/gorm v1.23.5
 | 
						gorm.io/gorm v1.23.8
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
@@ -28,13 +30,12 @@ require (
 | 
				
			|||||||
	github.com/go-playground/locales v0.14.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/universal-translator v0.18.0 // indirect
 | 
				
			||||||
	github.com/go-playground/validator/v10 v10.10.1 // 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/go-stack/stack v1.8.0 // indirect
 | 
				
			||||||
	github.com/goccy/go-json v0.9.7 // indirect
 | 
						github.com/goccy/go-json v0.9.7 // indirect
 | 
				
			||||||
	github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
 | 
						github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
 | 
				
			||||||
	github.com/golang/snappy v0.0.1 // indirect
 | 
						github.com/golang/snappy v0.0.1 // indirect
 | 
				
			||||||
	github.com/jinzhu/inflection v1.0.0 // indirect
 | 
						github.com/jinzhu/inflection v1.0.0 // indirect
 | 
				
			||||||
	github.com/jinzhu/now v1.1.4 // indirect
 | 
						github.com/jinzhu/now v1.1.5 // indirect
 | 
				
			||||||
	github.com/json-iterator/go v1.1.12 // indirect
 | 
						github.com/json-iterator/go v1.1.12 // indirect
 | 
				
			||||||
	github.com/klauspost/compress v1.13.6 // indirect
 | 
						github.com/klauspost/compress v1.13.6 // indirect
 | 
				
			||||||
	github.com/kr/fs v0.1.0 // indirect
 | 
						github.com/kr/fs v0.1.0 // indirect
 | 
				
			||||||
@@ -52,7 +53,7 @@ require (
 | 
				
			|||||||
	golang.org/x/image v0.0.0-20220302094943-723b81ca9867 // indirect
 | 
						golang.org/x/image v0.0.0-20220302094943-723b81ca9867 // indirect
 | 
				
			||||||
	golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
 | 
						golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
 | 
				
			||||||
	golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 // indirect
 | 
						golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 // indirect
 | 
				
			||||||
	golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
 | 
						golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
 | 
				
			||||||
	golang.org/x/text v0.3.7 // indirect
 | 
						golang.org/x/text v0.3.7 // indirect
 | 
				
			||||||
	golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
 | 
						golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
 | 
				
			||||||
	google.golang.org/protobuf v1.28.0 // indirect
 | 
						google.golang.org/protobuf v1.28.0 // indirect
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,16 +2,31 @@ package initialize
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	common_index_router "mayfly-go/internal/common/router"
 | 
						"io/fs"
 | 
				
			||||||
	devops_router "mayfly-go/internal/devops/router"
 | 
						common_router "mayfly-go/internal/common/router"
 | 
				
			||||||
 | 
						db_router "mayfly-go/internal/db/router"
 | 
				
			||||||
 | 
						machine_router "mayfly-go/internal/machine/router"
 | 
				
			||||||
 | 
						mongo_router "mayfly-go/internal/mongo/router"
 | 
				
			||||||
 | 
						project_router "mayfly-go/internal/project/router"
 | 
				
			||||||
 | 
						redis_router "mayfly-go/internal/redis/router"
 | 
				
			||||||
	sys_router "mayfly-go/internal/sys/router"
 | 
						sys_router "mayfly-go/internal/sys/router"
 | 
				
			||||||
	"mayfly-go/pkg/config"
 | 
						"mayfly-go/pkg/config"
 | 
				
			||||||
	"mayfly-go/pkg/middleware"
 | 
						"mayfly-go/pkg/middleware"
 | 
				
			||||||
 | 
						"mayfly-go/static"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func WrapStaticHandler(h http.Handler) gin.HandlerFunc {
 | 
				
			||||||
 | 
						return func(c *gin.Context) {
 | 
				
			||||||
 | 
							c.Writer.Header().Set("Cache-Control", `public, max-age=31536000`)
 | 
				
			||||||
 | 
							c.Request.URL.Path = strings.Split(c.Request.RequestURI, "/mayfly")[1]
 | 
				
			||||||
 | 
							h.ServeHTTP(c.Writer, c.Request)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func InitRouter() *gin.Engine {
 | 
					func InitRouter() *gin.Engine {
 | 
				
			||||||
	// server配置
 | 
						// server配置
 | 
				
			||||||
	serverConfig := config.Conf.Server
 | 
						serverConfig := config.Conf.Server
 | 
				
			||||||
@@ -25,12 +40,21 @@ func InitRouter() *gin.Engine {
 | 
				
			|||||||
		g.JSON(http.StatusNotFound, gin.H{"code": 404, "msg": fmt.Sprintf("not found '%s:%s'", g.Request.Method, g.Request.URL.Path)})
 | 
							g.JSON(http.StatusNotFound, gin.H{"code": 404, "msg": fmt.Sprintf("not found '%s:%s'", g.Request.Method, g.Request.URL.Path)})
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 使用embed打包静态资源至二进制文件中
 | 
				
			||||||
 | 
						fsys, _ := fs.Sub(static.Static, "static")
 | 
				
			||||||
 | 
						fileServer := http.FileServer(http.FS(fsys))
 | 
				
			||||||
 | 
						handler := WrapStaticHandler(fileServer)
 | 
				
			||||||
 | 
						router.GET("/", handler)
 | 
				
			||||||
 | 
						router.GET("/favicon.ico", handler)
 | 
				
			||||||
 | 
						router.GET("/config.js", handler)
 | 
				
			||||||
 | 
						// 所有/assets/**开头的都是静态资源文件
 | 
				
			||||||
 | 
						router.GET("/assets/*file", handler)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 设置静态资源
 | 
						// 设置静态资源
 | 
				
			||||||
	if staticConfs := serverConfig.Static; staticConfs != nil {
 | 
						if staticConfs := serverConfig.Static; staticConfs != nil {
 | 
				
			||||||
		for _, scs := range *staticConfs {
 | 
							for _, scs := range *staticConfs {
 | 
				
			||||||
			router.Static(scs.RelativePath, scs.Root)
 | 
								router.StaticFS(scs.RelativePath, http.Dir(scs.Root))
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// 设置静态文件
 | 
						// 设置静态文件
 | 
				
			||||||
	if staticFileConfs := serverConfig.StaticFile; staticFileConfs != nil {
 | 
						if staticFileConfs := serverConfig.StaticFile; staticFileConfs != nil {
 | 
				
			||||||
@@ -38,6 +62,7 @@ func InitRouter() *gin.Engine {
 | 
				
			|||||||
			router.StaticFile(sfs.RelativePath, sfs.Filepath)
 | 
								router.StaticFile(sfs.RelativePath, sfs.Filepath)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 是否允许跨域
 | 
						// 是否允许跨域
 | 
				
			||||||
	if serverConfig.Cors {
 | 
						if serverConfig.Cors {
 | 
				
			||||||
		router.Use(middleware.Cors())
 | 
							router.Use(middleware.Cors())
 | 
				
			||||||
@@ -46,23 +71,16 @@ func InitRouter() *gin.Engine {
 | 
				
			|||||||
	// 设置路由组
 | 
						// 设置路由组
 | 
				
			||||||
	api := router.Group("/api")
 | 
						api := router.Group("/api")
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		common_index_router.InitIndexRouter(api)
 | 
							common_router.InitIndexRouter(api)
 | 
				
			||||||
 | 
							common_router.InitCommonRouter(api)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		sys_router.InitCaptchaRouter(api)
 | 
							sys_router.Init(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)
 | 
							project_router.Init(api)
 | 
				
			||||||
		devops_router.InitDbRouter(api)
 | 
							machine_router.Init(api)
 | 
				
			||||||
		devops_router.InitDbSqlExecRouter(api)
 | 
							db_router.Init(api)
 | 
				
			||||||
		devops_router.InitRedisRouter(api)
 | 
							redis_router.Init(api)
 | 
				
			||||||
		devops_router.InitMachineRouter(api)
 | 
							mongo_router.Init(api)
 | 
				
			||||||
		devops_router.InitMachineScriptRouter(api)
 | 
					 | 
				
			||||||
		devops_router.InitMachineFileRouter(api)
 | 
					 | 
				
			||||||
		devops_router.InitMongoRouter(api)
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return router
 | 
						return router
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,10 +1,10 @@
 | 
				
			|||||||
package initialize
 | 
					package initialize
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	sys_application "mayfly-go/internal/sys/application"
 | 
						sysapp "mayfly-go/internal/sys/application"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func InitSaveLogFunc() ctx.SaveLogFunc {
 | 
					func InitSaveLogFunc() ctx.SaveLogFunc {
 | 
				
			||||||
	return sys_application.SyslogApp.SaveFromReq
 | 
						return sysapp.GetSyslogApp().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,23 +1,30 @@
 | 
				
			|||||||
package api
 | 
					package api
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"mayfly-go/internal/devops/application"
 | 
						dbapp "mayfly-go/internal/db/application"
 | 
				
			||||||
	"mayfly-go/internal/devops/domain/entity"
 | 
						dbentity "mayfly-go/internal/db/domain/entity"
 | 
				
			||||||
 | 
						machineentity "mayfly-go/internal/machine/domain/entity"
 | 
				
			||||||
 | 
						projectentity "mayfly-go/internal/project/domain/entity"
 | 
				
			||||||
 | 
						redisentity "mayfly-go/internal/redis/domain/entity"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						machineapp "mayfly-go/internal/machine/application"
 | 
				
			||||||
 | 
						projectapp "mayfly-go/internal/project/application"
 | 
				
			||||||
 | 
						redisapp "mayfly-go/internal/redis/application"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Index struct {
 | 
					type Index struct {
 | 
				
			||||||
	ProjectApp application.Project
 | 
						ProjectApp projectapp.Project
 | 
				
			||||||
	MachineApp application.Machine
 | 
						MachineApp machineapp.Machine
 | 
				
			||||||
	DbApp      application.Db
 | 
						DbApp      dbapp.Db
 | 
				
			||||||
	RedisApp   application.Redis
 | 
						RedisApp   redisapp.Redis
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (i *Index) Count(rc *ctx.ReqCtx) {
 | 
					func (i *Index) Count(rc *ctx.ReqCtx) {
 | 
				
			||||||
	rc.ResData = map[string]interface{}{
 | 
						rc.ResData = map[string]interface{}{
 | 
				
			||||||
		"projectNum": i.ProjectApp.Count(new(entity.Project)),
 | 
							"projectNum": i.ProjectApp.Count(new(projectentity.Project)),
 | 
				
			||||||
		"machineNum": i.MachineApp.Count(new(entity.Machine)),
 | 
							"machineNum": i.MachineApp.Count(new(machineentity.Machine)),
 | 
				
			||||||
		"dbNum":      i.DbApp.Count(new(entity.Db)),
 | 
							"dbNum":      i.DbApp.Count(new(dbentity.Db)),
 | 
				
			||||||
		"redisNum":   i.RedisApp.Count(new(entity.Redis)),
 | 
							"redisNum":   i.RedisApp.Count(new(redisentity.Redis)),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										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)
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -2,7 +2,10 @@ package router
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"mayfly-go/internal/common/api"
 | 
						"mayfly-go/internal/common/api"
 | 
				
			||||||
	devops_app "mayfly-go/internal/devops/application"
 | 
						dbapp "mayfly-go/internal/db/application"
 | 
				
			||||||
 | 
						machineapp "mayfly-go/internal/machine/application"
 | 
				
			||||||
 | 
						projectapp "mayfly-go/internal/project/application"
 | 
				
			||||||
 | 
						redisapp "mayfly-go/internal/redis/application"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
@@ -11,10 +14,10 @@ import (
 | 
				
			|||||||
func InitIndexRouter(router *gin.RouterGroup) {
 | 
					func InitIndexRouter(router *gin.RouterGroup) {
 | 
				
			||||||
	index := router.Group("common/index")
 | 
						index := router.Group("common/index")
 | 
				
			||||||
	i := &api.Index{
 | 
						i := &api.Index{
 | 
				
			||||||
		ProjectApp: devops_app.ProjectApp,
 | 
							ProjectApp: projectapp.GetProjectApp(),
 | 
				
			||||||
		MachineApp: devops_app.MachineApp,
 | 
							MachineApp: machineapp.GetMachineApp(),
 | 
				
			||||||
		DbApp:      devops_app.DbApp,
 | 
							DbApp:      dbapp.GetDbApp(),
 | 
				
			||||||
		RedisApp:   devops_app.RedisApp,
 | 
							RedisApp:   redisapp.GetRedisApp(),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		// 首页基本信息统计
 | 
							// 首页基本信息统计
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										35
									
								
								server/internal/common/utils/pwd.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								server/internal/common/utils/pwd.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
				
			|||||||
 | 
					package utils
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/config"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 使用config.yml的aes.key进行密码加密
 | 
				
			||||||
 | 
					func PwdAesEncrypt(password string) string {
 | 
				
			||||||
 | 
						if password == "" {
 | 
				
			||||||
 | 
							return ""
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						aes := config.Conf.Aes
 | 
				
			||||||
 | 
						if aes == nil {
 | 
				
			||||||
 | 
							return password
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						encryptPwd, err := aes.EncryptBase64([]byte(password))
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "密码加密失败: %s")
 | 
				
			||||||
 | 
						return encryptPwd
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 使用config.yml的aes.key进行密码解密
 | 
				
			||||||
 | 
					func PwdAesDecrypt(encryptPwd string) string {
 | 
				
			||||||
 | 
						if encryptPwd == "" {
 | 
				
			||||||
 | 
							return ""
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						aes := config.Conf.Aes
 | 
				
			||||||
 | 
						if aes == nil {
 | 
				
			||||||
 | 
							return encryptPwd
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						decryptPwd, err := aes.DecryptBase64(encryptPwd)
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "密码解密失败: %s")
 | 
				
			||||||
 | 
						// 解密后的密码
 | 
				
			||||||
 | 
						return string(decryptPwd)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										16
									
								
								server/internal/constant/constant.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								server/internal/constant/constant.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					package constant
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						MachineConnExpireTime = 60 * time.Minute
 | 
				
			||||||
 | 
						DbConnExpireTime      = 45 * time.Minute
 | 
				
			||||||
 | 
						RedisConnExpireTime   = 30 * time.Minute
 | 
				
			||||||
 | 
						MongoConnExpireTime   = 30 * time.Minute
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/****  开发测试使用   ****/
 | 
				
			||||||
 | 
					// MachineConnExpireTime = 4 * time.Minute
 | 
				
			||||||
 | 
					// DbConnExpireTime      = 2 * time.Minute
 | 
				
			||||||
 | 
					// RedisConnExpireTime   = 2 * time.Minute
 | 
				
			||||||
 | 
					// MongoConnExpireTime   = 2 * time.Minute
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
@@ -3,11 +3,12 @@ package api
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
	"mayfly-go/internal/devops/api/form"
 | 
						"mayfly-go/internal/db/api/form"
 | 
				
			||||||
	"mayfly-go/internal/devops/api/vo"
 | 
						"mayfly-go/internal/db/api/vo"
 | 
				
			||||||
	"mayfly-go/internal/devops/application"
 | 
						"mayfly-go/internal/db/application"
 | 
				
			||||||
	"mayfly-go/internal/devops/domain/entity"
 | 
						"mayfly-go/internal/db/domain/entity"
 | 
				
			||||||
	sysApplication "mayfly-go/internal/sys/application"
 | 
						projectapp "mayfly-go/internal/project/application"
 | 
				
			||||||
 | 
						sysapp "mayfly-go/internal/sys/application"
 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
	"mayfly-go/pkg/ginx"
 | 
						"mayfly-go/pkg/ginx"
 | 
				
			||||||
@@ -25,8 +26,8 @@ import (
 | 
				
			|||||||
type Db struct {
 | 
					type Db struct {
 | 
				
			||||||
	DbApp        application.Db
 | 
						DbApp        application.Db
 | 
				
			||||||
	DbSqlExecApp application.DbSqlExec
 | 
						DbSqlExecApp application.DbSqlExec
 | 
				
			||||||
	MsgApp       sysApplication.Msg
 | 
						MsgApp       sysapp.Msg
 | 
				
			||||||
	ProjectApp   application.Project
 | 
						ProjectApp   projectapp.Project
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const DEFAULT_COLUMN_SIZE = 500
 | 
					const DEFAULT_COLUMN_SIZE = 500
 | 
				
			||||||
@@ -47,6 +48,12 @@ func (d *Db) Save(rc *ctx.ReqCtx) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	db := new(entity.Db)
 | 
						db := new(entity.Db)
 | 
				
			||||||
	utils.Copy(db, form)
 | 
						utils.Copy(db, form)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 密码解密,并使用解密后的赋值
 | 
				
			||||||
 | 
						originPwd, err := utils.DefaultRsaDecrypt(form.Password, true)
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "解密密码错误: %s")
 | 
				
			||||||
 | 
						db.Password = originPwd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 密码脱敏记录日志
 | 
						// 密码脱敏记录日志
 | 
				
			||||||
	form.Password = "****"
 | 
						form.Password = "****"
 | 
				
			||||||
	rc.ReqParam = form
 | 
						rc.ReqParam = form
 | 
				
			||||||
@@ -55,6 +62,34 @@ func (d *Db) Save(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	d.DbApp.Save(db)
 | 
						d.DbApp.Save(db)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取数据库实例密码,由于数据库是加密存储,故提供该接口展示原文密码
 | 
				
			||||||
 | 
					func (d *Db) GetDbPwd(rc *ctx.ReqCtx) {
 | 
				
			||||||
 | 
						dbId := GetDbId(rc.GinCtx)
 | 
				
			||||||
 | 
						dbEntity := d.DbApp.GetById(dbId, "Password")
 | 
				
			||||||
 | 
						dbEntity.PwdDecrypt()
 | 
				
			||||||
 | 
						rc.ResData = dbEntity.Password
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取数据库实例的所有数据库名
 | 
				
			||||||
 | 
					func (d *Db) GetDatabaseNames(rc *ctx.ReqCtx) {
 | 
				
			||||||
 | 
						form := &form.DbForm{}
 | 
				
			||||||
 | 
						ginx.BindJsonAndValid(rc.GinCtx, form)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						db := new(entity.Db)
 | 
				
			||||||
 | 
						utils.Copy(db, form)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 密码解密,并使用解密后的赋值
 | 
				
			||||||
 | 
						originPwd, err := utils.DefaultRsaDecrypt(form.Password, true)
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "解密密码错误: %s")
 | 
				
			||||||
 | 
						db.Password = originPwd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 如果id不为空,并且密码为空则从数据库查询
 | 
				
			||||||
 | 
						if form.Id != 0 && db.Password == "" {
 | 
				
			||||||
 | 
							db = d.DbApp.GetById(form.Id)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						rc.ResData = d.DbApp.GetDatabases(db)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *Db) DeleteDb(rc *ctx.ReqCtx) {
 | 
					func (d *Db) DeleteDb(rc *ctx.ReqCtx) {
 | 
				
			||||||
	dbId := GetDbId(rc.GinCtx)
 | 
						dbId := GetDbId(rc.GinCtx)
 | 
				
			||||||
	d.DbApp.Delete(dbId)
 | 
						d.DbApp.Delete(dbId)
 | 
				
			||||||
@@ -63,19 +98,19 @@ func (d *Db) DeleteDb(rc *ctx.ReqCtx) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *Db) TableInfos(rc *ctx.ReqCtx) {
 | 
					func (d *Db) TableInfos(rc *ctx.ReqCtx) {
 | 
				
			||||||
	rc.ResData = d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx)).GetTableInfos()
 | 
						rc.ResData = d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx)).GetMeta().GetTableInfos()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *Db) TableIndex(rc *ctx.ReqCtx) {
 | 
					func (d *Db) TableIndex(rc *ctx.ReqCtx) {
 | 
				
			||||||
	tn := rc.GinCtx.Query("tableName")
 | 
						tn := rc.GinCtx.Query("tableName")
 | 
				
			||||||
	biz.NotEmpty(tn, "tableName不能为空")
 | 
						biz.NotEmpty(tn, "tableName不能为空")
 | 
				
			||||||
	rc.ResData = d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx)).GetTableIndex(tn)
 | 
						rc.ResData = d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx)).GetMeta().GetTableIndex(tn)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *Db) GetCreateTableDdl(rc *ctx.ReqCtx) {
 | 
					func (d *Db) GetCreateTableDdl(rc *ctx.ReqCtx) {
 | 
				
			||||||
	tn := rc.GinCtx.Query("tableName")
 | 
						tn := rc.GinCtx.Query("tableName")
 | 
				
			||||||
	biz.NotEmpty(tn, "tableName不能为空")
 | 
						biz.NotEmpty(tn, "tableName不能为空")
 | 
				
			||||||
	rc.ResData = d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx)).GetCreateTableDdl(tn)
 | 
						rc.ResData = d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx)).GetMeta().GetCreateTableDdl(tn)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *Db) ExecSql(rc *ctx.ReqCtx) {
 | 
					func (d *Db) ExecSql(rc *ctx.ReqCtx) {
 | 
				
			||||||
@@ -95,37 +130,21 @@ func (d *Db) ExecSql(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rc.ReqParam = fmt.Sprintf("db: %d:%s | sql: %s", id, db, sql)
 | 
						rc.ReqParam = fmt.Sprintf("db: %d:%s | sql: %s", id, db, sql)
 | 
				
			||||||
 | 
					 | 
				
			||||||
	biz.NotEmpty(sql, "sql不能为空")
 | 
						biz.NotEmpty(sql, "sql不能为空")
 | 
				
			||||||
	if strings.HasPrefix(sql, "SELECT") || strings.HasPrefix(sql, "select") || strings.HasPrefix(sql, "show") || strings.HasPrefix(sql, "explain") {
 | 
					 | 
				
			||||||
		colNames, res, err := dbInstance.SelectData(sql)
 | 
					 | 
				
			||||||
		biz.ErrIsNilAppendErr(err, "查询失败: %s")
 | 
					 | 
				
			||||||
		colAndRes := make(map[string]interface{})
 | 
					 | 
				
			||||||
		colAndRes["colNames"] = colNames
 | 
					 | 
				
			||||||
		colAndRes["res"] = res
 | 
					 | 
				
			||||||
		rc.ResData = colAndRes
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		// 根据执行sql,生成执行记录
 | 
					 | 
				
			||||||
		execRecord := d.DbSqlExecApp.GenExecLog(rc.LoginAccount, id, db, sql, dbInstance)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		rowsAffected, err := dbInstance.Exec(sql)
 | 
						execRes, err := d.DbSqlExecApp.Exec(&application.DbSqlExecReq{
 | 
				
			||||||
		biz.ErrIsNilAppendErr(err, "执行失败: %s")
 | 
							DbId:         id,
 | 
				
			||||||
		res := make([]map[string]string, 0)
 | 
							Db:           db,
 | 
				
			||||||
		resData := make(map[string]string)
 | 
							Sql:          sql,
 | 
				
			||||||
		resData["影响条数"] = fmt.Sprintf("%d", rowsAffected)
 | 
							Remark:       form.Remark,
 | 
				
			||||||
		res = append(res, resData)
 | 
							DbInstance:   dbInstance,
 | 
				
			||||||
 | 
							LoginAccount: rc.LoginAccount,
 | 
				
			||||||
		colAndRes := make(map[string]interface{})
 | 
						})
 | 
				
			||||||
		colAndRes["colNames"] = []string{"影响条数"}
 | 
						biz.ErrIsNilAppendErr(err, "执行失败: %s")
 | 
				
			||||||
		colAndRes["res"] = res
 | 
						colAndRes := make(map[string]interface{})
 | 
				
			||||||
 | 
						colAndRes["colNames"] = execRes.ColNames
 | 
				
			||||||
		rc.ResData = colAndRes
 | 
						colAndRes["res"] = execRes.Res
 | 
				
			||||||
		// 保存sql执行记录
 | 
						rc.ResData = colAndRes
 | 
				
			||||||
		if res[0]["影响条数"] > "0" {
 | 
					 | 
				
			||||||
			execRecord.Remark = form.Remark
 | 
					 | 
				
			||||||
			d.DbSqlExecApp.Save(execRecord)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 执行sql文件
 | 
					// 执行sql文件
 | 
				
			||||||
@@ -203,11 +222,12 @@ func (d *Db) DumpSql(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	writer.WriteString(fmt.Sprintf("\n-- 导出数据库: %s ", db))
 | 
						writer.WriteString(fmt.Sprintf("\n-- 导出数据库: %s ", db))
 | 
				
			||||||
	writer.WriteString("\n-- ----------------------------\n")
 | 
						writer.WriteString("\n-- ----------------------------\n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						dbmeta := d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx)).GetMeta()
 | 
				
			||||||
	for _, table := range tables {
 | 
						for _, table := range tables {
 | 
				
			||||||
		if needStruct {
 | 
							if needStruct {
 | 
				
			||||||
			writer.WriteString(fmt.Sprintf("\n-- ----------------------------\n-- 表结构: %s \n-- ----------------------------\n", table))
 | 
								writer.WriteString(fmt.Sprintf("\n-- ----------------------------\n-- 表结构: %s \n-- ----------------------------\n", table))
 | 
				
			||||||
			writer.WriteString(fmt.Sprintf("DROP TABLE IF EXISTS `%s`;\n", table))
 | 
								writer.WriteString(fmt.Sprintf("DROP TABLE IF EXISTS `%s`;\n", table))
 | 
				
			||||||
			writer.WriteString(dbInstance.GetCreateTableDdl(table)[0]["Create Table"].(string) + ";\n")
 | 
								writer.WriteString(dbmeta.GetCreateTableDdl(table)[0]["Create Table"].(string) + ";\n")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if !needData {
 | 
							if !needData {
 | 
				
			||||||
@@ -220,7 +240,13 @@ func (d *Db) DumpSql(rc *ctx.ReqCtx) {
 | 
				
			|||||||
		countSql := fmt.Sprintf("SELECT COUNT(*) count FROM %s", table)
 | 
							countSql := fmt.Sprintf("SELECT COUNT(*) count FROM %s", table)
 | 
				
			||||||
		_, countRes, _ := dbInstance.SelectData(countSql)
 | 
							_, countRes, _ := dbInstance.SelectData(countSql)
 | 
				
			||||||
		// 查询出所有列信息总数,手动分页获取所有数据
 | 
							// 查询出所有列信息总数,手动分页获取所有数据
 | 
				
			||||||
		maCount := int(countRes[0]["count"].(int64))
 | 
							maCount := 0
 | 
				
			||||||
 | 
							// 查询出所有列信息总数,手动分页获取所有数据
 | 
				
			||||||
 | 
							if count64, is64 := countRes[0]["maNum"].(int64); is64 {
 | 
				
			||||||
 | 
								maCount = int(count64)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								maCount = countRes[0]["maNum"].(int)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		// 计算需要查询的页数
 | 
							// 计算需要查询的页数
 | 
				
			||||||
		pageNum := maCount / DEFAULT_COLUMN_SIZE
 | 
							pageNum := maCount / DEFAULT_COLUMN_SIZE
 | 
				
			||||||
		if maCount%DEFAULT_COLUMN_SIZE > 0 {
 | 
							if maCount%DEFAULT_COLUMN_SIZE > 0 {
 | 
				
			||||||
@@ -229,9 +255,9 @@ func (d *Db) DumpSql(rc *ctx.ReqCtx) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		var sqlTmp string
 | 
							var sqlTmp string
 | 
				
			||||||
		switch dbInstance.Type {
 | 
							switch dbInstance.Type {
 | 
				
			||||||
		case "mysql":
 | 
							case entity.DbTypeMysql:
 | 
				
			||||||
			sqlTmp = "SELECT * FROM %s LIMIT %d, %d"
 | 
								sqlTmp = "SELECT * FROM %s LIMIT %d, %d"
 | 
				
			||||||
		case "postgres":
 | 
							case entity.DbTypePostgres:
 | 
				
			||||||
			sqlTmp = "SELECT * FROM %s OFFSET %d LIMIT %d"
 | 
								sqlTmp = "SELECT * FROM %s OFFSET %d LIMIT %d"
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		for index := 0; index < pageNum; index++ {
 | 
							for index := 0; index < pageNum; index++ {
 | 
				
			||||||
@@ -269,7 +295,7 @@ func (d *Db) DumpSql(rc *ctx.ReqCtx) {
 | 
				
			|||||||
func (d *Db) TableMA(rc *ctx.ReqCtx) {
 | 
					func (d *Db) TableMA(rc *ctx.ReqCtx) {
 | 
				
			||||||
	dbi := d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx))
 | 
						dbi := d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx))
 | 
				
			||||||
	biz.ErrIsNilAppendErr(d.ProjectApp.CanAccess(rc.LoginAccount.Id, dbi.ProjectId), "%s")
 | 
						biz.ErrIsNilAppendErr(d.ProjectApp.CanAccess(rc.LoginAccount.Id, dbi.ProjectId), "%s")
 | 
				
			||||||
	rc.ResData = dbi.GetTableMetedatas()
 | 
						rc.ResData = dbi.GetMeta().GetTables()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// @router /api/db/:dbId/c-metadata [get]
 | 
					// @router /api/db/:dbId/c-metadata [get]
 | 
				
			||||||
@@ -280,16 +306,17 @@ func (d *Db) ColumnMA(rc *ctx.ReqCtx) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	dbi := d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx))
 | 
						dbi := d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx))
 | 
				
			||||||
	biz.ErrIsNilAppendErr(d.ProjectApp.CanAccess(rc.LoginAccount.Id, dbi.ProjectId), "%s")
 | 
						biz.ErrIsNilAppendErr(d.ProjectApp.CanAccess(rc.LoginAccount.Id, dbi.ProjectId), "%s")
 | 
				
			||||||
	rc.ResData = dbi.GetColumnMetadatas(tn)
 | 
						rc.ResData = dbi.GetMeta().GetColumns(tn)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// @router /api/db/:dbId/hint-tables [get]
 | 
					// @router /api/db/:dbId/hint-tables [get]
 | 
				
			||||||
func (d *Db) HintTables(rc *ctx.ReqCtx) {
 | 
					func (d *Db) HintTables(rc *ctx.ReqCtx) {
 | 
				
			||||||
	dbi := d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx))
 | 
						dbi := d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx))
 | 
				
			||||||
	biz.ErrIsNilAppendErr(d.ProjectApp.CanAccess(rc.LoginAccount.Id, dbi.ProjectId), "%s")
 | 
						biz.ErrIsNilAppendErr(d.ProjectApp.CanAccess(rc.LoginAccount.Id, dbi.ProjectId), "%s")
 | 
				
			||||||
	// 获取所有表
 | 
					 | 
				
			||||||
	tables := dbi.GetTableMetedatas()
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						dm := dbi.GetMeta()
 | 
				
			||||||
 | 
						// 获取所有表
 | 
				
			||||||
 | 
						tables := dm.GetTables()
 | 
				
			||||||
	tableNames := make([]string, 0)
 | 
						tableNames := make([]string, 0)
 | 
				
			||||||
	for _, v := range tables {
 | 
						for _, v := range tables {
 | 
				
			||||||
		tableNames = append(tableNames, v["tableName"].(string))
 | 
							tableNames = append(tableNames, v["tableName"].(string))
 | 
				
			||||||
@@ -304,7 +331,7 @@ func (d *Db) HintTables(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 获取所有表下的所有列信息
 | 
						// 获取所有表下的所有列信息
 | 
				
			||||||
	columnMds := dbi.GetColumnMetadatas(tableNames...)
 | 
						columnMds := dm.GetColumns(tableNames...)
 | 
				
			||||||
	for _, v := range columnMds {
 | 
						for _, v := range columnMds {
 | 
				
			||||||
		tName := v["tableName"].(string)
 | 
							tName := v["tableName"].(string)
 | 
				
			||||||
		if res[tName] == nil {
 | 
							if res[tName] == nil {
 | 
				
			||||||
@@ -1,8 +1,8 @@
 | 
				
			|||||||
package api
 | 
					package api
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"mayfly-go/internal/devops/application"
 | 
						"mayfly-go/internal/db/application"
 | 
				
			||||||
	"mayfly-go/internal/devops/domain/entity"
 | 
						"mayfly-go/internal/db/domain/entity"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
	"mayfly-go/pkg/ginx"
 | 
						"mayfly-go/pkg/ginx"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -9,11 +9,14 @@ type DbForm struct {
 | 
				
			|||||||
	Username  string `binding:"required" json:"username"`
 | 
						Username  string `binding:"required" json:"username"`
 | 
				
			||||||
	Password  string `json:"password"`
 | 
						Password  string `json:"password"`
 | 
				
			||||||
	Params    string `json:"params"`
 | 
						Params    string `json:"params"`
 | 
				
			||||||
	Database  string `binding:"required" json:"database"`
 | 
						Database  string `json:"database"`
 | 
				
			||||||
	ProjectId uint64 `binding:"required" json:"projectId"`
 | 
						ProjectId uint64 `binding:"required" json:"projectId"`
 | 
				
			||||||
	Project   string `json:"project"`
 | 
						Project   string `json:"project"`
 | 
				
			||||||
	Env       string `json:"env"`
 | 
						Env       string `json:"env"`
 | 
				
			||||||
	EnvId     uint64 `binding:"required" json:"envId"`
 | 
						EnvId     uint64 `binding:"required" json:"envId"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						EnableSshTunnel    int8   `json:"enableSshTunnel"`
 | 
				
			||||||
 | 
						SshTunnelMachineId uint64 `json:"sshTunnelMachineId"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type DbSqlSaveForm struct {
 | 
					type DbSqlSaveForm struct {
 | 
				
			||||||
@@ -19,4 +19,7 @@ type SelectDataDbVO struct {
 | 
				
			|||||||
	CreateTime *time.Time `json:"createTime"`
 | 
						CreateTime *time.Time `json:"createTime"`
 | 
				
			||||||
	Creator    *string    `json:"creator"`
 | 
						Creator    *string    `json:"creator"`
 | 
				
			||||||
	CreatorId  *int64     `json:"creatorId"`
 | 
						CreatorId  *int64     `json:"creatorId"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						EnableSshTunnel    *int8   `json:"enableSshTunnel"`
 | 
				
			||||||
 | 
						SshTunnelMachineId *uint64 `json:"sshTunnelMachineId"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										16
									
								
								server/internal/db/application/application.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								server/internal/db/application/application.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					package application
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "mayfly-go/internal/db/infrastructure/persistence"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var (
 | 
				
			||||||
 | 
						dbApp        Db        = newDbApp(persistence.GetDbRepo(), persistence.GetDbSqlRepo())
 | 
				
			||||||
 | 
						dbSqlExecApp DbSqlExec = newDbSqlExecApp(persistence.GetDbSqlExecRepo())
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetDbApp() Db {
 | 
				
			||||||
 | 
						return dbApp
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetDbSqlExecApp() DbSqlExec {
 | 
				
			||||||
 | 
						return dbSqlExecApp
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,24 +1,28 @@
 | 
				
			|||||||
package application
 | 
					package application
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
	"database/sql"
 | 
						"database/sql"
 | 
				
			||||||
	"errors"
 | 
					 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"mayfly-go/internal/devops/domain/entity"
 | 
						"mayfly-go/internal/constant"
 | 
				
			||||||
	"mayfly-go/internal/devops/domain/repository"
 | 
						"mayfly-go/internal/db/domain/entity"
 | 
				
			||||||
	"mayfly-go/internal/devops/infrastructure/persistence"
 | 
						"mayfly-go/internal/db/domain/repository"
 | 
				
			||||||
 | 
						machineapp "mayfly-go/internal/machine/application"
 | 
				
			||||||
 | 
						"mayfly-go/internal/machine/infrastructure/machine"
 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
	"mayfly-go/pkg/cache"
 | 
						"mayfly-go/pkg/cache"
 | 
				
			||||||
	"mayfly-go/pkg/global"
 | 
						"mayfly-go/pkg/global"
 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
	"mayfly-go/pkg/utils"
 | 
						"mayfly-go/pkg/utils"
 | 
				
			||||||
 | 
						"net"
 | 
				
			||||||
	"reflect"
 | 
						"reflect"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_ "github.com/lib/pq"
 | 
						"github.com/go-sql-driver/mysql"
 | 
				
			||||||
 | 
						"github.com/lib/pq"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Db interface {
 | 
					type Db interface {
 | 
				
			||||||
@@ -42,6 +46,16 @@ type Db interface {
 | 
				
			|||||||
	// @param id 数据库实例id
 | 
						// @param id 数据库实例id
 | 
				
			||||||
	// @param db 数据库
 | 
						// @param db 数据库
 | 
				
			||||||
	GetDbInstance(id uint64, db string) *DbInstance
 | 
						GetDbInstance(id uint64, db string) *DbInstance
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 获取数据库实例的所有数据库列表
 | 
				
			||||||
 | 
						GetDatabases(entity *entity.Db) []string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func newDbApp(dbRepo repository.Db, dbSqlRepo repository.DbSql) Db {
 | 
				
			||||||
 | 
						return &dbAppImpl{
 | 
				
			||||||
 | 
							dbRepo:    dbRepo,
 | 
				
			||||||
 | 
							dbSqlRepo: dbSqlRepo,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type dbAppImpl struct {
 | 
					type dbAppImpl struct {
 | 
				
			||||||
@@ -49,11 +63,6 @@ type dbAppImpl struct {
 | 
				
			|||||||
	dbSqlRepo repository.DbSql
 | 
						dbSqlRepo repository.DbSql
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var DbApp Db = &dbAppImpl{
 | 
					 | 
				
			||||||
	dbRepo:    persistence.DbDao,
 | 
					 | 
				
			||||||
	dbSqlRepo: persistence.DbSqlDao,
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 分页获取数据库信息列表
 | 
					// 分页获取数据库信息列表
 | 
				
			||||||
func (d *dbAppImpl) GetPageList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					func (d *dbAppImpl) GetPageList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
				
			||||||
	return d.dbRepo.GetDbList(condition, pageParam, toEntity, orderBy...)
 | 
						return d.dbRepo.GetDbList(condition, pageParam, toEntity, orderBy...)
 | 
				
			||||||
@@ -75,10 +84,11 @@ func (d *dbAppImpl) GetById(id uint64, cols ...string) *entity.Db {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (d *dbAppImpl) Save(dbEntity *entity.Db) {
 | 
					func (d *dbAppImpl) Save(dbEntity *entity.Db) {
 | 
				
			||||||
	// 默认tcp连接
 | 
						// 默认tcp连接
 | 
				
			||||||
	dbEntity.Network = "tcp"
 | 
						dbEntity.Network = dbEntity.GetNetwork()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 测试连接
 | 
						// 测试连接
 | 
				
			||||||
	if dbEntity.Password != "" {
 | 
						if dbEntity.Password != "" {
 | 
				
			||||||
		TestConnection(*dbEntity)
 | 
							TestConnection(dbEntity)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 查找是否存在该库
 | 
						// 查找是否存在该库
 | 
				
			||||||
@@ -88,6 +98,7 @@ func (d *dbAppImpl) Save(dbEntity *entity.Db) {
 | 
				
			|||||||
	if dbEntity.Id == 0 {
 | 
						if dbEntity.Id == 0 {
 | 
				
			||||||
		biz.NotEmpty(dbEntity.Password, "密码不能为空")
 | 
							biz.NotEmpty(dbEntity.Password, "密码不能为空")
 | 
				
			||||||
		biz.IsTrue(err != nil, "该数据库实例已存在")
 | 
							biz.IsTrue(err != nil, "该数据库实例已存在")
 | 
				
			||||||
 | 
							dbEntity.PwdEncrypt()
 | 
				
			||||||
		d.dbRepo.Insert(dbEntity)
 | 
							d.dbRepo.Insert(dbEntity)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -102,6 +113,8 @@ func (d *dbAppImpl) Save(dbEntity *entity.Db) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	var oldDbs []interface{}
 | 
						var oldDbs []interface{}
 | 
				
			||||||
	for _, v := range strings.Split(old.Database, " ") {
 | 
						for _, v := range strings.Split(old.Database, " ") {
 | 
				
			||||||
 | 
							// 关闭数据库连接
 | 
				
			||||||
 | 
							CloseDb(dbEntity.Id, v)
 | 
				
			||||||
		oldDbs = append(oldDbs, v)
 | 
							oldDbs = append(oldDbs, v)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -114,14 +127,12 @@ func (d *dbAppImpl) Save(dbEntity *entity.Db) {
 | 
				
			|||||||
		return i1.(string) == i2.(string)
 | 
							return i1.(string) == i2.(string)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	for _, v := range delDb {
 | 
						for _, v := range delDb {
 | 
				
			||||||
		// 先关闭数据库连接
 | 
					 | 
				
			||||||
		CloseDb(dbEntity.Id, v.(string))
 | 
					 | 
				
			||||||
		// 删除该库关联的所有sql记录
 | 
							// 删除该库关联的所有sql记录
 | 
				
			||||||
		d.dbSqlRepo.DeleteBy(&entity.DbSql{DbId: dbId, Db: v.(string)})
 | 
							d.dbSqlRepo.DeleteBy(&entity.DbSql{DbId: dbId, Db: v.(string)})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						dbEntity.PwdEncrypt()
 | 
				
			||||||
	d.dbRepo.Update(dbEntity)
 | 
						d.dbRepo.Update(dbEntity)
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *dbAppImpl) Delete(id uint64) {
 | 
					func (d *dbAppImpl) Delete(id uint64) {
 | 
				
			||||||
@@ -136,11 +147,35 @@ func (d *dbAppImpl) Delete(id uint64) {
 | 
				
			|||||||
	d.dbSqlRepo.DeleteBy(&entity.DbSql{DbId: id})
 | 
						d.dbSqlRepo.DeleteBy(&entity.DbSql{DbId: id})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (d *dbAppImpl) GetDatabases(ed *entity.Db) []string {
 | 
				
			||||||
 | 
						ed.Network = ed.GetNetwork()
 | 
				
			||||||
 | 
						databases := make([]string, 0)
 | 
				
			||||||
 | 
						var dbConn *sql.DB
 | 
				
			||||||
 | 
						var metaDb string
 | 
				
			||||||
 | 
						var getDatabasesSql string
 | 
				
			||||||
 | 
						if ed.Type == entity.DbTypeMysql {
 | 
				
			||||||
 | 
							metaDb = "information_schema"
 | 
				
			||||||
 | 
							getDatabasesSql = "SELECT SCHEMA_NAME AS dbname FROM SCHEMATA"
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							metaDb = "postgres"
 | 
				
			||||||
 | 
							getDatabasesSql = "SELECT datname AS dbname FROM pg_database"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						dbConn, err := GetDbConn(ed, metaDb)
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "数据库连接失败: %s")
 | 
				
			||||||
 | 
						defer dbConn.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, res, err := SelectDataByDb(dbConn, getDatabasesSql)
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "获取数据库列表失败")
 | 
				
			||||||
 | 
						for _, re := range res {
 | 
				
			||||||
 | 
							databases = append(databases, re["dbname"].(string))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return databases
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var mutex sync.Mutex
 | 
					var mutex sync.Mutex
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (da *dbAppImpl) GetDbInstance(id uint64, db string) *DbInstance {
 | 
					func (da *dbAppImpl) GetDbInstance(id uint64, db string) *DbInstance {
 | 
				
			||||||
	mutex.Lock()
 | 
					 | 
				
			||||||
	defer mutex.Unlock()
 | 
					 | 
				
			||||||
	// Id不为0,则为需要缓存
 | 
						// Id不为0,则为需要缓存
 | 
				
			||||||
	needCache := id != 0
 | 
						needCache := id != 0
 | 
				
			||||||
	if needCache {
 | 
						if needCache {
 | 
				
			||||||
@@ -149,20 +184,23 @@ func (da *dbAppImpl) GetDbInstance(id uint64, db string) *DbInstance {
 | 
				
			|||||||
			return load.(*DbInstance)
 | 
								return load.(*DbInstance)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						mutex.Lock()
 | 
				
			||||||
 | 
						defer mutex.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	d := da.GetById(id)
 | 
						d := da.GetById(id)
 | 
				
			||||||
 | 
						// 密码解密
 | 
				
			||||||
 | 
						d.PwdDecrypt()
 | 
				
			||||||
	biz.NotNil(d, "数据库信息不存在")
 | 
						biz.NotNil(d, "数据库信息不存在")
 | 
				
			||||||
	biz.IsTrue(strings.Contains(d.Database, db), "未配置该库的操作权限")
 | 
						biz.IsTrue(strings.Contains(d.Database, db), "未配置该库的操作权限")
 | 
				
			||||||
	global.Log.Infof("连接db: %s:%d/%s", d.Host, d.Port, db)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 将数据库替换为要访问的数据库,原本数据库为空格拼接的所有库
 | 
						cacheKey := GetDbCacheKey(id, db)
 | 
				
			||||||
	d.Database = db
 | 
						dbi := &DbInstance{Id: cacheKey, Type: d.Type, ProjectId: d.ProjectId, sshTunnelMachineId: d.SshTunnelMachineId}
 | 
				
			||||||
	DB, err := sql.Open(d.Type, getDsn(d))
 | 
					
 | 
				
			||||||
	biz.ErrIsNil(err, fmt.Sprintf("Open %s failed, err:%v\n", d.Type, err))
 | 
						DB, err := GetDbConn(d, db)
 | 
				
			||||||
	perr := DB.Ping()
 | 
						if err != nil {
 | 
				
			||||||
	if perr != nil {
 | 
							dbi.Close()
 | 
				
			||||||
		global.Log.Errorf("连接db失败: %s:%d/%s", d.Host, d.Port, db)
 | 
							global.Log.Errorf("连接db失败: %s:%d/%s", d.Host, d.Port, db)
 | 
				
			||||||
		panic(biz.NewBizErr(fmt.Sprintf("数据库连接失败: %s", perr.Error())))
 | 
							panic(biz.NewBizErr(fmt.Sprintf("数据库连接失败: %s", err.Error())))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 最大连接周期,超过时间的连接就close
 | 
						// 最大连接周期,超过时间的连接就close
 | 
				
			||||||
@@ -172,8 +210,8 @@ func (da *dbAppImpl) GetDbInstance(id uint64, db string) *DbInstance {
 | 
				
			|||||||
	// 设置闲置连接数
 | 
						// 设置闲置连接数
 | 
				
			||||||
	DB.SetMaxIdleConns(1)
 | 
						DB.SetMaxIdleConns(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cacheKey := GetDbCacheKey(id, db)
 | 
						dbi.db = DB
 | 
				
			||||||
	dbi := &DbInstance{Id: cacheKey, Type: d.Type, ProjectId: d.ProjectId, db: DB}
 | 
						global.Log.Infof("连接db: %s:%d/%s", d.Host, d.Port, db)
 | 
				
			||||||
	if needCache {
 | 
						if needCache {
 | 
				
			||||||
		dbCache.Put(cacheKey, dbi)
 | 
							dbCache.Put(cacheKey, dbi)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -182,14 +220,30 @@ func (da *dbAppImpl) GetDbInstance(id uint64, db string) *DbInstance {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
//------------------------------------------------------------------------------
 | 
					//------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 客户端连接缓存,30分钟内没有访问则会被关闭, key为数据库实例id:数据库
 | 
					// 单次最大查询数据集
 | 
				
			||||||
var dbCache = cache.NewTimedCache(30*time.Minute, 5*time.Second).
 | 
					const Max_Rows = 2000
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 客户端连接缓存,指定时间内没有访问则会被关闭, key为数据库实例id:数据库
 | 
				
			||||||
 | 
					var dbCache = cache.NewTimedCache(constant.DbConnExpireTime, 5*time.Second).
 | 
				
			||||||
	WithUpdateAccessTime(true).
 | 
						WithUpdateAccessTime(true).
 | 
				
			||||||
	OnEvicted(func(key interface{}, value interface{}) {
 | 
						OnEvicted(func(key interface{}, value interface{}) {
 | 
				
			||||||
		global.Log.Info(fmt.Sprintf("删除db连接缓存 id = %s", key))
 | 
							global.Log.Info(fmt.Sprintf("删除db连接缓存 id = %s", key))
 | 
				
			||||||
		value.(*DbInstance).Close()
 | 
							value.(*DbInstance).Close()
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func init() {
 | 
				
			||||||
 | 
						machine.AddCheckSshTunnelMachineUseFunc(func(machineId uint64) bool {
 | 
				
			||||||
 | 
							// 遍历所有db连接实例,若存在db实例使用该ssh隧道机器,则返回true,表示还在使用中...
 | 
				
			||||||
 | 
							items := dbCache.Items()
 | 
				
			||||||
 | 
							for _, v := range items {
 | 
				
			||||||
 | 
								if v.Value.(*DbInstance).sshTunnelMachineId == machineId {
 | 
				
			||||||
 | 
									return true
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func GetDbCacheKey(dbId uint64, db string) string {
 | 
					func GetDbCacheKey(dbId uint64, db string) string {
 | 
				
			||||||
	return fmt.Sprintf("%d:%s", dbId, db)
 | 
						return fmt.Sprintf("%d:%s", dbId, db)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -201,37 +255,45 @@ func GetDbInstanceByCache(id string) *DbInstance {
 | 
				
			|||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestConnection(d entity.Db) {
 | 
					func TestConnection(d *entity.Db) {
 | 
				
			||||||
	// 验证第一个库是否可以连接即可
 | 
						// 验证第一个库是否可以连接即可
 | 
				
			||||||
	d.Database = strings.Split(d.Database, " ")[0]
 | 
						DB, err := GetDbConn(d, strings.Split(d.Database, " ")[0])
 | 
				
			||||||
	DB, err := sql.Open(d.Type, getDsn(&d))
 | 
						biz.ErrIsNilAppendErr(err, "数据库连接失败: %s")
 | 
				
			||||||
	biz.ErrIsNil(err, "Open %s failed, err:%v\n", d.Type, err)
 | 
					 | 
				
			||||||
	defer DB.Close()
 | 
						defer DB.Close()
 | 
				
			||||||
	perr := DB.Ping()
 | 
					 | 
				
			||||||
	biz.ErrIsNilAppendErr(perr, "数据库连接失败: %s")
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// db实例
 | 
					// 获取数据库连接
 | 
				
			||||||
type DbInstance struct {
 | 
					func GetDbConn(d *entity.Db, db string) (*sql.DB, error) {
 | 
				
			||||||
	Id        string
 | 
						// SSH Conect
 | 
				
			||||||
	Type      string
 | 
						if d.EnableSshTunnel == 1 && d.SshTunnelMachineId != 0 {
 | 
				
			||||||
	ProjectId uint64
 | 
							sshTunnelMachine := machineapp.GetMachineApp().GetSshTunnelMachine(d.SshTunnelMachineId)
 | 
				
			||||||
	db        *sql.DB
 | 
							if d.Type == entity.DbTypeMysql {
 | 
				
			||||||
}
 | 
								mysql.RegisterDialContext(d.Network, func(ctx context.Context, addr string) (net.Conn, error) {
 | 
				
			||||||
 | 
									return sshTunnelMachine.GetDialConn("tcp", addr)
 | 
				
			||||||
// 执行查询语句
 | 
								})
 | 
				
			||||||
// 依次返回 列名数组,结果map,错误
 | 
							} else if d.Type == entity.DbTypePostgres {
 | 
				
			||||||
func (d *DbInstance) SelectData(execSql string) ([]string, []map[string]interface{}, error) {
 | 
								_, err := pq.DialOpen(&PqSqlDialer{sshTunnelMachine: sshTunnelMachine}, getDsn(d, db))
 | 
				
			||||||
	execSql = strings.Trim(execSql, " ")
 | 
								if err != nil {
 | 
				
			||||||
	isSelect := strings.HasPrefix(execSql, "SELECT") || strings.HasPrefix(execSql, "select")
 | 
									panic(biz.NewBizErr(fmt.Sprintf("postgres隧道连接失败: %s", err.Error())))
 | 
				
			||||||
	isShow := strings.HasPrefix(execSql, "show")
 | 
								}
 | 
				
			||||||
	isExplain := strings.HasPrefix(execSql, "explain")
 | 
							}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if !isSelect && !isShow && !isExplain {
 | 
					 | 
				
			||||||
		return nil, nil, errors.New("该sql非查询语句")
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rows, err := d.db.Query(execSql)
 | 
						DB, err := sql.Open(d.Type, getDsn(d, db))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						err = DB.Ping()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							DB.Close()
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return DB, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func SelectDataByDb(db *sql.DB, selectSql string) ([]string, []map[string]interface{}, error) {
 | 
				
			||||||
 | 
						rows, err := db.Query(selectSql)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, nil, err
 | 
							return nil, nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -257,7 +319,11 @@ func (d *DbInstance) SelectData(execSql string) ([]string, []map[string]interfac
 | 
				
			|||||||
	colNames := make([]string, 0)
 | 
						colNames := make([]string, 0)
 | 
				
			||||||
	// 是否第一次遍历,列名数组只需第一次遍历时加入
 | 
						// 是否第一次遍历,列名数组只需第一次遍历时加入
 | 
				
			||||||
	isFirst := true
 | 
						isFirst := true
 | 
				
			||||||
 | 
						rowNum := 0
 | 
				
			||||||
	for rows.Next() {
 | 
						for rows.Next() {
 | 
				
			||||||
 | 
							rowNum++
 | 
				
			||||||
 | 
							biz.IsTrue(rowNum <= Max_Rows, "结果集 > 2000, 请完善条件或分页信息")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 不Scan也会导致等待,该链接实际处于未工作的状态,然后也会导致连接数迅速达到最大
 | 
							// 不Scan也会导致等待,该链接实际处于未工作的状态,然后也会导致连接数迅速达到最大
 | 
				
			||||||
		err := rows.Scan(scans...)
 | 
							err := rows.Scan(scans...)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
@@ -271,6 +337,7 @@ func (d *DbInstance) SelectData(execSql string) ([]string, []map[string]interfac
 | 
				
			|||||||
			colName := colType.Name()
 | 
								colName := colType.Name()
 | 
				
			||||||
			// 字段类型名
 | 
								// 字段类型名
 | 
				
			||||||
			colScanType := colType.ScanType().Name()
 | 
								colScanType := colType.ScanType().Name()
 | 
				
			||||||
 | 
								// 如果是第一行,则将列名加入到列信息中,由于map是无序的,所有需要返回列名的有序数组
 | 
				
			||||||
			if isFirst {
 | 
								if isFirst {
 | 
				
			||||||
				colNames = append(colNames, colName)
 | 
									colNames = append(colNames, colName)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@@ -316,6 +383,37 @@ func (d *DbInstance) SelectData(execSql string) ([]string, []map[string]interfac
 | 
				
			|||||||
	return colNames, result, nil
 | 
						return colNames, result, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type PqSqlDialer struct {
 | 
				
			||||||
 | 
						sshTunnelMachine *machine.SshTunnelMachine
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (pd *PqSqlDialer) Dial(network, address string) (net.Conn, error) {
 | 
				
			||||||
 | 
						if sshConn, err := pd.sshTunnelMachine.GetDialConn("tcp", address); err == nil {
 | 
				
			||||||
 | 
							// 将ssh conn包装,否则redis内部设置超时会报错,ssh conn不支持设置超时会返回错误: ssh: tcpChan: deadline not supported
 | 
				
			||||||
 | 
							return &utils.WrapSshConn{Conn: sshConn}, nil
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					func (pd *PqSqlDialer) DialTimeout(network, address string, timeout time.Duration) (net.Conn, error) {
 | 
				
			||||||
 | 
						return pd.Dial(network, address)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// db实例
 | 
				
			||||||
 | 
					type DbInstance struct {
 | 
				
			||||||
 | 
						Id                 string
 | 
				
			||||||
 | 
						Type               string
 | 
				
			||||||
 | 
						ProjectId          uint64
 | 
				
			||||||
 | 
						db                 *sql.DB
 | 
				
			||||||
 | 
						sshTunnelMachineId uint64
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 执行查询语句
 | 
				
			||||||
 | 
					// 依次返回 列名数组,结果map,错误
 | 
				
			||||||
 | 
					func (d *DbInstance) SelectData(execSql string) ([]string, []map[string]interface{}, error) {
 | 
				
			||||||
 | 
						return SelectDataByDb(d.db, execSql)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 执行 update, insert, delete,建表等sql
 | 
					// 执行 update, insert, delete,建表等sql
 | 
				
			||||||
// 返回影响条数和错误
 | 
					// 返回影响条数和错误
 | 
				
			||||||
func (d *DbInstance) Exec(sql string) (int64, error) {
 | 
					func (d *DbInstance) Exec(sql string) (int64, error) {
 | 
				
			||||||
@@ -326,24 +424,41 @@ func (d *DbInstance) Exec(sql string) (int64, error) {
 | 
				
			|||||||
	return res.RowsAffected()
 | 
						return res.RowsAffected()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取数据库元信息实现接口
 | 
				
			||||||
 | 
					func (di *DbInstance) GetMeta() DbMetadata {
 | 
				
			||||||
 | 
						dbType := di.Type
 | 
				
			||||||
 | 
						if dbType == entity.DbTypeMysql {
 | 
				
			||||||
 | 
							return &MysqlMetadata{di: di}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if dbType == entity.DbTypePostgres {
 | 
				
			||||||
 | 
							return &PgsqlMetadata{di: di}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 关闭连接
 | 
					// 关闭连接
 | 
				
			||||||
func (d *DbInstance) Close() {
 | 
					func (d *DbInstance) Close() {
 | 
				
			||||||
	d.db.Close()
 | 
						if d.db != nil {
 | 
				
			||||||
 | 
							if err := d.db.Close(); err != nil {
 | 
				
			||||||
 | 
								global.Log.Errorf("关闭数据库实例[%s]连接失败: %s", d.Id, err.Error())
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							d.db = nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 获取dataSourceName
 | 
					// 获取dataSourceName
 | 
				
			||||||
func getDsn(d *entity.Db) string {
 | 
					func getDsn(d *entity.Db, db string) string {
 | 
				
			||||||
	var dsn string
 | 
						var dsn string
 | 
				
			||||||
	if d.Type == "mysql" {
 | 
						if d.Type == entity.DbTypeMysql {
 | 
				
			||||||
		dsn = fmt.Sprintf("%s:%s@%s(%s:%d)/%s?timeout=8s", 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, db)
 | 
				
			||||||
		if d.Params != "" {
 | 
							if d.Params != "" {
 | 
				
			||||||
			dsn = fmt.Sprintf("%s&%s", dsn, d.Params)
 | 
								dsn = fmt.Sprintf("%s&%s", dsn, d.Params)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return dsn
 | 
							return dsn
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if d.Type == "postgres" {
 | 
						if d.Type == entity.DbTypePostgres {
 | 
				
			||||||
		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)
 | 
							dsn = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", d.Host, d.Port, d.Username, d.Password, db)
 | 
				
			||||||
		if d.Params != "" {
 | 
							if d.Params != "" {
 | 
				
			||||||
			dsn = fmt.Sprintf("%s %s", dsn, strings.Join(strings.Split(d.Params, "&"), " "))
 | 
								dsn = fmt.Sprintf("%s %s", dsn, strings.Join(strings.Split(d.Params, "&"), " "))
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -357,8 +472,32 @@ func CloseDb(dbId uint64, db string) {
 | 
				
			|||||||
	dbCache.Delete(GetDbCacheKey(dbId, db))
 | 
						dbCache.Delete(GetDbCacheKey(dbId, db))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//-----------------------------------元数据-------------------------------------------
 | 
					// -----------------------------------元数据-------------------------------------------
 | 
				
			||||||
 | 
					// 数据库元信息接口(表、列等元信息)
 | 
				
			||||||
 | 
					type DbMetadata interface {
 | 
				
			||||||
 | 
						// 获取表基础元信息, 如表名等
 | 
				
			||||||
 | 
						GetTables() []map[string]interface{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 获取列元信息, 如列名等
 | 
				
			||||||
 | 
						GetColumns(tableNames ...string) []map[string]interface{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 获取表主键字段名,默认第一个字段
 | 
				
			||||||
 | 
						GetPrimaryKey(tablename string) string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 获取表信息,比GetTables获取更详细的表信息
 | 
				
			||||||
 | 
						GetTableInfos() []map[string]interface{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 获取表索引信息
 | 
				
			||||||
 | 
						GetTableIndex(tableName string) []map[string]interface{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 获取建表ddl
 | 
				
			||||||
 | 
						GetCreateTableDdl(tableName string) []map[string]interface{}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 默认每次查询列元信息数量
 | 
				
			||||||
 | 
					const DEFAULT_COLUMN_SIZE = 2000
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ---------------------------------- mysql元数据 -----------------------------------
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	// mysql 表信息元数据
 | 
						// mysql 表信息元数据
 | 
				
			||||||
	MYSQL_TABLE_MA = `SELECT table_name tableName, engine, table_comment tableComment, 
 | 
						MYSQL_TABLE_MA = `SELECT table_name tableName, engine, table_comment tableComment, 
 | 
				
			||||||
@@ -377,9 +516,6 @@ const (
 | 
				
			|||||||
	FROM information_schema.STATISTICS 
 | 
						FROM information_schema.STATISTICS 
 | 
				
			||||||
    WHERE table_schema = (SELECT database()) AND table_name = '%s' LIMIT 500`
 | 
					    WHERE table_schema = (SELECT database()) AND table_name = '%s' LIMIT 500`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 默认每次查询列元信息数量
 | 
					 | 
				
			||||||
	DEFAULT_COLUMN_SIZE = 2000
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// mysql 列信息元数据
 | 
						// mysql 列信息元数据
 | 
				
			||||||
	MYSQL_COLUMN_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
 | 
						column_comment columnComment, column_key columnKey, extra, is_nullable nullable from information_schema.columns
 | 
				
			||||||
@@ -390,6 +526,80 @@ const (
 | 
				
			|||||||
	WHERE table_name in (%s) AND table_schema = (SELECT database())`
 | 
						WHERE table_name in (%s) AND table_schema = (SELECT database())`
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type MysqlMetadata struct {
 | 
				
			||||||
 | 
						di *DbInstance
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取表基础元信息, 如表名等
 | 
				
			||||||
 | 
					func (mm *MysqlMetadata) GetTables() []map[string]interface{} {
 | 
				
			||||||
 | 
						_, res, _ := mm.di.SelectData(MYSQL_TABLE_MA)
 | 
				
			||||||
 | 
						return res
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取列元信息, 如列名等
 | 
				
			||||||
 | 
					func (mm *MysqlMetadata) GetColumns(tableNames ...string) []map[string]interface{} {
 | 
				
			||||||
 | 
						var sql, tableName string
 | 
				
			||||||
 | 
						for i := 0; i < len(tableNames); i++ {
 | 
				
			||||||
 | 
							if i != 0 {
 | 
				
			||||||
 | 
								tableName = tableName + ", "
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							tableName = tableName + "'" + tableNames[i] + "'"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pageNum := 1
 | 
				
			||||||
 | 
						// 如果大于一个表,则统计列数并分页获取
 | 
				
			||||||
 | 
						if len(tableNames) > 1 {
 | 
				
			||||||
 | 
							countSql := fmt.Sprintf(MYSQL_COLOUMN_MA_COUNT, tableName)
 | 
				
			||||||
 | 
							_, countRes, _ := mm.di.SelectData(countSql)
 | 
				
			||||||
 | 
							maCount := 0
 | 
				
			||||||
 | 
							// 查询出所有列信息总数,手动分页获取所有数据
 | 
				
			||||||
 | 
							if count64, is64 := countRes[0]["maNum"].(int64); is64 {
 | 
				
			||||||
 | 
								maCount = int(count64)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								maCount = countRes[0]["maNum"].(int)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// 计算需要查询的页数
 | 
				
			||||||
 | 
							pageNum = maCount / DEFAULT_COLUMN_SIZE
 | 
				
			||||||
 | 
							if maCount%DEFAULT_COLUMN_SIZE > 0 {
 | 
				
			||||||
 | 
								pageNum++
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						res := make([]map[string]interface{}, 0)
 | 
				
			||||||
 | 
						for index := 0; index < pageNum; index++ {
 | 
				
			||||||
 | 
							sql = fmt.Sprintf(MYSQL_COLUMN_MA, tableName, index*DEFAULT_COLUMN_SIZE, DEFAULT_COLUMN_SIZE)
 | 
				
			||||||
 | 
							_, result, err := mm.di.SelectData(sql)
 | 
				
			||||||
 | 
							biz.ErrIsNilAppendErr(err, "获取数据库列信息失败: %s")
 | 
				
			||||||
 | 
							res = append(res, result...)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return res
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取表主键字段名,默认第一个字段
 | 
				
			||||||
 | 
					func (mm *MysqlMetadata) GetPrimaryKey(tablename string) string {
 | 
				
			||||||
 | 
						return mm.GetColumns(tablename)[0]["columnName"].(string)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取表信息,比GetTableMetedatas获取更详细的表信息
 | 
				
			||||||
 | 
					func (mm *MysqlMetadata) GetTableInfos() []map[string]interface{} {
 | 
				
			||||||
 | 
						_, res, _ := mm.di.SelectData(MYSQL_TABLE_INFO)
 | 
				
			||||||
 | 
						return res
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取表索引信息
 | 
				
			||||||
 | 
					func (mm *MysqlMetadata) GetTableIndex(tableName string) []map[string]interface{} {
 | 
				
			||||||
 | 
						_, res, _ := mm.di.SelectData(MYSQL_INDEX_INFO)
 | 
				
			||||||
 | 
						return res
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取建表ddl
 | 
				
			||||||
 | 
					func (mm *MysqlMetadata) GetCreateTableDdl(tableName string) []map[string]interface{} {
 | 
				
			||||||
 | 
						_, res, _ := mm.di.SelectData(fmt.Sprintf("show create table %s ", tableName))
 | 
				
			||||||
 | 
						return res
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ---------------------------------- pgsql元数据 -----------------------------------
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	// postgres 表信息元数据
 | 
						// postgres 表信息元数据
 | 
				
			||||||
	PGSQL_TABLE_MA = `SELECT obj_description(c.oid) AS "tableComment", c.relname AS "tableName" FROM pg_class c 
 | 
						PGSQL_TABLE_MA = `SELECT obj_description(c.oid) AS "tableComment", c.relname AS "tableName" FROM pg_class c 
 | 
				
			||||||
@@ -436,18 +646,18 @@ const (
 | 
				
			|||||||
	`
 | 
						`
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *DbInstance) GetTableMetedatas() []map[string]interface{} {
 | 
					type PgsqlMetadata struct {
 | 
				
			||||||
	var sql string
 | 
						di *DbInstance
 | 
				
			||||||
	if d.Type == "mysql" {
 | 
					}
 | 
				
			||||||
		sql = MYSQL_TABLE_MA
 | 
					
 | 
				
			||||||
	} else if d.Type == "postgres" {
 | 
					// 获取表基础元信息, 如表名等
 | 
				
			||||||
		sql = PGSQL_TABLE_MA
 | 
					func (pm *PgsqlMetadata) GetTables() []map[string]interface{} {
 | 
				
			||||||
	}
 | 
						_, res, _ := pm.di.SelectData(PGSQL_TABLE_MA)
 | 
				
			||||||
	_, res, _ := d.SelectData(sql)
 | 
					 | 
				
			||||||
	return res
 | 
						return res
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *DbInstance) GetColumnMetadatas(tableNames ...string) []map[string]interface{} {
 | 
					// 获取列元信息, 如列名等
 | 
				
			||||||
 | 
					func (pm *PgsqlMetadata) GetColumns(tableNames ...string) []map[string]interface{} {
 | 
				
			||||||
	var sql, tableName string
 | 
						var sql, tableName string
 | 
				
			||||||
	for i := 0; i < len(tableNames); i++ {
 | 
						for i := 0; i < len(tableNames); i++ {
 | 
				
			||||||
		if i != 0 {
 | 
							if i != 0 {
 | 
				
			||||||
@@ -456,68 +666,53 @@ func (d *DbInstance) GetColumnMetadatas(tableNames ...string) []map[string]inter
 | 
				
			|||||||
		tableName = tableName + "'" + tableNames[i] + "'"
 | 
							tableName = tableName + "'" + tableNames[i] + "'"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var countSqlTmp string
 | 
						pageNum := 1
 | 
				
			||||||
	var sqlTmp string
 | 
						// 如果大于一个表,则统计列数并分页获取
 | 
				
			||||||
	if d.Type == "mysql" {
 | 
						if len(tableNames) > 1 {
 | 
				
			||||||
		countSqlTmp = MYSQL_COLOUMN_MA_COUNT
 | 
							countSql := fmt.Sprintf(PGSQL_COLUMN_MA_COUNT, tableName)
 | 
				
			||||||
		sqlTmp = MYSQL_COLUMN_MA
 | 
							_, countRes, _ := pm.di.SelectData(countSql)
 | 
				
			||||||
	} else if d.Type == "postgres" {
 | 
							maCount := 0
 | 
				
			||||||
		countSqlTmp = PGSQL_COLUMN_MA_COUNT
 | 
							// 查询出所有列信息总数,手动分页获取所有数据
 | 
				
			||||||
		sqlTmp = PGSQL_COLUMN_MA
 | 
							if count64, is64 := countRes[0]["maNum"].(int64); is64 {
 | 
				
			||||||
	}
 | 
								maCount = int(count64)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
	countSql := fmt.Sprintf(countSqlTmp, tableName)
 | 
								maCount = countRes[0]["maNum"].(int)
 | 
				
			||||||
	_, countRes, _ := d.SelectData(countSql)
 | 
							}
 | 
				
			||||||
	// 查询出所有列信息总数,手动分页获取所有数据
 | 
							// 计算需要查询的页数
 | 
				
			||||||
	maCount := int(countRes[0]["maNum"].(int64))
 | 
							pageNum = maCount / DEFAULT_COLUMN_SIZE
 | 
				
			||||||
	// 计算需要查询的页数
 | 
							if maCount%DEFAULT_COLUMN_SIZE > 0 {
 | 
				
			||||||
	pageNum := maCount / DEFAULT_COLUMN_SIZE
 | 
								pageNum++
 | 
				
			||||||
	if maCount%DEFAULT_COLUMN_SIZE > 0 {
 | 
							}
 | 
				
			||||||
		pageNum++
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	res := make([]map[string]interface{}, 0)
 | 
						res := make([]map[string]interface{}, 0)
 | 
				
			||||||
	for index := 0; index < pageNum; index++ {
 | 
						for index := 0; index < pageNum; index++ {
 | 
				
			||||||
		sql = fmt.Sprintf(sqlTmp, tableName, index*DEFAULT_COLUMN_SIZE, DEFAULT_COLUMN_SIZE)
 | 
							sql = fmt.Sprintf(PGSQL_COLUMN_MA, tableName, index*DEFAULT_COLUMN_SIZE, DEFAULT_COLUMN_SIZE)
 | 
				
			||||||
		_, result, err := d.SelectData(sql)
 | 
							_, result, err := pm.di.SelectData(sql)
 | 
				
			||||||
		biz.ErrIsNilAppendErr(err, "获取数据库列信息失败: %s")
 | 
							biz.ErrIsNilAppendErr(err, "获取数据库列信息失败: %s")
 | 
				
			||||||
		res = append(res, result...)
 | 
							res = append(res, result...)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return res
 | 
						return res
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 获取表的主键,目前默认第一列为主键
 | 
					// 获取表主键字段名,默认第一个字段
 | 
				
			||||||
func (d *DbInstance) GetPrimaryKey(tablename string) string {
 | 
					func (pm *PgsqlMetadata) GetPrimaryKey(tablename string) string {
 | 
				
			||||||
	return d.GetColumnMetadatas(tablename)[0]["columnName"].(string)
 | 
						return pm.GetColumns(tablename)[0]["columnName"].(string)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *DbInstance) GetTableInfos() []map[string]interface{} {
 | 
					// 获取表信息,比GetTables获取更详细的表信息
 | 
				
			||||||
	var sql string
 | 
					func (pm *PgsqlMetadata) GetTableInfos() []map[string]interface{} {
 | 
				
			||||||
	if d.Type == "mysql" {
 | 
						_, res, _ := pm.di.SelectData(PGSQL_TABLE_INFO)
 | 
				
			||||||
		sql = MYSQL_TABLE_INFO
 | 
					 | 
				
			||||||
	} else if d.Type == "postgres" {
 | 
					 | 
				
			||||||
		sql = PGSQL_TABLE_INFO
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	_, res, _ := d.SelectData(sql)
 | 
					 | 
				
			||||||
	return res
 | 
						return res
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *DbInstance) GetTableIndex(tableName string) []map[string]interface{} {
 | 
					// 获取表索引信息
 | 
				
			||||||
	var sql string
 | 
					func (pm *PgsqlMetadata) GetTableIndex(tableName string) []map[string]interface{} {
 | 
				
			||||||
	if d.Type == "mysql" {
 | 
						_, res, _ := pm.di.SelectData(PGSQL_INDEX_INFO)
 | 
				
			||||||
		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
 | 
						return res
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *DbInstance) GetCreateTableDdl(tableName string) []map[string]interface{} {
 | 
					// 获取建表ddl
 | 
				
			||||||
	var sql string
 | 
					func (mm *PgsqlMetadata) GetCreateTableDdl(tableName string) []map[string]interface{} {
 | 
				
			||||||
	if d.Type == "mysql" {
 | 
						return nil
 | 
				
			||||||
		sql = fmt.Sprintf("show create table %s ", tableName)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	_, res, _ := d.SelectData(sql)
 | 
					 | 
				
			||||||
	return res
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										200
									
								
								server/internal/db/application/db_sql_exec.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										200
									
								
								server/internal/db/application/db_sql_exec.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,200 @@
 | 
				
			|||||||
 | 
					package application
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"mayfly-go/internal/db/domain/entity"
 | 
				
			||||||
 | 
						"mayfly-go/internal/db/domain/repository"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/global"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/xwb1989/sqlparser"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type DbSqlExecReq struct {
 | 
				
			||||||
 | 
						DbId         uint64
 | 
				
			||||||
 | 
						Db           string
 | 
				
			||||||
 | 
						Sql          string
 | 
				
			||||||
 | 
						Remark       string
 | 
				
			||||||
 | 
						LoginAccount *model.LoginAccount
 | 
				
			||||||
 | 
						DbInstance   *DbInstance
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type DbSqlExecRes struct {
 | 
				
			||||||
 | 
						ColNames []string
 | 
				
			||||||
 | 
						Res      []map[string]interface{}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type DbSqlExec interface {
 | 
				
			||||||
 | 
						// 执行sql
 | 
				
			||||||
 | 
						Exec(execSqlReq *DbSqlExecReq) (*DbSqlExecRes, error)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 根据条件删除sql执行记录
 | 
				
			||||||
 | 
						DeleteBy(condition *entity.DbSqlExec)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 分页获取
 | 
				
			||||||
 | 
						GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func newDbSqlExecApp(dbExecSqlRepo repository.DbSqlExec) DbSqlExec {
 | 
				
			||||||
 | 
						return &dbSqlExecAppImpl{
 | 
				
			||||||
 | 
							dbSqlExecRepo: dbExecSqlRepo,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type dbSqlExecAppImpl struct {
 | 
				
			||||||
 | 
						dbSqlExecRepo repository.DbSqlExec
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (d *dbSqlExecAppImpl) Exec(execSqlReq *DbSqlExecReq) (*DbSqlExecRes, error) {
 | 
				
			||||||
 | 
						sql := execSqlReq.Sql
 | 
				
			||||||
 | 
						loginAccount := execSqlReq.LoginAccount
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 如果是pgsql并且为查询语句,则直接返回,sqlparser不支持解析pgsql select语句
 | 
				
			||||||
 | 
						if execSqlReq.DbInstance.Type == entity.DbTypePostgres && (strings.HasPrefix(sql, "SELECT") || strings.HasPrefix(sql, "select")) {
 | 
				
			||||||
 | 
							return doSelect(nil, execSqlReq, nil)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						stmt, err := sqlparser.Parse(sql)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							global.Log.Error("sql解析失败: ", err)
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						dbSqlExecRecord := new(entity.DbSqlExec)
 | 
				
			||||||
 | 
						dbSqlExecRecord.DbId = execSqlReq.DbId
 | 
				
			||||||
 | 
						dbSqlExecRecord.Db = execSqlReq.Db
 | 
				
			||||||
 | 
						dbSqlExecRecord.Sql = sql
 | 
				
			||||||
 | 
						dbSqlExecRecord.Remark = execSqlReq.Remark
 | 
				
			||||||
 | 
						dbSqlExecRecord.SetBaseInfo(loginAccount)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var execRes *DbSqlExecRes
 | 
				
			||||||
 | 
						isSelect := false
 | 
				
			||||||
 | 
						switch stmt := stmt.(type) {
 | 
				
			||||||
 | 
						case *sqlparser.Select:
 | 
				
			||||||
 | 
							isSelect = true
 | 
				
			||||||
 | 
							execRes, err = doSelect(stmt, execSqlReq, dbSqlExecRecord)
 | 
				
			||||||
 | 
						case *sqlparser.Show:
 | 
				
			||||||
 | 
							isSelect = true
 | 
				
			||||||
 | 
							execRes, err = doSelect(nil, execSqlReq, dbSqlExecRecord)
 | 
				
			||||||
 | 
						case *sqlparser.OtherRead:
 | 
				
			||||||
 | 
							isSelect = true
 | 
				
			||||||
 | 
							execRes, err = doSelect(nil, execSqlReq, dbSqlExecRecord)
 | 
				
			||||||
 | 
						case *sqlparser.Update:
 | 
				
			||||||
 | 
							execRes, err = doUpdate(stmt, execSqlReq, dbSqlExecRecord)
 | 
				
			||||||
 | 
						case *sqlparser.Delete:
 | 
				
			||||||
 | 
							execRes, err = doDelete(stmt, execSqlReq, dbSqlExecRecord)
 | 
				
			||||||
 | 
						case *sqlparser.Insert:
 | 
				
			||||||
 | 
							execRes, err = doInsert(stmt, execSqlReq, dbSqlExecRecord)
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							execRes, err = doExec(execSqlReq.Sql, execSqlReq.DbInstance)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !isSelect {
 | 
				
			||||||
 | 
							// 保存执行记录
 | 
				
			||||||
 | 
							d.dbSqlExecRepo.Insert(dbSqlExecRecord)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return execRes, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (d *dbSqlExecAppImpl) DeleteBy(condition *entity.DbSqlExec) {
 | 
				
			||||||
 | 
						d.dbSqlExecRepo.DeleteBy(condition)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (d *dbSqlExecAppImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
				
			||||||
 | 
						return d.dbSqlExecRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func doSelect(selectStmt *sqlparser.Select, execSqlReq *DbSqlExecReq, dbSqlExec *entity.DbSqlExec) (*DbSqlExecRes, error) {
 | 
				
			||||||
 | 
						dbInstance := execSqlReq.DbInstance
 | 
				
			||||||
 | 
						sql := execSqlReq.Sql
 | 
				
			||||||
 | 
						colNames, res, err := dbInstance.SelectData(sql)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return &DbSqlExecRes{
 | 
				
			||||||
 | 
							ColNames: colNames,
 | 
				
			||||||
 | 
							Res:      res,
 | 
				
			||||||
 | 
						}, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func doUpdate(update *sqlparser.Update, execSqlReq *DbSqlExecReq, dbSqlExec *entity.DbSqlExec) (*DbSqlExecRes, error) {
 | 
				
			||||||
 | 
						dbInstance := execSqlReq.DbInstance
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tableStr := sqlparser.String(update.TableExprs)
 | 
				
			||||||
 | 
						// 可能使用别名,故空格切割
 | 
				
			||||||
 | 
						tableName := strings.Split(tableStr, " ")[0]
 | 
				
			||||||
 | 
						where := sqlparser.String(update.Where)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						updateExprs := update.Exprs
 | 
				
			||||||
 | 
						updateColumns := make([]string, 0)
 | 
				
			||||||
 | 
						for _, v := range updateExprs {
 | 
				
			||||||
 | 
							updateColumns = append(updateColumns, v.Name.Name.String())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 获取表主键列名,排除使用别名
 | 
				
			||||||
 | 
						primaryKey := dbInstance.GetMeta().GetPrimaryKey(tableName)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						updateColumnsAndPrimaryKey := strings.Join(updateColumns, ",") + "," + primaryKey
 | 
				
			||||||
 | 
						// 查询要更新字段数据的旧值,以及主键值
 | 
				
			||||||
 | 
						selectSql := fmt.Sprintf("SELECT %s FROM %s %s LIMIT 200", updateColumnsAndPrimaryKey, tableStr, where)
 | 
				
			||||||
 | 
						_, res, _ := dbInstance.SelectData(selectSql)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bytes, _ := json.Marshal(res)
 | 
				
			||||||
 | 
						dbSqlExec.OldValue = string(bytes)
 | 
				
			||||||
 | 
						dbSqlExec.Table = tableName
 | 
				
			||||||
 | 
						dbSqlExec.Type = entity.DbSqlExecTypeUpdate
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return doExec(execSqlReq.Sql, dbInstance)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func doDelete(delete *sqlparser.Delete, execSqlReq *DbSqlExecReq, dbSqlExec *entity.DbSqlExec) (*DbSqlExecRes, error) {
 | 
				
			||||||
 | 
						dbInstance := execSqlReq.DbInstance
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tableStr := sqlparser.String(delete.TableExprs)
 | 
				
			||||||
 | 
						// 可能使用别名,故空格切割
 | 
				
			||||||
 | 
						table := strings.Split(tableStr, " ")[0]
 | 
				
			||||||
 | 
						where := sqlparser.String(delete.Where)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 查询删除数据
 | 
				
			||||||
 | 
						selectSql := fmt.Sprintf("SELECT * FROM %s %s LIMIT 200", tableStr, where)
 | 
				
			||||||
 | 
						_, res, _ := dbInstance.SelectData(selectSql)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bytes, _ := json.Marshal(res)
 | 
				
			||||||
 | 
						dbSqlExec.OldValue = string(bytes)
 | 
				
			||||||
 | 
						dbSqlExec.Table = table
 | 
				
			||||||
 | 
						dbSqlExec.Type = entity.DbSqlExecTypeDelete
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return doExec(execSqlReq.Sql, dbInstance)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func doInsert(insert *sqlparser.Insert, execSqlReq *DbSqlExecReq, dbSqlExec *entity.DbSqlExec) (*DbSqlExecRes, error) {
 | 
				
			||||||
 | 
						tableStr := sqlparser.String(insert.Table)
 | 
				
			||||||
 | 
						// 可能使用别名,故空格切割
 | 
				
			||||||
 | 
						table := strings.Split(tableStr, " ")[0]
 | 
				
			||||||
 | 
						dbSqlExec.Table = table
 | 
				
			||||||
 | 
						dbSqlExec.Type = entity.DbSqlExecTypeInsert
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return doExec(execSqlReq.Sql, execSqlReq.DbInstance)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func doExec(sql string, dbInstance *DbInstance) (*DbSqlExecRes, error) {
 | 
				
			||||||
 | 
						rowsAffected, err := dbInstance.Exec(sql)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						res := make([]map[string]interface{}, 0)
 | 
				
			||||||
 | 
						resData := make(map[string]interface{})
 | 
				
			||||||
 | 
						resData["影响条数"] = rowsAffected
 | 
				
			||||||
 | 
						res = append(res, resData)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return &DbSqlExecRes{
 | 
				
			||||||
 | 
							ColNames: []string{"影响条数"},
 | 
				
			||||||
 | 
							Res:      res,
 | 
				
			||||||
 | 
						}, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										56
									
								
								server/internal/db/domain/entity/db.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								server/internal/db/domain/entity/db.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,56 @@
 | 
				
			|||||||
 | 
					package entity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"mayfly-go/internal/common/utils"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Db struct {
 | 
				
			||||||
 | 
						model.Model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Name      string `orm:"column(name)" json:"name"`
 | 
				
			||||||
 | 
						Type      string `orm:"column(type)" json:"type"` // 类型,mysql oracle等
 | 
				
			||||||
 | 
						Host      string `orm:"column(host)" json:"host"`
 | 
				
			||||||
 | 
						Port      int    `orm:"column(port)" json:"port"`
 | 
				
			||||||
 | 
						Network   string `orm:"column(network)" json:"network"`
 | 
				
			||||||
 | 
						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
 | 
				
			||||||
 | 
						Env       string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						EnableSshTunnel    int8   `orm:"column(enable_ssh_tunnel)" json:"enableSshTunnel"`        // 是否启用ssh隧道
 | 
				
			||||||
 | 
						SshTunnelMachineId uint64 `orm:"column(ssh_tunnel_machine_id)" json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取数据库连接网络, 若没有使用ssh隧道,则直接返回。否则返回拼接的网络需要注册至指定dial
 | 
				
			||||||
 | 
					func (d *Db) GetNetwork() string {
 | 
				
			||||||
 | 
						network := d.Network
 | 
				
			||||||
 | 
						if d.EnableSshTunnel == 0 || d.EnableSshTunnel == -1 {
 | 
				
			||||||
 | 
							if network == "" {
 | 
				
			||||||
 | 
								return "tcp"
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								return network
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return fmt.Sprintf("%s+ssh:%d", d.Type, d.SshTunnelMachineId)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (d *Db) PwdEncrypt() {
 | 
				
			||||||
 | 
						// 密码替换为加密后的密码
 | 
				
			||||||
 | 
						d.Password = utils.PwdAesEncrypt(d.Password)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (d *Db) PwdDecrypt() {
 | 
				
			||||||
 | 
						// 密码替换为解密后的密码
 | 
				
			||||||
 | 
						d.Password = utils.PwdAesDecrypt(d.Password)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						DbTypeMysql    = "mysql"
 | 
				
			||||||
 | 
						DbTypePostgres = "postgres"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
package repository
 | 
					package repository
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"mayfly-go/internal/devops/domain/entity"
 | 
						"mayfly-go/internal/db/domain/entity"
 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
package repository
 | 
					package repository
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import "mayfly-go/internal/devops/domain/entity"
 | 
					import "mayfly-go/internal/db/domain/entity"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type DbSql interface {
 | 
					type DbSql interface {
 | 
				
			||||||
	DeleteBy(condition *entity.DbSql)
 | 
						DeleteBy(condition *entity.DbSql)
 | 
				
			||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
package repository
 | 
					package repository
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"mayfly-go/internal/devops/domain/entity"
 | 
						"mayfly-go/internal/db/domain/entity"
 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -2,18 +2,20 @@ package persistence
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"mayfly-go/internal/devops/domain/entity"
 | 
						"mayfly-go/internal/db/domain/entity"
 | 
				
			||||||
	"mayfly-go/internal/devops/domain/repository"
 | 
						"mayfly-go/internal/db/domain/repository"
 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type dbRepo struct{}
 | 
					type dbRepoImpl struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var DbDao repository.Db = &dbRepo{}
 | 
					func newDbRepo() repository.Db {
 | 
				
			||||||
 | 
						return new(dbRepoImpl)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 分页获取数据库信息列表
 | 
					// 分页获取数据库信息列表
 | 
				
			||||||
func (d *dbRepo) GetDbList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					func (d *dbRepoImpl) GetDbList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
				
			||||||
	sql := "SELECT d.* FROM t_db d JOIN t_project_member pm ON d.project_id = pm.project_id WHERE 1 = 1 "
 | 
						sql := "SELECT d.* FROM t_db d JOIN t_project_member pm ON d.project_id = pm.project_id WHERE 1 = 1 "
 | 
				
			||||||
	if condition.CreatorId != 0 {
 | 
						if condition.CreatorId != 0 {
 | 
				
			||||||
		// 使用创建者id模拟项目成员id
 | 
							// 使用创建者id模拟项目成员id
 | 
				
			||||||
@@ -35,17 +37,17 @@ func (d *dbRepo) GetDbList(condition *entity.Db, pageParam *model.PageParam, toE
 | 
				
			|||||||
	return model.GetPageBySql(sql, pageParam, toEntity)
 | 
						return model.GetPageBySql(sql, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *dbRepo) Count(condition *entity.Db) int64 {
 | 
					func (d *dbRepoImpl) Count(condition *entity.Db) int64 {
 | 
				
			||||||
	return model.CountBy(condition)
 | 
						return model.CountBy(condition)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 根据条件获取账号信息
 | 
					// 根据条件获取账号信息
 | 
				
			||||||
func (d *dbRepo) GetDb(condition *entity.Db, cols ...string) error {
 | 
					func (d *dbRepoImpl) GetDb(condition *entity.Db, cols ...string) error {
 | 
				
			||||||
	return model.GetBy(condition, cols...)
 | 
						return model.GetBy(condition, cols...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 根据id获取
 | 
					// 根据id获取
 | 
				
			||||||
func (d *dbRepo) GetById(id uint64, cols ...string) *entity.Db {
 | 
					func (d *dbRepoImpl) GetById(id uint64, cols ...string) *entity.Db {
 | 
				
			||||||
	db := new(entity.Db)
 | 
						db := new(entity.Db)
 | 
				
			||||||
	if err := model.GetById(db, id, cols...); err != nil {
 | 
						if err := model.GetById(db, id, cols...); err != nil {
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
@@ -54,14 +56,14 @@ func (d *dbRepo) GetById(id uint64, cols ...string) *entity.Db {
 | 
				
			|||||||
	return db
 | 
						return db
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *dbRepo) Insert(db *entity.Db) {
 | 
					func (d *dbRepoImpl) Insert(db *entity.Db) {
 | 
				
			||||||
	biz.ErrIsNil(model.Insert(db), "新增数据库信息失败")
 | 
						biz.ErrIsNil(model.Insert(db), "新增数据库信息失败")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *dbRepo) Update(db *entity.Db) {
 | 
					func (d *dbRepoImpl) Update(db *entity.Db) {
 | 
				
			||||||
	biz.ErrIsNil(model.UpdateById(db), "更新数据库信息失败")
 | 
						biz.ErrIsNil(model.UpdateById(db), "更新数据库信息失败")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *dbRepo) Delete(id uint64) {
 | 
					func (d *dbRepoImpl) Delete(id uint64) {
 | 
				
			||||||
	model.DeleteById(new(entity.Db), id)
 | 
						model.DeleteById(new(entity.Db), id)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										19
									
								
								server/internal/db/infrastructure/persistence/db_sql.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								server/internal/db/infrastructure/persistence/db_sql.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					package persistence
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"mayfly-go/internal/db/domain/entity"
 | 
				
			||||||
 | 
						"mayfly-go/internal/db/domain/repository"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type dbSqlRepoImpl struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func newDbSqlRepo() repository.DbSql {
 | 
				
			||||||
 | 
						return new(dbSqlRepoImpl)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 分页获取数据库信息列表
 | 
				
			||||||
 | 
					func (d *dbSqlRepoImpl) DeleteBy(condition *entity.DbSql) {
 | 
				
			||||||
 | 
						biz.ErrIsNil(model.DeleteByCondition(condition), "删除sql失败")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										27
									
								
								server/internal/db/infrastructure/persistence/db_sql_exec.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								server/internal/db/infrastructure/persistence/db_sql_exec.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
				
			|||||||
 | 
					package persistence
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"mayfly-go/internal/db/domain/entity"
 | 
				
			||||||
 | 
						"mayfly-go/internal/db/domain/repository"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type dbSqlExecRepoImpl struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func newDbSqlExecRepo() repository.DbSqlExec {
 | 
				
			||||||
 | 
						return new(dbSqlExecRepoImpl)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (d *dbSqlExecRepoImpl) Insert(dse *entity.DbSqlExec) {
 | 
				
			||||||
 | 
						model.Insert(dse)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (d *dbSqlExecRepoImpl) DeleteBy(condition *entity.DbSqlExec) {
 | 
				
			||||||
 | 
						biz.ErrIsNil(model.DeleteByCondition(condition), "删除sql执行记录失败")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 分页获取
 | 
				
			||||||
 | 
					func (d *dbSqlExecRepoImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
				
			||||||
 | 
						return model.GetPage(pageParam, condition, toEntity, orderBy...)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										21
									
								
								server/internal/db/infrastructure/persistence/persistence.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								server/internal/db/infrastructure/persistence/persistence.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					package persistence
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "mayfly-go/internal/db/domain/repository"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var (
 | 
				
			||||||
 | 
						dbRepo        repository.Db        = newDbRepo()
 | 
				
			||||||
 | 
						dbSqlRepo     repository.DbSql     = newDbSqlRepo()
 | 
				
			||||||
 | 
						dbSqlExecRepo repository.DbSqlExec = newDbSqlExecRepo()
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetDbRepo() repository.Db {
 | 
				
			||||||
 | 
						return dbRepo
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetDbSqlRepo() repository.DbSql {
 | 
				
			||||||
 | 
						return dbSqlRepo
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetDbSqlExecRepo() repository.DbSqlExec {
 | 
				
			||||||
 | 
						return dbSqlExecRepo
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,9 +1,10 @@
 | 
				
			|||||||
package router
 | 
					package router
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"mayfly-go/internal/devops/api"
 | 
						"mayfly-go/internal/db/api"
 | 
				
			||||||
	"mayfly-go/internal/devops/application"
 | 
						"mayfly-go/internal/db/application"
 | 
				
			||||||
	sysApplication "mayfly-go/internal/sys/application"
 | 
						projectapp "mayfly-go/internal/project/application"
 | 
				
			||||||
 | 
						sysapp "mayfly-go/internal/sys/application"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
@@ -13,15 +14,14 @@ func InitDbRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
	db := router.Group("dbs")
 | 
						db := router.Group("dbs")
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		d := &api.Db{
 | 
							d := &api.Db{
 | 
				
			||||||
			DbApp:        application.DbApp,
 | 
								DbApp:        application.GetDbApp(),
 | 
				
			||||||
			DbSqlExecApp: application.DbSqlExecApp,
 | 
								DbSqlExecApp: application.GetDbSqlExecApp(),
 | 
				
			||||||
			MsgApp:       sysApplication.MsgApp,
 | 
								MsgApp:       sysapp.GetMsgApp(),
 | 
				
			||||||
			ProjectApp:   application.ProjectApp,
 | 
								ProjectApp:   projectapp.GetProjectApp(),
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		// 获取所有数据库列表
 | 
							// 获取所有数据库列表
 | 
				
			||||||
		db.GET("", func(c *gin.Context) {
 | 
							db.GET("", func(c *gin.Context) {
 | 
				
			||||||
			rc := ctx.NewReqCtxWithGin(c)
 | 
								ctx.NewReqCtxWithGin(c).Handle(d.Dbs)
 | 
				
			||||||
			rc.Handle(d.Dbs)
 | 
					 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		saveDb := ctx.NewLogInfo("保存数据库信息").WithSave(true)
 | 
							saveDb := ctx.NewLogInfo("保存数据库信息").WithSave(true)
 | 
				
			||||||
@@ -31,6 +31,16 @@ func InitDbRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
				Handle(d.Save)
 | 
									Handle(d.Save)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// 获取数据库实例的所有数据库名
 | 
				
			||||||
 | 
							db.POST("databases", func(c *gin.Context) {
 | 
				
			||||||
 | 
								ctx.NewReqCtxWithGin(c).
 | 
				
			||||||
 | 
									Handle(d.GetDatabaseNames)
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							db.GET(":dbId/pwd", func(c *gin.Context) {
 | 
				
			||||||
 | 
								ctx.NewReqCtxWithGin(c).Handle(d.GetDbPwd)
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		deleteDb := ctx.NewLogInfo("删除数据库信息").WithSave(true)
 | 
							deleteDb := ctx.NewLogInfo("删除数据库信息").WithSave(true)
 | 
				
			||||||
		db.DELETE(":dbId", func(c *gin.Context) {
 | 
							db.DELETE(":dbId", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).
 | 
								ctx.NewReqCtxWithGin(c).
 | 
				
			||||||
@@ -1,8 +1,8 @@
 | 
				
			|||||||
package router
 | 
					package router
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"mayfly-go/internal/devops/api"
 | 
						"mayfly-go/internal/db/api"
 | 
				
			||||||
	"mayfly-go/internal/devops/application"
 | 
						"mayfly-go/internal/db/application"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
@@ -12,7 +12,7 @@ func InitDbSqlExecRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
	db := router.Group("/dbs/:dbId/sql-execs")
 | 
						db := router.Group("/dbs/:dbId/sql-execs")
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		d := &api.DbSqlExec{
 | 
							d := &api.DbSqlExec{
 | 
				
			||||||
			DbSqlExecApp: application.DbSqlExecApp,
 | 
								DbSqlExecApp: application.GetDbSqlExecApp(),
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		// 获取所有数据库sql执行记录列表
 | 
							// 获取所有数据库sql执行记录列表
 | 
				
			||||||
		db.GET("", func(c *gin.Context) {
 | 
							db.GET("", func(c *gin.Context) {
 | 
				
			||||||
							
								
								
									
										8
									
								
								server/internal/db/router/router.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								server/internal/db/router/router.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					package router
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "github.com/gin-gonic/gin"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Init(router *gin.RouterGroup) {
 | 
				
			||||||
 | 
						InitDbRouter(router)
 | 
				
			||||||
 | 
						InitDbSqlExecRouter(router)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,39 +0,0 @@
 | 
				
			|||||||
package form
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type KeyInfo struct {
 | 
					 | 
				
			||||||
	Key   string `binding:"required" json:"key"`
 | 
					 | 
				
			||||||
	Timed int64
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type StringValue struct {
 | 
					 | 
				
			||||||
	KeyInfo
 | 
					 | 
				
			||||||
	Value interface{} `binding:"required" json:"value"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type HashValue struct {
 | 
					 | 
				
			||||||
	KeyInfo
 | 
					 | 
				
			||||||
	Value []map[string]interface{} `binding:"required" json:"value"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,31 +0,0 @@
 | 
				
			|||||||
package vo
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import "time"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Redis struct {
 | 
					 | 
				
			||||||
	Id *int64 `json:"id"`
 | 
					 | 
				
			||||||
	// Name       *string    `json:"name"`
 | 
					 | 
				
			||||||
	Host       *string    `json:"host"`
 | 
					 | 
				
			||||||
	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"`
 | 
					 | 
				
			||||||
	Creator    *string    `json:"creator"`
 | 
					 | 
				
			||||||
	CreatorId  *int64     `json:"creatorId"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Keys struct {
 | 
					 | 
				
			||||||
	Cursor map[string]uint64 `json:"cursor"`
 | 
					 | 
				
			||||||
	Keys   []*KeyInfo        `json:"keys"`
 | 
					 | 
				
			||||||
	DbSize int64             `json:"dbSize"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type KeyInfo struct {
 | 
					 | 
				
			||||||
	Key  string `json:"key"`
 | 
					 | 
				
			||||||
	Ttl  int64  `json:"ttl"`
 | 
					 | 
				
			||||||
	Type string `json:"type"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,65 +0,0 @@
 | 
				
			|||||||
package vo
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import "time"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type AccountVO struct {
 | 
					 | 
				
			||||||
	//models.BaseModel
 | 
					 | 
				
			||||||
	Id         *int64  `json:"id"`
 | 
					 | 
				
			||||||
	Username   *string `json:"username"`
 | 
					 | 
				
			||||||
	CreateTime *string `json:"createTime"`
 | 
					 | 
				
			||||||
	Creator    *string `json:"creator"`
 | 
					 | 
				
			||||||
	CreatorId  *int64  `json:"creatorId"`
 | 
					 | 
				
			||||||
	// Role       *RoleVO `json:"roles"`
 | 
					 | 
				
			||||||
	//Status   int8   `json:"status"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type MachineVO struct {
 | 
					 | 
				
			||||||
	//models.BaseModel
 | 
					 | 
				
			||||||
	Id          *uint64    `json:"id"`
 | 
					 | 
				
			||||||
	ProjectId   uint64     `json:"projectId"`
 | 
					 | 
				
			||||||
	ProjectName string     `json:"projectName"`
 | 
					 | 
				
			||||||
	Name        *string    `json:"name"`
 | 
					 | 
				
			||||||
	Username    *string    `json:"username"`
 | 
					 | 
				
			||||||
	Ip          *string    `json:"ip"`
 | 
					 | 
				
			||||||
	Port        *int       `json:"port"`
 | 
					 | 
				
			||||||
	Status      *int8      `json:"status"`
 | 
					 | 
				
			||||||
	CreateTime  *time.Time `json:"createTime"`
 | 
					 | 
				
			||||||
	Creator     *string    `json:"creator"`
 | 
					 | 
				
			||||||
	CreatorId   *int64     `json:"creatorId"`
 | 
					 | 
				
			||||||
	UpdateTime  *time.Time `json:"updateTime"`
 | 
					 | 
				
			||||||
	Modifier    *string    `json:"modifier"`
 | 
					 | 
				
			||||||
	ModifierId  *int64     `json:"modifierId"`
 | 
					 | 
				
			||||||
	HasCli      bool       `json:"hasCli" gorm:"-"`
 | 
					 | 
				
			||||||
	Remark      *string    `json:"remark"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type MachineScriptVO struct {
 | 
					 | 
				
			||||||
	Id          *int64  `json:"id"`
 | 
					 | 
				
			||||||
	Name        *string `json:"name"`
 | 
					 | 
				
			||||||
	Script      *string `json:"script"`
 | 
					 | 
				
			||||||
	Type        *int    `json:"type"`
 | 
					 | 
				
			||||||
	Description *string `json:"description"`
 | 
					 | 
				
			||||||
	Params      *string `json:"params"`
 | 
					 | 
				
			||||||
	MachineId   *uint64 `json:"machineId"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type MachineFileVO struct {
 | 
					 | 
				
			||||||
	Id        *int64  `json:"id"`
 | 
					 | 
				
			||||||
	Name      *string `json:"name"`
 | 
					 | 
				
			||||||
	Path      *string `json:"path"`
 | 
					 | 
				
			||||||
	Type      *int    `json:"type"`
 | 
					 | 
				
			||||||
	MachineId *uint64 `json:"machineId"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type MachineFileInfo struct {
 | 
					 | 
				
			||||||
	Name string `json:"name"`
 | 
					 | 
				
			||||||
	Path string `json:"path"`
 | 
					 | 
				
			||||||
	Size int64  `json:"size"`
 | 
					 | 
				
			||||||
	Type string `json:"type"`
 | 
					 | 
				
			||||||
	Mode string `json:"mode"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type RoleVO struct {
 | 
					 | 
				
			||||||
	Id   *int64
 | 
					 | 
				
			||||||
	Name *string
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,127 +0,0 @@
 | 
				
			|||||||
package application
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"encoding/json"
 | 
					 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"mayfly-go/internal/devops/domain/entity"
 | 
					 | 
				
			||||||
	"mayfly-go/internal/devops/domain/repository"
 | 
					 | 
				
			||||||
	"mayfly-go/internal/devops/infrastructure/persistence"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/global"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
					 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/xwb1989/sqlparser"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type DbSqlExec interface {
 | 
					 | 
				
			||||||
	// 生成sql执行记录
 | 
					 | 
				
			||||||
	GenExecLog(loginAccount *model.LoginAccount, dbId uint64, db string, sql string, dbInstance *DbInstance) *entity.DbSqlExec
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 保存sql执行记录
 | 
					 | 
				
			||||||
	Save(*entity.DbSqlExec)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 根据条件删除sql执行记录
 | 
					 | 
				
			||||||
	DeleteBy(condition *entity.DbSqlExec)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 分页获取
 | 
					 | 
				
			||||||
	GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type dbSqlExecAppImpl struct {
 | 
					 | 
				
			||||||
	dbSqlExecRepo repository.DbSqlExec
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
var DbSqlExecApp DbSqlExec = &dbSqlExecAppImpl{
 | 
					 | 
				
			||||||
	dbSqlExecRepo: persistence.DbSqlExecDao,
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (d *dbSqlExecAppImpl) GenExecLog(loginAccount *model.LoginAccount, dbId uint64, db string, sql string, dbInstance *DbInstance) *entity.DbSqlExec {
 | 
					 | 
				
			||||||
	defer func() {
 | 
					 | 
				
			||||||
		if err := recover(); err != nil {
 | 
					 | 
				
			||||||
			global.Log.Error("生成sql执行记录失败", err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}()
 | 
					 | 
				
			||||||
	stmt, err := sqlparser.Parse(sql)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		global.Log.Error("记录数据库sql执行记录失败", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	dbSqlExecRecord := new(entity.DbSqlExec)
 | 
					 | 
				
			||||||
	dbSqlExecRecord.DbId = dbId
 | 
					 | 
				
			||||||
	dbSqlExecRecord.Db = db
 | 
					 | 
				
			||||||
	dbSqlExecRecord.Sql = sql
 | 
					 | 
				
			||||||
	dbSqlExecRecord.SetBaseInfo(loginAccount)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	switch stmt := stmt.(type) {
 | 
					 | 
				
			||||||
	case *sqlparser.Update:
 | 
					 | 
				
			||||||
		doUpdate(stmt, dbInstance, dbSqlExecRecord)
 | 
					 | 
				
			||||||
	case *sqlparser.Delete:
 | 
					 | 
				
			||||||
		doDelete(stmt, dbInstance, dbSqlExecRecord)
 | 
					 | 
				
			||||||
	case *sqlparser.Insert:
 | 
					 | 
				
			||||||
		doInsert(stmt, dbSqlExecRecord)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return dbSqlExecRecord
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (d *dbSqlExecAppImpl) Save(dse *entity.DbSqlExec) {
 | 
					 | 
				
			||||||
	d.dbSqlExecRepo.Insert(dse)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (d *dbSqlExecAppImpl) DeleteBy(condition *entity.DbSqlExec) {
 | 
					 | 
				
			||||||
	d.dbSqlExecRepo.DeleteBy(condition)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (d *dbSqlExecAppImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					 | 
				
			||||||
	return d.dbSqlExecRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func doUpdate(update *sqlparser.Update, dbInstance *DbInstance, dbSqlExec *entity.DbSqlExec) {
 | 
					 | 
				
			||||||
	tableStr := sqlparser.String(update.TableExprs)
 | 
					 | 
				
			||||||
	// 可能使用别名,故空格切割
 | 
					 | 
				
			||||||
	tableName := strings.Split(tableStr, " ")[0]
 | 
					 | 
				
			||||||
	where := sqlparser.String(update.Where)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	updateExprs := update.Exprs
 | 
					 | 
				
			||||||
	updateColumns := make([]string, 0)
 | 
					 | 
				
			||||||
	for _, v := range updateExprs {
 | 
					 | 
				
			||||||
		updateColumns = append(updateColumns, v.Name.Name.String())
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 获取表主键列名,排除使用别名
 | 
					 | 
				
			||||||
	primaryKey := dbInstance.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,133 +0,0 @@
 | 
				
			|||||||
package application
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"context"
 | 
					 | 
				
			||||||
	"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"
 | 
					 | 
				
			||||||
	"go.mongodb.org/mongo-driver/mongo/options"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Mongo interface {
 | 
					 | 
				
			||||||
	// 分页获取机器脚本信息列表
 | 
					 | 
				
			||||||
	GetPageList(condition *entity.Mongo, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	Count(condition *entity.Mongo) int64
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 根据条件获取
 | 
					 | 
				
			||||||
	GetBy(condition *entity.Mongo, cols ...string) error
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 根据id获取
 | 
					 | 
				
			||||||
	GetById(id uint64, cols ...string) *entity.Mongo
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	Save(entity *entity.Mongo)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 删除数据库信息
 | 
					 | 
				
			||||||
	Delete(id uint64)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 获取mongo连接client
 | 
					 | 
				
			||||||
	// @param id mongo id
 | 
					 | 
				
			||||||
	GetMongoCli(id uint64) *mongo.Client
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type mongoAppImpl struct {
 | 
					 | 
				
			||||||
	mongoRepo repository.Mongo
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
var MongoApp Mongo = &mongoAppImpl{
 | 
					 | 
				
			||||||
	mongoRepo: persistence.MongoDao,
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 分页获取数据库信息列表
 | 
					 | 
				
			||||||
func (d *mongoAppImpl) GetPageList(condition *entity.Mongo, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					 | 
				
			||||||
	return d.mongoRepo.GetList(condition, pageParam, toEntity, orderBy...)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (d *mongoAppImpl) Count(condition *entity.Mongo) int64 {
 | 
					 | 
				
			||||||
	return d.mongoRepo.Count(condition)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 根据条件获取
 | 
					 | 
				
			||||||
func (d *mongoAppImpl) GetBy(condition *entity.Mongo, cols ...string) error {
 | 
					 | 
				
			||||||
	return d.mongoRepo.Get(condition, cols...)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 根据id获取
 | 
					 | 
				
			||||||
func (d *mongoAppImpl) GetById(id uint64, cols ...string) *entity.Mongo {
 | 
					 | 
				
			||||||
	return d.mongoRepo.GetById(id, cols...)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (d *mongoAppImpl) Delete(id uint64) {
 | 
					 | 
				
			||||||
	d.mongoRepo.Delete(id)
 | 
					 | 
				
			||||||
	DeleteMongoCache(id)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (d *mongoAppImpl) Save(m *entity.Mongo) {
 | 
					 | 
				
			||||||
	if m.Id == 0 {
 | 
					 | 
				
			||||||
		d.mongoRepo.Insert(m)
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		// 先关闭连接
 | 
					 | 
				
			||||||
		DeleteMongoCache(m.Id)
 | 
					 | 
				
			||||||
		d.mongoRepo.Update(m)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (d *mongoAppImpl) GetMongoCli(id uint64) *mongo.Client {
 | 
					 | 
				
			||||||
	cli, err := GetMongoCli(id, func(u uint64) string {
 | 
					 | 
				
			||||||
		mongo := d.GetById(id)
 | 
					 | 
				
			||||||
		biz.NotNil(mongo, "mongo信息不存在")
 | 
					 | 
				
			||||||
		return mongo.Uri
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
	biz.ErrIsNilAppendErr(err, "连接mongo失败: %s")
 | 
					 | 
				
			||||||
	return cli
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// -----------------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//mongo客户端连接缓存,30分钟内没有访问则会被关闭
 | 
					 | 
				
			||||||
var mongoCliCache = cache.NewTimedCache(30*time.Minute, 5*time.Second).
 | 
					 | 
				
			||||||
	WithUpdateAccessTime(true).
 | 
					 | 
				
			||||||
	OnEvicted(func(key interface{}, value interface{}) {
 | 
					 | 
				
			||||||
		global.Log.Info("关闭mongo连接: id = ", key)
 | 
					 | 
				
			||||||
		value.(*mongo.Client).Disconnect(context.TODO())
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func GetMongoCli(mongoId uint64, getMongoUri func(uint64) string) (*mongo.Client, error) {
 | 
					 | 
				
			||||||
	cli, err := mongoCliCache.ComputeIfAbsent(mongoId, func(key interface{}) (interface{}, error) {
 | 
					 | 
				
			||||||
		c, err := connect(getMongoUri(mongoId))
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return nil, err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return c, nil
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if cli != nil {
 | 
					 | 
				
			||||||
		return cli.(*mongo.Client), err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil, err
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func DeleteMongoCache(mongoId uint64) {
 | 
					 | 
				
			||||||
	mongoCliCache.Delete(mongoId)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 连接mongo,并返回client
 | 
					 | 
				
			||||||
func connect(uri string) (*mongo.Client, error) {
 | 
					 | 
				
			||||||
	ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
 | 
					 | 
				
			||||||
	defer cancel()
 | 
					 | 
				
			||||||
	client, err := mongo.Connect(ctx, options.Client().ApplyURI(uri).SetMaxPoolSize(2))
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if err = client.Ping(context.TODO(), nil); err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return client, err
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,221 +0,0 @@
 | 
				
			|||||||
package application
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"context"
 | 
					 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"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/v8"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Redis interface {
 | 
					 | 
				
			||||||
	// 分页获取机器脚本信息列表
 | 
					 | 
				
			||||||
	GetPageList(condition *entity.Redis, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	Count(condition *entity.Redis) int64
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 根据id获取
 | 
					 | 
				
			||||||
	GetById(id uint64, cols ...string) *entity.Redis
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 根据条件获取
 | 
					 | 
				
			||||||
	GetRedisBy(condition *entity.Redis, cols ...string) error
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	Save(entity *entity.Redis)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 删除数据库信息
 | 
					 | 
				
			||||||
	Delete(id uint64)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 获取数据库连接实例
 | 
					 | 
				
			||||||
	GetRedisInstance(id uint64) *RedisInstance
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type redisAppImpl struct {
 | 
					 | 
				
			||||||
	redisRepo repository.Redis
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
var RedisApp Redis = &redisAppImpl{
 | 
					 | 
				
			||||||
	redisRepo: persistence.RedisDao,
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 分页获取机器脚本信息列表
 | 
					 | 
				
			||||||
func (r *redisAppImpl) GetPageList(condition *entity.Redis, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					 | 
				
			||||||
	return r.redisRepo.GetRedisList(condition, pageParam, toEntity, orderBy...)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (r *redisAppImpl) Count(condition *entity.Redis) int64 {
 | 
					 | 
				
			||||||
	return r.redisRepo.Count(condition)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 根据id获取
 | 
					 | 
				
			||||||
func (r *redisAppImpl) GetById(id uint64, cols ...string) *entity.Redis {
 | 
					 | 
				
			||||||
	return r.redisRepo.GetById(id, cols...)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 根据条件获取
 | 
					 | 
				
			||||||
func (r *redisAppImpl) GetRedisBy(condition *entity.Redis, cols ...string) error {
 | 
					 | 
				
			||||||
	return r.redisRepo.GetRedis(condition, cols...)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (r *redisAppImpl) Save(re *entity.Redis) {
 | 
					 | 
				
			||||||
	TestRedisConnection(re)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 查找是否存在该库
 | 
					 | 
				
			||||||
	oldRedis := &entity.Redis{Host: re.Host, Db: re.Db}
 | 
					 | 
				
			||||||
	err := r.GetRedisBy(oldRedis)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if re.Id == 0 {
 | 
					 | 
				
			||||||
		biz.IsTrue(err != nil, "该库已存在")
 | 
					 | 
				
			||||||
		r.redisRepo.Insert(re)
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		// 如果存在该库,则校验修改的库是否为该库
 | 
					 | 
				
			||||||
		if err == nil {
 | 
					 | 
				
			||||||
			biz.IsTrue(oldRedis.Id == re.Id, "该库已存在")
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		// 先关闭数据库连接
 | 
					 | 
				
			||||||
		CloseRedis(re.Id)
 | 
					 | 
				
			||||||
		r.redisRepo.Update(re)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 删除Redis信息
 | 
					 | 
				
			||||||
func (r *redisAppImpl) Delete(id uint64) {
 | 
					 | 
				
			||||||
	CloseRedis(id)
 | 
					 | 
				
			||||||
	r.redisRepo.Delete(id)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取数据库连接实例
 | 
					 | 
				
			||||||
func (r *redisAppImpl) GetRedisInstance(id uint64) *RedisInstance {
 | 
					 | 
				
			||||||
	// Id不为0,则为需要缓存
 | 
					 | 
				
			||||||
	needCache := id != 0
 | 
					 | 
				
			||||||
	if needCache {
 | 
					 | 
				
			||||||
		load, ok := redisCache.Get(id)
 | 
					 | 
				
			||||||
		if ok {
 | 
					 | 
				
			||||||
			return load.(*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)
 | 
					 | 
				
			||||||
	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分钟内没有访问则会被关闭
 | 
					 | 
				
			||||||
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).Close()
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 移除redis连接缓存并关闭redis连接
 | 
					 | 
				
			||||||
func CloseRedis(id uint64) {
 | 
					 | 
				
			||||||
	redisCache.Delete(id)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func TestRedisConnection(re *entity.Redis) {
 | 
					 | 
				
			||||||
	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 := 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.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,23 +0,0 @@
 | 
				
			|||||||
package entity
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Db struct {
 | 
					 | 
				
			||||||
	model.Model
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	Name      string `orm:"column(name)" json:"name"`
 | 
					 | 
				
			||||||
	Type      string `orm:"column(type)" json:"type"` // 类型,mysql oracle等
 | 
					 | 
				
			||||||
	Host      string `orm:"column(host)" json:"host"`
 | 
					 | 
				
			||||||
	Port      int    `orm:"column(port)" json:"port"`
 | 
					 | 
				
			||||||
	Network   string `orm:"column(network)" json:"network"`
 | 
					 | 
				
			||||||
	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
 | 
					 | 
				
			||||||
	Env       string
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,23 +0,0 @@
 | 
				
			|||||||
package entity
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Machine struct {
 | 
					 | 
				
			||||||
	model.Model
 | 
					 | 
				
			||||||
	ProjectId   uint64 `json:"projectId"`
 | 
					 | 
				
			||||||
	ProjectName string `json:"projectName"`
 | 
					 | 
				
			||||||
	Name        string `json:"name"`
 | 
					 | 
				
			||||||
	Ip          string `json:"ip"`       // IP地址
 | 
					 | 
				
			||||||
	Username    string `json:"username"` // 用户名
 | 
					 | 
				
			||||||
	Password    string `json:"-"`
 | 
					 | 
				
			||||||
	Port        int    `json:"port"`   // 端口号
 | 
					 | 
				
			||||||
	Status      int8   `json:"status"` // 状态 1:启用;2:停用
 | 
					 | 
				
			||||||
	Remark      string `json:"remark"` // 备注
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const (
 | 
					 | 
				
			||||||
	MachineStatusEnable  int8 = 1  // 启用状态
 | 
					 | 
				
			||||||
	MachineStatusDisable int8 = -1 // 禁用状态
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
@@ -1,14 +0,0 @@
 | 
				
			|||||||
package entity
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import "mayfly-go/pkg/model"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Mongo struct {
 | 
					 | 
				
			||||||
	model.Model
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	Name      string `orm:"column(name)" json:"name"`
 | 
					 | 
				
			||||||
	Uri       string `orm:"column(uri)" json:"uri"`
 | 
					 | 
				
			||||||
	ProjectId uint64 `json:"projectId"`
 | 
					 | 
				
			||||||
	Project   string `json:"project"`
 | 
					 | 
				
			||||||
	EnvId     uint64 `json:"envId"`
 | 
					 | 
				
			||||||
	Env       string `json:"env"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,24 +0,0 @@
 | 
				
			|||||||
package entity
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"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,186 +0,0 @@
 | 
				
			|||||||
package machine
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"errors"
 | 
					 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"mayfly-go/internal/devops/domain/entity"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/cache"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/global"
 | 
					 | 
				
			||||||
	"net"
 | 
					 | 
				
			||||||
	"time"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/pkg/sftp"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"golang.org/x/crypto/ssh"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 客户端信息
 | 
					 | 
				
			||||||
type Cli struct {
 | 
					 | 
				
			||||||
	machine *entity.Machine
 | 
					 | 
				
			||||||
	// ssh客户端
 | 
					 | 
				
			||||||
	client *ssh.Client
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	sftpClient *sftp.Client
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 机器客户端连接缓存,45分钟内没有访问则会被关闭
 | 
					 | 
				
			||||||
var cliCache = cache.NewTimedCache(45*time.Minute, 5*time.Second).
 | 
					 | 
				
			||||||
	WithUpdateAccessTime(true).
 | 
					 | 
				
			||||||
	OnEvicted(func(key interface{}, value interface{}) {
 | 
					 | 
				
			||||||
		value.(*Cli).Close()
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 是否存在指定id的客户端连接
 | 
					 | 
				
			||||||
func HasCli(machineId uint64) bool {
 | 
					 | 
				
			||||||
	if _, ok := cliCache.Get(machineId); ok {
 | 
					 | 
				
			||||||
		return true
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return false
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 删除指定机器客户端,并关闭客户端连接
 | 
					 | 
				
			||||||
func DeleteCli(id uint64) {
 | 
					 | 
				
			||||||
	cliCache.Delete(id)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 从缓存中获取客户端信息,不存在则回调获取机器信息函数,并新建
 | 
					 | 
				
			||||||
func GetCli(machineId uint64, getMachine func(uint64) *entity.Machine) (*Cli, error) {
 | 
					 | 
				
			||||||
	cli, err := cliCache.ComputeIfAbsent(machineId, func(key interface{}) (interface{}, error) {
 | 
					 | 
				
			||||||
		c, err := newClient(getMachine(machineId))
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return nil, err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return c, nil
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if cli != nil {
 | 
					 | 
				
			||||||
		return cli.(*Cli), err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil, err
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//根据机器信息创建客户端对象
 | 
					 | 
				
			||||||
func newClient(machine *entity.Machine) (*Cli, error) {
 | 
					 | 
				
			||||||
	if machine == nil {
 | 
					 | 
				
			||||||
		return nil, errors.New("机器不存在")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	global.Log.Infof("[%s]机器连接:%s:%d", machine.Name, machine.Ip, machine.Port)
 | 
					 | 
				
			||||||
	cli := new(Cli)
 | 
					 | 
				
			||||||
	cli.machine = machine
 | 
					 | 
				
			||||||
	err := cli.connect()
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return cli, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//连接
 | 
					 | 
				
			||||||
func (c *Cli) connect() error {
 | 
					 | 
				
			||||||
	// 如果已经有client则直接返回
 | 
					 | 
				
			||||||
	if c.client != nil {
 | 
					 | 
				
			||||||
		return nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	m := c.machine
 | 
					 | 
				
			||||||
	config := ssh.ClientConfig{
 | 
					 | 
				
			||||||
		User: m.Username,
 | 
					 | 
				
			||||||
		Auth: []ssh.AuthMethod{ssh.Password(m.Password)},
 | 
					 | 
				
			||||||
		HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
 | 
					 | 
				
			||||||
			return nil
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		Timeout: 5 * time.Second,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	addr := fmt.Sprintf("%s:%d", m.Ip, m.Port)
 | 
					 | 
				
			||||||
	sshClient, err := ssh.Dial("tcp", addr, &config)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	c.client = sshClient
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 测试连接
 | 
					 | 
				
			||||||
func TestConn(m *entity.Machine) error {
 | 
					 | 
				
			||||||
	config := ssh.ClientConfig{
 | 
					 | 
				
			||||||
		User: m.Username,
 | 
					 | 
				
			||||||
		Auth: []ssh.AuthMethod{ssh.Password(m.Password)},
 | 
					 | 
				
			||||||
		HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
 | 
					 | 
				
			||||||
			return nil
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		Timeout: 5 * time.Second,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	addr := fmt.Sprintf("%s:%d", m.Ip, m.Port)
 | 
					 | 
				
			||||||
	sshClient, err := ssh.Dial("tcp", addr, &config)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	defer sshClient.Close()
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 关闭client和并从缓存中移除
 | 
					 | 
				
			||||||
func (c *Cli) Close() {
 | 
					 | 
				
			||||||
	m := c.machine
 | 
					 | 
				
			||||||
	global.Log.Info(fmt.Sprintf("关闭机器客户端连接-> id: %d, name: %s, ip: %s", m.Id, m.Name, m.Ip))
 | 
					 | 
				
			||||||
	if c.client != nil {
 | 
					 | 
				
			||||||
		c.client.Close()
 | 
					 | 
				
			||||||
		c.client = nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if c.sftpClient != nil {
 | 
					 | 
				
			||||||
		c.sftpClient.Close()
 | 
					 | 
				
			||||||
		c.sftpClient = nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取sftp client
 | 
					 | 
				
			||||||
func (c *Cli) GetSftpCli() *sftp.Client {
 | 
					 | 
				
			||||||
	if c.client == nil {
 | 
					 | 
				
			||||||
		if err := c.connect(); err != nil {
 | 
					 | 
				
			||||||
			panic(biz.NewBizErr("连接ssh失败:" + err.Error()))
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	sftpclient := c.sftpClient
 | 
					 | 
				
			||||||
	// 如果sftpClient为nil,则连接
 | 
					 | 
				
			||||||
	if sftpclient == nil {
 | 
					 | 
				
			||||||
		sc, serr := sftp.NewClient(c.client)
 | 
					 | 
				
			||||||
		if serr != nil {
 | 
					 | 
				
			||||||
			panic(biz.NewBizErr("获取sftp client失败:" + serr.Error()))
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		sftpclient = sc
 | 
					 | 
				
			||||||
		c.sftpClient = sftpclient
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return sftpclient
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取session
 | 
					 | 
				
			||||||
func (c *Cli) GetSession() (*ssh.Session, error) {
 | 
					 | 
				
			||||||
	if c.client == nil {
 | 
					 | 
				
			||||||
		if err := c.connect(); err != nil {
 | 
					 | 
				
			||||||
			return nil, err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return c.client.NewSession()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//执行shell
 | 
					 | 
				
			||||||
//@param shell shell脚本命令
 | 
					 | 
				
			||||||
func (c *Cli) Run(shell string) (*string, error) {
 | 
					 | 
				
			||||||
	session, err := c.GetSession()
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.Close()
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	defer session.Close()
 | 
					 | 
				
			||||||
	buf, rerr := session.CombinedOutput(shell)
 | 
					 | 
				
			||||||
	if rerr != nil {
 | 
					 | 
				
			||||||
		return nil, rerr
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	res := string(buf)
 | 
					 | 
				
			||||||
	return &res, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (c *Cli) GetMachine() *entity.Machine {
 | 
					 | 
				
			||||||
	return c.machine
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,19 +0,0 @@
 | 
				
			|||||||
package machine
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const StatsShell = `
 | 
					 | 
				
			||||||
cat /proc/uptime
 | 
					 | 
				
			||||||
echo '-----'
 | 
					 | 
				
			||||||
/bin/hostname -f
 | 
					 | 
				
			||||||
echo '-----'
 | 
					 | 
				
			||||||
cat /proc/loadavg
 | 
					 | 
				
			||||||
echo '-----'
 | 
					 | 
				
			||||||
cat /proc/meminfo
 | 
					 | 
				
			||||||
echo '-----'
 | 
					 | 
				
			||||||
df -B1
 | 
					 | 
				
			||||||
echo '-----'
 | 
					 | 
				
			||||||
/sbin/ip -o addr
 | 
					 | 
				
			||||||
echo '-----'
 | 
					 | 
				
			||||||
/bin/cat /proc/net/dev
 | 
					 | 
				
			||||||
echo '-----'
 | 
					 | 
				
			||||||
top -b -n 1 | grep Cpu
 | 
					 | 
				
			||||||
`
 | 
					 | 
				
			||||||
@@ -1,195 +0,0 @@
 | 
				
			|||||||
package machine
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"bytes"
 | 
					 | 
				
			||||||
	"encoding/json"
 | 
					 | 
				
			||||||
	"io"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/global"
 | 
					 | 
				
			||||||
	"sync"
 | 
					 | 
				
			||||||
	"time"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/gorilla/websocket"
 | 
					 | 
				
			||||||
	"golang.org/x/crypto/ssh"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type safeBuffer struct {
 | 
					 | 
				
			||||||
	buffer bytes.Buffer
 | 
					 | 
				
			||||||
	mu     sync.Mutex
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (w *safeBuffer) Write(p []byte) (int, error) {
 | 
					 | 
				
			||||||
	w.mu.Lock()
 | 
					 | 
				
			||||||
	defer w.mu.Unlock()
 | 
					 | 
				
			||||||
	return w.buffer.Write(p)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
func (w *safeBuffer) Bytes() []byte {
 | 
					 | 
				
			||||||
	w.mu.Lock()
 | 
					 | 
				
			||||||
	defer w.mu.Unlock()
 | 
					 | 
				
			||||||
	return w.buffer.Bytes()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
func (w *safeBuffer) Reset() {
 | 
					 | 
				
			||||||
	w.mu.Lock()
 | 
					 | 
				
			||||||
	defer w.mu.Unlock()
 | 
					 | 
				
			||||||
	w.buffer.Reset()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const (
 | 
					 | 
				
			||||||
	wsMsgCmd    = "cmd"
 | 
					 | 
				
			||||||
	wsMsgResize = "resize"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type WsMsg struct {
 | 
					 | 
				
			||||||
	Type string `json:"type"`
 | 
					 | 
				
			||||||
	Msg  string `json:"msg"`
 | 
					 | 
				
			||||||
	Cols int    `json:"cols"`
 | 
					 | 
				
			||||||
	Rows int    `json:"rows"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type LogicSshWsSession struct {
 | 
					 | 
				
			||||||
	stdinPipe       io.WriteCloser
 | 
					 | 
				
			||||||
	comboOutput     *safeBuffer //ssh 终端混合输出
 | 
					 | 
				
			||||||
	inputFilterBuff *safeBuffer //用来过滤输入的命令和ssh_filter配置对比的
 | 
					 | 
				
			||||||
	session         *ssh.Session
 | 
					 | 
				
			||||||
	wsConn          *websocket.Conn
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func NewLogicSshWsSession(cols, rows int, cli *Cli, wsConn *websocket.Conn) (*LogicSshWsSession, error) {
 | 
					 | 
				
			||||||
	sshSession, err := cli.GetSession()
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	stdinP, err := sshSession.StdinPipe()
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	comboWriter := new(safeBuffer)
 | 
					 | 
				
			||||||
	inputBuf := new(safeBuffer)
 | 
					 | 
				
			||||||
	//ssh.stdout and stderr will write output into comboWriter
 | 
					 | 
				
			||||||
	sshSession.Stdout = comboWriter
 | 
					 | 
				
			||||||
	sshSession.Stderr = comboWriter
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	modes := ssh.TerminalModes{
 | 
					 | 
				
			||||||
		ssh.ECHO:          1,     // disable echo
 | 
					 | 
				
			||||||
		ssh.TTY_OP_ISPEED: 14400, // input speed = 14.4kbaud
 | 
					 | 
				
			||||||
		ssh.TTY_OP_OSPEED: 14400, // output speed = 14.4kbaud
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// Request pseudo terminal
 | 
					 | 
				
			||||||
	if err := sshSession.RequestPty("xterm", rows, cols, modes); err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// Start remote shell
 | 
					 | 
				
			||||||
	if err := sshSession.Shell(); err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return &LogicSshWsSession{
 | 
					 | 
				
			||||||
		stdinPipe:       stdinP,
 | 
					 | 
				
			||||||
		comboOutput:     comboWriter,
 | 
					 | 
				
			||||||
		inputFilterBuff: inputBuf,
 | 
					 | 
				
			||||||
		session:         sshSession,
 | 
					 | 
				
			||||||
		wsConn:          wsConn,
 | 
					 | 
				
			||||||
	}, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Close 关闭
 | 
					 | 
				
			||||||
func (sws *LogicSshWsSession) Close() {
 | 
					 | 
				
			||||||
	if sws.session != nil {
 | 
					 | 
				
			||||||
		sws.session.Close()
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if sws.comboOutput != nil {
 | 
					 | 
				
			||||||
		sws.comboOutput = nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (sws *LogicSshWsSession) Start(quitChan chan bool) {
 | 
					 | 
				
			||||||
	go sws.receiveWsMsg(quitChan)
 | 
					 | 
				
			||||||
	go sws.sendComboOutput(quitChan)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//receiveWsMsg  receive websocket msg do some handling then write into ssh.session.stdin
 | 
					 | 
				
			||||||
func (sws *LogicSshWsSession) receiveWsMsg(exitCh chan bool) {
 | 
					 | 
				
			||||||
	wsConn := sws.wsConn
 | 
					 | 
				
			||||||
	//tells other go routine quit
 | 
					 | 
				
			||||||
	defer setQuit(exitCh)
 | 
					 | 
				
			||||||
	for {
 | 
					 | 
				
			||||||
		select {
 | 
					 | 
				
			||||||
		case <-exitCh:
 | 
					 | 
				
			||||||
			return
 | 
					 | 
				
			||||||
		default:
 | 
					 | 
				
			||||||
			//read websocket msg
 | 
					 | 
				
			||||||
			_, wsData, err := wsConn.ReadMessage()
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				if websocket.IsCloseError(err, websocket.CloseGoingAway, websocket.CloseNoStatusReceived) {
 | 
					 | 
				
			||||||
					return
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				global.Log.Error("reading webSocket message failed: ", err)
 | 
					 | 
				
			||||||
				return
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			//unmashal bytes into struct
 | 
					 | 
				
			||||||
			msgObj := WsMsg{}
 | 
					 | 
				
			||||||
			if err := json.Unmarshal(wsData, &msgObj); err != nil {
 | 
					 | 
				
			||||||
				global.Log.Error("unmarshal websocket message failed:", err)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			switch msgObj.Type {
 | 
					 | 
				
			||||||
			case wsMsgResize:
 | 
					 | 
				
			||||||
				//handle xterm.js size change
 | 
					 | 
				
			||||||
				if msgObj.Cols > 0 && msgObj.Rows > 0 {
 | 
					 | 
				
			||||||
					if err := sws.session.WindowChange(msgObj.Rows, msgObj.Cols); err != nil {
 | 
					 | 
				
			||||||
						global.Log.Error("ssh pty change windows size failed")
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			case wsMsgCmd:
 | 
					 | 
				
			||||||
				sws.sendWebsocketInputCommandToSshSessionStdinPipe([]byte(msgObj.Msg))
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//sendWebsocketInputCommandToSshSessionStdinPipe
 | 
					 | 
				
			||||||
func (sws *LogicSshWsSession) sendWebsocketInputCommandToSshSessionStdinPipe(cmdBytes []byte) {
 | 
					 | 
				
			||||||
	if _, err := sws.stdinPipe.Write(cmdBytes); err != nil {
 | 
					 | 
				
			||||||
		global.Log.Error("ws cmd bytes write to ssh.stdin pipe failed")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (sws *LogicSshWsSession) sendComboOutput(exitCh chan bool) {
 | 
					 | 
				
			||||||
	wsConn := sws.wsConn
 | 
					 | 
				
			||||||
	//todo 优化成一个方法
 | 
					 | 
				
			||||||
	//tells other go routine quit
 | 
					 | 
				
			||||||
	defer setQuit(exitCh)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	//every 120ms write combine output bytes into websocket response
 | 
					 | 
				
			||||||
	tick := time.NewTicker(time.Millisecond * time.Duration(60))
 | 
					 | 
				
			||||||
	//for range time.Tick(120 * time.Millisecond){}
 | 
					 | 
				
			||||||
	defer tick.Stop()
 | 
					 | 
				
			||||||
	for {
 | 
					 | 
				
			||||||
		select {
 | 
					 | 
				
			||||||
		case <-tick.C:
 | 
					 | 
				
			||||||
			if sws.comboOutput == nil {
 | 
					 | 
				
			||||||
				return
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			bs := sws.comboOutput.Bytes()
 | 
					 | 
				
			||||||
			if len(bs) > 0 {
 | 
					 | 
				
			||||||
				err := wsConn.WriteMessage(websocket.TextMessage, bs)
 | 
					 | 
				
			||||||
				if err != nil {
 | 
					 | 
				
			||||||
					global.Log.Error("ssh sending combo output to webSocket failed")
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				sws.comboOutput.buffer.Reset()
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		case <-exitCh:
 | 
					 | 
				
			||||||
			return
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (sws *LogicSshWsSession) Wait(quitChan chan bool) {
 | 
					 | 
				
			||||||
	if err := sws.session.Wait(); err != nil {
 | 
					 | 
				
			||||||
		setQuit(quitChan)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func setQuit(ch chan bool) {
 | 
					 | 
				
			||||||
	ch <- true
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user