forked from bingoogolapple/bga_issue_blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
executable file
·112 lines (99 loc) · 2.82 KB
/
main.js
File metadata and controls
executable file
·112 lines (99 loc) · 2.82 KB
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
import Vue from 'vue'
import axios from 'axios'
import {
Loading,
Message
} from 'element-ui'
Vue.use(Loading)
Vue.component(Message.name, Message)
Vue.prototype.$message = Message
import BgaBackTop from 'bga-back-top-vue'
Vue.use(BgaBackTop)
import lodash from 'lodash'
import moment from 'moment'
import marked from 'marked'
import highlight from 'highlight.js'
import 'highlight.js/styles/github.css'
import 'github-markdown-css/github-markdown.css'
import App from './App'
import store from './store'
import router from './router'
import './css/main.css'
import { gitHubApi, isGetUserInfo, queryParse, queryStringify } from './utils'
import { showMessage, successMessage, errorMessage, warningMessage, infoMessage } from './utils/toastUtil'
Vue.prototype._ = lodash
moment.locale('zh-cn')
Vue.prototype.$moment = moment
Vue.prototype.$http = axios
Vue.prototype.$highlight = highlight
Vue.prototype.$showMessage = showMessage
Vue.prototype.$successMessage = successMessage
Vue.prototype.$errorMessage = errorMessage
Vue.prototype.$warningMessage = warningMessage
Vue.prototype.$gitHubApi = gitHubApi
Vue.prototype.$infoMessage = infoMessage
Vue.prototype.$isGetUserInfo = isGetUserInfo
Vue.prototype.$queryParse = queryParse
Vue.prototype.$queryStringify = queryStringify
marked.setOptions({
renderer: new marked.Renderer(),
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: false,
smartLists: true,
smartypants: false,
highlight: function (code) {
return Vue.prototype.$highlight.highlightAuto(code).value
}
})
Vue.prototype.$marked = marked
/* eslint-disable no-new */
const vm = new Vue({
el: '#app',
router,
store,
template: '<App/>',
components: {App}
})
let loadingInstance
// request拦截器
axios.interceptors.request.use((config) => {
let isGetUserInfo = vm.$isGetUserInfo(vm, config)
if (!isGetUserInfo) {
loadingInstance = Loading.service({
text: '拼命加载中...'
})
}
return config
}, (error) => {
return Promise.reject(error)
})
// response拦截器
axios.interceptors.response.use((response) => {
let isGetUserInfo = vm.$isGetUserInfo(vm, response.config)
if (isGetUserInfo) {
return response
} else {
setTimeout(() => {
loadingInstance.close()
}, 500)
return response
}
}, (error) => {
let isGetUserInfo = vm.$isGetUserInfo(vm, error.config)
if (!isGetUserInfo) {
loadingInstance.close()
if (error.response) {
if (error.response.status === 401) {
vm.$warningMessage('登录信息已过期,请重新登录!')
} else if (error.response.status === 403) {
vm.$warningMessage('您操作的太频繁,请稍后再试!')
} else if (error.response.statusText) {
vm.$errorMessage(error.response.status + ' ' + error.response.statusText)
}
}
}
return Promise.reject(error)
})