Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
wangxiaolu-sfa-ui
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
sfa
wangxiaolu-sfa-ui
Commits
d2635ee9
提交
d2635ee9
authored
1月 03, 2025
作者:
lidongxu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(vue 版本,bi): 更新 Vue 版本,修改格式化数字的函数,并用在使用的地方
同上
上级
71b6af3b
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
150 行增加
和
98 行删除
+150
-98
color.js
src/utils/color.js
+13
-0
math.js
src/utils/math.js
+50
-51
LineAndBar.vue
src/views/bi/competitor/cmm/LineAndBar.vue
+30
-6
GradientArea.vue
src/views/bi/competitor/sycm_prd/GradientArea.vue
+11
-2
index.vue
src/views/bi/competitor/sycm_prd/index.vue
+16
-15
GradientArea.vue
src/views/bi/competitor/sycm_store/GradientArea.vue
+11
-2
LineChart.vue
src/views/bi/sale/LineChart.vue
+17
-19
index.vue
src/views/bi/sale/index.vue
+2
-3
没有找到文件。
src/utils/color.js
浏览文件 @
d2635ee9
...
...
@@ -41,6 +41,19 @@ export const getBrandColor = (brand, index = 0) => {
}
}
// 按顺序循环取颜色
export
const
getAdditionalColor
=
(
index
=
0
)
=>
{
const
ADDITIONAL_COLORS
=
[
'#5470c6'
,
'#00EFDC'
,
'#91cc75'
,
'#fac858'
,
'#0062EB'
,
'#c23531'
,
'#66ccff'
,
'#CE09EB'
,
'#00EF5A'
,
'#EBE098'
,
'#00DDEB'
,
'#F0EA07'
,
'#3ba272'
,
'#EF8912'
,
'#fc8452'
,
'#00cc99'
,
'#ff6699'
,
'#A1EB00'
,
'#cc0066'
,
'#8409EB'
,
'#0720F0'
,
'#ee6666'
,
'#E7A2EB'
,
'#0099cc'
,
'#EB00B4'
];
return
ADDITIONAL_COLORS
[
index
%
ADDITIONAL_COLORS
.
length
];
}
// 生成 16 进制随机颜色
const
getRandomColor
=
()
=>
{
let
color
=
Math
.
floor
(
Math
.
random
()
*
16777215
).
toString
(
16
);
...
...
src/utils/math.js
浏览文件 @
d2635ee9
...
...
@@ -21,67 +21,66 @@ export function divSafe(arg1, arg2) {
/**
* 将数值转换为带单位的字符串,并添加千分位逗号
* @param {number} value - 要转换的数值
* @param {string} extraDescription - 额外的描述字符串(没有直接返回数据)
* @param {bool} bool - 是否开启转换
* @param {bool} round - 是否取整
* @param {object} 配置对象
* @param {number} value - 要转换的数值
* @param {bool} carry - 是否开启亿万数量进位
* @param {number} fixed - 保留几位小数
* @param {bool} round - 是否取整(四舍五入)
* @param {bool} pos - 是否统一正数
* @param {bool} comma - 是否使用千分位逗号
* @param {string} des - 尾部额外添加描述字符(例如:人 / 元 / %等)
* @returns {string} 格式化后的字符串
*/
export
function
formatNumberWithUnit
(
value
,
extraDescription
,
bool
,
round
)
{
// if (typeof value !== 'number') {
// throw new Error('输入值必须是数字');
// }
// 如果 value 是空直接返回 0
if
(
value
===
0
||
value
===
''
||
value
===
null
||
value
===
undefined
)
return
0
;
export
function
formatNumberWithUnit
({
value
,
carry
=
true
,
fixed
=
2
,
round
=
true
,
pos
=
true
,
comma
=
true
,
des
})
{
// console.log('传入', value, carry, fixed, round, pos, comma, des)
let
resultNum
=
0
// 保存计算后的结果
let
unit
=
''
;
// 保存转换后的单位(例如:万 / 亿)
// 不转换
if
(
!
bool
)
{
if
(
!
round
){
if
(
!
extraDescription
)
{
return
value
.
toFixed
(
2
)
}
else
{
return
value
.
toFixed
(
2
)
+
extraDescription
}
}
else
{
if
(
!
extraDescription
)
{
return
Math
.
round
(
value
)
+
''
}
else
{
return
Math
.
round
(
value
)
+
extraDescription
}
}
// 如果不是数字类型,先尝试转换
if
(
typeof
value
===
'number'
||
!
isNaN
(
value
))
{
value
=
Number
(
value
);
}
else
{
return
0
}
// 转换单位
let
unit
;
let
formattedValue
;
if
(
value
>=
100000000
)
{
unit
=
'亿'
;
formattedValue
=
(
value
/
100000000
);
}
else
if
(
value
>=
10000
)
{
unit
=
'万'
;
formattedValue
=
(
value
/
10000
);
// 如果 value 是空直接返回 0
if
(
value
===
0
||
value
===
''
||
value
===
null
||
value
===
undefined
||
isNaN
(
value
))
{
resultNum
=
0
}
if
(
carry
)
{
// 开启亿万数量进位
if
(
value
>=
100000000
)
{
unit
=
'亿'
;
resultNum
=
(
value
/
100000000
);
}
else
if
(
value
>=
10000
)
{
unit
=
'万'
;
resultNum
=
(
value
/
10000
);
}
else
{
unit
=
''
;
resultNum
=
value
;
}
}
else
{
unit
=
''
;
formattedValue
=
value
;
resultNum
=
value
}
if
(
fixed
)
{
// 保留几位小数
resultNum
=
parseFloat
(
resultNum
.
toFixed
(
fixed
));
// console.log('保留小数', resultNum.toFixed(fixed), resultNum)
}
// 判断是否取整
if
(
round
)
{
formattedValue
=
Math
.
round
(
formattedValue
)
+
''
;
}
else
{
formattedValue
=
formattedValue
.
toFixed
(
2
);
// 是否取整
resultNum
=
Math
.
round
(
resultNum
)
// console.log('取整', resultNum)
}
// 如果没有额外描述,直接返回数值
if
(
!
extraDescription
)
{
return
formattedValue
;
if
(
pos
)
{
// 是否取整
resultNum
=
Math
.
abs
(
resultNum
);
}
// 添加千分位逗号
formattedValue
=
formattedValue
.
replace
(
/
\B(?=(\d{3})
+
(?!\d))
/g
,
','
);
return
`
${
formattedValue
}${
unit
}${
extraDescription
}
`
;
if
(
comma
)
{
// 是否添加千分位符号(从这里开始就是字符串了)
resultNum
=
resultNum
.
toString
()
.
replace
(
/
\B(?=(\d{3})
+
(?!\d))
/g
,
','
);
}
return
`
${
resultNum
}
${
unit
}${
des
}
`
;
}
/**
...
...
src/views/bi/competitor/cmm/LineAndBar.vue
浏览文件 @
d2635ee9
...
...
@@ -46,13 +46,21 @@ const setOptions = () => {
},
axisLabel
:
{
formatter
(
value
)
{
return
formatNumberWithUnit
(
value
,
'元'
,
myThousand
,
true
)
return
formatNumberWithUnit
({
value
,
des
:
'元'
,
carry
:
myThousand
})
}
},
axisPointer
:
{
label
:
{
formatter
:
(
params
)
=>
{
return
formatNumberWithUnit
(
params
.
value
,
'元'
,
myThousand
,
true
)
return
formatNumberWithUnit
({
value
:
params
.
value
,
des
:
'元'
,
carry
:
myThousand
})
}
}
}
...
...
@@ -65,13 +73,21 @@ const setOptions = () => {
},
axisLabel
:
{
formatter
(
value
)
{
return
formatNumberWithUnit
(
value
,
'人'
,
myThousand
,
true
)
return
formatNumberWithUnit
({
value
,
des
:
'人'
,
carry
:
myThousand
})
}
},
axisPointer
:
{
label
:
{
formatter
:
(
params
)
=>
{
return
formatNumberWithUnit
(
params
.
value
,
'人'
,
myThousand
,
true
)
return
formatNumberWithUnit
({
value
:
params
.
value
,
des
:
'人'
,
carry
:
myThousand
})
}
}
}
...
...
@@ -134,9 +150,17 @@ const setOptions = () => {
var
color
=
item
.
color
;
// 拼接提示内容
if
(
item
.
seriesName
.
split
(
'-'
)[
1
]
===
'销售额'
)
{
tooltip
+=
'<span style="display:inline-block;margin-right:5px;width:12px;height:6px;background-color:'
+
color
+
';"></span>'
+
item
.
seriesName
+
': '
+
formatNumberWithUnit
(
item
.
value
,
'元'
,
myThousand
)
+
'<br>'
;
tooltip
+=
'<span style="display:inline-block;margin-right:5px;width:12px;height:6px;background-color:'
+
color
+
';"></span>'
+
item
.
seriesName
+
': '
+
formatNumberWithUnit
({
value
:
item
.
value
,
des
:
'元'
,
carry
:
myThousand
})
+
'<br>'
;
}
else
if
(
item
.
seriesName
.
split
(
'-'
)[
1
]
===
'观看人次'
)
{
tooltip
+=
'<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:'
+
color
+
';"></span>'
+
item
.
seriesName
+
': '
+
formatNumberWithUnit
(
item
.
value
,
'人'
,
myThousand
)
+
'<br>'
;
tooltip
+=
'<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:'
+
color
+
';"></span>'
+
item
.
seriesName
+
': '
+
formatNumberWithUnit
({
value
:
item
.
value
,
des
:
'人'
,
carry
:
myThousand
})
+
'<br>'
;
}
});
return
tooltip
;
...
...
src/views/bi/competitor/sycm_prd/GradientArea.vue
浏览文件 @
d2635ee9
...
...
@@ -54,9 +54,18 @@ const setOptions = () => {
var
color
=
item
.
color
;
// 拼接提示内容
if
(
item
.
seriesName
.
split
(
'-'
)[
1
].
includes
(
'速'
))
{
tooltip
+=
'<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:'
+
color
+
';"></span>'
+
item
.
seriesName
+
': '
+
formatNumberWithUnit
(
item
.
value
,
'%'
,
false
,
false
)
+
'<br>'
;
tooltip
+=
'<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:'
+
color
+
';"></span>'
+
item
.
seriesName
+
': '
+
formatNumberWithUnit
({
value
:
item
.
value
,
carry
:
false
,
round
:
false
,
pos
:
false
,
des
:
'%'
})
+
'<br>'
;
}
else
{
tooltip
+=
'<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:'
+
color
+
';"></span>'
+
item
.
seriesName
+
':'
+
formatNumberWithUnit
(
item
.
value
,
'人'
,
false
,
true
)
+
'<br>'
;
tooltip
+=
'<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:'
+
color
+
';"></span>'
+
item
.
seriesName
+
':'
+
formatNumberWithUnit
({
value
:
item
.
value
,
des
:
'人'
})
+
'<br>'
;
}
});
return
tooltip
;
...
...
src/views/bi/competitor/sycm_prd/index.vue
浏览文件 @
d2635ee9
...
...
@@ -72,7 +72,7 @@
import
GradientArea
from
'./GradientArea.vue'
;
import
TableList
from
'./TableList.vue'
;
import
{
getComPrdListAPI
,
getSycmListAPI
}
from
'@/api'
import
{
generatorDayList
,
parseTime
,
get
Brand
Color
,
resetObjValue
}
from
'@/utils'
import
{
generatorDayList
,
parseTime
,
get
Additional
Color
,
resetObjValue
}
from
'@/utils'
import
{
useDatePickerOptions
}
from
'@/hooks'
// 静态数据
...
...
@@ -122,8 +122,9 @@ const initChartsData = (data) => {
resetObjValue
(
allChartData
)
allChartData
.
xAxis
=
generatorDayList
(
queryParams
.
date
[
0
],
queryParams
.
date
[
1
])
// 图表数据
data
.
forEach
(
list
=>
{
// list: 每个店铺数据集合
data
.
forEach
((
list
,
index
)
=>
{
index
=
index
*
4
// list: 每个商品数据集合
// 公共的配置
let
commonObj
=
{
type
:
'line'
,
...
...
@@ -141,11 +142,11 @@ const initChartsData = (data) => {
let
jyzsObj
=
{
...
commonObj
,
itemStyle
:
{
color
:
get
BrandColor
(
list
[
0
]?.
platformStore
,
0
)
color
:
get
AdditionalColor
(
index
)
},
areaStyle
:
{
opacity
:
0.8
,
color
:
get
BrandColor
(
list
[
0
]?.
platformStore
,
0
)
color
:
get
AdditionalColor
(
index
)
},
name
:
list
[
0
]?.
platformStore
+
'-交易增速'
,
data
:
[]
...
...
@@ -153,11 +154,11 @@ const initChartsData = (data) => {
let
llzsObj
=
{
...
commonObj
,
itemStyle
:
{
color
:
get
BrandColor
(
list
[
0
]?.
platformStore
,
1
)
color
:
get
AdditionalColor
(
index
+
1
)
},
areaStyle
:
{
opacity
:
0.8
,
color
:
get
BrandColor
(
list
[
0
]?.
platformStore
,
1
)
color
:
get
AdditionalColor
(
index
+
1
)
},
name
:
list
[
0
]?.
platformStore
+
'-流量增速'
,
data
:
[],
...
...
@@ -165,11 +166,11 @@ const initChartsData = (data) => {
let
uvObj
=
{
...
commonObj
,
itemStyle
:
{
color
:
get
BrandColor
(
list
[
0
]?.
platformStore
,
2
)
color
:
get
AdditionalColor
(
index
+
2
)
},
areaStyle
:
{
opacity
:
0.8
,
color
:
get
BrandColor
(
list
[
0
]?.
platformStore
,
2
)
color
:
get
AdditionalColor
(
index
+
2
)
},
name
:
list
[
0
]?.
platformStore
+
'-独立访客范围'
,
data
:
[]
...
...
@@ -177,11 +178,11 @@ const initChartsData = (data) => {
let
zfmjObj
=
{
...
commonObj
,
itemStyle
:
{
color
:
get
BrandColor
(
list
[
0
]?.
platformStore
,
3
)
color
:
get
AdditionalColor
(
index
+
3
)
},
areaStyle
:
{
opacity
:
0.8
,
color
:
get
BrandColor
(
list
[
0
]?.
platformStore
,
3
)
color
:
get
AdditionalColor
(
index
+
3
)
},
name
:
list
[
0
]?.
platformStore
+
'-支付买家数'
,
data
:
[]
...
...
@@ -207,25 +208,25 @@ const initChartsData = (data) => {
data
:
[{
name
:
jyzsObj
.
name
,
type
:
'circle'
,
color
:
get
BrandColor
(
list
[
0
]?.
platformStore
,
0
),
color
:
get
AdditionalColor
(
index
),
effective
:
true
,
show
:
true
,
},
{
name
:
llzsObj
.
name
,
type
:
'circle'
,
color
:
get
BrandColor
(
list
[
0
]?.
platformStore
,
1
),
color
:
get
AdditionalColor
(
index
+
1
),
effective
:
true
,
show
:
true
},
{
name
:
uvObj
.
name
,
type
:
'circle'
,
color
:
get
BrandColor
(
list
[
0
]?.
platformStore
,
2
),
color
:
get
AdditionalColor
(
index
+
2
),
effective
:
true
,
show
:
true
},
{
name
:
zfmjObj
.
name
,
type
:
'circle'
,
color
:
get
BrandColor
(
list
[
0
]?.
platformStore
,
3
),
color
:
get
AdditionalColor
(
index
+
3
),
effective
:
true
,
show
:
true
}],
...
...
src/views/bi/competitor/sycm_store/GradientArea.vue
浏览文件 @
d2635ee9
...
...
@@ -54,9 +54,18 @@ const setOptions = () => {
var
color
=
item
.
color
;
// 拼接提示内容
if
(
item
.
seriesName
.
split
(
'-'
)[
1
].
includes
(
'速'
))
{
tooltip
+=
'<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:'
+
color
+
';"></span>'
+
item
.
seriesName
+
': '
+
formatNumberWithUnit
(
item
.
value
,
'%'
,
false
,
false
)
+
'<br>'
;
tooltip
+=
'<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:'
+
color
+
';"></span>'
+
item
.
seriesName
+
': '
+
formatNumberWithUnit
({
value
:
item
.
value
,
carry
:
false
,
round
:
false
,
pos
:
false
,
des
:
'%'
})
+
'<br>'
;
}
else
{
tooltip
+=
'<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:'
+
color
+
';"></span>'
+
item
.
seriesName
+
':'
+
formatNumberWithUnit
(
item
.
value
,
'人'
,
false
,
true
)
+
'<br>'
;
tooltip
+=
'<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:'
+
color
+
';"></span>'
+
item
.
seriesName
+
':'
+
formatNumberWithUnit
({
value
:
item
.
value
,
des
:
'人'
})
+
'<br>'
;
}
});
return
tooltip
;
...
...
src/views/bi/sale/LineChart.vue
浏览文件 @
d2635ee9
...
...
@@ -50,13 +50,13 @@ const setOptions = () => {
chart
.
setOption
({
color
:
[
'#5470c6'
,
'#91cc75'
,
'#fac858'
,
'#ee6666'
,
'#73c0de'
,
'#444648'
,
'#fc8452'
,
'#9a60b4'
,
'#ea7ccc'
],
title
:
{
text
:
thi
s
.
chartData
.
title
,
text
:
prop
s
.
chartData
.
title
,
},
tooltip
:
{
trigger
:
'axis'
},
legend
:
{
data
:
thi
s
.
chartData
.
data
?.
map
(
o
=>
o
.
name
)
data
:
prop
s
.
chartData
.
data
?.
map
(
o
=>
o
.
name
)
},
grid
:
{
left
:
'3%'
,
...
...
@@ -65,7 +65,7 @@ const setOptions = () => {
containLabel
:
true
},
toolbox
:
{
show
:
thi
s
.
showTool
,
show
:
prop
s
.
showTool
,
feature
:
{
saveAsImage
:
{},
// 保存为图片
magicType
:
{
...
...
@@ -76,9 +76,9 @@ const setOptions = () => {
title
:
'切换万单位'
,
icon
:
'path://M50,50 L100,50 L100,100 L150,100 L150,150 L100,150 L100,200 L50,200 L50,150 L0,150 L0,100 L50,100 Z'
,
onclick
:
()
=>
{
this
.
myThousand
=
!
this
.
myThousand
this
.
lockThousand
=
!
this
.
lockThousand
this
.
setOptions
()
myThousand
.
value
=
!
myThousand
.
value
lockThousand
.
value
=
!
lockThousand
.
value
setOptions
()
}
}
}
...
...
@@ -86,23 +86,21 @@ const setOptions = () => {
xAxis
:
{
type
:
'category'
,
boundaryGap
:
false
,
data
:
thi
s
.
chartData
.
xData
data
:
prop
s
.
chartData
.
xData
},
yAxis
:
{
type
:
'value'
,
name
:
(
this
.
myThousand
?
'(万)'
:
''
)
+
thi
s
.
chartData
.
yName
name
:
(
myThousand
.
value
?
'(万)'
:
''
)
+
prop
s
.
chartData
.
yName
},
series
:
[
...
this
.
chartData
.
data
?.
map
(
o
=>
{
return
{
name
:
o
.
name
,
type
:
'line'
,
data
:
o
.
data
.
map
(
num
=>
{
return
parseFloat
((
this
.
myThousand
?
num
/
10000
:
num
).
toFixed
(
2
))
})
}
})
]
series
:
props
.
chartData
.
data
?.
map
(
o
=>
{
return
{
name
:
o
.
name
,
type
:
'line'
,
data
:
o
.
data
.
map
(
num
=>
{
return
parseFloat
((
myThousand
.
value
?
num
/
10000
:
num
).
toFixed
(
2
))
})
}
})
})
}
...
...
src/views/bi/sale/index.vue
浏览文件 @
d2635ee9
...
...
@@ -112,7 +112,7 @@
align=
"center"
min-width=
"100px"
sortable
:formatter=
"(row, cell, cellValue) => formatNumberWithUnit(cellValue, '',
true, fals
e)"
></el-table-column>
:formatter=
"(row, cell, cellValue) => formatNumberWithUnit(cellValue, '',
false, tru
e)"
></el-table-column>
<el-table-column
label=
"销售额"
prop=
"YTD.salePrice"
align=
"center"
...
...
@@ -353,7 +353,7 @@ const getSaleList = async (item) => {
platformId
:
o
.
platformId
,
targetSaleSum
:
o
.
targetSaleSum
,
YTD
:
{
saleNum
:
o
.
saleCountY
,
saleNum
:
1398213.123
,
salePrice
:
o
.
saleSumY
,
goodsSupplyDemandCount
:
o
.
goodsSupplyDemandCountY
,
// needNumPercentage: (formatNumberWithUnit(o.saleCountY, o.goodsSupplyDemandCountY) * 100).toFixed(2)
...
...
@@ -513,7 +513,6 @@ const createTableAndECharts = () => {
item
.
queryParams
.
date
=
[
new
Date
().
setDate
(
1
),
new
Date
().
setDate
((
new
Date
().
getDate
()
-
1
))]
// 默认查询和显示的是当月 1 号到 T-1 日期
}
else
{
// 非第一套图表,滚动到底
console
.
log
(
document
.
querySelector
(
'.main-container'
).
scrollHeight
)
nextTick
(()
=>
{
gsap
.
to
(
document
.
documentElement
,
{
duration
:
1
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论