Skip to content

Commit 8a7556f

Browse files
committed
First command 10/17/21
0 parents  commit 8a7556f

Some content is hidden

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

82 files changed

+31204
-0
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[*.{js,jsx,ts,tsx,vue}]
2+
indent_style = space
3+
indent_size = 2
4+
trim_trailing_whitespace = true
5+
insert_final_newline = true

.env.development

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# just a flag
2+
ENV = 'development'
3+
4+
# base api
5+
VUE_APP_BASE_API = '/dev-api'

.env.production

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# just a flag
2+
ENV = 'production'
3+
4+
# base api
5+
VUE_APP_BASE_API = '/prod-api'

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.DS_Store
2+
node_modules
3+
/dist
4+
5+
6+
# local env files
7+
.env.local
8+
.env.*.local
9+
10+
# Log files
11+
npm-debug.log*
12+
yarn-debug.log*
13+
yarn-error.log*
14+
pnpm-debug.log*
15+
16+
# Editor directories and files
17+
.idea
18+
.vscode
19+
*.suo
20+
*.ntvs*
21+
*.njsproj
22+
*.sln
23+
*.sw?

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# vue-element-plus-admin [![Node.js CI](https://github.com/deadislove/vue-element-plus-admin/actions/workflows/node.js.yml/badge.svg?branch=main)](https://github.com/deadislove/vue-element-plus-admin/actions/workflows/node.js.yml)
2+
> vue 3 project with the element plus UI framework.
3+
4+
## Project startup
5+
```
6+
vue create vue-element-plus-admin
7+
```
8+
- **Vue project setting**
9+
> Vue CLI v4.5.13
10+
>
11+
> Please pick a preset: Manually select features
12+
>
13+
> Check the features needed for your project: Choose Vue version, Babel, Router, Vuex, CSS Pre-processors, Linter
14+
>
15+
> Choose a version of Vue.js that you want to start the project with 3.x
16+
>
17+
> Use history mode for router? (Requires proper server setup for index fallback in production) Yes
18+
>
19+
> Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with dart-sass)
20+
>
21+
> Pick a linter / formatter config: Standard
22+
>
23+
> Pick additional lint features: Lint on save
24+
>
25+
> Where do you prefer placing config for Babel, ESLint, etc.? In package.json
26+
>
27+
> Save this as a preset for future projects? No
28+
29+
- **Add the element plus UI framework to the Vue 3 project**
30+
```
31+
vue add element-plus
32+
```
33+
- **The element plus UI setting**
34+
> How do you want to import Element Plus? Fully import
35+
>
36+
> Do you want to overwrite the SCSS variables of Element Plus? Yes
37+
>
38+
> Choose the locale you want to load, the default locale is English (en) en
39+
>
40+
## Project setup
41+
```
42+
npm install
43+
```
44+
45+
### Compiles and hot-reloads for development
46+
```
47+
npm run serve
48+
```
49+
50+
### Compiles and minifies for production
51+
```
52+
npm run build
53+
```
54+
55+
### Lints and fixes files
56+
```
57+
npm run lint
58+
```
59+
60+
### Customize configuration
61+
See [Configuration Reference](https://cli.vuejs.org/config/).
62+
63+
## Reference

babel.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
presets: [
3+
'@vue/cli-plugin-babel/preset'
4+
]
5+
}

mock/index.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const Mock = require('mockjs')
2+
const { param2Obj } = require('./utils')
3+
4+
const user = require('./user')
5+
const role = require('./role')
6+
7+
const mocks = [
8+
...user,
9+
...role
10+
]
11+
12+
// for front mock
13+
// please use it cautiously, it will redefine XMLHttpRequest,
14+
// which will cause many of your third-party libraries to be invalidated(like progress event).
15+
function mockXHR () {
16+
// mock patch
17+
// https://github.com/nuysoft/Mock/issues/300
18+
Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send
19+
Mock.XHR.prototype.send = function () {
20+
if (this.custom.xhr) {
21+
this.custom.xhr.withCredentials = this.withCredentials || false
22+
23+
if (this.responseType) {
24+
this.custom.xhr.responseType = this.responseType
25+
}
26+
}
27+
this.proxy_send(...arguments)
28+
}
29+
30+
function XHR2ExpressReqWrap (respond) {
31+
return function (options) {
32+
let result = null
33+
if (respond instanceof Function) {
34+
const { body, type, url } = options
35+
// https://expressjs.com/en/4x/api.html#req
36+
result = respond({
37+
method: type,
38+
body: JSON.parse(body),
39+
query: param2Obj(url)
40+
})
41+
} else {
42+
result = respond
43+
}
44+
return Mock.mock(result)
45+
}
46+
}
47+
48+
for (const i of mocks) {
49+
Mock.mock(new RegExp(i.url), i.type || 'get', XHR2ExpressReqWrap(i.response))
50+
}
51+
}
52+
53+
module.exports = {
54+
mocks,
55+
mockXHR
56+
}

mock/mock-server.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
const chokidar = require('chokidar')
2+
const bodyParser = require('body-parser')
3+
const chalk = require('chalk')
4+
const path = require('path')
5+
const Mock = require('mockjs')
6+
7+
const mockDir = path.join(process.cwd(), 'mock')
8+
9+
function registerRoutes (app) {
10+
let mockLastIndex
11+
const { mocks } = require('./index.js')
12+
const mocksForServer = mocks.map(route => {
13+
return responseFake(route.url, route.type, route.response)
14+
})
15+
for (const mock of mocksForServer) {
16+
app[mock.type](mock.url, mock.response)
17+
mockLastIndex = app._router.stack.length
18+
}
19+
const mockRoutesLength = Object.keys(mocksForServer).length
20+
return {
21+
mockRoutesLength: mockRoutesLength,
22+
mockStartIndex: mockLastIndex - mockRoutesLength
23+
}
24+
}
25+
26+
function unregisterRoutes () {
27+
Object.keys(require.cache).forEach(i => {
28+
if (i.includes(mockDir)) {
29+
delete require.cache[require.resolve(i)]
30+
}
31+
})
32+
}
33+
34+
// for mock server
35+
const responseFake = (url, type, respond) => {
36+
return {
37+
url: new RegExp(`${process.env.VUE_APP_BASE_API}${url}`),
38+
type: type || 'get',
39+
response (req, res) {
40+
console.log('request invoke:' + req.path)
41+
res.json(Mock.mock(respond instanceof Function ? respond(req, res) : respond))
42+
}
43+
}
44+
}
45+
46+
module.exports = app => {
47+
// parse app.body
48+
// https://expressjs.com/en/4x/api.html#req.body
49+
app.use(bodyParser.json())
50+
app.use(bodyParser.urlencoded({
51+
extended: true
52+
}))
53+
54+
const mockRoutes = registerRoutes(app)
55+
var mockRoutesLength = mockRoutes.mockRoutesLength
56+
var mockStartIndex = mockRoutes.mockStartIndex
57+
58+
// watch files, hot reload mock server
59+
chokidar.watch(mockDir, {
60+
ignored: /mock-server/,
61+
ignoreInitial: true
62+
}).on('all', (event, path) => {
63+
if (event === 'change' || event === 'add') {
64+
try {
65+
// remove mock routes stack
66+
app._router.stack.splice(mockStartIndex, mockRoutesLength)
67+
68+
// clear routes cache
69+
unregisterRoutes()
70+
71+
const mockRoutes = registerRoutes(app)
72+
mockRoutesLength = mockRoutes.mockRoutesLength
73+
mockStartIndex = mockRoutes.mockStartIndex
74+
75+
console.log(chalk.magentaBright(`\n > Mock Server hot reload success! changed ${path}`))
76+
} catch (error) {
77+
console.log(chalk.redBright(error))
78+
}
79+
}
80+
})
81+
}

mock/role/index.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const Mock = require('mockjs')
2+
const { deepClone } = require('../utils')
3+
4+
const routes = deepClone([])
5+
6+
const roles = [
7+
{
8+
key: 'admin',
9+
name: 'admin',
10+
description: 'Super Administrator. Have access to view all pages.',
11+
routes: routes
12+
}
13+
]
14+
15+
module.exports = [
16+
// mock get all routes form server
17+
{
18+
url: '/routes',
19+
type: 'get',
20+
response: () => {
21+
return {
22+
code: 20000,
23+
data: routes
24+
}
25+
}
26+
},
27+
28+
// mock get all roles form server
29+
{
30+
url: '/roles',
31+
type: 'get',
32+
response: () => {
33+
return {
34+
code: 20000,
35+
data: roles
36+
}
37+
}
38+
},
39+
40+
// add role
41+
{
42+
url: '/role',
43+
type: 'post',
44+
response: {
45+
code: 20000,
46+
data: {
47+
key: Mock.mock('@integer(300, 5000)')
48+
}
49+
}
50+
},
51+
52+
// update role
53+
{
54+
url: '/role/[A-Za-z0-9]',
55+
type: 'put',
56+
response: {
57+
code: 20000,
58+
data: {
59+
status: 'success'
60+
}
61+
}
62+
},
63+
64+
// delete role
65+
{
66+
url: '/role/[A-Za-z0-9]',
67+
type: 'delete',
68+
response: {
69+
code: 20000,
70+
data: {
71+
status: 'success'
72+
}
73+
}
74+
}
75+
]

mock/role/routes.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Just a mock data
2+
3+
const constantRoutes = []
4+
5+
const asyncRoutes = []
6+
7+
module.exports = {
8+
constantRoutes,
9+
asyncRoutes
10+
}

0 commit comments

Comments
 (0)