| | |
| | | } |
| | | }; |
| | | } |
| | | |
| | | deepClone(target, map = new WeakMap()) { |
| | | // 处理原始值和函数(typeof 数组会返回object) |
| | | if (typeof target !== 'object' || target === null) { |
| | | return target; |
| | | } |
| | | |
| | | // 处理循环引用 |
| | | if (map.has(target)) { |
| | | return map.get(target); |
| | | } |
| | | |
| | | let clone; |
| | | |
| | | // 处理数组 |
| | | if (Array.isArray(target)) { |
| | | clone = []; |
| | | map.set(target, clone); |
| | | target.forEach((item, index) => { |
| | | clone[index] = deepClone(item, map); |
| | | }); |
| | | return clone; |
| | | } |
| | | |
| | | // 处理日期对象 |
| | | if (target instanceof Date) { |
| | | clone = new Date(target.getTime()); |
| | | map.set(target, clone); |
| | | return clone; |
| | | } |
| | | |
| | | // 处理正则表达式 |
| | | if (target instanceof RegExp) { |
| | | clone = new RegExp(target); |
| | | map.set(target, clone); |
| | | return clone; |
| | | } |
| | | |
| | | // 处理函数 (直接使用函数的引用) |
| | | if (typeof target === 'function') { |
| | | return target; |
| | | } |
| | | |
| | | // 处理其他对象(普通对象、类实例等) |
| | | clone = Object.create(Object.getPrototypeOf(target)); |
| | | map.set(target, clone); |
| | | |
| | | // 获取所有属性(包括 Symbol 类型) |
| | | const allKeys = [...Object.getOwnPropertyNames(target), ...Object.getOwnPropertySymbols(target)]; |
| | | |
| | | allKeys.forEach(key => { |
| | | const descriptor = Object.getOwnPropertyDescriptor(target, key); |
| | | if (descriptor && descriptor.enumerable) { |
| | | // 递归复制属性值 |
| | | clone[key] = deepClone(target[key], map); |
| | | } |
| | | }); |
| | | |
| | | return clone; |
| | | } |
| | | |
| | | // uni-app 使用 封装请求函数 使用传统函数当作回调需要传that,箭头函数不需要 |
| | | doRequest(url, data, resFunction, errFunction, method, that) { |
| | | that = that || this; |
| | |
| | | } |
| | | |
| | | // uni-app 播放音频封装 |
| | | playSound(e){ |
| | | playSound(e) { |
| | | const innerAudioContext = uni.createInnerAudioContext(); |
| | | if(e == 1){ |
| | | if (e == 1) { |
| | | innerAudioContext.src = '/static/success.wav'; |
| | | }else{ |
| | | } else { |
| | | innerAudioContext.src = '/static/jingbao.wav'; |
| | | } |
| | | innerAudioContext.play(); // 播放音频 |