Skip to content

Commit 7469e89

Browse files
committed
fix: review suggestion
1 parent fd65991 commit 7469e89

2 files changed

Lines changed: 59 additions & 82 deletions

File tree

packages/canvas/container/src/components/CanvasMenu.vue

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ const current = ref(null)
4848
const menuDom = ref(null)
4949
const subMenuStyles = ref(null)
5050
51+
// 子菜单宽度常量
52+
const SUB_MENU_WIDTH = 137
53+
5154
export const closeMenu = () => {
5255
menuState.show = false
5356
current.value = null
@@ -70,11 +73,11 @@ export const openMenu = (event) => {
7073
if (right > canvasRect.right) {
7174
menuState.position.left = `${parseInt(menuState.position.left) - width - 2}px`
7275
}
73-
// sub-menu样式width为137px,少于100宽度的空白区域则放置到左侧
74-
if (right + 137 < canvasRect.right) {
75-
subMenuStyles.value = { right: '-137px' }
76+
// sub-menu样式width为 137 px,少于 137 宽度的空白区域则放置到左侧
77+
if (right + SUB_MENU_WIDTH < canvasRect.right) {
78+
subMenuStyles.value = { right: `-${SUB_MENU_WIDTH}px`, width: `${SUB_MENU_WIDTH}px` }
7679
} else {
77-
subMenuStyles.value = { left: '-137px' }
80+
subMenuStyles.value = { left: `-${SUB_MENU_WIDTH}px`, width: `${SUB_MENU_WIDTH}px` }
7881
}
7982
}
8083
})
@@ -137,12 +140,6 @@ export default {
137140
value: 'div',
138141
check: () => areSiblingNodes()
139142
},
140-
{
141-
name: '文字提示(公共父级)',
142-
code: 'groupWrap',
143-
value: 'TinyTooltip',
144-
check: () => areSiblingNodes()
145-
},
146143
{
147144
name: '弹出框(公共父级)',
148145
code: 'groupWrap',
@@ -400,7 +397,6 @@ export default {
400397
}
401398
}
402399
&.sub-menu {
403-
width: 137px;
404400
position: absolute;
405401
top: -2px;
406402
}

packages/canvas/container/src/composables/useMultiSelect.ts

Lines changed: 52 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,54 @@ interface SelectionState {
2020
// 初始化多选节点
2121
const multiSelectedStates = ref<SelectionState[]>([])
2222

23+
/**
24+
* 创建TinyPopover组件结构
25+
* @param {Object} props 组件属性
26+
* @param {Node | Node[]} content 内容节点
27+
* @returns {Node} TinyPopover组件结构
28+
*/
29+
const createTinyPopoverSchema = (props: Record<string, any> = {}, content: Node | Node[]): Node => {
30+
const children = Array.isArray(content) ? content : [content]
31+
32+
return {
33+
componentName: 'TinyPopover',
34+
id: props.id !== undefined ? props.id : null,
35+
props: {
36+
width: 200,
37+
title: '弹框标题',
38+
trigger: 'manual',
39+
modelValue: true,
40+
...props
41+
},
42+
children: [
43+
{
44+
componentName: 'Template',
45+
id: null,
46+
props: {
47+
slot: 'reference'
48+
},
49+
children
50+
},
51+
{
52+
componentName: 'Template',
53+
id: null,
54+
props: {
55+
slot: 'default'
56+
},
57+
children: [
58+
{
59+
componentName: 'div',
60+
id: null,
61+
props: {
62+
placeholder: '提示内容'
63+
}
64+
}
65+
]
66+
}
67+
]
68+
}
69+
}
70+
2371
export const useMultiSelect = () => {
2472
/**
2573
* 添加state到多选列表
@@ -146,7 +194,7 @@ export const useMultiSelect = () => {
146194
const selectedNodes = indices.map((index) => parent.children[index])
147195

148196
// 创建新的包装组件
149-
const wrapSchema: Node = {
197+
let wrapSchema: Node = {
150198
componentName,
151199
id: utils.guid(),
152200
props: { ...props },
@@ -155,38 +203,7 @@ export const useMultiSelect = () => {
155203

156204
// 特殊处理 TinyPopover 等组件
157205
if (componentName === 'TinyPopover') {
158-
wrapSchema.props = {
159-
width: 200,
160-
title: '弹框标题',
161-
trigger: 'manual',
162-
modelValue: true
163-
}
164-
wrapSchema.children = [
165-
{
166-
componentName: 'Template',
167-
id: null,
168-
props: {
169-
slot: 'reference'
170-
},
171-
children: selectedNodes
172-
},
173-
{
174-
componentName: 'Template',
175-
id: null,
176-
props: {
177-
slot: 'default'
178-
},
179-
children: [
180-
{
181-
componentName: 'div',
182-
id: null,
183-
props: {
184-
placeholder: '提示内容'
185-
}
186-
}
187-
]
188-
}
189-
]
206+
wrapSchema = createTinyPopoverSchema({ ...props, id: utils.guid() }, selectedNodes)
190207
}
191208

192209
// 从后向前删除原来的节点,避免索引变化
@@ -229,43 +246,7 @@ export const useMultiSelect = () => {
229246

230247
// 需要对popover特殊处理
231248
if (componentName === 'TinyPopover') {
232-
wrapSchema = {
233-
componentName,
234-
id: null,
235-
props: {
236-
width: 200,
237-
title: '弹框标题',
238-
trigger: 'manual',
239-
modelValue: true,
240-
...props
241-
},
242-
children: [
243-
{
244-
componentName: 'Template',
245-
id: null,
246-
props: {
247-
slot: 'reference'
248-
},
249-
children: [childSchema]
250-
},
251-
{
252-
componentName: 'Template',
253-
id: null,
254-
props: {
255-
slot: 'default'
256-
},
257-
children: [
258-
{
259-
componentName: 'div',
260-
id: null,
261-
props: {
262-
placeholder: '提示内容'
263-
}
264-
}
265-
]
266-
}
267-
]
268-
}
249+
wrapSchema = createTinyPopoverSchema(props, childSchema)
269250
}
270251

271252
return wrapSchema
@@ -310,7 +291,7 @@ export const useMultiSelect = () => {
310291
)
311292
})
312293

313-
return false
294+
return true
314295
}
315296

316297
return {

0 commit comments

Comments
 (0)