Skip to content

Commit

Permalink
fix: 修复微信getSystemInfoSync接口废弃警告
Browse files Browse the repository at this point in the history
  • Loading branch information
jry committed Dec 30, 2024
1 parent a6cb3c2 commit 31749c4
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import { props } from './props';
import { mpMixin } from '../../libs/mixin/mpMixin';
import { mixin } from '../../libs/mixin/mixin';
import { addUnit, sys} from '../../libs/function/index';
import { addUnit, getWindowInfo} from '../../libs/function/index';
/**
* dropdown 下拉菜单
* @description 该组件一般用于向下展开菜单,同时可切换多个选项卡的场景
Expand Down Expand Up @@ -166,8 +166,8 @@
getContentHeight() {
// 这里的原理为,因为dropdown组件是相对定位的,它的下拉出来的内容,必须给定一个高度
// 才能让遮罩占满菜单一下,直到屏幕底部的高度
// sys()为uview-plus封装的获取设备信息的方法
let windowHeight = sys().windowHeight;
// getWindowInfo()为uview-plus封装的获取设备信息的方法
let windowHeight = getWindowInfo().windowHeight;
this.$uGetRect('.u-dropdown__menu').then(res => {
// 这里获取的是dropdown的尺寸,在H5上,uniapp获取尺寸是有bug的(以前提出修复过,后来又出现了此bug,目前hx2.8.11版本)
// H5端bug表现为元素尺寸的top值为导航栏底部到到元素的上边沿的距离,但是元素的bottom值确是导航栏顶部到元素底部的距离
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
import { props } from './props';
import { mpMixin } from '../../libs/mixin/mpMixin';
import { mixin } from '../../libs/mixin/mixin';
import { addUnit, sys, sleep, getPx } from '../../libs/function/index';
import { addUnit, getWindowInfo, sleep, getPx } from '../../libs/function/index';
// #ifdef APP-NVUE
// 由于weex为阿里的KPI业绩考核的产物,所以不支持百分比单位,这里需要通过dom查询组件的宽度
Expand Down Expand Up @@ -152,7 +152,7 @@
// scroll-view的高度
scrollViewHeight: 0,
// 系统信息
sys: sys(),
sys: {},
scrolling: false,
scrollIntoView: '',
pageY: 0,
Expand Down Expand Up @@ -188,6 +188,7 @@
created() {
this.children = []
this.anchors = []
this.sys = getWindowInfo()
},
mounted() {
this.init()
Expand Down Expand Up @@ -320,7 +321,7 @@
const {
height
} = size
const sysData = sys()
const sysData = getWindowInfo()
const windowHeight = sysData.windowHeight
let customNavHeight = 0
// 消除各端导航栏非原生和原生导致的差异,让索引列表字母对屏幕垂直居中
Expand Down Expand Up @@ -358,7 +359,7 @@
let index = this.currentIndex;
// 对H5的pageY进行修正,这是由于uni-app自作多情在H5中将触摸点的坐标跟H5的导航栏结合导致的问题
// #ifdef H5
// pageY += sys().windowTop
// pageY += getWindowInfo().windowTop
// #endif
// 对第一和最后一个字母做边界处理,因为用户可能在字母列表上触摸到两端的尽头后依然继续滑动
// console.log('top1', top)
Expand Down Expand Up @@ -476,8 +477,8 @@
let children = this.children
// #ifdef APP-NVUE
// nvue下获取的滚动条偏移为负数,需要转为正数
let sys = uni.getSystemInfoSync()
scrollTop = Math.abs(e.contentOffset.y) / 10
let sys = getWindowInfo()
scrollTop = Math.abs(e.contentOffset.y) / 10
// console.log('native', e)
// #endif
Expand Down Expand Up @@ -515,7 +516,7 @@
if (scrollTop <= children[0].top || scrollTop >= children[len - 1].top + children[len - 1].height) {
this.activeIndex = -1
break
} else if (!nextItem) {
} else if (!nextItem) {
// 当不存在下一个item时,意味着历遍到了最后一个
this.activeIndex = len - 1
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import { props } from './props';
import { mpMixin } from '../../libs/mixin/mpMixin';
import { mixin } from '../../libs/mixin/mixin';
import { sys } from '../../libs/function/index';
import { getWindowInfo } from '../../libs/function/index';
// #ifdef APP-NVUE
const dom = uni.requireNativePlugin('dom')
// #endif
Expand All @@ -39,7 +39,7 @@
rect: {},
index: 0,
show: true,
sys: sys()
sys: getWindowInfo()
}
},
computed: {
Expand Down
4 changes: 2 additions & 2 deletions src/uni_modules/uview-plus/components/u-list/u-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import { props } from './props';
import { mpMixin } from '../../libs/mixin/mpMixin';
import { mixin } from '../../libs/mixin/mixin';
import { addUnit, addStyle, deepMerge, sleep, sys } from '../../libs/function/index';
import { addUnit, addStyle, deepMerge, sleep, getWindowInfo } from '../../libs/function/index';
// #ifdef APP-NVUE
const dom = uni.requireNativePlugin('dom')
// #endif
Expand Down Expand Up @@ -90,7 +90,7 @@
innerScrollTop: 0,
// vue下,scroll-view在上拉加载时的偏移值
offset: 0,
sys: sys()
sys: getWindowInfo()
}
},
computed: {
Expand Down
6 changes: 3 additions & 3 deletions src/uni_modules/uview-plus/components/u-navbar/u-navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class="u-navbar__placeholder"
v-if="fixed && placeholder"
:style="{
height: addUnit(getPx(height) + sys().statusBarHeight,'px'),
height: addUnit(getPx(height) + getWindowInfo().statusBarHeight,'px'),
}"
></view>
<view :class="[fixed && 'u-navbar--fixed']">
Expand Down Expand Up @@ -77,7 +77,7 @@
import { props } from './props';
import { mpMixin } from '../../libs/mixin/mpMixin';
import { mixin } from '../../libs/mixin/mixin';
import { addUnit, addStyle, getPx, sys } from '../../libs/function/index';
import { addUnit, addStyle, getPx, getWindowInfo } from '../../libs/function/index';
/**
* Navbar 自定义导航栏
* @description 此组件一般用于在特殊情况下,需要自定义导航栏的时候用到,一般建议使用uni-app带的导航栏。
Expand Down Expand Up @@ -114,7 +114,7 @@
methods: {
addStyle,
addUnit,
sys,
getWindowInfo,
getPx,
// 点击左侧区域
leftClick() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import { props } from './props';
import { mpMixin } from '../../libs/mixin/mpMixin';
import { mixin } from '../../libs/mixin/mixin';
import { toast } from '../../libs/function/index';
import { toast, getDeviceInfo } from '../../libs/function/index';
/**
* noNetwork 无网络提示
* @description 该组件无需任何配置,引入即可,内部自动处理所有功能和事件。
Expand All @@ -67,7 +67,7 @@
}
},
mounted() {
this.isIOS = (uni.getSystemInfoSync().platform === 'ios')
this.isIOS = (getDeviceInfo().platform === 'ios')
uni.onNetworkStatusChange((res) => {
this.isConnected = res.isConnected
this.networkType = res.networkType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default {
return {
ctrl: {},
// #ifdef MP-WEIXIN
isiOS: uni.getSystemInfoSync().system.includes('iOS')
isiOS: uni.getDeviceInfo().system.includes('iOS')
// #endif
}
},
Expand Down
8 changes: 6 additions & 2 deletions src/uni_modules/uview-plus/components/u-parse/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,16 @@ const config = {
}
}
const tagSelector={}
// #ifdef APP || H5 || MP-WEIXIN
const { windowWidth } = uni.getWindowInfo()
const { system } = uni.getDeviceInfo()
// #endif
// #ifndef APP || H5 || MP-WEIXIN
const {
windowWidth,
// #ifdef MP-WEIXIN
system
// #endif
} = uni.getSystemInfoSync()
// #endif
const blankChar = makeMap(' ,\r,\n,\t,\f')
let idIndex = 0

Expand Down
4 changes: 2 additions & 2 deletions src/uni_modules/uview-plus/components/u-popup/u-popup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import { props } from './props';
import { mpMixin } from '../../libs/mixin/mpMixin';
import { mixin } from '../../libs/mixin/mixin';
import { addUnit, addStyle, deepMerge, sleep, sys } from '../../libs/function/index';
import { addUnit, addStyle, deepMerge, sleep, getWindowInfo } from '../../libs/function/index';
/**
* popup 弹窗
* @description 弹出层容器,用于展示弹窗、信息提示等内容,支持上、下、左、右和中部弹出。组件只提供容器,内部内容由用户自定义
Expand Down Expand Up @@ -139,7 +139,7 @@
// 不使用css方案,是因为nvue不支持css的iPhoneX安全区查询属性
const {
safeAreaInsets
} = sys()
} = getWindowInfo()
if (this.mode !== 'center') {
style.flex = 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import { props } from "./props.js";
import { mpMixin } from '../../libs/mixin/mpMixin';
import { mixin } from '../../libs/mixin/mixin';
import { addStyle, deepMerge, addUnit, sys } from '../../libs/function/index';
import { addStyle, deepMerge, addUnit, getWindowInfo } from '../../libs/function/index';
/**
* SafeBottom 底部安全区
* @description 这个适配,主要是针对IPhone X等一些底部带指示条的机型,指示条的操作区域与页面底部存在重合,容易导致用户误操作,因此我们需要针对这些机型进行底部安全区适配。
Expand All @@ -36,7 +36,7 @@
const style = {};
// #ifdef APP-NVUE || MP-TOUTIAO
// nvue下,高度使用js计算填充
style.height = addUnit(sys().safeAreaInsets.bottom, 'px');
style.height = addUnit(getWindowInfo().safeAreaInsets.bottom, 'px');
// #endif
return deepMerge(style, addStyle(this.customStyle));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import { props } from './props';
import { mpMixin } from '../../libs/mixin/mpMixin';
import { mixin } from '../../libs/mixin/mixin';
import { addUnit, addStyle, deepMerge, sys } from '../../libs/function/index';
import { addUnit, addStyle, deepMerge, getWindowInfo } from '../../libs/function/index';
/**
* StatbusBar 状态栏占位
* @description 本组件主要用于状态填充,比如在自定导航栏的时候,它会自动适配一个恰当的状态栏高度。
Expand All @@ -38,7 +38,7 @@
style() {
const style = {}
// 状态栏高度,由于某些安卓和微信开发工具无法识别css的顶部状态栏变量,所以使用js获取的方式
style.height = addUnit(sys().statusBarHeight, 'px')
style.height = addUnit(getWindowInfo().statusBarHeight, 'px')
style.backgroundColor = this.bgColor
return deepMerge(style, addStyle(this.customStyle))
}
Expand Down
4 changes: 2 additions & 2 deletions src/uni_modules/uview-plus/components/u-sticky/u-sticky.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { props } from './props';
import { mpMixin } from '../../libs/mixin/mpMixin';
import { mixin } from '../../libs/mixin/mixin';
import { addUnit, addStyle, deepMerge, getPx, guid, sys, os } from '../../libs/function/index';
import { addUnit, addStyle, deepMerge, getPx, guid, getDeviceInfo, os } from '../../libs/function/index';
import zIndex from '../../libs/config/zIndex';
/**
* sticky 吸顶
Expand Down Expand Up @@ -150,7 +150,7 @@
// #endif
// 如果安卓版本高于8.0,依然认为是支持css sticky的(因为安卓7在某些机型,可能不支持sticky)
if (os() === 'android' && Number(sys().system) > 8) {
if (os() === 'android' && Number(getDeviceInfo().system) > 8) {
this.cssSticky = true
}
Expand Down
4 changes: 2 additions & 2 deletions src/uni_modules/uview-plus/components/u-tabs/u-tabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
import { mpMixin } from '../../libs/mixin/mpMixin';
import { mixin } from '../../libs/mixin/mixin';
import defProps from '../../libs/config/props.js'
import { addUnit, addStyle, deepMerge, getPx, sleep, sys } from '../../libs/function/index';
import { addUnit, addStyle, deepMerge, getPx, sleep, getWindowInfo } from '../../libs/function/index';
/**
* Tabs 标签
* @description tabs标签组件,在标签多的时候,可以配置为左右滑动,标签少的时候,可以禁止滑动。 该组件的一个特点是配置为滚动模式时,激活的tab会自动移动到组件的中间位置。
Expand Down Expand Up @@ -253,7 +253,7 @@
return total + curr.rect.width
}, 0)
// 此处为屏幕宽度
const windowWidth = sys().windowWidth
const windowWidth = getWindowInfo().windowWidth
// 将活动的tabs-item移动到屏幕正中间,实际上是对scroll-view的移动
let scrollLeft = offsetLeft - (this.tabsRect.width - tabRect.rect.width) / 2 - (windowWidth - this.tabsRect
.right) / 2 + this.tabsRect.left / 2
Expand Down
4 changes: 2 additions & 2 deletions src/uni_modules/uview-plus/components/u-toast/u-toast.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<script>
import { mpMixin } from '../../libs/mixin/mpMixin';
import { mixin } from '../../libs/mixin/mixin';
import { os, sys, deepMerge, type2icon } from '../../libs/function/index';
import { os, getWindowInfo, deepMerge, type2icon } from '../../libs/function/index';
import color from '../../libs/config/color';
import { hexToRgb } from '../../libs/function/colorGradient';
/**
Expand Down Expand Up @@ -136,7 +136,7 @@
},
// 内容盒子的样式
contentStyle() {
const windowHeight = sys().windowHeight, style = {}
const windowHeight = getWindowInfo().windowHeight, style = {}
let value = 0
// 根据top和bottom,对Y轴进行窗体高度的百分比偏移
if(this.tmpConfig.position === 'top') {
Expand Down
4 changes: 2 additions & 2 deletions src/uni_modules/uview-plus/components/u-tooltip/u-tooltip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
import { props } from './props';
import { mpMixin } from '../../libs/mixin/mpMixin';
import { mixin } from '../../libs/mixin/mixin';
import { addStyle, addUnit, getPx, guid, toast, sleep, sys } from '../../libs/function/index';
import { addStyle, addUnit, getPx, guid, toast, sleep, getWindowInfo } from '../../libs/function/index';
// #ifdef APP-NVUE
const dom = uni.requireNativePlugin('dom')
// #endif
Expand Down Expand Up @@ -162,7 +162,7 @@
const style = {
transform: `translateY(${this.direction === 'top' ? '-100%' : '100%'})`,
},
sysInfo = sys()
sysInfo = getWindowInfo()
if (this.tooltipInfo.width / 2 > this.textInfo.left + this.textInfo.width / 2 - this.screenGap) {
this.indicatorStyle = {}
style.left = `-${addUnit(this.textInfo.left - this.screenGap)}`
Expand Down
32 changes: 29 additions & 3 deletions src/uni_modules/uview-plus/libs/function/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,40 @@ export function sleep(value = 30) {
* @returns {string} 返回所在平台(小写)
* @link 运行期判断平台 https://uniapp.dcloud.io/frame?id=判断平台
*/
export function os() {
return uni.getSystemInfoSync().platform.toLowerCase()
export function os() {
// #ifdef APP || H5 || MP-WEIXIN
return uni.getDeviceInfo().platform.toLowerCase()
// #endif
// #ifndef APP || H5 || MP-WEIXIN
return uni.getSystemInfoSync().platform.toLowerCase()
// #endif
}
/**
* @description 获取系统信息同步接口
* @link 获取系统信息同步接口 https://uniapp.dcloud.io/api/system/info?id=getsysteminfosync
*/
export function sys() {
return uni.getSystemInfoSync()
}
export function getWindowInfo() {
let ret = {}
// #ifdef APP || H5 || MP-WEIXIN
ret = uni.getWindowInfo()
// #endif
// #ifndef APP || H5 || MP-WEIXIN
ret = sys()
// #endif
return ret
}
export function getDeviceInfo() {
let ret = {}
// #ifdef APP || H5 || MP-WEIXIN
ret = uni.getDeviceInfo()
// #endif
// #ifndef APP || H5 || MP-WEIXIN
ret = sys()
// #endif
return ret
}

/**
Expand Down Expand Up @@ -710,7 +735,8 @@ export default {
getPx,
sleep,
os,
sys,
sys,
getWindowInfo,
random,
guid,
$parent,
Expand Down
2 changes: 1 addition & 1 deletion src/uni_modules/uview-plus/types/comps/actionSheet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ declare interface ActionSheetProps {
/**
* 点击ActionSheet列表项时触发
*/
onSelect?: () => any
onSelect?: (e: any) => any
/**
* 点击取消按钮时触发
*/
Expand Down

0 comments on commit 31749c4

Please sign in to comment.