mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-04 00:10:25 +08:00
Compare commits
108 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4cb9ff3f14 | ||
|
|
e4f3e2c4c1 | ||
|
|
a80adb7dd8 | ||
|
|
195127a9d4 | ||
|
|
24f543e667 | ||
|
|
772995705f | ||
|
|
3475c39fe6 | ||
|
|
e6e393379f | ||
|
|
03cc91c3e5 | ||
|
|
f82f7bec6a | ||
|
|
4afd5bbd5e | ||
|
|
86aac2bf08 | ||
|
|
70c8b25a67 | ||
|
|
231af72444 | ||
|
|
480e930385 | ||
|
|
debc34f0fb | ||
|
|
99ce3bd099 | ||
|
|
99431cf9a2 | ||
|
|
83711c69f9 | ||
|
|
9e67032280 | ||
|
|
fa37937410 | ||
|
|
1be2cad78e | ||
|
|
2b1e687ed4 | ||
|
|
881009321b | ||
|
|
aed99b63b8 | ||
|
|
dfa34ba371 | ||
|
|
20beb30dd8 | ||
|
|
4475972af3 | ||
|
|
a843c65783 | ||
|
|
c2de1d3fa2 | ||
|
|
c8d091da06 | ||
|
|
553208ba57 | ||
|
|
072028699a | ||
|
|
9cdcf145a5 | ||
|
|
4df1c19e81 | ||
|
|
ac26a214bc | ||
|
|
ad616496d1 | ||
|
|
9870582779 | ||
|
|
20cc696b33 | ||
|
|
d7263f2b3c | ||
|
|
74e5ee41fb | ||
|
|
f936331dff | ||
|
|
ba311c3504 | ||
|
|
03291594b1 | ||
|
|
a6d9a4b5ae | ||
|
|
875de022c1 | ||
|
|
2c863a2774 | ||
|
|
f2f086a82c | ||
|
|
936ca61f94 | ||
|
|
87ae2f81fa | ||
|
|
ecf67db2b1 | ||
|
|
2e5589e112 | ||
|
|
2598a60898 | ||
|
|
0de226bbf3 | ||
|
|
422f0d8491 | ||
|
|
b028708b94 | ||
|
|
812c0d0f6a | ||
|
|
46df5293dd | ||
|
|
ab42b3e90b | ||
|
|
1378259cc7 | ||
|
|
c8f0b0a83f | ||
|
|
acec760ec1 | ||
|
|
2fe70d49f6 | ||
|
|
9013fff804 | ||
|
|
e925a808c4 | ||
|
|
6c197edddd | ||
|
|
c35e91b7b6 | ||
|
|
575947795a | ||
|
|
51f116c7d2 | ||
|
|
c28254855c | ||
|
|
e8f3671ffb | ||
|
|
ac62767a18 | ||
|
|
2db4c20dd3 | ||
|
|
cfb7fd5b29 | ||
|
|
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
.gitignore
vendored
2
.gitignore
vendored
@@ -16,3 +16,5 @@
|
||||
|
||||
*/node_modules/
|
||||
**/vendor/
|
||||
.idea
|
||||
out
|
||||
|
||||
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
|
||||
|
||||
<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 群
|
||||
<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 "-------------------打包前端开始-------------------"
|
||||
yarn run build
|
||||
if [ "${copy2Server}" == "1" ] ; then
|
||||
echo_green '将打包后的静态文件拷贝至server/static'
|
||||
rm -rf ${server_folder}/static && mkdir -p ${server_folder}/static && cp -r ${web_folder}/dist/* ${server_folder}/static
|
||||
if [ "${copy2Server}" == "2" ] ; then
|
||||
echo_green '将打包后的静态文件拷贝至server/static/static'
|
||||
rm -rf ${server_folder}/static/static && mkdir -p ${server_folder}/static/static && cp -r ${web_folder}/dist/* ${server_folder}/static/static
|
||||
fi
|
||||
echo_yellow ">>>>>>>>>>>>>>>>>>>打包前端结束<<<<<<<<<<<<<<<<<<<<\n"
|
||||
}
|
||||
@@ -44,6 +44,7 @@ function build() {
|
||||
toFolder=$1
|
||||
os=$2
|
||||
arch=$3
|
||||
copyStatic=$4
|
||||
|
||||
echo_yellow "-------------------${os}-${arch}打包构建开始-------------------"
|
||||
|
||||
@@ -67,8 +68,10 @@ function build() {
|
||||
echo_green "移动二进制文件至'${toFolder}'"
|
||||
mv ${server_folder}/${execFileName} ${toFolder}
|
||||
|
||||
if [ "${copy2Server}" == "1" ] ; then
|
||||
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]"
|
||||
cp ${server_folder}/config.yml ${toFolder}
|
||||
@@ -81,15 +84,19 @@ function build() {
|
||||
}
|
||||
|
||||
function buildLinuxAmd64() {
|
||||
build "$1/mayfly-go-linux-amd64" "linux" "amd64"
|
||||
build "$1/mayfly-go-linux-amd64" "linux" "amd64" $2
|
||||
}
|
||||
|
||||
function buildLinuxArm64() {
|
||||
build "$1/mayfly-go-linux-arm64" "linux" "arm64"
|
||||
build "$1/mayfly-go-linux-arm64" "linux" "arm64" $2
|
||||
}
|
||||
|
||||
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() {
|
||||
@@ -103,34 +110,34 @@ function runBuild() {
|
||||
cd ${toPath}
|
||||
toPath=`pwd`
|
||||
|
||||
read -p "是否构建前端[0|其他->否 1->是 2->构建并拷贝至server/static]: " runBuildWeb
|
||||
read -p "请选择构建版本[0|其他->全部 1->linux-amd64 2->linux-arm64 3->windows]: " buildType
|
||||
read -p "是否构建前端[0|其他->否 1->是 2->构建并拷贝至server/static/static]: " runBuildWeb
|
||||
read -p "请选择构建版本[0|其他->全部 1->linux-amd64 2->linux-arm64 3->windows 4->mac]: " buildType
|
||||
|
||||
if [ "${runBuildWeb}" == "1" ];then
|
||||
buildWeb
|
||||
fi
|
||||
if [ "${runBuildWeb}" == "2" ];then
|
||||
buildWeb 1
|
||||
|
||||
if [ "${runBuildWeb}" == "1" ] || [ "${runBuildWeb}" == "2" ] ; then
|
||||
buildWeb ${runBuildWeb}
|
||||
fi
|
||||
|
||||
if [ "${buildType}" == "1" ];then
|
||||
buildLinuxAmd64 ${toPath}
|
||||
exit;
|
||||
fi
|
||||
|
||||
if [ "${buildType}" == "2" ];then
|
||||
buildLinuxArm64 ${toPath}
|
||||
exit;
|
||||
fi
|
||||
|
||||
if [ "${buildType}" == "3" ];then
|
||||
buildWindows ${toPath}
|
||||
exit;
|
||||
fi
|
||||
|
||||
buildLinuxAmd64 ${toPath}
|
||||
buildLinuxArm64 ${toPath}
|
||||
buildWindows ${toPath}
|
||||
case ${buildType} in
|
||||
"1")
|
||||
buildLinuxAmd64 ${toPath} ${runBuildWeb}
|
||||
;;
|
||||
"2")
|
||||
buildLinuxArm64 ${toPath} ${runBuildWeb}
|
||||
;;
|
||||
"3")
|
||||
buildWindows ${toPath} ${runBuildWeb}
|
||||
;;
|
||||
"4")
|
||||
buildMac ${toPath} ${runBuildWeb}
|
||||
;;
|
||||
*)
|
||||
buildLinuxAmd64 ${toPath} ${runBuildWeb}
|
||||
buildLinuxArm64 ${toPath} ${runBuildWeb}
|
||||
buildWindows ${toPath} ${runBuildWeb}
|
||||
buildMac ${toPath} ${runBuildWeb}
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
runBuild
|
||||
@@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html lang="zh_CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
@@ -18,8 +18,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<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="text/javascript" src="https://api.map.baidu.com/api?v=3.0&ak=wsijQt8sLXrCW71YesmispvYHitfG9gv&s=1"></script> -->
|
||||
</body>
|
||||
</html>
|
||||
|
||||
1166
mayfly_go_web/package-lock.json
generated
1166
mayfly_go_web/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -7,26 +7,29 @@
|
||||
"lint-fix": "eslint --fix --ext .js --ext .jsx --ext .vue src/"
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.0.6",
|
||||
"axios": "^0.27.2",
|
||||
"codemirror": "^5.65.5",
|
||||
"@element-plus/icons-vue": "^2.0.10",
|
||||
"asciinema-player": "^3.0.1",
|
||||
"axios": "^1.2.0",
|
||||
"countup.js": "^2.0.7",
|
||||
"cropperjs": "^1.5.11",
|
||||
"echarts": "^5.3.3",
|
||||
"element-plus": "^2.2.9",
|
||||
"jsoneditor": "^9.9.0",
|
||||
"echarts": "^5.4.0",
|
||||
"element-plus": "^2.2.26",
|
||||
"jsencrypt": "^3.2.1",
|
||||
"lodash": "^4.17.21",
|
||||
"mitt": "^3.0.0",
|
||||
"monaco-editor": "^0.34.1",
|
||||
"monaco-sql-languages": "^0.9.5",
|
||||
"monaco-themes": "^0.4.2",
|
||||
"nprogress": "^0.2.0",
|
||||
"screenfull": "^5.1.0",
|
||||
"screenfull": "^6.0.2",
|
||||
"sortablejs": "^1.13.0",
|
||||
"sql-formatter": "^7.0.3",
|
||||
"vue": "^3.2.37",
|
||||
"sql-formatter": "^9.2.0",
|
||||
"vue": "^3.2.45",
|
||||
"vue-clipboard3": "^1.0.1",
|
||||
"vue-router": "^4.0.16",
|
||||
"vue-router": "^4.1.6",
|
||||
"vuex": "^4.0.2",
|
||||
"xterm": "^4.19.0",
|
||||
"xterm-addon-fit": "^0.5.0"
|
||||
"xterm": "^5.0.0",
|
||||
"xterm-addon-fit": "^0.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash": "^4.14.178",
|
||||
|
||||
@@ -3,3 +3,22 @@ window.globalConfig = {
|
||||
"BaseApiUrl": "",
|
||||
"BaseWsUrl": ""
|
||||
}
|
||||
|
||||
// index.html添加百秒级时间戳,防止被浏览器缓存
|
||||
!function () {
|
||||
let t = "t=" + new Date().getTime().toString().substring(0, 8)
|
||||
let search = location.search;
|
||||
let m = search && search.match(/t=\d*/g)
|
||||
|
||||
if (m[0]) {
|
||||
if (m[0] !== t) {
|
||||
location.search = search.replace(m[0], t)
|
||||
}
|
||||
} else {
|
||||
if (search.indexOf('?') > -1) {
|
||||
location.search = search + '&' + t
|
||||
} else {
|
||||
location.search = t
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
14
mayfly_go_web/shim.d.ts
vendored
14
mayfly_go_web/shim.d.ts
vendored
@@ -1,9 +1,21 @@
|
||||
/* eslint-disable */
|
||||
import {IDisposable} from 'monaco-editor';
|
||||
|
||||
declare module '*.vue' {
|
||||
import type { DefineComponent } from 'vue';
|
||||
const component: DefineComponent<{}, {}, any>;
|
||||
export default component;
|
||||
}
|
||||
declare module 'codemirror';
|
||||
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
completionItemProvider?: IDisposable | undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
declare module 'sql-formatter';
|
||||
declare module 'jsoneditor';
|
||||
declare module 'asciinema-player';
|
||||
declare module 'monaco-editor';
|
||||
|
||||
@@ -11,6 +11,8 @@ import { useStore } from '@/store/index.ts';
|
||||
import { getLocal } from '@/common/utils/storage.ts';
|
||||
import LockScreen from '@/views/layout/lockScreen/index.vue';
|
||||
import Setings from '@/views/layout/navBars/breadcrumb/setings.vue';
|
||||
import Watermark from '@/common/utils/wartermark.ts';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'app',
|
||||
components: { LockScreen, Setings },
|
||||
@@ -57,6 +59,8 @@ export default defineComponent({
|
||||
() => route.path,
|
||||
() => {
|
||||
nextTick(() => {
|
||||
// 路由变化更新水印
|
||||
Watermark.use();
|
||||
document.title = `${route.meta.title} - ${getThemeConfig.value.globalTitle}` || getThemeConfig.value.globalTitle;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
const config = {
|
||||
baseApiUrl: `${(window as any).globalConfig.BaseApiUrl}/api`,
|
||||
baseWsUrl: `${(window as any).globalConfig.BaseWsUrl || `${location.protocol == 'https:' ? 'wss:' : 'ws:'}//${location.host}`}/api`
|
||||
baseWsUrl: `${(window as any).globalConfig.BaseWsUrl || `${location.protocol == 'https:' ? 'wss:' : 'ws:'}//${location.host}`}/api`,
|
||||
|
||||
// 系统版本
|
||||
version: 'v1.3.1'
|
||||
}
|
||||
|
||||
export default config
|
||||
@@ -1,4 +1,42 @@
|
||||
import * as echarts from 'echarts'
|
||||
// import * as echarts from 'echarts'
|
||||
|
||||
// 引入 echarts 核心模块,核心模块提供了 echarts 使用必须要的接口。
|
||||
import * as echarts from "echarts/core";
|
||||
|
||||
/** 图表后缀都为 Chart */
|
||||
import { PieChart } from "echarts/charts";
|
||||
|
||||
// 引入提示框,标题,直角坐标系,数据集,内置数据转换器组件,组件后缀都为 Component
|
||||
import {
|
||||
TitleComponent,
|
||||
TooltipComponent,
|
||||
GridComponent,
|
||||
DatasetComponent,
|
||||
TransformComponent,
|
||||
LegendComponent,
|
||||
} from "echarts/components";
|
||||
|
||||
// 标签自动布局,全局过渡动画等特性
|
||||
import { LabelLayout, UniversalTransition } from "echarts/features";
|
||||
|
||||
// 引入 Canvas 渲染器,注意引入 CanvasRenderer 或者 SVGRenderer 是必须的一步
|
||||
import { CanvasRenderer } from "echarts/renderers";
|
||||
|
||||
// 注册必须的组件
|
||||
echarts.use([
|
||||
TitleComponent,
|
||||
TooltipComponent,
|
||||
GridComponent,
|
||||
DatasetComponent,
|
||||
TransformComponent,
|
||||
LegendComponent,
|
||||
// BarChart,
|
||||
LabelLayout,
|
||||
UniversalTransition,
|
||||
CanvasRenderer,
|
||||
// LineChart,
|
||||
PieChart,
|
||||
]);
|
||||
|
||||
export default function(dom: any, theme: any = null, option: any) {
|
||||
let chart = echarts.init(dom, theme);
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import request from './request'
|
||||
|
||||
export default {
|
||||
login: (param: any) => request.request('POST', '/sys/accounts/login', param, null),
|
||||
captcha: () => request.request('GET', '/sys/captcha', null, null),
|
||||
logout: (param: any) => request.request('POST', '/sys/accounts/logout/{token}', param, null),
|
||||
getMenuRoute: (param: any) => request.request('Get', '/sys/resources/account', param, null)
|
||||
login: (param: any) => request.request('POST', '/sys/accounts/login', param),
|
||||
changePwd: (param: any) => request.request('POST', '/sys/accounts/change-pwd', param),
|
||||
getPublicKey: () => request.request('GET', '/common/public-key'),
|
||||
getConfigValue: (param: any) => request.request('GET', '/sys/configs/value', param),
|
||||
captcha: () => request.request('GET', '/sys/captcha'),
|
||||
logout: (param: any) => request.request('POST', '/sys/accounts/logout/{token}', param),
|
||||
getMenuRoute: (param: any) => request.request('Get', '/sys/resources/account', param)
|
||||
}
|
||||
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)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
export function dateFormat(fmt: string, date: Date) {
|
||||
export function dateFormat2(fmt: string, date: Date) {
|
||||
let ret;
|
||||
const opt = {
|
||||
"y+": date.getFullYear().toString(), // 年
|
||||
@@ -19,5 +19,9 @@ export function dateFormat(fmt: string, date: Date) {
|
||||
}
|
||||
|
||||
export function dateStrFormat(fmt: string, dateStr: string) {
|
||||
return dateFormat(fmt, new Date(dateStr))
|
||||
return dateFormat2(fmt, new Date(dateStr))
|
||||
}
|
||||
|
||||
export function dateFormat(dateStr: string) {
|
||||
return dateFormat2('yyyy-MM-dd HH:mm:ss',new Date(dateStr))
|
||||
}
|
||||
@@ -35,3 +35,22 @@ export function removeSession(key: string) {
|
||||
export function clearSession() {
|
||||
window.sessionStorage.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function getUserInfo4Session() {
|
||||
return getSession("userInfo")
|
||||
}
|
||||
|
||||
export function setUserInfo2Session(userinfo: any) {
|
||||
setSession("userInfo", userinfo)
|
||||
}
|
||||
|
||||
// 获取是否开启水印
|
||||
export function getUseWatermark4Session() {
|
||||
return getSession("useWatermark")
|
||||
}
|
||||
|
||||
export function setUseWatermark2Session(useWatermark: boolean) {
|
||||
setSession("useWatermark", useWatermark)
|
||||
}
|
||||
@@ -1,21 +1,26 @@
|
||||
import { getUseWatermark4Session, getUserInfo4Session } from '@/common/utils/storage.ts';
|
||||
import { dateFormat2 } from '@/common/utils/date.ts'
|
||||
|
||||
// 页面添加水印效果
|
||||
const setWatermark = (str: any) => {
|
||||
const id = '1.23452384164.123412416';
|
||||
if (document.getElementById(id) !== null) document.body.removeChild(document.getElementById(id) as any);
|
||||
const can = document.createElement('canvas');
|
||||
can.width = 250;
|
||||
can.height = 180;
|
||||
can.width = 400;
|
||||
can.height = 250;
|
||||
const cans: any = can.getContext('2d');
|
||||
cans.rotate((-20 * Math.PI) / 180);
|
||||
cans.font = '12px Vedana';
|
||||
cans.fillStyle = 'rgba(200, 200, 200, 0.30)';
|
||||
cans.textAlign = 'center';
|
||||
cans.font = '14px Vedana';
|
||||
cans.fillStyle = 'rgba(200, 200, 200, 0.35)';
|
||||
cans.textAlign = 'left';
|
||||
cans.textBaseline = 'Middle';
|
||||
cans.fillText(str, can.width / 10, can.height / 2);
|
||||
// cans.fillText('mayfly go', can.width / 4, can.height )
|
||||
cans.fillText(str, can.width / 8, can.height / 2);
|
||||
|
||||
const div = document.createElement('div');
|
||||
div.id = id;
|
||||
div.style.pointerEvents = 'none';
|
||||
div.style.top = '35px';
|
||||
div.style.top = '30px';
|
||||
div.style.left = '0px';
|
||||
div.style.position = 'fixed';
|
||||
div.style.zIndex = '10000000';
|
||||
@@ -26,16 +31,34 @@ const setWatermark = (str: any) => {
|
||||
return id;
|
||||
};
|
||||
|
||||
const watermark = {
|
||||
// 设置水印
|
||||
set: (str: any) => {
|
||||
function set(str: any) {
|
||||
let id = setWatermark(str);
|
||||
if (document.getElementById(id) === null) id = setWatermark(str);
|
||||
}
|
||||
|
||||
function del() {
|
||||
let id = '1.23452384164.123412416';
|
||||
if (document.getElementById(id) !== null) document.body.removeChild(document.getElementById(id) as any);
|
||||
}
|
||||
|
||||
const watermark = {
|
||||
use: () => {
|
||||
setTimeout(() => {
|
||||
const userinfo = getUserInfo4Session()
|
||||
if (userinfo && getUseWatermark4Session()) {
|
||||
set(`${userinfo.username} ${dateFormat2('yyyy-MM-dd HH:mm:ss', new Date())}`)
|
||||
} else {
|
||||
del();
|
||||
}
|
||||
}, 1500)
|
||||
},
|
||||
// 设置水印
|
||||
set: (str: any) => {
|
||||
set(str)
|
||||
},
|
||||
// 删除水印
|
||||
del: () => {
|
||||
let id = '1.23452384164.123412416';
|
||||
if (document.getElementById(id) !== null) document.body.removeChild(document.getElementById(id) as any);
|
||||
del();
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -1,339 +0,0 @@
|
||||
<template>
|
||||
<div class="in-coder-panel">
|
||||
<textarea ref="textarea"></textarea>
|
||||
<el-select v-if="canChangeMode" class="code-mode-select" v-model="mode" @change="changeMode">
|
||||
<el-option v-for="mode in modes" :key="mode.value" :label="mode.label" :value="mode.value"> </el-option>
|
||||
</el-select>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { ref, nextTick, toRefs, reactive, watch, onMounted, defineComponent } from 'vue';
|
||||
// 引入全局实例
|
||||
import _CodeMirror from 'codemirror';
|
||||
|
||||
// 核心样式
|
||||
import 'codemirror/lib/codemirror.css';
|
||||
// 引入主题后还需要在 options 中指定主题才会生效
|
||||
import 'codemirror/theme/cobalt.css';
|
||||
import 'codemirror/addon/selection/active-line.js';
|
||||
// 匹配括号
|
||||
import 'codemirror/addon/edit/matchbrackets.js';
|
||||
import 'codemirror/addon/selection/active-line';
|
||||
import 'codemirror/addon/comment/comment';
|
||||
|
||||
// 需要引入具体的语法高亮库才会有对应的语法高亮效果
|
||||
// codemirror 官方其实支持通过 /addon/mode/loadmode.js 和 /mode/meta.js 来实现动态加载对应语法高亮库
|
||||
// 但 vue 貌似没有无法在实例初始化后再动态加载对应 JS ,所以此处才把对应的 JS 提前引入
|
||||
import 'codemirror/mode/yaml/yaml.js';
|
||||
import 'codemirror/mode/dockerfile/dockerfile.js';
|
||||
import 'codemirror/mode/nginx/nginx.js';
|
||||
import 'codemirror/mode/javascript/javascript.js';
|
||||
import 'codemirror/mode/css/css.js';
|
||||
import 'codemirror/mode/xml/xml.js';
|
||||
import 'codemirror/mode/markdown/markdown.js';
|
||||
import 'codemirror/mode/python/python.js';
|
||||
import 'codemirror/mode/shell/shell.js';
|
||||
import 'codemirror/mode/sql/sql.js';
|
||||
import 'codemirror/mode/vue/vue.js';
|
||||
import 'codemirror/mode/textile/textile.js';
|
||||
import 'codemirror/addon/hint/show-hint.css';
|
||||
import 'codemirror/addon/hint/show-hint.js';
|
||||
|
||||
import { ElOption, ElSelect } from 'element-plus';
|
||||
|
||||
// 尝试获取全局实例
|
||||
const CodeMirror = (window as any).CodeMirror || _CodeMirror;
|
||||
|
||||
export default defineComponent({
|
||||
name: 'CodeMirror',
|
||||
components: {
|
||||
ElOption,
|
||||
ElSelect,
|
||||
},
|
||||
props: {
|
||||
modelValue: {
|
||||
type: String,
|
||||
},
|
||||
language: {
|
||||
type: String,
|
||||
default: null,
|
||||
},
|
||||
height: {
|
||||
type: String,
|
||||
default: "500px",
|
||||
},
|
||||
width: {
|
||||
type: String,
|
||||
default: "auto",
|
||||
},
|
||||
canChangeMode: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
options: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
let { modelValue, language } = toRefs(props);
|
||||
const textarea: any = ref(null);
|
||||
// 编辑器实例
|
||||
let coder = null as any;
|
||||
|
||||
const state = reactive({
|
||||
coder: null as any,
|
||||
content: '',
|
||||
// 默认的语法类型
|
||||
mode: 'x-sh',
|
||||
// 默认配置
|
||||
options: {
|
||||
// 缩进格式
|
||||
tabSize: 2,
|
||||
// 主题,对应主题库 JS 需要提前引入
|
||||
theme: 'cobalt',
|
||||
// 显示行号
|
||||
lineNumbers: true,
|
||||
line: true,
|
||||
indentWithTabs: true,
|
||||
smartIndent: true,
|
||||
matchBrackets: true,
|
||||
autofocus: true,
|
||||
styleSelectedText: true,
|
||||
styleActiveLine: true, // 高亮选中行
|
||||
foldGutter: true, // 块槽
|
||||
// extraKeys: { Tab: 'autocomplete' }, // 自定义快捷键
|
||||
hintOptions: {
|
||||
// 当匹配只有一项的时候是否自动补全
|
||||
completeSingle: false,
|
||||
},
|
||||
},
|
||||
// 支持切换的语法高亮类型,对应 JS 已经提前引入
|
||||
// 使用的是 MIME-TYPE ,不过作为前缀的 text/ 在后面指定时写死了
|
||||
modes: [
|
||||
{
|
||||
value: 'x-sh',
|
||||
label: 'Shell',
|
||||
},
|
||||
{
|
||||
value: 'x-yaml',
|
||||
label: 'Yaml',
|
||||
},
|
||||
{
|
||||
value: 'x-dockerfile',
|
||||
label: 'Dockerfile',
|
||||
},
|
||||
{
|
||||
value: 'x-nginx-conf',
|
||||
label: 'Nginx',
|
||||
},
|
||||
{
|
||||
value: 'html',
|
||||
label: 'XML/HTML',
|
||||
},
|
||||
{
|
||||
value: 'x-python',
|
||||
label: 'Python',
|
||||
},
|
||||
{
|
||||
value: 'x-sql',
|
||||
label: 'SQL',
|
||||
},
|
||||
{
|
||||
value: 'css',
|
||||
label: 'CSS',
|
||||
},
|
||||
{
|
||||
value: 'javascript',
|
||||
label: 'Javascript',
|
||||
},
|
||||
{
|
||||
value: 'x-java',
|
||||
label: 'Java',
|
||||
},
|
||||
{
|
||||
value: 'x-vue',
|
||||
label: 'Vue',
|
||||
},
|
||||
{
|
||||
value: 'markdown',
|
||||
label: 'Markdown',
|
||||
},
|
||||
{
|
||||
value: 'text/x-textile',
|
||||
label: 'text',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
init();
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(newValue) => {
|
||||
handerCodeChange(newValue);
|
||||
}
|
||||
);
|
||||
|
||||
// watch(
|
||||
// () => props.options,
|
||||
// (newValue, oldValue) => {
|
||||
// for (const key in newValue) {
|
||||
// coder.setOption(key, newValue[key]);
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
|
||||
const init = () => {
|
||||
if (props.options) {
|
||||
state.options = props.options;
|
||||
}
|
||||
// 初始化编辑器实例,传入需要被实例化的文本域对象和默认配置
|
||||
coder = CodeMirror.fromTextArea(textarea.value, state.options);
|
||||
coder.setValue(modelValue.value || state.content);
|
||||
|
||||
// 支持双向绑定
|
||||
coder.on('change', (coder: any) => {
|
||||
state.content = coder.getDoc().getValue();
|
||||
emit('update:modelValue', state.content);
|
||||
});
|
||||
|
||||
coder.on('inputRead', (instance: any, changeObj: any) => {
|
||||
if (/^[a-zA-Z]/.test(changeObj.text[0])) {
|
||||
instance.showHint();
|
||||
}
|
||||
});
|
||||
|
||||
coder.setSize(props.width, props.height);
|
||||
// editor.setSize('width','height');
|
||||
|
||||
// 修改编辑器的语法配置
|
||||
setMode(language.value);
|
||||
|
||||
[
|
||||
'scroll',
|
||||
'changes',
|
||||
'beforeChange',
|
||||
'cursorActivity',
|
||||
'keyHandled',
|
||||
'inputRead',
|
||||
'electricInput',
|
||||
'beforeSelectionChange',
|
||||
'viewportChange',
|
||||
'swapDoc',
|
||||
'gutterClick',
|
||||
'gutterContextMenu',
|
||||
'focus',
|
||||
'blur',
|
||||
'refresh',
|
||||
'optionChange',
|
||||
'scrollCursorIntoView',
|
||||
'update',
|
||||
].forEach((event) => {
|
||||
// 循环事件,并兼容 run-time 事件命名
|
||||
coder.on(event, (...args: any) => {
|
||||
// console.log('当有事件触发了', event, args);
|
||||
emit(event, ...args);
|
||||
const lowerCaseEvent = event.replace(/([A-Z])/g, '-$1').toLowerCase();
|
||||
if (lowerCaseEvent !== event) {
|
||||
emit(lowerCaseEvent, ...args);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
state.coder = coder;
|
||||
// 不加无法显示内容,需点击后才可显示
|
||||
refresh();
|
||||
};
|
||||
|
||||
const refresh = () => {
|
||||
nextTick(() => {
|
||||
coder.refresh();
|
||||
});
|
||||
};
|
||||
|
||||
// 设置模式
|
||||
const setMode = (val: string) => {
|
||||
if (val) {
|
||||
// 获取具体的语法类型对象
|
||||
let modeObj = getLanguage(val);
|
||||
// 判断父容器传入的语法是否被支持
|
||||
if (modeObj) {
|
||||
state.mode = modeObj.value;
|
||||
}
|
||||
}
|
||||
// 修改编辑器的语法配置
|
||||
coder.setOption('mode', `text/${state.mode}`);
|
||||
};
|
||||
|
||||
// 获取当前语法类型
|
||||
const getLanguage = (language: string) => {
|
||||
// 在支持的语法类型列表中寻找传入的语法类型
|
||||
return state.modes.find((mode: any) => {
|
||||
// 所有的值都忽略大小写,方便比较
|
||||
let currentLanguage = language.toLowerCase();
|
||||
let currentLabel = mode.label.toLowerCase();
|
||||
let currentValue = mode.value.toLowerCase();
|
||||
|
||||
// 由于真实值可能不规范,例如 java 的真实值是 x-java ,所以讲 value 和 label 同时和传入语法进行比较
|
||||
return currentLabel === currentLanguage || currentValue === currentLanguage;
|
||||
});
|
||||
};
|
||||
|
||||
// 更改模式
|
||||
const changeMode = (val: string) => {
|
||||
setMode(val);
|
||||
// 获取修改后的语法
|
||||
let label = (getLanguage(val) as any).label.toLowerCase();
|
||||
|
||||
// 允许父容器通过以下函数监听当前的语法值
|
||||
emit('language-change', label);
|
||||
};
|
||||
|
||||
const handerCodeChange = (newVal: string) => {
|
||||
const cm_value = coder.getValue();
|
||||
if (newVal !== cm_value) {
|
||||
const scrollInfo = coder.getScrollInfo();
|
||||
coder.setValue(newVal);
|
||||
state.content = newVal;
|
||||
coder.scrollTo(scrollInfo.left, scrollInfo.top);
|
||||
refresh()
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
textarea,
|
||||
changeMode,
|
||||
refresh,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.in-coder-panel {
|
||||
flex-grow: 1;
|
||||
display: flex;
|
||||
position: relative;
|
||||
.CodeMirror {
|
||||
flex-grow: 1;
|
||||
z-index: 1;
|
||||
.CodeMirror-code {
|
||||
line-height: 19px;
|
||||
}
|
||||
font-family: 'JetBrainsMono';
|
||||
}
|
||||
|
||||
.code-mode-select {
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
right: 10px;
|
||||
top: 10px;
|
||||
max-width: 130px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,20 +0,0 @@
|
||||
import _CodeMirror from 'codemirror'
|
||||
import codemirror from './codemirror.vue'
|
||||
|
||||
const CodeMirror = window.CodeMirror || _CodeMirror
|
||||
const install = (Vue, config) => {
|
||||
if (config) {
|
||||
if (config.options) {
|
||||
codemirror.props.globalOptions.default = () => config.options
|
||||
}
|
||||
if (config.events) {
|
||||
codemirror.props.globalEvents.default = () => config.events
|
||||
}
|
||||
}
|
||||
Vue.component(codemirror.name, codemirror)
|
||||
}
|
||||
|
||||
const VueCodemirror = { CodeMirror, codemirror, install }
|
||||
|
||||
export default VueCodemirror
|
||||
export { CodeMirror, codemirror, install }
|
||||
@@ -1,133 +0,0 @@
|
||||
<template>
|
||||
<div>
|
||||
<div ref="jsoneditorVue" :style="{ height: height, width: width }"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { ref, toRefs, reactive, nextTick, watch, onMounted, onUnmounted, defineComponent } from 'vue';
|
||||
import JSONEditor from 'jsoneditor';
|
||||
import 'jsoneditor/dist/jsoneditor.min.css';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'JsonEdit',
|
||||
components: {},
|
||||
props: {
|
||||
modelValue: {
|
||||
type: [String, Object],
|
||||
},
|
||||
height: {
|
||||
type: String,
|
||||
default: '500px',
|
||||
},
|
||||
width: {
|
||||
type: String,
|
||||
default: 'auto',
|
||||
},
|
||||
options: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
currentMode: {
|
||||
type: String,
|
||||
default: 'tree',
|
||||
},
|
||||
modeList: {
|
||||
type: Array,
|
||||
default() {
|
||||
return ['tree', 'code', 'form', 'text', 'view'];
|
||||
},
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
let { modelValue, options, modeList, currentMode } = toRefs(props);
|
||||
|
||||
const jsoneditorVue = ref(null)
|
||||
// 编辑器实例
|
||||
let editor = null as any;
|
||||
// 值类型
|
||||
let valueType = 'string';
|
||||
// 是否内部改变(即onChange事件双向绑定),内部改变则不需要重新赋值给editor
|
||||
let internalChange = false;
|
||||
|
||||
const state = reactive({
|
||||
height: '500px',
|
||||
width: 'auto',
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
state.width = props.width;
|
||||
state.height = props.height;
|
||||
|
||||
init();
|
||||
setJson(modelValue.value);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
editor?.destroy();
|
||||
editor = null;
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(newValue) => {
|
||||
if (!editor) {
|
||||
init();
|
||||
}
|
||||
setJson(newValue);
|
||||
}
|
||||
);
|
||||
|
||||
const setJson = (value: any) => {
|
||||
if (internalChange) {
|
||||
return;
|
||||
}
|
||||
if (typeof value == 'string') {
|
||||
valueType = 'string';
|
||||
editor.set(JSON.parse(value));
|
||||
} else {
|
||||
valueType = 'object';
|
||||
editor.set(value);
|
||||
}
|
||||
};
|
||||
|
||||
const onChange = () => {
|
||||
try {
|
||||
const json = editor.get();
|
||||
if (valueType == 'string') {
|
||||
emit('update:modelValue', JSON.stringify(json));
|
||||
} else {
|
||||
emit('update:modelValue', json);
|
||||
}
|
||||
emit('onChange', json);
|
||||
internalChange = true;
|
||||
nextTick(() => {
|
||||
internalChange = false;
|
||||
});
|
||||
} catch (error) {}
|
||||
};
|
||||
|
||||
const init = () => {
|
||||
console.log('init json editor');
|
||||
const finalOptions = {
|
||||
...options.value,
|
||||
mode: currentMode.value,
|
||||
modes: modeList.value,
|
||||
onChange,
|
||||
};
|
||||
editor = new JSONEditor(jsoneditorVue.value, finalOptions);
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
jsoneditorVue,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
div.jsoneditor-menu a.jsoneditor-poweredBy {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
280
mayfly_go_web/src/components/monaco/MonacoEditor.vue
Normal file
280
mayfly_go_web/src/components/monaco/MonacoEditor.vue
Normal file
@@ -0,0 +1,280 @@
|
||||
<template>
|
||||
<div class="monaco-editor" style="border: 1px solid #ccc;">
|
||||
<div ref="monacoTextarea" :style="{ height: height }"></div>
|
||||
<el-select v-if="canChangeMode" class="code-mode-select" v-model="languageMode" @change="changeLanguage">
|
||||
<el-option v-for="mode in languages" :key="mode.value" :label="mode.label" :value="mode.value"> </el-option>
|
||||
</el-select>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, watch, toRefs, reactive, onMounted, onBeforeUnmount } from 'vue';
|
||||
import EditorWorker from 'monaco-editor/esm/vs/editor/editor.worker.js?worker';
|
||||
import * as monaco from 'monaco-editor';
|
||||
import { editor, languages } from 'monaco-editor';
|
||||
import JsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker'
|
||||
// 主题仓库 https://github.com/brijeshb42/monaco-themes
|
||||
// 主题例子 https://editor.bitwiser.in/
|
||||
// import Monokai from 'monaco-themes/themes/Monokai.json'
|
||||
// import Active4D from 'monaco-themes/themes/Active4D.json'
|
||||
// import ahe from 'monaco-themes/themes/All Hallows Eve.json'
|
||||
// import bop from 'monaco-themes/themes/Birds of Paradise.json'
|
||||
// import krTheme from 'monaco-themes/themes/krTheme.json'
|
||||
// import Dracula from 'monaco-themes/themes/Dracula.json'
|
||||
import SolarizedLight from 'monaco-themes/themes/Solarized-light.json'
|
||||
import { language as shellLan } from 'monaco-editor/esm/vs/basic-languages/shell/shell.js';
|
||||
import { ElOption, ElSelect } from 'element-plus';
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
type: String,
|
||||
},
|
||||
language: {
|
||||
type: String,
|
||||
default: null,
|
||||
},
|
||||
height: {
|
||||
type: String,
|
||||
default: '500px',
|
||||
},
|
||||
width: {
|
||||
type: String,
|
||||
default: 'auto',
|
||||
},
|
||||
canChangeMode: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
options: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
})
|
||||
|
||||
//定义事件
|
||||
const emit = defineEmits(['update:modelValue'])
|
||||
|
||||
const languages = [
|
||||
{
|
||||
value: 'shell',
|
||||
label: 'Shell',
|
||||
},
|
||||
{
|
||||
value: 'json',
|
||||
label: 'JSON',
|
||||
},
|
||||
{
|
||||
value: 'yaml',
|
||||
label: 'Yaml',
|
||||
},
|
||||
{
|
||||
value: 'dockerfile',
|
||||
label: 'Dockerfile',
|
||||
},
|
||||
{
|
||||
value: 'html',
|
||||
label: 'XML/HTML',
|
||||
},
|
||||
{
|
||||
value: 'python',
|
||||
label: 'Python',
|
||||
},
|
||||
{
|
||||
value: 'sql',
|
||||
label: 'SQL',
|
||||
},
|
||||
{
|
||||
value: 'css',
|
||||
label: 'CSS',
|
||||
},
|
||||
{
|
||||
value: 'javascript',
|
||||
label: 'Javascript',
|
||||
},
|
||||
{
|
||||
value: 'java',
|
||||
label: 'Java',
|
||||
},
|
||||
{
|
||||
value: 'markdown',
|
||||
label: 'Markdown',
|
||||
},
|
||||
{
|
||||
value: 'text',
|
||||
label: 'text',
|
||||
},
|
||||
];
|
||||
|
||||
const options = {
|
||||
language: 'shell',
|
||||
theme: 'SolarizedLight',
|
||||
automaticLayout: true, //自适应宽高布局
|
||||
foldingStrategy: 'indentation',//代码可分小段折叠
|
||||
roundedSelection: false, // 禁用选择文本背景的圆角
|
||||
matchBrackets: 'near',
|
||||
linkedEditing: true,
|
||||
cursorBlinking: 'smooth',// 光标闪烁样式
|
||||
mouseWheelZoom: true, // 在按住Ctrl键的同时使用鼠标滚轮时,在编辑器中缩放字体
|
||||
overviewRulerBorder: false, // 不要滚动条的边框
|
||||
tabSize: 4, // tab 缩进长度
|
||||
// fontFamily: 'JetBrainsMono', // 字体 暂时不要设置,否则光标容易错位
|
||||
fontWeight: 'bold',
|
||||
// fontSize: 12,
|
||||
// letterSpacing: 1, 字符间距
|
||||
// quickSuggestions:false, // 禁用代码提示
|
||||
minimap: {
|
||||
enabled: false, // 不要小地图
|
||||
},
|
||||
}
|
||||
|
||||
const state = reactive({
|
||||
languageMode: 'shell',
|
||||
})
|
||||
|
||||
const {
|
||||
languageMode,
|
||||
} = toRefs(state)
|
||||
|
||||
onMounted(() => {
|
||||
state.languageMode = props.language;
|
||||
initMonacoEditorIns();
|
||||
setEditorValue(props.modelValue);
|
||||
registerCompletionItemProvider();
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (monacoEditorIns) {
|
||||
monacoEditorIns.dispose();
|
||||
}
|
||||
if (completionItemProvider) {
|
||||
completionItemProvider.dispose();
|
||||
}
|
||||
})
|
||||
|
||||
watch(() => props.modelValue, (newValue: any) => {
|
||||
if (!monacoEditorIns.hasTextFocus()) {
|
||||
state.languageMode = props.language;
|
||||
monacoEditorIns?.setValue(newValue);
|
||||
}
|
||||
})
|
||||
|
||||
watch(() => props.language, (newValue: any) => {
|
||||
changeLanguage(newValue);
|
||||
})
|
||||
|
||||
|
||||
const monacoTextarea: any = ref(null);
|
||||
|
||||
let monacoEditorIns: editor.IStandaloneCodeEditor = null as any;
|
||||
let completionItemProvider: any = null;
|
||||
|
||||
self.MonacoEnvironment = {
|
||||
getWorker(_: any, label: string) {
|
||||
if (label === 'json') {
|
||||
return new JsonWorker()
|
||||
}
|
||||
return new EditorWorker();
|
||||
}
|
||||
};
|
||||
|
||||
const initMonacoEditorIns = () => {
|
||||
console.log('初始化monaco编辑器')
|
||||
// options参数参考 https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.IStandaloneEditorConstructionOptions.html#language
|
||||
// 初始化一些主题
|
||||
monaco.editor.defineTheme('SolarizedLight', SolarizedLight);
|
||||
options.language = state.languageMode;
|
||||
// 从localStorage中获取,通过store可能存在父子组件都使用store报错
|
||||
options.theme = JSON.parse(localStorage.getItem('themeConfig') as string).editorTheme || 'vs';
|
||||
monacoEditorIns = monaco.editor.create(monacoTextarea.value, Object.assign(options, props.options as any));
|
||||
|
||||
// 监听内容改变,双向绑定
|
||||
monacoEditorIns.onDidChangeModelContent(() => {
|
||||
emit('update:modelValue', monacoEditorIns.getModel()?.getValue());
|
||||
})
|
||||
|
||||
// 动态设置主题
|
||||
// monaco.editor.setTheme('hc-black');
|
||||
};
|
||||
|
||||
const changeLanguage = (value: any) => {
|
||||
console.log('change lan');
|
||||
// 获取当前的文档模型
|
||||
let oldModel = monacoEditorIns.getModel()
|
||||
if (!oldModel) {
|
||||
return;
|
||||
}
|
||||
// 创建一个新的文档模型
|
||||
let newModel = monaco.editor.createModel(oldModel.getValue(), value)
|
||||
// 设置成新的
|
||||
monacoEditorIns.setModel(newModel)
|
||||
// 销毁旧的模型
|
||||
if (oldModel) {
|
||||
oldModel.dispose()
|
||||
}
|
||||
|
||||
registerCompletionItemProvider();
|
||||
}
|
||||
|
||||
const setEditorValue = (value: any) => {
|
||||
monacoEditorIns.getModel()?.setValue(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册联想补全提示
|
||||
*/
|
||||
const registerCompletionItemProvider = () => {
|
||||
if (completionItemProvider) {
|
||||
completionItemProvider.dispose();
|
||||
}
|
||||
if (state.languageMode == 'shell') {
|
||||
registeShell()
|
||||
}
|
||||
}
|
||||
|
||||
const registeShell = () => {
|
||||
completionItemProvider = monaco.languages.registerCompletionItemProvider('shell', {
|
||||
provideCompletionItems: async () => {
|
||||
let suggestions: languages.CompletionItem[] = []
|
||||
shellLan.keywords.forEach((item: any) => {
|
||||
suggestions.push({
|
||||
label: item,
|
||||
kind: monaco.languages.CompletionItemKind.Keyword,
|
||||
insertText: item,
|
||||
} as any);
|
||||
})
|
||||
shellLan.builtins.forEach((item: any) => {
|
||||
suggestions.push({
|
||||
label: item,
|
||||
kind: monaco.languages.CompletionItemKind.Property,
|
||||
insertText: item,
|
||||
} as any);
|
||||
})
|
||||
return {
|
||||
suggestions: suggestions
|
||||
};
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
const format = () => {
|
||||
/*
|
||||
触发自动格式化;
|
||||
*/
|
||||
monacoEditorIns.trigger('', 'editor.action.formatDocument', '')
|
||||
}
|
||||
|
||||
defineExpose({ format })
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.monaco-editor {
|
||||
.code-mode-select {
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
right: 10px;
|
||||
top: 10px;
|
||||
max-width: 130px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -2,7 +2,8 @@ import RouterParent from '@/views/layout/routerView/parent.vue';
|
||||
|
||||
export const imports = {
|
||||
'RouterParent': RouterParent,
|
||||
"Home": () => import('@/views/home/index.vue'),
|
||||
|
||||
"Home": () => import('@/views/home/Home.vue'),
|
||||
'Personal': () => import('@/views/personal/index.vue'),
|
||||
// machine
|
||||
"MachineList": () => import('@/views/ops/machine'),
|
||||
@@ -11,8 +12,11 @@ export const imports = {
|
||||
"RoleList": () => import('@/views/system/role'),
|
||||
"AccountList": () => import('@/views/system/account'),
|
||||
"SyslogList": () => import('@/views/system/syslog/SyslogList.vue'),
|
||||
// project
|
||||
"ProjectList": () => import('@/views/ops/project/ProjectList.vue'),
|
||||
"ConfigList": () => import('@/views/system/config/ConfigList.vue'),
|
||||
|
||||
// tag
|
||||
"TagTreeList": () => import('@/views/ops/tag/TagTreeList.vue'),
|
||||
"TeamList": () => import('@/views/ops/tag/TeamList.vue'),
|
||||
// db
|
||||
"DbList": () => import('@/views/ops/db/DbList.vue'),
|
||||
"SqlExec": () => import('@/views/ops/db'),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
import Layout from '@/views/layout/index.vue'
|
||||
import RouterParent from '@/views/layout/routerView/parent.vue';
|
||||
// import RouterParent from '@/views/layout/routerView/parent.vue';
|
||||
|
||||
// 定义动态路由
|
||||
export const dynamicRoutes = [
|
||||
@@ -12,119 +12,108 @@ export const dynamicRoutes = [
|
||||
meta: {
|
||||
isKeepAlive: true,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '/home',
|
||||
name: 'home',
|
||||
component: () => import('@/views/home/index.vue'),
|
||||
meta: {
|
||||
title: '首页',
|
||||
// iframe链接
|
||||
link: '',
|
||||
// 是否在菜单栏显示,默认显示
|
||||
isHide: false,
|
||||
isKeepAlive: true,
|
||||
// tag标签是否不可删除
|
||||
isAffix: true,
|
||||
// 是否为iframe
|
||||
isIframe: false,
|
||||
icon: 'el-icon-s-home',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/sys',
|
||||
name: 'Resource',
|
||||
redirect: '/sys/resources',
|
||||
meta: {
|
||||
title: '系统管理',
|
||||
// 资源code,用于校验用户是否拥有该资源权限
|
||||
code: 'sys',
|
||||
// children: [
|
||||
// {
|
||||
// path: '/home',
|
||||
// name: 'home',
|
||||
// component: () => import('@/views/home/index.vue'),
|
||||
// meta: {
|
||||
// title: '首页',
|
||||
// // iframe链接
|
||||
// link: '',
|
||||
// // 是否在菜单栏显示,默认显示
|
||||
// isHide: false,
|
||||
// isKeepAlive: true,
|
||||
icon: 'el-icon-monitor',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'sys/resources',
|
||||
name: 'ResourceList',
|
||||
component: () => import('@/views/system/resource'),
|
||||
meta: {
|
||||
title: '资源管理',
|
||||
code: 'resource:list',
|
||||
isKeepAlive: true,
|
||||
icon: 'el-icon-menu',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'sys/roles',
|
||||
name: 'RoleList',
|
||||
component: () => import('@/views/system/role'),
|
||||
meta: {
|
||||
title: '角色管理',
|
||||
code: 'role:list',
|
||||
isKeepAlive: true,
|
||||
icon: 'el-icon-menu',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'sys/accounts',
|
||||
name: 'ResourceList',
|
||||
component: () => import('@/views/system/account'),
|
||||
meta: {
|
||||
title: '账号管理',
|
||||
code: 'account:list',
|
||||
isKeepAlive: true,
|
||||
icon: 'el-icon-menu',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/machine',
|
||||
name: 'Machine',
|
||||
redirect: '/machine/list',
|
||||
meta: {
|
||||
title: '机器管理',
|
||||
// 资源code,用于校验用户是否拥有该资源权限
|
||||
code: 'machine',
|
||||
// // tag标签是否不可删除
|
||||
// isAffix: true,
|
||||
// // 是否为iframe
|
||||
// isIframe: false,
|
||||
// icon: 'el-icon-s-home',
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// path: '/sys',
|
||||
// name: 'Resource',
|
||||
// redirect: '/sys/resources',
|
||||
// meta: {
|
||||
// title: '系统管理',
|
||||
// // 资源code,用于校验用户是否拥有该资源权限
|
||||
// code: 'sys',
|
||||
// // isKeepAlive: true,
|
||||
// icon: 'el-icon-monitor',
|
||||
// },
|
||||
// children: [
|
||||
// {
|
||||
// path: 'sys/resources',
|
||||
// name: 'ResourceList',
|
||||
// component: () => import('@/views/system/resource'),
|
||||
// meta: {
|
||||
// title: '资源管理',
|
||||
// code: 'resource:list',
|
||||
// isKeepAlive: true,
|
||||
icon: 'el-icon-monitor',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '/list',
|
||||
name: 'MachineList',
|
||||
component: () => import('@/views/ops/machine'),
|
||||
meta: {
|
||||
title: '机器列表',
|
||||
code: 'machine:list',
|
||||
isKeepAlive: true,
|
||||
icon: 'el-icon-menu',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/personal',
|
||||
name: 'personal',
|
||||
component: () => import('@/views/personal/index.vue'),
|
||||
meta: {
|
||||
title: '个人中心',
|
||||
isKeepAlive: true,
|
||||
icon: 'el-icon-user',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/iframes',
|
||||
name: 'layoutIfameView',
|
||||
component: RouterParent,
|
||||
meta: {
|
||||
title: 'iframe',
|
||||
link: 'https://gitee.com/lyt-top/vue-next-admin',
|
||||
isIframe: true,
|
||||
icon: 'el-icon-menu',
|
||||
},
|
||||
},
|
||||
],
|
||||
// icon: 'el-icon-menu',
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// path: 'sys/roles',
|
||||
// name: 'RoleList',
|
||||
// component: () => import('@/views/system/role'),
|
||||
// meta: {
|
||||
// title: '角色管理',
|
||||
// code: 'role:list',
|
||||
// isKeepAlive: true,
|
||||
// icon: 'el-icon-menu',
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// path: 'sys/accounts',
|
||||
// name: 'ResourceList',
|
||||
// component: () => import('@/views/system/account'),
|
||||
// meta: {
|
||||
// title: '账号管理',
|
||||
// code: 'account:list',
|
||||
// isKeepAlive: true,
|
||||
// icon: 'el-icon-menu',
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
// {
|
||||
// path: '/machine',
|
||||
// name: 'Machine',
|
||||
// redirect: '/machine/list',
|
||||
// meta: {
|
||||
// title: '机器管理',
|
||||
// // 资源code,用于校验用户是否拥有该资源权限
|
||||
// code: 'machine',
|
||||
// // isKeepAlive: true,
|
||||
// icon: 'el-icon-monitor',
|
||||
// },
|
||||
// children: [
|
||||
// {
|
||||
// path: '/list',
|
||||
// name: 'MachineList',
|
||||
// component: () => import('@/views/ops/machine'),
|
||||
// meta: {
|
||||
// title: '机器列表',
|
||||
// code: 'machine:list',
|
||||
// isKeepAlive: true,
|
||||
// icon: 'el-icon-menu',
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
// {
|
||||
// path: '/personal',
|
||||
// name: 'personal',
|
||||
// component: () => import('@/views/personal/index.vue'),
|
||||
// meta: {
|
||||
// title: '个人中心',
|
||||
// isKeepAlive: true,
|
||||
// icon: 'el-icon-user',
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
},
|
||||
];
|
||||
|
||||
@@ -163,7 +152,6 @@ export const staticRoutes: Array<RouteRecordRaw> = [
|
||||
title: '终端 | {name}',
|
||||
// 是否根据query对标题名进行参数替换,即最终显示为‘终端_机器名’
|
||||
titleRename: true,
|
||||
icon: 'iconfont icon-caidan',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@@ -5,6 +5,9 @@ import themeConfig from '@/store/modules/themeConfig.ts';
|
||||
import routesList from '@/store/modules/routesList.ts';
|
||||
import keepAliveNames from '@/store/modules/keepAliveNames.ts';
|
||||
import userInfos from '@/store/modules/userInfos.ts';
|
||||
import sqlExecInfo from '@/store/modules/mysqlDbOptInfo.ts';
|
||||
import redisDbOptInfo from '@/store/modules/redisDbOptInfo.ts';
|
||||
import mongoDbOptInfo from '@/store/modules/mongoDbOptInfo.ts';
|
||||
|
||||
export const key: InjectionKey<Store<RootStateTypes>> = Symbol();
|
||||
|
||||
@@ -14,6 +17,9 @@ export const store = createStore<RootStateTypes>({
|
||||
routesList,
|
||||
keepAliveNames,
|
||||
userInfos,
|
||||
sqlExecInfo,
|
||||
redisDbOptInfo,
|
||||
mongoDbOptInfo,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -52,6 +52,8 @@ export interface ThemeConfigState {
|
||||
terminalBackground: string;
|
||||
terminalCursor: string;
|
||||
terminalFontSize: number;
|
||||
terminalFontWeight: string;
|
||||
editorTheme: string;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -70,6 +72,15 @@ export interface UserInfosState {
|
||||
userInfos: object;
|
||||
}
|
||||
|
||||
// 数据操作信息
|
||||
export interface DbOptInfoState {
|
||||
dbOptInfo: {
|
||||
tagPath?: string,
|
||||
dbId?: number,
|
||||
db?: string,
|
||||
}
|
||||
}
|
||||
|
||||
// 后端返回原始路由(未处理时)
|
||||
// export interface RequestOldRoutesState {
|
||||
// requestOldRoutes: Array<object>;
|
||||
@@ -81,5 +92,8 @@ export interface RootStateTypes {
|
||||
routesList: RoutesListState;
|
||||
keepAliveNames: KeepAliveNamesState;
|
||||
userInfos: UserInfosState;
|
||||
sqlExecInfo: DbOptInfoState;
|
||||
redisDbOptInfo: DbOptInfoState;
|
||||
mongoDbOptInfo: DbOptInfoState;
|
||||
// requestOldRoutes: RequestOldRoutesState;
|
||||
}
|
||||
|
||||
30
mayfly_go_web/src/store/modules/mongoDbOptInfo.ts
Normal file
30
mayfly_go_web/src/store/modules/mongoDbOptInfo.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Module } from 'vuex';
|
||||
// 此处加上 `.ts` 后缀报错,具体原因不详
|
||||
import {DbOptInfoState, RootStateTypes} from '@/store/interface';
|
||||
|
||||
const mongoDbOptInfoModule: Module<DbOptInfoState, RootStateTypes> = {
|
||||
namespaced: true,
|
||||
state: {
|
||||
dbOptInfo: {
|
||||
tagPath: '',
|
||||
dbId: 0,
|
||||
db: '0',
|
||||
},
|
||||
},
|
||||
mutations: {
|
||||
// 设置用户信息
|
||||
getMongoDbOptInfo(state: any, data: object) {
|
||||
state.dbOptInfo = data;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
// 设置用户信息
|
||||
async setMongoDbOptInfo({ commit }, data: object) {
|
||||
if (data) {
|
||||
commit('getMongoDbOptInfo', data);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default mongoDbOptInfoModule;
|
||||
30
mayfly_go_web/src/store/modules/mysqlDbOptInfo.ts
Normal file
30
mayfly_go_web/src/store/modules/mysqlDbOptInfo.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Module } from 'vuex';
|
||||
// 此处加上 `.ts` 后缀报错,具体原因不详
|
||||
import { DbOptInfoState, RootStateTypes } from '@/store/interface';
|
||||
|
||||
const sqlExecInfoModule: Module<DbOptInfoState, RootStateTypes> = {
|
||||
namespaced: true,
|
||||
state: {
|
||||
dbOptInfo: {
|
||||
tagPath: '',
|
||||
dbId: 0,
|
||||
db: '0',
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
// 设置用户信息
|
||||
getSqlExecInfo(state: any, data: object) {
|
||||
state.dbOptInfo = data;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
// 设置用户信息
|
||||
async setSqlExecInfo({ commit }, data: object) {
|
||||
if (data) {
|
||||
commit('getSqlExecInfo', data);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default sqlExecInfoModule;
|
||||
30
mayfly_go_web/src/store/modules/redisDbOptInfo.ts
Normal file
30
mayfly_go_web/src/store/modules/redisDbOptInfo.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Module } from 'vuex';
|
||||
// 此处加上 `.ts` 后缀报错,具体原因不详
|
||||
import {DbOptInfoState, RootStateTypes} from '@/store/interface';
|
||||
|
||||
const redisDbOptInfoModule: Module<DbOptInfoState, RootStateTypes> = {
|
||||
namespaced: true,
|
||||
state: {
|
||||
dbOptInfo: {
|
||||
tagPath: '',
|
||||
dbId: 0,
|
||||
db: '0',
|
||||
},
|
||||
},
|
||||
mutations: {
|
||||
// 设置用户信息
|
||||
getRedisDbOptInfo(state: any, data: object) {
|
||||
state.dbOptInfo = data;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
// 设置用户信息
|
||||
async setRedisDbOptInfo({ commit }, data: object) {
|
||||
if (data) {
|
||||
commit('getRedisDbOptInfo', data);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default redisDbOptInfoModule;
|
||||
@@ -113,6 +113,10 @@ const themeConfigModule: Module<ThemeConfigState, RootStateTypes> = {
|
||||
// ssh终端cursor色
|
||||
terminalCursor: '#268F81',
|
||||
terminalFontSize: 15,
|
||||
terminalFontWeight: 'normal',
|
||||
|
||||
// 编辑器主题
|
||||
editorTheme: 'vs',
|
||||
|
||||
|
||||
/* 后端控制路由
|
||||
|
||||
@@ -14,7 +14,7 @@ body,
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-family: Microsoft YaHei, Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, SimSun, sans-serif;
|
||||
font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
|
||||
font-weight: 450;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
@@ -290,3 +290,7 @@ body,
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
}
|
||||
|
||||
.el-table-z-index-inherit .el-table .el-table__cell {
|
||||
z-index: inherit !important;
|
||||
}
|
||||
@@ -947,12 +947,6 @@
|
||||
.el-select-dropdown .el-scrollbar__wrap {
|
||||
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 抽屉
|
||||
------------------------------- */
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
@import './base.scss';
|
||||
@import './other.scss';
|
||||
@import './element.scss';
|
||||
@import './iconSelector.scss';
|
||||
@import './media/media.scss';
|
||||
@import './waves.scss';
|
||||
@import './iconSelector.scss';
|
||||
@@ -7,13 +7,14 @@
|
||||
<img :src="getUserInfos.photo" />
|
||||
<div class="home-card-first-right ml15">
|
||||
<div class="flex-margin">
|
||||
<div class="home-card-first-right-title">{{ `${currentTime}, ${getUserInfos.username}` }}</div>
|
||||
<div class="home-card-first-right-title">{{ `${currentTime}, ${getUserInfos.username}`
|
||||
}}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-col>
|
||||
<el-col :sm="3" class="mb15" v-for="(v, k) in topCardItemList" :key="k">
|
||||
<el-col :sm="3" class="mb15" v-for="(v, k) in topCardItemList as any" :key="k">
|
||||
<div @click="toPage(v)" class="home-card-item home-card-item-box" :style="{ background: v.color }">
|
||||
<div class="home-card-item-flex">
|
||||
<div class="home-card-item-title pb3">{{ v.title }}</div>
|
||||
@@ -26,7 +27,7 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, reactive, onMounted, nextTick, computed } from 'vue';
|
||||
import { useStore } from '@/store/index.ts';
|
||||
// import * as echarts from 'echarts';
|
||||
@@ -34,37 +35,38 @@ import { CountUp } from 'countup.js';
|
||||
import { formatAxis } from '@/common/utils/formatTime.ts';
|
||||
import { indexApi } from './api';
|
||||
import { useRouter } from 'vue-router';
|
||||
export default {
|
||||
name: 'HomePage',
|
||||
setup() {
|
||||
// const { proxy } = getCurrentInstance() as any;
|
||||
|
||||
const router = useRouter();
|
||||
const store = useStore();
|
||||
const state = reactive({
|
||||
topCardItemList: [
|
||||
{
|
||||
title: '项目数',
|
||||
id: 'projectNum',
|
||||
color: '#FEBB50',
|
||||
},
|
||||
{
|
||||
title: 'Linux机器数',
|
||||
title: 'Linux机器',
|
||||
id: 'machineNum',
|
||||
color: '#F95959',
|
||||
},
|
||||
{
|
||||
title: '数据库总数',
|
||||
title: '数据库',
|
||||
id: 'dbNum',
|
||||
color: '#8595F4',
|
||||
},
|
||||
{
|
||||
title: 'redis总数',
|
||||
title: 'redis',
|
||||
id: 'redisNum',
|
||||
color: '#1abc9c',
|
||||
},
|
||||
{
|
||||
title: 'Mongo',
|
||||
id: 'mongoNum',
|
||||
color: '#FEBB50',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const {
|
||||
topCardItemList,
|
||||
} = toRefs(state)
|
||||
|
||||
// 当前时间提示语
|
||||
const currentTime = computed(() => {
|
||||
return formatAxis(new Date());
|
||||
@@ -74,7 +76,7 @@ export default {
|
||||
const initNumCountUp = async () => {
|
||||
const res: any = await indexApi.getIndexCount.request();
|
||||
nextTick(() => {
|
||||
new CountUp('projectNum', res.projectNum).start();
|
||||
new CountUp('mongoNum', res.mongoNum).start();
|
||||
new CountUp('machineNum', res.machineNum).start();
|
||||
new CountUp('dbNum', res.dbNum).start();
|
||||
new CountUp('redisNum', res.redisNum).start();
|
||||
@@ -87,20 +89,20 @@ export default {
|
||||
router.push('/personal');
|
||||
break;
|
||||
}
|
||||
case 'projectNum': {
|
||||
router.push('/ops/projects');
|
||||
case 'mongoNum': {
|
||||
router.push('/mongo/mongo-data-operation');
|
||||
break;
|
||||
}
|
||||
case 'machineNum': {
|
||||
router.push('/ops/machines');
|
||||
router.push('/machine/machines');
|
||||
break;
|
||||
}
|
||||
case 'dbNum': {
|
||||
router.push('/ops/dbms/dbs');
|
||||
router.push('/dbms/sql-exec');
|
||||
break;
|
||||
}
|
||||
case 'redisNum': {
|
||||
router.push('/ops/redis/manage');
|
||||
router.push('/redis/data-operation');
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -117,20 +119,12 @@ export default {
|
||||
const getUserInfos = computed(() => {
|
||||
return store.state.userInfos.userInfos;
|
||||
});
|
||||
|
||||
return {
|
||||
getUserInfos,
|
||||
currentTime,
|
||||
toPage,
|
||||
...toRefs(state),
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.home-container {
|
||||
overflow-x: hidden;
|
||||
|
||||
.home-card-item {
|
||||
width: 100%;
|
||||
height: 103px;
|
||||
@@ -138,16 +132,19 @@ export default {
|
||||
border-radius: 4px;
|
||||
transition: all ease 0.3s;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
|
||||
transition: all ease 0.3s;
|
||||
}
|
||||
}
|
||||
|
||||
.home-card-item-box {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
|
||||
&:hover {
|
||||
i {
|
||||
right: 0px !important;
|
||||
@@ -155,6 +152,7 @@ export default {
|
||||
transition: all ease 0.3s;
|
||||
}
|
||||
}
|
||||
|
||||
i {
|
||||
position: absolute;
|
||||
right: -10px;
|
||||
@@ -163,48 +161,59 @@ export default {
|
||||
transform: rotate(-30deg);
|
||||
transition: all ease 0.3s;
|
||||
}
|
||||
|
||||
.home-card-item-flex {
|
||||
padding: 0 20px;
|
||||
color: white;
|
||||
|
||||
.home-card-item-title,
|
||||
.home-card-item-tip {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.home-card-item-title-num {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.home-card-item-tip-num {
|
||||
font-size: 13px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.home-card-first {
|
||||
background: white;
|
||||
border: 1px solid #ebeef5;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
img {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 100%;
|
||||
border: 2px solid var(--color-primary-light-5);
|
||||
}
|
||||
|
||||
.home-card-first-right {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.home-card-first-right-msg {
|
||||
font-size: 13px;
|
||||
color: gray;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.home-monitor {
|
||||
height: 200px;
|
||||
|
||||
.flex-warp-item {
|
||||
width: 50%;
|
||||
height: 100px;
|
||||
display: flex;
|
||||
|
||||
.flex-warp-item-box {
|
||||
margin: auto;
|
||||
height: auto;
|
||||
@@ -212,19 +221,24 @@ export default {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.home-warning-card {
|
||||
height: 292px;
|
||||
|
||||
::v-deep(.el-card) {
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.home-dynamic {
|
||||
height: 200px;
|
||||
|
||||
.home-dynamic-item {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 60px;
|
||||
overflow: hidden;
|
||||
|
||||
&:first-of-type {
|
||||
.home-dynamic-item-line {
|
||||
i {
|
||||
@@ -232,20 +246,24 @@ export default {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.home-dynamic-item-left {
|
||||
text-align: right;
|
||||
.home-dynamic-item-left-time1 {
|
||||
}
|
||||
|
||||
.home-dynamic-item-left-time1 {}
|
||||
|
||||
.home-dynamic-item-left-time2 {
|
||||
font-size: 13px;
|
||||
color: gray;
|
||||
}
|
||||
}
|
||||
|
||||
.home-dynamic-item-line {
|
||||
height: 60px;
|
||||
border-right: 2px dashed #dfdfdf;
|
||||
margin: 0 20px;
|
||||
position: relative;
|
||||
|
||||
i {
|
||||
color: var(--color-primary);
|
||||
font-size: 12px;
|
||||
@@ -256,8 +274,10 @@ export default {
|
||||
background: white;
|
||||
}
|
||||
}
|
||||
|
||||
.home-dynamic-item-right {
|
||||
flex: 1;
|
||||
|
||||
.home-dynamic-item-right-title {
|
||||
i {
|
||||
margin-right: 5px;
|
||||
@@ -270,6 +290,7 @@ export default {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.home-dynamic-item-right-label {
|
||||
font-size: 13px;
|
||||
color: gray;
|
||||
@@ -83,7 +83,7 @@ export default defineComponent({
|
||||
() => route.path,
|
||||
() => {
|
||||
initCurrentRouteMeta(route.meta);
|
||||
proxy.$refs.layoutScrollbarRef.wrap$.scrollTop = 0;
|
||||
proxy.$refs.layoutScrollbarRef.wrapRef.scrollTop = 0;
|
||||
}
|
||||
);
|
||||
return {
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
<template>
|
||||
<div class="layout-logo" v-if="setShowLogo" @click="onThemeConfigChange">
|
||||
<img src="@/assets/image/logo.svg" class="layout-logo-medium-img" />
|
||||
<span>{{ getThemeConfig.globalTitle }}</span>
|
||||
<span>
|
||||
{{ `${getThemeConfig.globalTitle}` }}
|
||||
<sub><span style="font-size: 10px;color:goldenrod">{{ ` ${config.version}` }}</span></sub>
|
||||
</span>
|
||||
</div>
|
||||
<div class="layout-logo-size" v-else @click="onThemeConfigChange">
|
||||
<img src="@/assets/image/logo.svg" class="layout-logo-size-img" />
|
||||
@@ -11,6 +14,7 @@
|
||||
<script lang="ts">
|
||||
import { computed, getCurrentInstance } from 'vue';
|
||||
import { useStore } from '@/store/index.ts';
|
||||
import config from '@/common/config.ts';
|
||||
export default {
|
||||
name: 'layoutLogo',
|
||||
setup() {
|
||||
@@ -32,6 +36,7 @@ export default {
|
||||
store.state.themeConfig.themeConfig.isCollapse = !store.state.themeConfig.themeConfig.isCollapse;
|
||||
};
|
||||
return {
|
||||
config,
|
||||
setShowLogo,
|
||||
getThemeConfig,
|
||||
onThemeConfigChange,
|
||||
@@ -52,26 +57,31 @@ export default {
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
animation: logoAnimation 0.3s ease-in-out;
|
||||
|
||||
&:hover {
|
||||
span {
|
||||
color: var(--color-primary-light-2);
|
||||
}
|
||||
}
|
||||
|
||||
&-medium-img {
|
||||
width: 20px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
.layout-logo-size {
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
display: flex;
|
||||
cursor: pointer;
|
||||
animation: logoAnimation 0.3s ease-in-out;
|
||||
|
||||
&-img {
|
||||
width: 20px;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
img {
|
||||
animation: logoAnimation 0.3s ease-in-out;
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
</el-input-number>
|
||||
</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-value">
|
||||
<el-select @change="setLocalThemeConfig" v-model="getThemeConfig.terminalFontWeight" size="small" style="width: 90px">
|
||||
@@ -48,7 +48,19 @@
|
||||
<el-option label="bold" value="bold"> </el-option>
|
||||
</el-select>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
|
||||
<el-divider content-position="left">editor 设置</el-divider>
|
||||
<div class="layout-breadcrumb-seting-bar-flex">
|
||||
<div class="layout-breadcrumb-seting-bar-flex-label">主题</div>
|
||||
<div class="layout-breadcrumb-seting-bar-flex-value">
|
||||
<el-select @change="setLocalThemeConfig" v-model="getThemeConfig.editorTheme" size="small" style="width: 130px">
|
||||
<el-option label="vs" value="vs"> </el-option>
|
||||
<el-option label="vs-dark" value="vs-dark"> </el-option>
|
||||
<el-option label="SolarizedLight" value="SolarizedLight"> </el-option>
|
||||
</el-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 全局主题 -->
|
||||
<el-divider content-position="left">全局主题</el-divider>
|
||||
@@ -273,23 +285,6 @@
|
||||
<el-switch v-model="getThemeConfig.isInvert" @change="onAddFilterChange('invert')"></el-switch>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layout-breadcrumb-seting-bar-flex mt15">
|
||||
<div class="layout-breadcrumb-seting-bar-flex-label">开启水印</div>
|
||||
<div class="layout-breadcrumb-seting-bar-flex-value">
|
||||
<el-switch v-model="getThemeConfig.isWartermark" @change="onWartermarkChange"></el-switch>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layout-breadcrumb-seting-bar-flex mt14">
|
||||
<div class="layout-breadcrumb-seting-bar-flex-label">水印文案</div>
|
||||
<div class="layout-breadcrumb-seting-bar-flex-value">
|
||||
<el-input
|
||||
v-model="getThemeConfig.wartermarkText"
|
||||
size="small"
|
||||
style="width: 90px"
|
||||
@input="onWartermarkTextInput($event)"
|
||||
></el-input>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 其它设置 -->
|
||||
<el-divider content-position="left">其他设置</el-divider>
|
||||
@@ -440,8 +435,6 @@ import { ElMessage } from 'element-plus';
|
||||
import ClipboardJS from 'clipboard';
|
||||
import { useStore } from '@/store/index.ts';
|
||||
import { getLightColor } from '@/common/utils/theme.ts';
|
||||
import Watermark from '@/common/utils/wartermark.ts';
|
||||
import { verifyAndSpace } from '@/common/utils/toolsValidate.ts';
|
||||
import { setLocal, getLocal, removeLocal } from '@/common/utils/storage.ts';
|
||||
export default defineComponent({
|
||||
name: 'layoutBreadcrumbSeting',
|
||||
@@ -572,18 +565,6 @@ export default defineComponent({
|
||||
setLocalThemeConfig();
|
||||
setLocal('appFilterStyle', appEle.style.cssText);
|
||||
};
|
||||
// 4、界面显示 --> 开启水印
|
||||
const onWartermarkChange = () => {
|
||||
getThemeConfig.value.isWartermark ? Watermark.set(getThemeConfig.value.wartermarkText) : Watermark.del();
|
||||
setLocalThemeConfig();
|
||||
};
|
||||
// 4、界面显示 --> 水印文案
|
||||
const onWartermarkTextInput = (val: string) => {
|
||||
getThemeConfig.value.wartermarkText = verifyAndSpace(val);
|
||||
if (getThemeConfig.value.wartermarkText === '') return false;
|
||||
if (getThemeConfig.value.isWartermark) Watermark.set(getThemeConfig.value.wartermarkText);
|
||||
setLocalThemeConfig();
|
||||
};
|
||||
// 5、布局切换
|
||||
const onSetLayout = (layout: string) => {
|
||||
setLocal('oldLayout', layout);
|
||||
@@ -735,8 +716,6 @@ export default defineComponent({
|
||||
const appEl: any = document.querySelector('#app');
|
||||
appEl.style.cssText = getLocal('appFilterStyle');
|
||||
}
|
||||
// 开启水印
|
||||
onWartermarkChange();
|
||||
// // 语言国际化
|
||||
// if (getLocal('themeConfig')) proxy.$i18n.locale = getLocal('themeConfig').globalI18n;
|
||||
}, 1100);
|
||||
@@ -762,8 +741,6 @@ export default defineComponent({
|
||||
getThemeConfig,
|
||||
onDrawerClose,
|
||||
onAddFilterChange,
|
||||
onWartermarkChange,
|
||||
onWartermarkTextInput,
|
||||
onSetLayout,
|
||||
setLocalThemeConfig,
|
||||
onClassicSplitMenuChange,
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
<div class="layout-navbars-breadcrumb-user-icon" @click="onSearchClick">
|
||||
<!-- <div class="layout-navbars-breadcrumb-user-icon" @click="onSearchClick">
|
||||
<el-icon title="菜单搜索">
|
||||
<search />
|
||||
</el-icon>
|
||||
</div>
|
||||
</div> -->
|
||||
<div class="layout-navbars-breadcrumb-user-icon" @click="onLayoutSetingClick">
|
||||
<el-icon title="布局设置">
|
||||
<setting />
|
||||
@@ -28,12 +28,12 @@
|
||||
<el-popover
|
||||
placement="bottom"
|
||||
trigger="click"
|
||||
v-model:visible="isShowUserNewsPopover"
|
||||
:visible="isShowUserNewsPopover"
|
||||
:width="300"
|
||||
popper-class="el-popover-pupop-user-news"
|
||||
>
|
||||
<template #reference>
|
||||
<el-badge :is-dot="true" @click="isShowUserNewsPopover = !isShowUserNewsPopover">
|
||||
<el-badge :is-dot="false" @click="isShowUserNewsPopover = !isShowUserNewsPopover">
|
||||
<el-icon title="消息">
|
||||
<bell />
|
||||
</el-icon>
|
||||
@@ -55,7 +55,7 @@
|
||||
<el-dropdown :show-timeout="70" :hide-timeout="50" @command="onHandleCommandClick">
|
||||
<span class="layout-navbars-breadcrumb-user-link" style="cursor: pointer">
|
||||
<img :src="getUserInfos.photo" class="layout-navbars-breadcrumb-user-link-photo mr5" />
|
||||
{{ getUserInfos.username === '' ? 'test' : getUserInfos.username }}
|
||||
{{ getUserInfos.name || getUserInfos.username }}
|
||||
<i class="el-icon-arrow-down el-icon--right"></i>
|
||||
</span>
|
||||
<template #dropdown>
|
||||
|
||||
@@ -40,7 +40,7 @@ export default {
|
||||
};
|
||||
// 前往通知中心点击
|
||||
const toMsgCenter = () => {
|
||||
// window.open('https://gitee.com/lyt-top/vue-next-admin');
|
||||
|
||||
};
|
||||
return {
|
||||
onAllReadClick,
|
||||
|
||||
@@ -234,7 +234,7 @@ export default {
|
||||
};
|
||||
// 鼠标滚轮滚动
|
||||
const onHandleScroll = (e: any) => {
|
||||
proxy.$refs.scrollbarRef.$refs.wrap.scrollLeft += e.wheelDelta / 4;
|
||||
proxy.$refs.scrollbarRef.$refs.wrapRef.scrollLeft += e.wheelDelta / 4;
|
||||
};
|
||||
// tagsView 横向滚动
|
||||
const tagsViewmoveToCurrentTag = () => {
|
||||
@@ -251,7 +251,7 @@ export default {
|
||||
// 最后 li
|
||||
let liLast: any = tagsRefs.value[tagsRefs.value.length - 1];
|
||||
// 当前滚动条的值
|
||||
let scrollRefs = proxy.$refs.scrollbarRef.$refs.wrap$;
|
||||
let scrollRefs = proxy.$refs.scrollbarRef.$refs.wrapRef;
|
||||
// 当前滚动条滚动宽度
|
||||
let scrollS = scrollRefs.scrollWidth;
|
||||
// 当前滚动条偏移宽度
|
||||
|
||||
@@ -1,44 +1,26 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-form ref="loginFormRef" :model="loginForm" :rules="rules" class="login-content-form" size="large">
|
||||
<el-form-item prop="username">
|
||||
<el-input type="text" placeholder="请输入用户名" prefix-icon="user" v-model="loginForm.username" clearable autocomplete="off">
|
||||
<el-input type="text" placeholder="请输入用户名" prefix-icon="user" v-model="loginForm.username" clearable
|
||||
autocomplete="off">
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password">
|
||||
<el-input
|
||||
type="password"
|
||||
placeholder="请输入密码"
|
||||
prefix-icon="lock"
|
||||
v-model="loginForm.password"
|
||||
autocomplete="off"
|
||||
show-password
|
||||
>
|
||||
<el-input type="password" placeholder="请输入密码" prefix-icon="lock" v-model="loginForm.password"
|
||||
autocomplete="off" show-password>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="captcha">
|
||||
<el-form-item v-if="isUseLoginCaptcha" prop="captcha">
|
||||
<el-row :gutter="15">
|
||||
<el-col :span="16">
|
||||
<el-input
|
||||
type="text"
|
||||
maxlength="6"
|
||||
placeholder="请输入验证码"
|
||||
prefix-icon="position"
|
||||
v-model="loginForm.captcha"
|
||||
clearable
|
||||
autocomplete="off"
|
||||
@keyup.enter="login"
|
||||
></el-input>
|
||||
<el-input type="text" maxlength="6" placeholder="请输入验证码" prefix-icon="position"
|
||||
v-model="loginForm.captcha" clearable autocomplete="off" @keyup.enter="login"></el-input>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<div class="login-content-code">
|
||||
<img
|
||||
class="login-content-code-img"
|
||||
@click="getCaptcha"
|
||||
width="130px"
|
||||
height="40px"
|
||||
:src="captchaImage"
|
||||
style="cursor: pointer"
|
||||
/>
|
||||
<img class="login-content-code-img" @click="getCaptcha" width="130px" height="40px"
|
||||
:src="captchaImage" style="cursor: pointer" />
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
@@ -49,26 +31,61 @@
|
||||
</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 v-model.trim="changePwdDialog.form.newPassword" placeholder="须为8位以上且包含字⺟⼤⼩写+数字+特殊符号"
|
||||
type="password" autocomplete="new-password"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="cancelChangePwd">取 消</el-button>
|
||||
<el-button @click="changePwd" type="primary" :loading="loading.changePwd">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { onMounted, ref, toRefs, reactive, defineComponent, computed } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { nextTick, onMounted, ref, toRefs, reactive, computed } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { initBackEndControlRoutesFun } from '@/router/index.ts';
|
||||
import { useStore } from '@/store/index.ts';
|
||||
import { setSession } from '@/common/utils/storage.ts';
|
||||
import { setSession, setUserInfo2Session, setUseWatermark2Session } from '@/common/utils/storage.ts';
|
||||
import { formatAxis } from '@/common/utils/formatTime.ts';
|
||||
import openApi from '@/common/openApi';
|
||||
import { RsaEncrypt } from '@/common/rsa';
|
||||
import { useLoginCaptcha, useWartermark } from '@/common/sysconfig';
|
||||
import { letterAvatar } from '@/common/utils/string';
|
||||
export default defineComponent({
|
||||
name: 'AccountLogin',
|
||||
setup() {
|
||||
|
||||
const rules = {
|
||||
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
captcha: [{ required: true, message: '请输入验证码', trigger: 'blur' }],
|
||||
}
|
||||
|
||||
const store = useStore();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const loginFormRef: any = ref(null);
|
||||
const changePwdFormRef: any = ref(null);
|
||||
|
||||
const state = reactive({
|
||||
isUseLoginCaptcha: false,
|
||||
captchaImage: '',
|
||||
loginForm: {
|
||||
username: '',
|
||||
@@ -76,21 +93,51 @@ export default defineComponent({
|
||||
captcha: '',
|
||||
cid: '',
|
||||
},
|
||||
changePwdDialog: {
|
||||
visible: false,
|
||||
form: {
|
||||
username: '',
|
||||
oldPassword: '',
|
||||
newPassword: '',
|
||||
},
|
||||
rules: {
|
||||
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
captcha: [{ required: true, message: '请输入验证码', trigger: 'blur' }],
|
||||
newPassword: [
|
||||
{ required: true, message: '请输入新密码', trigger: 'blur' },
|
||||
{
|
||||
pattern: /^(?=.*[A-Za-z])(?=.*\d)(?=.*[`~!@#$%^&*()_+<>?:"{},.\/\\;'[\]])[A-Za-z\d`~!@#$%^&*()_+<>?:"{},.\/\\;'[\]]{8,}$/,
|
||||
message: '须为8位以上且包含字⺟⼤⼩写+数字+特殊符号',
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
loading: {
|
||||
signIn: false,
|
||||
changePwd: false,
|
||||
},
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
const {
|
||||
isUseLoginCaptcha,
|
||||
captchaImage,
|
||||
loginForm,
|
||||
changePwdDialog,
|
||||
loading,
|
||||
} = toRefs(state)
|
||||
|
||||
onMounted(async () => {
|
||||
nextTick(async () => {
|
||||
state.isUseLoginCaptcha = await useLoginCaptcha();
|
||||
getCaptcha();
|
||||
});
|
||||
// 移除公钥, 方便后续重新获取
|
||||
sessionStorage.removeItem('RsaPublicKey');
|
||||
});
|
||||
|
||||
const getCaptcha = async () => {
|
||||
if (!state.isUseLoginCaptcha) {
|
||||
return;
|
||||
}
|
||||
let res: any = await openApi.captcha();
|
||||
state.captchaImage = res.base64Captcha;
|
||||
state.loginForm.cid = res.cid;
|
||||
@@ -116,19 +163,31 @@ export default defineComponent({
|
||||
const onSignIn = async () => {
|
||||
state.loading.signIn = true;
|
||||
let loginRes;
|
||||
const originPwd = state.loginForm.password;
|
||||
try {
|
||||
loginRes = await openApi.login(state.loginForm);
|
||||
// // 存储 token 到浏览器缓存
|
||||
const loginReq = { ...state.loginForm };
|
||||
loginReq.password = await RsaEncrypt(originPwd);
|
||||
loginRes = await openApi.login(loginReq);
|
||||
// 存储 token 到浏览器缓存
|
||||
setSession('token', loginRes.token);
|
||||
setSession('menus', loginRes.menus);
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
state.loading.signIn = false;
|
||||
state.loginForm.captcha = '';
|
||||
// 密码强度不足
|
||||
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;
|
||||
}
|
||||
// 用户信息
|
||||
const userInfos = {
|
||||
name: loginRes.name,
|
||||
username: state.loginForm.username,
|
||||
// 头像
|
||||
photo: letterAvatar(state.loginForm.username),
|
||||
@@ -141,7 +200,7 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
// 存储用户信息到浏览器缓存
|
||||
setSession('userInfo', userInfos);
|
||||
setUserInfo2Session(userInfos);
|
||||
// 1、请注意执行顺序(存储用户信息到vuex)
|
||||
store.dispatch('userInfos/setUserInfos', userInfos);
|
||||
if (!store.state.themeConfig.themeConfig.isRequestRoutes) {
|
||||
@@ -167,31 +226,56 @@ export default defineComponent({
|
||||
// 如果是复制粘贴的路径,非首页/登录页,那么登录成功后重定向到对应的路径中
|
||||
route.query?.redirect ? router.push(route.query.redirect as string) : router.push('/');
|
||||
// 登录成功提示
|
||||
setTimeout(() => {
|
||||
setTimeout(async () => {
|
||||
// 关闭 loading
|
||||
state.loading.signIn = true;
|
||||
ElMessage.success(`${currentTimeInfo},欢迎回来!`);
|
||||
if (await useWartermark()) {
|
||||
setUseWatermark2Session(true);
|
||||
}
|
||||
}, 300);
|
||||
};
|
||||
|
||||
return {
|
||||
getCaptcha,
|
||||
currentTime,
|
||||
loginFormRef,
|
||||
login,
|
||||
...toRefs(state),
|
||||
};
|
||||
},
|
||||
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();
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.login-content-form {
|
||||
margin-top: 20px;
|
||||
|
||||
.login-content-code {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-around;
|
||||
|
||||
.login-content-code-img {
|
||||
width: 100%;
|
||||
height: 40px;
|
||||
@@ -208,12 +292,14 @@ export default defineComponent({
|
||||
transition: all ease 0.2s;
|
||||
border-radius: 4px;
|
||||
user-select: none;
|
||||
|
||||
&:hover {
|
||||
border-color: #c0c4cc;
|
||||
transition: all ease 0.2s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.login-content-submit {
|
||||
width: 100%;
|
||||
letter-spacing: 2px;
|
||||
|
||||
@@ -31,34 +31,31 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, reactive, computed } from 'vue';
|
||||
import Account from '@/views/login/component/AccountLogin.vue';
|
||||
import { useStore } from '@/store/index.ts';
|
||||
export default {
|
||||
name: 'LoginPage',
|
||||
components: { Account },
|
||||
setup() {
|
||||
|
||||
const store = useStore();
|
||||
const state = reactive({
|
||||
tabsActiveName: 'account',
|
||||
isTabPaneShow: true,
|
||||
});
|
||||
|
||||
const {
|
||||
isTabPaneShow,
|
||||
tabsActiveName,
|
||||
} = toRefs(state)
|
||||
|
||||
// 获取布局配置信息
|
||||
const getThemeConfig = computed(() => {
|
||||
return store.state.themeConfig.themeConfig;
|
||||
});
|
||||
|
||||
// 切换密码、手机登录
|
||||
const onTabsClick = () => {
|
||||
state.isTabPaneShow = !state.isTabPaneShow;
|
||||
};
|
||||
return {
|
||||
onTabsClick,
|
||||
getThemeConfig,
|
||||
...toRefs(state),
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@@ -67,6 +64,7 @@ export default {
|
||||
height: 100%;
|
||||
background: url('@/assets/image/bg-login.png') no-repeat;
|
||||
background-size: 100% 100%;
|
||||
|
||||
.login-logo {
|
||||
position: absolute;
|
||||
top: 30px;
|
||||
@@ -80,6 +78,7 @@ export default {
|
||||
width: 90%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
.login-content {
|
||||
width: 500px;
|
||||
padding: 20px;
|
||||
@@ -94,9 +93,11 @@ export default {
|
||||
height: 480px;
|
||||
overflow: hidden;
|
||||
z-index: 1;
|
||||
|
||||
.login-content-main {
|
||||
margin: 0 auto;
|
||||
width: 80%;
|
||||
|
||||
.login-content-title {
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
@@ -108,9 +109,11 @@ export default {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.login-content-mobile {
|
||||
height: 418px;
|
||||
}
|
||||
|
||||
.login-copyright {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
@@ -120,9 +123,11 @@ export default {
|
||||
color: white;
|
||||
font-size: 12px;
|
||||
opacity: 0.8;
|
||||
|
||||
.login-copyright-company {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.login-copyright-msg {
|
||||
@extend .login-copyright-company;
|
||||
}
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-form class="search-form" label-position="right" :inline="true">
|
||||
<el-form-item prop="project" label="项目" label-width="40px">
|
||||
<el-select v-model="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-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="env" label="env" label-width="33px">
|
||||
<el-select style="width: 80px" v-model="envId" placeholder="环境" @change="changeEnv" filterable>
|
||||
<el-option v-for="item in envs" :key="item.id" :label="item.name" :value="item.id">
|
||||
<span style="float: left">{{ item.name }}</span>
|
||||
<span style="float: right; color: #8492a6; font-size: 13px">{{ item.remark }}</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<slot></slot>
|
||||
</el-form>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, defineComponent, onMounted } from 'vue';
|
||||
import { projectApi } from '../project/api';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ProjectEnvSelect',
|
||||
props: {
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
data: {
|
||||
type: Object,
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
machineId: {
|
||||
type: Number,
|
||||
},
|
||||
isCommon: {
|
||||
type: Boolean,
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
const state = reactive({
|
||||
projects: [] as any,
|
||||
envs: [] as any,
|
||||
projectId: null,
|
||||
envId: null,
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
state.projects = await projectApi.accountProjects.request(null);
|
||||
});
|
||||
|
||||
const changeProject = async (projectId: any) => {
|
||||
emit('update:projectId', projectId);
|
||||
emit('changeProjectEnv', state.projectId, null);
|
||||
state.envId = null;
|
||||
state.envs = await projectApi.projectEnvs.request({ projectId });
|
||||
};
|
||||
|
||||
const changeEnv = (envId: any) => {
|
||||
emit('update:envId', envId);
|
||||
emit('changeProjectEnv', state.projectId, envId);
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
changeProject,
|
||||
changeEnv,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
</style>
|
||||
72
mayfly_go_web/src/views/ops/component/TagSelect.vue
Normal file
72
mayfly_go_web/src/views/ops/component/TagSelect.vue
Normal file
@@ -0,0 +1,72 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-tree-select @check="changeTag" style="width: 100%" v-model="selectTags" :data="tags"
|
||||
:render-after-expand="true" :default-expanded-keys="[selectTags]" show-checkbox check-strictly node-key="id"
|
||||
:props="{
|
||||
value: 'id',
|
||||
label: 'codePath',
|
||||
children: 'children',
|
||||
}">
|
||||
<template #default="{ data }">
|
||||
<span class="custom-tree-node">
|
||||
<span style="font-size: 13px">
|
||||
{{ data.code }}
|
||||
<span style="color: #3c8dbc">【</span>
|
||||
{{ data.name }}
|
||||
<span style="color: #3c8dbc">】</span>
|
||||
<el-tag v-if="data.children !== null" size="small">{{ data.children.length }}</el-tag>
|
||||
</span>
|
||||
</span>
|
||||
</template>
|
||||
</el-tree-select>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, reactive, onMounted } from 'vue';
|
||||
import { tagApi } from '../tag/api';
|
||||
|
||||
const props = defineProps({
|
||||
tagId: {
|
||||
type: Number,
|
||||
},
|
||||
tagPath: {
|
||||
type: String,
|
||||
},
|
||||
})
|
||||
|
||||
//定义事件
|
||||
const emit = defineEmits(['changeTag', 'update:tagId', 'update:tagPath'])
|
||||
|
||||
const state = reactive({
|
||||
tags: [],
|
||||
// 单选则为id,多选为id数组
|
||||
selectTags: null as any,
|
||||
});
|
||||
|
||||
const {
|
||||
tags,
|
||||
selectTags,
|
||||
} = toRefs(state)
|
||||
|
||||
onMounted(async () => {
|
||||
if (props.tagId) {
|
||||
state.selectTags = props.tagId;
|
||||
}
|
||||
state.tags = await tagApi.getTagTrees.request(null);
|
||||
});
|
||||
|
||||
const changeTag = (tag: any, checkInfo: any) => {
|
||||
if (checkInfo.checkedNodes.length > 0) {
|
||||
emit('update:tagId', tag.id);
|
||||
emit('update:tagPath', tag.codePath);
|
||||
emit('changeTag', tag);
|
||||
} else {
|
||||
emit('update:tagId', null);
|
||||
emit('update:tagPath', null);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-dialog title="创建表" v-model="dialogVisible" :before-close="cancel" width="90%">
|
||||
<el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" width="90%">
|
||||
<el-form label-position="left" ref="formRef" :model="tableData" label-width="80px">
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
@@ -13,10 +13,21 @@
|
||||
<el-input style="width: 80%" v-model="tableData.tableComment" size="small"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col style="margin-top: 20px" :span="12">
|
||||
<el-form-item prop="characterSet" label="字符集">
|
||||
<el-col :span="12">
|
||||
<el-form-item prop="characterSet" label="charset">
|
||||
<el-select filterable style="width: 80%" v-model="tableData.characterSet" size="small">
|
||||
<el-option v-for="item in characterSetNameList" :key="item" :label="item" :value="item"> </el-option>
|
||||
<el-option v-for="item in characterSetNameList" :key="item" :label="item" :value="item">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item prop="characterSet" label="collation">
|
||||
<el-select filterable style="width: 80%" v-model="tableData.collation" size="small">
|
||||
<el-option v-for="item in collationNameList" :key="item"
|
||||
:label="tableData.characterSet + '_' + item"
|
||||
:value="tableData.characterSet + '_' + item">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@@ -24,35 +35,88 @@
|
||||
|
||||
<el-tabs v-model="activeName">
|
||||
<el-tab-pane label="字段" name="1">
|
||||
<el-table :data="tableData.fields.res">
|
||||
<el-table-column :prop="item.prop" :label="item.label" v-for="item in tableData.fields.colNames" :key="item.prop">
|
||||
<el-table :data="tableData.fields.res" :max-height="tableData.height">
|
||||
<el-table-column :prop="item.prop" :label="item.label"
|
||||
v-for="item in tableData.fields.colNames" :key="item.prop">
|
||||
<template #default="scope">
|
||||
<el-input v-if="item.prop === 'name'" size="small" v-model="scope.row.name"></el-input>
|
||||
<el-input v-if="item.prop === 'name'" size="small" v-model="scope.row.name">
|
||||
</el-input>
|
||||
|
||||
<el-select v-if="item.prop === 'type'" filterable size="small" v-model="scope.row.type">
|
||||
<el-option v-for="typeValue in typeList" :key="typeValue" :value="typeValue">{{ typeValue }}</el-option>
|
||||
<el-select v-if="item.prop === 'type'" filterable size="small"
|
||||
v-model="scope.row.type">
|
||||
<el-option v-for="typeValue in columnTypeList" :key="typeValue"
|
||||
:value="typeValue">{{ typeValue }}</el-option>
|
||||
</el-select>
|
||||
|
||||
<el-input v-if="item.prop === 'value'" size="small" v-model="scope.row.value"> </el-input>
|
||||
<el-input v-if="item.prop === 'value'" size="small" v-model="scope.row.value">
|
||||
</el-input>
|
||||
|
||||
<el-input v-if="item.prop === 'length'" size="small" v-model="scope.row.length"> </el-input>
|
||||
<el-input v-if="item.prop === 'length'" size="small" v-model="scope.row.length">
|
||||
</el-input>
|
||||
|
||||
<el-checkbox v-if="item.prop === 'notNull'" size="small" v-model="scope.row.notNull"> </el-checkbox>
|
||||
<el-checkbox v-if="item.prop === 'notNull'" size="small"
|
||||
v-model="scope.row.notNull"> </el-checkbox>
|
||||
|
||||
<el-checkbox v-if="item.prop === 'pri'" size="small" v-model="scope.row.pri"> </el-checkbox>
|
||||
<el-checkbox v-if="item.prop === 'pri'" size="small" v-model="scope.row.pri">
|
||||
</el-checkbox>
|
||||
|
||||
<el-checkbox v-if="item.prop === 'auto_increment'" size="small" v-model="scope.row.auto_increment"> </el-checkbox>
|
||||
<el-checkbox v-if="item.prop === 'auto_increment'" size="small"
|
||||
v-model="scope.row.auto_increment"> </el-checkbox>
|
||||
|
||||
<el-input v-if="item.prop === 'remark'" size="small" v-model="scope.row.remark"> </el-input>
|
||||
<el-input v-if="item.prop === 'remark'" size="small" v-model="scope.row.remark">
|
||||
</el-input>
|
||||
|
||||
<el-button v-if="item.prop === 'action'" type="text" size="small" @click.prevent="deleteRow(scope.$index)">删除</el-button>
|
||||
<el-link v-if="item.prop === 'action'" type="danger" plain size="small"
|
||||
:underline="false" @click.prevent="deleteRow(scope.$index)">删除</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-row style="margin-top: 20px">
|
||||
<el-button @click="addRow()" type="text" icon="plus"></el-button>
|
||||
<el-button @click="addDefaultRows()" link type="warning" icon="plus">添加默认列</el-button>
|
||||
<el-button @click="addRow()" link type="primary" icon="plus">添加列</el-button>
|
||||
</el-row>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="索引" name="2">
|
||||
<el-table :data="tableData.indexs.res" :max-height="tableData.height">
|
||||
<el-table-column :prop="item.prop" :label="item.label"
|
||||
v-for="item in tableData.indexs.colNames" :key="item.prop">
|
||||
<template #default="scope">
|
||||
|
||||
<el-input v-if="item.prop === 'indexName'" size="small"
|
||||
v-model="scope.row.indexName"></el-input>
|
||||
|
||||
<el-select v-if="item.prop === 'columnNames'" v-model="scope.row.columnNames"
|
||||
multiple collapse-tags collapse-tags-tooltip filterable placeholder="请选择字段"
|
||||
style="width: 100%">
|
||||
<el-option v-for="cl in tableData.indexs.columns" :key="cl.name"
|
||||
:label="cl.name" :value="cl.name">
|
||||
{{ cl.name + ' - ' + (cl.remark || '') }}
|
||||
</el-option>
|
||||
</el-select>
|
||||
|
||||
<el-checkbox v-if="item.prop === 'unique'" size="small" v-model="scope.row.unique">
|
||||
</el-checkbox>
|
||||
|
||||
<el-select v-if="item.prop === 'indexType'" filterable size="small"
|
||||
v-model="scope.row.indexType">
|
||||
<el-option v-for="typeValue in indexTypeList" :key="typeValue"
|
||||
:value="typeValue">{{ typeValue }}</el-option>
|
||||
</el-select>
|
||||
|
||||
<el-input v-if="item.prop === 'indexComment'" size="small"
|
||||
v-model="scope.row.indexComment"> </el-input>
|
||||
|
||||
<el-link v-if="item.prop === 'action'" type="danger" plain size="small"
|
||||
:underline="false" @click.prevent="deleteIndex(scope.$index)">删除</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<el-row style="margin-top: 20px">
|
||||
<el-button @click="addIndex()" link type="primary" icon="plus">添加索引</el-button>
|
||||
</el-row>
|
||||
</el-tab-pane>
|
||||
|
||||
</el-tabs>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
@@ -63,14 +127,13 @@
|
||||
</template>
|
||||
|
||||
|
||||
<script lang="ts">
|
||||
import { watch, toRefs, reactive, defineComponent, ref, getCurrentInstance } from 'vue';
|
||||
import { TYPE_LIST, CHARACTER_SET_NAME_LIST } from './service.ts';
|
||||
<script lang="ts" setup>
|
||||
import { watch, toRefs, reactive, ref } from 'vue';
|
||||
import { TYPE_LIST, CHARACTER_SET_NAME_LIST, COLLATION_SUFFIX_LIST } from './service.ts';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import SqlExecBox from './component/SqlExecBox.ts';
|
||||
export default defineComponent({
|
||||
name: 'createTable',
|
||||
props: {
|
||||
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -86,16 +149,20 @@ export default defineComponent({
|
||||
db: {
|
||||
type: String,
|
||||
}
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
})
|
||||
|
||||
//定义事件
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'val-change', 'submit-sql'])
|
||||
|
||||
const formRef: any = ref();
|
||||
const { proxy } = getCurrentInstance() as any;
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
btnloading: false,
|
||||
activeName: '1',
|
||||
typeList: TYPE_LIST,
|
||||
columnTypeList: TYPE_LIST,
|
||||
indexTypeList: ['BTREE'], // mysql索引类型详解 http://c.biancheng.net/view/7897.html
|
||||
characterSetNameList: CHARACTER_SET_NAME_LIST,
|
||||
collationNameList: COLLATION_SUFFIX_LIST,
|
||||
tableData: {
|
||||
fields: {
|
||||
colNames: [
|
||||
@@ -137,7 +204,6 @@ export default defineComponent({
|
||||
label: '操作',
|
||||
},
|
||||
],
|
||||
|
||||
res: [
|
||||
{
|
||||
name: '',
|
||||
@@ -151,19 +217,72 @@ export default defineComponent({
|
||||
},
|
||||
],
|
||||
},
|
||||
indexs: {
|
||||
colNames: [
|
||||
{
|
||||
prop: 'indexName',
|
||||
label: '索引名',
|
||||
},
|
||||
{
|
||||
prop: 'columnNames',
|
||||
label: '列名',
|
||||
},
|
||||
{
|
||||
prop: 'unique',
|
||||
label: '唯一',
|
||||
},
|
||||
{
|
||||
prop: 'indexType',
|
||||
label: '类型',
|
||||
},
|
||||
{
|
||||
prop: 'indexComment',
|
||||
label: '备注',
|
||||
},
|
||||
{
|
||||
prop: 'action',
|
||||
label: '操作',
|
||||
},
|
||||
],
|
||||
columns: [{ name: '', remark: '' }],
|
||||
res: [
|
||||
{
|
||||
indexName: '',
|
||||
columnNames: [],
|
||||
unique: false,
|
||||
indexType: 'BTREE',
|
||||
indexComment: '',
|
||||
},
|
||||
],
|
||||
},
|
||||
characterSet: 'utf8mb4',
|
||||
collation: 'utf8mb4_general_ci',
|
||||
tableName: '',
|
||||
tableComment: '',
|
||||
height: 550
|
||||
},
|
||||
});
|
||||
|
||||
const {
|
||||
dialogVisible,
|
||||
btnloading,
|
||||
activeName,
|
||||
columnTypeList,
|
||||
indexTypeList,
|
||||
characterSetNameList,
|
||||
collationNameList,
|
||||
tableData,
|
||||
} = toRefs(state)
|
||||
|
||||
watch(props, async (newValue) => {
|
||||
state.dialogVisible = newValue.visible;
|
||||
});
|
||||
|
||||
const cancel = () => {
|
||||
emit('update:visible', false);
|
||||
reset();
|
||||
};
|
||||
|
||||
const addRow = () => {
|
||||
state.tableData.fields.res.push({
|
||||
name: '',
|
||||
@@ -176,45 +295,235 @@ export default defineComponent({
|
||||
remark: '',
|
||||
});
|
||||
};
|
||||
|
||||
const addIndex = () => {
|
||||
state.tableData.indexs.res.push({
|
||||
indexName: '',
|
||||
columnNames: [],
|
||||
unique: false,
|
||||
indexType: 'BTREE',
|
||||
indexComment: '',
|
||||
});
|
||||
};
|
||||
|
||||
const addDefaultRows = () => {
|
||||
state.tableData.fields.res.push(
|
||||
{ name: 'id', type: 'bigint', length: '20', value: '', notNull: true, pri: true, auto_increment: true, remark: '主键ID' },
|
||||
{ name: 'creator_id', type: 'bigint', length: '20', value: '', notNull: true, pri: false, auto_increment: false, remark: '创建人id' },
|
||||
{ name: 'creator', type: 'varchar', length: '100', value: '', notNull: true, pri: false, auto_increment: false, remark: '创建人姓名' },
|
||||
{ name: 'creat_time', type: 'datetime', length: '', value: '', notNull: true, pri: false, auto_increment: false, remark: '创建时间' },
|
||||
{ name: 'updater_id', type: 'bigint', length: '20', value: '', notNull: true, pri: false, auto_increment: false, remark: '修改人id' },
|
||||
{ name: 'updater', type: 'varchar', length: '100', value: '', notNull: true, pri: false, auto_increment: false, remark: '修改人姓名' },
|
||||
{ name: 'update_time', type: 'datetime', length: '', value: '', notNull: true, pri: false, auto_increment: false, remark: '修改时间' },
|
||||
);
|
||||
};
|
||||
|
||||
const deleteRow = (index: any) => {
|
||||
state.tableData.fields.res.splice(index, 1);
|
||||
};
|
||||
|
||||
const deleteIndex = (index: any) => {
|
||||
state.tableData.indexs.res.splice(index, 1);
|
||||
};
|
||||
|
||||
const submit = async () => {
|
||||
let data = state.tableData;
|
||||
let primary_key = '';
|
||||
let fields: string[] = [];
|
||||
data.fields.res.forEach((item) => {
|
||||
fields.push(
|
||||
`${item.name} ${item.type}${+item.length > 0 ? `(${item.length})` : ''} ${item.notNull ? 'NOT NULL' : ''} ${
|
||||
item.auto_increment ? 'AUTO_INCREMENT' : ''
|
||||
} ${item.value ? 'DEFAULT ' + item.value : item.notNull ? '' : 'DEFAULT NULL'} ${
|
||||
item.remark ? `COMMENT '${item.remark}'` : ''
|
||||
} \n`
|
||||
);
|
||||
if (item.pri) {
|
||||
primary_key += `${item.name},`;
|
||||
let sql = genSql();
|
||||
if (!sql) {
|
||||
ElMessage.warning('没有更改');
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
let sql = `
|
||||
CREATE TABLE ${data.tableName} (
|
||||
${fields.join(',')}
|
||||
${primary_key ? `, PRIMARY KEY (${primary_key.slice(0, -1)})` : ''}
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=${data.characterSet} COLLATE=utf8mb4_bin COMMENT='${data.tableComment}';`;
|
||||
|
||||
SqlExecBox({
|
||||
sql: sql,
|
||||
dbId: props.dbId as any,
|
||||
db: props.db,
|
||||
runSuccessCallback: () => {
|
||||
ElMessage.success('创建成功');
|
||||
proxy.$parent.tableInfo({ id: props.dbId });
|
||||
cancel();
|
||||
emit('submit-sql', {tableName: state.tableData.tableName });
|
||||
// cancel();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 对比两个数组,取出被修改过的对象数组
|
||||
* @param oldArr 原对象数组
|
||||
* @param nowArr 修改后的对象数组
|
||||
* @param key 标志对象唯一属性
|
||||
*/
|
||||
const filterChangedData = (oldArr: object[], nowArr: object[], key: string): { del: any[], add: any[], upd: any[] } => {
|
||||
let data = {
|
||||
del: [] as object[], // 删除的数据
|
||||
add: [] as object[], // 新增的数据
|
||||
upd: [] as object[] // 修改的数据
|
||||
}
|
||||
|
||||
// 旧数据为空
|
||||
if (oldArr && Array.isArray(oldArr) && oldArr.length === 0
|
||||
&& nowArr && Array.isArray(nowArr) && nowArr.length > 0) {
|
||||
data.add = nowArr;
|
||||
return data;
|
||||
}
|
||||
|
||||
// 新数据为空
|
||||
if (nowArr && Array.isArray(nowArr) && nowArr.length === 0
|
||||
&& oldArr && Array.isArray(oldArr) && oldArr.length > 0) {
|
||||
data.del = oldArr;
|
||||
return data;
|
||||
}
|
||||
|
||||
let oldMap = {}, newMap = {};
|
||||
oldArr.forEach(a => oldMap[a[key]] = a)
|
||||
|
||||
nowArr.forEach(a => {
|
||||
let k = a[key]
|
||||
newMap[k] = a;
|
||||
if (!oldMap.hasOwnProperty(k)) {// 新增
|
||||
data.add.push(a)
|
||||
}
|
||||
})
|
||||
|
||||
oldArr.forEach(a => {
|
||||
let k = a[key];
|
||||
let newData = newMap[k];
|
||||
if (!newData) { // 删除
|
||||
data.del.push(a)
|
||||
} else { // 判断每个字段是否相等,否则为修改
|
||||
for (let f in a) {
|
||||
let oldV = a[f]
|
||||
let newV = newData[f]
|
||||
if (oldV.toString() !== newV.toString()) {
|
||||
data.upd.push(newData)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
return data;
|
||||
}
|
||||
|
||||
const genSql = () => {
|
||||
|
||||
const genColumnBasicSql = (cl: any) => {
|
||||
let val = cl.value ? (cl.value === 'CURRENT_TIMESTAMP' ? cl.value : '\'' + cl.value + '\'') : '';
|
||||
let defVal = `${val ? ('DEFAULT ' + val) : ''}`;
|
||||
let length = cl.length ? `(${cl.length})` : '';
|
||||
return ` ${cl.name} ${cl.type}${length} ${cl.notNull ? 'NOT NULL' : 'NULL'} ${cl.auto_increment ? 'AUTO_INCREMENT' : ''} ${defVal} comment '${cl.remark || ''}' `
|
||||
}
|
||||
|
||||
let data = state.tableData;
|
||||
// 创建表
|
||||
if (!props.data?.edit) {
|
||||
if (state.activeName === '1') {// 创建表结构
|
||||
let primary_key = '';
|
||||
let fields: string[] = [];
|
||||
data.fields.res.forEach((item) => {
|
||||
fields.push(genColumnBasicSql(item));
|
||||
if (item.pri) {
|
||||
primary_key += `${item.name},`;
|
||||
}
|
||||
});
|
||||
|
||||
return `CREATE TABLE ${data.tableName}
|
||||
( ${fields.join(',')}
|
||||
${primary_key ? `, PRIMARY KEY (${primary_key.slice(0, -1)})` : ''}
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=${data.characterSet} COLLATE =${data.collation} COMMENT='${data.tableComment}';`;
|
||||
|
||||
} else if (state.activeName === '2' && data.indexs.res.length > 0) { // 创建索引
|
||||
let sql = `ALTER TABLE ${data.tableName}`;
|
||||
state.tableData.indexs.res.forEach(a => {
|
||||
sql += ` ADD ${a.unique ? 'UNIQUE' : ''} INDEX ${a.indexName}(${a.columnNames.join(',')}) USING ${a.indexType} COMMENT '${a.indexComment}',`;
|
||||
})
|
||||
return sql.substring(0, sql.length - 1) + ';'
|
||||
}
|
||||
} else { // 修改
|
||||
let addSql = '', updSql = '', delSql = '';
|
||||
if (state.activeName === '1') {// 修改列
|
||||
let changeData = filterChangedData(oldData.fields, state.tableData.fields.res, 'name')
|
||||
if (changeData.add.length > 0) {
|
||||
addSql = `ALTER TABLE ${data.tableName}`
|
||||
changeData.add.forEach(a => {
|
||||
addSql += ` ADD ${genColumnBasicSql(a)},`
|
||||
})
|
||||
addSql = addSql.substring(0, addSql.length - 1)
|
||||
addSql += ';'
|
||||
}
|
||||
|
||||
if (changeData.upd.length > 0) {
|
||||
updSql = `ALTER TABLE ${data.tableName}`;
|
||||
changeData.upd.forEach(a => {
|
||||
updSql += ` MODIFY ${genColumnBasicSql(a)},`
|
||||
})
|
||||
updSql = updSql.substring(0, updSql.length - 1)
|
||||
updSql += ';'
|
||||
}
|
||||
|
||||
if (changeData.del.length > 0) {
|
||||
changeData.del.forEach(a => {
|
||||
delSql += ` ALTER TABLE ${data.tableName} DROP COLUMN ${a.name}; `
|
||||
})
|
||||
}
|
||||
return addSql + updSql + delSql;
|
||||
|
||||
} else if (state.activeName === '2') { // 修改索引
|
||||
let changeData = filterChangedData(oldData.indexs, state.tableData.indexs.res, 'indexName')
|
||||
// 搜集修改和删除的索引,添加到drop index xx
|
||||
// 收集新增和修改的索引,添加到ADD xx
|
||||
// ALTER TABLE `test1`
|
||||
// DROP INDEX `test1_name_uindex`,
|
||||
// DROP INDEX `test1_column_name4_index`,
|
||||
// ADD UNIQUE INDEX `test1_name_uindex`(`id`) USING BTREE COMMENT 'ASDASD',
|
||||
// ADD INDEX `111`(`column_name4`) USING BTREE COMMENT 'zasf';
|
||||
|
||||
let dropIndexNames: string[] = [];
|
||||
let addIndexs: any[] = [];
|
||||
|
||||
if (changeData.upd.length > 0) {
|
||||
changeData.upd.forEach(a => {
|
||||
dropIndexNames.push(a.indexName)
|
||||
addIndexs.push(a)
|
||||
})
|
||||
}
|
||||
|
||||
if (changeData.del.length > 0) {
|
||||
changeData.del.forEach(a => {
|
||||
dropIndexNames.push(a.indexName)
|
||||
})
|
||||
}
|
||||
|
||||
if (changeData.add.length > 0) {
|
||||
changeData.add.forEach(a => {
|
||||
addIndexs.push(a)
|
||||
})
|
||||
}
|
||||
|
||||
if (dropIndexNames.length > 0 || addIndexs.length > 0) {
|
||||
let sql = `ALTER TABLE ${data.tableName} `;
|
||||
if (dropIndexNames.length > 0) {
|
||||
dropIndexNames.forEach(a => {
|
||||
sql += `DROP INDEX ${a},`
|
||||
})
|
||||
sql = sql.substring(0, sql.length - 1)
|
||||
}
|
||||
|
||||
if (addIndexs.length > 0) {
|
||||
if (dropIndexNames.length > 0){
|
||||
sql += ','
|
||||
}
|
||||
addIndexs.forEach(a => {
|
||||
sql += ` ADD ${a.unique ? 'UNIQUE' : ''} INDEX ${a.indexName}(${a.columnNames.join(',')}) USING ${a.indexType} COMMENT '${a.indexComment}',`;
|
||||
})
|
||||
sql = sql.substring(0, sql.length - 1)
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const reset = () => {
|
||||
formRef.value.resetFields();
|
||||
state.activeName = '1'
|
||||
formRef.value.resetFields()
|
||||
state.tableData.tableName = ''
|
||||
state.tableData.tableComment = ''
|
||||
state.tableData.fields.res = [
|
||||
{
|
||||
name: '',
|
||||
@@ -227,17 +536,64 @@ export default defineComponent({
|
||||
remark: '',
|
||||
},
|
||||
];
|
||||
state.tableData.indexs.res = [{
|
||||
indexName: '',
|
||||
columnNames: [],
|
||||
unique: false,
|
||||
indexType: 'BTREE',
|
||||
indexComment: '',
|
||||
},]
|
||||
};
|
||||
return {
|
||||
...toRefs(state),
|
||||
formRef,
|
||||
cancel,
|
||||
reset,
|
||||
addRow,
|
||||
deleteRow,
|
||||
submit,
|
||||
|
||||
const oldData = { indexs: [] as any[], fields: [] as any[] }
|
||||
watch(() => props.data, (newValue: any) => {
|
||||
const { row, indexs, columns } = newValue;
|
||||
// 回显表名表注释
|
||||
state.tableData.tableName = row.tableName
|
||||
state.tableData.tableComment = row.tableComment
|
||||
// 回显列
|
||||
if (columns && Array.isArray(columns) && columns.length > 0) {
|
||||
oldData.fields = [];
|
||||
state.tableData.fields.res = [];
|
||||
// 索引列下拉选
|
||||
state.tableData.indexs.columns = [];
|
||||
columns.forEach(a => {
|
||||
let typeObj = a.columnType.replace(')', '').split('(')
|
||||
let type = typeObj[0];
|
||||
let length = typeObj.length > 1 && typeObj[1] || '';
|
||||
let data = {
|
||||
name: a.columnName,
|
||||
type,
|
||||
value: a.columnDefault || '',
|
||||
length,
|
||||
notNull: a.nullable !== 'YES',
|
||||
pri: a.columnKey === 'PRI',
|
||||
auto_increment: a.extra?.indexOf('auto_increment') > -1,
|
||||
remark: a.columnComment,
|
||||
};
|
||||
},
|
||||
});
|
||||
state.tableData.fields.res.push(data)
|
||||
oldData.fields.push(JSON.parse(JSON.stringify(data)))
|
||||
// 索引字段下拉选项
|
||||
state.tableData.indexs.columns.push({ name: a.columnName, remark: a.columnComment })
|
||||
})
|
||||
}
|
||||
// 回显索引
|
||||
if (indexs && Array.isArray(indexs) && indexs.length > 0) {
|
||||
oldData.indexs = [];
|
||||
state.tableData.indexs.res = [];
|
||||
// 索引过滤掉主键
|
||||
indexs.filter(a => a.indexName !== "PRIMARY").forEach(a => {
|
||||
let data = {
|
||||
indexName: a.indexName,
|
||||
columnNames: a.columnName?.split(','),
|
||||
unique: a.nonUnique === 0 || false,
|
||||
indexType: a.indexType,
|
||||
indexComment: a.indexComment,
|
||||
}
|
||||
state.tableData.indexs.res.push(data)
|
||||
oldData.indexs.push(JSON.parse(JSON.stringify(data)))
|
||||
})
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :close-on-click-modal="false" :destroy-on-close="true" width="38%">
|
||||
<el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :close-on-click-modal="false"
|
||||
:destroy-on-close="true" width="38%">
|
||||
<el-form :model="form" ref="dbForm" :rules="rules" label-width="95px">
|
||||
<el-form-item prop="projectId" label="项目:" required>
|
||||
<el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
|
||||
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
</el-select>
|
||||
<el-form-item prop="tagId" label="标签:" required>
|
||||
<tag-select v-model:tag-id="form.tagId" v-model:tag-path="form.tagPath" style="width: 100%" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="envId" label="环境:" required>
|
||||
<el-select @change="changeEnv" style="width: 100%" v-model="form.envId" placeholder="请选择环境">
|
||||
<el-option v-for="item in envs" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item prop="name" label="别名:" required>
|
||||
<el-input v-model.trim="form.name" placeholder="请输入数据库别名" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
@@ -23,49 +17,73 @@
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item prop="host" label="host:" required>
|
||||
<el-input v-model.trim="form.host" placeholder="请输入主机ip" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="port" label="port:" required>
|
||||
<el-input type="number" v-model.trim="form.port" placeholder="请输入端口"></el-input>
|
||||
<el-col :span="18">
|
||||
<el-input :disabled="form.id !== undefined" v-model.trim="form.host" placeholder="请输入主机ip"
|
||||
auto-complete="off"></el-input>
|
||||
</el-col>
|
||||
<el-col style="text-align: center" :span="1">:</el-col>
|
||||
<el-col :span="5">
|
||||
<el-input type="number" v-model.number="form.port" placeholder="请输入端口"></el-input>
|
||||
</el-col>
|
||||
</el-form-item>
|
||||
<el-form-item prop="username" label="用户名:" required>
|
||||
<el-input v-model.trim="form.username" placeholder="请输入用户名"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password" label="密码:">
|
||||
<el-input
|
||||
type="password"
|
||||
show-password
|
||||
v-model.trim="form.password"
|
||||
placeholder="请输入密码,修改操作可不填"
|
||||
autocomplete="new-password"
|
||||
></el-input>
|
||||
<el-input type="password" show-password v-model.trim="form.password" placeholder="请输入密码,修改操作可不填"
|
||||
autocomplete="new-password">
|
||||
<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 prop="params" label="连接参数:">
|
||||
<el-input v-model="form.params" placeholder="其他连接参数,形如: key1=value1&key2=value2"></el-input>
|
||||
<el-input v-model.trim="form.params" placeholder="其他连接参数,形如: key1=value1&key2=value2">
|
||||
<template #suffix>
|
||||
<el-link target="_blank" href="https://github.com/go-sql-driver/mysql#parameters"
|
||||
:underline="false" type="primary" class="mr5">参数参考</el-link>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="database" label="数据库名:" required>
|
||||
<el-tag
|
||||
v-for="db in databaseList"
|
||||
:key="db"
|
||||
class="ml5 mt5"
|
||||
type="success"
|
||||
effect="plain"
|
||||
closable
|
||||
:disable-transitions="false"
|
||||
@close="handleClose(db)"
|
||||
>
|
||||
{{ db }}
|
||||
</el-tag>
|
||||
<el-input
|
||||
v-if="inputDbVisible"
|
||||
ref="InputDbRef"
|
||||
v-model="inputDbValue"
|
||||
style="width: 120px; margin-left: 5px; margin-top: 5px"
|
||||
size="small"
|
||||
@keyup.enter="handleInputDbConfirm"
|
||||
@blur="handleInputDbConfirm"
|
||||
/>
|
||||
<el-button v-else class="ml5 mt5" size="small" @click="showInputDb"> + 添加数据库 </el-button>
|
||||
<el-col :span="19">
|
||||
<el-select @change="changeDatabase" v-model="databaseList" multiple clearable collapse-tags
|
||||
collapse-tags-tooltip filterable allow-create placeholder="请确保数据库实例信息填写完整后获取库名"
|
||||
style="width: 100%">
|
||||
<el-option v-for="db in allDatabases" :key="db" :label="db" :value="db" />
|
||||
</el-select>
|
||||
</el-col>
|
||||
<el-col style="text-align: center" :span="1">
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
</el-col>
|
||||
<el-col :span="4">
|
||||
<el-link @click="getAllDatabase" :underline="false" type="success">获取库名</el-link>
|
||||
</el-col>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="remark" label="备注:">
|
||||
<el-input v-model.trim="form.remark" auto-complete="off" type="textarea"></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-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="5" v-if="form.enableSshTunnel == 1"> 机器: </el-col>
|
||||
<el-col :span="16" 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>
|
||||
|
||||
@@ -79,67 +97,35 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, nextTick, watch, defineComponent, ref } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, reactive, watch, ref } from 'vue';
|
||||
import { dbApi } from './api';
|
||||
import { projectApi } from '../project/api.ts';
|
||||
import { machineApi } from '../machine/api.ts';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import type { ElInput } from 'element-plus';
|
||||
import { notBlank } from '@/common/assert';
|
||||
import { RsaEncrypt } from '@/common/rsa';
|
||||
import TagSelect from '../component/TagSelect.vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'DbEdit',
|
||||
props: {
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
projects: {
|
||||
type: Array,
|
||||
},
|
||||
db: {
|
||||
type: [Boolean, Object],
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
const dbForm: any = ref(null);
|
||||
const InputDbRef = ref<InstanceType<typeof ElInput>>();
|
||||
})
|
||||
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
projects: [],
|
||||
envs: [],
|
||||
databaseList: [] as any,
|
||||
inputDbVisible: false,
|
||||
inputDbValue: '',
|
||||
form: {
|
||||
id: null,
|
||||
name: null,
|
||||
port: 3306,
|
||||
username: null,
|
||||
password: null,
|
||||
params: null,
|
||||
database: '',
|
||||
project: null,
|
||||
projectId: null,
|
||||
envId: null,
|
||||
env: null,
|
||||
},
|
||||
btnLoading: false,
|
||||
rules: {
|
||||
projectId: [
|
||||
//定义事件
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'val-change'])
|
||||
|
||||
const rules = {
|
||||
tagId: [
|
||||
{
|
||||
required: true,
|
||||
message: '请选择项目',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
envId: [
|
||||
{
|
||||
required: true,
|
||||
message: '请选择环境',
|
||||
message: '请选择标签',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
@@ -160,14 +146,7 @@ export default defineComponent({
|
||||
host: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入主机ip',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
port: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入端口',
|
||||
message: '请输入主机ip和port',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
@@ -185,45 +164,66 @@ export default defineComponent({
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const dbForm: any = ref(null);
|
||||
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
allDatabases: [] as any,
|
||||
databaseList: [] as any,
|
||||
sshTunnelMachineList: [] as any,
|
||||
form: {
|
||||
id: null,
|
||||
tagId: null as any,
|
||||
tagPath: null as any,
|
||||
type: null,
|
||||
name: null,
|
||||
host: '',
|
||||
port: 3306,
|
||||
username: null,
|
||||
password: null,
|
||||
params: null,
|
||||
database: '',
|
||||
project: null,
|
||||
projectId: null,
|
||||
envId: null,
|
||||
env: null,
|
||||
remark: '',
|
||||
enableSshTunnel: null,
|
||||
sshTunnelMachineId: null,
|
||||
},
|
||||
// 原密码
|
||||
pwd: '',
|
||||
btnLoading: false,
|
||||
});
|
||||
|
||||
watch(props, (newValue) => {
|
||||
state.projects = newValue.projects;
|
||||
const {
|
||||
dialogVisible,
|
||||
allDatabases,
|
||||
databaseList,
|
||||
sshTunnelMachineList,
|
||||
form,
|
||||
pwd,
|
||||
btnLoading,
|
||||
} = toRefs(state)
|
||||
|
||||
watch(props, (newValue: any) => {
|
||||
state.dialogVisible = newValue.visible;
|
||||
if (!state.dialogVisible) {
|
||||
return;
|
||||
}
|
||||
if (newValue.db) {
|
||||
getEnvs(newValue.db.projectId);
|
||||
state.form = { ...newValue.db };
|
||||
// 将数据库名使用空格切割,获取所有数据库列表
|
||||
state.databaseList = newValue.db.database.split(' ');
|
||||
} else {
|
||||
state.envs = [];
|
||||
state.form = { port: 3306 } as any;
|
||||
state.form = { port: 3306, enableSshTunnel: -1 } as any;
|
||||
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,38 +231,33 @@ export default defineComponent({
|
||||
state.form.database = state.databaseList.length == 0 ? '' : state.databaseList.join(' ');
|
||||
};
|
||||
|
||||
const getEnvs = async (projectId: any) => {
|
||||
state.envs = await projectApi.projectEnvs.request({ projectId });
|
||||
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 changeProject = (projectId: number) => {
|
||||
for (let p of state.projects as any) {
|
||||
if (p.id == projectId) {
|
||||
state.form.project = p.name;
|
||||
}
|
||||
}
|
||||
state.form.envId = null;
|
||||
state.form.env = null;
|
||||
state.envs = [];
|
||||
getEnvs(projectId);
|
||||
const getAllDatabase = async () => {
|
||||
const reqForm = { ...state.form };
|
||||
reqForm.password = await RsaEncrypt(reqForm.password);
|
||||
state.allDatabases = await dbApi.getAllDatabase.request(reqForm);
|
||||
ElMessage.success('获取成功, 请选择需要管理操作的数据库');
|
||||
};
|
||||
|
||||
const changeEnv = (envId: number) => {
|
||||
for (let p of state.envs as any) {
|
||||
if (p.id == envId) {
|
||||
state.form.env = p.name;
|
||||
}
|
||||
}
|
||||
const getDbPwd = async () => {
|
||||
state.pwd = await dbApi.getDbPwd.request({ id: state.form.id });
|
||||
};
|
||||
|
||||
const btnOk = async () => {
|
||||
if (!state.form.id) {
|
||||
notBlank(state.form.password, '新增操作,密码不可为空');
|
||||
}
|
||||
dbForm.value.validate((valid: boolean) => {
|
||||
dbForm.value.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
state.form.port = Number.parseInt(state.form.port as any);
|
||||
dbApi.saveDb.request(state.form).then(() => {
|
||||
const reqForm = { ...state.form };
|
||||
reqForm.password = await RsaEncrypt(reqForm.password);
|
||||
dbApi.saveDb.request(reqForm).then(() => {
|
||||
ElMessage.success('保存成功');
|
||||
emit('val-change', state.form);
|
||||
state.btnLoading = true;
|
||||
@@ -280,9 +275,8 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const resetInputDb = () => {
|
||||
state.inputDbVisible = false;
|
||||
state.databaseList = [];
|
||||
state.inputDbValue = '';
|
||||
state.allDatabases = [];
|
||||
};
|
||||
|
||||
const cancel = () => {
|
||||
@@ -292,21 +286,7 @@ export default defineComponent({
|
||||
resetInputDb();
|
||||
}, 500);
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
dbForm,
|
||||
InputDbRef,
|
||||
handleClose,
|
||||
showInputDb,
|
||||
handleInputDbConfirm,
|
||||
changeProject,
|
||||
changeEnv,
|
||||
btnOk,
|
||||
cancel,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
<div class="db-list">
|
||||
<el-card>
|
||||
<el-button v-auth="permissions.saveDb" type="primary" icon="plus" @click="editDb(true)">添加</el-button>
|
||||
<el-button v-auth="permissions.saveDb" :disabled="chooseId == null" @click="editDb(false)" type="primary" icon="edit">编辑</el-button>
|
||||
<el-button v-auth="permissions.delDb" :disabled="chooseId == null" @click="deleteDb(chooseId)" type="danger" icon="delete"
|
||||
>删除</el-button
|
||||
>
|
||||
<el-button v-auth="permissions.saveDb" :disabled="chooseId == null" @click="editDb(false)" type="primary"
|
||||
icon="edit">编辑</el-button>
|
||||
<el-button v-auth="permissions.delDb" :disabled="chooseId == null" @click="deleteDb(chooseId)" type="danger"
|
||||
icon="delete">删除</el-button>
|
||||
<div style="float: right">
|
||||
<el-select v-model="query.projectId" placeholder="请选择项目" filterable clearable>
|
||||
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
<el-select @focus="getTags" v-model="query.tagPath" placeholder="请选择标签" filterable clearable>
|
||||
<el-option v-for="item in tags" :key="item" :label="item" :value="item"> </el-option>
|
||||
</el-select>
|
||||
<el-button v-waves type="primary" icon="search" @click="search()" class="ml5">查询</el-button>
|
||||
</div>
|
||||
@@ -20,8 +20,7 @@
|
||||
</el-radio>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="project" label="项目" min-width="100" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="env" label="环境" min-width="100"></el-table-column>
|
||||
<el-table-column prop="tagPath" label="标签路径" min-width="150" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="name" label="名称" min-width="160" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column min-width="170" label="host:port" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
@@ -29,52 +28,58 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="type" label="类型" min-width="90"></el-table-column>
|
||||
<el-table-column prop="database" label="数据库" min-width="160">
|
||||
<el-table-column prop="database" label="数据库" min-width="80">
|
||||
<template #default="scope">
|
||||
<el-tag
|
||||
@click="showTableInfo(scope.row, db)"
|
||||
effect="plain"
|
||||
type="success"
|
||||
size="small"
|
||||
v-for="db in scope.row.dbs"
|
||||
:key="db"
|
||||
style="cursor: pointer; margin-left: 3px"
|
||||
>{{ db }}</el-tag
|
||||
>
|
||||
<el-popover placement="right" trigger="click" :width="300">
|
||||
<template #reference>
|
||||
<el-link type="primary" :underline="false" plain @click="selectDb(scope.row.dbs)">查看
|
||||
</el-link>
|
||||
</template>
|
||||
<el-input v-model="filterDb.param" @keyup="filterSchema" class="w-50 m-2" placeholder="搜索"
|
||||
size="small">
|
||||
<template #prefix>
|
||||
<el-icon class="el-input__icon">
|
||||
<search-icon />
|
||||
</el-icon>
|
||||
</template>
|
||||
</el-input>
|
||||
<div class="el-tag--plain el-tag--success" v-for="db in filterDb.list" :key="db"
|
||||
style="border:1px var(--color-success-light-3) solid; margin-top: 3px;border-radius: 5px; padding: 2px;position: relative">
|
||||
<el-link type="success" plain size="small" :underline="false"
|
||||
@click="showTableInfo(scope.row, db)">{{ db }}</el-link>
|
||||
<el-link type="primary" plain size="small" :underline="false"
|
||||
@click="openSqlExec(scope.row, db)" style="position: absolute; right: 4px">数据操作
|
||||
</el-link>
|
||||
</div>
|
||||
</el-popover>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="username" label="用户名" min-width="100"></el-table-column>
|
||||
<el-table-column prop="remark" label="备注" min-width="150" show-overflow-tooltip></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 label="操作" min-width="160" fixed="right">
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="操作" min-width="120" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-link type="primary" plain size="small" :underline="false" @click="onShowSqlExec(scope.row)">SQL执行记录</el-link>
|
||||
<el-link plain size="small" :underline="false" @click="showInfo(scope.row)">
|
||||
详情</el-link>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
<el-link class="ml5" type="primary" plain size="small" :underline="false"
|
||||
@click="onShowSqlExec(scope.row)">
|
||||
SQL执行记录</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-row style="margin-top: 20px" type="flex" justify="end">
|
||||
<el-pagination
|
||||
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-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>
|
||||
|
||||
<el-dialog width="75%" :title="`${db} 表信息`" :before-close="closeTableInfo" v-model="tableInfoDialog.visible">
|
||||
<el-dialog width="80%" :title="`${db} 表信息`" :before-close="closeTableInfo" v-model="tableInfoDialog.visible">
|
||||
<el-row class="mb10">
|
||||
<el-popover v-model:visible="showDumpInfo" :width="470" placement="right">
|
||||
<el-popover v-model:visible="showDumpInfo" :width="470" placement="right" trigger="click">
|
||||
<template #reference>
|
||||
<el-button class="ml5" type="success" size="small" @click="showDumpInfo = !showDumpInfo">导出</el-button>
|
||||
<el-button class="ml5" type="success" size="small">导出</el-button>
|
||||
</template>
|
||||
<el-form-item label="导出内容: ">
|
||||
<el-radio-group v-model="dumpInfo.type">
|
||||
@@ -85,10 +90,13 @@
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="导出表: ">
|
||||
<el-table @selection-change="handleDumpTableSelectionChange" max-height="300" size="small" :data="tableInfoDialog.infos">
|
||||
<el-table @selection-change="handleDumpTableSelectionChange" max-height="300" size="small"
|
||||
:data="tableInfoDialog.infos">
|
||||
<el-table-column type="selection" width="45" />
|
||||
<el-table-column property="tableName" label="表名" min-width="150" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column property="tableComment" label="备注" min-width="150" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column property="tableName" label="表名" min-width="150" show-overflow-tooltip>
|
||||
</el-table-column>
|
||||
<el-table-column property="tableComment" label="备注" min-width="150" show-overflow-tooltip>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-form-item>
|
||||
|
||||
@@ -98,44 +106,45 @@
|
||||
</div>
|
||||
</el-popover>
|
||||
|
||||
<el-button type="primary" size="small" @click="tableCreateDialog.visible = true">创建表</el-button>
|
||||
<el-button type="primary" size="small" @click="openEditTable(false)">创建表</el-button>
|
||||
</el-row>
|
||||
<el-table v-loading="tableInfoDialog.loading" border stripe :data="tableInfoDialog.infos" size="small">
|
||||
<el-table-column property="tableName" label="表名" min-width="150" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column property="tableComment" label="备注" min-width="150" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column
|
||||
prop="tableRows"
|
||||
label="Rows"
|
||||
min-width="70"
|
||||
sortable
|
||||
:sort-method="(a, b) => parseInt(a.tableRows) - parseInt(b.tableRows)"
|
||||
></el-table-column>
|
||||
<el-table-column
|
||||
property="dataLength"
|
||||
label="数据大小"
|
||||
sortable
|
||||
:sort-method="(a, b) => parseInt(a.dataLength) - parseInt(b.dataLength)"
|
||||
>
|
||||
<el-table v-loading="tableInfoDialog.loading" border stripe :data="filterTableInfos" size="small"
|
||||
max-height="680">
|
||||
<el-table-column property="tableName" label="表名" min-width="150" show-overflow-tooltip>
|
||||
<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 prop="tableRows" label="Rows" min-width="70" sortable
|
||||
:sort-method="(a: any, b: any) => parseInt(a.tableRows) - parseInt(b.tableRows)"></el-table-column>
|
||||
<el-table-column property="dataLength" label="数据大小" sortable
|
||||
:sort-method="(a: any, b: any) => parseInt(a.dataLength) - parseInt(b.dataLength)">
|
||||
<template #default="scope">
|
||||
{{ formatByteSize(scope.row.dataLength) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
property="indexLength"
|
||||
label="索引大小"
|
||||
sortable
|
||||
:sort-method="(a, b) => parseInt(a.indexLength) - parseInt(b.indexLength)"
|
||||
>
|
||||
<el-table-column property="indexLength" label="索引大小" sortable
|
||||
:sort-method="(a: any, b: any) => parseInt(a.indexLength) - parseInt(b.indexLength)">
|
||||
<template #default="scope">
|
||||
{{ formatByteSize(scope.row.indexLength) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column property="createTime" label="创建时间" min-width="150"> </el-table-column>
|
||||
<el-table-column label="更多信息" min-width="100">
|
||||
<el-table-column label="更多信息" min-width="140">
|
||||
<template #default="scope">
|
||||
<el-link @click.prevent="showColumns(scope.row)" type="primary">字段</el-link>
|
||||
<el-link class="ml5" @click.prevent="showTableIndex(scope.row)" type="success">索引</el-link>
|
||||
<el-link class="ml5" @click.prevent="showCreateDdl(scope.row)" type="info">SQL</el-link>
|
||||
<el-link class="ml5"
|
||||
v-if="tableCreateDialog.enableEditTypes.indexOf(tableCreateDialog.type) > -1"
|
||||
@click.prevent="openEditTable(scope.row)" type="warning">编辑表</el-link>
|
||||
<el-link class="ml5" @click.prevent="showCreateDdl(scope.row)" type="info">DDL</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" min-width="80">
|
||||
@@ -146,17 +155,18 @@
|
||||
</el-table>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
width="90%"
|
||||
:title="`${sqlExecLogDialog.title} - SQL执行记录`"
|
||||
:before-close="onBeforeCloseSqlExecDialog"
|
||||
v-model="sqlExecLogDialog.visible"
|
||||
>
|
||||
<el-dialog width="90%" :title="`${sqlExecLogDialog.title} - SQL执行记录`" :before-close="onBeforeCloseSqlExecDialog"
|
||||
v-model="sqlExecLogDialog.visible">
|
||||
<div class="toolbar">
|
||||
<el-input v-model="sqlExecLogDialog.query.db" placeholder="请输入数据库名" clearable style="width: 150px" />
|
||||
<el-input v-model="sqlExecLogDialog.query.table" placeholder="请输入表名" clearable class="ml5" style="width: 150px" />
|
||||
<el-select v-model="sqlExecLogDialog.query.db" placeholder="请选择数据库" filterable clearable>
|
||||
<el-option v-for="item in sqlExecLogDialog.dbs" :key="item" :label="`${item}`" :value="item">
|
||||
</el-option>
|
||||
</el-select>
|
||||
<el-input v-model="sqlExecLogDialog.query.table" placeholder="请输入表名" clearable class="ml5"
|
||||
style="width: 180px" />
|
||||
<el-select v-model="sqlExecLogDialog.query.type" placeholder="请选择操作类型" clearable class="ml5">
|
||||
<el-option v-for="item in enums.DbSqlExecTypeEnum" :key="item.value" :label="item.label" :value="item.value"> </el-option>
|
||||
<el-option v-for="item in enums.DbSqlExecTypeEnum as any" :key="item.value" :label="item.label"
|
||||
:value="item.value"> </el-option>
|
||||
</el-select>
|
||||
<el-button class="ml5" @click="searchSqlExecLog" type="success" icon="search"></el-button>
|
||||
</div>
|
||||
@@ -165,9 +175,12 @@
|
||||
<el-table-column prop="table" label="表" min-width="60" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column prop="type" label="类型" width="85" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
<el-tag v-if="scope.row.type == enums.DbSqlExecTypeEnum.UPDATE.value" color="#E4F5EB" size="small">UPDATE</el-tag>
|
||||
<el-tag v-if="scope.row.type == enums.DbSqlExecTypeEnum.DELETE.value" color="#F9E2AE" size="small">DELETE</el-tag>
|
||||
<el-tag v-if="scope.row.type == enums.DbSqlExecTypeEnum.INSERT.value" color="#A8DEE0" size="small">INSERT</el-tag>
|
||||
<el-tag v-if="scope.row.type == enums.DbSqlExecTypeEnum['UPDATE'].value" color="#E4F5EB"
|
||||
size="small">UPDATE</el-tag>
|
||||
<el-tag v-if="scope.row.type == enums.DbSqlExecTypeEnum['DELETE'].value" color="#F9E2AE"
|
||||
size="small">DELETE</el-tag>
|
||||
<el-tag v-if="scope.row.type == enums.DbSqlExecTypeEnum['INSERT'].value" color="#A8DEE0"
|
||||
size="small">INSERT</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="sql" label="SQL" min-width="230" show-overflow-tooltip> </el-table-column>
|
||||
@@ -175,38 +188,30 @@
|
||||
<el-table-column prop="creator" label="执行人" min-width="60" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column prop="createTime" label="执行时间" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.createTime) }}
|
||||
{{ dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="remark" label="备注" min-width="60" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column label="操作" min-width="50" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-link
|
||||
v-if="scope.row.type == enums.DbSqlExecTypeEnum.UPDATE.value || scope.row.type == enums.DbSqlExecTypeEnum.DELETE.value"
|
||||
type="primary"
|
||||
plain
|
||||
size="small"
|
||||
:underline="false"
|
||||
@click="onShowRollbackSql(scope.row)"
|
||||
>还原SQL</el-link
|
||||
>
|
||||
v-if="scope.row.type == enums.DbSqlExecTypeEnum['UPDATE'].value || scope.row.type == enums.DbSqlExecTypeEnum['DELETE'].value"
|
||||
type="primary" plain size="small" :underline="false" @click="onShowRollbackSql(scope.row)">
|
||||
还原SQL</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-row style="margin-top: 20px" type="flex" justify="end">
|
||||
<el-pagination
|
||||
style="text-align: right"
|
||||
@current-change="handleSqlExecPageChange"
|
||||
:total="sqlExecLogDialog.total"
|
||||
layout="prev, pager, next, total, jumper"
|
||||
v-model:current-page="sqlExecLogDialog.query.pageNum"
|
||||
:page-size="sqlExecLogDialog.query.pageSize"
|
||||
></el-pagination>
|
||||
<el-pagination style="text-align: right" @current-change="handleSqlExecPageChange"
|
||||
:total="sqlExecLogDialog.total" layout="prev, pager, next, total, jumper"
|
||||
v-model:current-page="sqlExecLogDialog.query.pageNum" :page-size="sqlExecLogDialog.query.pageSize">
|
||||
</el-pagination>
|
||||
</el-row>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog width="55%" :title="`还原SQL`" v-model="rollbackSqlDialog.visible">
|
||||
<el-input type="textarea" :autosize="{ minRows: 15, maxRows: 30 }" v-model="rollbackSqlDialog.sql" size="small"> </el-input>
|
||||
<el-input type="textarea" :autosize="{ minRows: 15, maxRows: 30 }" v-model="rollbackSqlDialog.sql"
|
||||
size="small"> </el-input>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog width="40%" :title="`${chooseTableName} 字段信息`" v-model="columnDialog.visible">
|
||||
@@ -220,59 +225,87 @@
|
||||
|
||||
<el-dialog width="40%" :title="`${chooseTableName} 索引信息`" v-model="indexDialog.visible">
|
||||
<el-table border stripe :data="indexDialog.indexs" size="small">
|
||||
<el-table-column prop="indexName" label="索引名" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column prop="columnName" label="列名" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column prop="indexName" label="索引名" min-width="120" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column prop="columnName" label="列名" min-width="120" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column prop="seqInIndex" label="列序列号" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column prop="indexType" label="类型"> </el-table-column>
|
||||
<el-table-column prop="indexComment" label="备注" min-width="230" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column prop="indexComment" label="备注" min-width="130" show-overflow-tooltip>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog width="55%" :title="`${chooseTableName} Create-DDL`" v-model="ddlDialog.visible">
|
||||
<el-input disabled type="textarea" :autosize="{ minRows: 15, maxRows: 30 }" v-model="ddlDialog.ddl" size="small"> </el-input>
|
||||
<el-input disabled type="textarea" :autosize="{ minRows: 15, maxRows: 30 }" v-model="ddlDialog.ddl"
|
||||
size="small"> </el-input>
|
||||
</el-dialog>
|
||||
|
||||
<db-edit
|
||||
@val-change="valChange"
|
||||
:projects="projects"
|
||||
:title="dbEditDialog.title"
|
||||
v-model:visible="dbEditDialog.visible"
|
||||
v-model:db="dbEditDialog.data"
|
||||
></db-edit>
|
||||
<create-table :dbId="dbId" v-model:visible="tableCreateDialog.visible"></create-table>
|
||||
<el-dialog v-model="infoDialog.visible">
|
||||
<el-descriptions title="详情" :column="3" border>
|
||||
<el-descriptions-item :span="1.5" label="id">{{ infoDialog.data.id }}</el-descriptions-item>
|
||||
<el-descriptions-item :span="1.5" label="名称">{{ infoDialog.data.name }}</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item :span="3" label="标签路径">{{ infoDialog.data.tagPath }}</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item :span="2" label="主机">{{ infoDialog.data.host }}</el-descriptions-item>
|
||||
<el-descriptions-item :span="1" label="端口">{{ infoDialog.data.port }}</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item :span="2" label="用户名">{{ infoDialog.data.username }}</el-descriptions-item>
|
||||
<el-descriptions-item :span="1" label="类型">{{ infoDialog.data.type }}</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item :span="3" label="连接参数">{{ infoDialog.data.params }}</el-descriptions-item>
|
||||
<el-descriptions-item :span="3" label="备注">{{ infoDialog.data.remark }}</el-descriptions-item>
|
||||
<el-descriptions-item :span="3" label="数据库">{{ infoDialog.data.database }}</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item :span="3" label="SSH隧道">{{ infoDialog.data.enableSshTunnel == 1 ? '是' : '否' }}
|
||||
</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item :span="2" label="创建时间">{{ dateFormat(infoDialog.data.createTime) }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item :span="1" label="创建者">{{ infoDialog.data.creator }}</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item :span="2" label="更新时间">{{ dateFormat(infoDialog.data.updateTime) }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item :span="1" label="修改者">{{ infoDialog.data.modifier }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</el-dialog>
|
||||
|
||||
<db-edit @val-change="valChange" :title="dbEditDialog.title" v-model:visible="dbEditDialog.visible"
|
||||
v-model:db="dbEditDialog.data"></db-edit>
|
||||
<create-table :title="tableCreateDialog.title" :active-name="tableCreateDialog.activeName" :dbId="dbId" :db="db"
|
||||
:data="tableCreateDialog.data" v-model:visible="tableCreateDialog.visible" @submit-sql="onSubmitSql">
|
||||
</create-table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang='ts'>
|
||||
import { toRefs, reactive, onMounted, defineComponent } from 'vue';
|
||||
<script lang='ts' setup>
|
||||
import { toRefs, reactive, computed, onMounted } from 'vue';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import { formatByteSize } from '@/common/utils/format';
|
||||
import DbEdit from './DbEdit.vue';
|
||||
import CreateTable from './CreateTable.vue';
|
||||
import { dbApi } from './api';
|
||||
import enums from './enums';
|
||||
import { projectApi } from '../project/api.ts';
|
||||
import SqlExecBox from './component/SqlExecBox.ts';
|
||||
import config from '@/common/config';
|
||||
import { getSession } from '@/common/utils/storage';
|
||||
import { isTrue } from '@/common/assert';
|
||||
import { Search as SearchIcon } from '@element-plus/icons-vue'
|
||||
import router from '@/router';
|
||||
import { store } from '@/store';
|
||||
import { tagApi } from '../tag/api.ts';
|
||||
import { dateFormat } from '@/common/utils/date';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'DbList',
|
||||
components: {
|
||||
DbEdit,
|
||||
CreateTable,
|
||||
},
|
||||
setup() {
|
||||
const state = reactive({
|
||||
dbId: 0,
|
||||
db: '',
|
||||
permissions: {
|
||||
const permissions = {
|
||||
saveDb: 'db:save',
|
||||
delDb: 'db:del',
|
||||
},
|
||||
projects: [],
|
||||
chooseId: null,
|
||||
}
|
||||
|
||||
const state = reactive({
|
||||
row: {},
|
||||
dbId: 0,
|
||||
db: '',
|
||||
tags: [],
|
||||
chooseId: null as any,
|
||||
/**
|
||||
* 选中的数据
|
||||
*/
|
||||
@@ -281,11 +314,17 @@ export default defineComponent({
|
||||
* 查询条件
|
||||
*/
|
||||
query: {
|
||||
tagPath: null,
|
||||
projectId: null,
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
},
|
||||
datas: [],
|
||||
total: 0,
|
||||
infoDialog: {
|
||||
visible: false,
|
||||
data: null as any,
|
||||
},
|
||||
showDumpInfo: false,
|
||||
dumpInfo: {
|
||||
id: 0,
|
||||
@@ -299,6 +338,7 @@ export default defineComponent({
|
||||
visible: false,
|
||||
data: [],
|
||||
total: 0,
|
||||
dbs: [],
|
||||
query: {
|
||||
dbId: 0,
|
||||
db: '',
|
||||
@@ -317,6 +357,8 @@ export default defineComponent({
|
||||
loading: false,
|
||||
visible: false,
|
||||
infos: [],
|
||||
tableNameSearch: '',
|
||||
tableCommentSearch: '',
|
||||
},
|
||||
columnDialog: {
|
||||
visible: false,
|
||||
@@ -332,17 +374,75 @@ export default defineComponent({
|
||||
},
|
||||
dbEditDialog: {
|
||||
visible: false,
|
||||
data: null,
|
||||
data: null as any,
|
||||
title: '新增数据库',
|
||||
},
|
||||
tableCreateDialog: {
|
||||
title: '创建表',
|
||||
visible: false,
|
||||
activeName: '1',
|
||||
type: '',
|
||||
enableEditTypes: ['mysql'], // 支持"编辑表"的数据库类型
|
||||
data: { // 修改表时,传递修改数据
|
||||
edit: false,
|
||||
row: {},
|
||||
indexs: [],
|
||||
columns: [],
|
||||
},
|
||||
},
|
||||
filterDb: {
|
||||
param: '',
|
||||
cache: [],
|
||||
list: [],
|
||||
}
|
||||
});
|
||||
|
||||
const {
|
||||
dbId,
|
||||
db,
|
||||
tags,
|
||||
chooseId,
|
||||
query,
|
||||
datas,
|
||||
total,
|
||||
infoDialog,
|
||||
showDumpInfo,
|
||||
dumpInfo,
|
||||
sqlExecLogDialog,
|
||||
rollbackSqlDialog,
|
||||
chooseTableName,
|
||||
tableInfoDialog,
|
||||
columnDialog,
|
||||
indexDialog,
|
||||
ddlDialog,
|
||||
dbEditDialog,
|
||||
tableCreateDialog,
|
||||
filterDb,
|
||||
} = toRefs(state)
|
||||
|
||||
|
||||
onMounted(async () => {
|
||||
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) => {
|
||||
@@ -369,7 +469,16 @@ export default defineComponent({
|
||||
search();
|
||||
};
|
||||
|
||||
const editDb = (isAdd = false) => {
|
||||
const showInfo = (info: any) => {
|
||||
state.infoDialog.data = info;
|
||||
state.infoDialog.visible = true;
|
||||
}
|
||||
|
||||
const getTags = async () => {
|
||||
state.tags = await tagApi.getAccountTags.request(null);
|
||||
};
|
||||
|
||||
const editDb = async (isAdd = false) => {
|
||||
if (isAdd) {
|
||||
state.dbEditDialog.data = null;
|
||||
state.dbEditDialog.title = '新增数据库资源';
|
||||
@@ -404,6 +513,7 @@ export default defineComponent({
|
||||
const onShowSqlExec = async (row: any) => {
|
||||
state.sqlExecLogDialog.title = `${row.name}[${row.host}:${row.port}]`;
|
||||
state.sqlExecLogDialog.query.dbId = row.id;
|
||||
state.sqlExecLogDialog.dbs = row.database.split(' ');
|
||||
searchSqlExecLog();
|
||||
state.sqlExecLogDialog.visible = true;
|
||||
};
|
||||
@@ -411,6 +521,7 @@ export default defineComponent({
|
||||
const onBeforeCloseSqlExecDialog = () => {
|
||||
state.sqlExecLogDialog.visible = false;
|
||||
state.sqlExecLogDialog.data = [];
|
||||
state.sqlExecLogDialog.dbs = [];
|
||||
state.sqlExecLogDialog.total = 0;
|
||||
state.sqlExecLogDialog.query.dbId = 0;
|
||||
state.sqlExecLogDialog.query.pageNum = 1;
|
||||
@@ -455,7 +566,7 @@ export default defineComponent({
|
||||
|
||||
const onShowRollbackSql = async (sqlExecLog: any) => {
|
||||
const columns = await dbApi.columnMetadata.request({ id: sqlExecLog.dbId, db: sqlExecLog.db, tableName: sqlExecLog.table });
|
||||
const primaryKey = columns[0].columnName;
|
||||
const primaryKey = getPrimaryKey(columns);
|
||||
const oldValue = JSON.parse(sqlExecLog.oldValue);
|
||||
|
||||
const rollbackSqls = [];
|
||||
@@ -485,6 +596,14 @@ export default defineComponent({
|
||||
state.rollbackSqlDialog.visible = true;
|
||||
};
|
||||
|
||||
const getPrimaryKey = (columns: any) => {
|
||||
const col = columns.find((c: any) => c.columnKey == 'PRI');
|
||||
if (col) {
|
||||
return col.columnName;
|
||||
}
|
||||
return columns[0].columnName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 包装值,如果值类型为number则直接返回,其他则需要使用''包装
|
||||
*/
|
||||
@@ -500,13 +619,22 @@ export default defineComponent({
|
||||
state.tableInfoDialog.visible = true;
|
||||
try {
|
||||
state.tableInfoDialog.infos = await dbApi.tableInfos.request({ id: row.id, db });
|
||||
state.tableCreateDialog.type = row.type
|
||||
state.dbId = row.id;
|
||||
state.row = row;
|
||||
state.db = db;
|
||||
} catch (e) {
|
||||
state.tableInfoDialog.visible = false;
|
||||
} finally {
|
||||
state.tableInfoDialog.loading = false;
|
||||
}
|
||||
};
|
||||
|
||||
const onSubmitSql = async (row: { tableName: string }) => {
|
||||
await openEditTable(row)
|
||||
state.tableInfoDialog.infos = await dbApi.tableInfos.request({ id: state.dbId, db: state.db });
|
||||
}
|
||||
|
||||
const closeTableInfo = () => {
|
||||
state.showDumpInfo = false;
|
||||
state.tableInfoDialog.visible = false;
|
||||
@@ -567,33 +695,64 @@ export default defineComponent({
|
||||
});
|
||||
} catch (err) { }
|
||||
};
|
||||
const openSqlExec = (row: any, db: any) => {
|
||||
// 判断db是否发生改变
|
||||
let oldDb = store.state.sqlExecInfo.dbOptInfo.db;
|
||||
if (db && oldDb !== db) {
|
||||
const { tagPath, id } = row;
|
||||
let params = {
|
||||
tagPath,
|
||||
dbId: id,
|
||||
db
|
||||
}
|
||||
store.dispatch('sqlExecInfo/setSqlExecInfo', params);
|
||||
}
|
||||
router.push({ name: 'SqlExec' });
|
||||
}
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
enums,
|
||||
search,
|
||||
choose,
|
||||
handlePageChange,
|
||||
editDb,
|
||||
valChange,
|
||||
deleteDb,
|
||||
onShowSqlExec,
|
||||
handleDumpTableSelectionChange,
|
||||
dump,
|
||||
onBeforeCloseSqlExecDialog,
|
||||
handleSqlExecPageChange,
|
||||
searchSqlExecLog,
|
||||
onShowRollbackSql,
|
||||
showTableInfo,
|
||||
closeTableInfo,
|
||||
showColumns,
|
||||
showTableIndex,
|
||||
showCreateDdl,
|
||||
dropTable,
|
||||
formatByteSize,
|
||||
};
|
||||
},
|
||||
// 点击查看时初始化数据
|
||||
const selectDb = (row: any) => {
|
||||
state.filterDb.param = ''
|
||||
state.filterDb.cache = row;
|
||||
state.filterDb.list = row;
|
||||
}
|
||||
|
||||
// 输入字符过滤schema
|
||||
const filterSchema = () => {
|
||||
if (state.filterDb.param) {
|
||||
state.filterDb.list = state.filterDb.cache.filter((a) => { return String(a).toLowerCase().indexOf(state.filterDb.param) > -1 })
|
||||
} else {
|
||||
state.filterDb.list = state.filterDb.cache;
|
||||
}
|
||||
}
|
||||
|
||||
// 打开编辑表
|
||||
const openEditTable = async (row: any) => {
|
||||
|
||||
state.tableCreateDialog.visible = true
|
||||
state.tableCreateDialog.activeName = '1'
|
||||
|
||||
if (row === false) {
|
||||
state.tableCreateDialog.data = { edit: false, row: {}, indexs: [], columns: [] }
|
||||
state.tableCreateDialog.title = '创建表'
|
||||
}
|
||||
|
||||
if (row.tableName) {
|
||||
state.tableCreateDialog.title = '修改表'
|
||||
let indexs = await dbApi.tableIndex.request({
|
||||
id: state.chooseId,
|
||||
db: state.db,
|
||||
tableName: row.tableName,
|
||||
});
|
||||
let columns = await dbApi.columnMetadata.request({
|
||||
id: state.chooseId,
|
||||
db: state.db,
|
||||
tableName: row.tableName,
|
||||
});
|
||||
state.tableCreateDialog.data = { edit: true, row, indexs, columns }
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,19 +2,18 @@
|
||||
<div>
|
||||
<el-dialog :title="`${title} 详情`" v-model="dialogVisible" :before-close="cancel" width="90%">
|
||||
<el-table @cell-click="cellClick" :data="data.res">
|
||||
<el-table-column :width="200" :prop="item" :label="item" v-for="item in data.colNames" :key="item"> </el-table-column>
|
||||
<el-table-column :width="200" :prop="item" :label="item" v-for="item in data.colNames" :key="item">
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
<script lang="ts">
|
||||
import { watch, toRefs, reactive, defineComponent } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { watch, toRefs, reactive } from 'vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'tableEdit',
|
||||
props: {
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -24,8 +23,11 @@ export default defineComponent({
|
||||
data: {
|
||||
type: Object,
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
})
|
||||
|
||||
//定义事件
|
||||
const emit = defineEmits(['update:visible'])
|
||||
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
data: {
|
||||
@@ -34,13 +36,18 @@ export default defineComponent({
|
||||
},
|
||||
});
|
||||
|
||||
watch(props, async (newValue) => {
|
||||
const {
|
||||
dialogVisible,
|
||||
data,
|
||||
} = toRefs(state)
|
||||
|
||||
watch(props, async (newValue: any) => {
|
||||
state.dialogVisible = newValue.visible;
|
||||
state.data.res = newValue.data.res;
|
||||
state.data.colNames = newValue.data.colNames;
|
||||
});
|
||||
const cellClick = (row: any, column: any, cell: any, event: any) => {
|
||||
console.log(cell.children[0].tagName);
|
||||
|
||||
const cellClick = (row: any, column: any, cell: any) => {
|
||||
let isDiv = cell.children[0].tagName === 'DIV';
|
||||
let text = cell.children[0].innerText;
|
||||
let div = cell.children[0];
|
||||
@@ -55,15 +62,10 @@ export default defineComponent({
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const cancel = () => {
|
||||
emit('update:visible', false);
|
||||
};
|
||||
return {
|
||||
...toRefs(state),
|
||||
cancel,
|
||||
cellClick,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ export const dbApi = {
|
||||
// 获取权限列表
|
||||
dbs: Api.create("/dbs", 'get'),
|
||||
saveDb: Api.create("/dbs", 'post'),
|
||||
getAllDatabase: Api.create("/dbs/databases", 'post'),
|
||||
getDbPwd: Api.create("/dbs/{id}/pwd", 'get'),
|
||||
deleteDb: Api.create("/dbs/{id}", 'delete'),
|
||||
dumpDb: Api.create("/dbs/{id}/dump", 'post'),
|
||||
tableInfos: Api.create("/dbs/{id}/t-infos", 'get'),
|
||||
|
||||
@@ -34,7 +34,7 @@ const SqlExecBox = (props: SqlExecProps): void => {
|
||||
if (boxInstance) {
|
||||
const boxVue = boxInstance.component
|
||||
// 调用open方法显示弹框,注意不能使用boxVue.ctx来调用组件函数(build打包后ctx会获取不到)
|
||||
boxVue.proxy.open(props);
|
||||
boxVue.exposed.open(props);
|
||||
} else {
|
||||
boxInstance = renderBox()
|
||||
SqlExecBox(props)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-dialog title="待执行SQL" v-model="dialogVisible" :show-close="false" width="600px">
|
||||
<codemirror height="350px" class="codesql" ref="cmEditor" language="sql" v-model="sqlValue" :options="cmOptions" />
|
||||
<el-dialog :destroy-on-close="true" title="待执行SQL" v-model="dialogVisible" :show-close="false" width="600px" @close="cancel">
|
||||
<monaco-editor height="300px" class="codesql" language="sql" v-model="sqlValue" />
|
||||
<el-input ref="remarkInputRef" v-model="remark" placeholder="请输入执行备注" class="mt5" />
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
@@ -13,29 +13,17 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, ref, nextTick, reactive, defineComponent } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, ref, nextTick, reactive } from 'vue';
|
||||
import { dbApi } from '../api';
|
||||
import { ElDialog, ElButton, ElInput, ElMessage, InputInstance } from 'element-plus';
|
||||
// import base style
|
||||
import 'codemirror/lib/codemirror.css';
|
||||
// 引入主题后还需要在 options 中指定主题才会生效
|
||||
import 'codemirror/theme/base16-light.css';
|
||||
import 'codemirror/addon/selection/active-line';
|
||||
import { codemirror } from '@/components/codemirror';
|
||||
import MonacoEditor from '@/components/monaco/MonacoEditor.vue';
|
||||
import { format as sqlFormatter } from 'sql-formatter';
|
||||
|
||||
import { SqlExecProps } from './SqlExecBox';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'SqlExecDialog',
|
||||
components: {
|
||||
codemirror,
|
||||
ElButton,
|
||||
ElDialog,
|
||||
ElInput,
|
||||
},
|
||||
props: {
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -48,8 +36,8 @@ export default defineComponent({
|
||||
sql: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
setup(props: any) {
|
||||
})
|
||||
|
||||
const remarkInputRef = ref<InputInstance>();
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
@@ -58,21 +46,16 @@ export default defineComponent({
|
||||
db: '',
|
||||
remark: '',
|
||||
btnLoading: false,
|
||||
cmOptions: {
|
||||
tabSize: 4,
|
||||
mode: 'text/x-sql',
|
||||
lineNumbers: true,
|
||||
line: true,
|
||||
indentWithTabs: true,
|
||||
smartIndent: true,
|
||||
matchBrackets: true,
|
||||
theme: 'base16-light',
|
||||
autofocus: true,
|
||||
extraKeys: { Tab: 'autocomplete' }, // 自定义快捷键
|
||||
},
|
||||
});
|
||||
state.sqlValue = props.sql;
|
||||
|
||||
const {
|
||||
dialogVisible,
|
||||
sqlValue,
|
||||
remark,
|
||||
btnLoading
|
||||
} = toRefs(state)
|
||||
|
||||
state.sqlValue = props.sql as any;
|
||||
let runSuccessCallback: any;
|
||||
let cancelCallback: any;
|
||||
let runSuccess: boolean = false;
|
||||
@@ -94,21 +77,26 @@ export default defineComponent({
|
||||
remark: state.remark,
|
||||
sql: state.sqlValue.trim(),
|
||||
});
|
||||
if (parseInt(res.res[0].影响条数) >= 1) {
|
||||
ElMessage.success('执行成功');
|
||||
runSuccess = true;
|
||||
} else {
|
||||
ElMessage.error('执行失败');
|
||||
runSuccess = false;
|
||||
|
||||
for (let re of res.res) {
|
||||
if (re.result !== 'success') {
|
||||
ElMessage.error(`${re.sql} \n执行失败: ${re.result}`);
|
||||
throw new Error(re.result)
|
||||
}
|
||||
}
|
||||
|
||||
runSuccess = true;
|
||||
ElMessage.success('执行成功');
|
||||
} catch (e) {
|
||||
runSuccess = false;
|
||||
}
|
||||
if (runSuccess && runSuccessCallback) {
|
||||
if (runSuccess) {
|
||||
if (runSuccessCallback) {
|
||||
runSuccessCallback();
|
||||
}
|
||||
state.btnLoading = false;
|
||||
cancel();
|
||||
}
|
||||
state.btnLoading = false;
|
||||
};
|
||||
|
||||
const cancel = () => {
|
||||
@@ -141,15 +129,7 @@ export default defineComponent({
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
remarkInputRef,
|
||||
open,
|
||||
runSql,
|
||||
cancel,
|
||||
};
|
||||
},
|
||||
});
|
||||
defineExpose({ open })
|
||||
</script>
|
||||
<style lang="scss">
|
||||
.codesql {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
export const TYPE_LIST = ['bigint', 'binary', 'blob', 'char', 'datetime', 'decimal', 'double', 'enum', 'float', 'int', 'json', 'longblob', 'longtext', 'mediumblob', 'mediumtext', 'set', 'smallint', 'text', 'time', 'timestamp', 'tinyint', 'varbinary', 'varchar']
|
||||
export const TYPE_LIST = ['bigint', 'binary', 'blob', 'char', 'datetime', 'date', 'decimal', 'double', 'enum', 'float', 'int', 'json', 'longblob', 'longtext', 'mediumblob', 'mediumtext', 'set', 'smallint', 'text', 'time', 'timestamp', 'tinyint', 'varbinary', 'varchar']
|
||||
|
||||
export const CHARACTER_SET_NAME_LIST = ['armscii8', 'ascii', 'big5', 'binary', 'cp1250', 'cp1251', 'cp1256', 'cp1257', 'cp850', 'cp852', 'cp866', 'cp932', 'dec8', 'eucjpms', 'euckr', 'gb18030', 'gb2312', 'gbk', 'geostd8', 'greek', 'hebrew', 'hp8', 'keybcs2', 'koi8r', 'koi8u', 'latin1', 'latin2', 'latin5', 'latin7', 'macce', 'macroman', 'sjis', 'swe7', 'tis620', 'ucs2', 'ujis', 'utf16', 'utf16le', 'utf32', 'utf8', 'utf8mb4']
|
||||
|
||||
export const COLLATION_SUFFIX_LIST = ['unicode_ci', 'bin', 'croatian_ci', 'czech_ci', 'danish_ci', 'esperanto_ci', 'estonian_ci', 'general_ci', 'german2_ci', 'hungarian_ci', 'icelandic_ci', 'latvian_ci', 'lithuanian_ci', 'persian_ci', 'polish_ci', 'roman_ci', 'romanian_ci', 'sinhala_ci', 'slovak_ci', 'slovenian_ci', 'spanish2_ci', 'spanish_ci', 'swedish_ci', 'turkish_ci', 'unicode_520_ci', 'vietnamese_ci']
|
||||
|
||||
@@ -3,70 +3,56 @@
|
||||
<el-dialog :title="title" v-model="dialogVisible" :show-close="true" :before-close="handleClose" width="800px">
|
||||
<div class="toolbar">
|
||||
<div style="float: right">
|
||||
<el-button v-auth="'machine:file:add'" type="primary" @click="add" icon="plus" size="small" plain>添加</el-button>
|
||||
<el-button v-auth="'machine:file:add'" type="primary" @click="add" icon="plus" size="small" plain>添加
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<el-table :data="fileTable" stripe style="width: 100%">
|
||||
<el-table-column prop="name" label="名称" width>
|
||||
<template #default="scope">
|
||||
<el-input v-model="scope.row.name" size="small" :disabled="scope.row.id != null" clearable></el-input>
|
||||
<el-input v-model="scope.row.name" size="small" :disabled="scope.row.id != null" clearable>
|
||||
</el-input>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="name" label="类型" min-width="50px">
|
||||
<template #default="scope">
|
||||
<el-select :disabled="scope.row.id != null" size="small" v-model="scope.row.type" style="width: 100px" placeholder="请选择">
|
||||
<el-option v-for="item in enums.FileTypeEnum" :key="item.value" :label="item.label" :value="item.value"></el-option>
|
||||
<el-select :disabled="scope.row.id != null" size="small" v-model="scope.row.type"
|
||||
style="width: 100px" placeholder="请选择">
|
||||
<el-option v-for="item in enums.FileTypeEnum as any" :key="item.value" :label="item.label"
|
||||
:value="item.value"></el-option>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="path" label="路径" width>
|
||||
<template #default="scope">
|
||||
<el-input v-model="scope.row.path" :disabled="scope.row.id != null" size="small" clearable></el-input>
|
||||
<el-input v-model="scope.row.path" :disabled="scope.row.id != null" size="small" clearable>
|
||||
</el-input>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width>
|
||||
<template #default="scope">
|
||||
<el-button v-if="scope.row.id == null" @click="addFiles(scope.row)" type="success" icon="success-filled" size="small" plain
|
||||
>确定</el-button
|
||||
>
|
||||
<el-button v-if="scope.row.id != null" @click="getConf(scope.row)" type="primary" icon="tickets" size="small" plain
|
||||
>查看</el-button
|
||||
>
|
||||
<el-button
|
||||
v-auth="'machine:file:del'"
|
||||
type="danger"
|
||||
@click="deleteRow(scope.$index, scope.row)"
|
||||
icon="delete"
|
||||
size="small"
|
||||
plain
|
||||
>删除</el-button
|
||||
>
|
||||
<el-button v-if="scope.row.id == null" @click="addFiles(scope.row)" type="success"
|
||||
icon="success-filled" size="small" plain>确定</el-button>
|
||||
<el-button v-if="scope.row.id != null" @click="getConf(scope.row)" type="primary" icon="tickets"
|
||||
size="small" plain>查看</el-button>
|
||||
<el-button v-auth="'machine:file:del'" type="danger" @click="deleteRow(scope.$index, scope.row)"
|
||||
icon="delete" size="small" plain>删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-row style="margin-top: 10px" type="flex" justify="end">
|
||||
<el-pagination
|
||||
small
|
||||
style="text-align: center"
|
||||
:total="total"
|
||||
layout="prev, pager, next, total, jumper"
|
||||
v-model:current-page="query.pageNum"
|
||||
:page-size="query.pageSize"
|
||||
@current-change="handlePageChange"
|
||||
></el-pagination>
|
||||
<el-pagination small style="text-align: center" :total="total" layout="prev, pager, next, total, jumper"
|
||||
v-model:current-page="query.pageNum" :page-size="query.pageSize" @current-change="handlePageChange">
|
||||
</el-pagination>
|
||||
</el-row>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog :title="tree.title" v-model="tree.visible" :close-on-click-modal="false" width="680px">
|
||||
<el-progress
|
||||
v-if="uploadProgressShow"
|
||||
style="width: 90%; margin-left: 20px"
|
||||
:text-inside="true"
|
||||
:stroke-width="20"
|
||||
:percentage="progressNum"
|
||||
/>
|
||||
<el-dialog :title="tree.title" v-model="tree.visible" :close-on-click-modal="false" width="70%">
|
||||
<el-progress v-if="uploadProgressShow" style="width: 90%; margin-left: 20px" :text-inside="true"
|
||||
:stroke-width="20" :percentage="progressNum" />
|
||||
<div style="height: 45vh; overflow: auto">
|
||||
<el-tree v-if="tree.visible" ref="fileTree" :load="loadNode" :props="props" lazy node-key="id" :expand-on-click-node="true">
|
||||
<el-tree v-if="tree.visible" ref="fileTree" :highlight-current="true" :load="loadNode"
|
||||
:props="treeProps" lazy node-key="id" :expand-on-click-node="true">
|
||||
<template #default="{ node, data }">
|
||||
<span class="custom-tree-node">
|
||||
<el-dropdown size="small" @visible-change="getFilePath(data, $event)" trigger="contextmenu">
|
||||
@@ -81,39 +67,32 @@
|
||||
<SvgIcon name="document" />
|
||||
</span>
|
||||
|
||||
<span style="display: inline-block">
|
||||
<span>
|
||||
{{ node.label }}
|
||||
<span style="color: #67c23a" v-if="data.type == '-'"> [{{ formatFileSize(data.size) }}]</span>
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item
|
||||
@click="getFileContent(tree.folder.id, data.path)"
|
||||
v-if="data.type == '-' && data.size < 1 * 1024 * 1024"
|
||||
>
|
||||
<el-dropdown-item @click="getFileContent(tree.folder.id, data.path)"
|
||||
v-if="data.type == '-' && data.size < 1 * 1024 * 1024">
|
||||
<el-link type="info" icon="view" :underline="false">查看</el-link>
|
||||
</el-dropdown-item>
|
||||
|
||||
<span v-auth="'machine:file:write'">
|
||||
<el-dropdown-item @click="showCreateFileDialog(node, data)" v-if="data.type == 'd'">
|
||||
<el-link type="primary" icon="document" :underline="false" style="margin-left: 2px">新建</el-link>
|
||||
<el-dropdown-item @click="showCreateFileDialog(node)"
|
||||
v-if="data.type == 'd'">
|
||||
<el-link type="primary" icon="document" :underline="false"
|
||||
style="margin-left: 2px">新建</el-link>
|
||||
</el-dropdown-item>
|
||||
</span>
|
||||
|
||||
<span v-auth="'machine:file:upload'">
|
||||
<el-dropdown-item v-if="data.type == 'd'">
|
||||
<el-upload
|
||||
:before-upload="beforeUpload"
|
||||
:on-success="uploadSuccess"
|
||||
action=""
|
||||
:http-request="getUploadFile"
|
||||
:headers="{ token }"
|
||||
:show-file-list="false"
|
||||
name="file"
|
||||
style="display: inline-block; margin-left: 2px"
|
||||
>
|
||||
<el-upload :before-upload="beforeUpload" :on-success="uploadSuccess"
|
||||
action="" :http-request="getUploadFile" :headers="{ token }"
|
||||
:show-file-list="false" name="file"
|
||||
style="display: inline-block; margin-left: 2px">
|
||||
<el-link icon="upload" :underline="false">上传</el-link>
|
||||
</el-upload>
|
||||
</el-dropdown-item>
|
||||
@@ -121,33 +100,34 @@
|
||||
|
||||
<span v-auth="'machine:file:write'">
|
||||
<el-dropdown-item @click="downloadFile(node, data)" v-if="data.type == '-'">
|
||||
<el-link type="primary" icon="download" :underline="false" style="margin-left: 2px">下载</el-link>
|
||||
<el-link type="primary" icon="download" :underline="false"
|
||||
style="margin-left: 2px">下载</el-link>
|
||||
</el-dropdown-item>
|
||||
</span>
|
||||
|
||||
<span v-auth="'machine:file:rm'">
|
||||
<el-dropdown-item @click="deleteFile(node, data)" v-if="!dontOperate(data)">
|
||||
<el-link type="danger" icon="delete" :underline="false" style="margin-left: 2px">删除</el-link>
|
||||
<el-link type="danger" icon="delete" :underline="false"
|
||||
style="margin-left: 2px">删除</el-link>
|
||||
</el-dropdown-item>
|
||||
</span>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
<span style="display: inline-block" class="ml15">
|
||||
<span style="color: #67c23a" v-if="data.type == '-'">[{{ formatFileSize(data.size)
|
||||
}}]</span>
|
||||
<span v-if="data.mode" style="color: #67c23a"> [{{ data.mode }} {{ data.modTime
|
||||
}}]</span>
|
||||
</span>
|
||||
</span>
|
||||
</template>
|
||||
</el-tree>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
:destroy-on-close="true"
|
||||
title="新建文件"
|
||||
v-model="createFileDialog.visible"
|
||||
:before-close="closeCreateFileDialog"
|
||||
:close-on-click-modal="false"
|
||||
top="5vh"
|
||||
width="400px"
|
||||
>
|
||||
<el-dialog :destroy-on-close="true" title="新建文件" v-model="createFileDialog.visible"
|
||||
:before-close="closeCreateFileDialog" :close-on-click-modal="false" top="5vh" width="400px">
|
||||
<div>
|
||||
<el-form-item prop="name" label="名称:">
|
||||
<el-input v-model.trim="createFileDialog.name" placeholder="请输入名称" auto-complete="off"></el-input>
|
||||
@@ -161,23 +141,17 @@
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<div>
|
||||
<el-button @click="closeCreateFileDialog">关闭</el-button>
|
||||
<el-button v-auth="'machine:file:write'" type="primary" @click="createFile">确定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
:destroy-on-close="true"
|
||||
:title="fileContent.dialogTitle"
|
||||
v-model="fileContent.contentVisible"
|
||||
:close-on-click-modal="false"
|
||||
top="5vh"
|
||||
width="70%"
|
||||
>
|
||||
<el-dialog :destroy-on-close="true" :title="fileContent.dialogTitle" v-model="fileContent.contentVisible" :close-on-click-modal="false"
|
||||
top="5vh" width="70%">
|
||||
<div>
|
||||
<codemirror :can-change-mode="true" ref="cmEditor" v-model="fileContent.content" :language="fileContent.type" />
|
||||
<monaco-editor :can-change-mode="true" v-model="fileContent.content" :language="fileContent.type" />
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
@@ -190,29 +164,31 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { ref, toRefs, reactive, watch, defineComponent } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { ref, toRefs, reactive, watch } from 'vue';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import { machineApi } from './api';
|
||||
|
||||
import { codemirror } from '@/components/codemirror';
|
||||
import MonacoEditor from '@/components/monaco/MonacoEditor.vue';
|
||||
import { getSession } from '@/common/utils/storage';
|
||||
import enums from './enums';
|
||||
import config from '@/common/config';
|
||||
import { isTrue } from '@/common/assert';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'FileManage',
|
||||
components: {
|
||||
codemirror,
|
||||
},
|
||||
props: {
|
||||
const props = defineProps({
|
||||
visible: { type: Boolean },
|
||||
machineId: { type: Number },
|
||||
title: { type: String },
|
||||
},
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'update:machineId'])
|
||||
|
||||
const treeProps = {
|
||||
label: 'name',
|
||||
children: 'zones',
|
||||
isLeaf: 'leaf',
|
||||
}
|
||||
|
||||
setup(props: any, { emit }) {
|
||||
const addFile = machineApi.addConf;
|
||||
const delFile = machineApi.delConf;
|
||||
const updateFileContent = machineApi.updateFileContent;
|
||||
@@ -256,18 +232,13 @@ export default defineComponent({
|
||||
},
|
||||
resolve: {},
|
||||
},
|
||||
props: {
|
||||
label: 'name',
|
||||
children: 'zones',
|
||||
isLeaf: 'leaf',
|
||||
},
|
||||
progressNum: 0,
|
||||
uploadProgressShow: false,
|
||||
dataObj: {
|
||||
name: '',
|
||||
path: '',
|
||||
type: '',
|
||||
},
|
||||
progressNum: 0,
|
||||
uploadProgressShow: false,
|
||||
createFileDialog: {
|
||||
visible: false,
|
||||
name: '',
|
||||
@@ -277,15 +248,27 @@ export default defineComponent({
|
||||
file: null as any,
|
||||
});
|
||||
|
||||
watch(props, (newValue) => {
|
||||
if (newValue.machineId) {
|
||||
getFiles();
|
||||
const {
|
||||
dialogVisible,
|
||||
query,
|
||||
total,
|
||||
fileTable,
|
||||
fileContent,
|
||||
tree,
|
||||
progressNum,
|
||||
uploadProgressShow,
|
||||
createFileDialog,
|
||||
} = toRefs(state)
|
||||
|
||||
watch(props, async (newValue) => {
|
||||
if (newValue.machineId && newValue.visible) {
|
||||
await getFiles();
|
||||
}
|
||||
state.dialogVisible = newValue.visible;
|
||||
});
|
||||
|
||||
const getFiles = async () => {
|
||||
state.query.id = props.machineId;
|
||||
state.query.id = props.machineId as any;
|
||||
const res = await files.request(state.query);
|
||||
state.fileTable = res.list;
|
||||
state.total = res.total;
|
||||
@@ -359,14 +342,17 @@ export default defineComponent({
|
||||
if (path.endsWith('.sh')) {
|
||||
return 'shell';
|
||||
}
|
||||
if (path.endsWith('js') || path.endsWith('json')) {
|
||||
if (path.endsWith('js')) {
|
||||
return 'javascript';
|
||||
}
|
||||
if (path.endsWith('json')) {
|
||||
return 'json';
|
||||
}
|
||||
if (path.endsWith('Dockerfile')) {
|
||||
return 'dockerfile';
|
||||
}
|
||||
if (path.endsWith('nginx.conf')) {
|
||||
return 'nginx';
|
||||
return 'shell';
|
||||
}
|
||||
if (path.endsWith('sql')) {
|
||||
return 'sql';
|
||||
@@ -524,7 +510,7 @@ export default defineComponent({
|
||||
const params = new FormData();
|
||||
params.append('file', content.file);
|
||||
params.append('path', state.dataObj.path);
|
||||
params.append('machineId', props.machineId);
|
||||
params.append('machineId', props.machineId as any);
|
||||
params.append('fileId', state.tree.folder.id as any);
|
||||
params.append('token', token);
|
||||
machineApi.uploadFile
|
||||
@@ -603,36 +589,7 @@ export default defineComponent({
|
||||
}
|
||||
return '-';
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
fileTree,
|
||||
enums,
|
||||
token,
|
||||
add,
|
||||
getFiles,
|
||||
handlePageChange,
|
||||
addFiles,
|
||||
deleteRow,
|
||||
getConf,
|
||||
getFileContent,
|
||||
updateContent,
|
||||
handleClose,
|
||||
loadNode,
|
||||
showCreateFileDialog,
|
||||
closeCreateFileDialog,
|
||||
createFile,
|
||||
deleteFile,
|
||||
downloadFile,
|
||||
getUploadFile,
|
||||
beforeUpload,
|
||||
getFilePath,
|
||||
uploadSuccess,
|
||||
dontOperate,
|
||||
formatFileSize,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
||||
@@ -1,36 +1,72 @@
|
||||
<template>
|
||||
<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-item prop="projectId" label="项目:" required>
|
||||
<el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
|
||||
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
</el-select>
|
||||
<el-form-item prop="tagId" label="标签:" required>
|
||||
<tag-select v-model:tag-id="form.tagId" v-model:tag-path="form.tagPath" style="width: 100%" />
|
||||
</el-form-item>
|
||||
<el-form-item prop="name" label="名称:" required>
|
||||
<el-input v-model.trim="form.name" placeholder="请输入机器别名" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="ip" label="ip:" required>
|
||||
<el-input v-model.trim="form.ip" placeholder="请输入主机ip" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="port" label="port:" required>
|
||||
<el-input type="number" v-model.number="form.port" placeholder="请输入端口"></el-input>
|
||||
<el-col :span="18">
|
||||
<el-input :disabled="form.id" v-model.trim="form.ip" placeholder="主机ip" auto-complete="off">
|
||||
</el-input>
|
||||
</el-col>
|
||||
<el-col style="text-align: center" :span="1">:</el-col>
|
||||
<el-col :span="5">
|
||||
<el-input type="number" v-model.number="form.port" placeholder="端口"></el-input>
|
||||
</el-col>
|
||||
</el-form-item>
|
||||
<el-form-item prop="username" label="用户名:" required>
|
||||
<el-input v-model.trim="form.username" placeholder="请输入用户名"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password" label="密码:">
|
||||
<el-input
|
||||
type="password"
|
||||
show-password
|
||||
v-model.trim="form.password"
|
||||
placeholder="请输入密码,修改操作可不填"
|
||||
autocomplete="new-password"
|
||||
></el-input>
|
||||
<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 type="password" show-password v-model.trim="form.password" placeholder="请输入密码,修改操作可不填"
|
||||
autocomplete="new-password">
|
||||
<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 prop="remark" label="备注:">
|
||||
<el-input type="textarea" v-model="form.remark"></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="enableRecorder" label="终端回放:">
|
||||
<el-checkbox v-model="form.enableRecorder" :true-label="1" :false-label="-1"></el-checkbox>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="enableSshTunnel" label="SSH隧道:">
|
||||
<el-col :span="3">
|
||||
<el-checkbox @change="getSshTunnelMachines" v-model="form.enableSshTunnel" :true-label="1"
|
||||
:false-label="-1"></el-checkbox>
|
||||
</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>
|
||||
|
||||
<template #footer>
|
||||
@@ -43,15 +79,15 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, reactive, watch, ref } from 'vue';
|
||||
import { machineApi } from './api';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { notBlank } from '@/common/assert';
|
||||
import { RsaEncrypt } from '@/common/rsa';
|
||||
import TagSelect from '../component/TagSelect.vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'MachineEdit',
|
||||
props: {
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -64,35 +100,16 @@ export default defineComponent({
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
const machineForm: any = ref(null);
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
projects: [],
|
||||
form: {
|
||||
id: null,
|
||||
projectId: null,
|
||||
projectName: null,
|
||||
name: null,
|
||||
port: 22,
|
||||
username: null,
|
||||
password: null,
|
||||
remark: '',
|
||||
},
|
||||
btnLoading: false,
|
||||
rules: {
|
||||
projectId: [
|
||||
})
|
||||
|
||||
//定义事件
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'val-change'])
|
||||
|
||||
const rules = {
|
||||
tagId: [
|
||||
{
|
||||
required: true,
|
||||
message: '请选择项目',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
envId: [
|
||||
{
|
||||
required: true,
|
||||
message: '请选择环境',
|
||||
message: '请选择标签',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
@@ -106,14 +123,7 @@ export default defineComponent({
|
||||
ip: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入主机ip',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
port: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入端口',
|
||||
message: '请输入主机ip和端口',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
@@ -124,43 +134,102 @@ export default defineComponent({
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
authMethod: [
|
||||
{
|
||||
required: true,
|
||||
message: '请选择认证方式',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const machineForm: any = ref(null);
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
sshTunnelMachineList: [] as any,
|
||||
form: {
|
||||
id: null,
|
||||
tagId: null as any,
|
||||
tagPath: '',
|
||||
ip: null,
|
||||
name: null,
|
||||
authMethod: 1,
|
||||
port: 22,
|
||||
username: '',
|
||||
password: '',
|
||||
remark: '',
|
||||
enableSshTunnel: null,
|
||||
sshTunnelMachineId: null,
|
||||
enableRecorder: -1,
|
||||
},
|
||||
pwd: '',
|
||||
btnLoading: false,
|
||||
});
|
||||
|
||||
watch(props, async (newValue) => {
|
||||
const {
|
||||
dialogVisible,
|
||||
sshTunnelMachineList,
|
||||
form,
|
||||
pwd,
|
||||
btnLoading,
|
||||
} = toRefs(state)
|
||||
|
||||
watch(props, async (newValue: any) => {
|
||||
state.dialogVisible = newValue.visible;
|
||||
state.projects = newValue.projects;
|
||||
if (!state.dialogVisible) {
|
||||
return;
|
||||
}
|
||||
if (newValue.machine) {
|
||||
state.form = { ...newValue.machine };
|
||||
} else {
|
||||
state.form = { port: 22 } as any;
|
||||
state.form = { port: 22, authMethod: 1 } as any;
|
||||
}
|
||||
getSshTunnelMachines();
|
||||
});
|
||||
|
||||
const changeProject = (projectId: number) => {
|
||||
for (let p of state.projects as any) {
|
||||
if (p.id == projectId) {
|
||||
state.form.projectName = p.name;
|
||||
}
|
||||
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) => {
|
||||
notBlank(machineId, '请选择或先创建一台隧道机器');
|
||||
return state.sshTunnelMachineList.find((x: any) => x.id == machineId);
|
||||
};
|
||||
|
||||
const getPwd = async () => {
|
||||
state.pwd = await machineApi.getMachinePwd.request({ id: state.form.id });
|
||||
};
|
||||
|
||||
const btnOk = async () => {
|
||||
if (!state.form.id) {
|
||||
notBlank(state.form.password, '新增操作,密码不可为空');
|
||||
}
|
||||
machineForm.value.validate((valid: boolean) => {
|
||||
machineForm.value.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
machineApi.saveMachine.request(state.form).then(() => {
|
||||
const 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('保存成功');
|
||||
emit('val-change', state.form);
|
||||
state.btnLoading = true;
|
||||
setTimeout(() => {
|
||||
state.btnLoading = false;
|
||||
}, 1000);
|
||||
|
||||
cancel();
|
||||
});
|
||||
} finally {
|
||||
state.btnLoading = false;
|
||||
}
|
||||
} else {
|
||||
ElMessage.error('请正确填写信息');
|
||||
return false;
|
||||
@@ -172,16 +241,7 @@ export default defineComponent({
|
||||
emit('update:visible', false);
|
||||
emit('cancel');
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
machineForm,
|
||||
changeProject,
|
||||
btnOk,
|
||||
cancel,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
||||
|
||||
@@ -2,33 +2,21 @@
|
||||
<div>
|
||||
<el-card>
|
||||
<div>
|
||||
<el-button v-auth="'machine:add'" type="primary" icon="plus" @click="openFormDialog(false)" plain>添加</el-button>
|
||||
<el-button
|
||||
v-auth="'machine:update'"
|
||||
type="primary"
|
||||
icon="edit"
|
||||
:disabled="currentId == null"
|
||||
@click="openFormDialog(currentData)"
|
||||
plain
|
||||
>编辑</el-button
|
||||
>
|
||||
<el-button v-auth="'machine:del'" :disabled="currentId == null" @click="deleteMachine(currentId)" type="danger" icon="delete"
|
||||
>删除</el-button
|
||||
>
|
||||
<el-button v-auth="'machine:add'" type="primary" icon="plus" @click="openFormDialog(false)" plain>添加
|
||||
</el-button>
|
||||
<el-button v-auth="'machine:update'" type="primary" icon="edit" :disabled="!currentId"
|
||||
@click="openFormDialog(currentData)" plain>编辑</el-button>
|
||||
<el-button v-auth="'machine:del'" :disabled="!currentId" @click="deleteMachine(currentId)" type="danger"
|
||||
icon="delete">删除</el-button>
|
||||
<div style="float: right">
|
||||
<el-select v-model="params.projectId" placeholder="请选择项目" @clear="search" filterable clearable>
|
||||
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
<el-select @focus="getTags" v-model="params.tagPath" placeholder="请选择标签" @clear="search" filterable
|
||||
clearable>
|
||||
<el-option v-for="item in tags" :key="item" :label="item" :value="item"> </el-option>
|
||||
</el-select>
|
||||
<el-input
|
||||
class="ml5"
|
||||
placeholder="请输入名称"
|
||||
style="width: 150px"
|
||||
v-model="params.name"
|
||||
@clear="search"
|
||||
plain
|
||||
clearable
|
||||
></el-input>
|
||||
<el-input class="ml5" placeholder="请输入ip" style="width: 150px" v-model="params.ip" @clear="search" plain clearable></el-input>
|
||||
<el-input class="ml5" placeholder="请输入名称" style="width: 150px" v-model="params.name" @clear="search"
|
||||
plain clearable></el-input>
|
||||
<el-input class="ml5" placeholder="请输入ip" style="width: 150px" v-model="params.ip" @clear="search"
|
||||
plain clearable></el-input>
|
||||
<el-button class="ml5" @click="search" type="success" icon="search"></el-button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -41,167 +29,175 @@
|
||||
</el-radio>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="tagPath" label="标签路径" min-width="150" 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">
|
||||
<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}`
|
||||
}}</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="status" label="状态" min-width="75">
|
||||
<el-table-column prop="status" label="状态" min-width="80">
|
||||
<template #default="scope">
|
||||
<el-switch
|
||||
v-auth:disabled="'machine:update'"
|
||||
:width="47"
|
||||
v-model="scope.row.status"
|
||||
:active-value="1"
|
||||
:inactive-value="-1"
|
||||
inline-prompt
|
||||
active-text="启用"
|
||||
inactive-text="停用"
|
||||
<el-switch v-auth:disabled="'machine:update'" :width="52" v-model="scope.row.status"
|
||||
:active-value="1" :inactive-value="-1" inline-prompt active-text="启用" inactive-text="停用"
|
||||
style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
|
||||
@change="changeStatus(scope.row)"
|
||||
></el-switch>
|
||||
@change="changeStatus(scope.row)"></el-switch>
|
||||
</template>
|
||||
</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="remark" label="备注" min-width="250" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="ip" label="hasCli" width="70">
|
||||
|
||||
<el-table-column label="操作" min-width="235" fixed="right">
|
||||
<template #default="scope">
|
||||
{{ `${scope.row.hasCli ? '是' : '否'}` }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="createTime" label="创建时间" min-width="165">
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="creator" label="创建者" min-width="80"></el-table-column>
|
||||
<el-table-column label="操作" min-width="280" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-link
|
||||
v-auth="'machine:terminal'"
|
||||
:disabled="scope.row.status == -1"
|
||||
type="primary"
|
||||
@click="showTerminal(scope.row)"
|
||||
plain
|
||||
size="small"
|
||||
:underline="false"
|
||||
>终端</el-link
|
||||
>
|
||||
<el-divider v-auth="'machine:terminal'" direction="vertical" border-style="dashed" />
|
||||
<el-link
|
||||
v-auth="'machine:file'"
|
||||
type="success"
|
||||
:disabled="scope.row.status == -1"
|
||||
@click="fileManage(scope.row)"
|
||||
plain
|
||||
size="small"
|
||||
:underline="false"
|
||||
>文件</el-link
|
||||
>
|
||||
<el-divider v-auth="'machine:file'" direction="vertical" border-style="dashed" />
|
||||
<el-link
|
||||
:disabled="scope.row.status == -1"
|
||||
type="warning"
|
||||
@click="serviceManager(scope.row)"
|
||||
plain
|
||||
size="small"
|
||||
:underline="false"
|
||||
>脚本</el-link
|
||||
>
|
||||
<span v-auth="'machine:terminal'">
|
||||
<el-link :disabled="scope.row.status == -1" type="primary" @click="showTerminal(scope.row)"
|
||||
plain size="small" :underline="false">终端</el-link>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
<el-link @click="showProcess(scope.row)" :disabled="scope.row.status == -1" plain :underline="false" size="small"
|
||||
>进程</el-link
|
||||
>
|
||||
</span>
|
||||
|
||||
<span v-auth="'machine:file'">
|
||||
<el-link type="success" :disabled="scope.row.status == -1"
|
||||
@click="showFileManage(scope.row)" plain size="small" :underline="false">文件</el-link>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
<el-link
|
||||
:disabled="!scope.row.hasCli || scope.row.status == -1"
|
||||
type="danger"
|
||||
@click="closeCli(scope.row)"
|
||||
plain
|
||||
size="small"
|
||||
:underline="false"
|
||||
>关闭连接</el-link
|
||||
>
|
||||
</span>
|
||||
|
||||
<el-link :disabled="scope.row.status == -1" type="warning" @click="serviceManager(scope.row)"
|
||||
plain size="small" :underline="false">脚本</el-link>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
|
||||
<el-dropdown>
|
||||
<span class="el-dropdown-link-machine-list">
|
||||
更多
|
||||
<el-icon class="el-icon--right">
|
||||
<arrow-down />
|
||||
</el-icon>
|
||||
</span>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item>
|
||||
<el-link @click="showInfo(scope.row)" plain :underline="false" size="small">详情
|
||||
</el-link>
|
||||
</el-dropdown-item>
|
||||
|
||||
<el-dropdown-item>
|
||||
<el-link @click="showProcess(scope.row)" :disabled="scope.row.status == -1"
|
||||
plain :underline="false" size="small">进程</el-link>
|
||||
</el-dropdown-item>
|
||||
|
||||
<el-dropdown-item v-if="scope.row.enableRecorder == 1">
|
||||
<el-link v-auth="'machine:update'" @click="showRec(scope.row)" plain
|
||||
:underline="false" size="small">终端回放</el-link>
|
||||
</el-dropdown-item>
|
||||
|
||||
<el-dropdown-item>
|
||||
<el-link :disabled="!scope.row.hasCli || scope.row.status == -1" type="danger"
|
||||
@click="closeCli(scope.row)" plain size="small" :underline="false">关闭连接
|
||||
</el-link>
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-row style="margin-top: 20px" type="flex" justify="end">
|
||||
<el-pagination
|
||||
style="text-align: right"
|
||||
:total="data.total"
|
||||
layout="prev, pager, next, total, jumper"
|
||||
v-model:current-page="params.pageNum"
|
||||
:page-size="params.pageSize"
|
||||
@current-change="handlePageChange"
|
||||
></el-pagination>
|
||||
<el-pagination style="text-align: right" :total="data.total" layout="prev, pager, next, total, jumper"
|
||||
v-model:current-page="params.pageNum" :page-size="params.pageSize"
|
||||
@current-change="handlePageChange"></el-pagination>
|
||||
</el-row>
|
||||
</el-card>
|
||||
|
||||
<machine-edit
|
||||
:title="machineEditDialog.title"
|
||||
:projects="projects"
|
||||
v-model:visible="machineEditDialog.visible"
|
||||
v-model:machine="machineEditDialog.data"
|
||||
@valChange="submitSuccess"
|
||||
></machine-edit>
|
||||
<el-dialog v-model="infoDialog.visible">
|
||||
<el-descriptions title="详情" :column="3" border>
|
||||
<el-descriptions-item :span="1.5" label="机器id">{{ infoDialog.data.id }}</el-descriptions-item>
|
||||
<el-descriptions-item :span="1.5" label="名称">{{ infoDialog.data.name }}</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item :span="3" label="标签路径">{{ infoDialog.data.tagPath }}</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item :span="2" label="IP">{{ infoDialog.data.ip }}</el-descriptions-item>
|
||||
<el-descriptions-item :span="1" label="端口">{{ infoDialog.data.port }}</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item :span="2" label="用户名">{{ infoDialog.data.username }}</el-descriptions-item>
|
||||
<el-descriptions-item :span="1" label="认证方式">{{ infoDialog.data.authMethod == 1 ? 'Password' :
|
||||
'PublicKey'
|
||||
}}</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item :span="3" label="备注">{{ infoDialog.data.remark }}</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item :span="1.5" label="SSH隧道">{{ infoDialog.data.enableSshTunnel == 1 ? '是' : '否' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item :span="1.5" label="终端回放">{{ infoDialog.data.enableRecorder == 1 ? '是' : '否' }}
|
||||
</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item :span="2" label="创建时间">{{ dateFormat(infoDialog.data.createTime) }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item :span="1" label="创建者">{{ infoDialog.data.creator }}</el-descriptions-item>
|
||||
|
||||
|
||||
<el-descriptions-item :span="2" label="更新时间">{{ dateFormat(infoDialog.data.updateTime) }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item :span="1" label="修改者">{{ infoDialog.data.modifier }}</el-descriptions-item>
|
||||
|
||||
</el-descriptions>
|
||||
</el-dialog>
|
||||
|
||||
<machine-edit :title="machineEditDialog.title" v-model:visible="machineEditDialog.visible"
|
||||
v-model:machine="machineEditDialog.data" @valChange="submitSuccess"></machine-edit>
|
||||
|
||||
<process-list v-model:visible="processDialog.visible" v-model:machineId="processDialog.machineId" />
|
||||
|
||||
<service-manage :title="serviceDialog.title" v-model:visible="serviceDialog.visible" v-model:machineId="serviceDialog.machineId" />
|
||||
<service-manage :title="serviceDialog.title" v-model:visible="serviceDialog.visible"
|
||||
v-model:machineId="serviceDialog.machineId" />
|
||||
|
||||
<file-manage :title="fileDialog.title" v-model:visible="fileDialog.visible" v-model:machineId="fileDialog.machineId" />
|
||||
<file-manage :title="fileDialog.title" v-model:visible="fileDialog.visible"
|
||||
v-model:machineId="fileDialog.machineId" />
|
||||
|
||||
<machine-stats
|
||||
v-model:visible="machineStatsDialog.visible"
|
||||
:machineId="machineStatsDialog.machineId"
|
||||
:title="machineStatsDialog.title"
|
||||
></machine-stats>
|
||||
<machine-stats v-model:visible="machineStatsDialog.visible" :machineId="machineStatsDialog.machineId"
|
||||
:title="machineStatsDialog.title"></machine-stats>
|
||||
|
||||
<machine-rec v-model:visible="machineRecDialog.visible" :machineId="machineRecDialog.machineId"
|
||||
:title="machineRecDialog.title"></machine-rec>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, onMounted, defineComponent } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, reactive, onMounted } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import { machineApi } from './api';
|
||||
import { projectApi } from '../project/api.ts';
|
||||
import { tagApi } from '../tag/api.ts';
|
||||
import ServiceManage from './ServiceManage.vue';
|
||||
import FileManage from './FileManage.vue';
|
||||
import MachineEdit from './MachineEdit.vue';
|
||||
import ProcessList from './ProcessList.vue';
|
||||
import MachineStats from './MachineStats.vue';
|
||||
import MachineRec from './MachineRec.vue';
|
||||
import { dateFormat } from '@/common/utils/date';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'MachineList',
|
||||
components: {
|
||||
ServiceManage,
|
||||
ProcessList,
|
||||
FileManage,
|
||||
MachineEdit,
|
||||
MachineStats,
|
||||
},
|
||||
setup() {
|
||||
const router = useRouter();
|
||||
const state = reactive({
|
||||
projects: [],
|
||||
stats: '',
|
||||
tags: [] as any,
|
||||
params: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
ip: null,
|
||||
name: null,
|
||||
tagPath: null,
|
||||
},
|
||||
// 列表数据
|
||||
data: {
|
||||
list: [],
|
||||
total: 10,
|
||||
},
|
||||
infoDialog: {
|
||||
visible: false,
|
||||
data: null as any,
|
||||
},
|
||||
// 当前选中数据id
|
||||
currentId: null,
|
||||
currentId: 0,
|
||||
currentData: null,
|
||||
serviceDialog: {
|
||||
visible: false,
|
||||
@@ -225,14 +221,33 @@ export default defineComponent({
|
||||
},
|
||||
machineEditDialog: {
|
||||
visible: false,
|
||||
data: null,
|
||||
data: null as any,
|
||||
title: '新增机器',
|
||||
},
|
||||
machineRecDialog: {
|
||||
visible: false,
|
||||
machineId: 0,
|
||||
title: '',
|
||||
},
|
||||
});
|
||||
|
||||
const {
|
||||
tags,
|
||||
params,
|
||||
data,
|
||||
infoDialog,
|
||||
currentId,
|
||||
currentData,
|
||||
serviceDialog,
|
||||
processDialog,
|
||||
fileDialog,
|
||||
machineStatsDialog,
|
||||
machineEditDialog,
|
||||
machineRecDialog,
|
||||
} = toRefs(state)
|
||||
|
||||
onMounted(async () => {
|
||||
search();
|
||||
state.projects = await projectApi.accountProjects.request(null);
|
||||
});
|
||||
|
||||
const choose = (item: any) => {
|
||||
@@ -255,18 +270,27 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const closeCli = async (row: any) => {
|
||||
await ElMessageBox.confirm(`确定关闭该机器客户端连接?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
});
|
||||
await machineApi.closeCli.request({ id: row.id });
|
||||
ElMessage.success('关闭成功');
|
||||
search();
|
||||
};
|
||||
|
||||
const openFormDialog = (redis: any) => {
|
||||
const getTags = async () => {
|
||||
state.tags = await tagApi.getAccountTags.request(null);
|
||||
};
|
||||
|
||||
const openFormDialog = async (machine: any) => {
|
||||
let dialogTitle;
|
||||
if (redis) {
|
||||
if (machine) {
|
||||
state.machineEditDialog.data = state.currentData as any;
|
||||
dialogTitle = '编辑机器';
|
||||
} else {
|
||||
state.machineEditDialog.data = { port: 22 } as any;
|
||||
state.machineEditDialog.data = null;
|
||||
dialogTitle = '添加机器';
|
||||
}
|
||||
|
||||
@@ -283,7 +307,7 @@ export default defineComponent({
|
||||
});
|
||||
await machineApi.del.request({ id });
|
||||
ElMessage.success('操作成功');
|
||||
state.currentId = null;
|
||||
state.currentId = 0;
|
||||
state.currentData = null;
|
||||
search();
|
||||
} catch (err) { }
|
||||
@@ -312,12 +336,12 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const submitSuccess = () => {
|
||||
state.currentId = null;
|
||||
state.currentId = 0;
|
||||
state.currentData = null;
|
||||
search();
|
||||
};
|
||||
|
||||
const fileManage = (currentData: any) => {
|
||||
const showFileManage = (currentData: any) => {
|
||||
state.fileDialog.visible = true;
|
||||
state.fileDialog.machineId = currentData.id;
|
||||
state.fileDialog.title = `${currentData.name} => ${currentData.ip}`;
|
||||
@@ -333,33 +357,33 @@ export default defineComponent({
|
||||
search();
|
||||
};
|
||||
|
||||
const showInfo = (info: any) => {
|
||||
state.infoDialog.data = info;
|
||||
state.infoDialog.visible = true;
|
||||
}
|
||||
|
||||
const showProcess = (row: any) => {
|
||||
state.processDialog.machineId = row.id;
|
||||
state.processDialog.visible = true;
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
choose,
|
||||
showTerminal,
|
||||
openFormDialog,
|
||||
deleteMachine,
|
||||
closeCli,
|
||||
serviceManager,
|
||||
showMachineStats,
|
||||
showProcess,
|
||||
changeStatus,
|
||||
submitSuccess,
|
||||
fileManage,
|
||||
search,
|
||||
handlePageChange,
|
||||
const showRec = (row: any) => {
|
||||
state.machineRecDialog.title = `${row.name}[${row.ip}]-终端回放记录`;
|
||||
state.machineRecDialog.machineId = row.id;
|
||||
state.machineRecDialog.visible = true;
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.el-dialog__body {
|
||||
padding: 2px 2px;
|
||||
}
|
||||
|
||||
.el-dropdown-link-machine-list {
|
||||
cursor: pointer;
|
||||
color: var(--el-color-primary);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-top: 6px;
|
||||
}
|
||||
</style>
|
||||
|
||||
130
mayfly_go_web/src/views/ops/machine/MachineRec.vue
Normal file
130
mayfly_go_web/src/views/ops/machine/MachineRec.vue
Normal file
@@ -0,0 +1,130 @@
|
||||
<template>
|
||||
<div id="terminalRecDialog">
|
||||
<el-dialog :title="title" v-model="dialogVisible" :before-close="handleClose" :close-on-click-modal="false"
|
||||
:destroy-on-close="true" width="70%">
|
||||
<div class="toolbar">
|
||||
<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[空格键]: 暂停/播放
|
||||
</div>
|
||||
<div ref="playerRef" id="rc-player"></div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, watch, ref, reactive } from 'vue';
|
||||
import { machineApi } from './api';
|
||||
import * as AsciinemaPlayer from 'asciinema-player';
|
||||
import 'asciinema-player/dist/bundle/asciinema-player.css';
|
||||
|
||||
const props = defineProps({
|
||||
visible: { type: Boolean },
|
||||
machineId: { type: Number },
|
||||
title: { type: String },
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'update:machineId'])
|
||||
|
||||
const playerRef = ref(null);
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
title: '',
|
||||
machineId: 0,
|
||||
operateDates: [],
|
||||
users: [],
|
||||
recs: [],
|
||||
operateDate: '',
|
||||
user: '',
|
||||
rec: '',
|
||||
});
|
||||
|
||||
const {
|
||||
dialogVisible,
|
||||
title,
|
||||
operateDates,
|
||||
operateDate,
|
||||
users,
|
||||
recs,
|
||||
user,
|
||||
rec,
|
||||
} = toRefs(state)
|
||||
|
||||
watch(props, async (newValue: any) => {
|
||||
const visible = newValue.visible;
|
||||
if (visible) {
|
||||
state.machineId = newValue.machineId;
|
||||
state.title = newValue.title;
|
||||
await getOperateDate();
|
||||
}
|
||||
state.dialogVisible = visible;
|
||||
});
|
||||
|
||||
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 = () => {
|
||||
emit('update:visible', false);
|
||||
emit('update:machineId', null);
|
||||
emit('cancel');
|
||||
state.operateDates = [];
|
||||
state.users = [];
|
||||
state.recs = [];
|
||||
state.operateDate = '';
|
||||
state.user = '';
|
||||
state.rec = '';
|
||||
};
|
||||
</script>
|
||||
<style lang="scss">
|
||||
#terminalRecDialog {
|
||||
.el-overlay .el-overlay-dialog .el-dialog .el-dialog__body {
|
||||
padding: 0px !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,6 +1,7 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-dialog :title="title" v-model="dialogVisible" :close-on-click-modal="true" :destroy-on-close="true" :before-close="cancel" width="1050px">
|
||||
<el-dialog :title="title" v-model="dialogVisible" :close-on-click-modal="true" :destroy-on-close="true"
|
||||
:before-close="cancel" width="1050px">
|
||||
<el-row :gutter="20">
|
||||
<el-col :lg="12" :md="12">
|
||||
<el-descriptions size="small" title="基础信息" :column="2" border>
|
||||
@@ -19,7 +20,8 @@
|
||||
<el-descriptions-item label="运行中任务">
|
||||
{{ stats.RunningProcs }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="负载"> {{ stats.Load1 }} {{ stats.Load5 }} {{ stats.Load10 }} </el-descriptions-item>
|
||||
<el-descriptions-item label="负载"> {{ stats.Load1 }} {{ stats.Load5 }} {{ stats.Load10 }}
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</el-col>
|
||||
|
||||
@@ -36,7 +38,8 @@
|
||||
<el-col :lg="8" :md="8">
|
||||
<span style="font-size: 16px; font-weight: 700">磁盘</span>
|
||||
<el-table :data="stats.FSInfos" stripe max-height="250" style="width: 100%" border>
|
||||
<el-table-column prop="MountPoint" label="挂载点" min-width="100" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="MountPoint" label="挂载点" min-width="100" show-overflow-tooltip>
|
||||
</el-table-column>
|
||||
<el-table-column prop="Used" label="可使用" min-width="70" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
{{ formatByteSize(scope.row.Free) }}
|
||||
@@ -54,8 +57,10 @@
|
||||
<span style="font-size: 16px; font-weight: 700">网卡</span>
|
||||
<el-table :data="netInter" stripe max-height="250" style="width: 100%" border>
|
||||
<el-table-column prop="name" label="网卡" min-width="120" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="IPv4" label="IPv4" min-width="130" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="IPv6" label="IPv6" min-width="130" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="IPv4" label="IPv4" min-width="130" show-overflow-tooltip>
|
||||
</el-table-column>
|
||||
<el-table-column prop="IPv6" label="IPv6" min-width="130" show-overflow-tooltip>
|
||||
</el-table-column>
|
||||
<el-table-column prop="Rx" label="接收(rx)" min-width="110" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
{{ formatByteSize(scope.row.Rx) }}
|
||||
@@ -73,17 +78,14 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, watch, defineComponent, ref, nextTick } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, reactive, watch, ref, nextTick } from 'vue';
|
||||
import useEcharts from '@/common/echarts/useEcharts.ts';
|
||||
import tdTheme from '@/common/echarts/theme.json';
|
||||
import { formatByteSize } from '@/common/utils/format';
|
||||
import { machineApi } from './api';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'MachineStats',
|
||||
components: {},
|
||||
props: {
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -96,8 +98,10 @@ export default defineComponent({
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'update:machineId'])
|
||||
|
||||
const cpuRef: any = ref();
|
||||
const memRef: any = ref();
|
||||
|
||||
@@ -106,12 +110,19 @@ export default defineComponent({
|
||||
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
charts: [] as any,
|
||||
stats: {} as any,
|
||||
netInter: [] as any,
|
||||
});
|
||||
|
||||
watch(props, async (newValue) => {
|
||||
const {
|
||||
dialogVisible,
|
||||
stats,
|
||||
netInter,
|
||||
} = toRefs(state)
|
||||
|
||||
let charts = [] as any
|
||||
|
||||
watch(props, async (newValue: any) => {
|
||||
const visible = newValue.visible;
|
||||
if (visible) {
|
||||
await setStats();
|
||||
@@ -186,7 +197,7 @@ export default defineComponent({
|
||||
}
|
||||
const chart: any = useEcharts(memRef.value, tdTheme, option);
|
||||
memChart = chart;
|
||||
state.charts.push(chart);
|
||||
charts.push(chart);
|
||||
};
|
||||
|
||||
const initCpuStats = () => {
|
||||
@@ -253,7 +264,7 @@ export default defineComponent({
|
||||
}
|
||||
const chart: any = useEcharts(cpuRef.value, tdTheme, option);
|
||||
cpuChart = chart;
|
||||
state.charts.push(chart);
|
||||
charts.push(chart);
|
||||
};
|
||||
|
||||
const initCharts = () => {
|
||||
@@ -267,9 +278,9 @@ export default defineComponent({
|
||||
|
||||
const initEchartResizeFun = () => {
|
||||
nextTick(() => {
|
||||
for (let i = 0; i < state.charts.length; i++) {
|
||||
for (let i = 0; i < charts.length; i++) {
|
||||
setTimeout(() => {
|
||||
state.charts[i].resize();
|
||||
charts[i].resize();
|
||||
}, i * 1000);
|
||||
}
|
||||
});
|
||||
@@ -301,17 +312,6 @@ export default defineComponent({
|
||||
memChart = null;
|
||||
}, 200);
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
cpuRef,
|
||||
memRef,
|
||||
cancel,
|
||||
formatByteSize,
|
||||
onRefresh,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
.card-item-chart {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<template>
|
||||
<div class="file-manage">
|
||||
<el-dialog title="进程信息" v-model="dialogVisible" :destroy-on-close="true" :show-close="true" :before-close="handleClose" width="65%">
|
||||
<el-dialog title="进程信息" v-model="dialogVisible" :destroy-on-close="true" :show-close="true"
|
||||
:before-close="handleClose" width="65%">
|
||||
<div class="toolbar">
|
||||
<el-row>
|
||||
<el-col :span="4">
|
||||
@@ -21,7 +22,8 @@
|
||||
</el-select>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-button class="ml5" @click="getProcess" type="primary" icon="tickets" size="small" plain>刷新</el-button>
|
||||
<el-button class="ml5" @click="getProcess" type="primary" icon="tickets" size="small" plain>刷新
|
||||
</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
@@ -35,7 +37,9 @@
|
||||
<template #header>
|
||||
VSZ
|
||||
<el-tooltip class="box-item" effect="dark" content="虚拟内存" placement="top">
|
||||
<el-icon><question-filled /></el-icon>
|
||||
<el-icon>
|
||||
<question-filled />
|
||||
</el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -43,7 +47,9 @@
|
||||
<template #header>
|
||||
RSS
|
||||
<el-tooltip class="box-item" effect="dark" content="固定内存" placement="top">
|
||||
<el-icon><question-filled /></el-icon>
|
||||
<el-icon>
|
||||
<question-filled />
|
||||
</el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -51,7 +57,9 @@
|
||||
<template #header>
|
||||
STAT
|
||||
<el-tooltip class="box-item" effect="dark" content="进程状态" placement="top">
|
||||
<el-icon><question-filled /></el-icon>
|
||||
<el-icon>
|
||||
<question-filled />
|
||||
</el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -59,7 +67,9 @@
|
||||
<template #header>
|
||||
START
|
||||
<el-tooltip class="box-item" effect="dark" content="启动时间" placement="top">
|
||||
<el-icon><question-filled /></el-icon>
|
||||
<el-icon>
|
||||
<question-filled />
|
||||
</el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -67,17 +77,21 @@
|
||||
<template #header>
|
||||
TIME
|
||||
<el-tooltip class="box-item" effect="dark" content="该进程实际使用CPU运作的时间" placement="top">
|
||||
<el-icon><question-filled /></el-icon>
|
||||
<el-icon>
|
||||
<question-filled />
|
||||
</el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="command" label="command" :min-width="120" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column prop="command" label="command" :min-width="120" show-overflow-tooltip>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="操作">
|
||||
<template #default="scope">
|
||||
<el-popconfirm title="确定终止该进程?" @confirm="confirmKillProcess(scope.row.pid)">
|
||||
<template #reference>
|
||||
<el-button v-auth="'machine:killprocess'" type="danger" icon="delete" size="small" plain>终止</el-button>
|
||||
<el-button v-auth="'machine:killprocess'" type="danger" icon="delete" size="small"
|
||||
plain>终止</el-button>
|
||||
</template>
|
||||
</el-popconfirm>
|
||||
<!-- <el-button @click="addFiles(scope.row)" type="danger" icon="delete" size="small" plain>终止</el-button> -->
|
||||
@@ -88,20 +102,19 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, watch, defineComponent } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, reactive, watch } from 'vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { machineApi } from './api';
|
||||
import enums from './enums';
|
||||
export default defineComponent({
|
||||
name: 'ProcessList',
|
||||
components: {},
|
||||
props: {
|
||||
|
||||
const props = defineProps({
|
||||
visible: { type: Boolean },
|
||||
machineId: { type: Number },
|
||||
title: { type: String },
|
||||
},
|
||||
setup(props: any, context) {
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'update:machineId'])
|
||||
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
params: {
|
||||
@@ -113,6 +126,13 @@ export default defineComponent({
|
||||
processList: [],
|
||||
});
|
||||
|
||||
const {
|
||||
dialogVisible,
|
||||
params,
|
||||
processList,
|
||||
} = toRefs(state)
|
||||
|
||||
|
||||
watch(props, (newValue) => {
|
||||
if (props.machineId) {
|
||||
state.params.id = props.machineId;
|
||||
@@ -181,9 +201,9 @@ export default defineComponent({
|
||||
* 关闭取消按钮触发的事件
|
||||
*/
|
||||
const handleClose = () => {
|
||||
context.emit('update:visible', false);
|
||||
context.emit('update:machineId', null);
|
||||
context.emit('cancel');
|
||||
emit('update:visible', false);
|
||||
emit('update:machineId', null);
|
||||
emit('cancel');
|
||||
state.params = {
|
||||
name: '',
|
||||
sortType: '1',
|
||||
@@ -192,14 +212,4 @@ export default defineComponent({
|
||||
};
|
||||
state.processList = [];
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
getProcess,
|
||||
confirmKillProcess,
|
||||
enums,
|
||||
handleClose,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
<template>
|
||||
<div class="mock-data-dialog">
|
||||
<el-dialog
|
||||
:title="title"
|
||||
v-model="dialogVisible"
|
||||
:close-on-click-modal="false"
|
||||
:before-close="cancel"
|
||||
:show-close="true"
|
||||
:destroy-on-close="true"
|
||||
width="800px"
|
||||
>
|
||||
<el-form :model="form" ref="mockDataForm" label-width="70px">
|
||||
<el-dialog :title="title" v-model="dialogVisible" :close-on-click-modal="false" :before-close="cancel"
|
||||
:show-close="true" :destroy-on-close="true" width="900px">
|
||||
<el-form :model="form" ref="scriptForm" label-width="50px" size="small">
|
||||
<el-form-item prop="method" label="名称">
|
||||
<el-input v-model.trim="form.name" placeholder="请输入名称"></el-input>
|
||||
</el-form-item>
|
||||
@@ -20,52 +13,61 @@
|
||||
|
||||
<el-form-item prop="type" label="类型">
|
||||
<el-select v-model="form.type" default-first-option style="width: 100%" placeholder="请选择类型">
|
||||
<el-option v-for="item in enums.scriptTypeEnum" :key="item.value" :label="item.label" :value="item.value"></el-option>
|
||||
<el-option v-for="item in enums.scriptTypeEnum as any" :key="item.value" :label="item.label"
|
||||
:value="item.value"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="params" label="参数">
|
||||
<el-input v-model="form.params" placeholder="参数数组json,若无可不填"></el-input>
|
||||
<el-row style="margin-left: 30px; margin-bottom: 5px">
|
||||
<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 prop="script" label="内容" id="content">
|
||||
<codemirror ref="cmEditor" v-model="form.script" language="shell" width="700px" />
|
||||
</el-form-item>
|
||||
<monaco-editor v-model="form.script" language="shell" height="300px" />
|
||||
</el-form>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="cancel()" :disabled="submitDisabled" size="small">关 闭</el-button>
|
||||
<el-button
|
||||
v-auth="'machine:script:save'"
|
||||
type="primary"
|
||||
:loading="btnLoading"
|
||||
@click="btnOk"
|
||||
size="small"
|
||||
:disabled="submitDisabled"
|
||||
>保 存</el-button
|
||||
>
|
||||
<el-button @click="cancel()" :disabled="submitDisabled">关 闭</el-button>
|
||||
<el-button v-auth="'machine:script:save'" type="primary" :loading="btnLoading" @click="btnOk"
|
||||
:disabled="submitDisabled">保 存</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { ref, toRefs, reactive, watch, defineComponent } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { ref, toRefs, reactive, watch } from 'vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { machineApi } from './api';
|
||||
import enums from './enums';
|
||||
import { notEmpty } from '@/common/assert';
|
||||
import MonacoEditor from '@/components/monaco/MonacoEditor.vue';
|
||||
|
||||
import { codemirror } from '@/components/codemirror';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ScriptEdit',
|
||||
components: {
|
||||
codemirror,
|
||||
},
|
||||
props: {
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -81,44 +83,72 @@ export default defineComponent({
|
||||
isCommon: {
|
||||
type: Boolean,
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'submitSuccess'])
|
||||
|
||||
const { isCommon, machineId } = toRefs(props);
|
||||
const mockDataForm: any = ref(null);
|
||||
const scriptForm: any = ref(null);
|
||||
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
submitDisabled: false,
|
||||
params: [] as any,
|
||||
form: {
|
||||
id: null,
|
||||
name: '',
|
||||
machineId: 0,
|
||||
description: '',
|
||||
script: '',
|
||||
params: null,
|
||||
params: '',
|
||||
type: null,
|
||||
},
|
||||
btnLoading: false,
|
||||
});
|
||||
|
||||
watch(props, (newValue) => {
|
||||
const {
|
||||
dialogVisible,
|
||||
submitDisabled,
|
||||
params,
|
||||
form,
|
||||
btnLoading,
|
||||
} = toRefs(state)
|
||||
|
||||
watch(props, (newValue: any) => {
|
||||
state.dialogVisible = newValue.visible;
|
||||
if (!newValue.visible) {
|
||||
return;
|
||||
}
|
||||
if (newValue.data) {
|
||||
state.form = { ...newValue.data };
|
||||
if (state.form.params) {
|
||||
state.params = JSON.parse(state.form.params);
|
||||
}
|
||||
} else {
|
||||
state.form = {} as any;
|
||||
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 = () => {
|
||||
state.form.machineId = isCommon.value ? 9999999 : (machineId.value as any);
|
||||
state.form.machineId = isCommon.value ? 9999999 : (machineId?.value as any);
|
||||
console.log('machineid:', machineId);
|
||||
mockDataForm.value.validate((valid: any) => {
|
||||
scriptForm.value.validate((valid: any) => {
|
||||
if (valid) {
|
||||
notEmpty(state.form.name, '名称不能为空');
|
||||
notEmpty(state.form.description, '描述不能为空');
|
||||
notEmpty(state.form.script, '内容不能为空');
|
||||
if (state.params) {
|
||||
state.form.params = JSON.stringify(state.params);
|
||||
}
|
||||
machineApi.saveScript.request(state.form).then(
|
||||
() => {
|
||||
ElMessage.success('保存成功');
|
||||
@@ -139,27 +169,9 @@ export default defineComponent({
|
||||
const cancel = () => {
|
||||
emit('update:visible', false);
|
||||
emit('cancel');
|
||||
state.params = [];
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
enums,
|
||||
mockDataForm,
|
||||
btnOk,
|
||||
cancel,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
// .m-dialog {
|
||||
// .el-cascader {
|
||||
// width: 100%;
|
||||
// }
|
||||
// }
|
||||
#content {
|
||||
.CodeMirror {
|
||||
height: 300px !important;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<template>
|
||||
<div class="file-manage">
|
||||
<el-dialog :title="title" v-model="dialogVisible" :destroy-on-close="true" :show-close="true" :before-close="handleClose" width="60%">
|
||||
<el-dialog :title="title" v-model="dialogVisible" :destroy-on-close="true" :show-close="true"
|
||||
:before-close="handleClose" width="60%">
|
||||
<div class="toolbar">
|
||||
<div style="float: left">
|
||||
<el-select v-model="type" @change="getScripts" size="small" placeholder="请选择">
|
||||
@@ -9,20 +10,12 @@
|
||||
</el-select>
|
||||
</div>
|
||||
<div style="float: right">
|
||||
<el-button @click="editScript(currentData)" :disabled="currentId == null" type="primary" icon="tickets" size="small" plain
|
||||
>查看</el-button
|
||||
>
|
||||
<el-button v-auth="'machine:script:save'" type="primary" @click="editScript(null)" icon="plus" size="small" plain>添加</el-button>
|
||||
<el-button
|
||||
v-auth="'machine:script:del'"
|
||||
:disabled="currentId == null"
|
||||
type="danger"
|
||||
@click="deleteRow(currentData)"
|
||||
icon="delete"
|
||||
size="small"
|
||||
plain
|
||||
>删除</el-button
|
||||
>
|
||||
<el-button @click="editScript(currentData)" :disabled="currentId == null" type="primary"
|
||||
icon="tickets" size="small" plain>查看</el-button>
|
||||
<el-button v-auth="'machine:script:save'" type="primary" @click="editScript(null)" icon="plus"
|
||||
size="small" plain>添加</el-button>
|
||||
<el-button v-auth="'machine:script:del'" :disabled="currentId == null" type="danger"
|
||||
@click="deleteRow(currentData)" icon="delete" size="small" plain>删除</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -43,40 +36,33 @@
|
||||
</el-table-column>
|
||||
<el-table-column label="操作">
|
||||
<template #default="scope">
|
||||
<el-button v-if="scope.row.id == null" @click="addFiles(scope.row)" type="success" icon="el-icon-success" size="small" plain
|
||||
>确定</el-button
|
||||
>
|
||||
<el-button v-if="scope.row.id == null" type="success" icon="el-icon-success" size="small" plain>
|
||||
确定</el-button>
|
||||
|
||||
<el-button
|
||||
v-auth="'machine:script:run'"
|
||||
v-if="scope.row.id != null"
|
||||
@click="runScript(scope.row)"
|
||||
type="primary"
|
||||
icon="video-play"
|
||||
size="small"
|
||||
plain
|
||||
>执行</el-button
|
||||
>
|
||||
<el-button v-auth="'machine:script:run'" v-if="scope.row.id != null"
|
||||
@click="runScript(scope.row)" type="primary" icon="video-play" size="small" plain>执行
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-row style="margin-top: 10px" type="flex" justify="end">
|
||||
<el-pagination
|
||||
small
|
||||
style="text-align: center"
|
||||
:total="total"
|
||||
layout="prev, pager, next, total, jumper"
|
||||
v-model:current-page="query.pageNum"
|
||||
:page-size="query.pageSize"
|
||||
@current-change="handlePageChange"
|
||||
></el-pagination>
|
||||
<el-pagination small style="text-align: center" :total="total" layout="prev, pager, next, total, jumper"
|
||||
v-model:current-page="query.pageNum" :page-size="query.pageSize" @current-change="handlePageChange">
|
||||
</el-pagination>
|
||||
</el-row>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog title="脚本参数" v-model="scriptParamsDialog.visible" width="400px">
|
||||
<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-input v-model="scriptParamsDialog.params[item.model]" :placeholder="item.placeholder" autocomplete="off"></el-input>
|
||||
<el-form-item v-for="item in scriptParamsDialog.paramsFormItem as any" :key="item.name"
|
||||
:prop="item.model" :label="item.name" required>
|
||||
<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>
|
||||
<template #footer>
|
||||
@@ -88,54 +74,37 @@
|
||||
|
||||
<el-dialog title="执行结果" v-model="resultDialog.visible" width="50%">
|
||||
<div style="white-space: pre-line; padding: 10px; color: #000000">
|
||||
<!-- {{ resultDialog.result }} -->
|
||||
<el-input v-model="resultDialog.result" :rows="20" type="textarea" />
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
v-if="terminalDialog.visible"
|
||||
title="终端"
|
||||
v-model="terminalDialog.visible"
|
||||
width="70%"
|
||||
:close-on-click-modal="false"
|
||||
:modal="false"
|
||||
@close="closeTermnial"
|
||||
>
|
||||
<ssh-terminal ref="terminal" :cmd="terminalDialog.cmd" :machineId="terminalDialog.machineId" height="600px" />
|
||||
<el-dialog v-if="terminalDialog.visible" title="终端" v-model="terminalDialog.visible" width="80%"
|
||||
:close-on-click-modal="false" :modal="false" @close="closeTermnial">
|
||||
<ssh-terminal ref="terminal" :cmd="terminalDialog.cmd" :machineId="terminalDialog.machineId"
|
||||
height="560px" />
|
||||
</el-dialog>
|
||||
|
||||
<script-edit
|
||||
v-model:visible="editDialog.visible"
|
||||
v-model:data="editDialog.data"
|
||||
:title="editDialog.title"
|
||||
v-model:machineId="editDialog.machineId"
|
||||
:isCommon="type == 1"
|
||||
@submitSuccess="submitSuccess"
|
||||
/>
|
||||
<script-edit v-model:visible="editDialog.visible" v-model:data="editDialog.data" :title="editDialog.title"
|
||||
v-model:machineId="editDialog.machineId" :isCommon="type == 1" @submitSuccess="submitSuccess" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { ref, toRefs, reactive, watch, defineComponent } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { ref, toRefs, reactive, watch } from 'vue';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import SshTerminal from './SshTerminal.vue';
|
||||
import { machineApi } from './api';
|
||||
import enums from './enums';
|
||||
import ScriptEdit from './ScriptEdit.vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ServiceManage',
|
||||
components: {
|
||||
ScriptEdit,
|
||||
SshTerminal,
|
||||
},
|
||||
props: {
|
||||
const props = defineProps({
|
||||
visible: { type: Boolean },
|
||||
machineId: { type: Number },
|
||||
title: { type: String },
|
||||
},
|
||||
setup(props: any, context) {
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'update:machineId'])
|
||||
|
||||
const paramsForm: any = ref(null);
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
@@ -143,13 +112,13 @@ export default defineComponent({
|
||||
currentId: null,
|
||||
currentData: null,
|
||||
query: {
|
||||
machineId: 0,
|
||||
machineId: 0 as any,
|
||||
pageNum: 1,
|
||||
pageSize: 8,
|
||||
},
|
||||
editDialog: {
|
||||
visible: false,
|
||||
data: null,
|
||||
data: null as any,
|
||||
title: '',
|
||||
machineId: 9999999,
|
||||
},
|
||||
@@ -171,9 +140,23 @@ export default defineComponent({
|
||||
},
|
||||
});
|
||||
|
||||
watch(props, (newValue) => {
|
||||
if (props.machineId) {
|
||||
getScripts();
|
||||
const {
|
||||
dialogVisible,
|
||||
type,
|
||||
currentId,
|
||||
currentData,
|
||||
query,
|
||||
editDialog,
|
||||
total,
|
||||
scriptTable,
|
||||
scriptParamsDialog,
|
||||
resultDialog,
|
||||
terminalDialog,
|
||||
} = toRefs(state)
|
||||
|
||||
watch(props, async (newValue) => {
|
||||
if (props.machineId && newValue.visible) {
|
||||
await getScripts();
|
||||
}
|
||||
state.dialogVisible = newValue.visible;
|
||||
});
|
||||
@@ -196,9 +179,11 @@ export default defineComponent({
|
||||
// 如果存在参数,则弹窗输入参数后执行
|
||||
if (script.params) {
|
||||
state.scriptParamsDialog.paramsFormItem = JSON.parse(script.params);
|
||||
if (state.scriptParamsDialog.paramsFormItem && state.scriptParamsDialog.paramsFormItem.length > 0) {
|
||||
state.scriptParamsDialog.visible = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
run(script);
|
||||
};
|
||||
@@ -246,7 +231,7 @@ export default defineComponent({
|
||||
}
|
||||
state.terminalDialog.cmd = script;
|
||||
state.terminalDialog.visible = true;
|
||||
state.terminalDialog.machineId = props.machineId;
|
||||
state.terminalDialog.machineId = props.machineId as any;
|
||||
return;
|
||||
}
|
||||
};
|
||||
@@ -268,8 +253,6 @@ export default defineComponent({
|
||||
const closeTermnial = () => {
|
||||
state.terminalDialog.visible = false;
|
||||
state.terminalDialog.machineId = 0;
|
||||
// const t: any = this.$refs['terminal']
|
||||
// t.closeAll()
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -284,7 +267,7 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const editScript = (data: any) => {
|
||||
state.editDialog.machineId = props.machineId;
|
||||
state.editDialog.machineId = props.machineId as any;
|
||||
state.editDialog.data = data;
|
||||
if (data) {
|
||||
state.editDialog.title = '查看编辑脚本';
|
||||
@@ -295,8 +278,6 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const submitSuccess = () => {
|
||||
// this.delChoose()
|
||||
// this.search()
|
||||
getScripts();
|
||||
};
|
||||
|
||||
@@ -322,29 +303,12 @@ export default defineComponent({
|
||||
* 关闭取消按钮触发的事件
|
||||
*/
|
||||
const handleClose = () => {
|
||||
context.emit('update:visible', false);
|
||||
context.emit('update:machineId', null);
|
||||
context.emit('cancel');
|
||||
emit('update:visible', false);
|
||||
emit('update:machineId', null);
|
||||
emit('cancel');
|
||||
state.scriptTable = [];
|
||||
state.scriptParamsDialog.paramsFormItem = [];
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
paramsForm,
|
||||
enums,
|
||||
getScripts,
|
||||
handlePageChange,
|
||||
runScript,
|
||||
hasParamsRun,
|
||||
closeTermnial,
|
||||
choose,
|
||||
editScript,
|
||||
submitSuccess,
|
||||
deleteRow,
|
||||
handleClose,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="sass">
|
||||
</style>
|
||||
|
||||
@@ -2,23 +2,21 @@
|
||||
<div :style="{ height: height }" id="xterm" class="xterm" />
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
<script lang="ts" setup>
|
||||
import 'xterm/css/xterm.css';
|
||||
import { Terminal } from 'xterm';
|
||||
import { FitAddon } from 'xterm-addon-fit';
|
||||
import { getSession } from '@/common/utils/storage.ts';
|
||||
import config from '@/common/config';
|
||||
import { useStore } from '@/store/index.ts';
|
||||
import { toRefs, watch, computed, reactive, defineComponent, onMounted, onBeforeUnmount } from 'vue';
|
||||
import { nextTick, toRefs, watch, computed, reactive, onMounted, onBeforeUnmount } from 'vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'SshTerminal',
|
||||
props: {
|
||||
const props = defineProps({
|
||||
machineId: { type: Number },
|
||||
cmd: { type: String },
|
||||
height: { type: String },
|
||||
},
|
||||
setup(props: any) {
|
||||
})
|
||||
|
||||
const state = reactive({
|
||||
machineId: 0,
|
||||
cmd: '',
|
||||
@@ -27,22 +25,24 @@ export default defineComponent({
|
||||
socket: null as any,
|
||||
});
|
||||
|
||||
watch(props, (newValue) => {
|
||||
const {
|
||||
height,
|
||||
} = toRefs(state)
|
||||
|
||||
const resize = 1;
|
||||
const data = 2;
|
||||
const ping = 3;
|
||||
|
||||
watch(props, (newValue: any) => {
|
||||
state.machineId = newValue.machineId;
|
||||
state.cmd = newValue.cmd;
|
||||
state.height = newValue.height;
|
||||
if (state.machineId) {
|
||||
initSocket();
|
||||
}
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
state.machineId = props.machineId;
|
||||
state.height = props.height;
|
||||
state.cmd = props.cmd;
|
||||
if (state.machineId) {
|
||||
initSocket();
|
||||
}
|
||||
state.machineId = props.machineId as any;
|
||||
state.height = props.height as any;
|
||||
state.cmd = props.cmd as any;
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
@@ -56,18 +56,23 @@ export default defineComponent({
|
||||
return store.state.themeConfig.themeConfig;
|
||||
});
|
||||
|
||||
nextTick(() => {
|
||||
initXterm();
|
||||
initSocket();
|
||||
});
|
||||
|
||||
function initXterm() {
|
||||
const term: any = new Terminal({
|
||||
fontSize: getThemeConfig.value.terminalFontSize || 15,
|
||||
// fontWeight: getThemeConfig.value.terminalFontWeight || 'normal',
|
||||
fontFamily: 'JetBrainsMono, Consolas, Menlo, Monaco',
|
||||
fontWeight: getThemeConfig.value.terminalFontWeight || 'normal',
|
||||
fontFamily: 'JetBrainsMono, monaco, Consolas, Lucida Console, monospace',
|
||||
cursorBlink: true,
|
||||
// cursorStyle: 'underline', //光标样式
|
||||
disableStdin: false,
|
||||
theme: {
|
||||
foreground: getThemeConfig.value.terminalForeground || '#7e9192', //字体
|
||||
background: getThemeConfig.value.terminalBackground || '#002833', //背景色
|
||||
cursor: getThemeConfig.value.terminalCursor || '#268F81', //设置光标
|
||||
// cursorAccent: "red", // 光标停止颜色
|
||||
} as any,
|
||||
});
|
||||
const fitAddon = new FitAddon();
|
||||
@@ -82,6 +87,14 @@ export default defineComponent({
|
||||
try {
|
||||
// 窗口大小改变时,触发xterm的resize方法使自适应
|
||||
fitAddon.fit();
|
||||
if (state.term) {
|
||||
state.term.focus();
|
||||
send({
|
||||
type: resize,
|
||||
Cols: parseInt(state.term.cols),
|
||||
Rows: parseInt(state.term.rows),
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
@@ -104,69 +117,51 @@ export default defineComponent({
|
||||
term.onData((key: any) => {
|
||||
sendCmd(key);
|
||||
});
|
||||
// 为解决窗体resize方法才会向后端发送列数和行数,所以页面加载时也要触发此方法
|
||||
send({
|
||||
type: 'resize',
|
||||
Cols: parseInt(term.cols),
|
||||
Rows: parseInt(term.rows),
|
||||
});
|
||||
}
|
||||
|
||||
let pingInterval: any;
|
||||
function initSocket() {
|
||||
state.socket = new WebSocket(
|
||||
`${config.baseWsUrl}/machines/${state.machineId}/terminal?token=${getSession('token')}&cols=${state.term.cols}&rows=${state.term.rows
|
||||
}`
|
||||
);
|
||||
|
||||
// 监听socket连接
|
||||
state.socket.onopen = () => {
|
||||
// 如果有初始要执行的命令,则发送执行命令
|
||||
if (state.cmd) {
|
||||
sendCmd(state.cmd + ' \r');
|
||||
}
|
||||
}
|
||||
// 开启心跳
|
||||
pingInterval = setInterval(() => {
|
||||
send({ type: ping, msg: 'ping' });
|
||||
}, 8000);
|
||||
};
|
||||
|
||||
function initSocket() {
|
||||
state.socket = new WebSocket(`${config.baseWsUrl}/machines/${state.machineId}/terminal?token=${getSession('token')}`);
|
||||
// 监听socket连接
|
||||
state.socket.onopen = open;
|
||||
// 监听socket错误信息
|
||||
state.socket.onerror = error;
|
||||
// 监听socket消息
|
||||
state.socket.onmessage = getMessage;
|
||||
state.socket.onerror = (e: any) => {
|
||||
console.log('连接错误', e);
|
||||
};
|
||||
|
||||
state.socket.onclose = () => {
|
||||
if (state.term) {
|
||||
state.term.writeln('\r\n\x1b[31m提示: 连接已关闭...');
|
||||
}
|
||||
if (pingInterval) {
|
||||
clearInterval(pingInterval);
|
||||
}
|
||||
};
|
||||
|
||||
// 发送socket消息
|
||||
state.socket.onsend = send;
|
||||
|
||||
// 监听socket消息
|
||||
state.socket.onmessage = getMessage;
|
||||
}
|
||||
|
||||
function open() {
|
||||
console.log('socket连接成功');
|
||||
initXterm();
|
||||
//开启心跳
|
||||
// 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 getMessage(msg: any) {
|
||||
// msg.data是真正后端返回的数据
|
||||
state.term.write(msg.data);
|
||||
}
|
||||
|
||||
function send(msg: any) {
|
||||
@@ -175,11 +170,18 @@ export default defineComponent({
|
||||
|
||||
function sendCmd(key: any) {
|
||||
send({
|
||||
type: 'cmd',
|
||||
type: data,
|
||||
msg: key,
|
||||
});
|
||||
}
|
||||
|
||||
function close() {
|
||||
if (state.socket) {
|
||||
state.socket.close();
|
||||
console.log('socket关闭');
|
||||
}
|
||||
}
|
||||
|
||||
function closeAll() {
|
||||
close();
|
||||
if (state.term) {
|
||||
@@ -187,10 +189,4 @@ export default defineComponent({
|
||||
state.term = null;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -4,36 +4,27 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
<script lang="ts" setup>
|
||||
import SshTerminal from './SshTerminal.vue';
|
||||
import { reactive, toRefs, defineComponent, onMounted } from 'vue';
|
||||
import { reactive, toRefs, onMounted } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'SshTerminalPage',
|
||||
components: {
|
||||
SshTerminal,
|
||||
},
|
||||
props: {
|
||||
machineId: { type: Number },
|
||||
},
|
||||
setup() {
|
||||
const route = useRoute();
|
||||
const state = reactive({
|
||||
machineId: 0,
|
||||
height: 700,
|
||||
});
|
||||
|
||||
const {
|
||||
machineId,
|
||||
height,
|
||||
} = toRefs(state)
|
||||
|
||||
onMounted(() => {
|
||||
state.height = window.innerHeight + 5;
|
||||
state.machineId = Number.parseInt(route.query.id as string);
|
||||
});
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
||||
|
||||
@@ -3,6 +3,7 @@ import Api from '@/common/Api';
|
||||
export const machineApi = {
|
||||
// 获取权限列表
|
||||
list: Api.create("/machines", 'get'),
|
||||
getMachinePwd: Api.create("/machines/{id}/pwd", 'get'),
|
||||
info: Api.create("/machines/{id}/sysinfo", 'get'),
|
||||
stats: Api.create("/machines/{id}/stats", 'get'),
|
||||
process: Api.create("/machines/{id}/process", 'get'),
|
||||
@@ -32,5 +33,6 @@ export const machineApi = {
|
||||
addConf: Api.create("/machines/{machineId}/files", 'post'),
|
||||
// 删除配置的文件or目录
|
||||
delConf: Api.create("/machines/{machineId}/files/{id}", 'delete'),
|
||||
terminal: Api.create("/api/machines/{id}/terminal", 'get')
|
||||
terminal: Api.create("/api/machines/{id}/terminal", 'get'),
|
||||
recDirNames: Api.create("/machines/rec/names", 'get')
|
||||
}
|
||||
@@ -3,20 +3,28 @@
|
||||
<div class="toolbar">
|
||||
<el-row type="flex" justify="space-between">
|
||||
<el-col :span="24">
|
||||
<project-env-select @changeProjectEnv="changeProjectEnv">
|
||||
<template #default>
|
||||
<el-form class="search-form" label-position="right" :inline="true">
|
||||
<el-form-item label="标签">
|
||||
<el-select @change="changeTag" @focus="getTags" v-model="query.tagPath" placeholder="请选择标签"
|
||||
filterable style="width: 250px">
|
||||
<el-option v-for="item in tags" :key="item" :label="item" :value="item"> </el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="实例" label-width="40px">
|
||||
<el-select v-model="mongoId" placeholder="请选择mongo" @change="changeMongo">
|
||||
<el-option v-for="item in mongoList" :key="item.id" :label="item.name" :value="item.id">
|
||||
<span style="float: left">{{ item.name }}</span>
|
||||
<span style="float: right; color: #8492a6; margin-left: 6px; font-size: 13px">{{ ` [${item.uri}]` }}</span>
|
||||
<span style="float: right; color: #8492a6; margin-left: 6px; font-size: 13px">{{ `
|
||||
[${item.uri}]`
|
||||
}}</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="库" label-width="20px">
|
||||
<el-select v-model="database" placeholder="请选择库" @change="changeDatabase">
|
||||
<el-option v-for="item in databases" :key="item.Name" :label="item.Name" :value="item.Name">
|
||||
<el-select v-model="database" placeholder="请选择库" @change="changeDatabase" filterable>
|
||||
<el-option v-for="item in databases" :key="item.Name" :label="item.Name"
|
||||
:value="item.Name">
|
||||
<span style="float: left">{{ item.Name }}</span>
|
||||
<span style="float: right; color: #8492a6; margin-left: 4px; font-size: 13px">{{
|
||||
` [${formatByteSize(item.SizeOnDisk)}]`
|
||||
@@ -26,35 +34,29 @@
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="集合" label-width="40px">
|
||||
<el-select v-model="collection" placeholder="请选择集合" @change="changeCollection">
|
||||
<el-select v-model="collection" placeholder="请选择集合" @change="changeCollection" filterable>
|
||||
<el-option v-for="item in collections" :key="item" :label="item" :value="item">
|
||||
<!-- <span style="float: left">{{ item.uri }}</span>
|
||||
<span style="float: right; color: #8492a6; margin-left: 6px; font-size: 13px">{{
|
||||
` [${item.name}]`
|
||||
}}</span> -->
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</project-env-select>
|
||||
</el-form>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
|
||||
<el-container id="data-exec" style="border: 1px solid #eee; margin-top: 1px">
|
||||
<el-tabs @tab-remove="removeDataTab" @tab-click="onDataTabClick" style="width: 100%; margin-left: 5px" v-model="activeName">
|
||||
<el-tabs @tab-remove="removeDataTab" @tab-click="onDataTabClick" style="width: 100%; margin-left: 5px"
|
||||
v-model="activeName">
|
||||
<el-tab-pane closable v-for="dt in dataTabs" :key="dt.name" :label="dt.name" :name="dt.name">
|
||||
<el-row v-if="mongoId">
|
||||
<el-link @click="findCommand(activeName)" icon="refresh" :underline="false" class="ml5"></el-link>
|
||||
<el-link @click="showInsertDocDialog" class="ml5" type="primary" icon="plus" :underline="false"></el-link>
|
||||
<el-link @click="findCommand(activeName)" icon="refresh" :underline="false" class="ml5">
|
||||
</el-link>
|
||||
<el-link @click="showInsertDocDialog" class="ml5" type="primary" icon="plus" :underline="false">
|
||||
</el-link>
|
||||
</el-row>
|
||||
<el-row class="mt5 mb5">
|
||||
<el-input
|
||||
ref="findParamInputRef"
|
||||
v-model="dt.findParamStr"
|
||||
placeholder="点击输入相应查询条件"
|
||||
@focus="showFindDialog(dt.name)"
|
||||
>
|
||||
<el-input ref="findParamInputRef" v-model="dt.findParamStr" placeholder="点击输入相应查询条件"
|
||||
@focus="showFindDialog(dt.name)">
|
||||
<template #prepend>查询参数</template>
|
||||
</el-input>
|
||||
</el-row>
|
||||
@@ -64,22 +66,20 @@
|
||||
<el-input type="textarea" v-model="item.value" :rows="12" />
|
||||
<div style="padding: 3px; float: right" class="mr5 mongo-doc-btns">
|
||||
<div>
|
||||
<el-link @click="onJsonEditor(item)" :underline="false" type="success" icon="MagicStick"></el-link>
|
||||
<el-link @click="onJsonEditor(item)" :underline="false" type="success"
|
||||
icon="MagicStick"></el-link>
|
||||
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
|
||||
<el-link
|
||||
@click="onSaveDoc(item.value)"
|
||||
:underline="false"
|
||||
type="warning"
|
||||
icon="DocumentChecked"
|
||||
></el-link>
|
||||
<el-link @click="onSaveDoc(item.value)" :underline="false" type="warning"
|
||||
icon="DocumentChecked"></el-link>
|
||||
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
|
||||
<el-popconfirm @confirm="onDeleteDoc(item.value)" title="确定删除该文档?">
|
||||
<template #reference>
|
||||
<el-link :underline="false" type="danger" icon="DocumentDelete"></el-link>
|
||||
<el-link :underline="false" type="danger" icon="DocumentDelete">
|
||||
</el-link>
|
||||
</template>
|
||||
</el-popconfirm>
|
||||
</div>
|
||||
@@ -94,10 +94,12 @@
|
||||
<el-dialog width="600px" title="find参数" v-model="findDialog.visible">
|
||||
<el-form label-width="70px">
|
||||
<el-form-item label="filter">
|
||||
<el-input v-model="findDialog.findParam.filter" type="textarea" :rows="6" clearable auto-complete="off"></el-input>
|
||||
<el-input v-model="findDialog.findParam.filter" type="textarea" :rows="6" clearable
|
||||
auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="sort">
|
||||
<el-input v-model="findDialog.findParam.sort" type="textarea" :rows="3" clearable auto-complete="off"></el-input>
|
||||
<el-input v-model="findDialog.findParam.sort" type="textarea" :rows="3" clearable
|
||||
auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="limit">
|
||||
<el-input v-model.number="findDialog.findParam.limit" type="number" auto-complete="off"></el-input>
|
||||
@@ -114,8 +116,9 @@
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog width="800px" :title="`新增'${activeName}'集合文档`" v-model="insertDocDialog.visible" :close-on-click-modal="false">
|
||||
<json-edit currentMode="code" v-model="insertDocDialog.doc" />
|
||||
<el-dialog width="60%" :title="`新增'${activeName}'集合文档`" v-model="insertDocDialog.visible"
|
||||
:close-on-click-modal="false">
|
||||
<monaco-editor v-model="insertDocDialog.doc" language="json" />
|
||||
<template #footer>
|
||||
<div>
|
||||
<el-button @click="insertDocDialog.visible = false">取 消</el-button>
|
||||
@@ -124,48 +127,46 @@
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog width="800px" title="json编辑器" v-model="jsoneditorDialog.visible" @close="onCloseJsonEditDialog" :close-on-click-modal="false">
|
||||
<json-edit v-model="jsoneditorDialog.doc" />
|
||||
<el-dialog width="60%" title="json编辑器" v-model="jsoneditorDialog.visible" @close="onCloseJsonEditDialog"
|
||||
:close-on-click-modal="false">
|
||||
<monaco-editor v-model="jsoneditorDialog.doc" language="json" />
|
||||
</el-dialog>
|
||||
|
||||
<div style="text-align: center; margin-top: 10px"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
<script lang="ts" setup>
|
||||
import { mongoApi } from './api';
|
||||
import { toRefs, ref, reactive, defineComponent } from 'vue';
|
||||
import { toRefs, ref, reactive, watch } from 'vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import ProjectEnvSelect from '../component/ProjectEnvSelect.vue';
|
||||
|
||||
import { isTrue, notBlank, notNull } from '@/common/assert';
|
||||
import { formatByteSize } from '@/common/utils/format';
|
||||
import JsonEdit from '@/components/jsonedit/index.vue';
|
||||
import { tagApi } from '../tag/api.ts';
|
||||
import { useStore } from '@/store/index.ts';
|
||||
import MonacoEditor from '@/components/monaco/MonacoEditor.vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'MongoDataOp',
|
||||
components: {
|
||||
ProjectEnvSelect,
|
||||
JsonEdit,
|
||||
},
|
||||
setup() {
|
||||
const store = useStore();
|
||||
const findParamInputRef: any = ref(null);
|
||||
const state = reactive({
|
||||
loading: false,
|
||||
mongoList: [],
|
||||
tags: [],
|
||||
mongoList: [] as any,
|
||||
query: {
|
||||
envId: 0,
|
||||
tagPath: null,
|
||||
},
|
||||
mongoId: null, // 当前选择操作的mongo
|
||||
database: '', // 当前选择操作的库
|
||||
collection: '', //当前选中的collection
|
||||
activeName: '', // 当前操作的tab
|
||||
databases: [],
|
||||
collections: [],
|
||||
dataTabs: {}, // 数据tabs
|
||||
databases: [] as any,
|
||||
collections: [] as any,
|
||||
dataTabs: {} as any, // 数据tabs
|
||||
findDialog: {
|
||||
visible: false,
|
||||
findParam: {
|
||||
limit: 0,
|
||||
skip: 0,
|
||||
filter: '',
|
||||
sort: '',
|
||||
},
|
||||
@@ -181,25 +182,44 @@ export default defineComponent({
|
||||
},
|
||||
});
|
||||
|
||||
const {
|
||||
tags,
|
||||
mongoList,
|
||||
query,
|
||||
mongoId,
|
||||
database,
|
||||
collection,
|
||||
activeName,
|
||||
databases,
|
||||
collections,
|
||||
dataTabs,
|
||||
findDialog,
|
||||
insertDocDialog,
|
||||
jsoneditorDialog,
|
||||
} = toRefs(state)
|
||||
|
||||
const searchMongo = async () => {
|
||||
notNull(state.query.envId, '请先选择项目环境');
|
||||
notNull(state.query.tagPath, '请先选择标签');
|
||||
const res = await mongoApi.mongoList.request(state.query);
|
||||
state.mongoList = res.list;
|
||||
};
|
||||
|
||||
const changeProjectEnv = (projectId: any, envId: any) => {
|
||||
const changeTag = (tagPath: string) => {
|
||||
state.databases = [];
|
||||
state.collections = [];
|
||||
state.mongoId = null;
|
||||
state.collection = '';
|
||||
state.database = '';
|
||||
state.dataTabs = {};
|
||||
if (envId != null) {
|
||||
state.query.envId = envId;
|
||||
if (tagPath != null) {
|
||||
searchMongo();
|
||||
}
|
||||
};
|
||||
|
||||
const getTags = async () => {
|
||||
state.tags = await tagApi.getAccountTags.request(null);
|
||||
};
|
||||
|
||||
const changeMongo = () => {
|
||||
state.databases = [];
|
||||
state.collections = [];
|
||||
@@ -420,28 +440,31 @@ export default defineComponent({
|
||||
delete state.dataTabs[targetName];
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
findParamInputRef,
|
||||
changeProjectEnv,
|
||||
changeMongo,
|
||||
changeDatabase,
|
||||
changeCollection,
|
||||
onDataTabClick,
|
||||
removeDataTab,
|
||||
showFindDialog,
|
||||
confirmFindDialog,
|
||||
findCommand,
|
||||
showInsertDocDialog,
|
||||
onInsertDoc,
|
||||
onSaveDoc,
|
||||
onDeleteDoc,
|
||||
onJsonEditor,
|
||||
onCloseJsonEditDialog,
|
||||
formatByteSize,
|
||||
};
|
||||
},
|
||||
});
|
||||
// 加载选中的tagPath
|
||||
const setSelects = async (mongoDbOptInfo: any) => {
|
||||
const { tagPath, dbId, db } = mongoDbOptInfo.dbOptInfo;
|
||||
state.query.tagPath = tagPath
|
||||
await searchMongo();
|
||||
state.mongoId = dbId
|
||||
await getDatabases();
|
||||
state.database = db
|
||||
await getCollections();
|
||||
if (state.collection) {
|
||||
state.collection = ''
|
||||
state.dataTabs = {}
|
||||
}
|
||||
}
|
||||
|
||||
// 判断如果有数据则加载下拉选项
|
||||
let mongoDbOptInfo = store.state.mongoDbOptInfo
|
||||
if (mongoDbOptInfo.dbOptInfo.tagPath) {
|
||||
setSelects(mongoDbOptInfo)
|
||||
}
|
||||
|
||||
// 监听选中操作的db变化,并加载下拉选项
|
||||
watch(store.state.mongoDbOptInfo, async (newValue) => {
|
||||
await setSelects(newValue)
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
@@ -1,29 +1,33 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :close-on-click-modal="false" width="35%" :destroy-on-close="true">
|
||||
<el-form :model="form" ref="mongoForm" :rules="rules" label-width="65px">
|
||||
<el-form-item prop="projectId" label="项目" required>
|
||||
<el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
|
||||
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
</el-select>
|
||||
<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="85px">
|
||||
<el-form-item prop="tagId" label="标签:" required>
|
||||
<tag-select v-model:tag-id="form.tagId" v-model:tag-path="form.tagPath" style="width: 100%" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="envId" label="环境" required>
|
||||
<el-select @change="changeEnv" style="width: 100%" v-model="form.envId" placeholder="请选择环境">
|
||||
<el-option v-for="item in envs" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item prop="name" label="名称" required>
|
||||
<el-input v-model.trim="form.name" placeholder="请输入名称" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="uri" label="uri" required>
|
||||
<el-input
|
||||
type="textarea"
|
||||
:rows="2"
|
||||
v-model.trim="form.uri"
|
||||
placeholder="形如 mongodb://username:password@host1:port1"
|
||||
auto-complete="off"
|
||||
></el-input>
|
||||
<el-input type="textarea" :rows="2" v-model.trim="form.uri"
|
||||
placeholder="形如 mongodb://username:password@host1:port1" auto-complete="off"></el-input>
|
||||
</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>
|
||||
|
||||
@@ -37,56 +41,33 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, reactive, watch, ref } from 'vue';
|
||||
import { mongoApi } from './api';
|
||||
import { projectApi } from '../project/api.ts';
|
||||
import { machineApi } from '../machine/api.ts';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import TagSelect from '../component/TagSelect.vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'MongoEdit',
|
||||
props: {
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
projects: {
|
||||
type: Array,
|
||||
},
|
||||
mongo: {
|
||||
type: [Boolean, Object],
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
const mongoForm: any = ref(null);
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
projects: [],
|
||||
envs: [],
|
||||
form: {
|
||||
id: null,
|
||||
name: null,
|
||||
uri: null,
|
||||
project: null,
|
||||
projectId: null,
|
||||
envId: null,
|
||||
env: null,
|
||||
},
|
||||
btnLoading: false,
|
||||
rules: {
|
||||
projectId: [
|
||||
})
|
||||
|
||||
//定义事件
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'val-change'])
|
||||
|
||||
const rules = {
|
||||
tagId: [
|
||||
{
|
||||
required: true,
|
||||
message: '请选择项目',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
envId: [
|
||||
{
|
||||
required: true,
|
||||
message: '请选择环境',
|
||||
message: '请选择标签',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
@@ -104,49 +85,57 @@ export default defineComponent({
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const mongoForm: any = ref(null);
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
sshTunnelMachineList: [] as any,
|
||||
form: {
|
||||
id: null,
|
||||
name: null,
|
||||
uri: null,
|
||||
enableSshTunnel: -1,
|
||||
sshTunnelMachineId: null,
|
||||
tagId: null as any,
|
||||
tagPath: null as any,
|
||||
},
|
||||
btnLoading: false,
|
||||
});
|
||||
|
||||
watch(props, async (newValue) => {
|
||||
const {
|
||||
dialogVisible,
|
||||
sshTunnelMachineList,
|
||||
form,
|
||||
btnLoading,
|
||||
} = toRefs(state)
|
||||
|
||||
watch(props, async (newValue: any) => {
|
||||
state.dialogVisible = newValue.visible;
|
||||
state.projects = newValue.projects;
|
||||
if (!state.dialogVisible) {
|
||||
return;
|
||||
}
|
||||
if (newValue.mongo) {
|
||||
getEnvs(newValue.mongo.projectId);
|
||||
state.form = { ...newValue.mongo };
|
||||
} else {
|
||||
state.envs = [];
|
||||
state.form = { db: 0 } as any;
|
||||
}
|
||||
getSshTunnelMachines();
|
||||
});
|
||||
|
||||
const getEnvs = async (projectId: any) => {
|
||||
state.envs = await projectApi.projectEnvs.request({ projectId });
|
||||
};
|
||||
|
||||
const changeProject = (projectId: number) => {
|
||||
for (let p of state.projects as any) {
|
||||
if (p.id == projectId) {
|
||||
state.form.project = p.name;
|
||||
}
|
||||
}
|
||||
state.form.envId = null;
|
||||
state.form.env = null;
|
||||
state.envs = [];
|
||||
getEnvs(projectId);
|
||||
};
|
||||
|
||||
const changeEnv = (envId: number) => {
|
||||
for (let p of state.envs as any) {
|
||||
if (p.id == envId) {
|
||||
state.form.env = p.name;
|
||||
}
|
||||
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 btnOk = async () => {
|
||||
mongoForm.value.validate((valid: boolean) => {
|
||||
mongoForm.value.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
mongoApi.saveMongo.request(state.form).then(() => {
|
||||
const reqForm = { ...state.form };
|
||||
// reqForm.uri = await RsaEncrypt(reqForm.uri);
|
||||
mongoApi.saveMongo.request(reqForm).then(() => {
|
||||
ElMessage.success('保存成功');
|
||||
emit('val-change', state.form);
|
||||
state.btnLoading = true;
|
||||
@@ -167,17 +156,7 @@ export default defineComponent({
|
||||
emit('update:visible', false);
|
||||
emit('cancel');
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
mongoForm,
|
||||
changeProject,
|
||||
changeEnv,
|
||||
btnOk,
|
||||
cancel,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
<div>
|
||||
<el-card>
|
||||
<el-button type="primary" icon="plus" @click="editMongo(true)" 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="primary" icon="edit" :disabled="currentId == null" @click="editMongo(false)" plain>编辑
|
||||
</el-button>
|
||||
<el-button type="danger" icon="delete" :disabled="currentId == null" @click="deleteMongo" plain>删除
|
||||
</el-button>
|
||||
<div style="float: right">
|
||||
<el-select v-model="query.projectId" placeholder="请选择项目" filterable clearable>
|
||||
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
<el-select @focus="getTags" v-model="query.tagPath" placeholder="请选择标签" filterable clearable>
|
||||
<el-option v-for="item in tags" :key="item" :label="item" :value="item"> </el-option>
|
||||
</el-select>
|
||||
<el-button class="ml5" @click="search" type="success" icon="search"></el-button>
|
||||
</div>
|
||||
@@ -18,8 +20,7 @@
|
||||
</el-radio>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="project" label="项目" width></el-table-column>
|
||||
<el-table-column prop="env" label="环境" width></el-table-column>
|
||||
<el-table-column prop="tagPath" label="标签路径" min-width="150" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="name" label="名称" width></el-table-column>
|
||||
<el-table-column prop="uri" label="连接uri" min-width="150" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
@@ -28,26 +29,22 @@
|
||||
</el-table-column>
|
||||
<el-table-column prop="createTime" label="创建时间" min-width="150">
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.createTime) }}
|
||||
{{ dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="creator" label="创建人"></el-table-column>
|
||||
|
||||
<el-table-column label="操作" width>
|
||||
<template #default="scope">
|
||||
<el-link type="primary" @click="showDatabases(scope.row.id)" plain size="small" :underline="false">数据库</el-link>
|
||||
<el-link type="primary" @click="showDatabases(scope.row.id)" plain size="small"
|
||||
:underline="false">数据库</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-row style="margin-top: 20px" type="flex" justify="end">
|
||||
<el-pagination
|
||||
style="text-align: right"
|
||||
@current-change="handlePageChange"
|
||||
:total="total"
|
||||
layout="prev, pager, next, total, jumper"
|
||||
v-model:current-page="query.pageNum"
|
||||
:page-size="query.pageSize"
|
||||
></el-pagination>
|
||||
<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>
|
||||
|
||||
@@ -61,16 +58,22 @@
|
||||
</el-table-column>
|
||||
<el-table-column min-width="80" property="Empty" label="是否为空" />
|
||||
|
||||
<el-table-column min-width="80" label="操作">
|
||||
<el-table-column min-width="150" label="操作">
|
||||
<template #default="scope">
|
||||
<el-link type="success" @click="showDatabaseStats(scope.row.Name)" plain size="small" :underline="false">stats</el-link>
|
||||
<el-link type="success" @click="showDatabaseStats(scope.row.Name)" plain size="small"
|
||||
:underline="false">stats</el-link>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
<el-link type="primary" @click="showCollections(scope.row.Name)" plain size="small" :underline="false">集合</el-link>
|
||||
<el-link type="primary" @click="showCollections(scope.row.Name)" plain size="small"
|
||||
:underline="false">集合</el-link>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
<el-link type="primary" @click="openDataOps(scope.row)" plain size="small" :underline="false">
|
||||
数据操作</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<el-dialog width="700px" :title="databaseDialog.statsDialog.title" v-model="databaseDialog.statsDialog.visible">
|
||||
<el-dialog width="700px" :title="databaseDialog.statsDialog.title"
|
||||
v-model="databaseDialog.statsDialog.visible">
|
||||
<el-descriptions title="库状态信息" :column="3" border size="small">
|
||||
<el-descriptions-item label="db" label-align="right" align="center">
|
||||
{{ databaseDialog.statsDialog.data.db }}
|
||||
@@ -119,7 +122,8 @@
|
||||
<el-table-column prop="name" label="名称" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column min-width="80" label="操作">
|
||||
<template #default="scope">
|
||||
<el-link type="success" @click="showCollectionStats(scope.row.name)" plain size="small" :underline="false">stats</el-link>
|
||||
<el-link type="success" @click="showCollectionStats(scope.row.name)" plain size="small"
|
||||
:underline="false">stats</el-link>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
<el-popconfirm @confirm="onDeleteCollection(scope.row.name)" title="确定删除该集合?">
|
||||
<template #reference>
|
||||
@@ -130,7 +134,8 @@
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<el-dialog width="700px" :title="collectionsDialog.statsDialog.title" v-model="collectionsDialog.statsDialog.visible">
|
||||
<el-dialog width="700px" :title="collectionsDialog.statsDialog.title"
|
||||
v-model="collectionsDialog.statsDialog.visible">
|
||||
<el-descriptions title="集合状态信息" :column="3" border size="small">
|
||||
<el-descriptions-item label="ns" label-align="right" :span="2" align="center">
|
||||
{{ collectionsDialog.statsDialog.data.ns }}
|
||||
@@ -178,45 +183,40 @@
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<mongo-edit
|
||||
@val-change="valChange"
|
||||
:projects="projects"
|
||||
:title="mongoEditDialog.title"
|
||||
v-model:visible="mongoEditDialog.visible"
|
||||
v-model:mongo="mongoEditDialog.data"
|
||||
></mongo-edit>
|
||||
<mongo-edit @val-change="valChange" :title="mongoEditDialog.title" v-model:visible="mongoEditDialog.visible"
|
||||
v-model:mongo="mongoEditDialog.data"></mongo-edit>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
<script lang="ts" setup>
|
||||
import { mongoApi } from './api';
|
||||
import { toRefs, reactive, defineComponent, onMounted } from 'vue';
|
||||
import { toRefs, reactive, onMounted } from 'vue';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import { projectApi } from '../project/api.ts';
|
||||
import { tagApi } from '../tag/api.ts';
|
||||
import MongoEdit from './MongoEdit.vue';
|
||||
import { formatByteSize } from '@/common/utils/format';
|
||||
import { store } from '@/store';
|
||||
import router from '@/router';
|
||||
import { dateFormat } from '@/common/utils/date';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'MongoList',
|
||||
components: {
|
||||
MongoEdit,
|
||||
},
|
||||
setup() {
|
||||
const state = reactive({
|
||||
projects: [],
|
||||
tags: [],
|
||||
dbOps: {
|
||||
dbId: 0,
|
||||
db: '',
|
||||
},
|
||||
list: [],
|
||||
total: 0,
|
||||
currentId: null,
|
||||
currentData: null,
|
||||
currentData: null as any,
|
||||
query: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
prjectId: null,
|
||||
clusterId: null,
|
||||
tagPath: null,
|
||||
},
|
||||
mongoEditDialog: {
|
||||
visible: false,
|
||||
data: null,
|
||||
data: null as any,
|
||||
title: '新增mongo',
|
||||
},
|
||||
databaseDialog: {
|
||||
@@ -225,7 +225,7 @@ export default defineComponent({
|
||||
title: '',
|
||||
statsDialog: {
|
||||
visible: false,
|
||||
data: {},
|
||||
data: {} as any,
|
||||
title: '',
|
||||
},
|
||||
},
|
||||
@@ -236,7 +236,7 @@ export default defineComponent({
|
||||
title: '',
|
||||
statsDialog: {
|
||||
visible: false,
|
||||
data: {},
|
||||
data: {} as any,
|
||||
title: '',
|
||||
},
|
||||
},
|
||||
@@ -248,9 +248,20 @@ export default defineComponent({
|
||||
},
|
||||
});
|
||||
|
||||
const {
|
||||
tags,
|
||||
list,
|
||||
total,
|
||||
currentId,
|
||||
query,
|
||||
mongoEditDialog,
|
||||
databaseDialog,
|
||||
collectionsDialog,
|
||||
createCollectionDialog,
|
||||
} = toRefs(state)
|
||||
|
||||
onMounted(async () => {
|
||||
search();
|
||||
state.projects = await projectApi.accountProjects.request(null);
|
||||
});
|
||||
|
||||
const handlePageChange = (curPage: number) => {
|
||||
@@ -267,6 +278,9 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const showDatabases = async (id: number) => {
|
||||
// state.query.tagPath = row.tagPath
|
||||
state.dbOps.dbId = id
|
||||
|
||||
state.databaseDialog.data = (await mongoApi.databases.request({ id })).Databases;
|
||||
state.databaseDialog.title = `数据库列表`;
|
||||
state.databaseDialog.visible = true;
|
||||
@@ -371,7 +385,11 @@ export default defineComponent({
|
||||
state.total = res.total;
|
||||
};
|
||||
|
||||
const editMongo = (isAdd = false) => {
|
||||
const getTags = async () => {
|
||||
state.tags = await tagApi.getAccountTags.request(null);
|
||||
};
|
||||
|
||||
const editMongo = async (isAdd = false) => {
|
||||
if (isAdd) {
|
||||
state.mongoEditDialog.data = null;
|
||||
state.mongoEditDialog.title = '新增mongo';
|
||||
@@ -388,26 +406,26 @@ export default defineComponent({
|
||||
search();
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
search,
|
||||
handlePageChange,
|
||||
choose,
|
||||
showDatabases,
|
||||
showDatabaseStats,
|
||||
showCollections,
|
||||
showCollectionStats,
|
||||
onDeleteCollection,
|
||||
showCreateCollectionDialog,
|
||||
onCreateCollection,
|
||||
formatByteSize,
|
||||
deleteMongo,
|
||||
editMongo,
|
||||
valChange,
|
||||
};
|
||||
},
|
||||
});
|
||||
const openDataOps = (row: any) => {
|
||||
state.dbOps.db = row.Name
|
||||
|
||||
debugger
|
||||
let data = {
|
||||
tagPath: state.currentData.tagPath,
|
||||
dbId: state.dbOps.dbId,
|
||||
db: state.dbOps.db,
|
||||
}
|
||||
state.databaseDialog.visible = false;
|
||||
// 判断db是否发生改变
|
||||
let oldDb = store.state.mongoDbOptInfo.dbOptInfo.db;
|
||||
if (oldDb !== row.Name) {
|
||||
store.dispatch('mongoDbOptInfo/setMongoDbOptInfo', data);
|
||||
}
|
||||
router.push({ name: 'MongoDataOp' });
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
|
||||
@@ -1,415 +0,0 @@
|
||||
<template>
|
||||
<div class="project-list">
|
||||
<el-card>
|
||||
<div>
|
||||
<el-button @click="showAddProjectDialog" v-auth="permissions.saveProject" type="primary" icon="plus">添加</el-button>
|
||||
<el-button
|
||||
@click="showAddProjectDialog(chooseData)"
|
||||
v-auth="permissions.saveProject"
|
||||
:disabled="chooseId == null"
|
||||
type="primary"
|
||||
icon="edit"
|
||||
>编辑</el-button
|
||||
>
|
||||
<el-button @click="showMembers(chooseData)" :disabled="chooseId == null" type="success" icon="user">成员管理</el-button>
|
||||
|
||||
<el-button @click="showEnv(chooseData)" :disabled="chooseId == null" type="info" icon="setting">环境管理</el-button>
|
||||
|
||||
<el-button v-auth="permissions.delProject" @click="delProject" :disabled="chooseId == null" type="danger" icon="delete"
|
||||
>删除</el-button
|
||||
>
|
||||
|
||||
<div style="float: right">
|
||||
<el-input class="mr2" placeholder="请输入项目名!" style="width: 200px" v-model="query.name" @clear="search" clearable></el-input>
|
||||
<el-button @click="search" type="success" icon="search"></el-button>
|
||||
</div>
|
||||
</div>
|
||||
<el-table :data="projects" @current-change="choose" ref="table" style="width: 100%">
|
||||
<el-table-column label="选择" width="50px">
|
||||
<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="remark" label="描述" min-width="180px" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="createTime" label="创建时间">
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="creator" label="创建者"> </el-table-column>
|
||||
<!-- <el-table-column label="查看更多" min-width="80px">
|
||||
<template #default="scope">
|
||||
<el-link @click.prevent="showMembers(scope.row)" type="success">成员</el-link>
|
||||
|
||||
<el-link class="ml5" @click.prevent="showEnv(scope.row)" type="info">环境</el-link>
|
||||
</template>
|
||||
</el-table-column> -->
|
||||
</el-table>
|
||||
<el-row style="margin-top: 20px" type="flex" justify="end">
|
||||
<el-pagination
|
||||
style="text-align: right"
|
||||
@current-change="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>
|
||||
|
||||
<el-dialog width="400px" title="项目编辑" :before-close="cancelAddProject" v-model="addProjectDialog.visible">
|
||||
<el-form :model="addProjectDialog.form" label-width="70px">
|
||||
<el-form-item prop="name" label="项目名:" required>
|
||||
<el-input :disabled="addProjectDialog.form.id ? true : false" v-model="addProjectDialog.form.name" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="描述:">
|
||||
<el-input v-model="addProjectDialog.form.remark" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="cancelAddProject()">取 消</el-button>
|
||||
<el-button @click="addProject" type="primary">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog width="500px" :title="showEnvDialog.title" v-model="showEnvDialog.visible">
|
||||
<div class="toolbar">
|
||||
<el-button @click="showAddEnvDialog" v-auth="permissions.saveMember" type="primary" icon="plus">添加</el-button>
|
||||
<!-- <el-button v-auth="'role:update'" :disabled="chooseId == null" type="danger" icon="delete">删除</el-button> -->
|
||||
</div>
|
||||
<el-table border :data="showEnvDialog.envs">
|
||||
<el-table-column property="name" label="环境名" width="125"></el-table-column>
|
||||
<el-table-column property="remark" label="描述" width="125"></el-table-column>
|
||||
<el-table-column property="createTime" label="创建时间">
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<el-dialog width="400px" title="添加环境" :before-close="cancelAddEnv" v-model="showEnvDialog.addVisible">
|
||||
<el-form :model="showEnvDialog.envForm" label-width="70px">
|
||||
<el-form-item prop="name" label="环境名:" required>
|
||||
<el-input v-model="showEnvDialog.envForm.name" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="描述:">
|
||||
<el-input v-model="showEnvDialog.envForm.remark" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="cancelAddEnv()">取 消</el-button>
|
||||
<el-button v-auth="permissions.saveEnv" @click="addEnv" type="primary" :loading="btnLoading">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog width="500px" :title="showMemDialog.title" v-model="showMemDialog.visible">
|
||||
<div class="toolbar">
|
||||
<el-button v-auth="permissions.saveMember" @click="showAddMemberDialog()" type="primary" icon="plus">添加</el-button>
|
||||
<el-button v-auth="permissions.delMember" @click="deleteMember" :disabled="showMemDialog.chooseId == null" type="danger" icon="delete"
|
||||
>移除</el-button
|
||||
>
|
||||
</div>
|
||||
<el-table @current-change="chooseMember" border :data="showMemDialog.members.list">
|
||||
<el-table-column label="选择" width="50px">
|
||||
<template #default="scope">
|
||||
<el-radio v-model="showMemDialog.chooseId" :label="scope.row.id">
|
||||
<i></i>
|
||||
</el-radio>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column property="username" label="账号" width="125"></el-table-column>
|
||||
<el-table-column property="createTime" label="加入时间">
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column property="creator" label="分配者" width="125"></el-table-column>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
@current-change="setMemebers"
|
||||
style="text-align: center"
|
||||
background
|
||||
layout="prev, pager, next, total, jumper"
|
||||
:total="showMemDialog.members.total"
|
||||
v-model:current-page="showMemDialog.query.pageNum"
|
||||
:page-size="showMemDialog.query.pageSize"
|
||||
/>
|
||||
|
||||
<el-dialog width="400px" title="添加成员" :before-close="cancelAddMember" v-model="showMemDialog.addVisible">
|
||||
<el-form :model="showMemDialog.memForm" label-width="70px">
|
||||
<el-form-item label="账号:">
|
||||
<el-select
|
||||
style="width: 100%"
|
||||
remote
|
||||
:remote-method="getAccount"
|
||||
v-model="showMemDialog.memForm.accountId"
|
||||
filterable
|
||||
placeholder="请选择"
|
||||
>
|
||||
<el-option v-for="item in showMemDialog.accounts" :key="item.id" :label="item.username" :value="item.id"> </el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<!-- <el-form-item label="描述:">
|
||||
<el-input v-model="showEnvDialog.envForm.remark" auto-complete="off"></el-input>
|
||||
</el-form-item> -->
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="cancelAddMember()">取 消</el-button>
|
||||
<el-button v-auth="permissions.saveMember" @click="addMember" type="primary" :loading="btnLoading">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, onMounted, defineComponent } from 'vue';
|
||||
import { projectApi } from './api';
|
||||
import { accountApi } from '../../system/api';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import { notEmpty, notNull } from '@/common/assert';
|
||||
export default defineComponent({
|
||||
name: 'ProjectList',
|
||||
components: {},
|
||||
setup() {
|
||||
const state = reactive({
|
||||
permissions: {
|
||||
saveProject: 'project:save',
|
||||
delProject: 'project:del',
|
||||
saveMember: 'project:member:add',
|
||||
delMember: 'project:member:del',
|
||||
saveEnv: 'project:env:add',
|
||||
},
|
||||
query: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
name: null,
|
||||
},
|
||||
total: 0,
|
||||
projects: [],
|
||||
btnLoading: false,
|
||||
chooseId: null as any,
|
||||
chooseData: null as any,
|
||||
addProjectDialog: {
|
||||
title: '新增项目',
|
||||
visible: false,
|
||||
form: { name: '', remark: '' },
|
||||
},
|
||||
showEnvDialog: {
|
||||
visible: false,
|
||||
envs: [],
|
||||
title: '',
|
||||
addVisible: false,
|
||||
envForm: {
|
||||
name: '',
|
||||
remark: '',
|
||||
projectId: 0,
|
||||
},
|
||||
},
|
||||
showMemDialog: {
|
||||
visible: false,
|
||||
chooseId: null,
|
||||
chooseData: null,
|
||||
query: {
|
||||
pageSize: 8,
|
||||
pageNum: 1,
|
||||
projectId: null,
|
||||
},
|
||||
members: {
|
||||
list: [],
|
||||
total: null,
|
||||
},
|
||||
title: '',
|
||||
addVisible: false,
|
||||
memForm: {},
|
||||
accounts: [],
|
||||
},
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
search();
|
||||
});
|
||||
|
||||
const search = async () => {
|
||||
let res = await projectApi.projects.request(state.query);
|
||||
state.projects = res.list;
|
||||
state.total = res.total;
|
||||
};
|
||||
|
||||
const handlePageChange = (curPage: number) => {
|
||||
state.query.pageNum = curPage;
|
||||
search();
|
||||
};
|
||||
|
||||
const showAddProjectDialog = (data: any) => {
|
||||
if (data) {
|
||||
state.addProjectDialog.form = { ...data };
|
||||
} else {
|
||||
state.addProjectDialog.form = {} as any;
|
||||
}
|
||||
state.addProjectDialog.visible = true;
|
||||
};
|
||||
|
||||
const cancelAddProject = () => {
|
||||
state.addProjectDialog.visible = false;
|
||||
state.addProjectDialog.form = {} as any;
|
||||
};
|
||||
|
||||
const addProject = async () => {
|
||||
const form = state.addProjectDialog.form as any;
|
||||
notEmpty(form.name, '项目名不能为空');
|
||||
notEmpty(form.remark, '项目描述不能为空');
|
||||
|
||||
await projectApi.saveProject.request(form);
|
||||
ElMessage.success('保存成功');
|
||||
search();
|
||||
cancelAddProject();
|
||||
};
|
||||
|
||||
const delProject = async () => {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定删除该项目?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
});
|
||||
await projectApi.delProject.request({ id: state.chooseId });
|
||||
ElMessage.success('删除成功');
|
||||
state.chooseData = null;
|
||||
state.chooseId = null;
|
||||
search();
|
||||
} catch (err) {}
|
||||
};
|
||||
|
||||
const choose = (item: any) => {
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
state.chooseId = item.id;
|
||||
state.chooseData = item;
|
||||
};
|
||||
|
||||
const showMembers = async (project: any) => {
|
||||
state.showMemDialog.query.projectId = project.id;
|
||||
await setMemebers();
|
||||
state.showMemDialog.title = `${project.name}的成员信息`;
|
||||
state.showMemDialog.visible = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 选中成员
|
||||
*/
|
||||
const chooseMember = (item: any) => {
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
state.showMemDialog.chooseData = item;
|
||||
state.showMemDialog.chooseId = item.id;
|
||||
};
|
||||
|
||||
const deleteMember = async () => {
|
||||
notNull(state.showMemDialog.chooseData, '请选选择成员');
|
||||
await projectApi.deleteProjectMem.request(state.showMemDialog.chooseData);
|
||||
ElMessage.success('移除成功');
|
||||
// 重新赋值成员列表
|
||||
setMemebers();
|
||||
};
|
||||
|
||||
/**
|
||||
* 设置成员列表信息
|
||||
*/
|
||||
const setMemebers = async () => {
|
||||
const res = await projectApi.projectMems.request(state.showMemDialog.query);
|
||||
state.showMemDialog.members.list = res.list;
|
||||
state.showMemDialog.members.total = res.total;
|
||||
};
|
||||
|
||||
const showEnv = async (project: any) => {
|
||||
state.showEnvDialog.envs = await projectApi.projectEnvs.request({ projectId: project.id });
|
||||
state.showEnvDialog.title = `${project.name}的环境信息`;
|
||||
state.showEnvDialog.visible = true;
|
||||
};
|
||||
|
||||
const showAddMemberDialog = () => {
|
||||
state.showMemDialog.addVisible = true;
|
||||
};
|
||||
|
||||
const addMember = async () => {
|
||||
const memForm = state.showMemDialog.memForm as any;
|
||||
memForm.projectId = state.chooseData.id;
|
||||
notEmpty(memForm.accountId, '请先选择账号');
|
||||
|
||||
await projectApi.saveProjectMem.request(memForm);
|
||||
ElMessage.success('保存成功');
|
||||
setMemebers();
|
||||
cancelAddMember();
|
||||
};
|
||||
|
||||
const cancelAddMember = () => {
|
||||
state.showMemDialog.memForm = {};
|
||||
state.showMemDialog.addVisible = false;
|
||||
state.showMemDialog.chooseData = null;
|
||||
state.showMemDialog.chooseId = null;
|
||||
};
|
||||
|
||||
const getAccount = (username: any) => {
|
||||
accountApi.list.request({ username }).then((res) => {
|
||||
state.showMemDialog.accounts = res.list;
|
||||
});
|
||||
};
|
||||
|
||||
const showAddEnvDialog = () => {
|
||||
state.showEnvDialog.addVisible = true;
|
||||
};
|
||||
|
||||
const addEnv = async () => {
|
||||
const envForm = state.showEnvDialog.envForm;
|
||||
envForm.projectId = state.chooseData.id;
|
||||
await projectApi.saveProjectEnv.request(envForm);
|
||||
ElMessage.success('保存成功');
|
||||
state.showEnvDialog.envs = await projectApi.projectEnvs.request({ projectId: envForm.projectId });
|
||||
cancelAddEnv();
|
||||
};
|
||||
|
||||
const cancelAddEnv = () => {
|
||||
state.showEnvDialog.envForm = {} as any;
|
||||
state.showEnvDialog.addVisible = false;
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
search,
|
||||
handlePageChange,
|
||||
choose,
|
||||
showAddProjectDialog,
|
||||
addProject,
|
||||
delProject,
|
||||
cancelAddProject,
|
||||
showMembers,
|
||||
setMemebers,
|
||||
showEnv,
|
||||
showAddMemberDialog,
|
||||
addMember,
|
||||
chooseMember,
|
||||
deleteMember,
|
||||
cancelAddMember,
|
||||
showAddEnvDialog,
|
||||
addEnv,
|
||||
cancelAddEnv,
|
||||
getAccount,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
</style>
|
||||
@@ -1,16 +0,0 @@
|
||||
import Api from '@/common/Api';
|
||||
|
||||
export const projectApi = {
|
||||
// 获取账号可访问的项目列表
|
||||
accountProjects: Api.create("/accounts/projects", 'get'),
|
||||
projects: Api.create("/projects", 'get'),
|
||||
saveProject: Api.create("/projects", 'post'),
|
||||
delProject: Api.create("/projects", 'delete'),
|
||||
// 获取项目下的环境信息
|
||||
projectEnvs: Api.create("/projects/{projectId}/envs", 'get'),
|
||||
saveProjectEnv: Api.create("/projects/{projectId}/envs", 'post'),
|
||||
// 获取项目下的成员信息
|
||||
projectMems: Api.create("/projects/{projectId}/members", 'get'),
|
||||
saveProjectMem: Api.create("/projects/{projectId}/members", 'post'),
|
||||
deleteProjectMem: Api.create("/projects/{projectId}/members/{accountId}", 'delete'),
|
||||
}
|
||||
@@ -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>
|
||||
@@ -4,39 +4,55 @@
|
||||
<div style="float: left">
|
||||
<el-row type="flex" justify="space-between">
|
||||
<el-col :span="24">
|
||||
<project-env-select @changeProjectEnv="changeProjectEnv" @clear="clearRedis">
|
||||
<template #default>
|
||||
<el-form-item label="redis" label-width="40px">
|
||||
<el-select v-model="scanParam.id" placeholder="请选择redis" @change="changeRedis" @clear="clearRedis" clearable>
|
||||
<el-option v-for="item in redisList" :key="item.id" :label="item.host" :value="item.id">
|
||||
<span style="float: left">{{ item.host }}</span>
|
||||
<span style="float: right; color: #8492a6; margin-left: 6px; font-size: 13px">{{
|
||||
`库: [${item.db}]`
|
||||
}}</span>
|
||||
<el-form class="search-form" label-position="right" :inline="true">
|
||||
<el-form-item label="标签">
|
||||
<el-select @change="changeTag" @focus="getTags" v-model="query.tagPath"
|
||||
placeholder="请选择标签" filterable style="width: 250px">
|
||||
<el-option v-for="item in tags" :key="item" :label="item" :value="item">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</project-env-select>
|
||||
<el-form-item label="redis" label-width="40px">
|
||||
<el-select v-model="scanParam.id" placeholder="请选择redis" @change="changeRedis"
|
||||
@clear="clearRedis" clearable style="width: 250px">
|
||||
<el-option v-for="item in redisList" :key="item.id"
|
||||
:label="`${item.name ? item.name : ''} [${item.host}]`" :value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="库" label-width="20px">
|
||||
<el-select v-model="scanParam.db" @change="changeDb" placeholder="库"
|
||||
style="width: 85px">
|
||||
<el-option v-for="db in dbList" :key="db" :label="db" :value="db"> </el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-col>
|
||||
<el-col class="mt10">
|
||||
<el-form class="search-form" label-position="right" :inline="true" label-width="60px">
|
||||
<el-form-item label="key" label-width="40px">
|
||||
<el-input
|
||||
placeholder="支持*模糊key"
|
||||
style="width: 240px"
|
||||
v-model="scanParam.match"
|
||||
@clear="clear()"
|
||||
clearable
|
||||
></el-input>
|
||||
<el-input placeholder="match 支持*模糊key" style="width: 250px" v-model="scanParam.match"
|
||||
@clear="clear()" clearable></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="count" label-width="60px">
|
||||
<el-input placeholder="count" style="width: 62px" v-model.number="scanParam.count"></el-input>
|
||||
<el-form-item label="count" label-width="40px">
|
||||
<el-input placeholder="count" style="width: 70px" v-model.number="scanParam.count">
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button @click="searchKey()" type="success" icon="search" plain></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>
|
||||
<div style="float: right">
|
||||
<span>keys: {{ dbsize }}</span>
|
||||
@@ -53,15 +69,17 @@
|
||||
<el-tag :color="getTypeColor(scope.row.type)" size="small">{{ scope.row.type }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="ttl" label="ttl(过期时间)" width="130">
|
||||
<el-table-column prop="ttl" label="ttl(过期时间)" width="140">
|
||||
<template #default="scope">
|
||||
{{ ttlConveter(scope.row.ttl) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作">
|
||||
<template #default="scope">
|
||||
<el-button @click="getValue(scope.row)" type="success" icon="search" plain size="small">查看</el-button>
|
||||
<el-button @click="del(scope.row.key)" type="danger" icon="delete" plain size="small">删除</el-button>
|
||||
<el-button @click="getValue(scope.row)" type="success" icon="search" plain size="small">查看
|
||||
</el-button>
|
||||
<el-button @click="del(scope.row.key)" type="danger" icon="delete" plain size="small">删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -69,54 +87,54 @@
|
||||
|
||||
<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" :db="scanParam.db"
|
||||
@cancel="onCancelDataEdit" @valChange="searchKey" />
|
||||
|
||||
<data-edit
|
||||
v-model:visible="dataEdit.visible"
|
||||
:title="dataEdit.title"
|
||||
:keyInfo="dataEdit.keyInfo"
|
||||
:redisId="scanParam.id"
|
||||
:operationType="dataEdit.operationType"
|
||||
:stringValue="dataEdit.stringValue"
|
||||
:setValue="dataEdit.setValue"
|
||||
:hashValue="dataEdit.hashValue"
|
||||
@valChange="searchKey"
|
||||
@cancel="onCancelDataEdit"
|
||||
/>
|
||||
<string-value v-model:visible="stringValueDialog.visible" :operationType="dataEdit.operationType"
|
||||
:title="dataEdit.title" :keyInfo="dataEdit.keyInfo" :redisId="scanParam.id" :db="scanParam.db"
|
||||
@cancel="onCancelDataEdit" @valChange="searchKey" />
|
||||
|
||||
<set-value v-model:visible="setValueDialog.visible" :title="dataEdit.title" :keyInfo="dataEdit.keyInfo"
|
||||
:redisId="scanParam.id" :db="scanParam.db" :operationType="dataEdit.operationType" @valChange="searchKey"
|
||||
@cancel="onCancelDataEdit" />
|
||||
|
||||
<list-value v-model:visible="listValueDialog.visible" :title="dataEdit.title" :keyInfo="dataEdit.keyInfo"
|
||||
:redisId="scanParam.id" :db="scanParam.db" :operationType="dataEdit.operationType" @valChange="searchKey"
|
||||
@cancel="onCancelDataEdit" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
<script lang="ts" setup>
|
||||
import { redisApi } from './api';
|
||||
import { toRefs, reactive, defineComponent } from 'vue';
|
||||
import { toRefs, reactive, watch } from 'vue';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
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';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'DataOperation',
|
||||
components: {
|
||||
DataEdit,
|
||||
ProjectEnvSelect,
|
||||
},
|
||||
setup() {
|
||||
import { useStore } from '@/store/index.ts';
|
||||
import { tagApi } from '../tag/api.ts';
|
||||
|
||||
let store = useStore();
|
||||
const state = reactive({
|
||||
loading: false,
|
||||
redisList: [],
|
||||
tags: [],
|
||||
redisList: [] as any,
|
||||
dbList: [],
|
||||
query: {
|
||||
envId: 0,
|
||||
tagPath: null,
|
||||
},
|
||||
scanParam: {
|
||||
id: null,
|
||||
id: null as any,
|
||||
mode: '',
|
||||
db: '',
|
||||
match: null,
|
||||
count: 10,
|
||||
cursor: {},
|
||||
},
|
||||
valueDialog: {
|
||||
visible: false,
|
||||
value: {},
|
||||
},
|
||||
dataEdit: {
|
||||
visible: false,
|
||||
title: '新增数据',
|
||||
@@ -126,30 +144,74 @@ export default defineComponent({
|
||||
timed: -1,
|
||||
key: '',
|
||||
},
|
||||
stringValue: '',
|
||||
hashValue: [{ key: '', value: '' }],
|
||||
setValue: [{ value: '' }],
|
||||
},
|
||||
hashValueDialog: {
|
||||
visible: false,
|
||||
},
|
||||
stringValueDialog: {
|
||||
visible: false,
|
||||
},
|
||||
setValueDialog: {
|
||||
visible: false,
|
||||
},
|
||||
listValueDialog: {
|
||||
visible: false,
|
||||
},
|
||||
keys: [],
|
||||
dbsize: 0,
|
||||
});
|
||||
|
||||
const {
|
||||
loading,
|
||||
tags,
|
||||
redisList,
|
||||
dbList,
|
||||
query,
|
||||
scanParam,
|
||||
dataEdit,
|
||||
hashValueDialog,
|
||||
stringValueDialog,
|
||||
setValueDialog,
|
||||
listValueDialog,
|
||||
keys,
|
||||
dbsize,
|
||||
} = toRefs(state)
|
||||
|
||||
const searchRedis = async () => {
|
||||
notNull(state.query.envId, '请先选择项目环境');
|
||||
notBlank(state.query.tagPath, '请先选择标签');
|
||||
const res = await redisApi.redisList.request(state.query);
|
||||
state.redisList = res.list;
|
||||
};
|
||||
|
||||
const changeProjectEnv = (projectId: any, envId: any) => {
|
||||
const changeTag = (tagPath: string) => {
|
||||
clearRedis();
|
||||
if (envId != null) {
|
||||
state.query.envId = envId;
|
||||
if (tagPath != null) {
|
||||
searchRedis();
|
||||
}
|
||||
};
|
||||
|
||||
const getTags = async () => {
|
||||
state.tags = await tagApi.getAccountTags.request(null);
|
||||
};
|
||||
|
||||
const changeRedis = (id: number) => {
|
||||
resetScanParam(id);
|
||||
resetScanParam();
|
||||
if (id != 0) {
|
||||
const redis: any = state.redisList.find((x: any) => x.id == id);
|
||||
if (redis) {
|
||||
state.dbList = (state.redisList.find((x: any) => x.id == id) as any).db.split(',');
|
||||
state.scanParam.mode = redis.mode;
|
||||
}
|
||||
}
|
||||
|
||||
// 默认选中配置的第一个库
|
||||
state.scanParam.db = state.dbList[0];
|
||||
state.keys = [];
|
||||
state.dbsize = 0;
|
||||
};
|
||||
|
||||
const changeDb = () => {
|
||||
resetScanParam();
|
||||
state.keys = [];
|
||||
state.dbsize = 0;
|
||||
searchKey();
|
||||
@@ -158,12 +220,29 @@ export default defineComponent({
|
||||
const scan = async () => {
|
||||
isTrue(state.scanParam.id != null, '请先选择redis');
|
||||
notBlank(state.scanParam.count, 'count不能为空');
|
||||
isTrue(state.scanParam.count < 20001, 'count不能超过20000');
|
||||
|
||||
const match: string = state.scanParam.match || '';
|
||||
if (!match) {
|
||||
isTrue(state.scanParam.count <= 100, "key搜索条件为空时, count不能大于100")
|
||||
} else if (match.indexOf('*') != -1) {
|
||||
const dbsize = state.dbsize;
|
||||
// 如果为模糊搜索,并且搜索的key模式大于指定字符数,则将count设大点scan
|
||||
if (match.length > 10) {
|
||||
state.scanParam.count = dbsize > 100000 ? Math.floor(dbsize / 10) : 1000;
|
||||
} else {
|
||||
state.scanParam.count = 100;
|
||||
}
|
||||
}
|
||||
|
||||
const scanParam = { ...state.scanParam }
|
||||
// 集群模式count设小点,因为后端会从所有master节点scan一遍然后合并结果,默认假设redis集群有3个master
|
||||
if (scanParam.mode == 'cluster') {
|
||||
scanParam.count = Math.floor(state.scanParam.count / 3)
|
||||
}
|
||||
|
||||
state.loading = true;
|
||||
|
||||
try {
|
||||
const res = await redisApi.scan.request(state.scanParam);
|
||||
const res = await redisApi.scan.request(scanParam);
|
||||
state.keys = res.keys;
|
||||
state.dbsize = res.dbSize;
|
||||
state.scanParam.cursor = res.cursor;
|
||||
@@ -181,6 +260,7 @@ export default defineComponent({
|
||||
state.redisList = [];
|
||||
state.scanParam.id = null;
|
||||
resetScanParam();
|
||||
state.scanParam.db = '';
|
||||
state.keys = [];
|
||||
state.dbsize = 0;
|
||||
};
|
||||
@@ -192,75 +272,55 @@ export default defineComponent({
|
||||
}
|
||||
};
|
||||
|
||||
const resetScanParam = (id: number = 0) => {
|
||||
const resetScanParam = () => {
|
||||
state.scanParam.count = 10;
|
||||
if (id != 0) {
|
||||
const redis: any = state.redisList.find((x: any) => x.id == id);
|
||||
// 集群模式count设小点,因为后端会从所有master节点scan一遍然后合并结果
|
||||
if (redis && redis.mode == 'cluster') {
|
||||
state.scanParam.count = 5;
|
||||
}
|
||||
}
|
||||
state.scanParam.match = null;
|
||||
state.scanParam.cursor = {};
|
||||
};
|
||||
|
||||
const getValue = async (row: any) => {
|
||||
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.timed = row.ttl;
|
||||
state.dataEdit.keyInfo.key = key;
|
||||
state.dataEdit.keyInfo.key = row.key;
|
||||
state.dataEdit.operationType = 2;
|
||||
state.dataEdit.title = '修改数据';
|
||||
state.dataEdit.visible = true;
|
||||
state.dataEdit.title = '查看数据';
|
||||
|
||||
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) => {
|
||||
@@ -274,6 +334,7 @@ export default defineComponent({
|
||||
.request({
|
||||
key,
|
||||
id: state.scanParam.id,
|
||||
db: state.scanParam.db,
|
||||
})
|
||||
.then(() => {
|
||||
ElMessage.success('删除成功!');
|
||||
@@ -331,38 +392,30 @@ export default defineComponent({
|
||||
}
|
||||
};
|
||||
|
||||
const onAddData = () => {
|
||||
notNull(state.scanParam.id, '请先选择redis');
|
||||
state.dataEdit.operationType = 1;
|
||||
state.dataEdit.title = '新增数据';
|
||||
state.dataEdit.visible = true;
|
||||
// 加载选中的db
|
||||
const setSelects = async (redisDbOptInfo: any) => {
|
||||
// 设置标签路径等
|
||||
const { tagPath, dbId } = redisDbOptInfo.dbOptInfo;
|
||||
state.query.tagPath = tagPath;
|
||||
await searchRedis();
|
||||
state.scanParam.id = dbId;
|
||||
changeRedis(dbId);
|
||||
changeDb();
|
||||
};
|
||||
|
||||
const onCancelDataEdit = () => {
|
||||
state.dataEdit.keyInfo = {} as any;
|
||||
state.dataEdit.stringValue = '';
|
||||
state.dataEdit.setValue = [];
|
||||
state.dataEdit.hashValue = [];
|
||||
};
|
||||
// 判断如果有数据则加载下拉选项
|
||||
let redisDbOptInfo = store.state.redisDbOptInfo;
|
||||
if (redisDbOptInfo.dbOptInfo.tagPath) {
|
||||
setSelects(redisDbOptInfo);
|
||||
}
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
changeProjectEnv,
|
||||
changeRedis,
|
||||
clearRedis,
|
||||
searchKey,
|
||||
scan,
|
||||
clear,
|
||||
getValue,
|
||||
del,
|
||||
ttlConveter,
|
||||
getTypeColor,
|
||||
onAddData,
|
||||
onCancelDataEdit,
|
||||
};
|
||||
},
|
||||
// 监听选中操作的db变化,并加载下拉选项
|
||||
watch(store.state.redisDbOptInfo, async (newValue) => {
|
||||
await setSelects(newValue);
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
|
||||
108
mayfly_go_web/src/views/ops/redis/FormatInput.vue
Normal file
108
mayfly_go_web/src/views/ops/redis/FormatInput.vue
Normal file
@@ -0,0 +1,108 @@
|
||||
<template>
|
||||
<div style="width: 100%;">
|
||||
<el-input @input="onInput" type="textarea" v-model="modelValue" :autosize="autosize" :rows="rows" />
|
||||
<div style="padding: 3px; float: right" class="mr5 format-btns">
|
||||
<div>
|
||||
<el-button @click="showFormatDialog()" :underline="false" type="success" icon="MagicStick" size="small">
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<el-dialog @opened="opened" width="60%" :title="title" v-model="formatDialog.visible"
|
||||
:close-on-click-modal="false">
|
||||
<monaco-editor ref="monacoEditorRef" :canChangeMode="true" v-model="formatDialog.value" language="json" />
|
||||
<template #footer>
|
||||
<div>
|
||||
<el-button @click="formatDialog.visible = false">取 消</el-button>
|
||||
<el-button @click="onConfirmValue" type="primary">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive, watch, toRefs, onMounted } from 'vue';
|
||||
import MonacoEditor from '@/components/monaco/MonacoEditor.vue';
|
||||
|
||||
const props = defineProps({
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
modelValue: {
|
||||
type: String,
|
||||
},
|
||||
rows: {
|
||||
type: Number,
|
||||
},
|
||||
autosize: {
|
||||
type: Object
|
||||
}
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:modelValue'])
|
||||
|
||||
const monacoEditorRef: any = ref(null)
|
||||
|
||||
const state = reactive({
|
||||
rows: 2,
|
||||
autosize: {},
|
||||
modelValue: '',
|
||||
formatDialog: {
|
||||
visible: false,
|
||||
value: '',
|
||||
}
|
||||
});
|
||||
|
||||
const {
|
||||
rows,
|
||||
autosize,
|
||||
modelValue,
|
||||
formatDialog,
|
||||
} = toRefs(state)
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(val: any) => {
|
||||
state.modelValue = val;
|
||||
}
|
||||
);
|
||||
|
||||
onMounted(() => {
|
||||
state.modelValue = props.modelValue as any;
|
||||
state.autosize = props.autosize as any;
|
||||
state.rows = props.rows as any;
|
||||
})
|
||||
|
||||
const showFormatDialog = () => {
|
||||
state.formatDialog.visible = true;
|
||||
state.formatDialog.value = state.modelValue;
|
||||
}
|
||||
|
||||
const opened = () => {
|
||||
monacoEditorRef.value.format();
|
||||
};
|
||||
|
||||
const onConfirmValue = () => {
|
||||
// 尝试压缩json
|
||||
try {
|
||||
state.modelValue = JSON.stringify(JSON.parse(state.formatDialog.value));
|
||||
} catch (e) {
|
||||
state.modelValue = state.formatDialog.value;
|
||||
}
|
||||
emit('update:modelValue', state.modelValue);
|
||||
state.formatDialog.visible = false;
|
||||
}
|
||||
|
||||
const onInput = (value: any) => {
|
||||
emit('update:modelValue', value);
|
||||
}
|
||||
|
||||
</script>
|
||||
<style lang="scss">
|
||||
.format-btns {
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
right: 5px;
|
||||
top: 4px;
|
||||
max-width: 120px;
|
||||
}
|
||||
</style>
|
||||
266
mayfly_go_web/src/views/ops/redis/HashValue.vue
Normal file
266
mayfly_go_web/src/views/ops/redis/HashValue.vue
Normal file
@@ -0,0 +1,266 @@
|
||||
<template>
|
||||
<el-dialog class="el-table-z-index-inherit" :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">
|
||||
<format-input :title="`type:【${key.type}】key:【${key.key}】field:【${scope.row.field}】`" v-model="scope.row.value"
|
||||
:autosize="{ minRows: 2, maxRows: 10 }" size="small"></format-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" setup>
|
||||
import { reactive, watch, toRefs } from 'vue';
|
||||
import { redisApi } from './api';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import { isTrue, notEmpty } from '@/common/assert';
|
||||
import FormatInput from './FormatInput.vue';
|
||||
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
// 操作类型,1:新增,2:修改
|
||||
operationType: {
|
||||
type: [Number],
|
||||
require: true,
|
||||
},
|
||||
redisId: {
|
||||
type: [Number],
|
||||
require: true,
|
||||
},
|
||||
db: {
|
||||
type: [String],
|
||||
require: true,
|
||||
},
|
||||
keyInfo: {
|
||||
type: [Object],
|
||||
},
|
||||
hashValue: {
|
||||
type: [Array, Object],
|
||||
},
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'valChange'])
|
||||
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
operationType: 1,
|
||||
redisId: 0,
|
||||
db: '0',
|
||||
key: {
|
||||
key: '',
|
||||
type: 'hash',
|
||||
timed: -1,
|
||||
},
|
||||
scanParam: {
|
||||
key: '',
|
||||
id: 0,
|
||||
db: '0',
|
||||
cursor: 0,
|
||||
match: '',
|
||||
count: 10,
|
||||
},
|
||||
keySize: 0,
|
||||
hashValues: [
|
||||
{
|
||||
field: '',
|
||||
value: '',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const {
|
||||
dialogVisible,
|
||||
operationType,
|
||||
key,
|
||||
scanParam,
|
||||
keySize,
|
||||
hashValues,
|
||||
} = toRefs(state)
|
||||
|
||||
const cancel = () => {
|
||||
emit('update:visible', false);
|
||||
emit('cancel');
|
||||
setTimeout(() => {
|
||||
state.hashValues = [];
|
||||
state.key = {} as any;
|
||||
}, 500);
|
||||
};
|
||||
|
||||
watch(props, async (newValue: any) => {
|
||||
const visible = newValue.visible;
|
||||
state.redisId = newValue.redisId;
|
||||
state.db = newValue.db;
|
||||
state.key = newValue.keyInfo;
|
||||
state.operationType = newValue.operationType;
|
||||
|
||||
if (visible && state.operationType == 2) {
|
||||
state.scanParam.id = props.redisId as any;
|
||||
state.scanParam.key = state.key.key;
|
||||
await reHscan();
|
||||
}
|
||||
|
||||
state.dialogVisible = visible;
|
||||
});
|
||||
|
||||
const reHscan = async () => {
|
||||
state.scanParam.id = state.redisId;
|
||||
state.scanParam.db = state.db;
|
||||
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,
|
||||
db: state.db,
|
||||
key: state.key.key,
|
||||
field,
|
||||
});
|
||||
ElMessage.success('删除成功');
|
||||
reHscan();
|
||||
};
|
||||
|
||||
const hset = async (row: any) => {
|
||||
await redisApi.saveHashValue.request({
|
||||
id: state.redisId,
|
||||
db: state.db,
|
||||
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, db: state.db };
|
||||
Object.assign(sv, state.key);
|
||||
await redisApi.saveHashValue.request(sv);
|
||||
ElMessage.success('保存成功');
|
||||
|
||||
cancel();
|
||||
emit('valChange');
|
||||
};
|
||||
</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>
|
||||
@@ -145,12 +145,10 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, reactive, watch, toRefs } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { reactive, watch, toRefs } from 'vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'Info',
|
||||
props: {
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -160,12 +158,18 @@ export default defineComponent({
|
||||
info: {
|
||||
type: [Boolean, Object],
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:visible', 'close'])
|
||||
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
});
|
||||
|
||||
const {
|
||||
dialogVisible,
|
||||
} = toRefs(state)
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
(val) => {
|
||||
@@ -177,13 +181,6 @@ export default defineComponent({
|
||||
emit('update:visible', false);
|
||||
emit('close');
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
close,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
200
mayfly_go_web/src/views/ops/redis/ListValue.vue
Normal file
200
mayfly_go_web/src/views/ops/redis/ListValue.vue
Normal file
@@ -0,0 +1,200 @@
|
||||
<template>
|
||||
<el-dialog class="el-table-z-index-inherit" :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">
|
||||
<format-input :title="`type:【${key.type}】key:【${key.key}】`" v-model="scope.row.value"
|
||||
:autosize="{ minRows: 2, maxRows: 10 }" size="small"></format-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" setup>
|
||||
import { reactive, watch, toRefs } from 'vue';
|
||||
import { redisApi } from './api';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import FormatInput from './FormatInput.vue';
|
||||
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
redisId: {
|
||||
type: [Number],
|
||||
require: true,
|
||||
},
|
||||
db: {
|
||||
type: [String],
|
||||
require: true,
|
||||
},
|
||||
keyInfo: {
|
||||
type: [Object],
|
||||
},
|
||||
// 操作类型,1:新增,2:修改
|
||||
operationType: {
|
||||
type: [Number],
|
||||
},
|
||||
listValue: {
|
||||
type: [Array, Object],
|
||||
},
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'valChange'])
|
||||
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
operationType: 1,
|
||||
redisId: '',
|
||||
db: '0',
|
||||
key: {
|
||||
key: '',
|
||||
type: 'string',
|
||||
timed: -1,
|
||||
},
|
||||
value: [{ value: '' }],
|
||||
len: 0,
|
||||
start: 0,
|
||||
stop: 0,
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
});
|
||||
|
||||
const {
|
||||
dialogVisible,
|
||||
operationType,
|
||||
key,
|
||||
value,
|
||||
len,
|
||||
pageNum,
|
||||
pageSize,
|
||||
} = toRefs(state)
|
||||
|
||||
const cancel = () => {
|
||||
emit('update:visible', false);
|
||||
emit('cancel');
|
||||
setTimeout(() => {
|
||||
state.key = {
|
||||
key: '',
|
||||
type: 'string',
|
||||
timed: -1,
|
||||
};
|
||||
state.value = [];
|
||||
}, 500);
|
||||
};
|
||||
|
||||
watch(props, async (newValue: any) => {
|
||||
state.dialogVisible = newValue.visible;
|
||||
state.key = newValue.key;
|
||||
state.redisId = newValue.redisId;
|
||||
state.db = newValue.db;
|
||||
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,
|
||||
db: state.db,
|
||||
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,
|
||||
db: state.db,
|
||||
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();
|
||||
};
|
||||
</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,42 +1,61 @@
|
||||
<template>
|
||||
<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-item prop="projectId" label="项目:" required>
|
||||
<el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
|
||||
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
</el-select>
|
||||
<el-form-item prop="tagId" label="标签:" required>
|
||||
<tag-select v-model:tag-id="form.tagId" v-model:tag-path="form.tagPath" style="width: 100%" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="envId" label="环境:" required>
|
||||
<el-select @change="changeEnv" style="width: 100%" v-model="form.envId" placeholder="请选择环境">
|
||||
<el-option v-for="item in envs" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
</el-select>
|
||||
<el-form-item prop="name" label="名称:" required>
|
||||
<el-input v-model.trim="form.name" placeholder="请输入redis名称" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="mode" label="mode:" required>
|
||||
<el-select style="width: 100%" v-model="form.mode" placeholder="请选择模式">
|
||||
<el-option label="standalone" value="standalone"> </el-option>
|
||||
<el-option label="cluster" value="cluster"> </el-option>
|
||||
<el-option label="sentinel" value="sentinel"> </el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item prop="host" label="host:" required>
|
||||
<el-input v-model.trim="form.host" placeholder="请输入host:port,集群模式用','分割" auto-complete="off" 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 prop="password" label="密码:">
|
||||
<el-input
|
||||
type="password"
|
||||
show-password
|
||||
v-model.trim="form.password"
|
||||
placeholder="请输入密码"
|
||||
autocomplete="new-password"
|
||||
></el-input>
|
||||
<el-input type="password" show-password v-model.trim="form.password" placeholder="请输入密码, 修改操作可不填"
|
||||
autocomplete="new-password"><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 prop="db" label="库号:" required>
|
||||
<el-input v-model.number="form.db" placeholder="请输入库号"></el-input>
|
||||
<el-select @change="changeDb" v-model="dbList" multiple allow-create filterable
|
||||
placeholder="请选择可操作库号" style="width: 100%">
|
||||
<el-option v-for="db in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]" :key="db"
|
||||
:label="db" :value="db" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item prop="remark" label="备注:">
|
||||
<el-input v-model.trim="form.remark" auto-complete="off" type="textarea"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-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 as any" :key="item.id"
|
||||
:label="`${item.ip}:${item.port} [${item.name}]`" :value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-col>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<template #footer>
|
||||
@@ -49,48 +68,29 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, reactive, watch, ref } from 'vue';
|
||||
import { redisApi } from './api';
|
||||
import { projectApi } from '../project/api.ts';
|
||||
import { machineApi } from '../machine/api.ts';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { RsaEncrypt } from '@/common/rsa';
|
||||
import TagSelect from '../component/TagSelect.vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'RedisEdit',
|
||||
props: {
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
projects: {
|
||||
type: Array,
|
||||
},
|
||||
redis: {
|
||||
type: [Boolean, Object],
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
const redisForm: any = ref(null);
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
projects: [],
|
||||
envs: [],
|
||||
form: {
|
||||
id: null,
|
||||
name: null,
|
||||
mode: "standalone",
|
||||
host: null,
|
||||
password: null,
|
||||
project: null,
|
||||
projectId: null,
|
||||
envId: null,
|
||||
env: null,
|
||||
remark: "",
|
||||
},
|
||||
btnLoading: false,
|
||||
rules: {
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:visible', 'val-change', 'cancel'])
|
||||
|
||||
const rules = {
|
||||
projectId: [
|
||||
{
|
||||
required: true,
|
||||
@@ -115,60 +115,102 @@ export default defineComponent({
|
||||
db: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入库号',
|
||||
message: '请选择库号',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
mode: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入模式',
|
||||
message: '请选择模式',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const redisForm: any = ref(null);
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
sshTunnelMachineList: [],
|
||||
form: {
|
||||
id: null,
|
||||
tagId: null as any,
|
||||
tagPath: null as any,
|
||||
name: null,
|
||||
mode: 'standalone',
|
||||
host: '',
|
||||
password: null,
|
||||
db: '',
|
||||
project: null,
|
||||
projectId: null,
|
||||
envId: null,
|
||||
env: null,
|
||||
remark: '',
|
||||
enableSshTunnel: null,
|
||||
sshTunnelMachineId: null,
|
||||
},
|
||||
dbList: [0],
|
||||
pwd: '',
|
||||
btnLoading: false,
|
||||
|
||||
});
|
||||
|
||||
watch(props, async (newValue) => {
|
||||
const {
|
||||
dialogVisible,
|
||||
sshTunnelMachineList,
|
||||
form,
|
||||
dbList,
|
||||
pwd,
|
||||
btnLoading,
|
||||
} = toRefs(state)
|
||||
|
||||
watch(props, async (newValue: any) => {
|
||||
state.dialogVisible = newValue.visible;
|
||||
state.projects = newValue.projects;
|
||||
if (newValue.redis) {
|
||||
getEnvs(newValue.redis.projectId);
|
||||
state.form = { ...newValue.redis };
|
||||
} else {
|
||||
state.envs = [];
|
||||
state.form = { db: 0 } as any;
|
||||
if (!state.dialogVisible) {
|
||||
return;
|
||||
}
|
||||
if (newValue.redis) {
|
||||
state.form = { ...newValue.redis };
|
||||
convertDb(state.form.db);
|
||||
} else {
|
||||
state.form = { db: '0', enableSshTunnel: -1 } as any;
|
||||
state.dbList = [];
|
||||
}
|
||||
getSshTunnelMachines();
|
||||
});
|
||||
|
||||
const getEnvs = async (projectId: any) => {
|
||||
state.envs = await projectApi.projectEnvs.request({ projectId });
|
||||
const convertDb = (db: string) => {
|
||||
state.dbList = db.split(',').map((x) => Number.parseInt(x));
|
||||
};
|
||||
|
||||
const changeProject = (projectId: number) => {
|
||||
for (let p of state.projects as any) {
|
||||
if (p.id == projectId) {
|
||||
state.form.project = p.name;
|
||||
}
|
||||
}
|
||||
state.form.envId = null;
|
||||
state.form.env = null;
|
||||
state.envs = [];
|
||||
getEnvs(projectId);
|
||||
/**
|
||||
* 改变表单中的数据库字段,方便表单错误提示。如全部删光,可提示请添加库号
|
||||
*/
|
||||
const changeDb = () => {
|
||||
state.form.db = state.dbList.length == 0 ? '' : state.dbList.join(',');
|
||||
};
|
||||
|
||||
const changeEnv = (envId: number) => {
|
||||
for (let p of state.envs as any) {
|
||||
if (p.id == envId) {
|
||||
state.form.env = p.name;
|
||||
}
|
||||
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 getPwd = async () => {
|
||||
state.pwd = await redisApi.getRedisPwd.request({ id: state.form.id });
|
||||
};
|
||||
|
||||
const btnOk = async () => {
|
||||
redisForm.value.validate((valid: boolean) => {
|
||||
redisForm.value.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
redisApi.saveRedis.request(state.form).then(() => {
|
||||
const reqForm = { ...state.form };
|
||||
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('保存成功');
|
||||
emit('val-change', state.form);
|
||||
state.btnLoading = true;
|
||||
@@ -189,17 +231,7 @@ export default defineComponent({
|
||||
emit('update:visible', false);
|
||||
emit('cancel');
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
redisForm,
|
||||
changeProject,
|
||||
changeEnv,
|
||||
btnOk,
|
||||
cancel,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
<div>
|
||||
<el-card>
|
||||
<el-button type="primary" icon="plus" @click="editRedis(true)" 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="primary" icon="edit" :disabled="currentId == null" @click="editRedis(false)" plain>编辑
|
||||
</el-button>
|
||||
<el-button type="danger" icon="delete" :disabled="currentId == null" @click="deleteRedis" plain>删除
|
||||
</el-button>
|
||||
<div style="float: right">
|
||||
<el-select v-model="query.projectId" placeholder="请选择项目" filterable clearable>
|
||||
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
<el-select @focus="getTags" v-model="query.tagPath" placeholder="请选择标签" filterable clearable>
|
||||
<el-option v-for="item in tags" :key="item" :label="item" :value="item"> </el-option>
|
||||
</el-select>
|
||||
<el-button class="ml5" @click="search" type="success" icon="search"></el-button>
|
||||
</div>
|
||||
@@ -18,42 +20,39 @@
|
||||
</el-radio>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="project" label="项目" min-width="100"></el-table-column>
|
||||
<el-table-column prop="env" label="环境" min-width="100"></el-table-column>
|
||||
<el-table-column prop="tagPath" label="标签路径" min-width="150" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="name" label="名称" min-width="100"></el-table-column>
|
||||
<el-table-column prop="host" label="host:port" min-width="150" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column prop="mode" label="mode" min-width="100"></el-table-column>
|
||||
<el-table-column prop="remark" label="备注" min-width="100"></el-table-column>
|
||||
<el-table-column prop="createTime" label="创建时间" min-width="160">
|
||||
<el-table-column prop="remark" label="备注" min-width="120" show-overflow-tooltip></el-table-column>
|
||||
|
||||
<el-table-column label="更多" min-width="155" fixed="right">
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="creator" label="创建人" min-width="100"></el-table-column>
|
||||
<el-table-column label="更多" min-width="130" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-link v-if="scope.row.mode == 'standalone'" type="primary" @click="info(scope.row)" :underline="false">单机信息</el-link>
|
||||
<el-link @click="onShowClusterInfo(scope.row)" v-if="scope.row.mode == 'cluster'" type="success" :underline="false"
|
||||
>集群信息</el-link
|
||||
>
|
||||
<el-link @click="showDetail(scope.row)" :underline="false">详情</el-link>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
|
||||
<el-link v-if="scope.row.mode === 'standalone' || scope.row.mode === 'sentinel'" type="primary"
|
||||
@click="showInfoDialog(scope.row)" :underline="false">单机信息</el-link>
|
||||
<el-link @click="onShowClusterInfo(scope.row)" v-if="scope.row.mode === 'cluster'"
|
||||
type="primary" :underline="false">集群信息</el-link>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
|
||||
<el-link @click="openDataOpt(scope.row)" type="success" :underline="false">数据操作</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-row style="margin-top: 20px" type="flex" justify="end">
|
||||
<el-pagination
|
||||
style="text-align: right"
|
||||
@current-change="handlePageChange"
|
||||
:total="total"
|
||||
layout="prev, pager, next, total, jumper"
|
||||
v-model:current-page="query.pageNum"
|
||||
:page-size="query.pageSize"
|
||||
></el-pagination>
|
||||
<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>
|
||||
|
||||
<info v-model:visible="infoDialog.visible" :title="infoDialog.title" :info="infoDialog.info"></info>
|
||||
|
||||
<el-dialog width="1000px" title="集群信息" v-model="clusterInfoDialog.visible">
|
||||
<el-input type="textarea" :autosize="{ minRows: 12, maxRows: 12 }" v-model="clusterInfoDialog.info"> </el-input>
|
||||
<el-input type="textarea" :autosize="{ minRows: 12, maxRows: 12 }" v-model="clusterInfoDialog.info">
|
||||
</el-input>
|
||||
|
||||
<el-divider content-position="left">节点信息</el-divider>
|
||||
<el-table :data="clusterInfoDialog.nodes" stripe size="small" border>
|
||||
@@ -61,44 +60,37 @@
|
||||
<template #header>
|
||||
nodeId
|
||||
<el-tooltip class="box-item" effect="dark" content="节点id" placement="top">
|
||||
<el-icon><question-filled /></el-icon>
|
||||
<el-icon>
|
||||
<question-filled />
|
||||
</el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="ip" label="ip" min-width="180">
|
||||
<template #header>
|
||||
ip
|
||||
<el-tooltip
|
||||
class="box-item"
|
||||
effect="dark"
|
||||
content="ip:port1@port2:port1指redis服务器与客户端通信的端口,port2则是集群内部节点间通信的端口"
|
||||
placement="top"
|
||||
>
|
||||
<el-icon><question-filled /></el-icon>
|
||||
<el-tooltip class="box-item" effect="dark"
|
||||
content="ip:port1@port2:port1指redis服务器与客户端通信的端口,port2则是集群内部节点间通信的端口" placement="top">
|
||||
<el-icon>
|
||||
<question-filled />
|
||||
</el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<template #default="scope">
|
||||
<el-tag
|
||||
@click="info({ id: clusterInfoDialog.redisId, ip: scope.row.ip })"
|
||||
effect="plain"
|
||||
type="success"
|
||||
size="small"
|
||||
style="cursor: pointer"
|
||||
>{{ scope.row.ip }}</el-tag
|
||||
>
|
||||
<el-tag @click="showInfoDialog({ id: clusterInfoDialog.redisId, ip: scope.row.ip })"
|
||||
effect="plain" type="success" size="small" style="cursor: pointer">{{ scope.row.ip }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="flags" label="flags" min-width="110"></el-table-column>
|
||||
<el-table-column prop="masterSlaveRelation" label="masterSlaveRelation" min-width="300">
|
||||
<template #header>
|
||||
masterSlaveRelation
|
||||
<el-tooltip
|
||||
class="box-item"
|
||||
effect="dark"
|
||||
content="如果节点是slave,并且已知master节点,则为master节点ID;否则为符号'-'"
|
||||
placement="top"
|
||||
>
|
||||
<el-icon><question-filled /></el-icon>
|
||||
<el-tooltip class="box-item" effect="dark"
|
||||
content="如果节点是slave,并且已知master节点,则为master节点ID;否则为符号'-'" placement="top">
|
||||
<el-icon>
|
||||
<question-filled />
|
||||
</el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -115,13 +107,12 @@
|
||||
<el-table-column prop="configEpoch" label="configEpoch" min-width="130">
|
||||
<template #header>
|
||||
configEpoch
|
||||
<el-tooltip
|
||||
class="box-item"
|
||||
effect="dark"
|
||||
<el-tooltip class="box-item" effect="dark"
|
||||
content="节点的epoch值(如果该节点是从节点,则为其主节点的epoch值)。每当节点发生失败切换时,都会创建一个新的,独特的,递增的epoch。"
|
||||
placement="top"
|
||||
>
|
||||
<el-icon><question-filled /></el-icon>
|
||||
placement="top">
|
||||
<el-icon>
|
||||
<question-filled />
|
||||
</el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -130,45 +121,62 @@
|
||||
</el-table>
|
||||
</el-dialog>
|
||||
|
||||
<redis-edit
|
||||
@val-change="valChange"
|
||||
:projects="projects"
|
||||
:title="redisEditDialog.title"
|
||||
v-model:visible="redisEditDialog.visible"
|
||||
v-model:redis="redisEditDialog.data"
|
||||
></redis-edit>
|
||||
<el-dialog v-model="detailDialog.visible">
|
||||
<el-descriptions title="详情" :column="3" border>
|
||||
<el-descriptions-item :span="1.5" label="id">{{ detailDialog.data.id }}</el-descriptions-item>
|
||||
<el-descriptions-item :span="1.5" label="名称">{{ detailDialog.data.name }}</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item :span="3" label="标签路径">{{ detailDialog.data.tagPath }}</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item :span="3" label="主机">{{ detailDialog.data.host }}</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item :span="3" label="库">{{ detailDialog.data.db }}</el-descriptions-item>
|
||||
<el-descriptions-item :span="3" label="备注">{{ detailDialog.data.remark }}</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item :span="3" label="SSH隧道">{{ detailDialog.data.enableSshTunnel == 1 ? '是' : '否' }}
|
||||
</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item :span="2" label="创建时间">{{ dateFormat(detailDialog.data.createTime) }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item :span="1" label="创建者">{{ detailDialog.data.creator }}</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item :span="2" label="更新时间">{{ dateFormat(detailDialog.data.updateTime) }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item :span="1" label="修改者">{{ detailDialog.data.modifier }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</el-dialog>
|
||||
|
||||
<redis-edit @val-change="valChange" :tags="tags" :title="redisEditDialog.title"
|
||||
v-model:visible="redisEditDialog.visible" v-model:redis="redisEditDialog.data"></redis-edit>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
<script lang="ts" setup>
|
||||
import Info from './Info.vue';
|
||||
import { redisApi } from './api';
|
||||
import { toRefs, reactive, defineComponent, onMounted } from 'vue';
|
||||
import { toRefs, reactive, onMounted } from 'vue';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import { projectApi } from '../project/api.ts';
|
||||
import { tagApi } from '../tag/api.ts';
|
||||
import RedisEdit from './RedisEdit.vue';
|
||||
import { dateFormat } from '@/common/utils/date';
|
||||
import { store } from '@/store';
|
||||
import router from '@/router';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'RedisList',
|
||||
components: {
|
||||
Info,
|
||||
RedisEdit,
|
||||
},
|
||||
setup() {
|
||||
const state = reactive({
|
||||
projects: [],
|
||||
tags: [],
|
||||
redisTable: [],
|
||||
total: 0,
|
||||
currentId: null,
|
||||
currentData: null,
|
||||
query: {
|
||||
tagPath: null,
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
prjectId: null,
|
||||
clusterId: null,
|
||||
},
|
||||
redisInfo: {
|
||||
url: '',
|
||||
detailDialog: {
|
||||
visible: false,
|
||||
data: null as any,
|
||||
},
|
||||
clusterInfoDialog: {
|
||||
visible: false,
|
||||
@@ -176,12 +184,6 @@ export default defineComponent({
|
||||
info: '',
|
||||
nodes: [],
|
||||
},
|
||||
clusters: [
|
||||
{
|
||||
id: 0,
|
||||
name: '单机',
|
||||
},
|
||||
],
|
||||
infoDialog: {
|
||||
title: '',
|
||||
visible: false,
|
||||
@@ -195,14 +197,25 @@ export default defineComponent({
|
||||
},
|
||||
redisEditDialog: {
|
||||
visible: false,
|
||||
data: null,
|
||||
data: null as any,
|
||||
title: '新增redis',
|
||||
},
|
||||
});
|
||||
|
||||
const {
|
||||
tags,
|
||||
redisTable,
|
||||
total,
|
||||
currentId,
|
||||
query,
|
||||
detailDialog,
|
||||
clusterInfoDialog,
|
||||
infoDialog,
|
||||
redisEditDialog,
|
||||
} = toRefs(state)
|
||||
|
||||
onMounted(async () => {
|
||||
search();
|
||||
state.projects = await projectApi.accountProjects.request(null);
|
||||
});
|
||||
|
||||
const handlePageChange = (curPage: number) => {
|
||||
@@ -210,6 +223,11 @@ export default defineComponent({
|
||||
search();
|
||||
};
|
||||
|
||||
const showDetail = (detail: any) => {
|
||||
state.detailDialog.data = detail;
|
||||
state.detailDialog.visible = true;
|
||||
}
|
||||
|
||||
const choose = (item: any) => {
|
||||
if (!item) {
|
||||
return;
|
||||
@@ -233,7 +251,7 @@ export default defineComponent({
|
||||
} catch (err) { }
|
||||
};
|
||||
|
||||
const info = async (redis: any) => {
|
||||
const showInfoDialog = async (redis: any) => {
|
||||
var host = redis.host;
|
||||
if (redis.ip) {
|
||||
host = redis.ip.split('@')[0];
|
||||
@@ -258,7 +276,11 @@ export default defineComponent({
|
||||
state.total = res.total;
|
||||
};
|
||||
|
||||
const editRedis = (isAdd = false) => {
|
||||
const getTags = async () => {
|
||||
state.tags = await tagApi.getAccountTags.request(null);
|
||||
};
|
||||
|
||||
const editRedis = async (isAdd = false) => {
|
||||
if (isAdd) {
|
||||
state.redisEditDialog.data = null;
|
||||
state.redisEditDialog.title = '新增redis';
|
||||
@@ -274,21 +296,23 @@ export default defineComponent({
|
||||
state.currentData = null;
|
||||
search();
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
search,
|
||||
handlePageChange,
|
||||
choose,
|
||||
info,
|
||||
onShowClusterInfo,
|
||||
deleteRedis,
|
||||
editRedis,
|
||||
valChange,
|
||||
};
|
||||
},
|
||||
});
|
||||
// 打开redis数据操作页
|
||||
const openDataOpt = (row: any) => {
|
||||
const { tagPath, id, db } = row;
|
||||
// 判断db是否发生改变
|
||||
let oldDbId = store.state.redisDbOptInfo.dbOptInfo.dbId;
|
||||
if (oldDbId !== id) {
|
||||
let params = {
|
||||
tagPath,
|
||||
dbId: id,
|
||||
db
|
||||
}
|
||||
store.dispatch('redisDbOptInfo/setRedisDbOptInfo', params);
|
||||
}
|
||||
router.push({ name: 'DataOperation' });
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
|
||||
163
mayfly_go_web/src/views/ops/redis/SetValue.vue
Normal file
163
mayfly_go_web/src/views/ops/redis/SetValue.vue
Normal file
@@ -0,0 +1,163 @@
|
||||
<template>
|
||||
<el-dialog class="el-table-z-index-inherit" :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">
|
||||
<format-input :title="`type:【${key.type}】key:【${key.key}】`" v-model="scope.row.value" clearable type="textarea"
|
||||
:autosize="{ minRows: 2, maxRows: 10 }" size="small"></format-input>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="90">
|
||||
<template #default="scope">
|
||||
<el-button type="danger" @click="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" setup>
|
||||
import { reactive, watch, toRefs } from 'vue';
|
||||
import { redisApi } from './api';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { isTrue, notEmpty } from '@/common/assert';
|
||||
import FormatInput from './FormatInput.vue';
|
||||
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
redisId: {
|
||||
type: [Number],
|
||||
require: true,
|
||||
},
|
||||
db: {
|
||||
type: [String],
|
||||
require: true,
|
||||
},
|
||||
keyInfo: {
|
||||
type: [Object],
|
||||
},
|
||||
// 操作类型,1:新增,2:修改
|
||||
operationType: {
|
||||
type: [Number],
|
||||
},
|
||||
setValue: {
|
||||
type: [Array, Object],
|
||||
},
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'valChange'])
|
||||
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
operationType: 1,
|
||||
redisId: '',
|
||||
db: '0',
|
||||
key: {
|
||||
key: '',
|
||||
type: 'set',
|
||||
timed: -1,
|
||||
},
|
||||
value: [{ value: '' }],
|
||||
});
|
||||
|
||||
const {
|
||||
dialogVisible,
|
||||
operationType,
|
||||
key,
|
||||
value,
|
||||
} = toRefs(state)
|
||||
|
||||
const cancel = () => {
|
||||
emit('update:visible', false);
|
||||
emit('cancel');
|
||||
setTimeout(() => {
|
||||
state.key = {
|
||||
key: '',
|
||||
type: 'string',
|
||||
timed: -1,
|
||||
};
|
||||
state.value = [];
|
||||
}, 500);
|
||||
};
|
||||
|
||||
watch(props, async (newValue: any) => {
|
||||
state.dialogVisible = newValue.visible;
|
||||
state.key = newValue.key;
|
||||
state.redisId = newValue.redisId;
|
||||
state.db = newValue.db;
|
||||
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,
|
||||
db: state.db,
|
||||
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, db: state.db };
|
||||
Object.assign(sv, state.key);
|
||||
await redisApi.saveSetValue.request(sv);
|
||||
|
||||
ElMessage.success('数据保存成功');
|
||||
cancel();
|
||||
emit('valChange');
|
||||
};
|
||||
|
||||
const onAddSetValue = () => {
|
||||
state.value.unshift({ value: '' });
|
||||
};
|
||||
</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>
|
||||
168
mayfly_go_web/src/views/ops/redis/StringValue.vue
Normal file
168
mayfly_go_web/src/views/ops/redis/StringValue.vue
Normal file
@@ -0,0 +1,168 @@
|
||||
<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%">
|
||||
<format-input :title="`type:【${key.type}】key:【${key.key}】`" v-model="string.value" :autosize="{ minRows: 10, maxRows: 20 }"></format-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" setup>
|
||||
import { reactive, watch, toRefs } from 'vue';
|
||||
import { redisApi } from './api';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { notEmpty } from '@/common/assert';
|
||||
import FormatInput from './FormatInput.vue';
|
||||
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
redisId: {
|
||||
type: [Number],
|
||||
require: true,
|
||||
},
|
||||
db: {
|
||||
type: [String],
|
||||
require: true,
|
||||
},
|
||||
keyInfo: {
|
||||
type: [Object],
|
||||
},
|
||||
// 操作类型,1:新增,2:修改
|
||||
operationType: {
|
||||
type: [Number],
|
||||
},
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'valChange'])
|
||||
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
operationType: 1,
|
||||
redisId: '',
|
||||
db: '0',
|
||||
key: {
|
||||
key: '',
|
||||
type: 'string',
|
||||
timed: -1,
|
||||
},
|
||||
string: {
|
||||
type: 'text',
|
||||
value: '',
|
||||
},
|
||||
});
|
||||
|
||||
const {
|
||||
dialogVisible,
|
||||
operationType,
|
||||
key,
|
||||
string,
|
||||
} = toRefs(state)
|
||||
|
||||
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 as any;
|
||||
}
|
||||
);
|
||||
|
||||
watch(
|
||||
() => props.db,
|
||||
(val) => {
|
||||
state.db = val as any;
|
||||
}
|
||||
);
|
||||
|
||||
watch(props, async (newValue: any) => {
|
||||
state.dialogVisible = newValue.visible;
|
||||
state.key = newValue.key;
|
||||
state.redisId = newValue.redisId;
|
||||
state.db = newValue.db;
|
||||
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,
|
||||
db: state.db,
|
||||
key: state.key.key,
|
||||
});
|
||||
};
|
||||
|
||||
const saveValue = async () => {
|
||||
notEmpty(state.key.key, 'key不能为空');
|
||||
|
||||
notEmpty(state.string.value, 'value不能为空');
|
||||
const sv = { value: state.string.value, id: state.redisId, db: state.db };
|
||||
Object.assign(sv, state.key);
|
||||
await redisApi.saveStringValue.request(sv);
|
||||
ElMessage.success('数据保存成功');
|
||||
cancel();
|
||||
emit('valChange');
|
||||
};
|
||||
</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,88 +0,0 @@
|
||||
<template>
|
||||
<el-dialog :title="keyValue.key" v-model="dialogVisible" :before-close="cancel" :show-close="false" width="900px">
|
||||
<el-form>
|
||||
<el-form-item>
|
||||
<el-input class="json-text" v-model="keyValue2.jsonValue" type="textarea" :autosize="{ minRows: 10, maxRows: 20 }"></el-input>
|
||||
</el-form-item>
|
||||
<!-- <vue3-json-editor v-model="keyValue2.jsonValue" @json-change="valueChange" :show-btns="false" :expandedOnStart="true" /> -->
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="cancel()">取 消</el-button>
|
||||
<el-button @click="saveValue" type="primary">确 定</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 } from '@/common/assert';
|
||||
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ValueDialog',
|
||||
components: {},
|
||||
props: {
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
keyValue: {
|
||||
type: [String, Object],
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
keyValue2: {} as any,
|
||||
});
|
||||
const cancel = () => {
|
||||
emit('update:visible', false);
|
||||
emit('cancel');
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
(val) => {
|
||||
state.dialogVisible = val;
|
||||
}
|
||||
);
|
||||
|
||||
watch(
|
||||
() => props.keyValue,
|
||||
(val) => {
|
||||
state.keyValue2 = val;
|
||||
if (typeof val.value == 'string') {
|
||||
state.keyValue2.jsonValue = JSON.stringify(JSON.parse(val.value), null, 2);
|
||||
} else {
|
||||
state.keyValue2.jsonValue = JSON.stringify(val.value, null, 2);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const saveValue = async () => {
|
||||
isTrue(state.keyValue2.type == 'string', '暂不支持除string外其他类型修改');
|
||||
|
||||
state.keyValue2.value = state.keyValue2.jsonValue;
|
||||
await redisApi.saveStringValue.request(state.keyValue2);
|
||||
ElMessage.success('保存成功');
|
||||
cancel();
|
||||
};
|
||||
|
||||
const valueChange = (val: any) => {
|
||||
state.keyValue2.value = JSON.stringify(val);
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
saveValue,
|
||||
valueChange,
|
||||
cancel,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -2,18 +2,25 @@ import Api from '@/common/Api';
|
||||
|
||||
export const redisApi = {
|
||||
redisList : Api.create("/redis", 'get'),
|
||||
getRedisPwd: Api.create("/redis/{id}/pwd", 'get'),
|
||||
redisInfo: Api.create("/redis/{id}/info", 'get'),
|
||||
clusterInfo: Api.create("/redis/{id}/cluster-info", 'get'),
|
||||
saveRedis: Api.create("/redis", 'post'),
|
||||
delRedis: Api.create("/redis/{id}", 'delete'),
|
||||
// 获取权限列表
|
||||
scan: Api.create("/redis/{id}/scan", 'post'),
|
||||
getStringValue: Api.create("/redis/{id}/string-value", 'get'),
|
||||
saveStringValue: Api.create("/redis/{id}/string-value", 'post'),
|
||||
getHashValue: Api.create("/redis/{id}/hash-value", 'get'),
|
||||
saveHashValue: Api.create("/redis/{id}/hash-value", 'post'),
|
||||
getSetValue: Api.create("/redis/{id}/set-value", 'get'),
|
||||
saveSetValue: Api.create("/redis/{id}/set-value", 'post'),
|
||||
del: Api.create("/redis/{id}/scan/{cursor}/{count}", 'delete'),
|
||||
delKey: Api.create("/redis/{id}/key", 'delete'),
|
||||
scan: Api.create("/redis/{id}/{db}/scan", 'post'),
|
||||
getStringValue: Api.create("/redis/{id}/{db}/string-value", 'get'),
|
||||
saveStringValue: Api.create("/redis/{id}/{db}/string-value", 'post'),
|
||||
getHashValue: Api.create("/redis/{id}/{db}/hash-value", 'get'),
|
||||
hscan: Api.create("/redis/{id}/{db}/hscan", 'get'),
|
||||
hget: Api.create("/redis/{id}/{db}/hget", 'get'),
|
||||
hdel: Api.create("/redis/{id}/{db}/hdel", 'delete'),
|
||||
saveHashValue: Api.create("/redis/{id}/{db}/hash-value", 'post'),
|
||||
getSetValue: Api.create("/redis/{id}/{db}/set-value", 'get'),
|
||||
saveSetValue: Api.create("/redis/{id}/{db}/set-value", 'post'),
|
||||
del: Api.create("/redis/{id}/{db}/scan/{cursor}/{count}", 'delete'),
|
||||
delKey: Api.create("/redis/{id}/{db}/key", 'delete'),
|
||||
getListValue: Api.create("/redis/{id}/{db}/list-value", 'get'),
|
||||
saveListValue: Api.create("/redis/{id}/{db}/list-value", 'post'),
|
||||
setListValue: Api.create("/redis/{id}/{db}/list-value/lset", 'post'),
|
||||
}
|
||||
293
mayfly_go_web/src/views/ops/tag/TagTreeList.vue
Normal file
293
mayfly_go_web/src/views/ops/tag/TagTreeList.vue
Normal file
@@ -0,0 +1,293 @@
|
||||
<template>
|
||||
<div class="menu">
|
||||
<div class="toolbar">
|
||||
<el-input v-model="filterTag" placeholder="输入标签关键字过滤" style="width: 200px; margin-right: 10px" />
|
||||
<el-button v-auth="'tag:save'" type="primary" icon="plus" @click="showSaveTabDialog(null)">添加</el-button>
|
||||
<div style="float: right">
|
||||
<el-tooltip effect="dark" placement="top">
|
||||
<template #content>
|
||||
1. 用于将资产进行归类
|
||||
<br />2. 可在团队管理中进行分配,用于资源隔离 <br />3. 拥有父标签的团队成员可访问操作其自身或子标签关联的资源
|
||||
</template>
|
||||
<span>标签作用<el-icon>
|
||||
<question-filled />
|
||||
</el-icon>
|
||||
</span>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
<el-tree ref="tagTreeRef" class="none-select" :indent="38" node-key="id" :props="props" :data="data"
|
||||
@node-expand="handleNodeExpand" @node-collapse="handleNodeCollapse"
|
||||
:default-expanded-keys="defaultExpandedKeys" :expand-on-click-node="false" :filter-node-method="filterNode">
|
||||
<template #default="{ data }">
|
||||
<span class="custom-tree-node">
|
||||
<span style="font-size: 13px">
|
||||
{{ data.code }}
|
||||
<span style="color: #3c8dbc">【</span>
|
||||
{{ data.name }}
|
||||
<span style="color: #3c8dbc">】</span>
|
||||
<el-tag v-if="data.children !== null" size="small">{{ data.children.length }}</el-tag>
|
||||
</span>
|
||||
|
||||
<el-link @click.prevent="info(data)" style="margin-left: 25px" icon="view" type="info"
|
||||
:underline="false" />
|
||||
|
||||
<el-link v-auth="'tag:save'" @click.prevent="showEditTagDialog(data)" class="ml5" type="primary"
|
||||
icon="edit" :underline="false" />
|
||||
|
||||
<el-link v-auth="'tag:save'" @click.prevent="showSaveTabDialog(data)" icon="circle-plus"
|
||||
:underline="false" type="success" class="ml5" />
|
||||
|
||||
<!-- <el-link
|
||||
v-auth="'resource:changeStatus'"
|
||||
@click.prevent="changeStatus(data, -1)"
|
||||
v-if="data.status === 1 && data.type === enums.ResourceTypeEnum.PERMISSION.value"
|
||||
icon="circle-close"
|
||||
:underline="false"
|
||||
type="warning"
|
||||
class="ml5"
|
||||
/>
|
||||
|
||||
<el-link
|
||||
v-auth="'resource:changeStatus'"
|
||||
@click.prevent="changeStatus(data, 1)"
|
||||
v-if="data.status === -1 && data.type === enums.ResourceTypeEnum.PERMISSION.value"
|
||||
type="success"
|
||||
icon="circle-check"
|
||||
:underline="false"
|
||||
plain
|
||||
class="ml5"
|
||||
/> -->
|
||||
|
||||
<el-link v-auth="'tag:del'" @click.prevent="deleteTag(data)" v-if="data.children == null"
|
||||
type="danger" icon="delete" :underline="false" plain class="ml5" />
|
||||
</span>
|
||||
</template>
|
||||
</el-tree>
|
||||
|
||||
<el-dialog width="500px" :title="saveTabDialog.title" :before-close="cancelSaveTag"
|
||||
v-model="saveTabDialog.visible">
|
||||
<el-form ref="tagForm" :rules="rules" :model="saveTabDialog.form" label-width="70px">
|
||||
<el-form-item prop="code" label="标识:" required>
|
||||
<el-input :disabled="saveTabDialog.form.id ? true : false" v-model="saveTabDialog.form.code"
|
||||
auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="name" label="名称:" required>
|
||||
<el-input v-model="saveTabDialog.form.name" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注:">
|
||||
<el-input v-model="saveTabDialog.form.remark" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="cancelSaveTag()">取 消</el-button>
|
||||
<el-button @click="saveTag" type="primary">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog v-model="infoDialog.visible">
|
||||
<el-descriptions title="节点信息" :column="2" border>
|
||||
<el-descriptions-item label="code">{{ infoDialog.data.code }}</el-descriptions-item>
|
||||
<el-descriptions-item label="code路径">{{ infoDialog.data.codePath }}</el-descriptions-item>
|
||||
<el-descriptions-item label="名称">{{ infoDialog.data.name }}</el-descriptions-item>
|
||||
<el-descriptions-item label="备注">{{ infoDialog.data.remark }}</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item label="创建者">{{ infoDialog.data.creator }}</el-descriptions-item>
|
||||
<el-descriptions-item label="创建时间">{{ dateFormat(infoDialog.data.createTime) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="修改者">{{ infoDialog.data.modifier }}</el-descriptions-item>
|
||||
<el-descriptions-item label="更新时间">{{ dateFormat(infoDialog.data.updateTime) }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, ref, watch, reactive, onMounted } from 'vue';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import { tagApi } from './api';
|
||||
import { dateFormat } from '@/common/utils/date';
|
||||
|
||||
interface Tree {
|
||||
id: number;
|
||||
codePath: string;
|
||||
name: string;
|
||||
children?: Tree[];
|
||||
}
|
||||
|
||||
const tagForm: any = ref(null);
|
||||
const tagTreeRef: any = ref(null);
|
||||
const filterTag = ref('');
|
||||
|
||||
const state = reactive({
|
||||
data: [],
|
||||
saveTabDialog: {
|
||||
title: '新增标签',
|
||||
visible: false,
|
||||
form: { id: 0, pid: 0, code: '', name: '', remark: '' },
|
||||
},
|
||||
infoDialog: {
|
||||
title: '',
|
||||
visible: false,
|
||||
// 资源类型选择是否选
|
||||
data: null as any,
|
||||
},
|
||||
// 展开的节点
|
||||
defaultExpandedKeys: [] as any
|
||||
});
|
||||
|
||||
const {
|
||||
data,
|
||||
saveTabDialog,
|
||||
infoDialog,
|
||||
defaultExpandedKeys,
|
||||
} = toRefs(state)
|
||||
|
||||
const props = {
|
||||
label: 'name',
|
||||
children: 'children',
|
||||
};
|
||||
|
||||
const rules = {
|
||||
code: [
|
||||
{ required: true, message: '标识符不能为空', trigger: 'blur' },
|
||||
// {
|
||||
// pattern: /^\w+$/g,
|
||||
// message: '标识符只能为空数字字母下划线等',
|
||||
// trigger: 'blur',
|
||||
// },
|
||||
],
|
||||
name: [{ required: true, message: '名称不能为空', trigger: 'blur' }],
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
search();
|
||||
});
|
||||
|
||||
watch(filterTag, (val) => {
|
||||
tagTreeRef.value!.filter(val);
|
||||
});
|
||||
|
||||
const filterNode = (value: string, data: Tree) => {
|
||||
if (!value) return true;
|
||||
return data.codePath.includes(value) || data.name.includes(value);
|
||||
};
|
||||
|
||||
const search = async () => {
|
||||
let res = await tagApi.getTagTrees.request(null);
|
||||
state.data = res;
|
||||
};
|
||||
|
||||
const info = async (data: any) => {
|
||||
state.infoDialog.data = data;
|
||||
state.infoDialog.visible = true;
|
||||
};
|
||||
|
||||
const showSaveTabDialog = (data: any) => {
|
||||
if (data) {
|
||||
state.saveTabDialog.form.pid = data.id;
|
||||
state.saveTabDialog.title = `新增 [${data.codePath}] 子标签信息`;
|
||||
} else {
|
||||
state.saveTabDialog.title = '新增根标签信息';
|
||||
}
|
||||
state.saveTabDialog.visible = true;
|
||||
};
|
||||
|
||||
const showEditTagDialog = (data: any) => {
|
||||
state.saveTabDialog.form.id = data.id;
|
||||
state.saveTabDialog.form.code = data.code;
|
||||
state.saveTabDialog.form.name = data.name;
|
||||
state.saveTabDialog.form.remark = data.remark;
|
||||
state.saveTabDialog.title = `修改 [${data.codePath}] 信息`;
|
||||
state.saveTabDialog.visible = true;
|
||||
};
|
||||
|
||||
const saveTag = async () => {
|
||||
tagForm.value.validate(async (valid: any) => {
|
||||
if (valid) {
|
||||
const form = state.saveTabDialog.form;
|
||||
await tagApi.saveTagTree.request(form);
|
||||
ElMessage.success('保存成功');
|
||||
search();
|
||||
cancelSaveTag();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const cancelSaveTag = () => {
|
||||
state.saveTabDialog.visible = false;
|
||||
state.saveTabDialog.form = {} as any;
|
||||
tagForm.value.resetFields();
|
||||
};
|
||||
|
||||
const deleteTag = (data: any) => {
|
||||
ElMessageBox.confirm(`此操作将删除 [${data.codePath}], 是否继续?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
}).then(async () => {
|
||||
await tagApi.delTagTree.request({ id: data.id });
|
||||
ElMessage.success('删除成功!');
|
||||
search();
|
||||
});
|
||||
};
|
||||
|
||||
// const changeStatus = async (data: any, status: any) => {
|
||||
// await resourceApi.changeStatus.request({
|
||||
// id: data.id,
|
||||
// status: status,
|
||||
// });
|
||||
// data.status = status;
|
||||
// ElMessage.success((status === 1 ? '启用' : '禁用') + '成功!');
|
||||
// };
|
||||
|
||||
// 节点被展开时触发的事件
|
||||
const handleNodeExpand = (data: any, node: any) => {
|
||||
const id: any = node.data.id;
|
||||
if (!state.defaultExpandedKeys.includes(id)) {
|
||||
state.defaultExpandedKeys.push(id);
|
||||
}
|
||||
};
|
||||
|
||||
// 关闭节点
|
||||
const handleNodeCollapse = (data: any, node: any) => {
|
||||
removeDeafultExpandId(node.data.id);
|
||||
|
||||
let childNodes = node.childNodes;
|
||||
for (let cn of childNodes) {
|
||||
if (cn.expanded) {
|
||||
removeDeafultExpandId(cn.data.id);
|
||||
}
|
||||
// 递归删除展开的子节点节点id
|
||||
handleNodeCollapse(data, cn);
|
||||
}
|
||||
};
|
||||
|
||||
const removeDeafultExpandId = (id: any) => {
|
||||
let index = state.defaultExpandedKeys.indexOf(id);
|
||||
if (index > -1) {
|
||||
state.defaultExpandedKeys.splice(index, 1);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<style lang="scss">
|
||||
.menu {
|
||||
height: 100%;
|
||||
|
||||
.el-tree-node__content {
|
||||
height: 40px;
|
||||
line-height: 40px;
|
||||
}
|
||||
}
|
||||
|
||||
.none-select {
|
||||
moz-user-select: -moz-none;
|
||||
-moz-user-select: none;
|
||||
-o-user-select: none;
|
||||
-khtml-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
</style>
|
||||
409
mayfly_go_web/src/views/ops/tag/TeamList.vue
Executable file
409
mayfly_go_web/src/views/ops/tag/TeamList.vue
Executable file
@@ -0,0 +1,409 @@
|
||||
<template>
|
||||
<div class="role-list">
|
||||
<el-card>
|
||||
<el-button v-auth="'team:save'" type="primary" icon="plus" @click="showSaveTeamDialog(false)">添加</el-button>
|
||||
<el-button v-auth="'team:save'" :disabled="!chooseId" @click="showSaveTeamDialog(chooseData)" type="primary"
|
||||
icon="edit">编辑</el-button>
|
||||
<el-button v-auth="'team:del'" :disabled="!chooseId" @click="deleteTeam(chooseData)" type="danger"
|
||||
icon="delete">删除</el-button>
|
||||
|
||||
<div style="float: right">
|
||||
<el-input placeholder="请输入团队名称" class="mr2" style="width: 200px" v-model="query.name" @clear="search"
|
||||
clearable></el-input>
|
||||
<el-button @click="search" type="success" icon="search"></el-button>
|
||||
</div>
|
||||
<el-table :data="data" @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="remark" label="备注" min-width="160px" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="createTime" label="创建时间">
|
||||
<template #default="scope">
|
||||
{{ dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="creator" label="创建者"> </el-table-column>
|
||||
<el-table-column label="操作" min-width="80px">
|
||||
<template #default="scope">
|
||||
<el-link @click.prevent="showMembers(scope.row)" :underline="false" type="primary">成员</el-link>
|
||||
<el-divider direction="vertical" border-style="dashed" />
|
||||
<el-link @click.prevent="showTags(scope.row)" :underline="false" type="success">标签</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-row style="margin-top: 20px" type="flex" justify="end">
|
||||
<el-pagination style="text-align: right" @current-change="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>
|
||||
|
||||
<el-dialog width="400px" title="团队编辑" :before-close="cancelSaveTeam" v-model="addTeamDialog.visible">
|
||||
<el-form ref="teamForm" :model="addTeamDialog.form" label-width="70px">
|
||||
<el-form-item prop="name" label="团队名:" required>
|
||||
<el-input v-model="addTeamDialog.form.name" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注:">
|
||||
<el-input v-model="addTeamDialog.form.remark" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="cancelSaveTeam()">取 消</el-button>
|
||||
<el-button @click="saveTeam" type="primary">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog width="500px" :title="showTagDialog.title" :before-close="closeTagDialog"
|
||||
v-model="showTagDialog.visible">
|
||||
<el-form label-width="70px">
|
||||
<el-form-item prop="project" label="标签:">
|
||||
<el-tree-select ref="tagTreeRef" style="width: 100%" v-model="showTagDialog.tagTreeTeams"
|
||||
:data="showTagDialog.tags" :default-expanded-keys="showTagDialog.tagTreeTeams" multiple
|
||||
:render-after-expand="true" show-checkbox check-strictly node-key="id"
|
||||
:props="showTagDialog.props" @check="tagTreeNodeCheck">
|
||||
<template #default="{ data }">
|
||||
<span class="custom-tree-node">
|
||||
<span style="font-size: 13px">
|
||||
{{ data.code }}
|
||||
<span style="color: #3c8dbc">【</span>
|
||||
{{ data.name }}
|
||||
<span style="color: #3c8dbc">】</span>
|
||||
<el-tag v-if="data.children !== null" size="small">{{ data.children.length }}
|
||||
</el-tag>
|
||||
</span>
|
||||
</span>
|
||||
</template>
|
||||
</el-tree-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="closeTagDialog()">取 消</el-button>
|
||||
<el-button v-auth="'team:tag:save'" @click="saveTags()" type="primary">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog width="700px" :title="showMemDialog.title" v-model="showMemDialog.visible">
|
||||
<div class="toolbar">
|
||||
<el-button v-auth="'team:member:save'" @click="showAddMemberDialog()" type="primary" icon="plus"
|
||||
size="small">添加</el-button>
|
||||
<el-button v-auth="'team:member:del'" @click="deleteMember" :disabled="showMemDialog.chooseId == null"
|
||||
type="danger" icon="delete" size="small">移除</el-button>
|
||||
<div style="float: right">
|
||||
<el-input placeholder="请输入用户名" class="mr2" style="width: 150px"
|
||||
v-model="showMemDialog.query.username" size="small" @clear="search" clearable></el-input>
|
||||
<el-button @click="setMemebers" type="success" icon="search" size="small"></el-button>
|
||||
</div>
|
||||
</div>
|
||||
<el-table @current-change="chooseMember" border :data="showMemDialog.members.list" size="small">
|
||||
<el-table-column label="选择" width="50px">
|
||||
<template #default="scope">
|
||||
<el-radio v-model="showMemDialog.chooseId" :label="scope.row.id">
|
||||
<i></i>
|
||||
</el-radio>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column property="name" label="姓名" width="115"></el-table-column>
|
||||
<el-table-column property="username" label="账号" width="135"></el-table-column>
|
||||
<el-table-column property="createTime" label="加入时间">
|
||||
<template #default="scope">
|
||||
{{ dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column property="creator" label="分配者" width="135"></el-table-column>
|
||||
</el-table>
|
||||
<el-pagination size="small" @current-change="setMemebers" style="text-align: center" background
|
||||
layout="prev, pager, next, total, jumper" :total="showMemDialog.members.total"
|
||||
v-model:current-page="showMemDialog.query.pageNum" :page-size="showMemDialog.query.pageSize" />
|
||||
|
||||
<el-dialog width="400px" title="添加成员" :before-close="cancelAddMember" v-model="showMemDialog.addVisible">
|
||||
<el-form :model="showMemDialog.memForm" label-width="70px">
|
||||
<el-form-item label="账号:">
|
||||
<el-select style="width: 100%" remote :remote-method="getAccount"
|
||||
v-model="showMemDialog.memForm.accountIds" filterable multiple placeholder="请输入账号模糊搜索并选择">
|
||||
<el-option v-for="item in showMemDialog.accounts" :key="item.id"
|
||||
:label="`${item.username} [${item.name}]`" :value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="cancelAddMember()">取 消</el-button>
|
||||
<el-button @click="addMember" type="primary">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, toRefs, reactive, onMounted } from 'vue';
|
||||
import { tagApi } from './api';
|
||||
import { accountApi } from '../../system/api';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import { dateFormat } from '@/common/utils/date';
|
||||
import { notBlank } from '@/common/assert';
|
||||
|
||||
const teamForm: any = ref(null);
|
||||
const tagTreeRef: any = ref(null);
|
||||
const state = reactive({
|
||||
currentEditPermissions: false,
|
||||
addTeamDialog: {
|
||||
title: '新增团队',
|
||||
visible: false,
|
||||
form: { id: 0, name: '', remark: '' },
|
||||
},
|
||||
query: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
name: null,
|
||||
},
|
||||
total: 0,
|
||||
data: [],
|
||||
chooseId: 0,
|
||||
chooseData: null,
|
||||
showMemDialog: {
|
||||
visible: false,
|
||||
chooseId: 0,
|
||||
chooseData: null,
|
||||
query: {
|
||||
pageSize: 10,
|
||||
pageNum: 1,
|
||||
teamId: null,
|
||||
username: null,
|
||||
},
|
||||
members: {
|
||||
list: [],
|
||||
total: null,
|
||||
},
|
||||
title: '',
|
||||
addVisible: false,
|
||||
memForm: {
|
||||
accountIds: [] as any,
|
||||
teamId: 0,
|
||||
},
|
||||
accounts: Array(),
|
||||
},
|
||||
showTagDialog: {
|
||||
title: '项目信息',
|
||||
visible: false,
|
||||
tags: [],
|
||||
teamId: 0,
|
||||
tagTreeTeams: [] as any,
|
||||
props: {
|
||||
value: 'id',
|
||||
label: 'codePath',
|
||||
children: 'children',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const {
|
||||
query,
|
||||
addTeamDialog,
|
||||
total,
|
||||
data,
|
||||
chooseId,
|
||||
chooseData,
|
||||
showMemDialog,
|
||||
showTagDialog,
|
||||
} = toRefs(state)
|
||||
|
||||
onMounted(() => {
|
||||
search();
|
||||
});
|
||||
|
||||
const search = async () => {
|
||||
let res = await tagApi.getTeams.request(state.query);
|
||||
state.data = 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 showSaveTeamDialog = (data: any) => {
|
||||
if (data) {
|
||||
state.addTeamDialog.form.id = data.id;
|
||||
state.addTeamDialog.form.name = data.name;
|
||||
state.addTeamDialog.form.remark = data.remark;
|
||||
state.addTeamDialog.title = `修改 [${data.codePath}] 信息`;
|
||||
}
|
||||
state.addTeamDialog.visible = true;
|
||||
};
|
||||
|
||||
const saveTeam = async () => {
|
||||
teamForm.value.validate(async (valid: any) => {
|
||||
if (valid) {
|
||||
const form = state.addTeamDialog.form;
|
||||
await tagApi.saveTeam.request(form);
|
||||
ElMessage.success('保存成功');
|
||||
search();
|
||||
cancelSaveTeam();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const cancelSaveTeam = () => {
|
||||
state.addTeamDialog.visible = false;
|
||||
state.addTeamDialog.form = {} as any;
|
||||
teamForm.value.resetFields();
|
||||
};
|
||||
|
||||
const deleteTeam = (data: any) => {
|
||||
ElMessageBox.confirm(`此操作将删除 [${data.name}], 是否继续?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
}).then(async () => {
|
||||
await tagApi.delTeam.request({ id: data.id });
|
||||
ElMessage.success('删除成功!');
|
||||
search();
|
||||
});
|
||||
};
|
||||
|
||||
/********** 团队成员相关 ***********/
|
||||
|
||||
const showMembers = async (team: any) => {
|
||||
state.showMemDialog.query.teamId = team.id;
|
||||
await setMemebers();
|
||||
state.showMemDialog.title = `[${team.name}] 成员信息`;
|
||||
state.showMemDialog.visible = true;
|
||||
};
|
||||
|
||||
const getAccount = (username: any) => {
|
||||
if (username) {
|
||||
accountApi.list.request({ username }).then((res) => {
|
||||
state.showMemDialog.accounts = res.list;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 选中成员
|
||||
*/
|
||||
const chooseMember = (item: any) => {
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
state.showMemDialog.chooseData = item;
|
||||
state.showMemDialog.chooseId = item.id;
|
||||
};
|
||||
|
||||
const deleteMember = async () => {
|
||||
await tagApi.delTeamMem.request(state.showMemDialog.chooseData);
|
||||
ElMessage.success('移除成功');
|
||||
// 重新赋值成员列表
|
||||
setMemebers();
|
||||
};
|
||||
|
||||
/**
|
||||
* 设置成员列表信息
|
||||
*/
|
||||
const setMemebers = async () => {
|
||||
const res = await tagApi.getTeamMem.request(state.showMemDialog.query);
|
||||
state.showMemDialog.members.list = res.list;
|
||||
state.showMemDialog.members.total = res.total;
|
||||
};
|
||||
|
||||
const showAddMemberDialog = () => {
|
||||
state.showMemDialog.addVisible = true;
|
||||
};
|
||||
|
||||
const addMember = async () => {
|
||||
const memForm = state.showMemDialog.memForm;
|
||||
memForm.teamId = state.chooseId;
|
||||
notBlank(memForm.accountIds, '请先选择账号');
|
||||
|
||||
await tagApi.saveTeamMem.request(memForm);
|
||||
ElMessage.success('保存成功');
|
||||
setMemebers();
|
||||
cancelAddMember();
|
||||
};
|
||||
|
||||
const cancelAddMember = () => {
|
||||
state.showMemDialog.memForm = {} as any;
|
||||
state.showMemDialog.addVisible = false;
|
||||
state.showMemDialog.chooseData = null;
|
||||
state.showMemDialog.chooseId = 0;
|
||||
};
|
||||
|
||||
/********** 标签相关 ***********/
|
||||
|
||||
const showTags = async (team: any) => {
|
||||
state.showTagDialog.tags = await tagApi.getTagTrees.request(null);
|
||||
state.showTagDialog.tagTreeTeams = await tagApi.getTeamTagIds.request({ teamId: team.id });
|
||||
state.showTagDialog.title = `[${team.name}] 团队标签信息`;
|
||||
state.showTagDialog.teamId = team.id;
|
||||
state.showTagDialog.visible = true;
|
||||
};
|
||||
|
||||
const closeTagDialog = () => {
|
||||
state.showTagDialog.visible = false;
|
||||
setTimeout(() => {
|
||||
state.showTagDialog.tagTreeTeams = [];
|
||||
}, 500);
|
||||
};
|
||||
|
||||
const saveTags = async () => {
|
||||
await tagApi.saveTeamTags.request({
|
||||
teamId: state.showTagDialog.teamId,
|
||||
tagIds: state.showTagDialog.tagTreeTeams,
|
||||
});
|
||||
ElMessage.success('保存成功');
|
||||
closeTagDialog();
|
||||
};
|
||||
|
||||
const tagTreeNodeCheck = () => {
|
||||
// const node = tagTreeRef.value.getNode(data.id);
|
||||
// console.log(node);
|
||||
// // state.showTagDialog.tagTreeTeams = [16]
|
||||
// if (node.checked) {
|
||||
// if (node.parent) {
|
||||
// console.log(node.parent);
|
||||
// // removeCheckedTagId(node.parent.key);
|
||||
// tagTreeRef.value.setChecked(node.parent, false, false);
|
||||
// }
|
||||
// // // parentNode = node.parent
|
||||
// // for (let parentNode of node.parent) {
|
||||
// // parentNode.setChecked(false);
|
||||
// // }
|
||||
// }
|
||||
// console.log(data);
|
||||
// console.log(checkInfo);
|
||||
};
|
||||
|
||||
// function removeCheckedTagId(id: any) {
|
||||
// console.log(state.showTagDialog.tagTreeTeams);
|
||||
// for (let i = 0; i < state.showTagDialog.tagTreeTeams.length; i++) {
|
||||
// if (state.showTagDialog.tagTreeTeams[i] == id) {
|
||||
// console.log('has id', id);
|
||||
// state.showTagDialog.tagTreeTeams.splice(i, 1);
|
||||
// }
|
||||
// }
|
||||
// console.log(state.showTagDialog.tagTreeTeams);
|
||||
// }
|
||||
</script>
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
||||
19
mayfly_go_web/src/views/ops/tag/api.ts
Normal file
19
mayfly_go_web/src/views/ops/tag/api.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import Api from '@/common/Api';
|
||||
|
||||
export const tagApi = {
|
||||
getAccountTags: Api.create("/tag-trees/account-has", 'get'),
|
||||
getTagTrees: Api.create("/tag-trees", 'get'),
|
||||
saveTagTree: Api.create("/tag-trees", 'post'),
|
||||
delTagTree: Api.create("/tag-trees/{id}", 'delete'),
|
||||
|
||||
getTeams: Api.create("/teams", 'get'),
|
||||
saveTeam: Api.create("/teams", 'post'),
|
||||
delTeam: Api.create("/teams/{id}", 'delete'),
|
||||
|
||||
getTeamMem: Api.create("/teams/{teamId}/members", 'get'),
|
||||
saveTeamMem: Api.create("/teams/{teamId}/members", 'post'),
|
||||
delTeamMem: Api.create("/teams/{teamId}/members/{accountId}", 'delete'),
|
||||
|
||||
getTeamTagIds: Api.create("/teams/{teamId}/tags", 'get'),
|
||||
saveTeamTags: Api.create("/teams/{teamId}/tags", 'post'),
|
||||
}
|
||||
@@ -12,8 +12,9 @@
|
||||
</div>
|
||||
<div class="personal-user-right">
|
||||
<el-row>
|
||||
<el-col :span="24" class="personal-title mb18"
|
||||
>{{ currentTime }},{{ getUserInfos.username }},生活变的再糟糕,也不妨碍我变得更好!
|
||||
<el-col :span="24" class="personal-title mb18">{{ currentTime }},{{
|
||||
getUserInfos.name
|
||||
}},生活变的再糟糕,也不妨碍我变得更好!
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
<el-row>
|
||||
@@ -35,7 +36,9 @@
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="16" class="personal-item mb6">
|
||||
<div class="personal-item-label">上次登录时间:</div>
|
||||
<div class="personal-item-value">{{ $filters.dateFormat(getUserInfos.lastLoginTime) }}</div>
|
||||
<div class="personal-item-value">{{
|
||||
dateFormat(getUserInfos.lastLoginTime)
|
||||
}}</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-col>
|
||||
@@ -54,7 +57,7 @@
|
||||
</template>
|
||||
<div class="personal-info-box">
|
||||
<ul class="personal-info-ul">
|
||||
<li v-for="(v, k) in msgDialog.msgs.list" :key="k" class="personal-info-li">
|
||||
<li v-for="(v, k) in msgDialog.msgs.list as any" :key="k" class="personal-info-li">
|
||||
<a class="personal-info-li-title">{{ `[${getMsgTypeDesc(v.type)}] ${v.msg}` }}</a>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -72,19 +75,13 @@
|
||||
<el-table-column property="msg" label="消息"></el-table-column>
|
||||
<el-table-column property="createTime" label="时间" width="150">
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.createTime) }}
|
||||
{{ dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
@current-change="getMsgs"
|
||||
style="text-align: center"
|
||||
background
|
||||
layout="prev, pager, next, total, jumper"
|
||||
:total="msgDialog.msgs.total"
|
||||
v-model:current-page="msgDialog.query.pageNum"
|
||||
:page-size="msgDialog.query.pageSize"
|
||||
/>
|
||||
<el-pagination @current-change="getMsgs" style="text-align: center" background
|
||||
layout="prev, pager, next, total, jumper" :total="msgDialog.msgs.total"
|
||||
v-model:current-page="msgDialog.query.pageNum" :page-size="msgDialog.query.pageSize" />
|
||||
</el-dialog>
|
||||
|
||||
<!-- 营销推荐 -->
|
||||
@@ -112,13 +109,8 @@
|
||||
<el-row :gutter="35">
|
||||
<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb20">
|
||||
<el-form-item label="密码">
|
||||
<el-input
|
||||
type="password"
|
||||
show-password
|
||||
v-model="accountForm.password"
|
||||
placeholder="请输入新密码"
|
||||
clearable
|
||||
></el-input>
|
||||
<el-input type="password" show-password v-model="accountForm.password"
|
||||
placeholder="请输入新密码" clearable></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<!-- -->
|
||||
@@ -181,17 +173,16 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, reactive, computed, onMounted } from 'vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { formatAxis } from '@/common/utils/formatTime.ts';
|
||||
import { recommendList } from './mock.ts';
|
||||
import { useStore } from '@/store/index.ts';
|
||||
import { personApi } from './api';
|
||||
export default {
|
||||
name: 'PersonalPage',
|
||||
setup() {
|
||||
import { dateFormat } from '@/common/utils/date';
|
||||
|
||||
const store = useStore();
|
||||
|
||||
const state = reactive({
|
||||
accountInfo: {
|
||||
roles: [],
|
||||
@@ -208,11 +199,17 @@ export default {
|
||||
total: null,
|
||||
},
|
||||
},
|
||||
recommendList,
|
||||
recommendList: [],
|
||||
accountForm: {
|
||||
password: '',
|
||||
},
|
||||
});
|
||||
|
||||
const {
|
||||
msgDialog,
|
||||
accountForm,
|
||||
} = toRefs(state)
|
||||
|
||||
// 当前时间提示语
|
||||
const currentTime = computed(() => {
|
||||
return formatAxis(new Date());
|
||||
@@ -261,42 +258,33 @@ export default {
|
||||
return '通知';
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
getUserInfos,
|
||||
currentTime,
|
||||
roleInfo,
|
||||
showMsgs,
|
||||
getAccountInfo,
|
||||
getMsgs,
|
||||
getMsgTypeDesc,
|
||||
updateAccount,
|
||||
...toRefs(state),
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@import '../../theme/mixins/mixins.scss';
|
||||
|
||||
.personal {
|
||||
.personal-user {
|
||||
height: 130px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.personal-user-left {
|
||||
width: 100px;
|
||||
height: 130px;
|
||||
border-radius: 3px;
|
||||
|
||||
::v-deep(.el-upload) {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.personal-user-left-upload {
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
img {
|
||||
animation: logoAnimation 0.3s ease-in-out;
|
||||
@@ -304,51 +292,63 @@ export default {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.personal-user-right {
|
||||
flex: 1;
|
||||
padding: 0 15px;
|
||||
|
||||
.personal-title {
|
||||
font-size: 18px;
|
||||
@include text-ellipsis(1);
|
||||
}
|
||||
|
||||
.personal-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 13px;
|
||||
|
||||
.personal-item-label {
|
||||
color: gray;
|
||||
@include text-ellipsis(1);
|
||||
}
|
||||
|
||||
.personal-item-value {
|
||||
@include text-ellipsis(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.personal-info {
|
||||
.personal-info-more {
|
||||
float: right;
|
||||
color: gray;
|
||||
font-size: 13px;
|
||||
|
||||
&:hover {
|
||||
color: var(--color-primary);
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.personal-info-box {
|
||||
height: 130px;
|
||||
overflow: hidden;
|
||||
|
||||
.personal-info-ul {
|
||||
list-style: none;
|
||||
|
||||
.personal-info-li {
|
||||
font-size: 13px;
|
||||
padding-bottom: 10px;
|
||||
|
||||
.personal-info-li-title {
|
||||
display: inline-block;
|
||||
@include text-ellipsis(1);
|
||||
color: grey;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
& a:hover {
|
||||
color: var(--color-primary);
|
||||
cursor: pointer;
|
||||
@@ -357,6 +357,7 @@ export default {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.personal-recommend-row {
|
||||
.personal-recommend-col {
|
||||
.personal-recommend {
|
||||
@@ -366,6 +367,7 @@ export default {
|
||||
border-radius: 3px;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
i {
|
||||
right: 0px !important;
|
||||
@@ -373,6 +375,7 @@ export default {
|
||||
transition: all ease 0.3s;
|
||||
}
|
||||
}
|
||||
|
||||
i {
|
||||
position: absolute;
|
||||
right: -10px;
|
||||
@@ -381,11 +384,13 @@ export default {
|
||||
transform: rotate(-30deg);
|
||||
transition: all ease 0.3s;
|
||||
}
|
||||
|
||||
.personal-recommend-auto {
|
||||
padding: 15px;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 5%;
|
||||
|
||||
.personal-recommend-msg {
|
||||
font-size: 12px;
|
||||
margin-top: 10px;
|
||||
@@ -394,11 +399,13 @@ export default {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.personal-edit {
|
||||
.personal-edit-title {
|
||||
position: relative;
|
||||
padding-left: 10px;
|
||||
color: #606266;
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
width: 2px;
|
||||
@@ -410,21 +417,26 @@ export default {
|
||||
background: var(--color-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.personal-edit-safe-box {
|
||||
border-bottom: 1px solid #ebeef5;
|
||||
padding: 15px 0;
|
||||
|
||||
.personal-edit-safe-item {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.personal-edit-safe-item-left {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
|
||||
.personal-edit-safe-item-left-label {
|
||||
color: #606266;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.personal-edit-safe-item-left-value {
|
||||
color: gray;
|
||||
@include text-ellipsis(1);
|
||||
@@ -432,6 +444,7 @@ export default {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&:last-of-type {
|
||||
padding-bottom: 0;
|
||||
border-bottom: none;
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
<template>
|
||||
<div class="account-dialog">
|
||||
<el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :show-close="false" width="35%" :destroy-on-close="true">
|
||||
<el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :show-close="false" width="35%"
|
||||
:destroy-on-close="true">
|
||||
<el-form :model="form" ref="accountForm" :rules="rules" label-width="85px">
|
||||
<el-form-item prop="name" label="姓名:" required>
|
||||
<el-input v-model.trim="form.name" placeholder="请输入姓名" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="username" label="用户名:" required>
|
||||
<el-input :disabled="edit" v-model.trim="form.username" placeholder="请输入账号用户名,密码默认与账号名一致" auto-complete="off"></el-input>
|
||||
<el-input :disabled="edit" v-model.trim="form.username" placeholder="请输入账号用户名,密码默认与账号名一致"
|
||||
auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<!-- <el-form-item prop="password" label="密码:" required>
|
||||
<el-input type="password" v-model.trim="form.password" placeholder="请输入密码" autocomplete="new-password"></el-input>
|
||||
<el-form-item v-if="edit" prop="password" label="密码:">
|
||||
<el-input type="password" v-model.trim="form.password" placeholder="输入密码可修改用户密码"
|
||||
autocomplete="new-password"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="!edit" label="确认密码:" required>
|
||||
<el-input type="password" v-model.trim="form.repassword" placeholder="请输入确认密码" autocomplete="new-password"></el-input>
|
||||
</el-form-item> -->
|
||||
</el-form>
|
||||
|
||||
<template #footer>
|
||||
@@ -23,14 +26,12 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, reactive, watch, ref } from 'vue';
|
||||
import { accountApi } from '../api';
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'AccountEdit',
|
||||
props: {
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -40,20 +41,21 @@ export default defineComponent({
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
})
|
||||
|
||||
//定义事件
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'val-change'])
|
||||
|
||||
const accountForm: any = ref(null);
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
edit: false,
|
||||
form: {
|
||||
id: null,
|
||||
username: null,
|
||||
password: null,
|
||||
repassword: null,
|
||||
|
||||
const rules = {
|
||||
name: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入姓名',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
btnLoading: false,
|
||||
rules: {
|
||||
],
|
||||
username: [
|
||||
{
|
||||
required: true,
|
||||
@@ -61,31 +63,43 @@ export default defineComponent({
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
// password: [
|
||||
// {
|
||||
// required: true,
|
||||
// message: '请输入密码',
|
||||
// trigger: ['change', 'blur'],
|
||||
// },
|
||||
// ],
|
||||
}
|
||||
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
edit: false,
|
||||
form: {
|
||||
id: null,
|
||||
name: null,
|
||||
username: null,
|
||||
password: null,
|
||||
repassword: null,
|
||||
},
|
||||
btnLoading: false
|
||||
});
|
||||
|
||||
watch(props, (newValue) => {
|
||||
const {
|
||||
dialogVisible,
|
||||
edit,
|
||||
form,
|
||||
btnLoading,
|
||||
} = toRefs(state)
|
||||
|
||||
watch(props, (newValue: any) => {
|
||||
if (newValue.account) {
|
||||
state.form = { ...newValue.account };
|
||||
state.edit = true;
|
||||
} else {
|
||||
state.edit = false;
|
||||
state.form = {} as any;
|
||||
}
|
||||
state.dialogVisible = newValue.visible;
|
||||
});
|
||||
|
||||
const btnOk = async () => {
|
||||
let p = state.form.id ? accountApi.update : accountApi.save;
|
||||
|
||||
accountForm.value.validate((valid: boolean) => {
|
||||
if (valid) {
|
||||
p.request(state.form).then(() => {
|
||||
accountApi.save.request(state.form).then(() => {
|
||||
ElMessage.success('操作成功');
|
||||
emit('val-change', state.form);
|
||||
state.btnLoading = true;
|
||||
@@ -107,15 +121,7 @@ export default defineComponent({
|
||||
emit('update:visible', false);
|
||||
emit('cancel');
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
accountForm,
|
||||
btnOk,
|
||||
cancel,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
||||
|
||||
@@ -2,55 +2,50 @@
|
||||
<div class="role-list">
|
||||
<el-card>
|
||||
<el-button v-auth="'account:add'" type="primary" icon="plus" @click="editAccount(true)">添加</el-button>
|
||||
<!-- <el-button v-auth="'account:update'" :disabled="chooseId == null" @click="editAccount(false)" type="primary" icon="edit">编辑</el-button> -->
|
||||
<el-button v-auth="'account:saveRoles'" :disabled="chooseId == null" @click="roleEdit()" type="success" icon="setting"
|
||||
>角色分配</el-button
|
||||
>
|
||||
<el-button v-auth="'account:del'" :disabled="chooseId == null" @click="deleteAccount()" type="danger" icon="delete">删除</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="showRoleEdit()" type="success"
|
||||
icon="setting">角色分配</el-button>
|
||||
<el-button v-auth="'account:del'" :disabled="chooseId == null" @click="deleteAccount()" type="danger"
|
||||
icon="delete">删除</el-button>
|
||||
<div style="float: right">
|
||||
<el-input
|
||||
class="mr2"
|
||||
placeholder="请输入账号名"
|
||||
size="small"
|
||||
style="width: 300px"
|
||||
v-model="query.username"
|
||||
@clear="search()"
|
||||
clearable
|
||||
></el-input>
|
||||
<el-input class="mr2" placeholder="请输入账号名" size="small" style="width: 300px" v-model="query.username"
|
||||
@clear="search()" clearable></el-input>
|
||||
<el-button @click="search()" type="success" icon="search" size="small"></el-button>
|
||||
</div>
|
||||
<el-table :data="datas" ref="table" @current-change="choose" show-overflow-tooltip>
|
||||
<el-table-column label="选择" width="50px">
|
||||
<el-table-column label="选择" width="55px">
|
||||
<template #default="scope">
|
||||
<el-radio v-model="chooseId" :label="scope.row.id">
|
||||
<i></i>
|
||||
</el-radio>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="name" 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="70">
|
||||
<template #default="scope">
|
||||
<el-tag v-if="scope.row.status == 1" type="success">正常</el-tag>
|
||||
<el-tag v-if="scope.row.status == -1" type="danger">禁用</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column min-width="160" prop="lastLoginTime" label="最后登录时间">
|
||||
<el-table-column min-width="160" prop="lastLoginTime" label="最后登录时间" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.lastLoginTime) }}
|
||||
{{ dateFormat(scope.row.lastLoginTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column min-width="115" prop="creator" label="创建账号"></el-table-column>
|
||||
<el-table-column min-width="160" prop="createTime" label="创建时间">
|
||||
<el-table-column min-width="160" prop="createTime" label="创建时间" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.createTime) }}
|
||||
{{ dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<!-- <el-table-column min-width="115" prop="modifier" label="更新账号"></el-table-column>
|
||||
<el-table-column min-width="160" prop="updateTime" label="修改时间">
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.updateTime) }}
|
||||
{{ dateFormat(scope.row.updateTime) }}
|
||||
</template>
|
||||
</el-table-column> -->
|
||||
|
||||
@@ -65,37 +60,17 @@
|
||||
|
||||
<el-table-column label="操作" min-width="200px">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
v-auth="'account:changeStatus'"
|
||||
@click="changeStatus(scope.row)"
|
||||
v-if="scope.row.status == 1"
|
||||
type="danger"
|
||||
icom="tickets"
|
||||
size="small"
|
||||
plain
|
||||
>禁用</el-button
|
||||
>
|
||||
<el-button
|
||||
v-auth="'account:changeStatus'"
|
||||
v-if="scope.row.status == -1"
|
||||
type="success"
|
||||
@click="changeStatus(scope.row)"
|
||||
size="small"
|
||||
plain
|
||||
>启用</el-button
|
||||
>
|
||||
<el-button v-auth="'account:changeStatus'" @click="changeStatus(scope.row)"
|
||||
v-if="scope.row.status == 1" type="danger" icom="tickets" size="small" plain>禁用</el-button>
|
||||
<el-button v-auth="'account:changeStatus'" v-if="scope.row.status == -1" type="success"
|
||||
@click="changeStatus(scope.row)" 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"
|
||||
@current-change="handlePageChange"
|
||||
:total="total"
|
||||
layout="prev, pager, next, total, jumper"
|
||||
v-model:current-page="query.pageNum"
|
||||
:page-size="query.pageSize"
|
||||
></el-pagination>
|
||||
<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>
|
||||
|
||||
@@ -105,48 +80,41 @@
|
||||
<el-table-column property="creator" label="分配账号" width="125"></el-table-column>
|
||||
<el-table-column property="createTime" label="分配时间">
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.createTime) }}
|
||||
{{ dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog :title="showResourceDialog.title" v-model="showResourceDialog.visible" width="400px">
|
||||
<el-tree
|
||||
style="height: 50vh; overflow: auto"
|
||||
:data="showResourceDialog.resources"
|
||||
node-key="id"
|
||||
:props="showResourceDialog.defaultProps"
|
||||
:expand-on-click-node="true"
|
||||
>
|
||||
<el-tree style="height: 50vh; overflow: auto" :data="showResourceDialog.resources" node-key="id"
|
||||
:props="showResourceDialog.defaultProps" :expand-on-click-node="true">
|
||||
<template #default="{ node, data }">
|
||||
<span class="custom-tree-node">
|
||||
<span v-if="data.type == enums.ResourceTypeEnum.MENU.value">{{ node.label }}</span>
|
||||
<span v-if="data.type == enums.ResourceTypeEnum.PERMISSION.value" style="color: #67c23a">{{ node.label }}</span>
|
||||
<span v-if="data.type == enums.ResourceTypeEnum['MENU'].value">{{ node.label }}</span>
|
||||
<span v-if="data.type == enums.ResourceTypeEnum['PERMISSION'].value" style="color: #67c23a">{{
|
||||
node.label
|
||||
}}</span>
|
||||
</span>
|
||||
</template>
|
||||
</el-tree>
|
||||
</el-dialog>
|
||||
|
||||
<role-edit v-model:visible="roleDialog.visible" :account="roleDialog.account" @cancel="cancel()" />
|
||||
<account-edit v-model:visible="accountDialog.visible" v-model:account="accountDialog.data" @val-change="valChange()" />
|
||||
<account-edit v-model:visible="accountDialog.visible" v-model:account="accountDialog.data"
|
||||
@val-change="valChange()" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang='ts'>
|
||||
import { toRefs, reactive, onMounted, defineComponent } from 'vue';
|
||||
<script lang='ts' setup>
|
||||
import { toRefs, reactive, onMounted } from 'vue';
|
||||
import RoleEdit from './RoleEdit.vue';
|
||||
import AccountEdit from './AccountEdit.vue';
|
||||
import enums from '../enums';
|
||||
import { accountApi } from '../api';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
export default defineComponent({
|
||||
name: 'AccountList',
|
||||
components: {
|
||||
RoleEdit,
|
||||
AccountEdit,
|
||||
},
|
||||
setup() {
|
||||
import { dateFormat } from '@/common/utils/date';
|
||||
|
||||
const state = reactive({
|
||||
chooseId: null,
|
||||
/**
|
||||
@@ -157,6 +125,7 @@ export default defineComponent({
|
||||
* 查询条件
|
||||
*/
|
||||
query: {
|
||||
username: '',
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
},
|
||||
@@ -178,15 +147,26 @@ export default defineComponent({
|
||||
},
|
||||
roleDialog: {
|
||||
visible: false,
|
||||
account: null,
|
||||
account: null as any,
|
||||
roles: [],
|
||||
},
|
||||
accountDialog: {
|
||||
visible: false,
|
||||
data: null,
|
||||
data: null as any,
|
||||
},
|
||||
});
|
||||
|
||||
const {
|
||||
chooseId,
|
||||
query,
|
||||
datas,
|
||||
total,
|
||||
showRoleDialog,
|
||||
showResourceDialog,
|
||||
roleDialog,
|
||||
accountDialog,
|
||||
} = toRefs(state)
|
||||
|
||||
onMounted(() => {
|
||||
search();
|
||||
});
|
||||
@@ -240,7 +220,7 @@ export default defineComponent({
|
||||
search();
|
||||
};
|
||||
|
||||
const roleEdit = () => {
|
||||
const showRoleEdit = () => {
|
||||
if (!state.chooseId) {
|
||||
ElMessage.error('请选择账号');
|
||||
}
|
||||
@@ -282,24 +262,7 @@ export default defineComponent({
|
||||
search();
|
||||
} catch (err) { }
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
enums,
|
||||
search,
|
||||
choose,
|
||||
showResources,
|
||||
showRoles,
|
||||
changeStatus,
|
||||
handlePageChange,
|
||||
roleEdit,
|
||||
editAccount,
|
||||
cancel,
|
||||
valChange,
|
||||
deleteAccount,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
<template>
|
||||
<div class="account-dialog">
|
||||
<el-dialog
|
||||
:title="account == null ? '' : '分配“' + account.username + '”的角色'"
|
||||
v-model="dialogVisible"
|
||||
:before-close="cancel"
|
||||
:show-close="false"
|
||||
>
|
||||
<el-dialog :title="account == null ? '' : '分配“' + account.username + '”的角色'" v-model="dialogVisible"
|
||||
:before-close="cancel" :show-close="false">
|
||||
<div class="toolbar">
|
||||
<div style="float: left">
|
||||
<el-input placeholder="请输入角色名" style="width: 150px" v-model="query.name" @clear="clear()" clearable></el-input>
|
||||
<el-input placeholder="请输入角色名" style="width: 150px" v-model="query.name" @clear="clear()" clearable>
|
||||
</el-input>
|
||||
<el-button @click="search" type="success" icon="search"></el-button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -22,15 +19,9 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
@current-change="handlePageChange"
|
||||
style="text-align: center; margin-top: 20px"
|
||||
background
|
||||
layout="prev, pager, next, total, jumper"
|
||||
:total="total"
|
||||
v-model:current-page="query.pageNum"
|
||||
:page-size="query.pageSize"
|
||||
></el-pagination>
|
||||
<el-pagination @current-change="handlePageChange" style="text-align: center; margin-top: 20px" background
|
||||
layout="prev, pager, next, total, jumper" :total="total" v-model:current-page="query.pageNum"
|
||||
:page-size="query.pageSize"></el-pagination>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
@@ -42,29 +33,29 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, reactive, watch, ref } from 'vue';
|
||||
import { roleApi, accountApi } from '../api';
|
||||
import { ElMessage } from 'element-plus';
|
||||
export default defineComponent({
|
||||
name: 'RoleEdit',
|
||||
props: {
|
||||
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
account: {
|
||||
type: [Boolean, Object],
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
account: Object
|
||||
})
|
||||
|
||||
//定义事件
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'val-change'])
|
||||
|
||||
const roleTable: any = ref(null);
|
||||
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
btnLoading: false,
|
||||
// 所有角色
|
||||
allRole: [] as any,
|
||||
// 该账号拥有的角色id
|
||||
roles: [] as any,
|
||||
query: {
|
||||
name: null,
|
||||
pageNum: 1,
|
||||
@@ -73,19 +64,28 @@ export default defineComponent({
|
||||
total: 0,
|
||||
});
|
||||
|
||||
watch(props, (newValue) => {
|
||||
const {
|
||||
dialogVisible,
|
||||
btnLoading,
|
||||
allRole,
|
||||
query,
|
||||
total,
|
||||
} = toRefs(state)
|
||||
|
||||
// 用户拥有的角色信息
|
||||
let roles: any[] = []
|
||||
|
||||
watch(props, (newValue: any) => {
|
||||
state.dialogVisible = newValue.visible;
|
||||
if (newValue.account && newValue.account.id != 0) {
|
||||
if (state.dialogVisible && newValue.account && newValue.account.id != 0) {
|
||||
accountApi.roleIds
|
||||
.request({
|
||||
id: props.account['id'],
|
||||
id: props.account!.id,
|
||||
})
|
||||
.then((res) => {
|
||||
state.roles = res || [];
|
||||
roles = res || [];
|
||||
search();
|
||||
});
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -99,7 +99,6 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const select = (val: any, row: any) => {
|
||||
let roles = state.roles;
|
||||
// 如果账号的角色id存在则为取消该角色(删除角色id列表中的该记录id),否则为新增角色
|
||||
if (roles.includes(row.id)) {
|
||||
for (let i = 0; i < roles.length; i++) {
|
||||
@@ -122,7 +121,7 @@ export default defineComponent({
|
||||
setTimeout(() => {
|
||||
roleTable.value.clearSelection();
|
||||
state.allRole.forEach((r: any) => {
|
||||
if (state.roles.includes(r.id)) {
|
||||
if (roles.includes(r.id)) {
|
||||
roleTable.value.toggleRowSelection(r, true);
|
||||
}
|
||||
});
|
||||
@@ -130,9 +129,9 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const btnOk = async () => {
|
||||
let roleIds = state.roles.join(',');
|
||||
let roleIds = roles.join(',');
|
||||
await accountApi.saveRoles.request({
|
||||
id: props.account['id'],
|
||||
id: props.account!.id,
|
||||
roleIds: roleIds,
|
||||
});
|
||||
ElMessage.success('保存成功!');
|
||||
@@ -164,18 +163,4 @@ export default defineComponent({
|
||||
state.total = res.total;
|
||||
checkSelected();
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
roleTable,
|
||||
search,
|
||||
handlePageChange,
|
||||
selectable,
|
||||
select,
|
||||
btnOk,
|
||||
cancel,
|
||||
clear,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -32,6 +32,12 @@ export const accountApi = {
|
||||
saveRoles: Api.create("/sys/accounts/roles", 'post')
|
||||
}
|
||||
|
||||
export const configApi = {
|
||||
list: Api.create("/sys/configs", 'get'),
|
||||
save: Api.create("/sys/configs", 'post'),
|
||||
getValue: Api.create("/sys/configs/value", 'get'),
|
||||
}
|
||||
|
||||
export const logApi = {
|
||||
list: Api.create("/syslogs", "get")
|
||||
}
|
||||
|
||||
148
mayfly_go_web/src/views/system/config/ConfigEdit.vue
Executable file
148
mayfly_go_web/src/views/system/config/ConfigEdit.vue
Executable file
@@ -0,0 +1,148 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-dialog :title="title" v-model="dvisible" :show-close="false" :before-close="cancel" width="750px"
|
||||
: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-row style="margin-left: 30px; margin-bottom: 5px">
|
||||
<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 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" setup>
|
||||
import { ref, toRefs, reactive, watch } from 'vue';
|
||||
import { configApi } from '../api';
|
||||
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
data: {
|
||||
type: [Boolean, Object],
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
})
|
||||
|
||||
//定义事件
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'val-change'])
|
||||
|
||||
|
||||
const configForm: any = ref(null);
|
||||
|
||||
const state = reactive({
|
||||
dvisible: false,
|
||||
params: [] as any,
|
||||
form: {
|
||||
id: null,
|
||||
name: '',
|
||||
key: '',
|
||||
params: '',
|
||||
value: '',
|
||||
remark: '',
|
||||
},
|
||||
btnLoading: false,
|
||||
});
|
||||
|
||||
const {
|
||||
dvisible,
|
||||
params,
|
||||
form,
|
||||
btnLoading,
|
||||
} = toRefs(state)
|
||||
|
||||
watch(props, (newValue: any) => {
|
||||
state.dvisible = newValue.visible;
|
||||
if (newValue.data) {
|
||||
state.form = { ...newValue.data };
|
||||
if (state.form.params) {
|
||||
state.params = JSON.parse(state.form.params);
|
||||
} else {
|
||||
state.params = [];
|
||||
}
|
||||
} else {
|
||||
state.form = {} as any;
|
||||
state.params = [];
|
||||
}
|
||||
});
|
||||
|
||||
const onAddParam = () => {
|
||||
state.params.push({ name: '', model: '', placeholder: '' });
|
||||
};
|
||||
|
||||
const onDeleteParam = (idx: number) => {
|
||||
state.params.splice(idx, 1);
|
||||
};
|
||||
|
||||
const cancel = () => {
|
||||
// 更新父组件visible prop对应的值为false
|
||||
emit('update:visible', false);
|
||||
// 若父组件有取消事件,则调用
|
||||
emit('cancel');
|
||||
};
|
||||
|
||||
const btnOk = async () => {
|
||||
configForm.value.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
if (state.params) {
|
||||
state.form.params = JSON.stringify(state.params);
|
||||
}
|
||||
await configApi.save.request(state.form);
|
||||
emit('val-change', state.form);
|
||||
cancel();
|
||||
state.btnLoading = true;
|
||||
setTimeout(() => {
|
||||
state.btnLoading = false;
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
};
|
||||
</script>
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
||||
211
mayfly_go_web/src/views/system/config/ConfigList.vue
Executable file
211
mayfly_go_web/src/views/system/config/ConfigList.vue
Executable file
@@ -0,0 +1,211 @@
|
||||
<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="更新时间" min-width="100px">
|
||||
<template #default="scope">
|
||||
{{ dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="modifier" label="修改者" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column label="操作" min-width="50" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-link :disabled="scope.row.status == -1" type="warning"
|
||||
@click="showSetConfigDialog(scope.row)" plain size="small" :underline="false">配置</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-row style="margin-top: 20px" type="flex" justify="end">
|
||||
<el-pagination style="text-align: right" @current-change="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>
|
||||
|
||||
<el-dialog :before-close="closeSetConfigDialog" title="配置项设置" v-model="paramsDialog.visible" width="500px">
|
||||
<el-form v-if="paramsDialog.paramsFormItem.length > 0" ref="paramsForm" :model="paramsDialog.params"
|
||||
label-width="90px">
|
||||
<el-form-item v-for="item in paramsDialog.paramsFormItem" :key="item.name" :prop="item.model"
|
||||
:label="item.name" required>
|
||||
<el-input v-if="!item.options" v-model="paramsDialog.params[item.model]"
|
||||
:placeholder="item.placeholder" autocomplete="off" clearable></el-input>
|
||||
<el-select v-else v-model="paramsDialog.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>
|
||||
<el-form v-else ref="paramsForm" label-width="90px">
|
||||
<el-form-item label="配置值" required>
|
||||
<el-input v-model="paramsDialog.params" :placeholder="paramsDialog.config.remark" autocomplete="off"
|
||||
clearable></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
<el-button @click="closeSetConfigDialog()">取 消</el-button>
|
||||
<el-button type="primary" @click="setConfig()">确 定</el-button>
|
||||
</span>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<config-edit :title="configEdit.title" v-model:visible="configEdit.visible" :data="configEdit.config"
|
||||
@val-change="configEditChange" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, reactive, onMounted } from 'vue';
|
||||
import ConfigEdit from './ConfigEdit.vue';
|
||||
import { configApi } from '../api';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { dateFormat } from '@/common/utils/date';
|
||||
|
||||
const state = reactive({
|
||||
query: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
name: null,
|
||||
},
|
||||
total: 0,
|
||||
configs: [],
|
||||
chooseId: null,
|
||||
chooseData: null,
|
||||
paramsDialog: {
|
||||
visible: false,
|
||||
config: null as any,
|
||||
params: {},
|
||||
paramsFormItem: [] as any,
|
||||
},
|
||||
configEdit: {
|
||||
title: '配置修改',
|
||||
visible: false,
|
||||
config: {},
|
||||
},
|
||||
});
|
||||
|
||||
const {
|
||||
query,
|
||||
total,
|
||||
configs,
|
||||
chooseId,
|
||||
chooseData,
|
||||
paramsDialog,
|
||||
configEdit,
|
||||
} = toRefs(state)
|
||||
|
||||
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 showSetConfigDialog = (row: any) => {
|
||||
state.paramsDialog.config = row;
|
||||
// 存在配置项则弹窗提示输入对应的配置项
|
||||
if (row.params) {
|
||||
state.paramsDialog.paramsFormItem = JSON.parse(row.params);
|
||||
if (state.paramsDialog.paramsFormItem && state.paramsDialog.paramsFormItem.length > 0) {
|
||||
if (row.value) {
|
||||
state.paramsDialog.params = JSON.parse(row.value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
state.paramsDialog.params = row.value;
|
||||
}
|
||||
state.paramsDialog.visible = true;
|
||||
};
|
||||
|
||||
const closeSetConfigDialog = () => {
|
||||
state.paramsDialog.visible = false;
|
||||
setTimeout(() => {
|
||||
state.paramsDialog.config = {};
|
||||
state.paramsDialog.params = {};
|
||||
state.paramsDialog.paramsFormItem = [];
|
||||
}, 300);
|
||||
};
|
||||
|
||||
const setConfig = async () => {
|
||||
let paramsValue = state.paramsDialog.params;
|
||||
if (state.paramsDialog.paramsFormItem.length > 0) {
|
||||
// 如果配置项删除,则需要将value中对应的字段移除
|
||||
for (let paramKey in paramsValue) {
|
||||
if (!hasParam(paramKey, state.paramsDialog.paramsFormItem)) {
|
||||
delete paramsValue[paramKey];
|
||||
}
|
||||
}
|
||||
paramsValue = JSON.stringify(paramsValue);
|
||||
}
|
||||
await configApi.save.request({
|
||||
id: state.paramsDialog.config.id,
|
||||
key: state.paramsDialog.config.key,
|
||||
name: state.paramsDialog.config.name,
|
||||
value: paramsValue,
|
||||
});
|
||||
ElMessage.success('保存成功');
|
||||
closeSetConfigDialog();
|
||||
search();
|
||||
};
|
||||
|
||||
const hasParam = (paramKey: string, paramItems: any) => {
|
||||
for (let paramItem of paramItems) {
|
||||
if (paramItem.model == paramKey) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
</script>
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
||||
@@ -6,7 +6,8 @@
|
||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb10">
|
||||
<el-form-item prop="type" label="类型" required>
|
||||
<el-select v-model="form.type" :disabled="typeDisabled" placeholder="请选择">
|
||||
<el-option v-for="item in enums.ResourceTypeEnum" :key="item.value" :label="item.label" :value="item.value">
|
||||
<el-option v-for="item in enums.ResourceTypeEnum as any" :key="item.value" :label="item.label"
|
||||
:value="item.value">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
@@ -27,55 +28,56 @@
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb10">
|
||||
<el-form-item v-if="form.type === enums.ResourceTypeEnum.MENU.value" label="图标">
|
||||
<el-form-item v-if="form.type === menuTypeValue" label="图标">
|
||||
<icon-selector v-model="form.meta.icon" type="ele" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb10">
|
||||
<el-form-item v-if="form.type === enums.ResourceTypeEnum.MENU.value" prop="code" label="路由名">
|
||||
<el-form-item v-if="form.type === menuTypeValue" prop="code" label="路由名">
|
||||
<el-input v-model.trim="form.meta.routeName" placeholder="请输入路由名称"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb10">
|
||||
<el-form-item v-if="form.type === enums.ResourceTypeEnum.MENU.value" prop="code" label="组件">
|
||||
<el-form-item v-if="form.type === menuTypeValue" prop="code" label="组件">
|
||||
<el-input v-model.trim="form.meta.component" placeholder="请输入组件名"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb10">
|
||||
<el-form-item v-if="form.type === enums.ResourceTypeEnum.MENU.value" prop="code" label="是否缓存">
|
||||
<el-form-item v-if="form.type === menuTypeValue" prop="code" label="是否缓存">
|
||||
<el-select v-model="form.meta.isKeepAlive" placeholder="请选择" width="w100">
|
||||
<el-option v-for="item in trueFalseOption" :key="item.value" :label="item.label" :value="item.value"> </el-option>
|
||||
<el-option v-for="item in trueFalseOption" :key="item.value" :label="item.label"
|
||||
:value="item.value"> </el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb10">
|
||||
<el-form-item v-if="form.type === enums.ResourceTypeEnum.MENU.value" prop="code" label="是否隐藏">
|
||||
<el-form-item v-if="form.type === menuTypeValue" prop="code" label="是否隐藏">
|
||||
<el-select v-model="form.meta.isHide" placeholder="请选择" width="w100">
|
||||
<el-option v-for="item in trueFalseOption" :key="item.value" :label="item.label" :value="item.value"> </el-option>
|
||||
<el-option v-for="item in trueFalseOption" :key="item.value" :label="item.label"
|
||||
:value="item.value"> </el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb10">
|
||||
<el-form-item v-if="form.type === enums.ResourceTypeEnum.MENU.value" prop="code" label="tag不可删除">
|
||||
<el-form-item v-if="form.type === menuTypeValue" prop="code" label="tag不可删除">
|
||||
<el-select v-model="form.meta.isAffix" placeholder="请选择" width="w100">
|
||||
<el-option v-for="item in trueFalseOption" :key="item.value" :label="item.label" :value="item.value"> </el-option>
|
||||
<el-option v-for="item in trueFalseOption" :key="item.value" :label="item.label"
|
||||
:value="item.value"> </el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb10">
|
||||
<el-form-item v-if="form.type === enums.ResourceTypeEnum.MENU.value" prop="code" label="是否iframe">
|
||||
<el-select @change="changeIsIframe" v-model="form.meta.isIframe" placeholder="请选择" width="w100">
|
||||
<el-option v-for="item in trueFalseOption" :key="item.value" :label="item.label" :value="item.value"> </el-option>
|
||||
<el-form-item v-if="form.type === menuTypeValue" prop="code" label="是否iframe">
|
||||
<el-select @change="changeIsIframe" v-model="form.meta.isIframe" placeholder="请选择"
|
||||
width="w100">
|
||||
<el-option v-for="item in trueFalseOption" :key="item.value" :label="item.label"
|
||||
:value="item.value"> </el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb10">
|
||||
<el-form-item
|
||||
v-if="form.type === enums.ResourceTypeEnum.MENU.value && form.meta.isIframe"
|
||||
prop="code"
|
||||
label="iframe地址"
|
||||
width="w100"
|
||||
>
|
||||
<el-form-item v-if="form.type === menuTypeValue && form.meta.isIframe" prop="code"
|
||||
label="iframe地址" width="w100">
|
||||
<el-input v-model.trim="form.meta.link" placeholder="请输入iframe url"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@@ -92,20 +94,15 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { ref, toRefs, reactive, watch, defineComponent } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { ref, toRefs, reactive, watch } from 'vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { resourceApi } from '../api';
|
||||
import enums from '../enums';
|
||||
import { notEmpty } from '@/common/assert';
|
||||
import iconSelector from '@/components/iconSelector/index.vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ResourceEdit',
|
||||
components: {
|
||||
iconSelector,
|
||||
},
|
||||
props: {
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -118,10 +115,15 @@ export default defineComponent({
|
||||
typeDisabled: {
|
||||
type: Boolean,
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
})
|
||||
|
||||
//定义事件
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'val-change'])
|
||||
|
||||
const menuForm: any = ref(null);
|
||||
|
||||
const menuTypeValue = enums.ResourceTypeEnum['MENU'].value
|
||||
|
||||
const defaultMeta = {
|
||||
routeName: '',
|
||||
icon: 'Menu',
|
||||
@@ -131,10 +133,27 @@ export default defineComponent({
|
||||
isHide: false,
|
||||
isAffix: false,
|
||||
isIframe: false,
|
||||
link: '',
|
||||
};
|
||||
|
||||
const state = reactive({
|
||||
trueFalseOption: [
|
||||
const rules = {
|
||||
name: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入资源名称',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
weight: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入序号',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const trueFalseOption = [
|
||||
{
|
||||
label: '是',
|
||||
value: true,
|
||||
@@ -143,19 +162,10 @@ export default defineComponent({
|
||||
label: '否',
|
||||
value: false,
|
||||
},
|
||||
],
|
||||
]
|
||||
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
//弹出框对象
|
||||
dialogForm: {
|
||||
title: '',
|
||||
visible: false,
|
||||
data: {},
|
||||
},
|
||||
props: {
|
||||
value: 'id',
|
||||
label: 'name',
|
||||
children: 'children',
|
||||
},
|
||||
form: {
|
||||
id: null,
|
||||
name: null,
|
||||
@@ -172,30 +182,19 @@ export default defineComponent({
|
||||
isHide: false,
|
||||
isAffix: false,
|
||||
isIframe: false,
|
||||
link: '',
|
||||
},
|
||||
},
|
||||
// 资源类型选择是否禁用
|
||||
// typeDisabled: false,
|
||||
btnLoading: false,
|
||||
rules: {
|
||||
name: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入资源名称',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
weight: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入序号',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
watch(props, (newValue) => {
|
||||
const {
|
||||
dialogVisible,
|
||||
form,
|
||||
btnLoading,
|
||||
} = toRefs(state)
|
||||
|
||||
watch(props, (newValue: any) => {
|
||||
state.dialogVisible = newValue.visible;
|
||||
if (newValue.data) {
|
||||
state.form = { ...newValue.data };
|
||||
@@ -285,17 +284,6 @@ export default defineComponent({
|
||||
emit('update:visible', false);
|
||||
emit('cancel');
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
enums,
|
||||
changeIsIframe,
|
||||
menuForm,
|
||||
btnOk,
|
||||
cancel,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
// .m-dialog {
|
||||
|
||||
@@ -2,100 +2,57 @@
|
||||
<div class="menu">
|
||||
<div class="toolbar">
|
||||
<div>
|
||||
<span style="font-size: 14px"><SvgIcon name="info-filled"/>红色字体表示禁用状态</span>
|
||||
<span style="font-size: 14px">
|
||||
<SvgIcon name="info-filled" />红色字体表示禁用状态
|
||||
</span>
|
||||
</div>
|
||||
<el-button v-auth="'resource:add'" type="primary" icon="plus" @click="addResource(false)">添加</el-button>
|
||||
</div>
|
||||
<el-tree
|
||||
class="none-select"
|
||||
:indent="38"
|
||||
node-key="id"
|
||||
:props="props"
|
||||
:data="data"
|
||||
@node-expand="handleNodeExpand"
|
||||
@node-collapse="handleNodeCollapse"
|
||||
:default-expanded-keys="defaultExpandedKeys"
|
||||
:expand-on-click-node="false"
|
||||
>
|
||||
<el-tree class="none-select" :indent="38" node-key="id" :props="props" :data="data"
|
||||
@node-expand="handleNodeExpand" @node-collapse="handleNodeCollapse"
|
||||
:default-expanded-keys="defaultExpandedKeys" :expand-on-click-node="false">
|
||||
<template #default="{ data }">
|
||||
<span class="custom-tree-node">
|
||||
<span style="font-size: 13px" v-if="data.type === enums.ResourceTypeEnum.MENU.value">
|
||||
<span style="font-size: 13px" v-if="data.type === menuTypeValue">
|
||||
<span style="color: #3c8dbc">【</span>
|
||||
{{ data.name }}
|
||||
<span style="color: #3c8dbc">】</span>
|
||||
<el-tag v-if="data.children !== null" size="small">{{ data.children.length }}</el-tag>
|
||||
</span>
|
||||
<span style="font-size: 13px" v-if="data.type === enums.ResourceTypeEnum.PERMISSION.value">
|
||||
<span style="font-size: 13px" v-if="data.type === permissionTypeValue">
|
||||
<span style="color: #3c8dbc">【</span>
|
||||
<span :style="data.status == 1 ? 'color: #67c23a;' : 'color: #f67c6c;'">{{ data.name }}</span>
|
||||
<span style="color: #3c8dbc">】</span>
|
||||
</span>
|
||||
|
||||
<el-link @click.prevent="info(data)" style="margin-left: 25px" icon="view" type="info" :underline="false" />
|
||||
<el-link @click.prevent="info(data)" style="margin-left: 25px" icon="view" type="info"
|
||||
:underline="false" />
|
||||
|
||||
<el-link
|
||||
v-auth="'resource:update'"
|
||||
@click.prevent="editResource(data)"
|
||||
class="ml5"
|
||||
type="primary"
|
||||
icon="edit"
|
||||
:underline="false"
|
||||
/>
|
||||
<el-link v-auth="'resource:update'" @click.prevent="editResource(data)" class="ml5" type="primary"
|
||||
icon="edit" :underline="false" />
|
||||
|
||||
<el-link
|
||||
v-auth="'resource:add'"
|
||||
@click.prevent="addResource(data)"
|
||||
v-if="data.type === enums.ResourceTypeEnum.MENU.value"
|
||||
icon="circle-plus"
|
||||
:underline="false"
|
||||
type="success"
|
||||
class="ml5"
|
||||
/>
|
||||
<el-link v-auth="'resource:add'" @click.prevent="addResource(data)"
|
||||
v-if="data.type === menuTypeValue" icon="circle-plus" :underline="false"
|
||||
type="success" class="ml5" />
|
||||
|
||||
<el-link
|
||||
v-auth="'resource:changeStatus'"
|
||||
@click.prevent="changeStatus(data, -1)"
|
||||
v-if="data.status === 1 && data.type === enums.ResourceTypeEnum.PERMISSION.value"
|
||||
icon="circle-close"
|
||||
:underline="false"
|
||||
type="warning"
|
||||
class="ml5"
|
||||
/>
|
||||
<el-link v-auth="'resource:changeStatus'" @click.prevent="changeStatus(data, -1)"
|
||||
v-if="data.status === 1 && data.type === permissionTypeValue"
|
||||
icon="circle-close" :underline="false" type="warning" class="ml5" />
|
||||
|
||||
<el-link
|
||||
v-auth="'resource:changeStatus'"
|
||||
@click.prevent="changeStatus(data, 1)"
|
||||
v-if="data.status === -1 && data.type === enums.ResourceTypeEnum.PERMISSION.value"
|
||||
type="success"
|
||||
icon="circle-check"
|
||||
:underline="false"
|
||||
plain
|
||||
class="ml5"
|
||||
/>
|
||||
<el-link v-auth="'resource:changeStatus'" @click.prevent="changeStatus(data, 1)"
|
||||
v-if="data.status === -1 && data.type === permissionTypeValue"
|
||||
type="success" icon="circle-check" :underline="false" plain class="ml5" />
|
||||
|
||||
<el-link
|
||||
v-auth="'resource:delete'"
|
||||
v-if="data.children == null && data.name !== '首页'"
|
||||
@click.prevent="deleteMenu(data)"
|
||||
type="danger"
|
||||
icon="delete"
|
||||
:underline="false"
|
||||
plain
|
||||
class="ml5"
|
||||
/>
|
||||
<el-link v-auth="'resource:delete'" v-if="data.children == null && data.name !== '首页'"
|
||||
@click.prevent="deleteMenu(data)" type="danger" icon="delete" :underline="false" plain
|
||||
class="ml5" />
|
||||
</span>
|
||||
</template>
|
||||
</el-tree>
|
||||
|
||||
<ResourceEdit
|
||||
:title="dialogForm.title"
|
||||
v-model:visible="dialogForm.visible"
|
||||
v-model:data="dialogForm.data"
|
||||
:typeDisabled="dialogForm.typeDisabled"
|
||||
:departTree="data"
|
||||
:type="dialogForm.type"
|
||||
@val-change="valChange"
|
||||
></ResourceEdit>
|
||||
<ResourceEdit :title="dialogForm.title" v-model:visible="dialogForm.visible" v-model:data="dialogForm.data"
|
||||
:typeDisabled="dialogForm.typeDisabled" :departTree="data" :type="dialogForm.type" @val-change="valChange">
|
||||
</ResourceEdit>
|
||||
|
||||
<el-dialog v-model="infoDialog.visible">
|
||||
<el-descriptions title="资源信息" :column="2" border>
|
||||
@@ -123,40 +80,41 @@
|
||||
<el-descriptions-item v-if="infoDialog.data.type == menuTypeValue" label="是否iframe">
|
||||
{{ infoDialog.data.meta.isIframe ? '是' : '否' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item v-if="infoDialog.data.type == menuTypeValue && infoDialog.data.meta.isIframe" label="iframe url">
|
||||
<el-descriptions-item v-if="infoDialog.data.type == menuTypeValue && infoDialog.data.meta.isIframe"
|
||||
label="iframe url">
|
||||
{{ infoDialog.data.meta.link }}
|
||||
</el-descriptions-item>
|
||||
|
||||
<el-descriptions-item label="创建者">{{ infoDialog.data.creator }}</el-descriptions-item>
|
||||
<el-descriptions-item label="创建时间">{{ $filters.dateFormat(infoDialog.data.createTime) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="创建时间">{{ dateFormat(infoDialog.data.createTime) }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="修改者">{{ infoDialog.data.modifier }}</el-descriptions-item>
|
||||
<el-descriptions-item label="更新时间">{{ $filters.dateFormat(infoDialog.data.updateTime) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="更新时间">{{ dateFormat(infoDialog.data.updateTime) }}
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, onMounted, defineComponent } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, reactive, onMounted } from 'vue';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import ResourceEdit from './ResourceEdit.vue';
|
||||
import enums from '../enums';
|
||||
import { resourceApi } from '../api';
|
||||
import { dateFormat } from '@/common/utils/date';
|
||||
|
||||
const menuTypeValue = enums.ResourceTypeEnum['MENU'].value
|
||||
const permissionTypeValue = enums.ResourceTypeEnum['PERMISSION'].value
|
||||
const props = {
|
||||
label: 'name',
|
||||
children: 'children',
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ResourceList',
|
||||
components: {
|
||||
ResourceEdit,
|
||||
},
|
||||
setup() {
|
||||
const state = reactive({
|
||||
menuTypeValue: enums.ResourceTypeEnum['MENU'].value,
|
||||
permissionTypeValue: enums.ResourceTypeEnum['PERMISSION'].value,
|
||||
showBtns: false,
|
||||
// 当前鼠标右击的节点数据
|
||||
rightClickData: {},
|
||||
//弹出框对象
|
||||
dialogForm: {
|
||||
type: null,
|
||||
title: '',
|
||||
visible: false,
|
||||
data: { pid: 0, type: 1, weight: 1 },
|
||||
@@ -169,18 +127,32 @@ export default defineComponent({
|
||||
visible: false,
|
||||
// 资源类型选择是否选
|
||||
data: {
|
||||
meta: {},
|
||||
meta: {} as any,
|
||||
name: '',
|
||||
type: null,
|
||||
creator: '',
|
||||
modifier: '',
|
||||
createTime: '',
|
||||
updateTime: '',
|
||||
weight: null,
|
||||
code: '',
|
||||
},
|
||||
},
|
||||
data: [],
|
||||
props: {
|
||||
label: 'name',
|
||||
children: 'children',
|
||||
},
|
||||
|
||||
// 展开的节点
|
||||
defaultExpandedKeys: [] as any[],
|
||||
});
|
||||
|
||||
|
||||
|
||||
const {
|
||||
dialogForm,
|
||||
infoDialog,
|
||||
data,
|
||||
defaultExpandedKeys,
|
||||
} = toRefs(state)
|
||||
|
||||
onMounted(() => {
|
||||
search();
|
||||
});
|
||||
@@ -214,7 +186,7 @@ export default defineComponent({
|
||||
// 添加顶级菜单情况
|
||||
if (!data) {
|
||||
dialog.typeDisabled = true;
|
||||
dialog.data.type = state.menuTypeValue;
|
||||
dialog.data.type = menuTypeValue;
|
||||
dialog.title = '添加顶级菜单';
|
||||
dialog.visible = true;
|
||||
return;
|
||||
@@ -230,16 +202,16 @@ export default defineComponent({
|
||||
dialog.typeDisabled = true;
|
||||
let hasPermission = false;
|
||||
for (let c of data.children) {
|
||||
if (c.type === state.permissionTypeValue) {
|
||||
if (c.type === permissionTypeValue) {
|
||||
hasPermission = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 如果子节点中存在权限资源,则只能新增权限资源,否则只能新增菜单资源
|
||||
if (hasPermission) {
|
||||
dialog.data.type = state.permissionTypeValue;
|
||||
dialog.data.type = permissionTypeValue;
|
||||
} else {
|
||||
dialog.data.type = state.menuTypeValue;
|
||||
dialog.data.type = menuTypeValue;
|
||||
}
|
||||
dialog.data.weight = data.children.length + 1;
|
||||
}
|
||||
@@ -314,21 +286,6 @@ export default defineComponent({
|
||||
}
|
||||
state.infoDialog.visible = true;
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
enums,
|
||||
deleteMenu,
|
||||
addResource,
|
||||
editResource,
|
||||
valChange,
|
||||
changeStatus,
|
||||
handleNodeExpand,
|
||||
handleNodeCollapse,
|
||||
info,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
.menu {
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-dialog :title="'分配“' + role.name + '”菜单&权限'" v-model="dialogVisible" :before-close="cancel" :show-close="false" width="400px">
|
||||
<el-tree
|
||||
style="height: 50vh; overflow: auto"
|
||||
ref="menuTree"
|
||||
:data="resources"
|
||||
show-checkbox
|
||||
node-key="id"
|
||||
:default-checked-keys="defaultCheckedKeys"
|
||||
:props="defaultProps"
|
||||
>
|
||||
<el-dialog :title="'分配“' + roleInfo?.name + '”菜单&权限'" v-model="dialogVisible" :before-close="cancel"
|
||||
:show-close="false" width="400px">
|
||||
<el-tree style="height: 50vh; overflow: auto" ref="menuTree" :data="resources" show-checkbox node-key="id"
|
||||
:default-checked-keys="defaultCheckedKeys" :props="defaultProps">
|
||||
<template #default="{ node, data }">
|
||||
<span class="custom-tree-node">
|
||||
<span v-if="data.type == enums.ResourceTypeEnum.MENU.value">{{ node.label }}</span>
|
||||
<span v-if="data.type == enums.ResourceTypeEnum.PERMISSION.value" style="color: #67c23a">{{ node.label }}</span>
|
||||
<span v-if="data.type == enums.ResourceTypeEnum['MENU'].value">{{ node.label }}</span>
|
||||
<span v-if="data.type == enums.ResourceTypeEnum['PERMISSION'].value" style="color: #67c23a">{{
|
||||
node.label
|
||||
}}</span>
|
||||
</span>
|
||||
</template>
|
||||
</el-tree>
|
||||
@@ -27,15 +23,13 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, reactive, watch, ref } from 'vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { roleApi } from '../api';
|
||||
import enums from '../enums';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ResourceEdit',
|
||||
props: {
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -53,22 +47,33 @@ export default defineComponent({
|
||||
resources: {
|
||||
type: Array,
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
})
|
||||
|
||||
//定义事件
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'val-change'])
|
||||
|
||||
const defaultProps = {
|
||||
children: 'children',
|
||||
label: 'name',
|
||||
}
|
||||
|
||||
const menuTree: any = ref(null);
|
||||
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
defaultProps: {
|
||||
children: 'children',
|
||||
label: 'name',
|
||||
},
|
||||
roleInfo: null as any,
|
||||
});
|
||||
|
||||
const {
|
||||
dialogVisible,
|
||||
roleInfo,
|
||||
} = toRefs(state)
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
(newValue) => {
|
||||
state.dialogVisible = newValue;
|
||||
state.roleInfo = props.role
|
||||
}
|
||||
);
|
||||
|
||||
@@ -76,30 +81,30 @@ export default defineComponent({
|
||||
* 获取所有菜单树的叶子节点
|
||||
* @param {Object} trees 菜单树列表
|
||||
*/
|
||||
const getAllLeafIds = (trees: any) => {
|
||||
let leafIds: any = [];
|
||||
for (let tree of trees) {
|
||||
setLeafIds(tree, leafIds);
|
||||
}
|
||||
return leafIds;
|
||||
};
|
||||
// const getAllLeafIds = (trees: any) => {
|
||||
// let leafIds: any = [];
|
||||
// for (let tree of trees) {
|
||||
// setLeafIds(tree, leafIds);
|
||||
// }
|
||||
// return leafIds;
|
||||
// };
|
||||
|
||||
const setLeafIds = (tree: any, ids: any) => {
|
||||
if (tree.children !== null) {
|
||||
for (let t of tree.children) {
|
||||
setLeafIds(t, ids);
|
||||
}
|
||||
} else {
|
||||
ids.push(tree.id);
|
||||
}
|
||||
};
|
||||
// const setLeafIds = (tree: any, ids: any) => {
|
||||
// if (tree.children !== null) {
|
||||
// for (let t of tree.children) {
|
||||
// setLeafIds(t, ids);
|
||||
// }
|
||||
// } else {
|
||||
// ids.push(tree.id);
|
||||
// }
|
||||
// };
|
||||
|
||||
const btnOk = async () => {
|
||||
let menuIds = menuTree.value.getCheckedKeys();
|
||||
let halfMenuIds = menuTree.value.getHalfCheckedKeys();
|
||||
let resources = [].concat(menuIds, halfMenuIds).join(',');
|
||||
await roleApi.saveResources.request({
|
||||
id: props.role['id'],
|
||||
id: props.role!.id,
|
||||
resourceIds: resources,
|
||||
});
|
||||
ElMessage.success('保存成功!');
|
||||
@@ -111,18 +116,8 @@ export default defineComponent({
|
||||
emit('update:visible', false);
|
||||
emit('cancel');
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
enums,
|
||||
menuTree,
|
||||
btnOk,
|
||||
getAllLeafIds,
|
||||
cancel,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
<template>
|
||||
<div class="role-dialog">
|
||||
<el-dialog :title="title" v-model="dvisible" :show-close="false" :before-close="cancel" width="500px" :destroy-on-close="true">
|
||||
<el-form :model="form" label-width="90px">
|
||||
<el-dialog :title="title" v-model="dvisible" :show-close="false" :before-close="cancel" width="500px"
|
||||
:destroy-on-close="true">
|
||||
<el-form ref="roleForm" :model="form" label-width="90px">
|
||||
<el-form-item prop="name" label="角色名称:" required>
|
||||
<el-input v-model="form.name" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="code" label="角色code:" required>
|
||||
<el-input
|
||||
:disabled="form.id != null"
|
||||
v-model="form.code"
|
||||
placeholder="COMMON开头则为所有账号共有角色"
|
||||
auto-complete="off"
|
||||
></el-input>
|
||||
<el-input :disabled="form.id != null" v-model="form.code" placeholder="COMMON开头则为所有账号共有角色"
|
||||
auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="角色描述:">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="3" placeholder="请输入角色描述"></el-input>
|
||||
@@ -27,13 +24,11 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, watch, defineComponent } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { ref, toRefs, reactive, watch } from 'vue';
|
||||
import { roleApi } from '../api';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'RoleEdit',
|
||||
props: {
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -43,20 +38,31 @@ export default defineComponent({
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
})
|
||||
|
||||
//定义事件
|
||||
const emit = defineEmits(['update:visible', 'cancel', 'val-change'])
|
||||
|
||||
const roleForm: any = ref(null);
|
||||
const state = reactive({
|
||||
dvisible: false,
|
||||
form: {
|
||||
id: null,
|
||||
name: '',
|
||||
code: '',
|
||||
status: 1,
|
||||
remark: '',
|
||||
},
|
||||
btnLoading: false,
|
||||
});
|
||||
|
||||
watch(props, (newValue) => {
|
||||
const {
|
||||
dvisible,
|
||||
form,
|
||||
btnLoading,
|
||||
} = toRefs(state)
|
||||
|
||||
watch(props, (newValue: any) => {
|
||||
state.dvisible = newValue.visible;
|
||||
if (newValue.data) {
|
||||
state.form = { ...newValue.data };
|
||||
@@ -73,7 +79,8 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const btnOk = async () => {
|
||||
// let p = state.form.id ? roleApi.update : roleApi.save;
|
||||
roleForm.value.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
await roleApi.save.request(state.form);
|
||||
emit('val-change', state.form);
|
||||
cancel();
|
||||
@@ -81,15 +88,10 @@ export default defineComponent({
|
||||
setTimeout(() => {
|
||||
state.btnLoading = false;
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
btnOk,
|
||||
cancel,
|
||||
};
|
||||
},
|
||||
}
|
||||
});
|
||||
};
|
||||
</script>
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
||||
|
||||
@@ -2,25 +2,20 @@
|
||||
<div class="role-list">
|
||||
<el-card>
|
||||
<el-button v-auth="'role:add'" type="primary" icon="plus" @click="editRole(false)">添加</el-button>
|
||||
<el-button v-auth="'role:update'" :disabled="chooseId == null" @click="editRole(chooseData)" type="primary" icon="edit">编辑</el-button>
|
||||
<el-button v-auth="'role:saveResources'" :disabled="chooseId == null" @click="editResource(chooseData)" type="success" icon="setting"
|
||||
>分配菜单&权限</el-button
|
||||
>
|
||||
<el-button v-auth="'role:del'" :disabled="chooseId == null" @click="deleteRole(chooseData)" type="danger" icon="delete">删除</el-button>
|
||||
<el-button v-auth="'role:update'" :disabled="chooseId == null" @click="editRole(chooseData)" type="primary"
|
||||
icon="edit">编辑</el-button>
|
||||
<el-button v-auth="'role:saveResources'" :disabled="chooseId == null" @click="editResource(chooseData)"
|
||||
type="success" icon="setting">分配菜单&权限</el-button>
|
||||
<el-button v-auth="'role:del'" :disabled="chooseId == null" @click="deleteRole(chooseData)" type="danger"
|
||||
icon="delete">删除</el-button>
|
||||
|
||||
<div style="float: right">
|
||||
<el-input
|
||||
placeholder="请输入角色名称"
|
||||
class="mr2"
|
||||
style="width: 200px"
|
||||
v-model="query.name"
|
||||
@clear="search"
|
||||
clearable
|
||||
></el-input>
|
||||
<el-input placeholder="请输入角色名称" class="mr2" style="width: 200px" v-model="query.name" @clear="search"
|
||||
clearable></el-input>
|
||||
<el-button @click="search" type="success" icon="search"></el-button>
|
||||
</div>
|
||||
<el-table :data="roles" @current-change="choose" ref="table" style="width: 100%">
|
||||
<el-table-column label="选择" width="50px">
|
||||
<el-table-column label="选择" width="55px">
|
||||
<template #default="scope">
|
||||
<el-radio v-model="chooseId" :label="scope.row.id">
|
||||
<i></i>
|
||||
@@ -32,12 +27,12 @@
|
||||
<el-table-column prop="remark" label="描述" min-width="160px" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="createTime" label="创建时间">
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.createTime) }}
|
||||
{{ dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="updateTime" label="修改时间">
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.updateTime) }}
|
||||
{{ dateFormat(scope.row.updateTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="查看更多" min-width="80px">
|
||||
@@ -47,51 +42,32 @@
|
||||
</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-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>
|
||||
|
||||
<role-edit :title="roleEdit.title" v-model:visible="roleEdit.visible" :data="roleEdit.role" @val-change="roleEditChange" />
|
||||
<resource-edit
|
||||
v-model:visible="resourceDialog.visible"
|
||||
:role="resourceDialog.role"
|
||||
:resources="resourceDialog.resources"
|
||||
:defaultCheckedKeys="resourceDialog.defaultCheckedKeys"
|
||||
@cancel="cancelEditResources()"
|
||||
/>
|
||||
<show-resource
|
||||
v-model:visible="showResourceDialog.visible"
|
||||
:title="showResourceDialog.title"
|
||||
v-model:resources="showResourceDialog.resources"
|
||||
/>
|
||||
<role-edit :title="roleEditDialog.title" v-model:visible="roleEditDialog.visible" :data="roleEditDialog.role"
|
||||
@val-change="roleEditChange" />
|
||||
<resource-edit v-model:visible="resourceDialog.visible" :role="resourceDialog.role"
|
||||
:resources="resourceDialog.resources" :defaultCheckedKeys="resourceDialog.defaultCheckedKeys"
|
||||
@cancel="cancelEditResources()" />
|
||||
<show-resource v-model:visible="showResourceDialog.visible" :title="showResourceDialog.title"
|
||||
v-model:resources="showResourceDialog.resources" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, onMounted, defineComponent } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, reactive, onMounted } from 'vue';
|
||||
import RoleEdit from './RoleEdit.vue';
|
||||
import ResourceEdit from './ResourceEdit.vue';
|
||||
import ShowResource from './ShowResource.vue';
|
||||
import { roleApi, resourceApi } from '../api';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
export default defineComponent({
|
||||
name: 'RoleList',
|
||||
components: {
|
||||
RoleEdit,
|
||||
ResourceEdit,
|
||||
ShowResource,
|
||||
},
|
||||
setup() {
|
||||
import { dateFormat } from '@/common/utils/date';
|
||||
|
||||
const state = reactive({
|
||||
dialogFormVisible: false,
|
||||
currentEditPermissions: false,
|
||||
query: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
@@ -107,7 +83,7 @@ export default defineComponent({
|
||||
resources: [],
|
||||
defaultCheckedKeys: [],
|
||||
},
|
||||
roleEdit: {
|
||||
roleEditDialog: {
|
||||
title: '角色编辑',
|
||||
visible: false,
|
||||
role: {},
|
||||
@@ -119,6 +95,17 @@ export default defineComponent({
|
||||
},
|
||||
});
|
||||
|
||||
const {
|
||||
query,
|
||||
total,
|
||||
roles,
|
||||
chooseId,
|
||||
chooseData,
|
||||
resourceDialog,
|
||||
roleEditDialog,
|
||||
showResourceDialog,
|
||||
} = toRefs(state)
|
||||
|
||||
onMounted(() => {
|
||||
search();
|
||||
});
|
||||
@@ -151,12 +138,12 @@ export default defineComponent({
|
||||
|
||||
const editRole = (data: any) => {
|
||||
if (data) {
|
||||
state.roleEdit.role = data;
|
||||
state.roleEditDialog.role = data;
|
||||
} else {
|
||||
state.roleEdit.role = false;
|
||||
state.roleEditDialog.role = false;
|
||||
}
|
||||
|
||||
state.roleEdit.visible = true;
|
||||
state.roleEditDialog.visible = true;
|
||||
};
|
||||
|
||||
const deleteRole = async (data: any) => {
|
||||
@@ -186,11 +173,6 @@ export default defineComponent({
|
||||
state.showResourceDialog.visible = true;
|
||||
};
|
||||
|
||||
const closeShowResourceDialog = () => {
|
||||
state.showResourceDialog.visible = false;
|
||||
state.showResourceDialog.resources = [];
|
||||
};
|
||||
|
||||
const editResource = async (row: any) => {
|
||||
let menus = await resourceApi.list.request(null);
|
||||
// 获取所有菜单列表
|
||||
@@ -247,22 +229,7 @@ export default defineComponent({
|
||||
state.resourceDialog.defaultCheckedKeys = [];
|
||||
}, 10);
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
search,
|
||||
handlePageChange,
|
||||
choose,
|
||||
roleEditChange,
|
||||
editRole,
|
||||
deleteRole,
|
||||
showResources,
|
||||
closeShowResourceDialog,
|
||||
editResource,
|
||||
cancelEditResources,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-dialog @close="closeDialog" :title="title" :before-close="closeDialog" v-model="dialogVisible" width="400px">
|
||||
<el-dialog @close="closeDialog" :title="title" :before-close="closeDialog" v-model="dialogVisible"
|
||||
width="400px">
|
||||
<el-tree style="height: 50vh; overflow: auto" :data="resources" node-key="id" :props="defaultProps">
|
||||
<template #default="{ node, data }">
|
||||
<span class="custom-tree-node">
|
||||
<span v-if="data.type == enums.ResourceTypeEnum.MENU.value">{{ node.label }}</span>
|
||||
<span v-if="data.type == enums.ResourceTypeEnum.PERMISSION.value" style="color: #67c23a">{{ node.label }}</span>
|
||||
<span v-if="data.type == enums.ResourceTypeEnum['MENU'].value">{{ node.label }}</span>
|
||||
<span v-if="data.type == enums.ResourceTypeEnum['PERMISSION'].value" style="color: #67c23a">{{
|
||||
node.label
|
||||
}}</span>
|
||||
|
||||
<el-link @click.prevent="info(data)" style="margin-left: 25px" icon="el-icon-view" type="info" :underline="false" />
|
||||
<el-link @click.prevent="info(data)" style="margin-left: 25px" icon="InfoFilled" type="info"
|
||||
:underline="false" />
|
||||
</span>
|
||||
</template>
|
||||
</el-tree>
|
||||
@@ -15,14 +19,12 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { getCurrentInstance, toRefs, reactive, watch, defineComponent } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { getCurrentInstance, toRefs, reactive, watch } from 'vue';
|
||||
import { ElMessageBox } from 'element-plus';
|
||||
import enums from '../enums';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ShowResource',
|
||||
props: {
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -32,16 +34,24 @@ export default defineComponent({
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
setup(props: any, { emit }) {
|
||||
})
|
||||
|
||||
//定义事件
|
||||
const emit = defineEmits(['update:visible', 'update:resources'])
|
||||
|
||||
const { proxy } = getCurrentInstance() as any;
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
defaultProps: {
|
||||
|
||||
const defaultProps = {
|
||||
children: 'children',
|
||||
label: 'name',
|
||||
},
|
||||
}
|
||||
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
});
|
||||
const {
|
||||
dialogVisible,
|
||||
} = toRefs(state)
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
@@ -74,16 +84,8 @@ export default defineComponent({
|
||||
emit('update:visible', false);
|
||||
emit('update:resources', []);
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
enums,
|
||||
info,
|
||||
closeDialog,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
|
||||
@@ -2,16 +2,10 @@
|
||||
<div class="role-list">
|
||||
<el-card>
|
||||
<div style="float: right">
|
||||
<el-select
|
||||
remote
|
||||
:remote-method="getAccount"
|
||||
v-model="query.creatorId"
|
||||
filterable
|
||||
placeholder="请输入并选择账号"
|
||||
clearable
|
||||
class="mr5"
|
||||
>
|
||||
<el-option v-for="item in accounts" :key="item.id" :label="item.username" :value="item.id"> </el-option>
|
||||
<el-select remote :remote-method="getAccount" v-model="query.creatorId" filterable
|
||||
placeholder="请输入并选择账号" clearable class="mr5">
|
||||
<el-option v-for="item in accounts" :key="item.id" :label="item.username" :value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
<el-select v-model="query.type" filterable placeholder="请选择操作结果" clearable class="mr5">
|
||||
<el-option label="成功" :value="1"> </el-option>
|
||||
@@ -23,7 +17,7 @@
|
||||
<el-table-column prop="creator" label="操作人" min-width="100" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="createTime" label="操作时间" min-width="160">
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.createTime) }}
|
||||
{{ dateFormat(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="type" label="结果" min-width="65">
|
||||
@@ -34,41 +28,43 @@
|
||||
</el-table-column>
|
||||
<el-table-column prop="description" label="描述" min-width="160" show-overflow-tooltip></el-table-column>
|
||||
|
||||
<el-table-column prop="reqParam" label="请求信息" min-width="300" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="reqParam" label="操作信息" min-width="300" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="resp" label="响应信息" min-width="200" show-overflow-tooltip></el-table-column>
|
||||
</el-table>
|
||||
<el-row style="margin-top: 20px" type="flex" justify="end">
|
||||
<el-pagination
|
||||
style="text-align: right"
|
||||
@current-change="handlePageChange"
|
||||
:total="total"
|
||||
layout="prev, pager, next, total, jumper"
|
||||
v-model:current-page="query.pageNum"
|
||||
:page-size="query.pageSize"
|
||||
></el-pagination>
|
||||
<el-pagination style="text-align: right" @current-change="handlePageChange" :total="total"
|
||||
layout="prev, pager, next, total, jumper" v-model:current-page="query.pageNum"
|
||||
:page-size="query.pageSize"></el-pagination>
|
||||
</el-row>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, onMounted, defineComponent } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { toRefs, reactive, onMounted } from 'vue';
|
||||
import { logApi, accountApi } from '../api';
|
||||
export default defineComponent({
|
||||
name: 'SyslogList',
|
||||
components: {},
|
||||
setup() {
|
||||
import { dateFormat } from '@/common/utils/date';
|
||||
|
||||
const state = reactive({
|
||||
query: {
|
||||
type: null,
|
||||
creatorId: null,
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
name: null,
|
||||
},
|
||||
total: 0,
|
||||
logs: [],
|
||||
accounts: [],
|
||||
accounts: [] as any,
|
||||
});
|
||||
|
||||
const {
|
||||
query,
|
||||
total,
|
||||
logs,
|
||||
accounts,
|
||||
} = toRefs(state)
|
||||
|
||||
onMounted(() => {
|
||||
search();
|
||||
});
|
||||
@@ -90,14 +86,7 @@ export default defineComponent({
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
search,
|
||||
handlePageChange,
|
||||
getAccount,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
||||
|
||||
@@ -37,14 +37,7 @@ const viteConfig: UserConfig = {
|
||||
outDir: 'dist',
|
||||
minify: 'esbuild',
|
||||
sourcemap: false,
|
||||
chunkSizeWarningLimit: 1500,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
entryFileNames: `assets/[name].${new Date().getTime()}.js`,
|
||||
chunkFileNames: `assets/[name].${new Date().getTime()}.js`,
|
||||
assetFileNames: `assets/[name].${new Date().getTime()}.[ext]`,
|
||||
},
|
||||
},
|
||||
chunkSizeWarningLimit: 1500
|
||||
},
|
||||
define: {
|
||||
__VUE_I18N_LEGACY_API__: JSON.stringify(false),
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user