mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 08:20:25 +08:00 
			
		
		
		
	Compare commits
	
		
			6 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					e925a808c4 | ||
| 
						 | 
					6c197edddd | ||
| 
						 | 
					c35e91b7b6 | ||
| 
						 | 
					575947795a | ||
| 
						 | 
					51f116c7d2 | ||
| 
						 | 
					c28254855c | 
@@ -9,21 +9,21 @@
 | 
				
			|||||||
  "dependencies": {
 | 
					  "dependencies": {
 | 
				
			||||||
    "@element-plus/icons-vue": "^2.0.9",
 | 
					    "@element-plus/icons-vue": "^2.0.9",
 | 
				
			||||||
    "asciinema-player": "^3.0.1",
 | 
					    "asciinema-player": "^3.0.1",
 | 
				
			||||||
    "axios": "^0.27.2",
 | 
					    "axios": "^1.1.2",
 | 
				
			||||||
    "codemirror": "^5.65.5",
 | 
					    "codemirror": "^5.65.5",
 | 
				
			||||||
    "countup.js": "^2.0.7",
 | 
					    "countup.js": "^2.0.7",
 | 
				
			||||||
    "cropperjs": "^1.5.11",
 | 
					    "cropperjs": "^1.5.11",
 | 
				
			||||||
    "echarts": "^5.3.3",
 | 
					    "echarts": "^5.3.3",
 | 
				
			||||||
    "element-plus": "^2.2.17",
 | 
					    "element-plus": "^2.2.18",
 | 
				
			||||||
    "jsencrypt": "^3.2.1",
 | 
					    "jsencrypt": "^3.2.1",
 | 
				
			||||||
    "jsoneditor": "^9.9.0",
 | 
					    "jsoneditor": "^9.9.2",
 | 
				
			||||||
    "lodash": "^4.17.21",
 | 
					    "lodash": "^4.17.21",
 | 
				
			||||||
    "mitt": "^3.0.0",
 | 
					    "mitt": "^3.0.0",
 | 
				
			||||||
    "nprogress": "^0.2.0",
 | 
					    "nprogress": "^0.2.0",
 | 
				
			||||||
    "screenfull": "^6.0.2",
 | 
					    "screenfull": "^6.0.2",
 | 
				
			||||||
    "sortablejs": "^1.13.0",
 | 
					    "sortablejs": "^1.13.0",
 | 
				
			||||||
    "sql-formatter": "^9.2.0",
 | 
					    "sql-formatter": "^9.2.0",
 | 
				
			||||||
    "vue": "^3.2.39",
 | 
					    "vue": "^3.2.41",
 | 
				
			||||||
    "vue-clipboard3": "^1.0.1",
 | 
					    "vue-clipboard3": "^1.0.1",
 | 
				
			||||||
    "vue-router": "^4.1.5",
 | 
					    "vue-router": "^4.1.5",
 | 
				
			||||||
    "vuex": "^4.0.2",
 | 
					    "vuex": "^4.0.2",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
export function dateFormat(fmt: string, date: Date) {
 | 
					export function dateFormat2(fmt: string, date: Date) {
 | 
				
			||||||
    let ret;
 | 
					    let ret;
 | 
				
			||||||
    const opt = {
 | 
					    const opt = {
 | 
				
			||||||
        "y+": date.getFullYear().toString(),        // 年
 | 
					        "y+": date.getFullYear().toString(),        // 年
 | 
				
			||||||
@@ -19,5 +19,9 @@ export function dateFormat(fmt: string, date: Date) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function dateStrFormat(fmt: string, dateStr: string) {
 | 
					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))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
import { getUseWatermark4Session, getUserInfo4Session } from '@/common/utils/storage.ts';
 | 
					import { getUseWatermark4Session, getUserInfo4Session } from '@/common/utils/storage.ts';
 | 
				
			||||||
import { dateFormat } from '@/common/utils/date.ts'
 | 
					import { dateFormat2 } from '@/common/utils/date.ts'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 页面添加水印效果
 | 
					// 页面添加水印效果
 | 
				
			||||||
const setWatermark = (str: any) => {
 | 
					const setWatermark = (str: any) => {
 | 
				
			||||||
@@ -46,7 +46,7 @@ const watermark = {
 | 
				
			|||||||
        setTimeout(() => {
 | 
					        setTimeout(() => {
 | 
				
			||||||
            const userinfo = getUserInfo4Session()
 | 
					            const userinfo = getUserInfo4Session()
 | 
				
			||||||
            if (userinfo && getUseWatermark4Session()) {
 | 
					            if (userinfo && getUseWatermark4Session()) {
 | 
				
			||||||
                set(`${userinfo.username} ${dateFormat('yyyy-MM-dd HH:mm:ss', new Date())}`)
 | 
					                set(`${userinfo.username} ${dateFormat2('yyyy-MM-dd HH:mm:ss', new Date())}`)
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                del();
 | 
					                del();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -47,7 +47,7 @@ const CodeMirror = (window as any).CodeMirror || _CodeMirror;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'CodeMirror',
 | 
					    name: 'CodeMirror',
 | 
				
			||||||
     components: {
 | 
					    components: {
 | 
				
			||||||
        ElOption,
 | 
					        ElOption,
 | 
				
			||||||
        ElSelect,
 | 
					        ElSelect,
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@@ -61,11 +61,11 @@ export default defineComponent({
 | 
				
			|||||||
        },
 | 
					        },
 | 
				
			||||||
        height: {
 | 
					        height: {
 | 
				
			||||||
            type: String,
 | 
					            type: String,
 | 
				
			||||||
            default: "500px",
 | 
					            default: '500px',
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        width: {
 | 
					        width: {
 | 
				
			||||||
            type: String,
 | 
					            type: String,
 | 
				
			||||||
            default: "auto",
 | 
					            default: 'auto',
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        canChangeMode: {
 | 
					        canChangeMode: {
 | 
				
			||||||
            type: Boolean,
 | 
					            type: Boolean,
 | 
				
			||||||
@@ -300,7 +300,7 @@ export default defineComponent({
 | 
				
			|||||||
                coder.setValue(newVal);
 | 
					                coder.setValue(newVal);
 | 
				
			||||||
                state.content = newVal;
 | 
					                state.content = newVal;
 | 
				
			||||||
                coder.scrollTo(scrollInfo.left, scrollInfo.top);
 | 
					                coder.scrollTo(scrollInfo.left, scrollInfo.top);
 | 
				
			||||||
                refresh()
 | 
					                refresh();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -327,7 +327,6 @@ export default defineComponent({
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        font-family: 'JetBrainsMono';
 | 
					        font-family: 'JetBrainsMono';
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    .code-mode-select {
 | 
					    .code-mode-select {
 | 
				
			||||||
        position: absolute;
 | 
					        position: absolute;
 | 
				
			||||||
        z-index: 2;
 | 
					        z-index: 2;
 | 
				
			||||||
@@ -336,4 +335,26 @@ export default defineComponent({
 | 
				
			|||||||
        max-width: 130px;
 | 
					        max-width: 130px;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					.CodeMirror-hints {
 | 
				
			||||||
 | 
					    position: absolute;
 | 
				
			||||||
 | 
					    z-index: 10000;
 | 
				
			||||||
 | 
					    overflow: hidden;
 | 
				
			||||||
 | 
					    list-style: none;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    margin: 0;
 | 
				
			||||||
 | 
					    padding: 2px;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    -webkit-box-shadow: 2px 3px 5px rgba(0, 0, 0, 0.2);
 | 
				
			||||||
 | 
					    -moz-box-shadow: 2px 3px 5px rgba(0, 0, 0, 0.2);
 | 
				
			||||||
 | 
					    box-shadow: 2px 3px 5px rgba(0, 0, 0, 0.2);
 | 
				
			||||||
 | 
					    border-radius: 3px;
 | 
				
			||||||
 | 
					    border: 1px solid silver;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    background: white;
 | 
				
			||||||
 | 
					    font-size: 90%;
 | 
				
			||||||
 | 
					    font-family: 'JetBrainsMono';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    max-height: 20em;
 | 
				
			||||||
 | 
					    overflow-y: auto;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
</style>
 | 
					</style>
 | 
				
			||||||
@@ -14,8 +14,9 @@ export const imports = {
 | 
				
			|||||||
    "SyslogList": () => import('@/views/system/syslog/SyslogList.vue'),
 | 
					    "SyslogList": () => import('@/views/system/syslog/SyslogList.vue'),
 | 
				
			||||||
    "ConfigList": () => import('@/views/system/config/ConfigList.vue'),
 | 
					    "ConfigList": () => import('@/views/system/config/ConfigList.vue'),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // project
 | 
					    // tag
 | 
				
			||||||
    "ProjectList": () => import('@/views/ops/project/ProjectList.vue'),
 | 
					    "TagTreeList": () => import('@/views/ops/tag/TagTreeList.vue'),
 | 
				
			||||||
 | 
					    "TeamList": () => import('@/views/ops/tag/TeamList.vue'),
 | 
				
			||||||
    // db
 | 
					    // db
 | 
				
			||||||
    "DbList": () => import('@/views/ops/db/DbList.vue'),
 | 
					    "DbList": () => import('@/views/ops/db/DbList.vue'),
 | 
				
			||||||
    "SqlExec": () => import('@/views/ops/db'),
 | 
					    "SqlExec": () => import('@/views/ops/db'),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
import { RouteRecordRaw } from 'vue-router';
 | 
					import { RouteRecordRaw } from 'vue-router';
 | 
				
			||||||
import Layout from '@/views/layout/index.vue'
 | 
					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 = [
 | 
					export const dynamicRoutes = [
 | 
				
			||||||
@@ -12,119 +12,108 @@ export const dynamicRoutes = [
 | 
				
			|||||||
        meta: {
 | 
					        meta: {
 | 
				
			||||||
            isKeepAlive: true,
 | 
					            isKeepAlive: true,
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        children: [
 | 
					    //     children: [
 | 
				
			||||||
            {
 | 
					    //         {
 | 
				
			||||||
                path: '/home',
 | 
					    //             path: '/home',
 | 
				
			||||||
                name: 'home',
 | 
					    //             name: 'home',
 | 
				
			||||||
                component: () => import('@/views/home/index.vue'),
 | 
					    //             component: () => import('@/views/home/index.vue'),
 | 
				
			||||||
                meta: {
 | 
					    //             meta: {
 | 
				
			||||||
                    title: '首页',
 | 
					    //                 title: '首页',
 | 
				
			||||||
                    // iframe链接
 | 
					    //                 // iframe链接
 | 
				
			||||||
                    link: '',
 | 
					    //                 link: '',
 | 
				
			||||||
                    // 是否在菜单栏显示,默认显示
 | 
					    //                 // 是否在菜单栏显示,默认显示
 | 
				
			||||||
                    isHide: false,
 | 
					    //                 isHide: false,
 | 
				
			||||||
                    isKeepAlive: true,
 | 
					    //                 isKeepAlive: true,
 | 
				
			||||||
                    // tag标签是否不可删除
 | 
					    //                 // tag标签是否不可删除
 | 
				
			||||||
                    isAffix: true,
 | 
					    //                 isAffix: true,
 | 
				
			||||||
                    // 是否为iframe
 | 
					    //                 // 是否为iframe
 | 
				
			||||||
                    isIframe: false,
 | 
					    //                 isIframe: false,
 | 
				
			||||||
                    icon: 'el-icon-s-home',
 | 
					    //                 icon: 'el-icon-s-home',
 | 
				
			||||||
                },
 | 
					    //             },
 | 
				
			||||||
            },
 | 
					    //         },
 | 
				
			||||||
            {
 | 
					    //         {
 | 
				
			||||||
                path: '/sys',
 | 
					    //             path: '/sys',
 | 
				
			||||||
                name: 'Resource',
 | 
					    //             name: 'Resource',
 | 
				
			||||||
                redirect: '/sys/resources',
 | 
					    //             redirect: '/sys/resources',
 | 
				
			||||||
                meta: {
 | 
					    //             meta: {
 | 
				
			||||||
                    title: '系统管理',
 | 
					    //                 title: '系统管理',
 | 
				
			||||||
                    // 资源code,用于校验用户是否拥有该资源权限
 | 
					    //                 // 资源code,用于校验用户是否拥有该资源权限
 | 
				
			||||||
                    code: 'sys',
 | 
					    //                 code: 'sys',
 | 
				
			||||||
                    // isKeepAlive: true,
 | 
					    //                 // isKeepAlive: true,
 | 
				
			||||||
                    icon: 'el-icon-monitor',
 | 
					    //                 icon: 'el-icon-monitor',
 | 
				
			||||||
                },
 | 
					    //             },
 | 
				
			||||||
                children: [
 | 
					    //             children: [
 | 
				
			||||||
                    {
 | 
					    //                 {
 | 
				
			||||||
                        path: 'sys/resources',
 | 
					    //                     path: 'sys/resources',
 | 
				
			||||||
                        name: 'ResourceList',
 | 
					    //                     name: 'ResourceList',
 | 
				
			||||||
                        component: () => import('@/views/system/resource'),
 | 
					    //                     component: () => import('@/views/system/resource'),
 | 
				
			||||||
                        meta: {
 | 
					    //                     meta: {
 | 
				
			||||||
                            title: '资源管理',
 | 
					    //                         title: '资源管理',
 | 
				
			||||||
                            code: 'resource:list',
 | 
					    //                         code: 'resource:list',
 | 
				
			||||||
                            isKeepAlive: true,
 | 
					    //                         isKeepAlive: true,
 | 
				
			||||||
                            icon: 'el-icon-menu',
 | 
					    //                         icon: 'el-icon-menu',
 | 
				
			||||||
                        },
 | 
					    //                     },
 | 
				
			||||||
                    },
 | 
					    //                 },
 | 
				
			||||||
                    {
 | 
					    //                 {
 | 
				
			||||||
                        path: 'sys/roles',
 | 
					    //                     path: 'sys/roles',
 | 
				
			||||||
                        name: 'RoleList',
 | 
					    //                     name: 'RoleList',
 | 
				
			||||||
                        component: () => import('@/views/system/role'),
 | 
					    //                     component: () => import('@/views/system/role'),
 | 
				
			||||||
                        meta: {
 | 
					    //                     meta: {
 | 
				
			||||||
                            title: '角色管理',
 | 
					    //                         title: '角色管理',
 | 
				
			||||||
                            code: 'role:list',
 | 
					    //                         code: 'role:list',
 | 
				
			||||||
                            isKeepAlive: true,
 | 
					    //                         isKeepAlive: true,
 | 
				
			||||||
                            icon: 'el-icon-menu',
 | 
					    //                         icon: 'el-icon-menu',
 | 
				
			||||||
                        },
 | 
					    //                     },
 | 
				
			||||||
                    },
 | 
					    //                 },
 | 
				
			||||||
                    {
 | 
					    //                 {
 | 
				
			||||||
                        path: 'sys/accounts',
 | 
					    //                     path: 'sys/accounts',
 | 
				
			||||||
                        name: 'ResourceList',
 | 
					    //                     name: 'ResourceList',
 | 
				
			||||||
                        component: () => import('@/views/system/account'),
 | 
					    //                     component: () => import('@/views/system/account'),
 | 
				
			||||||
                        meta: {
 | 
					    //                     meta: {
 | 
				
			||||||
                            title: '账号管理',
 | 
					    //                         title: '账号管理',
 | 
				
			||||||
                            code: 'account:list',
 | 
					    //                         code: 'account:list',
 | 
				
			||||||
                            isKeepAlive: true,
 | 
					    //                         isKeepAlive: true,
 | 
				
			||||||
                            icon: 'el-icon-menu',
 | 
					    //                         icon: 'el-icon-menu',
 | 
				
			||||||
                        },
 | 
					    //                     },
 | 
				
			||||||
                    },
 | 
					    //                 },
 | 
				
			||||||
                ],
 | 
					    //             ],
 | 
				
			||||||
            },
 | 
					    //         },
 | 
				
			||||||
            {
 | 
					    //         {
 | 
				
			||||||
                path: '/machine',
 | 
					    //             path: '/machine',
 | 
				
			||||||
                name: 'Machine',
 | 
					    //             name: 'Machine',
 | 
				
			||||||
                redirect: '/machine/list',
 | 
					    //             redirect: '/machine/list',
 | 
				
			||||||
                meta: {
 | 
					    //             meta: {
 | 
				
			||||||
                    title: '机器管理',
 | 
					    //                 title: '机器管理',
 | 
				
			||||||
                    // 资源code,用于校验用户是否拥有该资源权限
 | 
					    //                 // 资源code,用于校验用户是否拥有该资源权限
 | 
				
			||||||
                    code: 'machine',
 | 
					    //                 code: 'machine',
 | 
				
			||||||
                    // isKeepAlive: true,
 | 
					    //                 // isKeepAlive: true,
 | 
				
			||||||
                    icon: 'el-icon-monitor',
 | 
					    //                 icon: 'el-icon-monitor',
 | 
				
			||||||
                },
 | 
					    //             },
 | 
				
			||||||
                children: [
 | 
					    //             children: [
 | 
				
			||||||
                    {
 | 
					    //                 {
 | 
				
			||||||
                        path: '/list',
 | 
					    //                     path: '/list',
 | 
				
			||||||
                        name: 'MachineList',
 | 
					    //                     name: 'MachineList',
 | 
				
			||||||
                        component: () => import('@/views/ops/machine'),
 | 
					    //                     component: () => import('@/views/ops/machine'),
 | 
				
			||||||
                        meta: {
 | 
					    //                     meta: {
 | 
				
			||||||
                            title: '机器列表',
 | 
					    //                         title: '机器列表',
 | 
				
			||||||
                            code: 'machine:list',
 | 
					    //                         code: 'machine:list',
 | 
				
			||||||
                            isKeepAlive: true,
 | 
					    //                         isKeepAlive: true,
 | 
				
			||||||
                            icon: 'el-icon-menu',
 | 
					    //                         icon: 'el-icon-menu',
 | 
				
			||||||
                        },
 | 
					    //                     },
 | 
				
			||||||
                    },
 | 
					    //                 },
 | 
				
			||||||
                ],
 | 
					    //             ],
 | 
				
			||||||
            },
 | 
					    //         },
 | 
				
			||||||
            {
 | 
					    //         {
 | 
				
			||||||
                path: '/personal',
 | 
					    //             path: '/personal',
 | 
				
			||||||
                name: 'personal',
 | 
					    //             name: 'personal',
 | 
				
			||||||
                component: () => import('@/views/personal/index.vue'),
 | 
					    //             component: () => import('@/views/personal/index.vue'),
 | 
				
			||||||
                meta: {
 | 
					    //             meta: {
 | 
				
			||||||
                    title: '个人中心',
 | 
					    //                 title: '个人中心',
 | 
				
			||||||
                    isKeepAlive: true,
 | 
					    //                 isKeepAlive: true,
 | 
				
			||||||
                    icon: 'el-icon-user',
 | 
					    //                 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',
 | 
					 | 
				
			||||||
                },
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
        ],
 | 
					 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
];
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -165,17 +154,6 @@ export const staticRoutes: Array<RouteRecordRaw> = [
 | 
				
			|||||||
            titleRename: true,
 | 
					            titleRename: true,
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        path: '/machine/terminal-rec',
 | 
					 | 
				
			||||||
        name: 'machineTerminalRec',
 | 
					 | 
				
			||||||
        component: () => import('@/views/ops/machine/MachineRec.vue'),
 | 
					 | 
				
			||||||
        meta: {
 | 
					 | 
				
			||||||
            // 将路径 'xxx?name=名字' 里的name字段值替换到title里
 | 
					 | 
				
			||||||
            title: '终端回放 | {name}',
 | 
					 | 
				
			||||||
            // 是否根据query对标题名进行参数替换,即最终显示为‘终端_机器名’
 | 
					 | 
				
			||||||
            titleRename: true,
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
];
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 定义404界面
 | 
					// 定义404界面
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										87
									
								
								mayfly_go_web/src/theme/iconSelector.scss
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								mayfly_go_web/src/theme/iconSelector.scss
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,87 @@
 | 
				
			|||||||
 | 
					/* Popover 弹出框(图标选择器)
 | 
				
			||||||
 | 
					------------------------------- */
 | 
				
			||||||
 | 
					.icon-selector-popper {
 | 
				
			||||||
 | 
						padding: 0 !important;
 | 
				
			||||||
 | 
						.icon-selector-warp {
 | 
				
			||||||
 | 
							.icon-selector-warp-title {
 | 
				
			||||||
 | 
								height: 40px;
 | 
				
			||||||
 | 
								line-height: 40px;
 | 
				
			||||||
 | 
								padding: 0 15px;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							.icon-selector-warp-row {
 | 
				
			||||||
 | 
								max-height: 260px;
 | 
				
			||||||
 | 
								overflow-y: auto;
 | 
				
			||||||
 | 
								padding: 15px 15px 5px;
 | 
				
			||||||
 | 
								border-top: 1px solid #ebeef5;
 | 
				
			||||||
 | 
								.ele-col:nth-last-child(1),
 | 
				
			||||||
 | 
								.ele-col:nth-last-child(2) {
 | 
				
			||||||
 | 
									display: none;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								.awe-col:nth-child(-n + 24) {
 | 
				
			||||||
 | 
									display: none;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								.icon-selector-warp-item {
 | 
				
			||||||
 | 
									display: flex;
 | 
				
			||||||
 | 
									border: 1px solid #ebeef5;
 | 
				
			||||||
 | 
									padding: 10px;
 | 
				
			||||||
 | 
									border-radius: 5px;
 | 
				
			||||||
 | 
									margin-bottom: 10px;
 | 
				
			||||||
 | 
									transition: all 0.3s ease;
 | 
				
			||||||
 | 
									.icon-selector-warp-item-value {
 | 
				
			||||||
 | 
										transition: all 0.3s ease;
 | 
				
			||||||
 | 
										i {
 | 
				
			||||||
 | 
											font-size: 20px;
 | 
				
			||||||
 | 
											color: #606266;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									&:hover {
 | 
				
			||||||
 | 
										border: 1px solid var(--color-primary);
 | 
				
			||||||
 | 
										cursor: pointer;
 | 
				
			||||||
 | 
										transition: all 0.3s ease;
 | 
				
			||||||
 | 
										.icon-selector-warp-item-value {
 | 
				
			||||||
 | 
											i {
 | 
				
			||||||
 | 
												color: var(--color-primary);
 | 
				
			||||||
 | 
												transition: all 0.3s ease;
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								.icon-selector-active {
 | 
				
			||||||
 | 
									border: 1px solid var(--color-primary);
 | 
				
			||||||
 | 
									.icon-selector-warp-item-value {
 | 
				
			||||||
 | 
										i {
 | 
				
			||||||
 | 
											color: var(--color-primary);
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							.icon-selector-all {
 | 
				
			||||||
 | 
								.el-input {
 | 
				
			||||||
 | 
									padding: 0 15px;
 | 
				
			||||||
 | 
									margin-bottom: 10px;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								&-tabs {
 | 
				
			||||||
 | 
									display: flex;
 | 
				
			||||||
 | 
									height: 30px;
 | 
				
			||||||
 | 
									line-height: 30px;
 | 
				
			||||||
 | 
									padding: 0 15px;
 | 
				
			||||||
 | 
									margin-bottom: 5px;
 | 
				
			||||||
 | 
									&-item {
 | 
				
			||||||
 | 
										flex: 1;
 | 
				
			||||||
 | 
										text-align: center;
 | 
				
			||||||
 | 
										cursor: pointer;
 | 
				
			||||||
 | 
										&:hover {
 | 
				
			||||||
 | 
											color: var(--color-primary);
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									&-active {
 | 
				
			||||||
 | 
										background: var(--color-primary);
 | 
				
			||||||
 | 
										border-radius: 5px;
 | 
				
			||||||
 | 
										.label {
 | 
				
			||||||
 | 
											color: #ffffff;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -4,3 +4,4 @@
 | 
				
			|||||||
@import './element.scss';
 | 
					@import './element.scss';
 | 
				
			||||||
@import './media/media.scss';
 | 
					@import './media/media.scss';
 | 
				
			||||||
@import './waves.scss';
 | 
					@import './waves.scss';
 | 
				
			||||||
 | 
					@import './iconSelector.scss';
 | 
				
			||||||
@@ -43,25 +43,25 @@ export default {
 | 
				
			|||||||
        const state = reactive({
 | 
					        const state = reactive({
 | 
				
			||||||
            topCardItemList: [
 | 
					            topCardItemList: [
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    title: '项目数',
 | 
					                    title: 'Linux机器',
 | 
				
			||||||
                    id: 'projectNum',
 | 
					 | 
				
			||||||
                    color: '#FEBB50',
 | 
					 | 
				
			||||||
                },
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    title: 'Linux机器数',
 | 
					 | 
				
			||||||
                    id: 'machineNum',
 | 
					                    id: 'machineNum',
 | 
				
			||||||
                    color: '#F95959',
 | 
					                    color: '#F95959',
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    title: '数据库总数',
 | 
					                    title: '数据库',
 | 
				
			||||||
                    id: 'dbNum',
 | 
					                    id: 'dbNum',
 | 
				
			||||||
                    color: '#8595F4',
 | 
					                    color: '#8595F4',
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    title: 'redis总数',
 | 
					                    title: 'redis',
 | 
				
			||||||
                    id: 'redisNum',
 | 
					                    id: 'redisNum',
 | 
				
			||||||
                    color: '#1abc9c',
 | 
					                    color: '#1abc9c',
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    title: 'Mongo',
 | 
				
			||||||
 | 
					                    id: 'mongoNum',
 | 
				
			||||||
 | 
					                    color: '#FEBB50',
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
            ],
 | 
					            ],
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -74,7 +74,7 @@ export default {
 | 
				
			|||||||
        const initNumCountUp = async () => {
 | 
					        const initNumCountUp = async () => {
 | 
				
			||||||
            const res: any = await indexApi.getIndexCount.request();
 | 
					            const res: any = await indexApi.getIndexCount.request();
 | 
				
			||||||
            nextTick(() => {
 | 
					            nextTick(() => {
 | 
				
			||||||
                new CountUp('projectNum', res.projectNum).start();
 | 
					                new CountUp('mongoNum', res.mongoNum).start();
 | 
				
			||||||
                new CountUp('machineNum', res.machineNum).start();
 | 
					                new CountUp('machineNum', res.machineNum).start();
 | 
				
			||||||
                new CountUp('dbNum', res.dbNum).start();
 | 
					                new CountUp('dbNum', res.dbNum).start();
 | 
				
			||||||
                new CountUp('redisNum', res.redisNum).start();
 | 
					                new CountUp('redisNum', res.redisNum).start();
 | 
				
			||||||
@@ -87,20 +87,20 @@ export default {
 | 
				
			|||||||
                    router.push('/personal');
 | 
					                    router.push('/personal');
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                case 'projectNum': {
 | 
					                case 'mongoNum': {
 | 
				
			||||||
                    router.push('/ops/projects');
 | 
					                    router.push('/mongo/mongo-data-operation');
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                case 'machineNum': {
 | 
					                case 'machineNum': {
 | 
				
			||||||
                    router.push('/ops/machines');
 | 
					                    router.push('/machine/machines');
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                case 'dbNum': {
 | 
					                case 'dbNum': {
 | 
				
			||||||
                    router.push('/ops/dbms/dbs');
 | 
					                    router.push('/dbms/sql-exec');
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                case 'redisNum': {
 | 
					                case 'redisNum': {
 | 
				
			||||||
                    router.push('/ops/redis/manage');
 | 
					                    router.push('/redis/data-operation');
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,7 +8,7 @@
 | 
				
			|||||||
            </el-form-item>
 | 
					            </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            <el-form-item prop="env" label="env" label-width="33px">
 | 
					            <el-form-item prop="env" label="env" label-width="33px">
 | 
				
			||||||
                <el-select style="width: 80px" v-model="envId" placeholder="环境" @change="changeEnv" filterable>
 | 
					                <el-select style="width: 85px" v-model="envId" placeholder="环境" @change="changeEnv" filterable>
 | 
				
			||||||
                    <el-option v-for="item in envs" :key="item.id" :label="item.name" :value="item.id">
 | 
					                    <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: left">{{ item.name }}</span>
 | 
				
			||||||
                        <span style="float: right; color: #8492a6; font-size: 13px">{{ item.remark }}</span>
 | 
					                        <span style="float: right; color: #8492a6; font-size: 13px">{{ item.remark }}</span>
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										81
									
								
								mayfly_go_web/src/views/ops/component/TagSelect.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								mayfly_go_web/src/views/ops/component/TagSelect.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,81 @@
 | 
				
			|||||||
 | 
					<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">
 | 
				
			||||||
 | 
					import { toRefs, reactive, defineComponent, onMounted } from 'vue';
 | 
				
			||||||
 | 
					import { tagApi } from '../tag/api';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default defineComponent({
 | 
				
			||||||
 | 
					    name: 'TagSelect',
 | 
				
			||||||
 | 
					    props: {
 | 
				
			||||||
 | 
					        tagId: {
 | 
				
			||||||
 | 
					            type: Number,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        tagPath: {
 | 
				
			||||||
 | 
					            type: String,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    setup(props: any, { emit }) {
 | 
				
			||||||
 | 
					        const state = reactive({
 | 
				
			||||||
 | 
					            tags: [],
 | 
				
			||||||
 | 
					            // 单选则为id,多选为id数组
 | 
				
			||||||
 | 
					            selectTags: null as any,
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        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);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            ...toRefs(state),
 | 
				
			||||||
 | 
					            changeTag,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					<style lang="scss">
 | 
				
			||||||
 | 
					</style>
 | 
				
			||||||
@@ -2,17 +2,10 @@
 | 
				
			|||||||
    <div>
 | 
					    <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 :model="form" ref="dbForm" :rules="rules" label-width="95px">
 | 
				
			||||||
                <el-form-item prop="projectId" label="项目:" required>
 | 
					                <el-form-item prop="tagId" label="标签:" required>
 | 
				
			||||||
                    <el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
 | 
					                    <tag-select v-model:tag-id="form.tagId" v-model:tag-path="form.tagPath" style="width: 100%" />
 | 
				
			||||||
                        <el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
 | 
					 | 
				
			||||||
                    </el-select>
 | 
					 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                <el-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-form-item prop="name" label="别名:" required>
 | 
				
			||||||
                    <el-input v-model.trim="form.name" placeholder="请输入数据库别名" auto-complete="off"></el-input>
 | 
					                    <el-input v-model.trim="form.name" placeholder="请输入数据库别名" auto-complete="off"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
@@ -76,6 +69,10 @@
 | 
				
			|||||||
                    </el-col>
 | 
					                    </el-col>
 | 
				
			||||||
                </el-form-item>
 | 
					                </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-form-item prop="enableSshTunnel" label="SSH隧道:">
 | 
				
			||||||
                    <el-col :span="3">
 | 
					                    <el-col :span="3">
 | 
				
			||||||
                        <el-checkbox @change="getSshTunnelMachines" v-model="form.enableSshTunnel" :true-label="1" :false-label="-1"></el-checkbox>
 | 
					                        <el-checkbox @change="getSshTunnelMachines" v-model="form.enableSshTunnel" :true-label="1" :false-label="-1"></el-checkbox>
 | 
				
			||||||
@@ -108,14 +105,17 @@
 | 
				
			|||||||
<script lang="ts">
 | 
					<script lang="ts">
 | 
				
			||||||
import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
 | 
					import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
 | 
				
			||||||
import { dbApi } from './api';
 | 
					import { dbApi } from './api';
 | 
				
			||||||
import { projectApi } from '../project/api.ts';
 | 
					 | 
				
			||||||
import { machineApi } from '../machine/api.ts';
 | 
					import { machineApi } from '../machine/api.ts';
 | 
				
			||||||
import { ElMessage } from 'element-plus';
 | 
					import { ElMessage } from 'element-plus';
 | 
				
			||||||
import { notBlank } from '@/common/assert';
 | 
					import { notBlank } from '@/common/assert';
 | 
				
			||||||
import { RsaEncrypt } from '@/common/rsa';
 | 
					import { RsaEncrypt } from '@/common/rsa';
 | 
				
			||||||
 | 
					import TagSelect from '../component/TagSelect.vue';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'DbEdit',
 | 
					    name: 'DbEdit',
 | 
				
			||||||
 | 
					    components: {
 | 
				
			||||||
 | 
					        TagSelect,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    props: {
 | 
					    props: {
 | 
				
			||||||
        visible: {
 | 
					        visible: {
 | 
				
			||||||
            type: Boolean,
 | 
					            type: Boolean,
 | 
				
			||||||
@@ -139,10 +139,14 @@ export default defineComponent({
 | 
				
			|||||||
            envs: [],
 | 
					            envs: [],
 | 
				
			||||||
            allDatabases: [] as any,
 | 
					            allDatabases: [] as any,
 | 
				
			||||||
            databaseList: [] as any,
 | 
					            databaseList: [] as any,
 | 
				
			||||||
            sshTunnelMachineList: [],
 | 
					            sshTunnelMachineList: [] as any,
 | 
				
			||||||
            form: {
 | 
					            form: {
 | 
				
			||||||
                id: null,
 | 
					                id: null,
 | 
				
			||||||
 | 
					                tagId: null as any,
 | 
				
			||||||
 | 
					                tagPath: null as any,
 | 
				
			||||||
 | 
					                type: null,
 | 
				
			||||||
                name: null,
 | 
					                name: null,
 | 
				
			||||||
 | 
					                host: '',
 | 
				
			||||||
                port: 3306,
 | 
					                port: 3306,
 | 
				
			||||||
                username: null,
 | 
					                username: null,
 | 
				
			||||||
                password: null,
 | 
					                password: null,
 | 
				
			||||||
@@ -152,6 +156,7 @@ export default defineComponent({
 | 
				
			|||||||
                projectId: null,
 | 
					                projectId: null,
 | 
				
			||||||
                envId: null,
 | 
					                envId: null,
 | 
				
			||||||
                env: null,
 | 
					                env: null,
 | 
				
			||||||
 | 
					                remark: '',
 | 
				
			||||||
                enableSshTunnel: null,
 | 
					                enableSshTunnel: null,
 | 
				
			||||||
                sshTunnelMachineId: null,
 | 
					                sshTunnelMachineId: null,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
@@ -218,7 +223,6 @@ export default defineComponent({
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            state.projects = newValue.projects;
 | 
					            state.projects = newValue.projects;
 | 
				
			||||||
            if (newValue.db) {
 | 
					            if (newValue.db) {
 | 
				
			||||||
                getEnvs(newValue.db.projectId);
 | 
					 | 
				
			||||||
                state.form = { ...newValue.db };
 | 
					                state.form = { ...newValue.db };
 | 
				
			||||||
                // 将数据库名使用空格切割,获取所有数据库列表
 | 
					                // 将数据库名使用空格切割,获取所有数据库列表
 | 
				
			||||||
                state.databaseList = newValue.db.database.split(' ');
 | 
					                state.databaseList = newValue.db.database.split(' ');
 | 
				
			||||||
@@ -244,22 +248,6 @@ export default defineComponent({
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        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) => {
 | 
					        const changeEnv = (envId: number) => {
 | 
				
			||||||
            for (let p of state.envs as any) {
 | 
					            for (let p of state.envs as any) {
 | 
				
			||||||
                if (p.id == envId) {
 | 
					                if (p.id == envId) {
 | 
				
			||||||
@@ -272,7 +260,7 @@ export default defineComponent({
 | 
				
			|||||||
            const reqForm = { ...state.form };
 | 
					            const reqForm = { ...state.form };
 | 
				
			||||||
            reqForm.password = await RsaEncrypt(reqForm.password);
 | 
					            reqForm.password = await RsaEncrypt(reqForm.password);
 | 
				
			||||||
            state.allDatabases = await dbApi.getAllDatabase.request(reqForm);
 | 
					            state.allDatabases = await dbApi.getAllDatabase.request(reqForm);
 | 
				
			||||||
            ElMessage.success('获取成功, 请选择需要管理操作的数据库')
 | 
					            ElMessage.success('获取成功, 请选择需要管理操作的数据库');
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const getDbPwd = async () => {
 | 
					        const getDbPwd = async () => {
 | 
				
			||||||
@@ -324,7 +312,6 @@ export default defineComponent({
 | 
				
			|||||||
            getDbPwd,
 | 
					            getDbPwd,
 | 
				
			||||||
            changeDatabase,
 | 
					            changeDatabase,
 | 
				
			||||||
            getSshTunnelMachines,
 | 
					            getSshTunnelMachines,
 | 
				
			||||||
            changeProject,
 | 
					 | 
				
			||||||
            changeEnv,
 | 
					            changeEnv,
 | 
				
			||||||
            btnOk,
 | 
					            btnOk,
 | 
				
			||||||
            cancel,
 | 
					            cancel,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,8 +7,8 @@
 | 
				
			|||||||
                >删除</el-button
 | 
					                >删除</el-button
 | 
				
			||||||
            >
 | 
					            >
 | 
				
			||||||
            <div style="float: right">
 | 
					            <div style="float: right">
 | 
				
			||||||
                <el-select @focus="getProjects" v-model="query.projectId" placeholder="请选择项目" filterable clearable>
 | 
					                <el-select @focus="getTags" v-model="query.tagPath" placeholder="请选择标签" filterable clearable>
 | 
				
			||||||
                    <el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
 | 
					                    <el-option v-for="item in tags" :key="item" :label="item" :value="item"> </el-option>
 | 
				
			||||||
                </el-select>
 | 
					                </el-select>
 | 
				
			||||||
                <el-button v-waves type="primary" icon="search" @click="search()" class="ml5">查询</el-button>
 | 
					                <el-button v-waves type="primary" icon="search" @click="search()" class="ml5">查询</el-button>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
@@ -20,8 +20,7 @@
 | 
				
			|||||||
                        </el-radio>
 | 
					                        </el-radio>
 | 
				
			||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
                </el-table-column>
 | 
					                </el-table-column>
 | 
				
			||||||
                <el-table-column prop="project" label="项目" min-width="100" show-overflow-tooltip></el-table-column>
 | 
					                <el-table-column prop="tagPath" label="标签路径" min-width="150" show-overflow-tooltip></el-table-column>
 | 
				
			||||||
                <el-table-column prop="env" label="环境" min-width="100"></el-table-column>
 | 
					 | 
				
			||||||
                <el-table-column prop="name" label="名称" min-width="160" 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>
 | 
					                <el-table-column min-width="170" label="host:port" show-overflow-tooltip>
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
@@ -42,13 +41,14 @@
 | 
				
			|||||||
                                size="small"
 | 
					                                size="small"
 | 
				
			||||||
                                v-for="db in scope.row.dbs"
 | 
					                                v-for="db in scope.row.dbs"
 | 
				
			||||||
                                :key="db"
 | 
					                                :key="db"
 | 
				
			||||||
                                style="cursor: pointer; margin-left: 3px; margin-bottom: 3px;"
 | 
					                                style="cursor: pointer; margin-left: 3px; margin-bottom: 3px"
 | 
				
			||||||
                                >{{ db }}</el-tag
 | 
					                                >{{ db }}</el-tag
 | 
				
			||||||
                            >
 | 
					                            >
 | 
				
			||||||
                        </el-popover>
 | 
					                        </el-popover>
 | 
				
			||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
                </el-table-column>
 | 
					                </el-table-column>
 | 
				
			||||||
                <el-table-column prop="username" label="用户名" min-width="100"></el-table-column>
 | 
					                <el-table-column prop="username" label="用户名" min-width="100"></el-table-column>
 | 
				
			||||||
 | 
					                <el-table-column 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="115" prop="creator" label="创建账号"></el-table-column>
 | 
				
			||||||
                <el-table-column min-width="160" prop="createTime" label="创建时间" show-overflow-tooltip>
 | 
					                <el-table-column min-width="160" prop="createTime" label="创建时间" show-overflow-tooltip>
 | 
				
			||||||
@@ -190,7 +190,7 @@
 | 
				
			|||||||
                <el-table-column prop="creator" label="执行人" min-width="60" show-overflow-tooltip> </el-table-column>
 | 
					                <el-table-column prop="creator" label="执行人" min-width="60" show-overflow-tooltip> </el-table-column>
 | 
				
			||||||
                <el-table-column prop="createTime" label="执行时间" show-overflow-tooltip>
 | 
					                <el-table-column prop="createTime" label="执行时间" show-overflow-tooltip>
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        {{ $filters.dateFormat(scope.row.createTime) }}
 | 
					                        {{ dateFormat(scope.row.createTime) }}
 | 
				
			||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
                </el-table-column>
 | 
					                </el-table-column>
 | 
				
			||||||
                <el-table-column prop="remark" label="备注" min-width="60" show-overflow-tooltip> </el-table-column>
 | 
					                <el-table-column prop="remark" label="备注" min-width="60" show-overflow-tooltip> </el-table-column>
 | 
				
			||||||
@@ -249,12 +249,11 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        <db-edit
 | 
					        <db-edit
 | 
				
			||||||
            @val-change="valChange"
 | 
					            @val-change="valChange"
 | 
				
			||||||
            :projects="projects"
 | 
					 | 
				
			||||||
            :title="dbEditDialog.title"
 | 
					            :title="dbEditDialog.title"
 | 
				
			||||||
            v-model:visible="dbEditDialog.visible"
 | 
					            v-model:visible="dbEditDialog.visible"
 | 
				
			||||||
            v-model:db="dbEditDialog.data"
 | 
					            v-model:db="dbEditDialog.data"
 | 
				
			||||||
        ></db-edit>
 | 
					        ></db-edit>
 | 
				
			||||||
        <create-table :dbId="dbId" v-model:visible="tableCreateDialog.visible"></create-table>
 | 
					        <create-table :dbId="dbId" :db="db" v-model:visible="tableCreateDialog.visible"></create-table>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -266,11 +265,12 @@ import DbEdit from './DbEdit.vue';
 | 
				
			|||||||
import CreateTable from './CreateTable.vue';
 | 
					import CreateTable from './CreateTable.vue';
 | 
				
			||||||
import { dbApi } from './api';
 | 
					import { dbApi } from './api';
 | 
				
			||||||
import enums from './enums';
 | 
					import enums from './enums';
 | 
				
			||||||
import { projectApi } from '../project/api.ts';
 | 
					 | 
				
			||||||
import SqlExecBox from './component/SqlExecBox.ts';
 | 
					import SqlExecBox from './component/SqlExecBox.ts';
 | 
				
			||||||
import config from '@/common/config';
 | 
					import config from '@/common/config';
 | 
				
			||||||
import { getSession } from '@/common/utils/storage';
 | 
					import { getSession } from '@/common/utils/storage';
 | 
				
			||||||
import { isTrue } from '@/common/assert';
 | 
					import { isTrue } from '@/common/assert';
 | 
				
			||||||
 | 
					import { tagApi } from '../tag/api.ts';
 | 
				
			||||||
 | 
					import { dateFormat } from '@/common/utils/date';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'DbList',
 | 
					    name: 'DbList',
 | 
				
			||||||
@@ -286,7 +286,7 @@ export default defineComponent({
 | 
				
			|||||||
                saveDb: 'db:save',
 | 
					                saveDb: 'db:save',
 | 
				
			||||||
                delDb: 'db:del',
 | 
					                delDb: 'db:del',
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            projects: [],
 | 
					            tags: [],
 | 
				
			||||||
            chooseId: null,
 | 
					            chooseId: null,
 | 
				
			||||||
            /**
 | 
					            /**
 | 
				
			||||||
             * 选中的数据
 | 
					             * 选中的数据
 | 
				
			||||||
@@ -296,6 +296,7 @@ export default defineComponent({
 | 
				
			|||||||
             * 查询条件
 | 
					             * 查询条件
 | 
				
			||||||
             */
 | 
					             */
 | 
				
			||||||
            query: {
 | 
					            query: {
 | 
				
			||||||
 | 
					                tagPath: null,
 | 
				
			||||||
                pageNum: 1,
 | 
					                pageNum: 1,
 | 
				
			||||||
                pageSize: 10,
 | 
					                pageSize: 10,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
@@ -406,12 +407,11 @@ export default defineComponent({
 | 
				
			|||||||
            search();
 | 
					            search();
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const getProjects = async () => {
 | 
					        const getTags = async () => {
 | 
				
			||||||
            state.projects = await projectApi.accountProjects.request(null);
 | 
					            state.tags = await tagApi.getAccountTags.request(null);
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const editDb = async (isAdd = false) => {
 | 
					        const editDb = async (isAdd = false) => {
 | 
				
			||||||
            await getProjects();
 | 
					 | 
				
			||||||
            if (isAdd) {
 | 
					            if (isAdd) {
 | 
				
			||||||
                state.dbEditDialog.data = null;
 | 
					                state.dbEditDialog.data = null;
 | 
				
			||||||
                state.dbEditDialog.title = '新增数据库资源';
 | 
					                state.dbEditDialog.title = '新增数据库资源';
 | 
				
			||||||
@@ -616,7 +616,8 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
            getProjects,
 | 
					            dateFormat,
 | 
				
			||||||
 | 
					            getTags,
 | 
				
			||||||
            filterTableInfos,
 | 
					            filterTableInfos,
 | 
				
			||||||
            enums,
 | 
					            enums,
 | 
				
			||||||
            search,
 | 
					            search,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,46 +3,56 @@
 | 
				
			|||||||
        <div class="toolbar">
 | 
					        <div class="toolbar">
 | 
				
			||||||
            <el-row type="flex" justify="space-between">
 | 
					            <el-row type="flex" justify="space-between">
 | 
				
			||||||
                <el-col :span="24">
 | 
					                <el-col :span="24">
 | 
				
			||||||
                    <project-env-select @changeProjectEnv="changeProjectEnv">
 | 
					                    <el-form class="search-form" label-position="right" :inline="true">
 | 
				
			||||||
                        <template #default>
 | 
					                        <el-form-item label="标签">
 | 
				
			||||||
                            <el-form-item label="资源">
 | 
					                            <el-select @change="changeTag" @focus="getTags" v-model="params.tagPath" placeholder="请选择标签" filterable style="width: 220px">
 | 
				
			||||||
                                <el-select v-model="dbId" placeholder="请选择资源实例" @change="changeDbInstance" filterable style="width: 150px">
 | 
					                                <el-option v-for="item in tags" :key="item" :label="item" :value="item"> </el-option>
 | 
				
			||||||
                                    <el-option v-for="item in dbs" :key="item.id" :label="item.name" :value="item.id">
 | 
					                            </el-select>
 | 
				
			||||||
                                        <span style="float: left">{{ item.name }}</span>
 | 
					                        </el-form-item>
 | 
				
			||||||
                                        <span style="float: right; color: #8492a6; margin-left: 6px; font-size: 13px">{{
 | 
					 | 
				
			||||||
                                            `${item.host}:${item.port} ${item.type}`
 | 
					 | 
				
			||||||
                                        }}</span>
 | 
					 | 
				
			||||||
                                    </el-option>
 | 
					 | 
				
			||||||
                                </el-select>
 | 
					 | 
				
			||||||
                            </el-form-item>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            <el-form-item label="数据库">
 | 
					                        <el-form-item label="资源">
 | 
				
			||||||
                                <el-select
 | 
					                            <el-select v-model="dbId" placeholder="请选择资源实例" @change="changeDbInstance" filterable style="width: 220px">
 | 
				
			||||||
                                    v-model="db"
 | 
					                                <el-option v-for="item in dbs" :key="item.id" :label="`${item.name} [${item.tagPath}]`" :value="item.id">
 | 
				
			||||||
                                    placeholder="请选择数据库"
 | 
					                                    <span style="float: left">{{ `${item.name} [${item.tagPath}]` }}</span>
 | 
				
			||||||
                                    @change="changeDb"
 | 
					                                    <span style="float: rignt; color: #8492a6; margin-left: 10px; font-size: 13px">{{
 | 
				
			||||||
                                    @clear="clearDb"
 | 
					                                        `${item.host}:${item.port} ${item.type}`
 | 
				
			||||||
                                    clearable
 | 
					                                    }}</span>
 | 
				
			||||||
                                    filterable
 | 
					                                </el-option>
 | 
				
			||||||
                                    style="width: 150px"
 | 
					                            </el-select>
 | 
				
			||||||
 | 
					                        </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        <el-form-item label="数据库">
 | 
				
			||||||
 | 
					                            <el-select
 | 
				
			||||||
 | 
					                                v-model="db"
 | 
				
			||||||
 | 
					                                placeholder="请选择数据库"
 | 
				
			||||||
 | 
					                                @change="changeDb"
 | 
				
			||||||
 | 
					                                @clear="clearDb"
 | 
				
			||||||
 | 
					                                clearable
 | 
				
			||||||
 | 
					                                filterable
 | 
				
			||||||
 | 
					                                style="width: 150px"
 | 
				
			||||||
 | 
					                            >
 | 
				
			||||||
 | 
					                                <el-option v-for="item in databaseList" :key="item" :label="item" :value="item"> </el-option>
 | 
				
			||||||
 | 
					                            </el-select>
 | 
				
			||||||
 | 
					                        </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        <el-form-item label-width="20" label="表">
 | 
				
			||||||
 | 
					                            <el-select v-model="tableName" placeholder="选择表查看表数据" @change="changeTable" filterable style="width: 250px">
 | 
				
			||||||
 | 
					                                <el-option
 | 
				
			||||||
 | 
					                                    v-for="item in tableMetadata"
 | 
				
			||||||
 | 
					                                    :key="item.tableName"
 | 
				
			||||||
 | 
					                                    :label="item.tableName + (item.tableComment != '' ? `【${item.tableComment}】` : '')"
 | 
				
			||||||
 | 
					                                    :value="item.tableName"
 | 
				
			||||||
                                >
 | 
					                                >
 | 
				
			||||||
                                    <el-option v-for="item in databaseList" :key="item" :label="item" :value="item"> </el-option>
 | 
					                                </el-option>
 | 
				
			||||||
                                </el-select>
 | 
					                            </el-select>
 | 
				
			||||||
                            </el-form-item>
 | 
					                        </el-form-item>
 | 
				
			||||||
 | 
					                    </el-form>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    <!-- <project-env-select @changeTag="changeTag">
 | 
				
			||||||
 | 
					                        <template #default>
 | 
				
			||||||
                            
 | 
					                            
 | 
				
			||||||
                            <el-form-item label-width="20" label="表">
 | 
					 | 
				
			||||||
                                <el-select v-model="tableName" placeholder="选择表查看表数据" @change="changeTable" filterable style="width: 250px">
 | 
					 | 
				
			||||||
                                    <el-option
 | 
					 | 
				
			||||||
                                        v-for="item in tableMetadata"
 | 
					 | 
				
			||||||
                                        :key="item.tableName"
 | 
					 | 
				
			||||||
                                        :label="item.tableName + (item.tableComment != '' ? `【${item.tableComment}】` : '')"
 | 
					 | 
				
			||||||
                                        :value="item.tableName"
 | 
					 | 
				
			||||||
                                    >
 | 
					 | 
				
			||||||
                                    </el-option>
 | 
					 | 
				
			||||||
                                </el-select>
 | 
					 | 
				
			||||||
                            </el-form-item>
 | 
					 | 
				
			||||||
                        </template>
 | 
					                        </template>
 | 
				
			||||||
                    </project-env-select>
 | 
					                    </project-env-select> -->
 | 
				
			||||||
                </el-col>
 | 
					                </el-col>
 | 
				
			||||||
            </el-row>
 | 
					            </el-row>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
@@ -316,17 +326,15 @@ import 'codemirror/addon/hint/sql-hint.js';
 | 
				
			|||||||
import { format as sqlFormatter } from 'sql-formatter';
 | 
					import { format as sqlFormatter } from 'sql-formatter';
 | 
				
			||||||
import { notBlank, notEmpty, isTrue } from '@/common/assert';
 | 
					import { notBlank, notEmpty, isTrue } from '@/common/assert';
 | 
				
			||||||
import { ElMessage, ElMessageBox } from 'element-plus';
 | 
					import { ElMessage, ElMessageBox } from 'element-plus';
 | 
				
			||||||
import ProjectEnvSelect from '../component/ProjectEnvSelect.vue';
 | 
					 | 
				
			||||||
import config from '@/common/config';
 | 
					import config from '@/common/config';
 | 
				
			||||||
import { getSession } from '@/common/utils/storage';
 | 
					import { getSession } from '@/common/utils/storage';
 | 
				
			||||||
import SqlExecBox from './component/SqlExecBox';
 | 
					import SqlExecBox from './component/SqlExecBox';
 | 
				
			||||||
import { dateStrFormat } from '@/common/utils/date.ts';
 | 
					import { dateStrFormat } from '@/common/utils/date.ts';
 | 
				
			||||||
 | 
					import { tagApi } from '../tag/api.ts';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'SqlExec',
 | 
					    name: 'SqlExec',
 | 
				
			||||||
    components: {
 | 
					    components: {},
 | 
				
			||||||
        ProjectEnvSelect,
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    setup() {
 | 
					    setup() {
 | 
				
			||||||
        const codeTextarea: any = ref(null);
 | 
					        const codeTextarea: any = ref(null);
 | 
				
			||||||
        const token = getSession('token');
 | 
					        const token = getSession('token');
 | 
				
			||||||
@@ -336,11 +344,12 @@ export default defineComponent({
 | 
				
			|||||||
        const state = reactive({
 | 
					        const state = reactive({
 | 
				
			||||||
            token: token,
 | 
					            token: token,
 | 
				
			||||||
            defalutLimit: 20, // 默认查询数量
 | 
					            defalutLimit: 20, // 默认查询数量
 | 
				
			||||||
            dbs: [], // 数据库实例列表
 | 
					            tags: [],
 | 
				
			||||||
 | 
					            dbs: [] as any, // 数据库实例列表
 | 
				
			||||||
            databaseList: [], // 数据库实例拥有的数据库列表,1数据库实例  -> 多数据库
 | 
					            databaseList: [], // 数据库实例拥有的数据库列表,1数据库实例  -> 多数据库
 | 
				
			||||||
            db: '', // 当前操作的数据库
 | 
					            db: '', // 当前操作的数据库
 | 
				
			||||||
            dbType: '',
 | 
					            dbType: '',
 | 
				
			||||||
            tables: [],
 | 
					            tables: [] as any,
 | 
				
			||||||
            dbId: null, // 当前选中操作的数据库实例
 | 
					            dbId: null, // 当前选中操作的数据库实例
 | 
				
			||||||
            tableName: '',
 | 
					            tableName: '',
 | 
				
			||||||
            tableMetadata: [],
 | 
					            tableMetadata: [],
 | 
				
			||||||
@@ -349,7 +358,7 @@ export default defineComponent({
 | 
				
			|||||||
            activeName: 'Query',
 | 
					            activeName: 'Query',
 | 
				
			||||||
            queryTabName: 'Query',
 | 
					            queryTabName: 'Query',
 | 
				
			||||||
            nowTableName: '', // 当前表格数据操作的数据库表名,用于双击编辑表内容使用
 | 
					            nowTableName: '', // 当前表格数据操作的数据库表名,用于双击编辑表内容使用
 | 
				
			||||||
            dataTabs: {}, // 点击表信息后执行结果数据展示tabs
 | 
					            dataTabs: {} as any, // 点击表信息后执行结果数据展示tabs
 | 
				
			||||||
            dataTabsTableHeight: 600,
 | 
					            dataTabsTableHeight: 600,
 | 
				
			||||||
            // 查询tab
 | 
					            // 查询tab
 | 
				
			||||||
            queryTab: {
 | 
					            queryTab: {
 | 
				
			||||||
@@ -366,8 +375,8 @@ export default defineComponent({
 | 
				
			|||||||
            },
 | 
					            },
 | 
				
			||||||
            params: {
 | 
					            params: {
 | 
				
			||||||
                pageNum: 1,
 | 
					                pageNum: 1,
 | 
				
			||||||
                pageSize: 10,
 | 
					                pageSize: 100,
 | 
				
			||||||
                envId: null,
 | 
					                tagPath: null,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            conditionDialog: {
 | 
					            conditionDialog: {
 | 
				
			||||||
                title: '',
 | 
					                title: '',
 | 
				
			||||||
@@ -440,16 +449,17 @@ export default defineComponent({
 | 
				
			|||||||
        /**
 | 
					        /**
 | 
				
			||||||
         * 项目及环境更改后的回调事件
 | 
					         * 项目及环境更改后的回调事件
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
        const changeProjectEnv = (projectId: any, envId: any) => {
 | 
					        const changeTag = () => {
 | 
				
			||||||
            state.dbs = [];
 | 
					            state.dbs = [];
 | 
				
			||||||
            state.dbId = null;
 | 
					            state.dbId = null;
 | 
				
			||||||
            state.db = '';
 | 
					            state.db = '';
 | 
				
			||||||
            state.databaseList = [];
 | 
					            state.databaseList = [];
 | 
				
			||||||
            clearDb();
 | 
					            clearDb();
 | 
				
			||||||
            if (envId != null) {
 | 
					            search();
 | 
				
			||||||
                state.params.envId = envId;
 | 
					        };
 | 
				
			||||||
                search();
 | 
					
 | 
				
			||||||
            }
 | 
					        const getTags = async () => {
 | 
				
			||||||
 | 
					            state.tags = await tagApi.getAccountTags.request(null);
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const onBeforeChange = (instance: any, changeObj: any) => {
 | 
					        const onBeforeChange = (instance: any, changeObj: any) => {
 | 
				
			||||||
@@ -1221,8 +1231,9 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
 | 
					            getTags,
 | 
				
			||||||
            codeTextarea,
 | 
					            codeTextarea,
 | 
				
			||||||
            changeProjectEnv,
 | 
					            changeTag,
 | 
				
			||||||
            changeTable,
 | 
					            changeTable,
 | 
				
			||||||
            cellClick,
 | 
					            cellClick,
 | 
				
			||||||
            onRunSql,
 | 
					            onRunSql,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -88,27 +88,24 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                state.btnLoading = true;
 | 
					                state.btnLoading = true;
 | 
				
			||||||
                const res = await dbApi.sqlExec.request({
 | 
					                await dbApi.sqlExec.request({
 | 
				
			||||||
                    id: state.dbId,
 | 
					                    id: state.dbId,
 | 
				
			||||||
                    db: state.db,
 | 
					                    db: state.db,
 | 
				
			||||||
                    remark: state.remark,
 | 
					                    remark: state.remark,
 | 
				
			||||||
                    sql: state.sqlValue.trim(),
 | 
					                    sql: state.sqlValue.trim(),
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
                if (parseInt(res.res[0].影响条数) >= 1) {
 | 
					                ElMessage.success('执行成功');
 | 
				
			||||||
                    ElMessage.success('执行成功');
 | 
					                runSuccess = true;
 | 
				
			||||||
                    runSuccess = true;
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    ElMessage.error('执行失败');
 | 
					 | 
				
			||||||
                    runSuccess = false;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            } catch (e) {
 | 
					            } catch (e) {
 | 
				
			||||||
                runSuccess = false;
 | 
					                runSuccess = false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (runSuccess && runSuccessCallback) {
 | 
					            if (runSuccess) {
 | 
				
			||||||
                runSuccessCallback();
 | 
					                if (runSuccessCallback) {
 | 
				
			||||||
 | 
					                    runSuccessCallback();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                cancel();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            state.btnLoading = false;
 | 
					            state.btnLoading = false;
 | 
				
			||||||
            cancel();
 | 
					 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const cancel = () => {
 | 
					        const cancel = () => {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,17 +2,15 @@
 | 
				
			|||||||
    <div>
 | 
					    <div>
 | 
				
			||||||
        <el-dialog :title="title" v-model="dialogVisible" :close-on-click-modal="false" :destroy-on-close="true" :before-close="cancel" width="38%">
 | 
					        <el-dialog :title="title" v-model="dialogVisible" :close-on-click-modal="false" :destroy-on-close="true" :before-close="cancel" width="38%">
 | 
				
			||||||
            <el-form :model="form" ref="machineForm" :rules="rules" label-width="85px">
 | 
					            <el-form :model="form" ref="machineForm" :rules="rules" label-width="85px">
 | 
				
			||||||
                <el-form-item prop="projectId" label="项目:" required>
 | 
					                <el-form-item prop="tagId" label="标签:" required>
 | 
				
			||||||
                    <el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
 | 
					                    <tag-select v-model:tag-id="form.tagId" v-model:tag-path="form.tagPath" style="width: 100%" />
 | 
				
			||||||
                        <el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
 | 
					 | 
				
			||||||
                    </el-select>
 | 
					 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="name" label="名称:" required>
 | 
					                <el-form-item prop="name" label="名称:" required>
 | 
				
			||||||
                    <el-input v-model.trim="form.name" placeholder="请输入机器别名" auto-complete="off"></el-input>
 | 
					                    <el-input v-model.trim="form.name" placeholder="请输入机器别名" auto-complete="off"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="ip" label="ip:" required>
 | 
					                <el-form-item prop="ip" label="ip:" required>
 | 
				
			||||||
                    <el-col :span="18">
 | 
					                    <el-col :span="18">
 | 
				
			||||||
                        <el-input :disabled="form.id" v-model.trim="form.ip" placeholder="主机ip" auto-complete="off"></el-input>
 | 
					                        <el-input :disabled="form.id != 0" v-model.trim="form.ip" placeholder="主机ip" auto-complete="off"></el-input>
 | 
				
			||||||
                    </el-col>
 | 
					                    </el-col>
 | 
				
			||||||
                    <el-col style="text-align: center" :span="1">:</el-col>
 | 
					                    <el-col style="text-align: center" :span="1">:</el-col>
 | 
				
			||||||
                    <el-col :span="5">
 | 
					                    <el-col :span="5">
 | 
				
			||||||
@@ -91,9 +89,13 @@ import { machineApi } from './api';
 | 
				
			|||||||
import { ElMessage } from 'element-plus';
 | 
					import { ElMessage } from 'element-plus';
 | 
				
			||||||
import { notBlank } from '@/common/assert';
 | 
					import { notBlank } from '@/common/assert';
 | 
				
			||||||
import { RsaEncrypt } from '@/common/rsa';
 | 
					import { RsaEncrypt } from '@/common/rsa';
 | 
				
			||||||
 | 
					import TagSelect from '../component/TagSelect.vue';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'MachineEdit',
 | 
					    name: 'MachineEdit',
 | 
				
			||||||
 | 
					    components: {
 | 
				
			||||||
 | 
					        TagSelect,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    props: {
 | 
					    props: {
 | 
				
			||||||
        visible: {
 | 
					        visible: {
 | 
				
			||||||
            type: Boolean,
 | 
					            type: Boolean,
 | 
				
			||||||
@@ -112,12 +114,15 @@ export default defineComponent({
 | 
				
			|||||||
        const machineForm: any = ref(null);
 | 
					        const machineForm: any = ref(null);
 | 
				
			||||||
        const state = reactive({
 | 
					        const state = reactive({
 | 
				
			||||||
            dialogVisible: false,
 | 
					            dialogVisible: false,
 | 
				
			||||||
            projects: [],
 | 
					            projects: [] as any,
 | 
				
			||||||
            sshTunnelMachineList: [],
 | 
					            sshTunnelMachineList: [] as any,
 | 
				
			||||||
 | 
					            tags: [],
 | 
				
			||||||
 | 
					            selectTags: [],
 | 
				
			||||||
            form: {
 | 
					            form: {
 | 
				
			||||||
                id: null,
 | 
					                id: null,
 | 
				
			||||||
                projectId: null,
 | 
					                tagId: null as any,
 | 
				
			||||||
                projectName: null,
 | 
					                tagPath: '',
 | 
				
			||||||
 | 
					                ip: null,
 | 
				
			||||||
                name: null,
 | 
					                name: null,
 | 
				
			||||||
                authMethod: 1,
 | 
					                authMethod: 1,
 | 
				
			||||||
                port: 22,
 | 
					                port: 22,
 | 
				
			||||||
@@ -131,17 +136,10 @@ export default defineComponent({
 | 
				
			|||||||
            pwd: '',
 | 
					            pwd: '',
 | 
				
			||||||
            btnLoading: false,
 | 
					            btnLoading: false,
 | 
				
			||||||
            rules: {
 | 
					            rules: {
 | 
				
			||||||
                projectId: [
 | 
					                tagId: [
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        required: true,
 | 
					                        required: true,
 | 
				
			||||||
                        message: '请选择项目',
 | 
					                        message: '请选择标签',
 | 
				
			||||||
                        trigger: ['change', 'blur'],
 | 
					 | 
				
			||||||
                    },
 | 
					 | 
				
			||||||
                ],
 | 
					 | 
				
			||||||
                envId: [
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        required: true,
 | 
					 | 
				
			||||||
                        message: '请选择环境',
 | 
					 | 
				
			||||||
                        trigger: ['change', 'blur'],
 | 
					                        trigger: ['change', 'blur'],
 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
                ],
 | 
					                ],
 | 
				
			||||||
@@ -206,14 +204,6 @@ export default defineComponent({
 | 
				
			|||||||
            state.pwd = await machineApi.getMachinePwd.request({ id: state.form.id });
 | 
					            state.pwd = await machineApi.getMachinePwd.request({ id: state.form.id });
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const changeProject = (projectId: number) => {
 | 
					 | 
				
			||||||
            for (let p of state.projects as any) {
 | 
					 | 
				
			||||||
                if (p.id == projectId) {
 | 
					 | 
				
			||||||
                    state.form.projectName = p.name;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const btnOk = async () => {
 | 
					        const btnOk = async () => {
 | 
				
			||||||
            if (!state.form.id) {
 | 
					            if (!state.form.id) {
 | 
				
			||||||
                notBlank(state.form.password, '新增操作,密码不可为空');
 | 
					                notBlank(state.form.password, '新增操作,密码不可为空');
 | 
				
			||||||
@@ -258,7 +248,6 @@ export default defineComponent({
 | 
				
			|||||||
            machineForm,
 | 
					            machineForm,
 | 
				
			||||||
            getSshTunnelMachines,
 | 
					            getSshTunnelMachines,
 | 
				
			||||||
            getPwd,
 | 
					            getPwd,
 | 
				
			||||||
            changeProject,
 | 
					 | 
				
			||||||
            btnOk,
 | 
					            btnOk,
 | 
				
			||||||
            cancel,
 | 
					            cancel,
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,21 +3,15 @@
 | 
				
			|||||||
        <el-card>
 | 
					        <el-card>
 | 
				
			||||||
            <div>
 | 
					            <div>
 | 
				
			||||||
                <el-button v-auth="'machine:add'" type="primary" icon="plus" @click="openFormDialog(false)" plain>添加</el-button>
 | 
					                <el-button v-auth="'machine:add'" type="primary" icon="plus" @click="openFormDialog(false)" plain>添加</el-button>
 | 
				
			||||||
                <el-button
 | 
					                <el-button v-auth="'machine:update'" type="primary" icon="edit" :disabled="!currentId" @click="openFormDialog(currentData)" plain
 | 
				
			||||||
                    v-auth="'machine:update'"
 | 
					 | 
				
			||||||
                    type="primary"
 | 
					 | 
				
			||||||
                    icon="edit"
 | 
					 | 
				
			||||||
                    :disabled="currentId == null"
 | 
					 | 
				
			||||||
                    @click="openFormDialog(currentData)"
 | 
					 | 
				
			||||||
                    plain
 | 
					 | 
				
			||||||
                    >编辑</el-button
 | 
					                    >编辑</el-button
 | 
				
			||||||
                >
 | 
					                >
 | 
				
			||||||
                <el-button v-auth="'machine:del'" :disabled="currentId == null" @click="deleteMachine(currentId)" type="danger" icon="delete"
 | 
					                <el-button v-auth="'machine:del'" :disabled="!currentId" @click="deleteMachine(currentId)" type="danger" icon="delete"
 | 
				
			||||||
                    >删除</el-button
 | 
					                    >删除</el-button
 | 
				
			||||||
                >
 | 
					                >
 | 
				
			||||||
                <div style="float: right">
 | 
					                <div style="float: right">
 | 
				
			||||||
                    <el-select @focus="getProjects" v-model="params.projectId" placeholder="请选择项目" @clear="search" filterable clearable>
 | 
					                    <el-select @focus="getTags" v-model="params.tagPath" placeholder="请选择标签" @clear="search" filterable clearable>
 | 
				
			||||||
                        <el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
 | 
					                        <el-option v-for="item in tags" :key="item" :label="item" :value="item"> </el-option>
 | 
				
			||||||
                    </el-select>
 | 
					                    </el-select>
 | 
				
			||||||
                    <el-input
 | 
					                    <el-input
 | 
				
			||||||
                        class="ml5"
 | 
					                        class="ml5"
 | 
				
			||||||
@@ -66,15 +60,15 @@
 | 
				
			|||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
                </el-table-column>
 | 
					                </el-table-column>
 | 
				
			||||||
                <el-table-column prop="username" label="用户名" min-width="90"></el-table-column>
 | 
					                <el-table-column prop="username" label="用户名" min-width="90"></el-table-column>
 | 
				
			||||||
                <el-table-column prop="projectName" label="项目" min-width="120"></el-table-column>
 | 
					                <el-table-column prop="tagPath" label="标签路径" min-width="150" show-overflow-tooltip></el-table-column>
 | 
				
			||||||
                <el-table-column prop="remark" label="备注" min-width="250" show-overflow-tooltip></el-table-column>
 | 
					                <el-table-column prop="remark" label="备注" min-width="250" show-overflow-tooltip></el-table-column>
 | 
				
			||||||
                <el-table-column prop="createTime" label="创建时间" min-width="165">
 | 
					                <el-table-column prop="createTime" label="创建时间" min-width="165">
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        {{ $filters.dateFormat(scope.row.createTime) }}
 | 
					                        {{ dateFormat(scope.row.createTime) }}
 | 
				
			||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
                </el-table-column>
 | 
					                </el-table-column>
 | 
				
			||||||
                <el-table-column prop="creator" label="创建者" min-width="80"></el-table-column>
 | 
					                <el-table-column prop="creator" label="创建者" min-width="80"></el-table-column>
 | 
				
			||||||
                <el-table-column label="操作" min-width="335" fixed="right">
 | 
					                <el-table-column label="操作" min-width="235" fixed="right">
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        <span v-auth="'machine:terminal'">
 | 
					                        <span v-auth="'machine:terminal'">
 | 
				
			||||||
                            <el-link
 | 
					                            <el-link
 | 
				
			||||||
@@ -89,11 +83,6 @@
 | 
				
			|||||||
                            <el-divider direction="vertical" border-style="dashed" />
 | 
					                            <el-divider direction="vertical" border-style="dashed" />
 | 
				
			||||||
                        </span>
 | 
					                        </span>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        <span v-auth="'machine:update'" v-if="scope.row.enableRecorder == 1">
 | 
					 | 
				
			||||||
                            <el-link @click="showRec(scope.row)" plain :underline="false" size="small">终端回放</el-link>
 | 
					 | 
				
			||||||
                            <el-divider direction="vertical" border-style="dashed" />
 | 
					 | 
				
			||||||
                        </span>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                        <span v-auth="'machine:file'">
 | 
					                        <span v-auth="'machine:file'">
 | 
				
			||||||
                            <el-link
 | 
					                            <el-link
 | 
				
			||||||
                                type="success"
 | 
					                                type="success"
 | 
				
			||||||
@@ -118,20 +107,46 @@
 | 
				
			|||||||
                        >
 | 
					                        >
 | 
				
			||||||
                        <el-divider direction="vertical" border-style="dashed" />
 | 
					                        <el-divider direction="vertical" border-style="dashed" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        <el-link @click="showProcess(scope.row)" :disabled="scope.row.status == -1" plain :underline="false" size="small"
 | 
					                        <el-dropdown>
 | 
				
			||||||
                            >进程</el-link
 | 
					                            <span class="el-dropdown-link-machine-list">
 | 
				
			||||||
                        >
 | 
					                                更多
 | 
				
			||||||
                        <el-divider direction="vertical" border-style="dashed" />
 | 
					                                <el-icon class="el-icon--right">
 | 
				
			||||||
 | 
					                                    <arrow-down />
 | 
				
			||||||
 | 
					                                </el-icon>
 | 
				
			||||||
 | 
					                            </span>
 | 
				
			||||||
 | 
					                            <template #dropdown>
 | 
				
			||||||
 | 
					                                <el-dropdown-menu>
 | 
				
			||||||
 | 
					                                    <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-link
 | 
					                                    <el-dropdown-item v-if="scope.row.enableRecorder == 1"
 | 
				
			||||||
                            :disabled="!scope.row.hasCli || scope.row.status == -1"
 | 
					                                        ><el-link v-auth="'machine:update'" @click="showRec(scope.row)" plain :underline="false" size="small"
 | 
				
			||||||
                            type="danger"
 | 
					                                            >终端回放</el-link
 | 
				
			||||||
                            @click="closeCli(scope.row)"
 | 
					                                        ></el-dropdown-item
 | 
				
			||||||
                            plain
 | 
					                                    >
 | 
				
			||||||
                            size="small"
 | 
					
 | 
				
			||||||
                            :underline="false"
 | 
					                                    <el-dropdown-item
 | 
				
			||||||
                            >关闭连接</el-link
 | 
					                                        ><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>
 | 
					                    </template>
 | 
				
			||||||
                </el-table-column>
 | 
					                </el-table-column>
 | 
				
			||||||
            </el-table>
 | 
					            </el-table>
 | 
				
			||||||
@@ -149,7 +164,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        <machine-edit
 | 
					        <machine-edit
 | 
				
			||||||
            :title="machineEditDialog.title"
 | 
					            :title="machineEditDialog.title"
 | 
				
			||||||
            :projects="projects"
 | 
					 | 
				
			||||||
            v-model:visible="machineEditDialog.visible"
 | 
					            v-model:visible="machineEditDialog.visible"
 | 
				
			||||||
            v-model:machine="machineEditDialog.data"
 | 
					            v-model:machine="machineEditDialog.data"
 | 
				
			||||||
            @valChange="submitSuccess"
 | 
					            @valChange="submitSuccess"
 | 
				
			||||||
@@ -166,6 +180,8 @@
 | 
				
			|||||||
            :machineId="machineStatsDialog.machineId"
 | 
					            :machineId="machineStatsDialog.machineId"
 | 
				
			||||||
            :title="machineStatsDialog.title"
 | 
					            :title="machineStatsDialog.title"
 | 
				
			||||||
        ></machine-stats>
 | 
					        ></machine-stats>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <machine-rec v-model:visible="machineRecDialog.visible" :machineId="machineRecDialog.machineId" :title="machineRecDialog.title"></machine-rec>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -174,12 +190,14 @@ import { toRefs, reactive, onMounted, defineComponent } from 'vue';
 | 
				
			|||||||
import { useRouter } from 'vue-router';
 | 
					import { useRouter } from 'vue-router';
 | 
				
			||||||
import { ElMessage, ElMessageBox } from 'element-plus';
 | 
					import { ElMessage, ElMessageBox } from 'element-plus';
 | 
				
			||||||
import { machineApi } from './api';
 | 
					import { machineApi } from './api';
 | 
				
			||||||
import { projectApi } from '../project/api.ts';
 | 
					import { tagApi } from '../tag/api.ts';
 | 
				
			||||||
import ServiceManage from './ServiceManage.vue';
 | 
					import ServiceManage from './ServiceManage.vue';
 | 
				
			||||||
import FileManage from './FileManage.vue';
 | 
					import FileManage from './FileManage.vue';
 | 
				
			||||||
import MachineEdit from './MachineEdit.vue';
 | 
					import MachineEdit from './MachineEdit.vue';
 | 
				
			||||||
import ProcessList from './ProcessList.vue';
 | 
					import ProcessList from './ProcessList.vue';
 | 
				
			||||||
import MachineStats from './MachineStats.vue';
 | 
					import MachineStats from './MachineStats.vue';
 | 
				
			||||||
 | 
					import MachineRec from './MachineRec.vue';
 | 
				
			||||||
 | 
					import { dateFormat } from '@/common/utils/date';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'MachineList',
 | 
					    name: 'MachineList',
 | 
				
			||||||
@@ -189,17 +207,19 @@ export default defineComponent({
 | 
				
			|||||||
        FileManage,
 | 
					        FileManage,
 | 
				
			||||||
        MachineEdit,
 | 
					        MachineEdit,
 | 
				
			||||||
        MachineStats,
 | 
					        MachineStats,
 | 
				
			||||||
 | 
					        MachineRec,
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    setup() {
 | 
					    setup() {
 | 
				
			||||||
        const router = useRouter();
 | 
					        const router = useRouter();
 | 
				
			||||||
        const state = reactive({
 | 
					        const state = reactive({
 | 
				
			||||||
            projects: [],
 | 
					            tags: [] as any,
 | 
				
			||||||
            stats: '',
 | 
					            stats: '',
 | 
				
			||||||
            params: {
 | 
					            params: {
 | 
				
			||||||
                pageNum: 1,
 | 
					                pageNum: 1,
 | 
				
			||||||
                pageSize: 10,
 | 
					                pageSize: 10,
 | 
				
			||||||
                ip: null,
 | 
					                ip: null,
 | 
				
			||||||
                name: null,
 | 
					                name: null,
 | 
				
			||||||
 | 
					                tagPath: null,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            // 列表数据
 | 
					            // 列表数据
 | 
				
			||||||
            data: {
 | 
					            data: {
 | 
				
			||||||
@@ -207,7 +227,7 @@ export default defineComponent({
 | 
				
			|||||||
                total: 10,
 | 
					                total: 10,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            // 当前选中数据id
 | 
					            // 当前选中数据id
 | 
				
			||||||
            currentId: null,
 | 
					            currentId: 0,
 | 
				
			||||||
            currentData: null,
 | 
					            currentData: null,
 | 
				
			||||||
            serviceDialog: {
 | 
					            serviceDialog: {
 | 
				
			||||||
                visible: false,
 | 
					                visible: false,
 | 
				
			||||||
@@ -231,7 +251,7 @@ export default defineComponent({
 | 
				
			|||||||
            },
 | 
					            },
 | 
				
			||||||
            machineEditDialog: {
 | 
					            machineEditDialog: {
 | 
				
			||||||
                visible: false,
 | 
					                visible: false,
 | 
				
			||||||
                data: null,
 | 
					                data: null as any,
 | 
				
			||||||
                title: '新增机器',
 | 
					                title: '新增机器',
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            machineRecDialog: {
 | 
					            machineRecDialog: {
 | 
				
			||||||
@@ -275,12 +295,11 @@ export default defineComponent({
 | 
				
			|||||||
            search();
 | 
					            search();
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const getProjects = async () => {
 | 
					        const getTags = async () => {
 | 
				
			||||||
            state.projects = await projectApi.accountProjects.request(null);
 | 
					            state.tags = await tagApi.getAccountTags.request(null);
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const openFormDialog = async (machine: any) => {
 | 
					        const openFormDialog = async (machine: any) => {
 | 
				
			||||||
            await getProjects();
 | 
					 | 
				
			||||||
            let dialogTitle;
 | 
					            let dialogTitle;
 | 
				
			||||||
            if (machine) {
 | 
					            if (machine) {
 | 
				
			||||||
                state.machineEditDialog.data = state.currentData as any;
 | 
					                state.machineEditDialog.data = state.currentData as any;
 | 
				
			||||||
@@ -303,7 +322,7 @@ export default defineComponent({
 | 
				
			|||||||
                });
 | 
					                });
 | 
				
			||||||
                await machineApi.del.request({ id });
 | 
					                await machineApi.del.request({ id });
 | 
				
			||||||
                ElMessage.success('操作成功');
 | 
					                ElMessage.success('操作成功');
 | 
				
			||||||
                state.currentId = null;
 | 
					                state.currentId = 0;
 | 
				
			||||||
                state.currentData = null;
 | 
					                state.currentData = null;
 | 
				
			||||||
                search();
 | 
					                search();
 | 
				
			||||||
            } catch (err) {}
 | 
					            } catch (err) {}
 | 
				
			||||||
@@ -332,7 +351,7 @@ export default defineComponent({
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const submitSuccess = () => {
 | 
					        const submitSuccess = () => {
 | 
				
			||||||
            state.currentId = null;
 | 
					            state.currentId = 0;
 | 
				
			||||||
            state.currentData = null;
 | 
					            state.currentData = null;
 | 
				
			||||||
            search();
 | 
					            search();
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
@@ -359,20 +378,16 @@ export default defineComponent({
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const showRec = (row: any) => {
 | 
					        const showRec = (row: any) => {
 | 
				
			||||||
            const { href } = router.resolve({
 | 
					            state.machineRecDialog.title = `${row.name}[${row.ip}]-终端回放记录`;
 | 
				
			||||||
                path: `/machine/terminal-rec`,
 | 
					            state.machineRecDialog.machineId = row.id;
 | 
				
			||||||
                query: {
 | 
					            state.machineRecDialog.visible = true;
 | 
				
			||||||
                    id: row.id,
 | 
					 | 
				
			||||||
                    name: `${row.name}[${row.ip}]-终端回放记录`,
 | 
					 | 
				
			||||||
                },
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
            window.open(href, '_blank');
 | 
					 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
 | 
					            dateFormat,
 | 
				
			||||||
            choose,
 | 
					            choose,
 | 
				
			||||||
            getProjects,
 | 
					            getTags,
 | 
				
			||||||
            showTerminal,
 | 
					            showTerminal,
 | 
				
			||||||
            openFormDialog,
 | 
					            openFormDialog,
 | 
				
			||||||
            deleteMachine,
 | 
					            deleteMachine,
 | 
				
			||||||
@@ -395,4 +410,11 @@ export default defineComponent({
 | 
				
			|||||||
.el-dialog__body {
 | 
					.el-dialog__body {
 | 
				
			||||||
    padding: 2px 2px;
 | 
					    padding: 2px 2px;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					.el-dropdown-link-machine-list {
 | 
				
			||||||
 | 
					    cursor: pointer;
 | 
				
			||||||
 | 
					    color: var(--el-color-primary);
 | 
				
			||||||
 | 
					    display: flex;
 | 
				
			||||||
 | 
					    align-items: center;
 | 
				
			||||||
 | 
					    margin-top: 6px;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
</style>
 | 
					</style>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,30 +1,37 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
    <div>
 | 
					    <div id="terminalRecDialog">
 | 
				
			||||||
        <div class="toolbar">
 | 
					        <el-dialog
 | 
				
			||||||
            <span style="dispaly: inline-block" class="ml10">{{ title }}</span>
 | 
					            :title="title"
 | 
				
			||||||
            <el-divider direction="vertical" border-style="dashed" />
 | 
					            v-model="dialogVisible"
 | 
				
			||||||
            <el-select @change="getUsers" v-model="operateDate" placeholder="操作日期" filterable>
 | 
					            :before-close="handleClose"
 | 
				
			||||||
                <el-option v-for="item in operateDates" :key="item" :label="item" :value="item"> </el-option>
 | 
					            :close-on-click-modal="false"
 | 
				
			||||||
            </el-select>
 | 
					            :destroy-on-close="true"
 | 
				
			||||||
            <el-select class="ml10" @change="getRecs" filterable v-model="user" placeholder="请选择操作人">
 | 
					            width="70%"
 | 
				
			||||||
                <el-option v-for="item in users" :key="item" :label="item" :value="item"> </el-option>
 | 
					        >
 | 
				
			||||||
            </el-select>
 | 
					            <div class="toolbar">
 | 
				
			||||||
            <el-select class="ml10" @change="playRec" filterable v-model="rec" placeholder="请选择操作记录">
 | 
					                <el-select @change="getUsers" v-model="operateDate" placeholder="操作日期" filterable>
 | 
				
			||||||
                <el-option v-for="item in recs" :key="item" :label="item" :value="item"> </el-option>
 | 
					                    <el-option v-for="item in operateDates" :key="item" :label="item" :value="item"> </el-option>
 | 
				
			||||||
            </el-select>
 | 
					                </el-select>
 | 
				
			||||||
            <el-divider direction="vertical" border-style="dashed" />
 | 
					                <el-select class="ml10" @change="getRecs" filterable v-model="user" placeholder="请选择操作人">
 | 
				
			||||||
            快捷键-> space[空格键]: 暂停/播放  |  f: 全屏/取消全屏
 | 
					                    <el-option v-for="item in users" :key="item" :label="item" :value="item"> </el-option>
 | 
				
			||||||
        </div>
 | 
					                </el-select>
 | 
				
			||||||
        <div ref="playerRef" id="rc-player"></div>
 | 
					                <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>
 | 
					    </div>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script lang="ts">
 | 
					<script lang="ts">
 | 
				
			||||||
import { toRefs, onMounted, ref, reactive, defineComponent } from 'vue';
 | 
					import { toRefs, watch, ref, reactive, defineComponent } from 'vue';
 | 
				
			||||||
import { machineApi } from './api';
 | 
					import { machineApi } from './api';
 | 
				
			||||||
import * as AsciinemaPlayer from 'asciinema-player';
 | 
					import * as AsciinemaPlayer from 'asciinema-player';
 | 
				
			||||||
import 'asciinema-player/dist/bundle/asciinema-player.css';
 | 
					import 'asciinema-player/dist/bundle/asciinema-player.css';
 | 
				
			||||||
import { useRoute } from 'vue-router';
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'MachineRec',
 | 
					    name: 'MachineRec',
 | 
				
			||||||
    components: {},
 | 
					    components: {},
 | 
				
			||||||
@@ -34,7 +41,6 @@ export default defineComponent({
 | 
				
			|||||||
        title: { type: String },
 | 
					        title: { type: String },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    setup(props: any, context) {
 | 
					    setup(props: any, context) {
 | 
				
			||||||
        const route = useRoute();
 | 
					 | 
				
			||||||
        const playerRef = ref(null);
 | 
					        const playerRef = ref(null);
 | 
				
			||||||
        const state = reactive({
 | 
					        const state = reactive({
 | 
				
			||||||
            dialogVisible: false,
 | 
					            dialogVisible: false,
 | 
				
			||||||
@@ -48,10 +54,14 @@ export default defineComponent({
 | 
				
			|||||||
            rec: '',
 | 
					            rec: '',
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        onMounted(() => {
 | 
					        watch(props, async (newValue) => {
 | 
				
			||||||
            state.machineId = Number.parseInt(route.query.id as string);
 | 
					            const visible = newValue.visible;
 | 
				
			||||||
            state.title = route.query.name as string;
 | 
					            if (visible) {
 | 
				
			||||||
            getOperateDate();
 | 
					                state.machineId = newValue.machineId;
 | 
				
			||||||
 | 
					                state.title = newValue.title;
 | 
				
			||||||
 | 
					                await getOperateDate();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            state.dialogVisible = visible;
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const getOperateDate = async () => {
 | 
					        const getOperateDate = async () => {
 | 
				
			||||||
@@ -118,3 +128,10 @@ export default defineComponent({
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
 | 
					<style lang="scss">
 | 
				
			||||||
 | 
					#terminalRecDialog {
 | 
				
			||||||
 | 
					    .el-overlay .el-overlay-dialog .el-dialog .el-dialog__body {
 | 
				
			||||||
 | 
					        padding: 0px !important;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					</style>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,7 +9,7 @@
 | 
				
			|||||||
            :destroy-on-close="true"
 | 
					            :destroy-on-close="true"
 | 
				
			||||||
            width="900px"
 | 
					            width="900px"
 | 
				
			||||||
        >
 | 
					        >
 | 
				
			||||||
            <el-form :model="form" ref="scriptForm" label-width="70px" size="small">
 | 
					            <el-form :model="form" ref="scriptForm" label-width="50px" size="small">
 | 
				
			||||||
                <el-form-item prop="method" label="名称">
 | 
					                <el-form-item prop="method" label="名称">
 | 
				
			||||||
                    <el-input v-model.trim="form.name" placeholder="请输入名称"></el-input>
 | 
					                    <el-input v-model.trim="form.name" placeholder="请输入名称"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
@@ -187,11 +187,6 @@ export default defineComponent({
 | 
				
			|||||||
});
 | 
					});
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
<style lang="scss">
 | 
					<style lang="scss">
 | 
				
			||||||
// 	.m-dialog {
 | 
					 | 
				
			||||||
// 		.el-cascader {
 | 
					 | 
				
			||||||
// 			width: 100%;
 | 
					 | 
				
			||||||
// 		}
 | 
					 | 
				
			||||||
// 	}
 | 
					 | 
				
			||||||
#content {
 | 
					#content {
 | 
				
			||||||
    .CodeMirror {
 | 
					    .CodeMirror {
 | 
				
			||||||
        height: 300px !important;
 | 
					        height: 300px !important;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,36 +3,45 @@
 | 
				
			|||||||
        <div class="toolbar">
 | 
					        <div class="toolbar">
 | 
				
			||||||
            <el-row type="flex" justify="space-between">
 | 
					            <el-row type="flex" justify="space-between">
 | 
				
			||||||
                <el-col :span="24">
 | 
					                <el-col :span="24">
 | 
				
			||||||
                    <project-env-select @changeProjectEnv="changeProjectEnv">
 | 
					                    <el-form class="search-form" label-position="right" :inline="true">
 | 
				
			||||||
                        <template #default>
 | 
					                        <el-form-item label="标签">
 | 
				
			||||||
                            <el-form-item label="实例" label-width="40px">
 | 
					                            <el-select
 | 
				
			||||||
                                <el-select v-model="mongoId" placeholder="请选择mongo" @change="changeMongo">
 | 
					                                @change="changeTag"
 | 
				
			||||||
                                    <el-option v-for="item in mongoList" :key="item.id" :label="item.name" :value="item.id">
 | 
					                                @focus="getTags"
 | 
				
			||||||
                                        <span style="float: left">{{ item.name }}</span>
 | 
					                                v-model="query.tagPath"
 | 
				
			||||||
                                        <span style="float: right; color: #8492a6; margin-left: 6px; font-size: 13px">{{ ` [${item.uri}]` }}</span>
 | 
					                                placeholder="请选择标签"
 | 
				
			||||||
                                    </el-option>
 | 
					                                filterable
 | 
				
			||||||
                                </el-select>
 | 
					                                style="width: 250px"
 | 
				
			||||||
                            </el-form-item>
 | 
					                            >
 | 
				
			||||||
 | 
					                                <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>
 | 
				
			||||||
 | 
					                                </el-option>
 | 
				
			||||||
 | 
					                            </el-select>
 | 
				
			||||||
 | 
					                        </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            <el-form-item label="库" label-width="20px">
 | 
					                        <el-form-item label="库" label-width="20px">
 | 
				
			||||||
                                <el-select v-model="database" placeholder="请选择库" @change="changeDatabase" filterable>
 | 
					                            <el-select v-model="database" placeholder="请选择库" @change="changeDatabase" filterable>
 | 
				
			||||||
                                    <el-option v-for="item in databases" :key="item.Name" :label="item.Name" :value="item.Name">
 | 
					                                <el-option v-for="item in databases" :key="item.Name" :label="item.Name" :value="item.Name">
 | 
				
			||||||
                                        <span style="float: left">{{ item.Name }}</span>
 | 
					                                    <span style="float: left">{{ item.Name }}</span>
 | 
				
			||||||
                                        <span style="float: right; color: #8492a6; margin-left: 4px; font-size: 13px">{{
 | 
					                                    <span style="float: right; color: #8492a6; margin-left: 4px; font-size: 13px">{{
 | 
				
			||||||
                                            ` [${formatByteSize(item.SizeOnDisk)}]`
 | 
					                                        ` [${formatByteSize(item.SizeOnDisk)}]`
 | 
				
			||||||
                                        }}</span>
 | 
					                                    }}</span>
 | 
				
			||||||
                                    </el-option>
 | 
					                                </el-option>
 | 
				
			||||||
                                </el-select>
 | 
					                            </el-select>
 | 
				
			||||||
                            </el-form-item>
 | 
					                        </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            <el-form-item label="集合" label-width="40px">
 | 
					                        <el-form-item label="集合" label-width="40px">
 | 
				
			||||||
                                <el-select v-model="collection" placeholder="请选择集合" @change="changeCollection" filterable>
 | 
					                            <el-select v-model="collection" placeholder="请选择集合" @change="changeCollection" filterable>
 | 
				
			||||||
                                    <el-option v-for="item in collections" :key="item" :label="item" :value="item">
 | 
					                                <el-option v-for="item in collections" :key="item" :label="item" :value="item"> </el-option>
 | 
				
			||||||
                                    </el-option>
 | 
					                            </el-select>
 | 
				
			||||||
                                </el-select>
 | 
					                        </el-form-item>
 | 
				
			||||||
                            </el-form-item>
 | 
					                    </el-form>
 | 
				
			||||||
                        </template>
 | 
					 | 
				
			||||||
                    </project-env-select>
 | 
					 | 
				
			||||||
                </el-col>
 | 
					                </el-col>
 | 
				
			||||||
            </el-row>
 | 
					            </el-row>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
@@ -64,12 +73,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                                        <el-divider direction="vertical" border-style="dashed" />
 | 
					                                        <el-divider direction="vertical" border-style="dashed" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                        <el-link
 | 
					                                        <el-link @click="onSaveDoc(item.value)" :underline="false" type="warning" icon="DocumentChecked"></el-link>
 | 
				
			||||||
                                            @click="onSaveDoc(item.value)"
 | 
					 | 
				
			||||||
                                            :underline="false"
 | 
					 | 
				
			||||||
                                            type="warning"
 | 
					 | 
				
			||||||
                                            icon="DocumentChecked"
 | 
					 | 
				
			||||||
                                        ></el-link>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                        <el-divider direction="vertical" border-style="dashed" />
 | 
					                                        <el-divider direction="vertical" border-style="dashed" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -132,36 +136,38 @@
 | 
				
			|||||||
import { mongoApi } from './api';
 | 
					import { mongoApi } from './api';
 | 
				
			||||||
import { toRefs, ref, reactive, defineComponent } from 'vue';
 | 
					import { toRefs, ref, reactive, defineComponent } from 'vue';
 | 
				
			||||||
import { ElMessage } from 'element-plus';
 | 
					import { ElMessage } from 'element-plus';
 | 
				
			||||||
import ProjectEnvSelect from '../component/ProjectEnvSelect.vue';
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { isTrue, notBlank, notNull } from '@/common/assert';
 | 
					import { isTrue, notBlank, notNull } from '@/common/assert';
 | 
				
			||||||
import { formatByteSize } from '@/common/utils/format';
 | 
					import { formatByteSize } from '@/common/utils/format';
 | 
				
			||||||
import JsonEdit from '@/components/jsonedit/index.vue';
 | 
					import JsonEdit from '@/components/jsonedit/index.vue';
 | 
				
			||||||
 | 
					import { tagApi } from '../tag/api.ts';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'MongoDataOp',
 | 
					    name: 'MongoDataOp',
 | 
				
			||||||
    components: {
 | 
					    components: {
 | 
				
			||||||
        ProjectEnvSelect,
 | 
					 | 
				
			||||||
        JsonEdit,
 | 
					        JsonEdit,
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    setup() {
 | 
					    setup() {
 | 
				
			||||||
        const findParamInputRef: any = ref(null);
 | 
					        const findParamInputRef: any = ref(null);
 | 
				
			||||||
        const state = reactive({
 | 
					        const state = reactive({
 | 
				
			||||||
            loading: false,
 | 
					            loading: false,
 | 
				
			||||||
            mongoList: [],
 | 
					            tags: [],
 | 
				
			||||||
 | 
					            mongoList: [] as any,
 | 
				
			||||||
            query: {
 | 
					            query: {
 | 
				
			||||||
                envId: 0,
 | 
					                tagPath: null,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            mongoId: null, // 当前选择操作的mongo
 | 
					            mongoId: null, // 当前选择操作的mongo
 | 
				
			||||||
            database: '', // 当前选择操作的库
 | 
					            database: '', // 当前选择操作的库
 | 
				
			||||||
            collection: '', //当前选中的collection
 | 
					            collection: '', //当前选中的collection
 | 
				
			||||||
            activeName: '', // 当前操作的tab
 | 
					            activeName: '', // 当前操作的tab
 | 
				
			||||||
            databases: [],
 | 
					            databases: [] as any,
 | 
				
			||||||
            collections: [],
 | 
					            collections: [] as any,
 | 
				
			||||||
            dataTabs: {}, // 数据tabs
 | 
					            dataTabs: {} as any, // 数据tabs
 | 
				
			||||||
            findDialog: {
 | 
					            findDialog: {
 | 
				
			||||||
                visible: false,
 | 
					                visible: false,
 | 
				
			||||||
                findParam: {
 | 
					                findParam: {
 | 
				
			||||||
 | 
					                    limit: 0,
 | 
				
			||||||
 | 
					                    skip: 0,
 | 
				
			||||||
                    filter: '',
 | 
					                    filter: '',
 | 
				
			||||||
                    sort: '',
 | 
					                    sort: '',
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
@@ -178,24 +184,27 @@ export default defineComponent({
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const searchMongo = async () => {
 | 
					        const searchMongo = async () => {
 | 
				
			||||||
            notNull(state.query.envId, '请先选择项目环境');
 | 
					            notNull(state.query.tagPath, '请先选择标签');
 | 
				
			||||||
            const res = await mongoApi.mongoList.request(state.query);
 | 
					            const res = await mongoApi.mongoList.request(state.query);
 | 
				
			||||||
            state.mongoList = res.list;
 | 
					            state.mongoList = res.list;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const changeProjectEnv = (projectId: any, envId: any) => {
 | 
					        const changeTag = (tagPath: string) => {
 | 
				
			||||||
            state.databases = [];
 | 
					            state.databases = [];
 | 
				
			||||||
            state.collections = [];
 | 
					            state.collections = [];
 | 
				
			||||||
            state.mongoId = null;
 | 
					            state.mongoId = null;
 | 
				
			||||||
            state.collection = '';
 | 
					            state.collection = '';
 | 
				
			||||||
            state.database = '';
 | 
					            state.database = '';
 | 
				
			||||||
            state.dataTabs = {};
 | 
					            state.dataTabs = {};
 | 
				
			||||||
            if (envId != null) {
 | 
					            if (tagPath != null) {
 | 
				
			||||||
                state.query.envId = envId;
 | 
					 | 
				
			||||||
                searchMongo();
 | 
					                searchMongo();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getTags = async () => {
 | 
				
			||||||
 | 
					            state.tags = await tagApi.getAccountTags.request(null);
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const changeMongo = () => {
 | 
					        const changeMongo = () => {
 | 
				
			||||||
            state.databases = [];
 | 
					            state.databases = [];
 | 
				
			||||||
            state.collections = [];
 | 
					            state.collections = [];
 | 
				
			||||||
@@ -419,7 +428,8 @@ export default defineComponent({
 | 
				
			|||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
            findParamInputRef,
 | 
					            findParamInputRef,
 | 
				
			||||||
            changeProjectEnv,
 | 
					            getTags,
 | 
				
			||||||
 | 
					            changeTag,
 | 
				
			||||||
            changeMongo,
 | 
					            changeMongo,
 | 
				
			||||||
            changeDatabase,
 | 
					            changeDatabase,
 | 
				
			||||||
            changeCollection,
 | 
					            changeCollection,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,17 +2,10 @@
 | 
				
			|||||||
    <div>
 | 
					    <div>
 | 
				
			||||||
        <el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :close-on-click-modal="false" width="38%" :destroy-on-close="true">
 | 
					        <el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :close-on-click-modal="false" width="38%" :destroy-on-close="true">
 | 
				
			||||||
            <el-form :model="form" ref="mongoForm" :rules="rules" label-width="85px">
 | 
					            <el-form :model="form" ref="mongoForm" :rules="rules" label-width="85px">
 | 
				
			||||||
                <el-form-item prop="projectId" label="项目" required>
 | 
					                <el-form-item prop="tagId" label="标签:" required>
 | 
				
			||||||
                    <el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
 | 
					                    <tag-select v-model:tag-id="form.tagId" v-model:tag-path="form.tagPath" style="width: 100%" />
 | 
				
			||||||
                        <el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
 | 
					 | 
				
			||||||
                    </el-select>
 | 
					 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                <el-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-form-item prop="name" label="名称" required>
 | 
				
			||||||
                    <el-input v-model.trim="form.name" placeholder="请输入名称" auto-complete="off"></el-input>
 | 
					                    <el-input v-model.trim="form.name" placeholder="请输入名称" auto-complete="off"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
@@ -58,19 +51,19 @@
 | 
				
			|||||||
<script lang="ts">
 | 
					<script lang="ts">
 | 
				
			||||||
import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
 | 
					import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
 | 
				
			||||||
import { mongoApi } from './api';
 | 
					import { mongoApi } from './api';
 | 
				
			||||||
import { projectApi } from '../project/api.ts';
 | 
					 | 
				
			||||||
import { machineApi } from '../machine/api.ts';
 | 
					import { machineApi } from '../machine/api.ts';
 | 
				
			||||||
import { ElMessage } from 'element-plus';
 | 
					import { ElMessage } from 'element-plus';
 | 
				
			||||||
 | 
					import TagSelect from '../component/TagSelect.vue';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'MongoEdit',
 | 
					    name: 'MongoEdit',
 | 
				
			||||||
 | 
					    components: {
 | 
				
			||||||
 | 
					        TagSelect,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    props: {
 | 
					    props: {
 | 
				
			||||||
        visible: {
 | 
					        visible: {
 | 
				
			||||||
            type: Boolean,
 | 
					            type: Boolean,
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        projects: {
 | 
					 | 
				
			||||||
            type: Array,
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        mongo: {
 | 
					        mongo: {
 | 
				
			||||||
            type: [Boolean, Object],
 | 
					            type: [Boolean, Object],
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
@@ -82,33 +75,22 @@ export default defineComponent({
 | 
				
			|||||||
        const mongoForm: any = ref(null);
 | 
					        const mongoForm: any = ref(null);
 | 
				
			||||||
        const state = reactive({
 | 
					        const state = reactive({
 | 
				
			||||||
            dialogVisible: false,
 | 
					            dialogVisible: false,
 | 
				
			||||||
            projects: [],
 | 
					            sshTunnelMachineList: [] as any,
 | 
				
			||||||
            envs: [],
 | 
					 | 
				
			||||||
            sshTunnelMachineList: [],
 | 
					 | 
				
			||||||
            form: {
 | 
					            form: {
 | 
				
			||||||
                id: null,
 | 
					                id: null,
 | 
				
			||||||
                name: null,
 | 
					                name: null,
 | 
				
			||||||
                uri: null,
 | 
					                uri: null,
 | 
				
			||||||
                enableSshTunnel: -1,
 | 
					                enableSshTunnel: -1,
 | 
				
			||||||
                sshTunnelMachineId: null,
 | 
					                sshTunnelMachineId: null,
 | 
				
			||||||
                project: null,
 | 
					                tagId: null as any,
 | 
				
			||||||
                projectId: null,
 | 
					                tagPath: null as any,
 | 
				
			||||||
                envId: null,
 | 
					 | 
				
			||||||
                env: null,
 | 
					 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            btnLoading: false,
 | 
					            btnLoading: false,
 | 
				
			||||||
            rules: {
 | 
					            rules: {
 | 
				
			||||||
                projectId: [
 | 
					                tagId: [
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        required: true,
 | 
					                        required: true,
 | 
				
			||||||
                        message: '请选择项目',
 | 
					                        message: '请选择标签',
 | 
				
			||||||
                        trigger: ['change', 'blur'],
 | 
					 | 
				
			||||||
                    },
 | 
					 | 
				
			||||||
                ],
 | 
					 | 
				
			||||||
                envId: [
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        required: true,
 | 
					 | 
				
			||||||
                        message: '请选择环境',
 | 
					 | 
				
			||||||
                        trigger: ['change', 'blur'],
 | 
					                        trigger: ['change', 'blur'],
 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
                ],
 | 
					                ],
 | 
				
			||||||
@@ -134,12 +116,9 @@ export default defineComponent({
 | 
				
			|||||||
            if (!state.dialogVisible) {
 | 
					            if (!state.dialogVisible) {
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            state.projects = newValue.projects;
 | 
					 | 
				
			||||||
            if (newValue.mongo) {
 | 
					            if (newValue.mongo) {
 | 
				
			||||||
                getEnvs(newValue.mongo.projectId);
 | 
					 | 
				
			||||||
                state.form = { ...newValue.mongo };
 | 
					                state.form = { ...newValue.mongo };
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                state.envs = [];
 | 
					 | 
				
			||||||
                state.form = { db: 0 } as any;
 | 
					                state.form = { db: 0 } as any;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            getSshTunnelMachines();
 | 
					            getSshTunnelMachines();
 | 
				
			||||||
@@ -152,30 +131,6 @@ export default defineComponent({
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        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 btnOk = async () => {
 | 
					        const btnOk = async () => {
 | 
				
			||||||
            mongoForm.value.validate(async (valid: boolean) => {
 | 
					            mongoForm.value.validate(async (valid: boolean) => {
 | 
				
			||||||
                if (valid) {
 | 
					                if (valid) {
 | 
				
			||||||
@@ -206,9 +161,7 @@ export default defineComponent({
 | 
				
			|||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
            mongoForm,
 | 
					            mongoForm,
 | 
				
			||||||
            changeProject,
 | 
					 | 
				
			||||||
            getSshTunnelMachines,
 | 
					            getSshTunnelMachines,
 | 
				
			||||||
            changeEnv,
 | 
					 | 
				
			||||||
            btnOk,
 | 
					            btnOk,
 | 
				
			||||||
            cancel,
 | 
					            cancel,
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,8 +5,8 @@
 | 
				
			|||||||
            <el-button type="primary" icon="edit" :disabled="currentId == null" @click="editMongo(false)" plain>编辑</el-button>
 | 
					            <el-button type="primary" icon="edit" :disabled="currentId == null" @click="editMongo(false)" plain>编辑</el-button>
 | 
				
			||||||
            <el-button type="danger" icon="delete" :disabled="currentId == null" @click="deleteMongo" plain>删除</el-button>
 | 
					            <el-button type="danger" icon="delete" :disabled="currentId == null" @click="deleteMongo" plain>删除</el-button>
 | 
				
			||||||
            <div style="float: right">
 | 
					            <div style="float: right">
 | 
				
			||||||
                <el-select @focus="getProjects" v-model="query.projectId" placeholder="请选择项目" filterable clearable>
 | 
					                <el-select @focus="getTags" v-model="query.tagPath" placeholder="请选择标签" filterable clearable>
 | 
				
			||||||
                    <el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
 | 
					                    <el-option v-for="item in tags" :key="item" :label="item" :value="item"> </el-option>
 | 
				
			||||||
                </el-select>
 | 
					                </el-select>
 | 
				
			||||||
                <el-button class="ml5" @click="search" type="success" icon="search"></el-button>
 | 
					                <el-button class="ml5" @click="search" type="success" icon="search"></el-button>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
@@ -18,8 +18,7 @@
 | 
				
			|||||||
                        </el-radio>
 | 
					                        </el-radio>
 | 
				
			||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
                </el-table-column>
 | 
					                </el-table-column>
 | 
				
			||||||
                <el-table-column prop="project" label="项目" width></el-table-column>
 | 
					                <el-table-column prop="tagPath" label="标签路径" min-width="150" show-overflow-tooltip></el-table-column>
 | 
				
			||||||
                <el-table-column prop="env" label="环境" width></el-table-column>
 | 
					 | 
				
			||||||
                <el-table-column prop="name" label="名称" width></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>
 | 
					                <el-table-column prop="uri" label="连接uri" min-width="150" show-overflow-tooltip>
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
@@ -28,7 +27,7 @@
 | 
				
			|||||||
                </el-table-column>
 | 
					                </el-table-column>
 | 
				
			||||||
                <el-table-column prop="createTime" label="创建时间" min-width="150">
 | 
					                <el-table-column prop="createTime" label="创建时间" min-width="150">
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        {{ $filters.dateFormat(scope.row.createTime) }}
 | 
					                        {{ dateFormat(scope.row.createTime) }}
 | 
				
			||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
                </el-table-column>
 | 
					                </el-table-column>
 | 
				
			||||||
                <el-table-column prop="creator" label="创建人"></el-table-column>
 | 
					                <el-table-column prop="creator" label="创建人"></el-table-column>
 | 
				
			||||||
@@ -180,7 +179,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        <mongo-edit
 | 
					        <mongo-edit
 | 
				
			||||||
            @val-change="valChange"
 | 
					            @val-change="valChange"
 | 
				
			||||||
            :projects="projects"
 | 
					 | 
				
			||||||
            :title="mongoEditDialog.title"
 | 
					            :title="mongoEditDialog.title"
 | 
				
			||||||
            v-model:visible="mongoEditDialog.visible"
 | 
					            v-model:visible="mongoEditDialog.visible"
 | 
				
			||||||
            v-model:mongo="mongoEditDialog.data"
 | 
					            v-model:mongo="mongoEditDialog.data"
 | 
				
			||||||
@@ -192,9 +190,10 @@
 | 
				
			|||||||
import { mongoApi } from './api';
 | 
					import { mongoApi } from './api';
 | 
				
			||||||
import { toRefs, reactive, defineComponent, onMounted } from 'vue';
 | 
					import { toRefs, reactive, defineComponent, onMounted } from 'vue';
 | 
				
			||||||
import { ElMessage, ElMessageBox } from 'element-plus';
 | 
					import { ElMessage, ElMessageBox } from 'element-plus';
 | 
				
			||||||
import { projectApi } from '../project/api.ts';
 | 
					import { tagApi } from '../tag/api.ts';
 | 
				
			||||||
import MongoEdit from './MongoEdit.vue';
 | 
					import MongoEdit from './MongoEdit.vue';
 | 
				
			||||||
import { formatByteSize } from '@/common/utils/format';
 | 
					import { formatByteSize } from '@/common/utils/format';
 | 
				
			||||||
 | 
					import { dateFormat } from '@/common/utils/date';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'MongoList',
 | 
					    name: 'MongoList',
 | 
				
			||||||
@@ -203,7 +202,7 @@ export default defineComponent({
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
    setup() {
 | 
					    setup() {
 | 
				
			||||||
        const state = reactive({
 | 
					        const state = reactive({
 | 
				
			||||||
            projects: [],
 | 
					            tags: [],
 | 
				
			||||||
            list: [],
 | 
					            list: [],
 | 
				
			||||||
            total: 0,
 | 
					            total: 0,
 | 
				
			||||||
            currentId: null,
 | 
					            currentId: null,
 | 
				
			||||||
@@ -211,12 +210,11 @@ export default defineComponent({
 | 
				
			|||||||
            query: {
 | 
					            query: {
 | 
				
			||||||
                pageNum: 1,
 | 
					                pageNum: 1,
 | 
				
			||||||
                pageSize: 10,
 | 
					                pageSize: 10,
 | 
				
			||||||
                prjectId: null,
 | 
					                tagPath: null,
 | 
				
			||||||
                clusterId: null,
 | 
					 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            mongoEditDialog: {
 | 
					            mongoEditDialog: {
 | 
				
			||||||
                visible: false,
 | 
					                visible: false,
 | 
				
			||||||
                data: null,
 | 
					                data: null as any,
 | 
				
			||||||
                title: '新增mongo',
 | 
					                title: '新增mongo',
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            databaseDialog: {
 | 
					            databaseDialog: {
 | 
				
			||||||
@@ -225,7 +223,7 @@ export default defineComponent({
 | 
				
			|||||||
                title: '',
 | 
					                title: '',
 | 
				
			||||||
                statsDialog: {
 | 
					                statsDialog: {
 | 
				
			||||||
                    visible: false,
 | 
					                    visible: false,
 | 
				
			||||||
                    data: {},
 | 
					                    data: {} as any,
 | 
				
			||||||
                    title: '',
 | 
					                    title: '',
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
@@ -236,7 +234,7 @@ export default defineComponent({
 | 
				
			|||||||
                title: '',
 | 
					                title: '',
 | 
				
			||||||
                statsDialog: {
 | 
					                statsDialog: {
 | 
				
			||||||
                    visible: false,
 | 
					                    visible: false,
 | 
				
			||||||
                    data: {},
 | 
					                    data: {} as any,
 | 
				
			||||||
                    title: '',
 | 
					                    title: '',
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
@@ -370,12 +368,11 @@ export default defineComponent({
 | 
				
			|||||||
            state.total = res.total;
 | 
					            state.total = res.total;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const getProjects = async () => {
 | 
					        const getTags = async () => {
 | 
				
			||||||
            state.projects = await projectApi.accountProjects.request(null);
 | 
					            state.tags = await tagApi.getAccountTags.request(null);
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const editMongo = async (isAdd = false) => {
 | 
					        const editMongo = async (isAdd = false) => {
 | 
				
			||||||
            await getProjects();
 | 
					 | 
				
			||||||
            if (isAdd) {
 | 
					            if (isAdd) {
 | 
				
			||||||
                state.mongoEditDialog.data = null;
 | 
					                state.mongoEditDialog.data = null;
 | 
				
			||||||
                state.mongoEditDialog.title = '新增mongo';
 | 
					                state.mongoEditDialog.title = '新增mongo';
 | 
				
			||||||
@@ -394,7 +391,8 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
            getProjects,
 | 
					            dateFormat,
 | 
				
			||||||
 | 
					            getTags,
 | 
				
			||||||
            search,
 | 
					            search,
 | 
				
			||||||
            handlePageChange,
 | 
					            handlePageChange,
 | 
				
			||||||
            choose,
 | 
					            choose,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,443 +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="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="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 @click="deleteEnv" v-auth="permissions.delProject" :disabled="showEnvDialog.chooseId == null" type="danger" icon="delete"
 | 
					 | 
				
			||||||
                    >删除</el-button
 | 
					 | 
				
			||||||
                >
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
            <el-table @current-change="chooseEnv" border :data="showEnvDialog.envs">
 | 
					 | 
				
			||||||
                <el-table-column label="选择" width="50px">
 | 
					 | 
				
			||||||
                    <template #default="scope">
 | 
					 | 
				
			||||||
                        <el-radio v-model="showEnvDialog.chooseId" :label="scope.row.id">
 | 
					 | 
				
			||||||
                            <i></i>
 | 
					 | 
				
			||||||
                        </el-radio>
 | 
					 | 
				
			||||||
                    </template>
 | 
					 | 
				
			||||||
                </el-table-column>
 | 
					 | 
				
			||||||
                <el-table-column property="name" label="环境名" width="125"></el-table-column>
 | 
					 | 
				
			||||||
                <el-table-column property="remark" label="描述" width="125"></el-table-column>
 | 
					 | 
				
			||||||
                <el-table-column property="createTime" label="创建时间">
 | 
					 | 
				
			||||||
                    <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,
 | 
					 | 
				
			||||||
                chooseId: null,
 | 
					 | 
				
			||||||
                chooseData: null,
 | 
					 | 
				
			||||||
                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 chooseEnv = (item: any) => {
 | 
					 | 
				
			||||||
            if (!item) {
 | 
					 | 
				
			||||||
                return;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            state.showEnvDialog.chooseData = item;
 | 
					 | 
				
			||||||
            state.showEnvDialog.chooseId = item.id;
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const deleteEnv = async () => {
 | 
					 | 
				
			||||||
            notNull(state.showEnvDialog.chooseData, '请选选择环境');
 | 
					 | 
				
			||||||
            await projectApi.delProjectEnvs.request({ id: state.showEnvDialog.chooseId });
 | 
					 | 
				
			||||||
            ElMessage.success('删除成功');
 | 
					 | 
				
			||||||
            state.showEnvDialog.envs = await projectApi.projectEnvs.request({ projectId: state.chooseId });
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const showAddMemberDialog = () => {
 | 
					 | 
				
			||||||
            state.showMemDialog.addVisible = true;
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        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,
 | 
					 | 
				
			||||||
            deleteEnv,
 | 
					 | 
				
			||||||
            showAddMemberDialog,
 | 
					 | 
				
			||||||
            addMember,
 | 
					 | 
				
			||||||
            chooseMember,
 | 
					 | 
				
			||||||
            deleteMember,
 | 
					 | 
				
			||||||
            cancelAddMember,
 | 
					 | 
				
			||||||
            showAddEnvDialog,
 | 
					 | 
				
			||||||
            chooseEnv,
 | 
					 | 
				
			||||||
            addEnv,
 | 
					 | 
				
			||||||
            cancelAddEnv,
 | 
					 | 
				
			||||||
            getAccount,
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
</script>
 | 
					 | 
				
			||||||
<style lang="scss">
 | 
					 | 
				
			||||||
</style>
 | 
					 | 
				
			||||||
@@ -1,17 +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'),
 | 
					 | 
				
			||||||
    delProjectEnvs:  Api.create("/projects/envs", 'delete'),
 | 
					 | 
				
			||||||
    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'),
 | 
					 | 
				
			||||||
}   
 | 
					 | 
				
			||||||
@@ -4,34 +4,57 @@
 | 
				
			|||||||
            <div style="float: left">
 | 
					            <div style="float: left">
 | 
				
			||||||
                <el-row type="flex" justify="space-between">
 | 
					                <el-row type="flex" justify="space-between">
 | 
				
			||||||
                    <el-col :span="24">
 | 
					                    <el-col :span="24">
 | 
				
			||||||
                        <project-env-select @changeProjectEnv="changeProjectEnv" @clear="clearRedis">
 | 
					                        <el-form class="search-form" label-position="right" :inline="true">
 | 
				
			||||||
                            <template #default>
 | 
					                            <el-form-item label="标签">
 | 
				
			||||||
                                <el-form-item label="redis" label-width="40px">
 | 
					                                <el-select
 | 
				
			||||||
                                    <el-select v-model="scanParam.id" placeholder="请选择redis" @change="changeRedis" @clear="clearRedis" clearable>
 | 
					                                    @change="changeTag"
 | 
				
			||||||
                                        <el-option v-for="item in redisList" :key="item.id" :label="item.host" :value="item.id"> </el-option>
 | 
					                                    @focus="getTags"
 | 
				
			||||||
                                    </el-select>
 | 
					                                    v-model="query.tagPath"
 | 
				
			||||||
                                </el-form-item>
 | 
					                                    placeholder="请选择标签"
 | 
				
			||||||
                                <el-form-item label="库" label-width="20px">
 | 
					                                    filterable
 | 
				
			||||||
                                    <el-select v-model="scanParam.db" @change="changeDb" placeholder="库"  style="width: 70px">
 | 
					                                    style="width: 250px"
 | 
				
			||||||
                                        <el-option v-for="db in dbList" :key="db" :label="db" :value="db"> </el-option>
 | 
					                                >
 | 
				
			||||||
                                    </el-select>
 | 
					                                    <el-option v-for="item in tags" :key="item" :label="item" :value="item"> </el-option>
 | 
				
			||||||
                                </el-form-item>
 | 
					                                </el-select>
 | 
				
			||||||
                            </template>
 | 
					                            </el-form-item>
 | 
				
			||||||
                        </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>
 | 
				
			||||||
                    <el-col class="mt10">
 | 
					                    <el-col class="mt10">
 | 
				
			||||||
                        <el-form class="search-form" label-position="right" :inline="true" label-width="60px">
 | 
					                        <el-form class="search-form" label-position="right" :inline="true" label-width="60px">
 | 
				
			||||||
                            <el-form-item label="key" label-width="40px">
 | 
					                            <el-form-item label="key" label-width="40px">
 | 
				
			||||||
                                <el-input
 | 
					                                <el-input
 | 
				
			||||||
                                    placeholder="match 支持*模糊key"
 | 
					                                    placeholder="match 支持*模糊key"
 | 
				
			||||||
                                    style="width: 240px"
 | 
					                                    style="width: 250px"
 | 
				
			||||||
                                    v-model="scanParam.match"
 | 
					                                    v-model="scanParam.match"
 | 
				
			||||||
                                    @clear="clear()"
 | 
					                                    @clear="clear()"
 | 
				
			||||||
                                    clearable
 | 
					                                    clearable
 | 
				
			||||||
                                ></el-input>
 | 
					                                ></el-input>
 | 
				
			||||||
                            </el-form-item>
 | 
					                            </el-form-item>
 | 
				
			||||||
                            <el-form-item label="count" label-width="60px">
 | 
					                            <el-form-item label="count" label-width="40px">
 | 
				
			||||||
                                <el-input placeholder="count" style="width: 62px" v-model.number="scanParam.count"></el-input>
 | 
					                                <el-input placeholder="count" style="width: 70px" v-model.number="scanParam.count"></el-input>
 | 
				
			||||||
                            </el-form-item>
 | 
					                            </el-form-item>
 | 
				
			||||||
                            <el-form-item>
 | 
					                            <el-form-item>
 | 
				
			||||||
                                <el-button @click="searchKey()" type="success" icon="search" plain></el-button>
 | 
					                                <el-button @click="searchKey()" type="success" icon="search" plain></el-button>
 | 
				
			||||||
@@ -127,12 +150,12 @@
 | 
				
			|||||||
import { redisApi } from './api';
 | 
					import { redisApi } from './api';
 | 
				
			||||||
import { toRefs, reactive, defineComponent } from 'vue';
 | 
					import { toRefs, reactive, defineComponent } from 'vue';
 | 
				
			||||||
import { ElMessage, ElMessageBox } from 'element-plus';
 | 
					import { ElMessage, ElMessageBox } from 'element-plus';
 | 
				
			||||||
import ProjectEnvSelect from '../component/ProjectEnvSelect.vue';
 | 
					 | 
				
			||||||
import HashValue from './HashValue.vue';
 | 
					import HashValue from './HashValue.vue';
 | 
				
			||||||
import StringValue from './StringValue.vue';
 | 
					import StringValue from './StringValue.vue';
 | 
				
			||||||
import SetValue from './SetValue.vue';
 | 
					import SetValue from './SetValue.vue';
 | 
				
			||||||
import ListValue from './ListValue.vue';
 | 
					import ListValue from './ListValue.vue';
 | 
				
			||||||
import { isTrue, notBlank, notNull } from '@/common/assert';
 | 
					import { isTrue, notBlank, notNull } from '@/common/assert';
 | 
				
			||||||
 | 
					import { tagApi } from '../tag/api.ts';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'DataOperation',
 | 
					    name: 'DataOperation',
 | 
				
			||||||
@@ -141,15 +164,15 @@ export default defineComponent({
 | 
				
			|||||||
        HashValue,
 | 
					        HashValue,
 | 
				
			||||||
        SetValue,
 | 
					        SetValue,
 | 
				
			||||||
        ListValue,
 | 
					        ListValue,
 | 
				
			||||||
        ProjectEnvSelect,
 | 
					 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    setup() {
 | 
					    setup() {
 | 
				
			||||||
        const state = reactive({
 | 
					        const state = reactive({
 | 
				
			||||||
            loading: false,
 | 
					            loading: false,
 | 
				
			||||||
            redisList: [],
 | 
					            tags: [],
 | 
				
			||||||
 | 
					            redisList: [] as any,
 | 
				
			||||||
            dbList: [],
 | 
					            dbList: [],
 | 
				
			||||||
            query: {
 | 
					            query: {
 | 
				
			||||||
                envId: 0,
 | 
					                tagPath: null,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            scanParam: {
 | 
					            scanParam: {
 | 
				
			||||||
                id: null,
 | 
					                id: null,
 | 
				
			||||||
@@ -185,19 +208,22 @@ export default defineComponent({
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const searchRedis = async () => {
 | 
					        const searchRedis = async () => {
 | 
				
			||||||
            notNull(state.query.envId, '请先选择项目环境');
 | 
					            notBlank(state.query.tagPath, '请先选择标签');
 | 
				
			||||||
            const res = await redisApi.redisList.request(state.query);
 | 
					            const res = await redisApi.redisList.request(state.query);
 | 
				
			||||||
            state.redisList = res.list;
 | 
					            state.redisList = res.list;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const changeProjectEnv = (projectId: any, envId: any) => {
 | 
					        const changeTag = (tagPath: string) => {
 | 
				
			||||||
            clearRedis();
 | 
					            clearRedis();
 | 
				
			||||||
            if (envId != null) {
 | 
					            if (tagPath != null) {
 | 
				
			||||||
                state.query.envId = envId;
 | 
					 | 
				
			||||||
                searchRedis();
 | 
					                searchRedis();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getTags = async () => {
 | 
				
			||||||
 | 
					            state.tags = await tagApi.getAccountTags.request(null);
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const changeRedis = (id: number) => {
 | 
					        const changeRedis = (id: number) => {
 | 
				
			||||||
            resetScanParam(id);
 | 
					            resetScanParam(id);
 | 
				
			||||||
            state.scanParam.db = null;
 | 
					            state.scanParam.db = null;
 | 
				
			||||||
@@ -385,7 +411,8 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
            changeProjectEnv,
 | 
					            getTags,
 | 
				
			||||||
 | 
					            changeTag,
 | 
				
			||||||
            changeRedis,
 | 
					            changeRedis,
 | 
				
			||||||
            changeDb,
 | 
					            changeDb,
 | 
				
			||||||
            clearRedis,
 | 
					            clearRedis,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,16 +2,11 @@
 | 
				
			|||||||
    <div>
 | 
					    <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="redisForm" :rules="rules" label-width="85px">
 | 
					            <el-form :model="form" ref="redisForm" :rules="rules" label-width="85px">
 | 
				
			||||||
                <el-form-item prop="projectId" label="项目:" required>
 | 
					                <el-form-item prop="tagId" label="标签:" required>
 | 
				
			||||||
                    <el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
 | 
					                    <tag-select v-model:tag-id="form.tagId" v-model:tag-path="form.tagPath" style="width: 100%" />
 | 
				
			||||||
                        <el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
 | 
					 | 
				
			||||||
                    </el-select>
 | 
					 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					                <el-form-item prop="name" label="名称:" required>
 | 
				
			||||||
                <el-form-item prop="envId" label="环境:" required>
 | 
					                    <el-input v-model.trim="form.name" placeholder="请输入redis名称" auto-complete="off"></el-input>
 | 
				
			||||||
                    <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>
 | 
				
			||||||
                <el-form-item prop="mode" label="mode:" required>
 | 
					                <el-form-item prop="mode" label="mode:" required>
 | 
				
			||||||
                    <el-select style="width: 100%" v-model="form.mode" placeholder="请选择模式">
 | 
					                    <el-select style="width: 100%" v-model="form.mode" placeholder="请选择模式">
 | 
				
			||||||
@@ -88,9 +83,13 @@ import { projectApi } from '../project/api.ts';
 | 
				
			|||||||
import { machineApi } from '../machine/api.ts';
 | 
					import { machineApi } from '../machine/api.ts';
 | 
				
			||||||
import { ElMessage } from 'element-plus';
 | 
					import { ElMessage } from 'element-plus';
 | 
				
			||||||
import { RsaEncrypt } from '@/common/rsa';
 | 
					import { RsaEncrypt } from '@/common/rsa';
 | 
				
			||||||
 | 
					import TagSelect from '../component/TagSelect.vue';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'RedisEdit',
 | 
					    name: 'RedisEdit',
 | 
				
			||||||
 | 
					    components: {
 | 
				
			||||||
 | 
					        TagSelect,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    props: {
 | 
					    props: {
 | 
				
			||||||
        visible: {
 | 
					        visible: {
 | 
				
			||||||
            type: Boolean,
 | 
					            type: Boolean,
 | 
				
			||||||
@@ -114,6 +113,8 @@ export default defineComponent({
 | 
				
			|||||||
            sshTunnelMachineList: [],
 | 
					            sshTunnelMachineList: [],
 | 
				
			||||||
            form: {
 | 
					            form: {
 | 
				
			||||||
                id: null,
 | 
					                id: null,
 | 
				
			||||||
 | 
					                tagId: null as any,
 | 
				
			||||||
 | 
					                tatPath: null as any,
 | 
				
			||||||
                name: null,
 | 
					                name: null,
 | 
				
			||||||
                mode: 'standalone',
 | 
					                mode: 'standalone',
 | 
				
			||||||
                host: '',
 | 
					                host: '',
 | 
				
			||||||
@@ -176,7 +177,6 @@ export default defineComponent({
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            state.projects = newValue.projects;
 | 
					            state.projects = newValue.projects;
 | 
				
			||||||
            if (newValue.redis) {
 | 
					            if (newValue.redis) {
 | 
				
			||||||
                getEnvs(newValue.redis.projectId);
 | 
					 | 
				
			||||||
                state.form = { ...newValue.redis };
 | 
					                state.form = { ...newValue.redis };
 | 
				
			||||||
                convertDb(state.form.db);
 | 
					                convertDb(state.form.db);
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
@@ -205,34 +205,10 @@ export default defineComponent({
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const getEnvs = async (projectId: any) => {
 | 
					 | 
				
			||||||
            state.envs = await projectApi.projectEnvs.request({ projectId });
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const getPwd = async () => {
 | 
					        const getPwd = async () => {
 | 
				
			||||||
            state.pwd = await redisApi.getRedisPwd.request({ id: state.form.id });
 | 
					            state.pwd = await redisApi.getRedisPwd.request({ id: state.form.id });
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        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 btnOk = async () => {
 | 
					        const btnOk = async () => {
 | 
				
			||||||
            redisForm.value.validate(async (valid: boolean) => {
 | 
					            redisForm.value.validate(async (valid: boolean) => {
 | 
				
			||||||
                if (valid) {
 | 
					                if (valid) {
 | 
				
			||||||
@@ -270,8 +246,6 @@ export default defineComponent({
 | 
				
			|||||||
            changeDb,
 | 
					            changeDb,
 | 
				
			||||||
            getSshTunnelMachines,
 | 
					            getSshTunnelMachines,
 | 
				
			||||||
            getPwd,
 | 
					            getPwd,
 | 
				
			||||||
            changeProject,
 | 
					 | 
				
			||||||
            changeEnv,
 | 
					 | 
				
			||||||
            btnOk,
 | 
					            btnOk,
 | 
				
			||||||
            cancel,
 | 
					            cancel,
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,8 +5,8 @@
 | 
				
			|||||||
            <el-button type="primary" icon="edit" :disabled="currentId == null" @click="editRedis(false)" plain>编辑</el-button>
 | 
					            <el-button type="primary" icon="edit" :disabled="currentId == null" @click="editRedis(false)" plain>编辑</el-button>
 | 
				
			||||||
            <el-button type="danger" icon="delete" :disabled="currentId == null" @click="deleteRedis" plain>删除</el-button>
 | 
					            <el-button type="danger" icon="delete" :disabled="currentId == null" @click="deleteRedis" plain>删除</el-button>
 | 
				
			||||||
            <div style="float: right">
 | 
					            <div style="float: right">
 | 
				
			||||||
                <el-select @focus="getProjects" v-model="query.projectId" placeholder="请选择项目" filterable clearable>
 | 
					                <el-select @focus="getTags" v-model="query.tagPath" placeholder="请选择标签" filterable clearable>
 | 
				
			||||||
                    <el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
 | 
					                    <el-option v-for="item in tags" :key="item" :label="item" :value="item"> </el-option>
 | 
				
			||||||
                </el-select>
 | 
					                </el-select>
 | 
				
			||||||
                <el-button class="ml5" @click="search" type="success" icon="search"></el-button>
 | 
					                <el-button class="ml5" @click="search" type="success" icon="search"></el-button>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
@@ -18,14 +18,14 @@
 | 
				
			|||||||
                        </el-radio>
 | 
					                        </el-radio>
 | 
				
			||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
                </el-table-column>
 | 
					                </el-table-column>
 | 
				
			||||||
                <el-table-column prop="project" 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="env" label="环境" min-width="100"></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="host" label="host:port" min-width="150" show-overflow-tooltip> </el-table-column>
 | 
				
			||||||
                <el-table-column prop="mode" label="mode" min-width="100"></el-table-column>
 | 
					                <el-table-column prop="mode" label="mode" min-width="100"></el-table-column>
 | 
				
			||||||
                <el-table-column prop="remark" label="备注" min-width="120" show-overflow-tooltip></el-table-column>
 | 
					                <el-table-column prop="remark" label="备注" min-width="120" show-overflow-tooltip></el-table-column>
 | 
				
			||||||
                <el-table-column prop="createTime" label="创建时间" min-width="160">
 | 
					                <el-table-column prop="createTime" label="创建时间" min-width="160">
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        {{ $filters.dateFormat(scope.row.createTime) }}
 | 
					                        {{ dateFormat(scope.row.createTime) }}
 | 
				
			||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
                </el-table-column>
 | 
					                </el-table-column>
 | 
				
			||||||
                <el-table-column prop="creator" label="创建人" min-width="100"></el-table-column>
 | 
					                <el-table-column prop="creator" label="创建人" min-width="100"></el-table-column>
 | 
				
			||||||
@@ -138,7 +138,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        <redis-edit
 | 
					        <redis-edit
 | 
				
			||||||
            @val-change="valChange"
 | 
					            @val-change="valChange"
 | 
				
			||||||
            :projects="projects"
 | 
					            :tags="tags"
 | 
				
			||||||
            :title="redisEditDialog.title"
 | 
					            :title="redisEditDialog.title"
 | 
				
			||||||
            v-model:visible="redisEditDialog.visible"
 | 
					            v-model:visible="redisEditDialog.visible"
 | 
				
			||||||
            v-model:redis="redisEditDialog.data"
 | 
					            v-model:redis="redisEditDialog.data"
 | 
				
			||||||
@@ -151,8 +151,9 @@ import Info from './Info.vue';
 | 
				
			|||||||
import { redisApi } from './api';
 | 
					import { redisApi } from './api';
 | 
				
			||||||
import { toRefs, reactive, defineComponent, onMounted } from 'vue';
 | 
					import { toRefs, reactive, defineComponent, onMounted } from 'vue';
 | 
				
			||||||
import { ElMessage, ElMessageBox } from 'element-plus';
 | 
					import { ElMessage, ElMessageBox } from 'element-plus';
 | 
				
			||||||
import { projectApi } from '../project/api.ts';
 | 
					import { tagApi } from '../tag/api.ts';
 | 
				
			||||||
import RedisEdit from './RedisEdit.vue';
 | 
					import RedisEdit from './RedisEdit.vue';
 | 
				
			||||||
 | 
					import { dateFormat } from '@/common/utils/date';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'RedisList',
 | 
					    name: 'RedisList',
 | 
				
			||||||
@@ -162,15 +163,15 @@ export default defineComponent({
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
    setup() {
 | 
					    setup() {
 | 
				
			||||||
        const state = reactive({
 | 
					        const state = reactive({
 | 
				
			||||||
            projects: [],
 | 
					            tags: [],
 | 
				
			||||||
            redisTable: [],
 | 
					            redisTable: [],
 | 
				
			||||||
            total: 0,
 | 
					            total: 0,
 | 
				
			||||||
            currentId: null,
 | 
					            currentId: null,
 | 
				
			||||||
            currentData: null,
 | 
					            currentData: null,
 | 
				
			||||||
            query: {
 | 
					            query: {
 | 
				
			||||||
 | 
					                tagPath: null,
 | 
				
			||||||
                pageNum: 1,
 | 
					                pageNum: 1,
 | 
				
			||||||
                pageSize: 10,
 | 
					                pageSize: 10,
 | 
				
			||||||
                prjectId: null,
 | 
					 | 
				
			||||||
                clusterId: null,
 | 
					                clusterId: null,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            redisInfo: {
 | 
					            redisInfo: {
 | 
				
			||||||
@@ -263,12 +264,11 @@ export default defineComponent({
 | 
				
			|||||||
            state.total = res.total;
 | 
					            state.total = res.total;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const getProjects = async () => {
 | 
					        const getTags = async () => {
 | 
				
			||||||
            state.projects = await projectApi.accountProjects.request(null);
 | 
					            state.tags = await tagApi.getAccountTags.request(null);
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const editRedis = async (isAdd = false) => {
 | 
					        const editRedis = async (isAdd = false) => {
 | 
				
			||||||
            await getProjects();
 | 
					 | 
				
			||||||
            if (isAdd) {
 | 
					            if (isAdd) {
 | 
				
			||||||
                state.redisEditDialog.data = null;
 | 
					                state.redisEditDialog.data = null;
 | 
				
			||||||
                state.redisEditDialog.title = '新增redis';
 | 
					                state.redisEditDialog.title = '新增redis';
 | 
				
			||||||
@@ -287,7 +287,8 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
            getProjects,
 | 
					            dateFormat,
 | 
				
			||||||
 | 
					            getTags,
 | 
				
			||||||
            search,
 | 
					            search,
 | 
				
			||||||
            handlePageChange,
 | 
					            handlePageChange,
 | 
				
			||||||
            choose,
 | 
					            choose,
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										300
									
								
								mayfly_go_web/src/views/ops/tag/TagTreeList.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										300
									
								
								mayfly_go_web/src/views/ops/tag/TagTreeList.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,300 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					    <div class="menu">
 | 
				
			||||||
 | 
					        <div class="toolbar">
 | 
				
			||||||
 | 
					            <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
 | 
				
			||||||
 | 
					            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">
 | 
				
			||||||
 | 
					                        {{ 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">
 | 
				
			||||||
 | 
					import { toRefs, ref, reactive, onMounted, defineComponent } from 'vue';
 | 
				
			||||||
 | 
					import { ElMessage, ElMessageBox } from 'element-plus';
 | 
				
			||||||
 | 
					import { tagApi } from './api';
 | 
				
			||||||
 | 
					import { dateFormat } from '@/common/utils/date';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default defineComponent({
 | 
				
			||||||
 | 
					    name: 'TagTreeList',
 | 
				
			||||||
 | 
					    components: {},
 | 
				
			||||||
 | 
					    setup() {
 | 
				
			||||||
 | 
					        const tagForm: any = ref(null);
 | 
				
			||||||
 | 
					        const state = reactive({
 | 
				
			||||||
 | 
					            saveTabDialog: {
 | 
				
			||||||
 | 
					                title: '新增标签',
 | 
				
			||||||
 | 
					                visible: false,
 | 
				
			||||||
 | 
					                form: { id: 0, pid: 0, code: '', name: '', remark: '' },
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            //资源信息弹出框对象
 | 
				
			||||||
 | 
					            infoDialog: {
 | 
				
			||||||
 | 
					                title: '',
 | 
				
			||||||
 | 
					                visible: false,
 | 
				
			||||||
 | 
					                // 资源类型选择是否选
 | 
				
			||||||
 | 
					                data: null as any,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            data: [],
 | 
				
			||||||
 | 
					            props: {
 | 
				
			||||||
 | 
					                label: 'name',
 | 
				
			||||||
 | 
					                children: 'children',
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            // 展开的节点
 | 
				
			||||||
 | 
					            defaultExpandedKeys: [] as any[],
 | 
				
			||||||
 | 
					            rules: {
 | 
				
			||||||
 | 
					                code: [
 | 
				
			||||||
 | 
					                    { required: true, message: '标识符不能为空', trigger: 'blur' },
 | 
				
			||||||
 | 
					                    // {
 | 
				
			||||||
 | 
					                    //     pattern: /^\w+$/g,
 | 
				
			||||||
 | 
					                    //     message: '标识符只能为空数字字母下划线等',
 | 
				
			||||||
 | 
					                    //     trigger: 'blur',
 | 
				
			||||||
 | 
					                    // },
 | 
				
			||||||
 | 
					                ],
 | 
				
			||||||
 | 
					                name: [{ required: true, message: '名称不能为空', trigger: 'blur' }],
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        onMounted(() => {
 | 
				
			||||||
 | 
					            search();
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        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);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            ...toRefs(state),
 | 
				
			||||||
 | 
					            dateFormat,
 | 
				
			||||||
 | 
					            tagForm,
 | 
				
			||||||
 | 
					            info,
 | 
				
			||||||
 | 
					            saveTag,
 | 
				
			||||||
 | 
					            showSaveTabDialog,
 | 
				
			||||||
 | 
					            showEditTagDialog,
 | 
				
			||||||
 | 
					            cancelSaveTag,
 | 
				
			||||||
 | 
					            deleteTag,
 | 
				
			||||||
 | 
					            handleNodeExpand,
 | 
				
			||||||
 | 
					            handleNodeCollapse,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					</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>
 | 
				
			||||||
							
								
								
									
										440
									
								
								mayfly_go_web/src/views/ops/tag/TeamList.vue
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										440
									
								
								mayfly_go_web/src/views/ops/tag/TeamList.vue
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,440 @@
 | 
				
			|||||||
 | 
					<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 == null" @click="showSaveTeamDialog(chooseData)" type="primary" icon="edit"
 | 
				
			||||||
 | 
					                >编辑</el-button
 | 
				
			||||||
 | 
					            >
 | 
				
			||||||
 | 
					            <el-button v-auth="'team:del'" :disabled="chooseId == null" @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="600px" :title="showMemDialog.title" v-model="showMemDialog.visible">
 | 
				
			||||||
 | 
					            <div class="toolbar">
 | 
				
			||||||
 | 
					                <el-button v-auth="'team:member:save'" @click="showAddMemberDialog()" type="primary" icon="plus">添加</el-button>
 | 
				
			||||||
 | 
					                <el-button v-auth="'team:member:del'" @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="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
 | 
				
			||||||
 | 
					                @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>
 | 
				
			||||||
 | 
					                <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">
 | 
				
			||||||
 | 
					import { ref, toRefs, reactive, onMounted, defineComponent } 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';
 | 
				
			||||||
 | 
					export default defineComponent({
 | 
				
			||||||
 | 
					    name: 'TeamList',
 | 
				
			||||||
 | 
					    components: {},
 | 
				
			||||||
 | 
					    setup() {
 | 
				
			||||||
 | 
					        const teamForm: any = ref(null);
 | 
				
			||||||
 | 
					        const tagTreeRef: any = ref(null);
 | 
				
			||||||
 | 
					        const state = reactive({
 | 
				
			||||||
 | 
					            dialogFormVisible: false,
 | 
				
			||||||
 | 
					            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: 8,
 | 
				
			||||||
 | 
					                    pageNum: 1,
 | 
				
			||||||
 | 
					                    teamId: null,
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                members: {
 | 
				
			||||||
 | 
					                    list: [],
 | 
				
			||||||
 | 
					                    total: null,
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                title: '',
 | 
				
			||||||
 | 
					                addVisible: false,
 | 
				
			||||||
 | 
					                memForm: {
 | 
				
			||||||
 | 
					                    accountId: null as any,
 | 
				
			||||||
 | 
					                    teamId: 0,
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                accounts: Array(),
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            showTagDialog: {
 | 
				
			||||||
 | 
					                title: '项目信息',
 | 
				
			||||||
 | 
					                visible: false,
 | 
				
			||||||
 | 
					                tags: [],
 | 
				
			||||||
 | 
					                teamId: 0,
 | 
				
			||||||
 | 
					                tagTreeTeams: [] as any,
 | 
				
			||||||
 | 
					                props: {
 | 
				
			||||||
 | 
					                    value: 'id',
 | 
				
			||||||
 | 
					                    label: 'codePath',
 | 
				
			||||||
 | 
					                    children: 'children',
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        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) => {
 | 
				
			||||||
 | 
					            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.accountId, '请先选择账号');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            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 = (data: any, checkInfo: any) => {
 | 
				
			||||||
 | 
					            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);
 | 
				
			||||||
 | 
					        // }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            ...toRefs(state),
 | 
				
			||||||
 | 
					            teamForm,
 | 
				
			||||||
 | 
					            tagTreeRef,
 | 
				
			||||||
 | 
					            dateFormat,
 | 
				
			||||||
 | 
					            choose,
 | 
				
			||||||
 | 
					            search,
 | 
				
			||||||
 | 
					            handlePageChange,
 | 
				
			||||||
 | 
					            showSaveTeamDialog,
 | 
				
			||||||
 | 
					            saveTeam,
 | 
				
			||||||
 | 
					            cancelSaveTeam,
 | 
				
			||||||
 | 
					            deleteTeam,
 | 
				
			||||||
 | 
					            showMembers,
 | 
				
			||||||
 | 
					            setMemebers,
 | 
				
			||||||
 | 
					            getAccount,
 | 
				
			||||||
 | 
					            showAddMemberDialog,
 | 
				
			||||||
 | 
					            addMember,
 | 
				
			||||||
 | 
					            cancelAddMember,
 | 
				
			||||||
 | 
					            chooseMember,
 | 
				
			||||||
 | 
					            deleteMember,
 | 
				
			||||||
 | 
					            showTags,
 | 
				
			||||||
 | 
					            closeTagDialog,
 | 
				
			||||||
 | 
					            saveTags,
 | 
				
			||||||
 | 
					            tagTreeNodeCheck,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					</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'),
 | 
				
			||||||
 | 
					}   
 | 
				
			||||||
@@ -73,6 +73,7 @@ export default defineComponent({
 | 
				
			|||||||
                state.form = { ...newValue.account };
 | 
					                state.form = { ...newValue.account };
 | 
				
			||||||
                state.edit = true;
 | 
					                state.edit = true;
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
 | 
					                state.edit = false;
 | 
				
			||||||
                state.form = {} as any;
 | 
					                state.form = {} as any;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            state.dialogVisible = newValue.visible;
 | 
					            state.dialogVisible = newValue.visible;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
    <div>
 | 
					    <div>
 | 
				
			||||||
        <el-dialog :title="title" v-model="dvisible" :show-close="false" :before-close="cancel" width="500px" :destroy-on-close="true">
 | 
					        <el-dialog :title="title" v-model="dvisible" :show-close="false" :before-close="cancel" width="750px" :destroy-on-close="true">
 | 
				
			||||||
            <el-form ref="configForm" :model="form" label-width="90px">
 | 
					            <el-form ref="configForm" :model="form" label-width="90px">
 | 
				
			||||||
                <el-form-item prop="name" label="配置项:" required>
 | 
					                <el-form-item prop="name" label="配置项:" required>
 | 
				
			||||||
                    <el-input v-model="form.name"></el-input>
 | 
					                    <el-input v-model="form.name"></el-input>
 | 
				
			||||||
@@ -8,9 +8,28 @@
 | 
				
			|||||||
                <el-form-item prop="key" label="配置key:" required>
 | 
					                <el-form-item prop="key" label="配置key:" required>
 | 
				
			||||||
                    <el-input :disabled="form.id != null" v-model="form.key"></el-input>
 | 
					                    <el-input :disabled="form.id != null" v-model="form.key"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="value" label="配置值:" required>
 | 
					
 | 
				
			||||||
                    <el-input v-model="form.value"></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>
 | 
				
			||||||
 | 
					                <!-- <el-form-item prop="value" label="配置值:" required>
 | 
				
			||||||
 | 
					                    <el-input v-model="form.value"></el-input>
 | 
				
			||||||
 | 
					                </el-form-item> -->
 | 
				
			||||||
                <el-form-item label="备注:">
 | 
					                <el-form-item label="备注:">
 | 
				
			||||||
                    <el-input v-model="form.remark" type="textarea" :rows="2"></el-input>
 | 
					                    <el-input v-model="form.remark" type="textarea" :rows="2"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
@@ -46,10 +65,12 @@ export default defineComponent({
 | 
				
			|||||||
        const configForm: any = ref(null);
 | 
					        const configForm: any = ref(null);
 | 
				
			||||||
        const state = reactive({
 | 
					        const state = reactive({
 | 
				
			||||||
            dvisible: false,
 | 
					            dvisible: false,
 | 
				
			||||||
 | 
					            params: [] as any,
 | 
				
			||||||
            form: {
 | 
					            form: {
 | 
				
			||||||
                id: null,
 | 
					                id: null,
 | 
				
			||||||
                name: '',
 | 
					                name: '',
 | 
				
			||||||
                key: '',
 | 
					                key: '',
 | 
				
			||||||
 | 
					                params: '',
 | 
				
			||||||
                value: '',
 | 
					                value: '',
 | 
				
			||||||
                remark: '',
 | 
					                remark: '',
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
@@ -60,11 +81,25 @@ export default defineComponent({
 | 
				
			|||||||
            state.dvisible = newValue.visible;
 | 
					            state.dvisible = newValue.visible;
 | 
				
			||||||
            if (newValue.data) {
 | 
					            if (newValue.data) {
 | 
				
			||||||
                state.form = { ...newValue.data };
 | 
					                state.form = { ...newValue.data };
 | 
				
			||||||
 | 
					                if (state.form.params) {
 | 
				
			||||||
 | 
					                    state.params = JSON.parse(state.form.params);
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    state.params = [];
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                state.form = {} as any;
 | 
					                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 = () => {
 | 
					        const cancel = () => {
 | 
				
			||||||
            // 更新父组件visible prop对应的值为false
 | 
					            // 更新父组件visible prop对应的值为false
 | 
				
			||||||
            emit('update:visible', false);
 | 
					            emit('update:visible', false);
 | 
				
			||||||
@@ -75,6 +110,9 @@ export default defineComponent({
 | 
				
			|||||||
        const btnOk = async () => {
 | 
					        const btnOk = async () => {
 | 
				
			||||||
            configForm.value.validate(async (valid: boolean) => {
 | 
					            configForm.value.validate(async (valid: boolean) => {
 | 
				
			||||||
                if (valid) {
 | 
					                if (valid) {
 | 
				
			||||||
 | 
					                    if (state.params) {
 | 
				
			||||||
 | 
					                        state.form.params = JSON.stringify(state.params);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                    await configApi.save.request(state.form);
 | 
					                    await configApi.save.request(state.form);
 | 
				
			||||||
                    emit('val-change', state.form);
 | 
					                    emit('val-change', state.form);
 | 
				
			||||||
                    cancel();
 | 
					                    cancel();
 | 
				
			||||||
@@ -88,6 +126,8 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
 | 
					            onAddParam,
 | 
				
			||||||
 | 
					            onDeleteParam,
 | 
				
			||||||
            configForm,
 | 
					            configForm,
 | 
				
			||||||
            btnOk,
 | 
					            btnOk,
 | 
				
			||||||
            cancel,
 | 
					            cancel,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,12 +16,25 @@
 | 
				
			|||||||
                <el-table-column prop="key" label="配置key"></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="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="remark" label="备注" min-width="100px" show-overflow-tooltip></el-table-column>
 | 
				
			||||||
                <el-table-column prop="updateTime" label="更新时间">
 | 
					                <el-table-column prop="updateTime" label="更新时间" min-width="100px">
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        {{ $filters.dateFormat(scope.row.createTime) }}
 | 
					                        {{ $filters.dateFormat(scope.row.createTime) }}
 | 
				
			||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
                </el-table-column>
 | 
					                </el-table-column>
 | 
				
			||||||
                <el-table-column prop="modifier" label="修改者" show-overflow-tooltip></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-table>
 | 
				
			||||||
            <el-row style="margin-top: 20px" type="flex" justify="end">
 | 
					            <el-row style="margin-top: 20px" type="flex" justify="end">
 | 
				
			||||||
                <el-pagination
 | 
					                <el-pagination
 | 
				
			||||||
@@ -35,6 +48,42 @@
 | 
				
			|||||||
            </el-row>
 | 
					            </el-row>
 | 
				
			||||||
        </el-card>
 | 
					        </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" />
 | 
					        <config-edit :title="configEdit.title" v-model:visible="configEdit.visible" :data="configEdit.config" @val-change="configEditChange" />
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
@@ -62,6 +111,12 @@ export default defineComponent({
 | 
				
			|||||||
            configs: [],
 | 
					            configs: [],
 | 
				
			||||||
            chooseId: null,
 | 
					            chooseId: null,
 | 
				
			||||||
            chooseData: null,
 | 
					            chooseData: null,
 | 
				
			||||||
 | 
					            paramsDialog: {
 | 
				
			||||||
 | 
					                visible: false,
 | 
				
			||||||
 | 
					                config: null as any,
 | 
				
			||||||
 | 
					                params: {},
 | 
				
			||||||
 | 
					                paramsFormItem: [] as any,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
            configEdit: {
 | 
					            configEdit: {
 | 
				
			||||||
                title: '配置修改',
 | 
					                title: '配置修改',
 | 
				
			||||||
                visible: false,
 | 
					                visible: false,
 | 
				
			||||||
@@ -84,6 +139,62 @@ export default defineComponent({
 | 
				
			|||||||
            search();
 | 
					            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) => {
 | 
					        const choose = (item: any) => {
 | 
				
			||||||
            if (!item) {
 | 
					            if (!item) {
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
@@ -93,7 +204,7 @@ export default defineComponent({
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const configEditChange = () => {
 | 
					        const configEditChange = () => {
 | 
				
			||||||
            ElMessage.success('修改成功!');
 | 
					            ElMessage.success('保存成功');
 | 
				
			||||||
            state.chooseId = null;
 | 
					            state.chooseId = null;
 | 
				
			||||||
            state.chooseData = null;
 | 
					            state.chooseData = null;
 | 
				
			||||||
            search();
 | 
					            search();
 | 
				
			||||||
@@ -111,6 +222,9 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
 | 
					            showSetConfigDialog,
 | 
				
			||||||
 | 
					            closeSetConfigDialog,
 | 
				
			||||||
 | 
					            setConfig,
 | 
				
			||||||
            search,
 | 
					            search,
 | 
				
			||||||
            handlePageChange,
 | 
					            handlePageChange,
 | 
				
			||||||
            choose,
 | 
					            choose,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -223,6 +223,16 @@
 | 
				
			|||||||
    estree-walker "^2.0.2"
 | 
					    estree-walker "^2.0.2"
 | 
				
			||||||
    source-map "^0.6.1"
 | 
					    source-map "^0.6.1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					"@vue/compiler-core@3.2.41":
 | 
				
			||||||
 | 
					  version "3.2.41"
 | 
				
			||||||
 | 
					  resolved "https://registry.npmmirror.com/@vue/compiler-core/-/compiler-core-3.2.41.tgz#fb5b25f23817400f44377d878a0cdead808453ef"
 | 
				
			||||||
 | 
					  integrity sha512-oA4mH6SA78DT+96/nsi4p9DX97PHcNROxs51lYk7gb9Z4BPKQ3Mh+BLn6CQZBw857Iuhu28BfMSRHAlPvD4vlw==
 | 
				
			||||||
 | 
					  dependencies:
 | 
				
			||||||
 | 
					    "@babel/parser" "^7.16.4"
 | 
				
			||||||
 | 
					    "@vue/shared" "3.2.41"
 | 
				
			||||||
 | 
					    estree-walker "^2.0.2"
 | 
				
			||||||
 | 
					    source-map "^0.6.1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"@vue/compiler-dom@3.2.39":
 | 
					"@vue/compiler-dom@3.2.39":
 | 
				
			||||||
  version "3.2.39"
 | 
					  version "3.2.39"
 | 
				
			||||||
  resolved "https://registry.npmmirror.com/@vue/compiler-dom/-/compiler-dom-3.2.39.tgz"
 | 
					  resolved "https://registry.npmmirror.com/@vue/compiler-dom/-/compiler-dom-3.2.39.tgz"
 | 
				
			||||||
@@ -231,7 +241,31 @@
 | 
				
			|||||||
    "@vue/compiler-core" "3.2.39"
 | 
					    "@vue/compiler-core" "3.2.39"
 | 
				
			||||||
    "@vue/shared" "3.2.39"
 | 
					    "@vue/shared" "3.2.39"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"@vue/compiler-sfc@3.2.39", "@vue/compiler-sfc@^3.0.11":
 | 
					"@vue/compiler-dom@3.2.41":
 | 
				
			||||||
 | 
					  version "3.2.41"
 | 
				
			||||||
 | 
					  resolved "https://registry.npmmirror.com/@vue/compiler-dom/-/compiler-dom-3.2.41.tgz#dc63dcd3ce8ca8a8721f14009d498a7a54380299"
 | 
				
			||||||
 | 
					  integrity sha512-xe5TbbIsonjENxJsYRbDJvthzqxLNk+tb3d/c47zgREDa/PCp6/Y4gC/skM4H6PIuX5DAxm7fFJdbjjUH2QTMw==
 | 
				
			||||||
 | 
					  dependencies:
 | 
				
			||||||
 | 
					    "@vue/compiler-core" "3.2.41"
 | 
				
			||||||
 | 
					    "@vue/shared" "3.2.41"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					"@vue/compiler-sfc@3.2.41":
 | 
				
			||||||
 | 
					  version "3.2.41"
 | 
				
			||||||
 | 
					  resolved "https://registry.npmmirror.com/@vue/compiler-sfc/-/compiler-sfc-3.2.41.tgz#238fb8c48318408c856748f4116aff8cc1dc2a73"
 | 
				
			||||||
 | 
					  integrity sha512-+1P2m5kxOeaxVmJNXnBskAn3BenbTmbxBxWOtBq3mQTCokIreuMULFantBUclP0+KnzNCMOvcnKinqQZmiOF8w==
 | 
				
			||||||
 | 
					  dependencies:
 | 
				
			||||||
 | 
					    "@babel/parser" "^7.16.4"
 | 
				
			||||||
 | 
					    "@vue/compiler-core" "3.2.41"
 | 
				
			||||||
 | 
					    "@vue/compiler-dom" "3.2.41"
 | 
				
			||||||
 | 
					    "@vue/compiler-ssr" "3.2.41"
 | 
				
			||||||
 | 
					    "@vue/reactivity-transform" "3.2.41"
 | 
				
			||||||
 | 
					    "@vue/shared" "3.2.41"
 | 
				
			||||||
 | 
					    estree-walker "^2.0.2"
 | 
				
			||||||
 | 
					    magic-string "^0.25.7"
 | 
				
			||||||
 | 
					    postcss "^8.1.10"
 | 
				
			||||||
 | 
					    source-map "^0.6.1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					"@vue/compiler-sfc@^3.0.11":
 | 
				
			||||||
  version "3.2.39"
 | 
					  version "3.2.39"
 | 
				
			||||||
  resolved "https://registry.npmmirror.com/@vue/compiler-sfc/-/compiler-sfc-3.2.39.tgz"
 | 
					  resolved "https://registry.npmmirror.com/@vue/compiler-sfc/-/compiler-sfc-3.2.39.tgz"
 | 
				
			||||||
  integrity sha512-fqAQgFs1/BxTUZkd0Vakn3teKUt//J3c420BgnYgEOoVdTwYpBTSXCMJ88GOBCylmUBbtquGPli9tVs7LzsWIA==
 | 
					  integrity sha512-fqAQgFs1/BxTUZkd0Vakn3teKUt//J3c420BgnYgEOoVdTwYpBTSXCMJ88GOBCylmUBbtquGPli9tVs7LzsWIA==
 | 
				
			||||||
@@ -255,6 +289,14 @@
 | 
				
			|||||||
    "@vue/compiler-dom" "3.2.39"
 | 
					    "@vue/compiler-dom" "3.2.39"
 | 
				
			||||||
    "@vue/shared" "3.2.39"
 | 
					    "@vue/shared" "3.2.39"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					"@vue/compiler-ssr@3.2.41":
 | 
				
			||||||
 | 
					  version "3.2.41"
 | 
				
			||||||
 | 
					  resolved "https://registry.npmmirror.com/@vue/compiler-ssr/-/compiler-ssr-3.2.41.tgz#344f564d68584b33367731c04ffc949784611fcb"
 | 
				
			||||||
 | 
					  integrity sha512-Y5wPiNIiaMz/sps8+DmhaKfDm1xgj6GrH99z4gq2LQenfVQcYXmHIOBcs5qPwl7jaW3SUQWjkAPKMfQemEQZwQ==
 | 
				
			||||||
 | 
					  dependencies:
 | 
				
			||||||
 | 
					    "@vue/compiler-dom" "3.2.41"
 | 
				
			||||||
 | 
					    "@vue/shared" "3.2.41"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"@vue/devtools-api@^6.0.0-beta.11":
 | 
					"@vue/devtools-api@^6.0.0-beta.11":
 | 
				
			||||||
  version "6.0.0-beta.20.1"
 | 
					  version "6.0.0-beta.20.1"
 | 
				
			||||||
  resolved "https://registry.npmmirror.com/@vue/devtools-api/download/@vue/devtools-api-6.0.0-beta.20.1.tgz"
 | 
					  resolved "https://registry.npmmirror.com/@vue/devtools-api/download/@vue/devtools-api-6.0.0-beta.20.1.tgz"
 | 
				
			||||||
@@ -276,43 +318,59 @@
 | 
				
			|||||||
    estree-walker "^2.0.2"
 | 
					    estree-walker "^2.0.2"
 | 
				
			||||||
    magic-string "^0.25.7"
 | 
					    magic-string "^0.25.7"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"@vue/reactivity@3.2.39":
 | 
					"@vue/reactivity-transform@3.2.41":
 | 
				
			||||||
  version "3.2.39"
 | 
					  version "3.2.41"
 | 
				
			||||||
  resolved "https://registry.npmmirror.com/@vue/reactivity/-/reactivity-3.2.39.tgz"
 | 
					  resolved "https://registry.npmmirror.com/@vue/reactivity-transform/-/reactivity-transform-3.2.41.tgz#9ff938877600c97f646e09ac1959b5150fb11a0c"
 | 
				
			||||||
  integrity sha512-vlaYX2a3qMhIZfrw3Mtfd+BuU+TZmvDrPMa+6lpfzS9k/LnGxkSuf0fhkP0rMGfiOHPtyKoU9OJJJFGm92beVQ==
 | 
					  integrity sha512-mK5+BNMsL4hHi+IR3Ft/ho6Za+L3FA5j8WvreJ7XzHrqkPq8jtF/SMo7tuc9gHjLDwKZX1nP1JQOKo9IEAn54A==
 | 
				
			||||||
  dependencies:
 | 
					  dependencies:
 | 
				
			||||||
    "@vue/shared" "3.2.39"
 | 
					    "@babel/parser" "^7.16.4"
 | 
				
			||||||
 | 
					    "@vue/compiler-core" "3.2.41"
 | 
				
			||||||
 | 
					    "@vue/shared" "3.2.41"
 | 
				
			||||||
 | 
					    estree-walker "^2.0.2"
 | 
				
			||||||
 | 
					    magic-string "^0.25.7"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"@vue/runtime-core@3.2.39":
 | 
					"@vue/reactivity@3.2.41":
 | 
				
			||||||
  version "3.2.39"
 | 
					  version "3.2.41"
 | 
				
			||||||
  resolved "https://registry.npmmirror.com/@vue/runtime-core/-/runtime-core-3.2.39.tgz"
 | 
					  resolved "https://registry.npmmirror.com/@vue/reactivity/-/reactivity-3.2.41.tgz#0ad3bdf76d76822da1502dc9f394dafd02642963"
 | 
				
			||||||
  integrity sha512-xKH5XP57JW5JW+8ZG1khBbuLakINTgPuINKL01hStWLTTGFOrM49UfCFXBcFvWmSbci3gmJyLl2EAzCaZWsx8g==
 | 
					  integrity sha512-9JvCnlj8uc5xRiQGZ28MKGjuCoPhhTwcoAdv3o31+cfGgonwdPNuvqAXLhlzu4zwqavFEG5tvaoINQEfxz+l6g==
 | 
				
			||||||
  dependencies:
 | 
					  dependencies:
 | 
				
			||||||
    "@vue/reactivity" "3.2.39"
 | 
					    "@vue/shared" "3.2.41"
 | 
				
			||||||
    "@vue/shared" "3.2.39"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
"@vue/runtime-dom@3.2.39":
 | 
					"@vue/runtime-core@3.2.41":
 | 
				
			||||||
  version "3.2.39"
 | 
					  version "3.2.41"
 | 
				
			||||||
  resolved "https://registry.npmmirror.com/@vue/runtime-dom/-/runtime-dom-3.2.39.tgz"
 | 
					  resolved "https://registry.npmmirror.com/@vue/runtime-core/-/runtime-core-3.2.41.tgz#775bfc00b3fadbaddab77138f23322aee3517a76"
 | 
				
			||||||
  integrity sha512-4G9AEJP+sLhsqf5wXcyKVWQKUhI+iWfy0hWQgea+CpaTD7BR0KdQzvoQdZhwCY6B3oleSyNLkLAQwm0ya/wNoA==
 | 
					  integrity sha512-0LBBRwqnI0p4FgIkO9q2aJBBTKDSjzhnxrxHYengkAF6dMOjeAIZFDADAlcf2h3GDALWnblbeprYYpItiulSVQ==
 | 
				
			||||||
  dependencies:
 | 
					  dependencies:
 | 
				
			||||||
    "@vue/runtime-core" "3.2.39"
 | 
					    "@vue/reactivity" "3.2.41"
 | 
				
			||||||
    "@vue/shared" "3.2.39"
 | 
					    "@vue/shared" "3.2.41"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					"@vue/runtime-dom@3.2.41":
 | 
				
			||||||
 | 
					  version "3.2.41"
 | 
				
			||||||
 | 
					  resolved "https://registry.npmmirror.com/@vue/runtime-dom/-/runtime-dom-3.2.41.tgz#cdf86be7410f7b15c29632a96ce879e5b4c9ab92"
 | 
				
			||||||
 | 
					  integrity sha512-U7zYuR1NVIP8BL6jmOqmapRAHovEFp7CSw4pR2FacqewXNGqZaRfHoNLQsqQvVQ8yuZNZtxSZy0FFyC70YXPpA==
 | 
				
			||||||
 | 
					  dependencies:
 | 
				
			||||||
 | 
					    "@vue/runtime-core" "3.2.41"
 | 
				
			||||||
 | 
					    "@vue/shared" "3.2.41"
 | 
				
			||||||
    csstype "^2.6.8"
 | 
					    csstype "^2.6.8"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"@vue/server-renderer@3.2.39":
 | 
					"@vue/server-renderer@3.2.41":
 | 
				
			||||||
  version "3.2.39"
 | 
					  version "3.2.41"
 | 
				
			||||||
  resolved "https://registry.npmmirror.com/@vue/server-renderer/-/server-renderer-3.2.39.tgz"
 | 
					  resolved "https://registry.npmmirror.com/@vue/server-renderer/-/server-renderer-3.2.41.tgz#ca64552c05878f94e8d191ac439141c06c0fb2ad"
 | 
				
			||||||
  integrity sha512-1yn9u2YBQWIgytFMjz4f/t0j43awKytTGVptfd3FtBk76t1pd8mxbek0G/DrnjJhd2V7mSTb5qgnxMYt8Z5iSQ==
 | 
					  integrity sha512-7YHLkfJdTlsZTV0ae5sPwl9Gn/EGr2hrlbcS/8naXm2CDpnKUwC68i1wGlrYAfIgYWL7vUZwk2GkYLQH5CvFig==
 | 
				
			||||||
  dependencies:
 | 
					  dependencies:
 | 
				
			||||||
    "@vue/compiler-ssr" "3.2.39"
 | 
					    "@vue/compiler-ssr" "3.2.41"
 | 
				
			||||||
    "@vue/shared" "3.2.39"
 | 
					    "@vue/shared" "3.2.41"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"@vue/shared@3.2.39":
 | 
					"@vue/shared@3.2.39":
 | 
				
			||||||
  version "3.2.39"
 | 
					  version "3.2.39"
 | 
				
			||||||
  resolved "https://registry.npmmirror.com/@vue/shared/-/shared-3.2.39.tgz"
 | 
					  resolved "https://registry.npmmirror.com/@vue/shared/-/shared-3.2.39.tgz"
 | 
				
			||||||
  integrity sha512-D3dl2ZB9qE6mTuWPk9RlhDeP1dgNRUKC3NJxji74A4yL8M2MwlhLKUC/49WHjrNzSPug58fWx/yFbaTzGAQSBw==
 | 
					  integrity sha512-D3dl2ZB9qE6mTuWPk9RlhDeP1dgNRUKC3NJxji74A4yL8M2MwlhLKUC/49WHjrNzSPug58fWx/yFbaTzGAQSBw==
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					"@vue/shared@3.2.41":
 | 
				
			||||||
 | 
					  version "3.2.41"
 | 
				
			||||||
 | 
					  resolved "https://registry.npmmirror.com/@vue/shared/-/shared-3.2.41.tgz#fbc95422df654ea64e8428eced96ba6ad555d2bb"
 | 
				
			||||||
 | 
					  integrity sha512-W9mfWLHmJhkfAmV+7gDjcHeAWALQtgGT3JErxULl0oz6R6+3ug91I7IErs93eCFhPCZPHBs4QJS7YWEV7A3sxw==
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"@vueuse/core@^9.1.0":
 | 
					"@vueuse/core@^9.1.0":
 | 
				
			||||||
  version "9.2.0"
 | 
					  version "9.2.0"
 | 
				
			||||||
  resolved "https://registry.npmmirror.com/@vueuse/core/-/core-9.2.0.tgz"
 | 
					  resolved "https://registry.npmmirror.com/@vueuse/core/-/core-9.2.0.tgz"
 | 
				
			||||||
@@ -335,10 +393,10 @@
 | 
				
			|||||||
  dependencies:
 | 
					  dependencies:
 | 
				
			||||||
    vue-demi "*"
 | 
					    vue-demi "*"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ace-builds@^1.6.0:
 | 
					ace-builds@^1.10.1:
 | 
				
			||||||
  version "1.7.1"
 | 
					  version "1.11.2"
 | 
				
			||||||
  resolved "https://registry.npmmirror.com/ace-builds/-/ace-builds-1.7.1.tgz"
 | 
					  resolved "https://registry.npmmirror.com/ace-builds/-/ace-builds-1.11.2.tgz#93fd7b7770909f3a48a23d71bd212d1b77baaaf5"
 | 
				
			||||||
  integrity sha512-1mcbP5kXvr729sJ9dA/8tul0pjuvKbma0LF/ZMRwPEwjoNWNpe/x0OXpaPJo36aRpZCjRZMl5zsME3hAKTiaNw==
 | 
					  integrity sha512-1VNeUF56b6gkaeeWJXMBBuz5n0ceDchjUwwVmTKpNM/N3YRrUEpykGEEsg7Y1PKP7IRyqtXfAu6VJDg7OZaLfA==
 | 
				
			||||||
 | 
					
 | 
				
			||||||
acorn-jsx@^5.3.1:
 | 
					acorn-jsx@^5.3.1:
 | 
				
			||||||
  version "5.3.2"
 | 
					  version "5.3.2"
 | 
				
			||||||
@@ -413,13 +471,14 @@ asynckit@^0.4.0:
 | 
				
			|||||||
  resolved "https://registry.npmmirror.com/asynckit/-/asynckit-0.4.0.tgz"
 | 
					  resolved "https://registry.npmmirror.com/asynckit/-/asynckit-0.4.0.tgz"
 | 
				
			||||||
  integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==
 | 
					  integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==
 | 
				
			||||||
 | 
					
 | 
				
			||||||
axios@^0.27.2:
 | 
					axios@^1.1.2:
 | 
				
			||||||
  version "0.27.2"
 | 
					  version "1.1.2"
 | 
				
			||||||
  resolved "https://registry.npmmirror.com/axios/-/axios-0.27.2.tgz"
 | 
					  resolved "https://registry.npmmirror.com/axios/-/axios-1.1.2.tgz#8b6f6c540abf44ab98d9904e8daf55351ca4a331"
 | 
				
			||||||
  integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==
 | 
					  integrity sha512-bznQyETwElsXl2RK7HLLwb5GPpOLlycxHCtrpDR/4RqqBzjARaOTo3jz4IgtntWUYee7Ne4S8UHd92VCuzPaWA==
 | 
				
			||||||
  dependencies:
 | 
					  dependencies:
 | 
				
			||||||
    follow-redirects "^1.14.9"
 | 
					    follow-redirects "^1.15.0"
 | 
				
			||||||
    form-data "^4.0.0"
 | 
					    form-data "^4.0.0"
 | 
				
			||||||
 | 
					    proxy-from-env "^1.1.0"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
balanced-match@^1.0.0:
 | 
					balanced-match@^1.0.0:
 | 
				
			||||||
  version "1.0.2"
 | 
					  version "1.0.2"
 | 
				
			||||||
@@ -595,10 +654,10 @@ echarts@^5.3.3:
 | 
				
			|||||||
    tslib "2.3.0"
 | 
					    tslib "2.3.0"
 | 
				
			||||||
    zrender "5.3.2"
 | 
					    zrender "5.3.2"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
element-plus@^2.2.17:
 | 
					element-plus@^2.2.18:
 | 
				
			||||||
  version "2.2.17"
 | 
					  version "2.2.18"
 | 
				
			||||||
  resolved "https://registry.npmmirror.com/element-plus/-/element-plus-2.2.17.tgz"
 | 
					  resolved "https://registry.npmmirror.com/element-plus/-/element-plus-2.2.18.tgz#62b388e05587506d2d40bede0729046f7c41f9d9"
 | 
				
			||||||
  integrity sha512-MGwMIE/q+FFD3kgS23x8HIe5043tmD1cTRwjhIX9o6fim1avFnUkrsfYRvybbz4CkyqSb185EheZS5AUPpXh2g==
 | 
					  integrity sha512-2pK2zmVOwP14eFl3rGoR+3BWJwDyO+DZCvzjQ8L6qjUR+hVKwFhgxIcSkKJatbcHFw5Xui6UyN20jV+gQP7mLg==
 | 
				
			||||||
  dependencies:
 | 
					  dependencies:
 | 
				
			||||||
    "@ctrl/tinycolor" "^3.4.1"
 | 
					    "@ctrl/tinycolor" "^3.4.1"
 | 
				
			||||||
    "@element-plus/icons-vue" "^2.0.6"
 | 
					    "@element-plus/icons-vue" "^2.0.6"
 | 
				
			||||||
@@ -957,10 +1016,10 @@ flatted@^3.1.0:
 | 
				
			|||||||
  resolved "https://registry.npmmirror.com/flatted/download/flatted-3.2.4.tgz"
 | 
					  resolved "https://registry.npmmirror.com/flatted/download/flatted-3.2.4.tgz"
 | 
				
			||||||
  integrity sha512-8/sOawo8tJ4QOBX8YlQBMxL8+RLZfxMQOif9o0KUKTNTjMYElWPE0r/m5VNFxTRd0NSw8qSy8dajrwX4RYI1Hw==
 | 
					  integrity sha512-8/sOawo8tJ4QOBX8YlQBMxL8+RLZfxMQOif9o0KUKTNTjMYElWPE0r/m5VNFxTRd0NSw8qSy8dajrwX4RYI1Hw==
 | 
				
			||||||
 | 
					
 | 
				
			||||||
follow-redirects@^1.14.9:
 | 
					follow-redirects@^1.15.0:
 | 
				
			||||||
  version "1.15.1"
 | 
					  version "1.15.2"
 | 
				
			||||||
  resolved "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.15.1.tgz"
 | 
					  resolved "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
 | 
				
			||||||
  integrity sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==
 | 
					  integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==
 | 
				
			||||||
 | 
					
 | 
				
			||||||
form-data@^4.0.0:
 | 
					form-data@^4.0.0:
 | 
				
			||||||
  version "4.0.0"
 | 
					  version "4.0.0"
 | 
				
			||||||
@@ -1169,12 +1228,12 @@ json-stable-stringify-without-jsonify@^1.0.1:
 | 
				
			|||||||
  resolved "https://registry.nlark.com/json-stable-stringify-without-jsonify/download/json-stable-stringify-without-jsonify-1.0.1.tgz"
 | 
					  resolved "https://registry.nlark.com/json-stable-stringify-without-jsonify/download/json-stable-stringify-without-jsonify-1.0.1.tgz"
 | 
				
			||||||
  integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=
 | 
					  integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=
 | 
				
			||||||
 | 
					
 | 
				
			||||||
jsoneditor@^9.9.0:
 | 
					jsoneditor@^9.9.2:
 | 
				
			||||||
  version "9.9.0"
 | 
					  version "9.9.2"
 | 
				
			||||||
  resolved "https://registry.npmmirror.com/jsoneditor/-/jsoneditor-9.9.0.tgz"
 | 
					  resolved "https://registry.npmmirror.com/jsoneditor/-/jsoneditor-9.9.2.tgz#176112f71acbf37e977aae8656a17bc33a7a4269"
 | 
				
			||||||
  integrity sha512-NHJhyaqcc5U33ah6dEcd0S9b14Auocpe9nydvC9ui7Uq/vjEFnsd7ot6O9Jqwv53B7DmHFUWq5cT4qeWh4MEoA==
 | 
					  integrity sha512-hdM6bgGh3fqnbAEgO1zXM3bNdYfFH/9nPWWJYdNP/wyRU9H+t3Wvb+VtBBE8XjkBYv0rIYjeaYgrwDRaXC3zig==
 | 
				
			||||||
  dependencies:
 | 
					  dependencies:
 | 
				
			||||||
    ace-builds "^1.6.0"
 | 
					    ace-builds "^1.10.1"
 | 
				
			||||||
    ajv "^6.12.6"
 | 
					    ajv "^6.12.6"
 | 
				
			||||||
    javascript-natural-sort "^0.7.1"
 | 
					    javascript-natural-sort "^0.7.1"
 | 
				
			||||||
    jmespath "^0.16.0"
 | 
					    jmespath "^0.16.0"
 | 
				
			||||||
@@ -1417,6 +1476,11 @@ progress@^2.0.0:
 | 
				
			|||||||
  resolved "https://registry.nlark.com/progress/download/progress-2.0.3.tgz"
 | 
					  resolved "https://registry.nlark.com/progress/download/progress-2.0.3.tgz"
 | 
				
			||||||
  integrity sha1-foz42PW48jnBvGi+tOt4Vn1XLvg=
 | 
					  integrity sha1-foz42PW48jnBvGi+tOt4Vn1XLvg=
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					proxy-from-env@^1.1.0:
 | 
				
			||||||
 | 
					  version "1.1.0"
 | 
				
			||||||
 | 
					  resolved "https://registry.npmmirror.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
 | 
				
			||||||
 | 
					  integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==
 | 
				
			||||||
 | 
					
 | 
				
			||||||
punycode@^2.1.0:
 | 
					punycode@^2.1.0:
 | 
				
			||||||
  version "2.1.1"
 | 
					  version "2.1.1"
 | 
				
			||||||
  resolved "https://registry.nlark.com/punycode/download/punycode-2.1.1.tgz"
 | 
					  resolved "https://registry.nlark.com/punycode/download/punycode-2.1.1.tgz"
 | 
				
			||||||
@@ -1712,16 +1776,16 @@ vue-router@^4.1.5:
 | 
				
			|||||||
  dependencies:
 | 
					  dependencies:
 | 
				
			||||||
    "@vue/devtools-api" "^6.1.4"
 | 
					    "@vue/devtools-api" "^6.1.4"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
vue@^3.2.39:
 | 
					vue@^3.2.41:
 | 
				
			||||||
  version "3.2.39"
 | 
					  version "3.2.41"
 | 
				
			||||||
  resolved "https://registry.npmmirror.com/vue/-/vue-3.2.39.tgz"
 | 
					  resolved "https://registry.npmmirror.com/vue/-/vue-3.2.41.tgz#ed452b8a0f7f2b962f055c8955139c28b1c06806"
 | 
				
			||||||
  integrity sha512-tRkguhRTw9NmIPXhzk21YFBqXHT2t+6C6wPOgQ50fcFVWnPdetmRqbmySRHznrYjX2E47u0cGlKGcxKZJ38R/g==
 | 
					  integrity sha512-uuuvnrDXEeZ9VUPljgHkqB5IaVO8SxhPpqF2eWOukVrBnRBx2THPSGQBnVRt0GrIG1gvCmFXMGbd7FqcT1ixNQ==
 | 
				
			||||||
  dependencies:
 | 
					  dependencies:
 | 
				
			||||||
    "@vue/compiler-dom" "3.2.39"
 | 
					    "@vue/compiler-dom" "3.2.41"
 | 
				
			||||||
    "@vue/compiler-sfc" "3.2.39"
 | 
					    "@vue/compiler-sfc" "3.2.41"
 | 
				
			||||||
    "@vue/runtime-dom" "3.2.39"
 | 
					    "@vue/runtime-dom" "3.2.41"
 | 
				
			||||||
    "@vue/server-renderer" "3.2.39"
 | 
					    "@vue/server-renderer" "3.2.41"
 | 
				
			||||||
    "@vue/shared" "3.2.39"
 | 
					    "@vue/shared" "3.2.41"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
vuex@^4.0.2:
 | 
					vuex@^4.0.2:
 | 
				
			||||||
  version "4.0.2"
 | 
					  version "4.0.2"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,11 +15,11 @@ require (
 | 
				
			|||||||
	github.com/sirupsen/logrus v1.9.0
 | 
						github.com/sirupsen/logrus v1.9.0
 | 
				
			||||||
	github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
 | 
						github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
 | 
				
			||||||
	go.mongodb.org/mongo-driver v1.9.1 // mongo
 | 
						go.mongodb.org/mongo-driver v1.9.1 // mongo
 | 
				
			||||||
	golang.org/x/crypto v0.0.0-20220924013350-4ba4fb4dd9e7 // ssh
 | 
						golang.org/x/crypto v0.1.0 // ssh
 | 
				
			||||||
	gopkg.in/yaml.v3 v3.0.1
 | 
						gopkg.in/yaml.v3 v3.0.1
 | 
				
			||||||
	// gorm
 | 
						// gorm
 | 
				
			||||||
	gorm.io/driver/mysql v1.3.6
 | 
						gorm.io/driver/mysql v1.4.1
 | 
				
			||||||
	gorm.io/gorm v1.23.10
 | 
						gorm.io/gorm v1.24.0
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
@@ -50,10 +50,10 @@ require (
 | 
				
			|||||||
	github.com/xdg-go/stringprep v1.0.2 // indirect
 | 
						github.com/xdg-go/stringprep v1.0.2 // indirect
 | 
				
			||||||
	github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
 | 
						github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
 | 
				
			||||||
	golang.org/x/image v0.0.0-20220302094943-723b81ca9867 // indirect
 | 
						golang.org/x/image v0.0.0-20220302094943-723b81ca9867 // indirect
 | 
				
			||||||
	golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
 | 
						golang.org/x/net v0.1.0 // indirect
 | 
				
			||||||
	golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 // indirect
 | 
						golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 // indirect
 | 
				
			||||||
	golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
 | 
						golang.org/x/sys v0.1.0 // indirect
 | 
				
			||||||
	golang.org/x/text v0.3.7 // indirect
 | 
						golang.org/x/text v0.4.0 // indirect
 | 
				
			||||||
	golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
 | 
						golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
 | 
				
			||||||
	google.golang.org/protobuf v1.28.0 // indirect
 | 
						google.golang.org/protobuf v1.28.0 // indirect
 | 
				
			||||||
	gopkg.in/yaml.v2 v2.4.0 // indirect
 | 
						gopkg.in/yaml.v2 v2.4.0 // indirect
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,9 +7,9 @@ import (
 | 
				
			|||||||
	db_router "mayfly-go/internal/db/router"
 | 
						db_router "mayfly-go/internal/db/router"
 | 
				
			||||||
	machine_router "mayfly-go/internal/machine/router"
 | 
						machine_router "mayfly-go/internal/machine/router"
 | 
				
			||||||
	mongo_router "mayfly-go/internal/mongo/router"
 | 
						mongo_router "mayfly-go/internal/mongo/router"
 | 
				
			||||||
	project_router "mayfly-go/internal/project/router"
 | 
					 | 
				
			||||||
	redis_router "mayfly-go/internal/redis/router"
 | 
						redis_router "mayfly-go/internal/redis/router"
 | 
				
			||||||
	sys_router "mayfly-go/internal/sys/router"
 | 
						sys_router "mayfly-go/internal/sys/router"
 | 
				
			||||||
 | 
						tag_router "mayfly-go/internal/tag/router"
 | 
				
			||||||
	"mayfly-go/pkg/config"
 | 
						"mayfly-go/pkg/config"
 | 
				
			||||||
	"mayfly-go/pkg/middleware"
 | 
						"mayfly-go/pkg/middleware"
 | 
				
			||||||
	"mayfly-go/static"
 | 
						"mayfly-go/static"
 | 
				
			||||||
@@ -74,7 +74,8 @@ func InitRouter() *gin.Engine {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		sys_router.Init(api)
 | 
							sys_router.Init(api)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		project_router.Init(api)
 | 
							// project_router.Init(api)
 | 
				
			||||||
 | 
							tag_router.Init(api)
 | 
				
			||||||
		machine_router.Init(api)
 | 
							machine_router.Init(api)
 | 
				
			||||||
		db_router.Init(api)
 | 
							db_router.Init(api)
 | 
				
			||||||
		redis_router.Init(api)
 | 
							redis_router.Init(api)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,28 +3,43 @@ package api
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	dbapp "mayfly-go/internal/db/application"
 | 
						dbapp "mayfly-go/internal/db/application"
 | 
				
			||||||
	dbentity "mayfly-go/internal/db/domain/entity"
 | 
						dbentity "mayfly-go/internal/db/domain/entity"
 | 
				
			||||||
	machineentity "mayfly-go/internal/machine/domain/entity"
 | 
					 | 
				
			||||||
	projectentity "mayfly-go/internal/project/domain/entity"
 | 
					 | 
				
			||||||
	redisentity "mayfly-go/internal/redis/domain/entity"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	machineapp "mayfly-go/internal/machine/application"
 | 
						machineapp "mayfly-go/internal/machine/application"
 | 
				
			||||||
	projectapp "mayfly-go/internal/project/application"
 | 
						machineentity "mayfly-go/internal/machine/domain/entity"
 | 
				
			||||||
 | 
						mongoapp "mayfly-go/internal/mongo/application"
 | 
				
			||||||
 | 
						mongoentity "mayfly-go/internal/mongo/domain/entity"
 | 
				
			||||||
	redisapp "mayfly-go/internal/redis/application"
 | 
						redisapp "mayfly-go/internal/redis/application"
 | 
				
			||||||
 | 
						redisentity "mayfly-go/internal/redis/domain/entity"
 | 
				
			||||||
 | 
						tagapp "mayfly-go/internal/tag/application"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Index struct {
 | 
					type Index struct {
 | 
				
			||||||
	ProjectApp projectapp.Project
 | 
						TagApp     tagapp.TagTree
 | 
				
			||||||
	MachineApp machineapp.Machine
 | 
						MachineApp machineapp.Machine
 | 
				
			||||||
	DbApp      dbapp.Db
 | 
						DbApp      dbapp.Db
 | 
				
			||||||
	RedisApp   redisapp.Redis
 | 
						RedisApp   redisapp.Redis
 | 
				
			||||||
 | 
						MongoApp   mongoapp.Mongo
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (i *Index) Count(rc *ctx.ReqCtx) {
 | 
					func (i *Index) Count(rc *ctx.ReqCtx) {
 | 
				
			||||||
 | 
						accountId := rc.LoginAccount.Id
 | 
				
			||||||
 | 
						tagIds := i.TagApp.ListTagIdByAccountId(accountId)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var mongoNum int64
 | 
				
			||||||
 | 
						var redisNum int64
 | 
				
			||||||
 | 
						var dbNum int64
 | 
				
			||||||
 | 
						var machienNum int64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(tagIds) > 0 {
 | 
				
			||||||
 | 
							mongoNum = i.MongoApp.Count(&mongoentity.MongoQuery{TagIds: tagIds})
 | 
				
			||||||
 | 
							machienNum = i.MachineApp.Count(&machineentity.MachineQuery{TagIds: tagIds})
 | 
				
			||||||
 | 
							dbNum = i.DbApp.Count(&dbentity.DbQuery{TagIds: tagIds})
 | 
				
			||||||
 | 
							redisNum = i.RedisApp.Count(&redisentity.RedisQuery{TagIds: tagIds})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	rc.ResData = map[string]interface{}{
 | 
						rc.ResData = map[string]interface{}{
 | 
				
			||||||
		"projectNum": i.ProjectApp.Count(new(projectentity.Project)),
 | 
							"mongoNum":   mongoNum,
 | 
				
			||||||
		"machineNum": i.MachineApp.Count(new(machineentity.Machine)),
 | 
							"machineNum": machienNum,
 | 
				
			||||||
		"dbNum":      i.DbApp.Count(new(dbentity.Db)),
 | 
							"dbNum":      dbNum,
 | 
				
			||||||
		"redisNum":   i.RedisApp.Count(new(redisentity.Redis)),
 | 
							"redisNum":   redisNum,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,8 +4,9 @@ import (
 | 
				
			|||||||
	"mayfly-go/internal/common/api"
 | 
						"mayfly-go/internal/common/api"
 | 
				
			||||||
	dbapp "mayfly-go/internal/db/application"
 | 
						dbapp "mayfly-go/internal/db/application"
 | 
				
			||||||
	machineapp "mayfly-go/internal/machine/application"
 | 
						machineapp "mayfly-go/internal/machine/application"
 | 
				
			||||||
	projectapp "mayfly-go/internal/project/application"
 | 
						mongoapp "mayfly-go/internal/mongo/application"
 | 
				
			||||||
	redisapp "mayfly-go/internal/redis/application"
 | 
						redisapp "mayfly-go/internal/redis/application"
 | 
				
			||||||
 | 
						tagapp "mayfly-go/internal/tag/application"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
@@ -14,10 +15,11 @@ import (
 | 
				
			|||||||
func InitIndexRouter(router *gin.RouterGroup) {
 | 
					func InitIndexRouter(router *gin.RouterGroup) {
 | 
				
			||||||
	index := router.Group("common/index")
 | 
						index := router.Group("common/index")
 | 
				
			||||||
	i := &api.Index{
 | 
						i := &api.Index{
 | 
				
			||||||
		ProjectApp: projectapp.GetProjectApp(),
 | 
							TagApp:     tagapp.GetTagTreeApp(),
 | 
				
			||||||
		MachineApp: machineapp.GetMachineApp(),
 | 
							MachineApp: machineapp.GetMachineApp(),
 | 
				
			||||||
		DbApp:      dbapp.GetDbApp(),
 | 
							DbApp:      dbapp.GetDbApp(),
 | 
				
			||||||
		RedisApp:   redisapp.GetRedisApp(),
 | 
							RedisApp:   redisapp.GetRedisApp(),
 | 
				
			||||||
 | 
							MongoApp:   mongoapp.GetMongoApp(),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		// 首页基本信息统计
 | 
							// 首页基本信息统计
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,8 +7,8 @@ import (
 | 
				
			|||||||
	"mayfly-go/internal/db/api/vo"
 | 
						"mayfly-go/internal/db/api/vo"
 | 
				
			||||||
	"mayfly-go/internal/db/application"
 | 
						"mayfly-go/internal/db/application"
 | 
				
			||||||
	"mayfly-go/internal/db/domain/entity"
 | 
						"mayfly-go/internal/db/domain/entity"
 | 
				
			||||||
	projectapp "mayfly-go/internal/project/application"
 | 
					 | 
				
			||||||
	sysapp "mayfly-go/internal/sys/application"
 | 
						sysapp "mayfly-go/internal/sys/application"
 | 
				
			||||||
 | 
						tagapp "mayfly-go/internal/tag/application"
 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
	"mayfly-go/pkg/ginx"
 | 
						"mayfly-go/pkg/ginx"
 | 
				
			||||||
@@ -27,19 +27,24 @@ type Db struct {
 | 
				
			|||||||
	DbApp        application.Db
 | 
						DbApp        application.Db
 | 
				
			||||||
	DbSqlExecApp application.DbSqlExec
 | 
						DbSqlExecApp application.DbSqlExec
 | 
				
			||||||
	MsgApp       sysapp.Msg
 | 
						MsgApp       sysapp.Msg
 | 
				
			||||||
	ProjectApp   projectapp.Project
 | 
						TagApp       tagapp.TagTree
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const DEFAULT_COLUMN_SIZE = 500
 | 
					const DEFAULT_ROW_SIZE = 1800
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// @router /api/dbs [get]
 | 
					// @router /api/dbs [get]
 | 
				
			||||||
func (d *Db) Dbs(rc *ctx.ReqCtx) {
 | 
					func (d *Db) Dbs(rc *ctx.ReqCtx) {
 | 
				
			||||||
	g := rc.GinCtx
 | 
						condition := new(entity.DbQuery)
 | 
				
			||||||
	m := &entity.Db{EnvId: uint64(ginx.QueryInt(g, "envId", 0)),
 | 
						condition.TagPathLike = rc.GinCtx.Query("tagPath")
 | 
				
			||||||
		ProjectId: uint64(ginx.QueryInt(g, "projectId", 0)),
 | 
					
 | 
				
			||||||
 | 
						// 不存在可访问标签id,即没有可操作数据
 | 
				
			||||||
 | 
						tagIds := d.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
 | 
				
			||||||
 | 
						if len(tagIds) == 0 {
 | 
				
			||||||
 | 
							rc.ResData = model.EmptyPageResult()
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	m.CreatorId = rc.LoginAccount.Id
 | 
						condition.TagIds = tagIds
 | 
				
			||||||
	rc.ResData = d.DbApp.GetPageList(m, ginx.GetPageParam(rc.GinCtx), new([]vo.SelectDataDbVO))
 | 
						rc.ResData = d.DbApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]vo.SelectDataDbVO))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *Db) Save(rc *ctx.ReqCtx) {
 | 
					func (d *Db) Save(rc *ctx.ReqCtx) {
 | 
				
			||||||
@@ -121,7 +126,7 @@ func (d *Db) ExecSql(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	id := GetDbId(g)
 | 
						id := GetDbId(g)
 | 
				
			||||||
	db := form.Db
 | 
						db := form.Db
 | 
				
			||||||
	dbInstance := d.DbApp.GetDbInstance(id, db)
 | 
						dbInstance := d.DbApp.GetDbInstance(id, db)
 | 
				
			||||||
	biz.ErrIsNilAppendErr(d.ProjectApp.CanAccess(rc.LoginAccount.Id, dbInstance.ProjectId), "%s")
 | 
						biz.ErrIsNilAppendErr(d.TagApp.CanAccess(rc.LoginAccount.Id, dbInstance.TagPath), "%s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 去除前后空格及换行符
 | 
						// 去除前后空格及换行符
 | 
				
			||||||
	sql := strings.TrimFunc(form.Sql, func(r rune) bool {
 | 
						sql := strings.TrimFunc(form.Sql, func(r rune) bool {
 | 
				
			||||||
@@ -163,7 +168,7 @@ func (d *Db) ExecSqlFile(rc *ctx.ReqCtx) {
 | 
				
			|||||||
		db := d.DbApp.GetDbInstance(dbId, db)
 | 
							db := d.DbApp.GetDbInstance(dbId, db)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		dbEntity := d.DbApp.GetById(dbId)
 | 
							dbEntity := d.DbApp.GetById(dbId)
 | 
				
			||||||
		dbInfo := fmt.Sprintf("于%s的%s环境", dbEntity.Name, dbEntity.Env)
 | 
							dbInfo := fmt.Sprintf("于%s的%s环境", dbEntity.Name, dbEntity.TagPath)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		defer func() {
 | 
							defer func() {
 | 
				
			||||||
			if err := recover(); err != nil {
 | 
								if err := recover(); err != nil {
 | 
				
			||||||
@@ -174,7 +179,7 @@ func (d *Db) ExecSqlFile(rc *ctx.ReqCtx) {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}()
 | 
							}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		biz.ErrIsNilAppendErr(d.ProjectApp.CanAccess(rc.LoginAccount.Id, db.ProjectId), "%s")
 | 
							biz.ErrIsNilAppendErr(d.TagApp.CanAccess(rc.LoginAccount.Id, db.TagPath), "%s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		tokens := sqlparser.NewTokenizer(file)
 | 
							tokens := sqlparser.NewTokenizer(file)
 | 
				
			||||||
		for {
 | 
							for {
 | 
				
			||||||
@@ -208,7 +213,7 @@ func (d *Db) DumpSql(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	needData := dumpType == "2" || dumpType == "3"
 | 
						needData := dumpType == "2" || dumpType == "3"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dbInstance := d.DbApp.GetDbInstance(dbId, db)
 | 
						dbInstance := d.DbApp.GetDbInstance(dbId, db)
 | 
				
			||||||
	biz.ErrIsNilAppendErr(d.ProjectApp.CanAccess(rc.LoginAccount.Id, dbInstance.ProjectId), "%s")
 | 
						biz.ErrIsNilAppendErr(d.TagApp.CanAccess(rc.LoginAccount.Id, dbInstance.TagPath), "%s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	now := time.Now()
 | 
						now := time.Now()
 | 
				
			||||||
	filename := fmt.Sprintf("%s.%s.sql", db, now.Format("200601021504"))
 | 
						filename := fmt.Sprintf("%s.%s.sql", db, now.Format("200601021504"))
 | 
				
			||||||
@@ -248,8 +253,8 @@ func (d *Db) DumpSql(rc *ctx.ReqCtx) {
 | 
				
			|||||||
			maCount = countRes[0]["count"].(int)
 | 
								maCount = countRes[0]["count"].(int)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		// 计算需要查询的页数
 | 
							// 计算需要查询的页数
 | 
				
			||||||
		pageNum := maCount / DEFAULT_COLUMN_SIZE
 | 
							pageNum := maCount / DEFAULT_ROW_SIZE
 | 
				
			||||||
		if maCount%DEFAULT_COLUMN_SIZE > 0 {
 | 
							if maCount%DEFAULT_ROW_SIZE > 0 {
 | 
				
			||||||
			pageNum++
 | 
								pageNum++
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -261,7 +266,7 @@ func (d *Db) DumpSql(rc *ctx.ReqCtx) {
 | 
				
			|||||||
			sqlTmp = "SELECT * FROM %s OFFSET %d LIMIT %d"
 | 
								sqlTmp = "SELECT * FROM %s OFFSET %d LIMIT %d"
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		for index := 0; index < pageNum; index++ {
 | 
							for index := 0; index < pageNum; index++ {
 | 
				
			||||||
			sql := fmt.Sprintf(sqlTmp, table, index*DEFAULT_COLUMN_SIZE, DEFAULT_COLUMN_SIZE)
 | 
								sql := fmt.Sprintf(sqlTmp, table, index*DEFAULT_ROW_SIZE, DEFAULT_ROW_SIZE)
 | 
				
			||||||
			columns, result, _ := dbInstance.SelectData(sql)
 | 
								columns, result, _ := dbInstance.SelectData(sql)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			insertSql := "INSERT INTO `%s` VALUES (%s);\n"
 | 
								insertSql := "INSERT INTO `%s` VALUES (%s);\n"
 | 
				
			||||||
@@ -294,7 +299,7 @@ func (d *Db) DumpSql(rc *ctx.ReqCtx) {
 | 
				
			|||||||
// @router /api/db/:dbId/t-metadata [get]
 | 
					// @router /api/db/:dbId/t-metadata [get]
 | 
				
			||||||
func (d *Db) TableMA(rc *ctx.ReqCtx) {
 | 
					func (d *Db) TableMA(rc *ctx.ReqCtx) {
 | 
				
			||||||
	dbi := d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx))
 | 
						dbi := d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx))
 | 
				
			||||||
	biz.ErrIsNilAppendErr(d.ProjectApp.CanAccess(rc.LoginAccount.Id, dbi.ProjectId), "%s")
 | 
						biz.ErrIsNilAppendErr(d.TagApp.CanAccess(rc.LoginAccount.Id, dbi.TagPath), "%s")
 | 
				
			||||||
	rc.ResData = dbi.GetMeta().GetTables()
 | 
						rc.ResData = dbi.GetMeta().GetTables()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -305,14 +310,14 @@ func (d *Db) ColumnMA(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	biz.NotEmpty(tn, "tableName不能为空")
 | 
						biz.NotEmpty(tn, "tableName不能为空")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dbi := d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx))
 | 
						dbi := d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx))
 | 
				
			||||||
	biz.ErrIsNilAppendErr(d.ProjectApp.CanAccess(rc.LoginAccount.Id, dbi.ProjectId), "%s")
 | 
						// biz.ErrIsNilAppendErr(d.TagApp.CanAccess(rc.LoginAccount.Id, dbInstance.TagPath), "%s")
 | 
				
			||||||
	rc.ResData = dbi.GetMeta().GetColumns(tn)
 | 
						rc.ResData = dbi.GetMeta().GetColumns(tn)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// @router /api/db/:dbId/hint-tables [get]
 | 
					// @router /api/db/:dbId/hint-tables [get]
 | 
				
			||||||
func (d *Db) HintTables(rc *ctx.ReqCtx) {
 | 
					func (d *Db) HintTables(rc *ctx.ReqCtx) {
 | 
				
			||||||
	dbi := d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx))
 | 
						dbi := d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx))
 | 
				
			||||||
	biz.ErrIsNilAppendErr(d.ProjectApp.CanAccess(rc.LoginAccount.Id, dbi.ProjectId), "%s")
 | 
						// biz.ErrIsNilAppendErr(d.TagApp.CanAccess(rc.LoginAccount.Id, dbInstance.TagPath), "%s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dm := dbi.GetMeta()
 | 
						dm := dbi.GetMeta()
 | 
				
			||||||
	// 获取所有表
 | 
						// 获取所有表
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,19 +1,18 @@
 | 
				
			|||||||
package form
 | 
					package form
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type DbForm struct {
 | 
					type DbForm struct {
 | 
				
			||||||
	Id        uint64
 | 
						Id       uint64
 | 
				
			||||||
	Name      string `binding:"required" json:"name"`
 | 
						Name     string `binding:"required" json:"name"`
 | 
				
			||||||
	Type      string `binding:"required" json:"type"` // 类型,mysql oracle等
 | 
						Type     string `binding:"required" json:"type"` // 类型,mysql oracle等
 | 
				
			||||||
	Host      string `binding:"required" json:"host"`
 | 
						Host     string `binding:"required" json:"host"`
 | 
				
			||||||
	Port      int    `binding:"required" json:"port"`
 | 
						Port     int    `binding:"required" json:"port"`
 | 
				
			||||||
	Username  string `binding:"required" json:"username"`
 | 
						Username string `binding:"required" json:"username"`
 | 
				
			||||||
	Password  string `json:"password"`
 | 
						Password string `json:"password"`
 | 
				
			||||||
	Params    string `json:"params"`
 | 
						Params   string `json:"params"`
 | 
				
			||||||
	Database  string `json:"database"`
 | 
						Database string `json:"database"`
 | 
				
			||||||
	ProjectId uint64 `binding:"required" json:"projectId"`
 | 
						Remark   string `json:"remark"`
 | 
				
			||||||
	Project   string `json:"project"`
 | 
						TagId    uint64 `json:"tagId"`
 | 
				
			||||||
	Env       string `json:"env"`
 | 
						TagPath  string `json:"tagPath"`
 | 
				
			||||||
	EnvId     uint64 `binding:"required" json:"envId"`
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	EnableSshTunnel    int8   `json:"enableSshTunnel"`
 | 
						EnableSshTunnel    int8   `json:"enableSshTunnel"`
 | 
				
			||||||
	SshTunnelMachineId uint64 `json:"sshTunnelMachineId"`
 | 
						SshTunnelMachineId uint64 `json:"sshTunnelMachineId"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,10 +12,9 @@ type SelectDataDbVO struct {
 | 
				
			|||||||
	Params     *string    `json:"params"`
 | 
						Params     *string    `json:"params"`
 | 
				
			||||||
	Database   *string    `json:"database"`
 | 
						Database   *string    `json:"database"`
 | 
				
			||||||
	Username   *string    `json:"username"`
 | 
						Username   *string    `json:"username"`
 | 
				
			||||||
	ProjectId  *int64     `json:"projectId"`
 | 
						Remark     *string    `json:"remark"`
 | 
				
			||||||
	Project    *string    `json:"project"`
 | 
						TagId      *int64     `json:"tagId"`
 | 
				
			||||||
	Env        *string    `json:"env"`
 | 
						TagPath    *string    `json:"tagPath"`
 | 
				
			||||||
	EnvId      *int64     `json:"envId"`
 | 
					 | 
				
			||||||
	CreateTime *time.Time `json:"createTime"`
 | 
						CreateTime *time.Time `json:"createTime"`
 | 
				
			||||||
	Creator    *string    `json:"creator"`
 | 
						Creator    *string    `json:"creator"`
 | 
				
			||||||
	CreatorId  *int64     `json:"creatorId"`
 | 
						CreatorId  *int64     `json:"creatorId"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,9 +27,9 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type Db interface {
 | 
					type Db interface {
 | 
				
			||||||
	// 分页获取
 | 
						// 分页获取
 | 
				
			||||||
	GetPageList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
						GetPageList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Count(condition *entity.Db) int64
 | 
						Count(condition *entity.DbQuery) int64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 根据条件获取
 | 
						// 根据条件获取
 | 
				
			||||||
	GetDbBy(condition *entity.Db, cols ...string) error
 | 
						GetDbBy(condition *entity.Db, cols ...string) error
 | 
				
			||||||
@@ -64,11 +64,11 @@ type dbAppImpl struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 分页获取数据库信息列表
 | 
					// 分页获取数据库信息列表
 | 
				
			||||||
func (d *dbAppImpl) GetPageList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					func (d *dbAppImpl) GetPageList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
				
			||||||
	return d.dbRepo.GetDbList(condition, pageParam, toEntity, orderBy...)
 | 
						return d.dbRepo.GetDbList(condition, pageParam, toEntity, orderBy...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *dbAppImpl) Count(condition *entity.Db) int64 {
 | 
					func (d *dbAppImpl) Count(condition *entity.DbQuery) int64 {
 | 
				
			||||||
	return d.dbRepo.Count(condition)
 | 
						return d.dbRepo.Count(condition)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -92,7 +92,7 @@ func (d *dbAppImpl) Save(dbEntity *entity.Db) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 查找是否存在该库
 | 
						// 查找是否存在该库
 | 
				
			||||||
	oldDb := &entity.Db{Host: dbEntity.Host, Port: dbEntity.Port, EnvId: dbEntity.EnvId}
 | 
						oldDb := &entity.Db{Host: dbEntity.Host, Port: dbEntity.Port, TagId: dbEntity.TagId}
 | 
				
			||||||
	err := d.GetDbBy(oldDb)
 | 
						err := d.GetDbBy(oldDb)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if dbEntity.Id == 0 {
 | 
						if dbEntity.Id == 0 {
 | 
				
			||||||
@@ -165,7 +165,7 @@ func (d *dbAppImpl) GetDatabases(ed *entity.Db) []string {
 | 
				
			|||||||
	biz.ErrIsNilAppendErr(err, "数据库连接失败: %s")
 | 
						biz.ErrIsNilAppendErr(err, "数据库连接失败: %s")
 | 
				
			||||||
	defer dbConn.Close()
 | 
						defer dbConn.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_, res, err := SelectDataByDb(dbConn, getDatabasesSql)
 | 
						_, res, err := SelectDataByDb(dbConn, getDatabasesSql, true)
 | 
				
			||||||
	biz.ErrIsNilAppendErr(err, "获取数据库列表失败")
 | 
						biz.ErrIsNilAppendErr(err, "获取数据库列表失败")
 | 
				
			||||||
	for _, re := range res {
 | 
						for _, re := range res {
 | 
				
			||||||
		databases = append(databases, re["dbname"].(string))
 | 
							databases = append(databases, re["dbname"].(string))
 | 
				
			||||||
@@ -194,7 +194,7 @@ func (da *dbAppImpl) GetDbInstance(id uint64, db string) *DbInstance {
 | 
				
			|||||||
	biz.IsTrue(strings.Contains(d.Database, db), "未配置该库的操作权限")
 | 
						biz.IsTrue(strings.Contains(d.Database, db), "未配置该库的操作权限")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cacheKey := GetDbCacheKey(id, db)
 | 
						cacheKey := GetDbCacheKey(id, db)
 | 
				
			||||||
	dbi := &DbInstance{Id: cacheKey, Type: d.Type, ProjectId: d.ProjectId, sshTunnelMachineId: d.SshTunnelMachineId}
 | 
						dbi := &DbInstance{Id: cacheKey, Type: d.Type, TagPath: d.TagPath, sshTunnelMachineId: d.SshTunnelMachineId}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DB, err := GetDbConn(d, db)
 | 
						DB, err := GetDbConn(d, db)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@@ -206,7 +206,7 @@ func (da *dbAppImpl) GetDbInstance(id uint64, db string) *DbInstance {
 | 
				
			|||||||
	// 最大连接周期,超过时间的连接就close
 | 
						// 最大连接周期,超过时间的连接就close
 | 
				
			||||||
	// DB.SetConnMaxLifetime(100 * time.Second)
 | 
						// DB.SetConnMaxLifetime(100 * time.Second)
 | 
				
			||||||
	// 设置最大连接数
 | 
						// 设置最大连接数
 | 
				
			||||||
	DB.SetMaxOpenConns(2)
 | 
						DB.SetMaxOpenConns(5)
 | 
				
			||||||
	// 设置闲置连接数
 | 
						// 设置闲置连接数
 | 
				
			||||||
	DB.SetMaxIdleConns(1)
 | 
						DB.SetMaxIdleConns(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -218,6 +218,67 @@ func (da *dbAppImpl) GetDbInstance(id uint64, db string) *DbInstance {
 | 
				
			|||||||
	return dbi
 | 
						return dbi
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//----------------------------------------  db instance  ------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// db实例
 | 
				
			||||||
 | 
					type DbInstance struct {
 | 
				
			||||||
 | 
						Id                 string
 | 
				
			||||||
 | 
						Type               string
 | 
				
			||||||
 | 
						TagPath            string
 | 
				
			||||||
 | 
						db                 *sql.DB
 | 
				
			||||||
 | 
						sshTunnelMachineId uint64
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 执行查询语句
 | 
				
			||||||
 | 
					// 依次返回 列名数组,结果map,错误
 | 
				
			||||||
 | 
					func (d *DbInstance) SelectData(execSql string) ([]string, []map[string]interface{}, error) {
 | 
				
			||||||
 | 
						return SelectDataByDb(d.db, execSql, false)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 将查询结果映射至struct,可具体参考sqlx库
 | 
				
			||||||
 | 
					func (d *DbInstance) SelectData2Struct(execSql string, dest interface{}) error {
 | 
				
			||||||
 | 
						return Select2StructByDb(d.db, execSql, dest)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 执行内部查询语句,不返回列名以及不限制行数
 | 
				
			||||||
 | 
					// 依次返回 结果map,错误
 | 
				
			||||||
 | 
					func (d *DbInstance) innerSelect(execSql string) ([]map[string]interface{}, error) {
 | 
				
			||||||
 | 
						_, res, err := SelectDataByDb(d.db, execSql, true)
 | 
				
			||||||
 | 
						return res, err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 执行 update, insert, delete,建表等sql
 | 
				
			||||||
 | 
					// 返回影响条数和错误
 | 
				
			||||||
 | 
					func (d *DbInstance) Exec(sql string) (int64, error) {
 | 
				
			||||||
 | 
						res, err := d.db.Exec(sql)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return 0, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return res.RowsAffected()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取数据库元信息实现接口
 | 
				
			||||||
 | 
					func (di *DbInstance) GetMeta() DbMetadata {
 | 
				
			||||||
 | 
						dbType := di.Type
 | 
				
			||||||
 | 
						if dbType == entity.DbTypeMysql {
 | 
				
			||||||
 | 
							return &MysqlMetadata{di: di}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if dbType == entity.DbTypePostgres {
 | 
				
			||||||
 | 
							return &PgsqlMetadata{di: di}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 关闭连接
 | 
				
			||||||
 | 
					func (d *DbInstance) Close() {
 | 
				
			||||||
 | 
						if d.db != nil {
 | 
				
			||||||
 | 
							if err := d.db.Close(); err != nil {
 | 
				
			||||||
 | 
								global.Log.Errorf("关闭数据库实例[%s]连接失败: %s", d.Id, err.Error())
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							d.db = nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//------------------------------------------------------------------------------
 | 
					//------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 单次最大查询数据集
 | 
					// 单次最大查询数据集
 | 
				
			||||||
@@ -292,7 +353,28 @@ func GetDbConn(d *entity.Db, db string) (*sql.DB, error) {
 | 
				
			|||||||
	return DB, nil
 | 
						return DB, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func SelectDataByDb(db *sql.DB, selectSql string) ([]string, []map[string]interface{}, error) {
 | 
					// 获取dataSourceName
 | 
				
			||||||
 | 
					func getDsn(d *entity.Db, db string) string {
 | 
				
			||||||
 | 
						var dsn string
 | 
				
			||||||
 | 
						if d.Type == entity.DbTypeMysql {
 | 
				
			||||||
 | 
							dsn = fmt.Sprintf("%s:%s@%s(%s:%d)/%s?timeout=8s", d.Username, d.Password, d.Network, d.Host, d.Port, db)
 | 
				
			||||||
 | 
							if d.Params != "" {
 | 
				
			||||||
 | 
								dsn = fmt.Sprintf("%s&%s", dsn, d.Params)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return dsn
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if d.Type == entity.DbTypePostgres {
 | 
				
			||||||
 | 
							dsn = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", d.Host, d.Port, d.Username, d.Password, db)
 | 
				
			||||||
 | 
							if d.Params != "" {
 | 
				
			||||||
 | 
								dsn = fmt.Sprintf("%s %s", dsn, strings.Join(strings.Split(d.Params, "&"), " "))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return dsn
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return ""
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func SelectDataByDb(db *sql.DB, selectSql string, isInner bool) ([]string, []map[string]interface{}, error) {
 | 
				
			||||||
	rows, err := db.Query(selectSql)
 | 
						rows, err := db.Query(selectSql)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, nil, err
 | 
							return nil, nil, err
 | 
				
			||||||
@@ -322,7 +404,10 @@ func SelectDataByDb(db *sql.DB, selectSql string) ([]string, []map[string]interf
 | 
				
			|||||||
	rowNum := 0
 | 
						rowNum := 0
 | 
				
			||||||
	for rows.Next() {
 | 
						for rows.Next() {
 | 
				
			||||||
		rowNum++
 | 
							rowNum++
 | 
				
			||||||
		biz.IsTrue(rowNum <= Max_Rows, "结果集 > 2000, 请完善条件或分页信息")
 | 
							// 非内部sql,则校验返回结果数量
 | 
				
			||||||
 | 
							if !isInner {
 | 
				
			||||||
 | 
								biz.IsTrue(rowNum <= Max_Rows, "结果集 > 2000, 请完善条件或分页信息")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 不Scan也会导致等待,该链接实际处于未工作的状态,然后也会导致连接数迅速达到最大
 | 
							// 不Scan也会导致等待,该链接实际处于未工作的状态,然后也会导致连接数迅速达到最大
 | 
				
			||||||
		err := rows.Scan(scans...)
 | 
							err := rows.Scan(scans...)
 | 
				
			||||||
@@ -397,6 +482,27 @@ func valueConvert(data []byte, colType *sql.ColumnType) interface{} {
 | 
				
			|||||||
	return stringV
 | 
						return stringV
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 查询数据结果映射至struct。可参考sqlx库
 | 
				
			||||||
 | 
					func Select2StructByDb(db *sql.DB, selectSql string, dest interface{}) error {
 | 
				
			||||||
 | 
						rows, err := db.Query(selectSql)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						// rows对象一定要close掉,如果出错,不关掉则会很迅速的达到设置最大连接数,
 | 
				
			||||||
 | 
						// 后面的链接过来直接报错或拒绝,实际上也没有起效果
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							if rows != nil {
 | 
				
			||||||
 | 
								rows.Close()
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
						return scanAll(rows, dest, false)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 删除db缓存并关闭该数据库所有连接
 | 
				
			||||||
 | 
					func CloseDb(dbId uint64, db string) {
 | 
				
			||||||
 | 
						dbCache.Delete(GetDbCacheKey(dbId, db))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type PqSqlDialer struct {
 | 
					type PqSqlDialer struct {
 | 
				
			||||||
	sshTunnelMachine *machine.SshTunnelMachine
 | 
						sshTunnelMachine *machine.SshTunnelMachine
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -409,324 +515,7 @@ func (pd *PqSqlDialer) Dial(network, address string) (net.Conn, error) {
 | 
				
			|||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (pd *PqSqlDialer) DialTimeout(network, address string, timeout time.Duration) (net.Conn, error) {
 | 
					func (pd *PqSqlDialer) DialTimeout(network, address string, timeout time.Duration) (net.Conn, error) {
 | 
				
			||||||
	return pd.Dial(network, address)
 | 
						return pd.Dial(network, address)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
// db实例
 | 
					 | 
				
			||||||
type DbInstance struct {
 | 
					 | 
				
			||||||
	Id                 string
 | 
					 | 
				
			||||||
	Type               string
 | 
					 | 
				
			||||||
	ProjectId          uint64
 | 
					 | 
				
			||||||
	db                 *sql.DB
 | 
					 | 
				
			||||||
	sshTunnelMachineId uint64
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 执行查询语句
 | 
					 | 
				
			||||||
// 依次返回 列名数组,结果map,错误
 | 
					 | 
				
			||||||
func (d *DbInstance) SelectData(execSql string) ([]string, []map[string]interface{}, error) {
 | 
					 | 
				
			||||||
	return SelectDataByDb(d.db, execSql)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 执行 update, insert, delete,建表等sql
 | 
					 | 
				
			||||||
// 返回影响条数和错误
 | 
					 | 
				
			||||||
func (d *DbInstance) Exec(sql string) (int64, error) {
 | 
					 | 
				
			||||||
	res, err := d.db.Exec(sql)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return 0, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return res.RowsAffected()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取数据库元信息实现接口
 | 
					 | 
				
			||||||
func (di *DbInstance) GetMeta() DbMetadata {
 | 
					 | 
				
			||||||
	dbType := di.Type
 | 
					 | 
				
			||||||
	if dbType == entity.DbTypeMysql {
 | 
					 | 
				
			||||||
		return &MysqlMetadata{di: di}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if dbType == entity.DbTypePostgres {
 | 
					 | 
				
			||||||
		return &PgsqlMetadata{di: di}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 关闭连接
 | 
					 | 
				
			||||||
func (d *DbInstance) Close() {
 | 
					 | 
				
			||||||
	if d.db != nil {
 | 
					 | 
				
			||||||
		if err := d.db.Close(); err != nil {
 | 
					 | 
				
			||||||
			global.Log.Errorf("关闭数据库实例[%s]连接失败: %s", d.Id, err.Error())
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		d.db = nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取dataSourceName
 | 
					 | 
				
			||||||
func getDsn(d *entity.Db, db string) string {
 | 
					 | 
				
			||||||
	var dsn string
 | 
					 | 
				
			||||||
	if d.Type == entity.DbTypeMysql {
 | 
					 | 
				
			||||||
		dsn = fmt.Sprintf("%s:%s@%s(%s:%d)/%s?timeout=8s", d.Username, d.Password, d.Network, d.Host, d.Port, db)
 | 
					 | 
				
			||||||
		if d.Params != "" {
 | 
					 | 
				
			||||||
			dsn = fmt.Sprintf("%s&%s", dsn, d.Params)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return dsn
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if d.Type == entity.DbTypePostgres {
 | 
					 | 
				
			||||||
		dsn = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", d.Host, d.Port, d.Username, d.Password, db)
 | 
					 | 
				
			||||||
		if d.Params != "" {
 | 
					 | 
				
			||||||
			dsn = fmt.Sprintf("%s %s", dsn, strings.Join(strings.Split(d.Params, "&"), " "))
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return dsn
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return ""
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 删除db缓存并关闭该数据库所有连接
 | 
					 | 
				
			||||||
func CloseDb(dbId uint64, db string) {
 | 
					 | 
				
			||||||
	dbCache.Delete(GetDbCacheKey(dbId, db))
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// -----------------------------------元数据-------------------------------------------
 | 
					 | 
				
			||||||
// 数据库元信息接口(表、列等元信息)
 | 
					 | 
				
			||||||
type DbMetadata interface {
 | 
					 | 
				
			||||||
	// 获取表基础元信息, 如表名等
 | 
					 | 
				
			||||||
	GetTables() []map[string]interface{}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 获取列元信息, 如列名等
 | 
					 | 
				
			||||||
	GetColumns(tableNames ...string) []map[string]interface{}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 获取表主键字段名,默认第一个字段
 | 
					 | 
				
			||||||
	GetPrimaryKey(tablename string) string
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 获取表信息,比GetTables获取更详细的表信息
 | 
					 | 
				
			||||||
	GetTableInfos() []map[string]interface{}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 获取表索引信息
 | 
					 | 
				
			||||||
	GetTableIndex(tableName string) []map[string]interface{}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 获取建表ddl
 | 
					 | 
				
			||||||
	GetCreateTableDdl(tableName string) []map[string]interface{}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 默认每次查询列元信息数量
 | 
					 | 
				
			||||||
const DEFAULT_COLUMN_SIZE = 2000
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// ---------------------------------- mysql元数据 -----------------------------------
 | 
					 | 
				
			||||||
const (
 | 
					 | 
				
			||||||
	// mysql 表信息元数据
 | 
					 | 
				
			||||||
	MYSQL_TABLE_MA = `SELECT table_name tableName, engine, table_comment tableComment, 
 | 
					 | 
				
			||||||
	create_time createTime from information_schema.tables
 | 
					 | 
				
			||||||
	WHERE table_schema = (SELECT database()) LIMIT 2000`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// mysql 表信息
 | 
					 | 
				
			||||||
	MYSQL_TABLE_INFO = `SELECT table_name tableName, table_comment tableComment, table_rows tableRows,
 | 
					 | 
				
			||||||
	data_length dataLength, index_length indexLength, create_time createTime 
 | 
					 | 
				
			||||||
	FROM information_schema.tables 
 | 
					 | 
				
			||||||
    WHERE table_schema = (SELECT database()) LIMIT 2000`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// mysql 索引信息
 | 
					 | 
				
			||||||
	MYSQL_INDEX_INFO = `SELECT index_name indexName, column_name columnName, index_type indexType,
 | 
					 | 
				
			||||||
	SEQ_IN_INDEX seqInIndex, INDEX_COMMENT indexComment
 | 
					 | 
				
			||||||
	FROM information_schema.STATISTICS 
 | 
					 | 
				
			||||||
    WHERE table_schema = (SELECT database()) AND table_name = '%s' LIMIT 500`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// mysql 列信息元数据
 | 
					 | 
				
			||||||
	MYSQL_COLUMN_MA = `SELECT table_name tableName, column_name columnName, column_type columnType,
 | 
					 | 
				
			||||||
	column_comment columnComment, column_key columnKey, extra, is_nullable nullable from information_schema.columns
 | 
					 | 
				
			||||||
	WHERE table_name in (%s) AND table_schema = (SELECT database()) ORDER BY tableName, ordinal_position LIMIT %d, %d`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// mysql 列信息元数据总数
 | 
					 | 
				
			||||||
	MYSQL_COLOUMN_MA_COUNT = `SELECT COUNT(*) maNum from information_schema.columns
 | 
					 | 
				
			||||||
	WHERE table_name in (%s) AND table_schema = (SELECT database())`
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type MysqlMetadata struct {
 | 
					 | 
				
			||||||
	di *DbInstance
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取表基础元信息, 如表名等
 | 
					 | 
				
			||||||
func (mm *MysqlMetadata) GetTables() []map[string]interface{} {
 | 
					 | 
				
			||||||
	_, res, _ := mm.di.SelectData(MYSQL_TABLE_MA)
 | 
					 | 
				
			||||||
	return res
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取列元信息, 如列名等
 | 
					 | 
				
			||||||
func (mm *MysqlMetadata) GetColumns(tableNames ...string) []map[string]interface{} {
 | 
					 | 
				
			||||||
	var sql, tableName string
 | 
					 | 
				
			||||||
	for i := 0; i < len(tableNames); i++ {
 | 
					 | 
				
			||||||
		if i != 0 {
 | 
					 | 
				
			||||||
			tableName = tableName + ", "
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		tableName = tableName + "'" + tableNames[i] + "'"
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	pageNum := 1
 | 
					 | 
				
			||||||
	// 如果大于一个表,则统计列数并分页获取
 | 
					 | 
				
			||||||
	if len(tableNames) > 1 {
 | 
					 | 
				
			||||||
		countSql := fmt.Sprintf(MYSQL_COLOUMN_MA_COUNT, tableName)
 | 
					 | 
				
			||||||
		_, countRes, _ := mm.di.SelectData(countSql)
 | 
					 | 
				
			||||||
		maCount := 0
 | 
					 | 
				
			||||||
		// 查询出所有列信息总数,手动分页获取所有数据
 | 
					 | 
				
			||||||
		if count64, is64 := countRes[0]["maNum"].(int64); is64 {
 | 
					 | 
				
			||||||
			maCount = int(count64)
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			maCount = countRes[0]["maNum"].(int)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// 计算需要查询的页数
 | 
					 | 
				
			||||||
		pageNum = maCount / DEFAULT_COLUMN_SIZE
 | 
					 | 
				
			||||||
		if maCount%DEFAULT_COLUMN_SIZE > 0 {
 | 
					 | 
				
			||||||
			pageNum++
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	res := make([]map[string]interface{}, 0)
 | 
					 | 
				
			||||||
	for index := 0; index < pageNum; index++ {
 | 
					 | 
				
			||||||
		sql = fmt.Sprintf(MYSQL_COLUMN_MA, tableName, index*DEFAULT_COLUMN_SIZE, DEFAULT_COLUMN_SIZE)
 | 
					 | 
				
			||||||
		_, result, err := mm.di.SelectData(sql)
 | 
					 | 
				
			||||||
		biz.ErrIsNilAppendErr(err, "获取数据库列信息失败: %s")
 | 
					 | 
				
			||||||
		res = append(res, result...)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return res
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取表主键字段名,默认第一个字段
 | 
					 | 
				
			||||||
func (mm *MysqlMetadata) GetPrimaryKey(tablename string) string {
 | 
					 | 
				
			||||||
	return mm.GetColumns(tablename)[0]["columnName"].(string)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取表信息,比GetTableMetedatas获取更详细的表信息
 | 
					 | 
				
			||||||
func (mm *MysqlMetadata) GetTableInfos() []map[string]interface{} {
 | 
					 | 
				
			||||||
	_, res, _ := mm.di.SelectData(MYSQL_TABLE_INFO)
 | 
					 | 
				
			||||||
	return res
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取表索引信息
 | 
					 | 
				
			||||||
func (mm *MysqlMetadata) GetTableIndex(tableName string) []map[string]interface{} {
 | 
					 | 
				
			||||||
	_, res, _ := mm.di.SelectData(fmt.Sprintf(MYSQL_INDEX_INFO, tableName))
 | 
					 | 
				
			||||||
	return res
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取建表ddl
 | 
					 | 
				
			||||||
func (mm *MysqlMetadata) GetCreateTableDdl(tableName string) []map[string]interface{} {
 | 
					 | 
				
			||||||
	_, res, _ := mm.di.SelectData(fmt.Sprintf("show create table %s ", tableName))
 | 
					 | 
				
			||||||
	return res
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// ---------------------------------- pgsql元数据 -----------------------------------
 | 
					 | 
				
			||||||
const (
 | 
					 | 
				
			||||||
	// postgres 表信息元数据
 | 
					 | 
				
			||||||
	PGSQL_TABLE_MA = `SELECT obj_description(c.oid) AS "tableComment", c.relname AS "tableName" FROM pg_class c 
 | 
					 | 
				
			||||||
	JOIN pg_namespace n ON c.relnamespace = n.oid WHERE n.nspname = (select current_schema()) AND c.reltype > 0`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	PGSQL_TABLE_INFO = `SELECT obj_description(c.oid) AS "tableComment", c.relname AS "tableName" FROM pg_class c 
 | 
					 | 
				
			||||||
	JOIN pg_namespace n ON c.relnamespace = n.oid WHERE n.nspname = (select current_schema()) AND c.reltype > 0`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	PGSQL_INDEX_INFO = `SELECT indexname AS "indexName", indexdef AS "indexComment"
 | 
					 | 
				
			||||||
	FROM pg_indexes WHERE schemaname =  (select current_schema()) AND tablename = '%s'`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	PGSQL_COLUMN_MA = `SELECT
 | 
					 | 
				
			||||||
		C.relname AS "tableName",
 | 
					 | 
				
			||||||
		A.attname AS "columnName",
 | 
					 | 
				
			||||||
		concat_ws ( '', t.typname, SUBSTRING ( format_type ( a.atttypid, a.atttypmod ) FROM '\(.*\)' ) ) AS "columnType",
 | 
					 | 
				
			||||||
		d.description AS "columnComment" 
 | 
					 | 
				
			||||||
	FROM
 | 
					 | 
				
			||||||
		pg_attribute a LEFT JOIN pg_description d ON d.objoid = a.attrelid 
 | 
					 | 
				
			||||||
		AND d.objsubid = A.attnum
 | 
					 | 
				
			||||||
		LEFT JOIN pg_class c ON A.attrelid = c.oid
 | 
					 | 
				
			||||||
		LEFT JOIN pg_namespace pn ON c.relnamespace = pn.oid
 | 
					 | 
				
			||||||
		LEFT JOIN pg_type t ON a.atttypid = t.oid 
 | 
					 | 
				
			||||||
	WHERE
 | 
					 | 
				
			||||||
		A.attnum >= 0 
 | 
					 | 
				
			||||||
		AND pn.nspname = (select current_schema())
 | 
					 | 
				
			||||||
		AND C.relname in (%s)
 | 
					 | 
				
			||||||
	ORDER BY
 | 
					 | 
				
			||||||
		C.relname DESC,
 | 
					 | 
				
			||||||
		A.attnum ASC
 | 
					 | 
				
			||||||
	OFFSET %d LIMIT %d	
 | 
					 | 
				
			||||||
	`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	PGSQL_COLUMN_MA_COUNT = `SELECT COUNT(*) "maNum"
 | 
					 | 
				
			||||||
	FROM
 | 
					 | 
				
			||||||
		pg_attribute a LEFT JOIN pg_description d ON d.objoid = a.attrelid 
 | 
					 | 
				
			||||||
		AND d.objsubid = A.attnum
 | 
					 | 
				
			||||||
		LEFT JOIN pg_class c ON A.attrelid = c.oid
 | 
					 | 
				
			||||||
		LEFT JOIN pg_namespace pn ON c.relnamespace = pn.oid
 | 
					 | 
				
			||||||
		LEFT JOIN pg_type t ON a.atttypid = t.oid 
 | 
					 | 
				
			||||||
	WHERE
 | 
					 | 
				
			||||||
		A.attnum >= 0 
 | 
					 | 
				
			||||||
		AND pn.nspname = (select current_schema())
 | 
					 | 
				
			||||||
		AND C.relname in (%s)
 | 
					 | 
				
			||||||
	`
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type PgsqlMetadata struct {
 | 
					 | 
				
			||||||
	di *DbInstance
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取表基础元信息, 如表名等
 | 
					 | 
				
			||||||
func (pm *PgsqlMetadata) GetTables() []map[string]interface{} {
 | 
					 | 
				
			||||||
	_, res, _ := pm.di.SelectData(PGSQL_TABLE_MA)
 | 
					 | 
				
			||||||
	return res
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取列元信息, 如列名等
 | 
					 | 
				
			||||||
func (pm *PgsqlMetadata) GetColumns(tableNames ...string) []map[string]interface{} {
 | 
					 | 
				
			||||||
	var sql, tableName string
 | 
					 | 
				
			||||||
	for i := 0; i < len(tableNames); i++ {
 | 
					 | 
				
			||||||
		if i != 0 {
 | 
					 | 
				
			||||||
			tableName = tableName + ", "
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		tableName = tableName + "'" + tableNames[i] + "'"
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	pageNum := 1
 | 
					 | 
				
			||||||
	// 如果大于一个表,则统计列数并分页获取
 | 
					 | 
				
			||||||
	if len(tableNames) > 1 {
 | 
					 | 
				
			||||||
		countSql := fmt.Sprintf(PGSQL_COLUMN_MA_COUNT, tableName)
 | 
					 | 
				
			||||||
		_, countRes, _ := pm.di.SelectData(countSql)
 | 
					 | 
				
			||||||
		maCount := 0
 | 
					 | 
				
			||||||
		// 查询出所有列信息总数,手动分页获取所有数据
 | 
					 | 
				
			||||||
		if count64, is64 := countRes[0]["maNum"].(int64); is64 {
 | 
					 | 
				
			||||||
			maCount = int(count64)
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			maCount = countRes[0]["maNum"].(int)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		// 计算需要查询的页数
 | 
					 | 
				
			||||||
		pageNum = maCount / DEFAULT_COLUMN_SIZE
 | 
					 | 
				
			||||||
		if maCount%DEFAULT_COLUMN_SIZE > 0 {
 | 
					 | 
				
			||||||
			pageNum++
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	res := make([]map[string]interface{}, 0)
 | 
					 | 
				
			||||||
	for index := 0; index < pageNum; index++ {
 | 
					 | 
				
			||||||
		sql = fmt.Sprintf(PGSQL_COLUMN_MA, tableName, index*DEFAULT_COLUMN_SIZE, DEFAULT_COLUMN_SIZE)
 | 
					 | 
				
			||||||
		_, result, err := pm.di.SelectData(sql)
 | 
					 | 
				
			||||||
		biz.ErrIsNilAppendErr(err, "获取数据库列信息失败: %s")
 | 
					 | 
				
			||||||
		res = append(res, result...)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return res
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取表主键字段名,默认第一个字段
 | 
					 | 
				
			||||||
func (pm *PgsqlMetadata) GetPrimaryKey(tablename string) string {
 | 
					 | 
				
			||||||
	return pm.GetColumns(tablename)[0]["columnName"].(string)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取表信息,比GetTables获取更详细的表信息
 | 
					 | 
				
			||||||
func (pm *PgsqlMetadata) GetTableInfos() []map[string]interface{} {
 | 
					 | 
				
			||||||
	_, res, _ := pm.di.SelectData(PGSQL_TABLE_INFO)
 | 
					 | 
				
			||||||
	return res
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取表索引信息
 | 
					 | 
				
			||||||
func (pm *PgsqlMetadata) GetTableIndex(tableName string) []map[string]interface{} {
 | 
					 | 
				
			||||||
	_, res, _ := pm.di.SelectData(fmt.Sprintf(PGSQL_INDEX_INFO, tableName))
 | 
					 | 
				
			||||||
	return res
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取建表ddl
 | 
					 | 
				
			||||||
func (mm *PgsqlMetadata) GetCreateTableDdl(tableName string) []map[string]interface{} {
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										28
									
								
								server/internal/db/application/meta.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								server/internal/db/application/meta.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					package application
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// -----------------------------------元数据接口定义------------------------------------------
 | 
				
			||||||
 | 
					// 数据库元信息接口(表、列等元信息)
 | 
				
			||||||
 | 
					// 所有数据查出来直接用map接收,注意不同数据库实现该接口返回的map中的key需要统一.
 | 
				
			||||||
 | 
					// 即: 使用别名统一即可。如table_name AS tableName
 | 
				
			||||||
 | 
					type DbMetadata interface {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 获取表基础元信息
 | 
				
			||||||
 | 
						// 表名: tableName, 备注: tableComment
 | 
				
			||||||
 | 
						GetTables() []map[string]interface{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 获取指定表名的所有列元信息
 | 
				
			||||||
 | 
						// 表名: tableName, 列名: columnName, 列类型: columnType, 备注: columnComment, 是否可为null: nullable, 其他信息: extra
 | 
				
			||||||
 | 
						GetColumns(tableNames ...string) []map[string]interface{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 获取表主键字段名,目前默认第一个字段
 | 
				
			||||||
 | 
						GetPrimaryKey(tablename string) string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 获取表信息,比GetTables获取更详细的表信息
 | 
				
			||||||
 | 
						GetTableInfos() []map[string]interface{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 获取表索引信息
 | 
				
			||||||
 | 
						GetTableIndex(tableName string) []map[string]interface{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 获取建表ddl
 | 
				
			||||||
 | 
						GetCreateTableDdl(tableName string) []map[string]interface{}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										83
									
								
								server/internal/db/application/mysql_meta.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								server/internal/db/application/mysql_meta.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,83 @@
 | 
				
			|||||||
 | 
					package application
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ---------------------------------- mysql元数据 -----------------------------------
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						// mysql 表信息元数据
 | 
				
			||||||
 | 
						MYSQL_TABLE_MA = `SELECT table_name tableName, table_comment tableComment from information_schema.tables WHERE table_schema = (SELECT database())`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// mysql 表信息
 | 
				
			||||||
 | 
						MYSQL_TABLE_INFO = `SELECT table_name tableName, table_comment tableComment, table_rows tableRows,
 | 
				
			||||||
 | 
						data_length dataLength, index_length indexLength, create_time createTime 
 | 
				
			||||||
 | 
						FROM information_schema.tables 
 | 
				
			||||||
 | 
					    WHERE table_schema = (SELECT database())`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// mysql 索引信息
 | 
				
			||||||
 | 
						MYSQL_INDEX_INFO = `SELECT index_name indexName, column_name columnName, index_type indexType,
 | 
				
			||||||
 | 
						SEQ_IN_INDEX seqInIndex, INDEX_COMMENT indexComment
 | 
				
			||||||
 | 
						FROM information_schema.STATISTICS 
 | 
				
			||||||
 | 
					    WHERE table_schema = (SELECT database()) AND table_name = '%s'`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// mysql 列信息元数据
 | 
				
			||||||
 | 
						MYSQL_COLUMN_MA = `SELECT table_name tableName, column_name columnName, column_type columnType,
 | 
				
			||||||
 | 
						column_comment columnComment, column_key columnKey, extra, is_nullable nullable from information_schema.columns
 | 
				
			||||||
 | 
						WHERE table_schema = (SELECT database()) AND table_name in (%s) ORDER BY tableName, ordinal_position`
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type MysqlMetadata struct {
 | 
				
			||||||
 | 
						di *DbInstance
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取表基础元信息, 如表名等
 | 
				
			||||||
 | 
					func (mm *MysqlMetadata) GetTables() []map[string]interface{} {
 | 
				
			||||||
 | 
						res, err := mm.di.innerSelect(MYSQL_TABLE_MA)
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "获取表基本信息失败: %s")
 | 
				
			||||||
 | 
						return res
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取列元信息, 如列名等
 | 
				
			||||||
 | 
					func (mm *MysqlMetadata) GetColumns(tableNames ...string) []map[string]interface{} {
 | 
				
			||||||
 | 
						tableName := ""
 | 
				
			||||||
 | 
						for i := 0; i < len(tableNames); i++ {
 | 
				
			||||||
 | 
							if i != 0 {
 | 
				
			||||||
 | 
								tableName = tableName + ", "
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							tableName = tableName + "'" + tableNames[i] + "'"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						result, err := mm.di.innerSelect(fmt.Sprintf(MYSQL_COLUMN_MA, tableName))
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "获取数据库列信息失败: %s")
 | 
				
			||||||
 | 
						return result
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取表主键字段名,默认第一个字段
 | 
				
			||||||
 | 
					func (mm *MysqlMetadata) GetPrimaryKey(tablename string) string {
 | 
				
			||||||
 | 
						columns := mm.GetColumns(tablename)
 | 
				
			||||||
 | 
						if len(columns) == 0 {
 | 
				
			||||||
 | 
							panic(biz.NewBizErr(fmt.Sprintf("[%s] 表不存在", tablename)))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return columns[0]["columnName"].(string)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取表信息,比GetTableMetedatas获取更详细的表信息
 | 
				
			||||||
 | 
					func (mm *MysqlMetadata) GetTableInfos() []map[string]interface{} {
 | 
				
			||||||
 | 
						res, err := mm.di.innerSelect(MYSQL_TABLE_INFO)
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "获取表信息失败: %s")
 | 
				
			||||||
 | 
						return res
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取表索引信息
 | 
				
			||||||
 | 
					func (mm *MysqlMetadata) GetTableIndex(tableName string) []map[string]interface{} {
 | 
				
			||||||
 | 
						res, err := mm.di.innerSelect(fmt.Sprintf(MYSQL_INDEX_INFO, tableName))
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "获取表索引信息失败: %s")
 | 
				
			||||||
 | 
						return res
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取建表ddl
 | 
				
			||||||
 | 
					func (mm *MysqlMetadata) GetCreateTableDdl(tableName string) []map[string]interface{} {
 | 
				
			||||||
 | 
						res, _ := mm.di.innerSelect(fmt.Sprintf("show create table %s ", tableName))
 | 
				
			||||||
 | 
						return res
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										95
									
								
								server/internal/db/application/pgsql_meta.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								server/internal/db/application/pgsql_meta.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,95 @@
 | 
				
			|||||||
 | 
					package application
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ---------------------------------- pgsql元数据 -----------------------------------
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						// postgres 表信息元数据
 | 
				
			||||||
 | 
						PGSQL_TABLE_MA = `SELECT obj_description(c.oid) AS "tableComment", c.relname AS "tableName" FROM pg_class c 
 | 
				
			||||||
 | 
						JOIN pg_namespace n ON c.relnamespace = n.oid WHERE n.nspname = (select current_schema()) AND c.reltype > 0`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						PGSQL_TABLE_INFO = `SELECT obj_description(c.oid) AS "tableComment", c.relname AS "tableName" FROM pg_class c 
 | 
				
			||||||
 | 
						JOIN pg_namespace n ON c.relnamespace = n.oid WHERE n.nspname = (select current_schema()) AND c.reltype > 0`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						PGSQL_INDEX_INFO = `SELECT indexname AS "indexName", indexdef AS "indexComment"
 | 
				
			||||||
 | 
						FROM pg_indexes WHERE schemaname =  (select current_schema()) AND tablename = '%s'`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						PGSQL_COLUMN_MA = `SELECT
 | 
				
			||||||
 | 
							C.relname AS "tableName",
 | 
				
			||||||
 | 
							A.attname AS "columnName",
 | 
				
			||||||
 | 
							tc.is_nullable AS "nullable",
 | 
				
			||||||
 | 
							concat_ws ( '', t.typname, SUBSTRING ( format_type ( a.atttypid, a.atttypmod ) FROM '\(.*\)' ) ) AS "columnType",
 | 
				
			||||||
 | 
							d.description AS "columnComment" 
 | 
				
			||||||
 | 
						FROM
 | 
				
			||||||
 | 
							pg_attribute a LEFT JOIN pg_description d ON d.objoid = a.attrelid 
 | 
				
			||||||
 | 
							AND d.objsubid = A.attnum
 | 
				
			||||||
 | 
							LEFT JOIN pg_class c ON A.attrelid = c.oid
 | 
				
			||||||
 | 
							LEFT JOIN pg_namespace pn ON c.relnamespace = pn.oid
 | 
				
			||||||
 | 
							LEFT JOIN pg_type t ON a.atttypid = t.oid 
 | 
				
			||||||
 | 
							JOIN information_schema.columns tc ON tc.column_name = a.attname AND tc.table_name = C.relname AND tc.table_schema = pn.nspname
 | 
				
			||||||
 | 
						WHERE
 | 
				
			||||||
 | 
							A.attnum >= 0 
 | 
				
			||||||
 | 
							AND pn.nspname = (select current_schema())
 | 
				
			||||||
 | 
							AND C.relname in (%s)
 | 
				
			||||||
 | 
						ORDER BY
 | 
				
			||||||
 | 
							C.relname DESC,
 | 
				
			||||||
 | 
							A.attnum ASC	
 | 
				
			||||||
 | 
						`
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type PgsqlMetadata struct {
 | 
				
			||||||
 | 
						di *DbInstance
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取表基础元信息, 如表名等
 | 
				
			||||||
 | 
					func (pm *PgsqlMetadata) GetTables() []map[string]interface{} {
 | 
				
			||||||
 | 
						res, err := pm.di.innerSelect(PGSQL_TABLE_MA)
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "获取表基本信息失败: %s")
 | 
				
			||||||
 | 
						return res
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取列元信息, 如列名等
 | 
				
			||||||
 | 
					func (pm *PgsqlMetadata) GetColumns(tableNames ...string) []map[string]interface{} {
 | 
				
			||||||
 | 
						tableName := ""
 | 
				
			||||||
 | 
						for i := 0; i < len(tableNames); i++ {
 | 
				
			||||||
 | 
							if i != 0 {
 | 
				
			||||||
 | 
								tableName = tableName + ", "
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							tableName = tableName + "'" + tableNames[i] + "'"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						result, err := pm.di.innerSelect(fmt.Sprintf(PGSQL_COLUMN_MA, tableName))
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "获取数据库列信息失败: %s")
 | 
				
			||||||
 | 
						return result
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取表主键字段名,默认第一个字段
 | 
				
			||||||
 | 
					func (pm *PgsqlMetadata) GetPrimaryKey(tablename string) string {
 | 
				
			||||||
 | 
						columns := pm.GetColumns(tablename)
 | 
				
			||||||
 | 
						if len(columns) == 0 {
 | 
				
			||||||
 | 
							panic(biz.NewBizErr(fmt.Sprintf("[%s] 表不存在", tablename)))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return columns[0]["columnName"].(string)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取表信息,比GetTables获取更详细的表信息
 | 
				
			||||||
 | 
					func (pm *PgsqlMetadata) GetTableInfos() []map[string]interface{} {
 | 
				
			||||||
 | 
						res, err := pm.di.innerSelect(PGSQL_TABLE_INFO)
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "获取表信息失败: %s")
 | 
				
			||||||
 | 
						return res
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取表索引信息
 | 
				
			||||||
 | 
					func (pm *PgsqlMetadata) GetTableIndex(tableName string) []map[string]interface{} {
 | 
				
			||||||
 | 
						res, err := pm.di.innerSelect(fmt.Sprintf(PGSQL_INDEX_INFO, tableName))
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "获取表索引信息失败: %s")
 | 
				
			||||||
 | 
						return res
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取建表ddl
 | 
				
			||||||
 | 
					func (mm *PgsqlMetadata) GetCreateTableDdl(tableName string) []map[string]interface{} {
 | 
				
			||||||
 | 
						biz.IsTrue(tableName == "", "暂不支持获取pgsql建表DDL")
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										630
									
								
								server/internal/db/application/sqlx.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										630
									
								
								server/internal/db/application/sqlx.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,630 @@
 | 
				
			|||||||
 | 
					package application
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"database/sql"
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"reflect"
 | 
				
			||||||
 | 
						"runtime"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
						"sync"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 将结果scan至结构体,copy至 sqlx库: https://github.com/jmoiron/sqlx
 | 
				
			||||||
 | 
					func scanAll(rows *sql.Rows, dest interface{}, structOnly bool) error {
 | 
				
			||||||
 | 
						var v, vp reflect.Value
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						value := reflect.ValueOf(dest)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// json.Unmarshal returns errors for these
 | 
				
			||||||
 | 
						if value.Kind() != reflect.Ptr {
 | 
				
			||||||
 | 
							return errors.New("must pass a pointer, not a value, to StructScan destination")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if value.IsNil() {
 | 
				
			||||||
 | 
							return errors.New("nil pointer passed to StructScan destination")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						direct := reflect.Indirect(value)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						slice, err := baseType(value.Type(), reflect.Slice)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						direct.SetLen(0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						isPtr := slice.Elem().Kind() == reflect.Ptr
 | 
				
			||||||
 | 
						base := Deref(slice.Elem())
 | 
				
			||||||
 | 
						scannable := isScannable(base)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if structOnly && scannable {
 | 
				
			||||||
 | 
							return structOnlyError(base)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						columns, err := rows.Columns()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// if it's a base type make sure it only has 1 column;  if not return an error
 | 
				
			||||||
 | 
						if scannable && len(columns) > 1 {
 | 
				
			||||||
 | 
							return fmt.Errorf("non-struct dest type %s with >1 columns (%d)", base.Kind(), len(columns))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !scannable {
 | 
				
			||||||
 | 
							var values []interface{}
 | 
				
			||||||
 | 
							var m *Mapper = mapper()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							fields := m.TraversalsByName(base, columns)
 | 
				
			||||||
 | 
							// if we are not unsafe and are missing fields, return an error
 | 
				
			||||||
 | 
							if f, err := missingFields(fields); err != nil {
 | 
				
			||||||
 | 
								return fmt.Errorf("missing destination name %s in %T", columns[f], dest)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							values = make([]interface{}, len(columns))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							for rows.Next() {
 | 
				
			||||||
 | 
								// create a new struct type (which returns PtrTo) and indirect it
 | 
				
			||||||
 | 
								vp = reflect.New(base)
 | 
				
			||||||
 | 
								v = reflect.Indirect(vp)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								err = fieldsByTraversal(v, fields, values, true)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// scan into the struct field pointers and append to our results
 | 
				
			||||||
 | 
								err = rows.Scan(values...)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if isPtr {
 | 
				
			||||||
 | 
									direct.Set(reflect.Append(direct, vp))
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									direct.Set(reflect.Append(direct, v))
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							for rows.Next() {
 | 
				
			||||||
 | 
								vp = reflect.New(base)
 | 
				
			||||||
 | 
								err = rows.Scan(vp.Interface())
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								// append
 | 
				
			||||||
 | 
								if isPtr {
 | 
				
			||||||
 | 
									direct.Set(reflect.Append(direct, vp))
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									direct.Set(reflect.Append(direct, reflect.Indirect(vp)))
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return rows.Err()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func baseType(t reflect.Type, expected reflect.Kind) (reflect.Type, error) {
 | 
				
			||||||
 | 
						t = Deref(t)
 | 
				
			||||||
 | 
						if t.Kind() != expected {
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("expected %s but got %s", expected, t.Kind())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return t, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// structOnlyError returns an error appropriate for type when a non-scannable
 | 
				
			||||||
 | 
					// struct is expected but something else is given
 | 
				
			||||||
 | 
					func structOnlyError(t reflect.Type) error {
 | 
				
			||||||
 | 
						isStruct := t.Kind() == reflect.Struct
 | 
				
			||||||
 | 
						isScanner := reflect.PtrTo(t).Implements(_scannerInterface)
 | 
				
			||||||
 | 
						if !isStruct {
 | 
				
			||||||
 | 
							return fmt.Errorf("expected %s but got %s", reflect.Struct, t.Kind())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if isScanner {
 | 
				
			||||||
 | 
							return fmt.Errorf("structscan expects a struct dest but the provided struct type %s implements scanner", t.Name())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return fmt.Errorf("expected a struct, but struct %s has no exported fields", t.Name())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var _scannerInterface = reflect.TypeOf((*sql.Scanner)(nil)).Elem()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func isScannable(t reflect.Type) bool {
 | 
				
			||||||
 | 
						if reflect.PtrTo(t).Implements(_scannerInterface) {
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if t.Kind() != reflect.Struct {
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// it's not important that we use the right mapper for this particular object,
 | 
				
			||||||
 | 
						// we're only concerned on how many exported fields this struct has
 | 
				
			||||||
 | 
						return len(mapper().TypeMap(t).Index) == 0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var NameMapper = strings.ToLower
 | 
				
			||||||
 | 
					var origMapper = reflect.ValueOf(NameMapper)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Rather than creating on init, this is created when necessary so that
 | 
				
			||||||
 | 
					// importers have time to customize the NameMapper.
 | 
				
			||||||
 | 
					var mpr *Mapper
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// mprMu protects mpr.
 | 
				
			||||||
 | 
					var mprMu sync.Mutex
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// mapper returns a valid mapper using the configured NameMapper func.
 | 
				
			||||||
 | 
					func mapper() *Mapper {
 | 
				
			||||||
 | 
						mprMu.Lock()
 | 
				
			||||||
 | 
						defer mprMu.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if mpr == nil {
 | 
				
			||||||
 | 
							mpr = NewMapperFunc("db", NameMapper)
 | 
				
			||||||
 | 
						} else if origMapper != reflect.ValueOf(NameMapper) {
 | 
				
			||||||
 | 
							// if NameMapper has changed, create a new mapper
 | 
				
			||||||
 | 
							mpr = NewMapperFunc("db", NameMapper)
 | 
				
			||||||
 | 
							origMapper = reflect.ValueOf(NameMapper)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return mpr
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func missingFields(transversals [][]int) (field int, err error) {
 | 
				
			||||||
 | 
						for i, t := range transversals {
 | 
				
			||||||
 | 
							if len(t) == 0 {
 | 
				
			||||||
 | 
								return i, errors.New("missing field")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return 0, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// fieldsByName fills a values interface with fields from the passed value based
 | 
				
			||||||
 | 
					// on the traversals in int.  If ptrs is true, return addresses instead of values.
 | 
				
			||||||
 | 
					// We write this instead of using FieldsByName to save allocations and map lookups
 | 
				
			||||||
 | 
					// when iterating over many rows.  Empty traversals will get an interface pointer.
 | 
				
			||||||
 | 
					// Because of the necessity of requesting ptrs or values, it's considered a bit too
 | 
				
			||||||
 | 
					// specialized for inclusion in reflectx itself.
 | 
				
			||||||
 | 
					func fieldsByTraversal(v reflect.Value, traversals [][]int, values []interface{}, ptrs bool) error {
 | 
				
			||||||
 | 
						v = reflect.Indirect(v)
 | 
				
			||||||
 | 
						if v.Kind() != reflect.Struct {
 | 
				
			||||||
 | 
							return errors.New("argument not a struct")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for i, traversal := range traversals {
 | 
				
			||||||
 | 
							if len(traversal) == 0 {
 | 
				
			||||||
 | 
								values[i] = new(interface{})
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							f := FieldByIndexes(v, traversal)
 | 
				
			||||||
 | 
							if ptrs {
 | 
				
			||||||
 | 
								values[i] = f.Addr().Interface()
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								values[i] = f.Interface()
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// A FieldInfo is metadata for a struct field.
 | 
				
			||||||
 | 
					type FieldInfo struct {
 | 
				
			||||||
 | 
						Index    []int
 | 
				
			||||||
 | 
						Path     string
 | 
				
			||||||
 | 
						Field    reflect.StructField
 | 
				
			||||||
 | 
						Zero     reflect.Value
 | 
				
			||||||
 | 
						Name     string
 | 
				
			||||||
 | 
						Options  map[string]string
 | 
				
			||||||
 | 
						Embedded bool
 | 
				
			||||||
 | 
						Children []*FieldInfo
 | 
				
			||||||
 | 
						Parent   *FieldInfo
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// A StructMap is an index of field metadata for a struct.
 | 
				
			||||||
 | 
					type StructMap struct {
 | 
				
			||||||
 | 
						Tree  *FieldInfo
 | 
				
			||||||
 | 
						Index []*FieldInfo
 | 
				
			||||||
 | 
						Paths map[string]*FieldInfo
 | 
				
			||||||
 | 
						Names map[string]*FieldInfo
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GetByPath returns a *FieldInfo for a given string path.
 | 
				
			||||||
 | 
					func (f StructMap) GetByPath(path string) *FieldInfo {
 | 
				
			||||||
 | 
						return f.Paths[path]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GetByTraversal returns a *FieldInfo for a given integer path.  It is
 | 
				
			||||||
 | 
					// analogous to reflect.FieldByIndex, but using the cached traversal
 | 
				
			||||||
 | 
					// rather than re-executing the reflect machinery each time.
 | 
				
			||||||
 | 
					func (f StructMap) GetByTraversal(index []int) *FieldInfo {
 | 
				
			||||||
 | 
						if len(index) == 0 {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tree := f.Tree
 | 
				
			||||||
 | 
						for _, i := range index {
 | 
				
			||||||
 | 
							if i >= len(tree.Children) || tree.Children[i] == nil {
 | 
				
			||||||
 | 
								return nil
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							tree = tree.Children[i]
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return tree
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Mapper is a general purpose mapper of names to struct fields.  A Mapper
 | 
				
			||||||
 | 
					// behaves like most marshallers in the standard library, obeying a field tag
 | 
				
			||||||
 | 
					// for name mapping but also providing a basic transform function.
 | 
				
			||||||
 | 
					type Mapper struct {
 | 
				
			||||||
 | 
						cache      map[reflect.Type]*StructMap
 | 
				
			||||||
 | 
						tagName    string
 | 
				
			||||||
 | 
						tagMapFunc func(string) string
 | 
				
			||||||
 | 
						mapFunc    func(string) string
 | 
				
			||||||
 | 
						mutex      sync.Mutex
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// NewMapper returns a new mapper using the tagName as its struct field tag.
 | 
				
			||||||
 | 
					// If tagName is the empty string, it is ignored.
 | 
				
			||||||
 | 
					func NewMapper(tagName string) *Mapper {
 | 
				
			||||||
 | 
						return &Mapper{
 | 
				
			||||||
 | 
							cache:   make(map[reflect.Type]*StructMap),
 | 
				
			||||||
 | 
							tagName: tagName,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// NewMapperTagFunc returns a new mapper which contains a mapper for field names
 | 
				
			||||||
 | 
					// AND a mapper for tag values.  This is useful for tags like json which can
 | 
				
			||||||
 | 
					// have values like "name,omitempty".
 | 
				
			||||||
 | 
					func NewMapperTagFunc(tagName string, mapFunc, tagMapFunc func(string) string) *Mapper {
 | 
				
			||||||
 | 
						return &Mapper{
 | 
				
			||||||
 | 
							cache:      make(map[reflect.Type]*StructMap),
 | 
				
			||||||
 | 
							tagName:    tagName,
 | 
				
			||||||
 | 
							mapFunc:    mapFunc,
 | 
				
			||||||
 | 
							tagMapFunc: tagMapFunc,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// NewMapperFunc returns a new mapper which optionally obeys a field tag and
 | 
				
			||||||
 | 
					// a struct field name mapper func given by f.  Tags will take precedence, but
 | 
				
			||||||
 | 
					// for any other field, the mapped name will be f(field.Name)
 | 
				
			||||||
 | 
					func NewMapperFunc(tagName string, f func(string) string) *Mapper {
 | 
				
			||||||
 | 
						return &Mapper{
 | 
				
			||||||
 | 
							cache:   make(map[reflect.Type]*StructMap),
 | 
				
			||||||
 | 
							tagName: tagName,
 | 
				
			||||||
 | 
							mapFunc: f,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TypeMap returns a mapping of field strings to int slices representing
 | 
				
			||||||
 | 
					// the traversal down the struct to reach the field.
 | 
				
			||||||
 | 
					func (m *Mapper) TypeMap(t reflect.Type) *StructMap {
 | 
				
			||||||
 | 
						m.mutex.Lock()
 | 
				
			||||||
 | 
						mapping, ok := m.cache[t]
 | 
				
			||||||
 | 
						if !ok {
 | 
				
			||||||
 | 
							mapping = getMapping(t, m.tagName, m.mapFunc, m.tagMapFunc)
 | 
				
			||||||
 | 
							m.cache[t] = mapping
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						m.mutex.Unlock()
 | 
				
			||||||
 | 
						return mapping
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// FieldMap returns the mapper's mapping of field names to reflect values.  Panics
 | 
				
			||||||
 | 
					// if v's Kind is not Struct, or v is not Indirectable to a struct kind.
 | 
				
			||||||
 | 
					func (m *Mapper) FieldMap(v reflect.Value) map[string]reflect.Value {
 | 
				
			||||||
 | 
						v = reflect.Indirect(v)
 | 
				
			||||||
 | 
						mustBe(v, reflect.Struct)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						r := map[string]reflect.Value{}
 | 
				
			||||||
 | 
						tm := m.TypeMap(v.Type())
 | 
				
			||||||
 | 
						for tagName, fi := range tm.Names {
 | 
				
			||||||
 | 
							r[tagName] = FieldByIndexes(v, fi.Index)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// FieldByName returns a field by its mapped name as a reflect.Value.
 | 
				
			||||||
 | 
					// Panics if v's Kind is not Struct or v is not Indirectable to a struct Kind.
 | 
				
			||||||
 | 
					// Returns zero Value if the name is not found.
 | 
				
			||||||
 | 
					func (m *Mapper) FieldByName(v reflect.Value, name string) reflect.Value {
 | 
				
			||||||
 | 
						v = reflect.Indirect(v)
 | 
				
			||||||
 | 
						mustBe(v, reflect.Struct)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tm := m.TypeMap(v.Type())
 | 
				
			||||||
 | 
						fi, ok := tm.Names[name]
 | 
				
			||||||
 | 
						if !ok {
 | 
				
			||||||
 | 
							return v
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return FieldByIndexes(v, fi.Index)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// FieldsByName returns a slice of values corresponding to the slice of names
 | 
				
			||||||
 | 
					// for the value.  Panics if v's Kind is not Struct or v is not Indirectable
 | 
				
			||||||
 | 
					// to a struct Kind.  Returns zero Value for each name not found.
 | 
				
			||||||
 | 
					func (m *Mapper) FieldsByName(v reflect.Value, names []string) []reflect.Value {
 | 
				
			||||||
 | 
						v = reflect.Indirect(v)
 | 
				
			||||||
 | 
						mustBe(v, reflect.Struct)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tm := m.TypeMap(v.Type())
 | 
				
			||||||
 | 
						vals := make([]reflect.Value, 0, len(names))
 | 
				
			||||||
 | 
						for _, name := range names {
 | 
				
			||||||
 | 
							fi, ok := tm.Names[name]
 | 
				
			||||||
 | 
							if !ok {
 | 
				
			||||||
 | 
								vals = append(vals, *new(reflect.Value))
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								vals = append(vals, FieldByIndexes(v, fi.Index))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return vals
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TraversalsByName returns a slice of int slices which represent the struct
 | 
				
			||||||
 | 
					// traversals for each mapped name.  Panics if t is not a struct or Indirectable
 | 
				
			||||||
 | 
					// to a struct.  Returns empty int slice for each name not found.
 | 
				
			||||||
 | 
					func (m *Mapper) TraversalsByName(t reflect.Type, names []string) [][]int {
 | 
				
			||||||
 | 
						r := make([][]int, 0, len(names))
 | 
				
			||||||
 | 
						m.TraversalsByNameFunc(t, names, func(_ int, i []int) error {
 | 
				
			||||||
 | 
							if i == nil {
 | 
				
			||||||
 | 
								r = append(r, []int{})
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								r = append(r, i)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						return r
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TraversalsByNameFunc traverses the mapped names and calls fn with the index of
 | 
				
			||||||
 | 
					// each name and the struct traversal represented by that name. Panics if t is not
 | 
				
			||||||
 | 
					// a struct or Indirectable to a struct. Returns the first error returned by fn or nil.
 | 
				
			||||||
 | 
					func (m *Mapper) TraversalsByNameFunc(t reflect.Type, names []string, fn func(int, []int) error) error {
 | 
				
			||||||
 | 
						t = Deref(t)
 | 
				
			||||||
 | 
						mustBe(t, reflect.Struct)
 | 
				
			||||||
 | 
						tm := m.TypeMap(t)
 | 
				
			||||||
 | 
						for i, name := range names {
 | 
				
			||||||
 | 
							fi, ok := tm.Names[name]
 | 
				
			||||||
 | 
							if !ok {
 | 
				
			||||||
 | 
								if err := fn(i, nil); err != nil {
 | 
				
			||||||
 | 
									return err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								if err := fn(i, fi.Index); err != nil {
 | 
				
			||||||
 | 
									return err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// FieldByIndexes returns a value for the field given by the struct traversal
 | 
				
			||||||
 | 
					// for the given value.
 | 
				
			||||||
 | 
					func FieldByIndexes(v reflect.Value, indexes []int) reflect.Value {
 | 
				
			||||||
 | 
						for _, i := range indexes {
 | 
				
			||||||
 | 
							v = reflect.Indirect(v).Field(i)
 | 
				
			||||||
 | 
							// if this is a pointer and it's nil, allocate a new value and set it
 | 
				
			||||||
 | 
							if v.Kind() == reflect.Ptr && v.IsNil() {
 | 
				
			||||||
 | 
								alloc := reflect.New(Deref(v.Type()))
 | 
				
			||||||
 | 
								v.Set(alloc)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if v.Kind() == reflect.Map && v.IsNil() {
 | 
				
			||||||
 | 
								v.Set(reflect.MakeMap(v.Type()))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return v
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// FieldByIndexesReadOnly returns a value for a particular struct traversal,
 | 
				
			||||||
 | 
					// but is not concerned with allocating nil pointers because the value is
 | 
				
			||||||
 | 
					// going to be used for reading and not setting.
 | 
				
			||||||
 | 
					func FieldByIndexesReadOnly(v reflect.Value, indexes []int) reflect.Value {
 | 
				
			||||||
 | 
						for _, i := range indexes {
 | 
				
			||||||
 | 
							v = reflect.Indirect(v).Field(i)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return v
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Deref is Indirect for reflect.Types
 | 
				
			||||||
 | 
					func Deref(t reflect.Type) reflect.Type {
 | 
				
			||||||
 | 
						if t.Kind() == reflect.Ptr {
 | 
				
			||||||
 | 
							t = t.Elem()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return t
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// -- helpers & utilities --
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type kinder interface {
 | 
				
			||||||
 | 
						Kind() reflect.Kind
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// mustBe checks a value against a kind, panicing with a reflect.ValueError
 | 
				
			||||||
 | 
					// if the kind isn't that which is required.
 | 
				
			||||||
 | 
					func mustBe(v kinder, expected reflect.Kind) {
 | 
				
			||||||
 | 
						if k := v.Kind(); k != expected {
 | 
				
			||||||
 | 
							panic(&reflect.ValueError{Method: methodName(), Kind: k})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// methodName returns the caller of the function calling methodName
 | 
				
			||||||
 | 
					func methodName() string {
 | 
				
			||||||
 | 
						pc, _, _, _ := runtime.Caller(2)
 | 
				
			||||||
 | 
						f := runtime.FuncForPC(pc)
 | 
				
			||||||
 | 
						if f == nil {
 | 
				
			||||||
 | 
							return "unknown method"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return f.Name()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type typeQueue struct {
 | 
				
			||||||
 | 
						t  reflect.Type
 | 
				
			||||||
 | 
						fi *FieldInfo
 | 
				
			||||||
 | 
						pp string // Parent path
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// A copying append that creates a new slice each time.
 | 
				
			||||||
 | 
					func apnd(is []int, i int) []int {
 | 
				
			||||||
 | 
						x := make([]int, len(is)+1)
 | 
				
			||||||
 | 
						copy(x, is)
 | 
				
			||||||
 | 
						x[len(x)-1] = i
 | 
				
			||||||
 | 
						return x
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type mapf func(string) string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// parseName parses the tag and the target name for the given field using
 | 
				
			||||||
 | 
					// the tagName (eg 'json' for `json:"foo"` tags), mapFunc for mapping the
 | 
				
			||||||
 | 
					// field's name to a target name, and tagMapFunc for mapping the tag to
 | 
				
			||||||
 | 
					// a target name.
 | 
				
			||||||
 | 
					func parseName(field reflect.StructField, tagName string, mapFunc, tagMapFunc mapf) (tag, fieldName string) {
 | 
				
			||||||
 | 
						// first, set the fieldName to the field's name
 | 
				
			||||||
 | 
						fieldName = field.Name
 | 
				
			||||||
 | 
						// if a mapFunc is set, use that to override the fieldName
 | 
				
			||||||
 | 
						if mapFunc != nil {
 | 
				
			||||||
 | 
							fieldName = mapFunc(fieldName)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// if there's no tag to look for, return the field name
 | 
				
			||||||
 | 
						if tagName == "" {
 | 
				
			||||||
 | 
							return "", fieldName
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// if this tag is not set using the normal convention in the tag,
 | 
				
			||||||
 | 
						// then return the fieldname..  this check is done because according
 | 
				
			||||||
 | 
						// to the reflect documentation:
 | 
				
			||||||
 | 
						//    If the tag does not have the conventional format,
 | 
				
			||||||
 | 
						//    the value returned by Get is unspecified.
 | 
				
			||||||
 | 
						// which doesn't sound great.
 | 
				
			||||||
 | 
						if !strings.Contains(string(field.Tag), tagName+":") {
 | 
				
			||||||
 | 
							return "", fieldName
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// at this point we're fairly sure that we have a tag, so lets pull it out
 | 
				
			||||||
 | 
						tag = field.Tag.Get(tagName)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// if we have a mapper function, call it on the whole tag
 | 
				
			||||||
 | 
						// XXX: this is a change from the old version, which pulled out the name
 | 
				
			||||||
 | 
						// before the tagMapFunc could be run, but I think this is the right way
 | 
				
			||||||
 | 
						if tagMapFunc != nil {
 | 
				
			||||||
 | 
							tag = tagMapFunc(tag)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// finally, split the options from the name
 | 
				
			||||||
 | 
						parts := strings.Split(tag, ",")
 | 
				
			||||||
 | 
						fieldName = parts[0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return tag, fieldName
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// parseOptions parses options out of a tag string, skipping the name
 | 
				
			||||||
 | 
					func parseOptions(tag string) map[string]string {
 | 
				
			||||||
 | 
						parts := strings.Split(tag, ",")
 | 
				
			||||||
 | 
						options := make(map[string]string, len(parts))
 | 
				
			||||||
 | 
						if len(parts) > 1 {
 | 
				
			||||||
 | 
							for _, opt := range parts[1:] {
 | 
				
			||||||
 | 
								// short circuit potentially expensive split op
 | 
				
			||||||
 | 
								if strings.Contains(opt, "=") {
 | 
				
			||||||
 | 
									kv := strings.Split(opt, "=")
 | 
				
			||||||
 | 
									options[kv[0]] = kv[1]
 | 
				
			||||||
 | 
									continue
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								options[opt] = ""
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return options
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// getMapping returns a mapping for the t type, using the tagName, mapFunc and
 | 
				
			||||||
 | 
					// tagMapFunc to determine the canonical names of fields.
 | 
				
			||||||
 | 
					func getMapping(t reflect.Type, tagName string, mapFunc, tagMapFunc mapf) *StructMap {
 | 
				
			||||||
 | 
						m := []*FieldInfo{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						root := &FieldInfo{}
 | 
				
			||||||
 | 
						queue := []typeQueue{}
 | 
				
			||||||
 | 
						queue = append(queue, typeQueue{Deref(t), root, ""})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QueueLoop:
 | 
				
			||||||
 | 
						for len(queue) != 0 {
 | 
				
			||||||
 | 
							// pop the first item off of the queue
 | 
				
			||||||
 | 
							tq := queue[0]
 | 
				
			||||||
 | 
							queue = queue[1:]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// ignore recursive field
 | 
				
			||||||
 | 
							for p := tq.fi.Parent; p != nil; p = p.Parent {
 | 
				
			||||||
 | 
								if tq.fi.Field.Type == p.Field.Type {
 | 
				
			||||||
 | 
									continue QueueLoop
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							nChildren := 0
 | 
				
			||||||
 | 
							if tq.t.Kind() == reflect.Struct {
 | 
				
			||||||
 | 
								nChildren = tq.t.NumField()
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							tq.fi.Children = make([]*FieldInfo, nChildren)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// iterate through all of its fields
 | 
				
			||||||
 | 
							for fieldPos := 0; fieldPos < nChildren; fieldPos++ {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								f := tq.t.Field(fieldPos)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// parse the tag and the target name using the mapping options for this field
 | 
				
			||||||
 | 
								tag, name := parseName(f, tagName, mapFunc, tagMapFunc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// if the name is "-", disabled via a tag, skip it
 | 
				
			||||||
 | 
								if name == "-" {
 | 
				
			||||||
 | 
									continue
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								fi := FieldInfo{
 | 
				
			||||||
 | 
									Field:   f,
 | 
				
			||||||
 | 
									Name:    name,
 | 
				
			||||||
 | 
									Zero:    reflect.New(f.Type).Elem(),
 | 
				
			||||||
 | 
									Options: parseOptions(tag),
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// if the path is empty this path is just the name
 | 
				
			||||||
 | 
								if tq.pp == "" {
 | 
				
			||||||
 | 
									fi.Path = fi.Name
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									fi.Path = tq.pp + "." + fi.Name
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// skip unexported fields
 | 
				
			||||||
 | 
								if len(f.PkgPath) != 0 && !f.Anonymous {
 | 
				
			||||||
 | 
									continue
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// bfs search of anonymous embedded structs
 | 
				
			||||||
 | 
								if f.Anonymous {
 | 
				
			||||||
 | 
									pp := tq.pp
 | 
				
			||||||
 | 
									if tag != "" {
 | 
				
			||||||
 | 
										pp = fi.Path
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									fi.Embedded = true
 | 
				
			||||||
 | 
									fi.Index = apnd(tq.fi.Index, fieldPos)
 | 
				
			||||||
 | 
									nChildren := 0
 | 
				
			||||||
 | 
									ft := Deref(f.Type)
 | 
				
			||||||
 | 
									if ft.Kind() == reflect.Struct {
 | 
				
			||||||
 | 
										nChildren = ft.NumField()
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									fi.Children = make([]*FieldInfo, nChildren)
 | 
				
			||||||
 | 
									queue = append(queue, typeQueue{Deref(f.Type), &fi, pp})
 | 
				
			||||||
 | 
								} else if fi.Zero.Kind() == reflect.Struct || (fi.Zero.Kind() == reflect.Ptr && fi.Zero.Type().Elem().Kind() == reflect.Struct) {
 | 
				
			||||||
 | 
									fi.Index = apnd(tq.fi.Index, fieldPos)
 | 
				
			||||||
 | 
									fi.Children = make([]*FieldInfo, Deref(f.Type).NumField())
 | 
				
			||||||
 | 
									queue = append(queue, typeQueue{Deref(f.Type), &fi, fi.Path})
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								fi.Index = apnd(tq.fi.Index, fieldPos)
 | 
				
			||||||
 | 
								fi.Parent = tq.fi
 | 
				
			||||||
 | 
								tq.fi.Children[fieldPos] = &fi
 | 
				
			||||||
 | 
								m = append(m, &fi)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						flds := &StructMap{Index: m, Tree: root, Paths: map[string]*FieldInfo{}, Names: map[string]*FieldInfo{}}
 | 
				
			||||||
 | 
						for _, fi := range flds.Index {
 | 
				
			||||||
 | 
							// check if nothing has already been pushed with the same path
 | 
				
			||||||
 | 
							// sometimes you can choose to override a type using embedded struct
 | 
				
			||||||
 | 
							fld, ok := flds.Paths[fi.Path]
 | 
				
			||||||
 | 
							if !ok || fld.Embedded {
 | 
				
			||||||
 | 
								flds.Paths[fi.Path] = fi
 | 
				
			||||||
 | 
								if fi.Name != "" && !fi.Embedded {
 | 
				
			||||||
 | 
									flds.Names[fi.Path] = fi
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return flds
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -9,19 +9,18 @@ import (
 | 
				
			|||||||
type Db struct {
 | 
					type Db struct {
 | 
				
			||||||
	model.Model
 | 
						model.Model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Name      string `orm:"column(name)" json:"name"`
 | 
						Name     string `orm:"column(name)" json:"name"`
 | 
				
			||||||
	Type      string `orm:"column(type)" json:"type"` // 类型,mysql oracle等
 | 
						Type     string `orm:"column(type)" json:"type"` // 类型,mysql oracle等
 | 
				
			||||||
	Host      string `orm:"column(host)" json:"host"`
 | 
						Host     string `orm:"column(host)" json:"host"`
 | 
				
			||||||
	Port      int    `orm:"column(port)" json:"port"`
 | 
						Port     int    `orm:"column(port)" json:"port"`
 | 
				
			||||||
	Network   string `orm:"column(network)" json:"network"`
 | 
						Network  string `orm:"column(network)" json:"network"`
 | 
				
			||||||
	Username  string `orm:"column(username)" json:"username"`
 | 
						Username string `orm:"column(username)" json:"username"`
 | 
				
			||||||
	Password  string `orm:"column(password)" json:"-"`
 | 
						Password string `orm:"column(password)" json:"-"`
 | 
				
			||||||
	Database  string `orm:"column(database)" json:"database"`
 | 
						Database string `orm:"column(database)" json:"database"`
 | 
				
			||||||
	Params    string `json:"params"`
 | 
						Params   string `json:"params"`
 | 
				
			||||||
	ProjectId uint64
 | 
						Remark   string `json:"remark"`
 | 
				
			||||||
	Project   string
 | 
						TagId    uint64
 | 
				
			||||||
	EnvId     uint64
 | 
						TagPath  string
 | 
				
			||||||
	Env       string
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	EnableSshTunnel    int8   `orm:"column(enable_ssh_tunnel)" json:"enableSshTunnel"`        // 是否启用ssh隧道
 | 
						EnableSshTunnel    int8   `orm:"column(enable_ssh_tunnel)" json:"enableSshTunnel"`        // 是否启用ssh隧道
 | 
				
			||||||
	SshTunnelMachineId uint64 `orm:"column(ssh_tunnel_machine_id)" json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
						SshTunnelMachineId uint64 `orm:"column(ssh_tunnel_machine_id)" json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										24
									
								
								server/internal/db/domain/entity/query.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								server/internal/db/domain/entity/query.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
				
			|||||||
 | 
					package entity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "mayfly-go/pkg/model"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 数据库查询实体,不与数据库表字段一一对应
 | 
				
			||||||
 | 
					type DbQuery struct {
 | 
				
			||||||
 | 
						model.Model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Name     string `orm:"column(name)" json:"name"`
 | 
				
			||||||
 | 
						Type     string `orm:"column(type)" json:"type"` // 类型,mysql oracle等
 | 
				
			||||||
 | 
						Host     string `orm:"column(host)" json:"host"`
 | 
				
			||||||
 | 
						Port     int    `orm:"column(port)" json:"port"`
 | 
				
			||||||
 | 
						Network  string `orm:"column(network)" json:"network"`
 | 
				
			||||||
 | 
						Username string `orm:"column(username)" json:"username"`
 | 
				
			||||||
 | 
						Password string `orm:"column(password)" json:"-"`
 | 
				
			||||||
 | 
						Database string `orm:"column(database)" json:"database"`
 | 
				
			||||||
 | 
						Params   string `json:"params"`
 | 
				
			||||||
 | 
						Remark   string `json:"remark"`
 | 
				
			||||||
 | 
						TagId    uint64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ProjectIds  []uint64
 | 
				
			||||||
 | 
						TagIds      []uint64
 | 
				
			||||||
 | 
						TagPathLike string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -7,9 +7,9 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type Db interface {
 | 
					type Db interface {
 | 
				
			||||||
	// 分页获取机器信息列表
 | 
						// 分页获取机器信息列表
 | 
				
			||||||
	GetDbList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
						GetDbList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Count(condition *entity.Db) int64
 | 
						Count(condition *entity.DbQuery) int64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 根据条件获取账号信息
 | 
						// 根据条件获取账号信息
 | 
				
			||||||
	GetDb(condition *entity.Db, cols ...string) error
 | 
						GetDb(condition *entity.Db, cols ...string) error
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,8 @@ import (
 | 
				
			|||||||
	"mayfly-go/internal/db/domain/repository"
 | 
						"mayfly-go/internal/db/domain/repository"
 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/utils"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type dbRepoImpl struct{}
 | 
					type dbRepoImpl struct{}
 | 
				
			||||||
@@ -15,30 +17,33 @@ func newDbRepo() repository.Db {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 分页获取数据库信息列表
 | 
					// 分页获取数据库信息列表
 | 
				
			||||||
func (d *dbRepoImpl) GetDbList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					func (d *dbRepoImpl) GetDbList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
				
			||||||
	sql := "SELECT d.* FROM t_db d JOIN t_project_member pm ON d.project_id = pm.project_id WHERE 1 = 1 "
 | 
						sql := "SELECT d.* FROM t_db d WHERE 1 = 1 "
 | 
				
			||||||
	if condition.CreatorId != 0 {
 | 
					 | 
				
			||||||
		// 使用创建者id模拟项目成员id
 | 
					 | 
				
			||||||
		sql = fmt.Sprintf("%s AND pm.account_id = %d", sql, condition.CreatorId)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if condition.ProjectId != 0 {
 | 
					 | 
				
			||||||
		sql = fmt.Sprintf("%s AND d.project_id = %d", sql, condition.ProjectId)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if condition.EnvId != 0 {
 | 
					 | 
				
			||||||
		sql = fmt.Sprintf("%s AND d.env_id = %d", sql, condition.EnvId)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if condition.Host != "" {
 | 
						if condition.Host != "" {
 | 
				
			||||||
		sql = sql + " AND d.host LIKE '%" + condition.Host + "%'"
 | 
							sql = sql + " AND d.host LIKE '%" + condition.Host + "%'"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if condition.Database != "" {
 | 
						if condition.Database != "" {
 | 
				
			||||||
		sql = sql + " AND d.database LIKE '%" + condition.Database + "%'"
 | 
							sql = sql + " AND d.database LIKE '%" + condition.Database + "%'"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if len(condition.TagIds) > 0 {
 | 
				
			||||||
 | 
							sql = sql + " AND d.tag_id IN " + fmt.Sprintf("(%s)", strings.Join(utils.NumberArr2StrArr(condition.TagIds), ","))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if condition.TagPathLike != "" {
 | 
				
			||||||
 | 
							sql = sql + " AND d.tag_path LIKE '" + condition.TagPathLike + "%'"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	sql = sql + " ORDER BY d.create_time DESC"
 | 
						sql = sql + " ORDER BY d.create_time DESC"
 | 
				
			||||||
	return model.GetPageBySql(sql, pageParam, toEntity)
 | 
						return model.GetPageBySql(sql, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *dbRepoImpl) Count(condition *entity.Db) int64 {
 | 
					func (d *dbRepoImpl) Count(condition *entity.DbQuery) int64 {
 | 
				
			||||||
	return model.CountBy(condition)
 | 
						where := make(map[string]interface{})
 | 
				
			||||||
 | 
						if len(condition.TagIds) > 0 {
 | 
				
			||||||
 | 
							where["tag_id"] = condition.TagIds
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if condition.TagId != 0 {
 | 
				
			||||||
 | 
							where["tag_id"] = condition.TagId
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return model.CountByMap(new(entity.Db), where)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 根据条件获取账号信息
 | 
					// 根据条件获取账号信息
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,5 +23,5 @@ func (d *dbSqlExecRepoImpl) DeleteBy(condition *entity.DbSqlExec) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// 分页获取
 | 
					// 分页获取
 | 
				
			||||||
func (d *dbSqlExecRepoImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					func (d *dbSqlExecRepoImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
				
			||||||
	return model.GetPage(pageParam, condition, toEntity, orderBy...)
 | 
						return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,8 +3,8 @@ package router
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"mayfly-go/internal/db/api"
 | 
						"mayfly-go/internal/db/api"
 | 
				
			||||||
	"mayfly-go/internal/db/application"
 | 
						"mayfly-go/internal/db/application"
 | 
				
			||||||
	projectapp "mayfly-go/internal/project/application"
 | 
					 | 
				
			||||||
	sysapp "mayfly-go/internal/sys/application"
 | 
						sysapp "mayfly-go/internal/sys/application"
 | 
				
			||||||
 | 
						tagapp "mayfly-go/internal/tag/application"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
@@ -17,7 +17,7 @@ func InitDbRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
			DbApp:        application.GetDbApp(),
 | 
								DbApp:        application.GetDbApp(),
 | 
				
			||||||
			DbSqlExecApp: application.GetDbSqlExecApp(),
 | 
								DbSqlExecApp: application.GetDbSqlExecApp(),
 | 
				
			||||||
			MsgApp:       sysapp.GetMsgApp(),
 | 
								MsgApp:       sysapp.GetMsgApp(),
 | 
				
			||||||
			ProjectApp:   projectapp.GetProjectApp(),
 | 
								TagApp:       tagapp.GetTagTreeApp(),
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		// 获取所有数据库列表
 | 
							// 获取所有数据库列表
 | 
				
			||||||
		db.GET("", func(c *gin.Context) {
 | 
							db.GET("", func(c *gin.Context) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,8 +2,6 @@ package form
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type MachineForm struct {
 | 
					type MachineForm struct {
 | 
				
			||||||
	Id                 uint64 `json:"id"`
 | 
						Id                 uint64 `json:"id"`
 | 
				
			||||||
	ProjectId          uint64 `json:"projectId"`
 | 
					 | 
				
			||||||
	ProjectName        string `json:"projectName"`
 | 
					 | 
				
			||||||
	Name               string `json:"name" binding:"required"`
 | 
						Name               string `json:"name" binding:"required"`
 | 
				
			||||||
	Ip                 string `json:"ip" binding:"required"`       // IP地址
 | 
						Ip                 string `json:"ip" binding:"required"`       // IP地址
 | 
				
			||||||
	Username           string `json:"username" binding:"required"` // 用户名
 | 
						Username           string `json:"username" binding:"required"` // 用户名
 | 
				
			||||||
@@ -14,6 +12,8 @@ type MachineForm struct {
 | 
				
			|||||||
	EnableSshTunnel    int8   `json:"enableSshTunnel"`    // 是否启用ssh隧道
 | 
						EnableSshTunnel    int8   `json:"enableSshTunnel"`    // 是否启用ssh隧道
 | 
				
			||||||
	SshTunnelMachineId uint64 `json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
						SshTunnelMachineId uint64 `json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
				
			||||||
	EnableRecorder     int8   `json:"enableRecorder"`     // 是否启用终端回放记录
 | 
						EnableRecorder     int8   `json:"enableRecorder"`     // 是否启用终端回放记录
 | 
				
			||||||
 | 
						TagId              uint64 `json:"tagId"`
 | 
				
			||||||
 | 
						TagPath            string `json:"tagPath"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type MachineRunForm struct {
 | 
					type MachineRunForm struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,11 +8,12 @@ import (
 | 
				
			|||||||
	"mayfly-go/internal/machine/application"
 | 
						"mayfly-go/internal/machine/application"
 | 
				
			||||||
	"mayfly-go/internal/machine/domain/entity"
 | 
						"mayfly-go/internal/machine/domain/entity"
 | 
				
			||||||
	"mayfly-go/internal/machine/infrastructure/machine"
 | 
						"mayfly-go/internal/machine/infrastructure/machine"
 | 
				
			||||||
	projectapp "mayfly-go/internal/project/application"
 | 
						tagapp "mayfly-go/internal/tag/application"
 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
	"mayfly-go/pkg/config"
 | 
						"mayfly-go/pkg/config"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
	"mayfly-go/pkg/ginx"
 | 
						"mayfly-go/pkg/ginx"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
	"mayfly-go/pkg/utils"
 | 
						"mayfly-go/pkg/utils"
 | 
				
			||||||
	"mayfly-go/pkg/ws"
 | 
						"mayfly-go/pkg/ws"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
@@ -27,16 +28,22 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type Machine struct {
 | 
					type Machine struct {
 | 
				
			||||||
	MachineApp application.Machine
 | 
						MachineApp application.Machine
 | 
				
			||||||
	ProjectApp projectapp.Project
 | 
						TagApp     tagapp.TagTree
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *Machine) Machines(rc *ctx.ReqCtx) {
 | 
					func (m *Machine) Machines(rc *ctx.ReqCtx) {
 | 
				
			||||||
	condition := new(entity.Machine)
 | 
						condition := new(entity.MachineQuery)
 | 
				
			||||||
	// 使用创建者id模拟账号成员id
 | 
					 | 
				
			||||||
	condition.CreatorId = rc.LoginAccount.Id
 | 
					 | 
				
			||||||
	condition.Ip = rc.GinCtx.Query("ip")
 | 
						condition.Ip = rc.GinCtx.Query("ip")
 | 
				
			||||||
	condition.Name = rc.GinCtx.Query("name")
 | 
						condition.Name = rc.GinCtx.Query("name")
 | 
				
			||||||
	condition.ProjectId = uint64(ginx.QueryInt(rc.GinCtx, "projectId", 0))
 | 
						condition.TagPathLike = rc.GinCtx.Query("tagPath")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 不存在可访问标签id,即没有可操作数据
 | 
				
			||||||
 | 
						tagIds := m.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
 | 
				
			||||||
 | 
						if len(tagIds) == 0 {
 | 
				
			||||||
 | 
							rc.ResData = model.EmptyPageResult()
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						condition.TagIds = tagIds
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	res := m.MachineApp.GetMachineList(condition, ginx.GetPageParam(rc.GinCtx), new([]*vo.MachineVO))
 | 
						res := m.MachineApp.GetMachineList(condition, ginx.GetPageParam(rc.GinCtx), new([]*vo.MachineVO))
 | 
				
			||||||
	if res.Total == 0 {
 | 
						if res.Total == 0 {
 | 
				
			||||||
@@ -130,7 +137,7 @@ func (m *Machine) GetProcess(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	cmd += "| head -n " + count
 | 
						cmd += "| head -n " + count
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cli := m.MachineApp.GetCli(GetMachineId(rc.GinCtx))
 | 
						cli := m.MachineApp.GetCli(GetMachineId(rc.GinCtx))
 | 
				
			||||||
	biz.ErrIsNilAppendErr(m.ProjectApp.CanAccess(rc.LoginAccount.Id, cli.GetMachine().ProjectId), "%s")
 | 
						biz.ErrIsNilAppendErr(m.TagApp.CanAccess(rc.LoginAccount.Id, cli.GetMachine().TagPath), "%s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	res, err := cli.Run(cmd)
 | 
						res, err := cli.Run(cmd)
 | 
				
			||||||
	biz.ErrIsNilAppendErr(err, "获取进程信息失败: %s")
 | 
						biz.ErrIsNilAppendErr(err, "获取进程信息失败: %s")
 | 
				
			||||||
@@ -143,7 +150,7 @@ func (m *Machine) KillProcess(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	biz.NotEmpty(pid, "进程id不能为空")
 | 
						biz.NotEmpty(pid, "进程id不能为空")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cli := m.MachineApp.GetCli(GetMachineId(rc.GinCtx))
 | 
						cli := m.MachineApp.GetCli(GetMachineId(rc.GinCtx))
 | 
				
			||||||
	biz.ErrIsNilAppendErr(m.ProjectApp.CanAccess(rc.LoginAccount.Id, cli.GetMachine().ProjectId), "%s")
 | 
						biz.ErrIsNilAppendErr(m.TagApp.CanAccess(rc.LoginAccount.Id, cli.GetMachine().TagPath), "%s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_, err := cli.Run("sudo kill -9 " + pid)
 | 
						_, err := cli.Run("sudo kill -9 " + pid)
 | 
				
			||||||
	biz.ErrIsNilAppendErr(err, "终止进程失败: %s")
 | 
						biz.ErrIsNilAppendErr(err, "终止进程失败: %s")
 | 
				
			||||||
@@ -168,7 +175,7 @@ func (m *Machine) WsSSH(g *gin.Context) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cli := m.MachineApp.GetCli(GetMachineId(g))
 | 
						cli := m.MachineApp.GetCli(GetMachineId(g))
 | 
				
			||||||
	biz.ErrIsNilAppendErr(m.ProjectApp.CanAccess(rc.LoginAccount.Id, cli.GetMachine().ProjectId), "%s")
 | 
						biz.ErrIsNilAppendErr(m.TagApp.CanAccess(rc.LoginAccount.Id, cli.GetMachine().TagPath), "%s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cols := ginx.QueryInt(g, "cols", 80)
 | 
						cols := ginx.QueryInt(g, "cols", 80)
 | 
				
			||||||
	rows := ginx.QueryInt(g, "rows", 40)
 | 
						rows := ginx.QueryInt(g, "rows", 40)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,7 +6,7 @@ import (
 | 
				
			|||||||
	"mayfly-go/internal/machine/api/vo"
 | 
						"mayfly-go/internal/machine/api/vo"
 | 
				
			||||||
	"mayfly-go/internal/machine/application"
 | 
						"mayfly-go/internal/machine/application"
 | 
				
			||||||
	"mayfly-go/internal/machine/domain/entity"
 | 
						"mayfly-go/internal/machine/domain/entity"
 | 
				
			||||||
	projectapp "mayfly-go/internal/project/application"
 | 
						tagapp "mayfly-go/internal/tag/application"
 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
	"mayfly-go/pkg/ginx"
 | 
						"mayfly-go/pkg/ginx"
 | 
				
			||||||
@@ -19,7 +19,7 @@ import (
 | 
				
			|||||||
type MachineScript struct {
 | 
					type MachineScript struct {
 | 
				
			||||||
	MachineScriptApp application.MachineScript
 | 
						MachineScriptApp application.MachineScript
 | 
				
			||||||
	MachineApp       application.Machine
 | 
						MachineApp       application.Machine
 | 
				
			||||||
	ProjectApp       projectapp.Project
 | 
						TagApp           tagapp.TagTree
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *MachineScript) MachineScripts(rc *ctx.ReqCtx) {
 | 
					func (m *MachineScript) MachineScripts(rc *ctx.ReqCtx) {
 | 
				
			||||||
@@ -65,7 +65,7 @@ func (m *MachineScript) RunMachineScript(rc *ctx.ReqCtx) {
 | 
				
			|||||||
		script = utils.TemplateParse(ms.Script, utils.Json2Map(params))
 | 
							script = utils.TemplateParse(ms.Script, utils.Json2Map(params))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	cli := m.MachineApp.GetCli(machineId)
 | 
						cli := m.MachineApp.GetCli(machineId)
 | 
				
			||||||
	biz.ErrIsNilAppendErr(m.ProjectApp.CanAccess(rc.LoginAccount.Id, cli.GetMachine().ProjectId), "%s")
 | 
						biz.ErrIsNilAppendErr(m.TagApp.CanAccess(rc.LoginAccount.Id, cli.GetMachine().TagPath), "%s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	res, err := cli.Run(script)
 | 
						res, err := cli.Run(script)
 | 
				
			||||||
	// 记录请求参数
 | 
						// 记录请求参数
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,22 +2,8 @@ package vo
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import "time"
 | 
					import "time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type AccountVO struct {
 | 
					 | 
				
			||||||
	//models.BaseModel
 | 
					 | 
				
			||||||
	Id         *int64  `json:"id"`
 | 
					 | 
				
			||||||
	Username   *string `json:"username"`
 | 
					 | 
				
			||||||
	CreateTime *string `json:"createTime"`
 | 
					 | 
				
			||||||
	Creator    *string `json:"creator"`
 | 
					 | 
				
			||||||
	CreatorId  *int64  `json:"creatorId"`
 | 
					 | 
				
			||||||
	// Role       *RoleVO `json:"roles"`
 | 
					 | 
				
			||||||
	//Status   int8   `json:"status"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type MachineVO struct {
 | 
					type MachineVO struct {
 | 
				
			||||||
	//models.BaseModel
 | 
					 | 
				
			||||||
	Id                 *uint64    `json:"id"`
 | 
						Id                 *uint64    `json:"id"`
 | 
				
			||||||
	ProjectId          uint64     `json:"projectId"`
 | 
					 | 
				
			||||||
	ProjectName        string     `json:"projectName"`
 | 
					 | 
				
			||||||
	Name               *string    `json:"name"`
 | 
						Name               *string    `json:"name"`
 | 
				
			||||||
	Username           *string    `json:"username"`
 | 
						Username           *string    `json:"username"`
 | 
				
			||||||
	Ip                 *string    `json:"ip"`
 | 
						Ip                 *string    `json:"ip"`
 | 
				
			||||||
@@ -35,6 +21,8 @@ type MachineVO struct {
 | 
				
			|||||||
	HasCli             bool       `json:"hasCli" gorm:"-"`
 | 
						HasCli             bool       `json:"hasCli" gorm:"-"`
 | 
				
			||||||
	Remark             *string    `json:"remark"`
 | 
						Remark             *string    `json:"remark"`
 | 
				
			||||||
	EnableRecorder     int8       `json:"enableRecorder"`
 | 
						EnableRecorder     int8       `json:"enableRecorder"`
 | 
				
			||||||
 | 
						TagId              uint64     `json:"tagId"`
 | 
				
			||||||
 | 
						TagPath            string     `json:"tagPath"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type MachineScriptVO struct {
 | 
					type MachineScriptVO struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,7 @@ type Machine interface {
 | 
				
			|||||||
	// 调整机器状态
 | 
						// 调整机器状态
 | 
				
			||||||
	ChangeStatus(id uint64, status int8)
 | 
						ChangeStatus(id uint64, status int8)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Count(condition *entity.Machine) int64
 | 
						Count(condition *entity.MachineQuery) int64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Delete(id uint64)
 | 
						Delete(id uint64)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -27,7 +27,7 @@ type Machine interface {
 | 
				
			|||||||
	GetById(id uint64, cols ...string) *entity.Machine
 | 
						GetById(id uint64, cols ...string) *entity.Machine
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 分页获取机器信息列表
 | 
						// 分页获取机器信息列表
 | 
				
			||||||
	GetMachineList(condition *entity.Machine, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
						GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 获取机器连接
 | 
						// 获取机器连接
 | 
				
			||||||
	GetCli(id uint64) *machine.Cli
 | 
						GetCli(id uint64) *machine.Cli
 | 
				
			||||||
@@ -46,11 +46,11 @@ type machineAppImpl struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 分页获取机器信息列表
 | 
					// 分页获取机器信息列表
 | 
				
			||||||
func (m *machineAppImpl) GetMachineList(condition *entity.Machine, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					func (m *machineAppImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
				
			||||||
	return m.machineRepo.GetMachineList(condition, pageParam, toEntity, orderBy...)
 | 
						return m.machineRepo.GetMachineList(condition, pageParam, toEntity, orderBy...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *machineAppImpl) Count(condition *entity.Machine) int64 {
 | 
					func (m *machineAppImpl) Count(condition *entity.MachineQuery) int64 {
 | 
				
			||||||
	return m.machineRepo.Count(condition)
 | 
						return m.machineRepo.Count(condition)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,8 +7,7 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type Machine struct {
 | 
					type Machine struct {
 | 
				
			||||||
	model.Model
 | 
						model.Model
 | 
				
			||||||
	ProjectId          uint64 `json:"projectId"`
 | 
					
 | 
				
			||||||
	ProjectName        string `json:"projectName"`
 | 
					 | 
				
			||||||
	Name               string `json:"name"`
 | 
						Name               string `json:"name"`
 | 
				
			||||||
	Ip                 string `json:"ip"`         // IP地址
 | 
						Ip                 string `json:"ip"`         // IP地址
 | 
				
			||||||
	Username           string `json:"username"`   // 用户名
 | 
						Username           string `json:"username"`   // 用户名
 | 
				
			||||||
@@ -20,6 +19,8 @@ type Machine struct {
 | 
				
			|||||||
	EnableSshTunnel    int8   `json:"enableSshTunnel"`    // 是否启用ssh隧道
 | 
						EnableSshTunnel    int8   `json:"enableSshTunnel"`    // 是否启用ssh隧道
 | 
				
			||||||
	SshTunnelMachineId uint64 `json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
						SshTunnelMachineId uint64 `json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
				
			||||||
	EnableRecorder     int8   `json:"enableRecorder"`     // 是否启用终端回放记录
 | 
						EnableRecorder     int8   `json:"enableRecorder"`     // 是否启用终端回放记录
 | 
				
			||||||
 | 
						TagId              uint64 `json:"tagId"`
 | 
				
			||||||
 | 
						TagPath            string `json:"tagPath"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										16
									
								
								server/internal/machine/domain/entity/machine_task_config.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								server/internal/machine/domain/entity/machine_task_config.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					package entity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "mayfly-go/pkg/model"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 机器任务配置
 | 
				
			||||||
 | 
					type MachineTaskConfig struct {
 | 
				
			||||||
 | 
						model.Model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Name           string `json:"name"`
 | 
				
			||||||
 | 
						Cron           string `json:"cron"`   // cron表达式
 | 
				
			||||||
 | 
						Script         string `json:"script"` // 任务内容
 | 
				
			||||||
 | 
						Status         string `json:"status"`
 | 
				
			||||||
 | 
						EnableNotify   int    `json:"enableNotify"`   // 是否启用通知
 | 
				
			||||||
 | 
						NotifyTemplate string `json:"notifyTemplate"` // 通知模板
 | 
				
			||||||
 | 
						Remark         string `json:"remark"`         // 备注
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										25
									
								
								server/internal/machine/domain/entity/query.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								server/internal/machine/domain/entity/query.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					package entity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "mayfly-go/pkg/model"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type MachineQuery struct {
 | 
				
			||||||
 | 
						model.Model
 | 
				
			||||||
 | 
						ProjectId          uint64 `json:"projectId"`
 | 
				
			||||||
 | 
						ProjectName        string `json:"projectName"`
 | 
				
			||||||
 | 
						Name               string `json:"name"`
 | 
				
			||||||
 | 
						Ip                 string `json:"ip"`         // IP地址
 | 
				
			||||||
 | 
						Username           string `json:"username"`   // 用户名
 | 
				
			||||||
 | 
						AuthMethod         int8   `json:"authMethod"` // 授权认证方式
 | 
				
			||||||
 | 
						Password           string `json:"-"`
 | 
				
			||||||
 | 
						Port               int    `json:"port"`               // 端口号
 | 
				
			||||||
 | 
						Status             int8   `json:"status"`             // 状态 1:启用;2:停用
 | 
				
			||||||
 | 
						Remark             string `json:"remark"`             // 备注
 | 
				
			||||||
 | 
						EnableSshTunnel    int8   `json:"enableSshTunnel"`    // 是否启用ssh隧道
 | 
				
			||||||
 | 
						SshTunnelMachineId uint64 `json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
				
			||||||
 | 
						EnableRecorder     int8   `json:"enableRecorder"`     // 是否启用终端回放记录
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ProjectIds  []uint64
 | 
				
			||||||
 | 
						TagId       uint64
 | 
				
			||||||
 | 
						TagPathLike string
 | 
				
			||||||
 | 
						TagIds      []uint64
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -7,9 +7,9 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type Machine interface {
 | 
					type Machine interface {
 | 
				
			||||||
	// 分页获取机器信息列表
 | 
						// 分页获取机器信息列表
 | 
				
			||||||
	GetMachineList(condition *entity.Machine, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
						GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Count(condition *entity.Machine) int64
 | 
						Count(condition *entity.MachineQuery) int64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 根据条件获取账号信息
 | 
						// 根据条件获取账号信息
 | 
				
			||||||
	GetMachine(condition *entity.Machine, cols ...string) error
 | 
						GetMachine(condition *entity.Machine, cols ...string) error
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,22 @@
 | 
				
			|||||||
 | 
					package repository
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"mayfly-go/internal/machine/domain/entity"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type MachineTaskConfig interface {
 | 
				
			||||||
 | 
						GetPageList(condition *entity.MachineTaskConfig, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 根据条件获取
 | 
				
			||||||
 | 
						GetBy(condition *entity.MachineTaskConfig, cols ...string) error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 根据id获取
 | 
				
			||||||
 | 
						GetById(id uint64, cols ...string) *entity.MachineTaskConfig
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Delete(id uint64)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Create(entity *entity.MachineTaskConfig)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						UpdateById(entity *entity.MachineTaskConfig)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -6,6 +6,8 @@ import (
 | 
				
			|||||||
	"mayfly-go/internal/machine/domain/repository"
 | 
						"mayfly-go/internal/machine/domain/repository"
 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/utils"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type machineRepoImpl struct{}
 | 
					type machineRepoImpl struct{}
 | 
				
			||||||
@@ -15,27 +17,34 @@ func newMachineRepo() repository.Machine {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 分页获取机器信息列表
 | 
					// 分页获取机器信息列表
 | 
				
			||||||
func (m *machineRepoImpl) GetMachineList(condition *entity.Machine, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
				
			||||||
	sql := "SELECT m.* FROM t_machine m JOIN t_project_member pm ON m.project_id = pm.project_id WHERE 1 = 1 "
 | 
						sql := "SELECT m.* FROM t_machine m WHERE 1 = 1 "
 | 
				
			||||||
	if condition.CreatorId != 0 {
 | 
					 | 
				
			||||||
		// 使用创建者id模拟项目成员id
 | 
					 | 
				
			||||||
		sql = fmt.Sprintf("%s AND pm.account_id = %d", sql, condition.CreatorId)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if condition.ProjectId != 0 {
 | 
					 | 
				
			||||||
		sql = fmt.Sprintf("%s AND m.project_id = %d", sql, condition.ProjectId)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if condition.Ip != "" {
 | 
						if condition.Ip != "" {
 | 
				
			||||||
		sql = sql + " AND m.ip LIKE '%" + condition.Ip + "%'"
 | 
							sql = sql + " AND m.ip LIKE '%" + condition.Ip + "%'"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if condition.Name != "" {
 | 
						if condition.Name != "" {
 | 
				
			||||||
		sql = sql + " AND m.name LIKE '%" + condition.Name + "%'"
 | 
							sql = sql + " AND m.name LIKE '%" + condition.Name + "%'"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	sql = sql + " ORDER BY m.project_id, m.create_time DESC"
 | 
						if len(condition.TagIds) > 0 {
 | 
				
			||||||
 | 
							sql = fmt.Sprintf("%s AND m.tag_id IN (%s) ", sql, strings.Join(utils.NumberArr2StrArr(condition.TagIds), ","))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if condition.TagPathLike != "" {
 | 
				
			||||||
 | 
							sql = sql + " AND m.tag_path LIKE '" + condition.TagPathLike + "%'"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						sql = sql + " ORDER BY m.tag_id, m.create_time DESC"
 | 
				
			||||||
	return model.GetPageBySql(sql, pageParam, toEntity)
 | 
						return model.GetPageBySql(sql, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *machineRepoImpl) Count(condition *entity.Machine) int64 {
 | 
					func (m *machineRepoImpl) Count(condition *entity.MachineQuery) int64 {
 | 
				
			||||||
	return model.CountBy(condition)
 | 
						where := make(map[string]interface{})
 | 
				
			||||||
 | 
						if len(condition.TagIds) > 0 {
 | 
				
			||||||
 | 
							where["tag_id"] = condition.TagIds
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if condition.TagId != 0 {
 | 
				
			||||||
 | 
							where["tag_id"] = condition.TagId
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return model.CountByMap(new(entity.Machine), where)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 根据条件获取账号信息
 | 
					// 根据条件获取账号信息
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,7 +15,7 @@ func newMachineFileRepo() repository.MachineFile {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// 分页获取机器文件信息列表
 | 
					// 分页获取机器文件信息列表
 | 
				
			||||||
func (m *machineFileRepoImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					func (m *machineFileRepoImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
				
			||||||
	return model.GetPage(pageParam, condition, toEntity, orderBy...)
 | 
						return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 根据条件获取账号信息
 | 
					// 根据条件获取账号信息
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,7 +15,7 @@ func newMachineScriptRepo() repository.MachineScript {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// 分页获取机器信息列表
 | 
					// 分页获取机器信息列表
 | 
				
			||||||
func (m *machineScriptRepoImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					func (m *machineScriptRepoImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
				
			||||||
	return model.GetPage(pageParam, condition, toEntity, orderBy...)
 | 
						return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 根据条件获取账号信息
 | 
					// 根据条件获取账号信息
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@ package router
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"mayfly-go/internal/machine/api"
 | 
						"mayfly-go/internal/machine/api"
 | 
				
			||||||
	"mayfly-go/internal/machine/application"
 | 
						"mayfly-go/internal/machine/application"
 | 
				
			||||||
	projectapp "mayfly-go/internal/project/application"
 | 
						tagapp "mayfly-go/internal/tag/application"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
@@ -12,7 +12,7 @@ import (
 | 
				
			|||||||
func InitMachineRouter(router *gin.RouterGroup) {
 | 
					func InitMachineRouter(router *gin.RouterGroup) {
 | 
				
			||||||
	m := &api.Machine{
 | 
						m := &api.Machine{
 | 
				
			||||||
		MachineApp: application.GetMachineApp(),
 | 
							MachineApp: application.GetMachineApp(),
 | 
				
			||||||
		ProjectApp: projectapp.GetProjectApp(),
 | 
							TagApp:     tagapp.GetTagTreeApp(),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	machines := router.Group("machines")
 | 
						machines := router.Group("machines")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@ package router
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"mayfly-go/internal/machine/api"
 | 
						"mayfly-go/internal/machine/api"
 | 
				
			||||||
	"mayfly-go/internal/machine/application"
 | 
						"mayfly-go/internal/machine/application"
 | 
				
			||||||
	projectapp "mayfly-go/internal/project/application"
 | 
						tagapp "mayfly-go/internal/tag/application"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
@@ -15,7 +15,7 @@ func InitMachineScriptRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
		ms := &api.MachineScript{
 | 
							ms := &api.MachineScript{
 | 
				
			||||||
			MachineScriptApp: application.GetMachineScriptApp(),
 | 
								MachineScriptApp: application.GetMachineScriptApp(),
 | 
				
			||||||
			MachineApp:       application.GetMachineApp(),
 | 
								MachineApp:       application.GetMachineApp(),
 | 
				
			||||||
			ProjectApp:       projectapp.GetProjectApp(),
 | 
								TagApp:           tagapp.GetTagTreeApp(),
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 获取指定机器脚本列表
 | 
							// 获取指定机器脚本列表
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,10 +6,8 @@ type Mongo struct {
 | 
				
			|||||||
	EnableSshTunnel    int8   `json:"enableSshTunnel"`    // 是否启用ssh隧道
 | 
						EnableSshTunnel    int8   `json:"enableSshTunnel"`    // 是否启用ssh隧道
 | 
				
			||||||
	SshTunnelMachineId uint64 `json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
						SshTunnelMachineId uint64 `json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
				
			||||||
	Name               string `binding:"required" json:"name"`
 | 
						Name               string `binding:"required" json:"name"`
 | 
				
			||||||
	ProjectId          uint64 `binding:"required" json:"projectId"`
 | 
						TagId              uint64 `binding:"required" json:"tagId"`
 | 
				
			||||||
	Project            string `json:"project"`
 | 
						TagPath            string `json:"tagPath"`
 | 
				
			||||||
	Env                string `json:"env"`
 | 
					 | 
				
			||||||
	EnvId              uint64 `binding:"required" json:"envId"`
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type MongoCommand struct {
 | 
					type MongoCommand struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,9 +5,11 @@ import (
 | 
				
			|||||||
	"mayfly-go/internal/mongo/api/form"
 | 
						"mayfly-go/internal/mongo/api/form"
 | 
				
			||||||
	"mayfly-go/internal/mongo/application"
 | 
						"mayfly-go/internal/mongo/application"
 | 
				
			||||||
	"mayfly-go/internal/mongo/domain/entity"
 | 
						"mayfly-go/internal/mongo/domain/entity"
 | 
				
			||||||
 | 
						tagapp "mayfly-go/internal/tag/application"
 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
	"mayfly-go/pkg/ginx"
 | 
						"mayfly-go/pkg/ginx"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
	"mayfly-go/pkg/utils"
 | 
						"mayfly-go/pkg/utils"
 | 
				
			||||||
	"regexp"
 | 
						"regexp"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
@@ -20,15 +22,21 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type Mongo struct {
 | 
					type Mongo struct {
 | 
				
			||||||
	MongoApp application.Mongo
 | 
						MongoApp application.Mongo
 | 
				
			||||||
 | 
						TagApp   tagapp.TagTree
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *Mongo) Mongos(rc *ctx.ReqCtx) {
 | 
					func (m *Mongo) Mongos(rc *ctx.ReqCtx) {
 | 
				
			||||||
	g := rc.GinCtx
 | 
						condition := new(entity.MongoQuery)
 | 
				
			||||||
	mc := &entity.Mongo{EnvId: uint64(ginx.QueryInt(g, "envId", 0)),
 | 
						condition.TagPathLike = rc.GinCtx.Query("tagPath")
 | 
				
			||||||
		ProjectId: uint64(ginx.QueryInt(g, "projectId", 0)),
 | 
					
 | 
				
			||||||
 | 
						// 不存在可访问标签id,即没有可操作数据
 | 
				
			||||||
 | 
						tagIds := m.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
 | 
				
			||||||
 | 
						if len(tagIds) == 0 {
 | 
				
			||||||
 | 
							rc.ResData = model.EmptyPageResult()
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	mc.CreatorId = rc.LoginAccount.Id
 | 
						condition.TagIds = tagIds
 | 
				
			||||||
	rc.ResData = m.MongoApp.GetPageList(mc, ginx.GetPageParam(rc.GinCtx), new([]entity.Mongo))
 | 
						rc.ResData = m.MongoApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]entity.Mongo))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *Mongo) Save(rc *ctx.ReqCtx) {
 | 
					func (m *Mongo) Save(rc *ctx.ReqCtx) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,9 +22,9 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type Mongo interface {
 | 
					type Mongo interface {
 | 
				
			||||||
	// 分页获取机器脚本信息列表
 | 
						// 分页获取机器脚本信息列表
 | 
				
			||||||
	GetPageList(condition *entity.Mongo, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
						GetPageList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Count(condition *entity.Mongo) int64
 | 
						Count(condition *entity.MongoQuery) int64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 根据条件获取
 | 
						// 根据条件获取
 | 
				
			||||||
	GetBy(condition *entity.Mongo, cols ...string) error
 | 
						GetBy(condition *entity.Mongo, cols ...string) error
 | 
				
			||||||
@@ -53,11 +53,11 @@ type mongoAppImpl struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 分页获取数据库信息列表
 | 
					// 分页获取数据库信息列表
 | 
				
			||||||
func (d *mongoAppImpl) GetPageList(condition *entity.Mongo, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					func (d *mongoAppImpl) GetPageList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
				
			||||||
	return d.mongoRepo.GetList(condition, pageParam, toEntity, orderBy...)
 | 
						return d.mongoRepo.GetList(condition, pageParam, toEntity, orderBy...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *mongoAppImpl) Count(condition *entity.Mongo) int64 {
 | 
					func (d *mongoAppImpl) Count(condition *entity.MongoQuery) int64 {
 | 
				
			||||||
	return d.mongoRepo.Count(condition)
 | 
						return d.mongoRepo.Count(condition)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -141,7 +141,7 @@ func DeleteMongoCache(mongoId uint64) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type MongoInstance struct {
 | 
					type MongoInstance struct {
 | 
				
			||||||
	Id                 uint64
 | 
						Id                 uint64
 | 
				
			||||||
	ProjectId          uint64
 | 
						TagPath            string
 | 
				
			||||||
	Cli                *mongo.Client
 | 
						Cli                *mongo.Client
 | 
				
			||||||
	sshTunnelMachineId uint64
 | 
						sshTunnelMachineId uint64
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -160,7 +160,7 @@ func connect(me *entity.Mongo) (*MongoInstance, error) {
 | 
				
			|||||||
	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
 | 
						ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
 | 
				
			||||||
	defer cancel()
 | 
						defer cancel()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mongoInstance := &MongoInstance{Id: me.Id, ProjectId: me.ProjectId}
 | 
						mongoInstance := &MongoInstance{Id: me.Id, TagPath: me.TagPath}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mongoOptions := options.Client().ApplyURI(me.Uri).
 | 
						mongoOptions := options.Client().ApplyURI(me.Uri).
 | 
				
			||||||
		SetMaxPoolSize(1)
 | 
							SetMaxPoolSize(1)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,8 +9,6 @@ type Mongo struct {
 | 
				
			|||||||
	Uri                string `orm:"column(uri)" json:"uri"`
 | 
						Uri                string `orm:"column(uri)" json:"uri"`
 | 
				
			||||||
	EnableSshTunnel    int8   `orm:"column(enable_ssh_tunnel)" json:"enableSshTunnel"`        // 是否启用ssh隧道
 | 
						EnableSshTunnel    int8   `orm:"column(enable_ssh_tunnel)" json:"enableSshTunnel"`        // 是否启用ssh隧道
 | 
				
			||||||
	SshTunnelMachineId uint64 `orm:"column(ssh_tunnel_machine_id)" json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
						SshTunnelMachineId uint64 `orm:"column(ssh_tunnel_machine_id)" json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
				
			||||||
	ProjectId          uint64 `json:"projectId"`
 | 
						TagId              uint64 `json:"tagId"`
 | 
				
			||||||
	Project            string `json:"project"`
 | 
						TagPath            string `json:"tagPath"`
 | 
				
			||||||
	EnvId              uint64 `json:"envId"`
 | 
					 | 
				
			||||||
	Env                string `json:"env"`
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										17
									
								
								server/internal/mongo/domain/entity/query.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								server/internal/mongo/domain/entity/query.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					package entity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "mayfly-go/pkg/model"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type MongoQuery struct {
 | 
				
			||||||
 | 
						model.Model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Name               string
 | 
				
			||||||
 | 
						Uri                string
 | 
				
			||||||
 | 
						EnableSshTunnel    int8   // 是否启用ssh隧道
 | 
				
			||||||
 | 
						SshTunnelMachineId uint64 // ssh隧道机器id
 | 
				
			||||||
 | 
						TagId              uint64 `json:"tagId"`
 | 
				
			||||||
 | 
						TagPath            string `json:"tagPath"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						TagIds      []uint64
 | 
				
			||||||
 | 
						TagPathLike string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -7,9 +7,9 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type Mongo interface {
 | 
					type Mongo interface {
 | 
				
			||||||
	// 分页获取列表
 | 
						// 分页获取列表
 | 
				
			||||||
	GetList(condition *entity.Mongo, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
						GetList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Count(condition *entity.Mongo) int64
 | 
						Count(condition *entity.MongoQuery) int64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 根据条件获取
 | 
						// 根据条件获取
 | 
				
			||||||
	Get(condition *entity.Mongo, cols ...string) error
 | 
						Get(condition *entity.Mongo, cols ...string) error
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,8 @@ import (
 | 
				
			|||||||
	"mayfly-go/internal/mongo/domain/repository"
 | 
						"mayfly-go/internal/mongo/domain/repository"
 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/utils"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type mongoRepoImpl struct{}
 | 
					type mongoRepoImpl struct{}
 | 
				
			||||||
@@ -15,24 +17,28 @@ func newMongoRepo() repository.Mongo {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 分页获取数据库信息列表
 | 
					// 分页获取数据库信息列表
 | 
				
			||||||
func (d *mongoRepoImpl) GetList(condition *entity.Mongo, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					func (d *mongoRepoImpl) GetList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
				
			||||||
	sql := "SELECT d.* FROM t_mongo d JOIN t_project_member pm ON d.project_id = pm.project_id WHERE 1 = 1 "
 | 
						sql := "SELECT d.* FROM t_mongo d WHERE 1=1  "
 | 
				
			||||||
	if condition.CreatorId != 0 {
 | 
					
 | 
				
			||||||
		// 使用创建者id模拟项目成员id
 | 
						if len(condition.TagIds) > 0 {
 | 
				
			||||||
		sql = fmt.Sprintf("%s AND pm.account_id = %d", sql, condition.CreatorId)
 | 
							sql = sql + " AND d.tag_id IN " + fmt.Sprintf("(%s)", strings.Join(utils.NumberArr2StrArr(condition.TagIds), ","))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if condition.ProjectId != 0 {
 | 
						if condition.TagPathLike != "" {
 | 
				
			||||||
		sql = fmt.Sprintf("%s AND d.project_id = %d", sql, condition.ProjectId)
 | 
							sql = sql + " AND d.tag_path LIKE '" + condition.TagPathLike + "%'"
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if condition.EnvId != 0 {
 | 
					 | 
				
			||||||
		sql = fmt.Sprintf("%s AND d.env_id = %d", sql, condition.EnvId)
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	sql = sql + " ORDER BY d.create_time DESC"
 | 
						sql = sql + " ORDER BY d.create_time DESC"
 | 
				
			||||||
	return model.GetPageBySql(sql, pageParam, toEntity)
 | 
						return model.GetPageBySql(sql, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *mongoRepoImpl) Count(condition *entity.Mongo) int64 {
 | 
					func (d *mongoRepoImpl) Count(condition *entity.MongoQuery) int64 {
 | 
				
			||||||
	return model.CountBy(condition)
 | 
						where := make(map[string]interface{})
 | 
				
			||||||
 | 
						if len(condition.TagIds) > 0 {
 | 
				
			||||||
 | 
							where["tag_id"] = condition.TagIds
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if condition.TagId != 0 {
 | 
				
			||||||
 | 
							where["tag_id"] = condition.TagId
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return model.CountByMap(new(entity.Mongo), where)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 根据条件获取
 | 
					// 根据条件获取
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,7 @@ package router
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"mayfly-go/internal/mongo/api"
 | 
						"mayfly-go/internal/mongo/api"
 | 
				
			||||||
	"mayfly-go/internal/mongo/application"
 | 
						"mayfly-go/internal/mongo/application"
 | 
				
			||||||
 | 
						tagapp "mayfly-go/internal/tag/application"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
@@ -13,6 +14,7 @@ func InitMongoRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		ma := &api.Mongo{
 | 
							ma := &api.Mongo{
 | 
				
			||||||
			MongoApp: application.GetMongoApp(),
 | 
								MongoApp: application.GetMongoApp(),
 | 
				
			||||||
 | 
								TagApp:   tagapp.GetTagTreeApp(),
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 获取所有mongo列表
 | 
							// 获取所有mongo列表
 | 
				
			||||||
@@ -60,7 +62,7 @@ func InitMongoRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 执行mongo update by id命令
 | 
							// 执行mongo update by id命令
 | 
				
			||||||
		updateDocById := ctx.NewLogInfo("mongo-更新文档")
 | 
							updateDocById := ctx.NewLogInfo("mongo-更新文档").WithSave(true)
 | 
				
			||||||
		m.POST(":id/command/update-by-id", func(c *gin.Context) {
 | 
							m.POST(":id/command/update-by-id", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).
 | 
								ctx.NewReqCtxWithGin(c).
 | 
				
			||||||
				WithLog(updateDocById).
 | 
									WithLog(updateDocById).
 | 
				
			||||||
@@ -68,7 +70,7 @@ func InitMongoRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 执行mongo delete by id命令
 | 
							// 执行mongo delete by id命令
 | 
				
			||||||
		deleteDoc := ctx.NewLogInfo("mongo-删除文档")
 | 
							deleteDoc := ctx.NewLogInfo("mongo-删除文档").WithSave(true)
 | 
				
			||||||
		m.POST(":id/command/delete-by-id", func(c *gin.Context) {
 | 
							m.POST(":id/command/delete-by-id", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).
 | 
								ctx.NewReqCtxWithGin(c).
 | 
				
			||||||
				WithLog(deleteDoc).
 | 
									WithLog(deleteDoc).
 | 
				
			||||||
@@ -76,7 +78,7 @@ func InitMongoRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 执行mongo insert 命令
 | 
							// 执行mongo insert 命令
 | 
				
			||||||
		insertDoc := ctx.NewLogInfo("mongo-新增文档")
 | 
							insertDoc := ctx.NewLogInfo("mongo-新增文档").WithSave(true)
 | 
				
			||||||
		m.POST(":id/command/insert", func(c *gin.Context) {
 | 
							m.POST(":id/command/insert", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).
 | 
								ctx.NewReqCtxWithGin(c).
 | 
				
			||||||
				WithLog(insertDoc).
 | 
									WithLog(insertDoc).
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,110 +0,0 @@
 | 
				
			|||||||
package api
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"mayfly-go/internal/project/api/vo"
 | 
					 | 
				
			||||||
	projectapp "mayfly-go/internal/project/application"
 | 
					 | 
				
			||||||
	"mayfly-go/internal/project/domain/entity"
 | 
					 | 
				
			||||||
	sys_applicaiton "mayfly-go/internal/sys/application"
 | 
					 | 
				
			||||||
	sys_entity "mayfly-go/internal/sys/domain/entity"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/ginx"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Project struct {
 | 
					 | 
				
			||||||
	ProjectApp projectapp.Project
 | 
					 | 
				
			||||||
	AccountApp sys_applicaiton.Account
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取当前登录用户可以访问的项目列表
 | 
					 | 
				
			||||||
func (p *Project) GetProjectsByLoginAccount(rc *ctx.ReqCtx) {
 | 
					 | 
				
			||||||
	// 获取登录用户拥有的项目ids
 | 
					 | 
				
			||||||
	projectMembers := &[]entity.ProjectMember{}
 | 
					 | 
				
			||||||
	p.ProjectApp.ListMember(&entity.ProjectMember{AccountId: rc.LoginAccount.Id}, projectMembers)
 | 
					 | 
				
			||||||
	var pids []uint64
 | 
					 | 
				
			||||||
	for _, pm := range *projectMembers {
 | 
					 | 
				
			||||||
		pids = append(pids, pm.ProjectId)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 获取项目信息
 | 
					 | 
				
			||||||
	projects := &vo.AccountProjects{}
 | 
					 | 
				
			||||||
	p.ProjectApp.ListProjectByIds(pids, projects)
 | 
					 | 
				
			||||||
	rc.ResData = projects
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *Project) GetProjects(rc *ctx.ReqCtx) {
 | 
					 | 
				
			||||||
	condition := &entity.Project{}
 | 
					 | 
				
			||||||
	ginx.BindQuery(rc.GinCtx, condition)
 | 
					 | 
				
			||||||
	// condition.Name = rc.GinCtx.Query("name")
 | 
					 | 
				
			||||||
	rc.ResData = p.ProjectApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]entity.Project))
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *Project) SaveProject(rc *ctx.ReqCtx) {
 | 
					 | 
				
			||||||
	project := &entity.Project{}
 | 
					 | 
				
			||||||
	ginx.BindJsonAndValid(rc.GinCtx, project)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	rc.ReqParam = fmt.Sprintf("projectId: %d, projectName: %s, remark: %s", project.Id, project.Name, project.Remark)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	project.SetBaseInfo(rc.LoginAccount)
 | 
					 | 
				
			||||||
	p.ProjectApp.SaveProject(project)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *Project) DelProject(rc *ctx.ReqCtx) {
 | 
					 | 
				
			||||||
	p.ProjectApp.DelProject(uint64(ginx.QueryInt(rc.GinCtx, "id", 0)))
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *Project) DelProjectEnv(rc *ctx.ReqCtx) {
 | 
					 | 
				
			||||||
	p.ProjectApp.DelProjectEnv(uint64(ginx.QueryInt(rc.GinCtx, "id", 0)))
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取项目下的环境信息
 | 
					 | 
				
			||||||
func (p *Project) GetProjectEnvs(rc *ctx.ReqCtx) {
 | 
					 | 
				
			||||||
	projectEnvs := &[]entity.ProjectEnv{}
 | 
					 | 
				
			||||||
	p.ProjectApp.ListEnvByProjectId(uint64(ginx.PathParamInt(rc.GinCtx, "projectId")), projectEnvs)
 | 
					 | 
				
			||||||
	rc.ResData = projectEnvs
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 保存项目下的环境信息
 | 
					 | 
				
			||||||
func (p *Project) SaveProjectEnvs(rc *ctx.ReqCtx) {
 | 
					 | 
				
			||||||
	projectEnv := &entity.ProjectEnv{}
 | 
					 | 
				
			||||||
	ginx.BindJsonAndValid(rc.GinCtx, projectEnv)
 | 
					 | 
				
			||||||
	rc.ReqParam = projectEnv
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	projectEnv.SetBaseInfo(rc.LoginAccount)
 | 
					 | 
				
			||||||
	p.ProjectApp.SaveProjectEnv(projectEnv)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 获取项目下的成员信息
 | 
					 | 
				
			||||||
func (p *Project) GetProjectMembers(rc *ctx.ReqCtx) {
 | 
					 | 
				
			||||||
	projectMems := &[]entity.ProjectMember{}
 | 
					 | 
				
			||||||
	rc.ResData = p.ProjectApp.GetMemberPage(&entity.ProjectMember{ProjectId: uint64(ginx.PathParamInt(rc.GinCtx, "projectId"))},
 | 
					 | 
				
			||||||
		ginx.GetPageParam(rc.GinCtx), projectMems)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 保存项目的成员信息
 | 
					 | 
				
			||||||
func (p *Project) SaveProjectMember(rc *ctx.ReqCtx) {
 | 
					 | 
				
			||||||
	projectMem := &entity.ProjectMember{}
 | 
					 | 
				
			||||||
	ginx.BindJsonAndValid(rc.GinCtx, projectMem)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	rc.ReqParam = fmt.Sprintf("projectId: %d, username: %s", projectMem.ProjectId, projectMem.Username)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 校验账号,并赋值username
 | 
					 | 
				
			||||||
	account := &sys_entity.Account{}
 | 
					 | 
				
			||||||
	account.Id = projectMem.AccountId
 | 
					 | 
				
			||||||
	biz.ErrIsNil(p.AccountApp.GetAccount(account, "Id", "Username"), "账号不存在")
 | 
					 | 
				
			||||||
	projectMem.Username = account.Username
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	projectMem.SetBaseInfo(rc.LoginAccount)
 | 
					 | 
				
			||||||
	p.ProjectApp.SaveProjectMember(projectMem)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 删除项目成员
 | 
					 | 
				
			||||||
func (p *Project) DelProjectMember(rc *ctx.ReqCtx) {
 | 
					 | 
				
			||||||
	g := rc.GinCtx
 | 
					 | 
				
			||||||
	pid := ginx.PathParamInt(g, "projectId")
 | 
					 | 
				
			||||||
	aid := ginx.PathParamInt(g, "accountId")
 | 
					 | 
				
			||||||
	rc.ReqParam = fmt.Sprintf("projectId: %d, accountId: %d", pid, aid)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	p.ProjectApp.DeleteMember(uint64(pid), uint64(aid))
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,25 +0,0 @@
 | 
				
			|||||||
package application
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	dbapp "mayfly-go/internal/db/application"
 | 
					 | 
				
			||||||
	machineapp "mayfly-go/internal/machine/application"
 | 
					 | 
				
			||||||
	mongoapp "mayfly-go/internal/mongo/application"
 | 
					 | 
				
			||||||
	"mayfly-go/internal/project/infrastructure/persistence"
 | 
					 | 
				
			||||||
	redisapp "mayfly-go/internal/redis/application"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
var (
 | 
					 | 
				
			||||||
	projectApp Project = newProjectApp(
 | 
					 | 
				
			||||||
		persistence.GetProjectRepo(),
 | 
					 | 
				
			||||||
		persistence.GetProjectEnvRepo(),
 | 
					 | 
				
			||||||
		persistence.GetProjectMemberRepo(),
 | 
					 | 
				
			||||||
		machineapp.GetMachineApp(),
 | 
					 | 
				
			||||||
		redisapp.GetRedisApp(),
 | 
					 | 
				
			||||||
		dbapp.GetDbApp(),
 | 
					 | 
				
			||||||
		mongoapp.GetMongoApp(),
 | 
					 | 
				
			||||||
	)
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func GetProjectApp() Project {
 | 
					 | 
				
			||||||
	return projectApp
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,156 +0,0 @@
 | 
				
			|||||||
package application
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	dbapp "mayfly-go/internal/db/application"
 | 
					 | 
				
			||||||
	dbentity "mayfly-go/internal/db/domain/entity"
 | 
					 | 
				
			||||||
	machineapp "mayfly-go/internal/machine/application"
 | 
					 | 
				
			||||||
	machineentity "mayfly-go/internal/machine/domain/entity"
 | 
					 | 
				
			||||||
	mongoapp "mayfly-go/internal/mongo/application"
 | 
					 | 
				
			||||||
	mongoentity "mayfly-go/internal/mongo/domain/entity"
 | 
					 | 
				
			||||||
	"mayfly-go/internal/project/domain/entity"
 | 
					 | 
				
			||||||
	"mayfly-go/internal/project/domain/repository"
 | 
					 | 
				
			||||||
	redisapp "mayfly-go/internal/redis/application"
 | 
					 | 
				
			||||||
	redisentity "mayfly-go/internal/redis/domain/entity"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Project interface {
 | 
					 | 
				
			||||||
	// 分页获取项目信息列表
 | 
					 | 
				
			||||||
	GetPageList(condition *entity.Project, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	Count(condition *entity.Project) int64
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	ListProjectByIds(ids []uint64, toEntity interface{}, orderBy ...string)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	SaveProject(project *entity.Project)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	DelProject(id uint64)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	DelProjectEnv(id uint64)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 根据项目id获取所有该项目下的环境信息列表
 | 
					 | 
				
			||||||
	ListEnvByProjectId(projectId uint64, listPtr interface{})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 保存项目环境信息
 | 
					 | 
				
			||||||
	SaveProjectEnv(projectEnv *entity.ProjectEnv)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 根据条件获取项目成员信息
 | 
					 | 
				
			||||||
	ListMember(condition *entity.ProjectMember, toEntity interface{}, orderBy ...string)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	SaveProjectMember(pm *entity.ProjectMember)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 根据条件获取项目成员信息
 | 
					 | 
				
			||||||
	GetMemberPage(condition *entity.ProjectMember, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	DeleteMember(projectId, accountId uint64)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 账号是否有权限访问该项目关联的资源信息
 | 
					 | 
				
			||||||
	CanAccess(accountId, projectId uint64) error
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func newProjectApp(projectRepo repository.Project,
 | 
					 | 
				
			||||||
	projectEnvRepo repository.ProjectEnv,
 | 
					 | 
				
			||||||
	projectMemberRepo repository.ProjectMemeber,
 | 
					 | 
				
			||||||
	machineApp machineapp.Machine,
 | 
					 | 
				
			||||||
	redisApp redisapp.Redis,
 | 
					 | 
				
			||||||
	dbApp dbapp.Db,
 | 
					 | 
				
			||||||
	mongoApp mongoapp.Mongo) Project {
 | 
					 | 
				
			||||||
	return &projectAppImpl{
 | 
					 | 
				
			||||||
		projectRepo:       projectRepo,
 | 
					 | 
				
			||||||
		projectEnvRepo:    projectEnvRepo,
 | 
					 | 
				
			||||||
		projectMemberRepo: projectMemberRepo,
 | 
					 | 
				
			||||||
		machineApp:        machineApp,
 | 
					 | 
				
			||||||
		redisApp:          redisApp,
 | 
					 | 
				
			||||||
		dbApp:             dbApp,
 | 
					 | 
				
			||||||
		mongoApp:          mongoApp,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type projectAppImpl struct {
 | 
					 | 
				
			||||||
	projectRepo       repository.Project
 | 
					 | 
				
			||||||
	projectEnvRepo    repository.ProjectEnv
 | 
					 | 
				
			||||||
	projectMemberRepo repository.ProjectMemeber
 | 
					 | 
				
			||||||
	machineApp        machineapp.Machine
 | 
					 | 
				
			||||||
	redisApp          redisapp.Redis
 | 
					 | 
				
			||||||
	mongoApp          mongoapp.Mongo
 | 
					 | 
				
			||||||
	dbApp             dbapp.Db
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 分页获取项目信息列表
 | 
					 | 
				
			||||||
func (p *projectAppImpl) GetPageList(condition *entity.Project, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					 | 
				
			||||||
	return p.projectRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectAppImpl) Count(condition *entity.Project) int64 {
 | 
					 | 
				
			||||||
	return p.projectRepo.Count(condition)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectAppImpl) ListProjectByIds(ids []uint64, toEntity interface{}, orderBy ...string) {
 | 
					 | 
				
			||||||
	p.projectRepo.GetByIdIn(ids, toEntity, orderBy...)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectAppImpl) SaveProject(project *entity.Project) {
 | 
					 | 
				
			||||||
	if project.Id == 0 {
 | 
					 | 
				
			||||||
		p.projectRepo.Save(project)
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		// 防止误传导致项目名更新
 | 
					 | 
				
			||||||
		project.Name = ""
 | 
					 | 
				
			||||||
		p.projectRepo.Update(project)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectAppImpl) DelProject(id uint64) {
 | 
					 | 
				
			||||||
	biz.IsTrue(p.machineApp.Count(&machineentity.Machine{ProjectId: id}) == 0, "请先删除该项目关联的机器信息")
 | 
					 | 
				
			||||||
	biz.IsTrue(p.redisApp.Count(&redisentity.Redis{ProjectId: id}) == 0, "请先删除该项目关联的redis信息")
 | 
					 | 
				
			||||||
	biz.IsTrue(p.dbApp.Count(&dbentity.Db{ProjectId: id}) == 0, "请先删除该项目关联的数据库信息")
 | 
					 | 
				
			||||||
	biz.IsTrue(p.mongoApp.Count(&mongoentity.Mongo{ProjectId: id}) == 0, "请先删除该项目关联的Mongo信息")
 | 
					 | 
				
			||||||
	p.projectRepo.Delete(id)
 | 
					 | 
				
			||||||
	p.projectEnvRepo.DeleteEnvs(id)
 | 
					 | 
				
			||||||
	p.projectMemberRepo.DeleteMems(id)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 根据项目id获取所有该项目下的环境信息列表
 | 
					 | 
				
			||||||
func (p *projectAppImpl) ListEnvByProjectId(projectId uint64, listPtr interface{}) {
 | 
					 | 
				
			||||||
	p.projectEnvRepo.ListEnv(&entity.ProjectEnv{ProjectId: projectId}, listPtr)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 保存项目环境信息
 | 
					 | 
				
			||||||
func (p *projectAppImpl) SaveProjectEnv(projectEnv *entity.ProjectEnv) {
 | 
					 | 
				
			||||||
	p.projectEnvRepo.Save(projectEnv)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 删除项目环境信息
 | 
					 | 
				
			||||||
func (p *projectAppImpl) DelProjectEnv(id uint64) {
 | 
					 | 
				
			||||||
	biz.IsTrue(p.redisApp.Count(&redisentity.Redis{EnvId: id}) == 0, "请先删除该项目环境关联的redis信息")
 | 
					 | 
				
			||||||
	biz.IsTrue(p.dbApp.Count(&dbentity.Db{EnvId: id}) == 0, "请先删除该项目环境关联的数据库信息")
 | 
					 | 
				
			||||||
	biz.IsTrue(p.mongoApp.Count(&mongoentity.Mongo{ProjectId: id}) == 0, "请先删除该项目环境关联的Mongo信息")
 | 
					 | 
				
			||||||
	p.projectEnvRepo.DeleteEnv(id)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 根据条件获取项目成员信息
 | 
					 | 
				
			||||||
func (p *projectAppImpl) ListMember(condition *entity.ProjectMember, toEntity interface{}, orderBy ...string) {
 | 
					 | 
				
			||||||
	p.projectMemberRepo.ListMemeber(condition, toEntity, orderBy...)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectAppImpl) SaveProjectMember(pm *entity.ProjectMember) {
 | 
					 | 
				
			||||||
	pms := new([]entity.ProjectMember)
 | 
					 | 
				
			||||||
	p.ListMember(&entity.ProjectMember{ProjectId: pm.ProjectId, AccountId: pm.AccountId}, pms)
 | 
					 | 
				
			||||||
	biz.IsTrue(len(*pms) == 0, "该成员已存在")
 | 
					 | 
				
			||||||
	p.projectMemberRepo.Save(pm)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectAppImpl) GetMemberPage(condition *entity.ProjectMember, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					 | 
				
			||||||
	return p.projectMemberRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectAppImpl) DeleteMember(projectId, accountId uint64) {
 | 
					 | 
				
			||||||
	p.projectMemberRepo.DeleteByPidMid(projectId, accountId)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectAppImpl) CanAccess(accountId, projectId uint64) error {
 | 
					 | 
				
			||||||
	if p.projectMemberRepo.IsExist(projectId, accountId) {
 | 
					 | 
				
			||||||
		return nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return biz.NewBizErr("您无权操作该资源")
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,11 +0,0 @@
 | 
				
			|||||||
package entity
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import "mayfly-go/pkg/model"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 项目环境
 | 
					 | 
				
			||||||
type ProjectEnv struct {
 | 
					 | 
				
			||||||
	model.Model
 | 
					 | 
				
			||||||
	Name      string `json:"name"`      // 环境名
 | 
					 | 
				
			||||||
	ProjectId uint64 `json:"projectId"` // 项目id
 | 
					 | 
				
			||||||
	Remark    string `json:"remark"`    // 备注说明
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,11 +0,0 @@
 | 
				
			|||||||
package entity
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import "mayfly-go/pkg/model"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 项目成员,用于对项目下组件的访问控制
 | 
					 | 
				
			||||||
type ProjectMember struct {
 | 
					 | 
				
			||||||
	model.Model
 | 
					 | 
				
			||||||
	AccountId uint64 `json:"accountId"` // 账号
 | 
					 | 
				
			||||||
	Username  string `json:"username"`  // 账号用户名
 | 
					 | 
				
			||||||
	ProjectId uint64 `json:"projectId"` // 项目id
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,20 +0,0 @@
 | 
				
			|||||||
package repository
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"mayfly-go/internal/project/domain/entity"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Project interface {
 | 
					 | 
				
			||||||
	GetPageList(condition *entity.Project, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	Count(condition *entity.Project) int64
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	GetByIdIn(ids []uint64, toEntity interface{}, orderBy ...string)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	Save(p *entity.Project)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	Update(project *entity.Project)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	Delete(id uint64)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,14 +0,0 @@
 | 
				
			|||||||
package repository
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import "mayfly-go/internal/project/domain/entity"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type ProjectEnv interface {
 | 
					 | 
				
			||||||
	// 获取项目环境列表
 | 
					 | 
				
			||||||
	ListEnv(condition *entity.ProjectEnv, toEntity interface{}, orderBy ...string)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	Save(entity *entity.ProjectEnv)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	DeleteEnvs(projectId uint64)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	DeleteEnv(envId uint64)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,24 +0,0 @@
 | 
				
			|||||||
package repository
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"mayfly-go/internal/project/domain/entity"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type ProjectMemeber interface {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 获取项目成员列表
 | 
					 | 
				
			||||||
	ListMemeber(condition *entity.ProjectMember, toEntity interface{}, orderBy ...string)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	Save(mp *entity.ProjectMember)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	GetPageList(condition *entity.ProjectMember, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 根据成员id和项目id删除关联关系
 | 
					 | 
				
			||||||
	DeleteByPidMid(projectId, accountId uint64)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	DeleteMems(projectId uint64)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 是否存在指定的项目成员关联信息
 | 
					 | 
				
			||||||
	IsExist(projectId, accountId uint64) bool
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,21 +0,0 @@
 | 
				
			|||||||
package persistence
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import "mayfly-go/internal/project/domain/repository"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
var (
 | 
					 | 
				
			||||||
	projectRepo       repository.Project        = newProjectRepo()
 | 
					 | 
				
			||||||
	projectEnvRepo    repository.ProjectEnv     = newProjectEnvRepo()
 | 
					 | 
				
			||||||
	projectMemberRepo repository.ProjectMemeber = newProjectMemberRepo()
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func GetProjectRepo() repository.Project {
 | 
					 | 
				
			||||||
	return projectRepo
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func GetProjectEnvRepo() repository.ProjectEnv {
 | 
					 | 
				
			||||||
	return projectEnvRepo
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func GetProjectMemberRepo() repository.ProjectMemeber {
 | 
					 | 
				
			||||||
	return projectMemberRepo
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,38 +0,0 @@
 | 
				
			|||||||
package persistence
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"mayfly-go/internal/project/domain/entity"
 | 
					 | 
				
			||||||
	"mayfly-go/internal/project/domain/repository"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type projectRepoImpl struct{}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func newProjectRepo() repository.Project {
 | 
					 | 
				
			||||||
	return new(projectRepoImpl)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectRepoImpl) GetPageList(condition *entity.Project, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					 | 
				
			||||||
	return model.GetPage(pageParam, condition, toEntity, orderBy...)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectRepoImpl) Count(condition *entity.Project) int64 {
 | 
					 | 
				
			||||||
	return model.CountBy(condition)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectRepoImpl) GetByIdIn(ids []uint64, toEntity interface{}, orderBy ...string) {
 | 
					 | 
				
			||||||
	model.GetByIdIn(new(entity.Project), toEntity, ids, orderBy...)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectRepoImpl) Save(project *entity.Project) {
 | 
					 | 
				
			||||||
	biz.ErrIsNil(model.Insert(project), "保存项目失败")
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectRepoImpl) Update(project *entity.Project) {
 | 
					 | 
				
			||||||
	biz.ErrIsNil(model.UpdateById(project), "更新项目信息")
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectRepoImpl) Delete(id uint64) {
 | 
					 | 
				
			||||||
	model.DeleteById(new(entity.Project), id)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,30 +0,0 @@
 | 
				
			|||||||
package persistence
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"mayfly-go/internal/project/domain/entity"
 | 
					 | 
				
			||||||
	"mayfly-go/internal/project/domain/repository"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type projectEnvRepoImpl struct{}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func newProjectEnvRepo() repository.ProjectEnv {
 | 
					 | 
				
			||||||
	return new(projectEnvRepoImpl)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectEnvRepoImpl) ListEnv(condition *entity.ProjectEnv, toEntity interface{}, orderBy ...string) {
 | 
					 | 
				
			||||||
	model.ListByOrder(condition, toEntity, orderBy...)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectEnvRepoImpl) Save(entity *entity.ProjectEnv) {
 | 
					 | 
				
			||||||
	biz.ErrIsNilAppendErr(model.Insert(entity), "保存环境失败:%s")
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectEnvRepoImpl) DeleteEnvs(projectId uint64) {
 | 
					 | 
				
			||||||
	model.DeleteByCondition(&entity.ProjectEnv{ProjectId: projectId})
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectEnvRepoImpl) DeleteEnv(envId uint64) {
 | 
					 | 
				
			||||||
	model.DeleteById(new(entity.ProjectEnv), envId)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,38 +0,0 @@
 | 
				
			|||||||
package persistence
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"mayfly-go/internal/project/domain/entity"
 | 
					 | 
				
			||||||
	"mayfly-go/internal/project/domain/repository"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type projectMemberRepoImpl struct{}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func newProjectMemberRepo() repository.ProjectMemeber {
 | 
					 | 
				
			||||||
	return new(projectMemberRepoImpl)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectMemberRepoImpl) ListMemeber(condition *entity.ProjectMember, toEntity interface{}, orderBy ...string) {
 | 
					 | 
				
			||||||
	model.ListByOrder(condition, toEntity, orderBy...)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectMemberRepoImpl) Save(pm *entity.ProjectMember) {
 | 
					 | 
				
			||||||
	biz.ErrIsNilAppendErr(model.Insert(pm), "保存项目成员失败:%s")
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectMemberRepoImpl) GetPageList(condition *entity.ProjectMember, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					 | 
				
			||||||
	return model.GetPage(pageParam, condition, toEntity, orderBy...)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectMemberRepoImpl) DeleteByPidMid(projectId, accountId uint64) {
 | 
					 | 
				
			||||||
	model.DeleteByCondition(&entity.ProjectMember{ProjectId: projectId, AccountId: accountId})
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectMemberRepoImpl) DeleteMems(projectId uint64) {
 | 
					 | 
				
			||||||
	model.DeleteByCondition(&entity.ProjectMember{ProjectId: projectId})
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *projectMemberRepoImpl) IsExist(projectId, accountId uint64) bool {
 | 
					 | 
				
			||||||
	return model.CountBy(&entity.ProjectMember{ProjectId: projectId, AccountId: accountId}) > 0
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,90 +0,0 @@
 | 
				
			|||||||
package router
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"mayfly-go/internal/project/api"
 | 
					 | 
				
			||||||
	projectapp "mayfly-go/internal/project/application"
 | 
					 | 
				
			||||||
	sysapp "mayfly-go/internal/sys/application"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func InitProjectRouter(router *gin.RouterGroup) {
 | 
					 | 
				
			||||||
	m := &api.Project{
 | 
					 | 
				
			||||||
		ProjectApp: projectapp.GetProjectApp(),
 | 
					 | 
				
			||||||
		AccountApp: sysapp.GetAccountApp()}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	project := router.Group("/projects")
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		router.GET("/accounts/projects", func(c *gin.Context) {
 | 
					 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).Handle(m.GetProjectsByLoginAccount)
 | 
					 | 
				
			||||||
		})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// 获取项目列表
 | 
					 | 
				
			||||||
		project.GET("", func(c *gin.Context) {
 | 
					 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).Handle(m.GetProjects)
 | 
					 | 
				
			||||||
		})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		saveProjectLog := ctx.NewLogInfo("保存项目信息").WithSave(true)
 | 
					 | 
				
			||||||
		savePP := ctx.NewPermission("project:save")
 | 
					 | 
				
			||||||
		// 保存项目下的环境信息
 | 
					 | 
				
			||||||
		project.POST("", func(c *gin.Context) {
 | 
					 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(saveProjectLog).
 | 
					 | 
				
			||||||
				WithRequiredPermission(savePP).
 | 
					 | 
				
			||||||
				Handle(m.SaveProject)
 | 
					 | 
				
			||||||
		})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		delProjectLog := ctx.NewLogInfo("删除项目信息").WithSave(true)
 | 
					 | 
				
			||||||
		delPP := ctx.NewPermission("project:del")
 | 
					 | 
				
			||||||
		// 删除项目
 | 
					 | 
				
			||||||
		project.DELETE("", func(c *gin.Context) {
 | 
					 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(delProjectLog).
 | 
					 | 
				
			||||||
				WithRequiredPermission(delPP).
 | 
					 | 
				
			||||||
				Handle(m.DelProject)
 | 
					 | 
				
			||||||
		})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// 获取项目下的环境信息列表
 | 
					 | 
				
			||||||
		project.GET("/:projectId/envs", func(c *gin.Context) {
 | 
					 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).Handle(m.GetProjectEnvs)
 | 
					 | 
				
			||||||
		})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		saveProjectEnvLog := ctx.NewLogInfo("新增项目环境信息").WithSave(true)
 | 
					 | 
				
			||||||
		savePeP := ctx.NewPermission("project:env:add")
 | 
					 | 
				
			||||||
		// 保存项目下的环境信息
 | 
					 | 
				
			||||||
		project.POST("/:projectId/envs", func(c *gin.Context) {
 | 
					 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(saveProjectEnvLog).
 | 
					 | 
				
			||||||
				WithRequiredPermission(savePeP).
 | 
					 | 
				
			||||||
				Handle(m.SaveProjectEnvs)
 | 
					 | 
				
			||||||
		})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		delProjectEnvLog := ctx.NewLogInfo("删除项目环境信息").WithSave(true)
 | 
					 | 
				
			||||||
		project.DELETE("/envs", func(c *gin.Context) {
 | 
					 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(delProjectEnvLog).
 | 
					 | 
				
			||||||
				WithRequiredPermission(delPP).
 | 
					 | 
				
			||||||
				Handle(m.DelProjectEnv)
 | 
					 | 
				
			||||||
		})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// 获取项目下的成员信息列表
 | 
					 | 
				
			||||||
		project.GET("/:projectId/members", func(c *gin.Context) {
 | 
					 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).Handle(m.GetProjectMembers)
 | 
					 | 
				
			||||||
		})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// 保存项目成员
 | 
					 | 
				
			||||||
		saveProjectMemLog := ctx.NewLogInfo("新增项目成员").WithSave(true)
 | 
					 | 
				
			||||||
		savePmP := ctx.NewPermission("project:member:add")
 | 
					 | 
				
			||||||
		project.POST("/:projectId/members", func(c *gin.Context) {
 | 
					 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(saveProjectMemLog).
 | 
					 | 
				
			||||||
				WithRequiredPermission(savePmP).
 | 
					 | 
				
			||||||
				Handle(m.SaveProjectMember)
 | 
					 | 
				
			||||||
		})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// 删除项目成员
 | 
					 | 
				
			||||||
		delProjectMemLog := ctx.NewLogInfo("删除项目成员").WithSave(true)
 | 
					 | 
				
			||||||
		savePmdP := ctx.NewPermission("project:member:del")
 | 
					 | 
				
			||||||
		project.DELETE("/:projectId/members/:accountId", func(c *gin.Context) {
 | 
					 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(delProjectMemLog).
 | 
					 | 
				
			||||||
				WithRequiredPermission(savePmdP).
 | 
					 | 
				
			||||||
				Handle(m.DelProjectMember)
 | 
					 | 
				
			||||||
		})
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -2,16 +2,15 @@ package form
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type Redis struct {
 | 
					type Redis struct {
 | 
				
			||||||
	Id                 uint64
 | 
						Id                 uint64
 | 
				
			||||||
 | 
						Name               string `json:"name"`
 | 
				
			||||||
	Host               string `binding:"required" json:"host"`
 | 
						Host               string `binding:"required" json:"host"`
 | 
				
			||||||
	Password           string `json:"password"`
 | 
						Password           string `json:"password"`
 | 
				
			||||||
	Mode               string `json:"mode"`
 | 
						Mode               string `json:"mode"`
 | 
				
			||||||
	Db                 string `json:"db"`
 | 
						Db                 string `json:"db"`
 | 
				
			||||||
	EnableSshTunnel    int8   `json:"enableSshTunnel"`    // 是否启用ssh隧道
 | 
						EnableSshTunnel    int8   `json:"enableSshTunnel"`    // 是否启用ssh隧道
 | 
				
			||||||
	SshTunnelMachineId uint64 `json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
						SshTunnelMachineId uint64 `json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
				
			||||||
	ProjectId          uint64 `binding:"required" json:"projectId"`
 | 
						TagId              uint64 `binding:"required" json:"tagId"`
 | 
				
			||||||
	Project            string `json:"project"`
 | 
						TagPath            string `json:"tagPath"`
 | 
				
			||||||
	Env                string `json:"env"`
 | 
					 | 
				
			||||||
	EnvId              uint64 `binding:"required" json:"envId"`
 | 
					 | 
				
			||||||
	Remark             string `json:"remark"`
 | 
						Remark             string `json:"remark"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,14 +2,15 @@ package api
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	projectapp "mayfly-go/internal/project/application"
 | 
					 | 
				
			||||||
	"mayfly-go/internal/redis/api/form"
 | 
						"mayfly-go/internal/redis/api/form"
 | 
				
			||||||
	"mayfly-go/internal/redis/api/vo"
 | 
						"mayfly-go/internal/redis/api/vo"
 | 
				
			||||||
	"mayfly-go/internal/redis/application"
 | 
						"mayfly-go/internal/redis/application"
 | 
				
			||||||
	"mayfly-go/internal/redis/domain/entity"
 | 
						"mayfly-go/internal/redis/domain/entity"
 | 
				
			||||||
 | 
						tagapp "mayfly-go/internal/tag/application"
 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
	"mayfly-go/pkg/ginx"
 | 
						"mayfly-go/pkg/ginx"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
	"mayfly-go/pkg/utils"
 | 
						"mayfly-go/pkg/utils"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
@@ -20,17 +21,22 @@ import (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Redis struct {
 | 
					type Redis struct {
 | 
				
			||||||
	RedisApp   application.Redis
 | 
						RedisApp application.Redis
 | 
				
			||||||
	ProjectApp projectapp.Project
 | 
						TagApp   tagapp.TagTree
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (r *Redis) RedisList(rc *ctx.ReqCtx) {
 | 
					func (r *Redis) RedisList(rc *ctx.ReqCtx) {
 | 
				
			||||||
	g := rc.GinCtx
 | 
						condition := new(entity.RedisQuery)
 | 
				
			||||||
	m := &entity.Redis{EnvId: uint64(ginx.QueryInt(g, "envId", 0)),
 | 
						condition.TagPathLike = rc.GinCtx.Query("tagPath")
 | 
				
			||||||
		ProjectId: uint64(ginx.QueryInt(g, "projectId", 0)),
 | 
					
 | 
				
			||||||
 | 
						// 不存在可访问标签id,即没有可操作数据
 | 
				
			||||||
 | 
						tagIds := r.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
 | 
				
			||||||
 | 
						if len(tagIds) == 0 {
 | 
				
			||||||
 | 
							rc.ResData = model.EmptyPageResult()
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	m.CreatorId = rc.LoginAccount.Id
 | 
						condition.TagIds = tagIds
 | 
				
			||||||
	rc.ResData = r.RedisApp.GetPageList(m, ginx.GetPageParam(rc.GinCtx), new([]vo.Redis))
 | 
						rc.ResData = r.RedisApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]vo.Redis))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (r *Redis) Save(rc *ctx.ReqCtx) {
 | 
					func (r *Redis) Save(rc *ctx.ReqCtx) {
 | 
				
			||||||
@@ -184,7 +190,7 @@ func (r *Redis) ClusterInfo(rc *ctx.ReqCtx) {
 | 
				
			|||||||
func (r *Redis) Scan(rc *ctx.ReqCtx) {
 | 
					func (r *Redis) Scan(rc *ctx.ReqCtx) {
 | 
				
			||||||
	g := rc.GinCtx
 | 
						g := rc.GinCtx
 | 
				
			||||||
	ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), ginx.PathParamInt(g, "db"))
 | 
						ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), ginx.PathParamInt(g, "db"))
 | 
				
			||||||
	biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
 | 
						biz.ErrIsNilAppendErr(r.TagApp.CanAccess(rc.LoginAccount.Id, ri.TagPath), "%s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	form := &form.RedisScanForm{}
 | 
						form := &form.RedisScanForm{}
 | 
				
			||||||
	ginx.BindJsonAndValid(rc.GinCtx, form)
 | 
						ginx.BindJsonAndValid(rc.GinCtx, form)
 | 
				
			||||||
@@ -263,7 +269,7 @@ func (r *Redis) DeleteKey(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	biz.NotEmpty(key, "key不能为空")
 | 
						biz.NotEmpty(key, "key不能为空")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), ginx.PathParamInt(g, "db"))
 | 
						ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), ginx.PathParamInt(g, "db"))
 | 
				
			||||||
	biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
 | 
						biz.ErrIsNilAppendErr(r.TagApp.CanAccess(rc.LoginAccount.Id, ri.TagPath), "%s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rc.ReqParam = key
 | 
						rc.ReqParam = key
 | 
				
			||||||
	ri.GetCmdable().Del(context.Background(), key)
 | 
						ri.GetCmdable().Del(context.Background(), key)
 | 
				
			||||||
@@ -275,7 +281,7 @@ func (r *Redis) checkKey(rc *ctx.ReqCtx) (*application.RedisInstance, string) {
 | 
				
			|||||||
	biz.NotEmpty(key, "key不能为空")
 | 
						biz.NotEmpty(key, "key不能为空")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), ginx.PathParamInt(g, "db"))
 | 
						ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), ginx.PathParamInt(g, "db"))
 | 
				
			||||||
	biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
 | 
						biz.ErrIsNilAppendErr(r.TagApp.CanAccess(rc.LoginAccount.Id, ri.TagPath), "%s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return ri, key
 | 
						return ri, key
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -293,7 +299,7 @@ func (r *Redis) SetStringValue(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	ginx.BindJsonAndValid(g, keyValue)
 | 
						ginx.BindJsonAndValid(g, keyValue)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), ginx.PathParamInt(g, "db"))
 | 
						ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), ginx.PathParamInt(g, "db"))
 | 
				
			||||||
	biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
 | 
						biz.ErrIsNilAppendErr(r.TagApp.CanAccess(rc.LoginAccount.Id, ri.TagPath), "%s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	str, err := ri.GetCmdable().Set(context.TODO(), keyValue.Key, keyValue.Value, time.Second*time.Duration(keyValue.Timed)).Result()
 | 
						str, err := ri.GetCmdable().Set(context.TODO(), keyValue.Key, keyValue.Value, time.Second*time.Duration(keyValue.Timed)).Result()
 | 
				
			||||||
	biz.ErrIsNilAppendErr(err, "保存字符串值失败: %s")
 | 
						biz.ErrIsNilAppendErr(err, "保存字符串值失败: %s")
 | 
				
			||||||
@@ -345,7 +351,7 @@ func (r *Redis) SetHashValue(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	ginx.BindJsonAndValid(g, hashValue)
 | 
						ginx.BindJsonAndValid(g, hashValue)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), ginx.PathParamInt(g, "db"))
 | 
						ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), ginx.PathParamInt(g, "db"))
 | 
				
			||||||
	biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
 | 
						biz.ErrIsNilAppendErr(r.TagApp.CanAccess(rc.LoginAccount.Id, ri.TagPath), "%s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cmd := ri.GetCmdable()
 | 
						cmd := ri.GetCmdable()
 | 
				
			||||||
	key := hashValue.Key
 | 
						key := hashValue.Key
 | 
				
			||||||
@@ -372,7 +378,7 @@ func (r *Redis) SetSetValue(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	ginx.BindJsonAndValid(g, keyvalue)
 | 
						ginx.BindJsonAndValid(g, keyvalue)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), ginx.PathParamInt(g, "db"))
 | 
						ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), ginx.PathParamInt(g, "db"))
 | 
				
			||||||
	biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
 | 
						biz.ErrIsNilAppendErr(r.TagApp.CanAccess(rc.LoginAccount.Id, ri.TagPath), "%s")
 | 
				
			||||||
	cmd := ri.GetCmdable()
 | 
						cmd := ri.GetCmdable()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	key := keyvalue.Key
 | 
						key := keyvalue.Key
 | 
				
			||||||
@@ -411,7 +417,7 @@ func (r *Redis) SaveListValue(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	ginx.BindJsonAndValid(g, listValue)
 | 
						ginx.BindJsonAndValid(g, listValue)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), ginx.PathParamInt(g, "db"))
 | 
						ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), ginx.PathParamInt(g, "db"))
 | 
				
			||||||
	biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
 | 
						biz.ErrIsNilAppendErr(r.TagApp.CanAccess(rc.LoginAccount.Id, ri.TagPath), "%s")
 | 
				
			||||||
	cmd := ri.GetCmdable()
 | 
						cmd := ri.GetCmdable()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	key := listValue.Key
 | 
						key := listValue.Key
 | 
				
			||||||
@@ -431,7 +437,7 @@ func (r *Redis) SetListValue(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	ginx.BindJsonAndValid(g, listSetValue)
 | 
						ginx.BindJsonAndValid(g, listSetValue)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), ginx.PathParamInt(g, "db"))
 | 
						ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), ginx.PathParamInt(g, "db"))
 | 
				
			||||||
	biz.ErrIsNilAppendErr(r.ProjectApp.CanAccess(rc.LoginAccount.Id, ri.ProjectId), "%s")
 | 
						biz.ErrIsNilAppendErr(r.TagApp.CanAccess(rc.LoginAccount.Id, ri.TagPath), "%s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_, err := ri.GetCmdable().LSet(context.TODO(), listSetValue.Key, listSetValue.Index, listSetValue.Value).Result()
 | 
						_, err := ri.GetCmdable().LSet(context.TODO(), listSetValue.Key, listSetValue.Index, listSetValue.Value).Result()
 | 
				
			||||||
	biz.ErrIsNilAppendErr(err, "list set失败: %s")
 | 
						biz.ErrIsNilAppendErr(err, "list set失败: %s")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,8 +3,8 @@ package vo
 | 
				
			|||||||
import "time"
 | 
					import "time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Redis struct {
 | 
					type Redis struct {
 | 
				
			||||||
	Id *int64 `json:"id"`
 | 
						Id                 *int64     `json:"id"`
 | 
				
			||||||
	// Name       *string    `json:"name"`
 | 
						Name               *string    `json:"name"`
 | 
				
			||||||
	Host               *string    `json:"host"`
 | 
						Host               *string    `json:"host"`
 | 
				
			||||||
	Db                 string     `json:"db"`
 | 
						Db                 string     `json:"db"`
 | 
				
			||||||
	ProjectId          *int64     `json:"projectId"`
 | 
						ProjectId          *int64     `json:"projectId"`
 | 
				
			||||||
@@ -13,8 +13,8 @@ type Redis struct {
 | 
				
			|||||||
	EnableSshTunnel    *int8      `json:"enableSshTunnel"`    // 是否启用ssh隧道
 | 
						EnableSshTunnel    *int8      `json:"enableSshTunnel"`    // 是否启用ssh隧道
 | 
				
			||||||
	SshTunnelMachineId *uint64    `json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
						SshTunnelMachineId *uint64    `json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
				
			||||||
	Remark             *string    `json:"remark"`
 | 
						Remark             *string    `json:"remark"`
 | 
				
			||||||
	Env                *string    `json:"env"`
 | 
						TagId              *uint64    `json:"tagId"`
 | 
				
			||||||
	EnvId              *int64     `json:"envId"`
 | 
						TagPath            *string    `json:"tagPath"`
 | 
				
			||||||
	CreateTime         *time.Time `json:"createTime"`
 | 
						CreateTime         *time.Time `json:"createTime"`
 | 
				
			||||||
	Creator            *string    `json:"creator"`
 | 
						Creator            *string    `json:"creator"`
 | 
				
			||||||
	CreatorId          *int64     `json:"creatorId"`
 | 
						CreatorId          *int64     `json:"creatorId"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,9 +23,9 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type Redis interface {
 | 
					type Redis interface {
 | 
				
			||||||
	// 分页获取机器脚本信息列表
 | 
						// 分页获取机器脚本信息列表
 | 
				
			||||||
	GetPageList(condition *entity.Redis, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
						GetPageList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Count(condition *entity.Redis) int64
 | 
						Count(condition *entity.RedisQuery) int64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 根据id获取
 | 
						// 根据id获取
 | 
				
			||||||
	GetById(id uint64, cols ...string) *entity.Redis
 | 
						GetById(id uint64, cols ...string) *entity.Redis
 | 
				
			||||||
@@ -55,11 +55,11 @@ type redisAppImpl struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 分页获取机器脚本信息列表
 | 
					// 分页获取机器脚本信息列表
 | 
				
			||||||
func (r *redisAppImpl) GetPageList(condition *entity.Redis, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					func (r *redisAppImpl) GetPageList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
				
			||||||
	return r.redisRepo.GetRedisList(condition, pageParam, toEntity, orderBy...)
 | 
						return r.redisRepo.GetRedisList(condition, pageParam, toEntity, orderBy...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (r *redisAppImpl) Count(condition *entity.Redis) int64 {
 | 
					func (r *redisAppImpl) Count(condition *entity.RedisQuery) int64 {
 | 
				
			||||||
	return r.redisRepo.Count(condition)
 | 
						return r.redisRepo.Count(condition)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -172,7 +172,7 @@ func getRedisCacheKey(id uint64, db int) string {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func getRedisCient(re *entity.Redis, db int) *RedisInstance {
 | 
					func getRedisCient(re *entity.Redis, db int) *RedisInstance {
 | 
				
			||||||
	ri := &RedisInstance{Id: getRedisCacheKey(re.Id, db), ProjectId: re.ProjectId, Mode: re.Mode}
 | 
						ri := &RedisInstance{Id: getRedisCacheKey(re.Id, db), TagPath: re.TagPath, Mode: re.Mode}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	redisOptions := &redis.Options{
 | 
						redisOptions := &redis.Options{
 | 
				
			||||||
		Addr:         re.Host,
 | 
							Addr:         re.Host,
 | 
				
			||||||
@@ -191,7 +191,7 @@ func getRedisCient(re *entity.Redis, db int) *RedisInstance {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func getRedisClusterClient(re *entity.Redis) *RedisInstance {
 | 
					func getRedisClusterClient(re *entity.Redis) *RedisInstance {
 | 
				
			||||||
	ri := &RedisInstance{Id: getRedisCacheKey(re.Id, 0), ProjectId: re.ProjectId, Mode: re.Mode}
 | 
						ri := &RedisInstance{Id: getRedisCacheKey(re.Id, 0), TagPath: re.TagPath, Mode: re.Mode}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	redisClusterOptions := &redis.ClusterOptions{
 | 
						redisClusterOptions := &redis.ClusterOptions{
 | 
				
			||||||
		Addrs:       strings.Split(re.Host, ","),
 | 
							Addrs:       strings.Split(re.Host, ","),
 | 
				
			||||||
@@ -207,7 +207,7 @@ func getRedisClusterClient(re *entity.Redis) *RedisInstance {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func getRedisSentinelCient(re *entity.Redis, db int) *RedisInstance {
 | 
					func getRedisSentinelCient(re *entity.Redis, db int) *RedisInstance {
 | 
				
			||||||
	ri := &RedisInstance{Id: getRedisCacheKey(re.Id, db), ProjectId: re.ProjectId, Mode: re.Mode}
 | 
						ri := &RedisInstance{Id: getRedisCacheKey(re.Id, db), TagPath: re.TagPath, Mode: re.Mode}
 | 
				
			||||||
	// sentinel模式host为 masterName=host:port,host:port
 | 
						// sentinel模式host为 masterName=host:port,host:port
 | 
				
			||||||
	masterNameAndHosts := strings.Split(re.Host, "=")
 | 
						masterNameAndHosts := strings.Split(re.Host, "=")
 | 
				
			||||||
	sentinelOptions := &redis.FailoverOptions{
 | 
						sentinelOptions := &redis.FailoverOptions{
 | 
				
			||||||
@@ -245,7 +245,7 @@ func getRedisDialer(machineId uint64) func(ctx context.Context, network, addr st
 | 
				
			|||||||
var redisCache = cache.NewTimedCache(constant.RedisConnExpireTime, 5*time.Second).
 | 
					var redisCache = cache.NewTimedCache(constant.RedisConnExpireTime, 5*time.Second).
 | 
				
			||||||
	WithUpdateAccessTime(true).
 | 
						WithUpdateAccessTime(true).
 | 
				
			||||||
	OnEvicted(func(key interface{}, value interface{}) {
 | 
						OnEvicted(func(key interface{}, value interface{}) {
 | 
				
			||||||
		global.Log.Info(fmt.Sprintf("删除redis连接缓存 id = %d", key))
 | 
							global.Log.Info(fmt.Sprintf("删除redis连接缓存 id = %s", key))
 | 
				
			||||||
		value.(*RedisInstance).Close()
 | 
							value.(*RedisInstance).Close()
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -294,7 +294,7 @@ func TestRedisConnection(re *entity.Redis) {
 | 
				
			|||||||
// redis实例
 | 
					// redis实例
 | 
				
			||||||
type RedisInstance struct {
 | 
					type RedisInstance struct {
 | 
				
			||||||
	Id                 string
 | 
						Id                 string
 | 
				
			||||||
	ProjectId          uint64
 | 
						TagPath            string
 | 
				
			||||||
	Mode               string
 | 
						Mode               string
 | 
				
			||||||
	Cli                *redis.Client
 | 
						Cli                *redis.Client
 | 
				
			||||||
	ClusterCli         *redis.ClusterClient
 | 
						ClusterCli         *redis.ClusterClient
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										20
									
								
								server/internal/redis/domain/entity/query.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								server/internal/redis/domain/entity/query.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
				
			|||||||
 | 
					package entity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "mayfly-go/pkg/model"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type RedisQuery struct {
 | 
				
			||||||
 | 
						model.Model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Name               string `orm:"column(name)" json:"name"`
 | 
				
			||||||
 | 
						Host               string `orm:"column(host)" json:"host"`
 | 
				
			||||||
 | 
						Mode               string `json:"mode"`
 | 
				
			||||||
 | 
						Password           string `orm:"column(password)" json:"-"`
 | 
				
			||||||
 | 
						Db                 string `orm:"column(database)" json:"db"`
 | 
				
			||||||
 | 
						EnableSshTunnel    int8   `orm:"column(enable_ssh_tunnel)" json:"enableSshTunnel"`        // 是否启用ssh隧道
 | 
				
			||||||
 | 
						SshTunnelMachineId uint64 `orm:"column(ssh_tunnel_machine_id)" json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
				
			||||||
 | 
						Remark             string
 | 
				
			||||||
 | 
						TagId              uint64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						TagIds      []uint64
 | 
				
			||||||
 | 
						TagPathLike string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -8,6 +8,7 @@ import (
 | 
				
			|||||||
type Redis struct {
 | 
					type Redis struct {
 | 
				
			||||||
	model.Model
 | 
						model.Model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Name               string `orm:"column(name)" json:"name"`
 | 
				
			||||||
	Host               string `orm:"column(host)" json:"host"`
 | 
						Host               string `orm:"column(host)" json:"host"`
 | 
				
			||||||
	Mode               string `json:"mode"`
 | 
						Mode               string `json:"mode"`
 | 
				
			||||||
	Password           string `orm:"column(password)" json:"-"`
 | 
						Password           string `orm:"column(password)" json:"-"`
 | 
				
			||||||
@@ -15,10 +16,8 @@ type Redis struct {
 | 
				
			|||||||
	EnableSshTunnel    int8   `orm:"column(enable_ssh_tunnel)" json:"enableSshTunnel"`        // 是否启用ssh隧道
 | 
						EnableSshTunnel    int8   `orm:"column(enable_ssh_tunnel)" json:"enableSshTunnel"`        // 是否启用ssh隧道
 | 
				
			||||||
	SshTunnelMachineId uint64 `orm:"column(ssh_tunnel_machine_id)" json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
						SshTunnelMachineId uint64 `orm:"column(ssh_tunnel_machine_id)" json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
				
			||||||
	Remark             string
 | 
						Remark             string
 | 
				
			||||||
	ProjectId          uint64
 | 
						TagId              uint64
 | 
				
			||||||
	Project            string
 | 
						TagPath            string
 | 
				
			||||||
	EnvId              uint64
 | 
					 | 
				
			||||||
	Env                string
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,9 +7,9 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type Redis interface {
 | 
					type Redis interface {
 | 
				
			||||||
	// 分页获取机器信息列表
 | 
						// 分页获取机器信息列表
 | 
				
			||||||
	GetRedisList(condition *entity.Redis, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
						GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Count(condition *entity.Redis) int64
 | 
						Count(condition *entity.RedisQuery) int64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 根据id获取
 | 
						// 根据id获取
 | 
				
			||||||
	GetById(id uint64, cols ...string) *entity.Redis
 | 
						GetById(id uint64, cols ...string) *entity.Redis
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,8 @@ import (
 | 
				
			|||||||
	"mayfly-go/internal/redis/domain/repository"
 | 
						"mayfly-go/internal/redis/domain/repository"
 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/utils"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type redisRepoImpl struct{}
 | 
					type redisRepoImpl struct{}
 | 
				
			||||||
@@ -15,27 +17,32 @@ func newRedisRepo() repository.Redis {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 分页获取机器信息列表
 | 
					// 分页获取机器信息列表
 | 
				
			||||||
func (r *redisRepoImpl) GetRedisList(condition *entity.Redis, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					func (r *redisRepoImpl) GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
				
			||||||
	sql := "SELECT d.* FROM t_redis d JOIN t_project_member pm ON d.project_id = pm.project_id WHERE 1 = 1 "
 | 
						sql := "SELECT d.* FROM t_redis d WHERE 1=1  "
 | 
				
			||||||
	if condition.CreatorId != 0 {
 | 
					
 | 
				
			||||||
		// 使用创建者id模拟项目成员id
 | 
					 | 
				
			||||||
		sql = fmt.Sprintf("%s AND pm.account_id = %d", sql, condition.CreatorId)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if condition.ProjectId != 0 {
 | 
					 | 
				
			||||||
		sql = fmt.Sprintf("%s AND d.project_id = %d", sql, condition.ProjectId)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if condition.EnvId != 0 {
 | 
					 | 
				
			||||||
		sql = fmt.Sprintf("%s AND d.env_id = %d", sql, condition.EnvId)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if condition.Host != "" {
 | 
						if condition.Host != "" {
 | 
				
			||||||
		sql = sql + " AND d.host LIKE '%" + condition.Host + "%'"
 | 
							sql = sql + " AND d.host LIKE '%" + condition.Host + "%'"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if len(condition.TagIds) > 0 {
 | 
				
			||||||
 | 
							sql = sql + " AND d.tag_id IN " + fmt.Sprintf("(%s)", strings.Join(utils.NumberArr2StrArr(condition.TagIds), ","))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if condition.TagPathLike != "" {
 | 
				
			||||||
 | 
							sql = sql + " AND d.tag_path LIKE '" + condition.TagPathLike + "%'"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	sql = sql + " ORDER BY d.create_time DESC"
 | 
						sql = sql + " ORDER BY d.create_time DESC"
 | 
				
			||||||
	return model.GetPageBySql(sql, pageParam, toEntity)
 | 
						return model.GetPageBySql(sql, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (r *redisRepoImpl) Count(condition *entity.Redis) int64 {
 | 
					func (r *redisRepoImpl) Count(condition *entity.RedisQuery) int64 {
 | 
				
			||||||
	return model.CountBy(condition)
 | 
						where := make(map[string]interface{})
 | 
				
			||||||
 | 
						if len(condition.TagIds) > 0 {
 | 
				
			||||||
 | 
							where["tag_id"] = condition.TagIds
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if condition.TagId != 0 {
 | 
				
			||||||
 | 
							where["tag_id"] = condition.TagId
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return model.CountByMap(new(entity.Redis), where)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 根据id获取
 | 
					// 根据id获取
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,9 @@
 | 
				
			|||||||
package router
 | 
					package router
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	projectapp "mayfly-go/internal/project/application"
 | 
					 | 
				
			||||||
	"mayfly-go/internal/redis/api"
 | 
						"mayfly-go/internal/redis/api"
 | 
				
			||||||
	"mayfly-go/internal/redis/application"
 | 
						"mayfly-go/internal/redis/application"
 | 
				
			||||||
 | 
						tagapp "mayfly-go/internal/tag/application"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
@@ -13,8 +13,8 @@ func InitRedisRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
	redis := router.Group("redis")
 | 
						redis := router.Group("redis")
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		rs := &api.Redis{
 | 
							rs := &api.Redis{
 | 
				
			||||||
			RedisApp:   application.GetRedisApp(),
 | 
								RedisApp: application.GetRedisApp(),
 | 
				
			||||||
			ProjectApp: projectapp.GetProjectApp(),
 | 
								TagApp:   tagapp.GetTagTreeApp(),
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 获取redis list
 | 
							// 获取redis list
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,8 +2,9 @@ package form
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type ConfigForm struct {
 | 
					type ConfigForm struct {
 | 
				
			||||||
	Id     int
 | 
						Id     int
 | 
				
			||||||
	Name   string `binding:"required"`
 | 
						Name   string
 | 
				
			||||||
	Key    string `binding:"required"`
 | 
						Key    string
 | 
				
			||||||
 | 
						Params string
 | 
				
			||||||
	Value  string
 | 
						Value  string
 | 
				
			||||||
	Remark string `json:"remark"`
 | 
						Remark string `json:"remark"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,9 @@
 | 
				
			|||||||
package entity
 | 
					package entity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import "mayfly-go/pkg/model"
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	ConfigKeyUseLoginCaptcha string = "UseLoginCaptcha" // 是否使用登录验证码
 | 
						ConfigKeyUseLoginCaptcha string = "UseLoginCaptcha" // 是否使用登录验证码
 | 
				
			||||||
@@ -10,6 +13,7 @@ type Config struct {
 | 
				
			|||||||
	model.Model
 | 
						model.Model
 | 
				
			||||||
	Name   string `json:"name"` // 配置名
 | 
						Name   string `json:"name"` // 配置名
 | 
				
			||||||
	Key    string `json:"key"`  // 配置key
 | 
						Key    string `json:"key"`  // 配置key
 | 
				
			||||||
 | 
						Params string `json:"params"`
 | 
				
			||||||
	Value  string `json:"value"`
 | 
						Value  string `json:"value"`
 | 
				
			||||||
	Remark string `json:"remark"`
 | 
						Remark string `json:"remark"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -27,3 +31,13 @@ func (c *Config) BoolValue(defaultValue bool) bool {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return c.Value == "1"
 | 
						return c.Value == "1"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 值返回json map
 | 
				
			||||||
 | 
					func (c *Config) GetJsonMap() map[string]string {
 | 
				
			||||||
 | 
						var res map[string]string
 | 
				
			||||||
 | 
						if c.Id == 0 || c.Value == "" {
 | 
				
			||||||
 | 
							return res
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						_ = json.Unmarshal([]byte(c.Value), &res)
 | 
				
			||||||
 | 
						return res
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,7 +14,7 @@ func newConfigRepo() repository.Config {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *configRepoImpl) GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
					func (m *configRepoImpl) GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
				
			||||||
	return model.GetPage(pageParam, condition, toEntity)
 | 
						return model.GetPage(pageParam, condition, condition, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *configRepoImpl) Insert(config *entity.Config) {
 | 
					func (m *configRepoImpl) Insert(config *entity.Config) {
 | 
				
			||||||
 
 | 
				
			|||||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user