quick.ui.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. window._setDocAppOptions = window.setDocAppOptions;
  2. window.setDocAppOptions = function(_, options)
  3. {
  4. options = window._setDocAppOptions(_, options);
  5. const onSwitchView = options.onSwitchView;
  6. const initLibID = options.libID;
  7. options = $.extend(options,
  8. {
  9. docFetcher: {url: options.docFetcher, dataFilter: (data) => $.extend(data, {lib: initLibID || options.libID})},
  10. viewModeUrl: function(options)
  11. {
  12. const lib = this.getLib(options.libID);
  13. const quickType = lib ? lib.data.quickType : 'view';
  14. return $.createLink('doc', 'quick', zui.formatString('type={type}&docID={docID}&orderBy={orderBy}&recPerPage={recPerPage}&pageID={page}', $.extend({type: quickType}, options))).replace('&docID=0&orderBy=&recPerPage=20&pageID=1', '').replace('&orderBy=&recPerPage=20&pageID=1', '');
  15. },
  16. onSwitchView: function(mode, location, info)
  17. {
  18. onSwitchView.call(this, mode, location, info);
  19. trySwitchView(this, location.libID, mode);
  20. },
  21. formatDataItem: function(type, item)
  22. {
  23. if(type === 'doc') item.libID = options.libID;
  24. return item;
  25. }
  26. });
  27. if(typeof window._currentLibID === 'number') options.libID = window._currentLibID;
  28. return options;
  29. };
  30. /**
  31. * 尝试切换视图。
  32. * Try to switch view.
  33. * @param {Object} docApp - 文档应用实例。
  34. * @param {number} libID - 库ID。
  35. * @param {string} mode - 模式。
  36. */
  37. function trySwitchView(docApp, libID, mode)
  38. {
  39. if(window._trySwitchViewTimer) clearTimeout(window._trySwitchViewTimer);
  40. if(libID === window._currentLibID || mode !== 'list') return;
  41. window._currentLibID = libID;
  42. window._trySwitchViewTimer = setTimeout(() => {
  43. window._trySwitchViewTimer = 0;
  44. if(libID === docApp.props.libID) return;
  45. const lib = docApp.lib;
  46. const quickType = lib ? lib.data.quickType : 'view';
  47. const url = $.createLink('doc', 'quick', `type=${quickType}`);
  48. docApp.signals.loading.value = true;
  49. $('#mainContent').addClass('loading');
  50. loadPartial(url, '#mainContent', {complete: () => {
  51. $('#mainContent').removeClass('loading');
  52. docApp.signals.loading.value = false;
  53. }});
  54. }, 10);
  55. }
  56. function getObjectBrowseUrl(object, objectType, libID)
  57. {
  58. const browsePath =
  59. {
  60. execution: ['execution', 'browse'],
  61. project: ['doc', 'projectSpace'],
  62. product: ['doc', 'productSpace'],
  63. mine: ['doc', 'mySpace'],
  64. custom: ['doc', 'teamSpace'],
  65. };
  66. const path = browsePath[objectType];
  67. return path ? $.createLink(path[0], path[1], `objectID=${object.id}&libID=${libID || 0}`) : null;
  68. }
  69. const buildDocActions = window.docAppActions.doc;
  70. window.docAppActions.doc = function(info)
  71. {
  72. const actions = buildDocActions.call(this, info);
  73. if(info.ui === 'toolbar')
  74. {
  75. const doc = info.data;
  76. const object = doc.object;
  77. const lib = doc.libInfo;
  78. const docUrl = $.createLink('doc', 'view', `docID=${doc.id}`);
  79. actions.unshift(
  80. {
  81. type: 'custom',
  82. component: 'div',
  83. className: 'order-first mr-2',
  84. html: [
  85. `<span class="text-gray">${getDocAppLang('position')}${getDocAppLang('colon')} </span>`,
  86. `<a href="${docUrl}">`,
  87. [
  88. object ? (object.name || object.title) : '',
  89. lib ? lib.name : '',
  90. ].filter(Boolean).join(' <span class="text-gray">/</span> '),
  91. '</a>',
  92. ].join(''),
  93. });
  94. }
  95. return actions;
  96. };
  97. window.docAppCommands.exportWord = function(_, args)
  98. {
  99. const docApp = getDocApp();
  100. const docID = args[2] || docApp.docID;
  101. const doc = docID ? docApp.getDoc(docID) : null;
  102. if(!doc || !doc.objectType) return;
  103. const moduleID = args[1] || docApp.moduleID;
  104. const libID = doc.libInfo ? doc.libInfo.id : (args[0] || docApp.libID);
  105. const type = doc.objectType || doc.object.type;
  106. const url = $.createLink('doc', `${type}2export`, `libID=${libID}&moduleID=${moduleID}&docID=${docID}`);
  107. window.open(url, '_self');
  108. };
  109. window.onPageUnmount = function()
  110. {
  111. window._currentLibID = null;
  112. };