common.js
3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import Vue from 'vue'
import VueResource from 'vue-resource'
import FileSaver from "file-saver";
import XLSX from "xlsx";
Vue.use(VueResource)
//const httpUrl = 'http://1.1.1.1:8080/'
/**
* 格式化枚举中文显示
* 其中枚举是单个字符
*/
function formatterInfo(value, options) {
if(value==null || value==""){
return "";
}
let res = value;
for (let i = 0; i < options.length; i++) {
if (value == options[i].value) {
res = options[i].label;
break;
}
}
return res;
}
/**
* 格式化枚举类型中文显示
* 其中枚举可能是多个字符
*/
function formatterMoreInfo(value, options) {
if(value==null || value==""){
return "";
}
let res = "";
let arrValue = value.split("");
for (let j = 0; j < arrValue.length; j++) {
let val = arrValue[j];
for (let i = 0; i < options.length; i++) {
if (val == options[i].value) {
res += "," + options[i].label;
break;
}
}
}
if (res == "") {
return value;
} else {
return res.substring(1);
}
}
/**
* 对部分枚举可能值是0开头的,但是表数据不规范的时候,导致01变为1这种情况进行解决
* @param {} value
* @param {*} options
*/
function formatterInfoChangInt(value, options) {
if(value==null || value==""){
return "";
}
let res = value;
for (let i = 0; i < options.length; i++) {
if (parseInt(value) == parseInt(options[i].value)) {
res = options[i].label;
break;
}
}
return res;
}
/**
* 处理图片访问地址的,目的是解决谷歌高版本浏览器不支持ftp协议
* @param {*} path
*/
function imgPathAnalysis(serip,path){
if(path !=null && path != "" && path.length > 10){
var path = path.trim().toLowerCase();
if(path.indexOf("ftp://") == 0){
return serip+"/image/showByByte"+"?ipath="+path;
}else{
return path;
}
}else{
return "";
}
}
function formatDateFun(date, fmt) {
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
}
let o = {
'M+': date.getMonth() + 1,
'd+': date.getDate(),
'h+': date.getHours(),
'm+': date.getMinutes(),
's+': date.getSeconds()
};
for (let k in o) {
if (new RegExp(`(${k})`).test(fmt)) {
let str = o[k] + '';
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str));
}
}
return fmt;
}
function padLeftZero(str) {
return ('00' + str).substr(str.length);
}
function exportExcel(title) {
/* generate workbook object from table */
let wb = XLSX.utils.table_to_book(
document.querySelector("#rebateSetTable")
);
/* get binary string as output */
let wbout = XLSX.write(wb, {
bookType: "xlsx",
bookSST: true,
type: "array"
});
try {
FileSaver.saveAs(
new Blob([wbout], { type: "application/octet-stream" }),
title+".xlsx"
);
} catch (e) {
if (typeof console !== "undefined") console.log(e, wbout);
}
return wbout;
}
function getEndDay(dateType,date) {
let newEndDay=''
switch (dateType){
case "month":{
let dateArr=date.split('-');
var maxDay = new Date(dateArr[0],dateArr[1],0).getDate(); //获取date月最大天数
var selectDate=new Date(Date.parse((date+'-'+maxDay).replace(/-/g,"/")));
var curDate=new Date();
if(selectDate > curDate){
newEndDay=formatDateFun(new Date(),'yyyy-MM-dd')
}else{
newEndDay = date+'-'+maxDay
}
return newEndDay;
}
break;
default:
break;
}
if(dateType=="month"){
}
}
export default {
formatterInfo,
formatterMoreInfo,
formatterInfoChangInt,
imgPathAnalysis,
formatDateFun,
exportExcel,
getEndDay
}