index.js 3.4 KB

1
  1. "use strict";const p=require("../../../../common/vendor.js"),a=require("./test.js"),h=require("../config/config.js");function $(e,t=!1){return a.number(e)?t?`${e}px`:Number(e):/(rpx|upx)$/.test(e)?t?`${p.index.rpx2px(parseInt(e))}px`:Number(p.index.rpx2px(parseInt(e))):t?`${parseInt(e)}px`:parseInt(e)}function m(e=30){return new Promise(t=>{setTimeout(()=>{t()},e)})}function b(){const t=(p.index.getWindowInfo()||{}).platform||"";return String(t).toLowerCase()}function y(){return p.index.getWindowInfo()}function w(e=32,t=!0,r=null){const n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),i=[];if(r=r||n.length,e)for(let o=0;o<e;o++)i[o]=n[0|Math.random()*r];else{let o;i[8]=i[13]=i[18]=i[23]="-",i[14]="4";for(let f=0;f<36;f++)i[f]||(o=0|Math.random()*16,i[f]=n[f==19?o&3|8:o])}return t?(i.shift(),`u${i.join("")}`):i.join("")}function l(e=void 0){let t=this.$parent;for(;t;)if(t.$options&&t.$options.name!==e)t=t.$parent;else return t;return!1}function x(e,t="object"){if(a.empty(e)||typeof e=="object"&&t==="object"||t==="string"&&typeof e=="string")return e;if(t==="object"){e=c(e);const n=e.split(";"),i={};for(let o=0;o<n.length;o++)if(n[o]){const f=n[o].split(":");i[c(f[0])]=c(f[1])}return i}let r="";return typeof e=="object"&&e.forEach((n,i)=>{const o=i.replace(/([A-Z])/g,"-$1").toLowerCase();r+=`${o}:${n};`}),c(r)}function _(e="auto",t=""){return t||(t=h.config.unit),e=String(e),a.number(e)?`${e}${t}`:e}function d(e){if([null,void 0,NaN,!1].includes(e)||typeof e!="object"&&typeof e!="function")return e;const t=a.array(e)?[]:{};for(const r in e)e.hasOwnProperty(r)&&(t[r]=typeof e[r]=="object"?d(e[r]):e[r]);return t}function g(e={},t={}){let r=d(e);if(typeof r!="object"||typeof t!="object")return!1;for(const n in t)t.hasOwnProperty(n)&&(n in r?t[n]==null||typeof r[n]!="object"||typeof t[n]!="object"?r[n]=t[n]:r[n].concat&&t[n].concat?r[n]=r[n].concat(t[n]):r[n]=g(r[n],t[n]):r[n]=t[n]);return r}String.prototype.padStart||(String.prototype.padStart=function(e,t=" "){if(Object.prototype.toString.call(t)!=="[object String]")throw new TypeError("fillString must be String");const r=this;if(r.length>=e)return String(r);const n=e-r.length;let i=Math.ceil(n/t.length);for(;i>>=1;)t+=t,i===1&&(t+=t);return t.slice(0,n)+r});function c(e,t="both"){return e=String(e),t=="both"?e.replace(/^\s+|\s+$/g,""):t=="left"?e.replace(/^\s*/,""):t=="right"?e.replace(/(\s*$)/g,""):t=="all"?e.replace(/\s+/g,""):e}function k(e={},t=!0,r="brackets"){const n=t?"?":"",i=[];["indices","brackets","repeat","comma"].indexOf(r)==-1&&(r="brackets");for(const o in e){const f=e[o];if(!(["",void 0,null].indexOf(f)>=0))if(f.constructor===Array)switch(r){case"indices":for(let s=0;s<f.length;s++)i.push(`${o}[${s}]=${f[s]}`);break;case"brackets":f.forEach(s=>{i.push(`${o}[]=${s}`)});break;case"repeat":f.forEach(s=>{i.push(`${o}=${s}`)});break;case"comma":let u="";f.forEach(s=>{u+=(u?",":"")+s}),i.push(`${o}=${u}`);break;default:f.forEach(s=>{i.push(`${o}[]=${s}`)})}else i.push(`${o}=${f}`)}return i.length?n+i.join("&"):""}function P(e,t){const r=l.call(e,"u-form-item"),n=l.call(e,"u-form");r&&n&&n.validateField(r.prop,()=>{},t)}function I(){const e=getCurrentPages();return`/${e[e.length-1].route||""}`}exports.$parent=l;exports.addStyle=x;exports.addUnit=_;exports.deepMerge=g;exports.formValidate=P;exports.getPx=$;exports.guid=w;exports.os=b;exports.page=I;exports.queryParams=k;exports.sleep=m;exports.sys=y;