Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改webui #565

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

修改webui #565

wants to merge 8 commits into from

Conversation

Ander-pixe
Copy link

@Ander-pixe Ander-pixe commented Nov 25, 2024

Sourcery的总结

重新设计网页UI,通过更新网络配置布局、添加主题切换功能以及改进导航和登录界面来提升用户体验。

增强功能:

  • 重新设计网络配置UI,以更有条理的布局和额外的配置选项来改善用户体验。
  • 重构主题管理系统,允许用户在浅色、深色和自动主题之间切换,并根据系统设置自动调整。
  • 增强侧边栏菜单,添加可折叠功能和工具提示,以便在不同屏幕尺寸上更好地导航。
  • 改进登录组件,添加工具提示并重组布局,以提供更直观的用户界面。
Original summary in English

Summary by Sourcery

重新设计网页用户界面,通过更新网络配置布局、添加主题切换功能以及增强导航和登录界面来改善用户体验。

新功能:

  • 引入主题管理系统,允许用户在浅色、深色和自动主题之间切换,并根据系统设置自动调整。

增强功能:

  • 重新设计网络配置用户界面,以获得更有条理的布局和更多的配置选项。
  • 增强侧边栏菜单,添加可折叠功能和工具提示,以便在不同屏幕尺寸上更好地导航。
  • 改进登录组件,添加工具提示并重新组织布局,以提供更直观的用户界面。
Original summary in English

Summary by Sourcery

Redesign the web UI to improve user experience by updating the network configuration layout, adding theme switching functionality, and enhancing navigation and login interfaces.

New Features:

  • Introduce a theme management system allowing users to switch between light, dark, and auto themes, with automatic adjustments based on system settings.

Enhancements:

  • Redesign the network configuration UI for a more organized layout and additional configuration options.
  • Enhance the sidebar menu with collapsible functionality and tooltips for better navigation on different screen sizes.
  • Improve the login component by adding tooltips and reorganizing the layout for a more intuitive user interface.

Copy link

sourcery-ai bot commented Nov 25, 2024

审核指南由 Sourcery 提供

此 PR 实现了 Web UI 的重大重新设计,重点在于改进网络配置界面、添加主题管理以及增强整体用户体验。更改包括为网络配置提供新的卡片布局、响应式设计改进以及添加主题切换组件。

更新的网络配置组件类图

classDiagram
    class NetworkConfigType {
        +Array websocketClients
        +Array websocketServers
        +Array httpClients
        +Array httpServers
    }
    class TypeChType {
        +String httpServers
        +String httpClients
        +String websocketServers
        +String websocketClients
    }
    class WebConfg {
        +Map all
        +Map httpServers
        +Map httpClients
        +Map websocketServers
        +Map websocketClients
    }
    class ConfigKey {
        <<enumeration>>
        httpServers
        httpClients
        websocketServers
        websocketClients
    }
    class ThemeMode {
        <<enumeration>>
        Dark
        Light
        Auto
    }
    NetworkConfigType --> TypeChType
    NetworkConfigType --> WebConfg
    WebConfg --> ConfigKey
    WebConfg --> ThemeMode
    note for NetworkConfigType "表示网络配置的结构"
    note for TypeChType "将配置类型映射到其字符串表示"
    note for WebConfg "以映射格式存储配置数据"
    note for ConfigKey "配置键的枚举"
    note for ThemeMode "主题模式的枚举"
Loading

文件级更改

更改 详情 文件
使用新的卡片布局重新设计网络配置界面
  • 用卡片网格布局替换基于选项卡的网络配置界面
  • 添加按配置类型过滤的功能
  • 实现响应式网格布局以适应不同屏幕尺寸
  • 添加编辑和删除功能以及确认对话框
napcat.webui/src/pages/NetWork.vue
添加具有亮、暗和自动模式的主题管理系统
  • 实现具有三种模式的主题切换组件:亮、暗和自动
  • 添加系统主题检测和自动主题切换
  • 创建用于主题控制的粘性工具组件
napcat.webui/src/App.vue
增强导航和布局组件
  • 添加具有响应行为的可折叠侧边栏
  • 在侧边栏折叠时为导航项实现工具提示
  • 为导航添加徽标和品牌
  • 创建用于组件通信的事件总线系统
napcat.webui/src/components/webui/Nav.vue
napcat.webui/src/components/Dashboard.vue
napcat.webui/src/ts/event-bus.ts
改进的登录组件,提供更好的 UI/UX
  • 使用卡片布局重新设计登录表单
  • 为登录选项添加工具提示
  • 改进移动设备的响应式设计
  • 更新页脚样式和定位
napcat.webui/src/components/QQLogin.vue
napcat.webui/src/components/WebUiLogin.vue
精简网络配置组件
  • 简化所有网络配置组件的表单布局
  • 标准化表单样式和行为
  • 删除冗余的容器元素和样式
napcat.webui/src/pages/network/HttpServerComponent.vue
napcat.webui/src/pages/network/HttpClientComponent.vue
napcat.webui/src/pages/network/WebsocketServerComponent.vue
napcat.webui/src/pages/network/WebsocketClientComponent.vue

提示和命令

与 Sourcery 互动

  • 触发新审核: 在拉取请求中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审核评论。
  • 从审核评论生成 GitHub 问题: 通过回复审核评论请求 Sourcery 从中创建问题。
  • 生成拉取请求标题: 在拉取请求标题中任意位置写 @sourcery-ai 以随时生成标题。
  • 生成拉取请求摘要: 在拉取请求正文中任意位置写 @sourcery-ai summary 以随时生成 PR 摘要。您也可以使用此命令指定摘要应插入的位置。

自定义您的体验

访问您的仪表板以:

  • 启用或禁用审核功能,例如 Sourcery 生成的拉取请求摘要、审核指南等。
  • 更改审核语言。
  • 添加、删除或编辑自定义审核说明。
  • 调整其他审核设置。

获取帮助

Original review guide in English

Reviewer's Guide by Sourcery

This PR implements a major redesign of the web UI, focusing on improving the network configuration interface, adding theme management, and enhancing the overall user experience. The changes include a new card-based layout for network configurations, responsive design improvements, and the addition of a theme switcher component.

Updated class diagram for network configuration components

classDiagram
    class NetworkConfigType {
        +Array websocketClients
        +Array websocketServers
        +Array httpClients
        +Array httpServers
    }
    class TypeChType {
        +String httpServers
        +String httpClients
        +String websocketServers
        +String websocketClients
    }
    class WebConfg {
        +Map all
        +Map httpServers
        +Map httpClients
        +Map websocketServers
        +Map websocketClients
    }
    class ConfigKey {
        <<enumeration>>
        httpServers
        httpClients
        websocketServers
        websocketClients
    }
    class ThemeMode {
        <<enumeration>>
        Dark
        Light
        Auto
    }
    NetworkConfigType --> TypeChType
    NetworkConfigType --> WebConfg
    WebConfg --> ConfigKey
    WebConfg --> ThemeMode
    note for NetworkConfigType "Represents the structure for network configurations"
    note for TypeChType "Maps configuration types to their string representations"
    note for WebConfg "Stores configuration data in a map format"
    note for ConfigKey "Enumeration for configuration keys"
    note for ThemeMode "Enumeration for theme modes"
Loading

File-Level Changes

Change Details Files
Redesigned the network configuration interface with a new card-based layout
  • Replaced tab-based interface with a card grid layout for network configurations
  • Added filtering capability by configuration type
  • Implemented responsive grid layout that adapts to different screen sizes
  • Added edit and delete functionality with confirmation dialogs
napcat.webui/src/pages/NetWork.vue
Added theme management system with light, dark, and auto modes
  • Implemented theme switcher component with three modes: light, dark, and auto
  • Added system theme detection and automatic theme switching
  • Created sticky tool component for theme controls
napcat.webui/src/App.vue
Enhanced navigation and layout components
  • Added collapsible sidebar with responsive behavior
  • Implemented tooltips for navigation items when sidebar is collapsed
  • Added logo and branding to the navigation
  • Created event bus system for component communication
napcat.webui/src/components/webui/Nav.vue
napcat.webui/src/components/Dashboard.vue
napcat.webui/src/ts/event-bus.ts
Improved login components with better UI/UX
  • Redesigned login forms with card-based layout
  • Added tooltips to login options
  • Improved responsive design for mobile devices
  • Updated footer styling and positioning
napcat.webui/src/components/QQLogin.vue
napcat.webui/src/components/WebUiLogin.vue
Streamlined network configuration components
  • Simplified form layouts across all network configuration components
  • Standardized form styling and behavior
  • Removed redundant container elements and styles
napcat.webui/src/pages/network/HttpServerComponent.vue
napcat.webui/src/pages/network/HttpClientComponent.vue
napcat.webui/src/pages/network/WebsocketServerComponent.vue
napcat.webui/src/pages/network/WebsocketClientComponent.vue

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@pk5ls20 pk5ls20 self-assigned this Nov 25, 2024
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ander-pixe - 我已经审查了你的更改,看起来很棒!

这是我在审查期间查看的内容
  • 🟢 一般问题:一切看起来都很好
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟡 复杂性:发现1个问题
  • 🟢 文档:一切看起来都很好

Sourcery 对开源项目免费 - 如果你喜欢我们的审查,请考虑分享它们 ✨
帮助我变得更有用!请在每条评论上点击 👍 或 👎,我将使用反馈来改进你的审查。
Original comment in English

Hey @Ander-pixe - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -0,0 +1,3 @@
import mitt from "mitt"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): 考虑采用 Vue 的原生组件通信模式,而不是引入第三方事件总线库

考虑使用 Vue 的内置模式而不是全局事件总线。这将使代码流更易于追踪和维护。这里有两个替代方案:

  1. 对于父子通信,使用 props 和事件:
// Parent.vue
<template>
  <child-component
    :data="data"
    @update="handleUpdate"
  />
</template>

// Child.vue
<script>
export default {
  props: ['data'],
  methods: {
    updateData() {
      this.$emit('update', newValue)
    }
  }
}
</script>
  1. 对于远程组件,使用 provide/inject:
// Parent.vue
export default {
  provide() {
    return {
      updateData: this.updateData
    }
  }
}

// Deeply nested child
export default {
  inject: ['updateData']
}

如果你需要全局状态管理,考虑使用 Vuex,它提供了更好的调试和状态跟踪能力。

Original comment in English

issue (complexity): Consider adopting Vue's native component communication patterns instead of introducing a third-party event bus library

Consider using Vue's built-in patterns instead of a global event bus. This will make the code flow more traceable and maintainable. Here are two alternatives:

  1. For parent-child communication, use props and events:
// Parent.vue
<template>
  <child-component
    :data="data"
    @update="handleUpdate"
  />
</template>

// Child.vue
<script>
export default {
  props: ['data'],
  methods: {
    updateData() {
      this.$emit('update', newValue)
    }
  }
}
</script>
  1. For distant components, use provide/inject:
// Parent.vue
export default {
  provide() {
    return {
      updateData: this.updateData
    }
  }
}

// Deeply nested child
export default {
  inject: ['updateData']
}

If you need global state management, consider using Vuex which provides better debugging and state tracking capabilities.

@pk5ls20 pk5ls20 marked this pull request as draft November 25, 2024 11:58
@pk5ls20 pk5ls20 marked this pull request as ready for review November 25, 2024 12:04
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ander-pixe - 我已经审查了你的更改,看起来很棒!

这是我在审查期间查看的内容
  • 🟡 一般问题:发现4个问题
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟡 复杂性:发现1个问题
  • 🟢 文档:一切看起来都很好

Sourcery对开源项目免费 - 如果你喜欢我们的审查,请考虑分享它们 ✨
帮助我变得更有用!请在每条评论上点击👍或👎,我将使用反馈来改进你的审查。
Original comment in English

Hey @Ander-pixe - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 4 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

if (!userConfig) {
await MessagePlugin.error('无法获取配置!');
return;
const handleResize = () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议(性能): 考虑对调整大小处理程序进行防抖以提高性能

调整大小处理程序被频繁调用并执行DOM测量。考虑使用防抖函数将更新频率限制为100毫秒间隔。

const handleResize = debounce(() => {
Original comment in English

suggestion (performance): Consider debouncing the resize handler to improve performance

The resize handler is called frequently and performs DOM measurements. Consider using a debounce function to limit the rate of updates to something like 100ms intervals.

const handleResize = debounce(() => {

@@ -0,0 +1,3 @@
import mitt from "mitt"
const emitter = mitt();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议: 考虑为事件总线实现添加类型安全

mitt事件发射器可以通过TypeScript类型增强事件名称和负载,以在编译时捕获潜在错误。

const emitter = mitt<{
  'modal:open': { id: string };
  'modal:close': { id: string };
  'notification:show': { message: string; type: 'success' | 'error' };
}>();
Original comment in English

suggestion: Consider adding type safety to the event bus implementation

The mitt event emitter could be enhanced with TypeScript types for event names and payloads to catch potential errors at compile time.

const emitter = mitt<{
  'modal:open': { id: string };
  'modal:close': { id: string };
  'notification:show': { message: string; type: 'success' | 'error' };
}>();

await MessagePlugin.error('无法获取配置!');
return;
const handleResize = () => {
tabsWidth.value = window.innerWidth- 40 -menuWidth.value
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议: 将魔术数字提取为命名常量

填充/边距值(40)应提取为命名常量,以提高可维护性并使布局计算更清晰。

Suggested change
tabsWidth.value = window.innerWidth- 40 -menuWidth.value
const WINDOW_PADDING = 40;
tabsWidth.value = window.innerWidth - WINDOW_PADDING - menuWidth.value;
Original comment in English

suggestion: Extract magic numbers into named constants

The padding/margin values (40) should be extracted into named constants to improve maintainability and make the layout calculations more clear.

Suggested change
tabsWidth.value = window.innerWidth- 40 -menuWidth.value
const WINDOW_PADDING = 40;
tabsWidth.value = window.innerWidth - WINDOW_PADDING - menuWidth.value;

else if(operateType.value=='delete'){
networkConfig[newTab.value.type].splice(configIndex.value,1)
}
const userConfig = await getOB11Config();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议: 为配置加载失败添加错误处理

配置加载应更优雅地处理网络错误和无效的配置数据,向用户显示适当的错误消息。

    try {
        const userConfig = await getOB11Config();
        if (!userConfig) {
            throw new Error('Failed to load configuration');
        }
    } catch (error) {
        ElMessage.error(`Configuration error: ${error.message}`);
        return;
    }
Original comment in English

suggestion: Add error handling for failed config loading

The config loading should handle network errors and invalid config data more gracefully, showing appropriate error messages to the user.

    try {
        const userConfig = await getOB11Config();
        if (!userConfig) {
            throw new Error('Failed to load configuration');
        }
    } catch (error) {
        ElMessage.error(`Configuration error: ${error.message}`);
        return;
    }

@@ -0,0 +1,3 @@
import mitt from "mitt"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

问题(复杂性): 考虑使用Vue的依赖注入模式进行事件处理,而不是全局事件总线

考虑使用Vue的内置provide/inject API,而不是全局事件总线。这保持了组件层次结构并提高了代码可追溯性,同时实现了相同的目标。示例:

// 在你的根组件或应用设置中
import { provide } from 'vue'

const emitter = {
  emit: (event, data) => {
    state.listeners[event]?.forEach(callback => callback(data))
  },
  on: (event, callback) => {
    if (!state.listeners[event]) state.listeners[event] = []
    state.listeners[event].push(callback)
  }
}

const state = {
  listeners: {}
}

provide('eventBus', emitter)

// 在子组件中
import { inject } from 'vue'

const eventBus = inject('eventBus')
eventBus.emit('event', data)
eventBus.on('event', callback)

这种方法:

  • 将事件处理保持在Vue的组件系统内
  • 通过注入使依赖关系显式化
  • 更容易使用Vue开发工具进行测试和调试
  • 消除了对mitt的外部依赖
Original comment in English

issue (complexity): Consider using Vue's dependency injection pattern for event handling instead of a global event bus

Consider using Vue's built-in provide/inject API instead of a global event bus. This maintains component hierarchy and improves code traceability while achieving the same goals. Example:

// In your root component or app setup
import { provide } from 'vue'

const emitter = {
  emit: (event, data) => {
    state.listeners[event]?.forEach(callback => callback(data))
  },
  on: (event, callback) => {
    if (!state.listeners[event]) state.listeners[event] = []
    state.listeners[event].push(callback)
  }
}

const state = {
  listeners: {}
}

provide('eventBus', emitter)

// In child components
import { inject } from 'vue'

const eventBus = inject('eventBus')
eventBus.emit('event', data)
eventBus.on('event', callback)

This approach:

  • Keeps event handling within Vue's component system
  • Makes dependencies explicit through injection
  • Easier to test and debug with Vue devtools
  • Removes external dependency on mitt

@pk5ls20 pk5ls20 self-requested a review November 25, 2024 13:08
@MliKiowa MliKiowa self-requested a review November 26, 2024 04:41
Copy link

sonarcloud bot commented Nov 26, 2024

@MliKiowa MliKiowa removed their request for review November 26, 2024 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants