初始版本 0.1.0:四道菜团队中台 DSH 插件
模型通道:接管官方 API Key 通道指向弹匣网关(GLM-5.3 / GLM-5.3-Flash) 登录:浏览器取一次性接入码 → 换成员专属 key → 写入 DSH 凭据 工具面:MCP 暴露查汇总/查任务/查项目/建任务/完成/改期/whoami 面板:侧边栏入口,个人看板 + 角色可见范围 + 行内操作 离职吊销:成员停用即吊销名下全部 TDB key 发布配置:scope 包名、私有 registry 锁定、prepack 自动构建、prepublishOnly 检查
This commit is contained in:
commit
ff8017bbbb
26 files changed
+2924
No files matched your search
+220
@@ -0,0 +1,220 @@
|
||||
/**
|
||||
* 四道菜团队中台 —— 宿主半片。
|
||||
*
|
||||
* 三件事:
|
||||
* 1. cordis.patch.yml 把模型通道指向公司网关(那份配置自己生效,不在这里管)
|
||||
* 2. MCP 工具面:弹匣的汇总/查任务/查项目/建任务,给 agent 用
|
||||
* 3. 本地面板接口:给侧边栏面板取数据(浏览器侧不碰凭证,只调这里)
|
||||
*
|
||||
* 面板取数的身份就是登录时那张工具凭证(MARKMAG_TOOL_TOKEN),所以打开面板
|
||||
* 不需要再登录一次弹匣。数据一律现取现给,不落地存储 —— 弹匣是唯一数据源,
|
||||
* 这里只是显示器(写入仍走弹匣同一套 API,规则判定全在弹匣侧)。
|
||||
*
|
||||
* 排查约定:产品 profile 没有控制台日志,每走一步都往
|
||||
* $DSH_HOME/markmag-plugin-state.json 写一行进展。
|
||||
*/
|
||||
import { writeFileSync, mkdirSync, readFileSync } from 'node:fs'
|
||||
import { homedir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
export const name = 'dsh-markmag'
|
||||
|
||||
// tools:MCP 客户端要靠这个服务把工具交给 agent 循环
|
||||
// webServer / connection:本地面板接口 + 请求准入
|
||||
export const inject = ['tools', 'webServer', 'connection']
|
||||
|
||||
const CREDENTIAL = 'MARKMAG_TEAM_KEY'
|
||||
const TOOL_CREDENTIAL = 'MARKMAG_TOOL_TOKEN'
|
||||
const MARKMAG_BASE = 'https://brain.sidaocai.cn/markmag'
|
||||
const STEPS = []
|
||||
|
||||
function stateFile() {
|
||||
const home = process.env.DSH_HOME || join(homedir(), '.dsh')
|
||||
mkdirSync(home, { recursive: true })
|
||||
return join(home, 'markmag-plugin-state.json')
|
||||
}
|
||||
|
||||
function step(name, extra) {
|
||||
STEPS.push({ step: name, at: new Date().toISOString().slice(11, 19), ...(extra || {}) })
|
||||
try {
|
||||
writeFileSync(stateFile(), JSON.stringify({ updatedAt: new Date().toISOString(), pid: process.pid, steps: STEPS }, null, 1))
|
||||
} catch {
|
||||
// 状态文件写不了不影响功能
|
||||
}
|
||||
}
|
||||
|
||||
/** 工具凭证:环境变量优先,其次 DSH 凭据文件。 */
|
||||
function toolToken() {
|
||||
if (process.env.MARKMAG_TOOL_TOKEN) return process.env.MARKMAG_TOOL_TOKEN
|
||||
try {
|
||||
const home = process.env.DSH_HOME || join(homedir(), '.dsh')
|
||||
const y = readFileSync(join(home, '.credentials.yaml'), 'utf8')
|
||||
const m = y.match(/^\s+MARKMAG_TOOL_TOKEN:\s*(\S+)/m)
|
||||
return m ? m[1] : ''
|
||||
} catch {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
/** 调弹匣工具面(同一个端点,agent 和面板共用;规则判定全在弹匣侧)。 */
|
||||
async function callMarkmag(tool, args) {
|
||||
const token = toolToken()
|
||||
if (!token) return { ok: false, err: '还没接入弹匣:缺少工具凭证' }
|
||||
try {
|
||||
const res = await fetch(MARKMAG_BASE + '/api/dsh/tool', {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json', 'x-markmag-token': token },
|
||||
body: JSON.stringify({ tool, args: args || {} }),
|
||||
signal: AbortSignal.timeout(15000),
|
||||
})
|
||||
return await res.json()
|
||||
} catch (e) {
|
||||
return { ok: false, err: '连不上弹匣:' + (e.name === 'TimeoutError' ? '超时' : e.message) }
|
||||
}
|
||||
}
|
||||
|
||||
function readJson(req, limit) {
|
||||
return new Promise((resolve) => {
|
||||
const chunks = []
|
||||
let size = 0
|
||||
req.on('data', (c) => {
|
||||
size += c.length
|
||||
if (size > (limit || 1_000_000)) {
|
||||
resolve({})
|
||||
req.destroy()
|
||||
return
|
||||
}
|
||||
chunks.push(c)
|
||||
})
|
||||
req.on('end', () => {
|
||||
try {
|
||||
resolve(JSON.parse(Buffer.concat(chunks).toString('utf8') || '{}'))
|
||||
} catch {
|
||||
resolve({})
|
||||
}
|
||||
})
|
||||
req.on('error', () => resolve({}))
|
||||
})
|
||||
}
|
||||
|
||||
function json(res, status, body) {
|
||||
res.statusCode = status
|
||||
res.setHeader('content-type', 'application/json; charset=utf-8')
|
||||
res.setHeader('cache-control', 'no-store')
|
||||
res.end(JSON.stringify(body))
|
||||
}
|
||||
|
||||
function requestRejection(ctx, req) {
|
||||
const connection = ctx.get('connection')
|
||||
if (typeof connection?.requestRejection !== 'function') return 403
|
||||
return connection.requestRejection({ headers: req.headers })
|
||||
}
|
||||
|
||||
export function apply(ctx) {
|
||||
step('apply-entered')
|
||||
|
||||
// ── 1. MCP 工具面 ───────────────────────────────────────
|
||||
const serverPath = fileURLToPath(new URL('./mcp-server.mjs', import.meta.url))
|
||||
step('server-path-resolved', { serverPath })
|
||||
|
||||
;(async () => {
|
||||
let mcpClient
|
||||
try {
|
||||
mcpClient = await import('@deepseek-ai/dsh-mcp-client')
|
||||
step('mcp-client-imported')
|
||||
} catch (e) {
|
||||
step('mcp-client-import-failed', { error: String(e?.message || e).slice(0, 300) })
|
||||
return
|
||||
}
|
||||
try {
|
||||
ctx.plugin(mcpClient, {
|
||||
transport: 'stdio',
|
||||
serverName: 'markmag',
|
||||
command: process.execPath,
|
||||
args: [serverPath],
|
||||
env: { ELECTRON_RUN_AS_NODE: '1' },
|
||||
toolCallTimeoutMs: 30000,
|
||||
})
|
||||
step('mcp-plugin-mounted')
|
||||
} catch (e) {
|
||||
step('mcp-plugin-mount-failed', { error: String(e?.message || e).slice(0, 300) })
|
||||
}
|
||||
})()
|
||||
|
||||
// ── 2. 面板数据接口 ─────────────────────────────────────
|
||||
ctx.effect(
|
||||
() =>
|
||||
ctx.webServer.register({
|
||||
kind: 'prefix',
|
||||
path: '/__markmag',
|
||||
handler: async (req, res) => {
|
||||
try {
|
||||
const rejection = requestRejection(ctx, req)
|
||||
if (rejection) {
|
||||
json(res, rejection, { ok: false, err: 'unauthorized' })
|
||||
return
|
||||
}
|
||||
const url = new URL(req.url || '/', 'http://127.0.0.1')
|
||||
const p = url.pathname.replace(/\/+$/, '')
|
||||
const isPost = (req.method || 'GET').toUpperCase() === 'POST'
|
||||
|
||||
// ── 写操作:面板上的按钮落到弹匣同一套 store,规则不在本地重写 ──
|
||||
if (isPost && p === '/__markmag/task/toggle') {
|
||||
const body = await readJson(req)
|
||||
json(res, 200, await callMarkmag('toggle_task', { id: body.id, to: body.to }))
|
||||
return
|
||||
}
|
||||
if (isPost && p === '/__markmag/task/update') {
|
||||
const body = await readJson(req)
|
||||
json(res, 200, await callMarkmag('update_task', { id: body.id, patch: body.patch || {} }))
|
||||
return
|
||||
}
|
||||
if (isPost && p === '/__markmag/task/create') {
|
||||
const body = await readJson(req)
|
||||
json(res, 200, await callMarkmag('create_task', Object.assign({}, body, { confirm: true })))
|
||||
return
|
||||
}
|
||||
|
||||
if (p === '/__markmag/me') {
|
||||
json(res, 200, await callMarkmag('whoami', {}))
|
||||
return
|
||||
}
|
||||
if (p === '/__markmag/summary') {
|
||||
json(res, 200, await callMarkmag('get_summary', {}))
|
||||
return
|
||||
}
|
||||
if (p === '/__markmag/projects') {
|
||||
json(res, 200, await callMarkmag('query_projects', {}))
|
||||
return
|
||||
}
|
||||
if (p === '/__markmag/tasks') {
|
||||
const args = {}
|
||||
const status = url.searchParams.get('status')
|
||||
const owner = url.searchParams.get('owner')
|
||||
const project = url.searchParams.get('project')
|
||||
if (status) args.status = status
|
||||
if (owner) args.owner = owner
|
||||
if (project) args.project = project
|
||||
json(res, 200, await callMarkmag('query_tasks', args))
|
||||
return
|
||||
}
|
||||
json(res, 404, { ok: false, err: 'not found' })
|
||||
} catch (e) {
|
||||
json(res, 500, { ok: false, err: String(e?.message || e).slice(0, 200) })
|
||||
}
|
||||
},
|
||||
}),
|
||||
'dsh-markmag: panel api'
|
||||
)
|
||||
step('panel-api-registered')
|
||||
|
||||
// ── 3. 启动提示 ─────────────────────────────────────────
|
||||
ctx.effect(() => {
|
||||
try {
|
||||
ctx.get('logger')?.info?.(
|
||||
'[dsh-markmag] 已挂载:四道菜模型通道(GLM-5.3 / GLM-5.3-Flash,凭据 ' + CREDENTIAL + ')+ 弹匣工具面 + 侧边栏面板'
|
||||
)
|
||||
} catch {}
|
||||
}, 'dsh-markmag: startup note')
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* 弹匣工具面 —— MCP stdio server。
|
||||
*
|
||||
* 把弹匣的四件工具(汇总/查任务/查项目/建任务)接到 DSH 里,让 agent 能直接
|
||||
* 查团队的任务和项目,不用切到网页。权限跟着工具凭证走:部门隔离由弹匣侧
|
||||
* 按成员的 depts 判定,这里不重复实现(一份规则,一处维护)。
|
||||
*
|
||||
* 凭证来源:环境变量 MARKMAG_TOOL_TOKEN,没有就读 DSH 凭据文件。
|
||||
*/
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { homedir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { createInterface } from 'node:readline'
|
||||
|
||||
const BASE = process.env.MARKMAG_BASE || 'https://brain.sidaocai.cn/markmag'
|
||||
|
||||
function readToken() {
|
||||
if (process.env.MARKMAG_TOOL_TOKEN) return process.env.MARKMAG_TOOL_TOKEN
|
||||
try {
|
||||
const y = readFileSync(join(homedir(), '.dsh/.credentials.yaml'), 'utf8')
|
||||
const m = y.match(/^\s+MARKMAG_TOOL_TOKEN:\s*(\S+)/m)
|
||||
return m ? m[1] : ''
|
||||
} catch {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
const TOOLS = [
|
||||
{
|
||||
name: 'get_summary',
|
||||
description: '弹匣全局汇总:各项目健康度与阶段、未完成任务数、逾期任务、目标达成率。想知道「团队现在什么状况」时先调这个。',
|
||||
inputSchema: { type: 'object', properties: {} },
|
||||
},
|
||||
{
|
||||
name: 'query_tasks',
|
||||
description: '查弹匣里的任务。可按项目 id、负责人姓名、状态过滤。只返回当前账号有权看的部门。',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
project: { type: 'string', description: '项目 id(精确匹配)' },
|
||||
owner: { type: 'string', description: '负责人姓名(精确匹配)' },
|
||||
status: { type: 'string', enum: ['todo', 'doing', 'blocked', 'done'] },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'query_projects',
|
||||
description: '列出弹匣全部项目(健康度、阶段、进度、负责人)。',
|
||||
inputSchema: { type: 'object', properties: {} },
|
||||
},
|
||||
{
|
||||
name: 'create_task',
|
||||
description: '在弹匣里创建任务。走起草确认制:第一次不带 confirm,只生成草稿并展示给用户;用户明确同意后再带 confirm=true 真正创建。',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
required: ['title'],
|
||||
properties: {
|
||||
title: { type: 'string', description: '任务标题(动作,不是主题)' },
|
||||
owner: { type: 'string', description: '负责人姓名' },
|
||||
due: { type: 'string', description: '截止日 YYYY-MM-DD' },
|
||||
project: { type: 'string', description: '项目 id' },
|
||||
priority: { type: 'string', enum: ['P0', 'P1', 'P2'] },
|
||||
confirm: { type: 'boolean', description: '用户已明确同意创建时传 true' },
|
||||
},
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
const TOOL_MAP = {
|
||||
get_summary: 'get_summary',
|
||||
query_tasks: 'query_tasks',
|
||||
query_projects: 'query_projects',
|
||||
create_task: 'create_task',
|
||||
}
|
||||
|
||||
async function callTool(name, args) {
|
||||
const tool = TOOL_MAP[name]
|
||||
if (!tool) return { isError: true, text: '未知工具:' + name }
|
||||
const token = readToken()
|
||||
if (!token) {
|
||||
return { isError: true, text: '还没接入弹匣:缺少工具凭证。跑一次 dsh-markmag 的 setup-account 脚本即可。' }
|
||||
}
|
||||
try {
|
||||
const res = await fetch(BASE + '/api/dsh/tool', {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json', 'x-markmag-token': token },
|
||||
body: JSON.stringify({ tool, args: args || {} }),
|
||||
signal: AbortSignal.timeout(20000),
|
||||
})
|
||||
const data = await res.json().catch(() => ({}))
|
||||
if (!data.ok) return { isError: true, text: data.err || '弹匣返回 ' + res.status }
|
||||
return { isError: false, text: JSON.stringify(data.result, null, 1) }
|
||||
} catch (e) {
|
||||
return { isError: true, text: '连不上弹匣:' + (e.name === 'TimeoutError' ? '超时' : e.message) }
|
||||
}
|
||||
}
|
||||
|
||||
function send(obj) {
|
||||
process.stdout.write(JSON.stringify(obj) + '\n')
|
||||
}
|
||||
|
||||
const rl = createInterface({ input: process.stdin })
|
||||
rl.on('line', async (line) => {
|
||||
const raw = line.trim()
|
||||
if (!raw) return
|
||||
let msg
|
||||
try {
|
||||
msg = JSON.parse(raw)
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
const { id, method, params } = msg || {}
|
||||
if (!method) return
|
||||
|
||||
if (method === 'initialize') {
|
||||
return send({
|
||||
jsonrpc: '2.0',
|
||||
id,
|
||||
result: {
|
||||
protocolVersion: '2024-11-05',
|
||||
capabilities: { tools: {} },
|
||||
serverInfo: { name: 'markmag', version: '0.1.0' },
|
||||
},
|
||||
})
|
||||
}
|
||||
if (method === 'notifications/initialized' || method === 'initialized') return
|
||||
if (method === 'tools/list') return send({ jsonrpc: '2.0', id, result: { tools: TOOLS } })
|
||||
if (method === 'tools/call') {
|
||||
const r = await callTool(params?.name || '', params?.arguments || {})
|
||||
return send({
|
||||
jsonrpc: '2.0',
|
||||
id,
|
||||
result: { content: [{ type: 'text', text: r.text }], isError: r.isError },
|
||||
})
|
||||
}
|
||||
if (method === 'ping') return send({ jsonrpc: '2.0', id, result: {} })
|
||||
if (id !== undefined) {
|
||||
send({ jsonrpc: '2.0', id, error: { code: -32601, message: 'unsupported method: ' + method } })
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,185 @@
|
||||
.mm-wrap{
|
||||
--ink:var(--dsw-alias-label-primary,#111);
|
||||
--ink2:var(--dsw-alias-label-secondary,#555);
|
||||
--ink3:var(--dsw-alias-label-tertiary,#888);
|
||||
--ink4:var(--dsw-alias-label-caption,#aaa);
|
||||
--line:var(--dsw-alias-border-l2,rgba(0,0,0,.1));
|
||||
--line2:var(--dsw-alias-border-l4,rgba(0,0,0,.16));
|
||||
--card:var(--dsw-alias-bg-layer-2,#fff);
|
||||
--bg:var(--dsw-alias-bg-base,#f7f7f8);
|
||||
--hover:var(--dsw-alias-interactive-bg-hover,rgba(0,0,0,.04));
|
||||
--primary:var(--dsw-alias-button-primary-fill,#2E6BFF);
|
||||
--primary-hover:var(--dsw-alias-button-primary-hover,#4D82FF);
|
||||
--on-primary:var(--dsw-alias-label-primary-inverted,#fff);
|
||||
--ok:var(--dsw-alias-state-success-primary,#10B981);
|
||||
--warn:var(--dsw-alias-state-warn-primary,#D9A406);
|
||||
--err:var(--dsw-alias-state-error-primary,#E5484D);
|
||||
--info:var(--dsw-alias-state-business-primary,#2E6BFF);
|
||||
--idle:var(--dsw-alias-state-idle-primary,#9aa2ad);
|
||||
--r-sm:var(--dsw-radius-sm,8px);
|
||||
--r-md:var(--dsw-radius-md,12px);
|
||||
--r-xl:var(--dsw-radius-xl,20px);
|
||||
height:100%;overflow:auto;background:var(--bg);color:var(--ink);
|
||||
font-family:-apple-system,BlinkMacSystemFont,"PingFang SC","Microsoft YaHei",sans-serif;
|
||||
font-size:13px;line-height:1.5;-webkit-font-smoothing:antialiased;
|
||||
}
|
||||
.mm-inner{max-width:1000px;margin:0 auto;padding:20px 22px 48px}
|
||||
.mm-head{display:flex;align-items:center;gap:11px;margin-bottom:14px}
|
||||
.mm-logo{width:32px;height:32px;border-radius:var(--r-md);flex:none;display:grid;place-items:center;
|
||||
background:var(--primary);color:var(--on-primary)}
|
||||
.mm-title{font-size:15.5px;font-weight:650;letter-spacing:.01em}
|
||||
.mm-sub{font-size:11.5px;color:var(--ink4);margin-top:2px}
|
||||
.mm-actions{margin-left:auto;display:flex;align-items:center;gap:8px;flex:none}
|
||||
.mm-btn{border:1px solid var(--line);background:transparent;color:var(--ink2);
|
||||
border-radius:var(--r-sm);padding:5px 11px;font-size:12px;cursor:pointer;transition:.15s;
|
||||
white-space:nowrap;font-family:inherit}
|
||||
.mm-btn:hover{background:var(--hover);color:var(--ink);border-color:var(--line2)}
|
||||
.mm-btn:disabled{cursor:default;opacity:.6}
|
||||
.mm-btn-primary{background:var(--primary);border-color:transparent;color:var(--on-primary);font-weight:560}
|
||||
.mm-btn-primary:hover{background:var(--primary-hover);color:var(--on-primary)}
|
||||
.mm-nav{display:flex;gap:4px;border-bottom:1px solid var(--line);margin-bottom:16px}
|
||||
.mm-nav-i{border:none;background:transparent;color:var(--ink3);font-size:13px;font-family:inherit;
|
||||
padding:8px 12px;cursor:pointer;border-bottom:2px solid transparent;margin-bottom:-1px;transition:.15s;
|
||||
display:flex;align-items:center;gap:6px}
|
||||
.mm-nav-i:hover{color:var(--ink)}
|
||||
.mm-nav-on{color:var(--primary);border-bottom-color:var(--primary);font-weight:560}
|
||||
.mm-nav-c{font-size:10.5px;background:var(--hover);border-radius:999px;padding:0 6px;color:var(--ink3);
|
||||
font-variant-numeric:tabular-nums}
|
||||
.mm-nav-on .mm-nav-c{background:color-mix(in srgb,var(--primary) 16%,transparent);color:var(--primary)}
|
||||
.mm-stats{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;margin-bottom:20px}
|
||||
.mm-stat{background:var(--card);border:1px solid var(--line);border-radius:var(--r-xl);padding:15px 17px}
|
||||
.mm-stat-n{font-size:26px;font-weight:660;letter-spacing:-.02em;line-height:1.1;font-variant-numeric:tabular-nums}
|
||||
.mm-stat-l{font-size:11.5px;color:var(--ink3);margin-top:4px}
|
||||
.mm-card{background:var(--card);border:1px solid var(--line);border-radius:var(--r-xl);overflow:hidden}
|
||||
.mm-row{display:flex;align-items:center;gap:11px;padding:10px 15px;border-top:1px solid var(--line);transition:background .12s}
|
||||
.mm-row:first-child{border-top:none}
|
||||
.mm-row:hover{background:var(--hover)}
|
||||
.mm-dot{width:7px;height:7px;border-radius:50%;flex:none}
|
||||
.mm-dot-ok{background:var(--ok)}
|
||||
.mm-dot-warn{background:var(--warn)}
|
||||
.mm-dot-err{background:var(--err)}
|
||||
.mm-dot-idle{background:var(--idle)}
|
||||
.mm-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--ink)}
|
||||
.mm-meta{font-size:11.5px;color:var(--ink3);flex:none;white-space:nowrap}
|
||||
.mm-date{font-family:ui-monospace,"SF Mono",Menlo,monospace;font-size:11.5px;color:var(--ink4);
|
||||
flex:none;font-variant-numeric:tabular-nums}
|
||||
.mm-date-late{color:var(--err)}
|
||||
.mm-badge{font-size:11px;font-weight:560;padding:2px 8px;border-radius:var(--r-sm);flex:none;white-space:nowrap}
|
||||
.mm-b-todo{background:var(--hover);color:var(--ink2)}
|
||||
.mm-b-doing{background:color-mix(in srgb,var(--info) 14%,transparent);color:var(--info)}
|
||||
.mm-b-blocked{background:color-mix(in srgb,var(--err) 14%,transparent);color:var(--err)}
|
||||
.mm-b-done{background:color-mix(in srgb,var(--ok) 14%,transparent);color:var(--ok)}
|
||||
.mm-empty{padding:24px 16px;text-align:center;color:var(--ink4);font-size:12.5px}
|
||||
.mm-err{background:color-mix(in srgb,var(--err) 10%,transparent);border:1px solid var(--err);
|
||||
color:var(--err);border-radius:var(--r-md);padding:10px 13px;font-size:12.5px;margin-bottom:16px}
|
||||
.mm-foot{margin-top:20px;font-size:11px;color:var(--ink4);line-height:1.7;text-align:center}
|
||||
.mm-sk{height:13px;border-radius:var(--r-sm);background:var(--dsw-alias-bg-skeleton,rgba(0,0,0,.06));
|
||||
animation:mm-pulse 1.4s ease-in-out infinite}
|
||||
@keyframes mm-pulse{0%,100%{opacity:.55}50%{opacity:1}}
|
||||
|
||||
.mm-sched{display:flex;gap:14px;align-items:flex-start}
|
||||
.mm-cal{flex:1;min-width:0;background:var(--card);border:1px solid var(--line);border-radius:var(--r-xl);padding:12px}
|
||||
.mm-cal-h{display:flex;align-items:center;gap:6px;margin-bottom:8px;padding:0 2px}
|
||||
.mm-cal-m{font-size:13.5px;font-weight:640;font-variant-numeric:tabular-nums}
|
||||
.mm-cal-sp{margin-left:auto;display:flex;gap:3px}
|
||||
.mm-cal-b{height:23px;padding:0 7px;border:1px solid var(--line);background:transparent;color:var(--ink3);
|
||||
border-radius:var(--r-sm);cursor:pointer;display:grid;place-items:center;font-size:11.5px;line-height:1;font-family:inherit}
|
||||
.mm-cal-b:hover{background:var(--hover);color:var(--ink)}
|
||||
.mm-cal-grid{display:grid;grid-template-columns:repeat(7,1fr);gap:2px}
|
||||
.mm-cal-w{font-size:10px;color:var(--ink4);text-align:center;padding:2px 0 4px}
|
||||
.mm-cal-d{border:none;background:transparent;border-radius:var(--r-sm);cursor:pointer;font-family:inherit;
|
||||
height:90px;display:flex;flex-direction:column;align-items:stretch;gap:2px;padding:4px 4px 3px;
|
||||
color:var(--ink2);position:relative;transition:background .12s;text-align:left;overflow:hidden}
|
||||
.mm-cal-d:hover{background:var(--hover)}
|
||||
.mm-cal-pad{height:90px}
|
||||
.mm-cal-n{font-size:10.5px;line-height:1.15;color:var(--ink3);flex:none;font-variant-numeric:tabular-nums}
|
||||
.mm-today{box-shadow:inset 0 0 0 1.5px var(--primary)}
|
||||
.mm-today .mm-cal-n{color:var(--primary);font-weight:650}
|
||||
.mm-sel{background:var(--primary)!important}
|
||||
.mm-sel .mm-cal-n{color:var(--on-primary)}
|
||||
.mm-ev{font-size:9.5px;line-height:1.45;border-radius:3px;padding:0 3px;overflow:hidden;text-overflow:ellipsis;
|
||||
white-space:nowrap;background:var(--hover);color:var(--ink2);flex:none;max-width:100%}
|
||||
.mm-ev-late{background:color-mix(in srgb,var(--err) 13%,transparent);color:var(--err)}
|
||||
.mm-ev-doing{background:color-mix(in srgb,var(--info) 13%,transparent);color:var(--info)}
|
||||
.mm-ev-more{font-size:9px;color:var(--ink4);padding-left:2px;flex:none}
|
||||
.mm-sel .mm-ev{background:rgba(255,255,255,.22);color:var(--on-primary)}
|
||||
.mm-sel .mm-ev-late{background:rgba(255,255,255,.22);color:var(--on-primary)}
|
||||
.mm-sel .mm-ev-more{color:rgba(255,255,255,.72)}
|
||||
.mm-day{width:268px;flex:none}
|
||||
.mm-day-h{margin-bottom:8px}
|
||||
.mm-day-t{font-size:13px;font-weight:640;font-variant-numeric:tabular-nums}
|
||||
.mm-day-s{font-size:11.5px;color:var(--ink4);margin-top:2px}
|
||||
@media (max-width:820px){.mm-sched{flex-direction:column}.mm-day{width:100%}}
|
||||
|
||||
/* 甘特图 */
|
||||
.mm-gantt{background:var(--card);border:1px solid var(--line);border-radius:var(--r-xl);overflow:hidden}
|
||||
.mm-gantt-h{display:flex;align-items:stretch;border-bottom:1px solid var(--line);background:var(--hover)}
|
||||
.mm-gantt-hn{width:170px;flex:none;padding:7px 14px;font-size:11px;color:var(--ink3);display:flex;align-items:center}
|
||||
.mm-gantt-cols{flex:1;display:flex;min-width:0}
|
||||
.mm-gantt-c{flex:1;min-width:0;text-align:center;font-size:9.5px;color:var(--ink4);padding:5px 0 4px;
|
||||
border-left:1px solid var(--line);line-height:1.35;overflow:hidden}
|
||||
.mm-gantt-c-w{font-size:9px;color:var(--ink4);opacity:.75}
|
||||
.mm-gantt-cow{color:var(--primary);font-weight:650;background:color-mix(in srgb,var(--primary) 8%,transparent)}
|
||||
.mm-gantt-row{display:flex;align-items:stretch;border-top:1px solid var(--line);height:36px}
|
||||
.mm-gantt-row:first-child{border-top:none}
|
||||
.mm-gantt-row:hover{background:var(--hover)}
|
||||
.mm-gantt-n{width:170px;flex:none;display:flex;align-items:center;gap:7px;padding:0 14px;min-width:0}
|
||||
.mm-gantt-nm{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12.5px}
|
||||
.mm-gantt-track{flex:1;position:relative;display:flex;min-width:0}
|
||||
.mm-gantt-cell{flex:1;min-width:0;border-left:1px solid var(--line)}
|
||||
.mm-gantt-cell-cow{background:color-mix(in srgb,var(--primary) 5%,transparent)}
|
||||
.mm-gantt-bar{position:absolute;top:50%;height:15px;transform:translateY(-50%);border-radius:4px;
|
||||
background:var(--primary);opacity:.82;z-index:1;min-width:4px}
|
||||
.mm-gantt-bar-doing{background:var(--info)}
|
||||
.mm-gantt-bar-late{background:var(--err);opacity:.9}
|
||||
.mm-gantt-bar-done{background:var(--ok);opacity:.55}
|
||||
.mm-gantt-lbl{position:absolute;top:50%;transform:translateY(-50%);font-size:9.5px;color:var(--ink3);
|
||||
padding-left:6px;white-space:nowrap;z-index:1}
|
||||
.mm-gantt-legend{display:flex;gap:14px;margin-top:10px;padding-left:2px;flex-wrap:wrap}
|
||||
.mm-lgi{display:flex;align-items:center;gap:5px;font-size:11px;color:var(--ink4)}
|
||||
.mm-lgd{width:16px;height:8px;border-radius:3px}
|
||||
|
||||
/* 身份 / 焦点 / 项目矩阵 / 可点行 */
|
||||
.mm-id{font-size:11.5px;color:var(--ink4);margin-top:2px}
|
||||
.mm-row-click{cursor:pointer}
|
||||
.mm-focus{background:var(--card);border:1px solid var(--line);border-radius:var(--r-xl);overflow:hidden;margin-bottom:20px}
|
||||
.mm-focus-h{display:flex;align-items:center;gap:8px;padding:11px 15px 9px}
|
||||
.mm-focus-t{font-size:12px;font-weight:640;color:var(--err)}
|
||||
.mm-focus-c{font-size:11px;color:var(--ink4)}
|
||||
.mm-focus-i{display:flex;align-items:center;gap:10px;padding:10px 15px;border-top:1px solid var(--line);
|
||||
cursor:pointer;transition:background .12s}
|
||||
.mm-focus-i:hover{background:var(--hover)}
|
||||
.mm-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:10px}
|
||||
.mm-grid-1{grid-template-columns:1fr}
|
||||
.mm-pcard{background:var(--card);border:1px solid var(--line);border-radius:var(--r-lg);padding:13px 15px;
|
||||
cursor:pointer;transition:.15s;min-width:0}
|
||||
.mm-pcard:hover{border-color:var(--line2);background:var(--hover)}
|
||||
.mm-pcard-n{font-size:13.5px;font-weight:600;color:var(--ink);margin-bottom:7px;line-height:1.35}
|
||||
.mm-pcard-m{display:flex;align-items:center;gap:6px;font-size:11.5px;color:var(--ink3);flex-wrap:wrap}
|
||||
.mm-bar{height:4px;border-radius:2px;background:var(--hover);overflow:hidden;margin-top:9px}
|
||||
.mm-bar-i{height:100%;border-radius:2px;background:var(--primary)}
|
||||
.mm-empty-hint{padding:22px 16px;text-align:center;color:var(--ink4);font-size:12.5px;line-height:1.9}
|
||||
.mm-actions-2{display:flex;gap:6px;margin-bottom:9px;flex-wrap:wrap}
|
||||
|
||||
/* 行内操作 / 改期 / 新建 */
|
||||
.mm-row-ops{margin-left:auto;display:flex;gap:5px;opacity:0;transition:opacity .12s;flex:none}
|
||||
.mm-row:hover .mm-row-ops,.mm-focus-i:hover .mm-row-ops{opacity:1}
|
||||
.mm-op{height:21px;padding:0 7px;border:1px solid var(--line);border-radius:6px;background:transparent;
|
||||
color:var(--ink3);font-size:11px;cursor:pointer;font-family:inherit;line-height:19px;white-space:nowrap}
|
||||
.mm-op:hover{background:var(--hover);color:var(--ink);border-color:var(--line2)}
|
||||
.mm-op-done:hover{color:var(--ok);border-color:var(--ok)}
|
||||
.mm-op:disabled{opacity:.45;cursor:default}
|
||||
.mm-date-edit{cursor:pointer;border-bottom:1px dashed var(--line2)}
|
||||
.mm-date-edit:hover{color:var(--ink);border-bottom-color:var(--ink3)}
|
||||
.mm-date-in{width:126px;border:1px solid var(--primary);border-radius:6px;padding:1px 4px;
|
||||
font-size:11.5px;font-family:inherit;background:var(--card);color:var(--ink)}
|
||||
.mm-new{margin-top:10px}
|
||||
.mm-new-row{display:flex;gap:8px;flex-wrap:wrap;align-items:center;padding:12px 15px}
|
||||
.mm-in{border:1px solid var(--line);border-radius:var(--r-sm);padding:6px 9px;font-size:12.5px;
|
||||
font-family:inherit;background:var(--bg);color:var(--ink);min-width:0}
|
||||
.mm-in:focus{outline:none;border-color:var(--primary)}
|
||||
.mm-in-t{flex:1;min-width:170px}
|
||||
.mm-in-d{width:142px}
|
||||
.mm-in-s{width:150px}
|
||||
.mm-ok{background:color-mix(in srgb,var(--ok) 10%,transparent);border:1px solid var(--ok);color:var(--ok);
|
||||
border-radius:var(--r-md);padding:9px 13px;font-size:12.5px;margin-bottom:14px}
|
||||
@@ -0,0 +1,434 @@
|
||||
/**
|
||||
* 弹匣工作台 —— DSH 客户端半片(侧边栏面板)。
|
||||
*
|
||||
* 定位:DSH 里「我现在该干什么」+ 就地处理 + 一键跳回弹匣看全貌。
|
||||
* 数据与写操作全部走 /__markmag/*(宿主转调弹匣 API,鉴权用工具凭证)。
|
||||
*
|
||||
* 写操作的规矩:面板只把按钮接到弹匣已有的能力上(tasks_store.cycle / update / create),
|
||||
* 状态机、字段白名单、部门可见性、活动日志、依赖预警全在弹匣侧判定,这里一行规则都不重写。
|
||||
*
|
||||
* 默认个人看板;第二栏的可见范围由弹匣后端 _vis_ok 决定,面板只按角色给名字。
|
||||
* 产物由 scripts/build-client.mjs 从 panel.css + panel.template.js 合成。
|
||||
*/
|
||||
window.__ModuleLoader__.load({
|
||||
id: "dsh-markmag",
|
||||
factory: function (require) {
|
||||
const module = { exports: {} }
|
||||
const exports = module.exports
|
||||
|
||||
const reactMod = require("react")
|
||||
const React = reactMod && reactMod.default ? reactMod.default : reactMod
|
||||
const h = React.createElement
|
||||
const useState = React.useState
|
||||
const useEffect = React.useEffect
|
||||
const useCallback = React.useCallback
|
||||
const useMemo = React.useMemo
|
||||
|
||||
const KEY = "markmag"
|
||||
const BASE = "https://brain.sidaocai.cn/markmag/"
|
||||
const CSS = __CSS_JSON__
|
||||
|
||||
const HEALTH_CLASS = { green: "mm-dot-ok", yellow: "mm-dot-warn", amber: "mm-dot-warn", red: "mm-dot-err" }
|
||||
const HEALTH_TXT = { green: "健康", yellow: "注意", amber: "注意", red: "异常" }
|
||||
const STATUS = {
|
||||
todo: ["待办", "mm-b-todo"],
|
||||
doing: ["进行中", "mm-b-doing"],
|
||||
blocked: ["受阻", "mm-b-blocked"],
|
||||
done: ["已完成", "mm-b-done"],
|
||||
}
|
||||
const FILTERS = [["", "全部"], ["todo", "待办"], ["doing", "进行中"], ["blocked", "受阻"]]
|
||||
|
||||
function pad2(n) { return String(n).padStart(2, "0") }
|
||||
function todayStr() {
|
||||
const d = new Date()
|
||||
return d.getFullYear() + "-" + pad2(d.getMonth() + 1) + "-" + pad2(d.getDate())
|
||||
}
|
||||
function openInMarkmag(hash) { window.open(BASE + (hash || ""), "_blank", "noopener") }
|
||||
|
||||
async function postJson(url, body) {
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
method: "POST",
|
||||
credentials: "same-origin",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify(body || {}),
|
||||
})
|
||||
return await res.json()
|
||||
} catch (e) {
|
||||
return { ok: false, err: "请求失败:" + (e.message || e) }
|
||||
}
|
||||
}
|
||||
|
||||
function Icon(props) {
|
||||
const size = (props && props.size) || 20
|
||||
return h("svg", {
|
||||
width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor",
|
||||
strokeWidth: 1.9, strokeLinecap: "round", strokeLinejoin: "round",
|
||||
},
|
||||
h("rect", { x: 3, y: 4.5, width: 18, height: 15, rx: 2.5 }),
|
||||
h("path", { d: "M7.5 9.5h9" }),
|
||||
h("path", { d: "M7.5 13.5h5.5" })
|
||||
)
|
||||
}
|
||||
|
||||
function Logo() {
|
||||
return h("div", { className: "mm-logo" },
|
||||
h("svg", {
|
||||
width: 17, height: 17, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor",
|
||||
strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round",
|
||||
},
|
||||
h("rect", { x: 3.5, y: 5, width: 17, height: 14, rx: 2.5 }),
|
||||
h("path", { d: "M8 10h8" }),
|
||||
h("path", { d: "M8 14h4.5" })
|
||||
))
|
||||
}
|
||||
|
||||
function Badge(props) {
|
||||
const st = STATUS[props.status] || [props.status || "", "mm-b-todo"]
|
||||
return h("span", { className: "mm-badge " + st[1] }, st[0])
|
||||
}
|
||||
|
||||
function Skeleton() {
|
||||
return [0, 1, 2].map(function (i) {
|
||||
return h("div", { key: i, className: "mm-row" },
|
||||
h("div", { className: "mm-sk", style: { width: (150 + i * 60) + "px" } }))
|
||||
})
|
||||
}
|
||||
|
||||
function Panel() {
|
||||
const sMe = useState(null), me = sMe[0], setMe = sMe[1]
|
||||
const sTasks = useState([]), tasks = sTasks[0], setTasks = sTasks[1]
|
||||
const sProjects = useState([]), projects = sProjects[0], setProjects = sProjects[1]
|
||||
const sErr = useState(""), err = sErr[0], setErr = sErr[1]
|
||||
const sNote = useState(""), note = sNote[0], setNote = sNote[1]
|
||||
const sLoading = useState(true), loading = sLoading[0], setLoading = sLoading[1]
|
||||
const sAt = useState(""), at = sAt[0], setAt = sAt[1]
|
||||
const sTab = useState("mine"), tab = sTab[0], setTab = sTab[1]
|
||||
const sFilter = useState(""), filter = sFilter[0], setFilter = sFilter[1]
|
||||
const sUrgent = useState(false), urgent = sUrgent[0], setUrgent = sUrgent[1]
|
||||
const sBusy = useState(0), busy = sBusy[0], setBusy = sBusy[1]
|
||||
const sEditing = useState(0), editing = sEditing[0], setEditing = sEditing[1]
|
||||
const sNew = useState(false), showNew = sNew[0], setShowNew = sNew[1]
|
||||
const sForm = useState({ title: "", due: "", project: "" }), form = sForm[0], setForm = sForm[1]
|
||||
|
||||
const load = useCallback(function () {
|
||||
setLoading(true)
|
||||
setErr("")
|
||||
Promise.all([
|
||||
fetch("/__markmag/me", { credentials: "same-origin" }).then(function (r) { return r.json() }),
|
||||
fetch("/__markmag/tasks", { credentials: "same-origin" }).then(function (r) { return r.json() }),
|
||||
fetch("/__markmag/projects", { credentials: "same-origin" }).then(function (r) { return r.json() }),
|
||||
]).then(function (res) {
|
||||
const m = res[0], t = res[1], p = res[2]
|
||||
if (m && m.ok && m.result) setMe(m.result)
|
||||
else if (m && !m.ok) throw new Error(m.err || "读取身份失败")
|
||||
setTasks(t && t.ok && t.result && t.result.tasks ? t.result.tasks : [])
|
||||
setProjects(p && p.ok && p.result && p.result.projects ? p.result.projects : [])
|
||||
setAt(new Date().toLocaleTimeString("zh-CN", { hour: "2-digit", minute: "2-digit" }))
|
||||
}).catch(function (e) {
|
||||
setErr(e.message || String(e))
|
||||
}).then(function () {
|
||||
setLoading(false)
|
||||
})
|
||||
}, [])
|
||||
|
||||
useEffect(function () { load() }, [load])
|
||||
|
||||
// ── 写操作:都落到弹匣同一套 store,成功后重新拉一遍 ──
|
||||
async function doToggle(t) {
|
||||
setBusy(t.id); setErr(""); setNote("")
|
||||
const r = await postJson("/__markmag/task/toggle", { id: t.id })
|
||||
setBusy(0)
|
||||
if (r && r.ok) {
|
||||
const st = r.result && r.result.status
|
||||
setNote((st === "done" ? "已完成:" : "状态:" + (STATUS[st] ? STATUS[st][0] : st) + " ") + t.title)
|
||||
load()
|
||||
} else setErr((r && r.err) || "操作失败")
|
||||
}
|
||||
|
||||
async function doSetDue(t, due) {
|
||||
setEditing(0); setErr(""); setNote("")
|
||||
if (!due || due === t.due) return
|
||||
setBusy(t.id)
|
||||
const r = await postJson("/__markmag/task/update", { id: t.id, patch: { due: due } })
|
||||
setBusy(0)
|
||||
if (r && r.ok) { setNote("截止日已改为 " + due + ":" + t.title); load() }
|
||||
else setErr((r && r.err) || "改期失败")
|
||||
}
|
||||
|
||||
async function doCreate() {
|
||||
const title = (form.title || "").trim()
|
||||
if (!title) { setErr("先写个任务标题"); return }
|
||||
setBusy(-1); setErr(""); setNote("")
|
||||
const payload = { title: title }
|
||||
if (form.due) payload.due = form.due
|
||||
if (form.project) payload.project = form.project
|
||||
const r = await postJson("/__markmag/task/create", payload)
|
||||
setBusy(0)
|
||||
if (r && r.ok) {
|
||||
setNote("已建任务:" + title)
|
||||
setForm({ title: "", due: "", project: "" })
|
||||
setShowNew(false)
|
||||
load()
|
||||
} else setErr((r && r.err) || "建任务失败")
|
||||
}
|
||||
|
||||
const today = todayStr()
|
||||
const myName = (me && me.name) || ""
|
||||
const myRole = (me && me.role) || "member"
|
||||
const scopeLabel = myRole === "admin" ? "全团队" : (myRole === "dept_admin" ? "本部门" : "部门可见")
|
||||
|
||||
const mine = useMemo(function () {
|
||||
return tasks.filter(function (t) { return t.owner === myName || t.created_by === myName })
|
||||
}, [tasks, myName])
|
||||
|
||||
const openTasks = useMemo(function () {
|
||||
return tasks.filter(function (t) { return t.status !== "done" })
|
||||
}, [tasks])
|
||||
|
||||
const focus = useMemo(function () {
|
||||
return openTasks.filter(function (t) { return t.due && t.due <= today })
|
||||
.sort(function (a, b) { return a.due < b.due ? -1 : 1 })
|
||||
}, [openTasks, today])
|
||||
|
||||
const overdueCount = useMemo(function () {
|
||||
return openTasks.filter(function (t) { return t.due && t.due < today }).length
|
||||
}, [openTasks, today])
|
||||
|
||||
const base = tab === "mine" ? mine.filter(function (t) { return t.status !== "done" }) : openTasks
|
||||
const shown = useMemo(function () {
|
||||
let list = base
|
||||
if (urgent) list = list.filter(function (t) { return t.due && t.due < today })
|
||||
if (filter) list = list.filter(function (t) { return t.status === filter })
|
||||
return list.slice().sort(function (a, b) {
|
||||
if (!a.due && !b.due) return 0
|
||||
if (!a.due) return 1
|
||||
if (!b.due) return -1
|
||||
return a.due < b.due ? -1 : 1
|
||||
})
|
||||
}, [base, urgent, filter, today])
|
||||
|
||||
/** 一行任务:徽章 + 标题 + 负责人 + 日期(可改)+ hover 操作(完成/改期/去弹匣) */
|
||||
function TaskLine(t) {
|
||||
const late = t.due && t.due < today
|
||||
const isEditing = editing === t.id
|
||||
const ops = h("div", { className: "mm-row-ops" },
|
||||
h("button", {
|
||||
className: "mm-op mm-op-done",
|
||||
disabled: busy === t.id,
|
||||
onClick: function (e) { e.stopPropagation(); doToggle(t) },
|
||||
}, t.status === "done" ? "重开" : "完成"),
|
||||
h("button", {
|
||||
className: "mm-op",
|
||||
onClick: function (e) { e.stopPropagation(); setEditing(isEditing ? 0 : t.id) },
|
||||
}, "改期"),
|
||||
h("button", {
|
||||
className: "mm-op",
|
||||
onClick: function (e) { e.stopPropagation(); openInMarkmag("#today") },
|
||||
}, "弹匣"))
|
||||
const dateEl = isEditing
|
||||
? h("input", {
|
||||
className: "mm-date-in",
|
||||
type: "date",
|
||||
defaultValue: t.due || today,
|
||||
autoFocus: true,
|
||||
onClick: function (e) { e.stopPropagation() },
|
||||
onChange: function (e) { doSetDue(t, e.target.value) },
|
||||
onBlur: function () { setEditing(0) },
|
||||
})
|
||||
: h("span", {
|
||||
className: "mm-date mm-date-edit" + (late ? " mm-date-late" : ""),
|
||||
style: { width: 70, textAlign: "right" },
|
||||
onClick: function (e) { e.stopPropagation(); setEditing(t.id) },
|
||||
}, t.due || "设日期")
|
||||
return h("div", {
|
||||
key: t.id,
|
||||
className: "mm-row mm-row-click",
|
||||
onClick: function () { openInMarkmag("#today") },
|
||||
},
|
||||
h(Badge, { status: t.status }),
|
||||
h("span", { className: "mm-name" }, t.title),
|
||||
h("span", { className: "mm-meta", style: { flex: "none" } }, t.owner || ""),
|
||||
dateEl,
|
||||
ops)
|
||||
}
|
||||
|
||||
const focusEl = focus.length
|
||||
? h("div", { className: "mm-focus" },
|
||||
h("div", { className: "mm-focus-h" },
|
||||
h("span", { className: "mm-focus-t" },
|
||||
overdueCount ? "要处理:" + overdueCount + " 项已逾期" : "今天到期"),
|
||||
h("span", { className: "mm-focus-c" }, "可直接完成或改期")),
|
||||
focus.slice(0, 6).map(function (t) { return TaskLine(t) }))
|
||||
: null
|
||||
|
||||
const statsEl = h("div", { className: "mm-stats" },
|
||||
h("div", { className: "mm-stat", style: { cursor: "pointer" },
|
||||
onClick: function () { setTab("scope"); setUrgent(false); setFilter("") } },
|
||||
h("div", { className: "mm-stat-n" }, String(mine.filter(function (t) { return t.status !== "done" }).length)),
|
||||
h("div", { className: "mm-stat-l" }, "我的未完成")),
|
||||
h("div", { className: "mm-stat", style: { cursor: "pointer" },
|
||||
onClick: function () { setTab("scope"); setUrgent(true); setFilter("") } },
|
||||
h("div", { className: "mm-stat-n", style: overdueCount ? { color: "var(--err)" } : null }, String(overdueCount)),
|
||||
h("div", { className: "mm-stat-l" }, "已逾期")),
|
||||
h("div", { className: "mm-stat", style: { cursor: "pointer" },
|
||||
onClick: function () { openInMarkmag("#proj") } },
|
||||
h("div", { className: "mm-stat-n" }, String(projects.length)),
|
||||
h("div", { className: "mm-stat-l" }, "项目")))
|
||||
|
||||
const tabsEl = h("div", { className: "mm-actions-2" },
|
||||
[["mine", "我的"], ["scope", scopeLabel]].map(function (item) {
|
||||
const k = item[0], label = item[1]
|
||||
return h("button", {
|
||||
key: k,
|
||||
className: "mm-tab" + (tab === k ? " mm-tab-on" : ""),
|
||||
onClick: function () { setTab(k); setUrgent(false) },
|
||||
}, label)
|
||||
}),
|
||||
h("span", { style: { flex: 1 } }),
|
||||
urgent ? h("button", { className: "mm-tab mm-tab-on", onClick: function () { setUrgent(false) } }, "只看逾期 ×") : null)
|
||||
|
||||
const filtersEl = h("div", { className: "mm-actions-2" },
|
||||
FILTERS.map(function (f) {
|
||||
const v = f[0], label = f[1]
|
||||
return h("button", {
|
||||
key: "f" + v,
|
||||
className: "mm-tab" + (filter === v ? " mm-tab-on" : ""),
|
||||
onClick: function () { setFilter(v) },
|
||||
}, label)
|
||||
}))
|
||||
|
||||
const taskRows = shown.length
|
||||
? shown.map(function (t) { return TaskLine(t) })
|
||||
: (loading
|
||||
? h(Skeleton)
|
||||
: h("div", { className: "mm-empty-hint" },
|
||||
tab === "mine" ? "你手上没有到期任务" : "这个范围里没有任务"))
|
||||
|
||||
const projectOptions = projects.map(function (p) {
|
||||
return h("option", { key: p.id, value: p.id }, p.name)
|
||||
})
|
||||
|
||||
const newEl = h("div", { className: "mm-new" },
|
||||
showNew
|
||||
? h("div", { className: "mm-card" },
|
||||
h("div", { className: "mm-new-row" },
|
||||
h("input", {
|
||||
className: "mm-in mm-in-t",
|
||||
placeholder: "任务标题",
|
||||
value: form.title,
|
||||
autoFocus: true,
|
||||
onChange: function (e) { setForm(Object.assign({}, form, { title: e.target.value })) },
|
||||
onKeyDown: function (e) { if (e.key === "Enter") doCreate() },
|
||||
}),
|
||||
h("input", {
|
||||
className: "mm-in mm-in-d",
|
||||
type: "date",
|
||||
value: form.due,
|
||||
onChange: function (e) { setForm(Object.assign({}, form, { due: e.target.value })) },
|
||||
}),
|
||||
h("select", {
|
||||
className: "mm-in mm-in-s",
|
||||
value: form.project,
|
||||
onChange: function (e) { setForm(Object.assign({}, form, { project: e.target.value })) },
|
||||
}, h("option", { value: "" }, "不挂项目"), projectOptions),
|
||||
h("button", {
|
||||
className: "mm-btn mm-btn-primary",
|
||||
disabled: busy === -1,
|
||||
onClick: doCreate,
|
||||
}, busy === -1 ? "提交中…" : "建任务"),
|
||||
h("button", { className: "mm-btn", onClick: function () { setShowNew(false) } }, "取消")))
|
||||
: h("button", {
|
||||
className: "mm-btn",
|
||||
style: { width: "100%" },
|
||||
onClick: function () { setShowNew(true); setNote("") },
|
||||
}, "+ 快速建任务"))
|
||||
|
||||
const projectCards = projects.length
|
||||
? projects.map(function (p, i) {
|
||||
const key = String(p.health || "").toLowerCase()
|
||||
const pct = typeof p.progress === "number" ? Math.max(0, Math.min(100, p.progress)) : null
|
||||
return h("div", {
|
||||
key: p.id || i,
|
||||
className: "mm-pcard",
|
||||
onClick: function () { openInMarkmag(p.id ? "#d/" + p.id : "#proj") },
|
||||
},
|
||||
h("div", { className: "mm-pcard-n" }, p.name),
|
||||
h("div", { className: "mm-pcard-m" },
|
||||
h("span", { className: "mm-dot " + (HEALTH_CLASS[key] || "mm-dot-idle") }),
|
||||
h("span", null, HEALTH_TXT[key] || "—"),
|
||||
p.stage ? h("span", null, "· " + p.stage) : null,
|
||||
p.owner ? h("span", null, "· " + p.owner) : null),
|
||||
pct === null ? null : h("div", { className: "mm-bar" },
|
||||
h("div", { className: "mm-bar-i", style: { width: pct + "%" } })))
|
||||
})
|
||||
: h("div", { className: "mm-pcard" },
|
||||
h("div", { className: "mm-pcard-n" }, loading ? "读取中…" : "还没有项目"))
|
||||
|
||||
const identity = me
|
||||
? myName + (myRole === "admin" ? " · 团队负责人" : myRole === "dept_admin" ? " · 部门负责人" : "")
|
||||
: ""
|
||||
|
||||
return h("div", { className: "mm-wrap" },
|
||||
h("style", { dangerouslySetInnerHTML: { __html: CSS } }),
|
||||
h("div", { className: "mm-inner" },
|
||||
h("div", { className: "mm-head" },
|
||||
h(Logo),
|
||||
h("div", null,
|
||||
h("div", { className: "mm-title" }, "弹匣工作台"),
|
||||
h("div", { className: "mm-sub" }, identity || (at ? "数据更新于 " + at : "四道菜 · 团队作战台"))),
|
||||
h("div", { className: "mm-actions" },
|
||||
h("button", { className: "mm-btn", onClick: load, disabled: loading },
|
||||
loading ? "读取中…" : "刷新"),
|
||||
h("button", {
|
||||
className: "mm-btn mm-btn-primary",
|
||||
onClick: function () { openInMarkmag("#today") },
|
||||
}, "弹匣全貌"))),
|
||||
|
||||
err ? h("div", { className: "mm-err" }, err) : null,
|
||||
note ? h("div", { className: "mm-ok" }, note) : null,
|
||||
focusEl,
|
||||
statsEl,
|
||||
|
||||
h("div", { className: "mm-sec" },
|
||||
h("div", { className: "mm-sec-h" },
|
||||
h("span", { className: "mm-sec-t" }, "任务"),
|
||||
h("span", { className: "mm-sec-c" }, String(shown.length))),
|
||||
tabsEl,
|
||||
filtersEl,
|
||||
h("div", { className: "mm-card" }, taskRows),
|
||||
newEl),
|
||||
|
||||
h("div", { className: "mm-sec" },
|
||||
h("div", { className: "mm-sec-h" },
|
||||
h("span", { className: "mm-sec-t" }, "项目"),
|
||||
h("span", { className: "mm-sec-c" }, String(projects.length))),
|
||||
h("div", { className: "mm-grid" }, projectCards)),
|
||||
|
||||
h("div", { className: "mm-foot" }, "悬停任务行可完成 / 改期 · 写操作与弹匣同一套规则")))
|
||||
}
|
||||
|
||||
function apply(ctx) {
|
||||
ctx.slots.inject("main", function () {
|
||||
return ctx.slots.register({ name: "main", key: KEY }, Panel)
|
||||
})
|
||||
ctx.effect(function () {
|
||||
let dispose = null
|
||||
function mount() {
|
||||
if (dispose) dispose()
|
||||
dispose = ctx.slots.inject("sidebar.panellist", function () {
|
||||
return ctx.slots.register(
|
||||
{ name: "sidebar.panellist", id: KEY, order: 6, label: function () { return "弹匣工作台" } },
|
||||
Icon
|
||||
)
|
||||
})
|
||||
}
|
||||
mount()
|
||||
return function () { if (dispose) dispose() }
|
||||
}, "dsh-markmag: sidebar entry")
|
||||
}
|
||||
|
||||
module.exports = { inject: ["slots"], apply: apply }
|
||||
return module.exports
|
||||
},
|
||||
})
|
||||
Reference in new issue
Block a user