@jzliu-cli/bi-engine 0.0.1 → 0.0.56

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 CHANGED
@@ -14,54 +14,83 @@ npm install @jzliu-cli/bi-engine
14
14
 
15
15
  ## 🚀 快速开始
16
16
 
17
- ### 基础使用
17
+ ### 1. 安装依赖
18
18
 
19
+ ```bash
20
+ # 安装核心依赖
21
+ yarn add @jzliu-cli/bi-engine element-ui vue@^2.6.11 vuex@^3.6.2
22
+
23
+ # 或使用 npm
24
+ npm install @jzliu-cli/bi-engine element-ui vue@^2.6.11 vuex@^3.6.2
25
+ ```
26
+
27
+ ### 2. 基础配置
28
+
29
+ **main.js**:
19
30
  ```javascript
20
31
  import Vue from 'vue'
21
- import BiDashboard, { chartRender } from '@jzliu-cli/bi-engine'
22
32
  import ElementUI from 'element-ui'
23
33
  import 'element-ui/lib/theme-chalk/index.css'
34
+ import Vuex from 'vuex'
24
35
 
25
- // 使用 Element UI
36
+ // 必需:使用 Element UI
26
37
  Vue.use(ElementUI)
27
38
 
28
- // 使用 BiDashboard
29
- Vue.use(BiDashboard)
39
+ // 必需:使用 Vuex
40
+ Vue.use(Vuex)
30
41
 
31
- // 在组件中使用
32
- export default {
33
- components: {
34
- chartRender
35
- },
36
- data() {
37
- return {
38
- chartData: {
39
- type: 'Column',
40
- name: '柱状图',
41
- // ... 其他配置
42
- }
43
- }
44
- }
45
- }
42
+ new Vue({
43
+ render: h => h(App),
44
+ }).$mount('#app')
46
45
  ```
47
46
 
48
- ### 完整仪表板使用
47
+ ### 3. 快速上手
49
48
 
50
- ```javascript
51
- import Vue from 'vue'
52
- import BiDashboard from '@jzliu-cli/bi-engine'
53
- import ElementUI from 'element-ui'
54
- import 'element-ui/lib/theme-chalk/index.css'
49
+ **最简单的使用方式**:
50
+ ```vue
51
+ <template>
52
+ <div style="height: 100vh;">
53
+ <bi-dashboard />
54
+ </div>
55
+ </template>
55
56
 
56
- Vue.use(ElementUI)
57
- Vue.use(BiDashboard)
57
+ <script>
58
+ import { BiDashboard } from '@jzliu-cli/bi-engine'
59
+
60
+ export default {
61
+ components: { BiDashboard }
62
+ }
63
+ </script>
64
+ ```
58
65
 
59
- // 在模板中使用
66
+ **使用内置数据**:
67
+ ```vue
60
68
  <template>
61
- <div>
62
- <bi-dashboard :config="dashboardConfig" />
69
+ <div style="height: 100vh;">
70
+ <bi-dashboard
71
+ :widgets="widgets"
72
+ :layoutObj="layoutObj"
73
+ />
63
74
  </div>
64
75
  </template>
76
+
77
+ <script>
78
+ import bi, { BiDashboard } from '@jzliu-cli/bi-engine'
79
+
80
+ export default {
81
+ components: { BiDashboard },
82
+ data() {
83
+ return {
84
+ // 使用内置模拟数据
85
+ widgets: bi.mockData.widgets,
86
+ layoutObj: {
87
+ layout: [],
88
+ dashboardName: '我的仪表板'
89
+ }
90
+ }
91
+ }
92
+ }
93
+ </script>
65
94
  ```
66
95
 
67
96
  ## 📚 API 文档
@@ -72,12 +101,15 @@ Vue.use(BiDashboard)
72
101
  主仪表板组件,提供完整的仪表板设计器功能。
73
102
 
74
103
  **Props:**
75
- - `config` (Object): 仪表板配置对象
76
- - `previewMode` (Boolean): 预览模式开关
104
+ - `previewFlag` (Boolean): 预览模式开关
105
+ - `layoutObj` (Object): 仪表板布局配置对象
106
+ - `widgets` (Array): 外部传入的图表组件数据
107
+ - `enableTabSwitch` (Boolean): 是否启用 tab 切换功能,默认 true
77
108
 
78
109
  **Events:**
79
110
  - `@dashboard-updated`: 仪表板更新时触发
80
111
  - `@chart-selected`: 图表选中时触发
112
+ - `@tab-change`: 组件面板 tab 切换时触发,参数为 `{ tabKey, tabLabel }`
81
113
 
82
114
  #### chartRender
83
115
  图表渲染组件,用于渲染单个图表。
@@ -95,6 +127,26 @@ Vue.use(BiDashboard)
95
127
  />
96
128
  ```
97
129
 
130
+ #### cTabs
131
+ 自定义标签页组件,提供美观的标签页切换功能。
132
+
133
+ **Props:**
134
+ - `tabList` (Array): 标签页列表,格式:`[{ key: 'tab1', label: '标签1' }, { key: 'tab2', label: '标签2' }]`
135
+ - `value` (String|Number): 当前激活的标签页 key
136
+
137
+ **Events:**
138
+ - `@input`: 标签页切换时触发,参数为新的 tabKey
139
+ - `@change`: 标签页切换时触发,参数为新的 tabKey
140
+
141
+ **示例:**
142
+ ```javascript
143
+ <c-tabs
144
+ :tabList="tabList"
145
+ v-model="activeTab"
146
+ @change="handleTabChange"
147
+ />
148
+ ```
149
+
98
150
  ### 工具函数 (utils)
99
151
 
100
152
  提供丰富的工具函数集合:
@@ -370,6 +422,307 @@ MIT License
370
422
 
371
423
  欢迎提交 Issue 和 Pull Request!
372
424
 
425
+ ## 🔄 第三方项目集成示例
426
+
427
+ ### 1. 基础项目配置
428
+
429
+ **main.js 配置**:
430
+ ```javascript
431
+ import Vue from 'vue'
432
+ import ElementUI from 'element-ui'
433
+ import 'element-ui/lib/theme-chalk/index.css'
434
+ import Vuex from 'vuex'
435
+
436
+ // 使用 Element UI
437
+ Vue.use(ElementUI)
438
+
439
+ // 使用 Vuex (必需)
440
+ Vue.use(Vuex)
441
+
442
+ new Vue({
443
+ render: h => h(App),
444
+ }).$mount('#app')
445
+ ```
446
+
447
+ ### 2. 完整仪表板使用
448
+
449
+ **编辑模式 - 支持拖拽设计**:
450
+ ```vue
451
+ <template>
452
+ <div id="app" style="min-width: 1366px;">
453
+ <div style="height:100%;width:100%;">
454
+ <bi-dashboard
455
+ :widgets="widgets"
456
+ :layoutObj="layoutObj"
457
+ @tab-change="handleTabChange"
458
+ />
459
+ </div>
460
+ </div>
461
+ </template>
462
+
463
+ <script>
464
+ import bi, { BiDashboard } from '@jzliu-cli/bi-engine'
465
+
466
+ export default {
467
+ name: 'App',
468
+ components: {
469
+ BiDashboard,
470
+ },
471
+ data() {
472
+ return {
473
+ // 使用内置模拟数据
474
+ widgets: bi.mockData.widgets,
475
+ layoutObj: {
476
+ "layout": [
477
+ {
478
+ "type": "Table",
479
+ "defaultRows": 8,
480
+ "dataSetId": "USER_BEHAVIOR_FACT",
481
+ "dataSetName": "用户行为事实表",
482
+ "name": "交叉表",
483
+ "defaultCols": "whole",
484
+ "className": "component-type-cross-table",
485
+ "measures": [
486
+ {
487
+ "unitCode": "page_views",
488
+ "unitName": "页面浏览量",
489
+ "belongDimName": null
490
+ }
491
+ ],
492
+ "dimensions": [
493
+ {
494
+ "unitCode": "user_id",
495
+ "unitName": "用户ID",
496
+ "belongDimName": "用户维度"
497
+ }
498
+ ]
499
+ }
500
+ ],
501
+ "dashboardName": "我的仪表板"
502
+ }
503
+ }
504
+ },
505
+ methods: {
506
+ handleTabChange(tabInfo) {
507
+ console.log('Tab 切换:', tabInfo)
508
+ // 这里可以根据 tab 切换重新加载数据
509
+ // 例如:this.loadWidgetsByTab(tabInfo.tabKey)
510
+ }
511
+ }
512
+ }
513
+ </script>
514
+ ```
515
+
516
+ **预览模式 - 只读展示**:
517
+ ```vue
518
+ <template>
519
+ <div id="app" style="min-width: 1366px;">
520
+ <div style="height:100%;width:100%;">
521
+ <Preview :widgets="widgets" :layoutObj="layoutObj" />
522
+ </div>
523
+ </div>
524
+ </template>
525
+
526
+ <script>
527
+ import bi, { Preview } from '@jzliu-cli/bi-engine'
528
+
529
+ export default {
530
+ name: 'App',
531
+ components: {
532
+ Preview,
533
+ },
534
+ data() {
535
+ return {
536
+ widgets: bi.mockData.widgets,
537
+ layoutObj: {
538
+ // 仪表板布局配置
539
+ }
540
+ }
541
+ }
542
+ }
543
+ </script>
544
+ ```
545
+
546
+ ### 3. 单独使用图表组件
547
+
548
+ **单个图表渲染**:
549
+ ```vue
550
+ <template>
551
+ <div>
552
+ <chart-render :chartData="chartData"></chart-render>
553
+ </div>
554
+ </template>
555
+
556
+ <script>
557
+ import BiDashboard, { chartRender, mockData, enumData } from '@jzliu-cli/bi-engine'
558
+
559
+ export default {
560
+ name: 'ChartComponent',
561
+ components: { chartRender },
562
+ data() {
563
+ return {
564
+ // 使用内置模拟数据
565
+ chartData: mockData.pieWidgets
566
+ }
567
+ }
568
+ }
569
+ </script>
570
+ ```
571
+
572
+ ### 4. 动态数据加载
573
+
574
+ **根据 tab 切换动态加载数据**:
575
+ ```vue
576
+ <template>
577
+ <div>
578
+ <bi-dashboard
579
+ :widgets="widgets"
580
+ :layoutObj="layoutObj"
581
+ @tab-change="handleTabChange"
582
+ />
583
+ </div>
584
+ </template>
585
+
586
+ <script>
587
+ import bi, { BiDashboard } from '@jzliu-cli/bi-engine'
588
+
589
+ export default {
590
+ components: { BiDashboard },
591
+ data() {
592
+ return {
593
+ widgets: [],
594
+ layoutObj: {
595
+ layout: [],
596
+ dashboardName: '动态仪表板'
597
+ },
598
+ currentTab: 'all'
599
+ }
600
+ },
601
+ methods: {
602
+ async handleTabChange(tabInfo) {
603
+ console.log('Tab 切换:', tabInfo)
604
+ this.currentTab = tabInfo.tabKey
605
+
606
+ // 根据 tab 切换重新调用接口获取数据
607
+ await this.loadWidgets(tabInfo.tabKey)
608
+ },
609
+
610
+ async loadWidgets(tabKey) {
611
+ try {
612
+ // 调用你的接口获取对应 tab 的 widgets 数据
613
+ const response = await this.$http.get(`/api/widgets?tab=${tabKey}`)
614
+ this.widgets = response.data
615
+ } catch (error) {
616
+ console.error('加载 widgets 失败:', error)
617
+ // 失败时使用默认数据
618
+ this.widgets = bi.mockData.widgets
619
+ }
620
+ }
621
+ },
622
+
623
+ async created() {
624
+ // 初始化加载数据
625
+ await this.loadWidgets('all')
626
+ }
627
+ }
628
+ </script>
629
+ ```
630
+
631
+ ### 5. 使用内置工具和配置
632
+
633
+ **使用工具函数和配置**:
634
+ ```javascript
635
+ import bi, {
636
+ chartRender,
637
+ mockData,
638
+ enumData,
639
+ utils,
640
+ panelConfig
641
+ } from '@jzliu-cli/bi-engine'
642
+
643
+ // 使用模拟数据
644
+ const sampleData = mockData.widgets
645
+
646
+ // 使用枚举数据
647
+ const chartTypes = enumData.chartTypeMap
648
+
649
+ // 使用工具函数
650
+ const processedData = utils.dataUtils.calcDescartes(data)
651
+
652
+ // 使用配置
653
+ const defaultConfig = panelConfig.getDefaultConfig()
654
+ ```
655
+
656
+ ## 🎯 常见使用场景
657
+
658
+ ### 场景1: 仪表板设计器
659
+ 适用于需要拖拽设计仪表板的场景,用户可以:
660
+ - 从组件面板拖拽图表到画布
661
+ - 配置图表样式和数据
662
+ - 实时预览效果
663
+ - 保存和加载仪表板配置
664
+
665
+ ### 场景2: 仪表板预览
666
+ 适用于只读展示的场景,用户可以:
667
+ - 查看已设计的仪表板
668
+ - 交互式浏览图表
669
+ - 响应式适配不同屏幕
670
+
671
+ ### 场景3: 单个图表展示
672
+ 适用于只需要展示单个图表的场景:
673
+ - 在现有页面中嵌入图表
674
+ - 使用内置的图表类型
675
+ - 自定义图表样式
676
+
677
+ ### 场景4: 动态数据仪表板
678
+ 适用于需要根据用户操作动态加载数据的场景:
679
+ - 根据 tab 切换加载不同数据
680
+ - 实时更新图表内容
681
+ - 支持数据筛选和查询
682
+
683
+ ## 📋 数据格式说明
684
+
685
+ ### widgets 数据格式
686
+ ```javascript
687
+ const widgets = [
688
+ {
689
+ type: 'Column', // 图表类型
690
+ name: '柱状图', // 图表名称
691
+ className: 'component-type-column', // CSS 类名
692
+ defaultImg: 'http://example.com/img.png', // 默认图片
693
+ measures: [ // 度量字段
694
+ {
695
+ unitCode: 'sales',
696
+ unitName: '销售额',
697
+ belongDimName: null
698
+ }
699
+ ],
700
+ dimensions: [ // 维度字段
701
+ {
702
+ unitCode: 'category',
703
+ unitName: '类别',
704
+ belongDimName: '商品维度'
705
+ }
706
+ ]
707
+ }
708
+ ]
709
+ ```
710
+
711
+ ### layoutObj 数据格式
712
+ ```javascript
713
+ const layoutObj = {
714
+ layout: [ // 布局配置
715
+ {
716
+ type: 'Column',
717
+ x: 0, y: 0, w: 6, h: 4, // 网格位置和大小
718
+ i: 'unique-id', // 唯一标识
719
+ // ... 其他图表配置
720
+ }
721
+ ],
722
+ dashboardName: '仪表板名称'
723
+ }
724
+ ```
725
+
373
726
  ## 📞 支持
374
727
 
375
728
  如有问题,请联系:
@@ -378,4 +731,3 @@ MIT License
378
731
 
379
732
  ---
380
733
 
381
- **注意**: 本组件库基于 Vue 2.x 开发,如需使用 Vue 3,请等待后续版本更新。
Binary file
@@ -12,10 +12,9 @@
12
12
  }
13
13
 
14
14
  //input
15
- .bi-header-name-input {
15
+ .jzliu-bi-engine-bi-header-name-input {
16
16
  transition: 0.3s all;
17
- width: 120px;
18
- max-width: 236px;
17
+ width: 300px;
19
18
  min-width: 150px;
20
19
  border: 1px solid transparent;
21
20
  box-shadow: none;
@@ -31,7 +30,7 @@
31
30
  }
32
31
 
33
32
  //button
34
- .bi-header-btn {
33
+ .jzliu-bi-engine-bi-header-btn {
35
34
  min-width: 108px;
36
35
  height: 26px;
37
36
  border-radius: 20px;
@@ -44,11 +43,11 @@
44
43
  cursor: pointer;
45
44
  }
46
45
 
47
- .bi-header-btn.primary {
46
+ .jzliu-bi-engine-bi-header-btn.primary {
48
47
  background: @color1;
49
48
  }
50
49
 
51
- .bi-header-btn.default {
50
+ .jzliu-bi-engine-bi-header-btn.default {
52
51
  background: transparent;
53
52
  }
54
53
 
@@ -71,7 +70,7 @@
71
70
  transition: all .2s ease;
72
71
  }
73
72
 
74
- .chart-warp {
73
+ .jzliu-bi-engine-chart-warp {
75
74
  width: 100%;
76
75
  height: 100%;
77
76
  }
@@ -245,6 +244,25 @@
245
244
  }
246
245
  }
247
246
 
247
+ .jzliu-bi-engine-vertical-text {
248
+ height: 60px;
249
+ width: 100%;
250
+ color: rgba(255, 255, 255, 0.75);
251
+ font-size: 14px;
252
+ letter-spacing: 3px;
253
+ cursor: pointer;
254
+ writing-mode: tb-rl;
255
+ writing-mode: vertical-lr;
256
+ justify-content: center;
257
+ display: flex;
258
+ align-items: center;
259
+ justify-content: center;
260
+ cursor: pointer;
261
+ &:hover {
262
+ color: #5890FF;
263
+ }
264
+ }
265
+
248
266
  /* Element UI 组件 label 样式 */
249
267
  .cdsp_dashboard .el-input__label,
250
268
  .cdsp_dashboard .el-form-item__label,
@@ -317,4 +335,11 @@
317
335
  .cdsp_dashboard .el-datetime-picker__label,
318
336
  .cdsp_dashboard .el-datetime-range-picker__label {
319
337
  font-size: 12px !important;
338
+ }
339
+
340
+ .cdsp_dashboard .sortable-ghost {
341
+ margin: 9px 9px;
342
+ padding: 4px 8px;
343
+ background-color: #2e74ff;
344
+ border: 1px dashed #2e74ff;
320
345
  }