提交 0e167c54 编写于 作者: Mosher's avatar Mosher

update:更新多项选择视图逻辑

上级 85348837
......@@ -24,11 +24,9 @@ export class MPickupView extends PickupView {
*/
public declare props: MPickupViewProps;
public select: IParam = {};
public onMoveRight() {
const { selections, selectedData } = toRefs(this.state);
selections.value.push(selectedData.value);
selections.value = selectedData.value;
}
public onMoveLeft() {
......@@ -44,8 +42,13 @@ export class MPickupView extends PickupView {
}
public onAllMoveLeft() {
const { selections } = toRefs(this.state);
selections.value.splice(0, selections.value.length);
const { selections, selectedData } = toRefs(this.state);
selections.value = [];
selectedData.value = [];
}
protected onRightPanelClick(item: IParam, event: MouseEvent) {
console.log("选中右侧面板数据", item, event);
}
/**
......@@ -61,6 +64,7 @@ export class MPickupView extends PickupView {
onMoveLeft: this.onMoveLeft.bind(this),
onAllMoveRight: this.onAllMoveRight.bind(this),
onAllMoveLeft: this.onAllMoveLeft.bind(this),
onRightPanelClick: this.onRightPanelClick.bind(this)
};
}
}
\ No newline at end of file
......@@ -87,14 +87,6 @@ export class ControlBase {
});
}
/**
* 使用部件初始化模块
*
* @protected
* @memberof ControlBase
*/
protected useCtrlInit(): void {};
/**
* 获取当前激活数据
*
......@@ -133,8 +125,6 @@ export class ControlBase {
this.useControlContextParams();
// 使用计数器服务
this.useCounterService();
// 使用部件初始化模块
this.useCtrlInit();
return {
state: this.state,
name: this.state.controlName,
......
......@@ -358,30 +358,13 @@ export class GridControl extends MDControl {
* @memberof GridControl
*/
public handleDefaultSelect() {
const { selectedData, selectFirstDefault, items } = this.state;
const { selectedRowKeys, selections } = toRefs(this.state);
if (selectedData?.length > 0) {
const _selectedRowKeys: string[] = [];
const _selections: IParam[] = [];
selectedData.forEach((selected: IParam) => {
if (selected.srfkey) {
_selectedRowKeys.push(selected.srfkey);
const item = items.find((item: IParam) => item.srfkey === selected.srfkey);
if (item) {
_selections.push(item);
}
}
const { selectFirstDefault, items } = this.state;
if (selectFirstDefault && items && items.length) {
this.emit("ctrlEvent", {
tag: this.props.name,
action: "selectionChange",
data: [deepCopy(items[0])],
});
selectedRowKeys.value = [..._selectedRowKeys];
selections.value = [..._selections];
} else if (selectFirstDefault) {
if (items && items.length > 0) {
this.emit("ctrlEvent", {
tag: this.props.name,
action: "selectionChange",
data: [deepCopy(items[0])],
});
}
}
}
......
......@@ -71,13 +71,6 @@ export interface MDControlState extends MainControlState {
*/
rowActiveMode: 0 | 1 | 2;
/**
* @description 选中数据(选择视图传递)
* @type {IParam[]}
* @memberof MDControlState
*/
selectedData: IParam[];
/**
* @description 选中数据
* @type {IParam[]}
......
......@@ -26,11 +26,9 @@ export class MDControl extends MainControl {
this.state.rowEditState = toRef(this.props, 'rowEditState') as any;
this.state.rowActiveMode = toRef(this.props, 'rowActiveMode') as any;
this.state.selectFirstDefault = toRef(this.props, 'selectFirstDefault') as any;
}
protected useCtrlInit() {
super.useCtrlInit();
this.handleSelectedData();
watch(() => this.props.selectedData, (newVal: IParam[], oldVal: any) => {
this.handleSelectedData(newVal, oldVal);
});
}
/**
......@@ -39,22 +37,22 @@ export class MDControl extends MainControl {
* @private
* @memberof MDControl
*/
protected handleSelectedData() {
const { viewParams } = this.state;
// 存在该字段则表示在选择视图中
if (viewParams && viewParams.selectedData) {
const data = viewParams.selectedData[0];
const keys = data?.srfkey?.split(',') || [];
this.state.selectedData = [];
if (keys.length) {
keys.forEach((key: string) => {
this.state.selectedData.push({ srfkey: key });
});
} else {
// 无值时给一个空对象,确保清空选中数据
this.state.selectedData.push({});
protected handleSelectedData(newVal: IParam[], oldVal: any) {
const { selections, selectedRowKeys, items } = toRefs(this.state);
selections.value = [];
const _selectedRowKeys: string[] = [];
const _selections: IParam[] = [];
newVal.forEach((selected: IParam) => {
if (selected.srfkey) {
_selectedRowKeys.push(selected.srfkey);
const item = items.value.find((item: IParam) => item.srfkey === selected.srfkey);
if (item) {
_selections.push(item);
}
}
}
});
selectedRowKeys.value = [..._selectedRowKeys];
selections.value = [..._selections];
}
/**
......@@ -553,8 +551,8 @@ export class MDControl extends MainControl {
let tempContext = deepCopy(context ? context : {});
try {
const response = await controlService.search(tempContext, arg, {
action: controlAction.fetchAction,
isLoading: showBusyIndicator
action: controlAction.fetchAction,
isLoading: showBusyIndicator
});
if (!response || response.status !== 200) {
App.getNotificationService().warning({
......
......@@ -18,16 +18,6 @@ export class PickupViewPanelControl extends MainControl {
*/
public declare state: PickupViewPanelControlState;
/**
* 设置部件状态
*
* @memberof PickupViewPanelControl
*/
public setState(): void {
super.setState();
this.state.selectedData = toRef(this.props, 'selectedData') as any;
}
/**
* @description
* @param {PickupViewPanelControlProps} props
......
export const viewState = {
// 实际选中数据
selections: [],
// 右侧面板选中数据
rightPanelSelections: [],
{{> @macro/front-end/views/view-base-config.hbs}}
};
\ No newline at end of file
......@@ -30,7 +30,7 @@ const emit = defineEmits<ViewEmit>();
// 安装功能模块,提供状态和能力方法
const mpickupView = new MPickupView(viewState, props, emit).moduleInstall();
const { state, onCancel, onConfirm, onCtrlEvent, onMoveRight, onMoveLeft, onAllMoveRight, onAllMoveLeft } = mpickupView;
const { state, onCancel, onConfirm, onCtrlEvent, onMoveRight, onMoveLeft, onAllMoveRight, onAllMoveLeft, onRightPanelClick } = mpickupView;
</script>
<template>
......@@ -63,6 +63,7 @@ const { state, onCancel, onConfirm, onCtrlEvent, onMoveRight, onMoveLeft, onAllM
:controlAction="state.{{name}}.action"
:viewSubject="state.viewSubject"
:multiple="true"
:selectedData="state.selections"
:parent="mpickupView"
@onCtrlEvent="onCtrlEvent"
></{{codeName}}PickupViewPanel>
......@@ -78,7 +79,9 @@ const { state, onCancel, onConfirm, onCtrlEvent, onMoveRight, onMoveLeft, onAllM
</a-space>
</a-col>
<a-col :span="5" class="split__right">
<div v-for="(item,index) in state.selections" :key="index">\{{item.srfmajortext}}</div>
<div v-for="(item, index) in state.selections" :key="index" class="selection-item" @click="(event) => onRightPanelClick(item, event)">
<span class="text">\{{item.srfmajortext}}</span>
</div>
</a-col>
</a-row>
<template v-slot:footer>
......
......@@ -22,7 +22,7 @@ interface Props {
viewParams?: IParam;
openType?: "ROUTE" | "MODAL" | "EMBED";
viewSubject?: Subject<IActionParam>;
selectedData?: string;
selectedData?: IParam[];
multiple?: boolean;
}
......@@ -113,6 +113,7 @@ const { state, grid, onCtrlEvent, onQuickGroupEvent, onQuickSearchEvent } = pick
:showBusyIndicator="true"
:viewParams="state.viewParams"
:controlAction="state.{{name}}.action"
:selectedData="selectedData"
:viewSubject="state.viewSubject"
:parent="pickupGridView"
@ctrlEvent="onCtrlEvent"
......
......@@ -22,7 +22,7 @@ interface Props {
viewParams?: IParam;
openType?: "ROUTE" | "MODAL" | "EMBED";
viewSubject?: Subject<IActionParam>;
selectedData?: string;
selectedData?: IParam[];
}
const props = withDefaults(defineProps<Props>(), {
......@@ -111,6 +111,7 @@ const { state, tree, onCtrlEvent, onQuickGroupEvent, onQuickSearchEvent } = pick
:controlAction="state.{{name}}.action"
:viewSubject="state.viewSubject"
:parent="pickupTreeView"
:selectedData="selectedData"
@ctrlEvent="onCtrlEvent"
></{{codeName}}Tree>
{{/eq}}
......
......@@ -14,6 +14,7 @@ interface Props {
multiple?: boolean;
rowEditState?: boolean;
rowActiveMode?: 0 | 1 | 2;
selectedData: IParam[];
selectFirstDefault?: boolean;
controlAction: ControlAction;
showBusyIndicator?: boolean;
......
......@@ -14,7 +14,7 @@ interface Props {
showBusyIndicator?: boolean;
isSingleSelect?: boolean;
viewMode?: number;
selectedData?: string;
selectedData?: IParam[];
isShowButton?: boolean;
viewSubject: Subject<IActionParam>;
multiple?: boolean;
......@@ -51,7 +51,7 @@ defineExpose({ name, state});
:context="state.context"
:viewParams="state.viewParams"
:isShowButton="state.isShowButton"
:selectedData="state.selectedData"
:selectedData="selectedData"
:viewSubject="state.viewSubject"
:multiple="multiple"
@viewEvent="onViewEvent"
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册