Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
fix: template list data chunked update
Browse files Browse the repository at this point in the history
  • Loading branch information
hibig committed Aug 23, 2023
1 parent 0835269 commit 8798b8a
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/api/axios-chunk-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export function useSetChunkRequest() {
}

handler(result);
console.log('chunkrequest========', { result, url });
}
});
requestReadyState.value = request?.readyState;
Expand Down
12 changes: 12 additions & 0 deletions src/assets/style/global.less
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ body {
text-align: left;
}

.align-center {
text-align: center;
}

.font-52 {
font-size: 52px;
}
Expand Down Expand Up @@ -369,6 +373,14 @@ body {
}
}

.border-radius-4 {
border-radius: 4px;
}

.seal-bordered {
border: 1px solid var(--color-border-2);
}

@import url('./variable.less');
@import url('./custom.less');
@import url('./form.less');
Expand Down
4 changes: 4 additions & 0 deletions src/assets/style/margin.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.m-r-10 {
margin-right: 10px;
}

.p-16 {
padding: 16px;
}
4 changes: 4 additions & 0 deletions src/views/commons/hooks/use-update-chunked-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface ChunkedCollection {
export function useUpdateChunkedList(
dataList: Ref<{ id: string }[]>,
options?: {
callback?: (args: any) => void;
filterFun?: (args: any) => boolean;
computedID?: (d: object) => string;
}
Expand Down Expand Up @@ -50,6 +51,9 @@ export function useUpdateChunkedList(
dataList.value[updateIndex] = updateItem;
}
});
if (options?.callback) {
options?.callback(dataList.value);
}
};
return {
updateChunkedList
Expand Down
43 changes: 19 additions & 24 deletions src/views/cost-management/analyse/pages/perspective-edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,24 @@
</a-button>
</div>
</div>
<SealFormItemWrap
v-if="!formData.costQueries[0].sharedOptions.item.length"
:label="$t('cost.optimize.form.commonCost')"
:style="{ minWidth: `${InputWidth.LARGE}px` }"
>
<div
class="fill-width seal-bordered border-radius-4 p-16 align-center"
>
<a-button
type="text"
size="small"
@click="handleAddShareOptionItem"
>
<template #icon><icon-plus /></template>
{{ $t('cost.analyse.view.strategy') }}
</a-button>
</div>
</SealFormItemWrap>
</div>
<span v-else class="readonly-view-label"> - </span>
</a-form-item>
Expand Down Expand Up @@ -462,22 +480,6 @@
return !groupByDate.includes(item.value);
});
});
const sharingStrategyRequired = computed(() => {
const shareCostFilter =
get(formData, 'costQueries.0.sharedOptions.item') || [];
const shareCostIdleCostFilters =
get(formData, 'costQueries.0.sharedOptions.idle') || [];
const shareCostmanagementCostFilters =
get(formData, 'costQueries.0.sharedOptions.management') || [];
if (
shareCostFilter?.length ||
shareCostIdleCostFilters?.length ||
shareCostmanagementCostFilters?.length
) {
return true;
}
return false;
});
const handleDeleteShareOptionItem = (index) => {
formData.costQueries[0].sharedOptions.item.splice(index, 1);
Expand Down Expand Up @@ -542,14 +544,7 @@
const costres = validateCostFilter();
return !res && allres && costres;
};
const setShareCostFilter = (list) => {
const arr = map(list, (item) => {
return {
...pickBy(item, (val) => val?.length)
};
});
return filter(arr, (o) => keys(o).length);
};
const handleOk = async () => {
if (isEqual(copyFormData, formData) && id) {
router.back();
Expand Down
4 changes: 2 additions & 2 deletions src/views/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@
<style lang="less" scoped>
.container {
display: flex;
height: calc(100vh - 48px);
margin-top: 0;
overflow: auto;
background-image: url('../../assets/images/bg2.jpeg');
background-repeat: no-repeat;
background-position: center center;
Expand Down Expand Up @@ -184,6 +182,8 @@
flex: 1;
align-items: center;
justify-content: center;
height: max-content;
min-height: calc(100vh - 48px);
padding-bottom: 40px;
.content-inner {
Expand Down
58 changes: 55 additions & 3 deletions src/views/operation-hub/templates/pages/list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
import { deleteModal, execSucceed } from '@/utils/monitor';
import { PageAction } from '@/views/config';
import { useUpdateChunkedList } from '@/views/commons/hooks/use-update-chunked-list';
import { queryCatalogs } from '../../catalogs/api';
import { queryCatalogs, CatalogAPI } from '../../catalogs/api';
import ThumbView from '../components/thumb-view.vue';
import ListView from '../components/list-view.vue';
import { TemplateRowData } from '../config/interface';
Expand All @@ -148,12 +148,15 @@
let timer: any = null;
const userStore = useUserStore();
const { setChunkRequest } = useSetChunkRequest();
const { setChunkRequest: setCatalogChunkRequest } = useSetChunkRequest();
const { router } = useCallCommon();
const loading = ref(false);
const selectedKeys = ref<string[]>([]);
const sort = ref<string[]>(['-createTime']);
const dataList = ref<TemplateRowData[]>([]);
const catalogList = ref<{ label: string; value: string }[]>([]);
const catalogList = ref<
{ label: string; value: string; id: string; name: string }[]
>([]);
const listViewRef = ref();
const total = ref(0);
const queryParams = reactive({
Expand All @@ -163,6 +166,22 @@
perPage: 10
});
const { updateChunkedList } = useUpdateChunkedList(dataList);
const { updateChunkedList: updateCatalogList } = useUpdateChunkedList(
catalogList,
{
callback: (list) => {
catalogList.value = _.map(list, (o) => {
const item = _.cloneDeep(o);
return {
label: item.name,
value: item.id,
id: item.id,
name: item.name
};
});
}
}
);
const handleCreate = () => {
router.push({
Expand Down Expand Up @@ -243,6 +262,25 @@
_.each(list, (data) => {
updateChunkedList(data);
});
if (!dataList.value.length) {
queryParams.page = 1;
handleFilter();
}
};
const updateCatalogHandler = (list) => {
_.each(list, (data) => {
updateCatalogList(data);
});
if (queryParams.catalogID) {
const catalog = _.find(catalogList.value, {
value: queryParams.catalogID
});
if (!catalog) {
queryParams.catalogID = '';
handleSearch();
}
}
};
const createTemplateChunkRequest = () => {
try {
Expand All @@ -257,6 +295,17 @@
// ignore
}
};
const createCatalogChunkRequest = () => {
try {
setCatalogChunkRequest({
url: CatalogAPI,
handler: updateCatalogHandler
});
} catch (error) {
// ignore
}
};
const handleReset = () => {
queryParams.query = '';
queryParams.page = 1;
Expand Down Expand Up @@ -285,7 +334,9 @@
catalogList.value = _.map(data?.items || [], (item) => {
return {
label: item.name,
value: item.id
value: item.id,
id: item.id,
name: item.name
};
});
} catch (error) {
Expand All @@ -297,6 +348,7 @@
getCatalogList();
nextTick(() => {
createTemplateChunkRequest();
createCatalogChunkRequest();
});
});
</script>
Expand Down

0 comments on commit 8798b8a

Please sign in to comment.