瀏覽代碼

search baseWidget 还剩快捷键部分没有完成。
准备做 form 表单提交

luoyifan 3 年之前
父節點
當前提交
455a7609ff
共有 7 個文件被更改,包括 223 次插入80 次删除
  1. 1 1
      src/controls/component.js
  2. 5 5
      src/controls/grid.js
  3. 6 56
      src/controls/input/search.js
  4. 1 0
      src/index.ts
  5. 173 6
      src/lib/systemLib.ts
  6. 37 0
      src/message.ts
  7. 0 12
      src/utils.ts

+ 1 - 1
src/controls/component.js

@@ -5,7 +5,7 @@ export default function () {
     const ct = Ext.Component.prototype.constructor
     const ct = Ext.Component.prototype.constructor
     Ext.Component.override({
     Ext.Component.override({
         constructor: function (config) {
         constructor: function (config) {
-            if(!window["IS_DESIGN_MODE"] && config) {
+            if (!window["IS_DESIGN_MODE"] && config) {
                 const me = this
                 const me = this
                 // 任意组件 Ext.Component 构造时调用的方法, 可以用来在渲染之前加工处理 VJSON
                 // 任意组件 Ext.Component 构造时调用的方法, 可以用来在渲染之前加工处理 VJSON
                 _.each(baseConfigProcessList, process => {
                 _.each(baseConfigProcessList, process => {

+ 5 - 5
src/controls/grid.js

@@ -199,11 +199,11 @@ export default function () {
                     }
                     }
                 },
                 },
                 itemcontextmenu(view, rec, node, index, e) {
                 itemcontextmenu(view, rec, node, index, e) {
-                    if (this.contextMenu) {
-                        e.stopEvent();
-                        this.contextMenu.show().setLocalXY(e.getXY());
-                        return false;
-                    }
+                    // if (this.contextMenu) {
+                    //     e.stopEvent();
+                    //     this.contextMenu.show().setLocalXY(e.getXY());
+                    //     return false;
+                    // }
                 },
                 },
                 destory() {
                 destory() {
                 },
                 },

+ 6 - 56
src/controls/input/search.js

@@ -1,9 +1,8 @@
 import _ from 'lodash'
 import _ from 'lodash'
 import {baseConfig} from "../base";
 import {baseConfig} from "../base";
 import {search} from "../../Defaults";
 import {search} from "../../Defaults";
-import {invokeMethod, stopEvent} from "../../utils";
-import {lookupScope} from "../../lib/lib"
-import {calcObjectFlat,tryWriteByExpress} from "../../lib/systemLib"
+import {invokeMethod} from '../../utils'
+import {clearViewModelByLookup, showWidget, stopEvent} from "../../lib/systemLib"
 
 
 export default function () {
 export default function () {
 
 
@@ -61,7 +60,7 @@ export default function () {
             const me = this
             const me = this
             const {config} = me
             const {config} = me
             const {widget, vjson, lookup} = config
             const {widget, vjson, lookup} = config
-            const parentScope = lookupScope(sender)
+
 
 
             if (e) {
             if (e) {
                 e.preventDefault()
                 e.preventDefault()
@@ -73,48 +72,7 @@ export default function () {
                 return
                 return
             }
             }
 
 
-            // @ts-ignore
-            require([widget], (widgetScope) => {
-                const WidgetScopeClass = widgetScope.default
-                widgetScope = new WidgetScopeClass()
-
-                const rawValue = this.getRawValue()
-
-                // 传递进 widget.model 的数据
-                const widgetDialogData = calcObjectFlat({queryValue: rawValue, ...parentScope.viewModel.data}, lookup)
-                widgetScope.parentScope = parentScope
-                widgetScope.searchWidgetSuccess = (data) => {
-                    if (typeof lookup === 'string') {
-                        // lookup 是字符串的情况下,就是取某个列作为 value 值
-                        me.setValue(data[lookup])
-                        return
-                    }
-
-                    /**
-                     * lookup: {
-                     *   // 扩展到 viewModel 的值做更改
-                     *   WH_CODE: "{queryValue}",
-                     *   WH_NAME: "{query.WH_NAME}",
-                     * }
-                     */
-                    if (_.isPlainObject(lookup)) {
-                        const parentScope = lookupScope(sender)
-
-                        tryWriteByExpress(parentScope.viewModel, )
-
-                        _.forOwn(lookup, (value, key) => {
-                            if (!key || key === 'value') {
-                                me.setValue(data[value])
-                            } else {
-                                parentScope.viewModel.set(key, data[value])
-                            }
-                        })
-                    }
-
-                    return true
-                }
-                widgetScope.showDialog(sender, vjson, {data: widgetDialogData})
-            })
+            showWidget(widget, lookup, sender, me.getRawValue(), vjson)
         },
         },
 
 
         replaceRawInputEvent() {
         replaceRawInputEvent() {
@@ -157,17 +115,9 @@ export default function () {
             const {config} = me
             const {config} = me
             const {lookup} = config
             const {lookup} = config
 
 
-            if (_.isPlainObject(lookup)) {
-                const parentScope = lookupScope(sender)
+            me.setValue('')
 
 
-                _.forOwn(lookup, (value, key) => {
-                    if (!key || key === 'value') {
-                        me.setValue('')
-                    } else {
-                        parentScope.viewModel.set(key, '')
-                    }
-                })
-            }
+            clearViewModelByLookup(sender, lookup)
         }
         }
     });
     });
 }
 }

+ 1 - 0
src/index.ts

@@ -17,6 +17,7 @@ export {
     Defaults
     Defaults
 }
 }
 
 
+export * from './message'
 export * from './Scope'
 export * from './Scope'
 export * from './init'
 export * from './init'
 export * from './lib/ajax'
 export * from './lib/ajax'

+ 173 - 6
src/lib/systemLib.ts

@@ -2,6 +2,8 @@ import _ from 'lodash'
 import {Lib, lookupScope} from './lib'
 import {Lib, lookupScope} from './lib'
 import {ajax} from "./config";
 import {ajax} from "./config";
 
 
+export const SIMPLE_RE = /^(?:\{(?:(\d+)|([a-z_][\w\.]*))\})$/i
+
 /**
 /**
  * 对某个表达式进行求值
  * 对某个表达式进行求值
  * a:{query.a},b:{query.b} -> a:aValue,b:bValue
  * a:{query.a},b:{query.b} -> a:aValue,b:bValue
@@ -16,6 +18,12 @@ import {ajax} from "./config";
 export function calcExpress(data, express) {
 export function calcExpress(data, express) {
     let result = express
     let result = express
 
 
+    if (SIMPLE_RE.test(express)) {
+        // '{foo}' 简单表达式
+        const path = express.substring(1, express.length - 1);
+        return _.get(data, path)
+    }
+
     while (true) {
     while (true) {
         const mlist = result.match(/{(.*?)}/)
         const mlist = result.match(/{(.*?)}/)
         if (!mlist) {
         if (!mlist) {
@@ -110,8 +118,8 @@ export function calcObjectFlat(data, paramObject) {
  * @param value 目标值
  * @param value 目标值
  */
  */
 export function tryWriteByExpress(viewModel, express, value) {
 export function tryWriteByExpress(viewModel, express, value) {
-    if (/^(?:\{(?:(\d+)|([a-z_][\w\.]*))\})$/i.test(express)) {
-        // If we have '{foo}' alone it is a literal 简单表达式
+    if (SIMPLE_RE.test(express)) {
+        // '{foo}' 简单表达式
         express = express.substring(1, express.length - 1);
         express = express.substring(1, express.length - 1);
         viewModel.set(express, value)
         viewModel.set(express, value)
     }
     }
@@ -120,7 +128,7 @@ export function tryWriteByExpress(viewModel, express, value) {
 /**
 /**
  * 尝试根据含表达式的对象回写, calcObjectFlat 的逆向方法
  * 尝试根据含表达式的对象回写, calcObjectFlat 的逆向方法
  * @example
  * @example
- * tryWriteObject(null, { a:'{query.a}', b:{b1:'{query.b1}', b2:'{query.b2}'},c:'aa',d:['{query.d1}','{query.d2}'] }, { a: 'aValue', b: { b1: 'b1Value', b2: 'b2Value' }, c: 'aa', d: [ '1', '2' ] })
+ * tryWriteObject({ a:'{query.a}', b:{b1:'{query.b1}', b2:'{query.b2}'},c:'aa',d:['{query.d1}','{query.d2}']}, {a:'aValue', b:{b1:'b1Value', b2:'b2Value'}, c:'aa', d:[1,2]})
  *
  *
  * expressObject:
  * expressObject:
  * {
  * {
@@ -157,7 +165,7 @@ export function tryWriteByExpress(viewModel, express, value) {
  *
  *
  * @param expressObject 含表达式的对象
  * @param expressObject 含表达式的对象
  * @param valueObject 表达式计算完成之后的结果对象
  * @param valueObject 表达式计算完成之后的结果对象
- * @param writeFn 忽略方法 (key,value)=>boolean ,如果这个方法返回 false 代表不需要系统做处理
+ * @param writeFn 写入的方法 (path, value)=>void
  */
  */
 export function tryWriteObject(expressObject, valueObject, writeFn) {
 export function tryWriteObject(expressObject, valueObject, writeFn) {
 
 
@@ -173,7 +181,7 @@ export function tryWriteObject(expressObject, valueObject, writeFn) {
 
 
             } else if (_.isString(value)) {
             } else if (_.isString(value)) {
                 // 字符串直接用 calcExpress 表达式求解
                 // 字符串直接用 calcExpress 表达式求解
-                if (/^(?:\{(?:(\d+)|([a-z_][\w\.]*))\})$/i.test(value)) {
+                if (SIMPLE_RE.test(value)) {
                     // If we have '{foo}' alone it is a literal 简单表达式
                     // If we have '{foo}' alone it is a literal 简单表达式
                     const targetPath = value.substring(1, value.length - 1);
                     const targetPath = value.substring(1, value.length - 1);
                     const targetValue = _.get(valueObject, (pathPrefix + "." + key).substr(1))
                     const targetValue = _.get(valueObject, (pathPrefix + "." + key).substr(1))
@@ -185,7 +193,15 @@ export function tryWriteObject(expressObject, valueObject, writeFn) {
                 }
                 }
             } else if (_.isArray(value)) {
             } else if (_.isArray(value)) {
                 _.each(value, (v, idx) => {
                 _.each(value, (v, idx) => {
-
+                    if (SIMPLE_RE.test(v)) {
+                        const targetPath = (pathPrefix + "." + key).substr(1) + "[" + idx + "]";
+                        const targetValue = _.get(valueObject, (pathPrefix + "." + key).substr(1) + "[" + idx + "]")
+                        if (!writeFn) {
+                            console.log(`viewModel.set('${targetPath}', '${targetValue}')`)
+                        } else {
+                            writeFn(targetPath, targetValue)
+                        }
+                    }
                 })
                 })
             }
             }
         })
         })
@@ -498,4 +514,155 @@ class SystemEventFu {
             })
             })
         }
         }
     }
     }
+
+    @Lib({
+        title: '弹出查找框(不借助 search)',
+        author: '罗一帆',
+        createAt: '2021-07-02',
+        updateAt: '2021-07-02',
+        type: 'system',
+        category: '对话框',
+        args: [
+            {
+                type: 'module',
+                title: '模块名 (WidgetDialog)',
+                name: 'widgetUrl',
+            },
+            {
+                type: 'object',
+                title: 'lookup 映射关系',
+                name: 'lookupSetting',
+                allowEmpty: true,
+            }
+        ]
+    })
+    showWidget(widgetUrl, lookup) {
+        return function (sender, queryValue) {
+            showWidget(widgetUrl, lookup, sender, queryValue)
+        }
+    }
+
+    @Lib({
+        title: '根据 lookup 清空 viewModel',
+        author: '罗一帆',
+        createAt: '2021-07-05',
+        updateAt: '2021-07-05',
+        type: 'system',
+        category: '表单',
+        args: [
+            {
+                type: 'viewModel',
+                title: 'lookup 设值',
+                name: 'lookup',
+            },
+        ]
+    })
+    clearViewModelByLookup(lookup) {
+        return function (sender) {
+            clearViewModelByLookup(sender, lookup)
+        }
+    }
+
+    @Lib({
+        title: '关闭对话框',
+        author: '罗一帆',
+        createAt: '2021-07-05',
+        updateAt: '2021-07-05',
+        type: 'system',
+        category: '对话框',
+        args: [
+            {
+                type: 'event',
+                title: '对话框的返回值回调',
+                name: 'callBack',
+            },
+        ]
+    })
+    closeMe(callBack) {
+        return function (sender) {
+            const scope = lookupScope(sender)
+            scope.close()
+
+            if (callBack) {
+                callBack.call(sender)
+            }
+        }
+    }
+}
+
+export function clearViewModelByLookup(sender, lookup) {
+    if (_.isPlainObject(lookup)) {
+        const parentScope = lookupScope(sender)
+
+        _.forOwn(lookup, (value, key) => {
+            if (SIMPLE_RE.test(value)) {
+                // '{foo}' 简单表达式
+                const path = value.substring(1, value.length - 1);
+                if (path !== 'queryValue') {
+                    parentScope.viewModel.set(path, '')
+                }
+            }
+        })
+    }
+}
+
+export function showWidget(widgetUrl, lookup, sender, queryValue, vjson = {}) {
+    const parentScope = lookupScope(sender)
+    const me = sender
+
+    // @ts-ignore
+    require([widgetUrl], (widgetScope) => {
+        const WidgetScopeClass = widgetScope.default
+        widgetScope = new WidgetScopeClass()
+
+        // 传递进 widget.model 的数据
+        const widgetDialogData = calcObjectFlat({
+            queryValue: queryValue,
+            ...parentScope.viewModel.data
+        }, lookup)
+        widgetScope.parentScope = parentScope
+        widgetScope.searchWidgetSuccess = (data) => {
+            if (typeof lookup === 'string') {
+                // lookup 是字符串的情况下,就是取某个列作为 value 值
+                me.setValue(data[lookup])
+                return
+            }
+
+            /**
+             * lookup: {
+             *   // 扩展到 viewModel 的值做更改
+             *   WH_CODE: "{queryValue}",
+             *   WH_NAME: "{query.WH_NAME}",
+             * }
+             */
+            if (_.isPlainObject(lookup)) {
+                const parentScope = lookupScope(sender)
+
+                tryWriteObject(lookup, data, (path, value) => {
+                        if (path === 'queryValue') {
+                            me.setValue(value)
+                        } else {
+                            parentScope.viewModel.set(path, value)
+                        }
+                    }
+                )
+            }
+
+            return true
+        }
+        widgetScope.showDialog(sender, vjson, {data: widgetDialogData})
+    })
+}
+
+/**
+ * 停止事件的默认行为
+ * @param e
+ */
+export function stopEvent(e) {
+    e.preventDefault()
+    e.stopPropagation()
+    // @ts-ignore
+    window.event.cancelBubble = true
+    e.returnValue = false;
+    e.cancelBubble = true;
 }
 }

+ 37 - 0
src/message.ts

@@ -0,0 +1,37 @@
+import $ from 'jquery'
+import _ from 'lodash'
+
+/**
+ * 中间灰底白字提示
+ */
+export function msg(message: string): void {
+    const $body = $('body')
+
+    $body.find('[xtype=tooltip]').remove()
+    const $w = $(
+        '<div xtype="tooltip" class="yvan-msg yvan-anim yvan-anim-00">' +
+        '  <div class="yvan-msg-content">' +
+        _.escape(message) +
+        '</div></div>'
+    )
+    $body.append($w)
+
+    const iframeWidth = $w.parent().width() as number
+    const iframeHeight = $w.parent().height() as number
+
+    const windowWidth = $w.width() as number
+    const windowHeight = $w.height() as number
+
+    let setWidth = (iframeWidth - windowWidth) / 2
+    let setHeight = (iframeHeight - windowHeight) / 2
+    if (iframeHeight < windowHeight || setHeight < 0) {
+        setHeight = 0
+    }
+    if (iframeWidth < windowWidth || setWidth < 0) {
+        setWidth = 0
+    }
+    $w.css({left: setWidth, top: setHeight})
+    setTimeout(() => {
+        $w.remove()
+    }, 3000)
+}

+ 0 - 12
src/utils.ts

@@ -7,16 +7,4 @@ export function invokeMethod(fn: any, sender: any, args: any) {
     }
     }
 }
 }
 
 
-/**
- * 停止事件的默认行为
- * @param e
- */
-export function stopEvent(e) {
-    e.preventDefault()
-    e.stopPropagation()
-    // @ts-ignore
-    window.event.cancelBubble = true
-    e.returnValue = false;
-    e.cancelBubble = true;
-}