From 7f7192f38a980c1acfd1b215442d0b56b61eef0c Mon Sep 17 00:00:00 2001 From: lb Date: Wed, 22 Mar 2023 15:04:00 +0800 Subject: [PATCH] =?UTF-8?q?add=20mockjs=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + public/index.html | 1 + src/main.js | 2 ++ src/mocks/carManagement/index.js | 16 ++++++++++++++++ src/mocks/index.js | 21 +++++++++++++++++++++ 5 files changed, 41 insertions(+) create mode 100644 src/mocks/carManagement/index.js create mode 100644 src/mocks/index.js diff --git a/package.json b/package.json index 6685203..59434b1 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "@vue/cli-plugin-babel": "^4.4.6", "@vue/cli-service": "^4.4.6", "element-theme-chalk": "^2.15.12", + "mockjs": "^1.1.0", "natives": "^1.1.6", "vue-template-compiler": "^2.6.11" }, diff --git a/public/index.html b/public/index.html index c743726..78aa5e3 100644 --- a/public/index.html +++ b/public/index.html @@ -41,6 +41,7 @@ // window.SITE_CONFIG['apiURL'] = 'http://192.168.1.49:8080/pms-am'; // tengyun // window.SITE_CONFIG['apiURL'] = 'http://192.168.1.62:8080/pms-am'; // tao window.SITE_CONFIG['apiURL'] = 'http://192.168.1.21:8080/pms-am'; // xv + // window.SITE_CONFIG['apiURL'] = 'http://localhost:3000/pms-am'; // xv <% } %> diff --git a/src/main.js b/src/main.js index 4f8e563..a16c25d 100644 --- a/src/main.js +++ b/src/main.js @@ -25,6 +25,8 @@ import cloneDeep from 'lodash/cloneDeep' import myComponents from 'code-brick-zj' +import mocks from './mocks' + Vue.config.productionTip = false Vue.use(Element, { diff --git a/src/mocks/carManagement/index.js b/src/mocks/carManagement/index.js new file mode 100644 index 0000000..05831f8 --- /dev/null +++ b/src/mocks/carManagement/index.js @@ -0,0 +1,16 @@ +import Mock from 'mockjs' +const Random = Mock.Random + +const pageViewModel = () => ({ + code: Random.county(), + stateDictValue: Random.integer(1, 7), + orderCode: Random.string(10), + posCode: Random.string(10), + startTime: Random.datetime(), + endTime: Random.datetime(), +}) +pageViewModel.url = '/pms/carHandle/pageView' +pageViewModel.method = 'post' + + +export default pageViewModel \ No newline at end of file diff --git a/src/mocks/index.js b/src/mocks/index.js new file mode 100644 index 0000000..86f5150 --- /dev/null +++ b/src/mocks/index.js @@ -0,0 +1,21 @@ +import Mock from 'mockjs' + +import carManagement from './carManagement' + + +function m(url, type, fn) { + return Mock.mock(window.SITE_CONFIG['apiURL'] + url, type, fn) +} + +m(carManagement.url, carManagement.type, opt => { + let { limit, page } = JSON.parse(opt.body) + // console.log('limit, page', limit, page, opt.body) + limit = 5 + return { + code: 0, + data: { + list: Array(limit).fill(null).map(carManagement), + total: limit * page + 10 + } + } +}) \ No newline at end of file