From f093da99ecb963d19d62dc0f242f00b20bc8895c Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期三, 14 四月 2021 13:22:31 +0800 Subject: [PATCH] Merge branch 'master' of https://gitee.com/y_project/RuoYi-Vue into dev --- ruoyi-ui/src/store/modules/permission.js | 21 ++ ruoyi-ui/src/views/monitor/druid/index.vue | 2 ruoyi-ui/src/assets/styles/sidebar.scss | 3 ruoyi-ui/src/settings.js | 5 ruoyi-ui/src/components/Editor/index.vue | 65 +++++++ ruoyi-ui/src/utils/ruoyi.js | 63 +++++-- ruoyi-ui/src/layout/components/Settings/index.vue | 62 +++++++ ruoyi-ui/src/assets/styles/ruoyi.scss | 6 ruoyi-ui/src/store/getters.js | 2 ruoyi-ui/src/layout/components/Navbar.vue | 15 + ruoyi-ui/src/store/modules/settings.js | 13 ruoyi-ui/src/components/TopNav/index.vue | 154 +++++++++++++++++++ ruoyi-admin/src/main/resources/application-prod.yml | 2 ruoyi-generator/src/main/resources/vm/java/controller.java.vm | 2 ruoyi-ui/src/layout/components/TagsView/index.vue | 15 + ruoyi-ui/src/store/modules/tagsView.js | 24 +++ 16 files changed, 412 insertions(+), 42 deletions(-) diff --git a/ruoyi-admin/src/main/resources/application-prod.yml b/ruoyi-admin/src/main/resources/application-prod.yml index ed1a529..8f81bbd 100644 --- a/ruoyi-admin/src/main/resources/application-prod.yml +++ b/ruoyi-admin/src/main/resources/application-prod.yml @@ -43,7 +43,7 @@ allow: url-pattern: /druid/* # 鎺у埗鍙扮鐞嗙敤鎴峰悕鍜屽瘑鐮� - login-username: admin + login-username: ruoyi login-password: 123456 filter: stat: diff --git a/ruoyi-generator/src/main/resources/vm/java/controller.java.vm b/ruoyi-generator/src/main/resources/vm/java/controller.java.vm index 31e473d..670813c 100644 --- a/ruoyi-generator/src/main/resources/vm/java/controller.java.vm +++ b/ruoyi-generator/src/main/resources/vm/java/controller.java.vm @@ -74,7 +74,7 @@ public AjaxResult<${ClassName}Vo> export(${ClassName}QueryBo bo) { List<${ClassName}Vo> list = i${ClassName}Service.queryList(bo); ExcelUtil<${ClassName}Vo> util = new ExcelUtil<${ClassName}Vo>(${ClassName}Vo.class); - return util.exportExcel(list, "${businessName}" ); + return util.exportExcel(list, "${businessName}鏁版嵁" ); } /** diff --git a/ruoyi-ui/src/assets/styles/ruoyi.scss b/ruoyi-ui/src/assets/styles/ruoyi.scss index de1db7f..c7ff69c 100644 --- a/ruoyi-ui/src/assets/styles/ruoyi.scss +++ b/ruoyi-ui/src/assets/styles/ruoyi.scss @@ -176,6 +176,12 @@ color: #FFFFFF; } +/* submenu item */ +.el-menu--horizontal > .el-submenu .el-submenu__title { + height: 50px !important; + line-height: 50px !important; +} + /* text color */ .text-navy { color: #1ab394; diff --git a/ruoyi-ui/src/assets/styles/sidebar.scss b/ruoyi-ui/src/assets/styles/sidebar.scss index 0eb8e78..2f368c3 100644 --- a/ruoyi-ui/src/assets/styles/sidebar.scss +++ b/ruoyi-ui/src/assets/styles/sidebar.scss @@ -135,9 +135,6 @@ margin-left: 20px; } - .el-submenu__icon-arrow { - display: none; - } } } diff --git a/ruoyi-ui/src/components/Editor/index.vue b/ruoyi-ui/src/components/Editor/index.vue index ba2ea73..640049c 100644 --- a/ruoyi-ui/src/components/Editor/index.vue +++ b/ruoyi-ui/src/components/Editor/index.vue @@ -1,5 +1,19 @@ <template> + <div> + <el-upload + :action="uploadUrl" + :on-success="handleUploadSuccess" + :on-error="handleUploadError" + name="file" + :show-file-list="false" + :headers="headers" + style="display: none" + ref="upload" + v-if="this.uploadUrl" + > + </el-upload> <div class="editor" ref="editor" :style="styles"></div> + </div> </template> <script> @@ -7,6 +21,7 @@ import "quill/dist/quill.core.css"; import "quill/dist/quill.snow.css"; import "quill/dist/quill.bubble.css"; +import { getToken } from "@/utils/auth"; export default { name: "Editor", @@ -30,10 +45,18 @@ readOnly: { type: Boolean, default: false, + }, + /* 涓婁紶鍦板潃 */ + uploadUrl: { + type: String, + default: "", } }, data() { return { + headers: { + Authorization: "Bearer " + getToken() + }, Quill: null, currentValue: "", options: { @@ -52,7 +75,7 @@ [{ color: [] }, { background: [] }], // 瀛椾綋棰滆壊銆佸瓧浣撹儗鏅鑹� [{ align: [] }], // 瀵归綈鏂瑰紡 ["clean"], // 娓呴櫎鏂囨湰鏍煎紡 - ["link", "image", "video"] // 閾炬帴銆佸浘鐗囥�佽棰� + ["link", "image"] // 閾炬帴銆佸浘鐗� ], }, placeholder: "璇疯緭鍏ュ唴瀹�", @@ -95,6 +118,26 @@ init() { const editor = this.$refs.editor; this.Quill = new Quill(editor, this.options); + // 濡傛灉璁剧疆浜嗕笂浼犲湴鍧�鍒欒嚜瀹氫箟鍥剧墖涓婁紶浜嬩欢 + if (this.uploadUrl) { + let toolbar = this.Quill.getModule("toolbar"); + toolbar.addHandler("image", (value) => { + this.uploadType = "image"; + if (value) { + this.$refs.upload.$children[0].$refs.input.click(); + } else { + this.quill.format("image", false); + } + }); + toolbar.addHandler("video", (value) => { + this.uploadType = "video"; + if (value) { + this.$refs.upload.$children[0].$refs.input.click(); + } else { + this.quill.format("video", false); + } + }); + } this.Quill.pasteHTML(this.currentValue); this.Quill.on("text-change", (delta, oldDelta, source) => { const html = this.$refs.editor.children[0].innerHTML; @@ -114,13 +157,31 @@ this.$emit("on-editor-change", eventName, ...args); }); }, + handleUploadSuccess(res, file) { + // 鑾峰彇瀵屾枃鏈粍浠跺疄渚� + let quill = this.Quill; + // 濡傛灉涓婁紶鎴愬姛 + if (res.code == 200) { + // 鑾峰彇鍏夋爣鎵�鍦ㄤ綅缃� + let length = quill.getSelection().index; + // 鎻掑叆鍥剧墖 res.url涓烘湇鍔″櫒杩斿洖鐨勫浘鐗囧湴鍧� + quill.insertEmbed(length, "image", res.url); + // 璋冩暣鍏夋爣鍒版渶鍚� + quill.setSelection(length + 1); + } else { + this.$message.error("鍥剧墖鎻掑叆澶辫触"); + } + }, + handleUploadError() { + this.$message.error("鍥剧墖鎻掑叆澶辫触"); + }, }, }; </script> <style> .editor, .ql-toolbar { - white-space: pre-wrap!important; + white-space: pre-wrap !important; line-height: normal !important; } .quill-img { diff --git a/ruoyi-ui/src/components/TopNav/index.vue b/ruoyi-ui/src/components/TopNav/index.vue new file mode 100644 index 0000000..3eebda4 --- /dev/null +++ b/ruoyi-ui/src/components/TopNav/index.vue @@ -0,0 +1,154 @@ +<template> + <el-menu + :default-active="activeMenu" + mode="horizontal" + @select="handleSelect" + > + <template v-for="(item, index) in topMenus"> + <el-menu-item :index="item.path" :key="index" v-if="index < visibleNumber" + ><svg-icon :icon-class="item.meta.icon" /> + {{ item.meta.title }}</el-menu-item + > + </template> + + <!-- 椤堕儴鑿滃崟瓒呭嚭鏁伴噺鎶樺彔 --> + <el-submenu index="more" v-if="topMenus.length > visibleNumber"> + <template slot="title">鏇村鑿滃崟</template> + <template v-for="(item, index) in topMenus"> + <el-menu-item + :index="item.path" + :key="index" + v-if="index >= visibleNumber" + ><svg-icon :icon-class="item.meta.icon" /> + {{ item.meta.title }}</el-menu-item + > + </template> + </el-submenu> + </el-menu> +</template> + +<script> +import { constantRoutes } from "@/router"; + +// 涓嶉渶瑕佹縺娲荤殑璺敱 +const noactiveList = ["/user/profile", "/dict/type", "/gen/edit", "/job/log"]; + +export default { + data() { + return { + // 椤堕儴鏍忓垵濮嬫暟 + visibleNumber: 5, + // 鏄惁涓洪娆″姞杞� + isFrist: false, + }; + }, + computed: { + // 椤堕儴鏄剧ず鑿滃崟 + topMenus() { + let topMenus = []; + this.routers.map((menu) => { + if (menu.hidden !== true) { + topMenus.push(menu); + } + }); + return topMenus; + }, + // 鎵�鏈夌殑璺敱淇℃伅 + routers() { + return this.$store.state.permission.topbarRouters; + }, + // 璁剧疆瀛愯矾鐢� + childrenMenus() { + var childrenMenus = []; + this.routers.map((router) => { + for (var item in router.children) { + if (router.children[item].parentPath === undefined) { + router.children[item].path = router.path + "/" + router.children[item].path; + router.children[item].parentPath = router.path; + } + childrenMenus.push(router.children[item]); + } + }); + return constantRoutes.concat(childrenMenus); + }, + // 榛樿婵�娲荤殑鑿滃崟 + activeMenu() { + const path = this.$route.path; + let activePath = this.routers[0].path; + var noactive = noactiveList.some(function (item) { + return path.indexOf(item) !== -1; + }); + if (noactive) { + return; + } + if (path.lastIndexOf("/") > 0) { + const tmpPath = path.substring(1, path.length); + activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/")); + } else if ("/index" == path || "" == path) { + if (!this.isFrist) { + this.isFrist = true; + } else { + activePath = "index"; + } + } + this.activeRoutes(activePath); + return activePath; + }, + }, + beforeMount() { + window.addEventListener('resize', this.setVisibleNumber) + }, + beforeDestroy() { + window.removeEventListener('resize', this.setVisibleNumber) + }, + mounted() { + this.setVisibleNumber(); + }, + methods: { + // 鏍规嵁瀹藉害璁$畻璁剧疆鏄剧ず鏍忔暟 + setVisibleNumber() { + const width = document.body.getBoundingClientRect().width / 3; + this.visibleNumber = parseInt(width / 85); + }, + // 鑿滃崟閫夋嫨浜嬩欢 + handleSelect(key, keyPath) { + if (key.indexOf("http://") !== -1 || key.indexOf("https://") !== -1) { + // http(s):// 璺緞鏂扮獥鍙f墦寮� + window.open(key, "_blank"); + } else { + this.activeRoutes(key); + } + }, + // 褰撳墠婵�娲荤殑璺敱 + activeRoutes(key) { + var routes = []; + if (this.childrenMenus && this.childrenMenus.length > 0) { + this.childrenMenus.map((item) => { + if (key == item.parentPath || (key == "index" && "" == item.path)) { + routes.push(item); + } + }); + } + this.$store.commit("SET_SIDEBAR_ROUTERS", routes); + } + }, +}; +</script> + +<style lang="scss" scoped> +.el-menu--horizontal > .el-menu-item { + float: left; + height: 50px; + line-height: 50px; + margin: 0; + border-bottom: 3px solid transparent; + color: #999093; + padding: 0 5px; + margin: 0 10px; +} + +.el-menu--horizontal > .el-menu-item.is-active { + border-bottom: 3px solid #409eff; + color: #303133; +} +</style> diff --git a/ruoyi-ui/src/layout/components/Navbar.vue b/ruoyi-ui/src/layout/components/Navbar.vue index b11460a..9d220e9 100644 --- a/ruoyi-ui/src/layout/components/Navbar.vue +++ b/ruoyi-ui/src/layout/components/Navbar.vue @@ -2,7 +2,8 @@ <div class="navbar"> <hamburger id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" /> - <breadcrumb id="breadcrumb-container" class="breadcrumb-container" /> + <breadcrumb id="breadcrumb-container" class="breadcrumb-container" v-if="!topNav"/> + <top-nav id="topmenu-container" class="topmenu-container" v-if="topNav"/> <div class="right-menu"> <template v-if="device!=='mobile'"> @@ -48,6 +49,7 @@ <script> import { mapGetters } from 'vuex' import Breadcrumb from '@/components/Breadcrumb' +import TopNav from '@/components/TopNav' import Hamburger from '@/components/Hamburger' import Screenfull from '@/components/Screenfull' import SizeSelect from '@/components/SizeSelect' @@ -58,6 +60,7 @@ export default { components: { Breadcrumb, + TopNav, Hamburger, Screenfull, SizeSelect, @@ -80,6 +83,11 @@ key: 'showSettings', value: val }) + } + }, + topNav: { + get() { + return this.$store.state.settings.topNav } } }, @@ -127,6 +135,11 @@ float: left; } + .topmenu-container { + position: absolute; + left: 50px; + } + .errLog-container { display: inline-block; vertical-align: top; diff --git a/ruoyi-ui/src/layout/components/Settings/index.vue b/ruoyi-ui/src/layout/components/Settings/index.vue index 9d42790..193ccae 100644 --- a/ruoyi-ui/src/layout/components/Settings/index.vue +++ b/ruoyi-ui/src/layout/components/Settings/index.vue @@ -41,6 +41,11 @@ <el-divider/> <h3 class="drawer-title">绯荤粺甯冨眬閰嶇疆</h3> + + <div class="drawer-item"> + <span>寮�鍚� TopNav</span> + <el-switch v-model="topNav" class="drawer-switch" /> + </div> <div class="drawer-item"> <span>寮�鍚� Tags-Views</span> @@ -57,6 +62,10 @@ <el-switch v-model="sidebarLogo" class="drawer-switch" /> </div> + <el-divider/> + + <el-button size="small" type="primary" plain icon="el-icon-document-add" @click="saveSetting">淇濆瓨閰嶇疆</el-button> + <el-button size="small" plain icon="el-icon-refresh" @click="resetSetting">閲嶇疆閰嶇疆</el-button> </div> </div> </template> @@ -67,14 +76,13 @@ export default { components: { ThemePicker }, data() { - return {} + return { + sideTheme: this.$store.state.settings.sideTheme + }; }, computed: { theme() { return this.$store.state.settings.theme - }, - sideTheme() { - return this.$store.state.settings.sideTheme }, fixedHeader: { get() { @@ -85,6 +93,20 @@ key: 'fixedHeader', value: val }) + } + }, + topNav: { + get() { + return this.$store.state.settings.topNav + }, + set(val) { + this.$store.dispatch('settings/changeSetting', { + key: 'topNav', + value: val + }) + if (!val) { + this.$store.commit("SET_SIDEBAR_ROUTERS", this.$store.state.permission.defaultRoutes); + } } }, tagsView: { @@ -122,6 +144,38 @@ key: 'sideTheme', value: val }) + this.sideTheme = val; + }, + saveSetting() { + const loading = this.$loading({ + lock: true, + fullscreen: false, + text: "姝e湪淇濆瓨鍒版湰鍦帮紝璇风◢鍚�...", + spinner: "el-icon-loading", + background: "rgba(0, 0, 0, 0.7)" + }); + localStorage.setItem( + "layout-setting", + `{ + "topNav":${this.topNav}, + "tagsView":${this.tagsView}, + "fixedHeader":${this.fixedHeader}, + "sidebarLogo":${this.sidebarLogo}, + "sideTheme":"${this.sideTheme}" + }` + ); + setTimeout(loading.close(), 1000) + }, + resetSetting() { + this.$loading({ + lock: true, + fullscreen: false, + text: "姝e湪娓呴櫎璁剧疆缂撳瓨骞跺埛鏂帮紝璇风◢鍚�...", + spinner: "el-icon-loading", + background: "rgba(0, 0, 0, 0.7)" + }); + localStorage.removeItem("layout-setting") + setTimeout("window.location.reload()", 1000) } } } diff --git a/ruoyi-ui/src/layout/components/TagsView/index.vue b/ruoyi-ui/src/layout/components/TagsView/index.vue index d1e059e..6caf350 100644 --- a/ruoyi-ui/src/layout/components/TagsView/index.vue +++ b/ruoyi-ui/src/layout/components/TagsView/index.vue @@ -21,6 +21,7 @@ <li @click="refreshSelectedTag(selectedTag)">鍒锋柊椤甸潰</li> <li v-if="!isAffix(selectedTag)" @click="closeSelectedTag(selectedTag)">鍏抽棴褰撳墠</li> <li @click="closeOthersTags">鍏抽棴鍏朵粬</li> + <li v-if="!isLastView()" @click="closeRightTags">鍏抽棴鍙充晶</li> <li @click="closeAllTags(selectedTag)">鍏抽棴鎵�鏈�</li> </ul> </div> @@ -82,6 +83,13 @@ }, isAffix(tag) { return tag.meta && tag.meta.affix + }, + isLastView() { + try { + return this.selectedTag.fullPath === this.visitedViews[this.visitedViews.length - 1].fullPath + } catch (err) { + return false + } }, filterAffixTags(routes, basePath = '/') { let tags = [] @@ -152,6 +160,13 @@ } }) }, + closeRightTags() { + this.$store.dispatch('tagsView/delRightTags', this.selectedTag).then(visitedViews => { + if (!visitedViews.find(i => i.fullPath === this.$route.fullPath)) { + this.toLastView(visitedViews) + } + }) + }, closeOthersTags() { this.$router.push(this.selectedTag).catch(()=>{}); this.$store.dispatch('tagsView/delOthersViews', this.selectedTag).then(() => { diff --git a/ruoyi-ui/src/settings.js b/ruoyi-ui/src/settings.js index 40a7f15..ba5cbd0 100644 --- a/ruoyi-ui/src/settings.js +++ b/ruoyi-ui/src/settings.js @@ -12,6 +12,11 @@ showSettings: false, /** + * 鏄惁鏄剧ず椤堕儴瀵艰埅 + */ + topNav: false, + + /** * 鏄惁鏄剧ず tagsView */ tagsView: true, diff --git a/ruoyi-ui/src/store/getters.js b/ruoyi-ui/src/store/getters.js index 00c4ebf..da6ab39 100644 --- a/ruoyi-ui/src/store/getters.js +++ b/ruoyi-ui/src/store/getters.js @@ -11,6 +11,8 @@ roles: state => state.user.roles, permissions: state => state.user.permissions, permission_routes: state => state.permission.routes, + topbarRouters:state => state.permission.topbarRouters, + defaultRoutes:state => state.permission.defaultRoutes, sidebarRouters:state => state.permission.sidebarRouters, } export default getters diff --git a/ruoyi-ui/src/store/modules/permission.js b/ruoyi-ui/src/store/modules/permission.js index 80015b0..aacfc8c 100644 --- a/ruoyi-ui/src/store/modules/permission.js +++ b/ruoyi-ui/src/store/modules/permission.js @@ -7,6 +7,8 @@ state: { routes: [], addRoutes: [], + defaultRoutes: [], + topbarRouters: [], sidebarRouters: [] }, mutations: { @@ -14,8 +16,19 @@ state.addRoutes = routes state.routes = constantRoutes.concat(routes) }, - SET_SIDEBAR_ROUTERS: (state, routers) => { - state.sidebarRouters = constantRoutes.concat(routers) + SET_DEFAULT_ROUTES: (state, routes) => { + state.defaultRoutes = constantRoutes.concat(routes) + }, + SET_TOPBAR_ROUTES: (state, routes) => { + // 椤堕儴瀵艰埅鑿滃崟榛樿娣诲姞缁熻鎶ヨ〃鏍忔寚鍚戦椤� + const index = [{ + path: 'index', + meta: { title: '缁熻鎶ヨ〃', icon: 'dashboard'} + }] + state.topbarRouters = routes.concat(index); + }, + SET_SIDEBAR_ROUTERS: (state, routes) => { + state.sidebarRouters = routes }, }, actions: { @@ -30,7 +43,9 @@ const rewriteRoutes = filterAsyncRouter(rdata, false, true) rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true }) commit('SET_ROUTES', rewriteRoutes) - commit('SET_SIDEBAR_ROUTERS', sidebarRoutes) + commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes)) + commit('SET_DEFAULT_ROUTES', sidebarRoutes) + commit('SET_TOPBAR_ROUTES', sidebarRoutes) resolve(rewriteRoutes) }) }) diff --git a/ruoyi-ui/src/store/modules/settings.js b/ruoyi-ui/src/store/modules/settings.js index 8bd81a3..bb8062f 100644 --- a/ruoyi-ui/src/store/modules/settings.js +++ b/ruoyi-ui/src/store/modules/settings.js @@ -1,17 +1,18 @@ import variables from '@/assets/styles/element-variables.scss' import defaultSettings from '@/settings' -const { sideTheme, showSettings, tagsView, fixedHeader, sidebarLogo } = defaultSettings +const { sideTheme, showSettings, topNav, tagsView, fixedHeader, sidebarLogo } = defaultSettings +const storageSetting = JSON.parse(localStorage.getItem('layout-setting')) || '' const state = { theme: variables.theme, - sideTheme: sideTheme, + sideTheme: storageSetting.sideTheme || sideTheme, showSettings: showSettings, - tagsView: tagsView, - fixedHeader: fixedHeader, - sidebarLogo: sidebarLogo + topNav: storageSetting.topNav === undefined ? topNav : storageSetting.topNav, + tagsView: storageSetting.tagsView === undefined ? tagsView : storageSetting.tagsView, + fixedHeader: storageSetting.fixedHeader === undefined ? fixedHeader : storageSetting.fixedHeader, + sidebarLogo: storageSetting.sidebarLogo === undefined ? sidebarLogo : storageSetting.sidebarLogo } - const mutations = { CHANGE_SETTING: (state, { key, value }) => { if (state.hasOwnProperty(key)) { diff --git a/ruoyi-ui/src/store/modules/tagsView.js b/ruoyi-ui/src/store/modules/tagsView.js index 2e30d15..68bb81d 100644 --- a/ruoyi-ui/src/store/modules/tagsView.js +++ b/ruoyi-ui/src/store/modules/tagsView.js @@ -62,6 +62,23 @@ break } } + }, + + DEL_RIGHT_VIEWS: (state, view) => { + const index = state.visitedViews.findIndex(v => v.path === view.path) + if (index === -1) { + return + } + state.visitedViews = state.visitedViews.filter((item, idx) => { + if (idx <= index || (item.meta && item.meta.affix)) { + return true + } + const i = state.cachedViews.indexOf(item.name) + if (i > -1) { + state.cachedViews.splice(i, 1) + } + return false + }) } } @@ -148,6 +165,13 @@ updateVisitedView({ commit }, view) { commit('UPDATE_VISITED_VIEW', view) + }, + + delRightTags({ commit }, view) { + return new Promise(resolve => { + commit('DEL_RIGHT_VIEWS', view) + resolve([...state.visitedViews]) + }) } } diff --git a/ruoyi-ui/src/utils/ruoyi.js b/ruoyi-ui/src/utils/ruoyi.js index 53b2ae2..ac390f5 100644 --- a/ruoyi-ui/src/utils/ruoyi.js +++ b/ruoyi-ui/src/utils/ruoyi.js @@ -58,7 +58,7 @@ var search = params; search.params = {}; if (null != dateRange && '' != dateRange) { - if (typeof(propName) === "undefined") { + if (typeof (propName) === "undefined") { search.params["beginTime"] = dateRange[0]; search.params["endTime"] = dateRange[1]; } else { @@ -129,24 +129,47 @@ * @param {*} id id瀛楁 榛樿 'id' * @param {*} parentId 鐖惰妭鐐瑰瓧娈� 榛樿 'parentId' * @param {*} children 瀛╁瓙鑺傜偣瀛楁 榛樿 'children' - * @param {*} rootId 鏍笽d 榛樿 0 */ -export function handleTree(data, id, parentId, children, rootId) { - id = id || 'id' - parentId = parentId || 'parentId' - children = children || 'children' - rootId = rootId || Math.min.apply(Math, data.map(item => { return item[parentId] })) || 0 - //瀵规簮鏁版嵁娣卞害鍏嬮殕 - const cloneData = JSON.parse(JSON.stringify(data)) - //寰幆鎵�鏈夐」 - const treeData = cloneData.filter(father => { - let branchArr = cloneData.filter(child => { - //杩斿洖姣忎竴椤圭殑瀛愮骇鏁扮粍 - return father[id] === child[parentId] - }); - branchArr.length > 0 ? father.children = branchArr : ''; - //杩斿洖绗竴灞� - return father[parentId] === rootId; - }); - return treeData != '' ? treeData : data; +export function handleTree(data, id, parentId, children) { + let config = { + id: id || 'id', + parentId: parentId || 'parentId', + childrenList: children || 'children' + }; + + var childrenListMap = {}; + var nodeIds = {}; + var tree = []; + + for (let d of data) { + let parentId = d[config.parentId]; + if (childrenListMap[parentId] == null) { + childrenListMap[parentId] = []; + } + nodeIds[d[config.id]] = d; + childrenListMap[parentId].push(d); + } + + for (let d of data) { + let parentId = d[config.parentId]; + if (nodeIds[parentId] == null) { + tree.push(d); + } + } + + for (let t of tree) { + adaptToChildrenList(t); + } + + function adaptToChildrenList(o) { + if (childrenListMap[o[config.id]] !== null) { + o[config.childrenList] = childrenListMap[o[config.id]]; + } + if (o[config.childrenList]) { + for (let c of o[config.childrenList]) { + adaptToChildrenList(c); + } + } + } + return tree; } diff --git a/ruoyi-ui/src/views/monitor/druid/index.vue b/ruoyi-ui/src/views/monitor/druid/index.vue index da5b08f..a1a0bd9 100644 --- a/ruoyi-ui/src/views/monitor/druid/index.vue +++ b/ruoyi-ui/src/views/monitor/druid/index.vue @@ -8,7 +8,7 @@ name: "Druid", data() { return { - src: process.env.VUE_APP_BASE_API + "/druid/index.html", + src: process.env.VUE_APP_BASE_API + "/druid/login.html", height: document.documentElement.clientHeight - 94.5 + "px;", loading: true }; -- Gitblit v1.9.3