123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- import modal from "./modal.plugins";
- export default {
-
- tansParams(params) {
- let result = "";
- for (const propName of Object.keys(params)) {
- const value = params[propName];
- var part = encodeURIComponent(propName) + "=";
- if (value !== null && value !== "" && typeof value !== "undefined") {
- if (typeof value === "object") {
- for (const key of Object.keys(value)) {
- if (value[key] !== null && value[key] !== "" && typeof value[key] !== "undefined") {
- let params = propName + "[" + key + "]";
- var subPart = encodeURIComponent(params) + "=";
- result += subPart + encodeURIComponent(value[key]) + "&";
- }
- }
- } else {
- result += part + encodeURIComponent(value) + "&";
- }
- }
- }
- return result;
- },
-
- mapping(reKey, isKey, value, data) {
- if (typeof value == "string" && value.indexOf(",") > -1) {
-
- let arr = value.split(",");
- let returnValue = "";
- arr.forEach((e, index) => {
- data.forEach((f) => {
- if (e == f[isKey]) {
- returnValue = returnValue ? `${returnValue},${f[reKey]}` : f[reKey];
- }
- })
- })
- return returnValue;
- } else {
- if (!data) return;
- for (let i = 0; i < data.length; i++) {
- if (value == data[i][isKey]) {
- return data[i][reKey];
- }
- }
- }
- },
-
- makePhoneCall(phone) {
- uni.makePhoneCall({
- phoneNumber: phone,
- success: function () {
- console.log('success');
- },
- fail: function () {
- }
- });
- },
-
- uniCopy({ content, success, error }) {
- if (!content) return error('复制的内容不能为空 !')
- content = typeof content === 'string' ? content : content.toString()
-
-
- uni.setClipboardData({
- data: content,
- success: function () {
- success("复制成功~")
- console.log('success');
- },
- fail: function () {
- success("复制失败~")
- }
- });
-
-
-
- if (!document.queryCommandSupported('copy')) {
-
- error('浏览器不支持')
- }
- let textarea = document.createElement("textarea")
- textarea.value = content
- textarea.readOnly = "readOnly"
- document.body.appendChild(textarea)
- textarea.select()
- textarea.setSelectionRange(0, content.length)
- let result = document.execCommand("copy")
- if (result) {
- success("复制成功~")
- } else {
- error("复制失败,请检查h5中调用该方法的方式,是不是用户点击的方式调用的,如果不是请改为用户点击的方式触发该方法,因为h5中安全性,不能js直接调用!")
- }
- textarea.remove()
-
- },
-
- groupedItems(data, timeKey) {
- if (data <= 0) {
- return false
- }
- const grouped = {};
- data.forEach((item) => {
- const date = item[timeKey].split("T")[0];
- grouped[date] = grouped[date] || [];
- grouped[date].push(item);
- });
- return grouped;
- },
-
- getUrlList() {
-
- var url = window.location.href;
- var theRequest = new Object();
- if (url.indexOf("?") != -1) {
- var str = url.split("?")[1];
- var strs = str.split("&");
- for (var i = 0; i < strs.length; i++) {
- theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
- }
- }
- return theRequest;
- },
-
- sortEvent(data, sort) {
- let arr = [];
-
- let sortKeys = Object.keys(JSON.parse(JSON.stringify(data))).sort((a, b) => {
- return sort == 0 ? JSON.parse(JSON.stringify(data))[a].sort - JSON.parse(JSON.stringify(data))[b].sort : JSON.parse(JSON.stringify(data))[b].sort - JSON.parse(JSON.stringify(data))[a].sort;
- });
-
- for (var sortIndex in sortKeys) {
- arr.push(JSON.parse(JSON.stringify(data))[sortKeys[sortIndex]]);
- }
- return arr;
- },
-
- uniq(data, objectName) {
- if (!objectName) {
- var newArr = [...new Set(data)]
- return newArr;
- } else {
- let obj = {};
- let peon = data.reduce((cur, next) => {
- obj[next[objectName]] ? "" : obj[next[objectName]] = true && cur.push(next);
- return cur;
- }, [])
- return peon;
- }
- },
-
- isNetwork() {
- let status = true
-
- uni.getNetworkType({
- success: function (res) {
- if (res.networkType === "none") {
- modal.msg("网络异常,请稍后重试!");
- status = false
- } else {
- status = true
- }
- },
- });
- return status
- },
-
- isExpirationTime() {
- let sotrTime = uni.getStorageSync("expirationTime");
- if (sotrTime) {
- if (sotrTime + 3600 * 24 * 2 <= Date.parse(new Date()) / 1000) {
- return true
- } else {
- return false
- }
- } else {
- return true
- }
- },
-
- isWechatMp() {
- var ua = navigator?.userAgent.toLowerCase();
- if (ua?.match(/MicroMessenger/i) == 'micromessenger') {
- return true;
- } else {
-
- return false;
- }
- },
-
- isVisible() {
- let visible = true;
-
- visible = !this.isWechatMp();
-
-
- visible = true;
-
- return visible;
- },
-
- imgEnlarge(type, data) {
- let param = {}
- if (type == 1) {
- param = {
- urls: [data],
- current: data
- }
- }
- if (type == 2) {
- let arr = []
- for (let i = 0; i < data.length; i++) {
- arr.push(data[i].url)
- }
- param = {
- urls: arr,
- current: arr[0]
- }
- }
- if (data && data.length > 0) {
- uni.previewImage(param)
- }
- }
- };
|