Skip to content

Commit

Permalink
fix: 修复数据源改变时内部全量数据未更新问题
Browse files Browse the repository at this point in the history
  • Loading branch information
YufJi committed Apr 24, 2024
1 parent f6d1482 commit 2d1043d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
39 changes: 22 additions & 17 deletions src/mixins/DataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export default {
},
allRemoteData() {
if (this.currentDataSource?.remote) {
return this.currentDataSource?.allData || this.currentDataSource?.data || [];
return (
this.currentDataSource?.allData || this.currentDataSource?.data || []
);
}

return this.currentDataSource?.data || [];
Expand Down Expand Up @@ -84,10 +86,11 @@ export default {
if (
typeof dataSource === 'function' &&
String(dataSource) === String(old)
)
) {
return;
}

this.handleData();
this.onDataSourceChange();
},
sorting: {
deep: true,
Expand All @@ -113,25 +116,27 @@ export default {
},
created() {
this.debouncedLoad = _debounce(this.load, 300);
this.currentDataSource = this.normalizeDataSource(this.dataSource);

// 初始加载开启时
if (this.currentDataSource && this.initialLoad) {
if (this.pageNumber && this.pageable) {
this.page(this.pageNumber);
} else {
this.load();
}
}

this.handleData();
},
methods: {
onDataSourceChange() {
// 重置allRemoteData
this.currentDataSource?.clearLocalData();

this.handleData();
},
handleData() {
this.currentDataSource = this.normalizeDataSource(this.dataSource);
if (this.$env && this.$env.VUE_APP_DESIGNER) return;

this.currentDataSource = this.normalizeDataSource(this.dataSource);
// 初始加载开启时
if (this.currentDataSource && this.initialLoad) {
if (this.$env && this.$env.VUE_APP_DESIGNER) return;

this.load();
if (this.pageNumber && this.pageable) {
this.page(this.pageNumber);
} else {
this.load();
}
}
},
getExtraParams() {
Expand Down
11 changes: 6 additions & 5 deletions src/utils/DataSource/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,6 @@ const VueDataSource = Vue.extend({
this.originTotal = arrangedData.length;
}

// 重置清除标志
if (this.cleared) {
this.cleared = false;
}

if (this.queryChanged) {
this.queryChanged = false;
}
Expand All @@ -252,6 +247,7 @@ const VueDataSource = Vue.extend({
this.originTotal = Infinity; // originTotal 必须清空,否则空列表不会更新
this.arranged = false;
this.initialLoaded = false;
this.allData = null;

this.cleared = true;
},
Expand Down Expand Up @@ -317,6 +313,11 @@ const VueDataSource = Vue.extend({
this.paging.number = 1;
}
offset = 0;

// 重置清除标志
if (this.cleared) {
this.cleared = false;
}
}

// 不需要走后端
Expand Down

0 comments on commit 2d1043d

Please sign in to comment.