|
|
@@ -7,15 +7,15 @@ const previewUrl = import.meta.env.VITE_PREVIEW_URL
|
|
|
const u = {
|
|
|
url: {
|
|
|
file: fileUrl,
|
|
|
- server:serverUrl,
|
|
|
- preview:previewUrl
|
|
|
+ server: serverUrl,
|
|
|
+ preview: previewUrl
|
|
|
},
|
|
|
- dialog:{
|
|
|
- actions:{
|
|
|
- 'add':{title:'新增',btn:'创建'},
|
|
|
- 'del':{title:'删除',btn:'确定'},
|
|
|
- 'edit':{title:'修改',btn:'修改'},
|
|
|
- 'view':{title:'详情',btn:'确定'},
|
|
|
+ dialog: {
|
|
|
+ actions: {
|
|
|
+ 'add': {title: '新增', btn: '创建'},
|
|
|
+ 'del': {title: '删除', btn: '确定'},
|
|
|
+ 'edit': {title: '修改', btn: '修改'},
|
|
|
+ 'view': {title: '详情', btn: '确定'},
|
|
|
},
|
|
|
},
|
|
|
/**
|
|
|
@@ -34,14 +34,31 @@ const u = {
|
|
|
// Return the RGB values as an object
|
|
|
return {r, g, b};
|
|
|
},
|
|
|
-
|
|
|
+ distinctByKey(elements: Array<any>, key: string) {
|
|
|
+ let result:any[] = [];
|
|
|
+ let keys:Array<string> = [];
|
|
|
+ if (!elements || elements.length === 0) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ for (let i = 0; i < elements.length; i++) {
|
|
|
+ if (!elements[i][key] && elements[i][key] !== 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ let k = elements[i][key].toString();
|
|
|
+ if(!keys.includes(k)){
|
|
|
+ result.push(elements[i]);
|
|
|
+ keys.push(k);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ },
|
|
|
groupByKey(elements: Array<any>, key: string) {
|
|
|
let map = {};
|
|
|
if (!elements || elements.length === 0) {
|
|
|
return map;
|
|
|
}
|
|
|
for (let i = 0; i < elements.length; i++) {
|
|
|
- if(!elements[i][key]&&elements[i][key]!==0){
|
|
|
+ if (!elements[i][key] && elements[i][key] !== 0) {
|
|
|
continue;
|
|
|
}
|
|
|
let k = elements[i][key].toString();
|
|
|
@@ -85,10 +102,10 @@ const u = {
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- toMap(elements: Array<any>, fn:Function) {
|
|
|
+ toMap(elements: Array<any>, fn: Function) {
|
|
|
let ret = {};
|
|
|
- elements.forEach(item=>{
|
|
|
- let key = fn.apply(null,[item]);
|
|
|
+ elements.forEach(item => {
|
|
|
+ let key = fn.apply(null, [item]);
|
|
|
ret[key] = item;
|
|
|
})
|
|
|
return ret;
|
|
|
@@ -443,7 +460,7 @@ const u = {
|
|
|
}
|
|
|
return t;
|
|
|
},
|
|
|
- end(time:Date, type = 'day') {
|
|
|
+ end(time: Date, type = 'day') {
|
|
|
let t: Date = time || new Date();
|
|
|
let year = t.getFullYear(), month = t.getMonth(), day = t.getDate()
|
|
|
switch (type) {
|
|
|
@@ -473,7 +490,7 @@ const u = {
|
|
|
},
|
|
|
validator: {
|
|
|
required: {required: true, message: "必填项", trigger: 'blur'},
|
|
|
- requiredEnum: {type:'number',min: 1, message: "必选项", trigger: 'blur'}, //字典类的校验规则
|
|
|
+ requiredEnum: {type: 'number', min: 1, message: "必选项", trigger: 'blur'}, //字典类的校验规则
|
|
|
verifyCode: {required: true, message: "请输入验证码", trigger: 'blur'},
|
|
|
rangeDate: {type: 'array', length: 2, required: true, message: "必选项"},
|
|
|
lengthMax2: {type: 'string', max: 2, message: "最多2个字"},
|
|
|
@@ -491,31 +508,35 @@ const u = {
|
|
|
negativeInt: {type: 'number', max: -1, message: "必须为负数"},
|
|
|
mobile: {type: 'string', length: 11, max: 11, pattern: '^[1][3,4,5,7,8][0-9]{9}$', message: "11位数字手机号格式错误"},
|
|
|
email: {type: 'email', min: 6, pattern: '^(\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$', message: "邮箱格式错误"},
|
|
|
- password: { min: 8,message: "请输入8位密码", trigger: 'blur'},
|
|
|
+ password: {min: 8, message: "请输入8位密码", trigger: 'blur'},
|
|
|
// password: {type: 'string', min: 6, max: 12, pattern: '(\\w){6,12}', message: '格式为6-12位数字字母组合'},
|
|
|
idNo: {type: 'string', pattern: '(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X)$)', message: '身份证号码格式错误'},
|
|
|
chinese: {type: 'string', pattern: '^[\\u4e00-\\u9fa5]{0,}$', message: '请输入中文字符'},
|
|
|
num: {type: 'string', pattern: /^\d*$/, message: "只能输入数字"},
|
|
|
letter: {type: 'string', pattern: /^[A-Za-z0-9\-]$/, message: "只能输入字母和数字"},
|
|
|
tel: {type: 'string', pattern: /^[-\d]*$/, message: "电话只能包含数字和-"},
|
|
|
- url: {type: 'string', pattern: /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/, message: "链接地址错误"},
|
|
|
+ url: {
|
|
|
+ type: 'string',
|
|
|
+ pattern: /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/,
|
|
|
+ message: "链接地址错误"
|
|
|
+ },
|
|
|
},
|
|
|
fmt: {
|
|
|
- fmtMoney:function (money:number) {
|
|
|
- if(!money){
|
|
|
+ fmtMoney: function (money: number) {
|
|
|
+ if (!money) {
|
|
|
return "0.00";
|
|
|
}
|
|
|
- return ( money/100).toFixed(2);
|
|
|
+ return (money / 100).toFixed(2);
|
|
|
},
|
|
|
fmtUrl: function (v: string) {
|
|
|
let token = Session.get('accessToken')
|
|
|
- if(!v){
|
|
|
+ if (!v) {
|
|
|
return '';
|
|
|
}
|
|
|
if (v.indexOf("http") === 0) {
|
|
|
return v;
|
|
|
}
|
|
|
- console.log(v,fileUrl)
|
|
|
+ console.log(v, fileUrl)
|
|
|
// return fileUrl + v;
|
|
|
return `${fileUrl}${v}`
|
|
|
},
|
|
|
@@ -544,22 +565,22 @@ const u = {
|
|
|
* byte 单位转换
|
|
|
* @param size
|
|
|
*/
|
|
|
- fmtSize(size:number=0){
|
|
|
- if(size<1024){
|
|
|
- return size+'B';
|
|
|
- }
|
|
|
- size = size/ 1024;
|
|
|
- if(size>1024){
|
|
|
- size = size/ 1024;
|
|
|
- if(size>1024){
|
|
|
- size = size/ 1024;
|
|
|
- return size.toFixed(2)+'GB'
|
|
|
- }else{
|
|
|
- return size.toFixed(2)+'MB'
|
|
|
- }
|
|
|
- }else{
|
|
|
- return size.toFixed(2)+'KB'
|
|
|
- }
|
|
|
+ fmtSize(size: number = 0) {
|
|
|
+ if (size < 1024) {
|
|
|
+ return size + 'B';
|
|
|
+ }
|
|
|
+ size = size / 1024;
|
|
|
+ if (size > 1024) {
|
|
|
+ size = size / 1024;
|
|
|
+ if (size > 1024) {
|
|
|
+ size = size / 1024;
|
|
|
+ return size.toFixed(2) + 'GB'
|
|
|
+ } else {
|
|
|
+ return size.toFixed(2) + 'MB'
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return size.toFixed(2) + 'KB'
|
|
|
+ }
|
|
|
},
|
|
|
fmtDateTime(t: any) {
|
|
|
if (t == null) {
|