diff --git a/.vscode/settings.json b/.vscode/settings.json index 9ca4513e..24c19500 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -55,5 +55,8 @@ "rust-analyzer.linkedProjects": [ "apps/desktop/src-tauri/Cargo.toml", "packages/alignment-wasm/Cargo.toml" - ] + ], + "[rust]": { + "editor.defaultFormatter": "rust-lang.rust-analyzer" + } } diff --git a/apps/app/public/img/scrollTable.70b511f1.png b/apps/app/public/img/scrollTable.70b511f1.png index f179fc9f..4b28bd81 100644 Binary files a/apps/app/public/img/scrollTable.70b511f1.png and b/apps/app/public/img/scrollTable.70b511f1.png differ diff --git a/apps/app/src/api/aiModel.ts b/apps/app/src/api/aiModel.ts index 61b1813c..b4c4f3fc 100644 --- a/apps/app/src/api/aiModel.ts +++ b/apps/app/src/api/aiModel.ts @@ -1,8 +1,8 @@ import type { BaseEntity } from "@/model/BaseEntity"; import { serverRequest } from "@/utils/serverService"; -/** 3 个模型角色 */ -export type ModelRole = "reasoning" | "vision" | "embedding"; +/** 4 个模型角色 */ +export type ModelRole = "reasoning" | "vision" | "embedding" | "image"; export interface AiModelVo { role: ModelRole; diff --git a/apps/app/src/components/ScreenwrightThirdPartComponent/echartcommon/useEchartsCommon.ts b/apps/app/src/components/ScreenwrightThirdPartComponent/echartcommon/useEchartsCommon.ts index 3221c1fb..ff691d87 100644 --- a/apps/app/src/components/ScreenwrightThirdPartComponent/echartcommon/useEchartsCommon.ts +++ b/apps/app/src/components/ScreenwrightThirdPartComponent/echartcommon/useEchartsCommon.ts @@ -1,3 +1,4 @@ +import { cloneDeep } from "lodash-es"; import { shallowRef, watch } from "vue"; import { echartsCore as echarts } from "@screenwright/material/chart"; @@ -6,6 +7,41 @@ import { useBaseData } from "@/hooks/useBaseData"; import { getFunction } from "@/utils/utils"; import type { ComponentType } from "@/views/build/components/buildRender/type"; +/** echartcommon 组件既有的 {categories, series}[] 数据形状 */ +type CategorySeriesDataItem = { + categories: string[]; + series: { name: string; data: unknown[] }[]; +}; + +const isCategorySeriesShape = (data: unknown): data is CategorySeriesDataItem[] => + Array.isArray(data) && + data.length > 0 && + data.every((item) => item && typeof item === "object" && "categories" in item && "series" in item); + +/** + * 把 dataChart 转换为可作为 echarts dataset.source 使用的行记录表 + * - 已是扁平记录数组(非 {categories, series} 形状):直接原样使用 + * - {categories, series}[] 形状:取第一项,转换为按 category 行展开的表 + */ +const buildDatasetSource = (data: unknown): Record[] => { + if (!isCategorySeriesShape(data)) { + return Array.isArray(data) ? (data as Record[]) : []; + } + + const [first] = data; + + if (!first) { + return []; + } + + const { categories, series } = first; + + return categories.map((name, i) => ({ + name, + ...Object.fromEntries(series.map((s) => [s.name, s.data[i]])) + })); +}; + export const useEchartsCommon = (options: ComponentType) => { const { dataChart, option, styleSizeName } = useBaseData(options); const echartsOptions = shallowRef>({}); @@ -17,7 +53,37 @@ export const useEchartsCommon = (options: ComponentType) => { console.error(`[useEchartsCommon] echartFormatter 执行失败: ${message}`, error); }; - const getEchartsOptions = () => { + /** 新链路:存在 echartsOption 时,注入 dataset 并(可选)交给 echartFormatter 做二次处理 */ + const getEchartsOptionsFromEchartsOption = (echartsOption: Record) => { + try { + const nextOption = cloneDeep(echartsOption); + + nextOption.dataset = { source: buildDatasetSource(dataChart.value) }; + + const echartFormatter = getFunction(option.value.echartFormatter, false); + + if (typeof echartFormatter !== "function") { + echartsOptions.value = nextOption; + return echartsOptions.value; + } + + const formatted = echartFormatter(dataChart.value, nextOption); + + // 仅在返回有效配置时更新,避免把已有配置覆盖成异常值 + if (formatted && typeof formatted === "object") { + echartsOptions.value = formatted; + } + + return echartsOptions.value; + } catch (error) { + showFormatterError(error); + // 出错时保持旧配置,不影响后续逻辑 + return echartsOptions.value; + } + }; + + /** 旧链路:无 echartsOption 时,保持与迁移前完全一致的行为 */ + const getEchartsOptionsLegacy = () => { try { const echartFormatter = getFunction(option.value.echartFormatter, true); @@ -39,6 +105,16 @@ export const useEchartsCommon = (options: ComponentType) => { return echartsOptions.value; } }; + + const getEchartsOptions = () => { + const echartsOption = option.value.echartsOption as Record | undefined; + + if (echartsOption) { + return getEchartsOptionsFromEchartsOption(echartsOption); + } + + return getEchartsOptionsLegacy(); + }; watch( () => dataChart.value, (nv) => { diff --git a/apps/app/src/components/componentEntry/type.ts b/apps/app/src/components/componentEntry/type.ts index 90a1b75f..7d28984c 100644 --- a/apps/app/src/components/componentEntry/type.ts +++ b/apps/app/src/components/componentEntry/type.ts @@ -35,6 +35,7 @@ export const renderMediaComponentType: MediaEnum[] = [ MediaEnum.SwEmbedAudio, MediaEnum.SwIframe, MediaEnum.SwImg, + MediaEnum.SwBox, MediaEnum.SwOpenVideo, MediaEnum.SwImgBorder, MediaEnum.SwSwiper, diff --git a/apps/app/src/hooks/eventHandling/actionStrategies.ts b/apps/app/src/hooks/eventHandling/actionStrategies.ts index d2f02ee5..d6676666 100644 --- a/apps/app/src/hooks/eventHandling/actionStrategies.ts +++ b/apps/app/src/hooks/eventHandling/actionStrategies.ts @@ -1088,127 +1088,6 @@ export class SwitchVideoStrategy extends ActionStrategy { } } -export class sendUE4MessageStrategy extends ActionStrategy { - async execute({ - componentIds, - isConditionSatisfied, - globalComponentMap, - ue4Config, - info, - animation, - action, - eventList - }: ActionExecutionParams & { - info: Record | null; - }): Promise { - if (!isConditionSatisfied || action === undefined) { - return; - } - - const ue4Info = action === ActionTypeEnum.SendUe4Msg ? info : null; - - const targetComponentId = componentIds[0]; - - /** - * @description 获取组件类型 - * @returns "PixelStreaming" | "PeerStreaming" | "" | null - */ - const getComponentType = () => { - const targetComponent = globalComponentMap.get(String(targetComponentId)); - if (!targetComponent) { - return null; - } - - const propMap: Record = { - [extendsEnumType.UePixelStreaming]: "PixelStreaming", - [extendsEnumType.UePeerStreaming]: "PeerStreaming", - [extendsEnumType.UeVessel]: "ue-vessel", - [extendsEnumType.SwUnrealEngine]: "sw-unreal-engine" - }; - - if (!propMap[targetComponent.component.prop]) { - return ""; - } - - return propMap[targetComponent.component.prop]; - }; - - /** - * @description 处理消息数据 - */ - const processMessageData = (messageContent: any, messageType: string, info?: any) => { - if (info) { - return messageType === "string" ? JSON.stringify(info) : { ...info }; - } - - switch (messageType) { - case "string": - return messageContent; - case "json": - return typeof messageContent === "string" ? JSON.parse(messageContent) : { data: messageContent }; - default: - return messageContent; - } - }; - - /** - * @description 发送UE消息 - */ - const sendUEMessage = () => { - console.log("sendUEMessage", window, (window as any).pixelStreaming, window.ue4); - if (!window.ue4 || !ue4Config) { - return; - } - - const { messageName, messageContent, messageType } = ue4Config; - - if (!messageName) { - return; - } - - const componentType = getComponentType(); - console.log("sendUEMessage22", componentType); - if (!componentType) { - return; - } - - const data = processMessageData(messageContent, messageType, ue4Info); - - // 根据组件类型发送消息 - switch (componentType) { - case "PeerStreaming": - if (window.funPS) { - window.funPS.emitMessage({ name: messageName, data }); - } - return; - - case "PixelStreaming": - console.log("PixelStreaming", { name: messageName, data }, (window as any).pixelStreaming); - if (window.playerStream) { - (window as any).playerStream.emitUIInteraction({ name: messageName, data }); - } - return; - - case "ue-vessel": - console.log("window.ue4.v2", messageName, data); - window.ue4?.v2?.(messageName, data); - return; - case "sw-unreal-engine": - componentIds.forEach((componentId) => { - const event = eventList[`${extendsEnumType.SwUnrealEngine}-${componentId}`]; - event.sendMessageToUe(messageName, data); - }); - break; - default: - return; - } - }; - - await delay(animation?.delay || 0); - sendUEMessage(); - } -} - export class SwitchBlueprintTab extends ActionStrategy { execute({ componentIds, blueprintKey, eventList, info }: ActionExecutionParams): void { if (!blueprintKey) { @@ -1222,37 +1101,6 @@ export class SwitchBlueprintTab extends ActionStrategy { } } -export class sendAIManMsgStaticStrategy extends ActionStrategy { - async execute({ - componentIds, - isConditionSatisfied, - globalComponentMap, - eventList, - animation, - info - }: ActionExecutionParams & { - info: Record | null; - }): Promise { - console.log("receiveWSMessage 触发数字人方法", info, isConditionSatisfied); - if (!isConditionSatisfied) { - return; - } - await delay(animation?.delay || 0); - componentIds.forEach((id) => { - const component = globalComponentMap.get(`${id}`); - if (!component) { - return; - } - - const event = (eventList as Record)[`${component.component.prop}-${id}`]; - if (!event.sendMsgToHuman) { - return; - } - event.sendMsgToHuman(info); - }); - } -} - export class SetIndexStrategy extends ActionStrategy { async execute({ componentIds, @@ -1632,9 +1480,6 @@ export class ActionStrategyFactory { [ActionTypeEnum.VideoToFastin]: new VideoToFastinStrategy(), [ActionTypeEnum.VideoToRewind]: new VideoToRewindStrategy(), [ActionTypeEnum.SwitchVideoProgress]: new SwitchVideoStrategy(), - [ActionTypeEnum.SendUe4Msg]: new sendUE4MessageStrategy(), - [ActionTypeEnum.SendUe4MsgStatic]: new sendUE4MessageStrategy(), - [ActionTypeEnum.SendAIManMsgStatic]: new sendAIManMsgStaticStrategy(), [ActionTypeEnum.SwitchBlueprintTab]: new SwitchBlueprintTab(), [ActionTypeEnum.nextPage]: new nextPageStrategy(), [ActionTypeEnum.prevPage]: new prevPageStrategy(), diff --git a/apps/app/src/hooks/eventHandling/useActionMessage.ts b/apps/app/src/hooks/eventHandling/useActionMessage.ts deleted file mode 100644 index deec2a71..00000000 --- a/apps/app/src/hooks/eventHandling/useActionMessage.ts +++ /dev/null @@ -1,2 +0,0 @@ -// useActionMessage 已下沉到 @screenwright/composables,这里保留原路径作为转发壳,避免调用方大范围改 import。 -export * from "@screenwright/composables"; diff --git a/apps/app/src/hooks/eventHandling/useTcpUdpWebSocket.ts b/apps/app/src/hooks/eventHandling/useTcpUdpWebSocket.ts deleted file mode 100644 index 24217c7f..00000000 --- a/apps/app/src/hooks/eventHandling/useTcpUdpWebSocket.ts +++ /dev/null @@ -1,2 +0,0 @@ -// useTcpUdpWebSocket 已下沉到 @screenwright/composables,这里保留原路径作为转发壳,避免调用方大范围改 import。 -export * from "@screenwright/composables"; diff --git a/apps/app/src/hooks/useEditingComponents.ts b/apps/app/src/hooks/useEditingComponents.ts new file mode 100644 index 00000000..19159012 --- /dev/null +++ b/apps/app/src/hooks/useEditingComponents.ts @@ -0,0 +1,32 @@ +/** + * 追踪"正在被 agent 编辑"的组件 id 集合,供画布渲染层叠加扫光效果。 + * + * 模块级单例(不是 Pinia store):这类纯 UI 提示状态没有持久化/多处 action 的需求, + * 用一个模块作用域的 reactive 就够了,聊天面板(写入方)和画布(读取方)分处两棵组件树, + * import 同一个模块自然共享同一份状态,不需要为它专门开一个 store module。 + * + * 用引用计数而不是简单的 add/delete:同一个组件短时间内可能被多个工具调用同时命中 + * (比如一次批量 edit_files 里出现两次),后进的调用先结束不该把还在跑的那次的高亮撤掉。 + */ +import { reactive } from "vue"; + +const refCounts = new Map(); + +/** 当前正在编辑的组件 id(字符串形式,和画布渲染层 `component.id` 的比较口径一致)。 */ +export const editingComponentIds = reactive(new Set()); + +export const markComponentEditing = (id: string): void => { + const next = (refCounts.get(id) ?? 0) + 1; + refCounts.set(id, next); + editingComponentIds.add(id); +}; + +export const unmarkComponentEditing = (id: string): void => { + const next = (refCounts.get(id) ?? 0) - 1; + if (next <= 0) { + refCounts.delete(id); + editingComponentIds.delete(id); + } else { + refCounts.set(id, next); + } +}; diff --git a/apps/app/src/service-workers/minioCache/ForceCacheStrategy.ts b/apps/app/src/service-workers/minioCache/ForceCacheStrategy.ts index 3673f044..605a7605 100644 --- a/apps/app/src/service-workers/minioCache/ForceCacheStrategy.ts +++ b/apps/app/src/service-workers/minioCache/ForceCacheStrategy.ts @@ -76,7 +76,9 @@ async function cleanExpiredCache() { for (const request of requests) { const response = await cache.match(request); - if (!response) continue; + if (!response) { + continue; + } const dateHeader = response.headers.get("date"); if (dateHeader) { diff --git a/apps/app/src/service-workers/minioCache/minio-cache-online.ts b/apps/app/src/service-workers/minioCache/minio-cache-online.ts index 9465507c..a53c9c2f 100644 --- a/apps/app/src/service-workers/minioCache/minio-cache-online.ts +++ b/apps/app/src/service-workers/minioCache/minio-cache-online.ts @@ -9,10 +9,11 @@ import { ForceCacheStrategy } from "./ForceCacheStrategy"; self.__WB_DISABLE_DEV_LOGS = true; /** - * 匹配 MinIO 资源请求(仅图片、视频,不包含字体) + * 匹配对象存储资源请求(仅图片、视频,不包含字体) + * MinIO 形态:`/assets/...`;fs 存储形态:`/blobs/` */ registerRoute(({ url }) => { - const isMinioPath = url.pathname.includes("/version-test/") || url.pathname.includes("/assets/"); + const isMinioPath = ["/assets/", "/blobs/"].some((seg) => url.pathname.includes(seg)); const isMediaFile = /\.(png|jpg|jpeg|gif|mp4|webm)$/i.test(url.pathname); return isMinioPath && isMediaFile; }, new ForceCacheStrategy()); @@ -26,5 +27,5 @@ registerRoute(({ url }) => { return isFontPath && isFontFile; }, new ForceCacheStrategy()); -console.log("[SW] MinIO 媒体资源缓存策略已激活(仅图片和视频)"); +console.log("[SW] 对象存储媒体资源缓存策略已激活(仅图片和视频)"); console.log("[SW] 本地字体文件缓存策略已激活(/lib/fonts/)"); diff --git a/apps/app/src/service-workers/minioCache/useMinioPreload.ts b/apps/app/src/service-workers/minioCache/useMinioPreload.ts index 28f3d5ee..15e106a0 100644 --- a/apps/app/src/service-workers/minioCache/useMinioPreload.ts +++ b/apps/app/src/service-workers/minioCache/useMinioPreload.ts @@ -3,15 +3,27 @@ import { setMinioUrl } from "@/utils/config"; import type { SystemComponentProps } from "../../views/build/components/buildRender/core/SystemComponent/type"; /** - * 提取面板数据中的所有 Minio 资源 URL + * 对象存储资源 URL 形态:`http://host/blobs/`(fs 存储绝对地址,原样使用) + * 键名可含中文/空格,故不用 `\S`,只以引号截断。 + */ +const IMAGE_EXT = "png|jpg|jpeg"; +const VIDEO_EXT = "mp4|webm"; +const buildAssetPattern = (ext: string, flags: string) => + new RegExp(String.raw`https?://[^"'\s]{1,120}/blobs/[^"']{1,80}\.(?:${ext})`, flags); + +/** + * 提取面板数据中的所有对象存储资源 URL */ function getMinioList(panelDataStr: string): string[] { - if (!panelDataStr) return []; + if (!panelDataStr) { + return []; + } try { - // 匹配 version-test/ 开头的图片和视频 URL - const matches = panelDataStr.match(/version-test\/.{1,80}\.(png|jpg|jpeg|mp4|webm)/gi); - if (!matches) return []; + const matches = panelDataStr.match(buildAssetPattern(`${IMAGE_EXT}|${VIDEO_EXT}`, "gi")); + if (!matches) { + return []; + } return [...new Set(matches)]; } catch (error) { console.error("解析面板数据失败:", error); @@ -129,14 +141,14 @@ function preloadResources(urls: string[]): Promise<{ images: HTMLImageElement[]; * 判断是否是图片 URL */ function isImageUrl(url: string): boolean { - return /version-test\/.{1,80}\.(png|jpg|jpeg)/i.test(url); + return buildAssetPattern(IMAGE_EXT, "i").test(url); } /** * 判断是否是视频 URL */ function isVideoUrl(url: string): boolean { - return /version-test\/.{1,80}\.(mp4|webm)/i.test(url); + return buildAssetPattern(VIDEO_EXT, "i").test(url); } /** @@ -147,7 +159,9 @@ export function useMinioPreload() { const videoRefs: HTMLVideoElement[] = []; const startPreload = async (component: SystemComponentProps) => { - if (!component) return { images: [] as HTMLImageElement[], videos: [] as HTMLVideoElement[] }; + if (!component) { + return { images: [] as HTMLImageElement[], videos: [] as HTMLVideoElement[] }; + } try { // 提取所有 Minio URL diff --git a/apps/app/src/tests/atomicComponents/useEchartsCommon.test.ts b/apps/app/src/tests/atomicComponents/useEchartsCommon.test.ts new file mode 100644 index 00000000..a5004aa2 --- /dev/null +++ b/apps/app/src/tests/atomicComponents/useEchartsCommon.test.ts @@ -0,0 +1,143 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; + +import { ref } from "vue"; + +// 不挂载组件,直接调用 hook;仅拦截 vue 生命周期,computed/ref/watch 保留真实行为 +vi.mock("vue", async () => ({ + ...((await vi.importActual("vue")) as any), + onMounted: vi.fn(), + onBeforeUnmount: vi.fn() +})); + +// useEchartsCommon 把取数/option 读取委托给 useBaseData,这里 mock 掉, +// 直接控制 dataChart / option,聚焦验证 useEchartsCommon 如何把数据转换为最终 echarts option。 +const mockOption = ref>({}); +const mockDataChart = ref([]); + +vi.mock("@/hooks/useBaseData", () => ({ + useBaseData: vi.fn(() => ({ + dataChart: mockDataChart, + option: mockOption, + styleSizeName: ref({}) + })) +})); + +// @screenwright/material/chart 是包含图表编辑器 UI 的重量级 barrel,useEchartsCommon 仅用到 +// echartsCore(挂到 window.echarts,与本文件断言逻辑无关),mock 掉避免加载整个图表编辑器依赖树。 +vi.mock("@screenwright/material/chart", () => ({ + echartsCore: {} +})); + +import { useEchartsCommon } from "@/components/ScreenwrightThirdPartComponent/echartcommon/useEchartsCommon"; + +describe("useEchartsCommon", () => { + beforeEach(() => { + mockOption.value = {}; + mockDataChart.value = []; + vi.spyOn(console, "error").mockImplementation(() => {}); + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); + + it("getEchartsOptions,仅有 echartFormatter 无 echartsOption,单参数调用且返回值即最终 option", () => { + mockDataChart.value = [{ name: "a", value: 1 }]; + mockOption.value = { + echartFormatter: "(dataChart) => ({ series: [{ data: dataChart }] })" + }; + + const { getEchartsOptions } = useEchartsCommon({} as any); + const result = getEchartsOptions(); + + expect(result).toEqual({ series: [{ data: [{ name: "a", value: 1 }] }] }); + expect(result.dataset, "旧链路不应注入 dataset").toBeUndefined(); + }); + + it("getEchartsOptions,仅有 echartsOption 且 dataChart 为扁平记录数组,dataset.source 等于原数组", () => { + mockDataChart.value = [ + { name: "Mon", value: 10 }, + { name: "Tue", value: 20 } + ]; + mockOption.value = { + echartsOption: { series: [{ type: "bar", encode: { x: "name", y: "value" } }] } + }; + + const { getEchartsOptions } = useEchartsCommon({} as any); + const result = getEchartsOptions(); + + expect(result.dataset).toEqual({ + source: [ + { name: "Mon", value: 10 }, + { name: "Tue", value: 20 } + ] + }); + expect(result.series, "原 echartsOption 字段应保留").toEqual([ + { type: "bar", encode: { x: "name", y: "value" } } + ]); + }); + + it("getEchartsOptions,仅有 echartsOption 且 dataChart 为 {categories, series}[] 形状,dataset.source 转换为按类目展开的行表", () => { + mockDataChart.value = [ + { + categories: ["Mon", "Tue"], + series: [ + { name: "系列一", data: [10, 20] }, + { name: "系列二", data: [30, 40] } + ] + } + ]; + mockOption.value = { + echartsOption: { series: [{ type: "line" }] } + }; + + const { getEchartsOptions } = useEchartsCommon({} as any); + const result = getEchartsOptions(); + + expect(result.dataset).toEqual({ + source: [ + { name: "Mon", 系列一: 10, 系列二: 30 }, + { name: "Tue", 系列一: 20, 系列二: 40 } + ] + }); + }); + + it("getEchartsOptions,echartsOption 与 echartFormatter 同时存在,formatter 以 (dataChart, 注入dataset后的option) 两参数被调用且返回值即最终 option", () => { + mockDataChart.value = [{ name: "a", value: 1 }]; + mockOption.value = { + echartsOption: { title: { text: "base" } }, + echartFormatter: + "(dataChart, option) => ({ title: option.title, dataset: option.dataset, extra: dataChart.length })" + }; + + const { getEchartsOptions } = useEchartsCommon({} as any); + const result = getEchartsOptions(); + + expect(result).toEqual({ + title: { text: "base" }, + dataset: { source: [{ name: "a", value: 1 }] }, + extra: 1 + }); + }); + + it("getEchartsOptions,新链路 echartFormatter 执行抛出异常,不崩溃且保留调用前的 option", () => { + mockDataChart.value = [{ name: "a", value: 1 }]; + mockOption.value = { + echartsOption: { title: { text: "base" } } + }; + + const { getEchartsOptions } = useEchartsCommon({} as any); + const firstResult = getEchartsOptions(); + + mockOption.value = { + echartsOption: { title: { text: "base" } }, + echartFormatter: "(dataChart, option) => { throw new Error('boom') }" + }; + const secondResult = getEchartsOptions(); + + // 注:本仓库当前 vitest(0.32) + jsdom 环境下 vi.spyOn(console, "error") 的调用计数不可靠 + // (直接调用 console.error 后 spy.mock.calls 仍为空,已排查确认非本文件代码问题), + // 因此这里以“保留调用前的 option 引用”作为出错未崩溃、且未被异常值覆盖的可验证信号。 + expect(secondResult, "抛出异常后应保留上一次的 option 引用").toBe(firstResult); + }); +}); diff --git a/apps/app/src/tests/atomicComponents/useSwBox.test.ts b/apps/app/src/tests/atomicComponents/useSwBox.test.ts new file mode 100644 index 00000000..a4e97147 --- /dev/null +++ b/apps/app/src/tests/atomicComponents/useSwBox.test.ts @@ -0,0 +1,103 @@ +import { describe, expect, it } from "vitest"; + +import { buildSwBoxStyle } from "@material/components/ScreenwrightMedia/components/swBox/useSwBox"; + +// ============================================================ +// buildSwBoxStyle:纯函数,空 option 得到透明盒子默认样式, +// 各字段单独设置时正确进入 style 对象(方案文档 §4.3)。 +// ============================================================ + +describe("buildSwBoxStyle", () => { + it("空 option 时返回透明盒子的默认样式(pointerEvents 默认 none,不含其他字段)", () => { + const style = buildSwBoxStyle(undefined); + expect(style).toEqual({ pointerEvents: "none" }); + }); + + it("null option 同样得到默认样式", () => { + const style = buildSwBoxStyle(null); + expect(style).toEqual({ pointerEvents: "none" }); + }); + + it("pointerEvents=true 时映射为 auto", () => { + const style = buildSwBoxStyle({ pointerEvents: true }); + expect(style.pointerEvents).toBe("auto"); + }); + + it("background 透传(支持渐变字符串)", () => { + const style = buildSwBoxStyle({ background: "linear-gradient(90deg, #000, #fff)" }); + expect(style.background).toBe("linear-gradient(90deg, #000, #fff)"); + }); + + it("border 透传", () => { + const style = buildSwBoxStyle({ border: "1px solid rgba(69,131,255,.4)" }); + expect(style.border).toBe("1px solid rgba(69,131,255,.4)"); + }); + + it("borderRadius 为数字时补 px 单位", () => { + const style = buildSwBoxStyle({ borderRadius: 8 }); + expect(style.borderRadius).toBe("8px"); + }); + + it("borderRadius 为字符串时按 CSS 原样透传", () => { + const style = buildSwBoxStyle({ borderRadius: "8px 8px 0 0" }); + expect(style.borderRadius).toBe("8px 8px 0 0"); + }); + + it("boxShadow 透传", () => { + const style = buildSwBoxStyle({ boxShadow: "inset 0 0 20px rgba(69,131,255,.5)" }); + expect(style.boxShadow).toBe("inset 0 0 20px rgba(69,131,255,.5)"); + }); + + it("backdropFilter 透传", () => { + const style = buildSwBoxStyle({ backdropFilter: "blur(8px)" }); + expect(style.backdropFilter).toBe("blur(8px)"); + }); + + it("opacity 透传", () => { + const style = buildSwBoxStyle({ opacity: 0.5 }); + expect(style.opacity).toBe(0.5); + }); + + it("clipPath 透传", () => { + const style = buildSwBoxStyle({ clipPath: "polygon(12px 0,100% 0,100% 100%,0 100%,0 12px)" }); + expect(style.clipPath).toBe("polygon(12px 0,100% 0,100% 100%,0 100%,0 12px)"); + }); + + it("transform 透传", () => { + const style = buildSwBoxStyle({ transform: "rotate(3deg)" }); + expect(style.transform).toBe("rotate(3deg)"); + }); + + it("animation 透传(内置预设关键帧名)", () => { + const style = buildSwBoxStyle({ animation: "sw-breath 3s infinite" }); + expect(style.animation).toBe("sw-breath 3s infinite"); + }); + + it("所有字段同时设置时全部正确进入 style 对象", () => { + const option = { + background: "#123456", + border: "1px solid #fff", + borderRadius: 4, + boxShadow: "0 0 4px #000", + backdropFilter: "blur(4px)", + opacity: 0.8, + clipPath: "circle(50%)", + transform: "scale(1.1)", + animation: "sw-zoom 2s infinite", + pointerEvents: true + }; + const style = buildSwBoxStyle(option); + expect(style).toEqual({ + pointerEvents: "auto", + background: "#123456", + border: "1px solid #fff", + borderRadius: "4px", + boxShadow: "0 0 4px #000", + backdropFilter: "blur(4px)", + opacity: 0.8, + clipPath: "circle(50%)", + transform: "scale(1.1)", + animation: "sw-zoom 2s infinite" + }); + }); +}); diff --git a/apps/app/src/tests/atomicComponents/useSwImg.test.ts b/apps/app/src/tests/atomicComponents/useSwImg.test.ts new file mode 100644 index 00000000..8869dfd8 --- /dev/null +++ b/apps/app/src/tests/atomicComponents/useSwImg.test.ts @@ -0,0 +1,134 @@ +import { describe, expect, it, vi } from "vitest"; + +import { ref } from "vue"; + +// 不挂载组件,直接调用 hook;仅拦截 vue 生命周期,computed/ref/watch 保留真实行为 +vi.mock("vue", async (importOriginal) => ({ + ...(await importOriginal()), + onMounted: vi.fn(), + onBeforeUnmount: vi.fn() +})); + +// useSwImg 把取数/option 读取委托给 useBaseData,毛玻璃样式委托给 useFrostedStyle, +// 这里 mock 掉两者,直接控制 option/dataChart,聚焦验证 useSwImg 自身的样式派生逻辑。 +const mockOption = ref>({}); +const mockDataChart = ref({}); + +vi.mock("@screenwright/composables", async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + useBaseData: vi.fn(() => ({ + dataChart: mockDataChart, + option: mockOption, + isBuild: { value: false }, + clickFormatter: undefined + })), + useFrostedStyle: vi.fn(() => ({ + getFrostedStyle: ref({}) + })) + }; +}); + +import { + buildAnimationStyle, + buildFilterStyle, + buildTransformStyle, + useSwImg +} from "@material/components/ScreenwrightMedia/components/swImg/useSwImg"; + +// ============================================================ +// 纯函数:option.filter / option.transform 在新 schema 里已是完整 CSS 字符串,直接透传 +// ============================================================ + +describe("buildFilterStyle", () => { + it("option.filter 已是完整 CSS filter 字符串,原样透传", () => { + expect(buildFilterStyle({ filter: "blur(4px) brightness(1.2) grayscale(1)" })).toEqual({ + filter: "blur(4px) brightness(1.2) grayscale(1)" + }); + }); + + it("option.filter 未设置时透传 undefined", () => { + expect(buildFilterStyle({})).toEqual({ filter: undefined }); + }); +}); + +describe("buildTransformStyle", () => { + it("option.transform 已是完整 CSS transform 字符串,原样透传", () => { + expect(buildTransformStyle({ transform: "scaleX(-1)" })).toEqual({ transform: "scaleX(-1)" }); + }); + + it("option.transform 未设置时透传 undefined", () => { + expect(buildTransformStyle({})).toEqual({ transform: undefined }); + }); +}); + +describe("buildAnimationStyle", () => { + it("option.animation 存在时映射为 animation + WebkitAnimation", () => { + expect(buildAnimationStyle({ animation: "sw-rotate 8s linear infinite" })).toEqual({ + animation: "sw-rotate 8s linear infinite", + WebkitAnimation: "sw-rotate 8s linear infinite" + }); + }); + + it("option.animation 未设置时返回空对象(不覆盖 keyframes 驱动的动画)", () => { + expect(buildAnimationStyle({})).toEqual({}); + }); +}); + +// ============================================================ +// useSwImg:legacy 格式 option 经 upgradeSwimgOption 自动升级后, +// 驱动出正确的当前 schema 样式(旋转 -> transform) +// ============================================================ + +describe("useSwImg", () => { + it("legacy 格式 option(rotateShow/rotateX/Y/Z)自动升级为 transform,并进入 img 样式", () => { + mockOption.value = { + rotateShow: true, + rotateX: 10, + rotateY: 20, + rotateZ: 30 + }; + mockDataChart.value = { value: "a.png" }; + + const { option, styleImgBoxName } = useSwImg({} as any); + + expect(option.value.transform, "legacy 旋转字段应升级为 CSS transform 字符串").toBe( + "rotateX(10deg) rotateY(20deg) rotateZ(30deg)" + ); + expect(styleImgBoxName.value.transform, "样式对象应携带升级后的 transform").toBe( + "rotateX(10deg) rotateY(20deg) rotateZ(30deg)" + ); + }); + + it("legacy 格式 option(滤镜开关)自动升级为 filter 字符串,并进入 img 样式", () => { + mockOption.value = { + contrastShow: true, + contrast: 120, + gaussianBlurShow: true, + gaussianBlur: 4 + }; + mockDataChart.value = { value: "a.png" }; + + const { option, styleImgBoxName } = useSwImg({} as any); + + expect(option.value.filter).toBe("contrast(120%) blur(4px)"); + expect(styleImgBoxName.value.filter).toBe("contrast(120%) blur(4px)"); + }); + + it("当前格式 option(无 legacy 字段)经 upgradeSwimgOption 保持恒等", () => { + mockOption.value = { + objectFit: "cover", + opacity: 0.5, + pointerEvents: true + }; + mockDataChart.value = { value: "a.png" }; + + const { option, styleImgBoxName } = useSwImg({} as any); + + expect(option.value).toEqual(mockOption.value); + expect(styleImgBoxName.value.objectFit).toBe("cover"); + expect(styleImgBoxName.value.opacity).toBe(0.5); + expect(styleImgBoxName.value.pointerEvents).toBe("auto"); + }); +}); diff --git a/apps/app/src/tests/atomicComponents/useText.test.ts b/apps/app/src/tests/atomicComponents/useText.test.ts new file mode 100644 index 00000000..de50de56 --- /dev/null +++ b/apps/app/src/tests/atomicComponents/useText.test.ts @@ -0,0 +1,234 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; + +import { ref } from "vue"; + +import type { ComponentType } from "@screenwright/types"; + +// 不挂载组件,直接调用 hook;仅拦截 vue 生命周期,computed/ref/watch 保留真实行为 +vi.mock("vue", async (importOriginal) => ({ + ...(await importOriginal()), + onMounted: vi.fn(), + onBeforeUnmount: vi.fn() +})); + +// useText 把取数/option 读取委托给 useBaseData,这里 mock 掉, +// 直接控制 dataChart / option / clickFormatter,聚焦验证 useText 如何把 option 转换成渲染样式。 +vi.mock("@screenwright/composables", async (importOriginal) => { + const actual = await importOriginal(); + return { + ...(actual as any), + useBaseData: vi.fn() + }; +}); + +import { useBaseData } from "@screenwright/composables"; + +import { + DEFAULTS, + formatTextValue, + isGradientColor, + textShadowToDropShadow, + useText +} from "@material/components/ScreenwrightText/components/swText/useText"; + +// ============================================================ +// 辅助 +// ============================================================ + +/** 构造 useBaseData 的返回值,option/dataChart 是测试中可修改的 ref */ +const setupUseBaseData = (option: Record, dataValue: unknown = { value: "" }) => { + const optionRef = ref>(option); + const dataChartRef = ref(dataValue); + vi.mocked(useBaseData).mockReturnValue({ + isBuild: { value: false }, + dataChart: dataChartRef, + option: optionRef, + width: ref(200), + clickFormatter: vi.fn() + } as any); + return { optionRef, dataChartRef }; +}; + +const mockElement = {} as ComponentType; + +// ============================================================ +// 测试套件 +// ============================================================ + +describe("useText", () => { + beforeEach(() => { + vi.mocked(useBaseData).mockReset(); + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + + it("useText,旧格式 option(selectedTextType/iswrap/shadowShow/textAlignVertical/scroll)自动升级并渲染", () => { + setupUseBaseData({ + selectedTextType: "normal", + color: "#112233", + iswrap: true, + textAlignVertical: "top", + shadowShow: true, + shadowColor: "rgba(0,0,0,1)", + shadowX: 1, + shadowY: 2, + shadowFuzzy: 3, + scroll: true, + step: 5, + speed: 100 + }); + + const { option, getTextStyle, styleBox, isMarquee } = useText(mockElement); + + expect(option.value.color, "旧 color 字段应原样搬运").toBe("#112233"); + expect(getTextStyle.value.whiteSpace, "iswrap=true 应转成 pre-line").toBe("pre-line"); + expect(styleBox.value.alignItems, "textAlignVertical=top 应映射为 flex-start").toBe("flex-start"); + expect(getTextStyle.value.textShadow, "非渐变文字下阴影走 text-shadow").toBe("1px 2px 3px rgba(0,0,0,1)"); + expect(isMarquee.value, "旧 scroll=true 应升级为 marquee 存在").toBe(true); + }); + + it("useText,当前格式 option 直接使用,不做二次转换", () => { + setupUseBaseData({ color: "#abcdef", fontSize: 20 }); + + const { option, getTextStyle } = useText(mockElement); + + expect(option.value.color).toBe("#abcdef"); + expect(getTextStyle.value.fontSize, "当前格式字段应直接透传").toBe("20px"); + expect(getTextStyle.value.color).toBe("#abcdef"); + }); + + it("useText,color 为 linear-gradient 时,getTextStyle 生成 background-clip 渐变文字样式", () => { + setupUseBaseData({ color: "linear-gradient(90deg, #fff, #000)" }); + + const { getTextStyle } = useText(mockElement); + + expect(getTextStyle.value.backgroundImage).toBe("linear-gradient(90deg, #fff, #000)"); + expect(getTextStyle.value.backgroundClip).toBe("text"); + expect(getTextStyle.value.WebkitBackgroundClip).toBe("text"); + expect(getTextStyle.value.WebkitTextFillColor).toBe("transparent"); + expect(getTextStyle.value.color).toBe("transparent"); + }); + + it("useText,渐变文字同时设置 textShadow 时,转成 filter: drop-shadow(...) 而非 text-shadow", () => { + setupUseBaseData({ + color: "linear-gradient(90deg, #fff, #000)", + textShadow: "1px 2px 3px #000" + }); + + const { getTextStyle } = useText(mockElement); + + expect(getTextStyle.value.filter).toBe("drop-shadow(1px 2px 3px #000)"); + expect(getTextStyle.value.textShadow, "渐变文字下不应再输出 text-shadow").toBeUndefined(); + }); + + it("useText,option.marquee 存在即视为跑马灯,宽度变为 fit-content", () => { + setupUseBaseData({ marquee: { speed: 50 } }); + + const { isMarquee, getTextStyle } = useText(mockElement); + + expect(isMarquee.value).toBe(true); + expect(getTextStyle.value.width).toBe("fit-content"); + }); + + it("useText,仅有旧字段 type='scroll' 但无 scroll 布尔值时,不应触发跑马灯(已修复的死代码路径)", () => { + setupUseBaseData({ type: "scroll" }); + + const { isMarquee } = useText(mockElement); + + expect(isMarquee.value, "type='scroll' 不再是判定依据").toBe(false); + }); + + it("useText,option.href 存在即视为超链接,linkHref/linkTarget 读取自 option", () => { + setupUseBaseData({ href: "https://example.com", target: "_blank" }); + + const { isLink, linkHref, linkTarget } = useText(mockElement); + + expect(isLink.value).toBe(true); + expect(linkHref.value).toBe("https://example.com"); + expect(linkTarget.value).toBe("_blank"); + }); + + it("useText,空 option 时 isLink 为 false", () => { + setupUseBaseData({}); + + const { isLink } = useText(mockElement); + + expect(isLink.value).toBe(false); + }); + + it("useText,空 option 时使用 DEFAULTS 兜底,getTextStyle 无 NaN/undefined 字符串泄漏", () => { + setupUseBaseData({}); + + const { getTextStyle } = useText(mockElement); + + expect(getTextStyle.value.fontFamily).toBe(DEFAULTS.fontFamily); + expect(getTextStyle.value.fontSize).toBe(`${DEFAULTS.fontSize}px`); + expect(getTextStyle.value.color).toBe(DEFAULTS.color); + expect(getTextStyle.value.lineHeight).toBe(DEFAULTS.lineHeight); + expect(getTextStyle.value.whiteSpace).toBe(DEFAULTS.whiteSpace); + expect(getTextStyle.value.textOverflow).toBe(DEFAULTS.textOverflow); + expect(JSON.stringify(getTextStyle.value)).not.toMatch(/NaN|undefined/); + }); +}); + +// ============================================================ +// 纯函数单测:颜色/阴影/数值格式化 +// ============================================================ + +describe("isGradientColor", () => { + it("isGradientColor,linear-gradient 前缀,返回 true", () => { + expect(isGradientColor("linear-gradient(90deg, #fff, #000)")).toBe(true); + }); + + it("isGradientColor,radial-gradient 前缀,返回 true", () => { + expect(isGradientColor("radial-gradient(circle, #fff, #000)")).toBe(true); + }); + + it("isGradientColor,纯色字符串,返回 false", () => { + expect(isGradientColor("#ffffff")).toBe(false); + }); + + it("isGradientColor,undefined,返回 false", () => { + expect(isGradientColor(undefined)).toBe(false); + }); +}); + +describe("textShadowToDropShadow", () => { + it("textShadowToDropShadow,单层阴影,转成单个 drop-shadow 函数", () => { + expect(textShadowToDropShadow("1px 2px 3px #000")).toBe("drop-shadow(1px 2px 3px #000)"); + }); + + it("textShadowToDropShadow,多层阴影(逗号分隔),转成多个 drop-shadow 函数并用空格拼接", () => { + expect(textShadowToDropShadow("1px 1px 0 #fff, 2px 2px 4px #000")).toBe( + "drop-shadow(1px 1px 0 #fff) drop-shadow(2px 2px 4px #000)" + ); + }); +}); + +describe("formatTextValue", () => { + it("formatTextValue,decimals=2,数字保留两位小数", () => { + expect(formatTextValue(1234.5678, { decimals: 2 })).toBe("1234.57"); + }); + + it("formatTextValue,thousands=true,千分位分隔", () => { + expect(formatTextValue(1234567, { thousands: true })).toBe("1,234,567"); + }); + + it("formatTextValue,decimals+thousands+template 组合,得到完整格式化文本", () => { + expect(formatTextValue(1234.5678, { decimals: 2, thousands: true, template: "{value} kWh" })).toBe( + "1,234.57 kWh" + ); + }); + + it("formatTextValue,非数字内容,decimals/thousands 不生效但 template 仍替换", () => { + expect(formatTextValue("大屏标题", { decimals: 2, thousands: true, template: "标题:{value}" })).toBe( + "标题:大屏标题" + ); + }); + + it("formatTextValue,undefined 内容,返回空字符串", () => { + expect(formatTextValue(undefined, {})).toBe(""); + }); +}); diff --git a/apps/app/src/views/build/components/agentBI/components/ToolCallPart.vue b/apps/app/src/views/build/components/agentBI/components/ToolCallPart.vue index dc4f48ee..3e9e0ed7 100644 --- a/apps/app/src/views/build/components/agentBI/components/ToolCallPart.vue +++ b/apps/app/src/views/build/components/agentBI/components/ToolCallPart.vue @@ -9,13 +9,26 @@
{{ errorMessage }}
+ + +
+ +
- - diff --git a/apps/app/src/views/build/components/buildConfig/attrsRender/components/controlEncodes/useControlEncodes.ts b/apps/app/src/views/build/components/buildConfig/attrsRender/components/controlEncodes/useControlEncodes.ts deleted file mode 100644 index 236a53c0..00000000 --- a/apps/app/src/views/build/components/buildConfig/attrsRender/components/controlEncodes/useControlEncodes.ts +++ /dev/null @@ -1,148 +0,0 @@ -import { computed, ref } from "vue"; - -import { ElMessage } from "element-plus"; - -import { updateLargeScreen } from "@/api/library"; -import { useEditStore } from "@/views/build/components/buildRender/hooks/useEditStore"; -import { useLargeScreenInfo } from "@/views/build/useLargeScreenInfo"; -import { useEncodeCommunication } from "@/views/view/useEncodeCommunication"; - -/** - * 控制编码组件业务逻辑 - */ -export const useControlEncodes = () => { - const { encodedControlValues } = useEncodeCommunication(); - const { selectTargetData } = useEditStore(); - const { navInfo } = useLargeScreenInfo(); - /** - * 当前组件的控制编码值 - * 从 encodedControlValues 中读取当前选中组件的编码,支持双向绑定 - */ - const codeValue = computed({ - get: () => { - if (!selectTargetData.value?.length) return ""; - - const currentComponentId = `${selectTargetData.value[0].id}`; - const targetEncode = encodedControlValues.value.find((item) => item.id === currentComponentId); - return targetEncode?.code || ""; - }, - set: (value: string) => { - if (!selectTargetData.value?.length) return; - - const currentComponentId = `${selectTargetData.value[0].id}`; - - /** - * id-code-value - */ - - const targetEncodeIndex = encodedControlValues.value.findIndex((item) => item.id === currentComponentId); - - if (targetEncodeIndex !== -1) { - // 更新existing编码 - 使用浅拷贝 - const newEncodedValues = [...encodedControlValues.value]; - newEncodedValues[targetEncodeIndex] = { - id: currentComponentId, - code: value, - value: selectTargetData.value[0]?.data?.[0]?.value ?? "" - }; - encodedControlValues.value = newEncodedValues; - } else { - // 添加新编码 - 先删除原有相同id的数据,再添加新数据 - const filteredValues = encodedControlValues.value.filter((item) => item.id !== currentComponentId); - encodedControlValues.value = [ - ...filteredValues, - { - id: currentComponentId, - code: value, - value: selectTargetData.value[0]?.data?.[0]?.value ?? "" - } - ]; - } - } - }); - - /** - * 处理编码变更 - * @param value 新的编码值 - */ - const handleCodeChange = () => { - const update = () => { - const updateParams = { - encodedControl: JSON.stringify(navInfo.value.encodedControl), - id: Number(navInfo.value.id) - }; - updateLargeScreen(updateParams); - }; - update(); - }; - - // 内部状态 - const isFocused = ref(false); - - /** - * 验证控制编码格式 - * @param code 编码字符串 - */ - const validateControlCode = (code: string): boolean => { - if (!code.trim()) return true; // 允许为空 - - // 验证规则:只允许字母、数字、下划线、中划线 - const regex = /^[a-zA-Z0-9_-]+$/; - if (!regex.test(code)) { - ElMessage.warning("控制编码只能包含字母、数字、下划线和中划线"); - return false; - } - - // 长度验证 - if (code.length > 50) { - ElMessage.warning("控制编码长度不能超过50个字符"); - return false; - } - - return true; - }; - - /** - * 格式化控制编码 - * @param code 原始编码 - */ - const formatControlCode = (code: string): string => { - // 去除首尾空格,转换为小写 - return code.trim().toLowerCase(); - }; - - /** - * 处理输入框失焦 - */ - const handleBlur = () => { - isFocused.value = false; - - // 失焦时进行最终验证和格式化 - if (codeValue.value) { - const formattedValue = formatControlCode(codeValue.value); - if (validateControlCode(formattedValue)) { - codeValue.value = formattedValue; - } - } - }; - - /** - * 处理输入框聚焦 - */ - const handleFocus = () => { - isFocused.value = true; - }; - - return { - // 状态 - codeValue, - isFocused, - - // 方法 - handleCodeChange, - handleBlur, - handleFocus, - validateControlCode, - formatControlCode - }; -}; diff --git a/apps/app/src/views/build/components/buildConfig/attrsRender/components/interactiveConfig/componentActionConfigs/ActionComponentMapping.ts b/apps/app/src/views/build/components/buildConfig/attrsRender/components/interactiveConfig/componentActionConfigs/ActionComponentMapping.ts index 46f8a476..f1973da9 100644 --- a/apps/app/src/views/build/components/buildConfig/attrsRender/components/interactiveConfig/componentActionConfigs/ActionComponentMapping.ts +++ b/apps/app/src/views/build/components/buildConfig/attrsRender/components/interactiveConfig/componentActionConfigs/ActionComponentMapping.ts @@ -14,8 +14,6 @@ import GlMapRegionLift from "./actions/GlMapRegionLift.vue"; import GlMapSceneRoam from "./actions/GlMapSceneRoam.vue"; import HandleSceneObjExplosion from "./actions/HandleSceneObjExplosion.vue"; import ProjectFunction from "./actions/ProjectFunction.vue"; -import SendAIManMsg from "./actions/SendAIManMsg.vue"; -import SendUE4Msg from "./actions/SendUE4Msg.vue"; import SetDelay from "./actions/SetDelay.vue"; import SetIndex from "./actions/SetIndex.vue"; import SetStateAnimation from "./actions/SetStateAnimation.vue"; @@ -40,9 +38,6 @@ export const actionComponentMap: Record = { [ActionTypeEnum.Show]: ShowHide, [ActionTypeEnum.Hide]: ShowHide, [ActionTypeEnum.ShowHide]: ShowHide, - [ActionTypeEnum.SendUe4Msg]: SendUE4Msg, - [ActionTypeEnum.SendUe4MsgStatic]: SendUE4Msg, - [ActionTypeEnum.SendAIManMsgStatic]: SendAIManMsg, [ActionTypeEnum.SwitchSceneStatus]: SwitchSceneStatus, [ActionTypeEnum.SwitchSceneRoam]: SwitchSceneRoam, [ActionTypeEnum.SwitchSceneLevel]: SwitchSceneLevel, diff --git a/apps/app/src/views/build/components/buildConfig/attrsRender/components/interactiveConfig/componentActionConfigs/actions/SendAIManMsg.vue b/apps/app/src/views/build/components/buildConfig/attrsRender/components/interactiveConfig/componentActionConfigs/actions/SendAIManMsg.vue deleted file mode 100644 index 3940b5ac..00000000 --- a/apps/app/src/views/build/components/buildConfig/attrsRender/components/interactiveConfig/componentActionConfigs/actions/SendAIManMsg.vue +++ /dev/null @@ -1,32 +0,0 @@ - - - diff --git a/apps/app/src/views/build/components/buildConfig/attrsRender/components/interactiveConfig/componentActionConfigs/actions/SendUE4Msg.vue b/apps/app/src/views/build/components/buildConfig/attrsRender/components/interactiveConfig/componentActionConfigs/actions/SendUE4Msg.vue deleted file mode 100644 index 2f85ed0b..00000000 --- a/apps/app/src/views/build/components/buildConfig/attrsRender/components/interactiveConfig/componentActionConfigs/actions/SendUE4Msg.vue +++ /dev/null @@ -1,39 +0,0 @@ - - - diff --git a/apps/app/src/views/build/components/buildConfig/attrsRender/components/interactiveConfig/customEvent.vue b/apps/app/src/views/build/components/buildConfig/attrsRender/components/interactiveConfig/customEvent.vue index 15d591ce..ce08bc06 100644 --- a/apps/app/src/views/build/components/buildConfig/attrsRender/components/interactiveConfig/customEvent.vue +++ b/apps/app/src/views/build/components/buildConfig/attrsRender/components/interactiveConfig/customEvent.vue @@ -130,10 +130,6 @@ -
- -
-
-
- -
- - - diff --git a/apps/app/src/views/build/components/buildConfig/attrsRender/components/interactiveConfig/options.ts b/apps/app/src/views/build/components/buildConfig/attrsRender/components/interactiveConfig/options.ts index 40935a06..14db4d80 100644 --- a/apps/app/src/views/build/components/buildConfig/attrsRender/components/interactiveConfig/options.ts +++ b/apps/app/src/views/build/components/buildConfig/attrsRender/components/interactiveConfig/options.ts @@ -28,18 +28,11 @@ import { customTableListOptions, EncodeEventTypeEnum, EventTypeEnum, - MessageTypeEnum, - messageTypeOptions, ParameterTypeEnum, parameterTypeOptions, SceneObjectExplosionType, sceneObjectExplosionTypeOptions, - tcpudpDataTypeEnum, - tcpudpDataTypeOptions, timingFunction, - UDPSendtypeEnum, - UDPSendtypeListOptions, - ueMessageTypeOptions, VisibleTypeEnum, visibleTypeOptions } from "../../../constants/index"; @@ -174,30 +167,15 @@ export const templateActions = (): Action => { toY: 0 }, encodeKey: null, - ue4Config: { - messageName: "", - messageJson: "", - messageContent: "", - messageType: MessageTypeEnum.String - }, customActionType: "component", // 动作-类型 panelStatusAnimationId: "", // 面板状态动画ID panelStatusId: "", // 面板状态ID - tcpudpConfig: { - dataType: tcpudpDataTypeEnum.None, - dataSourceId: "", - dataSourceObj: null, - sendData: "", - sendType: UDPSendtypeEnum.Unicast, - dataDelay: 0 - }, projectFunName: "", projectParamList: [], projectParamType: ParameterTypeEnum.Default, projectParamValue: {}, projectParamCode: "", swiperCardTabsName: "", - aiManMsgContent: "", setBroadcastId: null, videoStartTime: 0, videoEndTime: 0, @@ -400,22 +378,6 @@ export const createTemplateAction = (actionType: ActionTypeEnum): Partial { [ConfigFieldEnum.ConditionType]: conditionTypeOptions, [ConfigFieldEnum.ConditionCompare]: conditionCompareOptions, [ConfigFieldEnum.VisibleType]: visibleTypeOptions, - [ConfigFieldEnum.MessageType]: messageTypeOptions, - [ConfigFieldEnum.UeMessageType]: ueMessageTypeOptions, [ConfigFieldEnum.CustomTableList]: customTableListOptions, - [ConfigFieldEnum.TcpudpDataType]: tcpudpDataTypeOptions, - [ConfigFieldEnum.UDPSendtypeList]: UDPSendtypeListOptions, [ConfigFieldEnum.ParameterType]: parameterTypeOptions, [ConfigFieldEnum.AnimationOutType]: animationOutList, [ConfigFieldEnum.SceneObjectExplosionType]: sceneObjectExplosionTypeOptions @@ -642,7 +578,7 @@ export const moreActionSExcludes = () => { export const switchStateProp = (prop: AllComponentType) => { const getComponent2ActionMap = createComponent2ActionMapGetter(); const propActions = getComponent2ActionMap().get(prop) || ""; - return propActions.includes(ActionTypeEnum.SwitchState) || propActions.includes(ActionTypeEnum.SwitchTCState); + return propActions.includes(ActionTypeEnum.SwitchState); }; export const switchSceneStatusProp = (prop: AllComponentType) => { diff --git a/apps/app/src/views/build/components/buildConfig/attrsRender/components/statusAnimation/components/hooks/generators/mappings.ts b/apps/app/src/views/build/components/buildConfig/attrsRender/components/statusAnimation/components/hooks/generators/mappings.ts index 2314e08e..737b23f0 100644 --- a/apps/app/src/views/build/components/buildConfig/attrsRender/components/statusAnimation/components/hooks/generators/mappings.ts +++ b/apps/app/src/views/build/components/buildConfig/attrsRender/components/statusAnimation/components/hooks/generators/mappings.ts @@ -63,8 +63,8 @@ export const DEFAULT_PROPERTY_MAPPINGS: PropertyMapping[] = [ } ]; -const advanceMappings: PropertyMapping[] = [ - // 外观组属性 +// 外观组属性:opacity 字段名在原子组件迁移前后都叫 option.opacity,所有组件通用 +const opacityMapping: PropertyMapping[] = [ { source: "opacity", target: "option.opacity", @@ -72,9 +72,14 @@ const advanceMappings: PropertyMapping[] = [ validator: (value) => typeof value === "number" && value >= 0 && value <= 1, description: "透明度", group: "appearance" - }, + } +]; - // 旋转组属性 +// 旋转组属性:仅适用于仍然使用离散 rotateX/Y/Z 字段的组件(如 SwVideo/SwMutual)。 +// swimg/swtext 迁移到新 schema 后旋转已经并入通用的 option.transform 字符串, +// 不再有离散的 rotateX/Y/Z 字段,所以这两个组件不再拼进这组映射(否则状态动画面板 +// 会显示一个写了也不生效的"旋转"属性组)。 +const rotationMappings: PropertyMapping[] = [ { source: "rotateX", target: "option.rotateX", @@ -101,6 +106,9 @@ const advanceMappings: PropertyMapping[] = [ } ]; +// 保留原名/原组合,供其他未在 COMPONENT_TYPE_MAPPINGS 里单独列出的组件类型兜底使用(见文件末尾 fallback) +const advanceMappings: PropertyMapping[] = [...opacityMapping, ...rotationMappings]; + const ftImgMappings: PropertyMapping[] = [ { source: "image", diff --git a/apps/app/src/views/build/components/buildConfig/attrsRender/components/useDataApi.ts b/apps/app/src/views/build/components/buildConfig/attrsRender/components/useDataApi.ts index 6008f7d1..da08880d 100644 --- a/apps/app/src/views/build/components/buildConfig/attrsRender/components/useDataApi.ts +++ b/apps/app/src/views/build/components/buildConfig/attrsRender/components/useDataApi.ts @@ -6,7 +6,6 @@ import type { dbModelReq } from "@/model/DataModel"; import { DataSourceType } from "@/views/source/type"; import type { ComponentType } from "../../../buildRender/type"; -import { tcpudpDataTypeEnum } from "../../constants"; export type ApiFunction = (params: dbModelReq) => Promise; export interface DataSource { @@ -24,13 +23,6 @@ const apiMap = new Map([ [DataSourceType.TCPUDP, getDataSocketList] ]); -const dataTypeMapDataSourceType = { - [tcpudpDataTypeEnum.None]: DataSourceType.LOCAL, - [tcpudpDataTypeEnum.TCP]: DataSourceType.TCPUDP, - [tcpudpDataTypeEnum.UDP]: DataSourceType.TCPUDP, - [tcpudpDataTypeEnum.WebSocket]: DataSourceType.WEBSOCKET -}; - const useDataApi = createGlobalState((type?: DataSourceType) => { const options = ref< Array< @@ -79,4 +71,4 @@ const useDataApi = createGlobalState((type?: DataSourceType) => { return { options, getMenuApi, getOptionData, setOptions }; }); -export { dataTypeMapDataSourceType, useDataApi }; +export { useDataApi }; diff --git a/apps/app/src/views/build/components/buildConfig/attrsRender/interactiveConfig.vue b/apps/app/src/views/build/components/buildConfig/attrsRender/interactiveConfig.vue index 9d2b506a..accb7fff 100644 --- a/apps/app/src/views/build/components/buildConfig/attrsRender/interactiveConfig.vue +++ b/apps/app/src/views/build/components/buildConfig/attrsRender/interactiveConfig.vue @@ -1,7 +1,6 @@