Files
t-admin/unpackage/dist/build/web/assets/util.BgZN-4QF.js
T
2025-06-13 21:16:12 +08:00

2 lines
5.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{ad as e,e as t}from"./index-CS85kPhe.js";function n(e){let{fieldsMap:t,data:n,formatter:r=!0}=e,i=JSON.parse(JSON.stringify(n));return i.map((e=>{for(let i in e){let o=t.find((e=>e.field==i));if("object"==typeof o){let{fix:t=0}=o;"number"==typeof o.multiple&&"number"==typeof e[i]&&(e[i]=Number((e[i]*o.multiple).toFixed(t))),r&&o.formatter&&"number"==typeof e[i]&&(","===o.formatter?e[i]=(n=e[i],String(n).replace(/\B(?=(\d{3})+(?!\d))/g,",")):"%"===o.formatter?e[i]=`${(100*e[i]).toFixed(t)}%`:"-"===o.formatter&&(e[i]=p(e[i])))}}var n})),i}function r(e,t,n){let{start_time:r,dimension:i}=t;if(["hour","day"].indexOf(i)>-1){let t,o=[];"hour"===i?t=36e5:"day"===i&&(t=864e5);let a=r[0],s=r[1],u=a;for(o=[a];u+t<=s;)u+=t,o.push(u);let f=[];for(let r=0;r<o.length;r++){let t=o[r],i=e.find(((e,n)=>e.start_time===t));if(i)f.push(i);else{let e={start_time:t};n.map(((t,n)=>{e[t.field]=0})),f.push(e)}}return f}return e}function i(t,n=!1,r=[]){const i=[],o=Object.keys(t),a=t.start_time;o.forEach((o=>{if("time_range"===o||-1!==r.indexOf(o))return;let s=t[o];if(s)if("string"==typeof s&&s.indexOf(o)>-1)i.push(s);else if("string"==typeof s&&(s=`"${s}"`),Array.isArray(s))2===s.length&&o.indexOf("time")>-1?i.push(`${o} >= ${s[0]} && ${o} <= ${s[1]}`):(s=s.map((e=>`${o} == "${e}"`)).join(" || "),s&&i.push(`(${s})`));else if(n&&"dimension"===o)if(m(a))i.push('dimension == "hour"');else{let t=e(),n=t[t.length-1];["pages/uni-stat/device/trend/trend","pages/uni-stat/user/trend/trend"].indexOf(n.route)>-1||s&&'"hour"'!==s?i.push(`${o} == ${s}`):i.push('dimension == "day"')}else i.push(`${o} == ${s}`)}));return i.join(" && ")||{}}function o(e,t={},n,r="",i="value"){const o=[],a=n;e=JSON.parse(JSON.stringify(e));const s=JSON.parse(JSON.stringify(t));for(const l of e){let{field:e,computed:p,formatter:c,disable:d,fix:m}=l;if(!d){const d=(n=a||l).hasOwnProperty(i),h=r+e;if(t){const o=t[h];if(p){const t=p.split("/");let[o,a]=t;o=Number(s[r+o]),a=Number(s[r+a]);const l=f(u(o,a),c,m);d&&e===n.field?n[i]=l:n[e]=l}else if(o){const t=f(o,c,m);d?n.field===e&&(n[i]=t):n[e]=t}}d&&o.push(n)}}return o}function a(e,t,n){t&&(e=e.filter((e=>e.field===t))),n&&(e=e.filter((e=>e.field&&e.hasOwnProperty(n))));return e.map((e=>{let t=[];return e.computed?t=e.computed.split("/"):t.push(e.field),t=t.map((t=>-1===e.stat?t:`${t} as ${"temp_"+t}`)),t.join()})).join()}function s(e,t,n){t&&(e=e.filter((e=>e.field===t))),n&&(e=e.filter((e=>e.field&&e.hasOwnProperty(n))));return e.map((e=>{const t=e.stat;let n=[];return e.computed?n=e.computed.split("/"):n.push(e.field),n=n.map((e=>{if(-1!==t)return`${t||"sum"}(${"temp_"+e}) as ${e}`})),n.filter(Boolean).join()})).filter(Boolean).join()}function u(e,t){return t?e/t:0}function f(e,t=",",n){if("number"!=typeof e)return e;if("%"===t)return e*=100,String(e).indexOf(".")>-1&&(e=e.toFixed(2)),e=e?e+t:e;if("%%"===t)return(e=Number(e)).toFixed(2)+"%";if("-"===t)return l(e,"day");if(":"===t){let n,r,i;e=Math.ceil(e),n=r=i=0;const o=3600,a=60;if(e>=o){n=Math.floor(e/o);const t=e%o;t>=a?(r=Math.floor(t/a),i=t%a):i=t}else o>=e&&e>=a?(r=Math.floor(e/a),i=e%a):i=e;return[n,r,i].map((e=>e<10?"0"+e:e)).join(t)}return","===t?e.toLocaleString():(String(e).indexOf(".")>-1&&(e=Math.abs(e)>1?e.toFixed(n||0):e.toFixed(n||2)),e)}function l(e,t){let n=new Date(e);if("hour"===t){let e=n.getHours();e=e<10?"0"+e:e;let t=`${e}:00 ~ ${e}:59`;if("00"===e){t=p(n)+"(00:00 ~ 00:59)"}return t}if("week"===t){const e=n.getDate()-n.getDay()+1,t=e+6;let r=new Date(n.setDate(e));r=p(r);let i=new Date(n.setDate(t));return i=p(i),`${r} ~ ${i}`}if("month"===t){let e=new Date(n.getFullYear(),n.getMonth(),1);e=p(e);let t=new Date(n.getFullYear(),n.getMonth()+1,0);return t=p(t),`${e} ~ ${t}`}return p(n)}function p(e,t,n="-"){let r=e;"object"!=typeof r&&(r=new Date(r));const i=r.getFullYear(),o=r.getMonth()+1,a=r.getDate(),s=r.getHours(),u=r.getMinutes(),f=r.getSeconds(),l=[i,c(o),c(a)].join(n),p=[c(s),c(u),c(f)].join(":");return"dateTime"===t?l+" "+p:l}function c(e){return e<10?"0"+e:e}function d(e=0,t=Date.now()){const n=new Date(t);let r=[n.getFullYear(),n.getMonth()+1,n.getDate()].join("/");r+=" 00:00:00";return new Date(r).getTime()-864e5*e}function m(e,t=2){if(!e.length)return!0;const[n,r]=e;return r-n<864e5*t}function h(e=this.query,n="total_devices"){let r;"object"==typeof e&&(e=i(e,!1,["uni_platform"]));return t.database().collection("uni-stat-result").where(e).field(`${n} as temp_${n}, start_time`).groupBy("start_time").groupField(`sum(temp_${n}) as ${n}`).orderBy("start_time","desc").get().then((e=>{const t=e.result.data;return r=t.length&&t[0][n],r=f(r),this.panelData&&this.panelData.forEach((e=>{e.field===n&&(e.value=r)})),Promise.resolve(r)}))}function g(e,t=100){let n=null;return function(...r){n&&clearTimeout(n),n=setTimeout((()=>{e.apply(this,r)}),t)}}const y={};function $(e){for(const n in y)if(y.hasOwnProperty(n)){if(y[n]===e)return n}let t=(window.URL||window.webkitURL).createObjectURL(e);return y[t]=e,t}function w(e,t){let n=[],r=0;for(;t.getTime()-e.getTime()>=0;)n[r]=e.getTime(),e.setDate(e.getDate()+1),r+=1;return n}function O(e){return Object.assign({},e,{type:"native_app",create_env:"uni-stat"})}export{a,s as b,h as c,g as d,m as e,f,d as g,l as h,O as i,w as j,$ as k,n as l,o as m,r as n,p,i as s};