提交 54d5d1d8 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

chore: 优化截图对比测试计算状态栏高度逻辑

上级 d3404d85
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
getWindowInfo: function () { getWindowInfo: function () {
const res = uni.getWindowInfo(); const res = uni.getWindowInfo();
// 获取状态栏+导航栏高度, 供截图对比使用 // 获取状态栏+导航栏高度, 供截图对比使用
setHeaderHeight(res.screenHeight - res.windowHeight); setStatusBarHeight(res.statusBarHeight);
this.items = [] as Item[]; this.items = [] as Item[];
for (const key in res) { for (const key in res) {
const value = res[key]; const value = res[key];
......
...@@ -269,7 +269,7 @@ describe("shot-compare", () => { ...@@ -269,7 +269,7 @@ describe("shot-compare", () => {
const isNeedAdbScreenshot = needAdbScreenshot(pages[pageIndex]); const isNeedAdbScreenshot = needAdbScreenshot(pages[pageIndex]);
const isCustomNavigationBar = customNavigationPages.includes(pages[pageIndex]); const isCustomNavigationBar = customNavigationPages.includes(pages[pageIndex]);
const { const {
headerHeight, statusBarHeight,
devicePixelRatio devicePixelRatio
} = await page.data(); } = await page.data();
const screenshotParams = { const screenshotParams = {
...@@ -278,7 +278,7 @@ describe("shot-compare", () => { ...@@ -278,7 +278,7 @@ describe("shot-compare", () => {
// adb 截图时跳过状态栏 // adb 截图时跳过状态栏
area: { area: {
x: 0, x: 0,
y: (headerHeight - 44) * devicePixelRatio, y: statusBarHeight * devicePixelRatio,
}, },
} }
const screenshotPath = `__webview__${pages[pageIndex].replace(/\//g, "-")}`; const screenshotPath = `__webview__${pages[pageIndex].replace(/\//g, "-")}`;
......
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
src: '', src: '',
webviewContext: null as WebviewContext | null, webviewContext: null as WebviewContext | null,
isLoaded: false, isLoaded: false,
headerHeight: state.headerHeight, statusBarHeight: state.statusBarHeight,
isCustomNavigationBar: false, isCustomNavigationBar: false,
placeholderStyle: { placeholderStyle: {
display: 'block', display: 'block',
height: `${state.headerHeight - 44}px`, height: `${state.statusBarHeight}px`,
backgroundColor: '#007aff' backgroundColor: '#007aff'
}, },
devicePixelRatio: state.devicePixelRatio, devicePixelRatio: state.devicePixelRatio,
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
if (this.src.indexOf('pages/template/navbar-lite/navbar-lite') > -1) { if (this.src.indexOf('pages/template/navbar-lite/navbar-lite') > -1) {
this.webviewContext?.evalJS(` this.webviewContext?.evalJS(`
const uniNavbar = document.querySelector('.uni-navbar'); const uniNavbar = document.querySelector('.uni-navbar');
uniNavbar.style.paddingTop = '${state.headerHeight - 44}px'; uniNavbar.style.paddingTop = '${state.statusBarHeight}px';
`) `)
} else if (this.src.indexOf('pages/template/scroll-fold-nav/scroll-fold-nav') > -1) { } else if (this.src.indexOf('pages/template/scroll-fold-nav/scroll-fold-nav') > -1) {
this.webviewContext?.evalJS(` this.webviewContext?.evalJS(`
......
type State = { type State = {
lifeCycleNum : number, lifeCycleNum : number,
// 状态栏 + 导航栏高度 // 状态栏高度
headerHeight : number, statusBarHeight : number,
// 设备像素比 // 设备像素比
devicePixelRatio : number devicePixelRatio : number
} }
export const state = reactive({ lifeCycleNum: 0, headerHeight: 0, devicePixelRatio: 1 } as State) export const state = reactive({ lifeCycleNum: 0, statusBarHeight: 0, devicePixelRatio: 1 } as State)
export const setLifeCycleNum = (num : number) => { export const setLifeCycleNum = (num : number) => {
state.lifeCycleNum = num state.lifeCycleNum = num
} }
export const setHeaderHeight = (height : number) => { export const setStatusBarHeight = (height : number) => {
state.headerHeight = height state.statusBarHeight = height
} }
export const setDevicePixelRatio = (devicePixelRatio : number) => { export const setDevicePixelRatio = (devicePixelRatio : number) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册