From 035171cbe8bb806ddd81d61d508d1c8136b872c8 Mon Sep 17 00:00:00 2001 From: LH_R Date: Fri, 15 Aug 2025 16:04:10 +0800 Subject: [PATCH] feat(ui): update resource view menu display and CMDB route redirection --- cmdb-ui/src/components/Ellipsis/Ellipsis.vue | 60 + cmdb-ui/src/components/Ellipsis/index.js | 3 + cmdb-ui/src/components/Ellipsis/index.md | 38 + cmdb-ui/src/components/Menu/menu.js | 85 +- cmdb-ui/src/components/index.js | 4 +- cmdb-ui/src/components/tools/TopMenu.vue | 15 +- .../cmdb/components/cmdbGrant/utils.js | 13 +- .../subscribeSetting/subscribeSetting.vue | 13 +- cmdb-ui/src/modules/cmdb/router/index.js | 42 +- cmdb-ui/src/modules/cmdb/views/ci/index.vue | 1014 ++++------------- .../modules/cmdb/views/ci/instanceList.vue | 829 ++++++++++++++ .../views/ci/modules/CreateInstanceForm.vue | 6 +- 12 files changed, 1207 insertions(+), 915 deletions(-) create mode 100644 cmdb-ui/src/components/Ellipsis/Ellipsis.vue create mode 100644 cmdb-ui/src/components/Ellipsis/index.js create mode 100644 cmdb-ui/src/components/Ellipsis/index.md create mode 100644 cmdb-ui/src/modules/cmdb/views/ci/instanceList.vue diff --git a/cmdb-ui/src/components/Ellipsis/Ellipsis.vue b/cmdb-ui/src/components/Ellipsis/Ellipsis.vue new file mode 100644 index 0000000..ff8d69c --- /dev/null +++ b/cmdb-ui/src/components/Ellipsis/Ellipsis.vue @@ -0,0 +1,60 @@ + diff --git a/cmdb-ui/src/components/Ellipsis/index.js b/cmdb-ui/src/components/Ellipsis/index.js new file mode 100644 index 0000000..91e3ff4 --- /dev/null +++ b/cmdb-ui/src/components/Ellipsis/index.js @@ -0,0 +1,3 @@ +import Ellipsis from './Ellipsis' + +export default Ellipsis diff --git a/cmdb-ui/src/components/Ellipsis/index.md b/cmdb-ui/src/components/Ellipsis/index.md new file mode 100644 index 0000000..f528ac7 --- /dev/null +++ b/cmdb-ui/src/components/Ellipsis/index.md @@ -0,0 +1,38 @@ +# Ellipsis 文本自动省略号 + +文本过长自动处理省略号,支持按照文本长度和最大行数两种方式截取。 + + + +引用方式: + +```javascript +import Ellipsis from '@/components/Ellipsis' + +export default { + components: { + Ellipsis + } +} +``` + + + +## 代码演示 [demo](https://pro.loacg.com/test/home) + +```html + + There were injuries alleged in three cases in 2015, and a + fourth incident in September, according to the safety recall report. After meeting with US regulators in October, the firm decided to issue a voluntary recall. + +``` + + + +## API + + +参数 | 说明 | 类型 | 默认值 +----|------|-----|------ +tooltip | 移动到文本展示完整内容的提示 | boolean | - +length | 在按照长度截取下的文本最大字符数,超过则截取省略 | number | - \ No newline at end of file diff --git a/cmdb-ui/src/components/Menu/menu.js b/cmdb-ui/src/components/Menu/menu.js index 24d3cc5..e9f2e79 100644 --- a/cmdb-ui/src/components/Menu/menu.js +++ b/cmdb-ui/src/components/Menu/menu.js @@ -1,14 +1,6 @@ -import router, { resetRouter } from '@/router' import Menu from 'ant-design-vue/es/menu' import Icon from 'ant-design-vue/es/icon' -import store from '@/store' -import { - subscribeCIType, - subscribeTreeView, -} from '@/modules/cmdb/api/preference' import { searchResourceType } from '@/modules/acl/api/resource' -import { roleHasPermissionToGrant } from '@/modules/acl/api/permission' -import CMDBGrant from '@/modules/cmdb/components/cmdbGrant' import styles from './index.module.less' import { mapActions } from 'vuex' @@ -87,40 +79,6 @@ export default { inject: ['reload'], methods: { ...mapActions(['UpdateCMDBSEarchValue']), - cancelAttributes(e, menu) { - const that = this - e.preventDefault() - e.stopPropagation() - this.$confirm({ - title: this.$t('warning'), - content: this.$t('cmdb.preference.confirmcancelSub2', { name: menu.meta.title }), - onOk() { - const citypeId = menu.meta.typeId - const unsubCIType = subscribeCIType(citypeId, '') - const unsubTree = subscribeTreeView(citypeId, '') - Promise.all([unsubCIType, unsubTree]).then(() => { - that.$message.success(that.$t('cmdb.preference.cancelSubSuccess')) - const lastTypeId = window.localStorage.getItem('ops_ci_typeid') || undefined - if (Number(citypeId) === Number(lastTypeId)) { - localStorage.setItem('ops_ci_typeid', '') - } - const href = window.location.href - const hrefSplit = href.split('/') - if (Number(hrefSplit[hrefSplit.length - 1]) === Number(citypeId)) { - that.$router.push('/cmdb/preference') - } - const roles = store.getters.roles - resetRouter() - store.dispatch('GenerateRoutes', { roles }, { root: true }).then(() => { - router.addRoutes(store.getters.appRoutes) - }) - if (hrefSplit[hrefSplit.length - 1] === 'preference') { - that.reload() - } - }) - }, - }) - }, // select menu item onOpenChange(openKeys) { if (this.mode === 'horizontal') { @@ -170,7 +128,6 @@ export default { return this.$t(`${title}`) }, renderMenuItem(menu) { - const isShowDot = menu.path.substr(0, 22) === '/cmdb/instances/types/' const target = menu.meta.target || null const tag = target && 'a' || 'router-link' const props = { to: { name: menu.name } } @@ -187,26 +144,11 @@ export default { {this.renderIcon({ icon: menu.meta.icon, customIcon: menu.meta.customIcon, name: menu.meta.name, typeId: menu.meta.typeId, routeName: menu.name, selectedIcon: menu.meta.selectedIcon, })} - 10 ? 'scroll' : ''}>{this.renderI18n(menu.meta.title)} - {isShowDot && !menu.meta.disabled && - trigger} - content={() => -
-
this.handlePerm(e, menu, 'CIType')} class="custom-menu-extra-submenu-item">{ this.renderI18n('grant') }
-
this.cancelAttributes(e, menu)} class="custom-menu-extra-submenu-item">{ this.renderI18n('cmdb.preference.cancelSub') }
-
} - > - -
- } + 10 ? 'scroll' : ''}> + {this.renderI18n(menu.meta.title)} +
- {isShowDot && } ) }, @@ -269,27 +211,6 @@ export default { ) } }, - handlePerm(e, menu, resource_type_name) { - e.stopPropagation() - e.preventDefault() - roleHasPermissionToGrant({ - app_id: 'cmdb', - resource_type_name, - perm: 'grant', - resource_name: menu.meta.name, - }).then(res => { - if (res.result) { - console.log(menu) - if (resource_type_name === 'CIType') { - this.$refs.cmdbGrantCIType.open({ name: menu.meta.name, cmdbGrantType: 'ci', CITypeId: menu.meta?.typeId }) - } else { - this.$refs.cmdbGrantRelationView.open({ name: menu.meta.name, cmdbGrantType: 'relation_view' }) - } - } else { - this.$message.error(this.$t('noPermission')) - } - }) - }, jumpCMDBSearch(value) { this.UpdateCMDBSEarchValue(value) diff --git a/cmdb-ui/src/components/index.js b/cmdb-ui/src/components/index.js index 3b4e3fc..77b4a81 100644 --- a/cmdb-ui/src/components/index.js +++ b/cmdb-ui/src/components/index.js @@ -2,10 +2,12 @@ import MultiTab from '@/components/MultiTab' import Result from '@/components/Result' import TagSelect from '@/components/TagSelect' import ExceptionPage from '@/components/Exception' +import Ellipsis from '@/components/Ellipsis' export { MultiTab, Result, ExceptionPage, - TagSelect + TagSelect, + Ellipsis } diff --git a/cmdb-ui/src/components/tools/TopMenu.vue b/cmdb-ui/src/components/tools/TopMenu.vue index bf9c97e..6e98d4c 100644 --- a/cmdb-ui/src/components/tools/TopMenu.vue +++ b/cmdb-ui/src/components/tools/TopMenu.vue @@ -38,7 +38,7 @@ - - diff --git a/cmdb-ui/src/modules/cmdb/views/ci/instanceList.vue b/cmdb-ui/src/modules/cmdb/views/ci/instanceList.vue new file mode 100644 index 0000000..ff38641 --- /dev/null +++ b/cmdb-ui/src/modules/cmdb/views/ci/instanceList.vue @@ -0,0 +1,829 @@ + + + + + + + diff --git a/cmdb-ui/src/modules/cmdb/views/ci/modules/CreateInstanceForm.vue b/cmdb-ui/src/modules/cmdb/views/ci/modules/CreateInstanceForm.vue index 0fad2eb..b31d1a5 100644 --- a/cmdb-ui/src/modules/cmdb/views/ci/modules/CreateInstanceForm.vue +++ b/cmdb-ui/src/modules/cmdb/views/ci/modules/CreateInstanceForm.vue @@ -191,6 +191,10 @@ export default { CIReferenceAttr }, props: { + typeIdFromProp: { + type: Number, + default: 0, + }, typeIdFromRelation: { type: Number, default: 0, @@ -235,7 +239,7 @@ export default { if (this.typeIdFromRelation) { return this.typeIdFromRelation } - return this.$router.currentRoute.meta.typeId + return this.typeIdFromProp }, valueTypeMap() { return valueTypeMap()