"use strict";
|
|
const common_vendor = require("../common/vendor.js");
|
|
function toArray(data) {
|
|
if (!data)
|
|
return [];
|
|
if (data instanceof Array) {
|
|
return data;
|
|
} else {
|
|
return [data];
|
|
}
|
|
}
|
|
function generateUUID() {
|
|
return "xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
var r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
|
return v.toString(16);
|
|
});
|
|
}
|
|
function generateRandomColor() {
|
|
const letters = "0123456789ABCDEF";
|
|
let color = "#";
|
|
for (let i = 0; i < 6; i++) {
|
|
color += letters[Math.floor(Math.random() * 16)];
|
|
}
|
|
return color;
|
|
}
|
|
function generateLightRandomColor() {
|
|
const min = 150;
|
|
const range = 105;
|
|
const r = Math.floor(Math.random() * range + min);
|
|
const g = Math.floor(Math.random() * range + min);
|
|
const b = Math.floor(Math.random() * range + min);
|
|
const color = "rgb(" + r + "," + g + "," + b + ")";
|
|
return color;
|
|
}
|
|
function verificationAll(data, msg) {
|
|
if (!msg) {
|
|
common_vendor.index.__f__("log", "at utils/utils.js:63", msg);
|
|
return false;
|
|
}
|
|
if (!data) {
|
|
common_vendor.index.showToast({
|
|
title: "表单数据未填写",
|
|
icon: "none"
|
|
});
|
|
}
|
|
for (let key in msg) {
|
|
if (!data[key]) {
|
|
common_vendor.index.showToast({
|
|
title: msg[key],
|
|
icon: "none"
|
|
});
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
function verificationPhone(phone) {
|
|
if (!/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(phone)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
function getHrefParams(name) {
|
|
var url = window.location.href;
|
|
try {
|
|
var cs = url.split("?")[1];
|
|
var cs_arr = cs.split("&");
|
|
for (var i = 0; i < cs_arr.length; i++) {
|
|
if (cs_arr[i].split("=")[0] == name) {
|
|
return cs_arr[i].split("=")[1];
|
|
}
|
|
}
|
|
return "";
|
|
} catch {
|
|
return "";
|
|
}
|
|
}
|
|
function deepMergeObject(a, b) {
|
|
let data = JSON.parse(JSON.stringify(a));
|
|
function mergeObject(obj1, obj2) {
|
|
for (let key in obj2) {
|
|
if (typeof obj1[key] == "object") {
|
|
obj1[key] = mergeObject(obj1[key], obj2[key]);
|
|
} else {
|
|
obj1[key] = obj2[key];
|
|
}
|
|
}
|
|
return obj1;
|
|
}
|
|
return mergeObject(data, b);
|
|
}
|
|
function copyText(content) {
|
|
common_vendor.index.setClipboardData({
|
|
data: content,
|
|
success: () => {
|
|
common_vendor.index.showToast({
|
|
title: "复制成功",
|
|
icon: "none"
|
|
});
|
|
}
|
|
});
|
|
}
|
|
function stringFormatHtml(str) {
|
|
return str && str.replace(/\n/gi, "<br>").replace(/ /gi, " ");
|
|
}
|
|
function params(url) {
|
|
if (typeof url == "object") {
|
|
return url;
|
|
}
|
|
let data = {
|
|
url
|
|
};
|
|
if (!data.url.includes("/pages")) {
|
|
data.url = "/pages" + data.url;
|
|
}
|
|
return data;
|
|
}
|
|
function navigateTo(...args) {
|
|
common_vendor.index.navigateTo(params(...args));
|
|
}
|
|
function navigateBack(num = -1) {
|
|
common_vendor.index.navigateBack(num);
|
|
}
|
|
function redirectTo(...args) {
|
|
common_vendor.index.redirectTo(params(...args));
|
|
}
|
|
const toLogin = /* @__PURE__ */ function() {
|
|
let time = 0;
|
|
return () => {
|
|
if ((/* @__PURE__ */ new Date()).getTime() - time < 1e3) {
|
|
return;
|
|
}
|
|
time = (/* @__PURE__ */ new Date()).getTime();
|
|
common_vendor.index.navigateTo({
|
|
url: "/pages/index/index"
|
|
});
|
|
};
|
|
}();
|
|
const util = {
|
|
toArray,
|
|
generateUUID,
|
|
verificationAll,
|
|
generateRandomColor,
|
|
generateLightRandomColor,
|
|
verificationPhone,
|
|
getHrefParams,
|
|
deepMergeObject,
|
|
navigateTo,
|
|
navigateBack,
|
|
redirectTo,
|
|
copyText,
|
|
stringFormatHtml,
|
|
toLogin
|
|
};
|
|
exports.util = util;
|
|
//# sourceMappingURL=../../.sourcemap/mp-weixin/utils/utils.js.map
|