biliob/Web/js/CommonConfig.js

60 lines
1.7 KiB
JavaScript
Raw Normal View History

2024-10-30 18:27:37 +08:00
var headerModel=0;
function createUi(html){
return fetch(html)
.then(response=>response.text())
.then(htmlText=>{
return htmlText;
})
2024-10-31 18:23:39 +08:00
}
function getParam(name){
console.log(window.location.href)
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results == null) {
return null;
} else {
return decodeURI(results[1]) || 0;
}
}
function showImage(url, imgElement) {
2024-11-21 18:29:19 +08:00
2024-10-31 18:23:39 +08:00
getHttpImage(url)
.then(imageUrl => {
imgElement.src = imageUrl;
})
.catch(error => {
console.log("Error loading image:", error);
// 可以在这里设置一个默认图片或者显示错误信息
});
2024-11-01 00:15:12 +08:00
}
function showTmpImage(url, imgElement) {
2024-11-21 18:29:19 +08:00
console.log(url)
if(!hasString(url)){
imgElement.src='/assets/def.png'
return
}
2024-11-01 00:15:12 +08:00
getHttpTmpImage(url)
.then(blob => {
imgElement.src ="data:image/jpeg;base64,"+blob;
})
.catch(error => {
console.log("Error loading image:", error);
// 可以在这里设置一个默认图片或者显示错误信息
});
2024-11-18 18:27:49 +08:00
}
function hasString(text){
return !!text;
2024-11-21 18:29:19 +08:00
}
function formatDate(timestamp) {
const date = new Date(timestamp);
const padZero = (num) => (num < 10 ? '0' + num : num);
const year = date.getFullYear();
const month = padZero(date.getMonth() + 1);
const day = padZero(date.getDate());
const hours = padZero(date.getHours());
const minutes = padZero(date.getMinutes());
const seconds = padZero(date.getSeconds());
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
2024-10-30 18:27:37 +08:00
}