king
2020-10-21 0b733984acbbc018511fba1ce3ce913d71639f64
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import axios from 'axios'
import md5 from 'md5'
 
import Utils from '@/utils'
 
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 = config.data || {}
  config.method = 'post'
  config.data.userid = 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({
          url: `/webapi/dostar/${DBS}`,
          data: {
            func: DBS
          }
        }).then(res => {
          if (res.status) {
            sessionStorage.setItem(DBS, JSON.stringify(res))
          }
          resolve(res)
        })
      })
    }
  }
 
  /**
   * @description 游客登录
   */
  loginSSO () {
    let param = {
      func: 's_visitor_login',
      timestamp: Utils.getCurrentTime(),
      SessionUid: localStorage.getItem('SessionUid'),
      TypeCharOne: 'pc'
    }
    
    param.LText = md5(window.btoa(localStorage.getItem('SessionUid') + param.timestamp))
    param.secretkey = md5(param.LText + 'mingke' + param.timestamp)
    param.appkey = window.GLOB.appkey
    param.rduri = window.GLOB.rduri.replace('webapi/dostars', 'webapi/dologon')
 
    return axios({
      url: '/webapi/dostar',
      data: param
    })
  }
 
  /**
   * @description 转接调用sso系统的dostars
   * @param {String} param 请求参数
   */
  setSSORequest (param) {
    param.appkey = window.GLOB.appkey
    param.rduri = window.GLOB.rduri
 
    param.userid = sessionStorage.getItem('UserID') || ''
    param.SessionUid = localStorage.getItem('SessionUid') || ''
    param.LoginUID = sessionStorage.getItem('LoginUID') || ''
 
    param.nonc = Utils.getuuid()
    
    let keys = Object.keys(param).sort()
    let values = ''
    keys.forEach(key => {
      if (key === 'rduri' || key === 't') return
      if (typeof(param[key]) === 'object') {
        values += key + JSON.stringify(param[key])
      } else {
        values += key + param[key]
      }
    })
    param.sign  = md5(values)
    param.t = new Date().getTime()
 
    return axios({
      url: `/webapi/dostar/${param.func}`,
      data: param
    })
  }
 
  /**
   * @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({
          url: `/webapi/dostar/${param.func}`,
          data: param
        }).then(res => {
          if (res.status) {
            sessionStorage.setItem(_param, JSON.stringify(res))
          }
          resolve(res)
        })
      })
    }
  }
 
  /**
   * @description 提交
   * @param {String} param 请求参数
   */
  setSubmit (param) {
    return axios({
      url: `/webapi/dostar/${param.func}`,
      data: param
    })
  }
}