Parcourir la Source

Mock模拟数据调整

daxiong.yang 7 ans auparavant
Parent
commit
70a79ab8a5
6 fichiers modifiés avec 21 ajouts et 13 suppressions
  1. 1 1
      build/webpack.base.conf.js
  2. 1 0
      index.html
  3. 0 1
      package.json
  4. 8 6
      src/mock/index.js
  5. 9 4
      src/mock/modules/common.js
  6. 2 1
      src/views/login/index.vue

+ 1 - 1
build/webpack.base.conf.js

@ -91,6 +91,6 @@ module.exports = {
91 91
  },
92 92
  externals: {
93 93
    // 打包生产环境时, 排除mockjs模拟数据组件
94
    mockjs: 'mockjs'
94
    mockjs: 'Mock'
95 95
  }
96 96
}

+ 1 - 0
index.html

@ -18,6 +18,7 @@
18 18
    </script>
19 19
  <% }else { %>
20 20
    <!-- 开发环境 -->
21
    <script src="https://cdn.bootcss.com/Mock.js/1.0.0/mock-min.js"></script>
21 22
    <script src="./static/config/index.js?v=<%=new Date().getTime()%>"></script>
22 23
  <% } %>
23 24
</head>

+ 0 - 1
package.json

@ -24,7 +24,6 @@
24 24
    "gulp-replace": "0.6.1",
25 25
    "gulp-shell": "0.6.5",
26 26
    "lodash": "4.17.5",
27
    "mockjs": "1.0.0",
28 27
    "vue": "2.5.2",
29 28
    "vue-cookie": "1.1.4",
30 29
    "vue-router": "3.0.1",

+ 8 - 6
src/mock/index.js

@ -1,11 +1,13 @@
1 1
import Mock from 'mockjs'
2 2
import requestUrl from '@/api/requestUrl'
3
import './modules/common'
3
// import * as common from './modules/common'
4 4
5
var data = {
6
  code: 0,
7
  token: Mock.Random.guid()
5
var addModule = (mods) => {
6
  for (var key in mods) {
7
    var mod = mods[key]()
8
    Mock.mock(requestUrl(mod.url), mod.type, mod.data)
9
  }
8 10
}
9
Mock.mock(requestUrl('/sys/login'), 'post', data)
10 11
11
export default Mock
12
addModule(require('./modules/common'))
13
// Mock.mock(requestUrl('/sys/login'), 'post', common.login)

+ 9 - 4
src/mock/modules/common.js

@ -2,9 +2,14 @@ import Mock from 'mockjs'
2 2
3 3
// 登录
4 4
export function login () {
5
  var res = {
6
    code: 1,
7
    name: 'daxiong'
5
  return {
6
    url: '/sys/login',
7
    type: 'post',
8
    data: {
9
      code: 0,
10
      expire: 60 * 60 * 12,
11
      msg: 'success',
12
      token: Mock.Random.guid()
13
    }
8 14
  }
9
  Mock.mock('/sys/login', 'post', res)
10 15
}

+ 2 - 1
src/views/login/index.vue

@ -77,8 +77,9 @@
77 77
              'captcha': this.dataForm.captcha
78 78
            }
79 79
            API.common.login(params).then(({data}) => {
80
              console.log(data)
80 81
              if (data && data.code === 0) {
81
                this.$cookie.set('token', data.token)
82
                this.$cookie.set('token', data.token, { expires: `${data.expire || 0}s` })
82 83
                this.$router.replace({ name: 'home' })
83 84
              } else {
84 85
                this.getCaptcha()