|
@@ -1,6 +1,8 @@
|
|
|
import _ from 'lodash'
|
|
|
import {Lib, lookupScope} from './lib'
|
|
|
import {ajax} from "./config";
|
|
|
+import {Model} from 'src/types';
|
|
|
+import {msg, showErrorDialog} from "../message";
|
|
|
|
|
|
export const SIMPLE_RE = /^(?:\{(?:(\d+)|([a-z_][\w\.]*))\})$/i
|
|
|
|
|
@@ -396,6 +398,72 @@ export function toPlainObject(obj) {
|
|
|
class SystemEventFu {
|
|
|
|
|
|
@Lib({
|
|
|
+ title: '提交表单',
|
|
|
+ author: '罗一帆',
|
|
|
+ createAt: '2021-07-02',
|
|
|
+ updateAt: '2021-07-02',
|
|
|
+ type: 'system',
|
|
|
+ category: '表单',
|
|
|
+ args: [
|
|
|
+ {
|
|
|
+ type: 'string',
|
|
|
+ title: 'groovy 服务路径',
|
|
|
+ name: 'groovyUrl',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: 'object',
|
|
|
+ title: '参数的 lookup 表达式, 如果不填 默认提交所有的 viewModel.data',
|
|
|
+ name: 'arg0',
|
|
|
+ allowEmpty: true,
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ })
|
|
|
+ formCommit(groovyUrl: string, arg0: any) {
|
|
|
+ return function (sender) {
|
|
|
+ const scope = lookupScope(sender)
|
|
|
+ const valid = scope.down('form').isValid()
|
|
|
+ if (!valid) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ scope.setLoading(true)
|
|
|
+
|
|
|
+ let data = scope.viewModel.data
|
|
|
+ if (arg0) {
|
|
|
+ data = calcObjectFlat(data, arg0)
|
|
|
+ }
|
|
|
+
|
|
|
+ invokeServer(groovyUrl, data).then(res => {
|
|
|
+ if (res.success) {
|
|
|
+ scope.dialogSuccess(res)
|
|
|
+ } else {
|
|
|
+ showErrorDialog(res.msg || '未知错误', sender)
|
|
|
+ }
|
|
|
+
|
|
|
+ }).catch((e) => {
|
|
|
+ const msg = e.response?.data?.msg
|
|
|
+ showErrorDialog(msg || e.toString(), sender)
|
|
|
+
|
|
|
+ }).finally(() => {
|
|
|
+ scope.setLoading(false)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Lib({
|
|
|
+ title: '对话框成功回调',
|
|
|
+ author: '罗一帆',
|
|
|
+ createAt: '2021-07-02',
|
|
|
+ updateAt: '2021-07-02',
|
|
|
+ type: 'system',
|
|
|
+ category: '对话框',
|
|
|
+ args: []
|
|
|
+ })
|
|
|
+ dialogSuccess() {
|
|
|
+ debugger
|
|
|
+ }
|
|
|
+
|
|
|
+ @Lib({
|
|
|
title: '清空 viewModel 某个属性',
|
|
|
author: '罗一帆',
|
|
|
createAt: '2021-07-02',
|
|
@@ -494,23 +562,30 @@ class SystemEventFu {
|
|
|
},
|
|
|
{
|
|
|
type: 'object',
|
|
|
- title: '参数数据',
|
|
|
- name: 'dataParam',
|
|
|
+ title: '参数数据 lookup 表达式',
|
|
|
+ name: 'lookupForData',
|
|
|
+ allowEmpty: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: 'event',
|
|
|
+ title: '成功回调',
|
|
|
+ name: 'successCallback',
|
|
|
allowEmpty: true,
|
|
|
}
|
|
|
]
|
|
|
})
|
|
|
- showDialog(url: string, dataParam: any) {
|
|
|
+ showDialog(url: string, lookupForData: any, successCallback) {
|
|
|
return function (sender) {
|
|
|
const scope = lookupScope(sender)
|
|
|
-
|
|
|
- calcObject(scope.viewModel, dataParam).then((param) => {
|
|
|
- // @ts-ignore
|
|
|
- require([url], (module) => {
|
|
|
- const ScopeClass = module.default
|
|
|
- const scope = new ScopeClass()
|
|
|
- scope.showDialog(sender, {}, {data: param})
|
|
|
- })
|
|
|
+ const data = scope.viewModel.data
|
|
|
+
|
|
|
+ const param = calcObjectFlat(data, lookupForData)
|
|
|
+ // @ts-ignore
|
|
|
+ require([url], (module) => {
|
|
|
+ const ScopeClass = module.default
|
|
|
+ const scope = new ScopeClass()
|
|
|
+ scope.success = successCallback
|
|
|
+ scope.showDialog(sender, {}, {data: param})
|
|
|
})
|
|
|
}
|
|
|
}
|