init.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import _ from 'lodash'
  2. import {lookupFn, lookupScope} from "./lib/lib"
  3. import initCols from './controls/cols'
  4. import * as SystemLib from './lib/systemLib'
  5. import './lib/fix'
  6. export function init() {
  7. /**
  8. * 改变事件的触发方式
  9. */
  10. const _getFireInfo = Ext.util.Event.prototype.getFireInfo
  11. Ext.util.Event.prototype.getFireInfo = function (listener, fromWrapped) {
  12. var observable = this.observable,
  13. fireFn = listener.fireFn,
  14. scope = listener.scope,
  15. namedScope = listener.namedScope,
  16. fn, origin;
  17. fn = fromWrapped ? listener.fn : fireFn;
  18. if (typeof fn === 'string' &&
  19. (_.startsWith(fn, 'scope.') ||
  20. _.startsWith(fn, 'system.') ||
  21. _.startsWith(fn, 'format.')
  22. )) {
  23. if (window["IS_DESIGN_MODE"]) {
  24. fn = Ext.emptyFn
  25. } else {
  26. scope = lookupScope(observable)
  27. fn = lookupFn(scope, fn)
  28. }
  29. return {scope, fn}
  30. }
  31. return _getFireInfo.call(this, listener, fromWrapped)
  32. }
  33. // const _addListener = Ext.mixin.Observable.prototype.addListener
  34. // Ext.mixin.Observable.prototype.addListener = function (eventName, fn, scope, options, order, caller) {
  35. // console.log('addListener', eventName, fn, scope, options, order, caller)
  36. // // const scope = lookupScope(this)
  37. // // const fn = lookupFn(scope, fn)
  38. //
  39. // return _addListener.call(this, eventName, fn, scope, options, order, caller)
  40. // }
  41. /**
  42. * 改变事件的获取方式.
  43. * 具体见: ext-all-debug.js:23216 addListener
  44. * https://docs.sencha.com/extjs/6.6.0/classic/Ext.util.Observable.html#method-addListener
  45. * https://docs.sencha.com/extjs/6.6.0/classic/src/Observable.js.html#Ext.mixin.Observable-method-addListener
  46. */
  47. // const _doAddListener = Ext.mixin.Observable.prototype.doAddListener
  48. // Ext.mixin.Observable.prototype.doAddListener = function (ename, fn, scope, options, order, caller, manager) {
  49. // console.log('doAddListener', ename, fn, scope)
  50. // if (typeof fn === 'string' &&
  51. // (_.startsWith(fn, 'scope.') ||
  52. // _.startsWith(fn, 'system.') ||
  53. // _.startsWith(fn, 'format.')
  54. // )) {
  55. //
  56. // if (window["IS_DESIGN_MODE"]) {
  57. // fn = Ext.emptyFn
  58. // } else {
  59. // // console.log('doAddListener', ename, fn, scope, options, order, caller, manager)
  60. // // const vm = this.lookupViewModel()
  61. // // if (vm && vm.yvanScope) {
  62. // // scope = vm.yvanScope
  63. // // fn = scope[fn.substr('scope.'.length)]
  64. // // }
  65. // scope = lookupScope(this)
  66. // fn = lookupFn(scope, fn)
  67. // }
  68. // }
  69. //
  70. // _doAddListener.call(this, ename, fn, scope, options, order, caller, manager)
  71. // }
  72. // 将 SystemLib 扩展到 window.system 下
  73. if (!window['system']) {
  74. window['system'] = {}
  75. }
  76. _.extend(window['system'], SystemLib)
  77. initCols()
  78. }