开源项目分析代码
开源项目分析代码
开源项目分析代码
官网地址: ruoyi

前端代码

首页

1
2
#首页主界面:  src/views/index.vue
#布局页面: src/layout/index.vue

页面查询缓存

01)配置代码规范prettier

当前node的环境node V16.16.0

文件01.editorconfig

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# http://editorconfig.org

root = true

[*] # 表示所有文件适用
charset = utf-8 # 设置文件字符集为 utf-8
indent_style = space # 缩进风格(tab | space)
indent_size = 2 # 缩进大小
end_of_line = lf # 控制换行类型(lf | cr | crlf)
trim_trailing_whitespace = true # 去除行首的任意空白字符
insert_final_newline = false # 始终在文件末尾插入一个新行

[*.md] # 表示仅 md 文件适用以下规则
max_line_length = off
trim_trailing_whitespace = false

文件02.eslintignore

1
2
3
4
5
6
7
8
node_modules
dist
dist-staging
.vscode
bin/*
package-lock.json
CHANGELOG.en-US.md
!.*

文件03.eslintrc.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const { defineConfig } = require('eslint-define-config')
// ESlint 配置
module.exports = defineConfig({
root: true,
env: {
browser: true,
node: true,
// es6: true,
es2022: true,
'vue/setup-compiler-macros': true // 开启setup语法糖环境
},
parser: 'vue-eslint-parser',
parserOptions: {
// parser: 'vue-eslint-parser',
ecmaVersion: 'latest',
sourceType: 'module' // 使用 ES 模块
},
extends: [
'plugin:vue/vue3-recommended', // vue3 的规则
'plugin:vue/recommended', // vue2语法可用的规则
'eslint:recommended', // 引入标准 Eslint 规则,或者使用 Airbnb 规则
'prettier',
// prettier 的推荐规则
// 注意,它必须放在数组的最后 ,因为它可以保证能够覆盖前面的那些配置,也就可以解决 与eslint 的冲突
'plugin:prettier/recommended'
],
// add your custom rules here
// it is base on https://github.com/vuejs/eslint-config-vue
// 0 关闭 1 警告 2 错误
// vue 校验规则:https://eslint.vuejs.org/rules/
rules: {
'vue/no-v-model-argument': 0, // 关闭 v-model 不能带参数的校验
'vue/multi-word-component-names': 0, // 关闭组件名必须是多个单词的限制
'no-undef': 0, // 关闭未引入的 Vue 定义方法的限制 因为 auto-import 不需要引入 ref 等
'vue/no-multiple-template-root': 0, // 关闭限制 template 只能有一个根元素的限制Vue3 组件支持多个根节点
'vue/require-default-prop': 0, // 关闭 props 要求默认值
'vue/attribute-hyphenation': 0, // 关闭自定义属性必须使用中划线的规则
'vue/v-on-event-hyphenation': 0, // 关闭自定义事件必须使用中划线的规则
'vue/no-mutating-props': 0, // 关闭不能修改 v-model 绑定的 props 的规则,因为 element 用 v-model 绑定显示隐藏的 visible
'object-curly-spacing': ['error', 'always'], // 对象前后要加空格 { a: 1 }
'vue/no-v-for-template-key': 0 // 关闭template上v-for不能添加key的限制(Vue3支持)
}
})

文件04.npmrc

1
engine-strict = true

文件05.prettierignore

1
2
3
4
5
6
7
8
9
.vscode/
bin/
dist/
dist-staging/
node_modules/
/public/*
**/*.svg
**/*.sh
*.html

文件06.prettierrc.js

1
2
3
4
5
6
7
8
9
10
11
12
13
module.exports = {
semi: false,
singleQuote: true,
printWidth: 100,
tabWidth: 2,
useTabs: false,
trailingComma: 'none',
arrowParens: 'avoid',
vueIndentScriptAndStyle: true,
endOfLine: 'auto',
proseWrap: 'never',
htmlWhitespaceSensitivity: 'strict'
}

文件07package.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"scripts": {
"dev": "vite",
"build:prod": "vite build",
"build:stage": "vite build --mode staging",
"preview": "vite preview --open chrome",
"lint": "eslint --fix --ext .js --ext .vue src/views"
},

"devDependencies": {
"babel-eslint": "^10.1.0",
"eslint": "^8.52.0",
"eslint-config-prettier": "^9.0.0",
"eslint-define-config": "^1.24.1",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-vue": "^9.17.0",
"prettier": "^3.0.3",
"vue-eslint-parser": "^9.3.2"
}
1
2
3
4
5
6
7
8
9
#命令安装
npm install babel-eslint --save-dev
npm install eslint --save-dev
npm install eslint-config-prettier --save-dev
npm install eslint-define-config --save-dev
npm install eslint-plugin-prettier --save-dev
npm install eslint-plugin-vue --save-dev
npm install prettier --save-dev
npm install vue-eslint-parser --save-dev

最后配置webstorm

1
2
3
#01) 打开set配置 -> ESLint 把下面2个选项都选择
Automatic ESLint configuration
Run eslint --fix on save

02) 精简配置代码规范 prettier

当前node的环境node V20.15.1

1
2
3
"devDependencies": {
"prettier": "^2.8.7",
}

文件01.prettierignore

1
2
3
4
5
6
7
8
9
.vscode/
bin/
dist/
dist-staging/
node_modules/
/public/*
**/*.svg
**/*.sh
*.html

文件02.prettierrc.js

1
2
3
4
5
6
7
8
9
10
11
12
13
module.exports = {
semi: false,
singleQuote: true,
printWidth: 100,
tabWidth: 2,
useTabs: false,
trailingComma: 'none',
arrowParens: 'avoid',
vueIndentScriptAndStyle: true,
endOfLine: 'auto',
proseWrap: 'never',
htmlWhitespaceSensitivity: 'strict'
}

最后配置webstorm中的prettier

1
2
3
#01) 打开set配置 ->  Languages & Frameworks -> JavaScript -> Prettier
Automatic Prettier configuration
Run on save All actions save...

vue-echarts 使用

1
2
3
4
5
6
7
8
9
10
11
12
13
01) 安装依赖 vue-echarts
02) main.js 引入

// 导入图表库
import ECharts from 'vue-echarts'
import { use } from 'echarts/core'
// 全局导入图表库模块 减少打包体积
// CanvasRenderer 和 GridComponent是每个模块必须的
import { CanvasRenderer } from 'echarts/renderers'
import { GridComponent } from 'echarts/components'
use([CanvasRenderer, GridComponent])
const app = createApp(App)
app.component('VChart', ECharts) // 全局挂载图表组件

vite代理图片地址

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// demo, 代理api, 同时代理一个文件地址
// 原因在,开发阶段, 后端返回的地址不带 api, 这时候直接访问不到

// 后端地址需要给 api, 但是这时候前端地址中没有api, 这时候需要代理 profilePath 这个路径
// 把 http://localhost:8282/profilePath/upload/001.png
// 代理成为 http://localhost:8282/api/profilePath/upload/001.png

server: {
port: 8282,
host: true,
// open: true,
proxy: {
// https://cn.vitejs.dev/config/#server-proxy
'^/api': {
target: 'http://localhost:8182',
changeOrigin: true
// rewrite: (p) => p.replace(/^\/api/, '')
},
'/profilePath': {
target: 'http://localhost:8182',
changeOrigin: true,
// *** 把 profilePath 代理成为 api/profilePath *****
rewrite: p => p.replace(/^\/profilePath/, 'api/profilePath')
}
}
},

上传图片组件使用

1
2
3
4
5
 const feiUrl = ref('/profilePath/upload/2024/05/19/001_20240519171820A004.png')


图片地址: {{ feiUrl }}
<ImageUpload v-model="feiUrl" />

按钮主题色

1
2
// 文件 src/store/modules/settings.js 中
theme: storageSetting.theme || '#4180b3',

页面名称修改

1
2
const newRoute = Object.assign({}, route, { title: '编辑标签' })
store.dispatch('tagsView/updateVisitedView', newRoute)

底部

没有了