@@ -117,6 +117,8 @@ import { ref, computed, watch } from 'vue'
117117import { Message } from ' @arco-design/web-vue'
118118import { Actions } from ' @/components/actions'
119119import ActionRenderer from ' @/components/actions/ActionRenderer.vue'
120+ import { executeAction } from ' @/api/modules/module.js'
121+ import { getActionTimeout } from ' @/api/config'
120122
121123const props = defineProps ({
122124 visible: {
@@ -245,6 +247,55 @@ const getEmptyStateHint = () => {
245247 return ' 请确保站源配置中包含动作信息'
246248}
247249
250+ // T4接口调用方法
251+ const callT4Action = async (action , siteKey , apiUrl , extend ) => {
252+ if (! siteKey && ! apiUrl) {
253+ console .warn (' 未提供siteKey或apiUrl,无法调用T4接口' )
254+ return null
255+ }
256+
257+ const actionData = {
258+ action: action
259+ }
260+
261+ // 添加扩展参数
262+ if (extend && extend .ext ) {
263+ actionData .extend = extend .ext
264+ }
265+
266+ // 添加API URL到actionData中
267+ if (apiUrl) {
268+ actionData .apiUrl = apiUrl
269+ }
270+
271+ console .log (' GlobalActionDialog调用T4接口:' , {
272+ siteKey,
273+ actionData,
274+ apiUrl
275+ })
276+
277+ let result = null
278+ if (siteKey) {
279+ console .log (' 调用模块:' , siteKey)
280+ result = await executeAction (siteKey, actionData)
281+ } else if (apiUrl) {
282+ // 直接调用API
283+ console .log (' 直接调用API:' , apiUrl)
284+ const axios = (await import (' axios' )).default
285+ const response = await axios .post (apiUrl, actionData, {
286+ timeout: getActionTimeout (),
287+ headers: {
288+ ' Accept' : ' application/json' ,
289+ ' Content-Type' : ' application/json;charset=UTF-8' ,
290+ }
291+ })
292+ result = response .data
293+ }
294+
295+ console .log (' T4接口返回结果:' , result)
296+ return result
297+ }
298+
248299// 处理动作点击
249300const handleActionClick = async (action ) => {
250301 try {
@@ -262,12 +313,67 @@ const handleActionClick = async (action) => {
262313 // 尝试解析JSON字符串
263314 actionConfig = JSON .parse (action .action .replace (/ '/ g , ' "' ))
264315 } catch (parseError) {
265- // 如果不是JSON,则作为简单字符串处理
266- actionConfig = {
267- actionId: action .action ,
268- type: ' msgbox' ,
269- title: action .name || ' 未知动作' ,
270- msg: ` 执行动作: ${ action .action } `
316+ // 如果不是JSON,则调用T4接口获取动作配置
317+ console .log (' 纯字符串动作,调用T4接口:' , action .action )
318+
319+ try {
320+ const t4Result = await callT4Action (action .action , action .siteKey , action .siteApi , action .siteExt )
321+
322+ if (t4Result) {
323+ // 检查T4接口返回的结果
324+ if (typeof t4Result === ' string' ) {
325+ try {
326+ // 尝试解析T4返回的JSON字符串
327+ const parsedResult = JSON .parse (t4Result)
328+ // 如果解析结果包含action字段,则使用action字段作为动作配置
329+ let extractedAction = parsedResult .action || parsedResult
330+
331+ // 检查action字段是否也是JSON字符串,如果是则进行二次解析
332+ if (typeof extractedAction === ' string' ) {
333+ try {
334+ extractedAction = JSON .parse (extractedAction)
335+ } catch (secondParseError) {
336+ console .warn (' action字段不是有效的JSON字符串:' , extractedAction)
337+ }
338+ }
339+
340+ actionConfig = extractedAction
341+ } catch (jsonParseError) {
342+ // 如果T4返回的不是JSON,则显示为消息框
343+ actionConfig = {
344+ type: ' msgbox' ,
345+ title: action .name || ' 动作结果' ,
346+ msg: t4Result
347+ }
348+ }
349+ } else if (typeof t4Result === ' object' && t4Result !== null ) {
350+ // T4返回的是对象,检查是否包含action字段
351+ let extractedAction = t4Result .action || t4Result
352+
353+ // 检查action字段是否也是JSON字符串,如果是则进行二次解析
354+ if (typeof extractedAction === ' string' ) {
355+ try {
356+ extractedAction = JSON .parse (extractedAction)
357+ } catch (secondParseError) {
358+ console .warn (' action字段不是有效的JSON字符串:' , extractedAction)
359+ }
360+ }
361+
362+ actionConfig = extractedAction
363+ } else {
364+ throw new Error (' T4接口返回了无效的数据格式' )
365+ }
366+ } else {
367+ throw new Error (' T4接口调用失败或返回空结果' )
368+ }
369+ } catch (t4Error) {
370+ console .error (' T4接口调用失败:' , t4Error)
371+ // T4接口调用失败时,显示错误信息
372+ actionConfig = {
373+ type: ' msgbox' ,
374+ title: ' 动作执行失败' ,
375+ msg: ` 调用T4接口失败: ${ t4Error .message } `
376+ }
271377 }
272378 }
273379 } else if (typeof action .action === ' object' && action .action !== null ) {
0 commit comments