/**
 * CMS后台公共JS
 * 通用工具函数
 */

// 通用 AJAX 封装
function postJSON(url, data) {
    return fetch(url || '', {
        method: 'POST',
        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
        body: new URLSearchParams(data)
    }).then(res => {
        if (!res.ok) throw new Error('HTTP ' + res.status);
        return res.json();
    });
}

// 通用提示
function showToast(msg, type) {
    type = type || 'info';
    var colors = {success:'#28a745',error:'#dc3545',warning:'#ffc107',info:'#17a2b8'};
    var el = document.createElement('div');
    el.style.cssText = 'position:fixed;top:20px;right:20px;padding:12px24px;background:'+colors[type]+';color:#fff;border-radius:4px;z-index:9999;font-size:14px;';
    el.textContent = msg;
    document.body.appendChild(el);
    setTimeout(function(){el.remove()},3000);
}
