Browse Source

通知单保存

liuzhuang 3 years ago
parent
commit
0cb669cf4a
2 changed files with 36 additions and 5 deletions
  1. 4 2
      src/Scope.ts
  2. 32 3
      src/lib/systemLib.ts

+ 4 - 2
src/Scope.ts

@@ -77,12 +77,14 @@ export class Scope {
     /**
      * 对话框"保存"成功.
      * 关闭对话框,并响应 success 方法
+     * @param data 要傳回的數據(可以為空)
      */
-    dialogSuccess(data) {
+    dialogSuccess(data?) {
         this._handle.fireEvent('success', this, data)
         const sender = this._handle.config.animateTarget
+        const scope = lookupScope(sender)
         if (typeof this['success'] === 'function') {
-            this['success'].call(sender, sender, data)
+            this['success'].call(scope, sender, data)
         }
         this.close()
     }

+ 32 - 3
src/lib/systemLib.ts

@@ -81,6 +81,10 @@ export function calcExpress(data, express) {
 export function calcObjectFlat(data, paramObject) {
     const result = _.cloneDeep(paramObject)
 
+    if (typeof paramObject === 'string') {
+        return calcExpress(data, paramObject)
+    }
+
     const trav = (param) => {
         _.forOwn(param, (value, key) => {
             if (_.isPlainObject(value)) {
@@ -105,6 +109,15 @@ export function calcObjectFlat(data, paramObject) {
 }
 
 /**
+ * 合併 data 到當前的 ViewModel 對象
+ */
+export function mergeViewModel(viewModel, propertyName, data) {
+    _.forOwn(data, (value, key) => {
+        viewModel.set(propertyName + "." + key, value)
+    })
+}
+
+/**
  * 根据表达式进入写值
  * express="{query.a}"   写值就是 viewModel.set('query.a', value)
  * express="test-{query.a}"   写值就会失败
@@ -765,10 +778,26 @@ class SystemEventFu {
         updateAt: '2021-07-02',
         type: 'system',
         category: '对话框',
-        args: []
+        args: [
+            {
+                type: 'object',
+                title: '傳回成功數據的 lookup 表達式',
+                name: 'lookupObject',
+                allowEmpty: true,
+            }
+        ]
     })
-    dialogSuccess() {
-        debugger
+    dialogSuccess(lookupObject) {
+        return function (sender) {
+            const scope = lookupScope(sender)
+            if (lookupObject) {
+                scope.dialogSuccess(
+                    calcObjectFlat(scope.viewModel.data, lookupObject)
+                )
+            } else {
+                scope.dialogSuccess()
+            }
+        }
     }
 
     @Lib({