diff --git a/magic-editor/src/console/src/components/magic-editor.vue b/magic-editor/src/console/src/components/magic-editor.vue index 2a787cb9..fba417fe 100644 --- a/magic-editor/src/console/src/components/magic-editor.vue +++ b/magic-editor/src/console/src/components/magic-editor.vue @@ -42,7 +42,7 @@ import contants from '@/scripts/contants.js' import MagicWebSocket from '@/scripts/websocket.js' import store from '@/scripts/store.js' import Key from '@/scripts/hotkey.js' -import {replaceURL} from '@/scripts/utils.js' +import {replaceURL,getQueryVariable} from '@/scripts/utils.js' import {defineTheme} from '@/scripts/editor/theme.js' import defaultTheme from '@/scripts/editor/default-theme.js' import darkTheme from '@/scripts/editor/dark-theme.js' @@ -193,6 +193,7 @@ export default { } }) bus.$on('logout', () => this.showLogin = true) + this.open() }, destroyed() { bus.$off(); @@ -299,6 +300,21 @@ export default { .catch(ignore => { bus.$emit('status', '版本检测失败') }) + }, + /** + * 传入id来打开对应api或者function + */ + open(openIds) { + openIds = openIds || getQueryVariable('openIds') + if (openIds) { + if (typeof openIds === 'string') { + openIds = openIds.split(',') + } + openIds.forEach(id => { + this.$refs.apiList.openItemById(id) + this.$refs.functionList.openItemById(id) + }) + } } }, watch: { diff --git a/magic-editor/src/console/src/components/resources/magic-api-list.vue b/magic-editor/src/console/src/components/resources/magic-api-list.vue index cf56d688..e770a858 100644 --- a/magic-editor/src/console/src/components/resources/magic-api-list.vue +++ b/magic-editor/src/console/src/components/resources/magic-api-list.vue @@ -136,7 +136,9 @@ export default { draggableItem: {}, draggableTargetItem: {}, // 是否展示tree-loading - showLoading: true + showLoading: true, + // 缓存一个openId + tmpOpenId: [] } }, methods: { @@ -166,6 +168,7 @@ export default { request.send('list').success(data => { this.listChildrenData = data this.initTreeData() + this.openItemById() this.showLoading = false }) }) @@ -780,6 +783,26 @@ export default { item = this.getItemById(item.parentId) } return items + }, + // 根据id打开对应item + openItemById(openId) { + // 证明当前请求还没有请求到数据 + if (this.listChildrenData.length === 0) { + this.tmpOpenId.push(openId) + } else { + if (!this.tmpOpenId.includes(openId)) { + this.tmpOpenId.push(openId) + } + this.tmpOpenId.forEach(id => { + const cache = this.getItemById(id) + if (cache) { + this.$nextTick(() => { + this.open(cache) + }) + } + }) + this.tmpOpenId = [] + } } }, mounted() { diff --git a/magic-editor/src/console/src/components/resources/magic-function-list.vue b/magic-editor/src/console/src/components/resources/magic-function-list.vue index d8753dfd..8dc646fc 100644 --- a/magic-editor/src/console/src/components/resources/magic-function-list.vue +++ b/magic-editor/src/console/src/components/resources/magic-function-list.vue @@ -135,7 +135,9 @@ export default { draggableItem: {}, draggableTargetItem: {}, // 是否展示tree-loading - showLoading: true + showLoading: true, + // 缓存一个openId + tmpOpenId: [] } }, methods: { @@ -169,6 +171,7 @@ export default { request.send('function/list').success(data => { this.listChildrenData = data this.initTreeData() + this.openItemById() this.showLoading = false }) }) @@ -718,6 +721,26 @@ export default { } return handle(this.tree) }, + // 根据id打开对应item + openItemById(openId) { + // 证明当前请求还没有请求到数据 + if (this.listChildrenData.length === 0) { + this.tmpOpenId.push(openId) + } else { + if (!this.tmpOpenId.includes(openId)) { + this.tmpOpenId.push(openId) + } + this.tmpOpenId.forEach(id => { + const cache = this.getItemById(id) + if (cache) { + this.$nextTick(() => { + this.open(cache) + }) + } + }) + this.tmpOpenId = [] + } + } }, mounted() { JavaClass.setupOnlineFunction(this.doFindFunction); diff --git a/magic-editor/src/console/src/scripts/utils.js b/magic-editor/src/console/src/scripts/utils.js index f3f2922b..5c34c9d4 100644 --- a/magic-editor/src/console/src/scripts/utils.js +++ b/magic-editor/src/console/src/scripts/utils.js @@ -94,4 +94,22 @@ const goToAnchor = (dom) => { dom.scrollIntoView(true) } } -export {replaceURL, isVisible, formatJson, formatDate, paddingZero, download, requestGroup, deepClone, goToAnchor} + +/** + * 获取url中的参数 + * @param {String} variable + * @returns + */ +const getQueryVariable = (variable) => { + var query = window.location.search.substring(1) + var vars = query.split('&') + for (var i = 0; i < vars.length; i++) { + var pair = vars[i].split('=') + if (pair[0] == variable) { + return pair[1] + } + } + return false +} + +export {replaceURL, isVisible, formatJson, formatDate, paddingZero, download, requestGroup, deepClone, goToAnchor, getQueryVariable}