check-parse-data.html 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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>检查 Parse 后端数据</title>
  7. <script src="https://npmcdn.com/parse/dist/parse.min.js"></script>
  8. <style>
  9. body {
  10. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  11. max-width: 1200px;
  12. margin: 50px auto;
  13. padding: 20px;
  14. background: #f5f5f5;
  15. }
  16. .container {
  17. background: white;
  18. padding: 30px;
  19. border-radius: 8px;
  20. box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  21. }
  22. h1 {
  23. color: #333;
  24. margin-bottom: 30px;
  25. }
  26. .input-group {
  27. margin-bottom: 20px;
  28. }
  29. label {
  30. display: block;
  31. margin-bottom: 8px;
  32. font-weight: 600;
  33. color: #555;
  34. }
  35. input {
  36. width: 100%;
  37. padding: 12px;
  38. border: 1px solid #ddd;
  39. border-radius: 4px;
  40. font-size: 14px;
  41. box-sizing: border-box;
  42. }
  43. button {
  44. background: #007bff;
  45. color: white;
  46. border: none;
  47. padding: 12px 24px;
  48. border-radius: 4px;
  49. cursor: pointer;
  50. font-size: 16px;
  51. margin-right: 10px;
  52. }
  53. button:hover {
  54. background: #0056b3;
  55. }
  56. button:disabled {
  57. background: #ccc;
  58. cursor: not-allowed;
  59. }
  60. .success {
  61. background: #28a745;
  62. }
  63. .success:hover {
  64. background: #218838;
  65. }
  66. .result {
  67. margin-top: 30px;
  68. padding: 20px;
  69. background: #f8f9fa;
  70. border-radius: 4px;
  71. border-left: 4px solid #007bff;
  72. white-space: pre-wrap;
  73. font-family: 'Courier New', monospace;
  74. font-size: 13px;
  75. line-height: 1.6;
  76. max-height: 600px;
  77. overflow-y: auto;
  78. }
  79. .error {
  80. border-left-color: #dc3545;
  81. color: #dc3545;
  82. }
  83. .success-msg {
  84. border-left-color: #28a745;
  85. color: #28a745;
  86. }
  87. .status {
  88. display: inline-block;
  89. padding: 4px 12px;
  90. border-radius: 12px;
  91. font-size: 12px;
  92. font-weight: 600;
  93. margin-left: 10px;
  94. }
  95. .status.pending {
  96. background: #fff3cd;
  97. color: #856404;
  98. }
  99. .status.approved {
  100. background: #d4edda;
  101. color: #155724;
  102. }
  103. .status.undefined {
  104. background: #f8d7da;
  105. color: #721c24;
  106. }
  107. .highlight {
  108. background: #fffacd;
  109. padding: 2px 6px;
  110. border-radius: 3px;
  111. font-weight: 600;
  112. }
  113. </style>
  114. </head>
  115. <body>
  116. <div class="container">
  117. <h1>🔍 检查 Parse 后端项目数据</h1>
  118. <div class="input-group">
  119. <label>项目 ID:</label>
  120. <input type="text" id="projectId" placeholder="例如:EyO8xplVhz" value="EyO8xplVhz">
  121. </div>
  122. <button onclick="checkData()">🔍 查询数据</button>
  123. <button class="success" onclick="fixData()" id="fixBtn" disabled>🔧 修复数据(设置为 pending)</button>
  124. <div id="result"></div>
  125. </div>
  126. <script>
  127. // 初始化 Parse
  128. Parse.initialize("YSS_PROJECT");
  129. Parse.serverURL = 'https://server.fmode.cn/parse';
  130. let currentProject = null;
  131. async function checkData() {
  132. const projectId = document.getElementById('projectId').value.trim();
  133. const resultDiv = document.getElementById('result');
  134. const fixBtn = document.getElementById('fixBtn');
  135. if (!projectId) {
  136. resultDiv.className = 'result error';
  137. resultDiv.textContent = '❌ 请输入项目 ID';
  138. return;
  139. }
  140. resultDiv.className = 'result';
  141. resultDiv.textContent = '⏳ 正在查询...';
  142. fixBtn.disabled = true;
  143. try {
  144. const query = new Parse.Query('Project');
  145. const project = await query.get(projectId);
  146. currentProject = project;
  147. const data = project.get('data') || {};
  148. const currentStage = project.get('currentStage');
  149. const title = project.get('title');
  150. const approvalStatus = data.approvalStatus;
  151. const pendingApprovalBy = data.pendingApprovalBy;
  152. const approvalHistory = data.approvalHistory || [];
  153. let statusClass = 'undefined';
  154. if (approvalStatus === 'pending') statusClass = 'pending';
  155. if (approvalStatus === 'approved') statusClass = 'approved';
  156. let output = `
  157. ✅ 查询成功!
  158. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  159. 📋 项目基本信息:
  160. 项目 ID: ${projectId}
  161. 项目名称: ${title || '未设置'}
  162. 当前阶段: ${currentStage || '未设置'}
  163. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  164. 🎯 审批状态检查:
  165. approvalStatus: ${approvalStatus || 'undefined'} ${approvalStatus === 'pending' ? '✅' : '❌'}
  166. pendingApprovalBy: ${pendingApprovalBy || 'undefined'}
  167. 审批历史记录数: ${approvalHistory.length} 条
  168. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  169. 📊 完整的 data 字段:
  170. ${JSON.stringify(data, null, 2)}
  171. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  172. ${approvalStatus === 'pending'
  173. ? '✅ 数据正常!approvalStatus 已正确设置为 pending'
  174. : '❌ 数据异常!approvalStatus 不是 pending,需要修复'}
  175. `;
  176. resultDiv.className = approvalStatus === 'pending' ? 'result success-msg' : 'result error';
  177. resultDiv.textContent = output;
  178. // 如果数据异常,启用修复按钮
  179. fixBtn.disabled = (approvalStatus === 'pending');
  180. } catch (error) {
  181. console.error('查询失败:', error);
  182. resultDiv.className = 'result error';
  183. resultDiv.textContent = `❌ 查询失败:\n\n${error.message}\n\n${error.stack}`;
  184. currentProject = null;
  185. fixBtn.disabled = true;
  186. }
  187. }
  188. async function fixData() {
  189. if (!currentProject) {
  190. alert('请先查询项目数据');
  191. return;
  192. }
  193. const resultDiv = document.getElementById('result');
  194. const fixBtn = document.getElementById('fixBtn');
  195. if (!confirm('确定要将此项目的 approvalStatus 设置为 pending 吗?')) {
  196. return;
  197. }
  198. resultDiv.className = 'result';
  199. resultDiv.textContent = '⏳ 正在修复数据...';
  200. fixBtn.disabled = true;
  201. try {
  202. const data = currentProject.get('data') || {};
  203. // 设置审批状态
  204. data.approvalStatus = 'pending';
  205. data.pendingApprovalBy = 'team-leader';
  206. // 确保 currentStage 是"订单分配"
  207. currentProject.set('currentStage', '订单分配');
  208. currentProject.set('data', data);
  209. console.log('🔧 准备保存修复后的数据:', {
  210. projectId: currentProject.id,
  211. currentStage: currentProject.get('currentStage'),
  212. approvalStatus: data.approvalStatus,
  213. pendingApprovalBy: data.pendingApprovalBy
  214. });
  215. await currentProject.save();
  216. // 验证保存
  217. const verifyQuery = new Parse.Query('Project');
  218. const savedProject = await verifyQuery.get(currentProject.id);
  219. const savedData = savedProject.get('data') || {};
  220. let output = `
  221. ✅ 修复成功!
  222. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  223. 已更新的字段:
  224. currentStage: ${savedProject.get('currentStage')}
  225. approvalStatus: ${savedData.approvalStatus}
  226. pendingApprovalBy: ${savedData.pendingApprovalBy}
  227. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  228. 验证结果:
  229. ${savedData.approvalStatus === 'pending' ? '✅ approvalStatus 已正确设置为 pending' : '❌ 修复失败,approvalStatus 仍不是 pending'}
  230. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  231. 请刷新组长端页面查看效果!
  232. `;
  233. resultDiv.className = 'result success-msg';
  234. resultDiv.textContent = output;
  235. fixBtn.disabled = true;
  236. } catch (error) {
  237. console.error('修复失败:', error);
  238. resultDiv.className = 'result error';
  239. resultDiv.textContent = `❌ 修复失败:\n\n${error.message}\n\n${error.stack}`;
  240. }
  241. }
  242. // 页面加载时自动查询
  243. window.onload = () => {
  244. const projectId = document.getElementById('projectId').value;
  245. if (projectId) {
  246. checkData();
  247. }
  248. };
  249. </script>
  250. </body>
  251. </html>