diff --git a/admin/local-preview/PreviewIdentity.vue b/admin/local-preview/PreviewIdentity.vue index 132028642..db5a89d34 100644 --- a/admin/local-preview/PreviewIdentity.vue +++ b/admin/local-preview/PreviewIdentity.vue @@ -1,2 +1,2 @@ - + diff --git a/admin/local-preview/README.md b/admin/local-preview/README.md index a0bd371d4..e8614ccec 100644 --- a/admin/local-preview/README.md +++ b/admin/local-preview/README.md @@ -15,3 +15,5 @@ node local-preview/build.mjs && node local-preview/server.mjs 5178 本机若用 macOS 会话任务启动本分支的预览,可用 `launchctl list local.zyt.theme-preview.bfc2` 查看、`launchctl remove local.zyt.theme-preview.bfc2` 停止;停止预览不影响其他应用。未安装开机启动项。 验证:`node --test local-preview/fixtures.test.mjs` 检查模拟数据;服务运行后 `node local-preview/verify-http.mjs` 复核写入、代理、跨域等均被拒绝。可选的 `browser_smoke.py` 使用 Python Playwright 和本地 Chromium,只允许本机请求。 + +`verify-art-parameters.py --chrome --out <截图目录>` 对照固定的 Art Design Pro 默认参数,测量实际渲染的亮色、暗色和经典外观,并保存对应截图和 computed.json。该验收同样只访问回环地址。 diff --git a/admin/local-preview/Root.vue b/admin/local-preview/Root.vue index 67b699c52..3afb33bbe 100644 --- a/admin/local-preview/Root.vue +++ b/admin/local-preview/Root.vue @@ -1,12 +1,12 @@ diff --git a/admin/local-preview/main.ts b/admin/local-preview/main.ts index 51b783722..716a17648 100644 --- a/admin/local-preview/main.ts +++ b/admin/local-preview/main.ts @@ -3,7 +3,7 @@ import 'element-plus/dist/index.css' import 'element-plus/theme-chalk/dark/css-vars.css' import '@/styles/index.scss' import '@/install/plugins/echart' -import { createApp } from 'vue' +import { createApp, watch } from 'vue' import ElementPlus from 'element-plus' import installIcons from '@/install/plugins/element' import perms from '@/install/directives/perms' @@ -14,11 +14,14 @@ import useTabsStore from '@/stores/modules/multipleTabs' import useSettingStore from '@/stores/modules/setting' import Root from './Root.vue' import router, { pages } from './router' -import logo from './preview-mark.svg' +import classicLogo from './preview-mark.svg' +import artLogo from './preview-mark-art.svg' const app = createApp(Root) app.use(store); app.use(ElementPlus); installIcons(app); app.directive('perms', perms) useUserStore().$patch({ token: '', userInfo: { name: '本地预览', role_ids: [] }, perms: ['order.order/lists','order.order/detail'], routes: pages.map(({ path, name, meta }) => ({ path, name, meta })) as any }) -useAppStore().$patch({ configFetchAttempted: true, config: { web_name: '甄养堂', web_logo: logo } }) -useSettingStore().$patch({ showLogo: true }) +const appState = useAppStore(), settings = useSettingStore() +appState.$patch({ configFetchAttempted: true, config: { web_name: '甄养堂' } }) +settings.$patch({ showLogo: true }) +watch(() => settings.adminUi, mode => { appState.config.web_logo = mode === 'v2' ? artLogo : classicLogo }, { immediate: true }) useTabsStore().setRouteName('preview-workbench') app.use(router); router.isReady().then(() => app.mount('#app')) diff --git a/admin/local-preview/preview-mark-art.svg b/admin/local-preview/preview-mark-art.svg new file mode 100644 index 000000000..8526d02e2 --- /dev/null +++ b/admin/local-preview/preview-mark-art.svg @@ -0,0 +1 @@ + diff --git a/admin/local-preview/verify-art-parameters.py b/admin/local-preview/verify-art-parameters.py new file mode 100644 index 000000000..a59bbd6bb --- /dev/null +++ b/admin/local-preview/verify-art-parameters.py @@ -0,0 +1,66 @@ +"""Compare rendered elements, not just declared CSS tokens, to Art Design Pro f3aaf58.""" +import argparse +import json +import re +from pathlib import Path +from playwright.sync_api import expect, sync_playwright + +parser = argparse.ArgumentParser() +parser.add_argument('--out', type=Path, required=True) +parser.add_argument('--chrome', required=True) +parser.add_argument('--record-only', action='store_true', help='record the pre-correction build without asserting parity') +a = parser.parse_args() +a.out.mkdir(exist_ok=True, parents=True) +origin = 'http://127.0.0.1:5178/' +read_colors = """() => { + const style = (sel) => getComputedStyle(document.querySelector(sel)); + const sample = (sel, key) => { + const value = style(sel)[key]; + // Canvas normalises srgb color-mix / rgb / hex to the actual 8-bit pixel color. + const ctx=document.createElement('canvas').getContext('2d');ctx.fillStyle=value;ctx.fillRect(0,0,1,1); + return '#' + [...ctx.getImageData(0,0,1,1).data].slice(0,3).map(x=>x.toString(16).padStart(2,'0')).join('').toUpperCase(); + }; + const bg=sel=>sample(sel,'backgroundColor'); + return {primaryButton:bg('.wb-refresh-btn'), page:bg('.main-wrap'),sidebar:bg('.side'), + sidebarWidth:Math.round(document.querySelector('.app-aside').getBoundingClientRect().width), + activeItem:bg('.menu .el-menu-item.is-active'),activeText:sample('.menu .el-menu-item.is-active span','color'), + card:bg('.wb-section'),cardRadius:style('.wb-section').borderTopLeftRadius,cardBorder:style('.wb-section').borderTopColor, + cardShadow:style('.wb-section').boxShadow, buttonHeight:style('.wb-refresh-btn').height, + menuItemHeight:style('.menu .el-menu-item.is-active').height, + selectedColorToken:getComputedStyle(document.documentElement).getPropertyValue('--el-color-primary-light-9').trim()}; +}""" +modes = {}; external=[]; palette=[] +with sync_playwright() as pw: + browser=pw.chromium.launch(executable_path=a.chrome,args=['--disable-background-networking','--no-proxy-server','--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1']) + ctx=browser.new_context(viewport={'width':1440,'height':960},color_scheme='light',service_workers='block') + def local(route): + if route.request.url.startswith(origin): return route.continue_() + external.append(route.request.url); return route.abort() + ctx.route('**/*',local); page=ctx.new_page(); page.goto(origin+'admin/workbench',wait_until='networkidle'); expect(page.locator('.wb-refresh-btn')).to_be_visible() + for mode in ['light','dark','classic']: + if mode=='dark': page.emulate_media(color_scheme='dark'); expect(page.locator('html')).to_have_class(re.compile('dark')) + if mode=='classic': + page.emulate_media(color_scheme='light'); page.locator('[data-admin-ui-toggle]').click(); expect(page.locator('html')).to_have_attribute('data-admin-ui','legacy') + page.mouse.move(1430,950); page.wait_for_timeout(350) + modes[mode]=page.evaluate(read_colors); page.screenshot(path=str(a.out/(mode+'.png'))) + if not a.record_only: + page.locator('[data-admin-ui-toggle]').click(); page.locator('.navbar .setting').click() + drawer=page.locator('.setting-drawer .el-drawer:visible, .el-drawer:visible').last + expect(drawer.get_by_role('button',name='设计菜单')).to_have_attribute('aria-pressed','true') + expect(drawer.get_by_role('spinbutton').first).to_have_value('230') + drawer.locator('.el-color-picker').click() + swatches=page.locator('.el-color-predefine__color-selector:visible'); expect(swatches).to_have_count(7) + palette=swatches.evaluate_all("els => els.map(e => {const c=getComputedStyle(e.querySelector('div')).backgroundColor.match(/\\d+/g);return '#'+c.slice(0,3).map(v=>(+v).toString(16).padStart(2,'0')).join('').toUpperCase()})") + assert palette == ['#5D87FF','#B48DF3','#1D84FF','#60C041','#38C0FC','#F9901F','#FF80C8'],palette + swatches.nth(1).click(); page.locator('.el-color-picker__panel:visible, .el-color-picker-panel:visible').last.get_by_role('button',name=re.compile('确定|确认')).click() + expect(page.locator('.wb-refresh-btn')).to_have_css('background-color','rgb(180, 141, 243)') + drawer.get_by_role('button',name='重置主题').click(); expect(page.locator('.wb-refresh-btn')).to_have_css('background-color','rgb(93, 135, 255)') + browser.close() +report={'upstream':'f3aaf58eec1a0e988f162352c33862327a484f95','actual':modes,'settings_palette':palette,'external_requests':external} +(a.out/'computed.json').write_text(json.dumps(report,indent=2,ensure_ascii=False)+'\n'); print(json.dumps(report,ensure_ascii=False)); assert not external +if not a.record_only: + expected={'light':{'primaryButton':'#5D87FF','page':'#FAFBFC','sidebar':'#FFFFFF','activeItem':'#EEF3FF','activeText':'#5D87FF','card':'#FFFFFF','menuItemHeight':'42px','buttonHeight':'36px','cardRadius':'16px','cardBorder':'rgba(0, 0, 0, 0.08)','cardShadow':'none'}, 'dark':{'primaryButton':'#5D87FF','page':'#070707','sidebar':'#161618','activeItem':'#27282D','activeText':'#5D87FF','card':'#161618'}, 'classic':{'primaryButton':'#4A5DFF','sidebar':'#1D2124'}} + for mode,checks in expected.items(): + for k,v in checks.items(): assert modes[mode][k]==v,(mode,k,v,modes[mode][k]) + assert modes['light']['sidebarWidth'] in (230,231),modes['light']['sidebarWidth'] # pane + optional one-pixel boundary + print('PASS: Art theme parameters match rendered controls; classic appearance preserved.') diff --git a/admin/src/App.vue b/admin/src/App.vue index 02341ef36..b151f1186 100755 --- a/admin/src/App.vue +++ b/admin/src/App.vue @@ -1,20 +1,19 @@ diff --git a/admin/src/layout/default/components/sidebar/menu.vue b/admin/src/layout/default/components/sidebar/menu.vue index cc95122f4..fdf4ae447 100755 --- a/admin/src/layout/default/components/sidebar/menu.vue +++ b/admin/src/layout/default/components/sidebar/menu.vue @@ -1,7 +1,7 @@