chbim-time-axis-v2 0.0.5 → 0.0.7

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 ADDED
@@ -0,0 +1,204 @@
1
+ # chbim-time-axis-v2
2
+
3
+ [![npm version](https://img.shields.io/npm/v/chbim-time-axis-v2.svg?style=flat-square)](https://www.npmjs.com/package/chbim-time-axis-v2)
4
+ [![License](https://img.shields.io/npm/l/chbim-time-axis-v2.svg?style=flat-square)](https://www.npmjs.com/package/chbim-time-axis-v2)
5
+ [![Downloads](https://img.shields.io/npm/dt/chbim-time-axis-v2.svg?style=flat-square)](https://www.npmjs.com/package/chbim-time-axis-v2)
6
+
7
+ 一个专为 Vue 3 设计的甘特图组件,完美集成 Cesium 时间轴功能。
8
+
9
+ ## ✨ 特性
10
+
11
+ - 🤝 **Cesium 集成**: 与 Cesium Viewer 和 Timeline 无缝同步,实现二三维联动。
12
+ - 📅 **多功能甘特图**: 支持任务组、普通任务、时间块(Block)和瞬时点(Instant)多种类型。
13
+ - 🎨 **高度可定制**: 提供丰富的插槽(Slots)和事件(Events)以满足不同业务需求。
14
+ - ⚡ **TypeScript 支持**: 提供完整的类型定义,开发体验更佳。
15
+
16
+ ## 📦 安装
17
+
18
+ 使用 npm 或 yarn 安装:
19
+
20
+ ```bash
21
+ npm install chbim-time-axis-v2
22
+ # 或者
23
+ yarn add chbim-time-axis-v2
24
+ ```
25
+
26
+ ## 🚀 使用指南
27
+
28
+ ### 1. 全局注册(可选)
29
+
30
+ 在 `main.ts` 中引入并注册:
31
+
32
+ ```typescript
33
+ // main.ts
34
+ import { createApp } from "vue";
35
+ import App from "./App.vue";
36
+ import CesiumGantt from "chbim-time-axis-v2";
37
+ import "chbim-time-axis-v2/dist/style.css"; // 引入样式文件
38
+
39
+ const app = createApp(App);
40
+ app.use(CesiumGantt);
41
+ app.mount("#app");
42
+ ```
43
+
44
+ 之后可以在任意组件中直接使用,无需再次导入:
45
+
46
+ ```vue
47
+ <CesiumGantt :viewer="viewer" v-model:tasks="tasks" />
48
+ ```
49
+
50
+ ### 2. 局部注册(推荐)
51
+
52
+ 在组件中直接导入使用:
53
+
54
+ ```vue
55
+ <template>
56
+ <div class="container">
57
+ <!-- Cesium Viewer 容器 -->
58
+ <div ref="cesiumContainer" class="cesium-container"></div>
59
+
60
+ <!-- 甘特图组件容器 -->
61
+ <div class="gantt-container">
62
+ <CesiumGantt
63
+ v-if="viewer"
64
+ :viewer="viewer"
65
+ v-model:tasks="tasks"
66
+ @task-enter="handleTaskEnter"
67
+ @task-leave="handleTaskLeave"
68
+ />
69
+ </div>
70
+ </div>
71
+ </template>
72
+
73
+ <script setup lang="ts">
74
+ import { ref, onMounted, onUnmounted } from "vue";
75
+ import {
76
+ CesiumGantt,
77
+ type GanttTask,
78
+ type GanttGroup,
79
+ } from "chbim-time-axis-v2";
80
+ import "chbim-time-axis-v2/dist/style.css"; // 务必引入样式
81
+ import * as Cesium from "cesium";
82
+ import dayjs from "dayjs";
83
+
84
+ // Cesium 相关设置
85
+ const cesiumContainer = ref<HTMLElement | null>(null);
86
+ const viewer = ref<Cesium.Viewer | null>(null);
87
+
88
+ // 任务数据示例
89
+ const tasks = ref<(GanttTask | GanttGroup)[]>([
90
+ {
91
+ id: "1",
92
+ name: "示例任务组 1",
93
+ type: "group",
94
+ children: [
95
+ {
96
+ id: "1-1",
97
+ name: "任务 1",
98
+ startTime: dayjs().toISOString(),
99
+ endTime: dayjs().add(2, "day").toISOString(),
100
+ },
101
+ ],
102
+ },
103
+ ]);
104
+
105
+ // 初始化 Cesium
106
+ onMounted(() => {
107
+ if (cesiumContainer.value) {
108
+ viewer.value = new Cesium.Viewer(cesiumContainer.value, {
109
+ timeline: true,
110
+ animation: true,
111
+ baseLayerPicker: false,
112
+ });
113
+ }
114
+ });
115
+
116
+ onUnmounted(() => {
117
+ if (viewer.value) {
118
+ viewer.value.destroy();
119
+ }
120
+ });
121
+
122
+ // 事件处理
123
+ const handleTaskEnter = (items: any[]) => {
124
+ console.log("进入任务时间段:", items);
125
+ };
126
+
127
+ const handleTaskLeave = (items: any[]) => {
128
+ console.log("离开任务时间段:", items);
129
+ };
130
+ </script>
131
+
132
+ <style>
133
+ .container {
134
+ display: flex;
135
+ flex-direction: column;
136
+ height: 100vh;
137
+ }
138
+ .cesium-container {
139
+ flex: 1;
140
+ width: 100%;
141
+ }
142
+ .gantt-container {
143
+ height: 300px; /* 根据需要调整高度 */
144
+ background: #2b2b2b;
145
+ }
146
+ </style>
147
+ ```
148
+
149
+ ## ⚙️ 组件属性 (Props)
150
+
151
+ | 属性名 | 类型 | 描述 |
152
+ | :------- | :---------------------------- | :------------------------------------------------------------- |
153
+ | `viewer` | `Cesium.Viewer` | **必传**。Cesium Viewer 实例,用于时间轴同步。 |
154
+ | `clock` | `Cesium.Clock` | (可选) 如果不使用 viewer.clock,可显式传入 Cesium Clock 实例。 |
155
+ | `tasks` | `(GanttTask \| GanttGroup)[]` | 任务列表数据。支持 `v-model:tasks` 双向绑定。 |
156
+
157
+ ## 📡 事件系统 (Events)
158
+
159
+ | 事件名 | 载荷 (Payload) | 描述 |
160
+ | :------------- | :------------- | :---------------------------------------------------------------------------------------- |
161
+ | `update:tasks` | `tasks[]` | 当任务被更新(拖拽、编辑)时触发。 |
162
+ | `task-enter` | `items[]` | 当时间轴播放**进入**某个任务的时间范围时触发。Payload 包含 `{ task, block?, instant? }`。 |
163
+ | `task-leave` | `items[]` | 当时间轴播放**离开**某个任务的时间范围时触发。 |
164
+ | `add` | `parentId` | 点击组(group)上的新增按钮时触发(如果使用默认插槽)。 |
165
+ | `delete` | `taskId` | 点击任务上的删除按钮时触发(如果使用默认插槽)。 |
166
+
167
+ ## 📊 数据结构
168
+
169
+ ### GanttTask 类型定义
170
+
171
+ ```typescript
172
+ interface GanttTask {
173
+ id: string;
174
+ name: string;
175
+ startTime: string; // ISO 8601 格式字符串
176
+ endTime: string; // ISO 8601 格式字符串
177
+ type?: "task" | "group" | "block" | "instant";
178
+ children?: GanttTask[]; // 仅 "group" 类型有效
179
+
180
+ // 当 type 为 'block' 时使用
181
+ blocks?: {
182
+ startTime: string;
183
+ endTime: string;
184
+ name: string;
185
+ color?: string;
186
+ }[];
187
+
188
+ // 当 type 为 'instant' 时使用
189
+ instants?: {
190
+ id: string;
191
+ time: string;
192
+ name: string;
193
+ color?: string;
194
+ }[];
195
+ }
196
+ ```
197
+
198
+ ## 🧩 插槽 (Slots)
199
+
200
+ | 插槽名称 | Props 参数 | 描述 |
201
+ | :--------------- | :------------------------------------------- | :----------------------------------- |
202
+ | `toolbar` | `{ togglePlay, isPlaying, handleResetView }` | 自定义顶部工具栏区域的内容。 |
203
+ | `taskOp` | `{ item }` | 自定义任务列表每一行的操作按钮区域。 |
204
+ | `barContextMenu` | `{ task, block, instant, close }` | 自定义右键点击任务条时的上下文菜单。 |
@@ -12641,7 +12641,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
12641
12641
  class: "instantTaskPoint draggable",
12642
12642
  style: normalizeStyle({
12643
12643
  left: inst.left - 10 + "px",
12644
- /* Center the circle */
12644
+ /* 居中圆圈 */
12645
12645
  width: "18px",
12646
12646
  height: "18px",
12647
12647
  backgroundColor: inst.color || "#ffffff",
@@ -12670,8 +12670,8 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
12670
12670
  };
12671
12671
  }
12672
12672
  });
12673
- const TimelineChart_vue_vue_type_style_index_0_scoped_c5b5f160_lang = "";
12674
- const TimelineChart = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-c5b5f160"]]);
12673
+ const TimelineChart_vue_vue_type_style_index_0_scoped_92426524_lang = "";
12674
+ const TimelineChart = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-92426524"]]);
12675
12675
  const _hoisted_1 = { class: "toolbar" };
12676
12676
  const _hoisted_2 = { style: { "flex": "1", "display": "flex", "align-items": "center", "height": "100%" } };
12677
12677
  const _hoisted_3 = { class: "left-controls" };
@@ -12801,7 +12801,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
12801
12801
  time,
12802
12802
  name: "新瞬时点",
12803
12803
  color: "#ffffff"
12804
- // Default to white
12804
+ // 默认为白色
12805
12805
  });
12806
12806
  emit("taskUpdate", JSON.parse(JSON.stringify(t)));
12807
12807
  return true;
@@ -13517,8 +13517,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
13517
13517
  };
13518
13518
  }
13519
13519
  });
13520
- const CesiumGantt_vue_vue_type_style_index_0_scoped_cd0cef0f_lang = "";
13521
- const CesiumGantt = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-cd0cef0f"]]);
13520
+ const CesiumGantt_vue_vue_type_style_index_0_scoped_6d73b641_lang = "";
13521
+ const CesiumGantt = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-6d73b641"]]);
13522
13522
  CesiumGantt.install = (app) => {
13523
13523
  app.component("CesiumGantt", CesiumGantt);
13524
13524
  };