db7648eb4d
- 新增微信小程序版个人收藏夹全套功能,包含聚合首页、收藏列表、编辑、详情页面与配套后端API - 新增web版时光助手门户与个人收藏夹工具,支持与小程序共享后端数据 - 优化日历提醒工具:替换本地bootstrap资源为公共CDN版本,新增批量生成循环提醒的前端界面与后端逻辑,新增数据库batch_id字段,更新鉴权配置文件 - 补充项目配置、站点地图、调试诊断脚本等配套文件 - 完善各模块的页面配置与样式文件
75 lines
2.3 KiB
JavaScript
75 lines
2.3 KiB
JavaScript
(function () {
|
|
const api = window.__MPTA_API__
|
|
const $grid = document.getElementById('kit-grid')
|
|
const $status = document.getElementById('status-tag')
|
|
|
|
const KIT_PAGES = {
|
|
personal_collect: 'kits/personal_collect/list.html'
|
|
}
|
|
|
|
const KIT_ICONS = {
|
|
personal_collect: '📁'
|
|
}
|
|
|
|
function setStatus(text, cls) {
|
|
$status.textContent = text
|
|
$status.className = 'status-tag' + (cls ? ' ' + cls : '')
|
|
}
|
|
|
|
function renderKits(kits) {
|
|
if (!kits || !kits.length) {
|
|
$grid.innerHTML = '<div class="kit-empty">暂无可用工具</div>'
|
|
return
|
|
}
|
|
$grid.innerHTML = kits.map((kit) => {
|
|
const page = KIT_PAGES[kit.id] || '#'
|
|
const icon = KIT_ICONS[kit.id] || '🧰'
|
|
return (
|
|
`<div class="kit-card" data-kit="${kit.id}" data-page="${page}">` +
|
|
`<div class="kit-icon">${icon}</div>` +
|
|
`<div class="kit-name">${escapeHtml(kit.name || kit.id)}</div>` +
|
|
`<div class="kit-desc">${escapeHtml(kit.description || '')}</div>` +
|
|
`<div class="kit-arrow"><span>进入</span><span>→</span></div>` +
|
|
`</div>`
|
|
)
|
|
}).join('')
|
|
Array.from($grid.querySelectorAll('.kit-card')).forEach((card) => {
|
|
card.addEventListener('click', () => {
|
|
const page = card.getAttribute('data-page')
|
|
const kitId = card.getAttribute('data-kit')
|
|
const go = () => { window.location.href = page }
|
|
if (api && api.hub && api.hub.setActiveKit) {
|
|
api.hub.setActiveKit(kitId).then(go).catch(go)
|
|
} else {
|
|
go()
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
function escapeHtml(s) {
|
|
if (s === null || s === undefined) return ''
|
|
return String(s)
|
|
.replace(/&/g, '&')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>')
|
|
.replace(/"/g, '"')
|
|
.replace(/'/g, ''')
|
|
}
|
|
|
|
async function main() {
|
|
try {
|
|
if (!api || !api.hub) throw new Error('API 未加载')
|
|
const meta = await api.hub.meta()
|
|
const kits = (meta && meta.kits) || []
|
|
setStatus('后端已连通', 'ok')
|
|
renderKits(kits)
|
|
} catch (e) {
|
|
setStatus('后端连通失败:' + (e.message || '未知错误'), 'err')
|
|
$grid.innerHTML = `<div class="kit-empty">❌ 加载失败:${escapeHtml(e.message || '后端无响应')}</div>`
|
|
}
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', main)
|
|
})()
|