kd-lane-container 0.0.9 → 0.1.0

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
@@ -67,6 +67,40 @@ export default {
67
67
 
68
68
  ### 4.1 基本使用
69
69
 
70
+ #### 4.1.1 泳道宽度配置
71
+
72
+ 从版本 0.1.0 开始,支持通过 `width` 属性自定义泳道宽度。
73
+
74
+ **配置说明**:
75
+ - **自定义插槽泳道**:
76
+ - 如果泳道配置中包含 `width` 属性(数字类型),则动态设置 `style` 为 `width: ${width}px`。
77
+ - 如果未配置 `width`,则动态设置 `style` 为 `width: auto`,由插槽内容决定实际宽度(之前的默认逻辑)。
78
+ - **普通泳道**:
79
+ - 如果泳道配置中包含 `width` 属性(数字类型),则动态设置 `style` 为 `width: ${width}px`。
80
+ - 如果未配置 `width`,则动态设置 `style` 为 `flex: 1`,与其他未设置宽度的泳道平分剩余空间(之前的默认逻辑)。
81
+
82
+ **示例配置**:
83
+ ```javascript
84
+ lanes: [
85
+ { 其他属性..., width: 200 }, // 自定义宽度为 200px
86
+ { 其他属性..., } // 未设置宽度,使用默认逻辑
87
+ ]
88
+ ```
89
+
90
+ #### 4.1.2 泳道尺寸获取
91
+
92
+ 新增 `getGridSize` 方法,用于获取泳道的精确尺寸(包括泳道抬头部分)。
93
+
94
+ **注意事项**:
95
+ - 调用时机:需确保泳道容器的 `div` 已挂载并渲染完毕,否则可能返回空数组或错误数据。
96
+ - 返回值:返回泳道的 `x`、`y`、`width`、`height` 等尺寸信息,以及 `lane-id` 属性。
97
+
98
+ **示例代码**:
99
+ ```javascript
100
+ const gridSizes = this.$refs.laneContainer.getGridSize();
101
+ console.log(gridSizes); // 输出泳道尺寸信息
102
+ ```
103
+
70
104
  ```vue
71
105
  <KdLaneContainer
72
106
  class="container"
@@ -335,66 +369,75 @@ handleCustomMenuClick(event) {
335
369
  }
336
370
  ```
337
371
 
338
- ## 5. 组件 API
339
-
340
- ### 5.1 Props
341
-
342
- | 属性名 | 类型 | 默认值 | 说明 |
343
- | ---------------- | ------ | ------- | ------------------ |
344
- | config | Object | 必填 | 组件配置对象 |
345
- | headerPadding | Number | 4 | 泳道头部内边距 |
346
- | headerItemHeight | Number | 20 | 头部线条项高度 |
347
- | itemGap | Number | 2 | 线条项之间的间距 |
348
- | customMenuList | Array | [] | 自定义菜单列表 |
349
- | themeName | String | "white" | 当前使用的主题名称 |
350
-
351
- ### 5.2 事件
352
-
353
- | 事件名 | 参数 | 说明 |
354
- | ------------------- | -------- | ------------------ |
355
- | onCustomMenuClicked | event | 自定义菜单点击事件 |
356
- | line-change | line | 线条变化事件 |
357
- | template-change | template | 模板变化事件 |
358
-
359
- ### 5.3 方法
360
-
361
- **注:以下方法仅在使用 `custom` 模式时需要了解和实现,local 模式下不需要考虑。**
362
-
363
- 组件内部提供的方法主要用于模板和线条的管理:
364
-
365
- - upsertTemplate(data) - 新增或更新模板
366
-
367
- - 参数:`data` - 模板数据
368
- - 返回值:`Promise<Object>` - 插入或更新后的**完整**模板对象
369
-
370
- - delTemplate(data) - 删除模板
371
-
372
- - 参数:`data` - 模板数据(需包含`templateId`)
373
- - 返回值:`Promise<void>` - 操作成功或失败的 Promise
374
-
375
- - upsertLane(data) - 新增或更新泳道
376
-
377
- - 参数:`data` - 泳道数据
378
- - 返回值:`Promise<Object>` - 插入或更新后的**完整**泳道对象
379
-
380
- - delLane(lane) - 删除泳道
381
-
382
- - 参数:`lane` - 泳道数据(需包含`laneId`和`lines`数组)
383
- - 返回值:`Promise<void>` - 操作成功或失败的 Promise
384
-
385
- - upsertLine(data) - 新增或更新线条
386
-
387
- - 参数:`data` - 线条数据
388
- - 返回值:`Promise<Object>` - 插入或更新后的**完整线**条对象
389
-
390
- - delLine(data) - 删除线条
391
-
392
- - 参数:`data` - 线条数据(需包含`lineId`和`laneId`)
393
- - 返回值:`Promise<void>` - 操作成功或失败的 Promise
394
-
395
- - restoreSetting() - 恢复默认设置
396
- - 功能:将当前场景的数据重置为初始配置状态
397
- - 实现逻辑:使用构造函数传入的初始 dataSource 重新初始化数据
372
+ ## 5. 组件 API
373
+
374
+ ### 5.1 Props
375
+
376
+ | 属性名 | 类型 | 默认值 | 说明 |
377
+ | ---------------- | ------ | ------- | ------------------ |
378
+ | config | Object | 必填 | 组件配置对象 |
379
+ | headerPadding | Number | 4 | 泳道头部内边距 |
380
+ | headerItemHeight | Number | 20 | 头部线条项高度 |
381
+ | itemGap | Number | 2 | 线条项之间的间距 |
382
+ | customMenuList | Array | [] | 自定义菜单列表 |
383
+ | themeName | String | "white" | 当前使用的主题名称 |
384
+
385
+ ### 5.2 事件
386
+
387
+ | 事件名 | 参数 | 说明 |
388
+ | ------------------- | -------- | ------------------ |
389
+ | onCustomMenuClicked | event | 自定义菜单点击事件 |
390
+ | line-change | line | 线条变化事件 |
391
+ | template-change | template | 模板变化事件 |
392
+
393
+ ### 5.3 方法
394
+
395
+ #### 5.3.1 组件实例方法
396
+
397
+ | 方法名 | 作用描述 | 入参 |
398
+ |----------------|-------------------------------------------------------------------------|------|
399
+ | `getGridSize` | 获取泳道的精确尺寸(包括泳道抬头部分) | 无 |
400
+ | `restoreSetting` | 恢复组件的初始设置(如重置模板、泳道和线条配置到默认状态) | 无 |
401
+
402
+ #### 5.3.2 数据源方法(仅 custom 模式需要实现)
403
+
404
+ **注:以下方法仅在使用 `custom` 模式时需要了解和实现,local 模式下不需要考虑。**
405
+
406
+ 组件内部提供的方法主要用于模板和线条的管理:
407
+
408
+ - upsertTemplate(data) - 新增或更新模板
409
+
410
+ - 参数:`data` - 模板数据
411
+ - 返回值:`Promise<Object>` - 插入或更新后的**完整**模板对象
412
+
413
+ - delTemplate(data) - 删除模板
414
+
415
+ - 参数:`data` - 模板数据(需包含`templateId`)
416
+ - 返回值:`Promise<void>` - 操作成功或失败的 Promise
417
+
418
+ - upsertLane(data) - 新增或更新泳道
419
+
420
+ - 参数:`data` - 泳道数据
421
+ - 返回值:`Promise<Object>` - 插入或更新后的**完整**泳道对象
422
+
423
+ - delLane(lane) - 删除泳道
424
+
425
+ - 参数:`lane` - 泳道数据(需包含`laneId`和`lines`数组)
426
+ - 返回值:`Promise<void>` - 操作成功或失败的 Promise
427
+
428
+ - upsertLine(data) - 新增或更新线条
429
+
430
+ - 参数:`data` - 线条数据
431
+ - 返回值:`Promise<Object>` - 插入或更新后的**完整线**条对象
432
+
433
+ - delLine(data) - 删除线条
434
+
435
+ - 参数:`data` - 线条数据(需包含`lineId`和`laneId`)
436
+ - 返回值:`Promise<void>` - 操作成功或失败的 Promise
437
+
438
+ - restoreSetting() - 恢复默认设置
439
+ - 功能:将当前场景的数据重置为初始配置状态
440
+ - 实现逻辑:使用构造函数传入的初始 dataSource 重新初始化数据
398
441
  - 返回值:`Promise<void>` - 恢复默认设置的 Promise
399
442
 
400
443
  ## 6. 自定义插槽
package/dist/cjs/index.js CHANGED
@@ -898,6 +898,9 @@ class ConfigDBManager {
898
898
  }
899
899
  const dbHelper = new ConfigDBManager();
900
900
 
901
+ function isNumeric(val) {
902
+ return val != null && val !== "" && !Number.isNaN(Number(val));
903
+ }
901
904
  function pxToNumber(pxStr) {
902
905
  if (!pxStr || typeof pxStr !== "string") return 0;
903
906
  return parseFloat(pxStr.replace("px", "")) || 0;
@@ -3504,6 +3507,26 @@ var script = {
3504
3507
  mounted() {},
3505
3508
 
3506
3509
  methods: {
3510
+ getGridSize() {
3511
+ if (!this.$refs.refLaneDiv) return [];
3512
+ const isArray = Array.isArray(this.$refs.refLaneDiv);
3513
+ if (isArray) {
3514
+ return this.$refs.refLaneDiv.map((item) => {
3515
+ const { x, y, width, height, top, right, bottom, left } = item.getBoundingClientRect();
3516
+ return { x, y, width, height, top, bottom, right, left, "lane-id": item.getAttribute("lane-id") };
3517
+ });
3518
+ } else {
3519
+ return [this.$refs.refLaneDiv.getBoundingClientRect()];
3520
+ }
3521
+ },
3522
+ laneContainerStyle(lane, type) {
3523
+ const isWidthNumeric = isNumeric(lane.width);
3524
+ if (type === "slot") {
3525
+ return isWidthNumeric ? { width: `${lane.width}px` } : { width: "auto" };
3526
+ } else {
3527
+ return isWidthNumeric ? { width: `${lane.width}px` } : { flex: "1" };
3528
+ }
3529
+ },
3507
3530
  setExpanded() {
3508
3531
  this.$refs.curveConfig.setExpanded();
3509
3532
  },
@@ -3831,7 +3854,7 @@ var script = {
3831
3854
  },
3832
3855
  };
3833
3856
 
3834
- var css_248z = ".kd-lane-chart-container {\n height: 100%;\n width: 100%;\n overflow: hidden;\n position: relative;\n border: 1px solid var(--kd-lane-container-border-color, #333);\n display: flex;\n}\n.kd-lane-chart-container .kd-lane-chart-lane-slot-container, .kd-lane-chart-container .kd-lane-chart-lane-container {\n height: 100%;\n min-width: 0;\n overflow: hidden;\n z-index: 1;\n}\n.kd-lane-chart-container .kd-lane-chart-lane-slot-container .kd-lane-chart-lane-header, .kd-lane-chart-container .kd-lane-chart-lane-container .kd-lane-chart-lane-header {\n max-height: 40%;\n border-bottom: 1px solid var(--kd-lane-container-border-color, #333);\n overflow: hidden;\n z-index: 2;\n display: flex;\n flex-direction: column;\n justify-content: center;\n}\n.kd-lane-chart-container .kd-lane-chart-lane-container {\n flex: 1;\n}\n.kd-lane-chart-container .kd-lane-chart-lane-slot-container {\n width: auto;\n}\n.kd-lane-chart-container .border-left {\n border-left: 1px solid var(--kd-lane-container-border-color, #333);\n}\n.kd-lane-chart-container .kd-lane-chart-container-draw-area {\n position: absolute;\n left: 0;\n right: 0;\n bottom: 0;\n z-index: 3;\n border: none;\n}";
3857
+ var css_248z = ".kd-lane-chart-container {\n height: 100%;\n width: 100%;\n overflow: hidden;\n position: relative;\n border: 1px solid var(--kd-lane-container-border-color, #333);\n display: flex;\n}\n.kd-lane-chart-container .kd-lane-chart-lane-container,\n.kd-lane-chart-container .kd-lane-chart-lane-slot-container {\n height: 100%;\n min-width: 0;\n overflow: hidden;\n z-index: 1;\n}\n.kd-lane-chart-container .kd-lane-chart-lane-container .kd-lane-chart-lane-header,\n.kd-lane-chart-container .kd-lane-chart-lane-slot-container .kd-lane-chart-lane-header {\n max-height: 40%;\n border-bottom: 1px solid var(--kd-lane-container-border-color, #333);\n overflow: hidden;\n z-index: 2;\n display: flex;\n flex-direction: column;\n justify-content: center;\n}\n.kd-lane-chart-container .border-left {\n border-left: 1px solid var(--kd-lane-container-border-color, #333);\n}\n.kd-lane-chart-container .kd-lane-chart-container-draw-area {\n position: absolute;\n left: 0;\n right: 0;\n bottom: 0;\n z-index: 3;\n border: none;\n}";
3835
3858
  styleInject(css_248z);
3836
3859
 
3837
3860
  /* script */
@@ -3867,8 +3890,12 @@ var __vue_render__ = function () {
3867
3890
  "div",
3868
3891
  {
3869
3892
  key: lane.laneId,
3893
+ ref: "refLaneDiv",
3894
+ refInFor: true,
3870
3895
  staticClass: "kd-lane-chart-lane-slot-container",
3871
3896
  class: { "border-left": index != 0 },
3897
+ style: _vm.laneContainerStyle(lane, "slot"),
3898
+ attrs: { "lane-id": lane.laneId },
3872
3899
  },
3873
3900
  [
3874
3901
  _c(
@@ -3887,8 +3914,12 @@ var __vue_render__ = function () {
3887
3914
  "div",
3888
3915
  {
3889
3916
  key: "" + lane.laneId,
3917
+ ref: "refLaneDiv",
3918
+ refInFor: true,
3890
3919
  staticClass: "kd-lane-chart-lane-slot-container",
3891
3920
  class: { "border-left": index != 0 },
3921
+ style: _vm.laneContainerStyle(lane, "slot"),
3922
+ attrs: { "lane-id": lane.laneId },
3892
3923
  },
3893
3924
  [
3894
3925
  _c(
@@ -3907,8 +3938,12 @@ var __vue_render__ = function () {
3907
3938
  "div",
3908
3939
  {
3909
3940
  key: lane.laneId,
3941
+ ref: "refLaneDiv",
3942
+ refInFor: true,
3910
3943
  staticClass: "kd-lane-chart-lane-container",
3911
3944
  class: { "border-left": index != 0 },
3945
+ style: _vm.laneContainerStyle(lane, "lane"),
3946
+ attrs: { "lane-id": lane.laneId },
3912
3947
  },
3913
3948
  [
3914
3949
  _c(
@@ -3950,18 +3985,25 @@ var __vue_render__ = function () {
3950
3985
  }),
3951
3986
  ]
3952
3987
  : [
3953
- _c("div", { staticClass: "kd-lane-chart-lane-container" }, [
3954
- _c("div", {
3955
- staticClass: "kd-lane-chart-lane-header",
3956
- style: _vm.headerStyle,
3957
- on: {
3958
- contextmenu: function ($event) {
3959
- $event.preventDefault();
3960
- return _vm.showContextMenu.apply(null, arguments)
3988
+ _c(
3989
+ "div",
3990
+ {
3991
+ ref: "refLaneDiv",
3992
+ staticClass: "kd-lane-chart-lane-container",
3993
+ },
3994
+ [
3995
+ _c("div", {
3996
+ staticClass: "kd-lane-chart-lane-header",
3997
+ style: _vm.headerStyle,
3998
+ on: {
3999
+ contextmenu: function ($event) {
4000
+ $event.preventDefault();
4001
+ return _vm.showContextMenu.apply(null, arguments)
4002
+ },
3961
4003
  },
3962
- },
3963
- }),
3964
- ]),
4004
+ }),
4005
+ ]
4006
+ ),
3965
4007
  ],
3966
4008
  _vm._v(" "),
3967
4009
  _c(