index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * FeHelper 多维度工具组合
  3. */
  4. new Vue({
  5. el: '#pageContainer',
  6. data: {
  7. tools: {
  8. radix: '进制转换',
  9. color: '颜色转换',
  10. crontab: 'Crontab生成器',
  11. payback: '还款计算器'
  12. },
  13. loadManager: {}
  14. },
  15. mounted: function () {
  16. // 通过Tab的切换,来动态加载小工具
  17. jQuery('#tabs').tabs({
  18. show: (event, ui) => {
  19. window.location.hash = ui.panel.id;
  20. let widget = ui.panel.id.replace('tab-', '');
  21. document.title = '多维小工具集 - ' + this.tools[widget];
  22. if (this.loadManager[widget]) {
  23. return;
  24. }
  25. fetch(widget + '/index.html').then(resp => {
  26. resp.text().then(html => {
  27. this.loadManager[widget] = true;
  28. // 插入html
  29. ui.panel.innerHTML = html;
  30. // 插入css
  31. let link = document.createElement('link');
  32. link.setAttribute('rel', 'stylesheet');
  33. link.setAttribute('href', widget + '/index.css');
  34. document.head.appendChild(link);
  35. // 插入js
  36. let script = document.createElement('script');
  37. script.src = widget + '/index.js';
  38. document.body.appendChild(script);
  39. });
  40. });
  41. }
  42. });
  43. },
  44. methods: {}
  45. });