feat:还原更新框架
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import {
|
||||
number as testNumber,
|
||||
array as testArray,
|
||||
empty as testEmpty
|
||||
} from './test.js'
|
||||
import { round } from './digit.js'
|
||||
import config from '../config/config.js'
|
||||
import {
|
||||
number as testNumber,
|
||||
array as testArray,
|
||||
empty as testEmpty
|
||||
} from './test'
|
||||
import { round } from './digit.js'
|
||||
import config from '../config/config';
|
||||
/**
|
||||
* @description 如果value小于min,取min;如果value大于max,取max
|
||||
* @param {number} min
|
||||
@@ -32,20 +32,6 @@ export function getPx(value, unit = false) {
|
||||
return unit ? `${parseInt(value)}px` : parseInt(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 用于统一rpx2px方法,因uni-app现有API未统一。
|
||||
* @param {number} value 用户传递值的rpx值
|
||||
* @returns {number}
|
||||
*/
|
||||
export function rpx2px(value) {
|
||||
// #ifdef APP
|
||||
return uni.upx2px(value)
|
||||
// #endif
|
||||
// #ifndef APP
|
||||
return uni.rpx2px(value)
|
||||
// #endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 进行延时,以达到可以简写代码的目的 比如: await uni.$u.sleep(20)将会阻塞20ms
|
||||
* @param {number} value 堵塞时间 单位ms 毫秒
|
||||
@@ -63,12 +49,12 @@ export function sleep(value = 30) {
|
||||
* @returns {string} 返回所在平台(小写)
|
||||
* @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()
|
||||
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
|
||||
}
|
||||
/**
|
||||
@@ -77,26 +63,26 @@ export function os() {
|
||||
*/
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,14 +143,9 @@ export function $parent(name = undefined) {
|
||||
let parent = this.$parent
|
||||
// 通过while历遍,这里主要是为了H5需要多层解析的问题
|
||||
while (parent) {
|
||||
// 父组件
|
||||
let name2 = ''
|
||||
if (name.startsWith('up-')) {
|
||||
name2 = name.replace(/up-([a-zA-Z0-9-_]+)/g, 'u-$1')
|
||||
} else if (name.startsWith('u-')) {
|
||||
name2 = name.replace(/u-([a-zA-Z0-9-_]+)/g, 'up-$1')
|
||||
}
|
||||
if (parent.$options && parent.$options.name !== name && parent.$options.name !== name2) {
|
||||
// 父组件
|
||||
name = name.replace(/up-([a-zA-Z0-9-_]+)/g, 'u-$1')
|
||||
if (parent.$options && parent.$options.name !== name) {
|
||||
// 如果组件的name不相等,继续上一级寻找
|
||||
parent = parent.$parent
|
||||
} else {
|
||||
@@ -380,10 +361,6 @@ export function timeFormat(dateTime = null, formatStr = 'yyyy-mm-dd') {
|
||||
else if (typeof dateTime === 'string' && /^\d+$/.test(dateTime.trim())) {
|
||||
date = new Date(Number(dateTime))
|
||||
}
|
||||
// 检查是否为UTC格式的时间字符串 (2024-12-18T02:25:31.432Z)
|
||||
else if (typeof dateTime === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?(Z|[+-]\d{2}:\d{2})?$/.test(dateTime)) {
|
||||
date = new Date(dateTime)
|
||||
}
|
||||
// 其他都认为符合 RFC 2822 规范
|
||||
else {
|
||||
// 处理平台性差异,在Safari/Webkit中,new Date仅支持/作为分割符的字符串时间
|
||||
@@ -650,8 +627,8 @@ export function padZero(value) {
|
||||
* @param {*} event
|
||||
*/
|
||||
export function formValidate(instance, event) {
|
||||
const formItem = $parent.call(instance, 'up-form-item')
|
||||
const form = $parent.call(instance, 'up-form')
|
||||
const formItem = $parent.call(instance, 'u-form-item')
|
||||
const form = $parent.call(instance, 'u-form')
|
||||
// 如果发生变化的input或者textarea等,其父组件中有u-form-item或者u-form等,就执行form的validate方法
|
||||
// 同时将form-item的pros传递给form,让其进行精确对象验证
|
||||
if (formItem && form) {
|
||||
@@ -753,99 +730,12 @@ export function getValueByPath(obj, path) {
|
||||
}, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成同色系浅色背景色
|
||||
* @param {string} textColor - 支持 #RGB、#RRGGBB、rgb()、rgba() 格式
|
||||
* @param {number} [lightness=85] - 目标亮度百分比(默认85%)
|
||||
* @returns {string} 十六进制颜色值
|
||||
*/
|
||||
export function genLightColor(textColor, lightness = 95) {
|
||||
// 手动解析颜色值(避免使用document)
|
||||
const rgb = parseColorWithoutDOM(textColor);
|
||||
|
||||
// RGB转HSL色域
|
||||
const hsl = rgbToHsl(rgb.r, rgb.g, rgb.b);
|
||||
|
||||
// 生成浅色背景
|
||||
const bgHsl = {
|
||||
h: hsl.h,
|
||||
s: hsl.s,
|
||||
l: Math.min(lightness, 95)
|
||||
};
|
||||
|
||||
return hslToHex(bgHsl.h, bgHsl.s, bgHsl.l);
|
||||
}
|
||||
|
||||
/* 手动解析颜色字符串(兼容uni-app环境) */
|
||||
function parseColorWithoutDOM(colorStr) {
|
||||
// 统一转小写处理
|
||||
const str = colorStr.toLowerCase().trim();
|
||||
|
||||
// 处理十六进制格式
|
||||
if (str.startsWith('#')) {
|
||||
const hex = str.replace('#', '');
|
||||
const fullHex = hex.length === 3 ?
|
||||
hex.split('').map(c => c + c).join('') : hex;
|
||||
|
||||
return {
|
||||
r: parseInt(fullHex.substring(0,2), 16),
|
||||
g: parseInt(fullHex.substring(2,4), 16),
|
||||
b: parseInt(fullHex.substring(4,6), 16)
|
||||
};
|
||||
}
|
||||
|
||||
// 处理rgb/rgba格式
|
||||
const rgbMatch = str.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
|
||||
if (rgbMatch) {
|
||||
return {
|
||||
r: +rgbMatch[1],
|
||||
g: +rgbMatch[2],
|
||||
b: +rgbMatch[3]
|
||||
};
|
||||
}
|
||||
|
||||
throw new Error('Invalid color format');
|
||||
}
|
||||
|
||||
// 辅助函数:RGB 转 HSL(色相、饱和度、亮度)
|
||||
function rgbToHsl(r, g, b) {
|
||||
r /= 255, g /= 255, b /= 255;
|
||||
const max = Math.max(r, g, b), min = Math.min(r, g, b);
|
||||
let h, s, l = (max + min) / 2;
|
||||
|
||||
if (max === min) {
|
||||
h = s = 0; // achromatic
|
||||
} else {
|
||||
const d = max - min;
|
||||
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
||||
switch (max) {
|
||||
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
|
||||
case g: h = (b - r) / d + 2; break;
|
||||
case b: h = (r - g) / d + 4; break;
|
||||
}
|
||||
h = (h * 60).toFixed(1);
|
||||
}
|
||||
return { h: +h, s: +(s * 100).toFixed(1), l: +(l * 100).toFixed(1) };
|
||||
}
|
||||
|
||||
// 辅助函数:HSL 转十六进制
|
||||
function hslToHex(h, s, l) {
|
||||
l /= 100;
|
||||
const a = s * Math.min(l, 1 - l) / 100;
|
||||
const f = n => {
|
||||
const k = (n + h / 30) % 12;
|
||||
const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
|
||||
return Math.round(255 * color).toString(16).padStart(2, '0');
|
||||
};
|
||||
return `#${f(0)}${f(8)}${f(4)}`;
|
||||
}
|
||||
|
||||
export default {
|
||||
range,
|
||||
getPx,
|
||||
sleep,
|
||||
os,
|
||||
sys,
|
||||
sys,
|
||||
getWindowInfo,
|
||||
random,
|
||||
guid,
|
||||
@@ -872,7 +762,5 @@ export default {
|
||||
page,
|
||||
pages,
|
||||
getValueByPath,
|
||||
genLightColor,
|
||||
rpx2px
|
||||
// setConfig
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user