tools_dj 1.0.1 → 1.0.2
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/README.md +12 -3
- package/lib/index.d.ts +85 -0
- package/lib/index.js +1 -0
- package/package.json +17 -5
- package/index.js +0 -552
package/README.md
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
# element-plus 主题自定义
|
|
2
2
|
|
|
3
3
|
## 介绍
|
|
4
|
-
|
|
4
|
+
vue3.0 + element-plus-ui 动态切换主题
|
|
5
5
|
|
|
6
6
|
## 安装
|
|
7
|
-
npm i
|
|
7
|
+
npm i el_set_theme
|
|
8
8
|
|
|
9
9
|
## 使用
|
|
10
|
-
import {
|
|
10
|
+
import {setThemeData} from 'set_el_theme'
|
|
11
|
+
setThemeData({themeColor:'#38bd14', brightColor:'#0036ea', darkColor:'#9f450a'})
|
|
11
12
|
|
|
13
|
+
{themeColor:'#38bd14', brightColor:'#0036ea', darkColor:'#9f450a'},
|
|
14
|
+
themeColor: 主体颜色
|
|
15
|
+
brightColor: 亮处颜色
|
|
16
|
+
darkColor: 暗处颜色 不给黑色到亮色前一个色阶
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## 开发者注意事项
|
|
20
|
+
开发环境中携带_dev 文件的将它和原文件替换可以实现开发者环境 代码不压缩 原生打包
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export declare function del_repeat(obj: any): any;
|
|
2
|
+
export declare function formatDate(time: any, format?: string, type?: string): string;
|
|
3
|
+
export declare function time_change(data: any): number;
|
|
4
|
+
/** 2022/8/11 9:14 User: DJ
|
|
5
|
+
* content: 时间转换
|
|
6
|
+
* time 时间格式 YYYY-MM-DD hh:mm:ss week time_slot
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatTime(time: any, format?: string, type?: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* 计算两个日期之间的天数
|
|
11
|
+
* date1 开始日期 yyyy-MM-dd
|
|
12
|
+
* date2 结束日期 yyyy-MM-dd
|
|
13
|
+
* 如果日期相同 返回一天 开始日期大于结束日期,返回0
|
|
14
|
+
*/
|
|
15
|
+
export declare function getDaysBetween(date1: any, date2: any, negative?: any): number;
|
|
16
|
+
export declare function is_empty(obj: any): boolean;
|
|
17
|
+
export declare function repalce(str: any, index: any, char: any): any;
|
|
18
|
+
export declare function param(data: any, isPrefix?: boolean): string | false;
|
|
19
|
+
export declare function merge(obj1: any, obj2: any): any;
|
|
20
|
+
export declare function is(obj: any): any;
|
|
21
|
+
export declare function unique(obj: any): any;
|
|
22
|
+
export declare function first(obj: any): any;
|
|
23
|
+
export declare function last(obj: any): false | undefined;
|
|
24
|
+
/** 2022/7/15 16:45 User: DJ
|
|
25
|
+
* content: 二维数组查找返回他所在的下标
|
|
26
|
+
*/
|
|
27
|
+
export declare function findByIndex(array: any, key: any, data: any): any;
|
|
28
|
+
/** 2022/8/16 14:44 User: DJ
|
|
29
|
+
* content: 设置二维数据的值
|
|
30
|
+
* @source array /源数据
|
|
31
|
+
* @sourceKey string/源key
|
|
32
|
+
* @sourceData string/key值
|
|
33
|
+
* @nowKey string/目标key
|
|
34
|
+
* @nowData any/设置的数据
|
|
35
|
+
*/
|
|
36
|
+
export declare function setObjData(source: any, sourceKey: any, sourceData: any, nowKey: any, nowData: any): boolean;
|
|
37
|
+
/** 2022/8/18 9:20 User: DJ
|
|
38
|
+
* content: 查找二维数组数据
|
|
39
|
+
*/
|
|
40
|
+
export declare function selectObjData(source: any, sourceKey: any, sourceData: any): any;
|
|
41
|
+
/**
|
|
42
|
+
* 构造树型结构数据
|
|
43
|
+
* @param {*} data 数据源
|
|
44
|
+
* @param {*} id id字段 默认 'id'
|
|
45
|
+
* @param {*} parentId 父节点字段 默认 'parentId'
|
|
46
|
+
* @param {*} children 孩子节点字段 默认 'children'
|
|
47
|
+
*/
|
|
48
|
+
export declare function handleTree(data: any, id: string, parentId: string, children: string): any;
|
|
49
|
+
export declare function base64Img(base64: any, imgName: any): File;
|
|
50
|
+
/** 2022/8/27 10:19 User: DJ
|
|
51
|
+
* content: 排序时间
|
|
52
|
+
*/
|
|
53
|
+
export declare function compareDate(prop: any, type?: string): (a: any, b: any) => number;
|
|
54
|
+
/** 2022/8/27 10:19 User: DJ
|
|
55
|
+
* content: 排序
|
|
56
|
+
*/
|
|
57
|
+
export declare function compare(prop: any, type?: string): (a: any, b: any) => number;
|
|
58
|
+
/** 2023/2/16 14:18 User: DJ
|
|
59
|
+
* content: 前置补位
|
|
60
|
+
* str,字符或数字
|
|
61
|
+
* n 长度
|
|
62
|
+
* k 补位字符
|
|
63
|
+
* d 是否超出保留 false 截取
|
|
64
|
+
*/
|
|
65
|
+
export declare function numberRepair(str?: string, n?: number, k?: string, d?: boolean): string | number;
|
|
66
|
+
/** 2023/3/2 10:47 User: DJ
|
|
67
|
+
* content: 返回是否移动设备
|
|
68
|
+
*/
|
|
69
|
+
export declare function isMobile(): boolean;
|
|
70
|
+
/** 2023/3/2 15:53 User: DJ
|
|
71
|
+
* content: 设置头部
|
|
72
|
+
* 顺便设置了title
|
|
73
|
+
* cZoom 自定义缩放 没有不会生效
|
|
74
|
+
* mobile 移动端
|
|
75
|
+
* pc 电脑端
|
|
76
|
+
* isScale 是否缩放
|
|
77
|
+
* meta: {title: "简历",cZoom:{mobile:0.6,pc:1,isScale:'yes'}},
|
|
78
|
+
*/
|
|
79
|
+
export declare function setMeta(meta: any): void;
|
|
80
|
+
/** 2023/3/15 15:00 User: DJ
|
|
81
|
+
* content: 色阶取值
|
|
82
|
+
* 第一个颜色到第二个颜色
|
|
83
|
+
* 色阶宽度
|
|
84
|
+
*/
|
|
85
|
+
export declare function colorMix(color1: any, color2: any, weight: any): string;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function t(t){let e={};return t.forEach((function(t){e[JSON.stringify(t)]=t})),t=Object.keys(e).map((function(t){if("undefined"!=t)return JSON.parse(t)}))}function e(t){let e=!1;switch(Object.prototype.toString.call(t).slice(8,-1)){case"Undefined":case"Null":e=!0;break;case"String":e=0===t.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g,"").length;break;case"Boolean":e=!t;break;case"Array":e=0===t.length;break;case"Number":e=0===t||isNaN(t);break;case"Object":e=0===Object.keys(t).length}return e}function r(){return!e(navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))}Object.defineProperty(exports,"__esModule",{value:!0}),exports.colorMix=exports.setMeta=exports.isMobile=exports.numberRepair=exports.compare=exports.compareDate=exports.base64Img=exports.handleTree=exports.selectObjData=exports.setObjData=exports.findByIndex=exports.last=exports.first=exports.unique=exports.is=exports.merge=exports.param=exports.repalce=exports.is_empty=exports.getDaysBetween=exports.formatTime=exports.time_change=exports.formatDate=exports.del_repeat=void 0,exports.del_repeat=t,exports.formatDate=function(t,e="day",r="-"){let o=t.getFullYear(),n=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getDate().toString().padStart(2,"0"),c=t.getHours().toString().padStart(2,"0"),s=t.getMinutes().toString().padStart(2,"0"),i={year:1,month:2,day:3,hour:4,minute:5},p="";for(let t=0;t<i[e];t++)0==t&&(p+=o),1==t&&(p+=n),2==t&&(p+=a),3==t&&(p+=c),4==t&&(p+=s),t!=i[e]-1&&(p+=r);return p},exports.time_change=function(t){return Date.parse(t)},exports.formatTime=function(t,e="YYYY-MM-DD hh:mm:ss",r="-"){try{t=t.replaceAll("-","/")}catch(t){}let o=(t=new Date(t)).getFullYear(),n=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getDate().toString().padStart(2,"0"),c=t.getHours().toString().padStart(2,"0"),s=[];s=[{group:1,connect:"",format:"YYYY",data:o},{group:1,connect:"",format:"yyyy",data:o},{group:1,connect:r,format:"MM",data:n},{group:1,connect:r,format:"DD",data:a},{group:1,connect:r,format:"dd",data:a},{group:2,connect:" ",format:"hh",data:c},{group:2,connect:" ",format:"HH",data:c},{group:2,connect:":",format:"mm",data:t.getMinutes().toString().padStart(2,"0")},{group:2,connect:":",format:"ss",data:t.getSeconds().toString().padStart(2,"0")},{group:3,connect:" ",format:"week",data:{0:"周日",1:"周一",2:"周二",3:"周三",4:"周四",5:"周五",6:"周六"}[t.getDay()]},{group:4,connect:" ",format:"time_slot",data:c>12?"下午":"上午"}];let i=0,p="";return s.forEach((function(t,r){if(-1!=e.indexOf(t.format)){let e="";0!=i&&(e=t.connect),p+=e+t.data,i++}})),p},exports.getDaysBetween=function(t,e,r=!1){var o=Date.parse(t),n=Date.parse(e),a=0;return o>n&&(a=(o-n)/864e5),o<n&&(a=(n-o)/864e5,r&&(a=-a)),a},exports.is_empty=e,exports.repalce=function(t,e,r){return t.substring(0,e)+r+t.substring(e+1)},exports.param=function(t,r=!0){if(0==e(t)){let e=r?"?":"",o=[];for(let e in t){let r=t[e];["",void 0,null].includes(r)||(r.constructor===Array?r.forEach((t=>{o.push(encodeURIComponent(e)+"[]="+encodeURIComponent(t))})):o.push(encodeURIComponent(e)+"="+encodeURIComponent(r)))}return console.log(o.length?e+o.join("&"):""),o.length?e+o.join("&"):""}return console.log(!1),!1},exports.merge=function(e,r){const o=Object.prototype.toString.call(e);return"Array"==o.slice(8,-1)?(e.push.apply(e,r),t(e)):"Object"==o.slice(8,-1)?Object.assign(e,r):void 0},exports.is=function(t){return Object.prototype.toString.call(t).slice(8,-1)},exports.unique=function(r){if(0==e(r)){let e=t(r);return console.log(e),e}return console.log(!1),!1},exports.first=function(t){if(0!=e(t))return console.log(!1),!1;if("[object Object]"===Object.prototype.toString.call(t))for(const e of t)return console.log(e),e;else console.log(t[0])},exports.last=function(t){if(0!=e(t))return console.log(!1),!1;if("[object Object]"===Object.prototype.toString.call(t))for(const e of t)console.log(e);else console.log(t[t.length-1])},exports.findByIndex=function(t,e,r){return(t||[]).findIndex((t=>t[e]===r))},exports.setObjData=function(t,e,r,o,n){try{return t.find((function(t){return t[e]==r}))[o]=n,!0}catch(t){return!1}},exports.selectObjData=function(t,e,r){try{return t.find((function(t){return t[e]==r}))}catch(t){return""}},exports.handleTree=function(t,e,r,o){let n=e||"id",a=r||"parentId",c=o||"children";var s={},i={},p=[];for(let e of t){let t=e[a];null==s[t]&&(s[t]=[]),i[e[n]]=e,s[t].push(e)}for(let e of t){null==i[e[a]]&&p.push(e)}for(let t of p)u(t);function u(t){if(null!==s[t[n]]&&(t[c]=s[t[n]]),t[c])for(let e of t[c])u(e)}return p},exports.base64Img=function(t,e){let r=function(t){for(var e=t.split(","),r=e[0].match(/:(.*?);/)[1],o=atob(e[1]),n=o.length,a=new Uint8Array(n);n--;)a[n]=o.charCodeAt(n);return new Blob([a],{type:r})}(t);return new File([r],e)},exports.compareDate=function(t,e="up"){return function(r,o){return"up"==e?Date.parse(r[t])-Date.parse(o[t]):Date.parse(o[t])-Date.parse(r[t])}},exports.compare=function(t,e="up"){return function(r,o){return"up"==e?r[t]-o[t]:o[t]-r[t]}},exports.numberRepair=function(t="",e=2,r="0",o=!1){let n="",a=(""+t).length;if(a>e&&1==o)return a;{let o=e-a;if(o>0)for(let t=0;t<o;t++)n+=r;return(n+t).slice(-1*e)}},Number.prototype.repair=function(t=2){let e="";for(let r=1;r<t;r++)e+="0";return(e+this).slice(-1*t)},exports.isMobile=r,exports.setMeta=function(t){if(!e(t)){let e=[];document.head.childNodes.forEach((r=>{switch(r.tagName){case"META":e.push(r);break;case"TITLE":document.title=t.title||"模板测试"}}));const o=document.createElement("META");let n=1,a="yes";t.cZoom&&(r()?t.cZoom.mobile&&(n=t.cZoom.mobile):t.cZoom.pc&&(n=t.cZoom.pc),t.cZoom.isScale&&(a=t.cZoom.isScale));let c=`width=device-width,minimum-scale=${n},initial-scale=${n},user-scalable=${a}`;"no"==a&&(c+=`,maximum-scale=${n}`);const s=[{charset:"utf-8"},{name:"viewport",content:c}],i=document.createDocumentFragment();s.forEach((t=>{i.append(o.cloneNode()),Object.entries(t).forEach((t=>{i.lastChild.setAttribute(t[0],t[1])}))})),e.forEach((t=>{document.head.removeChild(t)})),document.head.prepend(i)}},exports.colorMix=function(t,e,r){r=Math.max(Math.min(Number(r),1),0);let o=parseInt(t.substring(1,3),16),n=parseInt(t.substring(3,5),16),a=parseInt(t.substring(5,7),16),c=parseInt(e.substring(1,3),16),s=parseInt(e.substring(3,5),16),i=parseInt(e.substring(5,7),16),p=Math.round(o*(1-r)+c*r),u=Math.round(n*(1-r)+s*r),l=Math.round(a*(1-r)+i*r);return p=("0"+(p||0).toString(16)).slice(-2),u=("0"+(u||0).toString(16)).slice(-2),l=("0"+(l||0).toString(16)).slice(-2),"#"+p+u+l};
|
package/package.json
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tools_dj",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "dj tools 工具库",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"module": "./lib/index.js",
|
|
7
|
+
"types": "./lib/index.d.ts",
|
|
6
8
|
"scripts": {
|
|
7
|
-
"
|
|
9
|
+
"build": "rollup -c",
|
|
10
|
+
"serve": "rollup -c -w"
|
|
8
11
|
},
|
|
9
|
-
"author": "
|
|
12
|
+
"author": "dj_h",
|
|
10
13
|
"license": "ISC",
|
|
11
14
|
"keywords": [
|
|
12
15
|
"tools",
|
|
13
16
|
"tool"
|
|
14
17
|
],
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@rollup/plugin-alias": "^5.0.0",
|
|
20
|
+
"@rollup/plugin-node-resolve": "^15.0.2",
|
|
21
|
+
"@rollup/plugin-typescript": "^11.1.0",
|
|
22
|
+
"rollup": "^2.79.1",
|
|
23
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
24
|
+
"tslib": "^2.5.0",
|
|
25
|
+
"typescript": "^5.0.3"
|
|
26
|
+
},
|
|
15
27
|
"files": [
|
|
16
|
-
"
|
|
28
|
+
"lib"
|
|
17
29
|
]
|
|
18
30
|
}
|
package/index.js
DELETED
|
@@ -1,552 +0,0 @@
|
|
|
1
|
-
/*删除数组重复的元素
|
|
2
|
-
*let newArr = del_repeat(Arr)
|
|
3
|
-
*/
|
|
4
|
-
export const del_repeat=(obj)=>{//新建一个去重的方法
|
|
5
|
-
let unique={};
|
|
6
|
-
obj.forEach(function (item){
|
|
7
|
-
unique[JSON.stringify(item)]=item;
|
|
8
|
-
})
|
|
9
|
-
obj=Object.keys(unique).map(function (u){
|
|
10
|
-
if (u!='undefined') return JSON.parse(u);
|
|
11
|
-
})
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
//格式化时间
|
|
16
|
-
//格式化参数format=[ year month day hour minute],type=- /
|
|
17
|
-
export const formatDate= (time,format='day',type='-')=> {
|
|
18
|
-
let year =time.getFullYear()//年
|
|
19
|
-
let month =(time.getMonth()+1).toString().padStart(2,'0')//月
|
|
20
|
-
let day =(time.getDate()).toString().padStart(2,'0')//日
|
|
21
|
-
let hour =(time.getHours()).toString().padStart(2,'0')//时
|
|
22
|
-
let minute =(time.getMinutes()).toString().padStart(2,'0')//分
|
|
23
|
-
let types={
|
|
24
|
-
year:1,
|
|
25
|
-
month:2,
|
|
26
|
-
day:3,
|
|
27
|
-
hour:4,
|
|
28
|
-
minute:5
|
|
29
|
-
}
|
|
30
|
-
let formDates="";
|
|
31
|
-
for (let i=0; i<types[format]; i++){
|
|
32
|
-
if(i==0)formDates+=year
|
|
33
|
-
if(i==1)formDates+=month
|
|
34
|
-
if(i==2)formDates+=day
|
|
35
|
-
if(i==3)formDates+=hour
|
|
36
|
-
if(i==4)formDates+=minute
|
|
37
|
-
if (i!=types[format]-1)formDates+=type
|
|
38
|
-
}
|
|
39
|
-
return formDates
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
//时间格式yyyy-MM-dd HH:mm 返回时间戳
|
|
43
|
-
export const time_change=(data)=>{
|
|
44
|
-
return Date.parse(data);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
/** 2022/8/11 9:14 User: DJ
|
|
49
|
-
* content: 时间转换
|
|
50
|
-
* time 时间格式 YYYY-MM-DD hh:mm:ss week time_slot
|
|
51
|
-
*/
|
|
52
|
-
export const formatTime= (time,format='YYYY-MM-DD hh:mm:ss',type='-')=> {
|
|
53
|
-
try {
|
|
54
|
-
time=time.replaceAll('-','/')
|
|
55
|
-
}catch (e) {}
|
|
56
|
-
time=new Date(time)
|
|
57
|
-
let year =time.getFullYear()//年
|
|
58
|
-
let month =(time.getMonth()+1).toString().padStart(2,'0')//月
|
|
59
|
-
let day =(time.getDate()).toString().padStart(2,'0')//日
|
|
60
|
-
let hour =(time.getHours()).toString().padStart(2,'0')//时
|
|
61
|
-
let minute =(time.getMinutes()).toString().padStart(2,'0')//分
|
|
62
|
-
let seconds =(time.getSeconds()).toString().padStart(2,'0')//秒
|
|
63
|
-
let weeks={
|
|
64
|
-
0:'周日',
|
|
65
|
-
1:'周一',
|
|
66
|
-
2:'周二',
|
|
67
|
-
3:'周三',
|
|
68
|
-
4:'周四',
|
|
69
|
-
5:'周五',
|
|
70
|
-
6:'周六',
|
|
71
|
-
}
|
|
72
|
-
let week =weeks[time.getDay()]
|
|
73
|
-
let time_slot=hour>12?'下午':'上午'
|
|
74
|
-
let arrayDate=[]
|
|
75
|
-
arrayDate=[
|
|
76
|
-
{group:1,connect:'',format:'YYYY',data:year},
|
|
77
|
-
{group:1,connect:'',format:'yyyy',data:year},
|
|
78
|
-
{group:1,connect:type,format:'MM',data:month},
|
|
79
|
-
{group:1,connect:type,format:'DD',data:day},
|
|
80
|
-
{group:1,connect:type,format:'dd',data:day},
|
|
81
|
-
{group:2,connect:' ',format:'hh',data:hour},
|
|
82
|
-
{group:2,connect:' ',format:'HH',data:hour},
|
|
83
|
-
{group:2,connect:':',format:'mm',data:minute},
|
|
84
|
-
{group:2,connect:':',format:'ss',data:seconds},
|
|
85
|
-
{group:3,connect:' ',format:'week',data:week},
|
|
86
|
-
{group:4,connect:' ',format:'time_slot',data:time_slot},
|
|
87
|
-
]
|
|
88
|
-
let indexItem=0
|
|
89
|
-
let formDates="";
|
|
90
|
-
arrayDate.forEach(function (item,index) {
|
|
91
|
-
let isIn =format.indexOf(item.format)
|
|
92
|
-
if (isIn!=-1){//在
|
|
93
|
-
let connect=''
|
|
94
|
-
if (indexItem!=0){
|
|
95
|
-
connect=item.connect
|
|
96
|
-
}
|
|
97
|
-
formDates+=(connect+item.data)
|
|
98
|
-
indexItem++
|
|
99
|
-
}
|
|
100
|
-
})
|
|
101
|
-
return formDates
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* 计算两个日期之间的天数
|
|
106
|
-
* date1 开始日期 yyyy-MM-dd
|
|
107
|
-
* date2 结束日期 yyyy-MM-dd
|
|
108
|
-
* 如果日期相同 返回一天 开始日期大于结束日期,返回0
|
|
109
|
-
*/
|
|
110
|
-
export function getDaysBetween(date1, date2 ,negative=false) {
|
|
111
|
-
var startDate = Date.parse(date1);
|
|
112
|
-
var endDate = Date.parse(date2);
|
|
113
|
-
var days = 0;
|
|
114
|
-
if (startDate > endDate) {
|
|
115
|
-
days = (startDate - endDate) / (24 * 60 * 60 * 1000);
|
|
116
|
-
}
|
|
117
|
-
if (startDate < endDate) {
|
|
118
|
-
days = (endDate - startDate) / (24 * 60 * 60 * 1000);
|
|
119
|
-
if (negative){
|
|
120
|
-
days=-days
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return days;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/*判断是否为空
|
|
127
|
-
* 传入一个值
|
|
128
|
-
* 为空返回true非空返回false*/
|
|
129
|
-
export const is_empty=(obj)=>{
|
|
130
|
-
const old=Object.prototype.toString.call(obj)
|
|
131
|
-
let res=false
|
|
132
|
-
switch (old.slice(8,-1)){
|
|
133
|
-
case 'Undefined':
|
|
134
|
-
res=true;
|
|
135
|
-
break;
|
|
136
|
-
case 'Null':
|
|
137
|
-
res=true;
|
|
138
|
-
break;
|
|
139
|
-
case 'String':
|
|
140
|
-
res=obj.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '').length === 0
|
|
141
|
-
break;
|
|
142
|
-
case 'Boolean':
|
|
143
|
-
res=(!obj)
|
|
144
|
-
break;
|
|
145
|
-
case 'Array':
|
|
146
|
-
res=obj.length === 0
|
|
147
|
-
break;
|
|
148
|
-
case 'Number':
|
|
149
|
-
res=(0 === obj || isNaN(obj))
|
|
150
|
-
break;
|
|
151
|
-
case 'Object':
|
|
152
|
-
const arr=Object.keys(obj)
|
|
153
|
-
res=(arr.length === 0)
|
|
154
|
-
break;
|
|
155
|
-
default:
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
return res
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/*字符串替换传入
|
|
162
|
-
str:字符串,index:位置第几位下标,char:替换的内容
|
|
163
|
-
返回一个字符串*/
|
|
164
|
-
export const repalce=(str,index,char)=>{
|
|
165
|
-
return str.substring(0,index)+char+str.substring(index+1);
|
|
166
|
-
}//字符串替换
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
/*url组装
|
|
170
|
-
* 传入一个对象,isPrefix不写 默认前缀带问号 如果isPrefix等于false就是不带前缀?
|
|
171
|
-
* return一个url格式的字符串*/
|
|
172
|
-
export const param=(data,isPrefix=true)=>{//组装成为url
|
|
173
|
-
if (is_empty(data) == false) {
|
|
174
|
-
let prefix = isPrefix ? '?' : ''
|
|
175
|
-
let _result = []
|
|
176
|
-
for (let key in data) {
|
|
177
|
-
let value = data[key]
|
|
178
|
-
if (['', undefined, null].includes(value)) {// 去掉为空的参数
|
|
179
|
-
continue
|
|
180
|
-
}
|
|
181
|
-
if (value.constructor === Array) {
|
|
182
|
-
value.forEach(_value => {
|
|
183
|
-
_result.push(encodeURIComponent(key) + '[]=' + encodeURIComponent(_value))
|
|
184
|
-
})
|
|
185
|
-
} else {
|
|
186
|
-
_result.push(encodeURIComponent(key) + '=' + encodeURIComponent(value))
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
console.log(_result.length ? prefix + _result.join('&') : '')
|
|
190
|
-
return _result.length ? prefix + _result.join('&') : ''
|
|
191
|
-
}else {
|
|
192
|
-
console.log(false)
|
|
193
|
-
return false
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
/*合并追加数组或者对象
|
|
199
|
-
* 传入两个数组或者对象
|
|
200
|
-
* return合并之后的数组或是对象*/
|
|
201
|
-
export const merge=(obj1,obj2)=>{//合并追加数组对象
|
|
202
|
-
const st=Object.prototype.toString.call(obj1)
|
|
203
|
-
if (st.slice(8,-1)=='Array'){
|
|
204
|
-
obj1.push.apply(obj1,obj2)//合并数组
|
|
205
|
-
return (new del_repeat(obj1))//数组去重
|
|
206
|
-
}if (st.slice(8,-1)=='Object'){
|
|
207
|
-
return Object.assign(obj1,obj2)
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/*判断类型
|
|
212
|
-
* 传入任意一个参数
|
|
213
|
-
* 返回他的类型*/
|
|
214
|
-
export const is=(obj)=>{//判断数据类型需要判断所有的类型
|
|
215
|
-
const st=Object.prototype.toString.call(obj)
|
|
216
|
-
return st.slice(8,-1)
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/*去除数组中的重复元素
|
|
220
|
-
* 传入一个数组
|
|
221
|
-
* return 一个数组出去*/
|
|
222
|
-
export const unique= (obj) => {//去除数组对象中的重复元素
|
|
223
|
-
if (is_empty(obj) == false) {
|
|
224
|
-
let res = new del_repeat(obj)
|
|
225
|
-
console.log(res)
|
|
226
|
-
return res
|
|
227
|
-
} else {
|
|
228
|
-
console.log(false)
|
|
229
|
-
return false
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/*输出数组对象的第一个元素
|
|
234
|
-
* 传入一个数组对象
|
|
235
|
-
* return一个对象或是数组
|
|
236
|
-
* 为空返回false*/
|
|
237
|
-
export const first= (obj)=> {//输出对象中的第一个元素
|
|
238
|
-
if (is_empty(obj) == false) {
|
|
239
|
-
const st = Object.prototype.toString.call(obj)
|
|
240
|
-
if (st === '[object Object]') {
|
|
241
|
-
new fora(obj, 1)
|
|
242
|
-
for (const objElement of obj) {
|
|
243
|
-
console.log(objElement)
|
|
244
|
-
return(objElement)
|
|
245
|
-
}
|
|
246
|
-
} else {
|
|
247
|
-
console.log(obj[0])
|
|
248
|
-
return log[0]
|
|
249
|
-
}
|
|
250
|
-
}else {
|
|
251
|
-
console.log(false)
|
|
252
|
-
return false
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/*输出数组对象的最后一个元素
|
|
257
|
-
* 传入一个数组对象
|
|
258
|
-
* return一个对象或是数组
|
|
259
|
-
* 为空返回false*/
|
|
260
|
-
export const last= (obj)=> {//输出对象中的最后一个元素
|
|
261
|
-
if (is_empty(obj) == false) {
|
|
262
|
-
const st = Object.prototype.toString.call(obj)
|
|
263
|
-
if (st === '[object Object]') {
|
|
264
|
-
new fora(obj, 2)
|
|
265
|
-
for (const objElement of obj) {
|
|
266
|
-
console.log(objElement)
|
|
267
|
-
// return(objElement)
|
|
268
|
-
}
|
|
269
|
-
} else {
|
|
270
|
-
console.log(obj[obj.length - 1])
|
|
271
|
-
}
|
|
272
|
-
} else {
|
|
273
|
-
console.log(false)
|
|
274
|
-
return false
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
/** 2022/7/15 16:45 User: DJ
|
|
278
|
-
* content: 二维数组查找返回他所在的下标
|
|
279
|
-
*/
|
|
280
|
-
export const findByIndex= (array,key,data) =>{
|
|
281
|
-
return (array|| []).findIndex((profile) => profile[key] === data);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/** 2022/8/16 14:44 User: DJ
|
|
285
|
-
* content: 设置二维数据的值
|
|
286
|
-
* @source array /源数据
|
|
287
|
-
* @sourceKey string/源key
|
|
288
|
-
* @sourceData string/key值
|
|
289
|
-
* @nowKey string/目标key
|
|
290
|
-
* @nowData any/设置的数据
|
|
291
|
-
*/
|
|
292
|
-
export function setObjData(source , sourceKey , sourceData, nowKey, nowData) {
|
|
293
|
-
try {
|
|
294
|
-
var p = source.find(function (curr) {
|
|
295
|
-
return curr[sourceKey] == sourceData
|
|
296
|
-
})
|
|
297
|
-
p[nowKey] = nowData
|
|
298
|
-
return true
|
|
299
|
-
} catch (e) {
|
|
300
|
-
return false
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
/** 2022/8/18 9:20 User: DJ
|
|
304
|
-
* content: 查找二维数组数据
|
|
305
|
-
*/
|
|
306
|
-
export function selectObjData(source , sourceKey , sourceData) {
|
|
307
|
-
try {
|
|
308
|
-
return source.find(function (curr) {
|
|
309
|
-
return curr[sourceKey] == sourceData
|
|
310
|
-
})
|
|
311
|
-
} catch (e) {
|
|
312
|
-
return ''
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* 构造树型结构数据
|
|
318
|
-
* @param {*} data 数据源
|
|
319
|
-
* @param {*} id id字段 默认 'id'
|
|
320
|
-
* @param {*} parentId 父节点字段 默认 'parentId'
|
|
321
|
-
* @param {*} children 孩子节点字段 默认 'children'
|
|
322
|
-
*/
|
|
323
|
-
export function handleTree(data, id, parentId, children) {
|
|
324
|
-
let config = {
|
|
325
|
-
id: id || 'id',
|
|
326
|
-
parentId: parentId || 'parentId',
|
|
327
|
-
childrenList: children || 'children'
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
var childrenListMap = {};
|
|
331
|
-
var nodeIds = {};
|
|
332
|
-
var tree = [];
|
|
333
|
-
|
|
334
|
-
for (let d of data) {
|
|
335
|
-
let parentId = d[config.parentId];
|
|
336
|
-
if (childrenListMap[parentId] == null) {
|
|
337
|
-
childrenListMap[parentId] = [];
|
|
338
|
-
}
|
|
339
|
-
nodeIds[d[config.id]] = d;
|
|
340
|
-
childrenListMap[parentId].push(d);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
for (let d of data) {
|
|
344
|
-
let parentId = d[config.parentId];
|
|
345
|
-
if (nodeIds[parentId] == null) {
|
|
346
|
-
tree.push(d);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
for (let t of tree) {
|
|
351
|
-
adaptToChildrenList(t);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
function adaptToChildrenList(o) {
|
|
355
|
-
if (childrenListMap[o[config.id]] !== null) {
|
|
356
|
-
o[config.childrenList] = childrenListMap[o[config.id]];
|
|
357
|
-
}
|
|
358
|
-
if (o[config.childrenList]) {
|
|
359
|
-
for (let c of o[config.childrenList]) {
|
|
360
|
-
adaptToChildrenList(c);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
return tree;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
//将base64转换为blob
|
|
369
|
-
function dataURLtoBlob(dataurl) {
|
|
370
|
-
var arr = dataurl.split(','),
|
|
371
|
-
mime = arr[0].match(/:(.*?);/)[1],
|
|
372
|
-
bstr = atob(arr[1]),
|
|
373
|
-
n = bstr.length,
|
|
374
|
-
u8arr = new Uint8Array(n);
|
|
375
|
-
while (n--) {
|
|
376
|
-
u8arr[n] = bstr.charCodeAt(n);
|
|
377
|
-
}
|
|
378
|
-
return new Blob([u8arr], { type: mime });
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
//将blob转换为file
|
|
383
|
-
function blobToFile(theBlob, fileName){
|
|
384
|
-
return new File([theBlob], fileName);
|
|
385
|
-
// theBlob.lastModifiedDate = new Date();
|
|
386
|
-
// theBlob.name = fileName;
|
|
387
|
-
// return theBlob;
|
|
388
|
-
}
|
|
389
|
-
export function base64Img(base64,imgName){
|
|
390
|
-
let blob = dataURLtoBlob(base64);
|
|
391
|
-
return blobToFile(blob, imgName);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/** 2022/8/27 10:19 User: DJ
|
|
395
|
-
* content: 排序时间
|
|
396
|
-
*/
|
|
397
|
-
export function compareDate(prop,type='up') {
|
|
398
|
-
|
|
399
|
-
return function(a, b) {
|
|
400
|
-
if (type=='up'){
|
|
401
|
-
return Date.parse(a[prop]) - Date.parse(b[prop]);
|
|
402
|
-
}else {
|
|
403
|
-
return Date.parse(b[prop]) - Date.parse(a[prop]);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
/** 2022/8/27 10:19 User: DJ
|
|
408
|
-
* content: 排序
|
|
409
|
-
*/
|
|
410
|
-
export function compare(prop,type='up') {
|
|
411
|
-
return function(a, b) {
|
|
412
|
-
if (type=='up'){
|
|
413
|
-
return a[prop] - b[prop] // 升序
|
|
414
|
-
}else {
|
|
415
|
-
return b[prop] - a[prop] // 降序
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
/** 2023/2/16 14:18 User: DJ
|
|
422
|
-
* content: 前置补位
|
|
423
|
-
* str,字符或数字
|
|
424
|
-
* n 长度
|
|
425
|
-
* k 补位字符
|
|
426
|
-
* d 是否超出保留 false 截取
|
|
427
|
-
*/
|
|
428
|
-
function numberRepair(str='',n=2,k='0',d=false){
|
|
429
|
-
let s = "";
|
|
430
|
-
let sLen=(''+str).length
|
|
431
|
-
if (sLen>n && d==true){
|
|
432
|
-
return sLen
|
|
433
|
-
}else {
|
|
434
|
-
let diffLen=n-sLen
|
|
435
|
-
if (diffLen>0){
|
|
436
|
-
for (let i = 0; i < diffLen; i++) {
|
|
437
|
-
s += k;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
return (s + str).slice(-1 * n);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
/** 2023/2/16 14:20 User: DJ
|
|
445
|
-
* content: 数字补位
|
|
446
|
-
*/
|
|
447
|
-
Number.prototype.repair = function(n = 2) {
|
|
448
|
-
let s = "";
|
|
449
|
-
for (let i = 1; i < n; i++) {
|
|
450
|
-
s += '0';
|
|
451
|
-
}
|
|
452
|
-
return (s + this).slice(-1 * n);
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
/** 2023/3/2 10:47 User: DJ
|
|
456
|
-
* content: 返回是否移动设备
|
|
457
|
-
*/
|
|
458
|
-
export function isMobile() {
|
|
459
|
-
let userAgent=navigator.userAgent
|
|
460
|
-
let flag = userAgent.match(
|
|
461
|
-
/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
|
|
462
|
-
);
|
|
463
|
-
return !is_empty(flag);
|
|
464
|
-
}
|
|
465
|
-
/** 2023/3/2 15:53 User: DJ
|
|
466
|
-
* content: 设置头部
|
|
467
|
-
* 顺便设置了title
|
|
468
|
-
* cZoom 自定义缩放 没有不会生效
|
|
469
|
-
* mobile 移动端
|
|
470
|
-
* pc 电脑端
|
|
471
|
-
* isScale 是否缩放
|
|
472
|
-
* meta: {title: "简历",cZoom:{mobile:0.6,pc:1,isScale:'yes'}},
|
|
473
|
-
*/
|
|
474
|
-
export function setMeta(meta) {
|
|
475
|
-
if (!is_empty(meta)) {
|
|
476
|
-
let metaArr = [];
|
|
477
|
-
document.head.childNodes.forEach((item) => {
|
|
478
|
-
switch (item.tagName) {
|
|
479
|
-
case "META":
|
|
480
|
-
metaArr.push(item);
|
|
481
|
-
break;
|
|
482
|
-
case "TITLE":
|
|
483
|
-
//顺便设置title
|
|
484
|
-
document.title = meta.title || "模板测试";
|
|
485
|
-
break;
|
|
486
|
-
}
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
const metas = document.createElement("META");//原始头//添加想要的meta(全局)
|
|
490
|
-
let minScale = 1
|
|
491
|
-
let isScale = 'yes' //允许视图缩放
|
|
492
|
-
if (meta.cZoom) {
|
|
493
|
-
if (isMobile()) {
|
|
494
|
-
if (meta.cZoom.mobile) {
|
|
495
|
-
minScale = meta.cZoom.mobile
|
|
496
|
-
}
|
|
497
|
-
} else {
|
|
498
|
-
if (meta.cZoom.pc) {
|
|
499
|
-
minScale = meta.cZoom.pc
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
if (meta.cZoom.isScale) {
|
|
503
|
-
isScale = meta.cZoom.isScale
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
let contentStr = `width=device-width,minimum-scale=${minScale},initial-scale=${minScale},user-scalable=${isScale}`
|
|
507
|
-
if (isScale == 'no') {
|
|
508
|
-
contentStr += `,maximum-scale=${minScale}`
|
|
509
|
-
}
|
|
510
|
-
const seat = [
|
|
511
|
-
{charset: "utf-8"},
|
|
512
|
-
{
|
|
513
|
-
name: "viewport",
|
|
514
|
-
content: contentStr,
|
|
515
|
-
},
|
|
516
|
-
];
|
|
517
|
-
const creatFrag = document.createDocumentFragment();
|
|
518
|
-
seat.forEach((ele) => {
|
|
519
|
-
creatFrag.append(metas.cloneNode());
|
|
520
|
-
Object.entries(ele).forEach((item) => {
|
|
521
|
-
creatFrag.lastChild.setAttribute(item[0], item[1]);
|
|
522
|
-
});
|
|
523
|
-
});
|
|
524
|
-
|
|
525
|
-
metaArr.forEach((item) => {//删除原来的meta
|
|
526
|
-
document.head.removeChild(item);
|
|
527
|
-
});
|
|
528
|
-
document.head.prepend(creatFrag); //将文档片段写入head
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
/** 2023/3/15 15:00 User: DJ
|
|
533
|
-
* content: 色阶取值
|
|
534
|
-
* 第一个颜色到第二个颜色
|
|
535
|
-
* 色阶宽度
|
|
536
|
-
*/
|
|
537
|
-
export const colorMix = (color1, color2, weight) => {
|
|
538
|
-
weight = Math.max(Math.min(Number(weight), 1), 0)
|
|
539
|
-
let r1 = parseInt(color1.substring(1, 3), 16)
|
|
540
|
-
let g1 = parseInt(color1.substring(3, 5), 16)
|
|
541
|
-
let b1 = parseInt(color1.substring(5, 7), 16)
|
|
542
|
-
let r2 = parseInt(color2.substring(1, 3), 16)
|
|
543
|
-
let g2 = parseInt(color2.substring(3, 5), 16)
|
|
544
|
-
let b2 = parseInt(color2.substring(5, 7), 16)
|
|
545
|
-
let r = Math.round(r1 * (1 - weight) + r2 * weight)
|
|
546
|
-
let g = Math.round(g1 * (1 - weight) + g2 * weight)
|
|
547
|
-
let b = Math.round(b1 * (1 - weight) + b2 * weight)
|
|
548
|
-
r = ("0" + (r || 0).toString(16)).slice(-2)
|
|
549
|
-
g = ("0" + (g || 0).toString(16)).slice(-2)
|
|
550
|
-
b = ("0" + (b || 0).toString(16)).slice(-2)
|
|
551
|
-
return "#" + r + g + b;
|
|
552
|
-
}
|