ApiHug SDK 1.3.5 Vue 框架 - 预览版

前端框架设计原则和说明, 前端完整模版尚未正式发布,还在内侧中。

ApiHug Vue 框架 - ApiHug前端框架设计原则和说明https://apihug.github.io/zhCN-docs/ui/002_vue

​Structure

项目整体采用 Monorepo 设计:

复制代码
├─packages (1)
│  ├─antd
│  ├─util
│  └─hook
├─src (2)
│  ├─assets
│  └─components
│
  1. (1) 独立包模块:组件、util、hook etc
  2. (2) 主应用

src 为主应用入口:

复制代码
├─assets (1)
│  ├─styles
│  │  └─transition
│  └─svg-icon
├─components (2)
│  ├─dashboard
│  └─ui
│      ├─accordion
│      ├─alert
├─composables (3)
├─config  (4)
├─directive (5)
├─layouts (6)
│  └─admin
├─lib (7)
├─locales  (8)
│  └─langs
│      ├─en-US
│      └─zh-CN
├─pages (9)
│  ├─dashboard
│  └─example
├─router (10)
│  └─auto
├─service (11)
│  ├─api
│  ├─form
│  ├─model
│  └─table
├─stores (12)
├─types  (13)
└─utils (14)
Directory Content
(1) CSS 风格
(2) 组件库
(3) Hook
(4) 配置
(5) 指令扩展
(6) 布局
(7) 三方类
(8) 国际化
(9) 页面
(10) 路由
(11) 服务
(12) 状态
(13) d.ts定义
(14) 帮助类

​功能

​Component

ui

来自 shadcn-vue , 独立共享组件。

This is NOT a component library. It's a collection of re-usable components that you can copy and paste or use the CLI to add to your apps.

源头来自: react 社区:shadcn

TBD: 移动到独立 packages

other

本目录下, 非 ui 为自定义组件, 注意所有 src/components 将被 unplugin-vue-components/vite 自动导入:

复制代码
    Components({
      dts: 'src/types/components.d.ts',
      dirs: ['src/components']
    })

​Router

路由自动发现注册,可由 hope 工具链,完整自动发现和生成, 配置在 {module}-appui.json 配置 ui

打开 autoRouter 标志, 自动扫描, pagesDir 默认配置自 {module}-ui模块下的src/pages路径。

页面 meta 信息需要额外配置元信息(defineOptions),如src/pages/dashboard/index.vue:

复制代码
<script setup lang="ts">
  defineOptions({
    name: 'Dashboard',
    meta: {
      title: 'Dashboard页面',
      //i18key: 'pages.dashboard.title',
      icon: 'lucide:table',
      hidden: false,
      layout: 'admin',
      sort: 1,
    },
  })
</script>

工具执行后,输出到 src/router/auto/index.ts (routerOutDir 默认配置 src/router/auto):

复制代码
export const pages: RouteRecordRaw[] = [{
  name: 'Dashboard',
  path: '/dashboard',
  component: () => import('@/pages/dashboard/index.vue'),
  meta: {
    title: 'Dashboard页面',
    i18key: 'pages.dashboard.title',
    icon: 'dash',
    layout: 'admin',
    hidden: false,
    type: 'LEAF',
    level: 0,
    displayOrder: 0,
  },
}]
Property Comment
title 标题描述
i18key 国际化key
icon icon
layout 样式布局
hidden 是否隐藏
type 类型
level level
displayOrder 显示顺序
  1. type: ROOT|BRANCH|LEAF 路径在整个路由中位置,根、中间、叶节点
  2. level: 深度,0 为根
  3. displayOrder: 显示顺序,同级别展示先后顺序, 在路由菜单中显示顺序

其他输出:

由路由树状结构生成菜单树结构可以作为默认菜单结构,也可做为定配菜单输入元信息。

Menu

复制代码
export const menus: MenuItem[] = [{
  name: 'Dashboard',
  path: '/dashboard',
  title: 'Dashboard页面',
  i18key: 'pages.dashboard.title',
  icon: 'dash',
  hidden: false,
  type: 'LEAF',
  level: 0,
  displayOrder: 0,
}, {
  path: '/example',
  i18key: 'pages.example.title',
  type: 'ROOT',
  level: 0,
  children: [{
    name: 'ExampleForm',
    path: '/example/form',
    title: '示例表单',
    i18key: 'pages.example.form.title',
    icon: 'lucide:search',
    type: 'LEAF',
    level: 1,
    parentPath: '/example',
    displayOrder: 0,
  }]
}]

i18n

工具自动生成 i18n 配置 sr/locals/{lang}/pages.json:

复制代码
{
  "dashboard": {
    "title": "Dashboard页面"
  },
  "example": {
    "title": "纯例子",
    "form": {
      "title": "示例表单-大帅"
    },
    "search-table": {
      "title": "搜索表格-小萌"
    },
    "table": {
      "title": "$示例表格"
    },
    "trivial": {
      "title": "示例页面"
    }
  }
}

这里会根据, ui 配置 firstLanguage & secondLanguage, 符合规则:

  1. 页面自带 title Meta 信息会输出到默认语言配置中
  2. 未配置,默认采用路径为值
  3. i18key 如果未配置默认使用路径名
  4. i18key 会自动格式化: pages. 开头, .title 结尾; 这个和框架 i18n 机制一致; 参考 ui 里配置 pagePrefix & pageSuffix
  5. i18n 配置符合整体框架原则:默认未改动一 $前缀, 修改完后去掉 $,后续不会再覆盖。

如例子中: example.form.title 后续页面中 meta.title 跟新,不再同步到这个 pages.json 配置内,应该没有 $ 前缀; 而 example.table.title 将根据 这个页面内 meta.title 自动更新。

这种工作机制主要帮助第一次构建页面 i18n 配置, 同时提醒开发人员改变默认配置($将展示在前台)。

​Authority

参考Hope 框架极简 Authentication & Authorization设计。

配合前端便捷利用现在Hope框架 Authentication & Authorization,工具栈对 Authority 处理如下:

Authority 定义 Enum 将被处理,生成到如下几个目录:

  1. src/service/model/{authority}.ts authority enum 对象定义

  2. src/types/auth.d.ts 全局 enum authority type 定义

    enum WorkAuthorityEnum {

    复制代码
     option (hope.swagger.enm) = { description: "Example Authority Enum for the project, MODIFY IT" };
    
     ROLE_ADD = 200 [(hope.constant.field) = {code: 200,message: "system:role:add", message2: "Authority to add role"}];
     //.... other

    }

enum 定义

复制代码
export const WorkAuthorityEnum = {
	USER_ADD: { title: 'USER_ADD', code: 1, permission: 'user:add', deprecated: false, remark: 'Authority to add user'},
  //......
}

 // eslint-disable-next-line ts/no-redeclare
export type WorkAuthorityEnum =  keyof typeof WorkAuthorityEnum

export type WorkAuthorityEnumValue =  typeof WorkAuthorityEnum[keyof typeof WorkAuthorityEnum]

Enum 包含属性:

Property Comment
title 标题: USER_ADD
code 代码: 1
permission 权限: user:add 一般: 代表层级关系
deprecated 失效否?
remark 描述:Authority to add user

d.ts 定义

  1. Api.Authority.Map Authority 定义 (map)

  2. Api.Authority.Type Authority 类型

  3. Api.Authority.TypeList Authority 类型列表

  4. Api.Authority.Item Authority 体

  5. Api.Authority.AuthorityItem Authority Tree 结构定义

  6. Api.Authority.AuthorityTree Authority Tree

    declare namespace Api {
    namespace Authority {

    复制代码
     export const Map: {
     		USER_ADD: { title: 'USER_ADD', code: 1, permission: 'user:add', deprecated: false, remark: 'Authority to remove user(Remove or modify this template sample)'}
         //...  

    }

    复制代码
     export type Type = keyof typeof Map
     export type TypeList = Type[]
    
     /**
      * Authority item type, contains the following properties:
      * - title: Authority title, USER_ADD
      * - code: Authority code, 1024
      * - permission: Permission, user:add
      * - deprecated: Whether it's deprecated, false
      * - remark: Additional notes, permission to add user account
      */
     export type Item = typeof Map[Type]
    
     interface AuthorityItem {
       code: number
       name: string
       expression: string
       deprecated: boolean
       type?: 'LEAF' | 'ROOT' | 'BRANCH'
       description?: string
       level?: number
       children?: AuthorityItem[]
     }
    
     
     export const AuthorityTree: AuthorityItem[] = [{
         "code" : 0,
         "name" : "system",
         "expression" : "system",
         "deprecated" : false,
         "type" : "ROOT",
         "children" : [ {
           "code" : 0,
           "name" : "system:role",
           "expression" : "system:role",
           "deprecated" : false,
           "type" : "BRANCH",
           "children" : [ {
             "code" : 10240200,
             "name" : "ROLE_ADD",
             "expression" : "system:role:add",
             "description" : "Authority to add role",
             "deprecated" : false,
             "type" : "LEAF",
             "level" : 2
           }],
           "level" : 1
         } ],
         "level" : 0
       }]

    }
    }

​Layout

TBD

​Style

  1. Theme
  2. Color
  3. Tailwindcss

​Catalog

统一三方依赖版本配置和管理,采用 catalog 方式统一配置, pnpm-workspace.yaml:

复制代码
packages:
  - 'packages/*'

catalog:
  # UI 框架相关
  'vue': '^3.5.13'
  'vue-router': '^4.5.0'
  'vue-i18n': '^11.1.2'

项目中包依赖:

复制代码
 {
   "dependencies": {
    "vee-validate": "catalog:",
    "axios": "catalog:"
   }
 }

​packages

​antd

​util

​hook

​Plugin

  1. Auto-import unplugin-auto-import/vite
  2. Auto-component unplugin-vue-components/vite
  3. Icon unplugin-icons/vite

​Trivial

  1. lint
  2. prettier
  3. vscode
  4. format/antfu

​Tip

  1. 生成文件可以在文件备注 // hope-no-merger 禁止生成覆盖,⚠️无法升级更新
相关推荐
-曾牛3 小时前
探索 Spring AI 的 ChatClient API:构建智能对话应用的利器
java·人工智能·spring boot·后端·spring·springai·ai指南
白露与泡影3 小时前
使用OAuth2保护Spring AI MCP服务!
java·后端·spring
magic 2453 小时前
Spring 命名空间注入:p、c 与 .util 的深度解析
java·前端·spring
钢铁男儿3 小时前
Python基本语法(函数partial)
前端·javascript·python
风清云淡_A3 小时前
【angular19】入门基础教程(三):关于angular里面的响应式数据入门使用
前端·angular.js
橘猫云计算机设计4 小时前
基于springboot的金院银行厅预约系统的设计及实现(源码+lw+部署文档+讲解),源码可白嫖!
java·数据库·spring boot·后端·爬虫·spring·毕业设计
green_pine_4 小时前
Vue3学习笔记2——路由守卫
前端·vue.js·笔记·学习
空中湖4 小时前
纯前端专业PDF在线浏览器查看器工具
前端·pdf
Aurora_NeAr4 小时前
Spring IoC容器的设计与实现
java·后端·spring
七灵微4 小时前
ES6入门---第二单元 模块二:关于数组新增
前端·javascript·es6