chore: 初始提交 - 移除所有硬编码凭据,统一从环境变量读取
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"_comment": "建行私募理财工具的前端鉴权配置",
|
||||
"enable_auth_comment": "true:启用鉴权(需要从导航登录);false:完全放开访问资金工具",
|
||||
"enable_auth": true,
|
||||
"max_age_days_comment": "鉴权 cookie 的最大有效天数(1~365)",
|
||||
"max_age_days": 30
|
||||
}
|
||||
@@ -0,0 +1,338 @@
|
||||
body {
|
||||
background: radial-gradient(circle at top left, #f5f9ff 0%, #e8f1ff 42%, #dce9ff 100%);
|
||||
color: #1b2a4a;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1400px;
|
||||
margin: 0 auto;
|
||||
padding: 28px 20px;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
padding: 20px;
|
||||
border-radius: 14px;
|
||||
border: 1px solid #c3d7ff;
|
||||
background: linear-gradient(140deg, #ffffff, #f2f7ff);
|
||||
box-shadow: 0 6px 20px rgba(40, 79, 158, 0.08);
|
||||
}
|
||||
|
||||
.panel-header h1 {
|
||||
margin: 0;
|
||||
color: #1f4b99;
|
||||
font-size: 2rem;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.panel-subtitle {
|
||||
margin: 8px 0 0 0;
|
||||
color: #4a6ba8;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.toolbar,
|
||||
.add-bar,
|
||||
.attachments-editor {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 14px;
|
||||
padding: 14px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid #cfe0ff;
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
box-shadow: 0 4px 14px rgba(37, 84, 171, 0.08);
|
||||
}
|
||||
|
||||
.attachments-editor {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.attachments-title {
|
||||
font-weight: 700;
|
||||
color: #2b4f8f;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
input,
|
||||
select {
|
||||
height: 38px;
|
||||
border: 1px solid #b6cbf3;
|
||||
border-radius: 8px;
|
||||
padding: 0 10px;
|
||||
color: #1e335a;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
input:focus,
|
||||
select:focus {
|
||||
outline: none;
|
||||
border-color: #5c8ee6;
|
||||
box-shadow: 0 0 0 3px rgba(92, 142, 230, 0.2);
|
||||
}
|
||||
|
||||
input[type="file"] {
|
||||
height: auto;
|
||||
min-height: 38px;
|
||||
padding: 6px 10px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
border: 1px solid #316ccc;
|
||||
background: linear-gradient(140deg, #2f69c9, #3f7de2);
|
||||
color: #fff;
|
||||
border-radius: 8px;
|
||||
height: 38px;
|
||||
padding: 0 14px;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
background: linear-gradient(140deg, #285cb2, #366cc6);
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
opacity: 0.65;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.btn-light {
|
||||
background: linear-gradient(140deg, #eef3ff, #dfeaff);
|
||||
color: #1f4380;
|
||||
border-color: #aac3f3;
|
||||
}
|
||||
|
||||
.btn-light:hover {
|
||||
background: linear-gradient(140deg, #dfeaff, #cfdeff);
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: linear-gradient(140deg, #bd3c4e, #d35364);
|
||||
border-color: #b23647;
|
||||
}
|
||||
|
||||
.btn-danger:hover {
|
||||
background: linear-gradient(140deg, #a63445, #bc4658);
|
||||
}
|
||||
|
||||
.table-wrap {
|
||||
border: 1px solid #cddfff;
|
||||
border-radius: 12px;
|
||||
overflow: auto;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
table.flows {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
table.flows th,
|
||||
table.flows td {
|
||||
padding: 10px 12px;
|
||||
border-bottom: 1px solid #e6eeff;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
table.flows th {
|
||||
background: linear-gradient(140deg, #2f5faa, #3c72c4);
|
||||
color: #fff;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
table.flows tr.in td {
|
||||
background: rgba(62, 121, 211, 0.06);
|
||||
}
|
||||
|
||||
table.flows tr.out td {
|
||||
background: rgba(41, 70, 128, 0.04);
|
||||
}
|
||||
|
||||
table.flows tr:hover td {
|
||||
background: rgba(78, 130, 220, 0.12);
|
||||
}
|
||||
|
||||
table.flows td.amount {
|
||||
font-weight: 700;
|
||||
color: #23447d;
|
||||
}
|
||||
|
||||
table.flows td.ending {
|
||||
font-weight: 700;
|
||||
color: #1f4e9e;
|
||||
}
|
||||
|
||||
.attachments-cell {
|
||||
min-width: 180px;
|
||||
}
|
||||
|
||||
.attachments-cell.expandable {
|
||||
position: relative;
|
||||
padding-bottom: 24px;
|
||||
}
|
||||
|
||||
.attachments-cell .expandable-content {
|
||||
overflow: hidden;
|
||||
max-height: 62px;
|
||||
transition: max-height 0.2s ease;
|
||||
}
|
||||
|
||||
.attachments-cell.expanded .expandable-content {
|
||||
max-height: none;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.attachments-cell .expandable-toggle {
|
||||
position: absolute;
|
||||
right: 4px;
|
||||
bottom: 2px;
|
||||
font-size: 12px;
|
||||
color: #345ea8;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
background: rgba(232, 241, 255, 0.9);
|
||||
padding: 0 4px;
|
||||
border-radius: 4px;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.att-none {
|
||||
color: #94a3b8;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.att-count {
|
||||
display: inline-block;
|
||||
font-size: 12px;
|
||||
color: #345ea8;
|
||||
font-weight: 700;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.att-links {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.att-links a {
|
||||
color: #2759a9;
|
||||
text-decoration: none;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
max-width: 220px;
|
||||
}
|
||||
|
||||
.att-links a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.att-extra {
|
||||
color: #5b76a8;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.attachments-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.attachment-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 8px 10px;
|
||||
border: 1px solid #dae7ff;
|
||||
border-radius: 8px;
|
||||
background: #f8fbff;
|
||||
}
|
||||
|
||||
.attachment-item a {
|
||||
color: #2558a7;
|
||||
text-decoration: none;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.attachment-item a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.empty-attachments {
|
||||
color: #6a7da1;
|
||||
}
|
||||
|
||||
.stats {
|
||||
margin: 14px 0;
|
||||
padding: 16px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #cfe2ff;
|
||||
background: linear-gradient(140deg, #f8fbff, #ebf3ff);
|
||||
color: #244983;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.status {
|
||||
margin: 8px 0 12px 0;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #bbd3fb;
|
||||
background: #eef5ff;
|
||||
color: #254d8a;
|
||||
}
|
||||
|
||||
.debug {
|
||||
margin: 12px 0;
|
||||
padding: 8px;
|
||||
border: 1px dashed #9db7e5;
|
||||
border-radius: 8px;
|
||||
background: #f8fbff;
|
||||
}
|
||||
|
||||
.debug-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.debug-output {
|
||||
height: 220px;
|
||||
overflow: auto;
|
||||
background: #f0f5ff;
|
||||
padding: 8px;
|
||||
border-radius: 8px;
|
||||
font-family: ui-monospace, Menlo, Consolas, monospace;
|
||||
font-size: 12px;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
@media (max-width: 880px) {
|
||||
.toolbar,
|
||||
.add-bar {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
.toolbar .btn,
|
||||
.add-bar .btn,
|
||||
.toolbar input,
|
||||
.toolbar select,
|
||||
.add-bar input,
|
||||
.add-bar select {
|
||||
width: 100%;
|
||||
}
|
||||
table.flows th,
|
||||
table.flows td {
|
||||
padding: 8px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,405 @@
|
||||
const fmtCN = n => n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
||||
const parseAmount = s => { const x = String(s || '').replace(/[,\s]/g, ''); const v = Number(x); if (!Number.isFinite(v)) return null; return Math.round(v * 100) }
|
||||
const centsToText = c => fmtCN((c || 0) / 100)
|
||||
const logBox = () => document.getElementById('fd-output')
|
||||
const logLocal = msg => { const b = logBox(); if (!b) return; const line = `${(window.fmtCNDateTime ? fmtCNDateTime(new Date()) : new Date().toLocaleString('zh-CN'))} ${msg}`; b.textContent = (b.textContent || '') + (b.textContent ? '\n' : '') + line; b.scrollTop = b.scrollHeight }
|
||||
|
||||
let editingId = null
|
||||
const attachmentCache = new Map()
|
||||
|
||||
const getEl = id => document.getElementById(id)
|
||||
const clearFileInput = () => { const fi = getEl('new-attachments'); if (fi) fi.value = '' }
|
||||
|
||||
const loadFlags = async () => {
|
||||
try {
|
||||
const r = await fetch('/api/flags')
|
||||
const d = await r.json()
|
||||
if (d && d.debug && d.debug.ccb_private_funds) {
|
||||
const sec = getEl('funds-debug')
|
||||
if (sec) sec.style.display = ''
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
const getAttachments = async flowId => {
|
||||
if (attachmentCache.has(flowId)) return attachmentCache.get(flowId)
|
||||
const r = await fetch(`/api/ccb_private_funds/attachments/${flowId}`)
|
||||
const d = await r.json()
|
||||
const rows = (d && d.ok && Array.isArray(d.rows)) ? d.rows : []
|
||||
attachmentCache.set(flowId, rows)
|
||||
return rows
|
||||
}
|
||||
|
||||
const invalidateAttachments = flowId => {
|
||||
attachmentCache.delete(flowId)
|
||||
}
|
||||
|
||||
const uploadFiles = async (flowId, files) => {
|
||||
if (!files || files.length === 0) return []
|
||||
const result = []
|
||||
for (const f of files) {
|
||||
const buf = await f.arrayBuffer()
|
||||
const r = await fetch(`/api/ccb_private_funds/attachments/upload?flow_id=${encodeURIComponent(flowId)}&filename=${encodeURIComponent(f.name)}&mime=${encodeURIComponent(f.type || 'application/octet-stream')}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/octet-stream' },
|
||||
body: buf
|
||||
})
|
||||
const d = await r.json()
|
||||
if (!d || !d.ok) throw new Error(d && d.error ? d.error : 'upload_failed')
|
||||
result.push(d)
|
||||
}
|
||||
invalidateAttachments(flowId)
|
||||
return result
|
||||
}
|
||||
|
||||
const renderAttachmentCell = async (flowId, td) => {
|
||||
td.className = 'attachments-cell expandable'
|
||||
td.innerHTML = ''
|
||||
const content = document.createElement('div')
|
||||
content.className = 'expandable-content'
|
||||
content.textContent = '加载中...'
|
||||
td.appendChild(content)
|
||||
const toggle = document.createElement('span')
|
||||
toggle.className = 'expandable-toggle'
|
||||
toggle.textContent = '👇展开'
|
||||
toggle.addEventListener('click', () => {
|
||||
const expanded = td.classList.toggle('expanded')
|
||||
toggle.textContent = expanded ? '👆收缩' : '👇展开'
|
||||
})
|
||||
td.appendChild(toggle)
|
||||
try {
|
||||
const atts = await getAttachments(flowId)
|
||||
if (!atts.length) {
|
||||
content.innerHTML = '<span class="att-none">无</span>'
|
||||
toggle.style.display = 'none'
|
||||
return
|
||||
}
|
||||
content.innerHTML = ''
|
||||
const c = document.createElement('span')
|
||||
c.className = 'att-count'
|
||||
c.textContent = `${atts.length} 个`
|
||||
content.appendChild(c)
|
||||
const wrap = document.createElement('div')
|
||||
wrap.className = 'att-links'
|
||||
for (const a of atts) {
|
||||
const link = document.createElement('a')
|
||||
link.href = a.url
|
||||
link.target = '_blank'
|
||||
link.rel = 'noopener noreferrer'
|
||||
link.textContent = a.filename
|
||||
wrap.appendChild(link)
|
||||
}
|
||||
content.appendChild(wrap)
|
||||
toggle.style.display = atts.length <= 2 ? 'none' : ''
|
||||
} catch {
|
||||
content.innerHTML = '<span class="att-none">加载失败</span>'
|
||||
toggle.style.display = 'none'
|
||||
}
|
||||
}
|
||||
|
||||
const renderEditAttachments = async flowId => {
|
||||
const editor = getEl('attachments-editor')
|
||||
const box = getEl('existing-attachments')
|
||||
if (!editor || !box) return
|
||||
if (!flowId) {
|
||||
editor.style.display = 'none'
|
||||
box.innerHTML = ''
|
||||
return
|
||||
}
|
||||
editor.style.display = ''
|
||||
box.innerHTML = '加载中...'
|
||||
try {
|
||||
const rows = await getAttachments(flowId)
|
||||
if (!rows.length) {
|
||||
box.innerHTML = '<div class="empty-attachments">暂无附件</div>'
|
||||
return
|
||||
}
|
||||
box.innerHTML = ''
|
||||
rows.forEach(a => {
|
||||
const item = document.createElement('div')
|
||||
item.className = 'attachment-item'
|
||||
const left = document.createElement('a')
|
||||
left.href = a.url
|
||||
left.target = '_blank'
|
||||
left.rel = 'noopener noreferrer'
|
||||
left.textContent = `${a.filename} (${fmtCN((a.size_bytes || 0) / 1024)} KB)`
|
||||
const del = document.createElement('button')
|
||||
del.className = 'btn btn-danger'
|
||||
del.textContent = '删除附件'
|
||||
del.addEventListener('click', async () => {
|
||||
const ok = window.confirm('确认删除此附件?')
|
||||
if (!ok) return
|
||||
const r = await fetch(`/api/ccb_private_funds/attachments/${a.id}`, { method: 'DELETE' })
|
||||
const d = await r.json()
|
||||
if (!d || !d.ok) {
|
||||
alert('附件删除失败')
|
||||
return
|
||||
}
|
||||
invalidateAttachments(flowId)
|
||||
await renderEditAttachments(flowId)
|
||||
await loadFlows()
|
||||
})
|
||||
item.appendChild(left)
|
||||
item.appendChild(del)
|
||||
box.appendChild(item)
|
||||
})
|
||||
} catch {
|
||||
box.innerHTML = '<div class="empty-attachments">加载失败</div>'
|
||||
}
|
||||
}
|
||||
|
||||
const enterEditMode = async row => {
|
||||
editingId = row.id
|
||||
getEl('new-date').value = row.date
|
||||
getEl('new-type').value = row.type
|
||||
getEl('new-amount').value = (row.amount_cents / 100).toFixed(2)
|
||||
getEl('new-bank').value = row.bank_status || ''
|
||||
getEl('new-remark').value = row.remark || ''
|
||||
const btnAdd = getEl('btn-add')
|
||||
const btnCancel = getEl('btn-cancel-edit')
|
||||
if (btnAdd) btnAdd.textContent = '保存修改'
|
||||
if (btnCancel) btnCancel.style.display = ''
|
||||
clearFileInput()
|
||||
await renderEditAttachments(editingId)
|
||||
document.querySelector('.add-bar').scrollIntoView({ behavior: 'smooth' })
|
||||
}
|
||||
|
||||
const exitEditMode = () => {
|
||||
editingId = null
|
||||
const btnAdd = getEl('btn-add')
|
||||
const btnCancel = getEl('btn-cancel-edit')
|
||||
if (btnAdd) btnAdd.textContent = '新增'
|
||||
if (btnCancel) btnCancel.style.display = 'none'
|
||||
clearFileInput()
|
||||
renderEditAttachments(0)
|
||||
}
|
||||
|
||||
const renderRows = rows => {
|
||||
const tb = getEl('flows-body')
|
||||
if (!tb) return
|
||||
tb.innerHTML = ''
|
||||
let sumIn = 0
|
||||
let sumOut = 0
|
||||
rows.forEach(r => {
|
||||
const tr = document.createElement('tr')
|
||||
tr.className = r.type === 'in' ? 'in' : 'out'
|
||||
const tdDate = document.createElement('td'); tdDate.textContent = r.date
|
||||
const tdType = document.createElement('td'); tdType.textContent = r.type === 'in' ? '汇入' : '汇出'
|
||||
const tdAmt = document.createElement('td'); tdAmt.className = 'amount'; tdAmt.textContent = centsToText(r.amount_cents)
|
||||
const tdBank = document.createElement('td'); tdBank.textContent = r.bank_status || ''
|
||||
const tdEnd = document.createElement('td'); tdEnd.className = 'ending'; tdEnd.textContent = centsToText(r.ending_cents)
|
||||
const tdRemark = document.createElement('td'); tdRemark.textContent = r.remark || ''
|
||||
const tdAtt = document.createElement('td'); tdAtt.className = 'attachments-cell'
|
||||
const tdOps = document.createElement('td')
|
||||
|
||||
const btnEdit = document.createElement('button')
|
||||
btnEdit.className = 'btn btn-light'
|
||||
btnEdit.textContent = '修改'
|
||||
btnEdit.style.marginRight = '6px'
|
||||
btnEdit.addEventListener('click', async () => { await enterEditMode(r) })
|
||||
tdOps.appendChild(btnEdit)
|
||||
|
||||
const btnDel = document.createElement('button')
|
||||
btnDel.className = 'btn btn-danger'
|
||||
btnDel.textContent = '删除'
|
||||
btnDel.addEventListener('click', async () => {
|
||||
const ok = window.confirm('确认删除该条流水及其全部附件?')
|
||||
if (!ok) return
|
||||
try { await fetch('/api/debug/event', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ source: 'ccb_private_funds', action: 'delete', id: r.id }) }) } catch {}
|
||||
const resp = await fetch(`/api/ccb_private_funds/flows/${r.id}`, { method: 'DELETE' })
|
||||
const data = await resp.json()
|
||||
if (!data || !data.ok) {
|
||||
alert('删除失败')
|
||||
return
|
||||
}
|
||||
invalidateAttachments(r.id)
|
||||
if (editingId === r.id) exitEditMode()
|
||||
await loadFlows()
|
||||
})
|
||||
tdOps.appendChild(btnDel)
|
||||
|
||||
tr.appendChild(tdDate)
|
||||
tr.appendChild(tdType)
|
||||
tr.appendChild(tdAmt)
|
||||
tr.appendChild(tdBank)
|
||||
tr.appendChild(tdEnd)
|
||||
tr.appendChild(tdRemark)
|
||||
tr.appendChild(tdAtt)
|
||||
tr.appendChild(tdOps)
|
||||
tb.appendChild(tr)
|
||||
renderAttachmentCell(r.id, tdAtt)
|
||||
if (r.type === 'in') sumIn += r.amount_cents
|
||||
else sumOut += r.amount_cents
|
||||
})
|
||||
const st = getEl('stats')
|
||||
if (st) st.textContent = `总汇入 ${centsToText(sumIn)} · 总汇出 ${centsToText(Math.abs(sumOut))} · 区间净变动 ${centsToText(sumIn + sumOut)} · 期末余额 ${rows.length ? centsToText(rows[rows.length - 1].ending_cents) : centsToText(0)}`
|
||||
}
|
||||
|
||||
const loadFlows = async () => {
|
||||
const st = getEl('funds-status')
|
||||
const btnQ = getEl('btn-load')
|
||||
if (st) { st.style.display = ''; st.textContent = '正在查询...' }
|
||||
if (btnQ) btnQ.disabled = true
|
||||
const start = getEl('date-start').value || ''
|
||||
const end = getEl('date-end').value || ''
|
||||
const type = getEl('type-filter').value || 'all'
|
||||
const kw = getEl('kw').value || ''
|
||||
try {
|
||||
const r = await fetch(`/api/ccb_private_funds/flows?start=${encodeURIComponent(start)}&end=${encodeURIComponent(end)}&type=${encodeURIComponent(type)}&kw=${encodeURIComponent(kw)}`)
|
||||
const d = await r.json()
|
||||
if (d.ok) renderRows(d.rows || [])
|
||||
if (st) { st.style.display = ''; st.textContent = `查询完成(${(d.rows || []).length} 条)` }
|
||||
} catch (e) {
|
||||
if (st) { st.style.display = ''; st.textContent = `查询失败:${String(e.message || e)}` }
|
||||
} finally {
|
||||
if (btnQ) btnQ.disabled = false
|
||||
setTimeout(() => { if (st) st.style.display = 'none' }, 1200)
|
||||
}
|
||||
}
|
||||
|
||||
const saveFlow = async () => {
|
||||
const st = getEl('funds-status')
|
||||
const btn = getEl('btn-add')
|
||||
if (st) { st.style.display = ''; st.textContent = editingId ? '正在保存修改...' : '正在新增...' }
|
||||
if (btn) btn.disabled = true
|
||||
|
||||
const date = getEl('new-date').value
|
||||
const type = getEl('new-type').value
|
||||
const amtText = getEl('new-amount').value
|
||||
const bank = getEl('new-bank').value
|
||||
const remark = getEl('new-remark').value
|
||||
const files = Array.from((getEl('new-attachments').files || []))
|
||||
if (!date || !type || !amtText || !bank || !remark) {
|
||||
if (st) st.textContent = '请完整填写日期、类型、金额、银行方/状态、备注'
|
||||
if (btn) btn.disabled = false
|
||||
setTimeout(() => { if (st) st.style.display = 'none' }, 1800)
|
||||
return
|
||||
}
|
||||
|
||||
const cents = parseAmount(amtText)
|
||||
if (cents === null) {
|
||||
if (st) st.textContent = '金额格式错误'
|
||||
if (btn) btn.disabled = false
|
||||
setTimeout(() => { if (st) st.style.display = 'none' }, 1800)
|
||||
return
|
||||
}
|
||||
|
||||
const body = { date, type, amount_cents: type === 'out' ? -Math.abs(cents) : Math.abs(cents), bank_status: bank, remark }
|
||||
|
||||
try {
|
||||
if (editingId) {
|
||||
const r = await fetch(`/api/ccb_private_funds/flows/${editingId}`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) })
|
||||
const d = await r.json()
|
||||
if (!d || !d.ok) throw new Error((d && d.error) || 'update_failed')
|
||||
if (files.length) await uploadFiles(editingId, files)
|
||||
invalidateAttachments(editingId)
|
||||
await renderEditAttachments(editingId)
|
||||
if (st) st.textContent = '修改成功'
|
||||
logLocal(`ccb_private_funds.update id=${editingId}`)
|
||||
} else {
|
||||
const dupRes = await fetch(`/api/ccb_private_funds/flows?start=${encodeURIComponent(date)}&end=${encodeURIComponent(date)}&type=all`)
|
||||
const dupData = await dupRes.json()
|
||||
if (dupData.ok && Array.isArray(dupData.rows) && dupData.rows.length > 0) {
|
||||
const ok = window.confirm(`该日期已有 ${dupData.rows.length} 条记录,是否继续新增?`)
|
||||
if (!ok) {
|
||||
if (btn) btn.disabled = false
|
||||
if (st) st.style.display = 'none'
|
||||
return
|
||||
}
|
||||
}
|
||||
const r = await fetch('/api/ccb_private_funds/flows', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) })
|
||||
const d = await r.json()
|
||||
if (!d || !d.ok || !d.id) throw new Error((d && d.error) || 'create_failed')
|
||||
if (files.length) await uploadFiles(d.id, files)
|
||||
invalidateAttachments(d.id)
|
||||
if (st) st.textContent = '新增成功'
|
||||
logLocal(`ccb_private_funds.add id=${d.id}`)
|
||||
}
|
||||
clearFileInput()
|
||||
await loadFlows()
|
||||
} catch (e) {
|
||||
if (st) st.textContent = `${editingId ? '修改' : '新增'}失败:${String(e.message || e)}`
|
||||
} finally {
|
||||
if (btn) btn.disabled = false
|
||||
setTimeout(() => { if (st) st.style.display = 'none' }, 1400)
|
||||
}
|
||||
}
|
||||
|
||||
const openSettings = async () => {
|
||||
const st = getEl('funds-status')
|
||||
try {
|
||||
if (st) { st.style.display = ''; st.textContent = '正在读取设置...' }
|
||||
const r = await fetch('/api/ccb_private_funds/config')
|
||||
const d = await r.json()
|
||||
if (!d || !d.ok || !d.config) throw new Error((d && d.error) || 'load_config_failed')
|
||||
const cfg = d.config || {}
|
||||
const currentBase = String(cfg.weekly_api_base || '')
|
||||
const currentKey = String(cfg.weekly_key || '93220')
|
||||
const currentSync = cfg.weekly_sync_enabled !== false ? 'on' : 'off'
|
||||
|
||||
const nextBaseRaw = window.prompt('周报同步地址 weekly_api_base', currentBase)
|
||||
if (nextBaseRaw === null) {
|
||||
if (st) st.textContent = '已取消设置'
|
||||
setTimeout(() => { if (st) st.style.display = 'none' }, 1200)
|
||||
return
|
||||
}
|
||||
const nextKeyRaw = window.prompt('周报同步密钥 weekly_key', currentKey)
|
||||
if (nextKeyRaw === null) {
|
||||
if (st) st.textContent = '已取消设置'
|
||||
setTimeout(() => { if (st) st.style.display = 'none' }, 1200)
|
||||
return
|
||||
}
|
||||
const nextSyncRaw = window.prompt('是否开启周报同步(on/off)', currentSync)
|
||||
if (nextSyncRaw === null) {
|
||||
if (st) st.textContent = '已取消设置'
|
||||
setTimeout(() => { if (st) st.style.display = 'none' }, 1200)
|
||||
return
|
||||
}
|
||||
|
||||
const syncText = String(nextSyncRaw || '').trim().toLowerCase()
|
||||
const weekly_sync_enabled = !(syncText === 'off' || syncText === '0' || syncText === 'false' || syncText === 'no')
|
||||
const payload = {
|
||||
weekly_api_base: String(nextBaseRaw || '').trim(),
|
||||
weekly_key: String(nextKeyRaw || '').trim(),
|
||||
weekly_sync_enabled
|
||||
}
|
||||
const wr = await fetch('/api/ccb_private_funds/config', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
const wd = await wr.json()
|
||||
if (!wd || !wd.ok) throw new Error((wd && wd.error) || 'save_config_failed')
|
||||
if (st) st.textContent = '设置已保存'
|
||||
logLocal('ccb_private_funds.config.saved')
|
||||
} catch (e) {
|
||||
if (st) st.textContent = `设置失败:${String(e.message || e)}`
|
||||
} finally {
|
||||
setTimeout(() => { if (st) st.style.display = 'none' }, 1500)
|
||||
}
|
||||
}
|
||||
|
||||
let pageInited = false
|
||||
const initPage = () => {
|
||||
if (pageInited) return
|
||||
pageInited = true
|
||||
loadFlags()
|
||||
const y = new Date().getFullYear()
|
||||
const d = new Date(y, 11, 31)
|
||||
const endOfYear = window.cnDateStr ? cnDateStr(d) : `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
|
||||
const ds = getEl('date-start'); if (ds) ds.value = '2024-01-01'
|
||||
const de = getEl('date-end'); if (de) de.value = endOfYear
|
||||
const nd = getEl('new-date'); if (nd) nd.value = window.cnDateStr ? cnDateStr(new Date()) : nd.value
|
||||
const bl = getEl('btn-load'); if (bl) bl.addEventListener('click', loadFlows)
|
||||
const ba = getEl('btn-add'); if (ba) ba.addEventListener('click', saveFlow)
|
||||
const bc = getEl('btn-cancel-edit'); if (bc) bc.addEventListener('click', exitEditMode)
|
||||
const be = getEl('btn-export'); if (be) be.addEventListener('click', async () => { const start = getEl('date-start').value || ''; const end = getEl('date-end').value || ''; location.href = `/api/ccb_private_funds/export.csv?start=${encodeURIComponent(start)}&end=${encodeURIComponent(end)}` })
|
||||
const bs = getEl('btn-settings'); if (bs) bs.addEventListener('click', openSettings)
|
||||
const bcp = getEl('fd-btn-copy'); if (bcp) bcp.addEventListener('click', async () => { try { await navigator.clipboard.writeText((logBox() && logBox().textContent) || '') } catch {} })
|
||||
const brf = getEl('fd-btn-refresh'); if (brf) brf.addEventListener('click', async () => { try { const r = await fetch('/api/debug/logs?limit=5000&channel=ccb_private_funds'); const d2 = await r.json(); if (d2.ok) { const b = logBox(); if (b) { b.textContent = (d2.lines || []).join('\n'); b.scrollTop = b.scrollHeight } } } catch {} })
|
||||
const bcl = getEl('fd-btn-clear'); if (bcl) bcl.addEventListener('click', async () => { try { await fetch('/api/debug/clear?channel=ccb_private_funds', { method: 'POST' }) } catch {}; const b = logBox(); if (b) b.textContent = '' })
|
||||
loadFlows()
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', initPage)
|
||||
else initPage()
|
||||
@@ -0,0 +1,83 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>建行私募理财</title>
|
||||
<link rel="icon" href="/icons/ccb_private_funds.svg" type="image/svg+xml" />
|
||||
<link rel="stylesheet" href="/common/common.css" />
|
||||
<link rel="stylesheet" href="/tools/ccb_private_funds/funds.css?v=1" />
|
||||
</head>
|
||||
<body>
|
||||
<main class="container">
|
||||
<div class="panel-header">
|
||||
<h1>CCB Private Funds</h1>
|
||||
<p class="panel-subtitle">私募资金流水管理</p>
|
||||
</div>
|
||||
<section class="toolbar">
|
||||
<input id="date-start" type="date" />
|
||||
<input id="date-end" type="date" />
|
||||
<select id="type-filter">
|
||||
<option value="all">全部</option>
|
||||
<option value="in">汇入</option>
|
||||
<option value="out">汇出</option>
|
||||
</select>
|
||||
<input id="kw" type="text" placeholder="银行/备注检索" />
|
||||
<button id="btn-load" class="btn">查询</button>
|
||||
<button id="btn-export" class="btn">导出CSV</button>
|
||||
<button id="btn-settings" class="btn">设置</button>
|
||||
</section>
|
||||
<div id="funds-status" class="status" style="display:none"></div>
|
||||
|
||||
<section class="add-bar">
|
||||
<input id="new-date" type="date" required />
|
||||
<select id="new-type" required>
|
||||
<option value="in">汇入</option>
|
||||
<option value="out">汇出</option>
|
||||
</select>
|
||||
<input id="new-amount" type="text" placeholder="金额(人民币),如 20,000.00 或 -5000" required />
|
||||
<input id="new-bank" type="text" placeholder="银行方/状态" required />
|
||||
<input id="new-remark" type="text" placeholder="备注" required />
|
||||
<input id="new-attachments" type="file" multiple />
|
||||
<button id="btn-add" class="btn">新增</button>
|
||||
<button id="btn-cancel-edit" class="btn btn-light" style="display:none">取消修改</button>
|
||||
</section>
|
||||
<section class="attachments-editor" id="attachments-editor" style="display:none">
|
||||
<div class="attachments-title">当前流水附件</div>
|
||||
<div id="existing-attachments" class="attachments-list"></div>
|
||||
</section>
|
||||
|
||||
<section class="stats" id="stats"></section>
|
||||
|
||||
<section class="table-wrap">
|
||||
<table class="flows" id="flows">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>日期</th>
|
||||
<th>类型</th>
|
||||
<th>金额(人民币)</th>
|
||||
<th>银行方/状态</th>
|
||||
<th>期末金额</th>
|
||||
<th>备注</th>
|
||||
<th>附件</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="flows-body"></tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
<section class="debug" id="funds-debug" style="display:none">
|
||||
<div class="debug-actions">
|
||||
<button id="fd-btn-copy" class="btn">复制调试信息</button>
|
||||
<button id="fd-btn-refresh" class="btn">刷新</button>
|
||||
<button id="fd-btn-clear" class="btn">清空</button>
|
||||
</div>
|
||||
<div id="fd-output" class="debug-output"></div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<script src="/common/common.js"></script>
|
||||
<script src="/tools/ccb_private_funds/funds.js?v=1"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user