Skip to content

Commit 925c1aa

Browse files
committed
feat: 调整界面数字展示
1 parent 95d733b commit 925c1aa

File tree

15 files changed

+200
-110
lines changed

15 files changed

+200
-110
lines changed

framework/sdk/frontend/commons/business/base-layout/home-page/items/bill/BillTrend.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import BillViewAPI from "@commons/api/bil_view/index";
99
import { useUserStore } from "@commons/stores/modules/user";
1010
import type { ECharts } from "echarts";
1111
import type { Result } from "@commons/request/Result";
12+
import DecimalFormat from "@commons/utils/decimalFormat";
1213
1314
import * as echarts from "echarts";
1415
@@ -152,17 +153,16 @@ const historyTrend = async (historyNum: number, active: string) => {
152153
color: "black",
153154
fontSize: 12,
154155
formatter: function (param: any) {
155-
return _.round(param.value, 2).toFixed(2);
156+
return DecimalFormat.format(param.value, 2);
156157
},
157158
},
158159
};
159160
option["tooltip"] = {
160161
trigger: "item",
161162
formatter: (p: any) => {
162-
return `<div>月份:${p.name}</div><div>金额:${_.round(
163-
p.value,
164-
2
165-
).toFixed(2)}</div>`;
163+
return `<div>月份:${p.name}</div><div>金额:${CurrencyFormat.format(
164+
p.value
165+
)}</div>`;
166166
},
167167
};
168168
historyTrendChart?.setOption(option);

framework/sdk/frontend/commons/components/ce-form/items/vsphere/VsphereComputeConfigForm.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@
6363
<div class="usage-bar-top-text">
6464
<span>
6565
可用:
66-
{{ (scope.row.totalCpu - scope.row.usedCpu).toFixed(2) }}GHz
66+
{{
67+
DecimalFormat.format(
68+
scope.row.totalCpu - scope.row.usedCpu,
69+
2
70+
)
71+
}}GHz
6772
</span>
6873
</div>
6974
<el-progress
@@ -89,7 +94,10 @@
8994
<div class="usage-bar-top-text">
9095
<span
9196
>可用:{{
92-
(scope.row.totalMemory - scope.row.usedMemory).toFixed(2)
97+
DecimalFormat.format(
98+
scope.row.totalMemory - scope.row.usedMemory,
99+
2
100+
)
93101
}}GB</span
94102
>
95103
</div>
@@ -155,6 +163,7 @@ import formApi from "@commons/api/form_resource_api";
155163
import { computed, onMounted, ref, watch } from "vue";
156164
import _ from "lodash";
157165
import { ElTable, type FormInstance } from "element-plus";
166+
import DecimalFormat from "@commons/utils/decimalFormat";
158167
159168
interface ComputeConfig {
160169
location: string;

framework/sdk/frontend/commons/components/ce-form/items/vsphere/VsphereDatastoreForm.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@
3939
<div class="usage-bar-bottom-text">
4040
<span>
4141
已用:
42-
{{ (scope.row.totalDisk - scope.row.freeDisk).toFixed(2) }}GB
42+
{{
43+
DecimalFormat.format(
44+
scope.row.totalDisk - scope.row.freeDisk,
45+
2
46+
)
47+
}}GB
4348
</span>
4449
<span>总量: {{ scope.row.totalDisk }}GB</span>
4550
</div>
@@ -60,9 +65,10 @@
6065
</template>
6166
<script setup lang="ts">
6267
import type { FormView } from "@commons/components/ce-form/type";
63-
import { computed, onMounted, ref } from "vue";
68+
import { computed, ref } from "vue";
6469
import _ from "lodash";
6570
import type { ElTable } from "element-plus";
71+
import DecimalFormat from "@commons/utils/decimalFormat";
6672
6773
interface DataStore {
6874
mor: string;

framework/sdk/frontend/commons/components/echart/Charts.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { onMounted, ref, watch } from "vue";
33
import * as echarts from "echarts";
44
import _ from "lodash";
5+
import DecimalFormat from "@commons/utils/decimalFormat";
56
67
const props = defineProps({
78
data: {
@@ -246,13 +247,13 @@ const timestampToTime = (timestamp: any) => {
246247
const changeByte = (byte: number) => {
247248
let size: string;
248249
if (byte < 1024) {
249-
size = `${byte.toFixed(2)}Byte`;
250+
size = `${DecimalFormat.format(byte, 2)}Byte`;
250251
} else if (byte < 1024 * 1024) {
251-
size = `${(byte / 1024).toFixed(2)}KB`;
252+
size = `${DecimalFormat.format(byte / 1024, 2)}KB`;
252253
} else if (byte < 1024 * 1024 * 1024) {
253-
size = `${(byte / (1024 * 1024)).toFixed(2)}MB`;
254+
size = `${DecimalFormat.format(byte / (1024 * 1024), 2)}MB`;
254255
} else {
255-
size = `${(byte / (1024 * 1024 * 1024)).toFixed(2)}GB`;
256+
size = `${DecimalFormat.format(byte / (1024 * 1024 * 1024), 2)}GB`;
256257
}
257258
// 转成字符串
258259
const sizeStr = `${size}`;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function format(decimal?: number, digits?: number): string | undefined {
2+
if (digits == undefined) {
3+
digits = 0;
4+
}
5+
return decimal?.toLocaleString("zh-CN", {
6+
style: "decimal",
7+
minimumFractionDigits: digits,
8+
maximumFractionDigits: digits,
9+
});
10+
}
11+
12+
const util = {
13+
format,
14+
};
15+
16+
export default util;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function format(decimal?: number): string | undefined {
2+
return decimal?.toLocaleString("zh-CN", {
3+
style: "percent",
4+
minimumFractionDigits: 2,
5+
maximumFractionDigits: 2,
6+
});
7+
}
8+
9+
const util = {
10+
format,
11+
};
12+
13+
export default util;

services/finance-management/frontend/src/views/bill_detailed/index.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
>
7979
<template #default="scope">
8080
<div style="display: flex; align-items: center">
81-
<platform_icon :platform="scope.row.provider"> </platform_icon>
81+
<PlatformIcon :platform="scope.row.provider"> </PlatformIcon>
8282
<div class="table_overflow">{{ scope.row.cloudAccountName }}</div>
8383
</div>
8484
</template>
@@ -163,7 +163,7 @@
163163
>
164164
<template #default="scope">
165165
<span :title="scope.row.totalCost + '元'">
166-
{{ _.round(scope.row.totalCost, 2).toFixed(2) }}元
166+
{{ DecimalFormat.format(scope.row.totalCost, 2) }}元
167167
</span>
168168
</template>
169169
</el-table-column>
@@ -175,7 +175,7 @@
175175
>
176176
<template #default="scope">
177177
<span :title="scope.row.realTotalCost + '元'">
178-
{{ _.round(scope.row.realTotalCost, 2).toFixed(2) }}元
178+
{{ DecimalFormat.format(scope.row.realTotalCost, 2) }}元
179179
</span>
180180
</template>
181181
</el-table-column>
@@ -193,10 +193,11 @@ import {
193193
TableSearch,
194194
} from "@commons/components/ce-table/type";
195195
import billDetailApi from "@/api/bill_detailed";
196-
import platform_icon from "@commons/components/platform-icon/index.vue";
196+
import PlatformIcon from "@commons/components/platform-icon/index.vue";
197197
import cloudAccountApi from "@commons/api/cloud_account/index";
198198
import type { CloudAccount } from "@commons/api/cloud_account/type";
199199
import _ from "lodash";
200+
import DecimalFormat from "@commons/utils/decimalFormat";
200201
/**
201202
*当前月份
202203
*/

services/finance-management/frontend/src/views/bill_view/components/ViewExpensesAggsCard.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
</template>
1515
<script setup lang="ts">
1616
import { ref, onMounted } from "vue";
17-
import _ from "lodash";
1817
import { computed } from "vue";
1918
import CurrencyFormat from "@commons/utils/currencyFormat";
19+
import DecimalFormat from "@commons/utils/decimalFormat";
2020
const loading = ref<boolean>(false);
2121
const expenses = ref<{ current: number; up: number }>({ current: 0, up: 0 });
2222
const props = defineProps<{
@@ -33,10 +33,10 @@ const scale = computed(() => {
3333
const s =
3434
expenses.value.up == 0
3535
? CurrencyFormat.format(expenses.value.current)
36-
: (
37-
((expenses.value.current - expenses.value.up) / expenses.value.up) *
38-
100
39-
).toFixed(2) + "%";
36+
: DecimalFormat.format(
37+
(expenses.value.current - expenses.value.up) / expenses.value.up,
38+
2
39+
);
4040
return expenses.value.current > expenses.value.up ? "+" + s : s;
4141
});
4242
onMounted(() => {

services/finance-management/frontend/src/views/bill_view/components/ViewTable.vue

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,14 @@
2424
sortable
2525
>
2626
<template #default="scope">
27-
{{ _.round(scope.row.value, 2).toFixed(2) }}
27+
{{ DecimalFormat.format(scope.row.value, 2) }}
2828
</template>
2929
</el-table-column>
3030
<el-table-column fixed="right" min-width="80" label="占比">
3131
<template #default="scope">{{
32-
Math.floor(
33-
(scope.row.value /
34-
viewData.map((b) => b.value).reduce((p, n) => p + n)) *
35-
10000
36-
) /
37-
100 +
38-
"%"
32+
PercentFormat.format(
33+
scope.row.value / viewData.map((b) => b.value).reduce((p, n) => p + n)
34+
)
3935
}}</template></el-table-column
4036
>
4137
<el-table-column width="200" fixed="right" label="趋势">
@@ -58,10 +54,11 @@
5854
</template>
5955
<script setup lang="ts">
6056
import { ref, computed } from "vue";
61-
import _ from "lodash";
6257
import type { BillSummary } from "@/echarts/bill_view/type";
6358
import type { BillRule } from "@/api/bill_rule/type";
6459
import ViewTrend from "@/views/bill_view/components/ViewTrendChart.vue";
60+
import PercentFormat from "@commons/utils/percentFormat";
61+
import DecimalFormat from "@commons/utils/decimalFormat";
6562
6663
const props = withDefaults(
6764
defineProps<{

services/finance-management/frontend/src/views/bill_view/components/ViewTrendChart.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@
88
<template #default>
99
<div class="content">
1010
<div class="title">
11-
{{ props.billSummary.group1
12-
}}<span class="child_title">的费用趋势</span>
11+
{{ props.billSummary.group1 }}
12+
<span class="child_title">的费用趋势</span>
1313
</div>
1414
<div ref="tree" class="tree"></div>
1515
</div>
1616
</template>
1717
<template #reference>
18-
<TableTrend :trend="props.billSummary.treed"></TableTrend
19-
></template>
18+
<TableTrend :trend="props.billSummary.treed" />
19+
</template>
2020
</el-popover>
2121
</template>
2222
<script setup lang="ts">
2323
import type { BillSummary, TrendData } from "@/echarts/bill_view/type";
2424
import type { ECharts } from "echarts";
2525
import { ref, inject, nextTick } from "vue";
26-
import { getTrendViewOption } from "@/echarts/bill_view/index";
27-
import _ from "lodash";
26+
import { getTrendViewOption } from "@/echarts/bill_view";
2827
import TableTrend from "@/views/bill_view/components/TableTrend.vue";
28+
import CurrencyFormat from "@commons/utils/currencyFormat";
2929
3030
const echarts: any = inject("echarts");
3131
const title = ref<string>();
@@ -52,8 +52,8 @@ const open = (treed: Array<TrendData>, row: BillSummary) => {
5252
option["tooltip"] = {
5353
trigger: "item",
5454
formatter: (p: any) => {
55-
return `<div>月份:${p.name}</div><div>金额:${_.round(p.value, 2).toFixed(
56-
2
55+
return `<div>月份:${p.name}</div><div>金额:${CurrencyFormat.format(
56+
p.value
5757
)}</div>`;
5858
},
5959
};

0 commit comments

Comments
 (0)