Browse Source

Mock模拟数据调整

daxiong.yang 7 years ago
parent
commit
70a79ab8a5
6 changed files with 21 additions and 13 deletions
  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
  },
91
  },
92
  externals: {
92
  externals: {
93
    // 打包生产环境时, 排除mockjs模拟数据组件
93
    // 打包生产环境时, 排除mockjs模拟数据组件
94
    mockjs: 'mockjs'
94
    mockjs: 'Mock'
95
  }
95
  }
96
}
96
}

+ 1 - 0
index.html

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

+ 0 - 1
package.json

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

+ 8 - 6
src/mock/index.js

1
import Mock from 'mockjs'
1
import Mock from 'mockjs'
2
import requestUrl from '@/api/requestUrl'
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
2
3
// 登录
3
// 登录
4
export function login () {
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
              'captcha': this.dataForm.captcha
77
              'captcha': this.dataForm.captcha
78
            }
78
            }
79
            API.common.login(params).then(({data}) => {
79
            API.common.login(params).then(({data}) => {
80
              console.log(data)
80
              if (data && data.code === 0) {
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
                this.$router.replace({ name: 'home' })
83
                this.$router.replace({ name: 'home' })
83
              } else {
84
              } else {
84
                this.getCaptcha()
85
                this.getCaptcha()