Skip to content

Commit 5fc74dd

Browse files
committed
项目结构基座优化
1 parent c1dc731 commit 5fc74dd

File tree

12 files changed

+300
-232
lines changed

12 files changed

+300
-232
lines changed

.env.development

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ PORT = '8888'
1010
VUE_APP_BASE_API = '/dev-api'
1111

1212
# 代理
13-
VUE_APP_PROXY_API = '/'
13+
VUE_APP_PROXY_API = 'http://localhost:4000'
1414

1515
# 主要用于控制 Babel 对 JavaScript 模块(如 ES Modules)的转译行为。它的核心作用是解决某些模块系统(如 CommonJS 和 ES Modules)之间的兼容性问题,尤其是在依赖第三方库或优化构建时。
1616
# 该环境变量会强制 Babel 将所有 ES Modules 转换为 CommonJS 格式

.eslintrc.js

+5-13
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ module.exports = {
33
env: {
44
node: true,
55
},
6+
// extends 字段表示 继承一组预定义的 ESLint 规则配置
67
extends: ['plugin:vue/essential', 'eslint:recommended', '@vue/prettier'],
78
// 【parserOptions】扩展 ESLint 对 JavaScript 新语法和实验性特性的支持
89
parserOptions: {
9-
parser: 'babel-eslint',
10+
parser: '@babel/eslint-parser',
1011
ecmaFeatures: {
1112
// 支持装饰器
1213
legacyDecorators: true,
@@ -37,35 +38,26 @@ module.exports = {
3738

3839
rules: {
3940
'prettier/prettier': [
41+
// 使用eslint-plugin-prettier可以让Prettier规则作为ESLint的一部分运行,这样可以在代码检查时同时处理格式问题,简化工作流。
42+
// 'prettier/prettier':表示该规则由 eslint-plugin-prettier 插件提供,用于将 Prettier 的格式化规则作为 ESLint 规则运行。
4043
'error',
4144
{
4245
semi: false,
4346
singleQuote: true,
4447
tabWidth: 2,
45-
printWidth: 120,
4648
arrowParens: 'avoid',
4749
bracketSpacing: true,
4850
insertPragma: false,
49-
jsxBracketSameLine: false,
5051
jsxSingleQuote: false,
5152
proseWrap: 'preserve',
5253
quoteProps: 'as-needed',
5354
requirePragma: false,
5455
trailingComma: 'none',
55-
useTabs: false,
56+
useTabs: false, // 禁止使用 Tab 缩进,强制使用空格
5657
},
5758
],
5859
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
5960
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
60-
// 使用2个空格缩进
61-
indent: [
62-
'error',
63-
2,
64-
{
65-
SwitchCase: 1,
66-
flatTernaryExpressions: true,
67-
},
68-
],
6961
// 代码后不使用分号
7062
semi: ['error', 'never'],
7163
// 注释 // 或 /* 之后必须有一个空格

.prettierrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
module.exports = {
1414
semi: false,
1515
singleQuote: true,
16-
printWidth: 120,
16+
printWidth: 150,
1717
htmlWhitespaceSensitivity: 'ignore',
1818
bracketSameLine: true, // 用于控制HTML元素的闭合括号是否与最后一行的内容在同一行
1919
// 动态条件示例

README.md

+36
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,42 @@ bash ./deploy.sh
9595
- 富文本
9696
```
9797

98+
## 目录结构说明
99+
100+
```
101+
vue-cms/ 项目名称
102+
|-- node_modules #存放第三方依赖包(例如,执行npm i安装的依赖包)
103+
|-- public/ #静态资源目录
104+
| |-- favicon.ico #网站图标
105+
| |-- index.html #项目的入口文件
106+
|-- src/ #项目的源代码目录
107+
| |-- assets/ #静态资源目录,如图片、字体等
108+
| |-- components/ #可复用的 Vue 组件
109+
| |-- router/ #Vue Router 的路由配置
110+
| | |-- index.js #路由的主文件
111+
| |-- store/ #Vuex 的状态管理
112+
| | |-- index.js #状态管理的主文件
113+
| |-- views/ #页面目录
114+
| | |-- About.vue #关于页面
115+
| | |-- Home.vue #首页
116+
| |-- App.vue #根组件
117+
| |-- main.js #项目的入口文件
118+
|-- tests/ #测试文件
119+
|-- .env #环境变量(在所有的环境中被载入)
120+
|-- .env.development #环境变量(仅开发环境)
121+
|-- .env.production #环境变量(仅生成环境(构建打包的时候))
122+
|-- .eslintrc.js #ESLint 配置
123+
|-- .eslintignore #ESLint 忽略的文件
124+
|-- .gitignore #Git 忽略的文件
125+
|-- .prettierrc.js #prettier 配置
126+
|-- babel.config.js #Babel 插件的配置文件
127+
|-- jest.config.js #jest 配置
128+
|-- package-lock.json #npm 依赖的锁定文件
129+
|-- package.json #项目的元数据文件和 npm 脚本
130+
|-- README.md #项目的说明文件
131+
|-- vue.config.js #Vue CLI 配置文件,比如配置alias、devServer和configure Webpack等
132+
```
133+
98134
## 截图
99135

100136
![](./resource/screenhot3.png)

package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,23 @@
6161
"xlsx": "^0.12.12"
6262
},
6363
"devDependencies": {
64-
"@vue/cli-plugin-babel": "~5.0.0",
65-
"@vue/cli-plugin-eslint": "~5.0.0",
66-
"@vue/cli-plugin-router": "~5.0.0",
67-
"@vue/cli-plugin-unit-jest": "~5.0.0",
68-
"@vue/cli-plugin-vuex": "~5.0.0",
69-
"@vue/cli-service": "~5.0.0",
64+
"@babel/core": "7.24.7",
65+
"@babel/eslint-parser": "7.24.7",
66+
"@vue/cli-plugin-babel": "5.0.8",
67+
"@vue/cli-plugin-eslint": "5.0.8",
68+
"@vue/cli-plugin-router": "5.0.8",
69+
"@vue/cli-plugin-unit-jest": "5.0.8",
70+
"@vue/cli-plugin-vuex": "5.0.8",
71+
"@vue/cli-service": "5.0.8",
7072
"@vue/eslint-config-prettier": "^6.0.0",
7173
"@vue/test-utils": "^1.0.3",
72-
"babel-eslint": "^10.1.0",
7374
"eslint": "7.32.0",
7475
"eslint-plugin-prettier": "^3.1.3",
7576
"eslint-plugin-vue": "8.7.1",
7677
"prettier": "^3.5.3",
7778
"stylus": "^0.54.7",
7879
"stylus-loader": "^3.0.2",
7980
"svg-sprite-loader": "^5.0.0",
80-
"vue-loader": "^15.9.6",
8181
"vue-template-compiler": "2.7.16"
8282
},
8383
"engines": {

src/App.vue

+6-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66

77
<script>
88
export default {
9-
watch: {
10-
$route(to) {
11-
if(to.path.indexOf('/login') === -1) {
12-
13-
}
14-
}
15-
}
9+
watch: {
10+
$route(to) {
11+
if (to.path.indexOf('/login') === -1) {
12+
}
13+
},
14+
},
1615
}
1716
</script>
1817

src/layout/app-main.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ export default {
1313
name: 'app-main',
1414
data() {
1515
return {
16-
desc: '这里是右侧主界面'
16+
desc: '这里是右侧主界面',
1717
}
1818
},
1919
computed: {
2020
key() {
2121
return this.$route.path
22-
}
23-
}
22+
},
23+
},
2424
}
2525
</script>
2626

src/layout/sidebar/sidebar-item.vue

+15-21
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,12 @@
99
<router-link
1010
v-if="
1111
hasOneShowingChildren(item.children, item) &&
12-
(!onlyOneChild.children || onlyOneChild.noShowingChild) &&
13-
!item.alwaysShow
12+
(!onlyOneChild.children || onlyOneChild.noShowingChild) &&
13+
!item.alwaysShow
1414
"
15-
:to="resolvePath(onlyOneChild.path)"
16-
>
15+
:to="resolvePath(onlyOneChild.path)">
1716
<el-menu-item :index="item.path">
18-
<item
19-
:icon="item.children[0].meta.icon"
20-
:title="item.children[0].meta.title"
21-
></item>
17+
<item :icon="item.children[0].meta.icon" :title="item.children[0].meta.title"></item>
2218
</el-menu-item>
2319
</router-link>
2420

@@ -32,8 +28,7 @@
3228
:item="child"
3329
:base-path="resolvePath(child.path)"
3430
:key="child.path"
35-
v-if="!child.hidden && child.children && child.children.length > 0"
36-
/>
31+
v-if="!child.hidden && child.children && child.children.length > 0" />
3732

3833
<router-link v-else :to="resolvePath(child.path)" :key="child.path">
3934
<el-menu-item :index="child.path">
@@ -46,27 +41,26 @@
4641
</div>
4742
</template>
4843
<script>
49-
import path from 'path'
5044
import Item from './item'
5145
export default {
5246
name: 'sidebar-item',
5347
components: {
54-
Item
48+
Item,
5549
},
5650
props: {
5751
// 一级路由对象
5852
item: {
5953
type: Object,
60-
required: true
54+
required: true,
6155
},
6256
basePath: {
6357
type: String,
64-
default: ''
65-
}
58+
default: '',
59+
},
6660
},
6761
data() {
6862
return {
69-
onlyOneChild: null
63+
onlyOneChild: null,
7064
}
7165
},
7266
methods: {
@@ -75,7 +69,7 @@ export default {
7569
// 1、后面要来判断,children 里面是不是只有一个
7670
// 2、亦或者没有 【比如 '/login' 这个 route 就没有 children】
7771
// 3、亦或者 children 里面的子路由大于1个
78-
const showingChildren = children.filter(item => {
72+
const showingChildren = children.filter((item) => {
7973
if (item.hidden) {
8074
return false
8175
} else {
@@ -94,7 +88,7 @@ export default {
9488
this.onlyOneChild = {
9589
...parent,
9690
path: '',
97-
noShowingChild: true
91+
noShowingChild: true,
9892
}
9993
return true
10094
}
@@ -103,11 +97,11 @@ export default {
10397
},
10498
resolvePath(routePath) {
10599
// console.log(path.resolve(this.basePath, routePath))
106-
return path.resolve(this.basePath, routePath)
107-
}
100+
return this.basePath + routePath
101+
},
108102
},
109103
created() {
110104
// console.log(this.basePath)
111-
}
105+
},
112106
}
113107
</script>

src/main.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import App from './App.vue'
1313
import store from './store'
1414
import router from './router'
1515

16-
1716
// 自定义的全局组件
1817
import Notification from '@/components/notification'
1918

@@ -27,8 +26,8 @@ import './permission'
2726
import './mock/index2'
2827

2928
Vue.use(ElementUI, {
30-
size: Cookies.get('size') || 'small',
31-
i18n: (key, value) => i18n.t(key, value)
29+
size: Cookies.get('size') || 'small',
30+
i18n: (key, value) => i18n.t(key, value),
3231
})
3332
Vue.use(Notification)
3433

@@ -38,5 +37,5 @@ new Vue({
3837
router,
3938
store,
4039
i18n,
41-
render: h => h(App)
40+
render: (h) => h(App),
4241
}).$mount('#app')

0 commit comments

Comments
 (0)