Skip to content

Commit 04ad326

Browse files
author
Taois
committed
feat:全局动作可以进行一些基本的交互
1 parent 73f5beb commit 04ad326

File tree

1 file changed

+87
-47
lines changed

1 file changed

+87
-47
lines changed

dashboard/src/components/GlobalActionDialog.vue

Lines changed: 87 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,30 @@
9393
</div>
9494
</div>
9595
</div>
96+
97+
<!-- ActionRenderer组件 -->
98+
<ActionRenderer
99+
v-if="showActionRenderer"
100+
ref="actionRendererRef"
101+
:action-data="currentActionData"
102+
:module="currentActionData?.siteKey"
103+
:extend="currentActionData?.siteExt"
104+
:api-url="currentActionData?.siteApi"
105+
:visible="showActionRenderer"
106+
@close="handleActionRendererClose"
107+
@action="handleActionRendererAction"
108+
@success="handleActionRendererSuccess"
109+
@error="handleActionRendererError"
110+
@special-action="handleSpecialAction"
111+
/>
96112
</a-modal>
97113
</template>
98114

99115
<script setup>
100116
import { ref, computed, watch } from 'vue'
101117
import { Message } from '@arco-design/web-vue'
102118
import { Actions } from '@/components/actions'
119+
import ActionRenderer from '@/components/actions/ActionRenderer.vue'
103120
104121
const props = defineProps({
105122
visible: {
@@ -112,11 +129,16 @@ const props = defineProps({
112129
}
113130
})
114131
115-
const emit = defineEmits(['update:visible', 'action-executed'])
132+
const emit = defineEmits(['update:visible', 'action-executed', 'special-action'])
116133
117134
const searchKeyword = ref('')
118135
const selectedSiteKey = ref('')
119136
137+
// ActionRenderer 相关状态
138+
const showActionRenderer = ref(false)
139+
const currentActionData = ref(null)
140+
const actionRendererRef = ref(null)
141+
120142
// 计算所有可用的动作
121143
const allActions = computed(() => {
122144
const actions = []
@@ -260,50 +282,11 @@ const handleActionClick = async (action) => {
260282
actionConfig.siteApi = action.siteApi
261283
actionConfig.siteExt = action.siteExt
262284
263-
// 根据动作类型执行相应的操作
264-
let result
265-
switch (actionConfig.type) {
266-
case 'input':
267-
result = await Actions.input(actionConfig)
268-
break
269-
case 'multiInput':
270-
result = await Actions.multiInput(actionConfig)
271-
break
272-
case 'multiInputX':
273-
result = await Actions.multiInputX(actionConfig)
274-
break
275-
case 'menu':
276-
result = await Actions.menu(actionConfig)
277-
break
278-
case 'select':
279-
result = await Actions.select(actionConfig)
280-
break
281-
case 'msgbox':
282-
result = await Actions.msgBox(actionConfig)
283-
break
284-
case 'webview':
285-
result = await Actions.webView(actionConfig)
286-
break
287-
case 'help':
288-
result = await Actions.help(actionConfig)
289-
break
290-
default:
291-
// 对于未知类型,显示错误信息
292-
result = await Actions.error(`不支持的动作类型: ${actionConfig.type}`)
293-
break
294-
}
295-
296-
// 发送动作执行完成事件
297-
emit('action-executed', {
298-
action,
299-
result,
300-
success: true
301-
})
285+
console.log('<actionConfig>:', actionConfig)
302286
303-
Message.success(`动作 "${action.name}" 执行成功`)
304-
305-
// 关闭弹窗
306-
handleCancel()
287+
// 使用 ActionRenderer 组件显示动作交互界面
288+
currentActionData.value = actionConfig
289+
showActionRenderer.value = true
307290
308291
} catch (error) {
309292
console.error('执行全局动作失败:', error)
@@ -315,9 +298,7 @@ const handleActionClick = async (action) => {
315298
success: false
316299
})
317300
318-
if (error.type !== 'cancel') {
319-
Message.error(`动作 "${action.name}" 执行失败: ${error.message}`)
320-
}
301+
Message.error(`动作 "${action.name}" 执行失败: ${error.message}`)
321302
}
322303
}
323304
@@ -328,6 +309,65 @@ const handleCancel = () => {
328309
selectedSiteKey.value = ''
329310
}
330311
312+
// ActionRenderer 事件处理函数
313+
const handleActionRendererClose = () => {
314+
showActionRenderer.value = false
315+
currentActionData.value = null
316+
}
317+
318+
const handleActionRendererAction = async (actionId, value) => {
319+
console.log('ActionRenderer 动作执行:', { actionId, value })
320+
// 这里可以添加自定义的动作处理逻辑
321+
return { success: true, message: '动作执行成功' }
322+
}
323+
324+
const handleActionRendererSuccess = (value) => {
325+
console.log('ActionRenderer 执行成功:', value)
326+
327+
// 发送动作执行完成事件
328+
emit('action-executed', {
329+
action: currentActionData.value,
330+
result: value,
331+
success: true
332+
})
333+
334+
Message.success(`动作执行成功`)
335+
336+
// 关闭 ActionRenderer
337+
handleActionRendererClose()
338+
339+
// 关闭全局动作弹窗
340+
handleCancel()
341+
}
342+
343+
const handleActionRendererError = (error) => {
344+
console.error('ActionRenderer 执行失败:', error)
345+
346+
// 发送动作执行失败事件
347+
emit('action-executed', {
348+
action: currentActionData.value,
349+
error: error.message || error,
350+
success: false
351+
})
352+
353+
if (error.type !== 'cancel') {
354+
Message.error(`动作执行失败: ${error.message || error}`)
355+
}
356+
357+
// 关闭 ActionRenderer
358+
handleActionRendererClose()
359+
}
360+
361+
const handleSpecialAction = (actionType, actionData) => {
362+
console.log('ActionRenderer special-action:', { actionType, actionData })
363+
364+
// 发送特殊动作事件给父组件处理
365+
emit('special-action', actionType, actionData)
366+
367+
// 关闭 ActionRenderer
368+
handleActionRendererClose()
369+
}
370+
331371
// 监听弹窗显示状态,重置搜索和筛选
332372
watch(() => props.visible, (newVisible) => {
333373
if (newVisible) {

0 commit comments

Comments
 (0)