uview-plus组件库全面升级更新,订单结算判断支付方式是否可用代码调整,公众号关注二维码修改
This commit is contained in:
64
uni_modules/uview-plus/libs/function/calc.js
Normal file
64
uni_modules/uview-plus/libs/function/calc.js
Normal file
@@ -0,0 +1,64 @@
|
||||
// 浮点数加法
|
||||
export function add (arg1, arg2) {
|
||||
var r1, r2, m
|
||||
try {
|
||||
r1 = arg1.toString().split('.')[1].length
|
||||
} catch (e) {
|
||||
r1 = 0
|
||||
}
|
||||
try {
|
||||
r2 = arg2.toString().split('.')[1].length
|
||||
} catch (e) {
|
||||
r2 = 0
|
||||
}
|
||||
m = Math.pow(10, Math.max(r1, r2))
|
||||
return (arg1 * m + arg2 * m) / m
|
||||
}
|
||||
// 浮点数减法
|
||||
export function sub (arg1, arg2) {
|
||||
var r1, r2, m, n
|
||||
try {
|
||||
r1 = arg1.toString().split('.')[1].length
|
||||
} catch (e) {
|
||||
r1 = 0
|
||||
}
|
||||
try {
|
||||
r2 = arg2.toString().split('.')[1].length
|
||||
} catch (e) {
|
||||
r2 = 0
|
||||
}
|
||||
m = Math.pow(10, Math.max(r1, r2))
|
||||
n = (r1 >= r2) ? r1 : r2
|
||||
return Math.abs(((arg1 * m - arg2 * m) / m).toFixed(n))
|
||||
}
|
||||
//浮点乘法
|
||||
export function mul (a, b) {
|
||||
var c = 0,
|
||||
d = a.toString(),
|
||||
e = b.toString();
|
||||
try {
|
||||
c += d.split(".")[1].length;
|
||||
} catch (f) {}
|
||||
try {
|
||||
c += e.split(".")[1].length;
|
||||
} catch (f) {}
|
||||
return Number(d.replace(".", "")) * Number(e.replace(".", "")) / Math.pow(10, c);
|
||||
}
|
||||
//浮点除法
|
||||
export function div (a, b) {
|
||||
var c, d, e = 0,
|
||||
f = 0;
|
||||
try {
|
||||
e = a.toString().split(".")[1].length;
|
||||
} catch (g) {}
|
||||
try {
|
||||
f = b.toString().split(".")[1].length;
|
||||
} catch (g) {}
|
||||
return c = Number(a.toString().replace(".", "")), d = Number(b.toString().replace(".", "")), xyutil.mul(c / d, Math.pow(10, f - e));
|
||||
}
|
||||
export default {
|
||||
add,
|
||||
sub,
|
||||
mul,
|
||||
div
|
||||
}
|
||||
4
uni_modules/uview-plus/libs/function/http.js
Normal file
4
uni_modules/uview-plus/libs/function/http.js
Normal file
@@ -0,0 +1,4 @@
|
||||
// 全局挂载引入http相关请求拦截插件
|
||||
import Request from '../luch-request'
|
||||
const http = new Request()
|
||||
export default http
|
||||
@@ -32,6 +32,20 @@ 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 毫秒
|
||||
@@ -361,6 +375,10 @@ 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{3}Z$/.test(dateTime)) {
|
||||
date = new Date(dateTime)
|
||||
}
|
||||
// 其他都认为符合 RFC 2822 规范
|
||||
else {
|
||||
// 处理平台性差异,在Safari/Webkit中,new Date仅支持/作为分割符的字符串时间
|
||||
@@ -730,6 +748,93 @@ 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,
|
||||
@@ -762,5 +867,6 @@ export default {
|
||||
page,
|
||||
pages,
|
||||
getValueByPath,
|
||||
// setConfig
|
||||
genLightColor,
|
||||
rpx2px
|
||||
}
|
||||
|
||||
@@ -237,6 +237,13 @@ export function object(value) {
|
||||
return Object.prototype.toString.call(value) === '[object Object]'
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是Promise对象
|
||||
*/
|
||||
export function objectPromise(value) {
|
||||
return Object.prototype.toString.call(value) === '[object Promise]';
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否短信验证码
|
||||
*/
|
||||
@@ -257,7 +264,7 @@ export function func(value) {
|
||||
* @param {Object} value
|
||||
*/
|
||||
export function promise(value) {
|
||||
return object(value) && func(value.then) && func(value.catch)
|
||||
return objectPromise(value) && func(value.then) && func(value.catch)
|
||||
}
|
||||
|
||||
/** 是否图片格式
|
||||
|
||||
Reference in New Issue
Block a user