@somecat/financial-report 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -29
- package/dist/financial-report.css +1 -1
- package/dist/financial-report.es.js +601 -410
- package/dist/financial-report.umd.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,21 +12,25 @@
|
|
|
12
12
|
|
|
13
13
|
```
|
|
14
14
|
h5-app/
|
|
15
|
-
├── public/assets/images/ # 切图资源
|
|
16
|
-
│ ├── header-bg.png # 头图背景
|
|
17
|
-
│ ├── banner-1.png # Banner 插图1
|
|
18
|
-
│ ├── banner-2.png # Banner 插图2
|
|
19
|
-
│ ├── banner-3.png # Banner 插图3
|
|
20
|
-
│ └── title-icon.png # 标题左侧 icon
|
|
21
15
|
├── src/
|
|
16
|
+
│ ├── assets/ # 切图与字体资源
|
|
22
17
|
│ ├── components/
|
|
23
|
-
│ │ ├──
|
|
24
|
-
│ │ ├──
|
|
25
|
-
│ │ ├──
|
|
26
|
-
│ │ ├──
|
|
27
|
-
│ │
|
|
28
|
-
│ ├──
|
|
29
|
-
│
|
|
18
|
+
│ │ ├── ReportHeader.vue # 页面头部(周次、标题、日期)
|
|
19
|
+
│ │ ├── SectionHeader.vue # 区块标题(编号徽章 + 文字)
|
|
20
|
+
│ │ ├── SectionDivider.vue # 区块标题下分隔线
|
|
21
|
+
│ │ ├── StatCard.vue # 指标卡片容器(头部指标 + 子标题行 + 图表插槽)
|
|
22
|
+
│ │ ├── SavingsSection.vue # Section 1 存款情况(变宽环形图 + 币种分布)
|
|
23
|
+
│ │ ├── SectionRepurchase.vue # Section 2 回购情况(34 省市横向条形图)
|
|
24
|
+
│ │ ├── SectionLiability.vue # Section 3 带息负债(6 列柱状图)
|
|
25
|
+
│ │ ├── SectionSupplyChain.vue # Section 4 供应链融资余额(分段柱状图)
|
|
26
|
+
│ │ ├── SectionSurplus.vue # Section 5 资金结余(5 项条形图 + 双指标头部)
|
|
27
|
+
│ │ └── StackedColumnChart.vue # 分段(堆叠)柱状图,纯 SVG 自封装
|
|
28
|
+
│ ├── styles/ # 设计变量 / report 样式(样式隔离)
|
|
29
|
+
│ ├── utils/ # color.js(CSS 变量解析,保障截图颜色一致)
|
|
30
|
+
│ ├── App.vue # 报告主页面(按区块组装,暴露 generateImage)
|
|
31
|
+
│ ├── report-data.js # 默认报告数据结构
|
|
32
|
+
│ ├── report-image.js # html-to-image PNG 导出
|
|
33
|
+
│ └── index.js # 库入口(ReportApp / ReportPlugin)
|
|
30
34
|
├── index.html
|
|
31
35
|
├── vite.config.js
|
|
32
36
|
└── package.json
|
|
@@ -34,21 +38,42 @@ h5-app/
|
|
|
34
38
|
|
|
35
39
|
## 组件说明
|
|
36
40
|
|
|
37
|
-
###
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
- 默认渲染 21 根递减红色柱状图
|
|
41
|
+
### StatCard.vue
|
|
42
|
+
指标卡片容器,接收 `stats`(头部指标数组,支持单/双指标)、`unit`、`subtitle`、
|
|
43
|
+
`unitLabel` 等 props;默认插槽放置图表内容,`header-extra` 具名插槽放置头部右侧插图。
|
|
41
44
|
|
|
42
|
-
###
|
|
43
|
-
|
|
44
|
-
- `data` 为数组,每项含 `label`、`value`、`color`
|
|
45
|
-
- 默认渲染 3 根对比柱(本周/上周/月均)
|
|
45
|
+
### StackedColumnChart.vue(分段柱状图,自封装)
|
|
46
|
+
纯 SVG 实现的分段(堆叠)柱状图,无 echarts 依赖,适配 html-to-image PNG 导出:
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
-
|
|
50
|
-
-
|
|
51
|
-
|
|
48
|
+
- 每组渲染一根堆叠柱,所有柱共享比例尺(最高柱撑满绘图区),柱高与组内分段值之和成正比;
|
|
49
|
+
- 组内分段默认按数值降序排列(大块在下、小块在上),避免小块贴近 x 轴导致标签拥挤;
|
|
50
|
+
- 每个分段以"引导线 + 名称/数值标签"标注,替代图例;首柱标签在柱左侧、其余柱在右侧;
|
|
51
|
+
- 不绘制 Y 轴刻度(数值已由标签标注),仅保留底部基线与组名。
|
|
52
|
+
|
|
53
|
+
数据类型定义:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
SegmentItem { name: string, value: number, color?: string } // 分段
|
|
57
|
+
StackedGroup { name: string, segments: SegmentItem[] } // 一根堆叠柱
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Props:
|
|
61
|
+
|
|
62
|
+
| Prop | 类型 | 默认值 | 说明 |
|
|
63
|
+
| --- | --- | --- | --- |
|
|
64
|
+
| `groups` | `StackedGroup[]` | 必填 | 柱分组数据 |
|
|
65
|
+
| `height` | `number` | `300` | SVG 高度,柱体最大高度 = height - 50 |
|
|
66
|
+
| `sortSegments` | `boolean` | `true` | 组内按值降序(大块在下、小块在上) |
|
|
67
|
+
| `formatValue` | `(value) => string` | 千分位 | 数值格式化 |
|
|
68
|
+
|
|
69
|
+
分段颜色建议使用 CSS 变量(如 `var(--color-primary)`),内部会经
|
|
70
|
+
`resolveCssColor` 解析为具体色值,保证页面显示与 PNG 截图一致。
|
|
71
|
+
|
|
72
|
+
### SectionSupplyChain.vue
|
|
73
|
+
Section 4 供应链融资余额:仅分段柱状图,不展示卡片头部指标区与子标题文案
|
|
74
|
+
(子标题行仅保留右侧"单位:亿元"标注)
|
|
75
|
+
(左柱"供应链融资"按融资品种构成,右柱"到期"按到期时间分布)。
|
|
76
|
+
Props:`groups`(结构同 `StackedColumnChart` 的 `groups`)。
|
|
52
77
|
|
|
53
78
|
## 运行方式
|
|
54
79
|
|
|
@@ -108,12 +133,37 @@ const reportData = {
|
|
|
108
133
|
},
|
|
109
134
|
repurchase: { headerValue: '205.2', provinces: [] },
|
|
110
135
|
liability: { headerValue: '825.6', columns: [] },
|
|
136
|
+
supplyChain: {
|
|
137
|
+
groups: [
|
|
138
|
+
{
|
|
139
|
+
name: '供应链融资',
|
|
140
|
+
segments: [
|
|
141
|
+
{ name: '银行承兑汇票', value: 142.5, color: '#C13224' },
|
|
142
|
+
{ name: '商业承兑汇票', value: 96.2, color: '#FCC2BE' },
|
|
143
|
+
{ name: '应付账款保理', value: 58.7, color: '#F68F87' }
|
|
144
|
+
]
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: '到期',
|
|
148
|
+
segments: [
|
|
149
|
+
{ name: '年内到期', value: 45.2, color: '#53968E' },
|
|
150
|
+
{ name: '明年到期', value: 15.8, color: '#82CDC0' }
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
},
|
|
111
155
|
surplus: { bars: [], note: '备注:...' }
|
|
112
156
|
}
|
|
113
157
|
|
|
114
158
|
const exportPng = async () => {
|
|
115
|
-
|
|
116
|
-
|
|
159
|
+
// 默认返回两张图:{ header, body },头部与正文各一张
|
|
160
|
+
const { header, body } = await reportRef.value.generateImage({ pixelRatio: 2 })
|
|
161
|
+
return { header, body }
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const exportWholePng = async () => {
|
|
165
|
+
// split: false 时返回整个报告的一张图
|
|
166
|
+
const dataUrl = await reportRef.value.generateImage({ pixelRatio: 2, split: false })
|
|
117
167
|
return dataUrl
|
|
118
168
|
}
|
|
119
169
|
</script>
|
|
@@ -124,7 +174,7 @@ const exportPng = async () => {
|
|
|
124
174
|
```
|
|
125
175
|
|
|
126
176
|
也可以注册为全局组件:`app.use(ReportPlugin, { name: 'FinancialReport' })`。
|
|
127
|
-
`generateImage()`
|
|
177
|
+
`generateImage()` 默认返回 `{ header, body }` 两张 PNG data URL(ReportHeader 一张、header 以下正文一张);传 `split: false` 时返回整个报告的一张 data URL。调用会等待 Vue 更新、`document.fonts.ready` 和图片资源加载完成。
|
|
128
178
|
|
|
129
179
|
截图字体注意事项:DIN 数字字体随 CSS 内联、思源宋体标题字体以文件形式随包分发,生成器会等待 `document.fonts.ready` 后再截图。正文中文目前依赖系统字体;若要求 Windows、macOS 和 Linux 像素级一致,应把设计指定的中文字体文件放入 `public/assets/fonts/`,再通过 `@font-face` 注册并在 `$font-sans` 中优先使用,且确认字体授权和文件体积。
|
|
130
180
|
|