commit 1e510efe8edf6f6e196ff97a0245ca69ac1eeac3 Author: rjl <98n9@163.com> Date: Fri Jan 16 13:06:44 2026 +0800 chore: init read-star monorepo diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0552777 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +# Editor configuration, see http://editorconfig.org + +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9553ccb --- /dev/null +++ b/.gitattributes @@ -0,0 +1,13 @@ +"*.vue" eol=lf +"*.js" eol=lf +"*.ts" eol=lf +"*.jsx" eol=lf +"*.tsx" eol=lf +"*.mjs" eol=lf +"*.json" eol=lf +"*.html" eol=lf +"*.css" eol=lf +"*.scss" eol=lf +"*.md" eol=lf +"*.yaml" eol=lf +"*.yml" eol=lf diff --git a/.github/ISSUE_TEMPLATE/bug-report_cn.yaml b/.github/ISSUE_TEMPLATE/bug-report_cn.yaml new file mode 100644 index 0000000..bdd67a6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report_cn.yaml @@ -0,0 +1,90 @@ +name: 🐞 Bug提交 +description: 在使用软件或功能的过程中遇到了错误 +title: '[Bug]: ' +labels: [bug?] + +body: + - type: markdown + attributes: + value: | + ## 请按照以下要求进行提交 + ### 1. 提交后需要指定标签和截止时间。 + --- + + - type: markdown + attributes: + value: | + ## 环境信息 + 请根据实际使用环境修改以下信息。 + + - type: input + id: env-program-ver + attributes: + label: 软件版本 + validations: + required: true + + - type: dropdown + id: env-vm-ver + attributes: + label: 运行环境 + description: 选择运行软件的系统版本 + options: + - Windows (64) + - Windows (32/x84) + - MacOS + - Linux + - Ubuntu + - CentOS + - ArchLinux + - UNIX (Android) + - 其它(请在下方说明) + validations: + required: true + + - type: dropdown + id: env-vm-arch + attributes: + label: 运行架构 + description: (可选) 选择运行软件的系统架构 + options: + - AMD64 + - x86 + - ARM [32] (别名:AArch32 / ARMv7) + - ARM [64] (别名:AArch64 / ARMv8) + - 其它 + + - type: textarea + id: reproduce-steps + attributes: + label: 重现步骤 + description: | + 我们需要执行哪些操作才能让 bug 出现? + 简洁清晰的重现步骤能够帮助我们更迅速地定位问题所在。 + validations: + required: true + + - type: textarea + id: expected + attributes: + label: 期望的结果是什么? + validations: + required: true + + - type: textarea + id: actual + attributes: + label: 实际的结果是什么? + validations: + required: true + + - type: textarea + id: logging + attributes: + label: 日志记录(可选) + render: golang + + - type: textarea + id: extra-desc + attributes: + label: 补充说明(可选) diff --git a/.github/ISSUE_TEMPLATE/bug-report_en.yaml b/.github/ISSUE_TEMPLATE/bug-report_en.yaml new file mode 100644 index 0000000..2a53ba8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report_en.yaml @@ -0,0 +1,90 @@ +name: 🐞 Bug Report +description: Encountered an error while using the software or feature +title: '[Bug]: ' +labels: [bug?] + +body: + - type: markdown + attributes: + value: | + ## Please submit according to the following requirements + ### 1. After submission, you need to specify the label and deadline. + --- + + - type: markdown + attributes: + value: | + ## Environment Information + Please modify the following information according to the actual usage environment. + + - type: input + id: env-program-ver + attributes: + label: Software Version + validations: + required: true + + - type: dropdown + id: env-vm-ver + attributes: + label: Operating Environment + description: Select the system version on which the software is running + options: + - Windows (64) + - Windows (32/x84) + - MacOS + - Linux + - Ubuntu + - CentOS + - ArchLinux + - UNIX (Android) + - Other (please specify below) + validations: + required: true + + - type: dropdown + id: env-vm-arch + attributes: + label: Operating Architecture + description: (Optional) Select the system architecture on which the software is running + options: + - AMD64 + - x86 + - ARM [32] (Alias:AArch32 / ARMv7) + - ARM [64] (Alias:AArch64 / ARMv8) + - Other + + - type: textarea + id: reproduce-steps + attributes: + label: Reproduce Steps + description: | + What operations do we need to perform to make the bug appear? + The concise and clear reproduction steps can help us locate the problem more quickly. + validations: + required: true + + - type: textarea + id: expected + attributes: + label: What is the expected result? + validations: + required: true + + - type: textarea + id: actual + attributes: + label: What is the actual result? + validations: + required: true + + - type: textarea + id: logging + attributes: + label: Logging (Optional) + render: golang + + - type: textarea + id: extra-desc + attributes: + label: Additional Description (Optional) diff --git a/.github/ISSUE_TEMPLATE/feature_request_cn.yaml b/.github/ISSUE_TEMPLATE/feature_request_cn.yaml new file mode 100644 index 0000000..fd6a17a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request_cn.yaml @@ -0,0 +1,48 @@ +--- +name: 🚀 功能请求 +description: 提出一个想法以帮助我们改进W&B +title: '[功能]: ' +labels: + - 功能请求 + +body: + - type: markdown + attributes: + value: | + **感谢 :heart: 您花时间填写此功能请求报告!** + 我们恳请您搜索看看您的功能是否[已经存在](https://github.com/reader-star/reader-star-admin/issues?q=is%3Aissue+sort%3Acreated-desc+)。 + + 我们也很乐意接受用户的贡献。有关更多详细信息,请参阅[此处](https://github.com/reader-star/reader-star-admin/blob/main/README.zh_CN.md#%E5%A6%82%E4%BD%95%E8%B4%A1%E7%8C%AE)。 + + - type: textarea + attributes: + label: 描述 + description: | + 对您感兴趣的功能的清晰简洁的描述。 + validations: + required: true + + - type: textarea + attributes: + label: 建议的解决方案 + description: | + 描述您想要的解决方案。对您希望发生的事情的清晰简洁的描述。 + validations: + required: true + + - type: textarea + attributes: + label: 替代方案 + description: | + 描述您考虑过的替代方案。 + 对您考虑过的任何替代解决方案或功能的清晰简洁的描述。 + validations: + required: false + + - type: textarea + attributes: + label: 额外的上下文 + description: | + 在此处添加有关问题的其他上下文。 + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE/feature_request_en.yaml b/.github/ISSUE_TEMPLATE/feature_request_en.yaml new file mode 100644 index 0000000..5bd61f8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request_en.yaml @@ -0,0 +1,48 @@ +--- +name: 🚀 Feature Request +description: Suggest an idea to help us improve W&B +title: '[Feature]: ' +labels: + - feature_request + +body: + - type: markdown + attributes: + value: | + **Thanks :heart: for taking the time to fill out this feature request report!** + We kindly ask that you search to see if an issue [already exists](https://github.com/reader-star/reader-star-admin/issues?q=is%3Aissue+sort%3Acreated-desc+) for your feature. + + We are also happy to accept contributions from our users. For more details see [here](https://github.com/reader-star/reader-star-admin/blob/main/README.md#how-to-contribute). + + - type: textarea + attributes: + label: Description + description: | + A clear and concise description of the feature you're interested in. + validations: + required: true + + - type: textarea + attributes: + label: Suggested Solution + description: | + Describe the solution you'd like. A clear and concise description of what you want to happen. + validations: + required: true + + - type: textarea + attributes: + label: Alternatives + description: | + Describe alternatives you've considered. + A clear and concise description of any alternative solutions or features you've considered. + validations: + required: false + + - type: textarea + attributes: + label: Additional Context + description: | + Add any other context about the problem here. + validations: + required: false diff --git a/.github/PULL_REQUEST_TEMPLATE/pr_cn.md b/.github/PULL_REQUEST_TEMPLATE/pr_cn.md new file mode 100644 index 0000000..d3b86ad --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/pr_cn.md @@ -0,0 +1,50 @@ +首先,感谢你的贡献! 😄 + +新特性请提交至 feature 分支,其余可提交至 main 分支。在一个维护者审核通过后合并。请确保填写以下 pull request 的信息,谢谢!~ + +[[English Template / 英文模板](./pr_en.md)] + +### 这个变动的性质是 + +- [ ] 新特性提交 +- [ ] 日常 bug 修复 +- [ ] 站点、文档改进 +- [ ] 组件样式改进 +- [ ] TypeScript 定义更新 +- [ ] 重构 +- [ ] 代码风格优化 +- [ ] 分支合并 +- [ ] 其他改动(是关于什么的改动?) + +### 需求背景 + +> 1. 描述相关需求的来源。 +> 2. 要解决的问题。 +> 3. 相关的 issue 讨论链接。 + +### 实现方案和 API(非新功能可选) + +> 1. 基本的解决思路和其他可选方案。 +> 2. 列出最终的 API 实现和用法。 +> 3. 涉及 UI/交互变动需要有截图或 GIF。 + +### 对用户的影响和可能的风险(非新功能可选) + +> 1. 这个改动对用户端是否有影响?影响的方面有哪些? +> 2. 是否有可能隐含的 break change 和其他风险? + +### Changelog 描述(非新功能可选) + +> 1. 英文描述 +> 2. 中文描述(可选) + +### 请求合并前的自查清单 + +- [ ] 文档已补充或无须补充 +- [ ] 代码演示已提供或无须提供 +- [ ] TypeScript 定义已补充或无须补充 +- [ ] Changelog 已提供或无须提供 + +### 后续计划(非新功能可选) + +> 如果这个提交后面还有相关的其他提交和跟进信息,可以写在这里。 diff --git a/.github/PULL_REQUEST_TEMPLATE/pr_en.md b/.github/PULL_REQUEST_TEMPLATE/pr_en.md new file mode 100644 index 0000000..06560ca --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/pr_en.md @@ -0,0 +1,51 @@ +First of all, thank you for your contribution! 😄 + +New feature please send pull request to feature branch, and rest to main branch. Pull request will be merged after one of collaborators approve. Please makes sure that these form are filled before submitting your pull request, thank you! + +[[中文版模板 / Chinese template](./pr_cn.md)] + +### This is a ... + +- [ ] New feature +- [ ] Bug fix +- [ ] Site / document update +- [ ] Component style update +- [ ] TypeScript definition update +- [ ] Refactoring +- [ ] Code style optimization +- [ ] Branch merge +- [ ] Other (about what?) + +### What's the background? + +> 1. Describe the source of requirement. +> 2. Resolve what problem. +> 3. Related issue link. + +### API Realization (Optional if not new feature) + +> 1. Basic thought of solution and other optional proposal. +> 2. List final API realization and usage sample. +> 3. GIF or snapshot should be provided if includes UI/interactive modification. + +### What's the effect? (Optional if not new feature) + +> 1. Does this PR affect user? Which part will be affected? +> 2. What will say in changelog? +> 3. Does this PR contains potential break change or other risk? + +### Changelog description (Optional if not new feature) + +> 1. English description +> 2. Chinese description (optional) + +### Self Check before Merge + +- [ ] Doc is updated/provided or not needed +- [ ] Demo is updated/provided or not needed +- [ ] TypeScript definition is updated/provided or not needed +- [ ] Changelog is provided or not needed + +### Additional Plan? (Optional if not new feature) + +> If this PR related with other PR or following info. You can type here. diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..450ec86 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,30 @@ +--- +name: Lint Code + +permissions: + contents: write + +on: + pull_request: + branches: [main] + +jobs: + lint: + name: Lint All Code + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Lint Code Base + uses: github/super-linter@v4 + env: + VALIDATE_ALL_CODEBASE: false + DEFAULT_BRANCH: main + # To change branch master or main + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + FILTER_REGEX_EXCLUDE: (docs|.github) + VALIDATE_MARKDOWN: false diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c93de2d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,25 @@ +name: Release + +permissions: + contents: write + +on: + push: + tags: + - 'v*' + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/setup-node@v3 + with: + node-version: 18.x + + - run: npx githublogen + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..99ff568 --- /dev/null +++ b/.gitignore @@ -0,0 +1,53 @@ +# --- 依赖与构建输出 --- +node_modules +dist +dist-ssr +*.local +# 忽略所有子应用的构建输出 +apps/*/dist +packages/*/dist + +# --- 日志文件 --- +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +# --- 系统与编辑器 --- +.DS_Store +.vscode/* +!.vscode/extensions.json +!.vscode/settings.json +!.vscode/launch.json +.idea +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? + +# --- 测试与覆盖率 --- +coverage +/cypress/videos/ +/cypress/screenshots/ +.VSCodeCounter + +# --- Lock 文件 --- +# 在 pnpm 工作区中,只需保留根目录的 pnpm-lock.yaml +# 如果有残留的 lock 文件建议忽略或删除 +package-lock.json +yarn.lock + +# --- 环境变量 --- +# 保护敏感信息,只允许提交 .env.example +.env +.env.production +.env.test +!.env.example + +# --- 特色插件生成文件 --- +# 如果你希望路由自动生成文件不进入版本管理(可选) +# apps/*/src/typings/elegant-router.d.ts diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..dfc2d68 --- /dev/null +++ b/.npmrc @@ -0,0 +1,4 @@ +registry=https://registry.npmmirror.com/ +shamefully-hoist=true +ignore-workspace-root-check=true +link-workspace-packages=true diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..83a3146 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,19 @@ +{ + "recommendations": [ + "afzalsayed96.icones", + "antfu.iconify", + "antfu.unocss", + "dbaeumer.vscode-eslint", + "editorconfig.editorconfig", + "lokalise.i18n-ally", + "mhutchie.git-graph", + "mikestead.dotenv", + "naumovs.color-highlight", + "pkief.material-icon-theme", + "sdras.vue-vscode-snippets", + "vue.volar", + "whtouche.vscode-js-console-utils", + "zhuangtongfa.material-theme", + "tu6ge.naive-ui-intelligence" + ] +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..e59c32b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,22 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "chrome", + "request": "launch", + "name": "Vue Debugger", + "url": "http://localhost:9527", + "webRoot": "${workspaceFolder}" + }, + { + "type": "node", + "request": "launch", + "name": "TS Debugger", + "runtimeExecutable": "tsx", + "skipFiles": ["/**", "${workspaceFolder}/node_modules/**"], + "program": "${file}", + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..47e2ceb --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,39 @@ +{ + // 1. 禁用原生格式化,避免冲突 + "editor.formatOnSave": false, + + // 2. 核心配置:保存时触发 ESLint 修复动作 + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "explicit", + "source.organizeImports": "never" + }, + + // 3. 必须:强制所有相关文件使用 ESLint 插件作为格式化器 + "[vue]": { + "editor.defaultFormatter": "dbaeumer.vscode-eslint" + }, + "[typescript]": { + "editor.defaultFormatter": "dbaeumer.vscode-eslint" + }, + "[javascript]": { + "editor.defaultFormatter": "dbaeumer.vscode-eslint" + }, + + // 4. 必须:显式声明需要校验的文件类型 + "eslint.validate": [ + "javascript", + "typescript", + "vue", + "html", + "json", + "jsonc" + ], + + // 5. 必须:指定工作区目录(让 Windsurf 知道去哪里加载每个包的配置) + "eslint.workingDirectories": [ + { "mode": "auto" }, + "./apps/admin", + "./apps/user", + "./packages/eslint-config" + ] +} diff --git a/.vscode/vue3.code-snippets b/.vscode/vue3.code-snippets new file mode 100644 index 0000000..0014fc3 --- /dev/null +++ b/.vscode/vue3.code-snippets @@ -0,0 +1,51 @@ +{ + "Print soy Vue3 SFC page": { + "scope": "vue", + "prefix": ["v3","page","view"], + "body": [ + "\n", + "\n", + ], + }, + + "Print soy Vue3 SFC Component": { + "scope": "vue", + "prefix": ["component","comp"], + "body": [ + "\n", + "\n", + ], + }, + "Print soy style": { + "scope": "vue", + "prefix": "st", + "body": ["\n"], + }, + "Print soy script": { + "scope": "vue", + "prefix": "sc", + "body": ["\n"], + }, + "Print soy template": { + "scope": "vue", + "prefix": "te", + "body": [ + "\n", + ], + }, +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..4c1701e --- /dev/null +++ b/README.md @@ -0,0 +1,156 @@ +## 简介 + +一个清新优雅、高颜值且功能强大的后台管理模板,基于最新的前端技术栈,包括 Vue3, Vite7, TypeScript, Pinia 和 UnoCSS。它内置了丰富的主题配置和组件,代码规范严谨,实现了自动化的文件路由系统. + +## 特性 + +- **前沿技术应用**:采用 Vue3, Vite7, TypeScript, Pinia 和 UnoCSS 等最新流行的技术栈。 +- **清晰的项目架构**:采用 pnpm monorepo 架构,结构清晰,优雅易懂。 +- **严格的代码规范**:遵循 prettier 和 simple-git-hooks,保证代码的规范性。 +- **TypeScript**: 支持严格的类型检查,提高代码的可维护性。 +- **丰富的主题配置**:内置多样的主题配置,与 UnoCSS 完美结合。 +- **内置国际化方案**:轻松实现多语言支持。 +- **自动化文件路由系统**:自动生成路由导入、声明和类型。更多细节请查看 [Elegant Router](https://github.com/reader-star/elegant-router)。 +- **灵活的权限路由**:同时支持前端静态路由和后端动态路由。 +- **丰富的页面组件**:内置多样页面和组件,包括403、404、500页面,以及布局组件、标签组件、主题配置组件等。 +- **命令行工具**:内置高效的命令行工具,git提交、删除文件、发布等。 +- **移动端适配**:完美支持移动端,实现自适应布局。 + +## 使用 + +**环境准备** + +确保你的环境满足以下要求: + +- **git**: 你需要git来克隆和管理项目版本。 +- **NodeJS**: >=20.19.0,推荐 20.19.0 或更高。 +- **pnpm**: >= 10.5.0,推荐 10.5.0 或更高。 + +**克隆项目** + +```bash +# github +git clone http://8.137.159.94:3000/ranjl/reader-star.git +``` + +**安装依赖** + +```bash +pnpm i +``` + +> 由于本项目采用了 pnpm monorepo 的管理方式,因此请不要使用 npm 或 yarn 来安装依赖。 + +**启动项目** + +```bash +pnpm dev +``` + +**构建项目** + +```bash +pnpm build +``` + +## Git 提交规范 + +本项目已内置 `commit` 命令,您可以通过执行 `pnpm commit` 来生成符合 [Conventional Commits](<[conventionalcommits](https://www.conventionalcommits.org/)>) 规范的提交信息。在提交PR时,请务必使用 `commit` 命令来创建提交信息,以确保信息的规范性。 + +## 项目层级 + +- `apps/admin`: 后台管理 +- `apps/user`: 用户端 +- `packages/eslint-config`: eslint 配置 +- `packages/shared`: 公共组件 + +## 目录说明 + +``` +read-star +├── .vscode // VSCode/Windsurf 项目级配置 +│ ├── extensions.json // 推荐安装的插件 +│ ├── launch.json // 调试配置文件 (Debug Vue/TS) +│ ├── settings.json // 项目专属设置 (ESLint 校验、格式化规则) +│ └── vue3.code-snippets // Vue3 代码片段 +├── apps // 业务应用目录 +│ ├── admin // 管理端应用 (原 soybean-admin 业务主体) +│ │ ├── build // Vite 构建相关配置和插件 +│ │ ├── src // 源代码 +│ │ │ ├── assets // 静态资源 (图片、svg图标) +│ │ │ ├── components // 全局组件 +│ │ │ ├── constants // 常量 (正则、业务常量) +│ │ │ ├── hooks // 组合式函数 hooks +│ │ │ ├── layouts // 布局组件 +│ │ │ ├── locales // 国际化配置 +│ │ │ ├── router // 路由配置 (含 elegant-router 生成文件) +│ │ │ ├── service // 网络请求接口 +│ │ │ ├── store // Pinia 状态管理 +│ │ │ ├── theme // 主题配置 +│ │ │ ├── typings // TS 类型声明 (*.d.ts) +│ │ │ ├── views // 页面视图 +│ │ │ ├── App.vue // 根组件 +│ │ │ └── main.ts // 入口文件 +│ │ ├── .env // 环境配置 +│ │ ├── index.html // 入口 HTML +│ │ ├── package.json // 应用依赖描述 +│ │ └── vite.config.ts // Vite 配置文件 +│ └── user // 用户端应用 (镜像拆分后的第二个端) +│ └── ... // 结构与 admin 一致 +├── packages // 公共共享包 (内部依赖库) +│ ├── alova // Alova 请求封装 +│ ├── axios // Axios 请求封装 +│ ├── color // 颜色处理工具 +│ ├── eslint-config // 自定义本地 ESLint 规范包 (私有化配置) +│ ├── hooks // 跨应用复用的组合式 hooks +│ ├── materials // 组件物料库 +│ ├── shared // 共享类型声明、常量和通用函数 +│ ├── uno-preset // UnoCSS 预设配置 +│ └── utils // 全局通用的纯工具函数 +├── .editorconfig // 统一编辑器编码规范 +├── .gitattributes // Git 属性配置 +├── .gitignore // Git 忽略文件配置 +├── .npmrc // npm/pnpm 运行参数配置 +├── eslint.config.js // 根目录 ESLint 平铺配置文件 (引用自 packages) +├── package.json // Monorepo 根依赖及脚本管理 +├── pnpm-lock.yaml // pnpm 依赖锁定文件 +├── pnpm-workspace.yaml // pnpm 工作区定义文件 +├── README.md // 项目英文介绍 +├── tsconfig.base.json // TS 基础共享配置 +├── tsconfig.json // TS 引用管理配置 (Project References) +├── uno.config.ts // 原子 CSS 框架 UnoCSS 全局配置 +└── vite.config.ts // (可选) 根目录 Vite 公共配置 +``` + +## 命令行工具 + +```bash +{ + // 构建打包(prod环境) + "build": "vite build --mode prod", + // 构建打包(test环境) + "build:test": "vite build --mode test", + // 删除主项目及子项目的 node_modules, dist, pnpm-lock.yaml + "cleanup": "sa cleanup", + // 提交代码 (生成符合 Conventional Commits standard 的提交信息) + "commit": "sa git-commit", + // 本地运行(test环境) + "dev": "vite --mode test", + // 本地运行(prod环境) + "dev:prod": "vite --mode prod", + // 生成路由 + "gen-route": "sa gen-route", + // eslint检查并自动修复 + "lint": "eslint . --fix", + // 初始化 simple-git-hooks + "prepare": "simple-git-hooks", + // 本地环境预览构建后的dist + "preview": "vite preview", + // 发布 + "release": "sa release", + // vue文件的ts检查 + "typecheck": "vue-tsc --noEmit --skipLibCheck", + // 更新依赖包 + "update-pkg": "sa update-pkg" +} +``` diff --git a/apps/admin/.env.prod b/apps/admin/.env.prod new file mode 100644 index 0000000..f567764 --- /dev/null +++ b/apps/admin/.env.prod @@ -0,0 +1,7 @@ +# backend service base url, prod environment +VITE_SERVICE_BASE_URL=https://mock.apifox.cn/m1/3109515-0-default + +# other backend service base url, prod environment +VITE_OTHER_SERVICE_BASE_URL= `{ + "demo": "http://localhost:9529" +}` diff --git a/apps/admin/build/config/index.ts b/apps/admin/build/config/index.ts new file mode 100644 index 0000000..7b3964b --- /dev/null +++ b/apps/admin/build/config/index.ts @@ -0,0 +1,2 @@ +export * from './proxy' +export * from './time' diff --git a/apps/admin/build/config/proxy.ts b/apps/admin/build/config/proxy.ts new file mode 100644 index 0000000..4e83860 --- /dev/null +++ b/apps/admin/build/config/proxy.ts @@ -0,0 +1,58 @@ +import type { ProxyOptions } from 'vite' +import { consola } from 'consola' +import { bgRed, bgYellow, green, lightBlue } from 'kolorist' +import { createServiceConfig } from '../../src/utils/service' + +/** + * Set http proxy + * + * @param env - The current env + * @param enable - If enable http proxy + */ +export function createViteProxy(env: Env.ImportMeta, enable: boolean) { + const isEnableHttpProxy = enable && env.VITE_HTTP_PROXY === 'Y' + + if (!isEnableHttpProxy) + return undefined + + const isEnableProxyLog = env.VITE_PROXY_LOG === 'Y' + + const { baseURL, proxyPattern, other } = createServiceConfig(env) + + const proxy: Record = createProxyItem({ baseURL, proxyPattern }, isEnableProxyLog) + + other.forEach((item) => { + Object.assign(proxy, createProxyItem(item, isEnableProxyLog)) + }) + + return proxy +} + +function createProxyItem(item: App.Service.ServiceConfigItem, enableLog: boolean) { + const proxy: Record = {} + + proxy[item.proxyPattern] = { + target: item.baseURL, + changeOrigin: true, + configure: (_proxy, options) => { + _proxy.on('proxyReq', (_proxyReq, req, _res) => { + if (!enableLog) + return + + const requestUrl = `${lightBlue('[proxy url]')}: ${bgYellow(` ${req.method} `)} ${green(`${item.proxyPattern}${req.url}`)}` + + const proxyUrl = `${lightBlue('[real request url]')}: ${green(`${options.target}${req.url}`)}` + + consola.log(`${requestUrl}\n${proxyUrl}`) + }) + _proxy.on('error', (_err, req, _res) => { + if (!enableLog) + return + consola.log(bgRed(`Error: ${req.method} `), green(`${options.target}${req.url}`)) + }) + }, + rewrite: path => path.replace(new RegExp(`^${item.proxyPattern}`), ''), + } + + return proxy +} diff --git a/apps/admin/build/config/time.ts b/apps/admin/build/config/time.ts new file mode 100644 index 0000000..cbdefdb --- /dev/null +++ b/apps/admin/build/config/time.ts @@ -0,0 +1,12 @@ +import dayjs from 'dayjs' +import timezone from 'dayjs/plugin/timezone' +import utc from 'dayjs/plugin/utc' + +export function getBuildTime() { + dayjs.extend(utc) + dayjs.extend(timezone) + + const buildTime = dayjs.tz(Date.now(), 'Asia/Shanghai').format('YYYY-MM-DD HH:mm:ss') + + return buildTime +} diff --git a/apps/admin/build/plugins/devtools.ts b/apps/admin/build/plugins/devtools.ts new file mode 100644 index 0000000..6687d12 --- /dev/null +++ b/apps/admin/build/plugins/devtools.ts @@ -0,0 +1,9 @@ +import VueDevtools from 'vite-plugin-vue-devtools' + +export function setupDevtoolsPlugin(viteEnv: Env.ImportMeta) { + const { VITE_DEVTOOLS_LAUNCH_EDITOR } = viteEnv + + return VueDevtools({ + launchEditor: VITE_DEVTOOLS_LAUNCH_EDITOR, + }) +} diff --git a/apps/admin/build/plugins/html.ts b/apps/admin/build/plugins/html.ts new file mode 100644 index 0000000..c98b13b --- /dev/null +++ b/apps/admin/build/plugins/html.ts @@ -0,0 +1,13 @@ +import type { Plugin } from 'vite' + +export function setupHtmlPlugin(buildTime: string) { + const plugin: Plugin = { + name: 'html-plugin', + apply: 'build', + transformIndexHtml(html) { + return html.replace('', `\n `) + }, + } + + return plugin +} diff --git a/apps/admin/build/plugins/index.ts b/apps/admin/build/plugins/index.ts new file mode 100644 index 0000000..5f6d7cf --- /dev/null +++ b/apps/admin/build/plugins/index.ts @@ -0,0 +1,24 @@ +import type { PluginOption } from 'vite' +import vue from '@vitejs/plugin-vue' +import vueJsx from '@vitejs/plugin-vue-jsx' +import progress from 'vite-plugin-progress' +import { setupDevtoolsPlugin } from './devtools' +import { setupHtmlPlugin } from './html' +import { setupElegantRouter } from './router' +import { setupUnocss } from './unocss' +import { setupUnplugin } from './unplugin' + +export function setupVitePlugins(viteEnv: Env.ImportMeta, buildTime: string) { + const plugins: PluginOption = [ + vue(), + vueJsx(), + setupDevtoolsPlugin(viteEnv), + setupElegantRouter(), + setupUnocss(viteEnv), + ...setupUnplugin(viteEnv), + progress(), + setupHtmlPlugin(buildTime), + ] + + return plugins +} diff --git a/apps/admin/build/plugins/router.ts b/apps/admin/build/plugins/router.ts new file mode 100644 index 0000000..cceb719 --- /dev/null +++ b/apps/admin/build/plugins/router.ts @@ -0,0 +1,41 @@ +import type { RouteKey } from '@elegant-router/types' +import type { RouteMeta } from 'vue-router' +import ElegantVueRouter from '@elegant-router/vue/vite' + +export function setupElegantRouter() { + return ElegantVueRouter({ + layouts: { + base: 'src/layouts/base-layout/index.vue', + blank: 'src/layouts/blank-layout/index.vue', + }, + routePathTransformer(routeName, routePath) { + const key = routeName as RouteKey + + if (key === 'login') { + const modules: UnionKey.LoginModule[] = ['pwd-login', 'code-login', 'register', 'reset-pwd', 'bind-wechat'] + + const moduleReg = modules.join('|') + + return `/login/:module(${moduleReg})?` + } + + return routePath + }, + onRouteMetaGen(routeName) { + const key = routeName as RouteKey + + const constantRoutes: RouteKey[] = ['login', '403', '404', '500'] + + const meta: Partial = { + title: key, + i18nKey: `route.${key}` as App.I18n.I18nKey, + } + + if (constantRoutes.includes(key)) { + meta.constant = true + } + + return meta + }, + }) +} diff --git a/apps/admin/build/plugins/unocss.ts b/apps/admin/build/plugins/unocss.ts new file mode 100644 index 0000000..da64b69 --- /dev/null +++ b/apps/admin/build/plugins/unocss.ts @@ -0,0 +1,31 @@ +import path from 'node:path' +import process from 'node:process' +import { FileSystemIconLoader } from '@iconify/utils/lib/loader/node-loaders' +import presetIcons from '@unocss/preset-icons' +import unocss from '@unocss/vite' + +export function setupUnocss(viteEnv: Env.ImportMeta) { + const { VITE_ICON_PREFIX, VITE_ICON_LOCAL_PREFIX } = viteEnv + + const localIconPath = path.join(process.cwd(), 'src/assets/svg-icon') + + /** The name of the local icon collection */ + const collectionName = VITE_ICON_LOCAL_PREFIX.replace(`${VITE_ICON_PREFIX}-`, '') + + return unocss({ + presets: [ + presetIcons({ + prefix: `${VITE_ICON_PREFIX}-`, + scale: 1, + extraProperties: { + display: 'inline-block', + }, + collections: { + [collectionName]: FileSystemIconLoader(localIconPath, svg => + svg.replace(/^ + svg.replace(/^ + + + + + + + %VITE_APP_TITLE% + + +
+ + + diff --git a/apps/admin/package.json b/apps/admin/package.json new file mode 100644 index 0000000..18b5b05 --- /dev/null +++ b/apps/admin/package.json @@ -0,0 +1,85 @@ +{ + "name": "@reader-star/admin", + "type": "module", + "version": "1.0.0", + "homepage": "http://8.137.159.94:3000/ranjl/reader-star.git", + "engines": { + "node": ">=20.19.0", + "pnpm": ">=10.5.0" + }, + "scripts": { + "build": "vite build --mode prod", + "build:test": "vite build --mode test", + "cleanup": "sa cleanup", + "commit": "sa git-commit", + "commit:zh": "sa git-commit -l=zh-cn", + "dev": "vite --mode test", + "dev:prod": "vite --mode prod", + "gen-route": "sa gen-route", + "lint": "eslint . --fix", + "prepare": "simple-git-hooks", + "preview": "vite preview", + "release": "sa release", + "typecheck": "vue-tsc --noEmit --skipLibCheck", + "update-pkg": "sa update-pkg" + }, + "dependencies": { + "@better-scroll/core": "2.5.1", + "@iconify/vue": "5.0.0", + "@sa/axios": "workspace:*", + "@sa/color": "workspace:*", + "@sa/hooks": "workspace:*", + "@sa/materials": "workspace:*", + "@sa/utils": "workspace:*", + "@vueuse/core": "14.1.0", + "clipboard": "2.0.11", + "dayjs": "1.11.19", + "defu": "6.1.4", + "echarts": "6.0.0", + "json5": "2.2.3", + "naive-ui": "2.43.2", + "nprogress": "0.2.0", + "pinia": "3.0.4", + "tailwind-merge": "3.4.0", + "vue": "3.5.26", + "vue-draggable-plus": "0.6.0", + "vue-i18n": "11.2.7", + "vue-router": "4.6.4" + }, + "devDependencies": { + "@elegant-router/vue": "0.3.8", + "@iconify/json": "2.2.417", + "@sa/scripts": "workspace:*", + "@sa/uno-preset": "workspace:*", + "@types/node": "25.0.3", + "@types/nprogress": "0.2.3", + "@unocss/eslint-config": "66.5.10", + "@unocss/preset-icons": "66.5.10", + "@unocss/preset-uno": "66.5.10", + "@unocss/transformer-directives": "66.5.10", + "@unocss/transformer-variant-group": "66.5.10", + "@unocss/vite": "66.5.10", + "@vitejs/plugin-vue": "6.0.3", + "@vitejs/plugin-vue-jsx": "5.1.3", + "consola": "3.4.2", + "eslint": "9.39.2", + "eslint-plugin-vue": "10.6.2", + "kolorist": "1.8.0", + "sass": "1.97.1", + "simple-git-hooks": "2.13.1", + "tsx": "4.21.0", + "typescript": "5.9.3", + "unplugin-icons": "22.5.0", + "unplugin-vue-components": "30.0.0", + "vite": "7.3.0", + "vite-plugin-progress": "0.0.7", + "vite-plugin-svg-icons": "2.0.1", + "vite-plugin-vue-devtools": "8.0.5", + "vue-eslint-parser": "10.2.0", + "vue-tsc": "3.2.1" + }, + "simple-git-hooks": { + "commit-msg": "pnpm sa git-commit-verify", + "pre-commit": "pnpm typecheck && pnpm lint && git diff --exit-code" + } +} diff --git a/apps/admin/public/favicon.svg b/apps/admin/public/favicon.svg new file mode 100644 index 0000000..dfaa6c8 --- /dev/null +++ b/apps/admin/public/favicon.svg @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/apps/admin/src/App.vue b/apps/admin/src/App.vue new file mode 100644 index 0000000..089e43b --- /dev/null +++ b/apps/admin/src/App.vue @@ -0,0 +1,58 @@ + + + + + diff --git a/apps/admin/src/assets/imgs/reader-star.jpg b/apps/admin/src/assets/imgs/reader-star.jpg new file mode 100644 index 0000000..75457d5 Binary files /dev/null and b/apps/admin/src/assets/imgs/reader-star.jpg differ diff --git a/apps/admin/src/assets/svg-icon/activity.svg b/apps/admin/src/assets/svg-icon/activity.svg new file mode 100644 index 0000000..abe892f --- /dev/null +++ b/apps/admin/src/assets/svg-icon/activity.svg @@ -0,0 +1 @@ + diff --git a/apps/admin/src/assets/svg-icon/at-sign.svg b/apps/admin/src/assets/svg-icon/at-sign.svg new file mode 100644 index 0000000..625214d --- /dev/null +++ b/apps/admin/src/assets/svg-icon/at-sign.svg @@ -0,0 +1 @@ + diff --git a/apps/admin/src/assets/svg-icon/avatar.svg b/apps/admin/src/assets/svg-icon/avatar.svg new file mode 100644 index 0000000..66fe6f2 --- /dev/null +++ b/apps/admin/src/assets/svg-icon/avatar.svg @@ -0,0 +1 @@ + diff --git a/apps/admin/src/assets/svg-icon/banner.svg b/apps/admin/src/assets/svg-icon/banner.svg new file mode 100644 index 0000000..192b637 --- /dev/null +++ b/apps/admin/src/assets/svg-icon/banner.svg @@ -0,0 +1 @@ + diff --git a/apps/admin/src/assets/svg-icon/cast.svg b/apps/admin/src/assets/svg-icon/cast.svg new file mode 100644 index 0000000..4f008d3 --- /dev/null +++ b/apps/admin/src/assets/svg-icon/cast.svg @@ -0,0 +1 @@ + diff --git a/apps/admin/src/assets/svg-icon/chrome.svg b/apps/admin/src/assets/svg-icon/chrome.svg new file mode 100644 index 0000000..6314173 --- /dev/null +++ b/apps/admin/src/assets/svg-icon/chrome.svg @@ -0,0 +1 @@ + diff --git a/apps/admin/src/assets/svg-icon/copy.svg b/apps/admin/src/assets/svg-icon/copy.svg new file mode 100644 index 0000000..ab25601 --- /dev/null +++ b/apps/admin/src/assets/svg-icon/copy.svg @@ -0,0 +1 @@ + diff --git a/apps/admin/src/assets/svg-icon/custom-icon.svg b/apps/admin/src/assets/svg-icon/custom-icon.svg new file mode 100644 index 0000000..b33a43f --- /dev/null +++ b/apps/admin/src/assets/svg-icon/custom-icon.svg @@ -0,0 +1 @@ + diff --git a/apps/admin/src/assets/svg-icon/empty-data.svg b/apps/admin/src/assets/svg-icon/empty-data.svg new file mode 100644 index 0000000..293486c --- /dev/null +++ b/apps/admin/src/assets/svg-icon/empty-data.svg @@ -0,0 +1 @@ + diff --git a/apps/admin/src/assets/svg-icon/expectation.svg b/apps/admin/src/assets/svg-icon/expectation.svg new file mode 100644 index 0000000..1d87d5e --- /dev/null +++ b/apps/admin/src/assets/svg-icon/expectation.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/apps/admin/src/assets/svg-icon/heart.svg b/apps/admin/src/assets/svg-icon/heart.svg new file mode 100644 index 0000000..56e59b4 --- /dev/null +++ b/apps/admin/src/assets/svg-icon/heart.svg @@ -0,0 +1 @@ + diff --git a/apps/admin/src/assets/svg-icon/logo.svg b/apps/admin/src/assets/svg-icon/logo.svg new file mode 100644 index 0000000..341675d --- /dev/null +++ b/apps/admin/src/assets/svg-icon/logo.svg @@ -0,0 +1 @@ + diff --git a/apps/admin/src/assets/svg-icon/network-error.svg b/apps/admin/src/assets/svg-icon/network-error.svg new file mode 100644 index 0000000..52f97ab --- /dev/null +++ b/apps/admin/src/assets/svg-icon/network-error.svg @@ -0,0 +1 @@ + diff --git a/apps/admin/src/assets/svg-icon/no-icon.svg b/apps/admin/src/assets/svg-icon/no-icon.svg new file mode 100644 index 0000000..f6dcdd0 --- /dev/null +++ b/apps/admin/src/assets/svg-icon/no-icon.svg @@ -0,0 +1 @@ + diff --git a/apps/admin/src/assets/svg-icon/no-permission.svg b/apps/admin/src/assets/svg-icon/no-permission.svg new file mode 100644 index 0000000..4c408ca --- /dev/null +++ b/apps/admin/src/assets/svg-icon/no-permission.svg @@ -0,0 +1 @@ + diff --git a/apps/admin/src/assets/svg-icon/not-found.svg b/apps/admin/src/assets/svg-icon/not-found.svg new file mode 100644 index 0000000..a513656 --- /dev/null +++ b/apps/admin/src/assets/svg-icon/not-found.svg @@ -0,0 +1 @@ + diff --git a/apps/admin/src/assets/svg-icon/service-error.svg b/apps/admin/src/assets/svg-icon/service-error.svg new file mode 100644 index 0000000..0120f1e --- /dev/null +++ b/apps/admin/src/assets/svg-icon/service-error.svg @@ -0,0 +1 @@ + diff --git a/apps/admin/src/assets/svg-icon/wind.svg b/apps/admin/src/assets/svg-icon/wind.svg new file mode 100644 index 0000000..7c90590 --- /dev/null +++ b/apps/admin/src/assets/svg-icon/wind.svg @@ -0,0 +1 @@ + diff --git a/apps/admin/src/components/advanced/table-column-setting.vue b/apps/admin/src/components/advanced/table-column-setting.vue new file mode 100644 index 0000000..c262375 --- /dev/null +++ b/apps/admin/src/components/advanced/table-column-setting.vue @@ -0,0 +1,45 @@ + + + + + diff --git a/apps/admin/src/components/advanced/table-header-operation.vue b/apps/admin/src/components/advanced/table-header-operation.vue new file mode 100644 index 0000000..4e699fa --- /dev/null +++ b/apps/admin/src/components/advanced/table-header-operation.vue @@ -0,0 +1,74 @@ + + + + + diff --git a/apps/admin/src/components/common/app-provider.vue b/apps/admin/src/components/common/app-provider.vue new file mode 100644 index 0000000..810afe5 --- /dev/null +++ b/apps/admin/src/components/common/app-provider.vue @@ -0,0 +1,39 @@ + + + + + diff --git a/apps/admin/src/components/common/dark-mode-container.vue b/apps/admin/src/components/common/dark-mode-container.vue new file mode 100644 index 0000000..f2fdb0a --- /dev/null +++ b/apps/admin/src/components/common/dark-mode-container.vue @@ -0,0 +1,17 @@ + + + + + diff --git a/apps/admin/src/components/common/exception-base.vue b/apps/admin/src/components/common/exception-base.vue new file mode 100644 index 0000000..e1f7c45 --- /dev/null +++ b/apps/admin/src/components/common/exception-base.vue @@ -0,0 +1,45 @@ + + + + + diff --git a/apps/admin/src/components/common/full-screen.vue b/apps/admin/src/components/common/full-screen.vue new file mode 100644 index 0000000..8380c68 --- /dev/null +++ b/apps/admin/src/components/common/full-screen.vue @@ -0,0 +1,22 @@ + + + + + diff --git a/apps/admin/src/components/common/icon-tooltip.vue b/apps/admin/src/components/common/icon-tooltip.vue new file mode 100644 index 0000000..0dc422b --- /dev/null +++ b/apps/admin/src/components/common/icon-tooltip.vue @@ -0,0 +1,42 @@ + + + diff --git a/apps/admin/src/components/common/lang-switch.vue b/apps/admin/src/components/common/lang-switch.vue new file mode 100644 index 0000000..ae8295d --- /dev/null +++ b/apps/admin/src/components/common/lang-switch.vue @@ -0,0 +1,62 @@ + + + + + diff --git a/apps/admin/src/components/common/menu-toggler.vue b/apps/admin/src/components/common/menu-toggler.vue new file mode 100644 index 0000000..3cc85e2 --- /dev/null +++ b/apps/admin/src/components/common/menu-toggler.vue @@ -0,0 +1,53 @@ + + + + + diff --git a/apps/admin/src/components/common/pin-toggler.vue b/apps/admin/src/components/common/pin-toggler.vue new file mode 100644 index 0000000..c19e8db --- /dev/null +++ b/apps/admin/src/components/common/pin-toggler.vue @@ -0,0 +1,26 @@ + + + + + diff --git a/apps/admin/src/components/common/reload-button.vue b/apps/admin/src/components/common/reload-button.vue new file mode 100644 index 0000000..e1242c6 --- /dev/null +++ b/apps/admin/src/components/common/reload-button.vue @@ -0,0 +1,21 @@ + + + + + diff --git a/apps/admin/src/components/common/system-logo.vue b/apps/admin/src/components/common/system-logo.vue new file mode 100644 index 0000000..7777825 --- /dev/null +++ b/apps/admin/src/components/common/system-logo.vue @@ -0,0 +1,160 @@ + + + diff --git a/apps/admin/src/components/common/theme-schema-switch.vue b/apps/admin/src/components/common/theme-schema-switch.vue new file mode 100644 index 0000000..a928b81 --- /dev/null +++ b/apps/admin/src/components/common/theme-schema-switch.vue @@ -0,0 +1,57 @@ + + + + + diff --git a/apps/admin/src/components/custom/better-scroll.vue b/apps/admin/src/components/custom/better-scroll.vue new file mode 100644 index 0000000..c16f8ad --- /dev/null +++ b/apps/admin/src/components/custom/better-scroll.vue @@ -0,0 +1,54 @@ + + + + + diff --git a/apps/admin/src/components/custom/button-icon.vue b/apps/admin/src/components/custom/button-icon.vue new file mode 100644 index 0000000..c8a6f32 --- /dev/null +++ b/apps/admin/src/components/custom/button-icon.vue @@ -0,0 +1,48 @@ + + + + + diff --git a/apps/admin/src/components/custom/count-to.vue b/apps/admin/src/components/custom/count-to.vue new file mode 100644 index 0000000..3a6ad43 --- /dev/null +++ b/apps/admin/src/components/custom/count-to.vue @@ -0,0 +1,88 @@ + + + + + diff --git a/apps/admin/src/components/custom/look-forward.vue b/apps/admin/src/components/custom/look-forward.vue new file mode 100644 index 0000000..7229b73 --- /dev/null +++ b/apps/admin/src/components/custom/look-forward.vue @@ -0,0 +1,22 @@ + + + + + diff --git a/apps/admin/src/components/custom/soybean-avatar.vue b/apps/admin/src/components/custom/soybean-avatar.vue new file mode 100644 index 0000000..dd383e1 --- /dev/null +++ b/apps/admin/src/components/custom/soybean-avatar.vue @@ -0,0 +1,13 @@ + + + + + diff --git a/apps/admin/src/components/custom/svg-icon.vue b/apps/admin/src/components/custom/svg-icon.vue new file mode 100644 index 0000000..a64c508 --- /dev/null +++ b/apps/admin/src/components/custom/svg-icon.vue @@ -0,0 +1,54 @@ + + + + + diff --git a/apps/admin/src/components/custom/wave-bg.vue b/apps/admin/src/components/custom/wave-bg.vue new file mode 100644 index 0000000..9587de5 --- /dev/null +++ b/apps/admin/src/components/custom/wave-bg.vue @@ -0,0 +1,61 @@ + + + + + diff --git a/apps/admin/src/constants/app.ts b/apps/admin/src/constants/app.ts new file mode 100644 index 0000000..e7eb6b9 --- /dev/null +++ b/apps/admin/src/constants/app.ts @@ -0,0 +1,71 @@ +import { transformRecordToOption } from '@/utils/common' + +export const GLOBAL_HEADER_MENU_ID = '__GLOBAL_HEADER_MENU__' + +export const GLOBAL_SIDER_MENU_ID = '__GLOBAL_SIDER_MENU__' + +export const themeSchemaRecord: Record = { + light: 'theme.appearance.themeSchema.light', + dark: 'theme.appearance.themeSchema.dark', + auto: 'theme.appearance.themeSchema.auto', +} + +export const themeSchemaOptions = transformRecordToOption(themeSchemaRecord) + +export const loginModuleRecord: Record = { + 'pwd-login': 'page.login.pwdLogin.title', + 'code-login': 'page.login.codeLogin.title', + 'register': 'page.login.register.title', + 'reset-pwd': 'page.login.resetPwd.title', + 'bind-wechat': 'page.login.bindWeChat.title', +} + +export const themeLayoutModeRecord: Record = { + 'vertical': 'theme.layout.layoutMode.vertical', + 'vertical-mix': 'theme.layout.layoutMode.vertical-mix', + 'vertical-hybrid-header-first': 'theme.layout.layoutMode.vertical-hybrid-header-first', + 'horizontal': 'theme.layout.layoutMode.horizontal', + 'top-hybrid-sidebar-first': 'theme.layout.layoutMode.top-hybrid-sidebar-first', + 'top-hybrid-header-first': 'theme.layout.layoutMode.top-hybrid-header-first', +} + +export const themeLayoutModeOptions = transformRecordToOption(themeLayoutModeRecord) + +export const themeScrollModeRecord: Record = { + wrapper: 'theme.layout.content.scrollMode.wrapper', + content: 'theme.layout.content.scrollMode.content', +} + +export const themeScrollModeOptions = transformRecordToOption(themeScrollModeRecord) + +export const themeTabModeRecord: Record = { + chrome: 'theme.layout.tab.mode.chrome', + button: 'theme.layout.tab.mode.button', + slider: 'theme.layout.tab.mode.slider', +} + +export const themeTabModeOptions = transformRecordToOption(themeTabModeRecord) + +export const themePageAnimationModeRecord: Record = { + 'fade-slide': 'theme.layout.content.page.mode.fade-slide', + 'fade': 'theme.layout.content.page.mode.fade', + 'fade-bottom': 'theme.layout.content.page.mode.fade-bottom', + 'fade-scale': 'theme.layout.content.page.mode.fade-scale', + 'zoom-fade': 'theme.layout.content.page.mode.zoom-fade', + 'zoom-out': 'theme.layout.content.page.mode.zoom-out', + 'none': 'theme.layout.content.page.mode.none', +} + +export const themePageAnimationModeOptions = transformRecordToOption(themePageAnimationModeRecord) + +export const DARK_CLASS = 'dark' + +export const watermarkTimeFormatOptions = [ + { label: 'YYYY-MM-DD HH:mm', value: 'YYYY-MM-DD HH:mm' }, + { label: 'YYYY-MM-DD HH:mm:ss', value: 'YYYY-MM-DD HH:mm:ss' }, + { label: 'YYYY/MM/DD HH:mm', value: 'YYYY/MM/DD HH:mm' }, + { label: 'YYYY/MM/DD HH:mm:ss', value: 'YYYY/MM/DD HH:mm:ss' }, + { label: 'HH:mm', value: 'HH:mm' }, + { label: 'HH:mm:ss', value: 'HH:mm:ss' }, + { label: 'MM-DD HH:mm', value: 'MM-DD HH:mm' }, +] diff --git a/apps/admin/src/constants/common.ts b/apps/admin/src/constants/common.ts new file mode 100644 index 0000000..2c52dfa --- /dev/null +++ b/apps/admin/src/constants/common.ts @@ -0,0 +1,8 @@ +import { transformRecordToOption } from '@/utils/common' + +export const yesOrNoRecord: Record = { + Y: 'common.yesOrNo.yes', + N: 'common.yesOrNo.no', +} + +export const yesOrNoOptions = transformRecordToOption(yesOrNoRecord) diff --git a/apps/admin/src/constants/reg.ts b/apps/admin/src/constants/reg.ts new file mode 100644 index 0000000..c568296 --- /dev/null +++ b/apps/admin/src/constants/reg.ts @@ -0,0 +1,25 @@ +export const REG_USER_NAME = /^[\u4E00-\u9FA5\w-]{4,16}$/ + +/** Phone reg */ +export const REG_PHONE + = /^1((3\d)|(4[014-9])|(5[0-35-9])|(6[2567])|(7[0-8])|(8\d)|(9[0-35-9]))\d{8}$/ + +/** + * Password reg + * + * 6-18 characters, including letters, numbers, and underscores + */ +export const REG_PWD = /^\w{6,18}$/ + +/** Email reg */ +export const REG_EMAIL = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/ + +/** Six digit code reg */ +export const REG_CODE_SIX = /^\d{6}$/ + +/** Four digit code reg */ +export const REG_CODE_FOUR = /^\d{4}$/ + +/** Url reg */ +export const REG_URL + = /(((^https?:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-]*)?\??[-+=&;%@.\w]*(?:#\w*)?)?)$/ diff --git a/apps/admin/src/enum/index.ts b/apps/admin/src/enum/index.ts new file mode 100644 index 0000000..7338a60 --- /dev/null +++ b/apps/admin/src/enum/index.ts @@ -0,0 +1,7 @@ +export enum SetupStoreId { + App = 'app-store', + Theme = 'theme-store', + Auth = 'auth-store', + Route = 'route-store', + Tab = 'tab-store', +} diff --git a/apps/admin/src/hooks/business/auth.ts b/apps/admin/src/hooks/business/auth.ts new file mode 100644 index 0000000..798c5d8 --- /dev/null +++ b/apps/admin/src/hooks/business/auth.ts @@ -0,0 +1,21 @@ +import { useAuthStore } from '@/store/modules/auth' + +export function useAuth() { + const authStore = useAuthStore() + + function hasAuth(codes: string | string[]) { + if (!authStore.isLogin) { + return false + } + + if (typeof codes === 'string') { + return authStore.userInfo.buttons.includes(codes) + } + + return codes.some(code => authStore.userInfo.buttons.includes(code)) + } + + return { + hasAuth, + } +} diff --git a/apps/admin/src/hooks/business/captcha.ts b/apps/admin/src/hooks/business/captcha.ts new file mode 100644 index 0000000..a4b7d3b --- /dev/null +++ b/apps/admin/src/hooks/business/captcha.ts @@ -0,0 +1,71 @@ +import { useCountDown, useLoading } from '@sa/hooks' +import { computed } from 'vue' +import { REG_PHONE } from '@/constants/reg' +import { $t } from '@/locales' + +export function useCaptcha() { + const { loading, startLoading, endLoading } = useLoading() + const { count, start, stop, isCounting } = useCountDown(10) + + const label = computed(() => { + let text = $t('page.login.codeLogin.getCode') + + const countingLabel = $t('page.login.codeLogin.reGetCode', { time: count.value }) + + if (loading.value) { + text = '' + } + + if (isCounting.value) { + text = countingLabel + } + + return text + }) + + function isPhoneValid(phone: string) { + if (phone.trim() === '') { + window.$message?.error?.($t('form.phone.required')) + + return false + } + + if (!REG_PHONE.test(phone)) { + window.$message?.error?.($t('form.phone.invalid')) + + return false + } + + return true + } + + async function getCaptcha(phone: string) { + const valid = isPhoneValid(phone) + + if (!valid || loading.value) { + return + } + + startLoading() + + // request + await new Promise((resolve) => { + setTimeout(resolve, 500) + }) + + window.$message?.success?.($t('page.login.codeLogin.sendCodeSuccess')) + + start() + + endLoading() + } + + return { + label, + start, + stop, + isCounting, + loading, + getCaptcha, + } +} diff --git a/apps/admin/src/hooks/common/echarts.ts b/apps/admin/src/hooks/common/echarts.ts new file mode 100644 index 0000000..fadbb11 --- /dev/null +++ b/apps/admin/src/hooks/common/echarts.ts @@ -0,0 +1,233 @@ +import type { + BarSeriesOption, + GaugeSeriesOption, + LineSeriesOption, + PictorialBarSeriesOption, + PieSeriesOption, + RadarSeriesOption, + ScatterSeriesOption, +} from 'echarts/charts' +import type { + DatasetComponentOption, + GridComponentOption, + LegendComponentOption, + TitleComponentOption, + ToolboxComponentOption, + TooltipComponentOption, +} from 'echarts/components' +import { useElementSize } from '@vueuse/core' +import { BarChart, GaugeChart, LineChart, PictorialBarChart, PieChart, RadarChart, ScatterChart } from 'echarts/charts' +import { + DatasetComponent, + GridComponent, + LegendComponent, + TitleComponent, + ToolboxComponent, + TooltipComponent, + TransformComponent, +} from 'echarts/components' +import * as echarts from 'echarts/core' +import { LabelLayout, UniversalTransition } from 'echarts/features' +import { CanvasRenderer } from 'echarts/renderers' +import { computed, effectScope, nextTick, onScopeDispose, shallowRef, watch } from 'vue' +import { useThemeStore } from '@/store/modules/theme' + +export type ECOption = echarts.ComposeOption< + | BarSeriesOption + | LineSeriesOption + | PieSeriesOption + | ScatterSeriesOption + | PictorialBarSeriesOption + | RadarSeriesOption + | GaugeSeriesOption + | TitleComponentOption + | LegendComponentOption + | TooltipComponentOption + | GridComponentOption + | ToolboxComponentOption + | DatasetComponentOption +> + +echarts.use([ + TitleComponent, + LegendComponent, + TooltipComponent, + GridComponent, + DatasetComponent, + TransformComponent, + ToolboxComponent, + BarChart, + LineChart, + PieChart, + ScatterChart, + PictorialBarChart, + RadarChart, + GaugeChart, + LabelLayout, + UniversalTransition, + CanvasRenderer, +]) + +interface ChartHooks { + onRender?: (chart: echarts.ECharts) => void | Promise + onUpdated?: (chart: echarts.ECharts) => void | Promise + onDestroy?: (chart: echarts.ECharts) => void | Promise +} + +/** + * use echarts + * + * @param optionsFactory echarts options factory function + * @param darkMode dark mode + */ +export function useEcharts(optionsFactory: () => T, hooks: ChartHooks = {}) { + const scope = effectScope() + + const themeStore = useThemeStore() + const darkMode = computed(() => themeStore.darkMode) + + const domRef = shallowRef(null) + const initialSize = { width: 0, height: 0 } + const { width, height } = useElementSize(domRef, initialSize) + + const chart = shallowRef(null) + const chartOptions: T = optionsFactory() + + const { + onRender = (instance) => { + const textColor = darkMode.value ? 'rgb(224, 224, 224)' : 'rgb(31, 31, 31)' + const maskColor = darkMode.value ? 'rgba(0, 0, 0, 0.4)' : 'rgba(255, 255, 255, 0.8)' + + instance.showLoading({ + color: themeStore.themeColor, + textColor, + fontSize: 14, + maskColor, + }) + }, + onUpdated = (instance) => { + instance.hideLoading() + }, + onDestroy, + } = hooks + + /** is chart rendered */ + function isRendered() { + return Boolean(domRef.value && chart.value) + } + + /** + * update chart options + * + * @param callback callback function + */ + async function updateOptions(callback: (opts: T, optsFactory: () => T) => ECOption = () => chartOptions) { + const updatedOpts = callback(chartOptions, optionsFactory) + + Object.assign(chartOptions, updatedOpts) + + await nextTick() + + if (!isRendered()) + return + + if (isRendered()) { + chart.value?.clear() + } + + chart.value?.setOption({ ...updatedOpts, backgroundColor: 'transparent' }) + + await onUpdated?.(chart.value!) + } + + function setOptions(options: T) { + chart.value?.setOption(options) + } + + /** render chart */ + async function render() { + if (isRendered()) + return + + const chartTheme = darkMode.value ? 'dark' : 'light' + + chart.value = echarts.init(domRef.value, chartTheme) + + chart.value?.setOption({ ...chartOptions, backgroundColor: 'transparent' }) + + await onRender?.(chart.value!) + } + + /** resize chart */ + function resize() { + chart.value?.resize() + } + + /** destroy chart */ + async function destroy() { + if (!chart.value) + return + + await onDestroy?.(chart.value) + chart.value?.dispose() + chart.value = null + } + + /** change chart theme */ + async function changeTheme() { + await destroy() + await render() + await onUpdated?.(chart.value!) + } + + /** + * render chart by size + * + * @param w width + * @param h height + */ + async function renderChartBySize(w: number, h: number) { + initialSize.width = w + initialSize.height = h + + // resize chart + if (isRendered()) { + resize() + + return + } + + // render chart + await render() + + if (chart.value) { + await onUpdated?.(chart.value) + } + } + + scope.run(() => { + watch( + [width, height], + ([newWidth, newHeight]) => { + renderChartBySize(newWidth, newHeight) + }, + { flush: 'post' }, + ) + + watch(darkMode, () => { + changeTheme() + }) + }) + + onScopeDispose(() => { + destroy() + scope.stop() + }) + + return { + domRef, + chart, + updateOptions, + setOptions, + } +} diff --git a/apps/admin/src/hooks/common/form.ts b/apps/admin/src/hooks/common/form.ts new file mode 100644 index 0000000..4d668d8 --- /dev/null +++ b/apps/admin/src/hooks/common/form.ts @@ -0,0 +1,97 @@ +import type { FormInst } from 'naive-ui' +import type { ComputedRef, Ref } from 'vue' +import { ref, toValue } from 'vue' +import { REG_CODE_SIX, REG_EMAIL, REG_PHONE, REG_PWD, REG_USER_NAME } from '@/constants/reg' +import { $t } from '@/locales' + +export function useFormRules() { + const patternRules = { + userName: { + pattern: REG_USER_NAME, + message: $t('form.userName.invalid'), + trigger: 'change', + }, + phone: { + pattern: REG_PHONE, + message: $t('form.phone.invalid'), + trigger: 'change', + }, + pwd: { + pattern: REG_PWD, + message: $t('form.pwd.invalid'), + trigger: 'change', + }, + code: { + pattern: REG_CODE_SIX, + message: $t('form.code.invalid'), + trigger: 'change', + }, + email: { + pattern: REG_EMAIL, + message: $t('form.email.invalid'), + trigger: 'change', + }, + } satisfies Record + + const formRules = { + userName: [createRequiredRule($t('form.userName.required')), patternRules.userName], + phone: [createRequiredRule($t('form.phone.required')), patternRules.phone], + pwd: [createRequiredRule($t('form.pwd.required')), patternRules.pwd], + code: [createRequiredRule($t('form.code.required')), patternRules.code], + email: [createRequiredRule($t('form.email.required')), patternRules.email], + } satisfies Record + + /** the default required rule */ + const defaultRequiredRule = createRequiredRule($t('form.required')) + + function createRequiredRule(message: string): App.Global.FormRule { + return { + required: true, + message, + } + } + + /** create a rule for confirming the password */ + function createConfirmPwdRule(pwd: string | Ref | ComputedRef) { + const confirmPwdRule: App.Global.FormRule[] = [ + { required: true, message: $t('form.confirmPwd.required') }, + { + asyncValidator: (rule, value) => { + if (value.trim() !== '' && value !== toValue(pwd)) { + return Promise.reject(rule.message) + } + return Promise.resolve() + }, + message: $t('form.confirmPwd.invalid'), + trigger: 'input', + }, + ] + return confirmPwdRule + } + + return { + patternRules, + formRules, + defaultRequiredRule, + createRequiredRule, + createConfirmPwdRule, + } +} + +export function useNaiveForm() { + const formRef = ref(null) + + async function validate() { + await formRef.value?.validate() + } + + async function restoreValidation() { + formRef.value?.restoreValidation() + } + + return { + formRef, + validate, + restoreValidation, + } +} diff --git a/apps/admin/src/hooks/common/icon.ts b/apps/admin/src/hooks/common/icon.ts new file mode 100644 index 0000000..795ae6b --- /dev/null +++ b/apps/admin/src/hooks/common/icon.ts @@ -0,0 +1,10 @@ +import { useSvgIconRender } from '@sa/hooks' +import SvgIcon from '@/components/custom/svg-icon.vue' + +export function useSvgIcon() { + const { SvgIconVNode } = useSvgIconRender(SvgIcon) + + return { + SvgIconVNode, + } +} diff --git a/apps/admin/src/hooks/common/router.ts b/apps/admin/src/hooks/common/router.ts new file mode 100644 index 0000000..0efd913 --- /dev/null +++ b/apps/admin/src/hooks/common/router.ts @@ -0,0 +1,116 @@ +import type { RouteKey } from '@elegant-router/types' +import type { RouteLocationRaw } from 'vue-router' +import { useRouter } from 'vue-router' +import { router as globalRouter } from '@/router' + +/** + * Router push + * + * Jump to the specified route, it can replace function router.push + * + * @param inSetup Whether is in vue script setup + */ +export function useRouterPush(inSetup = true) { + const router = inSetup ? useRouter() : globalRouter + const route = globalRouter.currentRoute + + const routerPush = router.push + + const routerBack = router.back + + async function routerPushByKey(key: RouteKey, options?: App.Global.RouterPushOptions) { + const { query, params } = options || {} + + const routeLocation: RouteLocationRaw = { + name: key, + } + + if (Object.keys(query || {}).length) { + routeLocation.query = query + } + + if (Object.keys(params || {}).length) { + routeLocation.params = params + } + + return routerPush(routeLocation) + } + + function routerPushByKeyWithMetaQuery(key: RouteKey) { + const allRoutes = router.getRoutes() + const meta = allRoutes.find(item => item.name === key)?.meta || null + + const query: Record = {} + + meta?.query?.forEach((item) => { + query[item.key] = item.value + }) + + return routerPushByKey(key, { query }) + } + + async function toHome() { + return routerPushByKey('root') + } + + /** + * Navigate to login page + * + * @param loginModule The login module + * @param redirectUrl The redirect url, if not specified, it will be the current route fullPath + */ + async function toLogin(loginModule?: UnionKey.LoginModule, redirectUrl?: string) { + const module = loginModule || 'pwd-login' + + const options: App.Global.RouterPushOptions = { + params: { + module, + }, + } + + const redirect = redirectUrl || route.value.fullPath + + options.query = { + redirect, + } + + return routerPushByKey('login', options) + } + + /** + * Toggle login module + * + * @param module + */ + async function toggleLoginModule(module: UnionKey.LoginModule) { + const query = route.value.query as Record + + return routerPushByKey('login', { query, params: { module } }) + } + + /** + * Redirect from login + * + * @param [needRedirect] Whether to redirect after login. Default is `true` + */ + async function redirectFromLogin(needRedirect = true) { + const redirect = route.value.query?.redirect as string + + if (needRedirect && redirect) { + await routerPush(redirect) + } + else { + await toHome() + } + } + + return { + routerPush, + routerBack, + routerPushByKey, + routerPushByKeyWithMetaQuery, + toLogin, + toggleLoginModule, + redirectFromLogin, + } +} diff --git a/apps/admin/src/hooks/common/table.ts b/apps/admin/src/hooks/common/table.ts new file mode 100644 index 0000000..d670e70 --- /dev/null +++ b/apps/admin/src/hooks/common/table.ts @@ -0,0 +1,315 @@ +import type { FlatResponseData } from '@sa/axios' +import type { PaginationData, TableColumnCheck, UseTableOptions } from '@sa/hooks' +import type { PaginationProps } from 'naive-ui' +import type { Ref } from 'vue' +import { useBoolean, useTable } from '@sa/hooks' +import { jsonClone } from '@sa/utils' +import { computed, effectScope, onScopeDispose, reactive, shallowRef, watch } from 'vue' +import { $t } from '@/locales' +import { useAppStore } from '@/store/modules/app' + +export type UseNaiveTableOptions = Omit< + UseTableOptions, Pagination>, + 'pagination' | 'getColumnChecks' | 'getColumns' +> & { + /** + * get column visible + * + * @param column + * + * @default true + * + * @returns true if the column is visible, false otherwise + */ + getColumnVisible?: (column: NaiveUI.TableColumn) => boolean +} + +const SELECTION_KEY = '__selection__' + +const EXPAND_KEY = '__expand__' + +export function useNaiveTable(options: UseNaiveTableOptions) { + const scope = effectScope() + const appStore = useAppStore() + + const result = useTable, false>({ + ...options, + getColumnChecks: cols => getColumnChecks(cols, options.getColumnVisible), + getColumns, + }) + + // calculate the total width of the table this is used for horizontal scrolling + const scrollX = computed(() => { + return result.columns.value.reduce((acc, column) => { + return acc + Number(column.width ?? column.minWidth ?? 120) + }, 0) + }) + + scope.run(() => { + watch( + () => appStore.locale, + () => { + result.reloadColumns() + }, + ) + }) + + onScopeDispose(() => { + scope.stop() + }) + + return { + ...result, + scrollX, + } +} + +type PaginationParams = Pick + +type UseNaivePaginatedTableOptions = UseNaiveTableOptions & { + paginationProps?: Omit + /** + * whether to show the total count of the table + * + * @default true + */ + showTotal?: boolean + onPaginationParamsChange?: (params: PaginationParams) => void | Promise +} + +export function useNaivePaginatedTable( + options: UseNaivePaginatedTableOptions, +) { + const scope = effectScope() + const appStore = useAppStore() + + const isMobile = computed(() => appStore.isMobile) + + const showTotal = computed(() => options.showTotal ?? true) + + const pagination = reactive({ + page: 1, + pageSize: 10, + itemCount: 0, + showSizePicker: true, + pageSizes: [10, 15, 20, 25, 30], + prefix: showTotal.value ? page => $t('datatable.itemCount', { total: page.itemCount }) : undefined, + onUpdatePage(page) { + pagination.page = page + }, + onUpdatePageSize(pageSize) { + pagination.pageSize = pageSize + pagination.page = 1 + }, + ...options.paginationProps, + }) as PaginationProps + + // this is for mobile, if the system does not support mobile, you can use `pagination` directly + const mobilePagination = computed(() => { + const p: PaginationProps = { + ...pagination, + pageSlot: isMobile.value ? 3 : 9, + prefix: !isMobile.value && showTotal.value ? pagination.prefix : undefined, + } + + return p + }) + + const paginationParams = computed(() => { + const { page, pageSize } = pagination + + return { + page, + pageSize, + } + }) + + const result = useTable, true>({ + ...options, + pagination: true, + getColumnChecks: cols => getColumnChecks(cols, options.getColumnVisible), + getColumns, + onFetched: (data) => { + pagination.itemCount = data.total + pagination.pageSize = data.pageSize + }, + }) + + async function getDataByPage(page: number = 1) { + if (page !== pagination.page) { + pagination.page = page + + return + } + + await result.getData() + } + + scope.run(() => { + watch( + () => appStore.locale, + () => { + result.reloadColumns() + }, + ) + + watch(paginationParams, async (newVal) => { + await options.onPaginationParamsChange?.(newVal) + + await result.getData() + }) + }) + + onScopeDispose(() => { + scope.stop() + }) + + return { + ...result, + getDataByPage, + pagination, + mobilePagination, + } +} + +export function useTableOperate( + data: Ref, + idKey: keyof TableData, + getData: () => Promise, +) { + const { bool: drawerVisible, setTrue: openDrawer, setFalse: closeDrawer } = useBoolean() + + const operateType = shallowRef('add') + + function handleAdd() { + operateType.value = 'add' + openDrawer() + } + + /** the editing row data */ + const editingData = shallowRef(null) + + function handleEdit(id: TableData[keyof TableData]) { + operateType.value = 'edit' + const findItem = data.value.find(item => item[idKey] === id) || null + editingData.value = jsonClone(findItem) + + openDrawer() + } + + /** the checked row keys of table */ + const checkedRowKeys = shallowRef([]) + + /** the hook after the batch delete operation is completed */ + async function onBatchDeleted() { + window.$message?.success($t('common.deleteSuccess')) + + checkedRowKeys.value = [] + + await getData() + } + + /** the hook after the delete operation is completed */ + async function onDeleted() { + window.$message?.success($t('common.deleteSuccess')) + + await getData() + } + + return { + drawerVisible, + openDrawer, + closeDrawer, + operateType, + handleAdd, + editingData, + handleEdit, + checkedRowKeys, + onBatchDeleted, + onDeleted, + } +} + +export function defaultTransform( + response: FlatResponseData>, +): PaginationData { + const { data, error } = response + + if (!error) { + const { records, current, size, total } = data + + return { + data: records, + pageNum: current, + pageSize: size, + total, + } + } + + return { + data: [], + pageNum: 1, + pageSize: 10, + total: 0, + } +} + +function getColumnChecks>( + cols: Column[], + getColumnVisible?: (column: Column) => boolean, +) { + const checks: TableColumnCheck[] = [] + + cols.forEach((column) => { + if (isTableColumnHasKey(column)) { + checks.push({ + key: column.key as string, + title: column.title!, + checked: true, + visible: getColumnVisible?.(column) ?? true, + }) + } + else if (column.type === 'selection') { + checks.push({ + key: SELECTION_KEY, + title: $t('common.check'), + checked: true, + visible: getColumnVisible?.(column) ?? false, + }) + } + else if (column.type === 'expand') { + checks.push({ + key: EXPAND_KEY, + title: $t('common.expandColumn'), + checked: true, + visible: getColumnVisible?.(column) ?? false, + }) + } + }) + + return checks +} + +function getColumns>(cols: Column[], checks: TableColumnCheck[]) { + const columnMap = new Map() + + cols.forEach((column) => { + if (isTableColumnHasKey(column)) { + columnMap.set(column.key as string, column) + } + else if (column.type === 'selection') { + columnMap.set(SELECTION_KEY, column) + } + else if (column.type === 'expand') { + columnMap.set(EXPAND_KEY, column) + } + }) + + const filteredColumns = checks.filter(item => item.checked).map(check => columnMap.get(check.key) as Column) + + return filteredColumns +} + +export function isTableColumnHasKey(column: NaiveUI.TableColumn): column is NaiveUI.TableColumnWithKey { + return Boolean((column as NaiveUI.TableColumnWithKey).key) +} diff --git a/apps/admin/src/layouts/base-layout/index.vue b/apps/admin/src/layouts/base-layout/index.vue new file mode 100644 index 0000000..c212c6f --- /dev/null +++ b/apps/admin/src/layouts/base-layout/index.vue @@ -0,0 +1,162 @@ + + + + + diff --git a/apps/admin/src/layouts/blank-layout/index.vue b/apps/admin/src/layouts/blank-layout/index.vue new file mode 100644 index 0000000..1ced20e --- /dev/null +++ b/apps/admin/src/layouts/blank-layout/index.vue @@ -0,0 +1,13 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-breadcrumb/index.vue b/apps/admin/src/layouts/modules/global-breadcrumb/index.vue new file mode 100644 index 0000000..8349ecb --- /dev/null +++ b/apps/admin/src/layouts/modules/global-breadcrumb/index.vue @@ -0,0 +1,47 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-content/index.vue b/apps/admin/src/layouts/modules/global-content/index.vue new file mode 100644 index 0000000..dcd33ed --- /dev/null +++ b/apps/admin/src/layouts/modules/global-content/index.vue @@ -0,0 +1,58 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-footer/index.vue b/apps/admin/src/layouts/modules/global-footer/index.vue new file mode 100644 index 0000000..8541cb4 --- /dev/null +++ b/apps/admin/src/layouts/modules/global-footer/index.vue @@ -0,0 +1,15 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-header/components/theme-button.vue b/apps/admin/src/layouts/modules/global-header/components/theme-button.vue new file mode 100644 index 0000000..308e2db --- /dev/null +++ b/apps/admin/src/layouts/modules/global-header/components/theme-button.vue @@ -0,0 +1,20 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-header/components/user-avatar.vue b/apps/admin/src/layouts/modules/global-header/components/user-avatar.vue new file mode 100644 index 0000000..6711b76 --- /dev/null +++ b/apps/admin/src/layouts/modules/global-header/components/user-avatar.vue @@ -0,0 +1,83 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-header/index.vue b/apps/admin/src/layouts/modules/global-header/index.vue new file mode 100644 index 0000000..1ac88f0 --- /dev/null +++ b/apps/admin/src/layouts/modules/global-header/index.vue @@ -0,0 +1,60 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-logo/index.vue b/apps/admin/src/layouts/modules/global-logo/index.vue new file mode 100644 index 0000000..be617d4 --- /dev/null +++ b/apps/admin/src/layouts/modules/global-logo/index.vue @@ -0,0 +1,27 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-menu/components/first-level-menu.vue b/apps/admin/src/layouts/modules/global-menu/components/first-level-menu.vue new file mode 100644 index 0000000..2bad193 --- /dev/null +++ b/apps/admin/src/layouts/modules/global-menu/components/first-level-menu.vue @@ -0,0 +1,109 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-menu/context/index.ts b/apps/admin/src/layouts/modules/global-menu/context/index.ts new file mode 100644 index 0000000..c223dd2 --- /dev/null +++ b/apps/admin/src/layouts/modules/global-menu/context/index.ts @@ -0,0 +1,185 @@ +import type { RouteKey } from '@elegant-router/types' +import { useContext } from '@sa/hooks' +import { computed, ref, watch } from 'vue' +import { useRoute } from 'vue-router' +import { useRouterPush } from '@/hooks/common/router' +import { useRouteStore } from '@/store/modules/route' +import { useThemeStore } from '@/store/modules/theme' + +export const [provideMixMenuContext, useMixMenuContext] = useContext('MixMenu', useMixMenu) + +function useMixMenu() { + const route = useRoute() + const routeStore = useRouteStore() + const themeStore = useThemeStore() + const { selectedKey } = useMenu() + const { routerPushByKeyWithMetaQuery } = useRouterPush() + + const allMenus = computed(() => routeStore.menus) + + const firstLevelMenus = computed(() => + routeStore.menus.map((menu) => { + const { children: _, ...rest } = menu + + return rest + }), + ) + + const activeFirstLevelMenuKey = ref('') + + function setActiveFirstLevelMenuKey(key: string) { + activeFirstLevelMenuKey.value = key + } + + function getActiveFirstLevelMenuKey() { + const [firstLevelRouteName] = selectedKey.value.split('_') + + setActiveFirstLevelMenuKey(firstLevelRouteName) + } + + const isActiveFirstLevelMenuHasChildren = computed(() => { + if (!activeFirstLevelMenuKey.value) { + return false + } + + const findItem = allMenus.value.find(item => item.key === activeFirstLevelMenuKey.value) + + return Boolean(findItem?.children?.length) + }) + + function handleSelectFirstLevelMenu(key: RouteKey) { + setActiveFirstLevelMenuKey(key) + + if (!isActiveFirstLevelMenuHasChildren.value) { + routerPushByKeyWithMetaQuery(key) + } + } + + const secondLevelMenus = computed( + () => allMenus.value.find(menu => menu.key === activeFirstLevelMenuKey.value)?.children || [], + ) + + const activeSecondLevelMenuKey = ref('') + + function setActiveSecondLevelMenuKey(key: string) { + activeSecondLevelMenuKey.value = key + } + + function getActiveSecondLevelMenuKey() { + const keys = selectedKey.value.split('_') + + if (keys.length < 2) { + setActiveSecondLevelMenuKey('') + return + } + + const [firstLevelRouteName, level2SuffixName] = keys + + const secondLevelRouteName = `${firstLevelRouteName}_${level2SuffixName}` + + setActiveSecondLevelMenuKey(secondLevelRouteName) + } + + const isActiveSecondLevelMenuHasChildren = computed(() => { + if (!activeSecondLevelMenuKey.value) { + return false + } + + const findItem = secondLevelMenus.value.find(item => item.key === activeSecondLevelMenuKey.value) + + return Boolean(findItem?.children?.length) + }) + + function handleSelectSecondLevelMenu(key: RouteKey) { + setActiveSecondLevelMenuKey(key) + + if (!isActiveSecondLevelMenuHasChildren.value) { + routerPushByKeyWithMetaQuery(key) + } + } + + const childLevelMenus = computed( + () => secondLevelMenus.value.find(menu => menu.key === activeSecondLevelMenuKey.value)?.children || [], + ) + + const hasChildLevelMenus = computed(() => childLevelMenus.value.length > 0) + + function getDeepestLevelMenuKey(): RouteKey | null { + if (!secondLevelMenus.value.length || !themeStore.sider.autoSelectFirstMenu) { + return null + } + + const secondLevelFirstMenu = secondLevelMenus.value[0] + + if (!secondLevelFirstMenu) { + return null + } + + function findDeepest(menu: App.Global.Menu): RouteKey { + if (!menu.children?.length) { + return menu.routeKey + } + + return findDeepest(menu.children[0]) + } + + return findDeepest(secondLevelFirstMenu) + } + + function activeDeepestLevelMenuKey() { + const deepestLevelMenuKey = getDeepestLevelMenuKey() + if (!deepestLevelMenuKey) + return + + // select the deepest second level menu + handleSelectSecondLevelMenu(deepestLevelMenuKey) + } + + watch( + () => route.name, + () => { + getActiveFirstLevelMenuKey() + // if there are child level menus, get the active second level menu key + if (hasChildLevelMenus.value) { + getActiveSecondLevelMenuKey() + } + }, + { immediate: true }, + ) + + return { + firstLevelMenus, + activeFirstLevelMenuKey, + setActiveFirstLevelMenuKey, + isActiveFirstLevelMenuHasChildren, + handleSelectFirstLevelMenu, + getActiveFirstLevelMenuKey, + secondLevelMenus, + activeSecondLevelMenuKey, + setActiveSecondLevelMenuKey, + isActiveSecondLevelMenuHasChildren, + handleSelectSecondLevelMenu, + getActiveSecondLevelMenuKey, + childLevelMenus, + hasChildLevelMenus, + getDeepestLevelMenuKey, + activeDeepestLevelMenuKey, + } +} + +export function useMenu() { + const route = useRoute() + + const selectedKey = computed(() => { + const { hideInMenu, activeMenu } = route.meta + const name = route.name as string + + const routeName = (hideInMenu ? activeMenu : name) || name + + return routeName + }) + + return { + selectedKey, + } +} diff --git a/apps/admin/src/layouts/modules/global-menu/index.vue b/apps/admin/src/layouts/modules/global-menu/index.vue new file mode 100644 index 0000000..d6507d2 --- /dev/null +++ b/apps/admin/src/layouts/modules/global-menu/index.vue @@ -0,0 +1,40 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-menu/modules/horizontal-menu.vue b/apps/admin/src/layouts/modules/global-menu/modules/horizontal-menu.vue new file mode 100644 index 0000000..1587b83 --- /dev/null +++ b/apps/admin/src/layouts/modules/global-menu/modules/horizontal-menu.vue @@ -0,0 +1,29 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-menu/modules/top-hybrid-header-first.vue b/apps/admin/src/layouts/modules/global-menu/modules/top-hybrid-header-first.vue new file mode 100644 index 0000000..5097662 --- /dev/null +++ b/apps/admin/src/layouts/modules/global-menu/modules/top-hybrid-header-first.vue @@ -0,0 +1,89 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-menu/modules/top-hybrid-sidebar-first.vue b/apps/admin/src/layouts/modules/global-menu/modules/top-hybrid-sidebar-first.vue new file mode 100644 index 0000000..ac7c0f7 --- /dev/null +++ b/apps/admin/src/layouts/modules/global-menu/modules/top-hybrid-sidebar-first.vue @@ -0,0 +1,64 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-menu/modules/vertical-hybrid-header-first.vue b/apps/admin/src/layouts/modules/global-menu/modules/vertical-hybrid-header-first.vue new file mode 100644 index 0000000..660251c --- /dev/null +++ b/apps/admin/src/layouts/modules/global-menu/modules/vertical-hybrid-header-first.vue @@ -0,0 +1,175 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-menu/modules/vertical-menu.vue b/apps/admin/src/layouts/modules/global-menu/modules/vertical-menu.vue new file mode 100644 index 0000000..735d413 --- /dev/null +++ b/apps/admin/src/layouts/modules/global-menu/modules/vertical-menu.vue @@ -0,0 +1,63 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-menu/modules/vertical-mix-menu.vue b/apps/admin/src/layouts/modules/global-menu/modules/vertical-mix-menu.vue new file mode 100644 index 0000000..301c543 --- /dev/null +++ b/apps/admin/src/layouts/modules/global-menu/modules/vertical-mix-menu.vue @@ -0,0 +1,129 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-search/components/search-footer.vue b/apps/admin/src/layouts/modules/global-search/components/search-footer.vue new file mode 100644 index 0000000..ac71f59 --- /dev/null +++ b/apps/admin/src/layouts/modules/global-search/components/search-footer.vue @@ -0,0 +1,36 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-search/components/search-modal.vue b/apps/admin/src/layouts/modules/global-search/components/search-modal.vue new file mode 100644 index 0000000..395efde --- /dev/null +++ b/apps/admin/src/layouts/modules/global-search/components/search-modal.vue @@ -0,0 +1,130 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-search/components/search-result.vue b/apps/admin/src/layouts/modules/global-search/components/search-result.vue new file mode 100644 index 0000000..e51ebf8 --- /dev/null +++ b/apps/admin/src/layouts/modules/global-search/components/search-result.vue @@ -0,0 +1,56 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-search/index.vue b/apps/admin/src/layouts/modules/global-search/index.vue new file mode 100644 index 0000000..a60512b --- /dev/null +++ b/apps/admin/src/layouts/modules/global-search/index.vue @@ -0,0 +1,18 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-sider/index.vue b/apps/admin/src/layouts/modules/global-sider/index.vue new file mode 100644 index 0000000..ba2366a --- /dev/null +++ b/apps/admin/src/layouts/modules/global-sider/index.vue @@ -0,0 +1,36 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-tab/context-menu.vue b/apps/admin/src/layouts/modules/global-tab/context-menu.vue new file mode 100644 index 0000000..cb746b6 --- /dev/null +++ b/apps/admin/src/layouts/modules/global-tab/context-menu.vue @@ -0,0 +1,147 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/global-tab/index.vue b/apps/admin/src/layouts/modules/global-tab/index.vue new file mode 100644 index 0000000..ab2a332 --- /dev/null +++ b/apps/admin/src/layouts/modules/global-tab/index.vue @@ -0,0 +1,237 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/theme-drawer/components/layout-mode-card.vue b/apps/admin/src/layouts/modules/theme-drawer/components/layout-mode-card.vue new file mode 100644 index 0000000..7fe6ce0 --- /dev/null +++ b/apps/admin/src/layouts/modules/theme-drawer/components/layout-mode-card.vue @@ -0,0 +1,104 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/theme-drawer/components/setting-item.vue b/apps/admin/src/layouts/modules/theme-drawer/components/setting-item.vue new file mode 100644 index 0000000..a4ad081 --- /dev/null +++ b/apps/admin/src/layouts/modules/theme-drawer/components/setting-item.vue @@ -0,0 +1,24 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/theme-drawer/index.vue b/apps/admin/src/layouts/modules/theme-drawer/index.vue new file mode 100644 index 0000000..9f4aa9d --- /dev/null +++ b/apps/admin/src/layouts/modules/theme-drawer/index.vue @@ -0,0 +1,66 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/theme-drawer/modules/appearance/index.vue b/apps/admin/src/layouts/modules/theme-drawer/modules/appearance/index.vue new file mode 100644 index 0000000..d711136 --- /dev/null +++ b/apps/admin/src/layouts/modules/theme-drawer/modules/appearance/index.vue @@ -0,0 +1,19 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/theme-drawer/modules/appearance/modules/theme-color.vue b/apps/admin/src/layouts/modules/theme-drawer/modules/appearance/modules/theme-color.vue new file mode 100644 index 0000000..2d66c5f --- /dev/null +++ b/apps/admin/src/layouts/modules/theme-drawer/modules/appearance/modules/theme-color.vue @@ -0,0 +1,83 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/theme-drawer/modules/appearance/modules/theme-radius.vue b/apps/admin/src/layouts/modules/theme-drawer/modules/appearance/modules/theme-radius.vue new file mode 100644 index 0000000..e6dda71 --- /dev/null +++ b/apps/admin/src/layouts/modules/theme-drawer/modules/appearance/modules/theme-radius.vue @@ -0,0 +1,22 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/theme-drawer/modules/appearance/modules/theme-schema.vue b/apps/admin/src/layouts/modules/theme-drawer/modules/appearance/modules/theme-schema.vue new file mode 100644 index 0000000..6ccf007 --- /dev/null +++ b/apps/admin/src/layouts/modules/theme-drawer/modules/appearance/modules/theme-schema.vue @@ -0,0 +1,76 @@ + + + + + diff --git a/apps/admin/src/layouts/modules/theme-drawer/modules/config-operation.vue b/apps/admin/src/layouts/modules/theme-drawer/modules/config-operation.vue new file mode 100644 index 0000000..0764e97 --- /dev/null +++ b/apps/admin/src/layouts/modules/theme-drawer/modules/config-operation.vue @@ -0,0 +1,63 @@ + + +