feat: OPC 工作台 — 科普(慰心斋)单项目管理系统
Flask + Tailwind CSS + Trix + Chart.js + Lucide Icons + SQLite - 首页概览:关键指标卡片、财务趋势图、风险提醒、近期动态 - 销售管理:客户表格 + 抽屉详情(自动保存 + 评论) - 业务方案:版本表格 + 抽屉(文件上传/预览/删除 + 评论) - 运营管理:项目表格(业务机会/执行项目分类)+ 抽屉 - 产品研发:版本表格 + 抽屉 - 财务管理:月度收入/毛利/成本/净利曲线图 + 明细表 - 所有抽屉:Plane 风格紧凑布局、字段失焦自动保存、Trix 富文本评论框、点击遮罩关闭
This commit is contained in:
388
static/app.js
Normal file
388
static/app.js
Normal file
@@ -0,0 +1,388 @@
|
||||
const state = {
|
||||
active: "home",
|
||||
data: null,
|
||||
opFilter: "all",
|
||||
chart: null,
|
||||
};
|
||||
|
||||
const money = (value) => `${Number(value || 0).toLocaleString("zh-CN")} 万`;
|
||||
const text = (value) => value === undefined || value === null || value === "" ? "—" : value;
|
||||
|
||||
async function api(path, options = {}) {
|
||||
const response = await fetch(path, {
|
||||
headers: options.body instanceof FormData ? undefined : { "Content-Type": "application/json" },
|
||||
...options,
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || "请求失败");
|
||||
return data;
|
||||
}
|
||||
|
||||
function badge(value) {
|
||||
const val = String(value || "—");
|
||||
let cls = "badge-slate";
|
||||
if (["P0", "有风险", "已丢单", "已延期"].includes(val)) cls = "badge-red";
|
||||
if (["P1", "方案中", "方案已提交", "商务谈判", "待客户确认"].includes(val)) cls = "badge-amber";
|
||||
if (["已签约", "已上线", "已完成", "已归档"].includes(val)) cls = "badge-green";
|
||||
if (["execution", "已签约执行项目"].includes(val)) cls = "badge-blue";
|
||||
return `<span class="badge ${cls}">${val === "execution" ? "已签约执行项目" : val === "opportunity" ? "业务机会项目" : val}</span>`;
|
||||
}
|
||||
|
||||
function card(content, cls = "") {
|
||||
return `<section class="card ${cls}">${content}</section>`;
|
||||
}
|
||||
|
||||
function renderTable(headers, rows, rowClicks) {
|
||||
const trAttrs = (rowClicks || []).map((rc) => rc ? `onclick="openDrawer('${rc.resource}', ${rc.id})" class="clickable-row"` : "");
|
||||
return card(`
|
||||
<div class="overflow-x-auto">
|
||||
<table>
|
||||
<thead><tr>${headers.map((h) => `<th>${h}</th>`).join("")}</tr></thead>
|
||||
<tbody>${rows.map((row, i) => `<tr ${trAttrs[i] || ""}>${row.map((c) => `<td>${c}</td>`).join("")}</tr>`).join("")}</tbody>
|
||||
</table>
|
||||
</div>
|
||||
`);
|
||||
}
|
||||
|
||||
async function load() {
|
||||
state.data = await api("/api/bootstrap");
|
||||
render();
|
||||
}
|
||||
|
||||
function switchTab(tab) {
|
||||
state.active = tab;
|
||||
document.querySelectorAll("#tabs button").forEach((btn) => btn.classList.toggle("active", btn.dataset.tab === tab));
|
||||
document.querySelectorAll(".panel").forEach((panel) => panel.classList.toggle("active", panel.id === tab));
|
||||
render();
|
||||
}
|
||||
|
||||
function render() {
|
||||
if (!state.data) return;
|
||||
renderHome();
|
||||
renderSales();
|
||||
renderProposals();
|
||||
renderOperations();
|
||||
renderProducts();
|
||||
renderFinance();
|
||||
if (window.lucide) window.lucide.createIcons();
|
||||
}
|
||||
|
||||
function renderHome() {
|
||||
const { summary, financeMonthly } = state.data;
|
||||
const m = summary.metrics;
|
||||
document.querySelector("#home").innerHTML = `
|
||||
<div class="grid gap-5">
|
||||
<div class="grid grid-cols-7 gap-3">
|
||||
${[
|
||||
["P0 客户数", m.p0_customers, "sales"],
|
||||
["跟进中销售机会", m.active_sales, "sales"],
|
||||
["已签约执行项目", m.execution_projects, "operations"],
|
||||
["有风险项目", m.risk_projects, "operations"],
|
||||
["本月收入", money(m.monthly_revenue), "finance"],
|
||||
["本月净利", money(m.monthly_net_profit), "finance"],
|
||||
["即将上线版本", m.upcoming_products, "products"],
|
||||
].map(([label, value, tab]) => `<button class="metric-card" onclick="switchTab('${tab}')"><span class="flex items-center gap-2 text-xs text-slate-500"><i data-lucide="gauge"></i>${label}</span><strong class="mt-2 block text-2xl">${value}</strong></button>`).join("")}
|
||||
</div>
|
||||
<div class="grid grid-cols-[1.35fr_0.65fr] gap-5">
|
||||
${card(`<div class="mb-4 flex items-center justify-between"><h2 class="text-lg font-bold">财务趋势</h2>${badge("YYYY-MM")}</div><canvas id="financeChart" height="125"></canvas>`, "p-5")}
|
||||
${card(`<h2 class="text-lg font-bold">风险提醒</h2><div class="mt-3 grid gap-2">${(summary.risks.length ? summary.risks : [{ title: "暂无高风险", content: "当前无明确阻塞,按周更新即可。" }]).map((r) => `<div class="rounded-md border border-amber-200 bg-amber-50 p-3"><p class="font-bold text-amber-900">${r.title}</p><p class="mt-1 text-sm text-amber-800">${r.content}</p></div>`).join("")}</div>`, "p-5")}
|
||||
</div>
|
||||
${card(`<h2 class="text-lg font-bold">近期动态</h2><div class="mt-4 grid gap-2">${summary.recent.map((r) => `<div class="flex justify-between rounded-md bg-slate-50 px-3 py-2 text-sm"><span>${r.content}</span><span class="text-slate-500">${r.followed_at}</span></div>`).join("")}</div>`, "p-5")}
|
||||
</div>
|
||||
`;
|
||||
renderChart(financeMonthly);
|
||||
}
|
||||
|
||||
function renderChart(data) {
|
||||
const canvas = document.querySelector("#financeChart");
|
||||
if (!canvas || !window.Chart) return;
|
||||
if (state.chart) state.chart.destroy();
|
||||
state.chart = new Chart(canvas, {
|
||||
type: "line",
|
||||
data: {
|
||||
labels: data.map((x) => x.month),
|
||||
datasets: [
|
||||
{ label: "收入", data: data.map((x) => x.revenue), borderColor: "#2563eb", tension: 0.3 },
|
||||
{ label: "毛利", data: data.map((x) => x.gross_profit), borderColor: "#059669", tension: 0.3 },
|
||||
{ label: "成本/费用", data: data.map((x) => x.cost_expense), borderColor: "#d97706", tension: 0.3 },
|
||||
{ label: "净利", data: data.map((x) => x.net_profit), borderColor: "#7c3aed", tension: 0.3 },
|
||||
],
|
||||
},
|
||||
options: { responsive: true, plugins: { legend: { position: "bottom" } } },
|
||||
});
|
||||
}
|
||||
|
||||
function formHtml(fields, button) {
|
||||
return `<form class="inline-form flex flex-wrap items-end gap-3" onsubmit="${button.handler}(event)">
|
||||
${fields.map((f) => `<label class="grid gap-1 text-sm"><span class="font-bold text-slate-600">${f.label}</span>${f.input}</label>`).join("")}
|
||||
<button class="btn btn-primary" type="submit">${button.text}</button>
|
||||
</form>`;
|
||||
}
|
||||
|
||||
async function createResource(event, resource) {
|
||||
event.preventDefault();
|
||||
const data = Object.fromEntries(new FormData(event.currentTarget).entries());
|
||||
await api(`/api/${resource}`, { method: "POST", body: JSON.stringify({ data }) });
|
||||
event.currentTarget.reset();
|
||||
await load();
|
||||
}
|
||||
|
||||
window.createSales = (event) => createResource(event, "sales");
|
||||
window.createProposal = (event) => createResource(event, "proposals");
|
||||
window.createOperation = (event) => createResource(event, "operations");
|
||||
window.createProduct = (event) => createResource(event, "products");
|
||||
window.createFinance = (event) => createResource(event, "finance");
|
||||
window.switchTab = switchTab;
|
||||
|
||||
function renderSales() {
|
||||
const rows = state.data.sales.map((x) => [x.target_customer, badge(x.priority), badge(x.status), text(x.latest_follow_up_record)]);
|
||||
const salesClicks = state.data.sales.map((x) => ({ resource: "sales", id: x.id }));
|
||||
document.querySelector("#sales").innerHTML = `<div class="grid gap-4">
|
||||
${card(formHtml([
|
||||
{ label: "目标客户", input: `<input name="target_customer" required placeholder="客户名称">` },
|
||||
{ label: "优先级", input: `<select name="priority"><option>P0</option><option selected>P1</option><option>P2</option><option>P3</option></select>` },
|
||||
{ label: "状态", input: `<select name="status"><option>待跟进</option><option>跟进中</option><option>方案中</option><option>商务谈判</option><option>已签约</option><option>暂缓</option><option>已丢单</option></select>` },
|
||||
], { handler: "createSales", text: `<i data-lucide="plus"></i>新增客户` }), "p-4")}
|
||||
${renderTable(["目标客户", "优先级", "状态", "最新跟进记录"], rows, salesClicks)}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function renderProposals() {
|
||||
const categories = ["方案", "成本", "SOP", "财务流程"];
|
||||
const proposalRows = state.data.proposals.map((p) => [p.customer_or_project_name, p.version, badge(p.status), p.files.length + " 个"]);
|
||||
const proposalClicks = state.data.proposals.map((p) => ({ resource: "proposals", id: p.id }));
|
||||
document.querySelector("#proposals").innerHTML = `<div class="grid gap-4">
|
||||
${card(formHtml([
|
||||
{ label: "客户/项目", input: `<input name="customer_or_project_name" required placeholder="如:信达生物">` },
|
||||
{ label: "版本号", input: `<input name="version" required placeholder="v1.0">` },
|
||||
{ label: "状态", input: `<select name="status"><option>草稿</option><option>内部评审</option><option selected>已提交客户</option><option>客户反馈中</option><option>已确认</option><option>已归档</option></select>` },
|
||||
], { handler: "createProposal", text: "新增版本" }), "p-4")}
|
||||
${renderTable(["客户/项目", "版本号", "状态", "文件数"], proposalRows, proposalClicks)}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function fileGroup(module, ownerId, version, category, files) {
|
||||
return `<div class="rounded-md border border-slate-200 px-3 py-2">
|
||||
<div class="flex items-center justify-between gap-3"><p class="text-[13px] font-semibold text-slate-800">${category}</p><label class="inline-flex cursor-pointer items-center gap-1 rounded-md border border-slate-200 px-2 py-1 text-[12px] font-medium text-slate-600 hover:bg-slate-50"><i data-lucide="upload"></i>上传<input class="hidden" type="file" onchange="uploadFile(event,'${module}',${ownerId},'${version}','${category}')"></label></div>
|
||||
<div class="mt-2 grid gap-1.5">${files.length ? files.map(fileItem).join("") : `<p class="text-[12px] text-slate-400">暂无文件</p>`}</div>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function fileItem(file) {
|
||||
return `<div class="flex items-center justify-between gap-2 rounded-md bg-slate-50 px-2 py-1.5 text-[13px]"><div class="min-w-0 flex-1"><p class="truncate font-medium text-slate-800">${file.file_name}</p><div class="mt-0.5 flex gap-3"><a class="file-link inline-flex items-center gap-1" target="_blank" href="/api/files/${file.id}/content?inline=true"><i data-lucide="eye"></i>预览</a><a class="file-link inline-flex items-center gap-1 text-slate-600" href="/api/files/${file.id}/content?inline=false"><i data-lucide="download"></i>下载</a></div></div><button class="btn btn-ghost btn-sm text-red-600" onclick="deleteFile(${file.id})" title="删除"><i data-lucide="trash-2"></i></button></div>`;
|
||||
}
|
||||
|
||||
window.deleteFile = async (fileId) => {
|
||||
if (!confirm("确认删除此文件?")) return;
|
||||
await api(`/api/files/${fileId}`, { method: "DELETE" });
|
||||
await load();
|
||||
closeDrawer();
|
||||
};
|
||||
|
||||
window.uploadFile = async (event, module, ownerId, version, category) => {
|
||||
const file = event.target.files[0];
|
||||
if (!file) return;
|
||||
const form = new FormData();
|
||||
form.append("module", module);
|
||||
form.append("owner_id", ownerId);
|
||||
form.append("owner_version", version);
|
||||
form.append("file_category", category);
|
||||
form.append("file", file);
|
||||
await api("/api/files/upload", { method: "POST", body: form });
|
||||
await load();
|
||||
};
|
||||
|
||||
function renderOperations() {
|
||||
const items = state.opFilter === "all" ? state.data.operations : state.data.operations.filter((x) => x.project_type === state.opFilter);
|
||||
const opRows = items.map((x) => [`<strong>${x.project_name}</strong><p class="text-xs text-slate-500">${x.project_version}</p>`, badge(x.project_type), badge(x.project_status), text(x.current_stage || x.sop_stage), `${x.files.length} 个`, text(x.latest_follow_up_record)]);
|
||||
const opClicks = items.map((x) => ({ resource: "operations", id: x.id }));
|
||||
document.querySelector("#operations").innerHTML = `<div class="grid gap-4">
|
||||
${card(formHtml([
|
||||
{ label: "项目名称", input: `<input name="project_name" required>` },
|
||||
{ label: "项目版本", input: `<input name="project_version" value="v1.0">` },
|
||||
{ label: "项目类型", input: `<select name="project_type"><option value="opportunity">业务机会项目</option><option value="execution">已签约执行项目</option></select>` },
|
||||
{ label: "状态", input: `<input name="project_status" value="线索发现">` },
|
||||
], { handler: "createOperation", text: "新增项目" }), "p-4")}
|
||||
<div class="flex gap-2">${[["all","全部项目"],["opportunity","业务机会项目"],["execution","已签约执行项目"]].map(([k,v]) => `<button class="btn ${state.opFilter === k ? "btn-primary" : "btn-ghost"}" onclick="state.opFilter='${k}'; renderOperations()">${v}</button>`).join("")}</div>
|
||||
${renderTable(["项目名称", "类型", "状态", "当前阶段", "交付文件", "最新跟进"], opRows, opClicks)}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function renderProducts() {
|
||||
document.querySelector("#products").innerHTML = `<div class="grid gap-4">
|
||||
${card(formHtml([
|
||||
{ label: "产品名称", input: `<input name="product_name" required>` },
|
||||
{ label: "版本号", input: `<input name="version" required>` },
|
||||
{ label: "上线日期", input: `<input name="launch_date" placeholder="2026-Q3">` },
|
||||
{ label: "状态", input: `<select name="status"><option>规划中</option><option>设计中</option><option>开发中</option><option>测试中</option><option>已上线</option><option>已延期</option><option>已取消</option></select>` },
|
||||
], { handler: "createProduct", text: "新增版本" }), "p-4")}
|
||||
${renderTable(["产品名称", "版本号", "版本目标", "核心功能", "上线日期", "状态"], state.data.products.map((p) => [p.product_name, p.version, text(p.version_goal), text(p.feature_list), text(p.launch_date), badge(p.status)]), state.data.products.map((p) => ({ resource: "products", id: p.id })))}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function renderFinance() {
|
||||
const rows = state.data.finance.map((x) => [x.month, badge(x.record_type === "revenue" ? "收入" : "成本/费用"), x.category, money(x.amount), x.occurred_date, text(x.notes)]);
|
||||
document.querySelector("#finance").innerHTML = `<div class="grid gap-4">
|
||||
${card(`<h2 class="mb-4 text-lg font-bold">收入、毛利、成本/费用、净利月度曲线</h2><canvas id="financeChart2" height="105"></canvas>`, "p-5")}
|
||||
${card(formHtml([
|
||||
{ label: "月份", input: `<input name="month" required placeholder="YYYY-MM" pattern="\\d{4}-\\d{2}">` },
|
||||
{ label: "类型", input: `<select name="record_type"><option value="revenue">收入</option><option value="cost_expense">成本/费用</option></select>` },
|
||||
{ label: "分类", input: `<input name="category" required>` },
|
||||
{ label: "金额/万", input: `<input name="amount" type="number" step="0.01" required>` },
|
||||
{ label: "发生日期", input: `<input name="occurred_date" type="date">` },
|
||||
], { handler: "createFinance", text: "新增明细" }), "p-4")}
|
||||
${renderTable(["月份", "类型", "分类", "金额", "发生日期", "备注"], rows)}
|
||||
</div>`;
|
||||
renderChartOn("financeChart2", state.data.financeMonthly);
|
||||
}
|
||||
|
||||
function renderChartOn(id, data) {
|
||||
const canvas = document.querySelector(`#${id}`);
|
||||
if (!canvas || !window.Chart) return;
|
||||
new Chart(canvas, {
|
||||
type: "line",
|
||||
data: {
|
||||
labels: data.map((x) => x.month),
|
||||
datasets: [
|
||||
{ label: "收入", data: data.map((x) => x.revenue), borderColor: "#2563eb", tension: 0.3 },
|
||||
{ label: "毛利", data: data.map((x) => x.gross_profit), borderColor: "#059669", tension: 0.3 },
|
||||
{ label: "成本/费用", data: data.map((x) => x.cost_expense), borderColor: "#d97706", tension: 0.3 },
|
||||
{ label: "净利", data: data.map((x) => x.net_profit), borderColor: "#7c3aed", tension: 0.3 },
|
||||
],
|
||||
},
|
||||
options: { responsive: true, plugins: { legend: { position: "bottom" } } },
|
||||
});
|
||||
}
|
||||
|
||||
function drawerField(icon, label, name, value, multiline = false) {
|
||||
const initialValue = text(value);
|
||||
const control = multiline
|
||||
? `<textarea name="${name}" rows="2" class="drawer-value drawer-textarea" data-original="${initialValue}">${initialValue}</textarea>`
|
||||
: `<input name="${name}" value="${initialValue}" class="drawer-value" data-original="${initialValue}">`;
|
||||
return `<div class="drawer-field">
|
||||
<div class="drawer-field-label"><i data-lucide="${icon}"></i><span>${label}</span></div>
|
||||
<div class="drawer-field-control">${control}</div>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function openDrawer(resource, id) {
|
||||
const list = resource === "sales" ? state.data.sales : resource === "operations" ? state.data.operations : resource === "proposals" ? state.data.proposals : state.data.products;
|
||||
const item = list.find((x) => x.id === id);
|
||||
const drawer = document.querySelector("#drawer");
|
||||
const fields = resource === "sales"
|
||||
? [["target_customer","目标客户"],["priority","优先级"],["status","状态"]]
|
||||
: resource === "operations"
|
||||
? [["project_name","项目名称"],["project_version","项目版本"],["project_status","项目状态"],["current_stage","当前阶段"],["target_customer","目标客户"],["customer_need","客户需求"],["expected_contract_amount","预计签约金额"],["expected_sign_date","预计签约时间"],["sign_probability","签约概率"],["sop_stage","SOP 阶段"],["execution_progress","执行进度"],["current_deliverable","当前交付物"],["risks","风险与阻塞"],["next_action","下一步动作"]]
|
||||
: resource === "proposals"
|
||||
? [["customer_or_project_name","客户/项目"],["version","版本号"],["description","版本说明"],["created_date","创建日期"],["status","状态"]]
|
||||
: [["product_name","产品名称"],["version","版本号"],["version_goal","版本目标"],["feature_list","核心功能清单"],["launch_date","上线日期"],["status","当前状态"],["notes","备注"]];
|
||||
const fieldIcons = {
|
||||
target_customer: "user", priority: "flag", status: "circle-dot",
|
||||
project_name: "briefcase-business", project_version: "git-branch", project_status: "circle-dot", current_stage: "map-pin",
|
||||
customer_need: "file-text", expected_contract_amount: "banknote", expected_sign_date: "calendar",
|
||||
sign_probability: "percent", sop_stage: "list-checks", execution_progress: "activity",
|
||||
current_deliverable: "package", risks: "alert-triangle", next_action: "arrow-right",
|
||||
product_name: "box", version: "tag", version_goal: "target", feature_list: "list",
|
||||
launch_date: "calendar", notes: "sticky-note"
|
||||
};
|
||||
const multilineFields = ["customer_need", "current_deliverable", "risks", "next_action", "version_goal", "feature_list", "notes"];
|
||||
const followupTarget = resource === "sales" ? "sales" : resource === "proposals" ? "proposal" : resource === "operations" ? "operation" : resource === "products" ? "product" : "";
|
||||
const title = item.target_customer || item.project_name || item.customer_or_project_name || item.product_name;
|
||||
drawer.innerHTML = `<div class="drawer-panel"><div class="sticky top-0 z-10 flex items-center justify-between border-b border-slate-200 bg-white/95 px-5 py-3 backdrop-blur"><div><p class="text-[10px] font-semibold uppercase tracking-[0.18em] text-slate-400">Detail Drawer</p><div class="flex items-center gap-2"><h2 class="drawer-title text-[17px] font-semibold leading-6 text-slate-900">${title}</h2><span id="drawerSaveStatus" class="save-status"></span></div></div><button class="btn btn-ghost btn-sm" onclick="closeDrawer()">关闭</button></div><div class="grid gap-5 p-5">
|
||||
<section>
|
||||
<h3 class="drawer-section-title">属性</h3>
|
||||
<form id="drawerForm" class="drawer-fields">${fields.map(([key,label]) => drawerField(fieldIcons[key] || "circle", label, key, item[key], multilineFields.includes(key))).join("")}</form>
|
||||
</section>
|
||||
${resource === "proposals" ? `<section><h3 class="drawer-section-title">方案文件</h3><div class="grid gap-2">${["方案","成本","SOP","财务流程"].map((cat) => fileGroup("proposal", item.id, item.version, cat, item.files.filter((f) => f.file_category === cat))).join("")}</div></section>` : ""}
|
||||
${followupTarget ? `<section>
|
||||
<h3 class="drawer-section-title">活动 / 跟进</h3>
|
||||
<div class="grid gap-2">${(item.followups || []).map((f) => `<div class="activity-item"><div class="activity-icon"><i data-lucide="message-square"></i></div><div class="min-w-0 flex-1"><div class="flex justify-between gap-3 text-[12px] text-slate-500"><span>${f.follower} · ${f.follow_up_method}</span><span>${f.followed_at}</span></div><div class="mt-1 leading-5 text-slate-800 trix-content">${f.content}</div>${f.next_action ? `<p class="mt-1 leading-5 text-blue-700">下一步:${text(f.next_action)}</p>` : ""}</div><button class="activity-delete" onclick="deleteFollowup(event, ${f.id}, '${resource}', ${item.id})" title="删除评论"><i data-lucide="trash-2"></i></button></div>`).join("")}</div>
|
||||
<form class="comment-box mt-3" onsubmit="submitComment(event,'${followupTarget}',${item.id},'${resource}')">
|
||||
<input id="commentHidden_${resource}_${item.id}" type="hidden" name="content">
|
||||
<trix-editor input="commentHidden_${resource}_${item.id}" placeholder="添加评论" class="comment-trix"></trix-editor>
|
||||
<div class="comment-toolbar">
|
||||
<span class="comment-hint">支持 Markdown 格式</span>
|
||||
<button class="btn btn-primary btn-sm comment-submit" type="submit">评论</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>` : ""}
|
||||
</div></div>`;
|
||||
drawer.classList.add("open");
|
||||
bindDrawerAutosave(resource, item.id, item);
|
||||
if (window.lucide) window.lucide.createIcons();
|
||||
}
|
||||
|
||||
function setDrawerSaveStatus(message, tone = "muted") {
|
||||
const el = document.querySelector("#drawerSaveStatus");
|
||||
if (!el) return;
|
||||
el.textContent = message;
|
||||
el.dataset.tone = tone;
|
||||
}
|
||||
|
||||
function bindDrawerAutosave(resource, id, item) {
|
||||
document.querySelectorAll("#drawerForm .drawer-value").forEach((field) => {
|
||||
field.addEventListener("keydown", (event) => {
|
||||
if (event.key === "Enter" && field.tagName !== "TEXTAREA") field.blur();
|
||||
});
|
||||
field.addEventListener("blur", async () => {
|
||||
const value = field.value;
|
||||
if (value === field.dataset.original) return;
|
||||
const previous = field.dataset.original;
|
||||
field.dataset.original = value;
|
||||
setDrawerSaveStatus("保存中…");
|
||||
try {
|
||||
await api(`/api/${resource}/${id}`, { method: "PUT", body: JSON.stringify({ data: { [field.name]: value } }) });
|
||||
item[field.name] = value;
|
||||
const titleValue = item.target_customer || item.project_name || item.customer_or_project_name || item.product_name;
|
||||
const titleEl = document.querySelector(".drawer-title");
|
||||
if (titleEl) titleEl.textContent = titleValue;
|
||||
render();
|
||||
setDrawerSaveStatus("已保存", "success");
|
||||
setTimeout(() => setDrawerSaveStatus(""), 1200);
|
||||
} catch (error) {
|
||||
field.dataset.original = previous;
|
||||
setDrawerSaveStatus("保存失败", "danger");
|
||||
alert(`自动保存失败:${error.message}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
window.openDrawer = openDrawer;
|
||||
window.closeDrawer = () => document.querySelector("#drawer").classList.remove("open");
|
||||
window.submitComment = async (event, targetType, targetId, resource) => {
|
||||
event.preventDefault();
|
||||
const form = event.currentTarget;
|
||||
const editor = form.querySelector("trix-editor");
|
||||
const content = editor.editor.getDocument().toString().trim();
|
||||
if (!content) return;
|
||||
const button = form.querySelector(".comment-submit");
|
||||
button.disabled = true;
|
||||
button.textContent = "发送中…";
|
||||
await api(`/api/followups/${targetType}/${targetId}`, { method: "POST", body: JSON.stringify({ data: { content } }) });
|
||||
await load();
|
||||
openDrawer(resource, targetId);
|
||||
};
|
||||
|
||||
window.deleteFollowup = async (event, followupId, resource, targetId) => {
|
||||
event.stopPropagation();
|
||||
if (!confirm("确认删除这条评论?")) return;
|
||||
await api(`/api/followups/${followupId}`, { method: "DELETE" });
|
||||
await load();
|
||||
openDrawer(resource, targetId);
|
||||
};
|
||||
|
||||
document.querySelector("#drawer").addEventListener("click", (event) => {
|
||||
if (event.target === event.currentTarget) closeDrawer();
|
||||
});
|
||||
|
||||
document.querySelector("#tabs").addEventListener("click", (event) => {
|
||||
const button = event.target.closest("button[data-tab]");
|
||||
if (button) switchTab(button.dataset.tab);
|
||||
});
|
||||
document.querySelector("#refreshBtn").addEventListener("click", load);
|
||||
load().catch((error) => {
|
||||
document.querySelector("main").innerHTML = `<section class="card p-6 text-red-700">加载失败:${error.message}</section>`;
|
||||
});
|
||||
441
static/styles.css
Normal file
441
static/styles.css
Normal file
@@ -0,0 +1,441 @@
|
||||
body {
|
||||
min-width: 1180px;
|
||||
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
|
||||
}
|
||||
|
||||
.topbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.tabs button {
|
||||
align-items: center;
|
||||
border-bottom: 2px solid transparent;
|
||||
color: #64748b;
|
||||
display: inline-flex;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
gap: 8px;
|
||||
padding: 14px 16px;
|
||||
}
|
||||
|
||||
.tabs button.active {
|
||||
border-bottom-color: #1d4ed8;
|
||||
color: #1d4ed8;
|
||||
}
|
||||
|
||||
.panel {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.panel.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: white;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.metric-card {
|
||||
background: white;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
padding: 16px;
|
||||
text-align: left;
|
||||
transition: border-color 0.2s ease;
|
||||
}
|
||||
|
||||
.metric-card:hover {
|
||||
border-color: #93c5fd;
|
||||
}
|
||||
|
||||
.badge {
|
||||
border-radius: 999px;
|
||||
display: inline-flex;
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
padding: 6px 8px;
|
||||
}
|
||||
|
||||
.badge-red { background: #fef2f2; color: #b91c1c; }
|
||||
.badge-amber { background: #fffbeb; color: #b45309; }
|
||||
.badge-green { background: #ecfdf5; color: #047857; }
|
||||
.badge-blue { background: #eff6ff; color: #1d4ed8; }
|
||||
.badge-slate { background: #f1f5f9; color: #475569; }
|
||||
|
||||
.btn {
|
||||
align-items: center;
|
||||
border-radius: 6px;
|
||||
display: inline-flex;
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
gap: 8px;
|
||||
justify-content: center;
|
||||
min-height: 38px;
|
||||
padding: 8px 12px;
|
||||
}
|
||||
|
||||
[data-lucide] {
|
||||
height: 16px;
|
||||
stroke-width: 2;
|
||||
width: 16px;
|
||||
}
|
||||
|
||||
.btn-primary { background: #1d4ed8; color: white; }
|
||||
.btn-primary:hover { background: #1e40af; }
|
||||
.btn-ghost { background: white; border: 1px solid #e2e8f0; color: #334155; }
|
||||
.btn-ghost:hover { background: #f8fafc; }
|
||||
|
||||
input,
|
||||
select,
|
||||
textarea {
|
||||
border: 1px solid #cbd5e1;
|
||||
border-radius: 6px;
|
||||
min-height: 38px;
|
||||
padding: 8px 10px;
|
||||
}
|
||||
|
||||
textarea {
|
||||
min-height: 96px;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
border-bottom: 1px solid #e2e8f0;
|
||||
padding: 12px 14px;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
th {
|
||||
background: #f1f5f9;
|
||||
color: #475569;
|
||||
font-size: 13px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
td {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
|
||||
.btn-sm {
|
||||
min-height: 30px;
|
||||
padding: 5px 10px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.drawer {
|
||||
background: rgba(15, 23, 42, 0.28);
|
||||
display: none;
|
||||
inset: 0;
|
||||
justify-content: flex-end;
|
||||
position: fixed;
|
||||
z-index: 50;
|
||||
}
|
||||
|
||||
.drawer.open {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.drawer-panel {
|
||||
background: white;
|
||||
box-shadow: -18px 0 45px rgba(15, 23, 42, 0.14);
|
||||
height: 100vh;
|
||||
overflow-y: auto;
|
||||
width: 560px;
|
||||
}
|
||||
|
||||
.file-link {
|
||||
color: #1d4ed8;
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.drawer-section-title {
|
||||
color: #334155;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.drawer-fields {
|
||||
display: grid;
|
||||
gap: 1px;
|
||||
}
|
||||
|
||||
.drawer-field {
|
||||
align-items: start;
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
grid-template-columns: 148px minmax(0, 1fr);
|
||||
padding: 5px 0;
|
||||
}
|
||||
|
||||
.drawer-field-label {
|
||||
align-items: center;
|
||||
color: #64748b;
|
||||
display: flex;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
gap: 8px;
|
||||
min-height: 30px;
|
||||
}
|
||||
|
||||
.drawer-field-label [data-lucide] {
|
||||
color: #94a3b8;
|
||||
height: 15px;
|
||||
width: 15px;
|
||||
}
|
||||
|
||||
.drawer-field-control {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.drawer-value {
|
||||
background: transparent;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 5px;
|
||||
color: #0f172a;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
min-height: 30px;
|
||||
padding: 4px 8px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.drawer-value:hover {
|
||||
background: #f8fafc;
|
||||
border-color: #e2e8f0;
|
||||
}
|
||||
|
||||
.drawer-value:focus {
|
||||
background: white;
|
||||
border-color: #60a5fa;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.drawer-textarea {
|
||||
line-height: 1.45;
|
||||
min-height: 54px;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.activity-item {
|
||||
background: #f8fafc;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 7px;
|
||||
display: flex;
|
||||
font-size: 13px;
|
||||
gap: 9px;
|
||||
padding: 9px;
|
||||
}
|
||||
|
||||
.activity-icon {
|
||||
align-items: center;
|
||||
background: #dbeafe;
|
||||
border-radius: 999px;
|
||||
color: #1d4ed8;
|
||||
display: flex;
|
||||
flex: 0 0 auto;
|
||||
height: 24px;
|
||||
justify-content: center;
|
||||
width: 24px;
|
||||
}
|
||||
|
||||
.activity-icon [data-lucide] {
|
||||
height: 13px;
|
||||
width: 13px;
|
||||
}
|
||||
|
||||
.inline-form input,
|
||||
.inline-form select {
|
||||
height: 40px;
|
||||
border: 1px solid #cbd5e1;
|
||||
border-radius: 6px;
|
||||
padding: 8px 10px;
|
||||
font-size: 14px;
|
||||
background: white;
|
||||
min-width: 120px;
|
||||
}
|
||||
|
||||
.inline-form input:focus,
|
||||
.inline-form select:focus {
|
||||
border-color: #3b82f6;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.clickable-row {
|
||||
cursor: pointer;
|
||||
transition: background 0.15s;
|
||||
}
|
||||
.clickable-row:hover {
|
||||
background: #f1f5f9;
|
||||
}
|
||||
|
||||
.save-status {
|
||||
color: #94a3b8;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.save-status[data-tone="success"] {
|
||||
color: #059669;
|
||||
}
|
||||
|
||||
.save-status[data-tone="danger"] {
|
||||
color: #dc2626;
|
||||
}
|
||||
|
||||
.comment-box {
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.comment-box:focus-within {
|
||||
border-color: #93c5fd;
|
||||
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.08);
|
||||
}
|
||||
|
||||
/* Trix editor inside comment box */
|
||||
.comment-trix {
|
||||
min-height: 80px;
|
||||
}
|
||||
|
||||
.comment-trix trix-editor {
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
font-size: 13px;
|
||||
line-height: 1.55;
|
||||
min-height: 80px;
|
||||
padding: 10px 12px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.comment-trix trix-toolbar {
|
||||
border: 0;
|
||||
border-top: 1px solid #e2e8f0;
|
||||
background: #f8fafc;
|
||||
padding: 6px 6px;
|
||||
}
|
||||
|
||||
.comment-trix trix-toolbar .trix-button {
|
||||
border-radius: 4px;
|
||||
padding: 3px 5px;
|
||||
font-size: 12px;
|
||||
background: transparent;
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
.comment-trix trix-toolbar .trix-button:hover,
|
||||
.comment-trix trix-toolbar .trix-button.trix-active {
|
||||
background: #e2e8f0;
|
||||
color: #1e293b;
|
||||
}
|
||||
|
||||
.comment-trix trix-toolbar .trix-button-group {
|
||||
border-color: #e2e8f0;
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
.comment-toolbar {
|
||||
align-items: center;
|
||||
background: #f8fafc;
|
||||
border-top: 1px solid #e2e8f0;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 7px 8px;
|
||||
}
|
||||
|
||||
.comment-hint {
|
||||
color: #94a3b8;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.toolbar-icon {
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
padding: 3px;
|
||||
transition: background 0.15s;
|
||||
}
|
||||
.toolbar-icon:hover {
|
||||
background: #e2e8f0;
|
||||
color: #1e293b;
|
||||
}
|
||||
|
||||
.btn:disabled,
|
||||
.btn:disabled:hover {
|
||||
background: #e2e8f0;
|
||||
border-color: #e2e8f0;
|
||||
color: #94a3b8;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.activity-delete {
|
||||
align-items: center;
|
||||
border-radius: 5px;
|
||||
color: #94a3b8;
|
||||
display: inline-flex;
|
||||
flex: 0 0 auto;
|
||||
height: 26px;
|
||||
justify-content: center;
|
||||
opacity: 0;
|
||||
transition: background 0.15s, color 0.15s, opacity 0.15s;
|
||||
width: 26px;
|
||||
}
|
||||
|
||||
.activity-item:hover .activity-delete {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.activity-delete:hover {
|
||||
background: #fee2e2;
|
||||
color: #dc2626;
|
||||
}
|
||||
|
||||
.activity-delete [data-lucide] {
|
||||
height: 14px;
|
||||
width: 14px;
|
||||
}
|
||||
/* Trix content in activity items */
|
||||
.activity-item .trix-content {
|
||||
font-size: 13px;
|
||||
line-height: 1.55;
|
||||
}
|
||||
.activity-item .trix-content div {
|
||||
font-size: 13px;
|
||||
}
|
||||
.activity-item .trix-content strong {
|
||||
font-weight: 600;
|
||||
}
|
||||
.activity-item .trix-content a {
|
||||
color: #1d4ed8;
|
||||
text-decoration: underline;
|
||||
}
|
||||
.activity-item .trix-content ul,
|
||||
.activity-item .trix-content ol {
|
||||
padding-left: 16px;
|
||||
margin: 4px 0;
|
||||
}
|
||||
.activity-item .trix-content blockquote {
|
||||
border-left: 3px solid #e2e8f0;
|
||||
padding-left: 10px;
|
||||
color: #64748b;
|
||||
margin: 4px 0;
|
||||
}
|
||||
Reference in New Issue
Block a user