CREATE-TEST-GROUPCHAT.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>创建测试群聊记录</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. box-sizing: border-box;
  12. }
  13. body {
  14. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  15. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  16. min-height: 100vh;
  17. display: flex;
  18. align-items: center;
  19. justify-content: center;
  20. padding: 20px;
  21. }
  22. .container {
  23. background: white;
  24. border-radius: 20px;
  25. box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  26. padding: 40px;
  27. max-width: 600px;
  28. width: 100%;
  29. }
  30. h1 {
  31. color: #333;
  32. margin-bottom: 10px;
  33. font-size: 28px;
  34. }
  35. .subtitle {
  36. color: #666;
  37. margin-bottom: 30px;
  38. font-size: 14px;
  39. }
  40. .info-box {
  41. background: #f8f9fa;
  42. border-left: 4px solid #667eea;
  43. padding: 15px;
  44. margin-bottom: 20px;
  45. border-radius: 4px;
  46. }
  47. .info-box h3 {
  48. color: #667eea;
  49. margin-bottom: 10px;
  50. font-size: 16px;
  51. }
  52. .info-box p {
  53. color: #666;
  54. font-size: 14px;
  55. line-height: 1.6;
  56. margin: 5px 0;
  57. }
  58. .info-box code {
  59. background: #e9ecef;
  60. padding: 2px 6px;
  61. border-radius: 3px;
  62. font-family: 'Courier New', monospace;
  63. font-size: 13px;
  64. color: #d63384;
  65. }
  66. button {
  67. width: 100%;
  68. padding: 15px;
  69. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  70. color: white;
  71. border: none;
  72. border-radius: 10px;
  73. font-size: 16px;
  74. font-weight: 600;
  75. cursor: pointer;
  76. transition: transform 0.2s, box-shadow 0.2s;
  77. margin-bottom: 15px;
  78. }
  79. button:hover {
  80. transform: translateY(-2px);
  81. box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
  82. }
  83. button:active {
  84. transform: translateY(0);
  85. }
  86. button:disabled {
  87. opacity: 0.6;
  88. cursor: not-allowed;
  89. transform: none;
  90. }
  91. .btn-secondary {
  92. background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  93. }
  94. .btn-success {
  95. background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  96. }
  97. .result {
  98. margin-top: 20px;
  99. padding: 15px;
  100. border-radius: 10px;
  101. display: none;
  102. animation: slideIn 0.3s ease-out;
  103. }
  104. @keyframes slideIn {
  105. from {
  106. opacity: 0;
  107. transform: translateY(-10px);
  108. }
  109. to {
  110. opacity: 1;
  111. transform: translateY(0);
  112. }
  113. }
  114. .result.success {
  115. background: #d4edda;
  116. border: 1px solid #c3e6cb;
  117. color: #155724;
  118. display: block;
  119. }
  120. .result.error {
  121. background: #f8d7da;
  122. border: 1px solid #f5c6cb;
  123. color: #721c24;
  124. display: block;
  125. }
  126. .result h3 {
  127. margin-bottom: 10px;
  128. font-size: 16px;
  129. }
  130. .result p {
  131. margin: 5px 0;
  132. font-size: 14px;
  133. line-height: 1.6;
  134. }
  135. .result a {
  136. color: #0056b3;
  137. text-decoration: none;
  138. word-break: break-all;
  139. font-weight: 600;
  140. }
  141. .result a:hover {
  142. text-decoration: underline;
  143. }
  144. .loading {
  145. display: none;
  146. text-align: center;
  147. padding: 20px;
  148. }
  149. .loading.active {
  150. display: block;
  151. }
  152. .spinner {
  153. border: 3px solid #f3f3f3;
  154. border-top: 3px solid #667eea;
  155. border-radius: 50%;
  156. width: 40px;
  157. height: 40px;
  158. animation: spin 1s linear infinite;
  159. margin: 0 auto 10px;
  160. }
  161. @keyframes spin {
  162. 0% { transform: rotate(0deg); }
  163. 100% { transform: rotate(360deg); }
  164. }
  165. </style>
  166. </head>
  167. <body>
  168. <div class="container">
  169. <h1>🚀 创建测试群聊记录</h1>
  170. <p class="subtitle">在Parse数据库中创建群聊记录,用于测试会话激活页面</p>
  171. <div class="info-box">
  172. <h3>📋 你的企微信息</h3>
  173. <p><strong>公司ID (cid):</strong> <code>cDL6R1hgSi</code></p>
  174. <p><strong>用户ID (userid):</strong> <code>woAs2qCQAAGQckyg7AQBxhMEoSwnlTvg</code></p>
  175. <p><strong>群聊ID (chat_id):</strong> <code>wrgKCxBwAALwOgUC9jMwdHiVTFmyXs_A</code></p>
  176. </div>
  177. <button onclick="createGroupChat()" id="createBtn">
  178. 📝 创建群聊记录
  179. </button>
  180. <button onclick="queryExisting()" id="queryBtn" class="btn-secondary">
  181. 🔍 查询现有记录
  182. </button>
  183. <button onclick="openTestPage()" id="openBtn" class="btn-success" disabled>
  184. 🌐 打开测试页面
  185. </button>
  186. <div class="loading" id="loading">
  187. <div class="spinner"></div>
  188. <p>处理中...</p>
  189. </div>
  190. <div class="result" id="result"></div>
  191. </div>
  192. <script type="module">
  193. const CONFIG = {
  194. cid: 'cDL6R1hgSi',
  195. userid: 'woAs2qCQAAGQckyg7AQBxhMEoSwnlTvg',
  196. wxworkChatId: 'wrgKCxBwAALwOgUC9jMwdHiVTFmyXs_A'
  197. };
  198. let currentGroupChatId = null;
  199. // 配置localStorage
  200. function setupLocalStorage() {
  201. localStorage.setItem('company', CONFIG.cid);
  202. localStorage.setItem(`${CONFIG.cid}/USERINFO`, JSON.stringify({
  203. userid: CONFIG.userid,
  204. errcode: 0,
  205. errmsg: 'ok',
  206. cid: CONFIG.cid
  207. }));
  208. console.log('✅ localStorage配置成功');
  209. }
  210. // 显示结果
  211. function showResult(type, title, content) {
  212. const resultDiv = document.getElementById('result');
  213. resultDiv.className = `result ${type}`;
  214. resultDiv.innerHTML = `<h3>${title}</h3>${content}`;
  215. }
  216. // 显示加载
  217. function showLoading(show) {
  218. document.getElementById('loading').className = show ? 'loading active' : 'loading';
  219. document.getElementById('createBtn').disabled = show;
  220. document.getElementById('queryBtn').disabled = show;
  221. }
  222. // 查询现有记录
  223. window.queryExisting = async function() {
  224. try {
  225. showLoading(true);
  226. setupLocalStorage();
  227. const { FmodeParse } = await import('fmode-ng/parse');
  228. const Parse = FmodeParse.with('nova');
  229. console.log('🔍 查询现有群聊记录...');
  230. const query = new Parse.Query('GroupChat');
  231. query.equalTo('chat_id', CONFIG.wxworkChatId);
  232. query.equalTo('company', { __type: 'Pointer', className: 'Company', objectId: CONFIG.cid });
  233. query.include('project');
  234. const groupChat = await query.first();
  235. if (groupChat) {
  236. currentGroupChatId = groupChat.id;
  237. document.getElementById('openBtn').disabled = false;
  238. const url = `http://localhost:4200/wxwork/${CONFIG.cid}/chat-activation/${groupChat.id}`;
  239. showResult('success', '✅ 找到现有记录!', `
  240. <p><strong>群聊名称:</strong> ${groupChat.get('name') || '未命名'}</p>
  241. <p><strong>Parse ID:</strong> ${groupChat.id}</p>
  242. <p><strong>企微 chat_id:</strong> ${groupChat.get('chat_id')}</p>
  243. <p><strong>成员数量:</strong> ${(groupChat.get('member_list') || []).length}</p>
  244. <p><strong>测试地址:</strong></p>
  245. <p><a href="${url}" target="_blank">${url}</a></p>
  246. <p style="margin-top: 10px; color: #666;">点击上方"打开测试页面"按钮或直接点击链接</p>
  247. `);
  248. console.log('✅ 找到群聊:', groupChat.toJSON());
  249. } else {
  250. showResult('error', '⚠️ 未找到记录', `
  251. <p>Parse数据库中没有该群聊记录</p>
  252. <p>请点击"创建群聊记录"按钮创建新记录</p>
  253. `);
  254. }
  255. } catch (error) {
  256. console.error('❌ 查询失败:', error);
  257. showResult('error', '❌ 查询失败', `
  258. <p>${error.message}</p>
  259. <p>请确保项目已启动且Parse Server已连接</p>
  260. `);
  261. } finally {
  262. showLoading(false);
  263. }
  264. };
  265. // 创建群聊记录
  266. window.createGroupChat = async function() {
  267. try {
  268. showLoading(true);
  269. setupLocalStorage();
  270. const { FmodeParse } = await import('fmode-ng/parse');
  271. const Parse = FmodeParse.with('nova');
  272. console.log('📝 创建群聊记录...');
  273. // 先检查是否已存在
  274. const existQuery = new Parse.Query('GroupChat');
  275. existQuery.equalTo('chat_id', CONFIG.wxworkChatId);
  276. existQuery.equalTo('company', { __type: 'Pointer', className: 'Company', objectId: CONFIG.cid });
  277. const existing = await existQuery.first();
  278. if (existing) {
  279. currentGroupChatId = existing.id;
  280. document.getElementById('openBtn').disabled = false;
  281. const url = `http://localhost:4200/wxwork/${CONFIG.cid}/chat-activation/${existing.id}`;
  282. showResult('success', '✅ 记录已存在!', `
  283. <p>该群聊记录已存在,无需重复创建</p>
  284. <p><strong>群聊名称:</strong> ${existing.get('name') || '未命名'}</p>
  285. <p><strong>Parse ID:</strong> ${existing.id}</p>
  286. <p><strong>测试地址:</strong></p>
  287. <p><a href="${url}" target="_blank">${url}</a></p>
  288. `);
  289. return;
  290. }
  291. // 创建新记录
  292. const GroupChat = Parse.Object.extend('GroupChat');
  293. const newGroupChat = new GroupChat();
  294. newGroupChat.set('chat_id', CONFIG.wxworkChatId);
  295. newGroupChat.set('name', '测试群聊 - ' + new Date().toLocaleString('zh-CN'));
  296. newGroupChat.set('company', { __type: 'Pointer', className: 'Company', objectId: CONFIG.cid });
  297. newGroupChat.set('member_list', [
  298. {
  299. userid: CONFIG.userid,
  300. type: 1,
  301. join_time: Math.floor(Date.now() / 1000),
  302. join_scene: 1
  303. }
  304. ]);
  305. newGroupChat.set('data', {
  306. createdFrom: 'test-html',
  307. createdAt: new Date(),
  308. wxworkChatId: CONFIG.wxworkChatId,
  309. note: '通过测试页面创建'
  310. });
  311. const savedGroupChat = await newGroupChat.save();
  312. currentGroupChatId = savedGroupChat.id;
  313. document.getElementById('openBtn').disabled = false;
  314. const url = `http://localhost:4200/wxwork/${CONFIG.cid}/chat-activation/${savedGroupChat.id}`;
  315. showResult('success', '✅ 创建成功!', `
  316. <p><strong>群聊名称:</strong> ${savedGroupChat.get('name')}</p>
  317. <p><strong>Parse ID:</strong> ${savedGroupChat.id}</p>
  318. <p><strong>企微 chat_id:</strong> ${savedGroupChat.get('chat_id')}</p>
  319. <p><strong>测试地址:</strong></p>
  320. <p><a href="${url}" target="_blank">${url}</a></p>
  321. <p style="margin-top: 15px; padding: 10px; background: #fff3cd; border-radius: 5px; color: #856404;">
  322. 💡 <strong>提示:</strong> 页面加载时会自动尝试从企微API同步最新数据(成员列表、群名称等)
  323. </p>
  324. `);
  325. console.log('✅ 群聊记录已创建:', savedGroupChat.toJSON());
  326. } catch (error) {
  327. console.error('❌ 创建失败:', error);
  328. showResult('error', '❌ 创建失败', `
  329. <p>${error.message}</p>
  330. <p>请确保:</p>
  331. <ul style="margin-left: 20px; margin-top: 10px;">
  332. <li>项目已启动 (npm start)</li>
  333. <li>Parse Server已连接</li>
  334. <li>网络连接正常</li>
  335. </ul>
  336. `);
  337. } finally {
  338. showLoading(false);
  339. }
  340. };
  341. // 打开测试页面
  342. window.openTestPage = function() {
  343. if (!currentGroupChatId) {
  344. alert('请先创建或查询群聊记录');
  345. return;
  346. }
  347. const url = `http://localhost:4200/wxwork/${CONFIG.cid}/chat-activation/${currentGroupChatId}`;
  348. window.open(url, '_blank');
  349. };
  350. // 页面加载时自动查询
  351. window.addEventListener('load', () => {
  352. console.log('🚀 页面已加载,可以开始测试');
  353. // 自动查询现有记录
  354. setTimeout(() => {
  355. queryExisting();
  356. }, 500);
  357. });
  358. </script>
  359. </body>
  360. </html>