提交 76b38363 编写于 作者: WodahsOrez's avatar WodahsOrez

update: 系统预置界面行为

上级 c183d531
......@@ -68,6 +68,21 @@ export class AppSysAction {
case 'NewRow':
this.newRow(params);
break;
case 'Refresh':
this.refresh(params);
break;
case 'Exit':
this.exit(params);
break;
case 'SaveAndExit':
this.saveAndExit(params);
break;
case 'RemoveAndExit':
this.removeAndExit(params);
break;
case 'ToggleFilter':
this.toggleFilter(params);
break;
default:
console.log(`未支持${tag}`);
}
......@@ -188,4 +203,82 @@ export class AppSysAction {
actionEnvironment.remove();
}
}
/**
* 刷新
*
* @param params 界面行为参数对象
* @return {*}
*/
public static refresh(params: IUIActionParams) {
const { actionEnvironment } = params;
// 视图里获取多数据部件
if(hasFunction(actionEnvironment.xDataControl, "refresh")){
actionEnvironment.xDataControl.refresh();
}else if(isExist(actionEnvironment.refresh)){
actionEnvironment.refresh();
}
}
/**
* 关闭
*
* @param params 界面行为参数对象
* @return {*}
*/
public static exit(params: IUIActionParams) {
const { actionEnvironment } = params;
if(isExist(actionEnvironment.closeView)){
actionEnvironment.refresh();
}
}
/**
* 保存并关闭
*
* @param params 界面行为参数对象
* @return {*}
*/
public static async saveAndExit(params: IUIActionParams) {
const { actionEnvironment } = params;
// 视图里获取多数据部件
if(hasFunction(actionEnvironment.xDataControl, "save")){
await actionEnvironment.xDataControl.save();
}else if(isExist(actionEnvironment.save)){
await actionEnvironment.save();
}
// 关闭视图
this.exit(params);
}
/**
* 删除并关闭
*
* @param params 界面行为参数对象
* @return {*}
*/
public static async removeAndExit(params: IUIActionParams) {
const { actionEnvironment } = params;
// 视图里获取多数据部件
if(hasFunction(actionEnvironment.xDataControl, "remove")){
await actionEnvironment.xDataControl.remove();
}else if(isExist(actionEnvironment.remove)){
await actionEnvironment.remove();
}
// 关闭视图
this.exit(params);
}
/**
* 过滤
*
* @param params 界面行为参数对象
* @return {*}
*/
public static toggleFilter(params: IUIActionParams) {
const { actionEnvironment } = params;
if(isExist(actionEnvironment.state.expandSearchForm)){
actionEnvironment.state.expandSearchForm = !actionEnvironment.state.expandSearchForm;
}
}
}
......@@ -44,7 +44,7 @@ export class MainView extends ViewBase {
const inputParam = {
context: this.state.context,
viewParams: this.state.viewParams,
data: this.xDataControl?.value?.data,
data: this.xDataControl?.getData?.(),
event: data.event,
actionEnvironment: this
};
......@@ -58,7 +58,12 @@ export class MainView extends ViewBase {
* @param {IActionParam} actionParam
* @memberof MainView
*/
public onCtrlEvent(actionParam: IActionParam) { }
public onCtrlEvent(actionParam: IActionParam) {
const { tag, action, data } = actionParam;
if (Object.is(action, 'closeView')) {
this.closeView();
}
}
/**
* @description 安装视图所有功能模块的方法
......
......@@ -88,6 +88,14 @@ export class ViewBase {
viewSubject.next({ tag: tag, action: action, data: data })
}
/**
* 关闭视图
*
*/
public closeView(){
window.history.go(-1);
}
/**
* @description 处理视图导航参数
*
......
......@@ -74,6 +74,14 @@ export class ControlBase {
return [];
}
/**
* 关闭视图
*
*/
public closeView(){
this.emit('ctrlEvent', { tag: this.props.name, action: 'closeView', data: undefined });
}
/**
* @description 安装部件所有功能模块的方法
* @param {ControlPropsBase} props 传入的Props
......@@ -86,7 +94,7 @@ export class ControlBase {
this.useControlContextParams();
return {
state: this.state,
activeData: this.getData()
getData: this.getData
};
}
}
......@@ -358,7 +358,6 @@ export class FormControl extends MainControl {
/**
* @description 使用加载草稿功能模块
* @param {FormControlProps} props 传入的props
* @return {*}
* @memberof FormControl
*/
......@@ -579,11 +578,10 @@ export class FormControl extends MainControl {
/**
* @description 使用加载功能模块
* @param {FormControlProps} props 传入的props
* @return {*}
* @memberof FormControl
*/
public useRemove(props: FormControlProps) {
public useRemove() {
const { viewSubject, controlName } = this.state;
/**
......@@ -632,7 +630,7 @@ export class FormControl extends MainControl {
// 订阅viewSubject,监听load行为
if (viewSubject) {
let subscription = viewSubject.subscribe(({ tag, action, data }: IActionParam) => {
if (Object.is(controlName, tag) && Object.is('load', action)) {
if (Object.is(controlName, tag) && Object.is('remove', action)) {
remove(data);
}
});
......@@ -646,6 +644,52 @@ export class FormControl extends MainControl {
return remove;
}
/**
* 刷新行为
*
* @protected
* @param [opt={}]
*/
protected async refresh(opt: any = {}) {}
/**
* @description 使用刷新功能模块
* @return {*}
* @memberof FormControl
*/
public useRefresh() {
const { viewSubject, controlName } = this.state;
/**
* 刷新行为
*
* @param [opt={}]
* @return {*}
*/
const refresh = async (opt: any = {}) => {
this.load(opt);
};
// 在类里绑定能力方法
this.refresh = refresh;
// 订阅viewSubject,监听load行为
if (viewSubject) {
let subscription = viewSubject.subscribe(({ tag, action, data }: IActionParam) => {
if (Object.is(controlName, tag) && Object.is('refresh', action)) {
refresh(data);
}
});
// 部件卸载时退订viewSubject
onUnmounted(() => {
subscription.unsubscribe();
});
}
return refresh;
}
/**
* @description 处理编辑器事件
* @param {IActionParam} actionParam 行为参数
......@@ -700,6 +744,7 @@ export class FormControl extends MainControl {
load: this.useLoad(),
loadDraft: this.useLoadDraft(),
save: this.useSave(),
refresh: this.useRefresh(),
onEditorEvent: this.onEditorEvent.bind(this),
onComponentEvent: this.onComponentEvent.bind(this),
};
......
......@@ -87,6 +87,8 @@ export class GridControl extends MDControl {
selection.push(select);
}
})
// 选中赋值
this.state.selectedData = selection;
this.emit("ctrlEvent", { tag: this.props.name, action: "selectionChange", data: selection })
},
};
......
import { MDControlState, MainControl, deepCopy, IActionParam, IParam } from '@core';
import { MDControlState, MainControl, deepCopy, IActionParam, IParam, UIBase } from '@core';
/**
* @description 多数据部件
......@@ -24,7 +24,7 @@ export class MDControl extends MainControl {
this.state.isMultiple = toRef(this.props, 'isMultiple') as any;
this.state.rowEditState = toRef(this.props, 'rowEditState') as any;
this.state.rowActiveMode = toRef(this.props, 'rowActiveMode') as any;
this.state.selectedData = toRef(this.props, 'selectedData') as any;
this.state.selectedData = UIBase.toOneWayRef(this.props, 'selectedData') as any;
this.state.selectFirstDefault = toRef(this.props, 'selectFirstDefault') as any;
}
......@@ -67,14 +67,14 @@ export class MDControl extends MainControl {
Object.assign(arg, tempViewParams);
// 组装视图其他查询参数
this.emit("ctrlEvent", { tag: this.props.name, action: 'beforeload', data: arg });
this.emit('ctrlEvent', { tag: this.props.name, action: 'beforeload', data: arg });
const response = await controlService.search(tempContext, arg, {
action: controlAction.fetchAction,
isLoading: showBusyIndicator,
});
if (response.status || response.status == 200) {
this.state.items = response.data;
this.emit("ctrlEvent", { tag: this.props.name, action: 'load', data: response.data });
this.emit('ctrlEvent', { tag: this.props.name, action: 'load', data: response.data });
if (enablePagingBar) {
this.state.mdCtrlPaging.pagination['total'] = response.total;
}
......@@ -128,6 +128,7 @@ export class MDControl extends MainControl {
const { updateAction, createAction } = controlAction;
const saveAction: any =
item.rowDataState == 'update' ? updateAction : item.rowDataState == 'create' ? createAction : '';
const saveFunName = item.rowDataState == 'update' ? 'update' : 'create';
if (!saveAction) {
return;
}
......@@ -136,7 +137,7 @@ export class MDControl extends MainControl {
let _viewParams = deepCopy(viewParams);
Object.assign(arg, item.getDo());
Object.assign(arg, { viewParams: _viewParams });
const response = await controlService[saveAction](_context, arg, {
const response = await controlService[saveFunName](_context, arg, {
action: saveAction,
isLoading: showBusyIndicator,
});
......@@ -306,6 +307,52 @@ export class MDControl extends MainControl {
return newRow;
}
/**
* 刷新行为
*
* @protected
* @param [opt={}]
*/
protected async refresh(opt: any = {}) {}
/**
* @description 使用刷新功能模块
* @return {*}
* @memberof MDControl
*/
public useRefresh() {
const { viewSubject, controlName } = this.state;
/**
* 刷新行为
*
* @param [opt={}]
* @return {*}
*/
const refresh = async (opt: any = {}) => {
this.load(opt);
};
// 在类里绑定能力方法
this.refresh = refresh;
// 订阅viewSubject,监听load行为
if (viewSubject) {
let subscription = viewSubject.subscribe(({ tag, action, data }: IActionParam) => {
if (Object.is(controlName, tag) && Object.is('refresh', action)) {
refresh(data);
}
});
// 部件卸载时退订viewSubject
onUnmounted(() => {
subscription.unsubscribe();
});
}
return refresh;
}
/**
* 处理数据状态变化(逻辑数据+UI)
*
......@@ -351,8 +398,7 @@ export class MDControl extends MainControl {
* @memberof MDControl
*/
public getData(): IParam[] {
const { selectedData } = this.state;
return selectedData;
return this.state.selectedData;
}
/**
......@@ -368,6 +414,7 @@ export class MDControl extends MainControl {
save: this.useSave(),
remove: this.useRemove(),
newRow: this.useNewRow(),
refresh: this.useRefresh(),
};
}
}
......@@ -36,11 +36,11 @@ interface CtrlEmit {
const emit = defineEmits<CtrlEmit>();
// 安装功能模块,提供状态和能力
const { state, useCustom, onEditorEvent, onToolbarEvent, newRow, remove, save, load } = new GridControl(ctrlState, props, emit).moduleInstall();
const { state, useCustom, onEditorEvent, onToolbarEvent, newRow, remove, save, load, refresh, getData } = new GridControl(ctrlState, props, emit).moduleInstall();
const { useScrollOption, useRowKey, useRowClassName, useCustomRow, useRowSelectionOption, onResizeColumn, onGridChange } = useCustom;
// 暴露内部状态及能力
defineExpose({ state, name: '{{ctrl.name}}', newRow, remove, save, load });
defineExpose({ state, name: '{{ctrl.name}}', newRow, remove, save, load, refresh, getData });
</script>
<template>
<a-table
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册