From dc279867ca3aee851c96d9c83149b59f22b1838f Mon Sep 17 00:00:00 2001 From: liujiayii Date: Tue, 9 Dec 2025 16:18:25 +0800 Subject: [PATCH 1/4] =?UTF-8?q?refactor(sys):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=20getSystemInfoSync=20=E5=85=BC=E5=AE=B9=E6=80=A7=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化微信小程序平台 getSystemInfoSync 兼容性处理 新增 getDeviceInfo() 、getWindowInfo() 方法 替换直接调用 uni.getSystemInfoSync() 为封装的函数 --- .../u-avatar-cropper/u-avatar-cropper.vue | 3 +- .../components/u-avatar-cropper/weCropper.js | 5 ++ .../components/u-avatar-cropper/weCropper.ts | 5 ++ .../u-circle-progress/u-circle-progress.vue | 3 +- .../components/u-navbar/u-navbar.vue | 18 ++--- .../components/u-no-network/u-no-network.vue | 4 +- .../components/u-skeleton/u-skeleton.vue | 7 +- .../u-tabs-swiper/u-tabs-swiper.vue | 3 +- .../uview-pro/libs/function/sys.ts | 78 +++++++++++++++++++ .../uview-pro/libs/util/system-theme.ts | 28 ++++--- 10 files changed, 127 insertions(+), 27 deletions(-) diff --git a/src/uni_modules/uview-pro/components/u-avatar-cropper/u-avatar-cropper.vue b/src/uni_modules/uview-pro/components/u-avatar-cropper/u-avatar-cropper.vue index dcf342b4..0163eaf6 100644 --- a/src/uni_modules/uview-pro/components/u-avatar-cropper/u-avatar-cropper.vue +++ b/src/uni_modules/uview-pro/components/u-avatar-cropper/u-avatar-cropper.vue @@ -57,6 +57,7 @@ import { $u } from '../..'; // 兼容 UMD/ESM 导入 weCropper.js import WeCropper from './weCropper'; import { AvatarCropperProps } from './types'; +import { getWindowInfo } from '../../libs/function/sys'; /** * 裁剪矩形框的样式,其中可包含的属性为lineWidth-边框宽度(单位rpx),color: 边框颜色, @@ -107,7 +108,7 @@ let cropper: any = null; // WeCropper 实例,类型 any,建议后续补充 */ onMounted(() => { // 获取系统信息 - const rectInfo = uni.getSystemInfoSync(); + const rectInfo = getWindowInfo(); width.value = rectInfo.windowWidth; height.value = rectInfo.windowHeight - bottomNavHeight.value; cropperOpt.width = width.value; diff --git a/src/uni_modules/uview-pro/components/u-avatar-cropper/weCropper.js b/src/uni_modules/uview-pro/components/u-avatar-cropper/weCropper.js index 8669adc0..5707c09f 100644 --- a/src/uni_modules/uview-pro/components/u-avatar-cropper/weCropper.js +++ b/src/uni_modules/uview-pro/components/u-avatar-cropper/weCropper.js @@ -38,7 +38,12 @@ function getDevice() { if (!device) { + // #ifdef MP-WEIXIN + device = uni.getWindowInfo(); + // #endif + // #ifndef MP-WEIXIN device = uni.getSystemInfoSync(); + // #endif } return device; } diff --git a/src/uni_modules/uview-pro/components/u-avatar-cropper/weCropper.ts b/src/uni_modules/uview-pro/components/u-avatar-cropper/weCropper.ts index 0f0df458..3ce80831 100644 --- a/src/uni_modules/uview-pro/components/u-avatar-cropper/weCropper.ts +++ b/src/uni_modules/uview-pro/components/u-avatar-cropper/weCropper.ts @@ -41,7 +41,12 @@ function validator(instance: any, o: any): void { function getDevice(): any { if (!device) { + // #ifdef MP-WEIXIN + device = uni.getWindowInfo(); + // #endif + // #ifndef MP-WEIXIN device = uni.getSystemInfoSync(); + // #endif } return device as any; } diff --git a/src/uni_modules/uview-pro/components/u-circle-progress/u-circle-progress.vue b/src/uni_modules/uview-pro/components/u-circle-progress/u-circle-progress.vue index 9c349d1e..c138f681 100644 --- a/src/uni_modules/uview-pro/components/u-circle-progress/u-circle-progress.vue +++ b/src/uni_modules/uview-pro/components/u-circle-progress/u-circle-progress.vue @@ -79,6 +79,7 @@ import { $u } from '../..'; import { CircleProgressProps } from './types'; // #ifdef MP-WEIXIN || MP-TOUTIAO import { canvas2d } from '../../libs/util/canvas-2d'; +import { getWindowInfo } from '../../libs/function/sys'; // #endif /** @@ -132,7 +133,7 @@ const circleColor = computed(() => { }); onBeforeMount(() => { - pixelRatio.value = uni.getSystemInfoSync().pixelRatio; + pixelRatio.value = getWindowInfo().pixelRatio; }); // 监听percent变化,动态绘制进度 diff --git a/src/uni_modules/uview-pro/components/u-navbar/u-navbar.vue b/src/uni_modules/uview-pro/components/u-navbar/u-navbar.vue index 32288233..0d6af381 100644 --- a/src/uni_modules/uview-pro/components/u-navbar/u-navbar.vue +++ b/src/uni_modules/uview-pro/components/u-navbar/u-navbar.vue @@ -68,6 +68,7 @@ export default { import { ref, computed } from 'vue'; import { $u } from '../..'; import { NavbarProps } from './types'; +import { getWindowInfo, os } from '../../libs/function/sys'; /** * navbar 自定义导航栏 @@ -94,8 +95,7 @@ import { NavbarProps } from './types'; */ const props = defineProps(NavbarProps); // 获取系统状态栏的高度 -const systemInfo = uni.getSystemInfoSync(); -const windowInfo = uni.getWindowInfo(); +const windowInfo = getWindowInfo(); let menuButtonInfo: any = {}; // 如果是小程序,获取右上角胶囊的尺寸信息,避免导航栏右侧内容与胶囊重叠(支付宝小程序非本API,尚未兼容) @@ -115,7 +115,7 @@ const navbarHeight = computed(() => { // 小程序特别处理,让导航栏高度 = 胶囊高度 + 两倍胶囊顶部与状态栏底部的距离之差(相当于同时获得了导航栏底部与胶囊底部的距离) // 此方法有缺陷,暂不用(会导致少了几个px),采用直接固定值的方式 // return menuButtonInfo.height + (menuButtonInfo.top - this.statusBarHeight) * 2;//导航高度 - let height = systemInfo.platform == 'ios' ? 44 : 48; + let height = os() === 'ios' ? 44 : 48; return props.height ? props.height : height; // #endif }); @@ -132,7 +132,7 @@ const navbarInnerStyle = computed(() => { style.height = String(navbarHeight.value) + 'px'; // 如果是各家小程序,导航栏内部的宽度需要减少右边胶囊的宽度 // #ifdef MP - let rightButtonWidth = systemInfo.windowWidth - menuButtonInfo.left; + let rightButtonWidth = windowInfo.windowWidth - menuButtonInfo.left; style.marginRight = rightButtonWidth + 'px'; // #endif return style; @@ -151,16 +151,16 @@ const navbarStyle = computed(() => { const titleStyle = computed(() => { let style: Record = {}; // #ifndef MP - style.left = (systemInfo.windowWidth - uni.upx2px(Number(props.titleWidth))) / 2 + 'px'; - style.right = (systemInfo.windowWidth - uni.upx2px(Number(props.titleWidth))) / 2 + 'px'; + style.left = (windowInfo.windowWidth - uni.upx2px(Number(props.titleWidth))) / 2 + 'px'; + style.right = (windowInfo.windowWidth - uni.upx2px(Number(props.titleWidth))) / 2 + 'px'; // #endif // #ifdef MP // 此处是为了让标题显示区域即使在小程序有右侧胶囊的情况下也能处于屏幕的中间,是通过绝对定位实现的 - let rightButtonWidth = systemInfo.windowWidth - menuButtonInfo.left; - style.left = (systemInfo.windowWidth - uni.upx2px(Number(props.titleWidth))) / 2 + 'px'; + let rightButtonWidth = windowInfo.windowWidth - menuButtonInfo.left; + style.left = (windowInfo.windowWidth - uni.upx2px(Number(props.titleWidth))) / 2 + 'px'; style.right = rightButtonWidth - - (systemInfo.windowWidth - uni.upx2px(Number(props.titleWidth))) / 2 + + (windowInfo.windowWidth - uni.upx2px(Number(props.titleWidth))) / 2 + rightButtonWidth + 'px'; // #endif diff --git a/src/uni_modules/uview-pro/components/u-no-network/u-no-network.vue b/src/uni_modules/uview-pro/components/u-no-network/u-no-network.vue index 994265c1..28e7cb90 100644 --- a/src/uni_modules/uview-pro/components/u-no-network/u-no-network.vue +++ b/src/uni_modules/uview-pro/components/u-no-network/u-no-network.vue @@ -32,7 +32,7 @@ export default { diff --git a/src/uni_modules/uview-pro/components/u-tabs-swiper/u-tabs-swiper.vue b/src/uni_modules/uview-pro/components/u-tabs-swiper/u-tabs-swiper.vue index 4e31ad19..e232c967 100644 --- a/src/uni_modules/uview-pro/components/u-tabs-swiper/u-tabs-swiper.vue +++ b/src/uni_modules/uview-pro/components/u-tabs-swiper/u-tabs-swiper.vue @@ -43,6 +43,7 @@ import { ref, computed, watch, nextTick, onMounted, getCurrentInstance } from 'v import colorGradient from '../../libs/function/colorGradient'; import { TabsSwiperProps } from './types'; import { $u } from '../..'; +import { getWindowInfo } from '../../libs/function/sys'; /** * tabsSwiper 全屏选项卡 @@ -75,7 +76,7 @@ import { $u } from '../..'; const props = defineProps(TabsSwiperProps); const color = colorGradient; -const { windowWidth } = uni.getSystemInfoSync(); +const { windowWidth } = getWindowInfo(); const preId = 'UEl_'; // emits 定义 diff --git a/src/uni_modules/uview-pro/libs/function/sys.ts b/src/uni_modules/uview-pro/libs/function/sys.ts index d0c24c0a..9bd2c0ac 100644 --- a/src/uni_modules/uview-pro/libs/function/sys.ts +++ b/src/uni_modules/uview-pro/libs/function/sys.ts @@ -3,13 +3,91 @@ * @returns 平台字符串,如 'ios'、'android'、'windows' 等 */ export function os(): string { + // #ifdef MP-WEIXIN + return uni.getDeviceInfo().platform; + // #endif + // #ifndef MP-WEIXIN return uni.getSystemInfoSync().platform; + // #endif } /** * 获取系统信息 + * @description 微信小程序已经弃用了 getSystemInfoSync 方法,建议在微信小程序中使用其它方法替代 * @returns uniapp 系统信息对象 */ export function sys(): UniApp.GetSystemInfoResult { return uni.getSystemInfoSync(); } + +/** + * 获取窗口信息 + * @returns 窗口信息对象 + */ +export function getWindowInfo(): Omit & { screenTop?: number } { + // #ifdef MP-WEIXIN + return uni.getWindowInfo(); + // #endif + // #ifndef MP-WEIXIN + const { + pixelRatio, + screenWidth, + screenHeight, + windowWidth, + windowHeight, + statusBarHeight, + windowTop, + windowBottom, + safeArea, + safeAreaInsets + } = sys(); + return { + pixelRatio, + screenWidth, + screenHeight, + windowWidth, + windowHeight, + statusBarHeight, + windowTop, + windowBottom, + safeArea, + safeAreaInsets + }; + // #endif +} + +/** + * 获取设备信息 + * @returns 设备信息对象 + */ +export function getDeviceInfo(): UniApp.GetDeviceInfoResult { + // #ifdef MP-WEIXIN + return uni.getDeviceInfo(); + // #endif + // #ifndef MP-WEIXIN + const { + deviceBrand, + deviceModel, + deviceId, + deviceType, + devicePixelRatio, + deviceOrientation, + brand, + model, + system, + platform + } = sys(); + // #endif + return { + deviceBrand, + deviceModel, + deviceId, + deviceType, + devicePixelRatio, + deviceOrientation, + brand, + model, + system, + platform + }; +} diff --git a/src/uni_modules/uview-pro/libs/util/system-theme.ts b/src/uni_modules/uview-pro/libs/util/system-theme.ts index 61b924d6..d676a43d 100644 --- a/src/uni_modules/uview-pro/libs/util/system-theme.ts +++ b/src/uni_modules/uview-pro/libs/util/system-theme.ts @@ -1,21 +1,29 @@ -declare const uni: any; +import { sys } from '../function/sys'; type SystemTheme = 'light' | 'dark'; +function getSystemTheme(): SystemTheme { + // #ifdef MP-WEIXIN + const { theme } = uni.getAppBaseInfo(); + return (theme || 'light') as SystemTheme; + // #endif + // #ifndef MP-WEIXIN + const sysInfo = sys(); + return (sysInfo.osTheme || sysInfo.theme || 'light') as SystemTheme; + // #endif +} + /** * 非 H5 平台获取当前系统主题 */ export function getSystemDarkMode(): SystemTheme { try { - if (typeof uni !== 'undefined' && typeof uni.getSystemInfoSync === 'function') { - const systemInfo = uni.getSystemInfoSync(); - const theme = systemInfo.osTheme || systemInfo.theme || 'light'; - if (theme === 'dark') { - return 'dark'; - } - if (theme === 'light') { - return 'light'; - } + const theme = getSystemTheme(); + if (theme === 'dark') { + return 'dark'; + } + if (theme === 'light') { + return 'light'; } } catch (e) { // 获取失败时默认返回亮色 From 8d102f9cd1f91478aaca14803e4f26315339b21c Mon Sep 17 00:00:00 2001 From: liujiayii Date: Sat, 20 Dec 2025 17:32:21 +0800 Subject: [PATCH 2/4] =?UTF-8?q?style:=20=E7=BB=9F=E4=B8=80=E7=BC=A9?= =?UTF-8?q?=E8=BF=9B=E4=B8=BA=E5=88=B6=E8=A1=A8=E7=AC=A6=E5=B9=B6=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=9D=A1=E4=BB=B6=E7=BC=96=E8=AF=91=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复条件编译指令前的空格不一致问题,并将所有缩进统一为制表符以提高代码可读性 --- src/uni_modules/uview-pro/libs/function/sys.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uni_modules/uview-pro/libs/function/sys.ts b/src/uni_modules/uview-pro/libs/function/sys.ts index 9bd2c0ac..a5252935 100644 --- a/src/uni_modules/uview-pro/libs/function/sys.ts +++ b/src/uni_modules/uview-pro/libs/function/sys.ts @@ -61,7 +61,7 @@ export function getWindowInfo(): Omit & * @returns 设备信息对象 */ export function getDeviceInfo(): UniApp.GetDeviceInfoResult { - // #ifdef MP-WEIXIN + // #ifdef MP-WEIXIN return uni.getDeviceInfo(); // #endif // #ifndef MP-WEIXIN @@ -77,7 +77,6 @@ export function getDeviceInfo(): UniApp.GetDeviceInfoResult { system, platform } = sys(); - // #endif return { deviceBrand, deviceModel, @@ -90,4 +89,5 @@ export function getDeviceInfo(): UniApp.GetDeviceInfoResult { system, platform }; + // #endif } From 295eaa6c7520c9d47c3972e5e9b80ef67f2276ed Mon Sep 17 00:00:00 2001 From: liujiayii Date: Mon, 22 Dec 2025 10:50:38 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat(sys):=20=E6=9B=BF=E6=8D=A2$u.sys()?= =?UTF-8?q?=E4=B8=BA$u.getWindowInfo()=E8=8E=B7=E5=8F=96=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 统一使用getWindowInfo方法替代旧的sys方法获取窗口信息,提高代码可维护性 --- src/pages/componentsB/tabbar/index.vue | 1 + .../components/u-dropdown/u-dropdown.vue | 4 ++-- .../uview-pro/components/u-fab/u-fab.vue | 24 +++++++++---------- .../u-safe-bottom/u-safe-bottom.vue | 2 +- .../components/u-status-bar/u-status-bar.vue | 2 +- .../components/u-tabbar/u-tabbar.vue | 2 +- src/uni_modules/uview-pro/libs/index.ts | 4 +++- 7 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/pages/componentsB/tabbar/index.vue b/src/pages/componentsB/tabbar/index.vue index 0d60aa2d..299c917d 100644 --- a/src/pages/componentsB/tabbar/index.vue +++ b/src/pages/componentsB/tabbar/index.vue @@ -36,6 +36,7 @@ :mid-button="midButton" :inactive-color="inactiveColor" :activeColor="activeColor" + :hide-tab-bar="false" > diff --git a/src/uni_modules/uview-pro/components/u-dropdown/u-dropdown.vue b/src/uni_modules/uview-pro/components/u-dropdown/u-dropdown.vue index b605b7a7..8d04595b 100644 --- a/src/uni_modules/uview-pro/components/u-dropdown/u-dropdown.vue +++ b/src/uni_modules/uview-pro/components/u-dropdown/u-dropdown.vue @@ -239,10 +239,10 @@ function highlight(index?: number) { * 获取下拉菜单内容的高度 * 这里的原理为,因为dropdown组件是相对定位的,它的下拉出来的内容,必须给定一个高度 * 才能让遮罩占满菜单一下,直到屏幕底部的高度 - * this.$u.sys()为uView封装的获取设备信息的方法 + * this.$u.getWindowInfo()为uView封装的获取设备窗口信息的方法 */ function getContentHeight() { - const windowHeight = $u.sys().windowHeight; + const windowHeight = $u.getWindowInfo().windowHeight; $u.getRect('.u-dropdown__menu', instance).then((res: any) => { // 这里获取的是dropdown的尺寸,在H5上,uniapp获取尺寸是有bug的(以前提出修复过,后来又出现了此bug,目前hx2.8.11版本) diff --git a/src/uni_modules/uview-pro/components/u-fab/u-fab.vue b/src/uni_modules/uview-pro/components/u-fab/u-fab.vue index 9e1f04b2..67e26183 100644 --- a/src/uni_modules/uview-pro/components/u-fab/u-fab.vue +++ b/src/uni_modules/uview-pro/components/u-fab/u-fab.vue @@ -50,7 +50,7 @@ const emit = defineEmits(['trigger']); const slots = useSlots(); const instance = getCurrentInstance(); -const sysInfo = $u.sys(); +const windowInfo = $u.getWindowInfo(); const dragging = ref(true); const minLeft = ref(0); const maxLeft = ref(0); @@ -58,9 +58,9 @@ const minTop = ref(0); const maxTop = ref(0); const expansion = ref(false); const direction = ref(props.direction); -const effectiveWindowHeight = ref(sysInfo.windowHeight); +const effectiveWindowHeight = ref(windowInfo.windowHeight); // #ifdef H5 -effectiveWindowHeight.value = sysInfo.windowTop + sysInfo.windowHeight; +effectiveWindowHeight.value = windowInfo.windowTop + windowInfo.windowHeight; // #endif const position = reactive({ top: 0, @@ -179,12 +179,12 @@ function handleTouchend() { return; } - const middle = sysInfo.windowWidth / 2; + const middle = windowInfo.windowWidth / 2; const buttonCenter = position.left + btnInfo.value.width / 2; // 自动吸边,按钮中心位置大于视口的一半时,自动依附在右边,不然就是左边 position.left = - buttonCenter > middle ? sysInfo.windowWidth - btnInfo.value.width - getGap('right') : getGap('left'); + buttonCenter > middle ? windowInfo.windowWidth - btnInfo.value.width - getGap('right') : getGap('left'); if (expansion.value) direction.value = calcDirection(); } @@ -221,7 +221,7 @@ function calcDirection() { if (position.left - getGap('left') < actionsWidth) dir = 'right'; } else if (dir === 'right') { // 按钮右侧剩余空间: 有效窗口宽度 - (按钮左侧 + 按钮宽 + 边距) - const right = sysInfo.windowWidth - (position.left + btnInfo.value.width + getGap('right')); + const right = windowInfo.windowWidth - (position.left + btnInfo.value.width + getGap('right')); if (right < actionsWidth) dir = 'left'; } @@ -232,17 +232,17 @@ function calcDirection() { function initPosition() { // 根据 props.position 计算初始 left/top const pos = props.position || 'right-bottom'; - const winW = sysInfo.windowWidth; + const winW = windowInfo.windowWidth; const winH = effectiveWindowHeight.value; switch (pos) { case 'left-top': position.left = getGap('left'); - position.top = getGap('top') + sysInfo.windowTop; + position.top = getGap('top') + windowInfo.windowTop; break; case 'right-top': position.left = winW - btnInfo.value.width - getGap('right'); - position.top = getGap('top') + sysInfo.windowTop; + position.top = getGap('top') + windowInfo.windowTop; break; case 'left-bottom': position.left = getGap('left'); @@ -262,7 +262,7 @@ function initPosition() { break; case 'top-center': position.left = Math.round((winW - btnInfo.value.width) / 2); - position.top = getGap('top') + sysInfo.windowTop; + position.top = getGap('top') + windowInfo.windowTop; break; case 'bottom-center': position.left = Math.round((winW - btnInfo.value.width) / 2); @@ -282,8 +282,8 @@ onMounted(async () => { initPosition(); minLeft.value = getGap('left'); - minTop.value = getGap('top') + sysInfo.windowTop; - maxLeft.value = sysInfo.windowWidth - btnInfo.value.width - getGap('right'); + minTop.value = getGap('top') + windowInfo.windowTop; + maxLeft.value = windowInfo.windowWidth - btnInfo.value.width - getGap('right'); maxTop.value = effectiveWindowHeight.value - btnInfo.value.height - getGap('bottom'); }); diff --git a/src/uni_modules/uview-pro/components/u-safe-bottom/u-safe-bottom.vue b/src/uni_modules/uview-pro/components/u-safe-bottom/u-safe-bottom.vue index f02833bc..c72e49af 100644 --- a/src/uni_modules/uview-pro/components/u-safe-bottom/u-safe-bottom.vue +++ b/src/uni_modules/uview-pro/components/u-safe-bottom/u-safe-bottom.vue @@ -38,7 +38,7 @@ const style = computed(() => { let result: CSSProperties = {}; // #ifdef APP-NVUE || MP-TOUTIAO // nvue下,高度使用js计算填充 - result.height = $u.addUnit($u.sys().safeAreaInsets.bottom, 'px'); + result.height = $u.addUnit($u.getWindowInfo().safeAreaInsets.bottom, 'px'); // #endif return result; }); diff --git a/src/uni_modules/uview-pro/components/u-status-bar/u-status-bar.vue b/src/uni_modules/uview-pro/components/u-status-bar/u-status-bar.vue index 6e48a316..c0bf7ec5 100644 --- a/src/uni_modules/uview-pro/components/u-status-bar/u-status-bar.vue +++ b/src/uni_modules/uview-pro/components/u-status-bar/u-status-bar.vue @@ -38,7 +38,7 @@ const style = computed(() => { let result: CSSProperties = { background: props.background }; - const statusBarHeight = $u.sys().statusBarHeight; + const statusBarHeight = $u.getWindowInfo().statusBarHeight; if (statusBarHeight === 0) { noBar.value = true; } else { diff --git a/src/uni_modules/uview-pro/components/u-tabbar/u-tabbar.vue b/src/uni_modules/uview-pro/components/u-tabbar/u-tabbar.vue index 59d2df9b..6b483018 100644 --- a/src/uni_modules/uview-pro/components/u-tabbar/u-tabbar.vue +++ b/src/uni_modules/uview-pro/components/u-tabbar/u-tabbar.vue @@ -216,7 +216,7 @@ function getOffsetRight(count: number, isDot: boolean): number { * 获取凸起按钮外层元素的left值,让其水平居中 */ function getMidButtonLeft() { - const windowWidth = $u.sys().windowWidth; + const windowWidth = $u.getWindowInfo().windowWidth; // 由于安卓中css计算left: 50%的结果不准确,故用js计算 midButtonLeft.value = windowWidth / 2 + 'px'; } diff --git a/src/uni_modules/uview-pro/libs/index.ts b/src/uni_modules/uview-pro/libs/index.ts index b0c864c8..7563ff9d 100644 --- a/src/uni_modules/uview-pro/libs/index.ts +++ b/src/uni_modules/uview-pro/libs/index.ts @@ -39,7 +39,7 @@ import $parent from './function/$parent'; // 获取sys()和os()工具方法 // 获取设备信息,挂载到$u的sys()(system的缩写)属性中, // 同时把安卓和ios平台的名称"ios"和"android"挂到$u.os()中,方便取用 -import { sys, os } from './function/sys'; +import { sys, os, getWindowInfo, getDeviceInfo } from './function/sys'; // 防抖方法 import debounce from './function/debounce'; // 节流方法 @@ -307,6 +307,8 @@ export const $u = { getColor, sys, os, + getWindowInfo, + getDeviceInfo, type2icon, randomArray, hexToRgb: colorGradients.hexToRgb, From 889fc3707250e62426bc9d62999ad1c45043b959 Mon Sep 17 00:00:00 2001 From: liujiayii Date: Mon, 22 Dec 2025 11:33:34 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix(u-circle-progress):=20=E8=B0=83?= =?UTF-8?q?=E6=95=B4getWindowInfo=E5=AF=BC=E5=85=A5=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E4=BB=A5=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移动getWindowInfo导入语句到正确的位置 --- .../components/u-circle-progress/u-circle-progress.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uni_modules/uview-pro/components/u-circle-progress/u-circle-progress.vue b/src/uni_modules/uview-pro/components/u-circle-progress/u-circle-progress.vue index c138f681..80f44b36 100644 --- a/src/uni_modules/uview-pro/components/u-circle-progress/u-circle-progress.vue +++ b/src/uni_modules/uview-pro/components/u-circle-progress/u-circle-progress.vue @@ -79,8 +79,8 @@ import { $u } from '../..'; import { CircleProgressProps } from './types'; // #ifdef MP-WEIXIN || MP-TOUTIAO import { canvas2d } from '../../libs/util/canvas-2d'; -import { getWindowInfo } from '../../libs/function/sys'; // #endif +import { getWindowInfo } from '../../libs/function/sys'; /** * circleProgress 环形进度条