Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
master-coder-ll committed Apr 15, 2023
1 parent b63d7de commit 95fe6f1
Show file tree
Hide file tree
Showing 26 changed files with 315 additions and 202 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017-present PanJiaChen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
13 changes: 11 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
module.exports = {
presets: [
'@vue/app'
]
// https://github.com/vuejs/vue-cli/tree/master/packages/@vue/babel-preset-app
'@vue/cli-plugin-babel/preset'
],
'env': {
'development': {
// babel-plugin-dynamic-import-node plugin only does one thing by converting all import() to require().
// This plugin can significantly increase the speed of hot updates, when you have a large number of pages.
// https://panjiachen.github.io/vue-element-admin-site/guide/advanced/lazy-loading.html
'plugins': ['dynamic-import-node']
}
}
}
25 changes: 25 additions & 0 deletions docAssets/vue-element-admin-simplify.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions mock/article.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Mock from 'mockjs'
const Mock = require('mockjs')

const List = []
const count = 100
Expand All @@ -18,7 +18,7 @@ for (let i = 0; i < count; i++) {
forecast: '@float(0, 100, 2, 2)',
importance: '@integer(1, 3)',
'type|1': ['CN', 'US', 'JP', 'EU'],
'status|1': ['published', 'draft', 'deleted'],
'status|1': ['published', 'draft'],
display_time: '@datetime',
comment_disabled: true,
pageviews: '@integer(300, 5000)',
Expand All @@ -27,9 +27,9 @@ for (let i = 0; i < count; i++) {
}))
}

export default [
module.exports = [
{
url: '/article/list',
url: '/vue-element-admin/article/list',
type: 'get',
response: config => {
const { importance, type, title, page = 1, limit = 20, sort } = config.query
Expand Down Expand Up @@ -58,7 +58,7 @@ export default [
},

{
url: '/article/detail',
url: '/vue-element-admin/article/detail',
type: 'get',
response: config => {
const { id } = config.query
Expand All @@ -74,7 +74,7 @@ export default [
},

{
url: '/article/pv',
url: '/vue-element-admin/article/pv',
type: 'get',
response: _ => {
return {
Expand All @@ -92,7 +92,7 @@ export default [
},

{
url: '/article/create',
url: '/vue-element-admin/article/create',
type: 'post',
response: _ => {
return {
Expand All @@ -103,7 +103,7 @@ export default [
},

{
url: '/article/update',
url: '/vue-element-admin/article/update',
type: 'post',
response: _ => {
return {
Expand Down
30 changes: 10 additions & 20 deletions mock/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Mock from 'mockjs'
import { param2Obj } from '../src/utils'
const Mock = require('mockjs')
const { param2Obj } = require('./utils')

import user from './user'
import role from './role'
import article from './article'
import search from './remote-search'
const user = require('./user')
const role = require('./role')
const article = require('./article')
const search = require('./remote-search')

const mocks = [
...user,
Expand All @@ -16,7 +16,7 @@ const mocks = [
// 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() {
function mockXHR() {
// mock patch
// https://github.com/nuysoft/Mock/issues/300
Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send
Expand Down Expand Up @@ -54,17 +54,7 @@ export function mockXHR() {
}
}

// 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))
}
}
module.exports = {
mocks,
mockXHR
}

export default mocks.map(route => {
return responseFake(route.url, route.type, route.response)
})
25 changes: 19 additions & 6 deletions mock/mock-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ const chokidar = require('chokidar')
const bodyParser = require('body-parser')
const chalk = require('chalk')
const path = require('path')
const Mock = require('mockjs')

const mockDir = path.join(process.cwd(), 'mock')

function registerRoutes(app) {
let mockLastIndex
const { default: mocks } = require('./index.js')
for (const mock of mocks) {
const { mocks } = require('./index.js')
const mocksForServer = mocks.map(route => {
return responseFake(route.url, route.type, route.response)
})
for (const mock of mocksForServer) {
app[mock.type](mock.url, mock.response)
mockLastIndex = app._router.stack.length
}
const mockRoutesLength = Object.keys(mocks).length
const mockRoutesLength = Object.keys(mocksForServer).length
return {
mockRoutesLength: mockRoutesLength,
mockStartIndex: mockLastIndex - mockRoutesLength
Expand All @@ -27,10 +31,19 @@ function unregisterRoutes() {
})
}

module.exports = app => {
// es6 polyfill
require('@babel/register')
// for mock server
const responseFake = (url, type, respond) => {
return {
url: new RegExp(`${process.env.VUE_APP_BASE_API}${url}`),
type: type || 'get',
response(req, res) {
console.log('request invoke:' + req.path)
res.json(Mock.mock(respond instanceof Function ? respond(req, res) : respond))
}
}
}

module.exports = app => {
// parse app.body
// https://expressjs.com/en/4x/api.html#req.body
app.use(bodyParser.json())
Expand Down
8 changes: 4 additions & 4 deletions mock/remote-search.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Mock from 'mockjs'
const Mock = require('mockjs')

const NameList = []
const count = 100
Expand All @@ -10,10 +10,10 @@ for (let i = 0; i < count; i++) {
}
NameList.push({ name: 'mock-Pan' })

export default [
module.exports = [
// username search
{
url: '/search/user',
url: '/vue-element-admin/search/user',
type: 'get',
response: config => {
const { name } = config.query
Expand All @@ -30,7 +30,7 @@ export default [

// transaction list
{
url: '/transaction/list',
url: '/vue-element-admin/transaction/list',
type: 'get',
response: _ => {
return {
Expand Down
Loading

0 comments on commit 95fe6f1

Please sign in to comment.