Conformance: infinite scroll done.
This commit is contained in:
@@ -43,15 +43,12 @@
|
||||
<div id="cfmTrace" ref="cfmTrace" class="h-full min-w-full relative"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="overflow-y-auto overflow-x-auto scrollbar h-[calc(100%_-_264px)]">
|
||||
<DataTable :value="caseData" showGridlines tableClass="text-sm" breakpoint="0">
|
||||
<div class="overflow-y-auto overflow-x-auto scrollbar h-[calc(100%_-_264px)] infiniteTable" @scroll="handleScroll">
|
||||
<DataTable :value="caseData" showGridlines tableClass="text-sm " breakpoint="0">
|
||||
<div v-for="(col, index) in columnData" :key="index">
|
||||
<Column :field="col.field" :header="col.header" sortable></Column>
|
||||
</div>
|
||||
</DataTable>
|
||||
<!-- <infinite-loading @infinite="infiniteHandler"></infinite-loading> -->
|
||||
<!-- <div v-if="!maxItems">Loading more...</div>
|
||||
<div v-else>No more data available.</div> -->
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
@@ -63,22 +60,20 @@ import ConformanceStore from '@/stores/conformance.js';
|
||||
import cytoscapeMapTrace from '@/module/cytoscapeMapTrace.js';
|
||||
|
||||
export default {
|
||||
props: ['issusModal', 'issusNo'],
|
||||
props: ['issusModal', 'issusNo', 'traceId', 'firstCases'],
|
||||
setup() {
|
||||
const conformanceStore = ConformanceStore();
|
||||
const { issueTraces, taskSeq, cases } = storeToRefs(conformanceStore);
|
||||
const { issueTraces, taskSeq, cases, infinite404 } = storeToRefs(conformanceStore);
|
||||
|
||||
return { issueTraces, taskSeq, cases, conformanceStore }
|
||||
return { issueTraces, taskSeq, cases, infinite404, conformanceStore }
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
contentClass: '!bg-neutral-100 border-t border-neutral-300 h-full',
|
||||
showTraceId: 1,
|
||||
infiniteData: [],
|
||||
busy: false,
|
||||
showTraceId: null,
|
||||
infiniteData: null,
|
||||
maxItems: false,
|
||||
start: 0,
|
||||
pageSize: 20,
|
||||
startNum: 0,
|
||||
processMap:{
|
||||
nodes:[],
|
||||
edges:[],
|
||||
@@ -102,14 +97,16 @@ export default {
|
||||
}).sort((x, y) => x.id - y.id);
|
||||
},
|
||||
caseData: function() {
|
||||
const data = JSON.parse(JSON.stringify(this.cases)); // 深拷貝原始 cases 的內容
|
||||
data.forEach(item => {
|
||||
item.attributes.forEach((attribute, index) => {
|
||||
item[`att_${index}`] = attribute.value; // 建立新的 key-value pair
|
||||
});
|
||||
delete item.attributes; // 刪除原本的 attributes 屬性
|
||||
})
|
||||
return data;
|
||||
if(this.infiniteData !== null){
|
||||
const data = JSON.parse(JSON.stringify(this.infiniteData)); // 深拷貝原始 cases 的內容
|
||||
data.forEach(item => {
|
||||
item.attributes.forEach((attribute, index) => {
|
||||
item[`att_${index}`] = attribute.value; // 建立新的 key-value pair
|
||||
});
|
||||
delete item.attributes; // 刪除原本的 attributes 屬性
|
||||
})
|
||||
return data;
|
||||
}
|
||||
},
|
||||
columnData: function() {
|
||||
const data = JSON.parse(JSON.stringify(this.cases)); // 深拷貝原始 cases 的內容
|
||||
@@ -122,6 +119,28 @@ export default {
|
||||
return result
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
taskSeq: function(newValue){
|
||||
if(newValue !== null) this.createCy();
|
||||
},
|
||||
traceId: function(newValue) {
|
||||
// 當 traceId 屬性變化時更新 showTraceId
|
||||
this.showTraceId = newValue;
|
||||
},
|
||||
showTraceId: function(newValue, oldValue) {
|
||||
let isScrollTop = document.querySelector('.infiniteTable');
|
||||
if(typeof isScrollTop.scrollTop !== 'undefined') if(newValue !== oldValue) isScrollTop.scrollTop = 0;
|
||||
},
|
||||
firstCases: function(newValue, oldValue){
|
||||
this.infiniteData = newValue;
|
||||
},
|
||||
infinite404: function(newValue, oldValue){
|
||||
if (newValue === 404) {
|
||||
this.maxItems = true;
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* Number to percentage
|
||||
@@ -143,9 +162,13 @@ export default {
|
||||
* switch case data
|
||||
* @param {number} id
|
||||
*/
|
||||
switchCaseData(id) {
|
||||
async switchCaseData(id) {
|
||||
this.infinite404 = null;
|
||||
this.maxItems = false;
|
||||
this.showTraceId = id;
|
||||
this.conformanceStore.getLogConformanceTraceDetail(this.issusNo, id, 0, 20)
|
||||
this.startNum = 0;
|
||||
let result = await this.conformanceStore.getLogConformanceTraceDetail(this.issusNo, id, 0);
|
||||
this.infiniteData = await result;
|
||||
},
|
||||
/**
|
||||
* 將 trace element nodes 資料彙整
|
||||
@@ -198,32 +221,29 @@ export default {
|
||||
cytoscapeMapTrace(this.processMap.nodes, this.processMap.edges, graphId);
|
||||
});
|
||||
},
|
||||
async infiniteHandler() {
|
||||
console.log('TT');
|
||||
|
||||
async fetchData() {
|
||||
try {
|
||||
await this.conformanceStore.getLogConformanceTraceDetail(this.issusNo, this.issueTraces[0], this.start, this.pageSize)
|
||||
this.cases = [...this.infiniteData, ...this.cases];
|
||||
console.log(this.cases);
|
||||
(this.cases.length < this.pageSize) ? this.maxItems = true : this.pageSize += 20;
|
||||
$state.loaded();
|
||||
this.loading = true;
|
||||
this.startNum += 20
|
||||
const result = await this.conformanceStore.getLogConformanceTraceDetail(this.issusNo, this.showTraceId, this.startNum);
|
||||
this.infiniteData = [...this.infiniteData, ...result];
|
||||
} catch(error) {
|
||||
if (error.response && error.response.status === 404) {
|
||||
$state.complete();
|
||||
} else {
|
||||
console.error('Failed to load data:', error);
|
||||
}
|
||||
// console.error('Failed to load data:', error);
|
||||
} finally {
|
||||
this.busy = false;
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
handleScroll(event) {
|
||||
if(this.loading || this.maxItems) return;
|
||||
|
||||
const container = event.target;
|
||||
const overScrollHeight = container.scrollTop + container.clientHeight + 20 >= container.scrollHeight;
|
||||
|
||||
if (overScrollHeight) {
|
||||
this.fetchData();
|
||||
this.loading = true;
|
||||
}
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
taskSeq: function(newValue){
|
||||
if(newValue !== null) this.createCy();
|
||||
}
|
||||
},
|
||||
mounted(){
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user