From 614bfde50ff3d249654dd2d0f781e9239f63e5ee Mon Sep 17 00:00:00 2001 From: jianweie Date: Tue, 16 May 2023 16:01:08 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8D=87=E7=BA=A7=E3=80=91=E5=8D=87?= =?UTF-8?q?=E7=BA=A7uView=E5=89=8D=E7=AB=AFUI=E6=A1=86=E6=9E=B6=E5=88=B02.?= =?UTF-8?q?0.36=E7=89=88=E6=9C=AC=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CoreShop/uni_modules/uview-ui/LICENSE | 4 +- .../uni_modules/uview-ui/changelog.md | 5 + .../uview-ui/components/u-modal/u-modal.vue | 2 +- .../uview-ui/components/u-text/props.js | 2 +- .../uview-ui/libs/config/config.js | 4 +- .../uview-ui/libs/function/index.js | 94 ++++++++++++------- .../uni_modules/uview-ui/package.json | 13 +-- 7 files changed, 76 insertions(+), 48 deletions(-) diff --git a/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/LICENSE b/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/LICENSE index 8e39eada..4db40efe 100644 --- a/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/LICENSE +++ b/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 www.uviewui.com +Copyright (c) 2023 www.uviewui.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/changelog.md b/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/changelog.md index d80fd9fe..f2bae726 100644 --- a/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/changelog.md +++ b/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/changelog.md @@ -1,3 +1,8 @@ +## 2.0.36(2023-03-27) +# uView2.0重磅发布,利剑出鞘,一统江湖 + +1. 重构`deepClone` & `deepMerge`方法 +2. 其他优化 ## 2.0.34(2022-09-24) # uView2.0重磅发布,利剑出鞘,一统江湖 diff --git a/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/components/u-modal/u-modal.vue b/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/components/u-modal/u-modal.vue index cc8fe05d..2cbc7370 100644 --- a/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/components/u-modal/u-modal.vue +++ b/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/components/u-modal/u-modal.vue @@ -114,7 +114,7 @@ * @event {Function} confirm 点击确认按钮时触发 * @event {Function} cancel 点击取消按钮时触发 * @event {Function} close 点击遮罩关闭出发,closeOnClickOverlay为true有效 - * @example + * @example */ export default { name: 'u-modal', diff --git a/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/components/u-text/props.js b/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/components/u-text/props.js index 85a0836b..d3300759 100644 --- a/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/components/u-text/props.js +++ b/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/components/u-text/props.js @@ -83,7 +83,7 @@ export default { }, // 文字装饰,下划线,中划线等,可选值 none|underline|line-through decoration: { - tepe: String, + type: String, default: uni.$u.props.text.decoration }, // 外边距,对象、字符串,数值形式均可 diff --git a/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/libs/config/config.js b/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/libs/config/config.js index 8389666a..a3a784e7 100644 --- a/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/libs/config/config.js +++ b/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/libs/config/config.js @@ -1,5 +1,5 @@ -// 此版本发布于2022-00-24 -const version = '2.0.34' +// 此版本发布于2023-03-27 +const version = '2.0.36' // 开发环境才提示,生产环境不会提示 if (process.env.NODE_ENV === 'development') { diff --git a/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/libs/function/index.js b/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/libs/function/index.js index 72351294..bd80ee7c 100644 --- a/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/libs/function/index.js +++ b/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/libs/function/index.js @@ -2,8 +2,8 @@ import test from './test.js' import { round } from './digit.js' /** * @description 如果value小于min,取min;如果value大于max,取max - * @param {number} min - * @param {number} max + * @param {number} min + * @param {number} max * @param {number} value */ function range(min = 0, max = 0, value = 0) { @@ -13,7 +13,7 @@ function range(min = 0, max = 0, value = 0) { /** * @description 用于获取用户传递值的px值 如果用户传递了"xxpx"或者"xxrpx",取出其数值部分,如果是"xxxrpx"还需要用过uni.upx2px进行转换 * @param {number|string} value 用户传递值的px值 - * @param {boolean} unit + * @param {boolean} unit * @returns {number|string} */ function getPx(value, unit = false) { @@ -41,7 +41,7 @@ function sleep(value = 30) { } /** * @description 运行期判断平台 - * @returns {string} 返回所在平台(小写) + * @returns {string} 返回所在平台(小写) * @link 运行期判断平台 https://uniapp.dcloud.io/frame?id=判断平台 */ function os() { @@ -49,7 +49,7 @@ function os() { } /** * @description 获取系统信息同步接口 - * @link 获取系统信息同步接口 https://uniapp.dcloud.io/api/system/info?id=getsysteminfosync + * @link 获取系统信息同步接口 https://uniapp.dcloud.io/api/system/info?id=getsysteminfosync */ function sys() { return uni.getSystemInfoSync() @@ -179,22 +179,34 @@ function addUnit(value = 'auto', unit = uni?.$u?.config?.unit ?? 'px') { /** * @description 深度克隆 * @param {object} obj 需要深度克隆的对象 + * @param cache 缓存 * @returns {*} 克隆后的对象或者原值(不是对象) */ -function deepClone(obj) { - // 对常见的“非”值,直接返回原来值 - if ([null, undefined, NaN, false].includes(obj)) return obj - if (typeof obj !== 'object' && typeof obj !== 'function') { - // 原始类型直接返回 - return obj - } - const o = test.array(obj) ? [] : {} - for (const i in obj) { - if (obj.hasOwnProperty(i)) { - o[i] = typeof obj[i] === 'object' ? deepClone(obj[i]) : obj[i] +function deepClone(obj, cache = new WeakMap()) { + if (obj === null || typeof obj !== 'object') return obj; + if (cache.has(obj)) return cache.get(obj); + let clone; + if (obj instanceof Date) { + clone = new Date(obj.getTime()); + } else if (obj instanceof RegExp) { + clone = new RegExp(obj); + } else if (obj instanceof Map) { + clone = new Map(Array.from(obj, ([key, value]) => [key, deepClone(value, cache)])); + } else if (obj instanceof Set) { + clone = new Set(Array.from(obj, value => deepClone(value, cache))); + } else if (Array.isArray(obj)) { + clone = obj.map(value => deepClone(value, cache)); + } else if (Object.prototype.toString.call(obj) === '[object Object]') { + clone = Object.create(Object.getPrototypeOf(obj)); + cache.set(obj, clone); + for (const [key, value] of Object.entries(obj)) { + clone[key] = deepClone(value, cache); } + } else { + clone = Object.assign({}, obj); } - return o + cache.set(obj, clone); + return clone; } /** @@ -205,24 +217,27 @@ function deepClone(obj) { */ function deepMerge(target = {}, source = {}) { target = deepClone(target) - if (typeof target !== 'object' || typeof source !== 'object') return false + if (typeof target !== 'object' || target === null || typeof source !== 'object' || source === null) return target; + const merged = Array.isArray(target) ? target.slice() : Object.assign({}, target); for (const prop in source) { - if (!source.hasOwnProperty(prop)) continue - if (prop in target) { - if (typeof target[prop] !== 'object') { - target[prop] = source[prop] - } else if (typeof source[prop] !== 'object') { - target[prop] = source[prop] - } else if (target[prop].concat && source[prop].concat) { - target[prop] = target[prop].concat(source[prop]) - } else { - target[prop] = deepMerge(target[prop], source[prop]) - } + if (!source.hasOwnProperty(prop)) continue; + const sourceValue = source[prop]; + const targetValue = merged[prop]; + if (sourceValue instanceof Date) { + merged[prop] = new Date(sourceValue); + } else if (sourceValue instanceof RegExp) { + merged[prop] = new RegExp(sourceValue); + } else if (sourceValue instanceof Map) { + merged[prop] = new Map(sourceValue); + } else if (sourceValue instanceof Set) { + merged[prop] = new Set(sourceValue); + } else if (typeof sourceValue === 'object' && sourceValue !== null) { + merged[prop] = deepMerge(targetValue, sourceValue); } else { - target[prop] = source[prop] + merged[prop] = sourceValue; } } - return target + return merged; } /** @@ -327,7 +342,7 @@ if (!String.prototype.padStart) { /** * @description 时间戳转为多久之前 * @param {String|Number} timestamp 时间戳 - * @param {String|Boolean} format + * @param {String|Boolean} format * 格式化规则如果为时间格式字符串,超出一定时间范围,返回固定的时间格式; * 如果为布尔值false,无论什么时间,都返回多久以前的格式 * @returns {string} 转化后的内容 @@ -517,7 +532,7 @@ function priceFormat(number, decimals = 0, decimalPoint = '.', thousandsSeparato while (re.test(s[0])) { s[0] = s[0].replace(re, `$1${sep}$2`) } - + if ((s[1] || '').length < prec) { s[1] = s[1] || '' s[1] += new Array(prec - s[1].length + 1).join('0') @@ -531,7 +546,7 @@ function priceFormat(number, decimals = 0, decimalPoint = '.', thousandsSeparato * 比如以30位阈值,那么300大于30,可以理解为用户想要的是300ms,而不是想花300s去执行一个动画 * @param {String|number} value 比如: "1s"|"100ms"|1|100 * @param {boolean} unit 提示: 如果是false 默认返回number - * @return {string|number} + * @return {string|number} */ function getDuration(value, unit = true) { const valueNum = parseInt(value) @@ -650,6 +665,16 @@ function pages() { return pages } +/** + * 获取页面历史栈指定层实例 + * @param back {number} [0] - 0或者负数,表示获取历史栈的哪一层,0表示获取当前页面实例,-1 表示获取上一个页面实例。默认0。 + */ +function getHistoryPage(back = 0) { + const pages = getCurrentPages() + const len = pages.length + return pages[len - 1 + back] +} + /** * @description 修改uView内置属性值 * @param {object} props 修改内置props属性 @@ -701,5 +726,6 @@ export default { setProperty, page, pages, + getHistoryPage, setConfig } diff --git a/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/package.json b/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/package.json index b5395638..e1169e51 100644 --- a/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/package.json +++ b/CoreCms.Net.Uni-App/CoreShop/uni_modules/uview-ui/package.json @@ -2,7 +2,7 @@ "id": "uview-ui", "name": "uview-ui", "displayName": "uView2.0重磅发布,利剑出鞘,一统江湖", - "version": "2.0.35", + "version": "2.0.36", "description": "uView UI已完美兼容nvue,全面的组件和便捷的工具会让您信手拈来,如鱼得水", "keywords": [ "uview", @@ -17,12 +17,8 @@ "engines": { "HBuilderX": "^3.1.0" }, - "dcloudext": { - "category": [ - "前端组件", - "通用组件" - ], - "sale": { + "dcloudext": { + "sale": { "regular": { "price": "0.00" }, @@ -38,7 +34,8 @@ "data": "无", "permissions": "无" }, - "npmurl": "https://www.npmjs.com/package/uview-ui" + "npmurl": "https://www.npmjs.com/package/uview-ui", + "type": "component-vue" }, "uni_modules": { "dependencies": [],