提交 12c8ec96 编写于 作者: KK's avatar KK

修复快速分组异常

上级 e6bdee4b
...@@ -29,25 +29,18 @@ ...@@ -29,25 +29,18 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { import { Vue, Component, Prop, Provide, Emit, Watch, } from "vue-property-decorator";
Vue,
Component,
Prop,
Provide,
Emit,
Watch,
} from "vue-property-decorator";
@Component({ @Component({
components: {}, components: {},
}) })
export default class AppQuickGroupTab extends Vue { export default class AppQuickGroupTab extends Vue {
/** /**
* 快速分组代码表 * 快速分组代码表
* *
* @type {any[]} * @type {any[]}
* @memberof ViewQuickGroupTab * @memberof ViewQuickGroupTab
*/ */
@Prop({ default: () => [] }) public items!: Array<any>; @Prop({ default: () => [] }) public items!: Array<any>;
/** /**
* 快速分组代码表 * 快速分组代码表
...@@ -55,160 +48,159 @@ export default class AppQuickGroupTab extends Vue { ...@@ -55,160 +48,159 @@ export default class AppQuickGroupTab extends Vue {
* @type {any[]} * @type {any[]}
* @memberof ViewQuickGroupTab * @memberof ViewQuickGroupTab
*/ */
@Prop({ default:0 }) public pageTotal!: number; @Prop({ default: 0 }) public pageTotal!: number;
/** /**
* 渲染列表 * 渲染列表
* *
* @type {any[]} * @type {any[]}
* @memberof AppQuickGroup * @memberof AppQuickGroup
*/ */
public showItems: any[] = []; public showItems: any[] = [];
/** /**
* 子项列表 * 子项列表
* *
* @type {any[]} * @type {any[]}
* @memberof AppQuickGroup * @memberof AppQuickGroup
*/ */
public subItems: any[] = []; public subItems: any[] = [];
/** /**
* 监控代码表变化 * 监控代码表变化
* *
* @memberof AppQuickGroup * @memberof AppQuickGroup
*/ */
@Watch("items", { immediate: true }) @Watch("items", { immediate: true })
public itemsWatch(): void { public itemsWatch(): void {
if (this.items) { if (this.items) {
this.items.every((item: any) => { this.items.every((item: any) => {
if (item.default) { if (item.default) {
this.$nextTick(() => { this.$nextTick(() => {
this.handleClick(item, true); this.handleClick(item, true, true);
}) })
}
return !item.default;
});
this.showItems = this.handleDataSet(this.items);
} }
return !item.default;
});
this.showItems = this.handleDataSet(this.items);
} }
}
/** /**
* UI选中项 * UI选中项
* *
* @type {*} * @type {*}
* @memberof AppQuickGroup * @memberof AppQuickGroup
*/ */
public selectedUiItem: any = {}; public selectedUiItem: any = {};
/** /**
* 是否选中当前项 * 是否选中当前项
* *
* @param item 传入当前项 * @param item 传入当前项
* @memberof AppQuickGroup * @memberof AppQuickGroup
*/ */
public isSelectedItem(item: any): boolean { public isSelectedItem(item: any): boolean {
if (this.selectedUiItem && this.selectedUiItem.id === item.id) { if (this.selectedUiItem && this.selectedUiItem.id === item.id) {
return true; return true;
} else { } else {
return false; return false;
}
} }
}
/** /**
* 处理代码表返回数据(树状结构) * 处理代码表返回数据(树状结构)
* *
* @param result 返回数组 * @param result 返回数组
* @memberof AppQuickGroup * @memberof AppQuickGroup
*/ */
public handleDataSet(result: Array<any>): any[] { public handleDataSet(result: Array<any>): any[] {
let list: Array<any> = []; let list: Array<any> = [];
if (result.length === 0) { if (result.length === 0) {
return list; return list;
}
result.forEach((codeItem: any) => {
if (!codeItem.pvalue) {
let valueField: string = codeItem.value;
this.setChildCodeItems(valueField, result, codeItem);
list.push(codeItem);
}
});
return list;
} }
result.forEach((codeItem: any) => {
if (!codeItem.pvalue) {
let valueField: string = codeItem.value;
this.setChildCodeItems(valueField, result, codeItem);
list.push(codeItem);
}
});
return list;
}
/** /**
* 处理非根节点数据 * 处理非根节点数据
* *
* @param pValue 父值 * @param pValue 父值
* @param result 返回数组 * @param result 返回数组
* @param codeItem 代码项 * @param codeItem 代码项
* @memberof AppQuickGroup * @memberof AppQuickGroup
*/ */
public setChildCodeItems( public setChildCodeItems(pValue: string, result: Array<any>, codeItem: any): void {
pValue: string, result.forEach((item: any) => {
result: Array<any>, if (item.pvalue == pValue) {
codeItem: any let valueField: string = item.value;
): void { this.setChildCodeItems(valueField, result, item);
result.forEach((item: any) => { if (!codeItem.children) {
if (item.pvalue == pValue) { codeItem.children = [];
let valueField: string = item.value; }
this.setChildCodeItems(valueField, result, item); codeItem.children.push(item);
if (!codeItem.children) { }
codeItem.children = []; });
}
/**
* 处理点击事件
*
* @param $event 值
* @param isswitch 是否切换UI选中项
* @memberof AppQuickGroup
*/
public handleClick($event: any, isswitch: boolean = true, isDefalut: boolean = false): void {
if (isswitch) {
this.selectedUiItem = $event;
} }
codeItem.children.push(item); if ($event.children) {
} if (this.subItems.length > 0) {
}); this.subItems.length = 0;
} } else {
this.subItems.push(...$event.children);
}
} else {
this.subItems.length = 0;
this.items.forEach((item: any) => {
item.selected = false;
item.childSelected = false;
item.selectChildLabel = "";
})
$event.selected = true;
if ($event.pvalue) {
this.items.forEach((item: any) => {
if (item.value === $event.pvalue) {
item.childSelected = true;
item.selectChildLabel = $event.label;
}
})
}
if (!isDefalut) {
this.$emit("valuechange", $event);
}
/** }
* 处理点击事件 this.$forceUpdate();
*
* @param $event 值
* @param isswitch 是否切换UI选中项
* @memberof AppQuickGroup
*/
public handleClick($event: any, isswitch: boolean = true): void {
if (isswitch) {
this.selectedUiItem = $event;
} }
if ($event.children) {
if (this.subItems.length > 0) { /**
* 关闭遮罩层
*
* @type {any[]}
* @memberof AppQuickGroup
*/
public closeBackdrop() {
this.subItems.length = 0; this.subItems.length = 0;
} else { this.$forceUpdate();
this.subItems.push(...$event.children);
}
} else {
this.subItems.length = 0;
this.items.forEach((item:any) => {
item.selected = false;
item.childSelected = false;
item.selectChildLabel = "";
})
$event.selected = true;
if ($event.pvalue) {
this.items.forEach((item:any) => {
if (item.value === $event.pvalue) {
item.childSelected = true;
item.selectChildLabel = $event.label;
}
})
}
this.$emit("valuechange", $event);
} }
this.$forceUpdate();
}
/**
* 关闭遮罩层
*
* @type {any[]}
* @memberof AppQuickGroup
*/
public closeBackdrop () {
this.subItems.length = 0;
this.$forceUpdate();
}
} }
</script> </script>
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册