Skip to content

Commit 6da39a5

Browse files
author
wangzhaohui
committed
正式提交zcf-vue-admin工程,前端部分
1 parent 5bb5767 commit 6da39a5

File tree

664 files changed

+313033
-52
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

664 files changed

+313033
-52
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# zcf-vue-admin
22

3-
基于 zcf+vue 的单页面后台管理系统脚手架的模板
3+
基于 zcf+vue 的多页面后台管理系统脚手架的模板
44

55
## 安装
66

template/client/.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.{json,js,vue,html,css}]
12+
indent_size = 2
13+
14+
[*.{java}]
15+
indent_size = 4
16+
17+
[*.md]
18+
trim_trailing_whitespace = false

template/client/.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/dist/
2+
/*.js
3+
node_modules/**

template/client/.eslintrc.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"root": true,
3+
"parserOptions": {
4+
"parser": "babel-eslint"
5+
},
6+
"env": {
7+
"browser": true
8+
},
9+
"extends": [
10+
"plugin:vue/essential",
11+
"standard"
12+
],
13+
"plugins": [
14+
"vue"
15+
],
16+
"rules": {
17+
"generator-star-spacing": "off"
18+
}
19+
}

template/client/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Thumbs.db
2+
.DS_Store
3+
.idea
4+
.classpath
5+
.settings
6+
.svn
7+
npm-debug.log
8+
node_modules
9+
WEB-INF
10+
bower_components
11+
typings
12+
.project
13+
14+
/bin/
15+
/dist/
16+
/target/
17+
/appdata/
18+
19+
*.psd
20+
*.log
21+
*.tmp
22+
*.iws
23+
*.iml
24+
*.ipr

template/client/README.md

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
前端使用用Vue及ElementUI框架,后端实现RESTful规范的接口与前端进行交互。
55
前端工程要配合后端工程提供的接口来使用。
66

7-
### 运用到的工具:
8-
> gulp + webpack3 + babel
9-
### 使用到的库或框架:
10-
> vue 2.x + vue-router2.x + element-ui1.x + axios
7+
### 运用到的工具、框架或库:
8+
- **[VueJS 2.x](https://github.com/vuejs/vue)**
9+
- [Vue-router](https://github.com/vuejs/vue-router)
10+
- [axios](https://github.com/mzabriskie/axios)
11+
- **[Element UI 2.x](https://github.com/ElemeFE/element)**
12+
- [Babel](https://babeljs.io/)
13+
- [Webpack](https://github.com/webpack/webpack)
14+
- [gulp](https://gulpjs.com/)
1115

1216
## 开发流程:
1317
1. 克隆本脚手架前端工程、后端工程,配置数据库,导入示例数据。
@@ -17,25 +21,18 @@
1721
1. 前端取消axios-mock-adapter拦截,调试后端接口。
1822

1923
## 注意事项
20-
1. JS风格使用`JavaScript Standard Style`,建议使用VSCode作为js/vue的编辑器,并安装以下插件`EditorConfig for VSCode`,`Prettier-Standard - JavaScript formatter`,`JavaScript Standard Style`,`stylefmt`,`Vetur`
24+
1. JS风格使用`JavaScript Standard Style`,建议使用VSCode作为js/vue的编辑器,并安装以下插件`EditorConfig for VSCode` , `Prettier-Standard - JavaScript formatter` , `JavaScript Standard Style` , `stylefmt` , `Vetur`
2125
并且vscode的配置里要加下面的命令,防止格式化时自动加分号。
2226
` "prettier.singleQuote": true,`
2327
` "prettier.semi": false,`
2428
1. 在开发界面时使用ElementUI提供的栅格系统(24列),对界面进行响应式布局,以便移动端访问。
2529
1. ZCMS3.0的界面布局参考ZCMS2.4扁平风格,因为使用第三方控件库,所以不要求界面完全相同,但要布局类似(主要是控件的位置,和控件间的留白)。
2630
1. 不要使用ElementUI提供的图标组件,使用Font Awesome 图标。
2731
1. 后端接口符合RESTful规范
28-
1. 注意后端返回前端的数据,字段名同数据库中的字段名,并转为小写字母开头的驼峰式命名(2017年11月底对框架3.0作的调整),构造mock数据时也要注意这一点。
32+
1. 注意后端返回前端的数据,字段名同数据库中的字段名,并转为小写字母开头的驼峰式命名(2017年11月底对框架3.0作的调整,用 java.beans.Introspector.decapitalize 方法处理了字段名),构造mock数据时也要注意这一点。
2933
1. 工程编译时,`source`目录下的`lib``assets`目录下的文件会被直接复制到`dist`目录下。
30-
1. 不要提交`node_modules``dist`目录到svn工程里
31-
1. 写接口的同事可维护raml格式接口文档,并用raml2html生成html格式接口文档(也可以使用 http://apizza.cc 在线文档服务)
32-
1. 测试发现`vue-loader 13.x`不能正常编译vue文件,路由配置的视图载不进来,还没有找到原因,所以暂时用 `vue-loader 12.2.2`。如要升级`vue-loader`,一定要先作测试确认能正常编译vue文件,路由配置的视图能载入进来。
33-
1. 为了便于维护,对话框、页签等如果里面的内容比较多(超过30行),要独立成vue组件,尽量不要让一个vue组件的代码太多(超过500行超过20K)。
34-
1. 从后台请求的数据有分页的情况下,Request参数的约定:`pageindex` 第几页(从第1页开始);`pagesize` 每页返回多少行。Response中返回数据除了有列表外,还要有`total`供分页条显示总记录数。
35-
36-
少数特定的api也可以支持
37-
startindex 从第几行记录开始
38-
count 返回多少行记录
34+
1. 为了便于维护,对话框、页签等如果里面的内容比较多(超过30行),要独立成vue组件,尽量不要让一个vue组件的代码太多(超过500行超过20K),尽量把vue文件里的js移到单独的文件,便于使用编辑器的js校验/js格式化功能。vue文件中css代码行数较多时(超过50行),亦可将css移到单独的css文件。模板部分要保持在vue文件里,以使用Vetur插件的模板语法校验功能。
35+
1. 从后台请求的数据有分页的情况下,Request参数的约定:`pageIndex` 第几页(从第1页开始);`pageSize` 每页返回多少行。Response中返回数据除了有列表外,还要有`total`供分页条显示总记录数。特定的api也可以支持 `startIndex` 从第几行记录开始,`count` 返回多少行记录。
3936

4037
## 目录说明
4138
目录结构类似 https://github.com/kenberkeley/vue-demo/tree/master/src 但有简化、调整。
@@ -71,7 +68,7 @@ source
7168
└─views 所有页面视图
7269
│ app.vue app主视图组件
7370
74-
├─workspace 对应一级菜单“我的工作台
71+
├─catalog 对应一级菜单“栏目配置
7572
│ ......
7673
├─plugins 对应一级菜单“功能组件”
7774
│ ......
@@ -97,59 +94,47 @@ source
9794
```
9895

9996
## 开发与构建命令
100-
建议使用npm5或以上版本,建议使用淘宝的npm仓库镜像,安装npm包速度更快:
101-
97+
建议使用`yarn`最新版本,下载地址 https://yarnpkg.com/latest.msi
98+
建议使用淘宝的npm仓库镜像,安装npm包速度更快:
10299
``` bash
103-
# 更新npm到最新版
104-
npm install npm@latest -g
105-
106100
# 使用淘宝的npm仓库镜像
107101
npm config set registry https://registry.npm.taobao.org
108102

109103
```
110104

111105
``` bash
112106
# 安装依赖
113-
npm install
107+
yarn install
114108

115109
# 进入开发模式,启动前台应用,localhost:3000 。监听vue文件改动自动刷新浏览器
116-
npm run dev
110+
yarn run dev
117111

118112
# 构建文件到dist目录供发布
119-
npm run build
120-
121-
```
122-
```bash
123-
# 安装 api-designer 到全局
124-
npm install -g api-designer
125-
126-
# 使用 api-designer 编辑raml格式接口文档,编辑时是暂存在浏览器本地缓存中的,需要导出或复制到工程根目录下API.raml文件
127-
api-designer
128-
129-
# 安装 raml2html 到全局
130-
npm install -g raml2html
131-
132-
# 构建raml格式接口文档为html格式接口文档
133-
raml2html API.raml -o API.html
113+
yarn run build
134114

135115
```
136116

137117
## 链接
118+
JavaScript Standard 代码规范
119+
https://github.com/standard/standard/blob/master/docs/README-zhcn.md
120+
138121
VUE 2 文档
139122
https://cn.vuejs.org/v2/api/
140-
123+
141124
Vue Router 2 文档
142125
https://router.vuejs.org/zh-cn/
143-
126+
144127
Element-UI 文档
145128
http://element.eleme.io/#/zh-CN/component/layout
146-
129+
147130
axios 介绍
148131
https://github.com/mzabriskie/axios/blob/master/README.md
149-
132+
150133
Font Awesome 图标
151-
http://fontawesome.io/icons/
152-
134+
~~http://fontawesome.io/icons/~~
135+
https://www.thinkcmf.com/font/font_awesome/icons.html
136+
153137
RAML 1.0 文档
154138
https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md
155-
139+
140+

template/client/gulpfile.js

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
单页应用js构建任务
3+
改动根目录下的js,则编译被改动的js
4+
改动非根目录下js,vue,都只编译根目录下的app.js
5+
*/
6+
const gulp = require('gulp')
7+
const gutil = require('gulp-util')
8+
const watch = require('gulp-watch')
9+
const webpack = require('webpack')
10+
const del = require('del')
11+
const runSequence = require('run-sequence')
12+
const browserSync = require('browser-sync').create()
13+
const bsReload = browserSync.reload
14+
const replace = require('gulp-replace')
15+
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
16+
17+
const webpackConfig = require('./webpack.config.js')
18+
19+
const srcFiles = {
20+
lib: './source/lib/**/*',
21+
assets: './source/assets/**/*',
22+
htmlInRoot: './source/*.{html,ico}'
23+
}
24+
25+
const dist = './dist'
26+
27+
gulp.task('copyHtml', function () {
28+
return gulp.src([srcFiles.htmlInRoot], { base: './source' }).pipe(gulp.dest(dist))
29+
})
30+
gulp.task('buildHtml', function () {
31+
return gulp.src([srcFiles.htmlInRoot], { base: './source' })
32+
.pipe(replace('<!-- replace by NODE_ENV -->', '<script>var NODE_ENV = "' + process.env.NODE_ENV + '"</script>'))
33+
.pipe(replace('[replace by time]', ~~(Date.now()/10000)))
34+
.pipe(gulp.dest(dist))
35+
})
36+
gulp.task('copyAssets', function () {
37+
return gulp.src([srcFiles.lib, srcFiles.assets], { base: './source' }).pipe(gulp.dest(dist))
38+
})
39+
40+
// 在dev模式,监听js、根目录、assets目录下文件的更改,重新载入浏览器中的页面
41+
gulp.task('dev', function () {
42+
process.env.NODE_ENV = process.env.NODE_ENV || 'dev'
43+
runSequence(
44+
'copyAssets',
45+
'copyHtml',
46+
function () {
47+
browserSync.init(dist, {
48+
startPath: '/', // 服务器运行时打开的页面
49+
server: {
50+
baseDir: [dist]
51+
},
52+
reloadDebounce: 1000, // 重载事件后1秒后才允许下次重载
53+
watchOptions: {
54+
ignoreInitial: true,
55+
ignored: ['node_modules', 'WEB-INF']
56+
}
57+
})
58+
59+
webpackConfig.watch = true
60+
webpackConfig.devtool = 'cheap-source-map'
61+
webpackConfig.plugins.push(new webpack.DefinePlugin({
62+
NODE_ENV: JSON.stringify('dev')
63+
}))
64+
webpack(webpackConfig).watch(200, function (err, stats) {
65+
if (err) {
66+
throw new gutil.PluginError('webpack', err)
67+
}
68+
gutil.log('webpack', stats.toString({
69+
colors: true,
70+
chunks: false,
71+
hash: false,
72+
version: false
73+
}))
74+
runSequence('buildHtml', bsReload)
75+
})
76+
77+
watch([srcFiles.htmlInRoot], evt => {
78+
runSequence('buildHtml', bsReload)
79+
})
80+
watch([srcFiles.lib, srcFiles.assets, '!**/*.tmp', '!**/*._t_'], evt => {
81+
var path = evt.path
82+
gulp
83+
.src(path, { base: './source' })
84+
.pipe(gulp.dest(dist))
85+
.pipe(bsReload)
86+
})
87+
}
88+
)
89+
})
90+
// 在build模式,仅打包,不监听
91+
gulp.task('build', function () {
92+
process.env.NODE_ENV = process.env.NODE_ENV || 'prod'
93+
runSequence(
94+
'clean',
95+
'copyAssets',
96+
'buildHtml',
97+
function () {
98+
webpackConfig.watch = false
99+
webpackConfig.devtool = undefined
100+
webpackConfig.plugins.push(new webpack.DefinePlugin({
101+
NODE_ENV: 'prod'
102+
}), new BundleAnalyzerPlugin())
103+
webpack(webpackConfig, function (err, stats) {
104+
if (err) {
105+
throw new gutil.PluginError('webpack', err)
106+
}
107+
gutil.log(
108+
'webpack',
109+
stats.toString({
110+
colors: true,
111+
chunks: false,
112+
hash: false,
113+
version: false
114+
})
115+
)
116+
})
117+
}
118+
)
119+
})
120+
gulp.task('webserver', function () {
121+
browserSync.init(dist, {
122+
startPath: '/', // 服务器运行时打开的页面
123+
server: {
124+
baseDir: [dist]
125+
},
126+
reloadDebounce: 2000, // 重载事件后1秒后才允许下次重载
127+
port: 3000,
128+
ghostMode: false, // 点击,滚动和表单不要镜像到其他设备里
129+
codeSync: false // 不要发送任何文件改变事件给浏览器
130+
})
131+
})
132+
gulp.task('clean', function () {
133+
// 删除dist目录下的某些被编译出的文件
134+
return del(['./dist', '!./dist/node_modules/*', '!./dist/WEB-INF/*'])
135+
})

template/client/jsconfig.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"exclude": [
3+
"node_modules",
4+
"dist"
5+
],
6+
"compilerOptions": {
7+
"target": "ES6",
8+
"module": "es6",
9+
"lib": ["es6", "dom"]
10+
}
11+
}

0 commit comments

Comments
 (0)