king
2019-08-23 4deda573bfc6663c1793b29f60a6e1035d891520
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import axios from 'axios'
 
axios.defaults.baseURL = '/minkesoft/webapi/dostar'
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
axios.defaults.crossDomain = true
axios.defaults.withCredentials = true
 
axios.interceptors.request.use((config) => {
  // 在发送请求之前做些什么
  config.data == undefined ? config.data = {} : false
  config.method = 'post'
  config.data.userid = ''
  config.data = JSON.stringify(config.data)
  return config
}, (error) => {
  // 对请求错误做些什么
  return Promise.reject(error)
});
 
axios.interceptors.response.use((response) => {
  // 对响应数据做点什么
  // response.data = JSON.parse(response.data)
  return Promise.resolve(response.data)
}, (error) => {
  // 对响应错误做点什么
  return Promise.resolve(error)
});
 
export default class Service {
  constructor () {
 
  }
 
  /**
   * @description 获取官网基础数据,并缓存至session
   * @param {String} DBS 存储过程
   */
  getBaseData (DBS) {
    // let cachedata = sessionStorage.getItem(DBS)
    let cachedata = ''
    if (cachedata) {
      return Promise.resolve(JSON.parse(cachedata))
    } else {
      return new Promise(resolve => {
        axios({
          data: {
            func: DBS
          }
        }).then(res => {
          if (res.status) {
            sessionStorage.setItem(DBS, JSON.stringify(res))
          }
          resolve(res)
        })
      })
    }
  }
 
  /**
   * @description 获取官网基础数据,并缓存至session
   * @param {String} param 请求参数
   */
  getParamData (param) {
    let _param = JSON.stringify(param)
    // let cachedata = sessionStorage.getItem(_param)
    let cachedata = ''
    if (cachedata) {
      return Promise.resolve(JSON.parse(cachedata))
    } else {
      return new Promise(resolve => {
        axios({
          data: param
        }).then(res => {
          if (res.status) {
            sessionStorage.setItem(_param, JSON.stringify(res))
          }
          resolve(res)
        })
      })
    }
  }
 
  /**
   * @description 提交
   * @param {String} param 请求参数
   */
  setSubmit (param) {
    return axios({
      data: param
    })
  }
}