var headerModel=0;

function createUi(html){
   return fetch(html)
    .then(response=>response.text())
    .then(htmlText=>{
        return htmlText;
    })
}
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) {

    getHttpImage(url)
        .then(imageUrl => {
            imgElement.src = imageUrl;
        })
        .catch(error => {
            console.log("Error loading image:", error);
            // 可以在这里设置一个默认图片或者显示错误信息
        });
}
function showTmpImage(url, imgElement) {
     console.log(url)
    if(!hasString(url)){
        imgElement.src='/assets/def.png'
        return
    }
    getHttpTmpImage(url)
        .then(blob => {
            imgElement.src ="data:image/jpeg;base64,"+blob;
        })
        .catch(error => {
            console.log("Error loading image:", error);
            // 可以在这里设置一个默认图片或者显示错误信息
        });
}
function hasString(text){
    return !!text;
}
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}`;
}
function showLoadingDialog(){
    return layer.msg('加载中', {
        icon: 16,
        shade: 0.4
      })
}