UNPKG

@pit-front-end/utils

Version:

湖南创智艾泰克科技有限公司

2 lines (1 loc) 5.6 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./global.js"),g=require("lodash"),p=require("dayjs");let f={state:{}};const u=()=>{var e,t;return(t=(e=f.state)==null?void 0:e.value)==null?void 0:t.user},h=e=>{f=e},d={hasCode:{btn_add:"btn_add",btn_edit:"btn_edit",btn_detail:"btn_detail",btn_remove:"btn_remove",btn_batchRemove:"btn_batchRemove",btn_copy:"btn_copy",btn_upload:"btn_upload",btn_download:"btn_download",btn_more:"btn_more",btn_grading:"btn_grading",btn_password:"btn_password",btn_menu:"btn_menu",btn_relation:"btn_relation",btn_batchXZ:"btn_batchXZ",btn_class:"btn_class",btn_reduction:"btn_reduction",btn_del:"btn_del",btn_autoSC:"btn_autoSC",btn_batchFB:"btn_batchFB",btn_sum:"btn_sum",btn_unlock:"btn_unlock",btn_estimate:"btn_estimate"},hasP(e){var a;const t=u().permissionList,n=((a=c.getGetRouter())==null?void 0:a.currentRoute.value).meta.modelId||"";if(!n)return!1;const r=t.filter(l=>l.modelId===n);if(!r.length)return!1;const o=r[0]&&r[0].column?r[0].column:[];return o.length?!!o.some(l=>l.enCode===e):!1},hasFormP(e){var a;const t=u().permissionList,n=((a=c.getGetRouter())==null?void 0:a.currentRoute.value).meta.modelId||"";if(!n)return!1;const r=t.filter(l=>l.modelId===n);if(!r.length)return!1;const o=r[0]&&r[0].form?r[0].form:[];return o.length?!!o.some(l=>l.enCode===e):!1},hasBtnP(e){var a;const t=u().permissionList,n=((a=c.getGetRouter())==null?void 0:a.currentRoute.value).meta.modelId||"";if(!n)return!1;const r=t.filter(l=>l.modelId===n);if(!r.length)return!1;const o=r[0]&&r[0].button?r[0].button:[];return o.length?!!o.some(l=>l.enCode===e):!1},hasFlow(e,t,s,n="writeable"){let r=!1;const o=e.approvalStatus==="draft"||e.approvalStatus==="reject"||e.approvalStatus==="withdraw"||e.approvalStatus==="termination"||e.approvalStatus===null||e.approvalStatus==="";return t?e[n]!==void 0?o&&e[n]?r=!0:r=!1:r=o:r=!0,r},toDate(e,t){if(t=t||"yyyy-MM-dd HH:mm",!e)return"";let s=e;typeof e=="string"?e.indexOf("/Date(")>-1?s=new Date(parseInt(e.replace("/Date(","").replace(")/",""),10)):s=new Date(Date.parse(e.replace(/-/g,"/").replace("T"," ").split(".")[0])):s=new Date(e);const n={"M+":s.getMonth()+1,"d+":s.getDate(),"h+":s.getHours(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(const r in n)new RegExp("("+r+")").test(t)&&(t=t.replace(RegExp.$1,RegExp.$1.length===1?n[r]:("00"+n[r]).substr((""+n[r]).length)));return t},parseTime(e,t){if(arguments.length===0||!e)return null;const s=t||"{y}-{m}-{d} {h}:{i}:{s}";let n;typeof e=="object"?n=e:(typeof e=="string"&&/^[0-9]+$/.test(e)?e=parseInt(e):typeof e=="string"&&(e=e.replace(new RegExp(/-/gm),"/").replace("T"," ").replace(new RegExp(/\.[\d]{3}/gm),"")),typeof e=="number"&&e.toString().length===10&&(e=e*1e3),n=new Date(e));const r={y:n.getFullYear(),m:n.getMonth()+1,d:n.getDate(),h:n.getHours(),i:n.getMinutes(),s:n.getSeconds(),a:n.getDay()};return s.replace(/{(y|m|d|h|i|s|a)+}/g,(i,a)=>{let l=r[a];return a==="a"?["日","一","二","三","四","五","六"][l]:(i.length>0&&l<10&&(l="0"+l),l||0)})},getNormalPath(e){if(e.length===0||!e||e=="undefined")return e;const t=e.replace("//","/");return t[t.length-1]==="/"?t.slice(0,t.length-1):t},dateFormat(e,t){return t=t||"YYYY-MM-DD HH:mm",e?p(e).format(t):""},formatFloat(e,t,s,n,r){let o=""+e;return o=o.replace(/[^\d.-]/g,"").replace(/^\./g,"").replace(/\.{2,}/g,".").replace(".","$#$").replace(/\./g,"").replace("$#$","."),r&&(o=o.slice(0,1)+o.slice(1).replace(/-/g,"")),t===2?o=o.replace(/^(\-)*(\d+)\.(\d\d).*$/,"$1$2.$3"):t===3?o=o.replace(/^(\-)*(\d+)\.(\d\d\d).*$/,"$1$2.$3"):t===4?o=o.replace(/^(\-)*(\d+)\.(\d\d\d\d).*$/,"$1$2.$3"):o=o.replace(/[^\d]/g,""),o.indexOf(".")<0,!isNaN(parseFloat(o))&&o>s&&(o=s),!isNaN(parseFloat(o))&&o<n&&(o=n),o},treeToArray(e,t=[]){return g.cloneDeep(e).forEach(n=>{const{children:r}=n;if(r&&r.length)return t.push(n),d.treeToArray(r,t);t.push(n)}),t.forEach(n=>{n.children=null,n.hasChildren=!1}),t},arrayToTree(e){const t={},s=[];e.forEach(r=>{t[r.id]={...r,children:[]}}),e.forEach(r=>{const o=r.parentId,i=t[r.id];if(o==="0")s.push(i);else{const a=t[o];a&&a.children.push(i)}});function n(r){r.forEach(o=>{o.children&&o.children.length===0?delete o.children:o.children&&n(o.children)})}return n(s),s},handleDateStr(e){return new Date(e).toLocaleString().replaceAll("/","-")},amountThousandsConversion(e){return e&&((e+"").includes(".")?(e+"").replace(/\d{1,3}(?=(\d{3})+(\.))/g,t=>t+","):(e+"").replace(/\d{1,3}(?=(\d{3})+$)/g,t=>t+","))},adminAuthority(){return localStorage.getItem("administrator")==="true"},isProjectManager(){return localStorage.getItem("isPermission")==="true"},iterationArr(e,t,s="children"){e==null||e.map(n=>{t(n),d.iterationArr(n[s],t)})},goToRouteWithThePlatform(e,t,s,n=1e3){e[0]==="/"&&(e=e.slice(1)),setTimeout(()=>{typeof s=="function"&&s(e);const r=/#/.test(location.href);window.open(r?location.href.replace(/#.*/,`#/${e}`):"/"+e,t)},n)},getBlobFileName(e){let t=decodeURIComponent(e.headers["content-disposition"])||"";return t?(t=t==null?void 0:t.split("=")[1],t):""},deepClone(e){if(!e&&typeof e!="object")throw new Error("error arguments");const t=e.constructor===Array?[]:{};return Object.keys(e).forEach(s=>{e[s]&&typeof e[s]=="object"?t[s]=this.deepClone(e[s]):t[s]=e[s]}),t},checkImgIsVaild(e){return new Promise(function(t,s){const n=new Image;n.src=e,n.onload=function(r){t(r)},n.onerror=function(r){s(r)}})}};exports.initUserStore=h;exports.pit=d;