feat: MVP v0.5 complete - All P0 features implemented and frontend verified. Backend API structure ready, pending final ES module configuration for deployment.
This commit is contained in:
144
dist-server/lib/decision-cards.js
Normal file
144
dist-server/lib/decision-cards.js
Normal file
@@ -0,0 +1,144 @@
|
||||
"use strict";
|
||||
/**
|
||||
* 决策交互卡片
|
||||
* 飞书消息卡片格式 + 回调处理
|
||||
*/
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DECISION_TEMPLATES = void 0;
|
||||
exports.buildDecisionCard = buildDecisionCard;
|
||||
exports.createDecision = createDecision;
|
||||
exports.handleDecisionCallback = handleDecisionCallback;
|
||||
exports.getPendingDecisions = getPendingDecisions;
|
||||
/**
|
||||
* 生成飞书消息卡片JSON
|
||||
*/
|
||||
function buildDecisionCard(card) {
|
||||
var elements = [
|
||||
{
|
||||
tag: 'div',
|
||||
text: { tag: 'plain_text', content: card.description },
|
||||
},
|
||||
];
|
||||
// Action buttons
|
||||
var actions = card.options.map(function (opt) { return ({
|
||||
tag: 'button',
|
||||
text: { tag: 'plain_text', content: opt.label },
|
||||
type: opt.style === 'danger' ? 'danger' : opt.style === 'primary' ? 'primary' : 'default',
|
||||
value: __assign({ action: opt.key }, card.metadata),
|
||||
}); });
|
||||
elements.push({ tag: 'action', actions: actions });
|
||||
return {
|
||||
msg_type: 'interactive',
|
||||
card: {
|
||||
header: {
|
||||
title: { tag: 'plain_text', content: card.title },
|
||||
template: 'blue',
|
||||
},
|
||||
elements: elements,
|
||||
},
|
||||
};
|
||||
}
|
||||
var pendingDecisions = new Map();
|
||||
/**
|
||||
* 创建决策请求
|
||||
*/
|
||||
function createDecision(card) {
|
||||
var id = "decision-".concat(Date.now());
|
||||
var record = {
|
||||
id: id,
|
||||
cardTitle: card.title,
|
||||
type: card.type,
|
||||
options: card.options.map(function (o) { return o.key; }),
|
||||
chosenOption: null,
|
||||
status: 'pending',
|
||||
createdAt: new Date().toISOString(),
|
||||
};
|
||||
pendingDecisions.set(id, record);
|
||||
return record;
|
||||
}
|
||||
/**
|
||||
* 处理决策回调
|
||||
*/
|
||||
function handleDecisionCallback(decisionId, actionKey) {
|
||||
var record = pendingDecisions.get(decisionId);
|
||||
if (!record) {
|
||||
return { ok: false, error: 'Decision not found' };
|
||||
}
|
||||
if (record.status !== 'pending') {
|
||||
return { ok: false, error: 'Already responded' };
|
||||
}
|
||||
record.chosenOption = actionKey;
|
||||
record.status = 'responded';
|
||||
record.respondedAt = new Date().toISOString();
|
||||
return { ok: true, record: record };
|
||||
}
|
||||
/**
|
||||
* 获取待决策列表
|
||||
*/
|
||||
function getPendingDecisions() {
|
||||
return Array.from(pendingDecisions.values()).filter(function (d) { return d.status === 'pending'; });
|
||||
}
|
||||
/**
|
||||
* 预定义的决策卡片模板
|
||||
*/
|
||||
exports.DECISION_TEMPLATES = {
|
||||
/** 章程审批 */
|
||||
charterApproval: function (projectName) { return ({
|
||||
title: '📋 项目章程审批',
|
||||
description: "\u9879\u76EE\u300C".concat(projectName, "\u300D\u7684\u7AE0\u7A0B\u5DF2\u751F\u6210\uFF0C\u8BF7\u5BA1\u6279\u3002"),
|
||||
type: 'approve_reject',
|
||||
options: [
|
||||
{ key: 'approve', label: '✅ 批准', style: 'primary', value: 'approved' },
|
||||
{ key: 'reject', label: '❌ 驳回', style: 'danger', value: 'rejected' },
|
||||
{ key: 'revise', label: '✏️ 需修改', value: 'needs_revision' },
|
||||
],
|
||||
metadata: { type: 'charter', project: projectName },
|
||||
}); },
|
||||
/** 风险应对 */
|
||||
riskResponse: function (riskDesc, priority) { return ({
|
||||
title: "\u26A0\uFE0F \u98CE\u9669\u5E94\u5BF9\u51B3\u7B56\uFF08\u4F18\u5148\u7EA7".concat(priority, "\uFF09"),
|
||||
description: riskDesc,
|
||||
type: 'multi_choice',
|
||||
options: [
|
||||
{ key: 'avoid', label: '🛡 规避', value: 'avoid' },
|
||||
{ key: 'transfer', label: '🔄 转移', value: 'transfer' },
|
||||
{ key: 'mitigate', label: '🔧 减轻', value: 'mitigate' },
|
||||
{ key: 'accept', label: '✅ 接受', value: 'accept' },
|
||||
],
|
||||
metadata: { type: 'risk', priority: priority },
|
||||
}); },
|
||||
/** 变更审批 */
|
||||
changeApproval: function (changeDesc) { return ({
|
||||
title: '🔀 变更请求审批',
|
||||
description: changeDesc,
|
||||
type: 'approve_reject',
|
||||
options: [
|
||||
{ key: 'approve', label: '✅ 批准', style: 'primary', value: 'approved' },
|
||||
{ key: 'reject', label: '❌ 拒绝', style: 'danger', value: 'rejected' },
|
||||
{ key: 'defer', label: '⏳ 延后', value: 'deferred' },
|
||||
],
|
||||
metadata: { type: 'change' },
|
||||
}); },
|
||||
/** 里程碑确认 */
|
||||
milestoneConfirm: function (name, date) { return ({
|
||||
title: "\uD83C\uDFC1 \u91CC\u7A0B\u7891\u8FBE\u6210\u786E\u8BA4",
|
||||
description: "\u91CC\u7A0B\u7891\u300C".concat(name, "\u300D\uFF08\u76EE\u6807\uFF1A").concat(date, "\uFF09\u662F\u5426\u5DF2\u8FBE\u6210\uFF1F"),
|
||||
type: 'confirm',
|
||||
options: [
|
||||
{ key: 'done', label: '✅ 已达成', style: 'primary', value: 'reached' },
|
||||
{ key: 'missed', label: '❌ 未达成', style: 'danger', value: 'missed' },
|
||||
],
|
||||
metadata: { type: 'milestone', name: name, date: date },
|
||||
}); },
|
||||
};
|
||||
Reference in New Issue
Block a user