Compare commits
1 Commits
v1.0.1-bet
...
v1.1.0-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b6257ff19 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,3 +6,4 @@ data/uploads/
|
|||||||
__pycache__/
|
__pycache__/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
data/opc.sqlite
|
data/opc.sqlite
|
||||||
|
.env
|
||||||
|
|||||||
@@ -1,5 +1,34 @@
|
|||||||
# OPC Manager Version Log
|
# OPC Manager Version Log
|
||||||
|
|
||||||
|
## v1.1.0-beta — 2026-06-23
|
||||||
|
- **安全**:.env 环境变量管理(SECRET_KEY/DB)、debug=False、except 改 mysql.connector.Error + logging
|
||||||
|
- **性能**:attach_common 批量 IN 查询消除 N+1、monthly_finance 预解析 budget_data
|
||||||
|
- **XSS**:批量添加 esc() 转义 21 处用户可控字段
|
||||||
|
- **架构**:app.js 拆分为 7 个模块(utils/home/projects/proposals/products/finance/drawer)+ admin.js
|
||||||
|
- **表单统一**:.form-ctrl 统一所有输入控件(替代 drawer-value/fin-input/inline-form 等)
|
||||||
|
- **首页**:移除风险提醒卡片;财务趋势拆为 3 图(签约趋势/确收毛利/回款费用)
|
||||||
|
- **业务方案**:标准资料库 + 其他资料双 Tab;标准 7 项自动初始化;标准资料支持评论
|
||||||
|
- **经营管理**:
|
||||||
|
- 字段改名:客户名称→项目名称、销售人员→商务负责人
|
||||||
|
- 必填约束:项目名称/商务负责人/经营负责人/签约月份/签约金额>0
|
||||||
|
- 新增经营负责人字段;移除转移功能,新增删除项目
|
||||||
|
- 视图切换:确收/毛利 ↔ 回款/费用
|
||||||
|
- **重点工作与台账**:
|
||||||
|
- 统计卡片样式与经营管理统一(无图标)
|
||||||
|
- 视图切换 + 新增任务按钮移到卡片外右对齐
|
||||||
|
- 任务状态简化为 3 态(未开始/进行中/已结束)
|
||||||
|
- 优先级点击切换、项目右键菜单(重命名/创建副本)
|
||||||
|
- 新建任务绑定当前选中项目(修复新建到错误项目的 bug)
|
||||||
|
- 任务详情抽屉改为创建到 document.body(避免 innerHTML 清除)
|
||||||
|
- **用户体系**:
|
||||||
|
- 新增工作台:MCN·无界、无界·无界
|
||||||
|
- 新增账号:mcn/mcn123、wuji/wuji123
|
||||||
|
- 账号管理后台(admin 限定):增删改查账号 + 工作台权限分配
|
||||||
|
- sidebar 顶部用户头像(首字母)+ 显示名,点击弹菜单(账号管理/退出)
|
||||||
|
- sidebar sticky 定位,滚动时不消失
|
||||||
|
- **登录页**:参考 UOC 业务管理平台样式优化(图标 logo、密码显隐、loading 态、回车提交)
|
||||||
|
- **初始化**:启动自动修正任务状态空值/done→进行中等非法值
|
||||||
|
|
||||||
## v1.0.1-beta — 2026-06-22
|
## v1.0.1-beta — 2026-06-22
|
||||||
- 数据库迁移:SQLite → MySQL 9.6,适配占位符/类型/游标
|
- 数据库迁移:SQLite → MySQL 9.6,适配占位符/类型/游标
|
||||||
- 用户体系:管理员 + OPC负责人角色,工作台权限隔离,登录鉴权
|
- 用户体系:管理员 + OPC负责人角色,工作台权限隔离,登录鉴权
|
||||||
|
|||||||
@@ -1,19 +1,31 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
import shutil
|
import shutil
|
||||||
import sqlite3 # 保留用于数据迁移
|
import sqlite3 # 保留用于数据迁移
|
||||||
|
import logging
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
|
||||||
from flask import Flask, jsonify, render_template, request, send_file, session, redirect
|
from flask import Flask, jsonify, render_template, request, send_file, session, redirect
|
||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
|
||||||
|
|
||||||
|
|
||||||
ROOT = Path(__file__).resolve().parents[1]
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
DATA_DIR = ROOT / "data"
|
DATA_DIR = ROOT / "data"
|
||||||
UPLOAD_DIR = DATA_DIR / "uploads"
|
UPLOAD_DIR = DATA_DIR / "uploads"
|
||||||
DB_PATH = DATA_DIR / "opc.sqlite"
|
DB_PATH = DATA_DIR / "opc.sqlite"
|
||||||
WEIXIN_BASE = Path("/Users/mac/天机阁/地阁/慰心斋")
|
|
||||||
|
try:
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
load_dotenv(ROOT / ".env")
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
WEIXIN_BASE = Path(os.environ.get("WEIXIN_BASE", "/Users/mac/天机阁/地阁/慰心斋"))
|
||||||
|
|
||||||
DATA_DIR.mkdir(parents=True, exist_ok=True)
|
DATA_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
@@ -36,6 +48,21 @@ def login_required(f):
|
|||||||
return f(*args, **kwargs)
|
return f(*args, **kwargs)
|
||||||
return decorated
|
return decorated
|
||||||
|
|
||||||
|
|
||||||
|
def admin_required(f):
|
||||||
|
from functools import wraps
|
||||||
|
@wraps(f)
|
||||||
|
def decorated(*args, **kwargs):
|
||||||
|
if "user_id" not in session:
|
||||||
|
return jsonify({"error": "未登录"}), 401
|
||||||
|
if session.get("role") != "admin":
|
||||||
|
return jsonify({"error": "无权限"}), 403
|
||||||
|
return f(*args, **kwargs)
|
||||||
|
return decorated
|
||||||
|
|
||||||
|
|
||||||
|
ALL_TENANTS = ["科普·无界", "科研·无界", "医患·无界", "MCN·无界", "无界·无界"]
|
||||||
|
|
||||||
@app.route("/login")
|
@app.route("/login")
|
||||||
def login_page():
|
def login_page():
|
||||||
return render_template("login.html")
|
return render_template("login.html")
|
||||||
@@ -57,7 +84,7 @@ def auth_login():
|
|||||||
session["role"] = user["role"]
|
session["role"] = user["role"]
|
||||||
# 管理员可看所有工作台,OPC负责人看分配的工作台
|
# 管理员可看所有工作台,OPC负责人看分配的工作台
|
||||||
if user["role"] == "admin":
|
if user["role"] == "admin":
|
||||||
session["tenants"] = ["科普·无界", "科研·无界", "医患·无界"]
|
session["tenants"] = ["科普·无界", "科研·无界", "医患·无界", "MCN·无界", "无界·无界"]
|
||||||
else:
|
else:
|
||||||
ut = rows(conn, "SELECT tenant FROM user_tenants WHERE user_id=?", (user["id"],))
|
ut = rows(conn, "SELECT tenant FROM user_tenants WHERE user_id=?", (user["id"],))
|
||||||
session["tenants"] = [x["tenant"] for x in ut]
|
session["tenants"] = [x["tenant"] for x in ut]
|
||||||
@@ -87,16 +114,128 @@ def auth_me():
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
# ---------- 账号管理 API ----------
|
||||||
|
|
||||||
|
@app.route("/api/users")
|
||||||
|
@admin_required
|
||||||
|
def list_users():
|
||||||
|
conn = db()
|
||||||
|
try:
|
||||||
|
users = rows(conn, "SELECT id, username, display_name, role, created_at FROM users ORDER BY id")
|
||||||
|
ut_rows = rows(conn, "SELECT user_id, tenant FROM user_tenants")
|
||||||
|
tenant_map = {}
|
||||||
|
for r in ut_rows:
|
||||||
|
tenant_map.setdefault(r["user_id"], []).append(r["tenant"])
|
||||||
|
for u in users:
|
||||||
|
u["tenants"] = tenant_map.get(u["id"], [])
|
||||||
|
return jsonify(users)
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/api/users", methods=["POST"])
|
||||||
|
@admin_required
|
||||||
|
def create_user():
|
||||||
|
data = request.get_json(force=True)
|
||||||
|
username = (data.get("username") or "").strip()
|
||||||
|
display_name = (data.get("display_name") or "").strip()
|
||||||
|
password = data.get("password") or ""
|
||||||
|
role = data.get("role") or "opc_owner"
|
||||||
|
tenants = data.get("tenants") or []
|
||||||
|
if not username or not password or not display_name:
|
||||||
|
return jsonify({"error": "用户名/密码/显示名不能为空"}), 400
|
||||||
|
if role not in ("admin", "opc_owner"):
|
||||||
|
return jsonify({"error": "角色非法"}), 400
|
||||||
|
conn = db()
|
||||||
|
try:
|
||||||
|
if one(conn, "SELECT id FROM users WHERE username=?", (username,)):
|
||||||
|
return jsonify({"error": "用户名已存在"}), 400
|
||||||
|
_exec(conn, "INSERT INTO users (username, password_hash, display_name, role, created_at) VALUES (?,?,?,?,?)",
|
||||||
|
(username, generate_password_hash(password, "pbkdf2:sha256"), display_name, role, date.today().isoformat()))
|
||||||
|
u = one(conn, "SELECT id FROM users WHERE username=?", (username,))
|
||||||
|
for t in tenants:
|
||||||
|
if t in ALL_TENANTS:
|
||||||
|
_exec(conn, "INSERT IGNORE INTO user_tenants (user_id, tenant) VALUES (?,?)", (u["id"], t))
|
||||||
|
conn.commit()
|
||||||
|
return jsonify({"ok": True, "id": u["id"]})
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/api/users/<int:uid>", methods=["PUT"])
|
||||||
|
@admin_required
|
||||||
|
def update_user(uid):
|
||||||
|
data = request.get_json(force=True)
|
||||||
|
conn = db()
|
||||||
|
try:
|
||||||
|
u = one(conn, "SELECT * FROM users WHERE id=?", (uid,))
|
||||||
|
if not u:
|
||||||
|
return jsonify({"error": "用户不存在"}), 404
|
||||||
|
display_name = (data.get("display_name") or "").strip() or u["display_name"]
|
||||||
|
role = data.get("role") or u["role"]
|
||||||
|
if role not in ("admin", "opc_owner"):
|
||||||
|
return jsonify({"error": "角色非法"}), 400
|
||||||
|
password = data.get("password") or ""
|
||||||
|
if password:
|
||||||
|
_exec(conn, "UPDATE users SET display_name=?, role=?, password_hash=? WHERE id=?",
|
||||||
|
(display_name, role, generate_password_hash(password, "pbkdf2:sha256"), uid))
|
||||||
|
else:
|
||||||
|
_exec(conn, "UPDATE users SET display_name=?, role=? WHERE id=?", (display_name, role, uid))
|
||||||
|
# 更新工作台权限
|
||||||
|
if "tenants" in data:
|
||||||
|
_exec(conn, "DELETE FROM user_tenants WHERE user_id=?", (uid,))
|
||||||
|
for t in data["tenants"]:
|
||||||
|
if t in ALL_TENANTS:
|
||||||
|
_exec(conn, "INSERT IGNORE INTO user_tenants (user_id, tenant) VALUES (?,?)", (uid, t))
|
||||||
|
# 不允许删除最后一个 admin
|
||||||
|
if role != "admin":
|
||||||
|
admin_count = one(conn, "SELECT COUNT(*) AS c FROM users WHERE role='admin'")["c"]
|
||||||
|
if admin_count == 0:
|
||||||
|
return jsonify({"error": "至少保留一个管理员"}), 400
|
||||||
|
conn.commit()
|
||||||
|
return jsonify({"ok": True})
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/api/users/<int:uid>", methods=["DELETE"])
|
||||||
|
@admin_required
|
||||||
|
def delete_user(uid):
|
||||||
|
if uid == session.get("user_id"):
|
||||||
|
return jsonify({"error": "不能删除当前登录账号"}), 400
|
||||||
|
conn = db()
|
||||||
|
try:
|
||||||
|
u = one(conn, "SELECT * FROM users WHERE id=?", (uid,))
|
||||||
|
if not u:
|
||||||
|
return jsonify({"error": "用户不存在"}), 404
|
||||||
|
# 不允许删除最后一个 admin
|
||||||
|
if u["role"] == "admin":
|
||||||
|
admin_count = one(conn, "SELECT COUNT(*) AS c FROM users WHERE role='admin'")["c"]
|
||||||
|
if admin_count <= 1:
|
||||||
|
return jsonify({"error": "至少保留一个管理员"}), 400
|
||||||
|
_exec(conn, "DELETE FROM user_tenants WHERE user_id=?", (uid,))
|
||||||
|
_exec(conn, "DELETE FROM users WHERE id=?", (uid,))
|
||||||
|
conn.commit()
|
||||||
|
return jsonify({"ok": True})
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/api/tenants")
|
||||||
|
def list_tenants():
|
||||||
|
return jsonify(ALL_TENANTS)
|
||||||
|
|
||||||
|
|
||||||
# ---------- 业务 API ----------
|
# ---------- 业务 API ----------
|
||||||
|
|
||||||
|
|
||||||
def db():
|
def db():
|
||||||
return mysql.connector.connect(
|
return mysql.connector.connect(
|
||||||
host="127.0.0.1",
|
host=os.environ.get("DB_HOST", "127.0.0.1"),
|
||||||
port=3306,
|
port=int(os.environ.get("DB_PORT", "3306")),
|
||||||
user="opc",
|
user=os.environ.get("DB_USER", "opc"),
|
||||||
password="opc123456",
|
password=os.environ.get("DB_PASSWORD", "opc123456"),
|
||||||
database="opc",
|
database=os.environ.get("DB_NAME", "opc"),
|
||||||
charset="utf8mb4",
|
charset="utf8mb4",
|
||||||
collation="utf8mb4_unicode_ci",
|
collation="utf8mb4_unicode_ci",
|
||||||
)
|
)
|
||||||
@@ -263,7 +402,7 @@ def init_db():
|
|||||||
role VARCHAR(50) NOT NULL DEFAULT 'opc_owner',
|
role VARCHAR(50) NOT NULL DEFAULT 'opc_owner',
|
||||||
created_at VARCHAR(30) NOT NULL DEFAULT ''
|
created_at VARCHAR(30) NOT NULL DEFAULT ''
|
||||||
)""")
|
)""")
|
||||||
except: pass
|
except mysql.connector.Error as e: logger.debug(f"users table: {e}")
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
# 用户-工作台关联表
|
# 用户-工作台关联表
|
||||||
@@ -273,7 +412,7 @@ def init_db():
|
|||||||
tenant VARCHAR(100) NOT NULL,
|
tenant VARCHAR(100) NOT NULL,
|
||||||
UNIQUE KEY (user_id, tenant)
|
UNIQUE KEY (user_id, tenant)
|
||||||
)""")
|
)""")
|
||||||
except: pass
|
except mysql.connector.Error as e: logger.debug(f"user_tenants table: {e}")
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
# project_finances 表(月度预算 + 签约信息)
|
# project_finances 表(月度预算 + 签约信息)
|
||||||
@@ -293,7 +432,7 @@ def init_db():
|
|||||||
created_at VARCHAR(30) NOT NULL DEFAULT '',
|
created_at VARCHAR(30) NOT NULL DEFAULT '',
|
||||||
updated_at VARCHAR(30) NOT NULL DEFAULT ''
|
updated_at VARCHAR(30) NOT NULL DEFAULT ''
|
||||||
)""")
|
)""")
|
||||||
except: pass
|
except mysql.connector.Error as e: logger.debug(f"project_finances table: {e}")
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
# Schema migrations — 添加后续迁移的列(幂等)
|
# Schema migrations — 添加后续迁移的列(幂等)
|
||||||
@@ -321,9 +460,18 @@ def init_db():
|
|||||||
|
|
||||||
for mig in migrations:
|
for mig in migrations:
|
||||||
try: _exec(conn, mig)
|
try: _exec(conn, mig)
|
||||||
except: pass
|
except mysql.connector.Error as e: logger.debug(f"migration skipped: {e}")
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
# 数据修正:status 为空或 'done' 的任务修正为合法值
|
||||||
|
try:
|
||||||
|
_exec(conn, "UPDATE project_tasks SET status='未开始' WHERE status='' OR status IS NULL")
|
||||||
|
_exec(conn, "UPDATE project_tasks SET status='已结束' WHERE status='done'")
|
||||||
|
_exec(conn, "UPDATE project_tasks SET status='进行中' WHERE status='验收中'")
|
||||||
|
conn.commit()
|
||||||
|
except mysql.connector.Error as e:
|
||||||
|
logger.warning(f"task status fix failed: {e}")
|
||||||
|
|
||||||
# 初始化默认用户(只执行一次)
|
# 初始化默认用户(只执行一次)
|
||||||
if not one(conn, "SELECT id FROM users LIMIT 1"):
|
if not one(conn, "SELECT id FROM users LIMIT 1"):
|
||||||
_exec(conn, """INSERT INTO users (username, password_hash, display_name, role, created_at) VALUES (?,?,?,?,?)""",
|
_exec(conn, """INSERT INTO users (username, password_hash, display_name, role, created_at) VALUES (?,?,?,?,?)""",
|
||||||
@@ -334,135 +482,147 @@ def init_db():
|
|||||||
("keyan", generate_password_hash("keyan123", "pbkdf2:sha256"), "科研负责人", "opc_owner", date.today().isoformat()))
|
("keyan", generate_password_hash("keyan123", "pbkdf2:sha256"), "科研负责人", "opc_owner", date.today().isoformat()))
|
||||||
_exec(conn, """INSERT INTO users (username, password_hash, display_name, role, created_at) VALUES (?,?,?,?,?)""",
|
_exec(conn, """INSERT INTO users (username, password_hash, display_name, role, created_at) VALUES (?,?,?,?,?)""",
|
||||||
("yihuan", generate_password_hash("yihuan123", "pbkdf2:sha256"), "医患负责人", "opc_owner", date.today().isoformat()))
|
("yihuan", generate_password_hash("yihuan123", "pbkdf2:sha256"), "医患负责人", "opc_owner", date.today().isoformat()))
|
||||||
|
_exec(conn, """INSERT INTO users (username, password_hash, display_name, role, created_at) VALUES (?,?,?,?,?)""",
|
||||||
|
("mcn", generate_password_hash("mcn123", "pbkdf2:sha256"), "MCN负责人", "opc_owner", date.today().isoformat()))
|
||||||
|
_exec(conn, """INSERT INTO users (username, password_hash, display_name, role, created_at) VALUES (?,?,?,?,?)""",
|
||||||
|
("wuji", generate_password_hash("wuji123", "pbkdf2:sha256"), "无界负责人", "opc_owner", date.today().isoformat()))
|
||||||
# 各 OPC 负责人绑定工作台
|
# 各 OPC 负责人绑定工作台
|
||||||
for uname, tenant in [("kepu","科普·无界"),("keyan","科研·无界"),("yihuan","医患·无界")]:
|
for uname, tenant in [("kepu","科普·无界"),("keyan","科研·无界"),("yihuan","医患·无界"),("mcn","MCN·无界"),("wuji","无界·无界")]:
|
||||||
u = one(conn, "SELECT id FROM users WHERE username=?", (uname,))
|
u = one(conn, "SELECT id FROM users WHERE username=?", (uname,))
|
||||||
if u:
|
if u:
|
||||||
_exec(conn, "INSERT INTO user_tenants (user_id, tenant) VALUES (?,?)", (u["id"], tenant))
|
_exec(conn, "INSERT INTO user_tenants (user_id, tenant) VALUES (?,?)", (u["id"], tenant))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
if one(conn, "SELECT id FROM sales_leads LIMIT 1"):
|
|
||||||
conn.close()
|
|
||||||
return
|
|
||||||
|
|
||||||
sales = [
|
|
||||||
("齐鲁制药", "P0", "跟进中", "多产品线科普年度框架,需推进高层沟通。"),
|
|
||||||
("百利天恒", "P0", "方案中", "BL-B01D1 上市前医生教育机会,准备方案。"),
|
|
||||||
("信达生物", "P0", "已签约", "现有科普项目升级/续约,重点保障执行。"),
|
|
||||||
("三生制药", "P1", "待跟进", "多科室医生教育+患者科普机会。"),
|
|
||||||
("天广实生物", "P1", "待跟进", "血液肿瘤医生教育机会。"),
|
|
||||||
]
|
|
||||||
for customer, priority, status, note in sales:
|
|
||||||
cur = _exec(conn,
|
|
||||||
"INSERT INTO sales_leads (target_customer, priority, status) VALUES (?,?,?)",
|
|
||||||
(customer, priority, status),
|
|
||||||
)
|
|
||||||
_exec(conn,
|
|
||||||
"INSERT INTO follow_up_records (target_type,target_id,followed_at,content,next_action) VALUES (?,?,?,?,?)",
|
|
||||||
("sales", cur.lastrowid, date.today().isoformat(), note, "明确下一次沟通人和时间"),
|
|
||||||
)
|
|
||||||
|
|
||||||
cur = _exec(conn,
|
|
||||||
"INSERT INTO business_proposals (customer_or_project_name,version,description,status,created_date) VALUES (?,?,?,?,?)",
|
|
||||||
("信达生物", "v1.5", "信达科普项目续约与报价方案", "已提交客户", "2026-05-28"),
|
|
||||||
)
|
|
||||||
proposal_id = cur.lastrowid
|
|
||||||
proposal_dir = WEIXIN_BASE / "2、业务方案/信达/v1.5"
|
|
||||||
for category, names in {
|
|
||||||
"方案": ["整体方案.pptx", "整体方案.pdf"],
|
|
||||||
"成本": ["业务报价-2亿方案.xlsx", "业务报价-5250万方案.xlsx", "5、最新报价.xlsx"],
|
|
||||||
"SOP": ["SOP.docx"],
|
|
||||||
"财务流程": ["财务流程.docx"],
|
|
||||||
}.items():
|
|
||||||
for name in names:
|
|
||||||
add_file_index(conn, "proposal", proposal_id, "v1.5", category, proposal_dir / name, external=True)
|
|
||||||
|
|
||||||
projects = [
|
|
||||||
("圆心科技 科普文章项目", "v2026-文章", "execution", "SOP 执行中", "内容生产", 55, "文章内容生产与审核执行中"),
|
|
||||||
("圆心科技 科普视频项目", "v2026-视频", "execution", "SOP 执行中", "内容生产", 45, "视频脚本、拍摄与审核推进"),
|
|
||||||
("圆心科技 科普专访项目", "v2026-专访", "opportunity", "方案已提交", "商务推进", 0, "专访项目推动签约"),
|
|
||||||
]
|
|
||||||
op_dir = WEIXIN_BASE / "3、运营方案"
|
|
||||||
for name, version, kind, status, stage, progress, note in projects:
|
|
||||||
cur = _exec(conn,
|
|
||||||
"""INSERT INTO operation_projects
|
|
||||||
(project_name,project_version,project_type,project_status,current_stage,target_customer,customer_need,
|
|
||||||
expected_contract_amount,expected_sign_date,sign_probability,next_action,sop_stage,execution_progress,current_deliverable)
|
|
||||||
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)""",
|
|
||||||
(name, version, kind, status, stage, "圆心科技", "科普内容项目执行与管理", 0 if kind == "execution" else 200, "2026-06", 100 if kind == "execution" else 70, "补齐版本要求文件并更新下一节点", stage, progress, note),
|
|
||||||
)
|
|
||||||
_exec(conn,
|
|
||||||
"INSERT INTO follow_up_records (target_type,target_id,followed_at,content,next_action) VALUES (?,?,?,?,?)",
|
|
||||||
("operation", cur.lastrowid, date.today().isoformat(), note, "补齐版本要求文件并更新下一节点"),
|
|
||||||
)
|
|
||||||
|
|
||||||
file_map = [
|
|
||||||
(1, "v2026-文章", "项目方案", "圆心科技--科普文章项目(1).pptx"),
|
|
||||||
(2, "v2026-视频", "项目方案", "圆心科技-科普视频项目(1).pptx"),
|
|
||||||
(3, "v2026-专访", "项目方案", "圆心科技-科普专访项目-2026年(1).pdf"),
|
|
||||||
(1, "v2026-文章", "项目管理手册", "圆心科技《项目管理手册》-2026年.pdf"),
|
|
||||||
(2, "v2026-视频", "审核标准", "科普项目-审核标准(文章-视频-音频).pdf"),
|
|
||||||
]
|
|
||||||
for project_id, version, category, filename in file_map:
|
|
||||||
add_file_index(conn, "operation", project_id, version, category, op_dir / filename, external=True)
|
|
||||||
|
|
||||||
products = [
|
|
||||||
("妙手医生服务小程序", "v1.1", "视频任务增强 + 积分商城", "草稿箱、批量上传、积分商城、消息通知", "2026-Q3", "规划中", "科普平台"),
|
|
||||||
("数字化营销后台管理系统", "v1.2", "运营数据看板 + 智能审核", "医生活跃、任务完成率、AI 预审、渠道数据上报", "2026-Q3", "设计中", "真研平台"),
|
|
||||||
("妙手患者服务", "v0.5", "科普浏览 + 医生主页 MVP", "科普文章/视频浏览、医生主页、搜索", "2026-Q3", "规划中", "科普平台"),
|
|
||||||
("数字人内容平台", "v0.1", "基础数字人视频生成 MVP", "预设形象、AI 配音、脚本驱动、简单模板", "2026-Q3", "规划中", "科普平台"),
|
|
||||||
("渠道分发引擎", "v1.0", "六渠道统一分发", "分发 API、内容适配、分发排期、效果追踪", "2027-Q1", "规划中", "科普平台"),
|
|
||||||
]
|
|
||||||
for product in products:
|
|
||||||
cur = _exec(conn,
|
|
||||||
"INSERT INTO product_versions (product_name,version,version_goal,feature_list,launch_date,status,platform) VALUES (?,?,?,?,?,?,?)",
|
|
||||||
product,
|
|
||||||
)
|
|
||||||
_exec(conn,
|
|
||||||
"INSERT INTO follow_up_records (target_type,target_id,followed_at,content,next_action) VALUES (?,?,?,?,?)",
|
|
||||||
("product", cur.lastrowid, date.today().isoformat(), f"{product[0]} {product[1]}:{product[2]}", "按路线图推进"),
|
|
||||||
)
|
|
||||||
|
|
||||||
for month, record_type, category, amount, notes in [
|
|
||||||
("2026-05", "revenue", "信达生物续约确认收入", 120, "信达项目阶段确收"),
|
|
||||||
("2026-06", "revenue", "信达生物续约确认收入", 80, "信达项目尾款预估"),
|
|
||||||
("2026-05", "cost_expense", "内容生产", 32, "医生劳务与内容制作"),
|
|
||||||
("2026-05", "cost_expense", "运营管理", 16, "项目管理与渠道协同"),
|
|
||||||
("2026-06", "cost_expense", "渠道分发", 24, "投放与分发费用"),
|
|
||||||
]:
|
|
||||||
_exec(conn,
|
|
||||||
"INSERT INTO finance_records (month,record_type,category,amount,occurred_date,notes) VALUES (?,?,?,?,?,?)",
|
|
||||||
(month, record_type, category, amount, f"{month}-01", notes),
|
|
||||||
)
|
|
||||||
|
|
||||||
# Seed project tasks for 信达科普文章项目 (project_id=1)
|
|
||||||
tasks_seed = [
|
|
||||||
("阶段1:渠道与商务确认", "商务对接", "合同签订", "Anna", "2026-06-30", "法务审核中", "合同签订后开始执行"),
|
|
||||||
("阶段1:渠道与商务确认", "官媒渠道确认", "沟通官媒确定", "段丽华", "2026-06-30", "官媒尽力推,以先达成合作为准", "集团支持"),
|
|
||||||
("阶段1:渠道与商务确认", "官媒渠道确认", "官媒合作签约", "段丽华", "2026-06-18", "", "官媒确认细节"),
|
|
||||||
("阶段2:系统与标准搭建", "系统开发上线", "音频专访系统开发上线", "戴敏/梁军营", "2026-06-18", "客户比较着急执行,需要技术的资源", ""),
|
|
||||||
("阶段2:系统与标准搭建", "系统开发上线", "精品视频系统开发上线", "戴敏/梁军营", "2026-06-25", "", ""),
|
|
||||||
("阶段2:系统与标准搭建", "标准与培训", "业务执行手册SOP", "胡龙飞", "2026-06-12", "", "系统开发上线"),
|
|
||||||
("阶段3:人员与审核入驻", "团队组建", "医学审核人员到位", "胡龙飞", "2026-06-15", "", "审核人员招聘"),
|
|
||||||
("阶段3:人员与审核入驻", "团队组建", "视频制作人员到位", "胡龙飞", "2026-06-18", "", "项目经理招聘"),
|
|
||||||
("阶段4:供应链与制作", "供应商准入", "准入拍摄/剪辑/主持人", "胡龙飞/侯亚凤", "2026-06-18", "", ""),
|
|
||||||
("阶段2:系统与标准搭建", "脚本生产及审核", "生产脚本", "军营", "2026-06-12", "脚本目前生产比较机械,需要提前准备", "细分标签领域完成"),
|
|
||||||
]
|
|
||||||
for phase, milestone, task, owner, due_date, blockers, notes in tasks_seed:
|
|
||||||
_exec(conn,
|
|
||||||
"INSERT INTO project_tasks (project_id,phase,milestone,task,owner,due_date,blockers,notes) VALUES (?,?,?,?,?,?,?,?)",
|
|
||||||
(1, phase, milestone, task, owner, due_date, blockers, notes),
|
|
||||||
)
|
|
||||||
|
|
||||||
conn.commit()
|
|
||||||
conn.close()
|
conn.close()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def seed_db():
|
||||||
|
"""填充初始示例数据(仅在空库时执行一次)"""
|
||||||
|
conn = db()
|
||||||
|
try:
|
||||||
|
if one(conn, "SELECT id FROM sales_leads LIMIT 1"):
|
||||||
|
return # 已有数据,跳过
|
||||||
|
|
||||||
|
sales = [
|
||||||
|
("齐鲁制药", "P0", "跟进中", "多产品线科普年度框架,需推进高层沟通。"),
|
||||||
|
("百利天恒", "P0", "方案中", "BL-B01D1 上市前医生教育机会,准备方案。"),
|
||||||
|
("信达生物", "P0", "已签约", "现有科普项目升级/续约,重点保障执行。"),
|
||||||
|
("三生制药", "P1", "待跟进", "多科室医生教育+患者科普机会。"),
|
||||||
|
("天广实生物", "P1", "待跟进", "血液肿瘤医生教育机会。"),
|
||||||
|
]
|
||||||
|
for customer, priority, status, note in sales:
|
||||||
|
cur = _exec(conn,
|
||||||
|
"INSERT INTO sales_leads (target_customer, priority, status) VALUES (?,?,?)",
|
||||||
|
(customer, priority, status),
|
||||||
|
)
|
||||||
|
_exec(conn,
|
||||||
|
"INSERT INTO follow_up_records (target_type,target_id,followed_at,content,next_action) VALUES (?,?,?,?,?)",
|
||||||
|
("sales", cur.lastrowid, date.today().isoformat(), note, "明确下一次沟通人和时间"),
|
||||||
|
)
|
||||||
|
|
||||||
|
cur = _exec(conn,
|
||||||
|
"INSERT INTO business_proposals (customer_or_project_name,version,description,status,created_date) VALUES (?,?,?,?,?)",
|
||||||
|
("信达生物", "v1.5", "信达科普项目续约与报价方案", "已提交客户", "2026-05-28"),
|
||||||
|
)
|
||||||
|
proposal_id = cur.lastrowid
|
||||||
|
proposal_dir = WEIXIN_BASE / "2、业务方案/信达/v1.5"
|
||||||
|
for category, names in {
|
||||||
|
"方案": ["整体方案.pptx", "整体方案.pdf"],
|
||||||
|
"成本": ["业务报价-2亿方案.xlsx", "业务报价-5250万方案.xlsx", "5、最新报价.xlsx"],
|
||||||
|
"SOP": ["SOP.docx"],
|
||||||
|
"财务流程": ["财务流程.docx"],
|
||||||
|
}.items():
|
||||||
|
for name in names:
|
||||||
|
add_file_index(conn, "proposal", proposal_id, "v1.5", category, proposal_dir / name, external=True)
|
||||||
|
|
||||||
|
projects = [
|
||||||
|
("圆心科技 科普文章项目", "v2026-文章", "execution", "SOP 执行中", "内容生产", 55, "文章内容生产与审核执行中"),
|
||||||
|
("圆心科技 科普视频项目", "v2026-视频", "execution", "SOP 执行中", "内容生产", 45, "视频脚本、拍摄与审核推进"),
|
||||||
|
("圆心科技 科普专访项目", "v2026-专访", "opportunity", "方案已提交", "商务推进", 0, "专访项目推动签约"),
|
||||||
|
]
|
||||||
|
op_dir = WEIXIN_BASE / "3、运营方案"
|
||||||
|
for name, version, kind, status, stage, progress, note in projects:
|
||||||
|
cur = _exec(conn,
|
||||||
|
"""INSERT INTO operation_projects
|
||||||
|
(project_name,project_version,project_type,project_status,current_stage,target_customer,customer_need,
|
||||||
|
expected_contract_amount,expected_sign_date,sign_probability,next_action,sop_stage,execution_progress,current_deliverable)
|
||||||
|
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)""",
|
||||||
|
(name, version, kind, status, stage, "圆心科技", "科普内容项目执行与管理", 0 if kind == "execution" else 200, "2026-06", 100 if kind == "execution" else 70, "补齐版本要求文件并更新下一节点", stage, progress, note),
|
||||||
|
)
|
||||||
|
_exec(conn,
|
||||||
|
"INSERT INTO follow_up_records (target_type,target_id,followed_at,content,next_action) VALUES (?,?,?,?,?)",
|
||||||
|
("operation", cur.lastrowid, date.today().isoformat(), note, "补齐版本要求文件并更新下一节点"),
|
||||||
|
)
|
||||||
|
|
||||||
|
file_map = [
|
||||||
|
(1, "v2026-文章", "项目方案", "圆心科技--科普文章项目(1).pptx"),
|
||||||
|
(2, "v2026-视频", "项目方案", "圆心科技-科普视频项目(1).pptx"),
|
||||||
|
(3, "v2026-专访", "项目方案", "圆心科技-科普专访项目-2026年(1).pdf"),
|
||||||
|
(1, "v2026-文章", "项目管理手册", "圆心科技《项目管理手册》-2026年.pdf"),
|
||||||
|
(2, "v2026-视频", "审核标准", "科普项目-审核标准(文章-视频-音频).pdf"),
|
||||||
|
]
|
||||||
|
for project_id, version, category, filename in file_map:
|
||||||
|
add_file_index(conn, "operation", project_id, version, category, op_dir / filename, external=True)
|
||||||
|
|
||||||
|
products = [
|
||||||
|
("妙手医生服务小程序", "v1.1", "视频任务增强 + 积分商城", "草稿箱、批量上传、积分商城、消息通知", "2026-Q3", "规划中", "科普平台"),
|
||||||
|
("数字化营销后台管理系统", "v1.2", "运营数据看板 + 智能审核", "医生活跃、任务完成率、AI 预审、渠道数据上报", "2026-Q3", "设计中", "真研平台"),
|
||||||
|
("妙手患者服务", "v0.5", "科普浏览 + 医生主页 MVP", "科普文章/视频浏览、医生主页、搜索", "2026-Q3", "规划中", "科普平台"),
|
||||||
|
("数字人内容平台", "v0.1", "基础数字人视频生成 MVP", "预设形象、AI 配音、脚本驱动、简单模板", "2026-Q3", "规划中", "科普平台"),
|
||||||
|
("渠道分发引擎", "v1.0", "六渠道统一分发", "分发 API、内容适配、分发排期、效果追踪", "2027-Q1", "规划中", "科普平台"),
|
||||||
|
]
|
||||||
|
for product in products:
|
||||||
|
cur = _exec(conn,
|
||||||
|
"INSERT INTO product_versions (product_name,version,version_goal,feature_list,launch_date,status,platform) VALUES (?,?,?,?,?,?,?)",
|
||||||
|
product,
|
||||||
|
)
|
||||||
|
_exec(conn,
|
||||||
|
"INSERT INTO follow_up_records (target_type,target_id,followed_at,content,next_action) VALUES (?,?,?,?,?)",
|
||||||
|
("product", cur.lastrowid, date.today().isoformat(), f"{product[0]} {product[1]}:{product[2]}", "按路线图推进"),
|
||||||
|
)
|
||||||
|
|
||||||
|
for month, record_type, category, amount, notes in [
|
||||||
|
("2026-05", "revenue", "信达生物续约确认收入", 120, "信达项目阶段确收"),
|
||||||
|
("2026-06", "revenue", "信达生物续约确认收入", 80, "信达项目尾款预估"),
|
||||||
|
("2026-05", "cost_expense", "内容生产", 32, "医生劳务与内容制作"),
|
||||||
|
("2026-05", "cost_expense", "运营管理", 16, "项目管理与渠道协同"),
|
||||||
|
("2026-06", "cost_expense", "渠道分发", 24, "投放与分发费用"),
|
||||||
|
]:
|
||||||
|
_exec(conn,
|
||||||
|
"INSERT INTO finance_records (month,record_type,category,amount,occurred_date,notes) VALUES (?,?,?,?,?,?)",
|
||||||
|
(month, record_type, category, amount, f"{month}-01", notes),
|
||||||
|
)
|
||||||
|
|
||||||
|
tasks_seed = [
|
||||||
|
("阶段1:渠道与商务确认", "商务对接", "合同签订", "Anna", "2026-06-30", "法务审核中", "合同签订后开始执行"),
|
||||||
|
("阶段1:渠道与商务确认", "官媒渠道确认", "沟通官媒确定", "段丽华", "2026-06-30", "官媒尽力推,以先达成合作为准", "集团支持"),
|
||||||
|
("阶段1:渠道与商务确认", "官媒渠道确认", "官媒合作签约", "段丽华", "2026-06-18", "", "官媒确认细节"),
|
||||||
|
("阶段2:系统与标准搭建", "系统开发上线", "音频专访系统开发上线", "戴敏/梁军营", "2026-06-18", "客户比较着急执行,需要技术的资源", ""),
|
||||||
|
("阶段2:系统与标准搭建", "系统开发上线", "精品视频系统开发上线", "戴敏/梁军营", "2026-06-25", "", ""),
|
||||||
|
("阶段2:系统与标准搭建", "标准与培训", "业务执行手册SOP", "胡龙飞", "2026-06-12", "", "系统开发上线"),
|
||||||
|
("阶段3:人员与审核入驻", "团队组建", "医学审核人员到位", "胡龙飞", "2026-06-15", "", "审核人员招聘"),
|
||||||
|
("阶段3:人员与审核入驻", "团队组建", "视频制作人员到位", "胡龙飞", "2026-06-18", "", "项目经理招聘"),
|
||||||
|
("阶段4:供应链与制作", "供应商准入", "准入拍摄/剪辑/主持人", "胡龙飞/侯亚凤", "2026-06-18", "", ""),
|
||||||
|
("阶段2:系统与标准搭建", "脚本生产及审核", "生产脚本", "军营", "2026-06-12", "脚本目前生产比较机械,需要提前准备", "细分标签领域完成"),
|
||||||
|
]
|
||||||
|
for phase, milestone, task, owner, due_date, blockers, notes in tasks_seed:
|
||||||
|
_exec(conn,
|
||||||
|
"INSERT INTO project_tasks (project_id,phase,milestone,task,owner,due_date,blockers,notes) VALUES (?,?,?,?,?,?,?,?)",
|
||||||
|
(1, phase, milestone, task, owner, due_date, blockers, notes),
|
||||||
|
)
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
logger.info("Seed data inserted successfully")
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
def add_file_index(conn, module, owner_id, owner_version, category, path, external=True):
|
def add_file_index(conn, module, owner_id, owner_version, category, path, external=True):
|
||||||
path = Path(path)
|
path = Path(path)
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
return
|
return
|
||||||
_exec(conn,
|
_exec(conn,
|
||||||
"""INSERT INTO file_assets
|
"""INSERT INTO file_assets
|
||||||
(module,owner_id,owner_version,file_category,file_name,file_type,file_size,file_path,is_external)
|
(module,owner_id,owner_version,file_category,file_name,file_type,file_size,file_path,is_external)
|
||||||
VALUES (?,?,?,?,?,?,?,?,?)""",
|
VALUES (?,?,?,?,?,?,?,?,?)""",
|
||||||
@@ -480,48 +640,90 @@ def latest_followup(conn, target_type, target_id):
|
|||||||
|
|
||||||
|
|
||||||
def attach_common(conn, resource, items):
|
def attach_common(conn, resource, items):
|
||||||
|
"""批量加载 followups 和 files,避免 N+1 查询"""
|
||||||
|
if not items:
|
||||||
|
return items
|
||||||
target_map = {"sales": "sales", "proposals": "proposal", "operations": "operation", "products": "product"}
|
target_map = {"sales": "sales", "proposals": "proposal", "operations": "operation", "products": "product"}
|
||||||
for item in items:
|
target_type = target_map.get(resource)
|
||||||
if resource in target_map:
|
ids = [item["id"] for item in items]
|
||||||
item["followups"] = rows(
|
|
||||||
conn,
|
# 批量查 followups(一次性 IN 查询)
|
||||||
"SELECT * FROM follow_up_records WHERE target_type=? AND target_id=? ORDER BY followed_at DESC, id DESC",
|
if target_type:
|
||||||
(target_map[resource], item["id"]),
|
placeholders = ",".join(["?"] * len(ids))
|
||||||
)
|
all_followups = rows(
|
||||||
|
conn,
|
||||||
|
f"SELECT * FROM follow_up_records WHERE target_type=? AND target_id IN ({placeholders}) ORDER BY followed_at DESC, id DESC",
|
||||||
|
[target_type] + ids,
|
||||||
|
)
|
||||||
|
# 按目标 id 分组
|
||||||
|
followups_by_id = {}
|
||||||
|
for fu in all_followups:
|
||||||
|
followups_by_id.setdefault(fu["target_id"], []).append(fu)
|
||||||
|
for item in items:
|
||||||
|
item["followups"] = followups_by_id.get(item["id"], [])
|
||||||
item["latest_follow_up_record"] = item["followups"][0]["content"] if item["followups"] else ""
|
item["latest_follow_up_record"] = item["followups"][0]["content"] if item["followups"] else ""
|
||||||
if resource == "proposals":
|
|
||||||
item["files"] = rows(conn, "SELECT * FROM file_assets WHERE module='proposal' AND owner_id=? ORDER BY id DESC", (item["id"],))
|
# 批量查 files(proposals + operations)
|
||||||
if resource == "operations":
|
file_modules = {"proposals": "proposal", "operations": "operation"}
|
||||||
item["files"] = rows(conn, "SELECT * FROM file_assets WHERE module='operation' AND owner_id=? ORDER BY id DESC", (item["id"],))
|
if resource in file_modules:
|
||||||
|
module = file_modules[resource]
|
||||||
|
placeholders = ",".join(["?"] * len(ids))
|
||||||
|
all_files = rows(
|
||||||
|
conn,
|
||||||
|
f"SELECT * FROM file_assets WHERE module=? AND owner_id IN ({placeholders}) ORDER BY id DESC",
|
||||||
|
[module] + ids,
|
||||||
|
)
|
||||||
|
files_by_id = {}
|
||||||
|
for f in all_files:
|
||||||
|
files_by_id.setdefault(f["owner_id"], []).append(f)
|
||||||
|
for item in items:
|
||||||
|
item["files"] = files_by_id.get(item["id"], [])
|
||||||
|
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
|
||||||
def monthly_finance(conn, tenant="科普·无界"):
|
def monthly_finance(conn, tenant="科普·无界"):
|
||||||
from datetime import date
|
months = [f"2026-{m:02d}" for m in range(1, 13)]
|
||||||
today = date.today()
|
pfs = rows(conn,
|
||||||
# 6 months: 3 before + current + 2 after
|
"SELECT sign_amount, sign_month, status, budget_data FROM project_finances WHERE tenant=?",
|
||||||
from dateutil.relativedelta import relativedelta
|
[tenant])
|
||||||
start = today + relativedelta(months=-3)
|
|
||||||
months = []
|
# 预解析 budget_data:{pf_index: {month_key: {rev, gross, payment, cost}}}
|
||||||
for i in range(6):
|
parsed_budgets = []
|
||||||
m = start + relativedelta(months=i)
|
for pf in pfs:
|
||||||
months.append(m.strftime("%Y-%m"))
|
try:
|
||||||
|
budget = json.loads(pf.get("budget_data") or "[]")
|
||||||
|
except (json.JSONDecodeError, TypeError):
|
||||||
|
budget = []
|
||||||
|
budget_map = {}
|
||||||
|
for b in budget:
|
||||||
|
key = (b.get("month") or "").replace("-", "_")
|
||||||
|
budget_map[key] = {
|
||||||
|
"rev": float(b.get("rev") or 0),
|
||||||
|
"gross": float(b.get("gross") or 0),
|
||||||
|
"payment": float(b.get("payment") or 0),
|
||||||
|
"cost": float(b.get("cost") or 0),
|
||||||
|
}
|
||||||
|
parsed_budgets.append((pf, budget_map))
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
for month in months:
|
for month in months:
|
||||||
col_month = month.replace("-", "_")
|
key = month.replace("-", "_")
|
||||||
col_rev = f"rev_{col_month}"
|
revenue = gross = payment = cost = sign = 0
|
||||||
col_gross = f"gross_{col_month}"
|
for pf, budget_map in parsed_budgets:
|
||||||
# Only project_finances has columns for 2026-06 through 2026-09
|
if pf["status"] == "已签约" and (pf.get("sign_month") or "") == month:
|
||||||
if month in ["2026-06", "2026-07", "2026-08", "2026-09"]:
|
sign += float(pf["sign_amount"] or 0)
|
||||||
revenue = one(conn, f"SELECT COALESCE(SUM({col_rev}),0) AS v FROM project_finances WHERE tenant=?", (tenant,))["v"]
|
b = budget_map.get(key)
|
||||||
gross = one(conn, f"SELECT COALESCE(SUM({col_gross}),0) AS v FROM project_finances WHERE tenant=?", (tenant,))["v"]
|
if b:
|
||||||
else:
|
revenue += b["rev"]
|
||||||
revenue = 0
|
gross += b["gross"]
|
||||||
gross = 0
|
payment += b["payment"]
|
||||||
|
cost += b["cost"]
|
||||||
data.append({
|
data.append({
|
||||||
"month": month, "revenue": revenue,
|
"month": month, "revenue": revenue,
|
||||||
"labor": 0, "expense": 0, "purchase": 0,
|
"labor": 0, "expense": 0, "purchase": 0,
|
||||||
"net_profit": gross,
|
"net_profit": gross,
|
||||||
|
"sign": sign, "payment": payment, "cost": cost,
|
||||||
})
|
})
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@@ -548,34 +750,49 @@ def bootstrap():
|
|||||||
return rows(conn, sql, args)
|
return rows(conn, sql, args)
|
||||||
sales = attach_common(conn, "sales", q("SELECT * FROM sales_leads WHERE tenant=? ORDER BY id DESC", tenant))
|
sales = attach_common(conn, "sales", q("SELECT * FROM sales_leads WHERE tenant=? ORDER BY id DESC", tenant))
|
||||||
proposals = attach_common(conn, "proposals", q("SELECT * FROM business_proposals WHERE tenant=? ORDER BY id DESC", tenant))
|
proposals = attach_common(conn, "proposals", q("SELECT * FROM business_proposals WHERE tenant=? ORDER BY id DESC", tenant))
|
||||||
operations = attach_common(conn, "operations", q("SELECT * FROM operation_projects WHERE tenant=? ORDER BY id DESC", tenant))
|
operations = attach_common(conn, "operations", q("SELECT * FROM operation_projects WHERE tenant=? ORDER BY id ASC", tenant))
|
||||||
products = attach_common(conn, "products", q("SELECT * FROM product_versions WHERE tenant=? ORDER BY id DESC", tenant))
|
products = attach_common(conn, "products", q("SELECT * FROM product_versions WHERE tenant=? ORDER BY id DESC", tenant))
|
||||||
finance = q("SELECT * FROM finance_records WHERE tenant=? ORDER BY month DESC, id DESC", tenant)
|
finance = q("SELECT * FROM finance_records WHERE tenant=? ORDER BY month DESC, id DESC", tenant)
|
||||||
tasks = q("SELECT * FROM project_tasks WHERE tenant=? ORDER BY phase, sort_order, id", tenant)
|
tasks = q("SELECT * FROM project_tasks WHERE tenant=? ORDER BY phase, sort_order, id", tenant)
|
||||||
pfs = q("SELECT * FROM project_finances WHERE tenant=? ORDER BY id DESC", tenant)
|
pfs = q("SELECT * FROM project_finances WHERE tenant=? ORDER BY id DESC", tenant)
|
||||||
current_month = "2026-06"
|
current_month = "2026-06"
|
||||||
# Finance aggregates — from project_finances (project-based)
|
signed_pfs = [x for x in pfs if x["status"] == "已签约"]
|
||||||
def pf_sum(field):
|
|
||||||
return sum(x[field] or 0 for x in pfs)
|
# 预解析 budget_data(避免重复 JSON 解析)
|
||||||
rev_month = pf_sum("rev_2026_06")
|
def parse_budget(pf):
|
||||||
gross_month = pf_sum("gross_2026_06")
|
|
||||||
rev_q2 = pf_sum("rev_2026_06")
|
|
||||||
gross_q2 = pf_sum("gross_2026_06")
|
|
||||||
rev_annual = rev_q2
|
|
||||||
gross_annual = gross_q2
|
|
||||||
# Contract aggregates — time-based
|
|
||||||
signed_amount = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_status"] == "已签约")
|
|
||||||
from datetime import date
|
|
||||||
today = date.today()
|
|
||||||
def contract_in_period(op, start, end):
|
|
||||||
if op["project_status"] != "已签约": return False
|
|
||||||
try:
|
try:
|
||||||
d = date.fromisoformat(op["created_at"][:10])
|
budget = json.loads(pf.get("budget_data") or "[]")
|
||||||
return start <= d <= end
|
except (json.JSONDecodeError, TypeError):
|
||||||
except: return False
|
budget = []
|
||||||
signed_annual = sum(x["expected_contract_amount"] or 0 for x in operations if contract_in_period(x, date(2026,1,1), date(2026,12,31)))
|
return {(b.get("month") or "").replace("-", "_"): b for b in budget}
|
||||||
signed_q2 = sum(x["expected_contract_amount"] or 0 for x in operations if contract_in_period(x, date(2026,4,1), date(2026,6,30)))
|
|
||||||
signed_month = sum(x["expected_contract_amount"] or 0 for x in operations if contract_in_period(x, date(2026,6,1), date(2026,6,30)))
|
budget_maps = [(pf, parse_budget(pf)) for pf in signed_pfs]
|
||||||
|
|
||||||
|
def sum_budget(field, months_range):
|
||||||
|
total = 0
|
||||||
|
for pf, bm in budget_maps:
|
||||||
|
for m in months_range:
|
||||||
|
b = bm.get(f"2026_{m:02d}")
|
||||||
|
if b:
|
||||||
|
total += float(b.get(field) or 0)
|
||||||
|
return total
|
||||||
|
|
||||||
|
rev_annual = sum_budget("rev", range(1, 13))
|
||||||
|
gross_annual = sum_budget("gross", range(1, 13))
|
||||||
|
rev_q2 = sum_budget("rev", range(4, 7))
|
||||||
|
gross_q2 = sum_budget("gross", range(4, 7))
|
||||||
|
rev_month = sum_budget("rev", [6])
|
||||||
|
gross_month = sum_budget("gross", [6])
|
||||||
|
# Contract aggregates — from project_finances (经营管理项目)
|
||||||
|
def pf_status_sum(status):
|
||||||
|
return sum(x["sign_amount"] or 0 for x in pfs if x["status"] == status)
|
||||||
|
signed_amount = pf_status_sum("已签约")
|
||||||
|
# 年度签约 = 所有已签约项目 2026 年的签约金额
|
||||||
|
signed_annual = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约")
|
||||||
|
# Q2 签约 = 签约月份在 2026-04~2026-06 的已签约项目
|
||||||
|
signed_q2 = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] in ["2026-04","2026-05","2026-06"])
|
||||||
|
# 本月签约 = 签约月份为 2026-06 的已签约项目
|
||||||
|
signed_month = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "") == "2026-06")
|
||||||
pipeline_amount = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_status"] not in ["已签约","已丢单","已归档","已完成"])
|
pipeline_amount = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_status"] not in ["已签约","已丢单","已归档","已完成"])
|
||||||
signed_not_executed = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_type"] == "execution" and x["execution_progress"] < 100)
|
signed_not_executed = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_type"] == "execution" and x["execution_progress"] < 100)
|
||||||
summary = {
|
summary = {
|
||||||
@@ -588,10 +805,10 @@ def bootstrap():
|
|||||||
"monthly_revenue": rev_month,
|
"monthly_revenue": rev_month,
|
||||||
"monthly_net_profit": gross_month,
|
"monthly_net_profit": gross_month,
|
||||||
"monthly_gross": gross_month,
|
"monthly_gross": gross_month,
|
||||||
"upcoming_products": len([x for x in products if x["status"] in ["规划中", "设计中", "开发中", "测试中"]]),
|
"upcoming_products": len(products),
|
||||||
"total_projects": len(operations),
|
"total_projects": len(signed_pfs),
|
||||||
"total_proposals": len(proposals),
|
"total_proposals": len(operations),
|
||||||
"total_products": len(products),
|
"total_products": len(proposals),
|
||||||
# Extended finance metrics
|
# Extended finance metrics
|
||||||
"signed_amount": signed_amount,
|
"signed_amount": signed_amount,
|
||||||
"signed_annual": signed_annual,
|
"signed_annual": signed_annual,
|
||||||
@@ -619,7 +836,7 @@ TABLES = {
|
|||||||
"products": ("product_versions", ["product_name", "version", "version_goal", "feature_list", "launch_date", "status", "platform", "notes", "tenant"]),
|
"products": ("product_versions", ["product_name", "version", "version_goal", "feature_list", "launch_date", "status", "platform", "notes", "tenant"]),
|
||||||
"finance": ("finance_records", ["month", "project_name", "record_type", "category", "amount", "occurred_date", "notes", "tenant"]),
|
"finance": ("finance_records", ["month", "project_name", "record_type", "category", "amount", "occurred_date", "notes", "tenant"]),
|
||||||
"tasks": ("project_tasks", ["project_id", "phase", "milestone", "task", "owner", "due_date", "blockers", "notes", "status", "sort_order", "priority", "tenant"]),
|
"tasks": ("project_tasks", ["project_id", "phase", "milestone", "task", "owner", "due_date", "blockers", "notes", "status", "sort_order", "priority", "tenant"]),
|
||||||
"projectFinances": ("project_finances", ["project_id", "tenant", "business_type", "customer_name", "sign_amount", "sign_month", "status", "sales_person", "total_rev", "total_gross", "budget_data"]),
|
"projectFinances": ("project_finances", ["project_id", "tenant", "business_type", "customer_name", "sign_amount", "sign_month", "status", "sales_person", "owner", "total_rev", "total_gross", "budget_data"]),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -630,9 +847,24 @@ def create_resource(resource):
|
|||||||
return jsonify({"error": "unknown resource"}), 404
|
return jsonify({"error": "unknown resource"}), 404
|
||||||
table, cols = TABLES[resource]
|
table, cols = TABLES[resource]
|
||||||
payload = request.get_json(force=True).get("data", {})
|
payload = request.get_json(force=True).get("data", {})
|
||||||
values = [payload.get(col, "") for col in cols]
|
# 任务状态校验:空值或非法值修正为"未开始"
|
||||||
|
if resource == "tasks":
|
||||||
|
valid_statuses = ["未开始", "进行中", "已结束"]
|
||||||
|
if not payload.get("status") or payload["status"] not in valid_statuses:
|
||||||
|
payload["status"] = "未开始"
|
||||||
conn = db()
|
conn = db()
|
||||||
try:
|
try:
|
||||||
|
# 获取列类型,数值列空字符串转 0 避免 MySQL 严格模式报错
|
||||||
|
type_cur = conn.cursor()
|
||||||
|
type_cur.execute(f"DESCRIBE {table}")
|
||||||
|
col_types = {r[0]: r[1].upper() for r in type_cur.fetchall()}
|
||||||
|
type_cur.close()
|
||||||
|
values = []
|
||||||
|
for col in cols:
|
||||||
|
val = payload.get(col, "")
|
||||||
|
if val == "" and ("DOUBLE" in col_types.get(col, "") or "INT" in col_types.get(col, "")):
|
||||||
|
val = 0
|
||||||
|
values.append(val)
|
||||||
cur = _exec(conn, f"INSERT INTO {table} ({','.join(cols)}) VALUES ({','.join(['?'] * len(cols))})", values)
|
cur = _exec(conn, f"INSERT INTO {table} ({','.join(cols)}) VALUES ({','.join(['?'] * len(cols))})", values)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
return jsonify({"id": cur.lastrowid})
|
return jsonify({"id": cur.lastrowid})
|
||||||
@@ -653,9 +885,14 @@ def update_resource(resource, item_id):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
return jsonify({"ok": True})
|
return jsonify({"ok": True})
|
||||||
payload = request.get_json(force=True).get("data", {})
|
payload = request.get_json(force=True).get("data", {})
|
||||||
|
# 任务状态校验:空值或非法值修正为"未开始"
|
||||||
|
if resource == "tasks" and "status" in payload:
|
||||||
|
valid_statuses = ["未开始", "进行中", "已结束"]
|
||||||
|
if not payload["status"] or payload["status"] not in valid_statuses:
|
||||||
|
payload["status"] = "未开始"
|
||||||
update_cols = [col for col in cols if col in payload]
|
update_cols = [col for col in cols if col in payload]
|
||||||
if update_cols:
|
if update_cols:
|
||||||
_exec(conn,
|
_exec(conn,
|
||||||
f"UPDATE {table} SET {','.join([col + '=?' for col in update_cols])}, updated_at=? WHERE id=?",
|
f"UPDATE {table} SET {','.join([col + '=?' for col in update_cols])}, updated_at=? WHERE id=?",
|
||||||
[payload[col] for col in update_cols] + [now(), item_id],
|
[payload[col] for col in update_cols] + [now(), item_id],
|
||||||
)
|
)
|
||||||
@@ -721,6 +958,20 @@ def batch_sort_tasks():
|
|||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/api/operations/batch-sort", methods=["POST"])
|
||||||
|
@login_required
|
||||||
|
def batch_sort_operations():
|
||||||
|
conn = db()
|
||||||
|
try:
|
||||||
|
items = request.get_json(force=True).get("items", [])
|
||||||
|
for item in items:
|
||||||
|
_exec(conn, "UPDATE operation_projects SET sort_order=? WHERE id=?", (item["sort_order"], item["id"]))
|
||||||
|
conn.commit()
|
||||||
|
return jsonify({"ok": True})
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/files/upload", methods=["POST"])
|
@app.route("/api/files/upload", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def upload_file():
|
def upload_file():
|
||||||
@@ -782,7 +1033,12 @@ def health():
|
|||||||
|
|
||||||
|
|
||||||
init_db()
|
init_db()
|
||||||
|
seed_db()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host="127.0.0.1", port=5177, debug=True)
|
app.run(
|
||||||
|
host="127.0.0.1",
|
||||||
|
port=5177,
|
||||||
|
debug=os.environ.get("FLASK_DEBUG", "false").lower() in ("true", "1", "yes"),
|
||||||
|
)
|
||||||
|
|||||||
1475
static/app.js
1475
static/app.js
File diff suppressed because it is too large
Load Diff
168
static/modules/admin.js
Normal file
168
static/modules/admin.js
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
// admin.js — 账号管理(仅 admin 可见)
|
||||||
|
|
||||||
|
window.openAdminUsers = async () => {
|
||||||
|
const overlay = document.createElement("div");
|
||||||
|
overlay.id = "adminOverlay";
|
||||||
|
overlay.className = "fixed inset-0 bg-black/40 z-[9998] flex items-center justify-center p-4";
|
||||||
|
overlay.innerHTML = `
|
||||||
|
<div class="bg-white rounded-xl shadow-2xl w-full max-w-3xl max-h-[85vh] flex flex-col">
|
||||||
|
<div class="flex items-center justify-between px-6 py-4 border-b border-slate-200">
|
||||||
|
<h2 class="text-lg font-semibold text-slate-800">账号管理</h2>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<button class="btn btn-primary btn-sm" onclick="openUserForm()"><i data-lucide="plus" style="width:14px;height:14px"></i>新增账号</button>
|
||||||
|
<button class="text-slate-400 hover:text-slate-700" onclick="closeAdminUsers()"><i data-lucide="x"></i></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="overflow-y-auto p-6" id="adminUserList"></div>
|
||||||
|
</div>`;
|
||||||
|
overlay.addEventListener("click", (e) => { if (e.target === overlay) closeAdminUsers(); });
|
||||||
|
document.body.appendChild(overlay);
|
||||||
|
if (window.lucide) lucide.createIcons();
|
||||||
|
await loadUserList();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.closeAdminUsers = () => {
|
||||||
|
const el = document.getElementById("adminOverlay");
|
||||||
|
if (el) el.remove();
|
||||||
|
};
|
||||||
|
|
||||||
|
async function loadUserList() {
|
||||||
|
const list = document.getElementById("adminUserList");
|
||||||
|
if (!list) return;
|
||||||
|
list.innerHTML = `<div class="text-center text-slate-400 py-8">加载中...</div>`;
|
||||||
|
try {
|
||||||
|
const users = await api("/api/users");
|
||||||
|
const tenants = await api("/api/tenants");
|
||||||
|
list.innerHTML = `
|
||||||
|
<table class="w-full text-sm">
|
||||||
|
<thead>
|
||||||
|
<tr class="border-b border-slate-200 text-slate-500 text-xs">
|
||||||
|
<th class="text-left py-2 px-2">用户名</th>
|
||||||
|
<th class="text-left py-2 px-2">显示名</th>
|
||||||
|
<th class="text-left py-2 px-2">角色</th>
|
||||||
|
<th class="text-left py-2 px-2">工作台</th>
|
||||||
|
<th class="text-right py-2 px-2">操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
${users.map(u => `
|
||||||
|
<tr class="border-b border-slate-100 hover:bg-slate-50">
|
||||||
|
<td class="py-3 px-2 font-medium text-slate-800">${esc(u.username)}</td>
|
||||||
|
<td class="py-3 px-2 text-slate-700">${esc(u.display_name)}</td>
|
||||||
|
<td class="py-3 px-2">
|
||||||
|
<span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ${u.role === 'admin' ? 'bg-blue-100 text-blue-700' : 'bg-slate-100 text-slate-600'}">${u.role === 'admin' ? '管理员' : 'OPC负责人'}</span>
|
||||||
|
</td>
|
||||||
|
<td class="py-3 px-2 text-slate-600 text-xs">${(u.tenants || []).map(t => `<span class="inline-block bg-slate-100 rounded px-1.5 py-0.5 mr-1 mb-1">${esc(t)}</span>`).join('') || '<span class="text-slate-400">—</span>'}</td>
|
||||||
|
<td class="py-3 px-2 text-right">
|
||||||
|
<button class="btn btn-ghost btn-sm" onclick="openUserForm(${u.id})"><i data-lucide="edit-2" style="width:14px;height:14px"></i>编辑</button>
|
||||||
|
<button class="btn btn-ghost btn-sm text-red-600 hover:bg-red-50" onclick="deleteUser(${u.id}, '${esc(u.username)}')"><i data-lucide="trash-2" style="width:14px;height:14px"></i>删除</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
`).join('')}
|
||||||
|
</tbody>
|
||||||
|
</table>`;
|
||||||
|
if (window.lucide) lucide.createIcons();
|
||||||
|
} catch (e) {
|
||||||
|
list.innerHTML = `<div class="text-center text-red-600 py-8">加载失败:${esc(e.message)}</div>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.openUserForm = async (uid) => {
|
||||||
|
let user = null;
|
||||||
|
let userTenants = [];
|
||||||
|
if (uid) {
|
||||||
|
try {
|
||||||
|
const users = await api("/api/users");
|
||||||
|
user = users.find(u => u.id === uid);
|
||||||
|
userTenants = user?.tenants || [];
|
||||||
|
} catch (e) { toast("加载用户失败", "error"); return; }
|
||||||
|
}
|
||||||
|
const tenants = await api("/api/tenants");
|
||||||
|
|
||||||
|
const modal = document.createElement("div");
|
||||||
|
modal.id = "userFormModal";
|
||||||
|
modal.className = "fixed inset-0 bg-black/40 z-[9999] flex items-center justify-center p-4";
|
||||||
|
modal.innerHTML = `
|
||||||
|
<div class="bg-white rounded-xl shadow-2xl w-full max-w-md">
|
||||||
|
<div class="flex items-center justify-between px-6 py-4 border-b border-slate-200">
|
||||||
|
<h3 class="text-base font-semibold text-slate-800">${user ? '编辑账号' : '新增账号'}</h3>
|
||||||
|
<button class="text-slate-400 hover:text-slate-700" onclick="document.getElementById('userFormModal').remove()"><i data-lucide="x"></i></button>
|
||||||
|
</div>
|
||||||
|
<form class="p-6 space-y-4" onsubmit="submitUserForm(event, ${uid || 0})">
|
||||||
|
<div>
|
||||||
|
<label class="block text-xs font-medium text-slate-600 mb-1">用户名 ${user ? '<span class="text-slate-400">(不可修改)</span>' : '<span class="text-red-500">*</span>'}</label>
|
||||||
|
<input name="username" class="form-ctrl w-full" value="${user ? esc(user.username) : ''}" ${user ? 'disabled' : 'required'} placeholder="登录用户名">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="block text-xs font-medium text-slate-600 mb-1">显示名 <span class="text-red-500">*</span></label>
|
||||||
|
<input name="display_name" class="form-ctrl w-full" value="${user ? esc(user.display_name) : ''}" required placeholder="如:科普负责人">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="block text-xs font-medium text-slate-600 mb-1">密码 ${user ? '<span class="text-slate-400">(留空不修改)</span>' : '<span class="text-red-500">*</span>'}</label>
|
||||||
|
<input name="password" type="password" class="form-ctrl w-full" ${user ? '' : 'required'} placeholder="${user ? '留空保持原密码' : '登录密码'}">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="block text-xs font-medium text-slate-600 mb-1">角色</label>
|
||||||
|
<select name="role" class="form-ctrl w-full">
|
||||||
|
<option value="opc_owner" ${user?.role === 'opc_owner' ? 'selected' : ''}>OPC负责人(仅看分配工作台)</option>
|
||||||
|
<option value="admin" ${user?.role === 'admin' ? 'selected' : ''}>管理员(看所有工作台)</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="block text-xs font-medium text-slate-600 mb-1">工作台权限 <span class="text-slate-400">(OPC负责人生效)</span></label>
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
${tenants.map(t => `
|
||||||
|
<label class="flex items-center gap-2 cursor-pointer">
|
||||||
|
<input type="checkbox" name="tenants" value="${esc(t)}" ${userTenants.includes(t) ? 'checked' : ''} class="rounded">
|
||||||
|
<span class="text-sm text-slate-700">${esc(t)}</span>
|
||||||
|
</label>
|
||||||
|
`).join('')}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-end gap-2 pt-2">
|
||||||
|
<button type="button" class="btn btn-ghost btn-sm" onclick="document.getElementById('userFormModal').remove()">取消</button>
|
||||||
|
<button type="submit" class="btn btn-primary btn-sm">保存</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>`;
|
||||||
|
modal.addEventListener("click", (e) => { if (e.target === modal) modal.remove(); });
|
||||||
|
document.body.appendChild(modal);
|
||||||
|
if (window.lucide) lucide.createIcons();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.submitUserForm = async (event, uid) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = event.target;
|
||||||
|
const fd = new FormData(form);
|
||||||
|
const payload = {
|
||||||
|
username: fd.get("username"),
|
||||||
|
display_name: fd.get("display_name"),
|
||||||
|
password: fd.get("password"),
|
||||||
|
role: fd.get("role"),
|
||||||
|
tenants: fd.getAll("tenants"),
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
if (uid) {
|
||||||
|
await api(`/api/users/${uid}`, { method: "PUT", body: JSON.stringify(payload) });
|
||||||
|
toast("已更新", "success");
|
||||||
|
} else {
|
||||||
|
await api("/api/users", { method: "POST", body: JSON.stringify(payload) });
|
||||||
|
toast("已新增", "success");
|
||||||
|
}
|
||||||
|
document.getElementById("userFormModal").remove();
|
||||||
|
await loadUserList();
|
||||||
|
} catch (e) {
|
||||||
|
toast("保存失败:" + e.message, "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.deleteUser = async (uid, username) => {
|
||||||
|
if (!confirm(`确认删除账号「${username}」?此操作不可撤销。`)) return;
|
||||||
|
try {
|
||||||
|
await api(`/api/users/${uid}`, { method: "DELETE" });
|
||||||
|
toast("已删除", "success");
|
||||||
|
await loadUserList();
|
||||||
|
} catch (e) {
|
||||||
|
toast("删除失败:" + e.message, "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
268
static/modules/drawer.js
Normal file
268
static/modules/drawer.js
Normal file
@@ -0,0 +1,268 @@
|
|||||||
|
// drawer.js — 详情抽屉 + 评论 + 转移 + 删除
|
||||||
|
|
||||||
|
function drawerField(icon, label, name, value, multiline = false, customControl = null) {
|
||||||
|
const safeValue = esc(value || "");
|
||||||
|
const control = customControl
|
||||||
|
? customControl
|
||||||
|
: multiline
|
||||||
|
? `<textarea name="${name}" rows="2" class="form-ctrl" data-original="${safeValue}">${safeValue}</textarea>`
|
||||||
|
: `<input name="${name}" value="${safeValue}" class="form-ctrl" data-original="${safeValue}">`;
|
||||||
|
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","项目名称"],["owner","负责人"],["expected_sign_date","截止时间"],["expected_contract_amount","金额"],["notes","项目说明"]]
|
||||||
|
: resource === "proposals"
|
||||||
|
? [["customer_or_project_name","客户/项目"],["proposal_type","方案类型"],["notes","备注"]]
|
||||||
|
: [["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",
|
||||||
|
owner: "user", 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", platform: "layers",
|
||||||
|
launch_date: "calendar", notes: "sticky-note", proposal_type: "tag", customer_or_project_name: "building"
|
||||||
|
};
|
||||||
|
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 = esc(item.target_customer || item.project_name || (item.customer_or_project_name ? `${item.customer_or_project_name} · ${item.proposal_type || ''}` : "") || item.product_name);
|
||||||
|
const titleForAttr = esc(item.target_customer || item.project_name || (item.customer_or_project_name ? `${item.customer_or_project_name} · ${item.proposal_type || ''}` : "") || 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><div class="flex items-center gap-2"><button class="btn btn-ghost btn-sm text-blue-600 hover:bg-blue-50" onclick="openTransferModal('${resource}', ${id}, '${titleForAttr}')" ${resource === 'operations' ? '' : 'style="display:none"'}><i data-lucide="move-right"></i>转移</button><button class="btn btn-ghost btn-sm text-red-600 hover:bg-red-50" onclick="deleteDrawerItem('${resource}', ${id})"><i data-lucide="trash-2"></i>删除</button><button class="btn btn-ghost btn-sm" onclick="closeDrawer()">关闭</button></div></div><div class="grid gap-5 p-5">
|
||||||
|
<section>
|
||||||
|
<h3 class="drawer-section-title">属性</h3>
|
||||||
|
<form id="drawerForm" class="drawer-fields">
|
||||||
|
${resource === "operations" ? drawerField("map-pin", "当前阶段", "current_stage", "", false, `<select name="current_stage" class="form-ctrl" onchange="saveDrawerField(this,'${resource}',${id})">${["商务洽谈","系统上线","团队分工","项目交付","上线推广","结项验收"].map((s) => `<option ${s === item.current_stage ? "selected" : ""}>${s}</option>`).join("")}</select>`) : ""}
|
||||||
|
${fields.map(([key,label]) => {
|
||||||
|
if (resource === "products" && key === "feature_list") {
|
||||||
|
const features = (item[key] || "").split("\n").filter(Boolean);
|
||||||
|
if (features.length === 0) features.push("");
|
||||||
|
return `<div class="drawer-field"><div class="drawer-field-label"><i data-lucide="list"></i><span>${label}</span></div><div class="drawer-field-control" data-field="feature_list" data-id="${id}"><div class="feature-list" id="featureList_${id}">${features.map((f,i) => `<div class="feature-item"><span class="feature-num">${i+1}.</span><input class="form-ctrl" value="${f.replace(/"/g,'"')}" onchange="saveFeatureList(${id})"><button class="feature-del" onclick="event.preventDefault();removeFeature(${id},${i})"><i data-lucide="x" style="width:12px;height:12px"></i></button></div>`).join("")}</div><button class="btn btn-ghost btn-sm text-blue-600 mt-1" onclick="event.preventDefault();addFeature(${id})"><i data-lucide="plus" style="width:14px;height:14px"></i>添加功能</button></div></div>`;
|
||||||
|
}
|
||||||
|
if (resource === "products" && key === "launch_date") {
|
||||||
|
return drawerField("calendar", label, key, item[key], false, `<input type="date" name="${key}" value="${item[key]||''}" class="form-ctrl" data-original="${item[key]||''}" onchange="saveDrawerField(this,'${resource}',${id})">`);
|
||||||
|
}
|
||||||
|
if (resource === "products" && key === "status") {
|
||||||
|
return drawerField("circle-dot", label, key, "", false, `<select name="status" class="form-ctrl" onchange="saveDrawerField(this,'${resource}',${id})">${["规划中","开发中","测试中","已上线","已取消"].map((s) => `<option ${s === (item.status||'规划中') ? "selected" : ""}>${s}</option>`).join("")}</select>`);
|
||||||
|
}
|
||||||
|
return drawerField(fieldIcons[key] || "circle", label, key, item[key], multilineFields.includes(key));
|
||||||
|
}).join("")}
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
${resource === "proposals" ? `<section><h3 class="drawer-section-title">附件</h3>${fileGroup("proposal", item.id, "", "附件", item.files || [])}</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>${esc(f.follower)} · ${esc(f.follow_up_method)}</span><span>${esc(f.followed_at)}</span></div><div class="mt-1 leading-5 text-slate-800 rich-content" data-html="${encodeURIComponent(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}')">
|
||||||
|
<div class="squire-toolbar">
|
||||||
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('bold')" title="加粗"><i data-lucide="bold"></i></button>
|
||||||
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('italic')" title="斜体"><i data-lucide="italic"></i></button>
|
||||||
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('underline')" title="下划线"><i data-lucide="underline"></i></button>
|
||||||
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('strikethrough')" title="删除线"><i data-lucide="strikethrough"></i></button>
|
||||||
|
<span class="squire-sep"></span>
|
||||||
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('makeUnorderedList')" title="无序列表"><i data-lucide="list"></i></button>
|
||||||
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('makeOrderedList')" title="有序列表"><i data-lucide="list-ordered"></i></button>
|
||||||
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('blockquote')" title="引用"><i data-lucide="quote"></i></button>
|
||||||
|
<span class="squire-sep"></span>
|
||||||
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('undo')" title="撤销"><i data-lucide="undo"></i></button>
|
||||||
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('redo')" title="重做"><i data-lucide="redo"></i></button>
|
||||||
|
</div>
|
||||||
|
<div class="squire-editor" id="squire_${resource}_${item.id}" placeholder="添加评论"></div>
|
||||||
|
<div class="comment-toolbar">
|
||||||
|
<span class="comment-hint">支持富文本编辑</span>
|
||||||
|
<button class="btn btn-primary btn-sm comment-submit" type="submit">评论</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</section>` : ""}
|
||||||
|
<div id="uploadTaskList"></div>
|
||||||
|
</div></div>`;
|
||||||
|
drawer.classList.add("open");
|
||||||
|
bindDrawerAutosave(resource, item.id, item);
|
||||||
|
if (window.lucide) window.lucide.createIcons();
|
||||||
|
renderUploadTasks();
|
||||||
|
drawer.querySelectorAll(".rich-content").forEach((el) => {
|
||||||
|
const html = el.dataset.html;
|
||||||
|
if (html) el.innerHTML = decodeURIComponent(html);
|
||||||
|
});
|
||||||
|
const squireDiv = drawer.querySelector(".squire-editor");
|
||||||
|
if (squireDiv && window.Squire) {
|
||||||
|
const id = squireDiv.id;
|
||||||
|
if (window.squireInstances[id]) window.squireInstances[id].destroy();
|
||||||
|
const sq = new Squire(squireDiv, { blockTag: "P" });
|
||||||
|
sq.addEventListener("input", () => {
|
||||||
|
const form = squireDiv.closest("form");
|
||||||
|
const btn = form.querySelector(".comment-submit");
|
||||||
|
});
|
||||||
|
window.squireInstances[id] = sq;
|
||||||
|
squireDiv.addEventListener("focus", () => squireDiv.classList.add("focused"));
|
||||||
|
squireDiv.addEventListener("blur", () => {
|
||||||
|
if (!squireDiv.textContent.trim()) squireDiv.classList.remove("focused");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 .form-ctrl").forEach((field) => {
|
||||||
|
field.addEventListener("keydown", (event) => {
|
||||||
|
if (event.key === "Enter" && field.tagName !== "TEXTAREA") field.blur();
|
||||||
|
});
|
||||||
|
const doSave = 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;
|
||||||
|
renderActive();
|
||||||
|
setDrawerSaveStatus("已保存", "success");
|
||||||
|
setTimeout(() => setDrawerSaveStatus(""), 1200);
|
||||||
|
} catch (error) {
|
||||||
|
field.dataset.original = previous;
|
||||||
|
setDrawerSaveStatus("保存失败", "danger");
|
||||||
|
toast(`自动保存失败:${error.message}`, "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
field.addEventListener("blur", doSave);
|
||||||
|
if (field.tagName === "SELECT") field.addEventListener("change", doSave);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
window.openDrawer = openDrawer;
|
||||||
|
window.closeDrawer = () => document.querySelector("#drawer").classList.remove("open");
|
||||||
|
|
||||||
|
window.deleteDrawerItem = async (resource, id) => {
|
||||||
|
if (!confirm("确认删除?此操作不可撤销。")) return;
|
||||||
|
try {
|
||||||
|
const listKey = { sales: "sales", proposals: "proposals", operations: "operations", products: "products" }[resource];
|
||||||
|
let name = "";
|
||||||
|
if (listKey && state.data[listKey]) {
|
||||||
|
const item = state.data[listKey].find(x => x.id === id);
|
||||||
|
name = item ? (item.target_customer || item.project_name || item.customer_or_project_name || item.product_name || "") : "";
|
||||||
|
}
|
||||||
|
await api(`/api/${resource}/${id}`, { method: "DELETE" });
|
||||||
|
if (name) {
|
||||||
|
const resType = { sales: "sales", proposals: "proposal", operations: "operation", products: "product" }[resource] || resource;
|
||||||
|
logActivity(resType, id, "删除了「" + name + "」");
|
||||||
|
}
|
||||||
|
closeDrawer();
|
||||||
|
await load();
|
||||||
|
} catch (error) {
|
||||||
|
toast("删除失败:" + error.message, "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.openTransferModal = (resource, id, title) => {
|
||||||
|
document.querySelector("#transfer-resource").value = resource;
|
||||||
|
document.querySelector("#transfer-id").value = id;
|
||||||
|
document.querySelector("#transfer-title-text").textContent = "将「" + title + "」转移到:";
|
||||||
|
document.querySelector("#transferModal").classList.remove("hidden");
|
||||||
|
};
|
||||||
|
|
||||||
|
window.closeTransferModal = () => {
|
||||||
|
document.querySelector("#transferModal").classList.add("hidden");
|
||||||
|
};
|
||||||
|
|
||||||
|
window.submitTransfer = async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = event.currentTarget;
|
||||||
|
const resource = form.querySelector('[name="transfer_resource"]').value;
|
||||||
|
const id = form.querySelector('[name="transfer_id"]').value;
|
||||||
|
const newTenant = form.querySelector('[name="transfer_tenant"]').value;
|
||||||
|
try {
|
||||||
|
await api(`/api/${resource}/${id}`, { method: "PUT", body: JSON.stringify({ data: { tenant: newTenant } }) });
|
||||||
|
closeTransferModal();
|
||||||
|
closeDrawer();
|
||||||
|
await load();
|
||||||
|
} catch (error) {
|
||||||
|
toast("转移失败:" + error.message, "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Squire 富文本编辑器
|
||||||
|
window.squireInstances = {};
|
||||||
|
window.squireCmd = (cmd) => {
|
||||||
|
const currentEditor = document.querySelector(".squire-editor");
|
||||||
|
if (!currentEditor) return;
|
||||||
|
const id = currentEditor.id;
|
||||||
|
const sq = window.squireInstances[id];
|
||||||
|
if (!sq) return;
|
||||||
|
sq.focus();
|
||||||
|
setTimeout(() => {
|
||||||
|
if (cmd === "bold") {
|
||||||
|
sq.hasFormat("b") || sq.hasFormat("strong") ? sq.removeBold() : sq.bold();
|
||||||
|
} else if (cmd === "italic") {
|
||||||
|
sq.hasFormat("i") || sq.hasFormat("em") ? sq.removeItalic() : sq.italic();
|
||||||
|
} else if (cmd === "underline") {
|
||||||
|
sq.hasFormat("u") ? sq.changeFormat(null, { tag: "u" }, null) : sq.changeFormat({ tag: "u" }, null, null);
|
||||||
|
} else if (cmd === "strikethrough") {
|
||||||
|
sq.hasFormat("s") || sq.hasFormat("del") || sq.hasFormat("strike") ? sq.changeFormat(null, { tag: "s" }, null) : sq.changeFormat({ tag: "s" }, null, null);
|
||||||
|
} else {
|
||||||
|
sq[cmd]();
|
||||||
|
}
|
||||||
|
}, 10);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.submitComment = async (event, targetType, targetId, resource) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = event.currentTarget;
|
||||||
|
const editorDiv = form.querySelector(".squire-editor");
|
||||||
|
const sq = window.squireInstances[editorDiv.id];
|
||||||
|
const content = sq ? sq.getHTML().trim() : "";
|
||||||
|
if (!content || content === "<div><br></div>" || content === "<p><br></p>") 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.deleteActivity = async (id) => {
|
||||||
|
if (!confirm("确认删除这条动态?")) return;
|
||||||
|
await api(`/api/followups/${id}`, { method: "DELETE" });
|
||||||
|
await load();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.deleteFollowup = async (event, followupId, resource, targetId) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
if (!confirm("确认删除这条评论?")) return;
|
||||||
|
await api(`/api/followups/${followupId}`, { method: "DELETE" });
|
||||||
|
await load();
|
||||||
|
openDrawer(resource, targetId);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.saveDrawerField = async (el, resource, id) => {
|
||||||
|
const name = el.name;
|
||||||
|
const value = el.value;
|
||||||
|
try {
|
||||||
|
await api(`/api/${resource}/${id}`, { method: "PUT", body: JSON.stringify({ data: { [name]: value } }) });
|
||||||
|
const listKey = { sales: "sales", proposals: "proposals", operations: "operations", products: "products" }[resource];
|
||||||
|
if (listKey && state.data[listKey]) {
|
||||||
|
const item = state.data[listKey].find(x => x.id === id);
|
||||||
|
if (item) item[name] = value;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
toast("保存失败:" + error.message, "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
366
static/modules/finance.js
Normal file
366
static/modules/finance.js
Normal file
@@ -0,0 +1,366 @@
|
|||||||
|
// finance.js — 经营管理(财务)模块
|
||||||
|
|
||||||
|
function renderFinance() {
|
||||||
|
const pfs = state.data.projectFinances || [];
|
||||||
|
const ops = state.data.operations || [];
|
||||||
|
const fmTypesByTenant = {
|
||||||
|
"科普·无界": ["科普音频","科普视频","科普文章","全品类科普","调研问卷"],
|
||||||
|
"科研·无界": ["真实世界研究","调研问卷","病例征集","患者招募"],
|
||||||
|
"医患·无界": ["医患运营","患者管理","患教会","创新支付","电商","其他"],
|
||||||
|
};
|
||||||
|
const fmTypes = fmTypesByTenant[state.tenant] || fmTypesByTenant["科普·无界"];
|
||||||
|
const tenantOps = (state.data.operations || []).filter(o => (o.project_name || "").includes(state.tenant.replace("·无界","")) || o.tenant === state.tenant);
|
||||||
|
const now = new Date();
|
||||||
|
const thisMonth = now.getMonth() + 1;
|
||||||
|
const displayMonths = [];
|
||||||
|
for (let i = 0; i < 4; i++) {
|
||||||
|
const m = thisMonth + i;
|
||||||
|
const mm = m > 12 ? m - 12 : m;
|
||||||
|
displayMonths.push({ key: "2026_" + String(mm).padStart(2, "0"), label: mm + "月" });
|
||||||
|
}
|
||||||
|
const months = displayMonths.map(d => d.key);
|
||||||
|
const monthLabels = displayMonths.map(d => d.label);
|
||||||
|
|
||||||
|
const signed = pfs.filter(x => x.status === "已签约");
|
||||||
|
const inContract = pfs.filter(x => x.status === "流程中");
|
||||||
|
const pending = pfs.filter(x => x.status === "待签约");
|
||||||
|
const sumSign = Math.round(signed.reduce((s,x) => s + (x.sign_amount||0), 0));
|
||||||
|
const sumPending = Math.round(pending.reduce((s,x) => s + (x.sign_amount||0), 0));
|
||||||
|
const sumContract = Math.round(inContract.reduce((s,x) => s + (x.sign_amount||0), 0));
|
||||||
|
|
||||||
|
const monthRev = months.map(m => {
|
||||||
|
return signed.reduce((s, pf) => {
|
||||||
|
let budget = [];
|
||||||
|
try { budget = JSON.parse(pf.budget_data || "[]"); } catch (e) {}
|
||||||
|
const row = budget.find(b => (b.month || "").replace("-", "_") === m);
|
||||||
|
return s + (row ? (parseFloat(row.rev) || 0) : 0);
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
const monthGross = months.map(m => {
|
||||||
|
return signed.reduce((s, pf) => {
|
||||||
|
let budget = [];
|
||||||
|
try { budget = JSON.parse(pf.budget_data || "[]"); } catch (e) {}
|
||||||
|
const row = budget.find(b => (b.month || "").replace("-", "_") === m);
|
||||||
|
return s + (row ? (parseFloat(row.gross) || 0) : 0);
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
const thisMonthKey = displayMonths[0].key;
|
||||||
|
const thisMonthRev = monthRev[0];
|
||||||
|
const thisMonthGross = monthGross[0];
|
||||||
|
let monthPayment = 0, monthCost = 0;
|
||||||
|
for (const pf of pfs) {
|
||||||
|
let budget = [];
|
||||||
|
try { budget = JSON.parse(pf.budget_data || "[]"); } catch (e) {}
|
||||||
|
for (const b of budget) {
|
||||||
|
const bKey = (b.month || "").replace("-", "_");
|
||||||
|
if (bKey === thisMonthKey) {
|
||||||
|
monthPayment += parseFloat(b.payment || 0);
|
||||||
|
monthCost += parseFloat(b.cost || 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
monthPayment = Math.round(monthPayment);
|
||||||
|
monthCost = Math.round(monthCost);
|
||||||
|
const monthCashflow = monthPayment - monthCost;
|
||||||
|
|
||||||
|
const renderPfRow = (pf) => {
|
||||||
|
let budgetMap = {};
|
||||||
|
try {
|
||||||
|
const budget = JSON.parse(pf.budget_data || "[]");
|
||||||
|
budget.forEach(b => { budgetMap[(b.month || "").replace("-", "_")] = b; });
|
||||||
|
} catch (e) {}
|
||||||
|
const isRevView = state.finView !== "cashflow";
|
||||||
|
const mCols = months.map(m => {
|
||||||
|
const b = budgetMap[m] || {};
|
||||||
|
if (isRevView) {
|
||||||
|
const rev = b.rev || 0;
|
||||||
|
const gross = b.gross || 0;
|
||||||
|
return `<td class="p-2 text-right whitespace-nowrap"><span class="${rev ? 'text-blue-700 font-medium' : 'text-slate-300'}">${rev ? money(rev) : '—'}</span><br><span class="text-xs ${gross ? 'text-green-600' : 'text-slate-300'}">${gross ? money(gross) : '—'}</span></td>`;
|
||||||
|
} else {
|
||||||
|
const payment = b.payment || 0;
|
||||||
|
const cost = b.cost || 0;
|
||||||
|
return `<td class="p-2 text-right whitespace-nowrap"><span class="${payment ? 'text-amber-700 font-medium' : 'text-slate-300'}">${payment ? money(payment) : '—'}</span><br><span class="text-xs ${cost ? 'text-rose-600' : 'text-slate-300'}">${cost ? money(cost) : '—'}</span></td>`;
|
||||||
|
}
|
||||||
|
}).join("");
|
||||||
|
const totalCol = (() => {
|
||||||
|
if (isRevView) {
|
||||||
|
const totalRev = pf.total_rev || 0;
|
||||||
|
const totalGross = pf.total_gross || 0;
|
||||||
|
return `<td class="p-2 text-right whitespace-nowrap font-semibold"><span class="${totalRev ? 'text-blue-700' : 'text-slate-300'}">${totalRev ? money(totalRev) : '—'}</span><br><span class="text-xs ${totalGross ? 'text-green-600' : 'text-slate-300'}">${totalGross ? money(totalGross) : '—'}</span></td>`;
|
||||||
|
} else {
|
||||||
|
let totalPayment = 0, totalCost = 0;
|
||||||
|
try { JSON.parse(pf.budget_data || "[]").forEach(b => { totalPayment += parseFloat(b.payment||0)||0; totalCost += parseFloat(b.cost||0)||0; }); } catch (e) {}
|
||||||
|
return `<td class="p-2 text-right whitespace-nowrap font-semibold"><span class="${totalPayment ? 'text-amber-700' : 'text-slate-300'}">${totalPayment ? money(totalPayment) : '—'}</span><br><span class="text-xs ${totalCost ? 'text-rose-600' : 'text-slate-300'}">${totalCost ? money(totalCost) : '—'}</span></td>`;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
const sm = pf.sign_month || "";
|
||||||
|
const signMonthCell = `<td class="p-2 text-center text-sm"><span class="pf-sm-text cursor-pointer hover:text-blue-600" id="pf-sm-${pf.id}" onclick="event.stopPropagation(); editPfSignMonth(event, ${pf.id})">${sm || '—'}</span></td>`;
|
||||||
|
return `<tr class="border-b border-slate-100 hover:bg-slate-50 cursor-pointer" onclick="openPfEditModal(${pf.id})"><td class="p-2 text-sm font-medium text-center">${esc(pf.customer_name)}</td><td class="p-2 text-sm text-center">${esc(pf.business_type)}</td><td class="p-2 text-sm text-center">${pf.status === "已签约" ? badge("已签约") : pf.status === "流程中" ? badge("流程中","blue") : badge("待签约","amber")}</td>${signMonthCell}<td class="p-2 text-center text-sm">${money(pf.sign_amount)}</td>${mCols}${totalCol}<td class="p-2 text-sm text-slate-500 text-center">${esc(pf.sales_person) || "—"}</td><td class="p-2 text-sm text-slate-500 text-center">${esc(pf.owner) || "—"}</td></tr>`;
|
||||||
|
};
|
||||||
|
|
||||||
|
document.querySelector("#finance").innerHTML = `<div class="grid gap-4">
|
||||||
|
<div class="grid grid-cols-6 gap-3">
|
||||||
|
${[["已签项目","" + signed.length],["签约金额",money(sumSign)],["流程项目","" + inContract.length],["流程金额",money(sumContract)],["待签项目","" + pending.length],["待签金额",money(sumPending)]].map(([l,v]) => `<div class="bg-white rounded-lg border border-slate-200 p-3 text-center"><p class="text-xs text-slate-500">${l}</p><p class="text-xl font-bold text-slate-800">${v}</p></div>`).join("")}
|
||||||
|
</div>
|
||||||
|
<div class="grid grid-cols-5 gap-3">
|
||||||
|
${[["本月确收",money(thisMonthRev)],["本月毛利",money(thisMonthGross)],["本月回款",money(monthPayment)],["本月费用",money(monthCost)],["本月现金流",money(monthCashflow)]].map(([l,v]) => `<div class="bg-white rounded-lg border border-slate-200 p-3 text-center"><p class="text-xs text-slate-500">${l}</p><p class="text-xl font-bold text-slate-800">${v}</p></div>`).join("")}
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-end"><button class="btn btn-primary btn-sm" onclick="openFinanceModal()"><i data-lucide="plus"></i>新增财务项目</button></div>
|
||||||
|
<div id="financeModal" class="hidden fixed inset-0 z-50 flex items-center justify-center bg-black/40" onclick="closeFinanceModal()"><div class="bg-white rounded-2xl shadow-2xl w-full max-w-5xl mx-4 max-h-[92vh] overflow-y-auto" onclick="event.stopPropagation()"><div class="sticky top-0 z-10 bg-white/95 backdrop-blur border-b border-slate-100 px-8 py-5 flex items-center justify-between"><div><h3 class="text-xl font-bold text-slate-800" id="financeModalTitle">新增项目财务</h3><p class="text-xs text-slate-400 mt-0.5">填写项目财务信息与月度预算</p></div><div class="flex items-center gap-2"><button class="btn btn-ghost btn-sm text-red-600 hidden" id="financeDeleteBtn" onclick="deleteFinanceItem()"><i data-lucide="trash-2"></i>删除</button><button class="btn btn-ghost btn-sm rounded-full w-8 h-8 p-0" onclick="closeFinanceModal()"><i data-lucide="x"></i></button></div></div>
|
||||||
|
<div class="finance-tabs">
|
||||||
|
<button class="finance-tab active" data-tab="info" onclick="switchFinanceTab('info')"><i data-lucide="info" style="width:14px;height:14px;display:inline-block;vertical-align:-2px;margin-right:4px"></i>基本信息</button>
|
||||||
|
<button class="finance-tab" data-tab="budget" onclick="switchFinanceTab('budget')"><i data-lucide="calendar" style="width:14px;height:14px;display:inline-block;vertical-align:-2px;margin-right:4px"></i>月度预算</button>
|
||||||
|
</div>
|
||||||
|
<form onsubmit="createFinance(event)" class="p-8 grid gap-6"><input type="hidden" name="pf_id" id="pf-id-input" value="">
|
||||||
|
<div id="financeTabInfo">
|
||||||
|
<div class="grid grid-cols-2 gap-5">
|
||||||
|
<div class="fin-field-group">
|
||||||
|
<p class="fin-section-label">项目信息</p>
|
||||||
|
<div class="grid gap-4">
|
||||||
|
<label class="block"><span class="fin-label">部门</span><input type="hidden" name="project_id" value="${state.tenant}"><input class="form-ctrl bg-slate-50 cursor-not-allowed" value="${state.tenant}" disabled></label>
|
||||||
|
<label class="block"><span class="fin-label">业务类型</span><select name="business_type" class="form-ctrl bg-white">${fmTypes.map(t => `<option>${t}</option>`).join("")}</select></label>
|
||||||
|
<label class="block"><span class="fin-label">项目名称 <span class="text-red-500">*</span></span><input name="customer_name" required class="form-ctrl" placeholder="请输入项目名称"></label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="fin-field-group">
|
||||||
|
<p class="fin-section-label">合同信息</p>
|
||||||
|
<div class="grid gap-4">
|
||||||
|
<label class="block"><span class="fin-label">签约金额(元) <span class="text-red-500">*</span></span><input name="sign_amount" type="number" step="0.01" min="0.01" required class="form-ctrl" placeholder="必须大于 0"></label>
|
||||||
|
<div class="grid grid-cols-2 gap-3">
|
||||||
|
<label class="block"><span class="fin-label">签约月份 <span class="text-red-500">*</span></span><select name="sign_month" required class="form-ctrl bg-white"><option value="">选择</option>${monthOptions('')}</select></label>
|
||||||
|
<label class="block"><span class="fin-label">项目状态</span><select name="status" class="form-ctrl bg-white"><option>已签约</option><option>流程中</option><option>待签约</option></select></label>
|
||||||
|
</div>
|
||||||
|
<div class="grid grid-cols-2 gap-3">
|
||||||
|
<label class="block"><span class="fin-label">商务负责人 <span class="text-red-500">*</span></span><input name="sales_person" required class="form-ctrl" placeholder="请输入商务负责人"></label>
|
||||||
|
<label class="block"><span class="fin-label">经营负责人 <span class="text-red-500">*</span></span><input name="owner" required class="form-ctrl" placeholder="请输入经营负责人"></label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="financeTabBudget" class="hidden">
|
||||||
|
<div class="grid grid-cols-4 gap-3 mb-4" id="budgetSummary">
|
||||||
|
<div class="bg-blue-50 rounded-lg p-3 text-center border border-blue-100">
|
||||||
|
<p class="text-xs text-blue-600 font-medium">总确收</p>
|
||||||
|
<p class="text-lg font-bold text-blue-700" id="budgetTotalRev">¥0</p>
|
||||||
|
</div>
|
||||||
|
<div class="bg-green-50 rounded-lg p-3 text-center border border-green-100">
|
||||||
|
<p class="text-xs text-green-600 font-medium">总毛利</p>
|
||||||
|
<p class="text-lg font-bold text-green-700" id="budgetTotalGross">¥0</p>
|
||||||
|
</div>
|
||||||
|
<div class="bg-amber-50 rounded-lg p-3 text-center border border-amber-100" id="budgetTotalPaymentCard">
|
||||||
|
<p class="text-xs text-amber-600 font-medium">总回款</p>
|
||||||
|
<p class="text-lg font-bold text-amber-700" id="budgetTotalPayment">¥0</p>
|
||||||
|
</div>
|
||||||
|
<div class="bg-rose-50 rounded-lg p-3 text-center border border-rose-100" id="budgetTotalCostCard">
|
||||||
|
<p class="text-xs text-rose-600 font-medium">总费用</p>
|
||||||
|
<p class="text-lg font-bold text-rose-700" id="budgetTotalCost">¥0</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<table class="w-full text-sm border border-slate-200 rounded-lg overflow-hidden" id="budgetTable">
|
||||||
|
<thead><tr class="bg-slate-50 border-b border-slate-200"><th class="p-2.5 text-left font-medium text-slate-500" style="min-width:140px">月份</th><th class="p-2.5 text-right font-medium text-slate-500">确收</th><th class="p-2.5 text-right font-medium text-slate-500">毛利</th><th class="p-2.5 text-right font-medium text-slate-500">回款</th><th class="p-2.5 text-right font-medium text-slate-500">费用</th><th class="p-2.5 w-8"></th></tr></thead>
|
||||||
|
<tbody id="budgetTbody"></tbody>
|
||||||
|
</table>
|
||||||
|
<button type="button" class="btn btn-ghost btn-sm mt-3" onclick="addBudgetRow()"><i data-lucide="plus"></i>添加月份</button>
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-end gap-3 pt-2"><button type="button" class="btn btn-ghost btn-sm px-6" onclick="closeFinanceModal()">取消</button><button type="submit" class="btn btn-primary btn-sm px-8">保存</button></div></form></div></div>
|
||||||
|
${card(`<div class="flex items-center justify-between mb-3"><h3 class="font-bold text-slate-700">项目明细 <span class="text-slate-400 font-normal">(${pfs.length})</span></h3><div class="flex items-center gap-1" id="finViewToggle"><button class="btn btn-sm ${state.finView !== 'cashflow' ? 'btn-primary' : 'btn-ghost'} p-1.5" data-view="rev" onclick="setFinView('rev')" title="确收/毛利视图"><i data-lucide="trending-up" style="width:16px;height:16px"></i></button><button class="btn btn-sm ${state.finView === 'cashflow' ? 'btn-primary' : 'btn-ghost'} p-1.5" data-view="cashflow" onclick="setFinView('cashflow')" title="回款/费用视图"><i data-lucide="wallet" style="width:16px;height:16px"></i></button></div></div><div class="flex gap-2 mb-3">${[["已签约","已签约"],["流程中","流程中"],["待签约","待签约"]].map(([k,v]) => `<button class="btn btn-sm ${state.finFilter === k ? 'btn-primary' : 'btn-ghost'}" onclick="state.finFilter='${k}';renderFinance()">${v} (${pfs.filter(x=>x.status===k).length})</button>`).join("")}</div><div class="overflow-x-auto"><table class="w-full text-sm"><thead><tr class="bg-slate-50 border-b border-slate-200"><th class="p-2 text-center font-semibold">项目名称</th><th class="p-2 text-center font-semibold">类型</th><th class="p-2 text-center font-semibold">状态</th><th class="p-2 text-center font-semibold">签约月份</th><th class="p-2 text-center font-semibold">签约金额</th>${monthLabels.map(l => `<th class="p-2 text-center font-semibold">${l}<br><span class="text-xs text-slate-400">${state.finView !== 'cashflow' ? '确收/毛利' : '回款/费用'}</span></th>`).join("")}<th class="p-2 text-center font-semibold">总计<br><span class="text-xs text-slate-400">${state.finView !== 'cashflow' ? '确收/毛利' : '回款/费用'}</span></th><th class="p-2 text-center font-semibold">商务负责人</th><th class="p-2 text-center font-semibold">经营负责人</th></tr></thead><tbody>${pfs.filter(x => x.status === state.finFilter).map(renderPfRow).join("")}</tbody></table></div>`, "p-4")}
|
||||||
|
</div>`;
|
||||||
|
if (window.lucide) window.lucide.createIcons();
|
||||||
|
}
|
||||||
|
|
||||||
|
window.openFinanceModal = () => {
|
||||||
|
const modal = document.querySelector("#financeModal");
|
||||||
|
const form = modal.querySelector("form");
|
||||||
|
form.querySelector('[name="project_id"]').value = state.tenant;
|
||||||
|
const dept = form.querySelector('input[disabled]');
|
||||||
|
if (dept) dept.value = state.tenant;
|
||||||
|
const pfIdInput = form.querySelector('[name="pf_id"]');
|
||||||
|
if (!pfIdInput || !pfIdInput.value) {
|
||||||
|
initBudgetTable(null);
|
||||||
|
document.querySelector("#financeDeleteBtn").classList.add("hidden");
|
||||||
|
}
|
||||||
|
modal.classList.remove("hidden");
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addBudgetRow = (month = '', rev = '', gross = '', payment = '', cost = '') => {
|
||||||
|
const tbody = document.querySelector("#budgetTbody");
|
||||||
|
if (!tbody) return;
|
||||||
|
const row = document.createElement("tr");
|
||||||
|
row.innerHTML = `<td><select name="budget_month[]" class="form-ctrl form-ctrl-sm w-full" style="min-width:140px" onchange="updateBudgetSummary()">${monthOptions(month)}</select></td>
|
||||||
|
<td><input name="budget_rev[]" type="number" step="0.01" class="form-ctrl form-ctrl-sm w-full text-right" placeholder="0" value="${rev}" oninput="updateBudgetSummary()"></td>
|
||||||
|
<td><input name="budget_gross[]" type="number" step="0.01" class="form-ctrl form-ctrl-sm w-full text-right" placeholder="0" value="${gross}" oninput="updateBudgetSummary()"></td>
|
||||||
|
<td><input name="budget_payment[]" type="number" step="0.01" class="form-ctrl form-ctrl-sm w-full text-right" placeholder="0" value="${payment}" oninput="updateBudgetSummary()"></td>
|
||||||
|
<td><input name="budget_cost[]" type="number" step="0.01" class="form-ctrl form-ctrl-sm w-full text-right" placeholder="0" value="${cost}" oninput="updateBudgetSummary()"></td>
|
||||||
|
<td><button type="button" class="btn btn-ghost btn-sm text-red-500 p-0 w-6 h-6" onclick="this.closest('tr').remove();updateBudgetSummary()"><i data-lucide="trash-2" style="width:14px;height:14px"></i></button></td>`;
|
||||||
|
tbody.appendChild(row);
|
||||||
|
if (window.lucide) window.lucide.createIcons();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.updateBudgetSummary = () => {
|
||||||
|
const revEl = document.querySelector("#budgetTotalRev");
|
||||||
|
const grossEl = document.querySelector("#budgetTotalGross");
|
||||||
|
const paymentEl = document.querySelector("#budgetTotalPayment");
|
||||||
|
const costEl = document.querySelector("#budgetTotalCost");
|
||||||
|
if (!revEl || !grossEl) return;
|
||||||
|
const revInputs = document.querySelectorAll('[name="budget_rev[]"]');
|
||||||
|
const grossInputs = document.querySelectorAll('[name="budget_gross[]"]');
|
||||||
|
const paymentInputs = document.querySelectorAll('[name="budget_payment[]"]');
|
||||||
|
const costInputs = document.querySelectorAll('[name="budget_cost[]"]');
|
||||||
|
let totalRev = 0, totalGross = 0, totalPayment = 0, totalCost = 0;
|
||||||
|
revInputs.forEach(el => { totalRev += parseFloat(el.value) || 0; });
|
||||||
|
grossInputs.forEach(el => { totalGross += parseFloat(el.value) || 0; });
|
||||||
|
paymentInputs.forEach(el => { totalPayment += parseFloat(el.value) || 0; });
|
||||||
|
costInputs.forEach(el => { totalCost += parseFloat(el.value) || 0; });
|
||||||
|
revEl.textContent = money(totalRev);
|
||||||
|
grossEl.textContent = money(totalGross);
|
||||||
|
if (paymentEl) paymentEl.textContent = money(totalPayment);
|
||||||
|
if (costEl) costEl.textContent = money(totalCost);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.initBudgetTable = (budgetData) => {
|
||||||
|
const tbody = document.querySelector("#budgetTbody");
|
||||||
|
if (!tbody) return;
|
||||||
|
tbody.innerHTML = "";
|
||||||
|
const rows = budgetData || [];
|
||||||
|
rows.forEach(r => addBudgetRow(r.month || '', r.rev || '', r.gross || '', r.payment || '', r.cost || ''));
|
||||||
|
setTimeout(() => updateBudgetSummary(), 50);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.closeFinanceModal = () => {
|
||||||
|
const modal = document.querySelector("#financeModal");
|
||||||
|
modal.classList.add("hidden");
|
||||||
|
};
|
||||||
|
|
||||||
|
window.editPfSignMonth = (event, pfId) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
const pf = (state.data.projectFinances || []).find(x => x.id === pfId);
|
||||||
|
if (!pf) return;
|
||||||
|
const span = event.currentTarget;
|
||||||
|
const td = span.parentElement;
|
||||||
|
const currentValue = pf.sign_month || "";
|
||||||
|
const select = document.createElement("select");
|
||||||
|
select.innerHTML = monthOptions(currentValue);
|
||||||
|
select.className = "form-ctrl form-ctrl-sm w-full";
|
||||||
|
select.value = currentValue;
|
||||||
|
select.addEventListener("change", async () => {
|
||||||
|
const newValue = select.value;
|
||||||
|
try {
|
||||||
|
await api(`/api/projectFinances/${pfId}`, { method: "PUT", body: JSON.stringify({ data: { sign_month: newValue } }) });
|
||||||
|
pf.sign_month = newValue;
|
||||||
|
td.innerHTML = `<span class="pf-sm-text cursor-pointer hover:text-blue-600" onclick="editPfSignMonth(event, ${pfId})">${newValue || '—'}</span>`;
|
||||||
|
} catch (e) { toast("修改失败:" + e.message, "error"); }
|
||||||
|
});
|
||||||
|
select.addEventListener("blur", () => {
|
||||||
|
td.innerHTML = `<span class="pf-sm-text cursor-pointer hover:text-blue-600" onclick="editPfSignMonth(event, ${pfId})">${currentValue || '—'}</span>`;
|
||||||
|
});
|
||||||
|
td.innerHTML = "";
|
||||||
|
td.appendChild(select);
|
||||||
|
select.focus();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.switchFinanceTab = (tab) => {
|
||||||
|
document.querySelectorAll(".finance-tab").forEach(b => b.classList.toggle("active", b.dataset.tab === tab));
|
||||||
|
document.querySelector("#financeTabInfo").classList.toggle("hidden", tab !== "info");
|
||||||
|
document.querySelector("#financeTabBudget").classList.toggle("hidden", tab !== "budget");
|
||||||
|
};
|
||||||
|
|
||||||
|
window.openPfEditModal = (pfId) => {
|
||||||
|
const pf = (state.data.projectFinances || []).find(x => x.id === pfId);
|
||||||
|
if (!pf) return;
|
||||||
|
document.querySelector("#pf-id-input").value = pf.id;
|
||||||
|
document.querySelector("#financeModalTitle").textContent = "编辑项目财务";
|
||||||
|
document.querySelector("#financeDeleteBtn").classList.remove("hidden");
|
||||||
|
const form = document.querySelector("#financeModal form");
|
||||||
|
form.querySelector('[name="project_id"]').value = pf.project_id || "";
|
||||||
|
const deptDisplay = form.querySelector('.bg-slate-50 [disabled]');
|
||||||
|
if (deptDisplay) deptDisplay.value = pf.project_id || "";
|
||||||
|
form.querySelector('[name="business_type"]').value = pf.business_type || "";
|
||||||
|
form.querySelector('[name="customer_name"]').value = pf.customer_name || "";
|
||||||
|
form.querySelector('[name="sign_amount"]').value = pf.sign_amount || "";
|
||||||
|
const signMonthValue = pf.sign_month || "";
|
||||||
|
const signMonthEl = form.querySelector('[name="sign_month"]');
|
||||||
|
if (signMonthEl && signMonthValue) {
|
||||||
|
signMonthEl.innerHTML = monthOptions(signMonthValue);
|
||||||
|
signMonthEl.value = signMonthValue;
|
||||||
|
}
|
||||||
|
form.querySelector('[name="status"]').value = pf.status || "待签约";
|
||||||
|
form.querySelector('[name="sales_person"]').value = pf.sales_person || "";
|
||||||
|
form.querySelector('[name="owner"]').value = pf.owner || "";
|
||||||
|
let budgetData = [];
|
||||||
|
try { budgetData = JSON.parse(pf.budget_data || "[]"); } catch (e) { budgetData = []; }
|
||||||
|
initBudgetTable(budgetData.length ? budgetData : null);
|
||||||
|
setTimeout(() => updateBudgetSummary(), 100);
|
||||||
|
openFinanceModal();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.createFinance = async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = event.currentTarget;
|
||||||
|
const data = Object.fromEntries(new FormData(form).entries());
|
||||||
|
data.tenant = state.tenant;
|
||||||
|
// 必填校验
|
||||||
|
if (!data.customer_name || !data.customer_name.trim()) { toast("项目名称必填", "error"); return; }
|
||||||
|
if (!data.sales_person || !data.sales_person.trim()) { toast("商务负责人必填", "error"); return; }
|
||||||
|
if (!data.owner || !data.owner.trim()) { toast("经营负责人必填", "error"); return; }
|
||||||
|
if (!data.sign_month) { toast("签约月份必填", "error"); return; }
|
||||||
|
data.sign_amount = parseFloat(data.sign_amount) || 0;
|
||||||
|
if (!(data.sign_amount > 0)) { toast("签约金额必须大于 0", "error"); return; }
|
||||||
|
const months = form.querySelectorAll('[name="budget_month[]"]');
|
||||||
|
const revs = form.querySelectorAll('[name="budget_rev[]"]');
|
||||||
|
const grosses = form.querySelectorAll('[name="budget_gross[]"]');
|
||||||
|
const payments = form.querySelectorAll('[name="budget_payment[]"]');
|
||||||
|
const costs = form.querySelectorAll('[name="budget_cost[]"]');
|
||||||
|
const budgetRows = [];
|
||||||
|
let totalRev = 0, totalGross = 0;
|
||||||
|
for (let i = 0; i < months.length; i++) {
|
||||||
|
const m = months[i].value.trim();
|
||||||
|
if (!m) continue;
|
||||||
|
const rev = parseFloat(revs[i].value) || 0;
|
||||||
|
const gross = parseFloat(grosses[i].value) || 0;
|
||||||
|
const payment = parseFloat(payments[i].value) || 0;
|
||||||
|
const cost = parseFloat(costs[i].value) || 0;
|
||||||
|
budgetRows.push({ month: m, rev, gross, payment, cost });
|
||||||
|
totalRev += rev;
|
||||||
|
totalGross += gross;
|
||||||
|
}
|
||||||
|
data.budget_data = JSON.stringify(budgetRows);
|
||||||
|
data.total_rev = totalRev;
|
||||||
|
data.total_gross = totalGross;
|
||||||
|
const pfId = data.pf_id;
|
||||||
|
delete data.pf_id;
|
||||||
|
try {
|
||||||
|
if (pfId) {
|
||||||
|
await api("/api/projectFinances/" + pfId, { method: "PUT", body: JSON.stringify({ data }) });
|
||||||
|
if (data.customer_name) logActivity("finance", pfId, "更新了「" + data.customer_name + "」的财务信息");
|
||||||
|
} else {
|
||||||
|
const result = await api("/api/projectFinances", { method: "POST", body: JSON.stringify({ data }) });
|
||||||
|
if (result.id && data.customer_name) logActivity("finance", result.id, "创建了「" + data.customer_name + "」的财务项目");
|
||||||
|
}
|
||||||
|
form.reset();
|
||||||
|
document.querySelector("#pf-id-input").value = "";
|
||||||
|
document.querySelector("#financeModalTitle").textContent = "新增项目财务";
|
||||||
|
closeFinanceModal();
|
||||||
|
await load();
|
||||||
|
} catch (error) {
|
||||||
|
toast("保存失败:" + error.message, "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.deleteFinanceItem = async () => {
|
||||||
|
const pfId = document.querySelector("#pf-id-input").value;
|
||||||
|
if (!pfId) return;
|
||||||
|
const pf = (state.data.projectFinances || []).find(x => x.id === parseInt(pfId));
|
||||||
|
const name = pf ? (pf.customer_name || "此项目") : "此项目";
|
||||||
|
if (!confirm(`确认删除「${name}」?此操作不可撤销。`)) return;
|
||||||
|
try {
|
||||||
|
await api(`/api/projectFinances/${pfId}`, { method: "DELETE" });
|
||||||
|
closeFinanceModal();
|
||||||
|
await load();
|
||||||
|
toast("已删除", "success");
|
||||||
|
} catch (error) {
|
||||||
|
toast("删除失败:" + error.message, "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
103
static/modules/home.js
Normal file
103
static/modules/home.js
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
// home.js — 首页渲染 + 财务趋势图
|
||||||
|
|
||||||
|
function renderHome() {
|
||||||
|
const { summary, financeMonthly } = state.data;
|
||||||
|
const m = summary.metrics;
|
||||||
|
const rows1 = [
|
||||||
|
["年度累计签约", money(m.signed_annual || m.signed_amount)],
|
||||||
|
["Q2 累计签约", money(m.signed_q2 || 0)],
|
||||||
|
["本月新增签约", money(m.signed_month || 0)],
|
||||||
|
];
|
||||||
|
const rows2 = [
|
||||||
|
["年度累计确收", money(m.revenue_annual)],
|
||||||
|
["Q2 累计确收", money(m.revenue_q2)],
|
||||||
|
["本月新增确收", money(m.monthly_revenue)],
|
||||||
|
];
|
||||||
|
const rows3 = [
|
||||||
|
["年度累计毛利", money(m.gross_annual)],
|
||||||
|
["Q2 累计毛利", money(m.gross_q2)],
|
||||||
|
["本月新增毛利", money(m.monthly_net_profit)],
|
||||||
|
];
|
||||||
|
const tblCard = (title, rows) => card(`<h3 class="text-sm font-bold text-slate-700 mb-3">${title}</h3><table class="w-full text-sm"><tbody>${rows.map(([label, value]) => `<tr class="border-b border-slate-100 last:border-0"><td class="py-2 pr-4 text-slate-500">${label}</td><td class="py-2 text-right font-semibold text-slate-800">${value}</td></tr>`).join("")}</tbody></table>`, "p-4");
|
||||||
|
document.querySelector("#home").innerHTML = `
|
||||||
|
<div class="grid gap-5">
|
||||||
|
<div class="grid grid-cols-4 gap-3">
|
||||||
|
${[
|
||||||
|
["经营管理", m.total_projects, "finance"],
|
||||||
|
["重点工作与台账", m.total_proposals, "projects"],
|
||||||
|
["业务方案", m.total_products, "proposals"],
|
||||||
|
["产品迭代", 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-3 gap-5">${tblCard("合同金额", rows1)}${tblCard("确收金额", rows2)}${tblCard("确收毛利", rows3)}</div>
|
||||||
|
<div class="grid grid-cols-3 gap-5">
|
||||||
|
${card(`<div class="mb-3 flex items-center justify-between"><h2 class="text-sm font-bold text-slate-600">月度签约趋势</h2><span class="text-xs text-slate-400">2026</span></div><div style="position:relative;height:200px"><canvas id="chartSign"></canvas></div>`, "p-4")}
|
||||||
|
${card(`<div class="mb-3 flex items-center justify-between"><h2 class="text-sm font-bold text-slate-600">月度确收与毛利</h2><span class="text-xs text-slate-400">2026</span></div><div style="position:relative;height:200px"><canvas id="chartRev"></canvas></div>`, "p-4")}
|
||||||
|
${card(`<div class="mb-3 flex items-center justify-between"><h2 class="text-sm font-bold text-slate-600">月度回款与费用</h2><span class="text-xs text-slate-400">2026</span></div><div style="position:relative;height:200px"><canvas id="chartCash"></canvas></div>`, "p-4")}
|
||||||
|
</div>
|
||||||
|
${card(`<h2 class="text-lg font-bold">近期动态</h2><div class="mt-4 grid gap-2">${summary.recent.map((r) => `<div class="flex items-start justify-between rounded-md bg-slate-50 px-3 py-2 text-sm group"><span class="break-words">${r.content}</span><div class="flex items-center gap-2 flex-shrink-0 ml-2"><span class="text-xs text-slate-400">${r.followed_at}</span><button class="btn btn-ghost btn-sm text-red-400 opacity-0 group-hover:opacity-100 p-0 w-5 h-5" onclick="event.preventDefault();deleteActivity(${r.id})" title="删除动态"><i data-lucide="x" style="width:14px;height:14px"></i></button></div></div>`).join("")}</div>`, "p-5")}
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
renderCharts(financeMonthly);
|
||||||
|
}
|
||||||
|
|
||||||
|
function chartOptions(yCallback) {
|
||||||
|
return {
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
plugins: { legend: { position: "bottom", labels: { boxWidth: 12, font: { size: 11 } } } },
|
||||||
|
scales: {
|
||||||
|
x: { ticks: { font: { size: 10 } }, grid: { display: false } },
|
||||||
|
y: { ticks: { font: { size: 11 }, callback: yCallback } },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const moneyTick = (v) => v >= 10000 ? (v / 10000).toFixed(0) + "万" : v;
|
||||||
|
const monthLabels = (data) => data.map((x) => parseInt(x.month.split("-")[1]) + "月");
|
||||||
|
|
||||||
|
function renderCharts(data) {
|
||||||
|
const labels = monthLabels(data);
|
||||||
|
const baseOpts = chartOptions(moneyTick);
|
||||||
|
|
||||||
|
// 图1:月度签约
|
||||||
|
const c1 = document.querySelector("#chartSign");
|
||||||
|
if (c1 && window.Chart) {
|
||||||
|
if (state.chart) state.chart.destroy();
|
||||||
|
state.chart = new Chart(c1, {
|
||||||
|
type: "line",
|
||||||
|
data: { labels, datasets: [
|
||||||
|
{ label: "签约金额", data: data.map((x) => x.sign || 0), borderColor: "#6366f1", backgroundColor: "rgba(99,102,241,0.06)", fill: true, tension: 0.3 },
|
||||||
|
]},
|
||||||
|
options: baseOpts,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 图2:月度确收与毛利
|
||||||
|
const c2 = document.querySelector("#chartRev");
|
||||||
|
if (c2 && window.Chart) {
|
||||||
|
if (state.chart2) state.chart2.destroy();
|
||||||
|
state.chart2 = new Chart(c2, {
|
||||||
|
type: "line",
|
||||||
|
data: { labels, datasets: [
|
||||||
|
{ label: "确收", data: data.map((x) => x.revenue || 0), borderColor: "#2563eb", backgroundColor: "rgba(37,99,235,0.06)", fill: true, tension: 0.3 },
|
||||||
|
{ label: "毛利", data: data.map((x) => x.net_profit || 0), borderColor: "#059669", backgroundColor: "rgba(5,150,105,0.06)", fill: true, tension: 0.3 },
|
||||||
|
]},
|
||||||
|
options: baseOpts,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 图3:月度回款与费用
|
||||||
|
const c3 = document.querySelector("#chartCash");
|
||||||
|
if (c3 && window.Chart) {
|
||||||
|
if (state.chart3) state.chart3.destroy();
|
||||||
|
state.chart3 = new Chart(c3, {
|
||||||
|
type: "bar",
|
||||||
|
data: { labels, datasets: [
|
||||||
|
{ label: "回款", data: data.map((x) => x.payment || 0), backgroundColor: "#d97706", borderRadius: 4 },
|
||||||
|
{ label: "费用", data: data.map((x) => x.cost || 0), backgroundColor: "#ef4444", borderRadius: 4 },
|
||||||
|
]},
|
||||||
|
options: baseOpts,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
204
static/modules/products.js
Normal file
204
static/modules/products.js
Normal file
@@ -0,0 +1,204 @@
|
|||||||
|
// products.js — 产品迭代模块
|
||||||
|
|
||||||
|
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 form = event.currentTarget;
|
||||||
|
const data = Object.fromEntries(new FormData(form).entries());
|
||||||
|
data.tenant = state.tenant;
|
||||||
|
try {
|
||||||
|
const result = await api(`/api/${resource}`, { method: "POST", body: JSON.stringify({ data }) });
|
||||||
|
const targetMap = { sales: "sales", proposals: "proposal", operations: "operation", products: "product" };
|
||||||
|
const resType = targetMap[resource] || resource;
|
||||||
|
const name = data.project_name || data.target_customer || data.customer_or_project_name || data.product_name || "";
|
||||||
|
if (result.id && name) logActivity(resType, result.id, "创建了" + name);
|
||||||
|
form.reset();
|
||||||
|
await load();
|
||||||
|
} catch (error) {
|
||||||
|
toast("创建失败:" + error.message, "error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.createSales = (event) => createResource(event, "sales");
|
||||||
|
window.createProposal = (event) => createResource(event, "proposals");
|
||||||
|
window.createOperation = async (event) => {
|
||||||
|
await createResource(event, "operations");
|
||||||
|
if (typeof closeNewProjectModal === "function") closeNewProjectModal();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.openProductDrawer = () => {
|
||||||
|
const drawer = document.querySelector("#productDrawer");
|
||||||
|
drawer.innerHTML = `<div class="task-drawer-hd">
|
||||||
|
<span class="task-drawer-title">新增产品版本</span>
|
||||||
|
<button class="task-close" onclick="closeProductDrawer()"><i data-lucide="x"></i></button>
|
||||||
|
</div>
|
||||||
|
<form class="task-drawer-form" onsubmit="submitProductDrawer(event)">
|
||||||
|
<label class="task-field"><span>产品名称</span><input name="product_name" required class="form-ctrl"></label>
|
||||||
|
<label class="task-field"><span>版本号</span><input name="version" required class="form-ctrl"></label>
|
||||||
|
<label class="task-field"><span>版本目标</span><textarea name="version_goal" rows="2" class="form-ctrl"></textarea></label>
|
||||||
|
<label class="task-field"><span>核心功能</span><div class="feature-list" id="newFeatureList"><div class="feature-item"><span class="feature-num">1.</span><input class="form-ctrl" value=""><button class="feature-del" onclick="event.preventDefault();removeNewFeature(this)"><i data-lucide="x" style="width:12px;height:12px"></i></button></div></div><button class="btn btn-ghost btn-sm text-blue-600 mt-1" onclick="event.preventDefault();addNewFeature()"><i data-lucide="plus" style="width:14px;height:14px"></i>添加功能</button></label>
|
||||||
|
<label class="task-field"><span>上线日期</span><input name="launch_date" type="date" class="form-ctrl"></label>
|
||||||
|
<label class="task-field"><span>状态</span><select name="status" class="form-ctrl"><option>规划中</option><option>开发中</option><option>测试中</option><option>已上线</option><option>已取消</option></select></label>
|
||||||
|
<input type="hidden" name="feature_list" id="newFeatureListHidden">
|
||||||
|
<div class="flex justify-end gap-2 mt-4 pt-3 border-t border-slate-100">
|
||||||
|
<button type="button" class="btn btn-ghost btn-sm" onclick="closeProductDrawer()">取消</button>
|
||||||
|
<button type="submit" class="btn btn-primary btn-sm">确认新增</button>
|
||||||
|
</div>
|
||||||
|
</form>`;
|
||||||
|
drawer.classList.add("open");
|
||||||
|
if (window.lucide) window.lucide.createIcons();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.closeProductDrawer = () => {
|
||||||
|
document.querySelector("#productDrawer").classList.remove("open");
|
||||||
|
};
|
||||||
|
|
||||||
|
window.cycleProductStatus = async (id) => {
|
||||||
|
const products = state.data.products || [];
|
||||||
|
const product = products.find(x => x.id === id);
|
||||||
|
if (!product) return;
|
||||||
|
const statuses = ["规划中", "开发中", "测试中", "已上线", "已取消"];
|
||||||
|
const current = statuses.indexOf(product.status) >= 0 ? product.status : "规划中";
|
||||||
|
const newStatus = statuses[(statuses.indexOf(current) + 1) % statuses.length];
|
||||||
|
try {
|
||||||
|
await api(`/api/products/${id}`, { method: "PUT", body: JSON.stringify({ data: { status: newStatus } }) });
|
||||||
|
product.status = newStatus;
|
||||||
|
renderProducts();
|
||||||
|
} catch (error) {
|
||||||
|
toast("更新失败:" + error.message, "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.editProductDate = (event, id) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
const products = state.data.products || [];
|
||||||
|
const product = products.find(x => x.id === id);
|
||||||
|
if (!product) return;
|
||||||
|
const span = event.currentTarget;
|
||||||
|
const td = span.parentElement;
|
||||||
|
const currentValue = product.launch_date || "";
|
||||||
|
const input = document.createElement("input");
|
||||||
|
input.type = "date";
|
||||||
|
input.className = "form-ctrl form-ctrl-sm w-full";
|
||||||
|
input.value = currentValue;
|
||||||
|
input.addEventListener("change", async () => {
|
||||||
|
const newValue = input.value;
|
||||||
|
try {
|
||||||
|
await api(`/api/products/${id}`, { method: "PUT", body: JSON.stringify({ data: { launch_date: newValue } }) });
|
||||||
|
product.launch_date = newValue;
|
||||||
|
td.innerHTML = `<span class="cursor-pointer hover:text-blue-600" onclick="editProductDate(event, ${id})">${newValue || '—'}</span>`;
|
||||||
|
} catch (e) { toast("修改失败:" + e.message, "error"); }
|
||||||
|
});
|
||||||
|
input.addEventListener("blur", () => {
|
||||||
|
td.innerHTML = `<span class="cursor-pointer hover:text-blue-600" onclick="editProductDate(event, ${id})">${currentValue || '—'}</span>`;
|
||||||
|
});
|
||||||
|
td.innerHTML = "";
|
||||||
|
td.appendChild(input);
|
||||||
|
input.focus();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addNewFeature = () => {
|
||||||
|
const list = document.querySelector("#newFeatureList");
|
||||||
|
if (!list) return;
|
||||||
|
const idx = list.children.length;
|
||||||
|
const div = document.createElement("div");
|
||||||
|
div.className = "feature-item";
|
||||||
|
div.innerHTML = `<span class="feature-num">${idx+1}.</span><input class="form-ctrl" value=""><button class="feature-del" onclick="event.preventDefault();removeNewFeature(this)"><i data-lucide="x" style="width:12px;height:12px"></i></button>`;
|
||||||
|
list.appendChild(div);
|
||||||
|
if (window.lucide) window.lucide.createIcons();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.removeNewFeature = (btn) => {
|
||||||
|
const div = btn.closest(".feature-item");
|
||||||
|
if (!div) return;
|
||||||
|
div.remove();
|
||||||
|
const list = document.querySelector("#newFeatureList");
|
||||||
|
if (list) list.querySelectorAll(".feature-num").forEach((el, i) => { el.textContent = (i+1) + "."; });
|
||||||
|
};
|
||||||
|
|
||||||
|
window.submitProductDrawer = async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = event.currentTarget;
|
||||||
|
const data = Object.fromEntries(new FormData(form).entries());
|
||||||
|
const featureInputs = form.querySelectorAll("#newFeatureList input");
|
||||||
|
data.feature_list = [...featureInputs].map(el => el.value.trim()).filter(Boolean).join("\n");
|
||||||
|
data.platform = "";
|
||||||
|
data.tenant = state.tenant;
|
||||||
|
try {
|
||||||
|
const result = await api("/api/products", { method: "POST", body: JSON.stringify({ data }) });
|
||||||
|
form.reset();
|
||||||
|
closeProductDrawer();
|
||||||
|
if (result.id) logActivity("product", result.id, "创建了产品版本「" + data.product_name + " " + data.version + "」");
|
||||||
|
await load();
|
||||||
|
} catch (error) {
|
||||||
|
toast("创建失败:" + error.message, "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addFeature = (id) => {
|
||||||
|
const list = document.querySelector(`#featureList_${id}`);
|
||||||
|
if (!list) return;
|
||||||
|
const idx = list.children.length;
|
||||||
|
const div = document.createElement("div");
|
||||||
|
div.className = "feature-item";
|
||||||
|
div.innerHTML = `<span class="feature-num">${idx+1}.</span><input class="form-ctrl" value="" onchange="saveFeatureList(${id})"><button class="feature-del" onclick="event.preventDefault();removeFeature(${id},${idx})"><i data-lucide="x" style="width:12px;height:12px"></i></button>`;
|
||||||
|
list.appendChild(div);
|
||||||
|
if (window.lucide) window.lucide.createIcons();
|
||||||
|
saveFeatureList(id);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.removeFeature = (id, idx) => {
|
||||||
|
const list = document.querySelector(`#featureList_${id}`);
|
||||||
|
if (!list) return;
|
||||||
|
const items = list.querySelectorAll(".feature-item");
|
||||||
|
if (items[idx]) items[idx].remove();
|
||||||
|
list.querySelectorAll(".feature-num").forEach((el, i) => { el.textContent = (i+1) + "."; });
|
||||||
|
saveFeatureList(id);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.saveFeatureList = (id) => {
|
||||||
|
const list = document.querySelector(`#featureList_${id}`);
|
||||||
|
if (!list) return;
|
||||||
|
const values = [...list.querySelectorAll("input")].map(el => el.value.trim()).filter(Boolean);
|
||||||
|
const data = values.join("\n");
|
||||||
|
api(`/api/products/${id}`, { method: "PUT", body: JSON.stringify({ data: { feature_list: data } }) });
|
||||||
|
const product = (state.data.products || []).find(x => x.id === id);
|
||||||
|
if (product) product.feature_list = data;
|
||||||
|
};
|
||||||
|
|
||||||
|
function renderProducts() {
|
||||||
|
const items = state.data.products || [];
|
||||||
|
document.querySelector("#products").innerHTML = `
|
||||||
|
<div class="grid gap-4">
|
||||||
|
<div class="flex justify-end">
|
||||||
|
<button class="btn btn-primary btn-sm" onclick="openProductDrawer()"><i data-lucide="plus"></i>新增产品版本</button>
|
||||||
|
</div>
|
||||||
|
<div class="grid grid-cols-3 gap-4">
|
||||||
|
${items.map((p) => `
|
||||||
|
<div class="bg-white rounded-xl border border-slate-200 p-4 cursor-pointer hover:shadow-lg hover:border-blue-200 transition-all" onclick="openDrawer('products', ${p.id})">
|
||||||
|
<div class="flex items-start justify-between">
|
||||||
|
<h4 class="text-base font-semibold text-slate-800 leading-tight">${esc(p.product_name)}</h4>
|
||||||
|
<span class="status-badge status-${esc(p.status)}" onclick="event.stopPropagation(); cycleProductStatus(${p.id})" title="点击切换状态">${esc(p.status) || '规划中'}</span>
|
||||||
|
</div>
|
||||||
|
<div class="mt-2 flex items-center gap-2 text-xs text-slate-500">
|
||||||
|
<span class="font-medium">${esc(p.version)}</span>
|
||||||
|
<span>·</span>
|
||||||
|
<span class="cursor-pointer hover:text-blue-600 transition-colors" onclick="event.stopPropagation(); editProductDate(event, ${p.id})">${esc(p.launch_date) || '—'}</span>
|
||||||
|
</div>
|
||||||
|
<div class="mt-3 space-y-1">
|
||||||
|
<p class="text-sm text-slate-700 mt-1.5 leading-relaxed">${esc(p.version_goal) || '—'}</p>
|
||||||
|
<div class="text-sm text-slate-600 mt-1.5 leading-relaxed whitespace-pre-line">${esc(p.feature_list) || '—'}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`).join("")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<aside id="productDrawer" class="task-drawer"></aside>
|
||||||
|
`;
|
||||||
|
}
|
||||||
519
static/modules/projects.js
Normal file
519
static/modules/projects.js
Normal file
@@ -0,0 +1,519 @@
|
|||||||
|
// projects.js — 重点工作与台账(项目管理 + 任务管理)
|
||||||
|
|
||||||
|
function applyUserTenants() {
|
||||||
|
fetch("/api/auth/me").then(r => r.json()).then(data => {
|
||||||
|
if (!data.logged_in) { window.location.href = "/login"; return; }
|
||||||
|
const user = data.user;
|
||||||
|
const avatar = document.querySelector("#userAvatar");
|
||||||
|
avatar.textContent = user.display_name.charAt(0);
|
||||||
|
avatar.title = user.display_name;
|
||||||
|
const nameEl = document.querySelector("#userDisplayName");
|
||||||
|
if (nameEl) { nameEl.textContent = user.display_name; nameEl.title = user.display_name; }
|
||||||
|
avatar.addEventListener("click", (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
toggleUserMenu(user);
|
||||||
|
});
|
||||||
|
const allowedTenants = data.tenants || [];
|
||||||
|
document.querySelectorAll(".workspace-nav-item").forEach(el => {
|
||||||
|
el.style.display = allowedTenants.includes(el.dataset.tenant) ? "" : "none";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
window.toggleUserMenu = (user) => {
|
||||||
|
let menu = document.getElementById("userMenu");
|
||||||
|
if (menu) { menu.remove(); return; }
|
||||||
|
const avatar = document.querySelector("#userAvatar");
|
||||||
|
const rect = avatar.getBoundingClientRect();
|
||||||
|
menu = document.createElement("div");
|
||||||
|
menu.id = "userMenu";
|
||||||
|
menu.className = "fixed bg-white rounded-lg shadow-xl border border-slate-200 py-1 min-w-[160px] z-[9999]";
|
||||||
|
menu.style.left = Math.min(rect.left - 8, window.innerWidth - 180) + "px";
|
||||||
|
menu.style.top = rect.bottom + 6 + "px";
|
||||||
|
menu.innerHTML = `
|
||||||
|
<div class="px-4 py-3 border-b border-slate-100">
|
||||||
|
<p class="text-sm font-semibold text-slate-800">${esc(user.display_name)}</p>
|
||||||
|
<p class="text-xs text-slate-500 mt-0.5">${esc(user.username || "")}</p>
|
||||||
|
</div>
|
||||||
|
${user.role === 'admin' ? `<button class="w-full text-left px-4 py-2 text-sm text-slate-700 hover:bg-slate-50 transition-colors flex items-center gap-2" onclick="closeUserMenu();openAdminUsers()">
|
||||||
|
<i data-lucide="users" style="width:14px;height:14px"></i>账号管理
|
||||||
|
</button>` : ''}
|
||||||
|
<button class="w-full text-left px-4 py-2 text-sm text-red-600 hover:bg-red-50 transition-colors flex items-center gap-2" onclick="doLogout()">
|
||||||
|
<i data-lucide="log-out" style="width:14px;height:14px"></i>退出登录
|
||||||
|
</button>`;
|
||||||
|
document.body.appendChild(menu);
|
||||||
|
if (window.lucide) lucide.createIcons();
|
||||||
|
setTimeout(() => {
|
||||||
|
document.addEventListener("click", function closeMenu() {
|
||||||
|
menu.remove();
|
||||||
|
document.removeEventListener("click", closeMenu);
|
||||||
|
}, { once: true });
|
||||||
|
}, 10);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.closeUserMenu = () => {
|
||||||
|
const m = document.getElementById("userMenu");
|
||||||
|
if (m) m.remove();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.selectProject = (id) => {
|
||||||
|
state.selectedProject = id;
|
||||||
|
document.querySelectorAll(".project-tree-node").forEach((el) => el.classList.toggle("active", parseInt(el.dataset.id) === id));
|
||||||
|
renderProjectTasks(id);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.togglePhase = (phaseId) => {
|
||||||
|
const wrap = document.querySelector(`#${phaseId}`);
|
||||||
|
if (!wrap) return;
|
||||||
|
wrap.classList.toggle("collapsed");
|
||||||
|
const toggle = document.querySelector(`#${phaseId}-toggle`);
|
||||||
|
if (toggle) toggle.style.transform = wrap.classList.contains("collapsed") ? "rotate(-90deg)" : "";
|
||||||
|
};
|
||||||
|
|
||||||
|
window.showProjectContext = (event, id) => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
const menu = document.querySelector("#projectContextMenu");
|
||||||
|
if (!menu) return;
|
||||||
|
menu.dataset.projectId = id;
|
||||||
|
menu.style.left = event.clientX + "px";
|
||||||
|
menu.style.top = event.clientY + "px";
|
||||||
|
menu.classList.remove("hidden");
|
||||||
|
};
|
||||||
|
|
||||||
|
window.openProjectDrawer = () => {
|
||||||
|
const menu = document.querySelector("#projectContextMenu");
|
||||||
|
if (menu) {
|
||||||
|
const id = parseInt(menu.dataset.projectId);
|
||||||
|
if (id) openDrawer("operations", id);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.renameProject = async () => {
|
||||||
|
const menu = document.querySelector("#projectContextMenu");
|
||||||
|
if (!menu) return;
|
||||||
|
const id = parseInt(menu.dataset.projectId);
|
||||||
|
if (!id) return;
|
||||||
|
const project = (state.data.operations || []).find(x => x.id === id);
|
||||||
|
if (!project) return;
|
||||||
|
const newName = prompt("请输入新的项目名称:", project.project_name);
|
||||||
|
if (!newName || newName.trim() === project.project_name) return;
|
||||||
|
try {
|
||||||
|
await api(`/api/operations/${id}`, { method: "PUT", body: JSON.stringify({ data: { project_name: newName.trim() } }) });
|
||||||
|
project.project_name = newName.trim();
|
||||||
|
renderProjects();
|
||||||
|
toast("已重命名", "success");
|
||||||
|
} catch (error) {
|
||||||
|
toast("重命名失败:" + error.message, "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.duplicateProject = async () => {
|
||||||
|
const menu = document.querySelector("#projectContextMenu");
|
||||||
|
if (!menu) return;
|
||||||
|
const id = parseInt(menu.dataset.projectId);
|
||||||
|
if (!id) return;
|
||||||
|
const project = (state.data.operations || []).find(x => x.id === id);
|
||||||
|
if (!project) return;
|
||||||
|
const newName = prompt("请输入副本项目名称:", project.project_name + " - 副本");
|
||||||
|
if (!newName) return;
|
||||||
|
try {
|
||||||
|
const result = await api("/api/operations", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ data: {
|
||||||
|
project_name: newName.trim(),
|
||||||
|
project_version: project.project_version || "v1.0",
|
||||||
|
project_type: project.project_type || "opportunity",
|
||||||
|
project_status: project.project_status || "",
|
||||||
|
current_stage: project.current_stage || "",
|
||||||
|
owner: project.owner || "慰心",
|
||||||
|
target_customer: project.target_customer || "",
|
||||||
|
customer_need: project.customer_need || "",
|
||||||
|
expected_contract_amount: project.expected_contract_amount || 0,
|
||||||
|
expected_sign_date: project.expected_sign_date || "",
|
||||||
|
sign_probability: project.sign_probability || 0,
|
||||||
|
next_action: project.next_action || "",
|
||||||
|
sop_stage: project.sop_stage || "",
|
||||||
|
execution_progress: project.execution_progress || 0,
|
||||||
|
current_deliverable: project.current_deliverable || "",
|
||||||
|
risks: project.risks || "",
|
||||||
|
notes: project.notes || "",
|
||||||
|
tenant: state.tenant,
|
||||||
|
}}),
|
||||||
|
});
|
||||||
|
// 复制任务
|
||||||
|
const tasks = (state.data.tasks || []).filter(t => t.project_id === id);
|
||||||
|
for (const t of tasks) {
|
||||||
|
await api("/api/tasks", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ data: {
|
||||||
|
project_id: result.id,
|
||||||
|
phase: t.phase || "",
|
||||||
|
milestone: t.milestone || "",
|
||||||
|
task: t.task || "",
|
||||||
|
owner: t.owner || "",
|
||||||
|
due_date: t.due_date || "",
|
||||||
|
blockers: t.blockers || "",
|
||||||
|
notes: t.notes || "",
|
||||||
|
status: "未开始",
|
||||||
|
priority: t.priority || "P2",
|
||||||
|
sort_order: t.sort_order || 0,
|
||||||
|
tenant: state.tenant,
|
||||||
|
}}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
toast("已创建副本", "success");
|
||||||
|
await load();
|
||||||
|
} catch (error) {
|
||||||
|
toast("创建副本失败:" + error.message, "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.hideProjectContext = () => {
|
||||||
|
const menu = document.querySelector("#projectContextMenu");
|
||||||
|
if (menu) menu.classList.add("hidden");
|
||||||
|
};
|
||||||
|
|
||||||
|
window.openNewProjectModal = () => {
|
||||||
|
document.querySelector("#newProjectModal").classList.remove("hidden");
|
||||||
|
};
|
||||||
|
|
||||||
|
window.closeNewProjectModal = () => {
|
||||||
|
document.querySelector("#newProjectModal").classList.add("hidden");
|
||||||
|
};
|
||||||
|
|
||||||
|
function renderProjects() {
|
||||||
|
const items = state.data.operations;
|
||||||
|
if (!state.selectedProject && items.length > 0) {
|
||||||
|
state.selectedProject = items[0].id;
|
||||||
|
}
|
||||||
|
const tasks = state.data.tasks || [];
|
||||||
|
const taskStats = {
|
||||||
|
total: tasks.length,
|
||||||
|
ongoing: tasks.filter(t => t.status === '进行中').length,
|
||||||
|
done: tasks.filter(t => t.status === '已结束').length,
|
||||||
|
pending: tasks.filter(t => t.status === '未开始').length,
|
||||||
|
};
|
||||||
|
document.querySelector("#projects").innerHTML = /*html*/`
|
||||||
|
<div class="grid grid-cols-5 gap-3 mb-4">
|
||||||
|
${[
|
||||||
|
["项目总数", items.length],
|
||||||
|
["任务总数", taskStats.total],
|
||||||
|
["进行中", taskStats.ongoing],
|
||||||
|
["已结束", taskStats.done],
|
||||||
|
["未开始", taskStats.pending],
|
||||||
|
].map(([label, value]) => `
|
||||||
|
<div class="bg-white rounded-lg border border-slate-200 p-3 text-center"><p class="text-xs text-slate-500">${label}</p><p class="text-xl font-bold text-slate-800">${value}</p></div>
|
||||||
|
`).join("")}
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-between items-center mb-3">
|
||||||
|
<div class="flex items-center gap-1" id="taskViewToggle">
|
||||||
|
<button class="btn btn-sm ${state.taskView === 'compact' ? 'btn-primary' : 'btn-ghost'} p-1.5" onclick="setTaskView('compact')" title="标题视图"><i data-lucide="list" style="width:16px;height:16px"></i></button>
|
||||||
|
<button class="btn btn-sm ${state.taskView !== 'compact' ? 'btn-primary' : 'btn-ghost'} p-1.5" onclick="setTaskView('detail')" title="详细视图"><i data-lucide="align-left" style="width:16px;height:16px"></i></button>
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-primary btn-sm" onclick="openTaskFormForSelected()">
|
||||||
|
<i data-lucide="plus"></i>新增任务
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="project-board">
|
||||||
|
<div class="project-board-body">
|
||||||
|
<div class="project-tree">
|
||||||
|
<div class="project-tree-hd">
|
||||||
|
<span>项目</span>
|
||||||
|
<button class="btn btn-ghost btn-sm rounded-full w-7 h-7 p-0" onclick="openNewProjectModal()" title="新增项目">
|
||||||
|
<i data-lucide="plus" style="width:16px;height:16px"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="project-tree-list" id="projectTreeList">
|
||||||
|
${items.map((x) => `
|
||||||
|
<div class="project-tree-node ${state.selectedProject === x.id ? 'active' : ''}"
|
||||||
|
data-id="${x.id}"
|
||||||
|
onclick="selectProject(${x.id})"
|
||||||
|
oncontextmenu="showProjectContext(event, ${x.id})">
|
||||||
|
<span class="project-tree-icon"><i data-lucide="folder"></i></span>
|
||||||
|
<span class="project-tree-name">${esc(x.project_name)}</span>
|
||||||
|
</div>
|
||||||
|
`).join("")}
|
||||||
|
${items.length === 0 ? '<div class="project-tree-empty">暂无项目</div>' : ''}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="task-feed">
|
||||||
|
${state.selectedProject ? '<div class="task-feed-body">' + renderTaskListHTML(state.selectedProject) + '</div>' : `
|
||||||
|
<div class="project-empty">
|
||||||
|
<div class="text-center">
|
||||||
|
<i data-lucide="arrow-left" style="width:32px;height:32px;margin:0 auto 12px;color:#cbd5e1"></i>
|
||||||
|
<p>请从左侧选择项目查看台账</p>
|
||||||
|
</div>
|
||||||
|
</div>`}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
document.querySelector("#projectContextMenu")?.remove();
|
||||||
|
const menu = document.createElement("div");
|
||||||
|
menu.id = "projectContextMenu";
|
||||||
|
menu.className = "project-context-menu hidden";
|
||||||
|
menu.innerHTML = `<div class="project-context-item" onclick="openProjectDrawer()"><i data-lucide="info"></i>查看项目详情</div><div class="project-context-item" onclick="renameProject()"><i data-lucide="edit-3"></i>重命名项目</div><div class="project-context-item" onclick="duplicateProject()"><i data-lucide="copy"></i>创建副本</div>`;
|
||||||
|
document.body.appendChild(menu);
|
||||||
|
document.removeEventListener("click", hideProjectContext);
|
||||||
|
document.addEventListener("click", hideProjectContext);
|
||||||
|
|
||||||
|
if (state.selectedProject) renderProjectTasks(state.selectedProject);
|
||||||
|
if (window.lucide) window.lucide.createIcons();
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterPhaseTasks(tasks, phase) {
|
||||||
|
return tasks.filter((t) => t.phase === phase);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderTaskListHTML(projectId) {
|
||||||
|
const project = state.data.operations.find((x) => x.id === projectId);
|
||||||
|
if (!project) return "";
|
||||||
|
const tasks = (state.data.tasks || []).filter((t) => t.project_id === projectId);
|
||||||
|
const filtered = tasks;
|
||||||
|
const defaultPhases = ["商务洽谈", "系统上线", "团队分工", "项目交付", "上线推广", "结项验收"];
|
||||||
|
const customPhases = [...new Set(filtered.map(t => t.phase).filter(Boolean))];
|
||||||
|
const phaseOrder = [...defaultPhases];
|
||||||
|
customPhases.forEach(p => { if (!phaseOrder.includes(p)) phaseOrder.push(p); });
|
||||||
|
const phases = phaseOrder.filter(p => filterPhaseTasks(filtered, p).length > 0);
|
||||||
|
const phaseTasks = phases.map(p => ({ phase: p, tasks: filterPhaseTasks(filtered, p) }));
|
||||||
|
|
||||||
|
return `
|
||||||
|
${phaseTasks.map(({ phase, tasks: pt }) => {
|
||||||
|
if (!pt.length) return "";
|
||||||
|
const phaseId = "phase-" + projectId + "-" + phase.replace(/\s/g, "");
|
||||||
|
return `<div class="task-section">
|
||||||
|
<div class="task-section-hd" onclick="togglePhase('${phaseId}')">
|
||||||
|
<span class="task-section-toggle" id="${phaseId}-toggle"><i data-lucide="chevron-down"></i></span>
|
||||||
|
<span class="task-section-icon"><i data-lucide="layers"></i></span>
|
||||||
|
<span class="task-section-label">${phase}</span>
|
||||||
|
<span class="task-section-n">${pt.length}</span>
|
||||||
|
</div>
|
||||||
|
<div class="task-section-list-wrap" id="${phaseId}">
|
||||||
|
<div class="task-section-list" data-phase="${phase}" ondrop="handleTaskDrop(event, ${projectId}, '${phase}')" ondragover="event.preventDefault(); event.currentTarget.classList.add('drag-over')" ondragleave="event.currentTarget.classList.remove('drag-over')">
|
||||||
|
${pt.map((t) => `<div class="task-item ${t.status === '已结束' ? 'task-done' : ''} ${t.priority === 'P0' ? 'task-p0' : t.priority === 'P1' ? 'task-p1' : ''} ${state.taskView === 'detail' ? 'task-detail' : ''}" data-id="${t.id}" draggable="true" ondragstart="handleTaskDragStart(event, ${t.id})" ondragend="event.currentTarget.classList.remove('dragging')">
|
||||||
|
<span class="task-grip"><i data-lucide="grip-vertical"></i></span>
|
||||||
|
<span class="task-status-badge status-${esc(t.status) || '未开始'}" onclick="event.stopPropagation(); cycleTaskStatus(${t.id}, ${projectId})" title="点击切换状态">${esc(t.status) || '未开始'}</span>
|
||||||
|
<span class="task-priority-badge priority-${(t.priority || 'P2').toLowerCase()}" onclick="event.stopPropagation(); cycleTaskPriority(${t.id}, ${projectId})" title="点击切换优先级">${esc(t.priority) || 'P2'}</span>
|
||||||
|
<div class="task-content" onclick="openTaskForm(${projectId}, ${t.id})">
|
||||||
|
<span class="task-title">${esc(t.task)}</span>
|
||||||
|
${state.taskView === 'detail' && t.notes ? '<span class="task-desc">' + esc(t.notes) + '</span>' : ""}
|
||||||
|
${state.taskView === 'detail' && t.blockers ? '<span class="task-blocker">\u26a0 ' + esc(t.blockers) + '</span>' : ""}
|
||||||
|
</div>
|
||||||
|
<span class="task-meta">${esc(t.owner) || ''}</span>
|
||||||
|
<span class="task-meta text-slate-400">${esc(t.due_date) || ''}</span>
|
||||||
|
</div>`).join("")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
}).join("")}
|
||||||
|
${filtered.length === 0 ? '<div class="task-empty">暂无任务,点击上方按钮创建</div>' : ''}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderProjectTasks(projectId) {
|
||||||
|
const project = state.data.operations.find((x) => x.id === projectId);
|
||||||
|
if (!project) { state.selectedProject = null; renderProjects(); return; }
|
||||||
|
const tasks = (state.data.tasks || []).filter((t) => t.project_id === projectId);
|
||||||
|
const defaultPhases = ["商务洽谈", "系统上线", "团队分工", "项目交付", "上线推广", "结项验收"];
|
||||||
|
const customPhases = [...new Set(tasks.map(t => t.phase).filter(Boolean))];
|
||||||
|
const phases = [...new Set([...defaultPhases, ...customPhases])];
|
||||||
|
|
||||||
|
const body = document.querySelector(".task-feed-body");
|
||||||
|
if (body) body.innerHTML = renderTaskListHTML(projectId);
|
||||||
|
if (window.lucide) window.lucide.createIcons();
|
||||||
|
}
|
||||||
|
window.openTaskFormForSelected = () => {
|
||||||
|
openTaskForm(state.selectedProject, null);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.openTaskForm = (projectId, taskId) => {
|
||||||
|
if (!projectId) return;
|
||||||
|
// 确保 drawer 存在
|
||||||
|
let drawer = document.querySelector(`#task-drawer-${projectId}`);
|
||||||
|
if (!drawer) {
|
||||||
|
drawer = document.createElement("div");
|
||||||
|
drawer.id = `task-drawer-${projectId}`;
|
||||||
|
drawer.className = "task-drawer";
|
||||||
|
document.body.appendChild(drawer);
|
||||||
|
}
|
||||||
|
const tasks = (state.data.tasks || []).filter((t) => t.project_id === projectId);
|
||||||
|
const defaultPhases = ["商务洽谈", "系统上线", "团队分工", "项目交付", "上线推广", "结项验收"];
|
||||||
|
const customPhases = [...new Set(tasks.map(t => t.phase).filter(Boolean))];
|
||||||
|
const phases = [...new Set([...defaultPhases, ...customPhases])];
|
||||||
|
const task = taskId ? (state.data.tasks || []).find((t) => t.id === taskId) : null;
|
||||||
|
drawer.innerHTML = `<div class="task-drawer-hd"><span class="task-drawer-title">${task ? "编辑任务" : "新增任务"}</span><div class="flex items-center gap-2">${task ? `<button type="button" class="btn btn-ghost btn-sm text-red-600 hover:bg-red-50" onclick="deleteTask(${projectId})"><i data-lucide="trash-2"></i>删除</button>` : ""}<button class="task-close" onclick="closeTaskDrawer(${projectId})"><i data-lucide="x"></i></button></div></div>
|
||||||
|
<form class="task-drawer-form" onsubmit="submitTaskForm(event, ${projectId})">
|
||||||
|
<input type="hidden" name="task_id" id="task-id-${projectId}" value="${task ? task.id : ''}">
|
||||||
|
<div class="task-field-row">
|
||||||
|
<label class="task-field"><span>任务名称</span><input name="task" required id="task-name-${projectId}" class="form-ctrl" value="${task ? esc(task.task) : ''}"></label>
|
||||||
|
<label class="task-field"><span>任务分组</span><select name="phase" id="task-phase-${projectId}" class="form-ctrl">${phases.map((p) => `<option ${task && task.phase === p ? "selected" : ""}>${p}</option>`).join("")}</select></label>
|
||||||
|
</div>
|
||||||
|
<div class="task-field-row">
|
||||||
|
<label class="task-field"><span>优先级</span><select name="priority" id="task-priority-${projectId}" class="form-ctrl"><option ${task && task.priority === 'P0' ? 'selected' : ''}>P0</option><option ${task && task.priority === 'P1' ? 'selected' : ''}>P1</option><option ${(!task || task.priority === 'P2') ? 'selected' : ''}>P2</option><option ${task && task.priority === 'P3' ? 'selected' : ''}>P3</option></select></label>
|
||||||
|
<label class="task-field"><span>状态</span><select name="status" id="task-status-${projectId}" class="form-ctrl"><option ${(!task || task.status === '未开始') ? 'selected' : ''}>未开始</option><option ${task && task.status === '进行中' ? 'selected' : ''}>进行中</option><option ${task && task.status === '已结束' ? 'selected' : ''}>已结束</option></select></label>
|
||||||
|
</div>
|
||||||
|
<div class="task-field-row">
|
||||||
|
<label class="task-field"><span>负责人</span><input name="owner" id="task-owner-${projectId}" class="form-ctrl" value="${task ? esc(task.owner) : ''}"></label>
|
||||||
|
<label class="task-field"><span>截止时间</span><input name="due_date" type="date" id="task-due-${projectId}" class="form-ctrl" value="${task ? esc(task.due_date) : ''}"></label>
|
||||||
|
</div>
|
||||||
|
<label class="task-field"><span>任务说明</span><textarea name="notes" rows="3" id="task-notes-${projectId}" class="form-ctrl">${task ? esc(task.notes) : ''}</textarea></label>
|
||||||
|
<label class="task-field"><span>卡点&备注</span><textarea name="blockers" rows="2" id="task-blockers-${projectId}" class="form-ctrl" placeholder="风险卡点、依赖项等">${task ? esc(task.blockers) : ''}</textarea></label>
|
||||||
|
<div class="flex justify-end gap-2 mt-4 pt-3 border-t border-slate-100">
|
||||||
|
<button type="button" class="btn btn-ghost btn-sm" onclick="closeTaskDrawer(${projectId})">取消</button>
|
||||||
|
<button type="submit" class="btn btn-primary btn-sm" id="task-submit-btn-${projectId}">${task ? "保存" : "确认新增"}</button>
|
||||||
|
</div>
|
||||||
|
</form>`;
|
||||||
|
drawer.classList.add("open");
|
||||||
|
if (window.lucide) window.lucide.createIcons();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.closeTaskDrawer = (projectId) => {
|
||||||
|
const drawer = document.querySelector(`#task-drawer-${projectId}`);
|
||||||
|
if (drawer) drawer.classList.remove("open");
|
||||||
|
refreshTaskList(projectId);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.refreshTaskList = (projectId) => {
|
||||||
|
const body = document.querySelector(".task-feed-body");
|
||||||
|
if (body && state.selectedProject === projectId) {
|
||||||
|
body.innerHTML = renderTaskListHTML(projectId);
|
||||||
|
if (window.lucide) window.lucide.createIcons();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.submitTaskForm = async (event, projectId) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const data = Object.fromEntries(new FormData(event.currentTarget).entries());
|
||||||
|
data.project_id = Number(projectId);
|
||||||
|
data.tenant = state.tenant;
|
||||||
|
const taskId = data.task_id;
|
||||||
|
delete data.task_id;
|
||||||
|
try {
|
||||||
|
if (taskId) {
|
||||||
|
await api(`/api/tasks/${taskId}`, { method: "PUT", body: JSON.stringify({ data }) });
|
||||||
|
const task = (state.data.tasks || []).find(t => t.id === parseInt(taskId));
|
||||||
|
if (task) Object.assign(task, data);
|
||||||
|
if (data.task) logActivity("task", taskId, "更新了任务「" + data.task + "」");
|
||||||
|
closeTaskDrawer(projectId);
|
||||||
|
} else {
|
||||||
|
const result = await api("/api/tasks", { method: "POST", body: JSON.stringify({ data }) });
|
||||||
|
if (result.id && data.task) logActivity("task", result.id, "创建了任务「" + data.task + "」");
|
||||||
|
closeTaskDrawer(projectId);
|
||||||
|
await load();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
toast("保存失败:" + error.message, "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.cycleTaskStatus = async (taskId, projectId) => {
|
||||||
|
const tasks = state.data.tasks || [];
|
||||||
|
const task = tasks.find((t) => t.id === taskId);
|
||||||
|
if (!task) return;
|
||||||
|
const statuses = ["未开始", "进行中", "已结束"];
|
||||||
|
const current = statuses.indexOf(task.status) >= 0 ? task.status : "未开始";
|
||||||
|
const newStatus = statuses[(statuses.indexOf(current) + 1) % statuses.length];
|
||||||
|
try {
|
||||||
|
await api(`/api/tasks/${taskId}`, { method: "PUT", body: JSON.stringify({ data: { status: newStatus } }) });
|
||||||
|
task.status = newStatus;
|
||||||
|
const row = document.querySelector(`.task-item[data-id="${taskId}"]`);
|
||||||
|
if (row) {
|
||||||
|
row.classList.toggle("task-done", newStatus === "已结束");
|
||||||
|
const badge = row.querySelector(".task-status-badge");
|
||||||
|
if (badge) {
|
||||||
|
badge.textContent = newStatus;
|
||||||
|
badge.className = "task-status-badge status-" + newStatus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
toast("更新失败:" + error.message, "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.cycleTaskPriority = async (taskId, projectId) => {
|
||||||
|
const tasks = state.data.tasks || [];
|
||||||
|
const task = tasks.find((t) => t.id === taskId);
|
||||||
|
if (!task) return;
|
||||||
|
const priorities = ["P0", "P1", "P2", "P3"];
|
||||||
|
const current = priorities.indexOf(task.priority) >= 0 ? task.priority : "P2";
|
||||||
|
const newPriority = priorities[(priorities.indexOf(current) + 1) % priorities.length];
|
||||||
|
try {
|
||||||
|
await api(`/api/tasks/${taskId}`, { method: "PUT", body: JSON.stringify({ data: { priority: newPriority } }) });
|
||||||
|
task.priority = newPriority;
|
||||||
|
const row = document.querySelector(`.task-item[data-id="${taskId}"]`);
|
||||||
|
if (row) {
|
||||||
|
row.classList.remove("task-p0", "task-p1");
|
||||||
|
if (newPriority === "P0") row.classList.add("task-p0");
|
||||||
|
else if (newPriority === "P1") row.classList.add("task-p1");
|
||||||
|
const badge = row.querySelector(".task-priority-badge");
|
||||||
|
if (badge) {
|
||||||
|
badge.textContent = newPriority;
|
||||||
|
badge.className = "task-priority-badge priority-" + newPriority.toLowerCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
toast("更新失败:" + error.message, "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.deleteTask = async (projectId) => {
|
||||||
|
const taskId = document.querySelector(`#task-id-${projectId}`).value;
|
||||||
|
if (!taskId) return;
|
||||||
|
if (!confirm("确认删除该任务?此操作不可撤销。")) return;
|
||||||
|
try {
|
||||||
|
const task = (state.data.tasks || []).find(t => t.id === parseInt(taskId));
|
||||||
|
const taskName = task ? task.task : "";
|
||||||
|
await api(`/api/tasks/${taskId}`, { method: "DELETE" });
|
||||||
|
if (taskName) logActivity("task", taskId, "删除了任务「" + taskName + "」");
|
||||||
|
closeTaskDrawer(projectId);
|
||||||
|
state.data.tasks = (state.data.tasks || []).filter(t => t.id !== parseInt(taskId));
|
||||||
|
const row = document.querySelector(`.task-item[data-id="${taskId}"]`);
|
||||||
|
if (row) row.remove();
|
||||||
|
} catch (error) {
|
||||||
|
toast("删除失败:" + error.message, "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 拖拽排序
|
||||||
|
let dragTaskId = null;
|
||||||
|
window.handleTaskDragStart = (event, taskId) => {
|
||||||
|
dragTaskId = taskId;
|
||||||
|
event.currentTarget.classList.add("dragging");
|
||||||
|
event.dataTransfer.effectAllowed = "move";
|
||||||
|
};
|
||||||
|
|
||||||
|
window.handleTaskDrop = async (event, projectId, phase) => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.currentTarget.classList.remove("drag-over");
|
||||||
|
const target = event.currentTarget;
|
||||||
|
if (!dragTaskId) return;
|
||||||
|
const dragged = document.querySelector(`.task-item[data-id="${dragTaskId}"]`);
|
||||||
|
if (!dragged) return;
|
||||||
|
const afterElement = getDragAfterElement(target, event.clientY);
|
||||||
|
if (afterElement) {
|
||||||
|
target.insertBefore(dragged, afterElement);
|
||||||
|
} else {
|
||||||
|
target.appendChild(dragged);
|
||||||
|
}
|
||||||
|
dragged.classList.remove("dragging");
|
||||||
|
const rows = [...target.querySelectorAll(".task-item")];
|
||||||
|
const updates = rows.map((row, i) => ({ id: parseInt(row.dataset.id), sort_order: i }));
|
||||||
|
try {
|
||||||
|
await api(`/api/tasks/batch-sort`, { method: "POST", body: JSON.stringify({ items: updates }) });
|
||||||
|
} catch (e) { /* non-critical */ }
|
||||||
|
dragTaskId = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
function getDragAfterElement(container, y) {
|
||||||
|
const elements = [...container.querySelectorAll(".task-item:not(.dragging)")];
|
||||||
|
return elements.reduce((closest, child) => {
|
||||||
|
const box = child.getBoundingClientRect();
|
||||||
|
const offset = y - box.top - box.height / 2;
|
||||||
|
if (offset < 0 && offset > closest.offset) {
|
||||||
|
return { offset: offset, element: child };
|
||||||
|
} else {
|
||||||
|
return closest;
|
||||||
|
}
|
||||||
|
}, { offset: Number.NEGATIVE_INFINITY }).element;
|
||||||
|
}
|
||||||
335
static/modules/proposals.js
Normal file
335
static/modules/proposals.js
Normal file
@@ -0,0 +1,335 @@
|
|||||||
|
// proposals.js — 业务方案 + 文件管理
|
||||||
|
|
||||||
|
// 标准资料库固定 7 项
|
||||||
|
const STANDARD_PROPOSALS = [
|
||||||
|
"业务方案-医生版",
|
||||||
|
"业务方案-药企版",
|
||||||
|
"服务清单与报价单",
|
||||||
|
"患者服务清单",
|
||||||
|
"医生项目清单与劳务报价",
|
||||||
|
"项目执行 SOP",
|
||||||
|
"财务结算流程",
|
||||||
|
];
|
||||||
|
|
||||||
|
// 确保标准资料库已初始化(首次进入时创建)
|
||||||
|
async function ensureStandardProposals() {
|
||||||
|
const existing = (state.data.proposals || []).filter(p => p.proposal_type === "标准资料");
|
||||||
|
const missing = STANDARD_PROPOSALS.filter(name => !existing.find(p => p.customer_or_project_name === name));
|
||||||
|
if (missing.length === 0) return;
|
||||||
|
for (const name of missing) {
|
||||||
|
try {
|
||||||
|
await api("/api/proposals", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ data: {
|
||||||
|
customer_or_project_name: name,
|
||||||
|
proposal_type: "标准资料",
|
||||||
|
notes: "",
|
||||||
|
version: "v1.0",
|
||||||
|
status: "已归档",
|
||||||
|
created_date: new Date().toISOString().slice(0, 10),
|
||||||
|
tenant: state.tenant,
|
||||||
|
}}),
|
||||||
|
});
|
||||||
|
} catch (e) { /* ignore */ }
|
||||||
|
}
|
||||||
|
await load();
|
||||||
|
}
|
||||||
|
|
||||||
|
window.switchProposalTab = (tab) => {
|
||||||
|
state.proposalTab = tab;
|
||||||
|
renderProposals();
|
||||||
|
};
|
||||||
|
|
||||||
|
function renderProposals() {
|
||||||
|
const items = state.data.proposals || [];
|
||||||
|
const standardItems = items.filter(p => p.proposal_type === "标准资料");
|
||||||
|
const otherItems = items.filter(p => p.proposal_type !== "标准资料");
|
||||||
|
const isStandard = state.proposalTab === "standard";
|
||||||
|
|
||||||
|
document.querySelector("#proposals").innerHTML = `<div class="grid gap-4">
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<div class="flex gap-1" id="proposalTabToggle">
|
||||||
|
<button class="btn btn-sm ${isStandard ? 'btn-primary' : 'btn-ghost'}" onclick="switchProposalTab('standard')">标准资料库</button>
|
||||||
|
<button class="btn btn-sm ${!isStandard ? 'btn-primary' : 'btn-ghost'}" onclick="switchProposalTab('other')">其他资料</button>
|
||||||
|
</div>
|
||||||
|
${!isStandard ? `<button class="btn btn-primary btn-sm" onclick="openProposalModal()"><i data-lucide="plus"></i>新增方案</button>` : ''}
|
||||||
|
</div>
|
||||||
|
${isStandard ? `<div class="flex items-start gap-2 rounded-lg bg-blue-50 border border-blue-100 px-4 py-3 text-sm text-blue-700"><i data-lucide="info" style="width:16px;height:16px;flex-shrink:0;margin-top:1px"></i><span>这是每一条 OPC 线,必须要梳理清楚的 7 份资料,项目不可以删除,只可以更新附件,请大家将最新的材料上传</span></div>` : `<div class="flex items-start gap-2 rounded-lg bg-emerald-50 border border-emerald-100 px-4 py-3 text-sm text-emerald-700"><i data-lucide="lightbulb" style="width:16px;height:16px;flex-shrink:0;margin-top:1px"></i><span>在这里新建,并且上传您希望与团队其他成员共享的资料</span></div>`}
|
||||||
|
${isStandard ? renderStandardTable(standardItems) : renderOtherTable(otherItems)}
|
||||||
|
</div>
|
||||||
|
<div id="proposalModal" class="hidden fixed inset-0 z-50 flex items-center justify-center bg-black/40" onclick="closeProposalModal()">
|
||||||
|
<div class="bg-white rounded-2xl shadow-2xl w-full max-w-md mx-4" onclick="event.stopPropagation()">
|
||||||
|
<div class="flex items-center justify-between px-6 py-4 border-b border-slate-100">
|
||||||
|
<h3 class="text-lg font-semibold text-slate-800">新增方案</h3>
|
||||||
|
<button class="btn btn-ghost btn-sm rounded-full w-8 h-8 p-0" onclick="closeProposalModal()"><i data-lucide="x"></i></button>
|
||||||
|
</div>
|
||||||
|
<form onsubmit="submitProposal(event)" class="p-6 grid gap-4">
|
||||||
|
<label class="block"><span class="text-xs font-medium text-slate-500">方案名称</span><input name="customer_or_project_name" required class="form-ctrl mt-1"></label>
|
||||||
|
<label class="block"><span class="text-xs font-medium text-slate-500">方案类型</span><select name="proposal_type" class="form-ctrl mt-1">${["业务方案","报价与成本","SOP","PRD","设计稿","财务流程","其他"].map(t => `<option>${t}</option>`).join("")}</select></label>
|
||||||
|
<label class="block"><span class="text-xs font-medium text-slate-500">方案说明</span><textarea name="notes" rows="3" class="form-ctrl mt-1"></textarea></label>
|
||||||
|
<div class="flex justify-end gap-3 pt-3 border-t border-slate-100">
|
||||||
|
<button type="button" class="btn btn-ghost btn-sm" onclick="closeProposalModal()">取消</button>
|
||||||
|
<button type="submit" class="btn btn-primary btn-sm">创建</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
if (window.lucide) window.lucide.createIcons();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 标准资料库:按固定顺序排序,点击行打开附件抽屉(不含删除按钮)
|
||||||
|
function renderStandardTable(items) {
|
||||||
|
const sorted = STANDARD_PROPOSALS.map(name => items.find(p => p.customer_or_project_name === name)).filter(Boolean);
|
||||||
|
const rows = sorted.map((p) => {
|
||||||
|
const fileCount = (p.files || []).length;
|
||||||
|
return `<tr class="border-b border-slate-100 hover:bg-slate-50 cursor-pointer" onclick="openStandardProposalDrawer(${p.id})">
|
||||||
|
<td class="p-3 text-sm font-medium text-slate-800">${esc(p.customer_or_project_name)}</td>
|
||||||
|
<td class="p-3 text-sm text-slate-500 text-center">${fileCount} 个文件</td>
|
||||||
|
<td class="p-3 text-sm text-slate-500 text-center">${(p.created_at || "").slice(0,10) || "—"}</td>
|
||||||
|
</tr>`;
|
||||||
|
}).join("");
|
||||||
|
return `<div class="bg-white rounded-lg border border-slate-200 overflow-hidden">
|
||||||
|
<div class="overflow-x-auto">
|
||||||
|
<table class="w-full text-sm">
|
||||||
|
<thead><tr class="bg-slate-50 border-b border-slate-200">
|
||||||
|
<th class="p-3 text-left font-semibold text-slate-600">资料名称</th>
|
||||||
|
<th class="p-3 text-center font-semibold text-slate-600">附件</th>
|
||||||
|
<th class="p-3 text-center font-semibold text-slate-600">创建日期</th>
|
||||||
|
</tr></thead>
|
||||||
|
<tbody>${rows}</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 其他资料:原有表格 + 行点击打开抽屉
|
||||||
|
function renderOtherTable(items) {
|
||||||
|
const rows = items.map((p) => [
|
||||||
|
`<strong>${esc(p.customer_or_project_name)}</strong>`,
|
||||||
|
p.proposal_type || "业务方案",
|
||||||
|
text(p.notes || ""),
|
||||||
|
(p.created_at || "").slice(0, 10) || "\u2014",
|
||||||
|
]);
|
||||||
|
return renderTable(["方案名称", "方案类型", "方案说明", "日期"], rows, items.map((p) => ({ resource: "proposals", id: p.id })));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 标准资料专用抽屉(附件管理 + 评论,不能编辑字段、不能删除项目)
|
||||||
|
window.openStandardProposalDrawer = (id) => {
|
||||||
|
const item = (state.data.proposals || []).find(p => p.id === id);
|
||||||
|
if (!item) return;
|
||||||
|
const drawer = document.querySelector("#drawer");
|
||||||
|
const title = esc(item.customer_or_project_name);
|
||||||
|
const followupTarget = "proposal";
|
||||||
|
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">标准资料</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>
|
||||||
|
${fileGroup("proposal", item.id, "", "附件", item.files || [])}
|
||||||
|
</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>${esc(f.follower)} · ${esc(f.follow_up_method)}</span><span>${esc(f.followed_at)}</span></div><div class="mt-1 leading-5 text-slate-800 rich-content" data-html="${encodeURIComponent(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}, 'proposals', ${item.id})" title="删除评论"><i data-lucide="trash-2"></i></button></div>`).join("")}</div>
|
||||||
|
<form class="comment-box mt-3" onsubmit="submitStandardComment(event, ${item.id})">
|
||||||
|
<div class="squire-toolbar">
|
||||||
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('bold')" title="加粗"><i data-lucide="bold"></i></button>
|
||||||
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('italic')" title="斜体"><i data-lucide="italic"></i></button>
|
||||||
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('underline')" title="下划线"><i data-lucide="underline"></i></button>
|
||||||
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('strikethrough')" title="删除线"><i data-lucide="strikethrough"></i></button>
|
||||||
|
<span class="squire-sep"></span>
|
||||||
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('makeUnorderedList')" title="无序列表"><i data-lucide="list"></i></button>
|
||||||
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('makeOrderedList')" title="有序列表"><i data-lucide="list-ordered"></i></button>
|
||||||
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('blockquote')" title="引用"><i data-lucide="quote"></i></button>
|
||||||
|
<span class="squire-sep"></span>
|
||||||
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('undo')" title="撤销"><i data-lucide="undo"></i></button>
|
||||||
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('redo')" title="重做"><i data-lucide="redo"></i></button>
|
||||||
|
</div>
|
||||||
|
<div class="squire-editor" id="squire_standard_${item.id}" placeholder="添加评论"></div>
|
||||||
|
<div class="comment-toolbar">
|
||||||
|
<span class="comment-hint">支持富文本编辑</span>
|
||||||
|
<button class="btn btn-primary btn-sm comment-submit" type="submit">评论</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</section>` : ""}
|
||||||
|
<div id="uploadTaskList"></div>
|
||||||
|
</div></div>`;
|
||||||
|
drawer.classList.add("open");
|
||||||
|
if (window.lucide) window.lucide.createIcons();
|
||||||
|
renderUploadTasks();
|
||||||
|
// 渲染富文本评论内容
|
||||||
|
drawer.querySelectorAll(".rich-content").forEach((el) => {
|
||||||
|
const html = el.dataset.html;
|
||||||
|
if (html) el.innerHTML = decodeURIComponent(html);
|
||||||
|
});
|
||||||
|
// 初始化 Squire 编辑器
|
||||||
|
const squireDiv = drawer.querySelector(".squire-editor");
|
||||||
|
if (squireDiv && window.Squire) {
|
||||||
|
const sid = squireDiv.id;
|
||||||
|
if (window.squireInstances[sid]) window.squireInstances[sid].destroy();
|
||||||
|
const sq = new Squire(squireDiv, { blockTag: "P" });
|
||||||
|
window.squireInstances[sid] = sq;
|
||||||
|
squireDiv.addEventListener("focus", () => squireDiv.classList.add("focused"));
|
||||||
|
squireDiv.addEventListener("blur", () => {
|
||||||
|
if (!squireDiv.textContent.trim()) squireDiv.classList.remove("focused");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 标准资料评论提交(提交后重新打开标准资料抽屉)
|
||||||
|
window.submitStandardComment = async (event, targetId) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = event.currentTarget;
|
||||||
|
const editorDiv = form.querySelector(".squire-editor");
|
||||||
|
const sq = window.squireInstances[editorDiv.id];
|
||||||
|
const content = sq ? sq.getHTML().trim() : "";
|
||||||
|
if (!content || content === "<div><br></div>" || content === "<p><br></p>") return;
|
||||||
|
const button = form.querySelector(".comment-submit");
|
||||||
|
button.disabled = true;
|
||||||
|
button.textContent = "发送中…";
|
||||||
|
await api(`/api/followups/proposal/${targetId}`, { method: "POST", body: JSON.stringify({ data: { content } }) });
|
||||||
|
await load();
|
||||||
|
openStandardProposalDrawer(targetId);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.openProposalModal = () => {
|
||||||
|
document.querySelector("#proposalModal").classList.remove("hidden");
|
||||||
|
};
|
||||||
|
window.closeProposalModal = () => {
|
||||||
|
document.querySelector("#proposalModal").classList.add("hidden");
|
||||||
|
};
|
||||||
|
window.submitProposal = async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = event.currentTarget;
|
||||||
|
const data = Object.fromEntries(new FormData(form).entries());
|
||||||
|
data.tenant = state.tenant;
|
||||||
|
if (!data.version) data.version = "v1.0";
|
||||||
|
if (!data.description) data.description = "";
|
||||||
|
if (!data.status) data.status = "草稿";
|
||||||
|
if (!data.created_date) data.created_date = new Date().toISOString().slice(0, 10);
|
||||||
|
try {
|
||||||
|
const result = await api("/api/proposals", { method: "POST", body: JSON.stringify({ data }) });
|
||||||
|
if (result.id && data.customer_or_project_name) logActivity("proposal", result.id, "创建了方案「" + data.customer_or_project_name + "」");
|
||||||
|
form.reset();
|
||||||
|
closeProposalModal();
|
||||||
|
await load();
|
||||||
|
} catch (error) {
|
||||||
|
toast("保存失败:" + error.message, "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 文件管理
|
||||||
|
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">${esc(file.file_name)}</p><div class="mt-0.5 flex gap-3"><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" });
|
||||||
|
// 优先在当前打开的抽屉中查找并刷新
|
||||||
|
const drawer = document.querySelector("#drawer.open");
|
||||||
|
if (drawer) {
|
||||||
|
const uploadList = drawer.querySelector("#uploadTaskList");
|
||||||
|
// 通过 file.id 反查所属 item
|
||||||
|
for (const listKey of ["proposals", "operations", "sales", "products"]) {
|
||||||
|
if (!state.data[listKey]) continue;
|
||||||
|
for (const item of state.data[listKey]) {
|
||||||
|
if (!item.files) continue;
|
||||||
|
const idx = item.files.findIndex(f => f.id === fileId);
|
||||||
|
if (idx !== -1) {
|
||||||
|
item.files.splice(idx, 1);
|
||||||
|
// 判断是标准资料还是普通抽屉
|
||||||
|
if (item.proposal_type === "标准资料") {
|
||||||
|
openStandardProposalDrawer(item.id);
|
||||||
|
} else {
|
||||||
|
openDrawer(listKey, item.id);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.uploadFile = (event, module, ownerId, version, category) => {
|
||||||
|
const file = event.target.files[0];
|
||||||
|
if (!file) return;
|
||||||
|
const taskId = Date.now();
|
||||||
|
const task = { id: taskId, name: file.name, progress: 0, xhr: null };
|
||||||
|
state.uploadTasks.push(task);
|
||||||
|
renderUploadTasks();
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
const xhr = new XMLHttpRequest();
|
||||||
|
task.xhr = xhr;
|
||||||
|
xhr.upload.addEventListener("progress", (e) => {
|
||||||
|
if (e.lengthComputable) {
|
||||||
|
task.progress = Math.round((e.loaded / e.total) * 100);
|
||||||
|
renderUploadTasks();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
xhr.addEventListener("load", () => {
|
||||||
|
if (xhr.status === 200) {
|
||||||
|
task.progress = 100;
|
||||||
|
renderUploadTasks();
|
||||||
|
const result = JSON.parse(xhr.responseText);
|
||||||
|
const resourceMap = { proposal: "proposals", operation: "operations", sales: "sales", product: "products" };
|
||||||
|
const listKey = resourceMap[module];
|
||||||
|
if (listKey && state.data[listKey]) {
|
||||||
|
const item = state.data[listKey].find(x => x.id === ownerId);
|
||||||
|
if (item) {
|
||||||
|
if (!item.files) item.files = [];
|
||||||
|
item.files.push({ id: result.id, file_name: file.name, file_category: category });
|
||||||
|
// 刷新当前抽屉
|
||||||
|
if (item.proposal_type === "标准资料") {
|
||||||
|
openStandardProposalDrawer(item.id);
|
||||||
|
} else if (document.querySelector("#drawer.open")) {
|
||||||
|
openDrawer(listKey, item.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setTimeout(() => {
|
||||||
|
state.uploadTasks = state.uploadTasks.filter(t => t.id !== taskId);
|
||||||
|
renderUploadTasks();
|
||||||
|
}, 1500);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
xhr.addEventListener("error", () => {
|
||||||
|
toast("上传失败:" + file.name, "error");
|
||||||
|
state.uploadTasks = state.uploadTasks.filter(t => t.id !== taskId);
|
||||||
|
renderUploadTasks();
|
||||||
|
});
|
||||||
|
xhr.open("POST", "/api/files/upload");
|
||||||
|
xhr.send(form);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.cancelUpload = (taskId) => {
|
||||||
|
const task = state.uploadTasks.find(t => t.id === taskId);
|
||||||
|
if (task && task.xhr) task.xhr.abort();
|
||||||
|
state.uploadTasks = state.uploadTasks.filter(t => t.id !== taskId);
|
||||||
|
renderUploadTasks();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.renderUploadTasks = () => {
|
||||||
|
const el = document.querySelector("#uploadTaskList");
|
||||||
|
if (!el) return;
|
||||||
|
el.innerHTML = state.uploadTasks.map(t => `
|
||||||
|
<div class="upload-task">
|
||||||
|
<span class="upload-task-name">${esc(t.name)}</span>
|
||||||
|
<div class="upload-task-bar"><div class="upload-task-fill" style="width:${t.progress}%"></div></div>
|
||||||
|
<span class="upload-task-pct">${t.progress}%</span>
|
||||||
|
<button class="upload-task-cancel" onclick="cancelUpload(${t.id})"><i data-lucide="x"></i></button>
|
||||||
|
</div>
|
||||||
|
`).join("");
|
||||||
|
if (window.lucide) window.lucide.createIcons();
|
||||||
|
};
|
||||||
188
static/modules/utils.js
Normal file
188
static/modules/utils.js
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
// utils.js — 全局工具函数与共享状态
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
active: "home",
|
||||||
|
data: null,
|
||||||
|
tenant: "科普·无界",
|
||||||
|
opFilter: "all",
|
||||||
|
finFilter: "已签约",
|
||||||
|
selectedProject: null,
|
||||||
|
taskQuery: "",
|
||||||
|
taskView: localStorage.getItem("opc-task-view") || "detail",
|
||||||
|
finView: localStorage.getItem("opc-fin-view") || "rev",
|
||||||
|
proposalTab: "standard",
|
||||||
|
chart: null,
|
||||||
|
chart2: null,
|
||||||
|
chart3: null,
|
||||||
|
productPlatform: "all",
|
||||||
|
uploadTasks: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
const money = (value) => `${Number(value || 0).toLocaleString("zh-CN")} 元`;
|
||||||
|
const text = (value) => value === undefined || value === null || value === "" ? "—" : esc(value);
|
||||||
|
|
||||||
|
function escapeHtml(str) { return String(str || "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """); }
|
||||||
|
const html = escapeHtml;
|
||||||
|
const esc = escapeHtml;
|
||||||
|
|
||||||
|
// Toast 通知
|
||||||
|
function toast(message, type = "info", duration = 3000) {
|
||||||
|
let container = document.querySelector(".toast-container");
|
||||||
|
if (!container) {
|
||||||
|
container = document.createElement("div");
|
||||||
|
container.className = "toast-container";
|
||||||
|
document.body.appendChild(container);
|
||||||
|
}
|
||||||
|
const el = document.createElement("div");
|
||||||
|
el.className = `toast toast-${type}`;
|
||||||
|
const icon = type === "success" ? "check-circle" : type === "error" ? "alert-circle" : "info";
|
||||||
|
el.innerHTML = `<i data-lucide="${icon}" style="width:16px;height:16px;flex-shrink:0"></i><span>${esc(message)}</span>`;
|
||||||
|
container.appendChild(el);
|
||||||
|
if (window.lucide) window.lucide.createIcons();
|
||||||
|
setTimeout(() => {
|
||||||
|
el.classList.add("fade-out");
|
||||||
|
setTimeout(() => el.remove(), 250);
|
||||||
|
}, duration);
|
||||||
|
}
|
||||||
|
window.toast = toast;
|
||||||
|
|
||||||
|
function monthOptions(selected = '') {
|
||||||
|
const now = new Date();
|
||||||
|
const startYear = now.getFullYear() - 1;
|
||||||
|
const endYear = now.getFullYear() + 1;
|
||||||
|
let options = selected ? '' : '<option value="">选择月份</option>';
|
||||||
|
for (let y = startYear; y <= endYear; y++) {
|
||||||
|
for (const m of ["01","02","03","04","05","06","07","08","09","10","11","12"]) {
|
||||||
|
const val = y + "-" + m;
|
||||||
|
const sel = val === selected ? " selected" : "";
|
||||||
|
options += `<option value="${val}"${sel}>${val}</option>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function logActivity(targetType, targetId, content) {
|
||||||
|
try {
|
||||||
|
await api(`/api/followups/${targetType}/${targetId}`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ data: { content, tenant: state.tenant } }),
|
||||||
|
});
|
||||||
|
} catch (e) { /* non-critical */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
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?tenant=${encodeURIComponent(state.tenant)}`);
|
||||||
|
// 首次加载时确保标准资料库 7 项已初始化
|
||||||
|
if (typeof ensureStandardProposals === "function") {
|
||||||
|
const existing = (state.data.proposals || []).filter(p => p.proposal_type === "标准资料");
|
||||||
|
const missingCount = 7 - existing.length;
|
||||||
|
if (missingCount > 0) {
|
||||||
|
await ensureStandardProposals();
|
||||||
|
return; // ensureStandardProposals 内部会再次 render
|
||||||
|
}
|
||||||
|
}
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
function switchTab(tab) {
|
||||||
|
state.active = tab;
|
||||||
|
localStorage.setItem("opc-active-tab", 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();
|
||||||
|
renderProjects();
|
||||||
|
renderProposals();
|
||||||
|
renderProducts();
|
||||||
|
renderFinance();
|
||||||
|
if (window.lucide) window.lucide.createIcons();
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderActive() {
|
||||||
|
if (!state.data) return;
|
||||||
|
const tab = state.active;
|
||||||
|
if (tab === "home") renderHome();
|
||||||
|
else if (tab === "projects") renderProjects();
|
||||||
|
else if (tab === "proposals") renderProposals();
|
||||||
|
else if (tab === "products") renderProducts();
|
||||||
|
else if (tab === "finance") renderFinance();
|
||||||
|
if (window.lucide) window.lucide.createIcons();
|
||||||
|
}
|
||||||
|
|
||||||
|
window.setTaskView = (view) => {
|
||||||
|
state.taskView = view;
|
||||||
|
localStorage.setItem("opc-task-view", view);
|
||||||
|
// 更新按钮选中状态
|
||||||
|
const toggle = document.querySelector("#taskViewToggle");
|
||||||
|
if (toggle) {
|
||||||
|
toggle.querySelectorAll("button").forEach((btn, i) => {
|
||||||
|
const isCompact = i === 0;
|
||||||
|
btn.className = `btn btn-sm ${(isCompact ? view === 'compact' : view !== 'compact') ? 'btn-primary' : 'btn-ghost'} p-1.5`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (state.selectedProject) {
|
||||||
|
const body = document.querySelector(".task-feed-body");
|
||||||
|
if (body) body.innerHTML = renderTaskListHTML(state.selectedProject);
|
||||||
|
if (window.lucide) window.lucide.createIcons();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.switchTab = switchTab;
|
||||||
|
|
||||||
|
window.setFinView = (view) => {
|
||||||
|
state.finView = view;
|
||||||
|
localStorage.setItem("opc-fin-view", view);
|
||||||
|
renderFinance();
|
||||||
|
};
|
||||||
|
window.switchTenant = (tenant) => {
|
||||||
|
state.tenant = tenant;
|
||||||
|
state.selectedProject = null;
|
||||||
|
localStorage.setItem("opc-active-tenant", tenant);
|
||||||
|
document.querySelector("#workspaceTitle").textContent = tenant.replace("·无界", "") + " OPC 工作台";
|
||||||
|
document.querySelectorAll(".workspace-nav-item").forEach((el) => el.classList.toggle("active", el.dataset.tenant === tenant));
|
||||||
|
load();
|
||||||
|
};
|
||||||
|
window.doLogout = async () => {
|
||||||
|
await api("/api/auth/logout", { method: "POST" });
|
||||||
|
location.href = "/login";
|
||||||
|
};
|
||||||
@@ -246,6 +246,7 @@ body {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
|
border-left: 1px solid #edf2f7;
|
||||||
}
|
}
|
||||||
|
|
||||||
.task-feed-hd {
|
.task-feed-hd {
|
||||||
@@ -264,7 +265,9 @@ body {
|
|||||||
|
|
||||||
.task-section {
|
.task-section {
|
||||||
border-bottom: 1px solid #edf2f7;
|
border-bottom: 1px solid #edf2f7;
|
||||||
|
border-top: 1px solid #edf2f7;
|
||||||
}
|
}
|
||||||
|
.task-section:first-child { border-top: none; }
|
||||||
|
|
||||||
.task-section-hd {
|
.task-section-hd {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -318,10 +321,13 @@ body {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
|
height: 60px;
|
||||||
padding: 9px 20px;
|
padding: 9px 20px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: background 0.1s;
|
transition: background 0.1s;
|
||||||
|
border-bottom: 1px solid #f1f5f9;
|
||||||
}
|
}
|
||||||
|
.task-item:last-child { border-bottom: none; }
|
||||||
|
|
||||||
.task-item:hover {
|
.task-item:hover {
|
||||||
background: #f9fafb;
|
background: #f9fafb;
|
||||||
@@ -349,12 +355,16 @@ body {
|
|||||||
.status-已结束 { background: #dcfce7; color: #166534; }
|
.status-已结束 { background: #dcfce7; color: #166534; }
|
||||||
/* 产品版本状态 */
|
/* 产品版本状态 */
|
||||||
.status-规划中 { background: #f1f5f9; color: #64748b; }
|
.status-规划中 { background: #f1f5f9; color: #64748b; }
|
||||||
.status-设计中 { background: #ede9fe; color: #7c3aed; }
|
|
||||||
.status-开发中 { background: #dbeafe; color: #1d4ed8; }
|
.status-开发中 { background: #dbeafe; color: #1d4ed8; }
|
||||||
.status-测试中 { background: #fef3c7; color: #92400e; }
|
.status-测试中 { background: #fef3c7; color: #92400e; }
|
||||||
.status-已上线 { background: #dcfce7; color: #166534; }
|
.status-已上线 { background: #dcfce7; color: #166534; }
|
||||||
.status-已延期 { background: #fee2e2; color: #991b1b; }
|
|
||||||
.status-已取消 { background: #f1f5f9; color: #94a3b8; }
|
.status-已取消 { background: #f1f5f9; color: #94a3b8; }
|
||||||
|
.status-badge {
|
||||||
|
flex-shrink: 0; display: inline-flex; align-items: center;
|
||||||
|
font-size: 12px; font-weight: 500; padding: 2px 10px;
|
||||||
|
border-radius: 10px; cursor: pointer; white-space: nowrap;
|
||||||
|
transition: background 0.15s;
|
||||||
|
}
|
||||||
|
|
||||||
/* 优先级底色 */
|
/* 优先级底色 */
|
||||||
.task-p0 { background: #fef2f2; }
|
.task-p0 { background: #fef2f2; }
|
||||||
@@ -401,12 +411,14 @@ body {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 1px;
|
gap: 1px;
|
||||||
}
|
}
|
||||||
|
.task-item.task-detail .task-content { flex-direction: row; align-items: center; gap: 8px; }
|
||||||
|
|
||||||
.task-feed .task-title {
|
.task-feed .task-title {
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
color: #1f2937;
|
color: #1f2937;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
.task-item.task-detail .task-title { font-weight: 500; white-space: nowrap; flex-shrink: 0; }
|
||||||
|
|
||||||
.task-desc {
|
.task-desc {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
@@ -431,6 +443,16 @@ body {
|
|||||||
color: #ef4444;
|
color: #ef4444;
|
||||||
margin-top: 2px;
|
margin-top: 2px;
|
||||||
}
|
}
|
||||||
|
.task-item.task-detail .task-blocker {
|
||||||
|
display: inline;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
max-width: 240px;
|
||||||
|
margin-top: 0;
|
||||||
|
flex-shrink: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.task-empty {
|
.task-empty {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -590,17 +612,69 @@ body {
|
|||||||
.btn-ghost { background: white; border: 1px solid #e2e8f0; color: #334155; }
|
.btn-ghost { background: white; border: 1px solid #e2e8f0; color: #334155; }
|
||||||
.btn-ghost:hover { background: #f8fafc; }
|
.btn-ghost:hover { background: #f8fafc; }
|
||||||
|
|
||||||
|
/* ===== 表单控件统一标准 ===== */
|
||||||
input,
|
input,
|
||||||
select,
|
select,
|
||||||
textarea {
|
textarea {
|
||||||
border: 1px solid #cbd5e1;
|
border: 1px solid #e2e8f0;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
min-height: 38px;
|
padding: 8px 12px;
|
||||||
padding: 8px 10px;
|
font-size: 13px;
|
||||||
|
color: #1e293b;
|
||||||
|
background: #fff;
|
||||||
|
outline: none;
|
||||||
|
transition: border-color 0.15s, box-shadow 0.15s;
|
||||||
|
height: 38px;
|
||||||
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
select {
|
||||||
|
appearance: none;
|
||||||
|
-webkit-appearance: none;
|
||||||
|
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: right 10px center;
|
||||||
|
padding-right: 32px;
|
||||||
|
}
|
||||||
|
input:focus,
|
||||||
|
select:focus,
|
||||||
|
textarea:focus {
|
||||||
|
border-color: #2563eb;
|
||||||
|
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
|
||||||
|
}
|
||||||
|
input::placeholder,
|
||||||
|
textarea::placeholder { color: #cbd5e1; }
|
||||||
|
input:disabled,
|
||||||
|
select:disabled,
|
||||||
|
textarea:disabled { background: #f8fafc; cursor: not-allowed; }
|
||||||
|
|
||||||
textarea {
|
textarea { min-height: 80px; height: auto; resize: vertical; }
|
||||||
min-height: 96px;
|
|
||||||
|
/* 标准控件类 */
|
||||||
|
.form-ctrl {
|
||||||
|
display: block;
|
||||||
|
height: 38px;
|
||||||
|
width: 100%;
|
||||||
|
border: 1px solid #e2e8f0;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 8px 12px;
|
||||||
|
font-size: 13px;
|
||||||
|
color: #1e293b;
|
||||||
|
background: #fff;
|
||||||
|
outline: none;
|
||||||
|
transition: border-color 0.15s, box-shadow 0.15s;
|
||||||
|
}
|
||||||
|
.form-ctrl:focus {
|
||||||
|
border-color: #2563eb;
|
||||||
|
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
|
||||||
|
}
|
||||||
|
.form-ctrl::placeholder { color: #cbd5e1; }
|
||||||
|
.form-ctrl:disabled { background: #f8fafc; cursor: not-allowed; }
|
||||||
|
|
||||||
|
/* 紧凑变体 */
|
||||||
|
.form-ctrl-sm {
|
||||||
|
padding: 5px 10px;
|
||||||
|
font-size: 12px;
|
||||||
|
height: 32px;
|
||||||
}
|
}
|
||||||
|
|
||||||
table {
|
table {
|
||||||
@@ -702,35 +776,6 @@ td {
|
|||||||
min-width: 0;
|
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 {
|
.activity-item {
|
||||||
background: #f8fafc;
|
background: #f8fafc;
|
||||||
border: 1px solid #e2e8f0;
|
border: 1px solid #e2e8f0;
|
||||||
@@ -758,23 +803,6 @@ td {
|
|||||||
width: 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 {
|
.clickable-row {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: background 0.15s;
|
transition: background 0.15s;
|
||||||
@@ -1063,13 +1091,9 @@ td {
|
|||||||
background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px;
|
background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px;
|
||||||
padding: 14px; margin-bottom: 16px;
|
padding: 14px; margin-bottom: 16px;
|
||||||
}
|
}
|
||||||
|
.task-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 4px; }
|
||||||
.task-field { display: flex; flex-direction: column; gap: 4px; }
|
.task-field { display: flex; flex-direction: column; gap: 4px; }
|
||||||
.task-field span { color: #64748b; font-size: 12px; }
|
.task-field span { color: #64748b; font-size: 12px; font-weight: 500; }
|
||||||
.task-field input, .task-field select, .task-field textarea {
|
|
||||||
background: #fff; border: 1px solid #e2e8f0; border-radius: 6px;
|
|
||||||
color: #1e293b; font-size: 13px; padding: 6px 10px; outline: none;
|
|
||||||
}
|
|
||||||
.task-field input:focus, .task-field select:focus, .task-field textarea:focus { border-color: #2563eb; }
|
|
||||||
.col-span-2 { grid-column: span 2; }
|
.col-span-2 { grid-column: span 2; }
|
||||||
.task-group-add {
|
.task-group-add {
|
||||||
display: block; width: 100%; padding: 10px; text-align: center;
|
display: block; width: 100%; padding: 10px; text-align: center;
|
||||||
@@ -1077,3 +1101,65 @@ td {
|
|||||||
border-top: 1px solid #24272d; cursor: pointer;
|
border-top: 1px solid #24272d; cursor: pointer;
|
||||||
}
|
}
|
||||||
.task-group-add:hover { color: #e4e5e7; background: #24272d; }
|
.task-group-add:hover { color: #e4e5e7; background: #24272d; }
|
||||||
|
|
||||||
|
/* Feature list(产品版本核心功能编号列表) */
|
||||||
|
.feature-item {
|
||||||
|
display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
|
||||||
|
}
|
||||||
|
.feature-num {
|
||||||
|
color: #94a3b8; font-size: 13px; font-weight: 500; min-width: 22px; flex-shrink: 0;
|
||||||
|
}
|
||||||
|
.feature-item .form-ctrl { flex: 1; padding: 5px 10px; }
|
||||||
|
.feature-del {
|
||||||
|
flex-shrink: 0; display: flex; align-items: center; justify-content: center;
|
||||||
|
width: 22px; height: 22px; border-radius: 4px; border: none; background: none;
|
||||||
|
color: #94a3b8; cursor: pointer; transition: color 0.15s;
|
||||||
|
}
|
||||||
|
.feature-del:hover { color: #ef4444; background: #fef2f2; }
|
||||||
|
|
||||||
|
/* Toast 通知 */
|
||||||
|
.toast-container {
|
||||||
|
position: fixed; top: 16px; right: 16px; z-index: 9999;
|
||||||
|
display: flex; flex-direction: column; gap: 8px; pointer-events: none;
|
||||||
|
}
|
||||||
|
.toast {
|
||||||
|
pointer-events: auto;
|
||||||
|
display: flex; align-items: center; gap: 10px;
|
||||||
|
padding: 10px 16px; border-radius: 8px;
|
||||||
|
font-size: 13px; font-weight: 500;
|
||||||
|
box-shadow: 0 4px 12px rgba(0,0,0,0.12);
|
||||||
|
animation: toastIn 0.2s ease-out; max-width: 380px;
|
||||||
|
}
|
||||||
|
.toast.toast-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
|
||||||
|
.toast.toast-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
|
||||||
|
.toast.toast-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
|
||||||
|
.toast.fade-out { animation: toastOut 0.25s ease-in forwards; }
|
||||||
|
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
|
||||||
|
@keyframes toastOut { to { opacity: 0; transform: translateX(20px); } }
|
||||||
|
|
||||||
|
/* 财务弹窗优化 */
|
||||||
|
.fin-field-group {
|
||||||
|
background: #f8fafc;
|
||||||
|
border: 1px solid #e2e8f0;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 18px;
|
||||||
|
}
|
||||||
|
.fin-section-label {
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #334155;
|
||||||
|
margin-bottom: 14px;
|
||||||
|
padding-bottom: 8px;
|
||||||
|
border-bottom: 1px solid #e2e8f0;
|
||||||
|
}
|
||||||
|
.fin-label {
|
||||||
|
display: block;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #64748b;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 项目树拖拽 */
|
||||||
|
.project-tree-node.dragging { opacity: 0.4; }
|
||||||
|
.project-tree-node.drag-over { border-top: 2px solid #2563eb; }
|
||||||
|
|||||||
@@ -28,8 +28,11 @@
|
|||||||
<body class="min-h-screen bg-slate-50 text-slate-950">
|
<body class="min-h-screen bg-slate-50 text-slate-950">
|
||||||
<div class="flex min-h-screen">
|
<div class="flex min-h-screen">
|
||||||
<!-- 左侧工作台切换栏 -->
|
<!-- 左侧工作台切换栏 -->
|
||||||
<aside class="w-[72px] bg-slate-900 flex flex-col items-center py-6 gap-1 shrink-0" id="workspaceSidebar">
|
<aside class="w-[72px] bg-slate-900 flex flex-col items-center py-6 gap-1 shrink-0 sticky top-0 h-screen overflow-y-auto" id="workspaceSidebar">
|
||||||
<div class="w-10 h-10 rounded-xl bg-blue-600 flex items-center justify-center mb-6 text-white font-bold text-sm">OPC</div>
|
<div class="flex flex-col items-center mb-6 cursor-pointer" onclick="document.getElementById('userAvatar').click()">
|
||||||
|
<div class="w-10 h-10 rounded-full bg-slate-700 flex items-center justify-center text-white font-bold text-sm hover:ring-2 hover:ring-blue-400 transition-all" id="userAvatar" title=""></div>
|
||||||
|
<span class="text-[10px] text-slate-400 mt-1.5 max-w-[64px] truncate text-center" id="userDisplayName" title=""></span>
|
||||||
|
</div>
|
||||||
<div class="workspace-nav-item active" data-tenant="科普·无界" onclick="switchTenant('科普·无界')" title="科普·无界">
|
<div class="workspace-nav-item active" data-tenant="科普·无界" onclick="switchTenant('科普·无界')" title="科普·无界">
|
||||||
<svg class="w-6 h-6" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M8 12h8"/><path d="M12 8v8"/></svg>
|
<svg class="w-6 h-6" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M8 12h8"/><path d="M12 8v8"/></svg>
|
||||||
<span class="text-[10px] mt-1">科普</span>
|
<span class="text-[10px] mt-1">科普</span>
|
||||||
@@ -42,10 +45,13 @@
|
|||||||
<svg class="w-6 h-6" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 12h-4l-3 9L9 3l-3 9H2"/></svg>
|
<svg class="w-6 h-6" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 12h-4l-3 9L9 3l-3 9H2"/></svg>
|
||||||
<span class="text-[10px] mt-1">医患</span>
|
<span class="text-[10px] mt-1">医患</span>
|
||||||
</div>
|
</div>
|
||||||
<!-- 用户区 -->
|
<div class="workspace-nav-item" data-tenant="MCN·无界" onclick="switchTenant('MCN·无界')" title="MCN·无界">
|
||||||
<div class="mt-auto flex flex-col items-center gap-2 pt-4">
|
<svg class="w-6 h-6" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="7" width="20" height="15" rx="2"/><path d="M17 2l-5 5-5-5"/></svg>
|
||||||
<div class="w-8 h-8 rounded-full bg-slate-700 flex items-center justify-center text-white text-[11px] font-medium" id="userAvatar" title=""></div>
|
<span class="text-[10px] mt-1">MCN</span>
|
||||||
<button class="text-[10px] text-slate-500 hover:text-red-400 transition-colors" onclick="doLogout()" title="退出登录">退出</button>
|
</div>
|
||||||
|
<div class="workspace-nav-item" data-tenant="无界·无界" onclick="switchTenant('无界·无界')" title="无界·无界">
|
||||||
|
<svg class="w-6 h-6" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M2 12h20"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg>
|
||||||
|
<span class="text-[10px] mt-1">无界</span>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
<!-- 主内容区 -->
|
<!-- 主内容区 -->
|
||||||
@@ -91,7 +97,7 @@
|
|||||||
<input type="hidden" name="transfer_id" id="transfer-id" value="">
|
<input type="hidden" name="transfer_id" id="transfer-id" value="">
|
||||||
<p id="transfer-title-text" class="text-sm text-slate-600"></p>
|
<p id="transfer-title-text" class="text-sm text-slate-600"></p>
|
||||||
<label class="block"><span class="text-xs font-medium text-slate-500">目标工作台</span>
|
<label class="block"><span class="text-xs font-medium text-slate-500">目标工作台</span>
|
||||||
<select name="transfer_tenant" class="mt-1 block w-full rounded-lg border border-slate-200 px-3 py-2.5 text-sm">
|
<select name="transfer_tenant" class="form-ctrl mt-1">
|
||||||
<option value="科普·无界">科普·无界</option>
|
<option value="科普·无界">科普·无界</option>
|
||||||
<option value="科研·无界">科研·无界</option>
|
<option value="科研·无界">科研·无界</option>
|
||||||
<option value="医患·无界">医患·无界</option>
|
<option value="医患·无界">医患·无界</option>
|
||||||
@@ -112,8 +118,8 @@
|
|||||||
<button class="btn btn-ghost btn-sm rounded-full w-8 h-8 p-0" onclick="closeNewProjectModal()"><i data-lucide="x"></i></button>
|
<button class="btn btn-ghost btn-sm rounded-full w-8 h-8 p-0" onclick="closeNewProjectModal()"><i data-lucide="x"></i></button>
|
||||||
</div>
|
</div>
|
||||||
<form onsubmit="createOperation(event)" class="p-6 grid gap-4">
|
<form onsubmit="createOperation(event)" class="p-6 grid gap-4">
|
||||||
<label class="block"><span class="text-xs font-medium text-slate-500">项目名称</span><input name="project_name" required class="mt-1 block w-full rounded-lg border border-slate-200 px-3 py-2.5 text-sm"></label>
|
<label class="block"><span class="text-xs font-medium text-slate-500">项目名称</span><input name="project_name" required class="form-ctrl mt-1"></label>
|
||||||
<label class="block"><span class="text-xs font-medium text-slate-500">项目备注</span><textarea name="notes" rows="3" class="mt-1 block w-full rounded-lg border border-slate-200 px-3 py-2.5 text-sm" placeholder="可选"></textarea></label>
|
<label class="block"><span class="text-xs font-medium text-slate-500">项目备注</span><textarea name="notes" rows="3" class="form-ctrl mt-1" placeholder="可选"></textarea></label>
|
||||||
<div class="flex justify-end gap-3 pt-3 border-t border-slate-100">
|
<div class="flex justify-end gap-3 pt-3 border-t border-slate-100">
|
||||||
<button type="button" class="btn btn-ghost btn-sm" onclick="closeNewProjectModal()">取消</button>
|
<button type="button" class="btn btn-ghost btn-sm" onclick="closeNewProjectModal()">取消</button>
|
||||||
<button type="submit" class="btn btn-primary btn-sm">创建</button>
|
<button type="submit" class="btn btn-primary btn-sm">创建</button>
|
||||||
@@ -121,6 +127,14 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script src="{{ url_for('static', filename='modules/utils.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='modules/home.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='modules/projects.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='modules/proposals.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='modules/products.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='modules/finance.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='modules/drawer.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='modules/admin.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='app.js') }}"></script>
|
<script src="{{ url_for('static', filename='app.js') }}"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -4,42 +4,99 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>OPC 工作台 · 登录</title>
|
<title>OPC 工作台 · 登录</title>
|
||||||
<script src="https://cdn.tailwindcss.com"></script>
|
<link rel="stylesheet" href="{{ url_for('static', filename='vendor/lucide.js') }}" onerror="this.remove()">
|
||||||
|
<script src="{{ url_for('static', filename='vendor/lucide.js') }}"></script>
|
||||||
|
<style>
|
||||||
|
*{box-sizing:border-box;margin:0;padding:0}
|
||||||
|
body{font-family:PingFang SC,Microsoft YaHei,-apple-system,sans-serif;background:#f8fafc;min-height:100vh;display:flex;align-items:center;justify-content:center}
|
||||||
|
.card{background:#fff;border-radius:16px;padding:40px 44px;width:400px;max-width:94vw;box-shadow:0 16px 48px rgba(15,23,42,.12)}
|
||||||
|
.logo{text-align:center;margin-bottom:32px}
|
||||||
|
.logo .icon{width:56px;height:56px;margin:0 auto 10px;display:flex;align-items:center;justify-content:center;background:linear-gradient(135deg,#1e293b,#0f172a);border-radius:14px;color:#fff}
|
||||||
|
.logo h1{font-size:20px;font-weight:700;color:#1e293b}
|
||||||
|
.logo p{font-size:13px;color:#94a3b8;margin-top:4px}
|
||||||
|
.form-group{margin-bottom:18px}
|
||||||
|
label{display:block;font-size:13px;font-weight:500;color:#475569;margin-bottom:6px}
|
||||||
|
.input-wrap{position:relative}
|
||||||
|
input[type=text],input[type=password]{width:100%;height:42px;padding:0 14px;border:1px solid #cbd5e1;border-radius:8px;font-size:14px;outline:none;transition:.2s;font-family:inherit;color:#1e293b;background:#fff}
|
||||||
|
.input-wrap input{padding:0 40px 0 14px}
|
||||||
|
input[type=text]:focus,input[type=password]:focus,.input-wrap input:focus{border-color:#334155;box-shadow:0 0 0 3px rgba(51,65,85,.12)}
|
||||||
|
input::placeholder{color:#94a3b8}
|
||||||
|
.toggle-pwd{position:absolute;right:10px;top:50%;transform:translateY(-50%);background:none;border:none;cursor:pointer;color:#94a3b8;padding:4px;display:flex;align-items:center;justify-content:center;transition:.2s}
|
||||||
|
.toggle-pwd:hover{color:#334155}
|
||||||
|
.btn{width:100%;height:44px;background:#1e293b;color:#fff;border:none;border-radius:8px;font-size:15px;font-weight:600;cursor:pointer;transition:.2s;margin-top:8px}
|
||||||
|
.btn:hover{background:#0f172a}
|
||||||
|
.btn:active{transform:scale(.98)}
|
||||||
|
.err{background:#fef2f2;border:1px solid #fecaca;color:#dc2626;border-radius:8px;padding:10px 14px;font-size:13px;margin-bottom:16px;display:none}
|
||||||
|
.err.show{display:block}
|
||||||
|
.footer{text-align:center;margin-top:24px;font-size:11px;color:#94a3b8}
|
||||||
|
.footer strong{color:#334155}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body class="min-h-screen bg-slate-50 flex items-center justify-center">
|
<body>
|
||||||
<div class="bg-white rounded-2xl shadow-lg p-8 w-full max-w-sm mx-4">
|
<div class="card">
|
||||||
<div class="text-center mb-6">
|
<div class="logo">
|
||||||
<h1 class="text-2xl font-bold text-slate-800">OPC 工作台</h1>
|
<div class="icon"><i data-lucide="layout-dashboard" style="width:28px;height:28px;stroke-width:2"></i></div>
|
||||||
<p class="text-sm text-slate-400 mt-1">请输入账号密码登录</p>
|
<h1>OPC 工作台</h1>
|
||||||
</div>
|
<p>请登录后继续</p>
|
||||||
<form id="loginForm" onsubmit="doLogin(event)" class="grid gap-4">
|
|
||||||
<label class="block">
|
|
||||||
<span class="text-xs font-medium text-slate-500">账号</span>
|
|
||||||
<input name="username" required class="mt-1 block w-full rounded-lg border border-slate-200 px-3 py-2.5 text-sm" placeholder="admin / kepu / keyan / yihuan" autofocus>
|
|
||||||
</label>
|
|
||||||
<label class="block">
|
|
||||||
<span class="text-xs font-medium text-slate-500">密码</span>
|
|
||||||
<input name="password" type="password" required class="mt-1 block w-full rounded-lg border border-slate-200 px-3 py-2.5 text-sm">
|
|
||||||
</label>
|
|
||||||
<p id="loginError" class="text-red-500 text-xs hidden"></p>
|
|
||||||
<button type="submit" class="btn w-full bg-slate-800 text-white rounded-lg py-2.5 text-sm font-medium hover:bg-slate-700">登 录</button>
|
|
||||||
</form>
|
|
||||||
<p class="text-xs text-slate-400 text-center mt-6">默认管理员:qiukai / yxcowork2026</p>
|
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<div class="err" id="errMsg"></div>
|
||||||
async function doLogin(e) {
|
<div class="form-group">
|
||||||
e.preventDefault();
|
<label>用户名</label>
|
||||||
const form = e.currentTarget;
|
<input type="text" id="username" placeholder="请输入用户名" autocomplete="username" autofocus>
|
||||||
const data = Object.fromEntries(new FormData(form).entries());
|
</div>
|
||||||
try {
|
<div class="form-group">
|
||||||
const res = await (await fetch("/api/auth/login", { method: "POST", headers: {"Content-Type":"application/json"}, body: JSON.stringify(data) })).json();
|
<label>密码</label>
|
||||||
if (res.error) { document.querySelector("#loginError").textContent = res.error; document.querySelector("#loginError").classList.remove("hidden"); return; }
|
<div class="input-wrap">
|
||||||
window.location.href = "/";
|
<input type="password" id="password" placeholder="请输入密码" autocomplete="current-password">
|
||||||
} catch (err) {
|
<button type="button" class="toggle-pwd" onclick="togglePwd('password', this)" title="显示/隐藏密码"><i data-lucide="eye" style="width:18px;height:18px"></i></button>
|
||||||
document.querySelector("#loginError").textContent = "网络错误,请重试";
|
</div>
|
||||||
document.querySelector("#loginError").classList.remove("hidden");
|
</div>
|
||||||
}
|
<button class="btn" id="loginBtn" onclick="doLogin()">登 录</button>
|
||||||
|
<div class="footer">默认管理员:<strong>qiukai / yxcowork2026</strong></div>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
if (window.lucide) lucide.createIcons();
|
||||||
|
|
||||||
|
function togglePwd(id, btn) {
|
||||||
|
const input = document.getElementById(id);
|
||||||
|
const isPwd = input.type === 'password';
|
||||||
|
input.type = isPwd ? 'text' : 'password';
|
||||||
|
btn.innerHTML = isPwd
|
||||||
|
? '<i data-lucide="eye-off" style="width:18px;height:18px"></i>'
|
||||||
|
: '<i data-lucide="eye" style="width:18px;height:18px"></i>';
|
||||||
|
if (window.lucide) lucide.createIcons();
|
||||||
|
}
|
||||||
|
|
||||||
|
const errEl = document.getElementById('errMsg');
|
||||||
|
function showErr(msg) { errEl.textContent = msg; errEl.classList.add('show'); }
|
||||||
|
function clearErr() { errEl.classList.remove('show'); }
|
||||||
|
|
||||||
|
document.getElementById('username').addEventListener('input', clearErr);
|
||||||
|
document.getElementById('password').addEventListener('input', clearErr);
|
||||||
|
|
||||||
|
// 回车提交
|
||||||
|
document.getElementById('password').addEventListener('keydown', (e) => { if (e.key === 'Enter') doLogin(); });
|
||||||
|
document.getElementById('username').addEventListener('keydown', (e) => { if (e.key === 'Enter') document.getElementById('password').focus(); });
|
||||||
|
|
||||||
|
async function doLogin() {
|
||||||
|
clearErr();
|
||||||
|
const username = document.getElementById('username').value.trim();
|
||||||
|
const password = document.getElementById('password').value;
|
||||||
|
if (!username || !password) { showErr('请输入用户名和密码'); return; }
|
||||||
|
const btn = document.getElementById('loginBtn');
|
||||||
|
btn.disabled = true; btn.style.opacity = .7; btn.textContent = '登录中...';
|
||||||
|
try {
|
||||||
|
const res = await (await fetch('/api/auth/login', {
|
||||||
|
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ username, password })
|
||||||
|
})).json();
|
||||||
|
if (res.error) { showErr(res.error); btn.disabled = false; btn.style.opacity = 1; btn.textContent = '登 录'; return; }
|
||||||
|
window.location.href = '/';
|
||||||
|
} catch (err) {
|
||||||
|
showErr('网络错误,请重试');
|
||||||
|
btn.disabled = false; btn.style.opacity = 1; btn.textContent = '登 录';
|
||||||
}
|
}
|
||||||
</script>
|
}
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user