diff --git a/CHANGELOG.md b/CHANGELOG.md index b115ad9..942fdf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.7.1] - 2026-01-11 + +### Added +- 🎉 新增:GanttChart新增属性,locale, theme, timeScale, fullscreen, expandAll供外部调用 +- 🎉 新增:GanttChart暴露国际化相关方法,setLocale & currentLocale +- 🎉 新增:GanttChart暴露主题相关方法,setTheme & currentTheme,setTimeScale & currentScale +- 🎉 新增:GanttChart暴露全屏相关方法,toggleFullscreen & enterFullscreen & exitFullscreen & isFullscreen +- 🎉 新增:GanttChart暴露展开/收起相关方法,toggleExpandAll & expandAll & collapseAll & isExpandAll +- 🎉 新增:GanttChart暴露滑至今日/任务/指定日期相关方法,scrollToToday & scrollToTask & scrollToDate +- 🎉 Added: New properties in GanttChart - locale, theme, timeScale, fullscreen, expandAll for external calls +- 🎉 Added: Exposed internationalization related methods in GanttChart - setLocale & currentLocale +- 🎉 Added: Exposed theme related methods in GanttChart - setTheme & currentTheme, setTimeScale & currentScale +- 🎉 Added: Exposed fullscreen related methods in GanttChart - toggleFullscreen & enterFullscreen & exitFullscreen & isFullscreen +- 🎉 Added: Exposed expand/collapse related methods in GanttChart - toggleExpandAll & expandAll & collapseAll & isExpandAll +- 🎉 Added: Exposed methods in GanttChart to scroll to today/task/specified date - scrollToToday & scrollToTask & scrollToDate + ## [1.7.0] - 2026-01-10 ### Added diff --git a/README-EN.md b/README-EN.md index 47660c7..574702a 100644 --- a/README-EN.md +++ b/README-EN.md @@ -1,5 +1,21 @@ # jordium-gantt-vue3 logo jordium-gantt-vue3 + +

npm version @@ -200,6 +216,11 @@ npm run dev | `enableTaskListContextMenu` | `boolean` | `true` | Whether to enable TaskList (TaskRow) context menu. When `true`: uses built-in menu if `task-list-context-menu` slot is not declared, uses custom menu if slot is declared; when `false`: context menu is completely disabled | | `enableTaskBarContextMenu` | `boolean` | `true` | Whether to enable TaskBar context menu. When `true`: uses built-in menu if `task-bar-context-menu` slot is not declared, uses custom menu if slot is declared; when `false`: context menu is completely disabled | | `assigneeOptions` | `Array<{ key?: string \| number; value: string \| number; label: string }>` | `[]` | Assignee dropdown options in task edit drawer | +| `locale` 1.7.1 | `'zh-CN' \| 'en-US'` | `'zh-CN'` | Language setting (reactive). Component's internal language will follow changes | +| `theme` 1.7.1 | `'light' \| 'dark'` | `'light'` | Theme mode (reactive). Component's theme will follow changes | +| `timeScale` 1.7.1 | `'hour' \| 'day' \| 'week' \| 'month' \| 'quarter' \| 'year'` | `'week'` | Time scale (reactive). Timeline scale will follow changes | +| `fullscreen` 1.7.1 | `boolean` | `false` | Fullscreen state control (reactive). Component's fullscreen state will follow changes | +| `expandAll` 1.7.1 | `boolean` | `true` | Expand/collapse all tasks (reactive). All tasks' expand state will follow changes | #### TaskListColumn Component Props @@ -537,6 +558,61 @@ const handleMilestoneSaved = milestone => { ``` +#### Example 4: External Component State Control (TimeScale, Fullscreen, Expand/Collapse, Locale, Theme) + +Control component state through reactive Props binding. Component state will automatically follow Props changes. + +```vue + + + +``` + --- ### Task Management @@ -2041,6 +2117,168 @@ The component has built-in intelligent timeline range calculation logic, ensurin > - Avoids issues with timeline being too narrow or having excessive whitespace > - Suitable for displaying at different resolutions +### Expose Methods + +The GanttChart component exposes a series of methods through `defineExpose`, allowing parent components to directly call these methods via template references (`ref`) to control component behavior. This imperative control approach is suitable for scenarios requiring precise timing control. + +#### Available Expose Methods + +| Method | Parameters | Return Value | Description | +| --- | --- | --- | --- | +| `setLocale` 1.7.1 | `locale: 'zh-CN' \| 'en-US'` | `void` | Set component language | +| `currentLocale` 1.7.1 | - | `'zh-CN' \| 'en-US'` | Get current language setting | +| `setTheme` 1.7.1 | `mode: 'light' \| 'dark'` | `void` | Set theme mode | +| `currentTheme` 1.7.1 | - | `'light' \| 'dark'` | Get current theme mode | +| `setTimeScale` 1.7.1 | `scale: TimelineScale` | `void` | Set time scale (`'hour' \| 'day' \| 'week' \| 'month' \| 'quarter' \| 'year'`) | +| `currentScale` 1.7.1 | - | `TimelineScale` | Get current time scale | +| `toggleFullscreen` 1.7.1 | - | `void` | Toggle fullscreen state | +| `enterFullscreen` 1.7.1 | - | `void` | Enter fullscreen mode | +| `exitFullscreen` 1.7.1 | - | `void` | Exit fullscreen mode | +| `isFullscreen` 1.7.1 | - | `boolean` | Get current fullscreen state | +| `toggleExpandAll` 1.7.1 | - | `void` | Toggle expand/collapse all tasks | +| `expandAll` 1.7.1 | - | `void` | Expand all tasks | +| `collapseAll` 1.7.1 | - | `void` | Collapse all tasks | +| `isExpandAll` 1.7.1 | - | `boolean` | Get current expand all state | +| `scrollToToday` 1.7.1 | - | `void` | Scroll to today's position | +| `scrollToTask` 1.7.1 | `taskId: number \| string` | `void` | Scroll to specified task (task will auto-expand to visible state) | +| `scrollToDate` 1.7.1 | `date: string \| Date` | `void` | Scroll to specified date position (format: `'YYYY-MM-DD'` or Date object) | + +#### Usage Example + +**Basic Usage: Imperative Control** + +```vue + + + + + +``` + +#### Best Practices + +1. **Imperative vs Reactive** + - Use **Expose Methods**: When you need precise control over timing, such as button clicks or specific event triggers + - Use **Props Binding**: When state needs to automatically update following data source, such as syncing with URL parameters + +2. **Getting State** + - Provides paired getter methods (like `currentLocale()`, `currentTheme()`) + - Can immediately get the latest state for verification after calling setters + +3. **Error Handling** + - Check if `ref` is mounted before calling: `ganttRef.value?.methodName()` + - Safer to call after `onMounted` lifecycle + +**Complete examples can be found in:** +- npm-demo project: `npm-demo/src/components/GanttTest.vue` +- npm-webpack-demo project: `npm-webpack-demo/src/App.vue` + +--- + ### Theme & Internationalization #### Theme Switching diff --git a/README.md b/README.md index d2c1204..e609c11 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,21 @@ # jordium-gantt-vue3 logo jordium-gantt-vue3 + +

npm version @@ -197,7 +213,12 @@ npm run dev | `enableTaskRowMove` | `boolean` | `false` | 是否允许拖拽和摆放TaskRow | | `enableTaskListContextMenu` | `boolean` | `true` | 是否启用 TaskList(TaskRow)右键菜单功能。为 `true` 时:未声明 `task-list-context-menu` 插槽则使用内置菜单,声明了插槽则使用自定义菜单;为 `false` 时右键菜单完全禁用 | | `enableTaskBarContextMenu` | `boolean` | `true` | 是否启用 TaskBar 右键菜单功能。为 `true` 时:未声明 `task-bar-context-menu` 插槽则使用内置菜单,声明了插槽则使用自定义菜单;为 `false` 时右键菜单完全禁用 | -| `assigneeOptions` | `Array<{ key?: string \| number; value: string \| number; label: string }>` | `[]` | 任务编辑抽屉中负责人下拉菜单的选项列表 | +| `assigneeOptions` | `Array<{ key?: string \| number; value: string \| number; label: string }>` | `[]` | 任务编辑抽屉中负责人下拉菜单的选项列表 | +| `locale` 1.7.1 | `'zh-CN' \| 'en-US'` | `'zh-CN'` | 语言设置(响应式)。设置后组件内部语言将跟随变化 | +| `theme` 1.7.1 | `'light' \| 'dark'` | `'light'` | 主题模式(响应式)。设置后组件主题将跟随变化 | +| `timeScale` 1.7.1 | `'hour' \| 'day' \| 'week' \| 'month' \| 'quarter' \| 'year'` | `'week'` | 时间刻度(响应式)。设置后时间线刻度将跟随变化 | +| `fullscreen` 1.7.1 | `boolean` | `false` | 全屏状态控制(响应式)。设置后组件全屏状态将跟随变化 | +| `expandAll` 1.7.1 | `boolean` | `true` | 展开/收起所有任务(响应式)。设置后所有任务的展开状态将跟随变化 | #### TaskListColumn 属性 @@ -535,6 +556,61 @@ const handleMilestoneSaved = milestone => { ``` +#### 示例4:外部组件控制状态(TimeScale、Fullscreen、Expand/Collapse、Locale、Theme) + +通过响应式Props绑定来控制组件状态,组件状态会自动跟随Props变化。 + +```vue + + + +``` + --- ### 任务管理 @@ -2032,6 +2108,168 @@ const taskBarConfig = computed(() => ({ > - 避免出现时间线过窄或留白过多的问题 > - 适用不同分辨率展示 +### Expose 方法 + +GanttChart 组件通过 `defineExpose` 暴露了一系列方法,允许父组件通过模板引用 (`ref`) 直接调用这些方法来控制组件行为。这种命令式的控制方式适合需要精确控制时机的场景。 + +#### 可用的 Expose 方法 + +| 方法名 | 参数 | 返回值 | 说明 | +| --- | --- | --- | --- | +| `setLocale` 1.7.1 | `locale: 'zh-CN' \| 'en-US'` | `void` | 设置组件语言 | +| `currentLocale` 1.7.1 | - | `'zh-CN' \| 'en-US'` | 获取当前语言设置 | +| `setTheme` 1.7.1 | `mode: 'light' \| 'dark'` | `void` | 设置主题模式 | +| `currentTheme` 1.7.1 | - | `'light' \| 'dark'` | 获取当前主题模式 | +| `setTimeScale` 1.7.1 | `scale: TimelineScale` | `void` | 设置时间刻度(`'hour' \| 'day' \| 'week' \| 'month' \| 'quarter' \| 'year'`) | +| `currentScale` 1.7.1 | - | `TimelineScale` | 获取当前时间刻度 | +| `toggleFullscreen` 1.7.1 | - | `void` | 切换全屏状态 | +| `enterFullscreen` 1.7.1 | - | `void` | 进入全屏模式 | +| `exitFullscreen` 1.7.1 | - | `void` | 退出全屏模式 | +| `isFullscreen` 1.7.1 | - | `boolean` | 获取当前是否处于全屏状态 | +| `toggleExpandAll` 1.7.1 | - | `void` | 切换展开/收起所有任务 | +| `expandAll` 1.7.1 | - | `void` | 展开所有任务 | +| `collapseAll` 1.7.1 | - | `void` | 收起所有任务 | +| `isExpandAll` 1.7.1 | - | `boolean` | 获取当前是否全部展开 | +| `scrollToToday` 1.7.1 | - | `void` | 滚动到今天的位置 | +| `scrollToTask` 1.7.1 | `taskId: number \| string` | `void` | 滚动到指定任务(任务会自动展开到可见状态) | +| `scrollToDate` 1.7.1 | `date: string \| Date` | `void` | 滚动到指定日期位置(格式:`'YYYY-MM-DD'` 或 Date 对象) | + +#### 使用示例 + +**基础用法:命令式控制** + +```vue + + + + + +``` + +#### 最佳实践 + +1. **命令式 vs 响应式** + - 使用 **Expose 方法**:需要精确控制调用时机,如按钮点击、特定事件触发 + - 使用 **Props 绑定**:状态需要跟随数据源自动更新,如与 URL 参数同步 + +2. **获取状态** + - 提供了成对的 getter 方法(如 `currentLocale()`、`currentTheme()`) + - 可在调用 setter 后立即获取最新状态进行验证 + +3. **错误处理** + - 调用前检查 `ref` 是否已挂载:`ganttRef.value?.methodName()` + - 在 `onMounted` 生命周期之后调用更安全 + +**完整示例可参考:** +- npm-demo 项目:`npm-demo/src/components/GanttTest.vue` +- npm-webpack-demo 项目:`npm-webpack-demo/src/App.vue` + +--- + ### 主题与国际化 #### 主题切换 diff --git a/demo/App.vue b/demo/App.vue index e69b422..5712109 100644 --- a/demo/App.vue +++ b/demo/App.vue @@ -1,5 +1,5 @@