customer.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ;(function () {
  2. var inner = window.OACustomer
  3. //命令
  4. var Commands = {
  5. //简单命令
  6. Save: function () {
  7. wps.Application.ActiveDocument.Save()
  8. },
  9. SaveAndClose: function () {
  10. var doc = wps.Application.ActiveDocument
  11. doc.Save()
  12. doc.Close()
  13. },
  14. Close: function () {
  15. var doc = wps.Application.ActiveDocument
  16. doc.Close(-2)
  17. },
  18. }
  19. //组件
  20. var Components = {
  21. SwitchTraceView: {
  22. getLabel: function () {
  23. var view = wps.Application.ActiveDocument.ActiveWindow.View
  24. return view.ShowRevisionsAndComments ? '隐藏痕迹' : '显示痕迹'
  25. },
  26. getIcon: function () {
  27. return '../img/components/SwitchTraceView.png'
  28. },
  29. onAction: function () {
  30. var view = wps.Application.ActiveDocument.ActiveWindow.View
  31. view.ShowRevisionsAndComments = !view.ShowRevisionsAndComments
  32. },
  33. },
  34. }
  35. //变量
  36. var _cacheBtns = {}
  37. var _initBtn = false
  38. function buildBtns(type) {
  39. var btns = []
  40. var source = inner.getCustomerData(type, 'btns') || []
  41. if (source.length > 0)
  42. source.forEach((item) => {
  43. if (item.componentId) {
  44. if (!Components.hasOwnProperty(item.componentId)) {
  45. loginfo('未发现自定义按钮' + item.componentId)
  46. }
  47. btns[item.order] = Object.assign(
  48. buildCmdBtn({}),
  49. item,
  50. Components[item.componentId]
  51. )
  52. } else if (item.cmd) {
  53. btns[item.order] = buildCmdBtn(item)
  54. }
  55. })
  56. return btns
  57. }
  58. function buildCmdBtn(data) {
  59. return {
  60. getIcon: function () {
  61. return !!data.icon ? '../' + data.icon : '../img/unknow.png'
  62. },
  63. getLabel: function () {
  64. return data.title || '未知'
  65. },
  66. onAction: function () {
  67. !!Commands[data.cmd] && Commands[data.cmd]()
  68. },
  69. }
  70. }
  71. function getCustomerBtn(type, orderid) {
  72. if (!_initBtn) {
  73. _initBtn = true
  74. _cacheBtns[type] = buildBtns(type)
  75. }
  76. return _cacheBtns[type][orderid]
  77. }
  78. window.OACustomer = Object.assign({}, inner, {
  79. getCustomerBtn,
  80. })
  81. })()