Initial project commit
This commit is contained in:
@@ -0,0 +1,496 @@
|
||||
/* ===== Admin Card-Style Layout ===== */
|
||||
|
||||
:root {
|
||||
--admin-primary: #6366f1;
|
||||
--admin-primary-light: rgba(99, 102, 241, 0.08);
|
||||
--admin-success: #22c55e;
|
||||
--admin-danger: #ef4444;
|
||||
--admin-warning: #f59e0b;
|
||||
--admin-radius: 10px;
|
||||
}
|
||||
|
||||
body {
|
||||
background: #f1f5f9 !important;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", sans-serif !important;
|
||||
}
|
||||
|
||||
/* Sidebar */
|
||||
.navbar-vertical {
|
||||
background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%) !important;
|
||||
border-right: none !important;
|
||||
box-shadow: 2px 0 12px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.navbar-vertical .nav-link {
|
||||
border-radius: 8px !important;
|
||||
margin: 2px 8px !important;
|
||||
padding: 8px 12px !important;
|
||||
transition: all 0.2s ease !important;
|
||||
}
|
||||
|
||||
.navbar-vertical .nav-link:hover {
|
||||
background: rgba(99, 102, 241, 0.15) !important;
|
||||
}
|
||||
|
||||
.navbar-vertical .nav-link.active {
|
||||
background: var(--admin-primary) !important;
|
||||
color: #fff !important;
|
||||
}
|
||||
|
||||
/* Page header */
|
||||
.page-header {
|
||||
padding: 16px 0 8px !important;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
font-size: 1.5rem !important;
|
||||
font-weight: 700 !important;
|
||||
color: #1e293b !important;
|
||||
}
|
||||
|
||||
/* Cards */
|
||||
.card {
|
||||
border: none !important;
|
||||
border-radius: var(--admin-radius) !important;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04) !important;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
background: #fff !important;
|
||||
border-bottom: 1px solid #f1f5f9 !important;
|
||||
padding: 16px 20px !important;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-weight: 700 !important;
|
||||
color: #1e293b !important;
|
||||
}
|
||||
|
||||
/* Table styling */
|
||||
.table {
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.table thead th {
|
||||
background: #f8fafc !important;
|
||||
border-bottom: 2px solid #e2e8f0 !important;
|
||||
font-weight: 600 !important;
|
||||
color: #64748b !important;
|
||||
font-size: 13px !important;
|
||||
text-transform: none !important;
|
||||
padding: 12px 16px !important;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.table tbody tr {
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
.table tbody tr:hover {
|
||||
background: var(--admin-primary-light) !important;
|
||||
}
|
||||
|
||||
.table tbody td {
|
||||
padding: 14px 16px !important;
|
||||
vertical-align: middle !important;
|
||||
border-bottom: 1px solid #f1f5f9 !important;
|
||||
font-size: 14px !important;
|
||||
color: #334155 !important;
|
||||
max-width: 300px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/* Action column icons */
|
||||
.table tbody td:nth-child(2) a {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 8px;
|
||||
transition: all 0.2s ease;
|
||||
text-decoration: none !important;
|
||||
}
|
||||
|
||||
.table tbody td:nth-child(2) a:hover {
|
||||
background: #f1f5f9;
|
||||
}
|
||||
|
||||
.table tbody td:nth-child(2) a[title="View"] i,
|
||||
.table tbody td:nth-child(2) a[title="查看"] i {
|
||||
color: var(--admin-primary) !important;
|
||||
}
|
||||
|
||||
.table tbody td:nth-child(2) a[title="Edit"] i,
|
||||
.table tbody td:nth-child(2) a[title="编辑"] i {
|
||||
color: var(--admin-warning) !important;
|
||||
}
|
||||
|
||||
.table tbody td:nth-child(2) a[title="Delete"] i,
|
||||
.table tbody td:nth-child(2) a[title="删除"] i {
|
||||
color: var(--admin-danger) !important;
|
||||
}
|
||||
|
||||
/* Image previews in table */
|
||||
.table img {
|
||||
border-radius: 8px !important;
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
|
||||
transition: transform 0.2s ease;
|
||||
}
|
||||
|
||||
.table img:hover {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
/* Buttons */
|
||||
.btn-primary {
|
||||
background: var(--admin-primary) !important;
|
||||
border-color: var(--admin-primary) !important;
|
||||
border-radius: 8px !important;
|
||||
font-weight: 600 !important;
|
||||
padding: 8px 18px !important;
|
||||
transition: all 0.2s ease !important;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background: #4f46e5 !important;
|
||||
border-color: #4f46e5 !important;
|
||||
box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3) !important;
|
||||
}
|
||||
|
||||
.btn-secondary, .btn-light {
|
||||
border-radius: 8px !important;
|
||||
}
|
||||
|
||||
/* Search bar */
|
||||
#search-input {
|
||||
border-radius: 8px 0 0 8px !important;
|
||||
border: 1px solid #e2e8f0 !important;
|
||||
padding: 8px 14px !important;
|
||||
}
|
||||
|
||||
#search-input:focus {
|
||||
border-color: var(--admin-primary) !important;
|
||||
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12) !important;
|
||||
}
|
||||
|
||||
#search-button {
|
||||
border-radius: 0 8px 8px 0 !important;
|
||||
background: var(--admin-primary) !important;
|
||||
color: #fff !important;
|
||||
border: 1px solid var(--admin-primary) !important;
|
||||
}
|
||||
|
||||
#search-reset {
|
||||
border-radius: 0 !important;
|
||||
}
|
||||
|
||||
/* Pagination */
|
||||
.card-footer {
|
||||
background: #fff !important;
|
||||
padding: 14px 20px !important;
|
||||
border-top: 1px solid #f1f5f9 !important;
|
||||
}
|
||||
|
||||
.page-item.active .page-link {
|
||||
background: var(--admin-primary) !important;
|
||||
border-color: var(--admin-primary) !important;
|
||||
}
|
||||
|
||||
.page-link {
|
||||
border-radius: 6px !important;
|
||||
margin: 0 2px !important;
|
||||
}
|
||||
|
||||
/* Form styling */
|
||||
.form-control, .form-select {
|
||||
border-radius: 8px !important;
|
||||
border: 1px solid #e2e8f0 !important;
|
||||
padding: 10px 14px !important;
|
||||
}
|
||||
|
||||
.form-control:focus, .form-select:focus {
|
||||
border-color: var(--admin-primary) !important;
|
||||
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12) !important;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
font-weight: 600 !important;
|
||||
color: #475569 !important;
|
||||
font-size: 13px !important;
|
||||
margin-bottom: 6px !important;
|
||||
}
|
||||
|
||||
/* Detail page */
|
||||
.table-bordered td, .table-bordered th {
|
||||
border-color: #f1f5f9 !important;
|
||||
}
|
||||
|
||||
/* Select2 */
|
||||
.select2-container--default .select2-selection--single {
|
||||
border-radius: 8px !important;
|
||||
border: 1px solid #e2e8f0 !important;
|
||||
height: 42px !important;
|
||||
padding: 6px 8px !important;
|
||||
}
|
||||
|
||||
/* Checkbox styling */
|
||||
.form-check-input:checked {
|
||||
background-color: var(--admin-primary) !important;
|
||||
border-color: var(--admin-primary) !important;
|
||||
}
|
||||
|
||||
/* Filter sidebar */
|
||||
#filter-sidebar {
|
||||
border-radius: var(--admin-radius) !important;
|
||||
}
|
||||
|
||||
#filter-sidebar .card-header {
|
||||
background: #f8fafc !important;
|
||||
}
|
||||
|
||||
/* Dropdown menus */
|
||||
.dropdown-menu {
|
||||
border-radius: 10px !important;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12) !important;
|
||||
border: 1px solid #e2e8f0 !important;
|
||||
padding: 6px !important;
|
||||
}
|
||||
|
||||
.dropdown-item {
|
||||
border-radius: 6px !important;
|
||||
padding: 8px 14px !important;
|
||||
}
|
||||
|
||||
.dropdown-item:hover {
|
||||
background: var(--admin-primary-light) !important;
|
||||
color: var(--admin-primary) !important;
|
||||
}
|
||||
|
||||
/* Modal */
|
||||
.modal-content {
|
||||
border-radius: 14px !important;
|
||||
border: none !important;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2) !important;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
border-bottom: 1px solid #f1f5f9 !important;
|
||||
padding: 20px 24px !important;
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
border-top: 1px solid #f1f5f9 !important;
|
||||
padding: 16px 24px !important;
|
||||
}
|
||||
|
||||
/* Login page */
|
||||
.vh-100 {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
||||
}
|
||||
|
||||
.vh-100 .card {
|
||||
border-radius: 16px !important;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2) !important;
|
||||
}
|
||||
|
||||
/* Responsive table: wrap long text in smaller screens */
|
||||
@media (max-width: 1200px) {
|
||||
.table-responsive {
|
||||
overflow-x: auto;
|
||||
}
|
||||
}
|
||||
|
||||
/* Boolean columns: style True/False */
|
||||
td:has(> .fa-check),
|
||||
td:has(> .fa-times) {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Smooth scrollbar */
|
||||
::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: #cbd5e1;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: #94a3b8;
|
||||
}
|
||||
|
||||
/* Logout button */
|
||||
.btn-icon {
|
||||
border-radius: 8px !important;
|
||||
transition: all 0.2s ease !important;
|
||||
}
|
||||
|
||||
.btn-icon:hover {
|
||||
background: rgba(239, 68, 68, 0.15) !important;
|
||||
border-color: transparent !important;
|
||||
color: var(--admin-danger) !important;
|
||||
}
|
||||
|
||||
/* ===== Image Picker Widget ===== */
|
||||
.image-picker-wrapper {
|
||||
padding: 12px 0;
|
||||
}
|
||||
|
||||
.image-picker-preview {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
margin-bottom: 10px;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.10);
|
||||
}
|
||||
|
||||
.image-picker-preview img {
|
||||
display: block;
|
||||
max-width: 200px;
|
||||
max-height: 200px;
|
||||
object-fit: cover;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.image-picker-remove {
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
right: 4px;
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
background: rgba(0,0,0,0.55);
|
||||
color: #fff;
|
||||
font-size: 16px;
|
||||
line-height: 26px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.image-picker-remove:hover {
|
||||
background: var(--admin-danger);
|
||||
}
|
||||
|
||||
.image-picker-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.image-picker-actions .btn {
|
||||
border-radius: 8px !important;
|
||||
font-size: 13px !important;
|
||||
padding: 6px 14px !important;
|
||||
}
|
||||
|
||||
/* ===== Image Picker Modal ===== */
|
||||
.ip-modal-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0,0,0,0.5);
|
||||
z-index: 99999;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
|
||||
.ip-modal {
|
||||
background: #fff;
|
||||
border-radius: 16px;
|
||||
width: 90vw;
|
||||
max-width: 900px;
|
||||
max-height: 80vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-shadow: 0 20px 60px rgba(0,0,0,0.25);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.ip-modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 18px 24px;
|
||||
border-bottom: 1px solid #f1f5f9;
|
||||
}
|
||||
|
||||
.ip-modal-header h3 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
color: #1e293b;
|
||||
}
|
||||
|
||||
.ip-modal-header-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.ip-modal-body {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 20px 24px;
|
||||
}
|
||||
|
||||
.ip-gallery {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.ip-gallery-item {
|
||||
cursor: pointer;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
border: 2px solid transparent;
|
||||
transition: all 0.2s ease;
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
||||
.ip-gallery-item:hover {
|
||||
border-color: var(--admin-primary);
|
||||
box-shadow: 0 4px 12px rgba(99,102,241,0.2);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.ip-gallery-item img {
|
||||
width: 100%;
|
||||
height: 120px;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.ip-gallery-name {
|
||||
padding: 4px 8px;
|
||||
font-size: 11px;
|
||||
color: #64748b;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.ip-loading,
|
||||
.ip-empty {
|
||||
text-align: center;
|
||||
padding: 40px 0;
|
||||
color: #94a3b8;
|
||||
font-size: 15px;
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
var map = {
|
||||
"Actions": "批量操作",
|
||||
"Export": "导出",
|
||||
"Search": "搜索",
|
||||
"Filters": "筛选",
|
||||
"Apply Filter": "应用筛选",
|
||||
"Select operation...": "选择操作...",
|
||||
"Enter value": "输入值",
|
||||
"Showing": "显示第",
|
||||
"items": "条",
|
||||
"prev": "上一页",
|
||||
"next": "下一页",
|
||||
"/ Page": "条/页",
|
||||
"Show": "每页",
|
||||
"Delete selected items": "删除选中项",
|
||||
"View": "查看",
|
||||
"Edit": "编辑",
|
||||
"Delete": "删除",
|
||||
"Save": "保存",
|
||||
"Submit": "提交",
|
||||
"Cancel": "取消",
|
||||
"Back": "返回",
|
||||
"Create": "新建",
|
||||
"Are you sure?": "确定执行此操作吗?",
|
||||
"Go Back": "返回列表",
|
||||
"Continue Editing": "继续编辑",
|
||||
"Save and Add Another": "保存并新增",
|
||||
"Save and Continue Editing": "保存并继续编辑",
|
||||
"Details": "详情",
|
||||
"Logout": "退出登录",
|
||||
"Login": "登录",
|
||||
"Username": "用户名",
|
||||
"Password": "密码",
|
||||
"Login to": "登录",
|
||||
"[Clear]": "[清除]",
|
||||
};
|
||||
|
||||
function translateNode(node) {
|
||||
if (node.nodeType === 3) {
|
||||
var text = node.textContent;
|
||||
if (!text || !text.trim()) return;
|
||||
var trimmed = text.trim();
|
||||
if (map[trimmed]) {
|
||||
node.textContent = text.replace(trimmed, map[trimmed]);
|
||||
}
|
||||
for (var en in map) {
|
||||
if (trimmed.indexOf(en) !== -1) {
|
||||
node.textContent = node.textContent.replace(en, map[en]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function walk(el) {
|
||||
var children = el.childNodes;
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var child = children[i];
|
||||
if (child.nodeType === 3) {
|
||||
translateNode(child);
|
||||
} else if (child.nodeType === 1) {
|
||||
if (child.tagName === "SCRIPT" || child.tagName === "STYLE") continue;
|
||||
if (child.placeholder) {
|
||||
for (var en in map) {
|
||||
if (child.placeholder === en) child.placeholder = map[en];
|
||||
}
|
||||
}
|
||||
if (child.title) {
|
||||
for (var en2 in map) {
|
||||
if (child.title === en2) child.title = map[en2];
|
||||
}
|
||||
}
|
||||
walk(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
walk(document.body);
|
||||
|
||||
// Translate "+ New XXX" buttons
|
||||
document.querySelectorAll("a.btn-primary").forEach(function (a) {
|
||||
var t = a.textContent.trim();
|
||||
if (t.startsWith("+ New ")) {
|
||||
a.textContent = "+ 新建" + t.replace("+ New ", "");
|
||||
}
|
||||
});
|
||||
|
||||
// Translate "Showing X to Y of Z items" to Chinese format
|
||||
document.querySelectorAll(".card-footer .text-muted").forEach(function (el) {
|
||||
var m = el.textContent.match(/显示第\s*(\d+)\s*to\s*(\d+)\s*of\s*(\d+)\s*条/);
|
||||
if (m) {
|
||||
el.innerHTML = "显示第 <span>" + m[1] + "</span> 至 <span>" + m[2] + "</span> 条,共 <span>" + m[3] + "</span> 条";
|
||||
}
|
||||
var m2 = el.textContent.match(/Showing\s*(\d+)\s*to\s*(\d+)\s*of\s*(\d+)\s*items/);
|
||||
if (m2) {
|
||||
el.innerHTML = "显示第 <span>" + m2[1] + "</span> 至 <span>" + m2[2] + "</span> 条,共 <span>" + m2[3] + "</span> 条";
|
||||
}
|
||||
});
|
||||
|
||||
// Translate form submit buttons (input[type="submit"] uses value attr)
|
||||
document.querySelectorAll("input[type='submit']").forEach(function (btn) {
|
||||
var v = btn.value;
|
||||
var submitMap = {
|
||||
"Save": "保存",
|
||||
"Submit": "提交",
|
||||
"Create": "新建",
|
||||
"Save and continue editing": "保存并继续编辑",
|
||||
"Save and add another": "保存并新增",
|
||||
"Save as new": "另存为新记录",
|
||||
};
|
||||
if (submitMap[v]) btn.value = submitMap[v];
|
||||
});
|
||||
|
||||
document.querySelectorAll("button[type='submit']").forEach(function (btn) {
|
||||
var t = btn.textContent.trim();
|
||||
if (t === "Save") btn.textContent = "保存";
|
||||
if (t === "Submit") btn.textContent = "提交";
|
||||
if (t === "Create") btn.textContent = "新建";
|
||||
if (t === "Apply Filter") btn.textContent = "应用筛选";
|
||||
});
|
||||
|
||||
// Translate "Go Back" / "Continue Editing" links
|
||||
document.querySelectorAll("a.btn").forEach(function (a) {
|
||||
var t = a.textContent.trim();
|
||||
if (t === "Go Back") a.textContent = "返回列表";
|
||||
if (t === "Continue Editing") a.textContent = "继续编辑";
|
||||
if (t === "Go back") a.textContent = "返回列表";
|
||||
});
|
||||
|
||||
// Translate delete modal
|
||||
document.querySelectorAll(".modal-title").forEach(function(el) {
|
||||
if (el.textContent.trim() === "Confirm Delete") el.textContent = "确认删除";
|
||||
});
|
||||
document.querySelectorAll(".modal-body").forEach(function(el) {
|
||||
var t = el.textContent.trim();
|
||||
if (t.indexOf("Are you sure you want to delete") !== -1) {
|
||||
el.innerHTML = el.innerHTML.replace("Are you sure you want to delete", "确定要删除");
|
||||
el.innerHTML = el.innerHTML.replace("selected items?", "所选项目吗?");
|
||||
el.innerHTML = el.innerHTML.replace("item?", "吗?");
|
||||
}
|
||||
});
|
||||
document.querySelectorAll(".modal-footer .btn-danger").forEach(function(btn) {
|
||||
if (btn.textContent.trim() === "Delete") btn.textContent = "确认删除";
|
||||
});
|
||||
document.querySelectorAll(".modal-footer .btn-secondary, .modal-footer [data-bs-dismiss]").forEach(function(btn) {
|
||||
if (btn.textContent.trim() === "Cancel" || btn.textContent.trim() === "Close") btn.textContent = "取消";
|
||||
});
|
||||
|
||||
// Style audit status badges in table cells
|
||||
document.querySelectorAll("td").forEach(function(td) {
|
||||
var t = td.textContent.trim();
|
||||
var statusColors = {
|
||||
"pending": ["#f59e0b", "rgba(245,158,11,0.12)"],
|
||||
"approved": ["#22c55e", "rgba(34,197,94,0.12)"],
|
||||
"rejected": ["#ef4444", "rgba(239,68,68,0.12)"],
|
||||
"deleted": ["#94a3b8", "rgba(148,163,184,0.12)"],
|
||||
"processing": ["#3b82f6", "rgba(59,130,246,0.12)"],
|
||||
"resolved": ["#22c55e", "rgba(34,197,94,0.12)"],
|
||||
"dismissed": ["#94a3b8", "rgba(148,163,184,0.12)"],
|
||||
"accepted": ["#22c55e", "rgba(34,197,94,0.12)"],
|
||||
};
|
||||
var statusLabels = {
|
||||
"pending": "待审核",
|
||||
"approved": "已通过",
|
||||
"rejected": "已驳回",
|
||||
"deleted": "已删除",
|
||||
"processing": "处理中",
|
||||
"resolved": "已处理",
|
||||
"dismissed": "已驳回",
|
||||
"accepted": "已采纳",
|
||||
};
|
||||
if (statusColors[t]) {
|
||||
td.innerHTML = '<span style="display:inline-block;padding:2px 10px;border-radius:6px;font-size:13px;font-weight:600;color:' +
|
||||
statusColors[t][0] + ';background:' + statusColors[t][1] + '">' + (statusLabels[t] || t) + '</span>';
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,169 @@
|
||||
/* Image Picker for Admin - media library modal + upload */
|
||||
(function () {
|
||||
var _currentField = null;
|
||||
var _modal = null;
|
||||
var _gallery = null;
|
||||
var _loading = null;
|
||||
|
||||
function ensureModal() {
|
||||
if (_modal) return;
|
||||
var html =
|
||||
'<div id="image-picker-modal" class="ip-modal-overlay" style="display:none">' +
|
||||
'<div class="ip-modal">' +
|
||||
'<div class="ip-modal-header">' +
|
||||
'<h3>素材库</h3>' +
|
||||
'<div class="ip-modal-header-actions">' +
|
||||
'<button class="btn btn-sm btn-outline-success" onclick="imagePickerModalUpload()">' +
|
||||
'<i class="fa-solid fa-upload"></i> 上传新图片</button>' +
|
||||
'<input type="file" id="ip-modal-file" accept="image/*" style="display:none" onchange="imagePickerModalFileSelected(this)">' +
|
||||
'<button class="btn btn-sm" onclick="imagePickerClose()">' +
|
||||
'<i class="fa-solid fa-times"></i> 关闭</button>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<div class="ip-modal-body">' +
|
||||
'<div id="ip-loading" class="ip-loading">加载中...</div>' +
|
||||
'<div id="ip-gallery" class="ip-gallery"></div>' +
|
||||
'<div id="ip-empty" class="ip-empty" style="display:none">暂无图片,请先上传</div>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
document.body.insertAdjacentHTML("beforeend", html);
|
||||
_modal = document.getElementById("image-picker-modal");
|
||||
_gallery = document.getElementById("ip-gallery");
|
||||
_loading = document.getElementById("ip-loading");
|
||||
|
||||
_modal.addEventListener("click", function (e) {
|
||||
if (e.target === _modal) imagePickerClose();
|
||||
});
|
||||
}
|
||||
|
||||
function loadGallery() {
|
||||
_loading.style.display = "block";
|
||||
_gallery.innerHTML = "";
|
||||
document.getElementById("ip-empty").style.display = "none";
|
||||
|
||||
fetch("/admin/api/media/list", { credentials: "same-origin" })
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (data) {
|
||||
_loading.style.display = "none";
|
||||
var images = data.images || [];
|
||||
if (images.length === 0) {
|
||||
document.getElementById("ip-empty").style.display = "block";
|
||||
return;
|
||||
}
|
||||
images.forEach(function (img) {
|
||||
var item = document.createElement("div");
|
||||
item.className = "ip-gallery-item";
|
||||
item.innerHTML =
|
||||
'<img src="' + img.url + '" alt="' + img.name + '">' +
|
||||
'<div class="ip-gallery-name">' + img.name + '</div>';
|
||||
item.addEventListener("click", function () {
|
||||
imagePickerSelect(img.url);
|
||||
});
|
||||
_gallery.appendChild(item);
|
||||
});
|
||||
})
|
||||
.catch(function () {
|
||||
_loading.style.display = "none";
|
||||
_gallery.innerHTML = '<div class="ip-empty">加载失败,请重试</div>';
|
||||
});
|
||||
}
|
||||
|
||||
window.imagePickerOpen = function (fieldId) {
|
||||
_currentField = fieldId;
|
||||
ensureModal();
|
||||
_modal.style.display = "flex";
|
||||
loadGallery();
|
||||
};
|
||||
|
||||
window.imagePickerClose = function () {
|
||||
if (_modal) _modal.style.display = "none";
|
||||
_currentField = null;
|
||||
};
|
||||
|
||||
window.imagePickerSelect = function (url) {
|
||||
if (!_currentField) return;
|
||||
setFieldValue(_currentField, url);
|
||||
imagePickerClose();
|
||||
};
|
||||
|
||||
window.imagePickerClear = function (fieldId) {
|
||||
setFieldValue(fieldId, "");
|
||||
};
|
||||
|
||||
window.imagePickerUpload = function (fieldId) {
|
||||
_currentField = fieldId;
|
||||
document.getElementById("file-" + fieldId).click();
|
||||
};
|
||||
|
||||
window.imagePickerFileSelected = function (fieldId, input) {
|
||||
if (!input.files || !input.files[0]) return;
|
||||
doUpload(input.files[0], fieldId);
|
||||
input.value = "";
|
||||
};
|
||||
|
||||
window.imagePickerModalUpload = function () {
|
||||
document.getElementById("ip-modal-file").click();
|
||||
};
|
||||
|
||||
window.imagePickerModalFileSelected = function (input) {
|
||||
if (!input.files || !input.files[0]) return;
|
||||
doUpload(input.files[0], _currentField, function () {
|
||||
loadGallery();
|
||||
});
|
||||
input.value = "";
|
||||
};
|
||||
|
||||
function doUpload(file, fieldId, callback) {
|
||||
var fd = new FormData();
|
||||
fd.append("file", file);
|
||||
|
||||
var btn = document.querySelector('.ip-modal-header-actions .btn-outline-success');
|
||||
if (btn) {
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i> 上传中...';
|
||||
}
|
||||
|
||||
fetch("/admin/api/media/upload", {
|
||||
method: "POST",
|
||||
body: fd,
|
||||
credentials: "same-origin",
|
||||
})
|
||||
.then(function (r) {
|
||||
if (!r.ok) throw new Error("Upload failed");
|
||||
return r.json();
|
||||
})
|
||||
.then(function (data) {
|
||||
if (fieldId) setFieldValue(fieldId, data.url);
|
||||
if (callback) callback();
|
||||
})
|
||||
.catch(function (err) {
|
||||
alert("上传失败: " + err.message);
|
||||
})
|
||||
.finally(function () {
|
||||
if (btn) {
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = '<i class="fa-solid fa-upload"></i> 上传新图片';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function setFieldValue(fieldId, url) {
|
||||
var input = document.getElementById(fieldId);
|
||||
if (input) input.value = url;
|
||||
|
||||
var preview = document.getElementById("preview-" + fieldId);
|
||||
var previewImg = document.getElementById("preview-img-" + fieldId);
|
||||
var urlDisplay = document.getElementById("url-display-" + fieldId);
|
||||
|
||||
if (url) {
|
||||
if (preview) preview.style.display = "block";
|
||||
if (previewImg) previewImg.src = url;
|
||||
if (urlDisplay) urlDisplay.textContent = url;
|
||||
} else {
|
||||
if (preview) preview.style.display = "none";
|
||||
if (previewImg) previewImg.src = "";
|
||||
if (urlDisplay) urlDisplay.textContent = "";
|
||||
}
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user