cmpt-huitu-cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +169 -0
  2. package/bin/huitu.js +30 -0
  3. package/package.json +38 -0
  4. package/src/create.js +127 -0
  5. package/src/versions.js +23 -0
  6. package/templates/default/README.md +127 -0
  7. package/templates/default/eslint.config.js +187 -0
  8. package/templates/default/index.html +38 -0
  9. package/templates/default/jsconfig.json +29 -0
  10. package/templates/default/package.json +56 -0
  11. package/templates/default/public/.DS_Store +0 -0
  12. package/templates/default/public/config/envCfg.js +68 -0
  13. package/templates/default/public/images/favicon.ico +0 -0
  14. package/templates/default/src/.DS_Store +0 -0
  15. package/templates/default/src/App.vue +49 -0
  16. package/templates/default/src/assets/.DS_Store +0 -0
  17. package/templates/default/src/assets/empty.png +0 -0
  18. package/templates/default/src/assets/images/.DS_Store +0 -0
  19. package/templates/default/src/assets/images/404/403_1.png +0 -0
  20. package/templates/default/src/assets/images/404/404.png +0 -0
  21. package/templates/default/src/assets/images/404/404_2.png +0 -0
  22. package/templates/default/src/assets/images/404/404_cloud.png +0 -0
  23. package/templates/default/src/assets/images/login/img.png +0 -0
  24. package/templates/default/src/assets/images/login/logo.png +0 -0
  25. package/templates/default/src/assets/images/login/person.png +0 -0
  26. package/templates/default/src/components/.DS_Store +0 -0
  27. package/templates/default/src/components/error/Error.vue +259 -0
  28. package/templates/default/src/components.d.ts +18 -0
  29. package/templates/default/src/imports.d.ts +90 -0
  30. package/templates/default/src/main.js +27 -0
  31. package/templates/default/src/routers/base.js +41 -0
  32. package/templates/default/src/routers/guard.js +43 -0
  33. package/templates/default/src/routers/index.js +36 -0
  34. package/templates/default/src/routers/modules/example.js +17 -0
  35. package/templates/default/src/services/.DS_Store +0 -0
  36. package/templates/default/src/services/login.js +32 -0
  37. package/templates/default/src/stores/README.md +317 -0
  38. package/templates/default/src/stores/index/global.js +49 -0
  39. package/templates/default/src/stores/index/template.js +31 -0
  40. package/templates/default/src/stores/index.js +14 -0
  41. package/templates/default/src/stores//344/275/277/347/224/250/347/244/272/344/276/213.vue +94 -0
  42. package/templates/default/src/styles/index.scss +23 -0
  43. package/templates/default/src/styles/theme/README.md +52 -0
  44. package/templates/default/src/styles/theme/variables.scss +62 -0
  45. package/templates/default/src/utils/RequestCache.js +198 -0
  46. package/templates/default/src/utils/auth.js +51 -0
  47. package/templates/default/src/utils/errorCode.js +16 -0
  48. package/templates/default/src/utils/index.js +519 -0
  49. package/templates/default/src/utils/requestAxios.js +148 -0
  50. package/templates/default/src/utils/theme.js +20 -0
  51. package/templates/default/src/views/About.vue +6 -0
  52. package/templates/default/src/views/Home.vue +111 -0
  53. package/templates/default/src/views/login/index.vue +285 -0
  54. package/templates/default/vite/plugins/autoComponents.js +18 -0
  55. package/templates/default/vite/plugins/autoImport.js +13 -0
  56. package/templates/default/vite/plugins/compression.js +24 -0
  57. package/templates/default/vite/plugins/externals.js +8 -0
  58. package/templates/default/vite/plugins/index.js +18 -0
  59. package/templates/default/vite/plugins/visualizer.js +11 -0
  60. package/templates/default/vite.config.js +185 -0
package/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # cmpt-huitu-cli
2
+
3
+ 慧图前端项目工程化 CLI 工具,用于快速创建基于 Vue 3 + Vite 的项目模板。
4
+
5
+ ## ✨ 特性
6
+
7
+ - 🚀 基于 Vue 3 (Composition API) + Vite 7.x
8
+ - 📦 自动集成 cmpt-huitu-ui 和 cmpt-huitu-utils
9
+ - 🎨 内置 Element Plus + Pinia + Vue Router
10
+ - 🔧 开箱即用的工程化配置(ESLint、Prettier、路径别名等)
11
+ - 📱 支持多页面应用(MPA)
12
+ - 🎯 TypeScript 友好(可选)
13
+
14
+ ## 📦 安装
15
+
16
+ ### 全局安装(推荐)
17
+
18
+ ```bash
19
+ npm install -g cmpt-huitu-cli
20
+ ```
21
+
22
+ ### 使用 npx(无需安装)
23
+
24
+ ```bash
25
+ npx cmpt-huitu-cli create my-project
26
+ ```
27
+
28
+ ## 🚀 快速开始
29
+
30
+ ### 创建新项目
31
+
32
+ ```bash
33
+ # 使用 npx(推荐)
34
+ npx cmpt-huitu-cli create my-project
35
+
36
+ # 或全局安装后
37
+ huitu create my-project
38
+
39
+ # 指定创建目录
40
+ huitu create my-project --dir /path/to/dir
41
+ ```
42
+
43
+ ### 启动项目
44
+
45
+ ```bash
46
+ cd my-project
47
+ pnpm install # 或 npm install
48
+ pnpm dev # 或 npm run dev
49
+ ```
50
+
51
+ ## 📁 生成的项目结构
52
+
53
+ ```
54
+ my-project/
55
+ ├── public/ # 静态资源
56
+ ├── src/
57
+ │ ├── assets/ # 资源文件
58
+ │ ├── components/ # 组件
59
+ │ ├── routers/ # 路由配置
60
+ │ ├── services/ # API 服务
61
+ │ ├── stores/ # Pinia 状态管理
62
+ │ ├── styles/ # 样式文件
63
+ │ ├── utils/ # 工具函数
64
+ │ └── views/ # 页面视图
65
+ ├── vite.config.js # Vite 配置
66
+ └── package.json
67
+ ```
68
+
69
+ ## 🎯 内置功能
70
+
71
+ ### 路径别名
72
+
73
+ 已配置以下路径别名(可在 `vite.config.js` 和 `jsconfig.json` 中查看):
74
+
75
+ - `@` → `./src`
76
+ - `@components` → `./src/components`
77
+ - `@views` → `./src/views`
78
+ - `@stores` → `./src/stores`
79
+ - `@utils` → `./src/utils`
80
+ - `@services` → `./src/services`
81
+ - `@assets` → `./src/assets`
82
+ - `@styles` → `./src/styles`
83
+
84
+ ### 样式系统
85
+
86
+ - 自动注入共享样式变量和 mixin(来自 cmpt-huitu-ui)
87
+ - 支持 SCSS
88
+ - 支持主题切换(浅色/深色)
89
+
90
+ ### 状态管理
91
+
92
+ - 集成 Pinia
93
+ - 延迟实例化模式(避免 Pinia 未初始化错误)
94
+ - 示例 Store 代码
95
+
96
+ ## 📚 使用 cmpt-huitu-ui 和 cmpt-huitu-utils
97
+
98
+ 创建的项目已自动安装并配置好 cmpt-huitu-ui 和 cmpt-huitu-utils。
99
+
100
+ ### 使用 UI 组件
101
+
102
+ ```vue
103
+ <script setup>
104
+ import { HTable, ModuleTitle } from 'cmpt-huitu-ui'
105
+ </script>
106
+
107
+ <template>
108
+ <ModuleTitle title="模块标题" />
109
+ <HTable :data="tableData" />
110
+ </template>
111
+ ```
112
+
113
+ ### 使用工具函数
114
+
115
+ ```javascript
116
+ import { parseTime, cache, modal } from 'cmpt-huitu-utils'
117
+
118
+ // 时间处理
119
+ const time = parseTime(new Date())
120
+
121
+ // 缓存
122
+ cache.session.set('key', 'value')
123
+ const value = cache.session.get('key')
124
+
125
+ // 消息提示
126
+ modal.msgSuccess('操作成功')
127
+ ```
128
+
129
+ ## 🔧 配置说明
130
+
131
+ ### 环境变量
132
+
133
+ 创建 `.env.development` 和 `.env.production` 文件:
134
+
135
+ ```env
136
+ VITE_PORT=3001
137
+ VITE_PATH=/
138
+ VITE_MOCK=false
139
+ ```
140
+
141
+ ### 代理配置
142
+
143
+ 在 `vite.config.js` 中配置开发代理:
144
+
145
+ ```javascript
146
+ proxy: {
147
+ '/api': {
148
+ target: 'http://localhost:3000',
149
+ changeOrigin: true,
150
+ rewrite: (path) => path.replace(/^\/api/, '')
151
+ }
152
+ }
153
+ ```
154
+
155
+ ## 📖 更多文档
156
+
157
+ - [项目规则与架构指南](../../.lingma/rules/project_rule.md)
158
+ - [cmpt-huitu-ui 文档](../ui/README.md)
159
+ - [cmpt-huitu-utils 文档](../utils/README.md)
160
+ - [发布指南](./发布指南.md)
161
+
162
+ ## 🤝 贡献
163
+
164
+ 欢迎提交 Issue 和 Pull Request!
165
+
166
+ ## 📄 许可证
167
+
168
+ ISC
169
+
package/bin/huitu.js ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from 'commander'
4
+ import chalk from 'chalk'
5
+ import { create } from '../src/create.js'
6
+ import fs from 'fs-extra'
7
+ import path from 'path'
8
+ import { fileURLToPath } from 'url'
9
+
10
+ // 获取 package.json 版本号
11
+ const __filename = fileURLToPath(import.meta.url)
12
+ const __dirname = path.dirname(__filename)
13
+ const pkg = fs.readJsonSync(path.join(__dirname, '../package.json'))
14
+
15
+ const program = new Command()
16
+
17
+ program
18
+ .name('huitu')
19
+ .description('慧图前端工程化 CLI 工具')
20
+ .version(pkg.version)
21
+
22
+ program
23
+ .command('create <name>')
24
+ .description('创建一个新项目')
25
+ .option('-d, --dir <dir>', '指定项目创建目录(默认为当前目录)')
26
+ .action((name, options) => {
27
+ create(name, options.dir)
28
+ })
29
+
30
+ program.parse(process.argv)
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "cmpt-huitu-cli",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "description": "慧图前端项目工程化 CLI 工具",
6
+ "main": "index.js",
7
+ "bin": {
8
+ "huitu": "./bin/huitu.js"
9
+ },
10
+ "files": [
11
+ "bin",
12
+ "src",
13
+ "templates"
14
+ ],
15
+ "scripts": {
16
+ "test": "echo \"Error: no test specified\" && exit 1",
17
+ "prepublishOnly": "node -e \"console.log('请确保模板文件已包含在 templates/ 目录中')\""
18
+ },
19
+ "keywords": [
20
+ "cli",
21
+ "scaffold",
22
+ "vue3",
23
+ "vite",
24
+ "huitu",
25
+ "vue-cli"
26
+ ],
27
+ "author": "",
28
+ "license": "ISC",
29
+ "dependencies": {
30
+ "chalk": "^4.1.2",
31
+ "commander": "^11.1.0",
32
+ "fs-extra": "^11.2.0",
33
+ "inquirer": "^8.2.6"
34
+ },
35
+ "engines": {
36
+ "node": ">=16.0.0"
37
+ }
38
+ }
package/src/create.js ADDED
@@ -0,0 +1,127 @@
1
+ import fs from 'fs-extra'
2
+ import path from 'path'
3
+ import inquirer from 'inquirer'
4
+ import chalk from 'chalk'
5
+ import { fileURLToPath } from 'url'
6
+ import { getDependencyVersion } from './versions.js'
7
+
8
+ const __filename = fileURLToPath(import.meta.url)
9
+ const __dirname = path.dirname(__filename)
10
+
11
+ // 模板目录:从 CLI 包内获取模板(发布后模板会随包一起发布)
12
+ const TEMPLATE_DIR = path.resolve(__dirname, '../templates/default')
13
+
14
+ /**
15
+ * 创建项目
16
+ * @param {string} projectName - 项目名称
17
+ * @param {string} targetDir - 目标目录(可选,默认为当前目录下的项目名)
18
+ */
19
+ export async function create(projectName, targetDir) {
20
+ // 如果没有指定目标目录,使用当前工作目录
21
+ if (!targetDir) {
22
+ targetDir = path.resolve(process.cwd(), projectName)
23
+ } else {
24
+ targetDir = path.resolve(targetDir, projectName)
25
+ }
26
+
27
+ // 1. 检查模板目录是否存在
28
+ if (!fs.existsSync(TEMPLATE_DIR)) {
29
+ console.error(chalk.red(`✘ 模板目录不存在: ${TEMPLATE_DIR}`))
30
+ console.error(chalk.yellow('请确保 CLI 包已正确安装'))
31
+ return
32
+ }
33
+
34
+ // 2. 检查目标目录是否存在
35
+ if (fs.existsSync(targetDir)) {
36
+ const { action } = await inquirer.prompt([
37
+ {
38
+ name: 'action',
39
+ type: 'list',
40
+ message: `目标目录 ${chalk.cyan(targetDir)} 已存在,请选择操作:`,
41
+ choices: [
42
+ { name: '覆盖 (Overwrite)', value: 'overwrite' },
43
+ { name: '取消 (Cancel)', value: 'cancel' },
44
+ ],
45
+ },
46
+ ])
47
+
48
+ if (action === 'cancel') {
49
+ console.log(chalk.yellow('操作已取消'))
50
+ return
51
+ }
52
+
53
+ if (action === 'overwrite') {
54
+ console.log(chalk.yellow(`\n正在移除旧目录 ${targetDir}...`))
55
+ await fs.remove(targetDir)
56
+ }
57
+ }
58
+
59
+ // 3. 复制模板
60
+ console.log(chalk.blue(`\n正在创建项目 ${chalk.cyan(projectName)}...`))
61
+ try {
62
+ await fs.copy(TEMPLATE_DIR, targetDir, {
63
+ filter: (src) => {
64
+ // 过滤不需要的文件和目录
65
+ const basename = path.basename(src)
66
+ const relativePath = path.relative(TEMPLATE_DIR, src)
67
+
68
+ // 过滤 node_modules、dist、.git 等
69
+ if (['node_modules', 'dist', '.git', '.DS_Store'].includes(basename)) {
70
+ return false
71
+ }
72
+
73
+ return true
74
+ },
75
+ })
76
+ console.log(chalk.green('✔ 模板复制完成'))
77
+ } catch (err) {
78
+ console.error(chalk.red('✘ 模板复制失败:'), err)
79
+ return
80
+ }
81
+
82
+ // 4. 修改 package.json
83
+ try {
84
+ const pkgPath = path.join(targetDir, 'package.json')
85
+ const pkg = await fs.readJson(pkgPath)
86
+
87
+ // 更新项目名称(去掉 @huitu/ 前缀,让用户自由命名)
88
+ pkg.name = projectName
89
+ pkg.description = `${projectName} project created by cmpt-huitu-cli`
90
+
91
+ // 将 workspace 协议改为具体版本号(从 npm 安装)
92
+ // 使用语义化版本范围(如 ^1.0.0),允许小版本和补丁版本更新
93
+ if (pkg.dependencies) {
94
+ if (pkg.dependencies['@huitu/ui'] === 'workspace:*') {
95
+ pkg.dependencies['cmpt-huitu-ui'] = getDependencyVersion('cmpt-huitu-ui')
96
+ delete pkg.dependencies['@huitu/ui']
97
+ }
98
+ if (pkg.dependencies['@huitu/utils'] === 'workspace:*') {
99
+ pkg.dependencies['cmpt-huitu-utils'] = getDependencyVersion('cmpt-huitu-utils')
100
+ delete pkg.dependencies['@huitu/utils']
101
+ }
102
+ }
103
+
104
+ await fs.writeJson(pkgPath, pkg, { spaces: 2 })
105
+ console.log(chalk.green('✔ 配置更新完成'))
106
+ } catch (err) {
107
+ console.error(chalk.red('✘ 配置更新失败:'), err)
108
+ return
109
+ }
110
+
111
+ // 5. 完成提示
112
+ console.log(chalk.green(`\n🎉 项目 ${chalk.cyan(projectName)} 创建成功!`))
113
+ console.log(chalk.cyan('\n请运行以下命令启动项目:\n'))
114
+ console.log(chalk.white(` cd ${projectName}`))
115
+ console.log(chalk.white(` pnpm install # 或 npm install / yarn install`))
116
+ console.log(chalk.white(` pnpm dev # 或 npm run dev`))
117
+ console.log('')
118
+
119
+ // 6. 提示信息
120
+ console.log(chalk.cyan('\n📦 项目已配置以下依赖:'))
121
+ console.log(chalk.white(` cmpt-huitu-ui: ${getDependencyVersion('cmpt-huitu-ui')}`))
122
+ console.log(chalk.white(` cmpt-huitu-utils: ${getDependencyVersion('cmpt-huitu-utils')}`))
123
+ console.log('')
124
+ console.log(chalk.yellow('💡 提示:'))
125
+ console.log(chalk.yellow(' - 如果使用私有 npm 仓库,请先配置正确的 registry'))
126
+ console.log(chalk.yellow(' - 运行 npm install 时会自动安装 @huitu/ui 和 @huitu/utils\n'))
127
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @fileoverview 依赖包版本配置
3
+ * 用于 CLI 创建项目时指定 @huitu 包的版本
4
+ *
5
+ * 更新说明:
6
+ * - 当 @huitu/ui 或 @huitu/utils 发布新版本时,同步更新此文件
7
+ * - 使用语义化版本范围(如 ^1.0.0)允许小版本和补丁版本更新
8
+ */
9
+
10
+ export const DEPENDENCY_VERSIONS = {
11
+ 'cmpt-huitu-ui': '^1.0.0',
12
+ 'cmpt-huitu-utils': '^1.0.0',
13
+ }
14
+
15
+ /**
16
+ * 获取依赖包的推荐版本
17
+ * @param {string} packageName - 包名
18
+ * @returns {string} 版本号(如 '^1.0.0')
19
+ */
20
+ export function getDependencyVersion(packageName) {
21
+ return DEPENDENCY_VERSIONS[packageName] || 'latest'
22
+ }
23
+
@@ -0,0 +1,127 @@
1
+ # 慧图 Vue3 项目模板
2
+
3
+ ## 📋 项目简介
4
+
5
+ 这是一个基于 Vue 3 + Vite + Element Plus 的标准项目模板,用于快速创建新的前端项目。
6
+
7
+ ## ✨ 核心特性
8
+
9
+ - ✅ **Vue 3.5**:使用 Composition API
10
+ - ✅ **Vite 7**:极速构建工具
11
+ - ✅ **Element Plus**:企业级 UI 组件库
12
+ - ✅ **Pinia**:Vue 3 官方状态管理
13
+ - ✅ **Vue Router**:官方路由管理器
14
+ - ✅ **@huitu/ui**:共享 UI 组件库
15
+ - ✅ **@huitu/utils**:共享工具函数库
16
+
17
+ ## 🚀 快速开始
18
+
19
+ ### 使用 CLI 工具创建项目
20
+
21
+ ```bash
22
+ # 在 Monorepo 根目录执行
23
+ pnpm huitu create <project-name>
24
+
25
+ # 例如
26
+ pnpm huitu create web-saas
27
+ ```
28
+
29
+ ### 手动创建项目
30
+
31
+ ```bash
32
+ # 1. 复制模板
33
+ cp -r apps/template apps/your-project-name
34
+
35
+ # 2. 修改 package.json 中的 name 字段
36
+ # 3. 安装依赖
37
+ pnpm install
38
+
39
+ # 4. 启动开发
40
+ pnpm --filter your-project-name dev
41
+ ```
42
+
43
+ ## 📁 项目结构
44
+
45
+ ```
46
+ template/
47
+ ├── public/ # 静态资源
48
+ │ ├── config/ # 配置文件
49
+ │ │ ├── envCfg.js # 环境配置模板
50
+ │ │ └── menuCfg.js # 菜单配置模板
51
+ │ ├── images/ # 图片资源
52
+ │ └── static/ # 静态文件
53
+ ├── src/
54
+ │ ├── assets/ # 资源文件
55
+ │ ├── components/ # 组件
56
+ │ ├── router/ # 路由配置
57
+ │ ├── services/ # API 服务
58
+ │ ├── stores/ # Pinia 状态管理
59
+ │ ├── styles/ # 样式文件
60
+ │ ├── utils/ # 工具函数
61
+ │ └── views/ # 页面视图
62
+ ├── vite/ # Vite 插件配置
63
+ ├── index.html # HTML 模板
64
+ └── vite.config.js # Vite 配置
65
+ ```
66
+
67
+ ## ⚙️ 配置说明
68
+
69
+ ### 环境配置
70
+
71
+ 编辑 `public/config/envCfg.js`,配置:
72
+
73
+ - API 地址
74
+ - 登录配置(SSO)
75
+ - 文件服务地址
76
+ - 地图服务地址(如需要)
77
+
78
+ ### 菜单配置
79
+
80
+ 编辑 `public/config/menuCfg.js`,配置项目菜单结构。
81
+
82
+ ## 📦 共享包使用
83
+
84
+ ### 使用 @huitu/ui 组件
85
+
86
+ ```javascript
87
+ import { HTable, ModuleTitle } from '@huitu/ui'
88
+ ```
89
+
90
+ ### 使用 @huitu/utils 工具
91
+
92
+ ```javascript
93
+ import { parseTime, cache, modal } from '@huitu/utils'
94
+ ```
95
+
96
+ ## 🔧 开发命令
97
+
98
+ ```bash
99
+ # 开发
100
+ pnpm --filter template dev
101
+
102
+ # 构建
103
+ pnpm --filter template build
104
+
105
+ # 预览
106
+ pnpm --filter template preview
107
+
108
+ # 代码检查
109
+ pnpm --filter template lint
110
+ ```
111
+
112
+ ## 📝 注意事项
113
+
114
+ 1. **配置修改**:创建新项目后,务必修改 `public/config/envCfg.js` 中的配置
115
+ 2. **项目信息**:修改 `index.html` 和登录页面中的项目名称
116
+ 3. **业务代码**:在 `src/views/` 中添加业务页面
117
+ 4. **样式变量**:如需使用已注释的样式变量,请添加对应的图片文件
118
+
119
+ ## 📚 相关文档
120
+
121
+ - [使用指南](../../web-saas使用指南.md)
122
+ - [模板检查清单](./模板项目检查清单.md)
123
+
124
+ ---
125
+
126
+ **版本**:1.0.0
127
+ **最后更新**:2026-01-04
@@ -0,0 +1,187 @@
1
+ import eslintParser from 'vue-eslint-parser'
2
+ import pluginVue from 'eslint-plugin-vue'
3
+ import pluginPrettier from 'eslint-plugin-prettier'
4
+ import configPrettier from 'eslint-config-prettier'
5
+ import { defineConfig, globalIgnores } from 'eslint/config'
6
+
7
+ // 声明被eslint忽略的全局变量
8
+ const global = {
9
+ acceptHMRUpdate: 'readonly',
10
+ computed: 'readonly',
11
+ createApp: 'readonly',
12
+ createPinia: 'readonly',
13
+ customRef: 'readonly',
14
+ defineAsyncComponent: 'readonly',
15
+ defineComponent: 'readonly',
16
+ defineStore: 'readonly',
17
+ effectScope: 'readonly',
18
+ getActivePinia: 'readonly',
19
+ getCurrentInstance: 'readonly',
20
+ getCurrentScope: 'readonly',
21
+ getCurrentWatcher: 'readonly',
22
+ h: 'readonly',
23
+ inject: 'readonly',
24
+ isProxy: 'readonly',
25
+ isReactive: 'readonly',
26
+ isReadonly: 'readonly',
27
+ isRef: 'readonly',
28
+ isShallow: 'readonly',
29
+ mapActions: 'readonly',
30
+ mapGetters: 'readonly',
31
+ mapState: 'readonly',
32
+ mapStores: 'readonly',
33
+ mapWritableState: 'readonly',
34
+ markRaw: 'readonly',
35
+ nextTick: 'readonly',
36
+ onActivated: 'readonly',
37
+ onBeforeMount: 'readonly',
38
+ onBeforeRouteLeave: 'readonly',
39
+ onBeforeRouteUpdate: 'readonly',
40
+ onBeforeUnmount: 'readonly',
41
+ onBeforeUpdate: 'readonly',
42
+ onDeactivated: 'readonly',
43
+ onErrorCaptured: 'readonly',
44
+ onMounted: 'readonly',
45
+ onRenderTracked: 'readonly',
46
+ onRenderTriggered: 'readonly',
47
+ onScopeDispose: 'readonly',
48
+ onServerPrefetch: 'readonly',
49
+ onUnmounted: 'readonly',
50
+ onUpdated: 'readonly',
51
+ onWatcherCleanup: 'readonly',
52
+ provide: 'readonly',
53
+ reactive: 'readonly',
54
+ readonly: 'readonly',
55
+ ref: 'readonly',
56
+ resolveComponent: 'readonly',
57
+ setActivePinia: 'readonly',
58
+ setMapStoreSuffix: 'readonly',
59
+ shallowReactive: 'readonly',
60
+ shallowReadonly: 'readonly',
61
+ shallowRef: 'readonly',
62
+ storeToRefs: 'readonly',
63
+ toRaw: 'readonly',
64
+ toRef: 'readonly',
65
+ toRefs: 'readonly',
66
+ toValue: 'readonly',
67
+ triggerRef: 'readonly',
68
+ unref: 'readonly',
69
+ useAttrs: 'readonly',
70
+ useCssModule: 'readonly',
71
+ useCssVars: 'readonly',
72
+ useId: 'readonly',
73
+ useLink: 'readonly',
74
+ useModel: 'readonly',
75
+ useRoute: 'readonly',
76
+ useRouter: 'readonly',
77
+ useSlots: 'readonly',
78
+ useTemplateRef: 'readonly',
79
+ watch: 'readonly',
80
+ watchEffect: 'readonly',
81
+ watchPostEffect: 'readonly',
82
+ watchSyncEffect: 'readonly',
83
+ window: 'readonly',
84
+ document: 'readonly',
85
+ location: 'readonly',
86
+ history‌: 'readonly',
87
+ screen‌‌: 'readonly',
88
+ URL: 'readonly',
89
+ setTimeout: 'readonly',
90
+ setInterval: 'readonly',
91
+ clearInterval: 'readonly',
92
+ clearTimeout: 'readonly',
93
+ console: 'readonly',
94
+ alert: 'readonly',
95
+ confirm: 'readonly',
96
+ atob: 'readonly',
97
+ btoa: 'readonly',
98
+ localStorage: 'readonly',
99
+ sessionStorage: 'readonly',
100
+ JSON: 'readonly',
101
+ Promise: 'readonly',
102
+ fetch: 'readonly',
103
+ process: 'readonly',
104
+ require: 'readonly',
105
+ Blob: 'readonly',
106
+ Image: 'readonly',
107
+ Cesium: 'readonly',
108
+ MetaGis: 'readonly',
109
+ URLSearchParams: 'readonly',
110
+ AbortController: 'readonly',
111
+ }
112
+
113
+ export default defineConfig([
114
+ // 0. 全局忽略目录配置,将忽略该目录及其子目录下的所有文件
115
+ globalIgnores(['node_modules/**', 'dist/**', 'mock/**', 'public/**', 'src/views/meta-base-layer/**', 'generate-api.js'], 'globaIgnoreDirectory'),
116
+
117
+ // 1. 基础配置:匹配.vue文件并指定解析器
118
+ {
119
+ files: ['src/**/*.js', 'src/**/*.vue'], // files: ['**/*.{js,vue}'],
120
+ // 以下忽略文件只是用于package.json中eslint全局校验格式化忽略的文件
121
+ ignores: ['*.yaml', '*.ts', '*.md', '*.txt', '*.prettierrc', '*.prettierignore'],
122
+ languageOptions: {
123
+ parser: eslintParser, // 使用vue-eslint-parser解析.vue文件
124
+ parserOptions: {
125
+ parser: '@babel/eslint-parser', // 解析<script>标签内的代码
126
+ ecmaVersion: 2021,
127
+ sourceType: 'module',
128
+ requireConfigFile: false, // 禁用Babel配置检查
129
+ },
130
+ globals: global,
131
+ },
132
+ },
133
+
134
+ // 2. 集成eslint-plugin-vue
135
+ {
136
+ plugins: {
137
+ vue: pluginVue, // 启用Vue插件
138
+ prettier: pluginPrettier,
139
+ },
140
+ rules: {
141
+ // "prettier/prettier": "error", // 全局启用 Prettier 校验
142
+ 'vue/multi-word-component-names': 'off', // 可选:关闭多单词组件名规则
143
+ },
144
+ },
145
+
146
+ // 3. 集成Prettier规则(关闭冲突规则)
147
+ {
148
+ ...configPrettier,
149
+ },
150
+
151
+ // 4. 自定义规则(可选)
152
+ {
153
+ rules: {
154
+ 'prettier/prettier': [
155
+ 'error',
156
+ {
157
+ printWidth: 150, // 每行代码宽度
158
+ singleQuote: true, // 使用单引号
159
+ semi: false, // 句尾分号
160
+ tabWidth: 2, // 缩进空格数
161
+ singleAttributePerLine: true, // 属性是否换行
162
+ vueIndentScriptAndStyle: true, // Vue 文件 script 和 style 缩进
163
+ trailingComma: 'es5', // 尾随逗号
164
+ bracketSpacing: true, // 对象字面量括号间距
165
+ bracketSameLine: false, // 箭头函数参数括号位置
166
+ },
167
+ ],
168
+ 'no-unused-vars': [
169
+ 'error',
170
+ {
171
+ vars: 'all', // 检测所有变量(默认)
172
+ varsIgnorePattern: '^(_|props|\\$)', // 忽略以(_|props|\\$) 开头的变量(如 _unused,$test,props)
173
+ args: 'all', // 检测函数参数
174
+ argsIgnorePattern: '^(_|event|evt)', // 忽略以 _ 开头的参数
175
+ caughtErrors: 'all', // 检测 catch 语句中的错误变量
176
+ caughtErrorsIgnorePattern: '^err', // 忽略catch 中以err开头的参数
177
+ ignoreRestSiblings: true, // 忽略解构剩余元素(如 const { a, ...rest } = obj; 中的 rest)
178
+ destructuredArrayIgnorePattern: '^_', // 数组解构中忽略以 _ 开头的元素
179
+ },
180
+ ],
181
+ 'no-undef': 'error', // 强制检测未声明变量
182
+ 'vars-on-top': 'error', // 强制变量声明在作用域顶部
183
+ 'block-scoped-var': 'error', // 防止块作用域变量泄漏
184
+ 'prefer-const': 'warn', // 优先使用 const
185
+ },
186
+ },
187
+ ])