luoyifan 4 سال پیش
والد
کامیت
f37db2e295
7فایلهای تغییر یافته به همراه107 افزوده شده و 1 حذف شده
  1. 1 1
      build/rollup.amd.js
  2. 0 0
      src/Defaults.ts
  3. 9 0
      src/Scope.ts
  4. 27 0
      src/controls/MainTab.js
  5. 13 0
      src/global.d.ts
  6. 7 0
      src/index.js
  7. 50 0
      src/init.ts

+ 1 - 1
build/rollup.amd.js

@@ -14,7 +14,7 @@ import builtins from 'rollup-plugin-node-builtins';
 
 export default {
     // 入口文件
-    input: resolve(__dirname, '../src/index.js'),
+    input: resolve(__dirname, '../src/index.ts'),
     plugins: [
         // tsx(),
         nodeResolve({

src/Defaults.js → src/Defaults.ts


+ 9 - 0
src/Scope.ts

@@ -0,0 +1,9 @@
+export class Scope {
+
+    viewModel
+
+    constructor({model}) {
+        this.viewModel = new Ext.app.ViewModel(model);
+        this.viewModel.yvanScope = this
+    }
+}

+ 27 - 0
src/controls/MainTab.js

@@ -0,0 +1,27 @@
+Ext.define('Yvan.MainTab', {
+    extend: 'Ext.tab.Panel',
+    xtype: 'maintab',
+
+    constructor(config) {
+        const self = this
+        const newConfig = _.defaultsDeep({}, config, {
+            listeners: {
+                tabchange(tabPanel, newCard, oldCard, eOpts) {
+                    console.log('tabChange')
+                    $(window).trigger('tabChange', {
+                        tabPanel, newCard, oldCard, eOpts
+                    });
+
+                    if (typeof config.tabchange === 'function') {
+                        config.tabchange.apply(this, arguments)
+                    }
+                }
+            }
+        })
+        this.superclass.constructor.call(self, newConfig)
+    },
+
+    addScope() {
+
+    }
+});

+ 13 - 0
src/global.d.ts

@@ -0,0 +1,13 @@
+import JQueryStatic from 'jquery'
+
+interface ExtInterface {
+    [v: string]: any
+}
+
+declare global {
+    // @ts-ignore
+    // const $: JQueryStatic;
+
+    // @ts-ignore
+    const Ext: ExtInterface;
+}

+ 7 - 0
src/index.js

@@ -1,6 +1,13 @@
 import _ from 'lodash'
 import Defaults from './Defaults'
+import init from './init'
 
 import './wotu-ui.css'
 
 export {_, Defaults}
+
+export * from './Scope'
+
+Ext.onReady(() => {
+    init()
+})

+ 50 - 0
src/init.ts

@@ -0,0 +1,50 @@
+import './controls/MainTab'
+
+export default function () {
+    // 引入 filters 过滤插件
+    Ext.require([
+        'Ext.grid.filters.Filters'
+    ])
+
+    // 启用 tooltip 快捷提示
+    Ext.QuickTips.init();
+
+    // 定义日期格式化方法
+    if (Ext.util && Ext.util.Format) {
+        Ext.apply(Ext.util.Format, {
+            dateFormat: 'Y-m-d'
+        });
+    }
+    Ext.define("Ext.locale.zh_CN.picker.Date", {
+        override: "Ext.picker.Date",
+        format: "Y-m-d",
+    });
+    Ext.define("Ext.locale.zh_CN.form.field.Date", {
+        override: "Ext.form.field.Date",
+        format: "Y-m-d",
+    });
+    Ext.define("Ext.locale.zh_CN.grid.PropertyColumnModel", {
+        override: "Ext.grid.PropertyColumnModel",
+        format: "Y-m-d",
+    });
+
+    /**
+     * 改变事件的获取方式.
+     * 具体见: ext-all-debug.js:23216 addListener
+     * https://docs.sencha.com/extjs/6.6.0/classic/Ext.util.Observable.html#method-addListener
+     * https://docs.sencha.com/extjs/6.6.0/classic/src/Observable.js.html#Ext.mixin.Observable-method-addListener
+     */
+    const _doAddListener = Ext.mixin.Observable.prototype.doAddListener
+    Ext.mixin.Observable.prototype.doAddListener = function (ename, fn, scope, options, order, caller, manager) {
+        if (typeof fn === 'string' && fn.startsWith('scope.')) {
+            // console.log('doAddListener', ename, fn, scope, options, order, caller, manager)
+            const vm = this.lookupViewModel()
+            if (vm && vm.yvanScope) {
+                scope = vm.yvanScope
+                fn = scope[fn.substr('scope.'.length)]
+            }
+        }
+
+        _doAddListener.call(this, ename, fn, scope, options, order, caller, manager)
+    }
+}