Files
F9Web/server/scripts/seed-im.mjs
T
fanhongcai 1bec470647 feat: 新增IM即时通讯(浮窗)、工作流、打印模块及工作台增强
- IM: 新增浮窗聊天(ImFloatWindow)、管理页(monitor/config/service/message)、SSE推送
- 工作流: 新增待办/我的流程页面及后端服务
- 打印: 新增打印模板、出库单打印(PrintPage)、模板种子脚本
- 工作台: 增强快捷入口与工作台数据
- 修复: TagsView页签关闭、CrudPage通用表格增强
- 移除导航菜单中的即时通讯入口,改为右下角浮窗
2026-08-16 00:19:24 +08:00

65 lines
2.4 KiB
JavaScript

/**
* 轻量 IM 种子:
* 1) 发几条演示系统通知(工单变更/工艺单变更/审批通知)
* ⚠️ 说明:原「协作 → 即时通讯」菜单已移除(聊天入口改为右下角浮窗,见 layout 的 ImFloatWindow),
* 本脚本不再创建该菜单,仅保留演示通知功能。
* 用法:node server/scripts/seed-im.mjs
*/
const BASE = process.env.F9MES_API || 'http://localhost:5136';
const PHONE = '13800000000';
const PASSWORD = '123456';
const ME_ID = 1;
async function api(h, method, url, body) {
const res = await fetch(BASE + url, {
method,
headers: h,
body: body ? JSON.stringify(body) : undefined,
});
const text = await res.text();
let json = null;
try { json = JSON.parse(text); } catch { /* ignore */ }
if (!res.ok || (json && json.code !== 0)) {
throw new Error(`HTTP ${res.status} ${url}: ${text.slice(0, 300)}`);
}
return json;
}
async function main() {
const login = await api({ 'Content-Type': 'application/json' }, 'POST', '/api/auth/login', {
phone: PHONE,
password: PASSWORD,
});
const token = login.data.token;
const h = { Authorization: 'Bearer ' + token, 'Content-Type': 'application/json' };
// ============ 1. 演示系统通知 ============
const demos = [
{ title: '工单变更', content: '任务工单 GD-20260815-003 的排产时间由 08:30 调整为 09:30,请注意查看。', msgType: 1 },
{ title: '工艺单变更', content: '工艺庄口「四川凉山-2026春茧」工艺参数已更新:缫丝车速 95r/min → 100r/min。', msgType: 1 },
{ title: '审批通知', content: '您有 1 条原料出库审批待办(CK-20260815-002),请及时处理。', msgType: 2 },
];
for (const d of demos) {
const r = await api(h, 'POST', '/api/im/notify', {
userIds: [ME_ID],
msgType: d.msgType,
title: d.title,
content: d.content,
});
console.log('通知「' + d.title + '」已发送(' + r.data + ' 条)');
}
// ============ 2. 验证 ============
const unread = await api(h, 'GET', '/api/im/unread-count');
console.log('当前未读数:' + unread.data);
const sessions = await api(h, 'GET', '/api/im/sessions');
console.log('会话数:' + (sessions.data || []).length);
console.log('\n完成。演示通知已就绪。');
}
main().catch((e) => {
console.error('ERR: ' + e.message);
process.exit(1);
});