| | |
| | | * @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 获取系统信息同步接口 |
| | |
| | | */ |
| | | 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 |
| | | } |
| | | |
| | | /** |
| | |
| | | // 通过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 |
| | |
| | | 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 |
| | | } |
| | | |
| | |
| | | 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, |
| | |
| | | setProperty, |
| | | page, |
| | | pages, |
| | | getValueByPath, |
| | | // setConfig |
| | | } |