120 lines
4.0 KiB
JavaScript
120 lines
4.0 KiB
JavaScript
//jquery全局配置
|
||
// $.ajaxSetup({
|
||
// cache: false,
|
||
// // crossDomain: true,
|
||
// // headers: { 'Authorization': token },
|
||
// complete: function (xhr) {
|
||
// if (xhr && xhr.status == 401) {
|
||
// console.log(xhr);
|
||
// layer.alert('权限不足,请重新登陆', {
|
||
// icon: 5,
|
||
// title: "提示"
|
||
// }, function () {
|
||
// window.parent.location.reload(); //刷新父页面
|
||
// window.parent.location.href = "/";
|
||
// });
|
||
// }
|
||
// }
|
||
// });
|
||
//图片预览,传url
|
||
function previewPicture(url) {
|
||
layer.photos({
|
||
photos: {
|
||
"title": '预览图',
|
||
"id": 222,
|
||
"start": 0,
|
||
"data": [{
|
||
"src": url
|
||
}]
|
||
}
|
||
// ,closeBtn: 1 //是否显示关闭按钮
|
||
});
|
||
}
|
||
// 设置图片信息
|
||
function setImgUrl(url) {
|
||
return 'https://school-1251542740.cos.ap-shanghai.myqcloud.com/' + url;
|
||
}
|
||
|
||
//视频预览,传url,width,height
|
||
function previewVideo(url, width, height) {
|
||
width = width ? width : '65%';
|
||
height = height ? height : '65%';
|
||
let content = '<video width="100%" height="90%" controls="controls" autobuffer="autobuffer" autoplay="autoplay" loop="loop">' +
|
||
'<source src="' + url + '" type="video/mp4"></source></video>';
|
||
layer.open({
|
||
type: 1,
|
||
maxmin: true, //打开放大缩小按钮
|
||
title: '视频播放',
|
||
area: [width, height],
|
||
content: content,
|
||
});
|
||
}
|
||
|
||
//文件预览
|
||
function previewFile(url) {
|
||
window.location.href = url;
|
||
}
|
||
|
||
function trim(str) {
|
||
if (str == null) {
|
||
return "";
|
||
}
|
||
return str.replace(/^\s*(.*?)[\s\n]*$/g, '$1');
|
||
}
|
||
|
||
function dataURItoBlob(dataURI) {
|
||
var byteString = atob(dataURI.split(',')[0]); //base64 解码
|
||
var arrayBuffer = new ArrayBuffer(byteString.length); //创建缓冲数组
|
||
var intArray = new Uint8Array(arrayBuffer); //创建视图
|
||
for (var i = 0; i < byteString.length; i++) {
|
||
intArray[i] = byteString.charCodeAt(i);
|
||
}
|
||
// return new Blob([intArray],{type: "application/vnd.ms-excel;charset=utf-8;"});//原来封装好的 下载的是excel
|
||
return new Blob([intArray], { type: "application/octet-stream;charset=utf-8;" });//修改-1
|
||
}
|
||
|
||
function saveData(data, filename) {
|
||
let blob = dataURItoBlob(data)
|
||
let objectUrl = URL.createObjectURL(blob);
|
||
//let spl = filename.split(".");
|
||
//window.open(objectUrl,'_blank','alwaysRaised=yes,height=500, width=800, toolbar= no, menubar=no, scrollbars=no, resizable=no, location=yes, status=no,top=100,left=300')
|
||
let aLink = document.createElement('a');//新添加的 尝试
|
||
let evt = document.createEvent("HTMLEvents");
|
||
evt.initEvent("click", true, true);
|
||
aLink.download = filename;//新添加的 尝试
|
||
aLink.href = objectUrl;
|
||
aLink.click()
|
||
//没有清理的 DOM 元素引用
|
||
//document.body.removeChild(aLink)
|
||
}
|
||
|
||
function getCurrentYearStart() {
|
||
const currentDate = new Date();
|
||
return new Date(currentDate.getFullYear(), 0, 1, 0, 0, 0, 0);
|
||
}
|
||
|
||
function formatDate(date, format) {
|
||
const year = date.getFullYear();
|
||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||
const day = String(date.getDate()).padStart(2, '0');
|
||
const hours = String(date.getHours()).padStart(2, '0');
|
||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||
const seconds = String(date.getSeconds()).padStart(2, '0');
|
||
|
||
return format
|
||
.replace('YYYY', year)
|
||
.replace('MM', month)
|
||
.replace('DD', day)
|
||
.replace('HH', hours)
|
||
.replace('mm', minutes)
|
||
.replace('ss', seconds);
|
||
}
|
||
|
||
function getCurrentMonthEnd() {
|
||
const currentDate = new Date();
|
||
const currentYear = currentDate.getFullYear();
|
||
const currentMonth = currentDate.getMonth();
|
||
const lastDayOfMonth = new Date(currentYear, currentMonth + 1, 0);
|
||
const lastDate = lastDayOfMonth.getDate();
|
||
return new Date(currentYear, currentMonth, lastDate, 23, 59, 59, 999);
|
||
} |