"use strict"; const common_vendor = require("../../../../common/vendor.js"); const uni_modules_uviewPlus_libs_function_test = require("./test.js"); const uni_modules_uviewPlus_libs_function_digit = require("./digit.js"); const uni_modules_uviewPlus_libs_config_config = require("../config/config.js"); function getPx(value, unit = false) { if (uni_modules_uviewPlus_libs_function_test.number(value)) { return unit ? `${value}px` : Number(value); } if (/(rpx|upx)$/.test(value)) { return unit ? `${common_vendor.index.rpx2px(parseInt(value))}px` : Number(common_vendor.index.rpx2px(parseInt(value))); } return unit ? `${parseInt(value)}px` : parseInt(value); } function sleep(value = 30) { return new Promise((resolve) => { setTimeout(() => { resolve(); }, value); }); } function os() { const windowInfo = common_vendor.index.getWindowInfo() || {}; const platform = windowInfo.platform || ""; return String(platform).toLowerCase(); } function sys() { return common_vendor.index.getWindowInfo(); } function random(min, max) { if (min >= 0 && max > 0 && max >= min) { const gab = max - min + 1; return Math.floor(Math.random() * gab + min); } return 0; } function guid(len = 32, firstU = true, radix = null) { const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""); const uuid = []; radix = radix || chars.length; if (len) { for (let i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix]; } else { let r; uuid[8] = uuid[13] = uuid[18] = uuid[23] = "-"; uuid[14] = "4"; for (let i = 0; i < 36; i++) { if (!uuid[i]) { r = 0 | Math.random() * 16; uuid[i] = chars[i == 19 ? r & 3 | 8 : r]; } } } if (firstU) { uuid.shift(); return `u${uuid.join("")}`; } return uuid.join(""); } function $parent(name = void 0) { let parent = this.$parent; while (parent) { if (parent.$options && parent.$options.name !== name) { parent = parent.$parent; } else { return parent; } } return false; } function addStyle(customStyle, target = "object") { if (uni_modules_uviewPlus_libs_function_test.empty(customStyle) || typeof customStyle === "object" && target === "object" || target === "string" && typeof customStyle === "string") { return customStyle; } if (target === "object") { customStyle = trim(customStyle); const styleArray = customStyle.split(";"); const style = {}; for (let i = 0; i < styleArray.length; i++) { if (styleArray[i]) { const item = styleArray[i].split(":"); style[trim(item[0])] = trim(item[1]); } } return style; } let string = ""; if (typeof customStyle === "object") { customStyle.forEach((val, i) => { const key = i.replace(/([A-Z])/g, "-$1").toLowerCase(); string += `${key}:${val};`; }); } return trim(string); } function addUnit(value = "auto", unit = "") { if (!unit) { unit = uni_modules_uviewPlus_libs_config_config.config.unit; } value = String(value); return uni_modules_uviewPlus_libs_function_test.number(value) ? `${value}${unit}` : value; } function deepClone(obj) { if ([null, void 0, NaN, false].includes(obj)) return obj; if (typeof obj !== "object" && typeof obj !== "function") { return obj; } const o = uni_modules_uviewPlus_libs_function_test.array(obj) ? [] : {}; for (const i in obj) { if (obj.hasOwnProperty(i)) { o[i] = typeof obj[i] === "object" ? deepClone(obj[i]) : obj[i]; } } return o; } function deepMerge(targetOrigin = {}, source = {}) { let target = deepClone(targetOrigin); if (typeof target !== "object" || typeof source !== "object") return false; for (const prop in source) { if (!source.hasOwnProperty(prop)) continue; if (prop in target) { if (source[prop] == null) { target[prop] = source[prop]; } else 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]); } } else { target[prop] = source[prop]; } } return target; } function error(err) { { console.error(`uView提示:${err}`); } } if (!String.prototype.padStart) { String.prototype.padStart = function(maxLength, fillString = " ") { if (Object.prototype.toString.call(fillString) !== "[object String]") { throw new TypeError( "fillString must be String" ); } const str = this; if (str.length >= maxLength) return String(str); const fillLength = maxLength - str.length; let times = Math.ceil(fillLength / fillString.length); while (times >>= 1) { fillString += fillString; if (times === 1) { fillString += fillString; } } return fillString.slice(0, fillLength) + str; }; } function timeFormat(dateTime = null, formatStr = "yyyy-mm-dd") { let date; if (!dateTime) { date = /* @__PURE__ */ new Date(); } else if (/^\d{10}$/.test(dateTime.toString().trim())) { date = new Date(dateTime * 1e3); } else if (typeof dateTime === "string" && /^\d+$/.test(dateTime.trim())) { date = new Date(Number(dateTime)); } else { date = new Date( typeof dateTime === "string" ? dateTime.replace(/-/g, "/") : dateTime ); } const timeSource = { "y": date.getFullYear().toString(), // 年 "m": (date.getMonth() + 1).toString().padStart(2, "0"), // 月 "d": date.getDate().toString().padStart(2, "0"), // 日 "h": date.getHours().toString().padStart(2, "0"), // 时 "M": date.getMinutes().toString().padStart(2, "0"), // 分 "s": date.getSeconds().toString().padStart(2, "0") // 秒 // 有其他格式化字符需求可以继续添加,必须转化成字符串 }; for (const key in timeSource) { const [ret] = new RegExp(`${key}+`).exec(formatStr) || []; if (ret) { const beginIndex = key === "y" && ret.length === 2 ? 2 : 0; formatStr = formatStr.replace(ret, timeSource[key].slice(beginIndex)); } } return formatStr; } function trim(str, pos = "both") { str = String(str); if (pos == "both") { return str.replace(/^\s+|\s+$/g, ""); } if (pos == "left") { return str.replace(/^\s*/, ""); } if (pos == "right") { return str.replace(/(\s*$)/g, ""); } if (pos == "all") { return str.replace(/\s+/g, ""); } return str; } function queryParams(data = {}, isPrefix = true, arrayFormat = "brackets") { const prefix = isPrefix ? "?" : ""; const _result = []; if (["indices", "brackets", "repeat", "comma"].indexOf(arrayFormat) == -1) arrayFormat = "brackets"; for (const key in data) { const value = data[key]; if (["", void 0, null].indexOf(value) >= 0) { continue; } if (value.constructor === Array) { switch (arrayFormat) { case "indices": for (let i = 0; i < value.length; i++) { _result.push(`${key}[${i}]=${value[i]}`); } break; case "brackets": value.forEach((_value) => { _result.push(`${key}[]=${_value}`); }); break; case "repeat": value.forEach((_value) => { _result.push(`${key}=${_value}`); }); break; case "comma": let commaStr = ""; value.forEach((_value) => { commaStr += (commaStr ? "," : "") + _value; }); _result.push(`${key}=${commaStr}`); break; default: value.forEach((_value) => { _result.push(`${key}[]=${_value}`); }); } } else { _result.push(`${key}=${value}`); } } return _result.length ? prefix + _result.join("&") : ""; } function toast(title, duration = 2e3) { common_vendor.index.showToast({ title: String(title), icon: "none", duration }); } function priceFormat(number, decimals = 0, decimalPoint = ".", thousandsSeparator = ",") { number = `${number}`.replace(/[^0-9+-Ee.]/g, ""); const n = !isFinite(+number) ? 0 : +number; const prec = !isFinite(+decimals) ? 0 : Math.abs(decimals); const sep = typeof thousandsSeparator === "undefined" ? "," : thousandsSeparator; const dec = typeof decimalPoint === "undefined" ? "." : decimalPoint; let s = ""; s = (prec ? uni_modules_uviewPlus_libs_function_digit.round(n, prec) + "" : `${Math.round(n)}`).split("."); const re = /(-?\d+)(\d{3})/; 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"); } return s.join(dec); } function formValidate(instance, event) { const formItem = $parent.call(instance, "u-form-item"); const form = $parent.call(instance, "u-form"); if (formItem && form) { form.validateField(formItem.prop, () => { }, event); } } function page() { const pages2 = getCurrentPages(); return `/${pages2[pages2.length - 1].route || ""}`; } exports.$parent = $parent; exports.addStyle = addStyle; exports.addUnit = addUnit; exports.deepMerge = deepMerge; exports.error = error; exports.formValidate = formValidate; exports.getPx = getPx; exports.guid = guid; exports.os = os; exports.page = page; exports.priceFormat = priceFormat; exports.queryParams = queryParams; exports.random = random; exports.sleep = sleep; exports.sys = sys; exports.timeFormat = timeFormat; exports.toast = toast;