|
| 1 | +/* |
| 2 | + * TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. |
| 3 | + * |
| 4 | + * Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. |
| 5 | + * |
| 6 | + * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at https://opensource.org/licenses/MIT |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed |
| 10 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for |
| 11 | + * the specific language governing permissions and limitations under the License. |
| 12 | + */ |
| 13 | + |
| 14 | +import { useRequest } from 'vue-request'; |
| 15 | + |
| 16 | +import { getReportCount } from '@services/source/report'; |
| 17 | + |
| 18 | +/** |
| 19 | + * 巡检报告统计数据 |
| 20 | + */ |
| 21 | +export const useReportCount = () => { |
| 22 | + const manageCount = ref(0); |
| 23 | + const assistCount = ref(0); |
| 24 | + const dbReportCountMap = ref< |
| 25 | + Record< |
| 26 | + string, |
| 27 | + { |
| 28 | + assistCount: number; |
| 29 | + manageCount: number; |
| 30 | + } |
| 31 | + > |
| 32 | + >({}); |
| 33 | + |
| 34 | + useRequest(getReportCount, { |
| 35 | + onSuccess(countResult) { |
| 36 | + let manages = 0; |
| 37 | + let assists = 0; |
| 38 | + Object.entries(countResult).forEach(([db, value]) => { |
| 39 | + const singleDbCount = Object.values(value).reduce( |
| 40 | + (results, item) => { |
| 41 | + Object.assign(results, { |
| 42 | + manageCount: item.manage_count + results.manageCount, |
| 43 | + assistCount: item.assist_count + results.assistCount, |
| 44 | + }); |
| 45 | + return results; |
| 46 | + }, |
| 47 | + { |
| 48 | + manageCount: 0, |
| 49 | + assistCount: 0, |
| 50 | + }, |
| 51 | + ); |
| 52 | + dbReportCountMap.value[db] = singleDbCount; |
| 53 | + manages = manages + singleDbCount.manageCount; |
| 54 | + assists = assists + singleDbCount.assistCount; |
| 55 | + }); |
| 56 | + manageCount.value = manages; |
| 57 | + assistCount.value = assists; |
| 58 | + }, |
| 59 | + }); |
| 60 | + |
| 61 | + return { |
| 62 | + manageCount, |
| 63 | + assistCount, |
| 64 | + dbReportCountMap, |
| 65 | + }; |
| 66 | +}; |
0 commit comments