-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed2bcc1
commit 0da8218
Showing
205 changed files
with
12,369 additions
and
1,783 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# http://editorconfig.org | ||
# https://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
ENV = 'production' | ||
|
||
# base api | ||
VUE_APP_BASE_API = '/api' | ||
VUE_APP_BASE_API = '/prod-api' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import Mock from 'mockjs' | ||
import { param2Obj } from '../src/utils' | ||
|
||
import user from './user' | ||
import role from './role' | ||
import search from './remote-search' | ||
|
||
const mocks = [ | ||
...user, | ||
...role, | ||
...search | ||
] | ||
|
||
// for front mock | ||
// please use it cautiously, it will redefine XMLHttpRequest, | ||
// which will cause many of your third-party libraries to be invalidated(like progress event). | ||
export function mockXHR() { | ||
// mock patch | ||
// https://github.com/nuysoft/Mock/issues/300 | ||
Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send | ||
Mock.XHR.prototype.send = function() { | ||
if (this.custom.xhr) { | ||
this.custom.xhr.withCredentials = this.withCredentials || false | ||
|
||
if (this.responseType) { | ||
this.custom.xhr.responseType = this.responseType | ||
} | ||
} | ||
this.proxy_send(...arguments) | ||
} | ||
|
||
function XHR2ExpressReqWrap(respond) { | ||
return function(options) { | ||
let result = null | ||
if (respond instanceof Function) { | ||
const { body, type, url } = options | ||
// https://expressjs.com/en/4x/api.html#req | ||
result = respond({ | ||
method: type, | ||
body: JSON.parse(body), | ||
query: param2Obj(url) | ||
}) | ||
} else { | ||
result = respond | ||
} | ||
return Mock.mock(result) | ||
} | ||
} | ||
|
||
for (const i of mocks) { | ||
Mock.mock(new RegExp(i.url), i.type || 'get', XHR2ExpressReqWrap(i.response)) | ||
} | ||
} | ||
|
||
// for mock server | ||
const responseFake = (url, type, respond) => { | ||
return { | ||
url: new RegExp(`/mock${url}`), | ||
type: type || 'get', | ||
response(req, res) { | ||
res.json(Mock.mock(respond instanceof Function ? respond(req, res) : respond)) | ||
} | ||
} | ||
} | ||
|
||
export default mocks.map(route => { | ||
return responseFake(route.url, route.type, route.response) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const chokidar = require('chokidar') | ||
const bodyParser = require('body-parser') | ||
const chalk = require('chalk') | ||
const path = require('path') | ||
|
||
const mockDir = path.join(process.cwd(), 'mock') | ||
|
||
function registerRoutes(app) { | ||
let mockLastIndex | ||
const { default: mocks } = require('./index.js') | ||
for (const mock of mocks) { | ||
app[mock.type](mock.url, mock.response) | ||
mockLastIndex = app._router.stack.length | ||
} | ||
const mockRoutesLength = Object.keys(mocks).length | ||
return { | ||
mockRoutesLength: mockRoutesLength, | ||
mockStartIndex: mockLastIndex - mockRoutesLength | ||
} | ||
} | ||
|
||
function unregisterRoutes() { | ||
Object.keys(require.cache).forEach(i => { | ||
if (i.includes(mockDir)) { | ||
delete require.cache[require.resolve(i)] | ||
} | ||
}) | ||
} | ||
|
||
module.exports = app => { | ||
// es6 polyfill | ||
require('@babel/register') | ||
|
||
// parse app.body | ||
// https://expressjs.com/en/4x/api.html#req.body | ||
app.use(bodyParser.json()) | ||
app.use(bodyParser.urlencoded({ | ||
extended: true | ||
})) | ||
|
||
const mockRoutes = registerRoutes(app) | ||
var mockRoutesLength = mockRoutes.mockRoutesLength | ||
var mockStartIndex = mockRoutes.mockStartIndex | ||
|
||
// watch files, hot reload mock server | ||
chokidar.watch(mockDir, { | ||
ignored: /mock-server/, | ||
ignoreInitial: true | ||
}).on('all', (event, path) => { | ||
if (event === 'change' || event === 'add') { | ||
try { | ||
// remove mock routes stack | ||
app._router.stack.splice(mockStartIndex, mockRoutesLength) | ||
|
||
// clear routes cache | ||
unregisterRoutes() | ||
|
||
const mockRoutes = registerRoutes(app) | ||
mockRoutesLength = mockRoutes.mockRoutesLength | ||
mockStartIndex = mockRoutes.mockStartIndex | ||
|
||
console.log(chalk.magentaBright(`\n > Mock Server hot reload success! changed ${path}`)) | ||
} catch (error) { | ||
console.log(chalk.redBright(error)) | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Mock from 'mockjs' | ||
|
||
const NameList = [] | ||
const count = 100 | ||
|
||
for (let i = 0; i < count; i++) { | ||
NameList.push(Mock.mock({ | ||
name: '@first' | ||
})) | ||
} | ||
NameList.push({ name: 'mock-Pan' }) | ||
|
||
export default [ | ||
// username search | ||
{ | ||
url: '/search/user', | ||
type: 'get', | ||
response: config => { | ||
const { name } = config.query | ||
const mockNameList = NameList.filter(item => { | ||
const lowerCaseName = item.name.toLowerCase() | ||
return !(name && lowerCaseName.indexOf(name.toLowerCase()) < 0) | ||
}) | ||
return { | ||
code: 20000, | ||
data: { items: mockNameList } | ||
} | ||
} | ||
}, | ||
|
||
// transaction list | ||
{ | ||
url: '/transaction/list', | ||
type: 'get', | ||
response: _ => { | ||
return { | ||
code: 20000, | ||
data: { | ||
total: 20, | ||
'items|20': [{ | ||
order_no: '@guid()', | ||
timestamp: +Mock.Random.date('T'), | ||
username: '@name()', | ||
price: '@float(1000, 15000, 0, 2)', | ||
'status|1': ['success', 'pending'] | ||
}] | ||
} | ||
} | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import Mock from 'mockjs' | ||
import { deepClone } from '../../src/utils/index.js' | ||
import { asyncRoutes, constantRoutes } from './routes.js' | ||
|
||
const routes = deepClone([...constantRoutes, ...asyncRoutes]) | ||
|
||
const roles = [ | ||
{ | ||
key: 'admin', | ||
name: 'admin', | ||
description: 'Super Administrator. Have access to view all pages.', | ||
routes: routes | ||
}, | ||
{ | ||
key: 'editor', | ||
name: 'editor', | ||
description: 'Normal Editor. Can see all pages except permission page', | ||
routes: routes.filter(i => i.path !== '/permission')// just a mock | ||
}, | ||
{ | ||
key: 'visitor', | ||
name: 'visitor', | ||
description: 'Just a visitor. Can only see the home page and the document page', | ||
routes: [{ | ||
path: '', | ||
redirect: 'dashboard', | ||
children: [ | ||
{ | ||
path: 'dashboard', | ||
name: 'Dashboard', | ||
meta: { title: 'dashboard', icon: 'dashboard' } | ||
} | ||
] | ||
}] | ||
} | ||
] | ||
|
||
export default [ | ||
// mock get all routes form server | ||
{ | ||
url: '/routes', | ||
type: 'get', | ||
response: _ => { | ||
return { | ||
code: 20000, | ||
data: routes | ||
} | ||
} | ||
}, | ||
|
||
// mock get all roles form server | ||
{ | ||
url: '/roles', | ||
type: 'get', | ||
response: _ => { | ||
return { | ||
code: 20000, | ||
data: roles | ||
} | ||
} | ||
}, | ||
|
||
// add role | ||
{ | ||
url: '/role', | ||
type: 'post', | ||
response: { | ||
code: 20000, | ||
data: { | ||
key: Mock.mock('@integer(300, 5000)') | ||
} | ||
} | ||
}, | ||
|
||
// update role | ||
{ | ||
url: '/role/[A-Za-z0-9]', | ||
type: 'put', | ||
response: { | ||
code: 20000, | ||
data: { | ||
status: 'success' | ||
} | ||
} | ||
}, | ||
|
||
// delete role | ||
{ | ||
url: '/role/[A-Za-z0-9]', | ||
type: 'delete', | ||
response: { | ||
code: 20000, | ||
data: { | ||
status: 'success' | ||
} | ||
} | ||
} | ||
] |
Oops, something went wrong.