|
@@ -1,7 +1,6 @@
|
|
|
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
|
|
@@ -23,7 +22,8 @@ export function calcExpress(data, express) {
|
|
|
if (SIMPLE_RE.test(express)) {
|
|
|
// '{foo}' 简单表达式
|
|
|
const path = express.substring(1, express.length - 1);
|
|
|
- return _.get(data, path)
|
|
|
+ const ret = _.get(data, path)
|
|
|
+ return ret.isModel ? ret.data : ret
|
|
|
}
|
|
|
|
|
|
while (true) {
|
|
@@ -395,9 +395,220 @@ export function toPlainObject(obj) {
|
|
|
return obj
|
|
|
}
|
|
|
|
|
|
+export function confirm(msg, sender?): Promise<void> {
|
|
|
+ return new Promise<void>(resolve => {
|
|
|
+ const scope = lookupScope(sender)
|
|
|
+ const config: any = {
|
|
|
+ title: '请确认',
|
|
|
+ icon: Ext.Msg.QUESTION,
|
|
|
+ modal: true,
|
|
|
+ animateTarget: sender,
|
|
|
+ // constrainHeader: true,
|
|
|
+ // constrain: true,
|
|
|
+ // constrainTo: scope._handle?.el?.dom || Ext.getBody(),
|
|
|
+ items: [
|
|
|
+ {
|
|
|
+ html: _.escape(msg)
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ buttons: [
|
|
|
+ {
|
|
|
+ xtype: 'button', text: '确定', iconCls: 'x-fa fa-check',
|
|
|
+ handler() {
|
|
|
+ resolve()
|
|
|
+ win.close()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ xtype: 'button', text: '取消', iconCls: 'x-fa fa-times',
|
|
|
+ handler() {
|
|
|
+ win.close()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ if (scope?._handle) {
|
|
|
+ config.constrain = true
|
|
|
+ }
|
|
|
+ const win = new Ext.Window(config);
|
|
|
+
|
|
|
+ if (scope?._handle) {
|
|
|
+ scope?._handle?.add(win)
|
|
|
+ }
|
|
|
+
|
|
|
+ win.show()
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
class SystemEventFu {
|
|
|
|
|
|
@Lib({
|
|
|
+ title: '弹出确认对话框,回答 YES 之后调用某方法',
|
|
|
+ author: '罗一帆',
|
|
|
+ createAt: '2021-07-06',
|
|
|
+ updateAt: '2021-07-06',
|
|
|
+ type: 'system',
|
|
|
+ category: '对话框',
|
|
|
+ args: [
|
|
|
+ {
|
|
|
+ type: 'string',
|
|
|
+ title: '对话框的确认文字',
|
|
|
+ name: 'text',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: 'event',
|
|
|
+ title: '确认之后调用的方法',
|
|
|
+ name: 'fn',
|
|
|
+ allowEmpty: true,
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ })
|
|
|
+ confirm(text, fn) {
|
|
|
+ return function (sender) {
|
|
|
+ const scope = lookupScope(sender)
|
|
|
+ const msg = calcExpress(scope.viewModel.data, text)
|
|
|
+ confirm(msg, sender).then(() => {
|
|
|
+ fn.call(scope, sender)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Lib({
|
|
|
+ title: '查询表单,如果 url 为空值,就取消查询',
|
|
|
+ author: '罗一帆',
|
|
|
+ createAt: '2021-07-06',
|
|
|
+ updateAt: '2021-07-06',
|
|
|
+ type: 'system',
|
|
|
+ category: '表单',
|
|
|
+ args: [
|
|
|
+ {
|
|
|
+ type: 'string',
|
|
|
+ title: 'groovy 服务路径',
|
|
|
+ name: 'invokeUrl',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: 'object',
|
|
|
+ title: 'invoke 参数的 lookup 表达式, 如果不填 默认提交所有的 viewModel.data',
|
|
|
+ name: 'invokeParam',
|
|
|
+ allowEmpty: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: 'string',
|
|
|
+ title: '服务读取后,数据的回写位置,可以是 scope.XX / system.XX / string / lookup表达式',
|
|
|
+ name: 'writeTarget',
|
|
|
+ allowEmpty: true,
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ })
|
|
|
+ loadForm(invokeUrl: string, invokeParam: any, writeTarget: any) {
|
|
|
+ return function (sender) {
|
|
|
+ if (!invokeUrl) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const scope = lookupScope(sender)
|
|
|
+ scope.setLoading(true)
|
|
|
+
|
|
|
+ let data = scope.viewModel.data
|
|
|
+ if (invokeParam) {
|
|
|
+ data = calcObjectFlat(data, invokeParam)
|
|
|
+ }
|
|
|
+
|
|
|
+ invokeServer(invokeUrl, data).then(res => {
|
|
|
+ if (res.success) {
|
|
|
+
|
|
|
+ if (typeof writeTarget === "string") {
|
|
|
+ _.forOwn(res.data, (v, k) => {
|
|
|
+ scope.viewModel.set(writeTarget + "." + k, v)
|
|
|
+ })
|
|
|
+
|
|
|
+ } else if (typeof writeTarget === 'function') {
|
|
|
+ writeTarget.call(scope, res.data)
|
|
|
+
|
|
|
+ } else if (typeof writeTarget === 'object') {
|
|
|
+ const ret = calcObjectFlat(res.data, writeTarget)
|
|
|
+ _.forOwn(ret, (v, k) => {
|
|
|
+ scope.viewModel.set(k, v)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ } 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: [
|
|
|
+ {
|
|
|
+ type: 'string',
|
|
|
+ title: 'groovy 服务路径',
|
|
|
+ name: 'groovyUrl',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: 'object',
|
|
|
+ title: '参数的 lookup 表达式, 如果不填 默认提交所有的 viewModel.data',
|
|
|
+ name: 'arg0',
|
|
|
+ allowEmpty: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: 'event',
|
|
|
+ title: '成功后的回调',
|
|
|
+ name: 'successCallback',
|
|
|
+ allowEmpty: true,
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ })
|
|
|
+ commit(groovyUrl: string, arg0: any, successCallback) {
|
|
|
+ return function (sender) {
|
|
|
+ const scope = lookupScope(sender)
|
|
|
+
|
|
|
+ scope.setLoading(true)
|
|
|
+
|
|
|
+ let data = scope.viewModel.data
|
|
|
+ if (arg0) {
|
|
|
+ data = calcObjectFlat(data, arg0)
|
|
|
+ }
|
|
|
+
|
|
|
+ invokeServer(groovyUrl, data).then(res => {
|
|
|
+ if (res.success) {
|
|
|
+ if (res.msg) {
|
|
|
+ msg(res.msg)
|
|
|
+ }
|
|
|
+ if (typeof successCallback === 'function') {
|
|
|
+ successCallback.call(scope, sender, res.data)
|
|
|
+ }
|
|
|
+
|
|
|
+ } 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',
|
|
@@ -421,9 +632,14 @@ class SystemEventFu {
|
|
|
formCommit(groovyUrl: string, arg0: any) {
|
|
|
return function (sender) {
|
|
|
const scope = lookupScope(sender)
|
|
|
- const valid = scope.down('form').isValid()
|
|
|
- if (!valid) {
|
|
|
- return
|
|
|
+
|
|
|
+ const form = scope.down('form')
|
|
|
+ if (form) {
|
|
|
+ // 如果下级有表单,就做表单校验
|
|
|
+ const valid = form.isValid()
|
|
|
+ if (!valid) {
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
scope.setLoading(true)
|
|
@@ -435,6 +651,9 @@ class SystemEventFu {
|
|
|
|
|
|
invokeServer(groovyUrl, data).then(res => {
|
|
|
if (res.success) {
|
|
|
+ if (res.msg) {
|
|
|
+ msg(res.msg)
|
|
|
+ }
|
|
|
scope.dialogSuccess(res)
|
|
|
} else {
|
|
|
showErrorDialog(res.msg || '未知错误', sender)
|