This commit is contained in:
wujj 2020-07-04 17:49:54 +08:00
parent 297c9a12a1
commit 4325e71164
9 changed files with 30323 additions and 331 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,8 @@
/**
* 兼容ie 重写合并js对象方法
* 在ie浏览器中使用es6 语法"Object.assign()"合并对象报错可以引用该js
*/
if (typeof Object.assign != 'function') {
Object.assign = function(target) {
'use strict';

View File

@ -1,5 +1,5 @@
/**
* 字典
* 字典
* 初始化ms.dict.list("A类型,B类型,C类型","子业务类型")
* 获取值ms.dict.getDictValue("A类型标签") ms.dict.getDictValue("C类型标签",3)
* 获取值ms.dict.getDictLabel("B类型值",2)

View File

@ -1,3 +1,6 @@
/**
* 封装http请求
*/
(function() {
axios.defaults.timeout = 1000 * 60;

View File

@ -1,3 +1,6 @@
/**
* 基础变量定义
*/
(function(window) {
var ms = {
base: null, //主机地址

View File

@ -1,295 +0,0 @@
/**
* 上传js
* 官方插件文档https://www.plupload.com
* 参数方法文档https://www.cnblogs.com/2050/p/3913184.html
*/
(function() {
// 默认支持上传的文件类型
var mimeTypes = {
"image": {
title: "Image files",
extensions: "jpg,JPG,jpeg,PNG,gif,png"
},
"file": {
title: "Zip files",
extensions: "ZIP,zip,DOC,doc,docx,xls,XLS,xlsx,RAR,rar"
},
"video": {
title: "video files",
extensions: "MP3,MP4"
},
"all": {
title: "all files",
extensions: "jpg,JPG,jpeg,PNG,gif,png,ZIP,zip,DOC,doc,docx,xls,XLS,xlsx,RAR,rar"
}
};
/**
* 文件上传
* id: id属性
* {
* url:"", //(可选)默认ms.base + "/file/upload.do"
* mime_types:"image", //(可选)默认图片支持image、file、video、all(表示包含前三种)也可以设置allowedFile参数覆盖
* allowedFile:""//(可选)自定义上传文件后缀例如jpg,gif
* max_file_size:"1mb", //(可选)默认1mb,单位kb,mb,gb,tb注意后端ms.properties文件也有配置上传大小优先上传控件大小
* multi_selection:false, //(可选)默认单文件
* uploadPath:"", //(可选)默认上传upload文件夹下面(如果非upload需要设置uploadFloderPath参数)对应的站点下面例如uload/1/xxxxx.jpg
* uploadFloderPath:"", //(可选)自定义上传文件夹路径,最终文件路径格式 uploadFloderPath/uploadPath/xxxxxx.jpg,注意这里的uploadPath已经没有了upload文件夹与站点id
* diyPath:"", //(可选)自定义上传文件夹路径,可以定义盘符路径
* isRename:true,//(可选)文件重命名,默认根据时间命名
* fileFiltered:function //每次选择一个文件都会触发
* filesAdded:function //每次选择好文件后都会触发
* beforeUpload:function //上传文件之前触发,确认上传 业务的情况下有用
* uploadProgress:function //处理进度条
* fileUploaded:function //必填上传成功返回主要会用到第三个参数的response这个值是上传成功后返回的数据
* }
*/
function upload(id, cfg) {
var uploadCfg = {
url: basePath+"/file/upload.do",
mime_types: mimeTypes["image"],
max_file_size: "1mb",
multi_selection: false,
uploadPath: "",
diyPath:"",
uploadFloderPath: "",
chunk: "",
chunks: "",
prevent_duplicates: true,
isRename: true,
fileFiltered: function(uploader, file) {},
filesAdded: function(uploader, files) {},
beforeUpload: function(uploader, file) {},
uploadProgress: function(uploader, file) {},
fileUploaded: function(uploader, file, responseObject) {},
error: function(uploader, errObject) {
if (errObject.code == -600) {
$('.ms-notifications').offset({top:43}).notify({
type:'warning',
message: { text:errObject.file.name + "文件超过" +
uploadCfg.max_file_size + "大小" }
}).show();
} else if (errObject.code == -601) {
$('.ms-notifications').offset({top:43}).notify({
type:'warning',
message: { text:errObject.file.name + "格式错误" }
}).show();
} else if (errObject.code == -700) {
$('.ms-notifications').offset({top:43}).notify({
type:'warning',
message: { text:errObject.file.name + "格式错误"}
}).show();
} else if (errObject.code == -300) {
$('.ms-notifications').offset({top:43}).notify({
type:'warning',
message: { text:errObject.file.name + "发生磁盘读写错误时的错误代码,例如本地上某个文件不可读"}
}).show();
} else if (errObject.code == -602) {
$('.ms-notifications').offset({top:43}).notify({
type:'warning',
message: { text:errObject.file.name + "文件已上传过,不能重复上传。"}
}).show();
} else if (errObject.code == -702) {
$('.ms-notifications').offset({top:43}).notify({
type:'warning',
message: { text:errObject.file.name + "文件网页上传不支持,太大的文件请通过其他途径上传。"}
}).show();
} else {
$('.ms-notifications').offset({top:43}).notify({
type:'warning',
message: { text:errObject.code + errObject.file.name}
}).show();
}
},
};
var multipart_params = {}; // 上传表单参数
multipart_params.maxSize = calculationMaxSize();
multipart_params.allowedFile = uploadCfg.mime_types.extensions;
// 判断cfg是否为json格式不是则将默认参数传给cfg
if (cfg != undefined && validator.isJSON(JSON.stringify(cfg))) {
// 重新定义后台上传路径
if (cfg.url != undefined && cfg.url != "") {
uploadCfg.url = cfg.url;
}
// 允许上传的后缀
if (cfg.allowedFile != undefined && cfg.allowedFile != "") {
uploadCfg.mime_types =
{
title: "all files",
extensions: cfg.allowedFile
};
multipart_params.allowedFile = cfg.allowedFile;
}
//组织后台需要的参数
if (cfg.max_file_size != undefined && cfg.max_file_size != "") {
uploadCfg.max_file_size = cfg.max_file_size;
multipart_params.maxSize = calculationMaxSize();
}
if (cfg.path != undefined && cfg.path != "") {
uploadCfg.uploadPath = cfg.path;
multipart_params.uploadPath = cfg.path;
}
if (cfg.diyPath != undefined && cfg.diyPath != "") {
uploadCfg.diyPath = cfg.diyPath;
multipart_params.diyPath = cfg.diyPath;
}
if (cfg.uploadFloderPath != undefined && cfg.uploadFloderPath != "") {
uploadCfg.uploadFloderPath = cfg.uploadFloderPath;
multipart_params.uploadFloderPath = cfg.uploadFloderPath;
}
if (cfg.chunk != undefined && cfg.chunk != "") {
multipart_params.chunk = cfg.chunk;
}
if (cfg.chunks != undefined && cfg.chunks != "") {
multipart_params.chunks = cfg.chunks;
}
if (cfg.name != undefined && cfg.name != "") {
multipart_params.name = cfg.name;
}
if (cfg.isRename != undefined) {
multipart_params.isRename = cfg.isRename;
}
if (cfg.multi_selection != undefined ) {
uploadCfg.multi_selection = cfg.multi_selection;
}
if (cfg.prevent_duplicates != undefined) {
uploadCfg.prevent_duplicates = cfg.prevent_duplicates;
}
//回调事件
if (cfg.fileUploaded != undefined && cfg.fileUploaded != "") {
uploadCfg.fileUploaded = cfg.fileUploaded;
}
if (cfg.filesAdded != undefined && cfg.filesAdded != "") {
uploadCfg.filesAdded = cfg.filesAdded;
}
if (cfg.fileFiltered != undefined && cfg.fileFiltered != "") {
uploadCfg.fileFiltered = cfg.fileFiltered;
}
if (cfg.beforeUpload != undefined && cfg.beforeUpload != "") {
uploadCfg.beforeUpload = cfg.beforeUpload;
}
if (cfg.uploadProgress != undefined && cfg.uploadProgress != "") {
uploadCfg.uploadProgress = cfg.uploadProgress;
}
if (cfg.error != undefined && cfg.error != "") {
uploadCfg.error = cfg.error;
}
}
// 实例化一个plupload上传对象
var uploader = new plupload.Uploader({
browse_button: id, // 预览按钮元素
url: uploadCfg.url, // 上传地址
flash_swf_url: 'js/Moxie.swf',
silverlight_xap_url: 'js/Moxie.xap',
multi_selection: uploadCfg.multi_selection, // 禁止浏览框多选
multipart_params: multipart_params,
filters: { // 文件类型 大小设置,对不同场景的文件上传配置此参数
mime_types: [uploadCfg.mime_types],
max_file_size: uploadCfg.max_file_size, // 最大只能上传400kb的文件
prevent_duplicates: uploadCfg.prevent_duplicates //布尔类型
// 不允许选取重复文件
},
});
uploader.init();
/**
* 选择了多少文件就会触发多少次
*uploader为当前的plupload实例对象file为触发此事件的文件对象
*/
uploader.bind('FileFiltered', function(uploader, file) {
eval(uploadCfg.fileFiltered(uploader, file));
});
/**
* 当文件添加到上传队列后触发
* uploader为当前的plupload实例对象files为一个数组里面的元素为本次添加到上传队列里的文件对象
* 每一次选择文件都会触发不管选择多个文件还是单个文件都只会触发一次
*/
uploader.bind('FilesAdded', function(uploader, files) {
eval(uploadCfg.filesAdded(uploader, files));
});
/**
* 当队列中的某一个文件正要开始上传前触发
* uploader为当前的plupload实例对象file为触发此事件的文件对象
*/
uploader.bind('BeforeUpload', function(uploader, file) {
eval(uploadCfg.beforeUpload(uploader, file));
});
/**
* 会在文件上传过程中不断触发可以用此事件来显示上传进度
* uploader为当前的plupload实例对象file为触发此事件的文件对象
*/
uploader.bind('UploadProgress', function(uploader, file) {
eval(uploadCfg.uploadProgress(uploader, file));
});
/**
* 当队列中的某一个文件上传完成后触发监听函数参数(uploader,file,responseObject)
* uploader为当前的plupload实例对象
* file为触发此事件的文件对象
* responseObject为服务器返回的信息对象它有以下3个属性
* response服务器返回的文本
* responseHeaders服务器返回的头信息
* status服务器返回的http状态码比如200
*/
uploader.bind('FileUploaded', function(uploader, file, responseObject) {
eval(uploadCfg.fileUploaded(uploader, file, responseObject));
});
/**
* 当发生错误时触发监听函数参数(uploader,errObject)
* uploader为当前的plupload实例对象
* errObject为错误对象它至少包含以下3个属性(因为不同类型的错误属性可能会不同)
* code错误代码具体请参考plupload上定义的表示错误代码的常量属性
* file与该错误相关的文件对象
* message错误信息
*/
uploader.bind('Error', function(uploader, errObject) {
eval(uploadCfg.error(uploader, errObject));
});
/**
* 计算后台的上传大小因为前端上传空间与后端的大小单位不一致
*/
function calculationMaxSize() {
var size = parseInt(uploadCfg.max_file_size);
if (uploadCfg.max_file_size.indexOf("kb") > -1) {
return parseInt(size) / 1024;
} else if (uploadCfg.max_file_size.indexOf("mb") > -1) {
return size;
} else if (uploadCfg.max_file_size.indexOf("gb") > -1) {
return size * 1024;
} else if (uploadCfg.max_file_size.indexOf("tb") > -1) {
return size * 1024 * 1024;
}
}
return uploader;
}
if (ms == undefined) {
ms = {};
}
window.ms.upload = upload;
}());

View File

@ -1,5 +1,5 @@
/**
* 通用工具
* 通用工具方法
*/
(function() {
@ -55,8 +55,14 @@
}
return true;
}
/**
* 数字转金额
* */
function moneyFormatter(cellValue) {
return accounting.formatMoney(cellValue, '¥',2)
}
//日期处理
//日期工具
var date = {
//格式化时间
fmt: function(de, fmt) {
@ -106,6 +112,7 @@
}
}
//数组工具
var array = {
//根据key清理arr里面重复的值
@ -132,16 +139,8 @@
}
}
return result;
},
//根据pro属性与value移除arr对应的值
remove: function(arr, attr, value) {
for (var j = 0; j < arr.length; j++) {
if (arr[j][attr] == value) {
arr.splice(j, 1);
break;
}
}
}
}
var convert = {
@ -204,7 +203,10 @@
}
}
/**
* window.sessionStorage方法封装
* @type {{set: set, get: (function(*=): string), remove: remove}}
*/
var store = {
set: function(key, value) {
window.sessionStorage.setItem(key, value);
@ -217,19 +219,137 @@
}
}
var cookie = {
/**
*
* 引入js-xlsx/xlsx.full.min.js
* @param dom dom 数据对象
* @param fileName 文件名
* @param data 数据
* @param format
* var tableNead = {
column:[
{filed: "projectName",label:"项目名称",width:50},
{filed: "managerNickName",label:"成员名称",width:50},
{filed: "pdmType",label:"种类",width:50,dictDataOptions: []},
{filed: "pdmMoney",label:"收入金额",width:50},
],
countFiled:["pdmMoney"],
};
* @returns {*}
*/
function exportTable(dom, fileName, data,format) {
/* 从表生成工作簿对象 */
var wb = XLSX.utils.table_to_book(dom);
var columnWidth = [];
var table = [];
var tableHead = [];
//初始化头部字段
format.column.forEach(function (value) {
tableHead.push(value.label);
columnWidth.push({
"wpx": value.width
});
});
table.push(tableHead);
var tableFoot = new Array(format.column.length);
}
//遍历,将数据整理重新返回
data.map(function (x) {
var a = [];
//遍历中设定需要的那些字段数据
format.column.forEach(function (value) {
if (x.hasOwnProperty(value.filed)){
//替换字典数据
if (value.dictDataOptions != undefined && value.dictDataOptions.length > 0){
//遍历字典数据,有就替换
var dict = value.dictDataOptions.find(function (val) {
return x[value.filed] == val.dictValue;
})
a.push(dict?dict.dictLabel:"");
}else {
a.push(x[value.filed]);
if (format.countFiled != undefined && format.countFiled.indexOf(value.filed) >= 0) {
tableFoot[0] = '总计';
format.column.findIndex(function (value1, index) {
if (value1.filed == value.filed){
tableFoot[index] = tableFoot[index] == undefined ? x[value.filed] : tableFoot[index] + x[value.filed];
}
});
}
}
}else {
a.push("");
}
});
return a
}).forEach(function (v, i) {
// 遍历整理后的数据加入table
table.push(v)
});
table.push(tableFoot);
var sheet = XLSX2.utils.aoa_to_sheet(table);
wb.Sheets.Sheet1 = sheet;
wb.Sheets.Sheet1['!cols'] = columnWidth;
/* 获取二进制字符串作为输出 */
var wbout = XLSX.write(wb, {
bookType: 'xlsx',
bookSST: true,
type: "array"
});
try {
//保存文件
saveAs(
//Blob 对象表示一个不可变、原始数据的类文件对象。
//Blob 表示的不一定是JavaScript原生格式的数据。
//File 接口基于Blob继承了 blob 的功能并将其扩展使其支持用户系统上的文件。
//返回一个新创建的 Blob 对象,其内容由参数中给定的数组串联组成。
new Blob([wbout], {type: "application/octet-stream"}),
//设置导出文件名称
fileName + '.xlsx'
);
} catch (e) {
if (typeof console !== "undefined") console.log(e, wbout);
}
return wbout;
};
/**
* 打印方法
* @param name 模板的名字
* @param data 需要绑定的数据
*/
function printFile(name,data){
if (name != "" && name != null && name != undefined){
ms.http.get(ms.manager+ "/mprint/printTemplate/get.do", {
name: name
}).then(function (res) {
if(data != null && data != undefined && res.data != null){
printVue.open(res.data,data);
}else {
console.error("未定义数据,或没有模板数据");
}
}).catch(function (err) {
console.log(err);
});
}else {
console.error("未定义模板名称");
}
};
var util = {
getParameter: getParameter,
treeData:treeData,
childValidate:childValidate,
moneyFormatter:moneyFormatter,
date: date,
array: array,
log: log,
convert: convert,
store: store,
exportTable:exportTable,
printFile:printFile,
}

View File

@ -1,25 +1,8 @@
/**
* vue 扩展属性方法
* 表格中的数字需要格式化金钱类型或百分数
*/
(function() {
Vue.prototype.$uploadEvents={
success:function(res,file, fileList) {
file.url = ms.base+res;
this.push(file);
},
preview:function(file) {
window.open(file.url)
},
remove:function(file, fileList) {
var index = -1;
index = (void 0).findIndex(function (text) {
return text == file;
});
if (index != -1) {
this.splice(index, 1);
}
},
exceed:function(file, fileList) {
Vue.prototype.$notify({ title: '当前最多上传'+this.length+'个附件', type: 'warning' });
},
}
Vue.prototype.$table = {}
Vue.prototype.$table.moneyFormatter = function (row, column, cellValue, index) {
if (cellValue != undefined) {