zy-react-library 1.2.34 → 1.2.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/utils/index.d.ts +8 -1
- package/utils/index.js +1 -1
package/package.json
CHANGED
package/utils/index.d.ts
CHANGED
|
@@ -350,12 +350,19 @@ export function validatorEndTime(options: { startTime: string; message?: string;
|
|
|
350
350
|
};
|
|
351
351
|
|
|
352
352
|
/**
|
|
353
|
-
*
|
|
353
|
+
* 验证时间是否大于当前时间
|
|
354
354
|
*/
|
|
355
355
|
export function validatorTimeGTCurrentDay(options?: { message?: string; type?: "date" | "datetime" }): {
|
|
356
356
|
validator: (_: any, value: any) => Promise<void | string>;
|
|
357
357
|
};
|
|
358
358
|
|
|
359
|
+
/**
|
|
360
|
+
* 验证时间是否大于等于当前时间
|
|
361
|
+
*/
|
|
362
|
+
export function validatorTimeGECurrentDay(options?: { message?: string; type?: "date" | "datetime" }): {
|
|
363
|
+
validator: (_: any, value: any) => Promise<void | string>;
|
|
364
|
+
};
|
|
365
|
+
|
|
359
366
|
/**
|
|
360
367
|
* 动态加载js资源
|
|
361
368
|
*/
|
package/utils/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{request}from"@cqsjjb/jjb-common-lib/http.js";import dayjs from"dayjs";import{ID_NUMBER}from"../regular/index.js";function serialNumber(e,t){return(e.current-1)*e.pageSize+(t+1)}function toArrayString(value){return value?eval(value).map(String):[]}function interceptTheSuffix(e,t){return e.substring(e.lastIndexOf("."),e.length).toLowerCase()===t.toLowerCase()}function image2Base64(e){return new Promise(t=>{const n=new Image;n.src=e,n.crossOrigin="Anonymous",n.onload=function(){const e=document.createElement("canvas");e.width=n.width,e.height=n.height,e.getContext("2d").drawImage(n,0,0,n.width,n.height);const r=n.src.substring(n.src.lastIndexOf(".")+1).toLowerCase();t(e.toDataURL(`image/${r}`))}})}function image2Base642(e){return new Promise((t,n)=>{const r=new FileReader;r.readAsDataURL(e),r.onload=e=>{t(e.target.result)},r.onerror=e=>{n(e)}})}function base642File(e,t="file"){const n=e.split(","),r=n[0].match(/:(.*?);/)[1],i=r.split("/")[1],a=atob(n[1]);let o=a.length;const s=new Uint8Array(o);for(;o--;)s[o]=a.charCodeAt(o);return new File([s],`${t}.${i}`,{type:r})}function checkImgExists(e){return new Promise((t,n)=>{const r=new Image;r.src=e,r.onload=function(e){t(e)},r.onerror=function(e){n(e)}})}function getDataType(e){return Object.prototype.toString.call(e).slice(8,-1)}function ArrayDeduplication(e){return[...new Set(e)]}function arrayObjectDeduplication(e,t){const n={};return e.reduce((e,r)=>(n[r[t]]||(n[r[t]]=!0,e.push(r)),e),[])}function findCharIndex(e){const{str:t,char:n,num:r}=e;let i=t.indexOf(n);if(-1===i)return-1;for(let e=0;e<r-1;e++)if(i=t.indexOf(n,i+1),-1===i)return-1;return i}function randoms(e,t){return Math.random()*(t-e+1)+e}function numFormat(e){if(e){const t=e.toString().split("."),n=t[0].split("").reverse();let r=[];for(let e=0;e<n.length;e++)e%3==0&&0!==e&&r.push(","),r.push(n[e]);return r.reverse(),r=t[1]?r.join("").concat(`.${t[1]}`):r.join(""),r}}function isEmpty(e){return null==e||"object"==typeof e&&0===Object.keys(e).length||"string"==typeof e&&0===e.trim().length}function getUrlParam(e){const t=new RegExp(`(^|&)${e}=([^&]*)(&|$)`),n=window.location.search.substr(1).match(t);return null!=n?decodeURI(n[2]):""}function paging(e){const{list:t,currentPage:n,pageSize:r}=e;return t.filter((e,t)=>t<+n*+r&&t>=(+n-1)*+r)}function getFileSuffix(e){return e.substring(e.lastIndexOf(".")+1)}function getFileName(e){return e?e.substring(e.lastIndexOf("/")+1):""}function readTxtDocument(e){return new Promise(t=>{const n=getFileUrl()+e,r=new XMLHttpRequest;r.open("get",n,!0),r.responseType="blob",r.onload=function(e){const n=new FileReader;n.readAsText(e.target.response,"GB2312"),n.onload=function(){t(n.result)}},r.send()})}function secondConversion(e){if(!e)return 0;const t=Number.parseInt((e/60/60).toString(),10),n=Number.parseInt((e/60%60).toString(),10),r=Number.parseInt((e%60).toString(),10);return t?`${t}小时${n}分钟${r}秒`:n?`${n}分钟${r}秒`:`${r}秒`}function addingPrefixToFile(e,t={}){if(!e)return[];const{pathKey:n="filePath",nameKey:r="fileName",idKey:i="id"}=t,a=getFileUrl();return e.filter(e=>e[n]).map(e=>({url:a+e[n],name:e[r]||getFileName(e[n]),id:e[i],...e}))}function getLabelName(e){const{status:t,list:n,idKey:r="bianma",nameKey:i="name"}=e;return(n.find(e=>e[r]?.toString()===t?.toString())||{[i]:""})[i]}function calculateFileSize(e){return e>1024?`${(""+e/1024).substring(0,(""+e/1024).lastIndexOf(".")+3)}MB`:`${e}KB`}function idCardGetDateAndGender(e){let t="",n="";if(ID_NUMBER.test(e)){const r=e.substring(6,14),i=e.substring(16,17),a=`${r.substring(0,4)}-${r.substring(4,6)}-${r.substring(6,8)}`,o=new Date(a.replace(/-/g,"/")),s=o.getMonth()+1;let l;const c=o.getDate();let u;l=s<10?`0${s}`:s,u=c<10?`0${c}`:c,t=i%2==1?"1":"0",n=`${o.getFullYear()}-${l}-${u}`}return{sex:t,date:n}}function getMatchedItems(e){const{list:t,value:n,idKey:r="bianma"}=e;return t.filter(e=>n.includes(e[r]))}function getUnmatchedItems(e){const{list:t,value:n,idKey:r="bianma"}=e;return t.filter(e=>!n.includes(e[r]))}function listTransTree(e){const{json:t,idKey:n,parentIdKey:r,childrenKey:i}=e,a=[],o={};let s=0,l=0;const c=t.length;for(;s<c;s++)o[t[s][n]]=t[s];for(;l<c;l++){const e=t[l],n=o[e[r]];n?(!n[i]&&(n[i]=[]),n[i].push(e)):a.push(e)}return a}function isEmptyToWhether(e,t={}){const{yesText:n="是",noText:r="否",yesValue:i="1"}=t;return isEmpty(e)?"":e.toString()===i.toString()?n:r}function createGuid(e=32){let t="";for(let n=0;n<e;n++)t+="abcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(36*Math.random()));return t}function getIndexColumn(e){return{title:"序号",key:"index",width:70,render:(t,n,r)=>!1===e?r+1:serialNumber(e,r)}}function getTreeNodePaths(e){const{data:t,targetId:n,idKey:r,childrenKey:i,path:a=[],isIncludeOneself:o}=e;for(let e=0;e<t.length;e++){const s=t[e],l=[...a,s];if(s[r]===n)return o?l:a;if(s[i]&&s[i].length>0){const e=getTreeNodePaths({data:s[i],targetId:n,idKey:r,childrenKey:i,path:l,isIncludeOneself:o});if(e)return e}}return null}function processTreeDataByLevel(e){const{data:t,level:n,childrenKey:r,currentLevel:i=1}=e;return t.map(e=>{const t={...e};return n&&i>=n?(t.isLeaf=!0,delete t[r]):e[r]&&e[r].length>0?t[r]=processTreeDataByLevel({data:e[r],currentLevel:i+1,level:n,childrenKey:r}):t.isLeaf=!0,t})}function processTreeDataForOnlyLastLevel(e){const{data:t,childrenKey:n,onlyLastLevel:r=!1}=e;return r?t.map(e=>{const t=e[n]&&e[n].length>0,i={...e,selectable:!t};return t&&(i[n]=processTreeDataForOnlyLastLevel({data:e[n],childrenKey:n,onlyLastLevel:r})),i}):t}function validatorEndTime(e){let{startTime:t,message:n="结束时间不能早于开始时间",type:r=""}=e;return{validator:(e,i)=>{if(!i||!t)return Promise.resolve();if(!r){const e=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;/^\d{4}-\d{2}-\d{2}$/.test(t)?r="date":e.test(t)&&(r="datetime")}return(dayjs.isDayjs(i)?i:dayjs(i)).isBefore(dayjs(t),"date"===r?"day":"seconds")?Promise.reject(n):Promise.resolve()}}}function validatorTimeGTCurrentDay(e){const{message:t="需要大于当前时间",type:n="date"}=e;return{validator:(e,r)=>r
|
|
1
|
+
import{request}from"@cqsjjb/jjb-common-lib/http.js";import dayjs from"dayjs";import{ID_NUMBER}from"../regular/index.js";function serialNumber(e,t){return(e.current-1)*e.pageSize+(t+1)}function toArrayString(value){return value?eval(value).map(String):[]}function interceptTheSuffix(e,t){return e.substring(e.lastIndexOf("."),e.length).toLowerCase()===t.toLowerCase()}function image2Base64(e){return new Promise(t=>{const n=new Image;n.src=e,n.crossOrigin="Anonymous",n.onload=function(){const e=document.createElement("canvas");e.width=n.width,e.height=n.height,e.getContext("2d").drawImage(n,0,0,n.width,n.height);const r=n.src.substring(n.src.lastIndexOf(".")+1).toLowerCase();t(e.toDataURL(`image/${r}`))}})}function image2Base642(e){return new Promise((t,n)=>{const r=new FileReader;r.readAsDataURL(e),r.onload=e=>{t(e.target.result)},r.onerror=e=>{n(e)}})}function base642File(e,t="file"){const n=e.split(","),r=n[0].match(/:(.*?);/)[1],i=r.split("/")[1],a=atob(n[1]);let o=a.length;const s=new Uint8Array(o);for(;o--;)s[o]=a.charCodeAt(o);return new File([s],`${t}.${i}`,{type:r})}function checkImgExists(e){return new Promise((t,n)=>{const r=new Image;r.src=e,r.onload=function(e){t(e)},r.onerror=function(e){n(e)}})}function getDataType(e){return Object.prototype.toString.call(e).slice(8,-1)}function ArrayDeduplication(e){return[...new Set(e)]}function arrayObjectDeduplication(e,t){const n={};return e.reduce((e,r)=>(n[r[t]]||(n[r[t]]=!0,e.push(r)),e),[])}function findCharIndex(e){const{str:t,char:n,num:r}=e;let i=t.indexOf(n);if(-1===i)return-1;for(let e=0;e<r-1;e++)if(i=t.indexOf(n,i+1),-1===i)return-1;return i}function randoms(e,t){return Math.random()*(t-e+1)+e}function numFormat(e){if(e){const t=e.toString().split("."),n=t[0].split("").reverse();let r=[];for(let e=0;e<n.length;e++)e%3==0&&0!==e&&r.push(","),r.push(n[e]);return r.reverse(),r=t[1]?r.join("").concat(`.${t[1]}`):r.join(""),r}}function isEmpty(e){return null==e||"object"==typeof e&&0===Object.keys(e).length||"string"==typeof e&&0===e.trim().length}function getUrlParam(e){const t=new RegExp(`(^|&)${e}=([^&]*)(&|$)`),n=window.location.search.substr(1).match(t);return null!=n?decodeURI(n[2]):""}function paging(e){const{list:t,currentPage:n,pageSize:r}=e;return t.filter((e,t)=>t<+n*+r&&t>=(+n-1)*+r)}function getFileSuffix(e){return e.substring(e.lastIndexOf(".")+1)}function getFileName(e){return e?e.substring(e.lastIndexOf("/")+1):""}function readTxtDocument(e){return new Promise(t=>{const n=getFileUrl()+e,r=new XMLHttpRequest;r.open("get",n,!0),r.responseType="blob",r.onload=function(e){const n=new FileReader;n.readAsText(e.target.response,"GB2312"),n.onload=function(){t(n.result)}},r.send()})}function secondConversion(e){if(!e)return 0;const t=Number.parseInt((e/60/60).toString(),10),n=Number.parseInt((e/60%60).toString(),10),r=Number.parseInt((e%60).toString(),10);return t?`${t}小时${n}分钟${r}秒`:n?`${n}分钟${r}秒`:`${r}秒`}function addingPrefixToFile(e,t={}){if(!e)return[];const{pathKey:n="filePath",nameKey:r="fileName",idKey:i="id"}=t,a=getFileUrl();return e.filter(e=>e[n]).map(e=>({url:a+e[n],name:e[r]||getFileName(e[n]),id:e[i],...e}))}function getLabelName(e){const{status:t,list:n,idKey:r="bianma",nameKey:i="name"}=e;return(n.find(e=>e[r]?.toString()===t?.toString())||{[i]:""})[i]}function calculateFileSize(e){return e>1024?`${(""+e/1024).substring(0,(""+e/1024).lastIndexOf(".")+3)}MB`:`${e}KB`}function idCardGetDateAndGender(e){let t="",n="";if(ID_NUMBER.test(e)){const r=e.substring(6,14),i=e.substring(16,17),a=`${r.substring(0,4)}-${r.substring(4,6)}-${r.substring(6,8)}`,o=new Date(a.replace(/-/g,"/")),s=o.getMonth()+1;let l;const c=o.getDate();let u;l=s<10?`0${s}`:s,u=c<10?`0${c}`:c,t=i%2==1?"1":"0",n=`${o.getFullYear()}-${l}-${u}`}return{sex:t,date:n}}function getMatchedItems(e){const{list:t,value:n,idKey:r="bianma"}=e;return t.filter(e=>n.includes(e[r]))}function getUnmatchedItems(e){const{list:t,value:n,idKey:r="bianma"}=e;return t.filter(e=>!n.includes(e[r]))}function listTransTree(e){const{json:t,idKey:n,parentIdKey:r,childrenKey:i}=e,a=[],o={};let s=0,l=0;const c=t.length;for(;s<c;s++)o[t[s][n]]=t[s];for(;l<c;l++){const e=t[l],n=o[e[r]];n?(!n[i]&&(n[i]=[]),n[i].push(e)):a.push(e)}return a}function isEmptyToWhether(e,t={}){const{yesText:n="是",noText:r="否",yesValue:i="1"}=t;return isEmpty(e)?"":e.toString()===i.toString()?n:r}function createGuid(e=32){let t="";for(let n=0;n<e;n++)t+="abcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(36*Math.random()));return t}function getIndexColumn(e){return{title:"序号",key:"index",width:70,render:(t,n,r)=>!1===e?r+1:serialNumber(e,r)}}function getTreeNodePaths(e){const{data:t,targetId:n,idKey:r,childrenKey:i,path:a=[],isIncludeOneself:o}=e;for(let e=0;e<t.length;e++){const s=t[e],l=[...a,s];if(s[r]===n)return o?l:a;if(s[i]&&s[i].length>0){const e=getTreeNodePaths({data:s[i],targetId:n,idKey:r,childrenKey:i,path:l,isIncludeOneself:o});if(e)return e}}return null}function processTreeDataByLevel(e){const{data:t,level:n,childrenKey:r,currentLevel:i=1}=e;return t.map(e=>{const t={...e};return n&&i>=n?(t.isLeaf=!0,delete t[r]):e[r]&&e[r].length>0?t[r]=processTreeDataByLevel({data:e[r],currentLevel:i+1,level:n,childrenKey:r}):t.isLeaf=!0,t})}function processTreeDataForOnlyLastLevel(e){const{data:t,childrenKey:n,onlyLastLevel:r=!1}=e;return r?t.map(e=>{const t=e[n]&&e[n].length>0,i={...e,selectable:!t};return t&&(i[n]=processTreeDataForOnlyLastLevel({data:e[n],childrenKey:n,onlyLastLevel:r})),i}):t}function validatorEndTime(e){let{startTime:t,message:n="结束时间不能早于开始时间",type:r=""}=e||{};return{validator:(e,i)=>{if(!i||!t)return Promise.resolve();if(!r){const e=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;/^\d{4}-\d{2}-\d{2}$/.test(t)?r="date":e.test(t)&&(r="datetime")}return(dayjs.isDayjs(i)?i:dayjs(i)).isBefore(dayjs(t),"date"===r?"day":"seconds")?Promise.reject(n):Promise.resolve()}}}function validatorTimeGTCurrentDay(e){const{message:t="需要大于当前时间",type:n="date"}=e||{};return{validator:(e,r)=>{if(!r)return Promise.resolve();const i=dayjs.isDayjs(r)?r:dayjs(r),a=dayjs();return("date"===n?i.isAfter(a,"day"):i.isAfter(a,"seconds"))?Promise.resolve():Promise.reject(t)}}}function validatorTimeGECurrentDay(e){const{message:t="需要大于等于当前时间",type:n="date"}=e||{};return{validator:(e,r)=>{if(!r)return Promise.resolve();const i=dayjs.isDayjs(r)?r:dayjs(r),a=dayjs();return("date"===n?i.isBefore(a,"day"):i.isBefore(a,"seconds"))?Promise.reject(t):Promise.resolve()}}}function dynamicLoadJs(e){return new Promise((t,n)=>{const r=document.createElement("script");r.type="text/javascript",r.src=e,r.onload=t,r.onerror=n,document.body.appendChild(r)})}function dynamicLoadCss(e){return new Promise((t,n)=>{const r=document.createElement("link");r.rel="stylesheet",r.type="text/css",r.href=e,r.onload=t,r.onerror=n,document.head.appendChild(r)})}function normalizeEmptyHtml(e){if(!e)return"";const t=e.replace(/\s+/g,"").toLowerCase();return"<p><br></p>"===t||"<p></p>"===t||""===t?"":e}function getFileUrl(){return window.fileUrl||process.env.app.fileUrl}async function getFileUrlFromServer(){if(window.fileUrl)return;const{data:e}=await request("/basicInfo/imgFiles/getImagePath","get");window.fileUrl=e}export{ArrayDeduplication,addingPrefixToFile,arrayObjectDeduplication,base642File,calculateFileSize,checkImgExists,createGuid,dynamicLoadCss,dynamicLoadJs,findCharIndex,getDataType,getFileName,getFileSuffix,getFileUrl,getFileUrlFromServer,getIndexColumn,getLabelName,getMatchedItems,getTreeNodePaths,getUnmatchedItems,getUrlParam,idCardGetDateAndGender,image2Base64,image2Base642,interceptTheSuffix,isEmpty,isEmptyToWhether,listTransTree,normalizeEmptyHtml,numFormat,paging,processTreeDataByLevel,processTreeDataForOnlyLastLevel,randoms,readTxtDocument,secondConversion,serialNumber,toArrayString,validatorEndTime,validatorTimeGECurrentDay,validatorTimeGTCurrentDay};
|