File tree Expand file tree Collapse file tree 11 files changed +124
-15
lines changed Expand file tree Collapse file tree 11 files changed +124
-15
lines changed Original file line number Diff line number Diff line change 3
3
module . exports = {
4
4
devServer : 'http://localhost:3000' ,
5
5
proServer : 'http://localhost:3000' ,
6
- token : 'X-BLACKCAT-TOKEN' ,
7
6
} ;
Original file line number Diff line number Diff line change
1
+ export const API_PRE = '/api/v1' ;
2
+
3
+ /* 处理接口地址前缀 */
4
+ export function stringifPath ( path : string ) {
5
+ return API_PRE + path ;
6
+ }
Original file line number Diff line number Diff line change 1
1
import { internalFetch , deletx } from '@/util/fetch' ;
2
+ import { saveLogin , loginOut as logout } from '@/util/session' ;
3
+ import { stringifPath } from './index' ;
2
4
3
5
const PATH = '/auth/token' ;
4
6
5
7
/* 登陆 */
6
8
export function login ( username : string , password : string ) {
7
- return internalFetch ( 'POST' ) ( true ) ( PATH , {
9
+ return internalFetch ( 'POST' ) ( true ) ( stringifPath ( PATH ) , {
8
10
body : { username, password } ,
11
+ } ) . then ( ( res ) => {
12
+ saveLogin ( res . token ) ;
9
13
} ) ;
10
14
}
11
15
12
16
/* 退出 */
13
17
export function loginOut ( ) {
14
- return deletx ( PATH ) ;
18
+ return deletx ( stringifPath ( PATH ) ) . then ( logout ) ;
15
19
}
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <div class =" loading" :class =" {showing}" >
3
+ <app-icon link =" #icon-loading" :iconStyle =" iconStyle" />
4
+ </div >
5
+ </template >
6
+
7
+ <script lang="ts">
8
+ import { Component , Vue } from ' vue-property-decorator' ;
9
+ import AppIcon from ' @/components/AppIcon.vue' ;
10
+
11
+ @Component ({
12
+ components: {
13
+ AppIcon ,
14
+ },
15
+ })
16
+ export default class Loading extends Vue {
17
+ private showing: boolean = false ;
18
+ private get iconStyle() {
19
+ return {
20
+ width: ' 100%' ,
21
+ height: ' 100%' ,
22
+ display: this .showing ? ' block' : ' none' ,
23
+ animation: this .showing
24
+ ? ' circle_rotating 1.2s linear infinite forwards'
25
+ : ' none' ,
26
+ };
27
+ }
28
+ public show() {
29
+ this .showing = true ;
30
+ return () => {
31
+ this .showing = false ;
32
+ };
33
+ }
34
+ }
35
+ </script >
36
+ <style lang="scss" scoped>
37
+ @import ' ../../scss/theme.scss' ;
38
+ @import ' ../../scss/_px2px.scss' ;
39
+
40
+ .loading {
41
+ position : fixed ;
42
+ top : 50% ;
43
+ left : 50% ;
44
+ transform : translate (-50% , -50% );
45
+ color : $themeMain ;
46
+ width : 64px ;
47
+ height : 64px ;
48
+ }
49
+ </style >
50
+
Original file line number Diff line number Diff line change
1
+ import Vue , { VueConstructor , PluginObject } from 'vue' ;
2
+ import Loading from './Loading.vue' ;
3
+
4
+ interface ShowFunc {
5
+ ( ) : ( ) => void ;
6
+ }
7
+
8
+ const plugin : PluginObject < { } > = {
9
+ install ( Vue : VueConstructor , options = { } ) {
10
+ const CONSTRUCTOR = Vue . extend ( Loading ) ;
11
+ let cache : Vue & { show : ShowFunc } | null = null ;
12
+
13
+ function loading ( ) : ( ) => void {
14
+ let loading = cache || ( cache = new CONSTRUCTOR ( ) ) ;
15
+ if ( ! loading . $el ) {
16
+ let vm = loading . $mount ( ) ;
17
+ ( document . querySelector ( 'body' ) as HTMLElement ) . appendChild ( vm . $el ) ;
18
+ }
19
+ return loading . show ( ) ;
20
+ }
21
+ Vue . prototype . $loading = loading ;
22
+ } ,
23
+ } ;
24
+
25
+ export default plugin ;
Original file line number Diff line number Diff line change
1
+ import Vue from 'vue' ;
2
+
3
+ interface LoadingFunc {
4
+ ( ) : ( ) => void ;
5
+ }
6
+
7
+ declare module 'vue/types/vue' {
8
+ interface Vue {
9
+ $loading : LoadingFunc ;
10
+ }
11
+ }
Original file line number Diff line number Diff line change 1
1
import Vue from 'vue' ;
2
2
import Toast from './Toast' ;
3
+ import Loading from './Loading' ;
3
4
4
5
Vue . use ( Toast ) ;
6
+ Vue . use ( Loading ) ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import { hasLogin } from '@/util/session';
9
9
Vue . use ( Router ) ;
10
10
11
11
let router = new Router ( {
12
+ mode : 'history' ,
12
13
routes : [
13
14
{
14
15
path : '/' ,
Original file line number Diff line number Diff line change 13
13
height : 100% ;
14
14
width : 100% ;
15
15
}
16
- body {
16
+ body {
17
17
width : 16rem ;
18
18
margin : 0 auto ;
19
19
}
20
+
21
+ @keyframes circle_rotating {
22
+ 0% {
23
+ transform : rotate (0 );
24
+ }
25
+ to {
26
+ transform : rotate (1turn );
27
+ }
28
+ }
Original file line number Diff line number Diff line change 1
1
/* fetch api */
2
2
3
3
import { getCookie } from '@/util/cookie' ;
4
- const { token } = require ( '../../.config.js' ) ;
4
+ import { TOKEN } from '@/util/session' ;
5
5
6
6
interface FetchParams {
7
7
body ?: { [ key : string ] : any } ;
@@ -28,7 +28,7 @@ export function internalFetch(type: 'GET' | 'POST' | 'DELETE') {
28
28
headers = headers instanceof Headers ? headers : new Headers ( ) ;
29
29
headers . set ( 'Content-Type' , 'application/json' ) ;
30
30
if ( ! isGetToken ) {
31
- headers . set ( token , getCookie ( token ) ) ;
31
+ headers . set ( TOKEN , getCookie ( TOKEN ) ) ;
32
32
}
33
33
let stringifyBody ;
34
34
if ( body ) {
You can’t perform that action at this time.
0 commit comments