fix: 修改右键

This commit is contained in:
MTrun 2022-02-07 20:55:40 +08:00
parent 8fb8b9328d
commit 88b03a416c
8 changed files with 83 additions and 54 deletions

View File

@ -0,0 +1,3 @@
import ChartSetting from './index.vue'
export { ChartSetting }

View File

@ -8,6 +8,5 @@
<style lang="scss" scoped> <style lang="scss" scoped>
@include go('chart-content-details') { @include go('chart-content-details') {
position: relative;
} }
</style> </style>

View File

@ -1,3 +0,0 @@
import Setting from './index.vue'
export { Setting }

View File

@ -26,16 +26,22 @@
size="small" size="small"
type="segment" type="segment"
> >
<n-tab-pane size="small" display-directive="show:lazy"> <n-tab-pane
v-for="item in globalTabList"
:key="item.key"
:name="item.key"
size="small"
display-directive="show:lazy"
>
<template #tab> <template #tab>
<n-space> <n-space>
<span> 页面设置 </span> <span>{{ item.title }}</span>
<n-icon size="16" class="icon-position"> <n-icon size="16" class="icon-position">
<DesktopOutlineIcon /> <component :is="item.icon"></component>
</n-icon> </n-icon>
</n-space> </n-space>
</template> </template>
<CanvasPage name="canvas" /> <component :is="item.render"></component>
</n-tab-pane> </n-tab-pane>
</n-tabs> </n-tabs>
@ -47,7 +53,7 @@
type="segment" type="segment"
> >
<n-tab-pane <n-tab-pane
v-for="item in tabList" v-for="item in canvasTabList"
:key="item.key" :key="item.key"
:name="item.key" :name="item.key"
size="small" size="small"
@ -86,8 +92,8 @@ const { ConstructIcon, FlashIcon, DesktopOutlineIcon } = icon.ionicons5
const ContentEdit = loadAsyncComponent(() => import('../ContentEdit/index.vue')) const ContentEdit = loadAsyncComponent(() => import('../ContentEdit/index.vue'))
const CanvasPage = loadSkeletonAsyncComponent(() =>import('./components/CanvasPage/index.vue')) const CanvasPage = loadSkeletonAsyncComponent(() =>import('./components/CanvasPage/index.vue'))
const Setting = loadSkeletonAsyncComponent(() =>import('./components/Setting/index.vue')) const ChartSetting = loadSkeletonAsyncComponent(() =>import('./components/ChartSetting/index.vue'))
const Behind = loadSkeletonAsyncComponent(() => import('./components/Behind/index.vue')) const ChartBehind = loadSkeletonAsyncComponent(() => import('./components/ChartBehind/index.vue'))
const collapsed = ref<boolean>(getDetails.value) const collapsed = ref<boolean>(getDetails.value)
@ -118,24 +124,27 @@ watch(getDetails, newData => {
}) })
// //
const pageSetting = reactive({ const globalTabList = reactive([
key: 'pageSetting',
title: '页面设置',
render: CanvasPage
})
const tabList = shallowRef([
{ {
key: 'setting', key: 'pageSetting',
title: '设置', title: '页面配置',
icon: DesktopOutlineIcon,
render: CanvasPage
}
])
const canvasTabList = shallowRef([
{
key: 'ChartSetting',
title: '定制',
icon: ConstructIcon, icon: ConstructIcon,
render: Setting render: ChartSetting
}, },
{ {
key: 'behind', key: 'ChartBehind',
title: '数据', title: '数据',
icon: FlashIcon, icon: FlashIcon,
render: Behind render: ChartBehind
} }
]) ])
</script> </script>

View File

@ -14,13 +14,13 @@
<!-- 图层内容 --> <!-- 图层内容 -->
<ListItem <ListItem
v-for="(item) in chartEditStore.getComponentList" v-for="item in chartEditStore.getComponentList"
:key="item.id" :key="item.id"
:componentData="item" :componentData="item"
@mousedown="mousedownHandle(item)" @mousedown="mousedownHandle(item)"
@mouseenter="mouseenterHandle(item)" @mouseenter="mouseenterHandle(item)"
@mouseleave="mouseleaveHandle(item)" @mouseleave="mouseleaveHandle(item)"
@contextmenu="handleContextMenu($event, item)" @contextmenu="handleContextMenu($event)"
/> />
</ContentBox> </ContentBox>
</template> </template>
@ -30,11 +30,17 @@ import { ContentBox } from '../ContentBox/index'
import { useChartLayoutStore } from '@/store/modules/chartLayoutStore/chartLayoutStore' import { useChartLayoutStore } from '@/store/modules/chartLayoutStore/chartLayoutStore'
import { ChartLayoutStoreEnum } from '@/store/modules/chartLayoutStore/chartLayoutStore.d' import { ChartLayoutStoreEnum } from '@/store/modules/chartLayoutStore/chartLayoutStore.d'
import { useChartEditStoreStore } from '@/store/modules/chartEditStore/chartEditStore' import { useChartEditStoreStore } from '@/store/modules/chartEditStore/chartEditStore'
import { ChartEditStoreEnum, TargetChartType } from '@/store/modules/chartEditStore/chartEditStore.d'
import { CreateComponentType } from '@/packages/index.d' import { CreateComponentType } from '@/packages/index.d'
import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook' import {
ChartEditStoreEnum,
TargetChartType
} from '@/store/modules/chartEditStore/chartEditStore.d'
import {
useContextMenu,
MenuOptionsItemType,
MenuEnum
} from '@/views/chart/hooks/useContextMenu.hook'
import { ListItem } from './components/ListItem/index' import { ListItem } from './components/ListItem/index'
import { icon } from '@/plugins' import { icon } from '@/plugins'
@ -42,7 +48,10 @@ import { icon } from '@/plugins'
const { LayersIcon } = icon.ionicons5 const { LayersIcon } = icon.ionicons5
const chartLayoutStore = useChartLayoutStore() const chartLayoutStore = useChartLayoutStore()
const chartEditStore = useChartEditStoreStore() const chartEditStore = useChartEditStoreStore()
const { handleContextMenu } = useContextMenu()
const { handleContextMenu } = useContextMenu({
hideOptionsList: [MenuEnum.CLEAR, MenuEnum.PARSE]
})
const backHandle = () => { const backHandle = () => {
chartLayoutStore.setItem(ChartLayoutStoreEnum.LAYERS, false) chartLayoutStore.setItem(ChartLayoutStoreEnum.LAYERS, false)

View File

@ -1,4 +1,4 @@
import { ref, nextTick } from 'vue' import { reactive, nextTick } from 'vue'
import { useChartEditStoreStore } from '@/store/modules/chartEditStore/chartEditStore' import { useChartEditStoreStore } from '@/store/modules/chartEditStore/chartEditStore'
import { CreateComponentType } from '@/packages/index.d' import { CreateComponentType } from '@/packages/index.d'
import { renderIcon, loadingError } from '@/utils' import { renderIcon, loadingError } from '@/utils'
@ -104,22 +104,13 @@ const defaultOptions: MenuOptionsItemType[] = [
} }
] ]
/** // * 去除隐藏选项
* * hook const clearHideOption = (options: MenuOptionsItemType[], hideList?: MenuEnum[]) => {
* @param menuOption if(!hideList) return options
* @returns const a = options.filter((op: MenuOptionsItemType) => {
*/ return hideList.findIndex((e: MenuEnum) => e !== op.key)
export const useContextMenu = (menuOption?: { })
// 自定义右键配置 }
selfOptions: MenuOptionsItemType[]
// 前置处理函数
optionsHandle: Function
}) => {
const selfOptions = menuOption?.selfOptions
const optionsHandle = menuOption?.optionsHandle
// * 右键选项
const menuOptions: MenuOptionsItemType[] = selfOptions || defaultOptions
// * 右键处理 // * 右键处理
const handleContextMenu = (e: MouseEvent, item: CreateComponentType) => { const handleContextMenu = (e: MouseEvent, item: CreateComponentType) => {
@ -136,6 +127,26 @@ export const useContextMenu = (menuOption?: {
}) })
} }
/**
* * hook
* @param menuConfig
* @returns
*/
export const useContextMenu = (menuConfig: {
// 自定义右键配置
selfOptions?: MenuOptionsItemType[]
// 前置处理函数
optionsHandle?: Function
// 隐藏列表
hideOptionsList?: MenuEnum[]
}) => {
const selfOptions = menuConfig?.selfOptions
const optionsHandle = menuConfig?.optionsHandle
const hideOptionsList = menuConfig?.hideOptionsList
// * 右键选项
const menuOptions: MenuOptionsItemType[] = selfOptions || defaultOptions
// * 失焦 // * 失焦
const onClickoutside = () => { const onClickoutside = () => {
chartEditStore.setRightMenuShow(false) chartEditStore.setRightMenuShow(false)
@ -158,9 +169,10 @@ export const useContextMenu = (menuOption?: {
} }
}) })
} }
return { return {
menuOptions: optionsHandle ? optionsHandle(menuOptions) : menuOptions, // todo 每次都重新计算的功能
// menuOptions: clearHideOption ? clearHideOption(menuOptions, hideOptionsList) : menuOptions,
menuOptions: menuOptions,
handleContextMenu, handleContextMenu,
onClickoutside, onClickoutside,
handleMenuSelect, handleMenuSelect,