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

update: 系统预置界面行为

上级 c183d531
...@@ -68,6 +68,21 @@ export class AppSysAction { ...@@ -68,6 +68,21 @@ export class AppSysAction {
case 'NewRow': case 'NewRow':
this.newRow(params); this.newRow(params);
break; 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: default:
console.log(`未支持${tag}`); console.log(`未支持${tag}`);
} }
...@@ -188,4 +203,82 @@ export class AppSysAction { ...@@ -188,4 +203,82 @@ export class AppSysAction {
actionEnvironment.remove(); 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 { ...@@ -44,7 +44,7 @@ export class MainView extends ViewBase {
const inputParam = { const inputParam = {
context: this.state.context, context: this.state.context,
viewParams: this.state.viewParams, viewParams: this.state.viewParams,
data: this.xDataControl?.value?.data, data: this.xDataControl?.getData?.(),
event: data.event, event: data.event,
actionEnvironment: this actionEnvironment: this
}; };
...@@ -58,7 +58,12 @@ export class MainView extends ViewBase { ...@@ -58,7 +58,12 @@ export class MainView extends ViewBase {
* @param {IActionParam} actionParam * @param {IActionParam} actionParam
* @memberof MainView * @memberof MainView
*/ */
public onCtrlEvent(actionParam: IActionParam) { } public onCtrlEvent(actionParam: IActionParam) {
const { tag, action, data } = actionParam;
if (Object.is(action, 'closeView')) {
this.closeView();
}
}
/** /**
* @description 安装视图所有功能模块的方法 * @description 安装视图所有功能模块的方法
......
...@@ -88,6 +88,14 @@ export class ViewBase { ...@@ -88,6 +88,14 @@ export class ViewBase {
viewSubject.next({ tag: tag, action: action, data: data }) viewSubject.next({ tag: tag, action: action, data: data })
} }
/**
* 关闭视图
*
*/
public closeView(){
window.history.go(-1);
}
/** /**
* @description 处理视图导航参数 * @description 处理视图导航参数
* *
......
...@@ -74,6 +74,14 @@ export class ControlBase { ...@@ -74,6 +74,14 @@ export class ControlBase {
return []; return [];
} }
/**
* 关闭视图
*
*/
public closeView(){
this.emit('ctrlEvent', { tag: this.props.name, action: 'closeView', data: undefined });
}
/** /**
* @description 安装部件所有功能模块的方法 * @description 安装部件所有功能模块的方法
* @param {ControlPropsBase} props 传入的Props * @param {ControlPropsBase} props 传入的Props
...@@ -86,7 +94,7 @@ export class ControlBase { ...@@ -86,7 +94,7 @@ export class ControlBase {
this.useControlContextParams(); this.useControlContextParams();
return { return {
state: this.state, state: this.state,
activeData: this.getData() getData: this.getData
}; };
} }
} }
...@@ -358,7 +358,6 @@ export class FormControl extends MainControl { ...@@ -358,7 +358,6 @@ export class FormControl extends MainControl {
/** /**
* @description 使用加载草稿功能模块 * @description 使用加载草稿功能模块
* @param {FormControlProps} props 传入的props
* @return {*} * @return {*}
* @memberof FormControl * @memberof FormControl
*/ */
...@@ -579,11 +578,10 @@ export class FormControl extends MainControl { ...@@ -579,11 +578,10 @@ export class FormControl extends MainControl {
/** /**
* @description 使用加载功能模块 * @description 使用加载功能模块
* @param {FormControlProps} props 传入的props
* @return {*} * @return {*}
* @memberof FormControl * @memberof FormControl
*/ */
public useRemove(props: FormControlProps) { public useRemove() {
const { viewSubject, controlName } = this.state; const { viewSubject, controlName } = this.state;
/** /**
...@@ -632,7 +630,7 @@ export class FormControl extends MainControl { ...@@ -632,7 +630,7 @@ export class FormControl extends MainControl {
// 订阅viewSubject,监听load行为 // 订阅viewSubject,监听load行为
if (viewSubject) { if (viewSubject) {
let subscription = viewSubject.subscribe(({ tag, action, data }: IActionParam) => { 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); remove(data);
} }
}); });
...@@ -646,6 +644,52 @@ export class FormControl extends MainControl { ...@@ -646,6 +644,52 @@ export class FormControl extends MainControl {
return remove; 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 处理编辑器事件 * @description 处理编辑器事件
* @param {IActionParam} actionParam 行为参数 * @param {IActionParam} actionParam 行为参数
...@@ -700,6 +744,7 @@ export class FormControl extends MainControl { ...@@ -700,6 +744,7 @@ export class FormControl extends MainControl {
load: this.useLoad(), load: this.useLoad(),
loadDraft: this.useLoadDraft(), loadDraft: this.useLoadDraft(),
save: this.useSave(), save: this.useSave(),
refresh: this.useRefresh(),
onEditorEvent: this.onEditorEvent.bind(this), onEditorEvent: this.onEditorEvent.bind(this),
onComponentEvent: this.onComponentEvent.bind(this), onComponentEvent: this.onComponentEvent.bind(this),
}; };
......
...@@ -87,6 +87,8 @@ export class GridControl extends MDControl { ...@@ -87,6 +87,8 @@ export class GridControl extends MDControl {
selection.push(select); selection.push(select);
} }
}) })
// 选中赋值
this.state.selectedData = selection;
this.emit("ctrlEvent", { tag: this.props.name, action: "selectionChange", data: 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 多数据部件 * @description 多数据部件
...@@ -24,7 +24,7 @@ export class MDControl extends MainControl { ...@@ -24,7 +24,7 @@ export class MDControl extends MainControl {
this.state.isMultiple = toRef(this.props, 'isMultiple') as any; this.state.isMultiple = toRef(this.props, 'isMultiple') as any;
this.state.rowEditState = toRef(this.props, 'rowEditState') as any; this.state.rowEditState = toRef(this.props, 'rowEditState') as any;
this.state.rowActiveMode = toRef(this.props, 'rowActiveMode') 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; this.state.selectFirstDefault = toRef(this.props, 'selectFirstDefault') as any;
} }
...@@ -67,14 +67,14 @@ export class MDControl extends MainControl { ...@@ -67,14 +67,14 @@ export class MDControl extends MainControl {
Object.assign(arg, tempViewParams); 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, { const response = await controlService.search(tempContext, arg, {
action: controlAction.fetchAction, action: controlAction.fetchAction,
isLoading: showBusyIndicator, isLoading: showBusyIndicator,
}); });
if (response.status || response.status == 200) { if (response.status || response.status == 200) {
this.state.items = response.data; 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) { if (enablePagingBar) {
this.state.mdCtrlPaging.pagination['total'] = response.total; this.state.mdCtrlPaging.pagination['total'] = response.total;
} }
...@@ -128,6 +128,7 @@ export class MDControl extends MainControl { ...@@ -128,6 +128,7 @@ export class MDControl extends MainControl {
const { updateAction, createAction } = controlAction; const { updateAction, createAction } = controlAction;
const saveAction: any = const saveAction: any =
item.rowDataState == 'update' ? updateAction : item.rowDataState == 'create' ? createAction : ''; item.rowDataState == 'update' ? updateAction : item.rowDataState == 'create' ? createAction : '';
const saveFunName = item.rowDataState == 'update' ? 'update' : 'create';
if (!saveAction) { if (!saveAction) {
return; return;
} }
...@@ -136,7 +137,7 @@ export class MDControl extends MainControl { ...@@ -136,7 +137,7 @@ export class MDControl extends MainControl {
let _viewParams = deepCopy(viewParams); let _viewParams = deepCopy(viewParams);
Object.assign(arg, item.getDo()); Object.assign(arg, item.getDo());
Object.assign(arg, { viewParams: _viewParams }); Object.assign(arg, { viewParams: _viewParams });
const response = await controlService[saveAction](_context, arg, { const response = await controlService[saveFunName](_context, arg, {
action: saveAction, action: saveAction,
isLoading: showBusyIndicator, isLoading: showBusyIndicator,
}); });
...@@ -306,6 +307,52 @@ export class MDControl extends MainControl { ...@@ -306,6 +307,52 @@ export class MDControl extends MainControl {
return newRow; 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) * 处理数据状态变化(逻辑数据+UI)
* *
...@@ -351,8 +398,7 @@ export class MDControl extends MainControl { ...@@ -351,8 +398,7 @@ export class MDControl extends MainControl {
* @memberof MDControl * @memberof MDControl
*/ */
public getData(): IParam[] { public getData(): IParam[] {
const { selectedData } = this.state; return this.state.selectedData;
return selectedData;
} }
/** /**
...@@ -368,6 +414,7 @@ export class MDControl extends MainControl { ...@@ -368,6 +414,7 @@ export class MDControl extends MainControl {
save: this.useSave(), save: this.useSave(),
remove: this.useRemove(), remove: this.useRemove(),
newRow: this.useNewRow(), newRow: this.useNewRow(),
refresh: this.useRefresh(),
}; };
} }
} }
...@@ -36,11 +36,11 @@ interface CtrlEmit { ...@@ -36,11 +36,11 @@ interface CtrlEmit {
const emit = defineEmits<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; 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> </script>
<template> <template>
<a-table <a-table
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册