Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
肖康
/
cloudSystem
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1c250cc5
authored
May 18, 2021
by
肖康
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
x
parent
c1bea471
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
10 deletions
src/ajax/index.js
src/ajax/loading.js
src/main.js
src/ajax/index.js
View file @
1c250cc5
...
@@ -28,7 +28,8 @@ switch (envs) {
...
@@ -28,7 +28,8 @@ switch (envs) {
}
}
export
const
http
=
(
method
,
url
,
param
)
=>
{
export
const
http
=
(
method
,
url
,
param
,
loading
)
=>
{
//loading 默认加载loading 传1 不加载
param
=
param
&&
typeof
param
===
'object'
?
param
:
{};
param
=
param
&&
typeof
param
===
'object'
?
param
:
{};
let
token
=
Util
.
getCookie
(
'token'
)
||
''
;
let
token
=
Util
.
getCookie
(
'token'
)
||
''
;
const
config
=
{
const
config
=
{
...
@@ -39,7 +40,8 @@ export const http = (method, url, param) => {
...
@@ -39,7 +40,8 @@ export const http = (method, url, param) => {
}],
}],
headers
:
{
headers
:
{
'Authorization'
:
'Bearer '
+
token
'Authorization'
:
'Bearer '
+
token
}
},
loading
:(
loading
?
false
:
true
)
};
};
// post请求时需要设定Content-Type
// post请求时需要设定Content-Type
...
...
src/ajax/loading.js
0 → 100644
View file @
1c250cc5
import
Vue
from
'vue'
;
import
{
Loading
}
from
'element-ui'
;
Vue
.
use
(
Loading
)
let
loadingCount
=
0
;
let
loading
;
const
startLoading
=
()
=>
{
loading
=
Loading
.
service
({
lock
:
true
,
// text: '加载中……',
background
:
'rgba(255, 255, 255, 0)'
});
};
const
endLoading
=
()
=>
{
loading
.
close
();
};
export
const
showLoading
=
()
=>
{
if
(
loadingCount
===
0
)
{
startLoading
();
}
loadingCount
+=
1
;
};
export
const
hideLoading
=
()
=>
{
if
(
loadingCount
<=
0
)
{
return
;
}
loadingCount
-=
1
;
if
(
loadingCount
===
0
)
{
endLoading
();
}
};
\ No newline at end of file
src/main.js
View file @
1c250cc5
...
@@ -3,9 +3,10 @@ import App from "./App.vue";
...
@@ -3,9 +3,10 @@ import App from "./App.vue";
import
router
from
"./router"
;
import
router
from
"./router"
;
import
filters
from
'./filters'
import
filters
from
'./filters'
import
directive
from
'./directive'
import
directive
from
'./directive'
import
{
http
}
from
'./ajax/index.js'
;
import
{
http
}
from
'./ajax/index.js'
;
import
axios
from
'axios'
import
axios
from
'axios'
import
{
Message
}
from
'element-ui'
;
import
{
Message
}
from
'element-ui'
;
import
{
showLoading
,
hideLoading
}
from
'./ajax/loading'
;
import
Util
from
"./tool"
;
import
Util
from
"./tool"
;
//本地环境开启提示信息
//本地环境开启提示信息
...
@@ -24,7 +25,7 @@ Vue.use(directive);
...
@@ -24,7 +25,7 @@ Vue.use(directive);
//处理顶部导航TAB
//处理顶部导航TAB
router
.
afterEach
((
to
,
from
,
next
)
=>
{
router
.
afterEach
((
to
,
from
,
next
)
=>
{
if
(
to
.
path
==
"/"
||
to
.
path
==
"/login"
)
{
if
(
to
.
path
==
"/"
||
to
.
path
==
"/login"
)
{
return
return
}
}
let
tabOldArr
=
sessionStorage
.
getItem
(
'tabs'
);
let
tabOldArr
=
sessionStorage
.
getItem
(
'tabs'
);
...
@@ -38,13 +39,13 @@ router.afterEach((to, from, next) => {
...
@@ -38,13 +39,13 @@ router.afterEach((to, from, next) => {
if
(
tabNewJson
.
indexOf
(
JSON
.
stringify
({
if
(
tabNewJson
.
indexOf
(
JSON
.
stringify
({
path
:
to
.
path
,
path
:
to
.
path
,
title
:
to
.
meta
.
title
,
title
:
to
.
meta
.
title
,
query
:
to
.
query
query
:
to
.
query
}))
==
-
1
)
{
}))
==
-
1
)
{
console
.
log
(
tabOldJson
)
console
.
log
(
tabOldJson
)
tabOldJson
.
push
({
tabOldJson
.
push
({
path
:
to
.
path
,
path
:
to
.
path
,
title
:
to
.
meta
.
title
,
title
:
to
.
meta
.
title
,
query
:
to
.
query
query
:
to
.
query
})
})
}
}
}
else
{
}
else
{
...
@@ -52,21 +53,35 @@ router.afterEach((to, from, next) => {
...
@@ -52,21 +53,35 @@ router.afterEach((to, from, next) => {
{
{
path
:
to
.
path
,
path
:
to
.
path
,
title
:
to
.
meta
.
title
,
title
:
to
.
meta
.
title
,
query
:
to
.
query
query
:
to
.
query
}
}
]
]
}
}
if
(
tabOldJson
)
{
if
(
tabOldJson
)
{
sessionStorage
.
setItem
(
'tabs'
,
JSON
.
stringify
(
tabOldJson
));
sessionStorage
.
setItem
(
'tabs'
,
JSON
.
stringify
(
tabOldJson
));
}
}
});
});
axios
.
interceptors
.
request
.
use
((
config
)
=>
{
if
(
config
.
loading
){
showLoading
();
}
return
config
;
},
(
err
)
=>
{
return
Promise
.
reject
(
err
)
})
axios
.
interceptors
.
response
.
use
(
res
=>
{
axios
.
interceptors
.
response
.
use
(
res
=>
{
hideLoading
();
return
res
.
data
;
return
res
.
data
;
},
error
=>
{
},
error
=>
{
// Message('网络出现问题,请检查网络');
// Message('网络出现问题,请检查网络');
hideLoading
();
return
Promise
.
reject
(
new
Error
(
error
))
return
Promise
.
reject
(
new
Error
(
error
))
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment