feat: 数据操作按钮跳转

This commit is contained in:
刘宗洋
2023-02-07 10:32:42 +08:00
parent 4c2c6f613e
commit 3da9ecfaa3
6 changed files with 132 additions and 49 deletions

View File

@@ -714,7 +714,6 @@ select * from invisit v where`.match(/(join|from)\s+(\w*-?\w*\.?\w+)\s*(as)?\s*(
onMounted(() => { onMounted(() => {
self.completionItemProvider?.dispose() self.completionItemProvider?.dispose()
setHeight(); setHeight();
instManage.loadSelectScheme()
// 监听浏览器窗口大小变化,更新对应组件高度 // 监听浏览器窗口大小变化,更新对应组件高度
window.onresize = () => setHeight(); window.onresize = () => setHeight();
}); });
@@ -1734,13 +1733,15 @@ const loadSchemaTables = async (inst: any, schema: string, fn: Function) => {
}else { }else {
tables.forEach((a:any)=>a.show=true) tables.forEach((a:any)=>a.show=true)
} }
fn() fn(state.instances.tables[id+schema])
} }
// 选择数据库实例 // 选择数据库实例
const changeInstance = (inst: any) => { const changeInstance = (inst: any, fn?: Function) => {
debugger
state.dbId = inst.id state.dbId = inst.id
state.dbType = inst.type state.dbType = inst.type
fn && fn()
} }
// 选择数据库 // 选择数据库
const changeSchema = (inst: any, schema: string) => { const changeSchema = (inst: any, schema: string) => {
@@ -1800,23 +1801,6 @@ const addQueryTab = async () => {
} }
const instManage = {
loadSelectScheme: ()=>{
let {tagPath, dbId, db} = store.state.sqlExecInfo.dbOptInfo;
if(dbId){
state.dbId = dbId;
state.db = db;
addQueryTab()
// fixme 差展开菜单树至对应的db
}
}
}
watch(()=>store.state.sqlExecInfo.dbOptInfo, () => {
instManage.loadSelectScheme()
})
</script> </script>
<style lang="scss"> <style lang="scss">

View File

@@ -2,7 +2,7 @@
<div class="instances-box layout-aside"> <div class="instances-box layout-aside">
<el-row type="flex" justify="space-between"> <el-row type="flex" justify="space-between">
<el-col :span="24" :style="{maxHeight: instanceMenuMaxHeight,height: instanceMenuMaxHeight, overflow:'auto'}" class="el-scrollbar flex-auto"> <el-col :span="24" :style="{maxHeight: instanceMenuMaxHeight,height: instanceMenuMaxHeight, overflow:'auto'}" class="el-scrollbar flex-auto">
<el-menu background-color="transparent" :collapse-transition="false"> <el-menu background-color="transparent" ref="menuRef">
<!-- 第一级tag --> <!-- 第一级tag -->
<el-sub-menu v-for="tag of instances.tags" :index="tag.tagPath" :key="tag.tagPath"> <el-sub-menu v-for="tag of instances.tags" :index="tag.tagPath" :key="tag.tagPath">
<template #title> <template #title>
@@ -13,7 +13,7 @@
<el-sub-menu v-for="inst in instances.tree[tag.tagId]" <el-sub-menu v-for="inst in instances.tree[tag.tagId]"
:index="'instance-' + inst.id" :index="'instance-' + inst.id"
:key="'instance-' + inst.id" :key="'instance-' + inst.id"
@click="changeInstance(inst)" @click="changeInstance(inst, ()=>{})"
> >
<template #title> <template #title>
<el-popover <el-popover
@@ -49,7 +49,7 @@
<!-- 第四级 01 --> <!-- 第四级 01 -->
<el-sub-menu :index="inst.id + schema + '-table'" > <el-sub-menu :index="inst.id + schema + '-table'" >
<template #title> <template #title>
<div style="width: 100%" @click="loadTableNames(inst, schema)"> <div style="width: 100%" @click="loadTableNames(inst, schema, ()=>{})">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<el-icon><Calendar color="#409eff"/></el-icon> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<el-icon><Calendar color="#409eff"/></el-icon>
<span></span> <span></span>
<el-icon v-show="state.loading[inst.id + schema]" class="is-loading"><Loading /></el-icon> <el-icon v-show="state.loading[inst.id + schema]" class="is-loading"><Loading /></el-icon>
@@ -113,7 +113,8 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import {onBeforeMount, reactive} from 'vue'; import {nextTick, onBeforeMount, onMounted, reactive, ref, Ref, watch} from 'vue';
import {store} from '@/store';
const props = defineProps({ const props = defineProps({
instanceMenuMaxHeight: { instanceMenuMaxHeight: {
@@ -130,6 +131,8 @@ onBeforeMount(async ()=>{
await initLoadInstances() await initLoadInstances()
}) })
const menuRef = ref(null) as Ref
const state = reactive({ const state = reactive({
nowSchema: '', nowSchema: '',
filterParam: {}, filterParam: {},
@@ -146,9 +149,10 @@ const initLoadInstances = () => {
/** /**
* 改变选中的数据库实例 * 改变选中的数据库实例
* @param inst 选中的实例对象 * @param inst 选中的实例对象
* @param fn 选中的实例对象后的回调函数
*/ */
const changeInstance = (inst : any) => { const changeInstance = (inst : any, fn: Function) => {
emits('changeInstance', inst) emits('changeInstance', inst, fn)
} }
/** /**
* 改变选中的数据库schema * 改变选中的数据库schema
@@ -163,11 +167,13 @@ const changeSchema = (inst : any, schema: string) => {
* 加载schema下所有表 * 加载schema下所有表
* @param inst 数据库实例 * @param inst 数据库实例
* @param schema database名 * @param schema database名
* @param fn 加载表集合后的回调函数参数res 表集合
*/ */
const loadTableNames = async (inst: any, schema: string) => { const loadTableNames = async (inst: any, schema: string, fn: Function) => {
state.loading[inst.id+schema] = true state.loading[inst.id+schema] = true
await emits('loadTableNames', inst, schema, ()=>{ await emits('loadTableNames', inst, schema, (res: any[])=>{
state.loading[inst.id+schema] = false state.loading[inst.id+schema] = false
fn && fn(res)
}) })
} }
/** /**
@@ -192,6 +198,39 @@ const filterTableName = (instId: number, schema: string, event?: any) => {
}) })
} }
const selectDb = async (val?: any) => {
let info = val || store.state.sqlExecInfo.dbOptInfo;
if (info && info.dbId) {
const {tagPath, dbId, db} = info
menuRef.value.open(tagPath);
menuRef.value.open('instance-' + dbId);
await changeInstance({id: dbId}, () => {
// 加载数据库
nextTick(async () => {
menuRef.value.open(dbId + db)
state.nowSchema = (dbId+db)
// 加载集合列表
await nextTick(async () => {
await loadTableNames({id: dbId}, db, (res: any[]) => {
// 展开集合列表
menuRef.value.open(dbId + db + '-table')
console.log(res)
})
})
})
})
}
}
onMounted(()=>{
selectDb();
})
watch(()=>store.state.sqlExecInfo.dbOptInfo, async newValue => {
await selectDb(newValue)
})
</script> </script>
<style lang="scss"> <style lang="scss">

View File

@@ -159,12 +159,12 @@ const {
jsonEditorDialog, jsonEditorDialog,
} = toRefs(state) } = toRefs(state)
const changeInstance = async (inst: any) => { const changeInstance = async (inst: any, fn: Function) => {
if (inst) { if (inst) {
if (!state.instances.dbs[inst.id]) { if (!state.instances.dbs[inst.id]) {
const res = await mongoApi.databases.request({id: inst.id}); const res = await mongoApi.databases.request({id: inst.id});
state.instances.dbs[inst.id] = res.Databases; state.instances.dbs[inst.id] = res.Databases;
console.log(res.Databases) fn && fn(res.Databases)
} }
} }
} }
@@ -179,7 +179,7 @@ const loadTableNames = async (inst: any, database: string, fn:Function) => {
tables.push({tableName: tb, show: true}) tables.push({tableName: tb, show: true})
} }
state.instances.tables[inst.id+database] = tables state.instances.tables[inst.id+database] = tables
fn() fn(tables)
} }
const changeCollection = (inst: any, schema: string, collection: string) => { const changeCollection = (inst: any, schema: string, collection: string) => {

View File

@@ -7,7 +7,7 @@
overflow:'auto' overflow:'auto'
}" class="el-scrollbar flex-auto"> }" class="el-scrollbar flex-auto">
<el-menu background-color="transparent" :collapse-transition="false"> <el-menu background-color="transparent" ref="menuRef">
<!-- 第一级tag --> <!-- 第一级tag -->
<el-sub-menu v-for="tag of instances.tags" :index="tag.tagPath" :key="tag.tagPath"> <el-sub-menu v-for="tag of instances.tags" :index="tag.tagPath" :key="tag.tagPath">
<template #title> <template #title>
@@ -18,7 +18,7 @@
<el-sub-menu v-for="inst in instances.tree[tag.tagId]" <el-sub-menu v-for="inst in instances.tree[tag.tagId]"
:index="'mongo-instance-' + inst.id" :index="'mongo-instance-' + inst.id"
:key="'mongo-instance-' + inst.id" :key="'mongo-instance-' + inst.id"
@click.prevent="changeInstance(inst)" @click.prevent="changeInstance(inst, ()=>{})"
> >
<template #title> <template #title>
<el-popover <el-popover
@@ -55,7 +55,7 @@
<!-- 第四级 01 --> <!-- 第四级 01 -->
<el-sub-menu :index="inst.id + db.Name + '-table'" > <el-sub-menu :index="inst.id + db.Name + '-table'" >
<template #title> <template #title>
<div style="width: 100%" @click="loadTableNames(inst, db.Name)"> <div style="width: 100%" @click="loadTableNames(inst, db.Name, ()=>{})">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<el-icon><Calendar color="#409eff"/></el-icon> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<el-icon><Calendar color="#409eff"/></el-icon>
<span>集合</span> <span>集合</span>
<el-icon v-show="state.loading[inst.id + db.Name]" class="is-loading"><Loading /></el-icon> <el-icon v-show="state.loading[inst.id + db.Name]" class="is-loading"><Loading /></el-icon>
@@ -97,8 +97,9 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import {onBeforeMount, reactive} from 'vue'; import {nextTick, onBeforeMount, onMounted, reactive, ref, Ref, watch} from 'vue';
import {formatByteSize} from '@/common/utils/format'; import {formatByteSize} from '@/common/utils/format';
import {store} from '@/store';
const props = defineProps({ const props = defineProps({
instances: { instances: {
@@ -117,6 +118,8 @@ const setHeight = () => {
state.instanceMenuMaxHeight = window.innerHeight - 140 + 'px'; state.instanceMenuMaxHeight = window.innerHeight - 140 + 'px';
} }
const menuRef = ref(null) as Ref
const state = reactive({ const state = reactive({
instanceMenuMaxHeight: '800px', instanceMenuMaxHeight: '800px',
nowSchema: '', nowSchema: '',
@@ -135,9 +138,10 @@ const initLoadInstances = () => {
/** /**
* 改变选中的数据库实例 * 改变选中的数据库实例
* @param inst 选中的实例对象 * @param inst 选中的实例对象
* @param fn 选中的实例对象后的回调事件
*/ */
const changeInstance = (inst : any) => { const changeInstance = (inst : any, fn: Function) => {
emits('changeInstance', inst) emits('changeInstance', inst, fn)
} }
/** /**
* 改变选中的数据库schema * 改变选中的数据库schema
@@ -151,12 +155,14 @@ const changeSchema = (inst : any, schema: string) => {
/** /**
* 加载schema下所有表 * 加载schema下所有表
* @param inst 数据库实例 * @param inst 数据库实例
* @param fn 加载表名后的回调函数参数表名list
* @param schema database名 * @param schema database名
*/ */
const loadTableNames = async (inst: any, schema: string) => { const loadTableNames = async (inst: any, schema: string, fn: Function) => {
state.loading[inst.id+schema] = true state.loading[inst.id+schema] = true
await emits('loadTableNames', inst, schema, ()=>{ await emits('loadTableNames', inst, schema, (res: any)=>{
state.loading[inst.id+schema] = false state.loading[inst.id+schema] = false
fn && fn(res)
}) })
} }
/** /**
@@ -181,6 +187,38 @@ const filterTableName = (instId: number, schema: string, event?: any) => {
}) })
} }
const selectDb = async (val?: any) => {
let info = val || store.state.mongoDbOptInfo.dbOptInfo;
if (info && info.dbId) {
const {tagPath, dbId, db} = info
menuRef.value.open(tagPath);
menuRef.value.open('mongo-instance-' + dbId);
await changeInstance({id: dbId}, () => {
// 加载数据库
nextTick(async () => {
menuRef.value.open(dbId + db)
// 加载集合列表
await nextTick(async () => {
await loadTableNames({id: dbId}, db, (res: any[]) => {
// 展开集合列表
menuRef.value.open(dbId + db + '-table')
// 加载第一张集合数据
loadTableData({id: dbId}, db, res[0].tableName)
})
})
})
})
}
}
onMounted(()=>{
selectDb();
})
watch(()=>store.state.mongoDbOptInfo.dbOptInfo, async newValue => {
await selectDb(newValue)
})
</script> </script>
<style lang="scss"> <style lang="scss">

View File

@@ -335,7 +335,7 @@ const initLoadInstances = async ()=>{
} }
} }
const changeInstance = async (inst: any) => { const changeInstance = async (inst: any, fn: Function) => {
let dbs = state.instances.dbs[inst.id] || [] let dbs = state.instances.dbs[inst.id] || []
if(dbs.length <=0 ){ if(dbs.length <=0 ){
const res = await redisApi.redisInfo.request({ id: inst.id, host:inst.host }); const res = await redisApi.redisInfo.request({ id: inst.id, host:inst.host });
@@ -348,8 +348,7 @@ const changeInstance = async (inst: any) => {
} }
state.instances.dbs[inst.id] = dbs state.instances.dbs[inst.id] = dbs
fn && fn(dbs)
} }
/** 初始化加载db数据 */ /** 初始化加载db数据 */

View File

@@ -7,7 +7,7 @@
overflow:'auto' overflow:'auto'
}" class="el-scrollbar flex-auto"> }" class="el-scrollbar flex-auto">
<el-menu background-color="transparent" :collapse-transition="false"> <el-menu background-color="transparent" ref="menuRef">
<!-- 第一级tag --> <!-- 第一级tag -->
<el-sub-menu v-for="tag of instances.tags" :index="tag.tagPath" :key="tag.tagPath"> <el-sub-menu v-for="tag of instances.tags" :index="tag.tagPath" :key="tag.tagPath">
<template #title> <template #title>
@@ -16,8 +16,8 @@
</template> </template>
<!-- 第二级数据库实例 --> <!-- 第二级数据库实例 -->
<el-sub-menu v-for="inst in instances.tree[tag.tagId]" <el-sub-menu v-for="inst in instances.tree[tag.tagId]"
:index="'mongo-instance-' + inst.id" :index="'redis-instance-' + inst.id"
:key="'mongo-instance-' + inst.id" :key="'redis-instance-' + inst.id"
@click.prevent="changeInstance(inst)" @click.prevent="changeInstance(inst)"
> >
<template #title> <template #title>
@@ -61,7 +61,8 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import {onBeforeMount, reactive} from 'vue'; import {onBeforeMount, onMounted, reactive, Ref, ref, watch} from 'vue';
import {store} from '@/store';
defineProps({ defineProps({
instances: { instances: {
@@ -80,12 +81,13 @@ const setHeight = () => {
state.instanceMenuMaxHeight = window.innerHeight - 140 + 'px'; state.instanceMenuMaxHeight = window.innerHeight - 140 + 'px';
} }
const menuRef = ref(null) as Ref;
const state = reactive({ const state = reactive({
instanceMenuMaxHeight: '800px', instanceMenuMaxHeight: '800px',
nowSchema: '', nowSchema: '',
filterParam: {}, filterParam: {},
loading: {}, loading: {},
}) })
/** /**
@@ -98,9 +100,10 @@ const initLoadInstances = () => {
/** /**
* 改变选中的数据库实例 * 改变选中的数据库实例
* @param inst 选中的实例对象 * @param inst 选中的实例对象
* @param fn 选中的实例后的回调函数
*/ */
const changeInstance = (inst : any) => { const changeInstance = (inst : any, fn?:Function) => {
emits('changeInstance', inst) emits('changeInstance', inst, fn)
} }
/** /**
* 改变选中的数据库schema * 改变选中的数据库schema
@@ -112,6 +115,26 @@ const changeSchema = (inst : any, schema: string) => {
emits('changeSchema', inst, schema) emits('changeSchema', inst, schema)
} }
const selectDb = async (val?: any) => {
const info = val || store.state.redisDbOptInfo.dbOptInfo
if (info && info.dbId) {
const {tagPath, dbId} = info
menuRef.value.open(tagPath);
menuRef.value.open('redis-instance-' + dbId);
await changeInstance({id: dbId}, async (dbs: any[]) => {
await changeSchema({id: dbId}, dbs[0]?.name)
})
}
}
onMounted(()=>{
selectDb();
})
watch(()=>store.state.redisDbOptInfo.dbOptInfo, async newValue =>{
await selectDb(newValue)
})
</script> </script>
<style lang="scss"> <style lang="scss">