init
This commit is contained in:
59
src/config/http.js
Normal file
59
src/config/http.js
Normal file
@@ -0,0 +1,59 @@
|
||||
import axios from 'axios'
|
||||
import qs from 'qs'
|
||||
import { Dialog } from './utils.js'
|
||||
// import { Dialog, toast } from './utils.js'
|
||||
import store from '../vuex/store'
|
||||
import router from './../router'
|
||||
|
||||
axios.defaults.timeout = 50000
|
||||
// axios.defaults.retry = 5
|
||||
// axios.defaults.retryDelay = 10000
|
||||
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
|
||||
|
||||
axios.interceptors.request.use(
|
||||
config => {
|
||||
if (config.method === 'post') {
|
||||
if (!config.data.flag) {
|
||||
config.data = qs.stringify(config.data)
|
||||
} else {
|
||||
config.data = config.data.formData
|
||||
}
|
||||
}
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
Dialog('错误的传参')
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
axios.interceptors.response.use(
|
||||
response => {
|
||||
return Promise.resolve(response)
|
||||
},
|
||||
error => {
|
||||
// toast(error.message)
|
||||
router.push({
|
||||
path: '/500',
|
||||
query: {redirect: router.currentRoute.fullPath}
|
||||
})
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
export const post = (params) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.post(`${store.getters.baseUrl}/wdk?action=wdk.pub&method=call_service&ajaxparam=` + new Date().getTime(), params)
|
||||
.then(response => {
|
||||
// if (response.data.code === '0') {
|
||||
// Dialog(response.data.desc)
|
||||
// }
|
||||
resolve(response.data)
|
||||
}, error => {
|
||||
reject(error.message)
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
12
src/config/rem.js
Normal file
12
src/config/rem.js
Normal file
@@ -0,0 +1,12 @@
|
||||
(function (doc, win) {
|
||||
var docEl = doc.documentElement
|
||||
var resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize'
|
||||
var recalc = function () {
|
||||
var clientWidth = docEl.clientWidth
|
||||
if (!clientWidth) return
|
||||
docEl.style.fontSize = 100 * (clientWidth / 800) + 'px'
|
||||
}
|
||||
if (!doc.addEventListener) return
|
||||
win.addEventListener(resizeEvt, recalc, false)
|
||||
doc.addEventListener('DOMContentLoaded', recalc, false)
|
||||
})(document, window)
|
||||
71
src/config/utils.js
Normal file
71
src/config/utils.js
Normal file
@@ -0,0 +1,71 @@
|
||||
import store from '../vuex/store'
|
||||
|
||||
/**
|
||||
* 弹出框
|
||||
*/
|
||||
export const Dialog = (str) => {
|
||||
store.dispatch('showAlert', true)
|
||||
store.dispatch('alertMsg', str)
|
||||
setTimeout(() => {
|
||||
store.dispatch('showAlert', false)
|
||||
}, 30000)
|
||||
}
|
||||
|
||||
/**
|
||||
* 提示框
|
||||
*/
|
||||
export const toast = (str) => {
|
||||
store.dispatch('showToast', true)
|
||||
store.dispatch('toastMsg', str)
|
||||
setTimeout(() => {
|
||||
store.dispatch('showToast', false)
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储localStorage
|
||||
*/
|
||||
export const setStore = (name, content) => {
|
||||
if (!name) return
|
||||
if (typeof content !== 'string') {
|
||||
content = JSON.stringify(content)
|
||||
}
|
||||
window.localStorage.setItem(name, content)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取localStorage
|
||||
*/
|
||||
export const getStore = name => {
|
||||
if (!name) return
|
||||
return window.localStorage.getItem(name)
|
||||
}
|
||||
|
||||
/**
|
||||
* yy-mm-dd
|
||||
*/
|
||||
export const dateFtt = date => {
|
||||
if (date == null) {
|
||||
return ''
|
||||
}
|
||||
let year = date.getFullYear()
|
||||
let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
|
||||
let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
/**
|
||||
* yy-mm-dd hh:mm:ss
|
||||
*/
|
||||
export const dateTimeFtt = date => {
|
||||
if (date == null) {
|
||||
return ''
|
||||
}
|
||||
let year = date.getFullYear()
|
||||
let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
|
||||
let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
|
||||
let hh = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
|
||||
let mm = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
|
||||
let ss = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
|
||||
return `${year}-${month}-${day} ${hh}:${mm}:${ss}`
|
||||
}
|
||||
Reference in New Issue
Block a user