From 2f4eed917e47245755256c7cdd65af3d8d585c65 Mon Sep 17 00:00:00 2001 From: luo Date: Sat, 31 Oct 2026 13:02:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=99=BD=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tests/pageTransitionRoots.test.mjs | 51 +++++++++++++++++++ .../asset-information/index.vue | 14 ++--- .../asset-management/device-list/index.vue | 16 +++--- .../iot-card-management/index.vue | 16 +++--- 4 files changed, 74 insertions(+), 23 deletions(-) create mode 100644 scripts/tests/pageTransitionRoots.test.mjs diff --git a/scripts/tests/pageTransitionRoots.test.mjs b/scripts/tests/pageTransitionRoots.test.mjs new file mode 100644 index 0000000..bb77fb8 --- /dev/null +++ b/scripts/tests/pageTransitionRoots.test.mjs @@ -0,0 +1,51 @@ +import test from 'node:test' +import assert from 'node:assert/strict' +import { readFileSync } from 'node:fs' +import { compileTemplate, parse } from '@vue/compiler-sfc' + +const pages = [ + ['asset-information', 'div', 'PollingStateDialog', 'pollingStateTarget'], + ['device-list', 'ArtTableFullScreen', 'PollingBatchDialog', 'pollingBatchIds'], + ['iot-card-management', 'ArtTableFullScreen', 'PollingBatchDialog', 'pollingBatchIds'] +] + +for (const [page, rootTag, dialogTag, dialogState] of pages) { + test(`${page} keeps its polling dialog inside one transition-compatible page root`, () => { + const filename = `src/views/asset-management/${page}/index.vue` + const { descriptor, errors } = parse(readFileSync(filename, 'utf8'), { filename }) + assert.deepEqual(errors, []) + const roots = descriptor.template.ast.children.filter((node) => node.type === 1) + assert.equal(roots.length, 1, 'sibling polling dialogs turn the page into a Fragment') + assert.equal(roots[0].tag, rootTag, 'preserve the existing page/layout root') + + const dialog = roots[0].children.find((node) => node.type === 1 && node.tag === dialogTag) + assert.ok(dialog, 'the polling dialog must remain available inside the page root') + const condition = dialog.props.find((prop) => prop.type === 7 && prop.name === 'if') + assert.equal(condition?.exp.content, dialogState) + const close = dialog.props.find( + (prop) => prop.type === 7 && prop.name === 'on' && prop.arg?.content === 'close' + ) + assert.equal(close?.exp.content, `${dialogState} = null`) + + // In production, a Fragment root never completes Transition's out-in leave, + // leaving KeepAlive on a comment placeholder for every subsequent route. + const compiled = compileTemplate({ + source: descriptor.template.content, + filename, + id: page, + isProd: true, + compilerOptions: { expressionPlugins: ['typescript'] } + }) + assert.deepEqual(compiled.errors, []) + assert.equal(compiled.ast.codegenNode.type, 13, 'the page must compile to a single VNode') + assert.equal(typeof compiled.ast.codegenNode.tag, 'string', 'never compile a Fragment root') + }) +} + +test('the table page layout provides a native element root for route transitions', () => { + const filename = 'src/components/core/tables/ArtTableFullScreen.vue' + const { descriptor } = parse(readFileSync(filename, 'utf8'), { filename }) + const roots = descriptor.template.ast.children.filter((node) => node.type === 1) + assert.equal(roots.length, 1) + assert.equal(roots[0].tag, 'div') +}) diff --git a/src/views/asset-management/asset-information/index.vue b/src/views/asset-management/asset-information/index.vue index a8b7d3f..2c0a655 100644 --- a/src/views/asset-management/asset-information/index.vue +++ b/src/views/asset-management/asset-information/index.vue @@ -188,14 +188,14 @@ :confirm-loading="speedTierSubmitting" @confirm="handleSpeedTierConfirm" /> + -