diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100755 index 00000000..1a114bc0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,33 @@ +--- +name: Bug report(报告问题) +about: Create a report to help us improve +--- + + + +## Bug report(问题描述) + +#### Steps to reproduce(问题复现步骤) + + +#### Screenshot or Gif(截图或动态图) + + +#### Link to minimal reproduction(最小可在线还原demo) + + + +#### Other relevant information(格外信息) +- Your OS: +- Node.js version: +- vue-element-admin version: diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100755 index 00000000..c33d10d4 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,7 @@ +--- +name: Feature Request(新功能建议) +about: Suggest an idea for this project +--- + +## Feature request(新功能建议) + diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md new file mode 100755 index 00000000..96be4532 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/question.md @@ -0,0 +1,14 @@ +--- +name: Question(提问) +about: Asking questions about use +--- + +## Question(提问) + + diff --git a/build/index.js b/build/index.js index baf3807a..0c57de2a 100644 --- a/build/index.js +++ b/build/index.js @@ -26,7 +26,7 @@ if (process.env.npm_config_preview || rawArgv.includes('--preview')) { app.listen(port, function () { console.log(chalk.green(`> Preview at http://localhost:${port}${publicPath}`)) if (report) { - console.log(chalk.green(`> Report at http://localhost:${port}${publicPath}/report.html`)) + console.log(chalk.green(`> Report at http://localhost:${port}${publicPath}report.html`)) } }) diff --git a/mock/index.js b/mock/index.js index 7d9609ab..08cdc471 100644 --- a/mock/index.js +++ b/mock/index.js @@ -1,11 +1,23 @@ import Mock from 'mockjs' -import mocks from './mocks' import { param2Obj } from '../src/utils' -const MOCK_API_BASE = '/mock' +import user from './user' +import role from './role' +import article from './article' +import search from './remoteSearch' +const mocks = [ + ...user, + ...role, + ...article, + ...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() { - // 修复在使用 MockJS 情况下,设置 withCredentials = true,且未被拦截的跨域请求丢失 Cookies 的问题 + // mock patch // https://github.com/nuysoft/Mock/issues/300 Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send Mock.XHR.prototype.send = function() { @@ -42,9 +54,10 @@ export function mockXHR() { } } +// for mock server const responseFake = (url, type, respond) => { return { - url: new RegExp(`${MOCK_API_BASE}${url}`), + url: new RegExp(`/mock${url}`), type: type || 'get', response(req, res) { res.json(Mock.mock(respond instanceof Function ? respond(req, res) : respond)) diff --git a/mock/mock-server.js b/mock/mock-server.js new file mode 100644 index 00000000..af7e67ee --- /dev/null +++ b/mock/mock-server.js @@ -0,0 +1,62 @@ +const chokidar = require('chokidar') +const bodyParser = require('body-parser') +const chalk = require('chalk') + +function registerRoutes(app) { + let mockStartIndex + const { default: mocks } = require('./index.js') + for (const mock of mocks) { + app[mock.type](mock.url, mock.response) + mockStartIndex = app._router.stack.length + } + const mockRoutesLength = Object.keys(mocks).length + return { + mockRoutesLength: mockRoutesLength, + mockStartIndex: mockStartIndex - mockRoutesLength + } +} + +function unregisterRoutes() { + Object.keys(require.cache).forEach(i => { + if (i.includes('/mock')) { + delete require.cache[require.resolve(i)] + } + }) +} + +module.exports = app => { + // es6 polyfill + require('@babel/register') + + // parse app.body + // http://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(('./mock'), { + ignored: 'mock/mock-server.js', + persistent: true, + ignoreInitial: true + }).on('all', (event, path) => { + if (event === 'change' || event === 'add') { + // 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}`)) + } + }) +} diff --git a/mock/mocks.js b/mock/mocks.js deleted file mode 100644 index 84a25ddc..00000000 --- a/mock/mocks.js +++ /dev/null @@ -1,12 +0,0 @@ -import user from './user' -import role from './role' -import article from './article' -import search from './remoteSearch' - -export default [ - ...user, - ...role, - ...article, - ...search -] - diff --git a/mock/role/routes.js b/mock/role/routes.js index d8eaf42a..14413d48 100644 --- a/mock/role/routes.js +++ b/mock/role/routes.js @@ -19,7 +19,7 @@ export const constantRoutes = [ }, { path: '/auth-redirect', - component: 'views/login/authredirect', + component: 'views/login/authRedirect', hidden: true }, { diff --git a/package.json b/package.json index 887d66f8..541f1cd2 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "@babel/core": "7.0.0", "@babel/register": "7.0.0", "@vue/cli-plugin-babel": "3.5.3", + "@vue/cli-plugin-eslint": "3.5.1", "@vue/cli-plugin-unit-jest": "3.5.3", "@vue/cli-service": "3.5.3", "@vue/test-utils": "1.0.0-beta.29", @@ -81,6 +82,7 @@ "babel-eslint": "10.0.1", "babel-jest": "23.6.0", "chalk": "2.4.2", + "chokidar": "2.1.5", "connect": "3.6.6", "eslint": "5.15.3", "eslint-plugin-vue": "5.2.2", diff --git a/src/components/DndList/index.vue b/src/components/DndList/index.vue index a4643c0a..23ca006e 100644 --- a/src/components/DndList/index.vue +++ b/src/components/DndList/index.vue @@ -2,7 +2,7 @@