fix: 资产管理区分主子阵地v1.0

develop
时启龙 2024-08-28 10:39:27 +08:00
parent d40145d562
commit 27c57d8c49
8 changed files with 94 additions and 18 deletions

View File

@ -3,6 +3,7 @@
*/
import { request } from '@cmp/cmp-element'
import { wrapperParams } from 'utils'
import { getSelectPosition } from '@/views/usePostion'
export function getPropertiesByCode(code) {
return request.get('/ims/v1/properties', {
params: wrapperParams({ code }),
@ -70,7 +71,7 @@ export function getModuleGroupRoot() {
}
export function getModuleGroupChildren(groupId, params) {
return request.get(`${baseUrl}/group/${groupId}/children`, { params })
return request.get(`${baseUrl}/group/${groupId}/children`, { params: { positionKey: getSelectPosition(), ...params } })
}
export function getRootGroups(groupId) {

View File

@ -1,4 +1,5 @@
import { request } from '@cmp/cmp-element'
import { getSelectPosition } from '@/views/usePostion'
export function getValidateRules(type: string) {
return request.get('/ams/v1/regexps', {
@ -7,7 +8,11 @@ export function getValidateRules(type: string) {
}
export function getPropertyByModule(moduleId: number) {
return request.get(`/ams/v1/module/${moduleId}/properties`)
return request.get(`/ams/v1/module/${moduleId}/properties`, {
params: {
positionKey: getSelectPosition(),
},
})
}
export function getModuleRelation(params: { sourceId: number; targetId: number; relationCategoryId: number }) {

View File

@ -1,8 +1,9 @@
import { request, downloadFile } from '@cmp/cmp-element'
import { getSelectPosition } from '@/views/usePostion'
const baseUrl = '/ams/v1/instances'
export function getInstance(params: Base.IListParams) {
return request.get(baseUrl, { params })
return request.get(baseUrl, { params: { positionKey: getSelectPosition(), ...params } })
}
export function getInstanceDetail(id: number) {
return request.get(`${baseUrl}/${id}`)

View File

@ -19,7 +19,6 @@ const codeMap = new Map([
['MULTILINETABLE', 'table-module'],
])
const vueFiles = require.context('./', true, /\.vue$/)
console.log(vueFiles)
export const components = getModules(vueFiles)
export function getCurrentComponent(type) {

View File

@ -1,7 +1,7 @@
<template>
<div>
<cb-advance-table :key="currentModule.id" v-if="!detailVisible" title="资源列表" :search-configs="searchConfigs" :data="list" :params="params" :columns="columns" :get-list="getList" :total="total" :loading="loading" @selection-change="handleSelectionChange">
<template #action>
<template #action v-if="isLeaderPosition">
<el-button type="primary" @click="handleCreate()" icon="el-icon-plus" :disabled="!currentModule.id">新增</el-button>
<ImportData url="/api/ams/v1/instances/upload" @getData="getList" template-url="/ams/v1/instances/download" :disabled="!currentModule.id" :params="{ moduleId: currentModule.id, moduleCode: currentModule.code, type: '2007' }"></ImportData>
<el-button @click="exportData" icon="el-icon-download" :disabled="!currentModule.id">导出</el-button>
@ -34,9 +34,11 @@
<span>{{ getMultileName(val, column.prop, propertyList) }}</span>
</template>
<template #operate="val, record" v-if="list.length">
<el-button type="text" @click="handleCreate(record)" :disabled="!record.authEdit"><i class="el-icon-edit"></i> 编辑</el-button>
<div class="action-divider"></div>
<el-button type="text" @click="handleDelete(record, { moduleCode: currentModule.code })" :disabled="!record.authDelete"><i class="el-icon-delete"></i> 删除</el-button>
<template v-if="isLeaderPosition">
<el-button type="text" @click="handleCreate(record)" :disabled="!record.authEdit"><i class="el-icon-edit"></i> 编辑</el-button>
<div class="action-divider"></div>
<el-button type="text" @click="handleDelete(record, { moduleCode: currentModule.code })" :disabled="!record.authDelete"><i class="el-icon-delete"></i> 删除</el-button>
</template>
</template>
</cb-advance-table>
<!--新增编辑界面-->
@ -55,7 +57,7 @@ import BatchEditDialog from './BatchEditDialog.vue'
import AuthDialog from './detail/AuthDialog.vue'
import TipDialog from './TipDialog.vue'
import { getInstance, removeInstance, exportInstance, batchRemove } from 'services/resource/moduleInstance'
import { defineComponent, ref, Ref } from 'vue'
import { defineComponent, ref, Ref, inject } from 'vue'
import { Message, MessageBox } from 'element-ui'
import { useTable, useSelection } from '@cmp/cmp-element'
import { getPropertyByModule } from 'services/index'
@ -66,6 +68,7 @@ import ImportData from '@cmp/cmp-common/components/import-data/index.vue'
export default defineComponent({
components: { AddDialog, DetailItem, ImportData, BatchEditDialog, TipDialog, AuthDialog },
setup(props, context) {
const isLeaderPosition = inject('isLeaderPosition') as Ref<boolean>
const { list, total, params, handleDelete, loading, getList } = useTable({
getService: getInstance,
removeService: removeInstance,
@ -234,6 +237,7 @@ export default defineComponent({
tipDialog,
batchOperate,
authDialog,
isLeaderPosition,
}
},
})

View File

@ -1,7 +1,7 @@
<template>
<div>
<cb-advance-table ref="tableRef" :card-border="false" :search-configs="searchConfigs" :data="list" :params="params" :columns="columns" :get-list="getList" :total="total" :loading="loading">
<template #action>
<template #action v-if="isLeaderPosition">
<el-button type="primary" @click="handleCreate()" icon="el-icon-plus">新增</el-button>
</template>
<template #operate="val, record">
@ -16,7 +16,7 @@
</template>
<script lang="ts">
import { getAuth, removeAuth } from 'services/resource/auth'
import { defineComponent, reactive, toRefs, ref } from 'vue'
import { defineComponent, reactive, inject, ref } from 'vue'
import { Message, MessageBox } from 'element-ui'
import { useTable } from '@cmp/cmp-element'
import { cloneDeep } from 'lodash-es'
@ -65,6 +65,7 @@ export default defineComponent({
},
},
setup(props) {
const isLeaderPosition = inject('isLeaderPosition')
const searchConfigs = reactive(cloneDeep(searchConfig))
searchConfigs[0].initValue = props.detailData.moduleId
searchConfigs[1].initValue = props.detailData.id
@ -109,6 +110,7 @@ export default defineComponent({
addDialog,
handleCreate,
handleDelete,
isLeaderPosition,
}
},
})

View File

@ -1,6 +1,10 @@
<template>
<split-pane :min-percent="10" :default-percent="15" split="vertical" style="height: calc(100vh - 110px)">
<template slot="paneL">
<!-- <el-button @click="setIsLeaderPosition"> {{ isLeaderPosition }}</el-button>
<el-radio-group v-model="select" @change="SET_SELECTED_POSITION" v-if="isLeaderPosition">
<el-radio v-for="item in ['sma-1', 'ams-2']" :key="item" :label="item">{{ item }}</el-radio>
</el-radio-group> -->
<SideMenu @handleNodeClick="handleNodeClick"></SideMenu>
</template>
<template slot="paneR">
@ -9,30 +13,57 @@
</split-pane>
</template>
<script lang="ts">
import { computed, defineComponent, ref, watch } from 'vue'
import { defineComponent, ref, unref } from 'vue'
import SplitPane from 'vue-splitpane'
import SideMenu from './SideMenu.vue'
import RightList from './List.vue'
import { useStore } from '@cmp/cmp-core'
import usePostion from '@/views/usePostion'
const addStorageEvent = (key, data) => {
// StorageEvent
var newStorageEvent = document.createEvent('StorageEvent')
const storage = {
setItem: function (k, val) {
sessionStorage.setItem(k, val)
//
newStorageEvent.initStorageEvent('setItem', false, false, k, null, val, null, null)
//
window.dispatchEvent(newStorageEvent)
},
}
return storage.setItem(key, data)
}
export default defineComponent({
components: { SplitPane, SideMenu, RightList },
setup() {
const store = useStore()
console.log(store)
const selectedPostion = computed(() => store.state.position.selectedPostion)
watch(selectedPostion, (val) => {
console.log('阵地切换', val)
// eslint-disable-next-line
const { isLeaderPosition } = usePostion(() => {
handleNodeClick(unref(lastNode))
})
const lastNode = ref(null)
const listRef = ref()
function handleNodeClick(node: any) {
lastNode.value = node
const { type, id } = node
if (type === 'module') {
listRef.value.init(node)
}
}
const select = ref('')
const SET_SELECTED_POSITION = () => {
addStorageEvent('selectPostion', unref(select))
}
const setIsLeaderPosition = () => {
const val = Math.random() > 0.5
addStorageEvent('isLeaderPosition', val)
if (!val) addStorageEvent('selectPostion', '')
}
return {
listRef,
handleNodeClick,
isLeaderPosition,
setIsLeaderPosition,
select,
SET_SELECTED_POSITION,
}
},
})

View File

@ -0,0 +1,33 @@
import { computed, onMounted, onUnmounted, provide, ref, unref, watch } from 'vue'
const usePostion = (cb?: Function) => {
const isLeaderPosition = ref(false)
const selectPostion = ref('')
provide(
'isLeaderPosition',
computed(() => unref(isLeaderPosition))
)
const handleStorageEvent = (event) => {
if (event.key === 'isLeaderPosition') {
isLeaderPosition.value = event.newValue === 'true'
}
if (event.key === 'selectPostion') {
selectPostion.value = event.newValue
}
}
watch(selectPostion, () => {
if (typeof cb === 'function') {
cb()
}
})
onMounted(() => window.addEventListener('setItem', handleStorageEvent))
onUnmounted(() => window.removeEventListener('setItem', handleStorageEvent))
return {
isLeaderPosition,
}
}
export const getSelectPosition = () => {
return window.sessionStorage.getItem('selectPostion')
}
export default usePostion