debug-team-leader-navigation.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /**
  2. * 组长端路由跳转调试脚本
  3. *
  4. * 使用方法:
  5. * 1. 在组长端 Dashboard 页面打开浏览器控制台(F12)
  6. * 2. 复制并粘贴此脚本到控制台执行
  7. * 3. 查看诊断结果
  8. */
  9. console.log('🔍 开始诊断组长端路由跳转问题...\n');
  10. // 1. 检查 localStorage 标记
  11. console.log('📦 检查 localStorage 标记:');
  12. console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
  13. const enterAsTeamLeader = localStorage.getItem('enterAsTeamLeader');
  14. const teamLeaderMode = localStorage.getItem('teamLeaderMode');
  15. const enterFromCustomerService = localStorage.getItem('enterFromCustomerService');
  16. const customerServiceMode = localStorage.getItem('customerServiceMode');
  17. const company = localStorage.getItem('company');
  18. console.log(` enterAsTeamLeader: ${enterAsTeamLeader || '❌ 未设置'}`);
  19. console.log(` teamLeaderMode: ${teamLeaderMode || '❌ 未设置'}`);
  20. console.log(` enterFromCustomerService: ${enterFromCustomerService || '✅ 未设置(正常)'}`);
  21. console.log(` customerServiceMode: ${customerServiceMode || '✅ 未设置(正常)'}`);
  22. console.log(` company (cid): ${company || '❌ 未设置'}\n`);
  23. // 2. 检查诊断结果
  24. let hasIssues = false;
  25. const issues = [];
  26. const recommendations = [];
  27. if (!teamLeaderMode && !enterAsTeamLeader) {
  28. hasIssues = true;
  29. issues.push('❌ 缺少组长模式标记(teamLeaderMode 和 enterAsTeamLeader)');
  30. recommendations.push('运行修复命令:fixTeamLeaderMode()');
  31. }
  32. if (!company) {
  33. hasIssues = true;
  34. issues.push('❌ 缺少公司ID(company)');
  35. recommendations.push('手动设置:localStorage.setItem("company", "cDL6R1hgSi")');
  36. }
  37. if (enterFromCustomerService === '1' || customerServiceMode === 'true') {
  38. hasIssues = true;
  39. issues.push('⚠️ 检测到客服模式标记,可能与组长模式冲突');
  40. recommendations.push('运行清理命令:cleanCustomerServiceMode()');
  41. }
  42. // 3. 输出诊断结果
  43. console.log('🏥 诊断结果:');
  44. console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
  45. if (!hasIssues) {
  46. console.log(' ✅ 所有标记正常,路由跳转应该可以正常工作\n');
  47. } else {
  48. console.log(' 发现以下问题:');
  49. issues.forEach((issue, i) => {
  50. console.log(` ${i + 1}. ${issue}`);
  51. });
  52. console.log('\n 🔧 建议修复:');
  53. recommendations.forEach((rec, i) => {
  54. console.log(` ${i + 1}. ${rec}`);
  55. });
  56. console.log('');
  57. }
  58. // 4. 检查当前路径
  59. console.log('🌐 当前环境信息:');
  60. console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
  61. console.log(` 当前URL: ${window.location.href}`);
  62. console.log(` 路径: ${window.location.pathname}`);
  63. console.log(` Referrer: ${document.referrer || '无'}\n`);
  64. // 5. 检查项目数据
  65. console.log('📊 检查项目数据(如果可用):');
  66. console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
  67. if (typeof window.Parse !== 'undefined') {
  68. console.log(' ✅ Parse SDK 已加载');
  69. // 检查停滞期/改图期项目
  70. const checkProjectStatus = async () => {
  71. try {
  72. const query = new window.Parse.Query('Project');
  73. query.limit(100);
  74. const projects = await query.find();
  75. let stalledCount = 0;
  76. let modificationCount = 0;
  77. projects.forEach(p => {
  78. const data = p.get('data') || {};
  79. if (data.isStalled === true) stalledCount++;
  80. if (data.isModification === true) modificationCount++;
  81. });
  82. console.log(` 总项目数: ${projects.length}`);
  83. console.log(` 停滞期项目: ${stalledCount} 个`);
  84. console.log(` 改图期项目: ${modificationCount} 个\n`);
  85. } catch (e) {
  86. console.error(' ❌ 检查项目数据失败:', e);
  87. }
  88. };
  89. checkProjectStatus();
  90. } else {
  91. console.log(' ⚠️ Parse SDK 未加载,跳过项目数据检查\n');
  92. }
  93. // 6. 提供修复函数
  94. console.log('🛠️ 可用的修复函数:');
  95. console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
  96. console.log(' 1. fixTeamLeaderMode() - 修复组长模式标记');
  97. console.log(' 2. cleanCustomerServiceMode() - 清除客服模式标记');
  98. console.log(' 3. resetAllMode() - 重置所有模式标记');
  99. console.log(' 4. testNavigation(projectId) - 测试跳转到指定项目\n');
  100. // 修复函数定义
  101. window.fixTeamLeaderMode = function() {
  102. console.log('🔧 正在修复组长模式标记...');
  103. try {
  104. localStorage.setItem('teamLeaderMode', 'true');
  105. localStorage.setItem('enterAsTeamLeader', '1');
  106. console.log('✅ 组长模式标记已设置');
  107. console.log(' teamLeaderMode: true');
  108. console.log(' enterAsTeamLeader: 1');
  109. console.log('\n💡 请重新点击"查看详情"按钮测试');
  110. } catch (e) {
  111. console.error('❌ 设置失败:', e);
  112. }
  113. };
  114. window.cleanCustomerServiceMode = function() {
  115. console.log('🧹 正在清除客服模式标记...');
  116. try {
  117. localStorage.removeItem('enterFromCustomerService');
  118. localStorage.removeItem('customerServiceMode');
  119. console.log('✅ 客服模式标记已清除');
  120. console.log('\n💡 请运行 fixTeamLeaderMode() 重新设置组长模式');
  121. } catch (e) {
  122. console.error('❌ 清除失败:', e);
  123. }
  124. };
  125. window.resetAllMode = function() {
  126. console.log('🔄 正在重置所有模式标记...');
  127. try {
  128. // 清除所有模式
  129. localStorage.removeItem('enterAsTeamLeader');
  130. localStorage.removeItem('teamLeaderMode');
  131. localStorage.removeItem('enterFromCustomerService');
  132. localStorage.removeItem('customerServiceMode');
  133. // 重新设置组长模式
  134. localStorage.setItem('teamLeaderMode', 'true');
  135. localStorage.setItem('enterAsTeamLeader', '1');
  136. console.log('✅ 已重置并设置为组长模式');
  137. console.log('\n💡 请刷新页面或重新点击"查看详情"按钮');
  138. } catch (e) {
  139. console.error('❌ 重置失败:', e);
  140. }
  141. };
  142. window.testNavigation = function(projectId) {
  143. if (!projectId) {
  144. console.error('❌ 请提供项目ID');
  145. console.log('用法: testNavigation("项目ID")');
  146. return;
  147. }
  148. console.log(`🧪 测试跳转到项目: ${projectId}`);
  149. // 确保标记已设置
  150. localStorage.setItem('teamLeaderMode', 'true');
  151. localStorage.setItem('enterAsTeamLeader', '1');
  152. const cid = localStorage.getItem('company') || 'cDL6R1hgSi';
  153. const url = `/wxwork/${cid}/project/${projectId}/delivery`;
  154. console.log(`📍 目标URL: ${url}`);
  155. console.log('⏳ 正在跳转...');
  156. window.location.href = url;
  157. };
  158. // 7. 监听 localStorage 变化
  159. if (typeof window.addEventListener !== 'undefined') {
  160. let storageListener = function(e) {
  161. if (e.key === 'teamLeaderMode' || e.key === 'enterAsTeamLeader') {
  162. console.log(`📢 localStorage 变化: ${e.key} = ${e.newValue}`);
  163. }
  164. };
  165. // 只添加一次监听器
  166. if (!window._debugStorageListenerAdded) {
  167. window.addEventListener('storage', storageListener);
  168. window._debugStorageListenerAdded = true;
  169. console.log('👂 已启动 localStorage 变化监听\n');
  170. }
  171. }
  172. console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
  173. console.log('📝 诊断完成!');
  174. console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n');
  175. if (hasIssues) {
  176. console.log('💡 快速修复:复制以下命令到控制台执行\n');
  177. console.log('fixTeamLeaderMode();\n');
  178. }