GET-CHAT-URL.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #!/usr/bin/env node
  2. /**
  3. * 会话激活页面测试地址获取脚本
  4. * 使用方法:
  5. * 1. 在浏览器访问 http://localhost:4200
  6. * 2. 打开控制台(F12)
  7. * 3. 复制下面的代码并运行
  8. */
  9. console.log('\n🚀 会话激活页面测试地址获取工具\n');
  10. console.log('=' .repeat(60));
  11. console.log('\n📋 您的配置信息:');
  12. console.log(' 公司ID (cid): cDL6R1hgSi');
  13. console.log(' 用户ID: woAs2qCQAAGQckyg7AQBxhMEoSwnlTvg');
  14. console.log('\n' + '='.repeat(60));
  15. console.log('\n📝 步骤1:启动项目');
  16. console.log(' cd yss-project');
  17. console.log(' npm start');
  18. console.log('\n📝 步骤2:打开浏览器');
  19. console.log(' 访问: http://localhost:4200');
  20. console.log('\n📝 步骤3:打开控制台(按F12)');
  21. console.log('\n📝 步骤4:复制并运行以下代码:');
  22. console.log('\n' + '-'.repeat(60));
  23. const script = `
  24. (async () => {
  25. try {
  26. // 配置信息
  27. const cid = 'cDL6R1hgSi';
  28. const userid = 'woAs2qCQAAGQckyg7AQBxhMEoSwnlTvg';
  29. // 设置localStorage
  30. localStorage.setItem('company', cid);
  31. localStorage.setItem(\`\${cid}/USERINFO\`, JSON.stringify({
  32. userid: userid,
  33. errcode: 0,
  34. errmsg: 'ok',
  35. cid: cid
  36. }));
  37. console.log('✅ localStorage配置成功');
  38. // 导入Parse
  39. const { FmodeParse } = await import('fmode-ng/parse');
  40. const Parse = FmodeParse.with('nova');
  41. // 查询群聊
  42. const query = new Parse.Query('GroupChat');
  43. query.equalTo('company', { __type: 'Pointer', className: 'Company', objectId: cid });
  44. query.include('project');
  45. query.descending('createdAt');
  46. query.limit(10);
  47. const chats = await query.find();
  48. if (chats.length > 0) {
  49. console.log(\`\\n✅ 找到 \${chats.length} 个群聊:\\n\`);
  50. chats.forEach((chat, i) => {
  51. const url = \`http://localhost:4200/wxwork/\${cid}/chat-activation/\${chat.id}\`;
  52. const name = chat.get('name') || '未命名';
  53. const project = chat.get('project');
  54. const projectName = project ? project.get('title') : '无项目';
  55. console.log(\`\${i + 1}. \${name}\`);
  56. console.log(\` 项目: \${projectName}\`);
  57. console.log(\` 🔗 \${url}\\n\`);
  58. });
  59. // 复制第一个
  60. const firstUrl = \`http://localhost:4200/wxwork/\${cid}/chat-activation/\${chats[0].id}\`;
  61. await navigator.clipboard.writeText(firstUrl);
  62. alert(\`✅ 已复制第一个群聊地址!\\n\\n\${chats[0].get('name')}\\n\\n\${firstUrl}\\n\\n点击确定后自动打开...\`);
  63. setTimeout(() => window.open(firstUrl, '_blank'), 500);
  64. } else {
  65. console.log('⚠️ 未找到群聊,正在创建测试数据...');
  66. // 创建测试群聊
  67. const GroupChat = Parse.Object.extend('GroupChat');
  68. const testChat = new GroupChat();
  69. testChat.set('name', '测试群聊 - ' + new Date().toLocaleString('zh-CN'));
  70. testChat.set('company', { __type: 'Pointer', className: 'Company', objectId: cid });
  71. testChat.set('chat_id', 'test_chat_' + Date.now());
  72. testChat.set('member_list', [
  73. { type: 1, userid: 'tech_001', name: '技术员-张三', avatar: '' },
  74. { type: 2, userid: 'customer_001', name: '客户-李四', avatar: '' },
  75. { type: 2, userid: 'customer_002', name: '客户-王五', avatar: '' }
  76. ]);
  77. testChat.set('messages', [
  78. { msgid: 'msg_001', from: 'customer_001', msgtime: Math.floor(Date.now() / 1000) - 3600, msgtype: 'text', text: { content: '你好,我想咨询一下项目进度' } },
  79. { msgid: 'msg_002', from: 'tech_001', msgtime: Math.floor(Date.now() / 1000) - 3500, msgtype: 'text', text: { content: '您好,项目正在进行中,预计本周完成' } },
  80. { msgid: 'msg_003', from: 'customer_001', msgtime: Math.floor(Date.now() / 1000) - 700, msgtype: 'text', text: { content: '可以帮我修改一下需求吗?' } },
  81. { msgid: 'msg_004', from: 'customer_002', msgtime: Math.floor(Date.now() / 1000) - 300, msgtype: 'text', text: { content: '设计稿什么时候能出来?' } }
  82. ]);
  83. const saved = await testChat.save();
  84. const url = \`http://localhost:4200/wxwork/\${cid}/chat-activation/\${saved.id}\`;
  85. console.log(\`\\n✅ 测试群聊创建成功!\`);
  86. console.log(\`群聊名称: \${saved.get('name')}\`);
  87. console.log(\`群聊ID: \${saved.id}\`);
  88. console.log(\`🔗 \${url}\\n\`);
  89. await navigator.clipboard.writeText(url);
  90. alert(\`✅ 测试群聊已创建!地址已复制\\n\\n\${url}\\n\\n点击确定后自动打开...\`);
  91. setTimeout(() => window.open(url, '_blank'), 500);
  92. }
  93. } catch (e) {
  94. console.error('❌ 错误:', e);
  95. alert('❌ 发生错误: ' + e.message + '\\n\\n请确保:\\n1. 项目已启动\\n2. Parse Server已连接');
  96. }
  97. })();
  98. `.trim();
  99. console.log(script);
  100. console.log('\n' + '-'.repeat(60));
  101. console.log('\n✨ 功能说明:');
  102. console.log(' • 自动配置localStorage');
  103. console.log(' • 查找现有群聊或创建测试群聊');
  104. console.log(' • 自动复制URL到剪贴板');
  105. console.log(' • 自动打开测试页面');
  106. console.log('\n📱 URL格式:');
  107. console.log(' http://localhost:4200/wxwork/cDL6R1hgSi/chat-activation/{群聊ID}');
  108. console.log('\n🎯 测试群聊包含:');
  109. console.log(' • 3个成员(1个技术员 + 2个客户)');
  110. console.log(' • 4条消息(包含1条超时未回复)');
  111. console.log(' • 完整的测试数据');
  112. console.log('\n' + '='.repeat(60));
  113. console.log('\n💡 提示:也可以打开 GET-CHAT-ACTIVATION-TEST-URL.html 使用可视化工具\n');