Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
TC
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
qlintonger xeno
TC
Commits
b6b22918
Commit
b6b22918
authored
Apr 18, 2025
by
qlintonger xeno
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 删除额外配置信息呢
parent
4961f4dc
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
22 deletions
+41
-22
src/App.vue
+2
-2
src/lib/Table2Chart/Components/global-echarts.vue
+3
-5
src/lib/Table2Chart/ScreenChart.vue
+11
-9
src/lib/Table2Chart/funcs/mapStyle.ts
+25
-4
src/lib/Table2Chart/types/ScreenChart.typing.ts
+0
-2
No files found.
src/App.vue
View file @
b6b22918
...
...
@@ -8,7 +8,7 @@ const layout = [
{
x
:
4
,
y
:
2
,
w
:
3
,
h
:
1
,},
{
x
:
7
,
y
:
1
,
w
:
5
,
h
:
4
,},
{
x
:
0
,
y
:
1
,
w
:
7
,
h
:
1
,},
{
x
:
0
,
y
:
3
,
w
:
7
,
h
:
1
,}
{
x
:
0
,
y
:
3
,
w
:
7
,
h
:
2
,}
].
map
((
a
,
q
)
=>
({
...
a
,
title
:
`示例图
${
q
+
1
}
`
,
chartData
:
a
.
w
>=
4
?
[
{
type
:
'bar'
,
category
:
[
'Mon'
,
'Tue'
,
'Wed'
,
'Thu'
,
'Fri'
,
'Sat'
,
'Sun'
],
data
:
[
120
,
200
,
150
,
80
,
70
,
110
,
130
]},
...
...
@@ -31,7 +31,7 @@ const layout = [
</
script
>
<
template
>
<screen-chart
:
grid=
"
{cols: 12, rows: 4}" :
layout="layout"/>
<screen-chart
:layout=
"layout"
/>
</
template
>
<
style
scoped
>
...
...
src/lib/Table2Chart/Components/global-echarts.vue
View file @
b6b22918
...
...
@@ -7,7 +7,6 @@ import * as echarts from "echarts";
import
{
ECBasicOption
}
from
"echarts/types/dist/shared"
;
import
{
isNumber
}
from
"lodash"
;
import
{
computed
,
nextTick
,
onMounted
,
onUnmounted
,
ref
,
watch
}
from
"vue"
;
import
{
debounce
}
from
"lodash"
;
interface
Props
{
options
?:
ECBasicOption
;
...
...
@@ -38,9 +37,6 @@ const getHeight = computed(() => {
const
chartRef
=
ref
(
null
);
let
ro
:
ResizeObserver
|
null
=
null
let
chartInstance
=
null
as
unknown
as
echarts
.
ECharts
;
let
handleR
=
debounce
(
function
()
{
chartInstance
?.
resize
();
},
500
)
onMounted
(()
=>
{
const
el
=
chartRef
.
value
;
if
(
el
)
{
...
...
@@ -48,7 +44,9 @@ onMounted(() => {
chartInstance
=
echarts
.
init
(
el
);
setOptions
(
ps
.
options
);
if
(
!
ro
)
{
ro
=
new
ResizeObserver
(
handleR
);
ro
=
new
ResizeObserver
(
function
()
{
chartInstance
?.
resize
();
});
ro
.
observe
(
el
,
{
box
:
"border-box"
});
}
chartInstance
?.
resize
();
...
...
src/lib/Table2Chart/ScreenChart.vue
View file @
b6b22918
<
script
lang=
"ts"
setup
>
import
{
ScreenChartProps
}
from
"./types/ScreenChart.typing.ts"
;
import
{
gridItemStyle
,
mapContainerStyle
}
from
"./funcs/mapStyle.ts"
;
import
{
gridItemStyle
,
mapContainerStyle
,
getAllGridSize
}
from
"./funcs/mapStyle.ts"
;
import
GlobalEcharts
from
"./Components/global-echarts.vue"
;
import
{
mapToEchartsOptions
}
from
"./funcs/mapToEchartsOptions.ts"
;
import
{
nextTick
,
onMounted
,
onUnmounted
,
ref
}
from
"vue"
;
import
{
geoContainer
}
from
"./funcs/mapGEOStyle.ts"
;
import
{
debounce
}
from
"lodash"
;
import
{
nextTick
,
onMounted
,
onUnmounted
,
ref
,
computed
}
from
"vue"
;
import
{
geoContainer
,
}
from
"./funcs/mapGEOStyle.ts"
;
const
props
=
withDefaults
(
defineProps
<
ScreenChartProps
>
(),
{
gap
:
16
,
containerPadding
:
12
,
gridItemPadding
:
12
gap
:
16
,
containerPadding
:
12
,
gridItemPadding
:
12
})
const
isAllMounted
=
ref
(
false
)
let
ro
:
ResizeObserver
|
null
=
null
...
...
@@ -18,18 +17,20 @@ onUnmounted(function () {
ro
=
null
}
})
const
gridConfig
=
computed
(()
=>
{
return
getAllGridSize
(
props
.
layout
)
})
const
startNow
=
function
calcGEO
()
{
const
rect
=
containerRef
.
value
.
getBoundingClientRect
()
geoContainer
.
value
.
width
=
rect
.
width
geoContainer
.
value
.
height
=
rect
.
height
}
const
calcGEO
=
debounce
(
startNow
,
500
)
onMounted
(
function
()
{
nextTick
(
function
()
{
isAllMounted
.
value
=
true
})
if
(
!
ro
)
{
ro
=
new
ResizeObserver
(
calcGEO
)
ro
=
new
ResizeObserver
(
startNow
)
ro
.
observe
(
containerRef
.
value
,
{
box
:
'border-box'
})
startNow
()
}
...
...
@@ -38,11 +39,12 @@ const containerRef = ref()
</
script
>
<
template
>
<div
:style=
"mapContainerStyle(props)"
class=
"w-full h-full pr"
ref=
"containerRef"
>
<div
:style=
"mapContainerStyle(props
, gridConfig
)"
class=
"w-full h-full pr"
ref=
"containerRef"
>
<div
v-for=
"(item, w) in props.layout"
:key=
"w"
:style=
"gridItemStyle(item, props)"
class=
"flex flex-col"
>
<div
v-if=
"!item.renderTitle"
class=
"w-full"
>
{{
item
.
title
}}
</div>
<component
:is=
"item.renderTitle(item, props.layout)"
v-else
/>
<div
v-if=
"isAllMounted"
class=
"mt-[12px] w-full flex items-stretch justify-between"
style=
"height: calc(100% - 12px - 12px)"
>
<div
v-if=
"isAllMounted"
class=
"mt-[12px] w-full flex items-stretch justify-between"
style=
"height: calc(100% - 12px - 12px)"
>
<global-echarts
v-for=
"(z,x) in item.chartData"
:key=
"x"
:options=
"mapToEchartsOptions(z)"
/>
</div>
</div>
...
...
src/lib/Table2Chart/funcs/mapStyle.ts
View file @
b6b22918
...
...
@@ -5,7 +5,7 @@ export const gridItemStyle = function (item: SingleLayoutConf, props: ScreenChar
return
{
gridColumn
:
`
${
item
.
x
+
1
}
/ span
${
item
.
w
}
`
,
gridRow
:
`
${
item
.
y
+
1
}
/ span
${
item
.
h
}
`
,
background
:
'
red
'
,
background
:
'
#f1f1f1
'
,
boxSizing
:
'border-box'
,
// @ts-ignore
padding
:
`
${
mapHeight
(
props
.
gridItemPadding
)}
px
${
mapWidth
(
props
.
gridItemPadding
)}
px
${
mapHeight
(
props
.
gridItemPadding
)}
px
${
mapWidth
(
props
.
gridItemPadding
)}
px`
,
...
...
@@ -13,15 +13,36 @@ export const gridItemStyle = function (item: SingleLayoutConf, props: ScreenChar
}
}
export
const
mapContainerStyle
=
function
(
props
:
ScreenChartProps
)
{
export
function
getAllGridSize
(
items
:
Array
<
SingleLayoutConf
>
)
{
let
maxCol
=
0
;
let
maxRow
=
0
;
for
(
const
item
of
items
)
{
// 计算当前元素的右边界和下边界
const
rightEdge
=
item
.
x
+
item
.
w
;
const
bottomEdge
=
item
.
y
+
item
.
h
;
// 更新最大列数和行数
if
(
rightEdge
>
maxCol
)
{
maxCol
=
rightEdge
;
}
if
(
bottomEdge
>
maxRow
)
{
maxRow
=
bottomEdge
;
}
}
return
{
rows
:
maxRow
,
cols
:
maxCol
};
}
export
const
mapContainerStyle
=
function
(
props
:
ScreenChartProps
,
gridConfig
:
{
rows
:
number
,
cols
:
number
})
{
return
{
display
:
'grid'
,
// @ts-ignore
gridRowGap
:
mapHeight
(
props
.
gap
)
+
'px'
,
// @ts-ignore
gridColumnGap
:
mapWidth
(
props
.
gap
)
+
'px'
,
gridTemplateColumns
:
`repeat(
${
props
.
grid
.
cols
}
, 1fr)`
,
gridTemplateRows
:
`repeat(
${
props
.
grid
.
rows
}
, 1fr)`
,
gridTemplateColumns
:
`repeat(
${
gridConfig
.
cols
}
, 1fr)`
,
gridTemplateRows
:
`repeat(
${
gridConfig
.
rows
}
, 1fr)`
,
boxSizing
:
'border-box'
,
// @ts-ignore
padding
:
`
${
mapHeight
(
props
.
containerPadding
)}
px
${
mapWidth
(
props
.
containerPadding
)}
px
${
mapHeight
(
props
.
containerPadding
)}
px
${
mapWidth
(
props
.
containerPadding
)}
px`
,
...
...
src/lib/Table2Chart/types/ScreenChart.typing.ts
View file @
b6b22918
...
...
@@ -20,7 +20,6 @@ export type LayoutConfig = Array<SingleLayoutConf>
export
type
ScreenChartProps
=
{
layout
:
LayoutConfig
;
gap
?:
number
;
grid
:
{
rows
:
number
,
cols
:
number
};
containerPadding
?:
number
;
gridItemPadding
?:
number
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment