loading-helper.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * 加载指示器助手
  3. * 解决CSP安全策略问题,将内联脚本提取到外部文件
  4. */
  5. // 为了确保加载指示器始终可用,添加一个全局函数
  6. window.showLoading = function(message) {
  7. // 尝试使用Vue的方式
  8. try {
  9. if (window.vueApp && window.vueApp.isProcessing !== undefined) {
  10. window.vueApp.isProcessing = true;
  11. window.vueApp.processingMessage = message || '正在处理,请稍候...';
  12. } else {
  13. throw new Error('Vue实例不可用');
  14. }
  15. } catch (e) {
  16. // 如果Vue方式失败,使用静态指示器
  17. var loadingEl = document.getElementById('static-loading');
  18. var messageEl = document.getElementById('static-loading-message');
  19. if (messageEl) messageEl.textContent = message || '正在处理,请稍候...';
  20. if (loadingEl) loadingEl.style.display = 'flex';
  21. }
  22. };
  23. window.hideLoading = function() {
  24. // 尝试使用Vue的方式
  25. try {
  26. if (window.vueApp && window.vueApp.isProcessing !== undefined) {
  27. window.vueApp.isProcessing = false;
  28. } else {
  29. throw new Error('Vue实例不可用');
  30. }
  31. } catch (e) {
  32. // 如果Vue方式失败,使用静态指示器
  33. var loadingEl = document.getElementById('static-loading');
  34. if (loadingEl) loadingEl.style.display = 'none';
  35. }
  36. };
  37. // 暴露Vue实例到全局,以便于调试和访问
  38. document.addEventListener('DOMContentLoaded', function() {
  39. setTimeout(function() {
  40. try {
  41. var vueInstance = document.getElementById('pageContainer').__vue__;
  42. if (vueInstance) {
  43. window.vueApp = vueInstance;
  44. }
  45. } catch (e) {
  46. console.warn('无法获取Vue实例:', e);
  47. }
  48. }, 500);
  49. });