-
zhangwei
2025-03-05 16213c0f85aa3ac8317797bf4a05fd12940e16d3
src/uni_modules/uview-plus/libs/function/index.js
@@ -50,7 +50,12 @@
 * @link 运行期判断平台 https://uniapp.dcloud.io/frame?id=判断平台
 */
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 获取系统信息同步接口
@@ -58,6 +63,26 @@
 */
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
}
/**
@@ -119,6 +144,7 @@
   // 通过while历遍,这里主要是为了H5需要多层解析的问题
   while (parent) {
      // 父组件
        name = name.replace(/up-([a-zA-Z0-9-_]+)/g, 'u-$1')
      if (parent.$options && parent.$options.name !== name) {
         // 如果组件的name不相等,继续上一级寻找
         parent = parent.$parent
@@ -181,8 +207,11 @@
   if (!unit) {
      unit = config.unit || 'px'
   }
   if (unit == 'rpx' && testNumber(String(value))) {
      value = value * 2
   }
   value = String(value)
   // 用uView内置验证规则中的number判断是否为数值
   // 用内置验证规则中的number判断是否为数值
   return testNumber(value) ? `${value}${unit}` : value
}
@@ -690,12 +719,24 @@
   return pages
}
export function getValueByPath(obj, path) {
    // 将路径字符串按 '.' 分割成数组
    const pathArr = path.split('.');
    // 使用 reduce 方法从 obj 开始,逐级访问嵌套属性
    return pathArr.reduce((acc, curr) => {
        // 如果当前累加器(acc)是对象且包含当前键(curr),则返回该键对应的值
        // 否则返回 undefined(表示路径不存在)
        return acc && acc[curr] !== undefined ? acc[curr] : undefined;
    }, obj);
}
export default {
   range,
   getPx,
   sleep,
   os,
   sys,
   getWindowInfo,
   random,
   guid,
   $parent,
@@ -720,5 +761,6 @@
   setProperty,
   page,
   pages,
   getValueByPath,
   // setConfig
}