1
1
function formatNumber ( n ) {
2
- const str = n . toString ( )
3
- return str [ 1 ] ? str : `0${ str } `
2
+ const str = n . toString ( ) ;
3
+ return str [ 1 ] ? str : `0${ str } ` ;
4
4
}
5
5
6
6
export function formatTime ( date ) {
7
- const year = date . getFullYear ( )
8
- const month = date . getMonth ( ) + 1
9
- const day = date . getDate ( )
7
+ const year = date . getFullYear ( ) ;
8
+ const month = date . getMonth ( ) + 1 ;
9
+ const day = date . getDate ( ) ;
10
10
11
- const hour = date . getHours ( )
12
- const minute = date . getMinutes ( )
13
- const second = date . getSeconds ( )
11
+ const hour = date . getHours ( ) ;
12
+ const minute = date . getMinutes ( ) ;
13
+ const second = date . getSeconds ( ) ;
14
14
15
- const t1 = [ year , month , day ] . map ( formatNumber ) . join ( '/' )
16
- const t2 = [ hour , minute , second ] . map ( formatNumber ) . join ( ':' )
15
+ const t1 = [ year , month , day ] . map ( formatNumber ) . join ( "/" ) ;
16
+ const t2 = [ hour , minute , second ] . map ( formatNumber ) . join ( ":" ) ;
17
17
18
- return `${ t1 } ${ t2 } `
18
+ return `${ t1 } ${ t2 } ` ;
19
19
}
20
20
21
-
22
21
//-------------------------------------------------------------------------请求的封装
23
22
24
- const host = 'https://www.heyuhsuo.xyz/heyushuo' ;
25
- export {
26
- host
27
- }
23
+ const host = "http://118.25.222.68:5757/heyushuo" ;
24
+ export { host } ;
28
25
//请求封装
29
26
function request ( url , method , data , header = { } ) {
30
27
wx . showLoading ( {
31
- title : ' 加载中' //数据请求前loading
32
- } )
28
+ title : " 加载中" //数据请求前loading
29
+ } ) ;
33
30
return new Promise ( ( resolve , reject ) => {
34
31
wx . request ( {
35
32
url : host + url , //仅为示例,并非真实的接口地址
36
33
method : method ,
37
34
data : data ,
38
35
header : {
39
- ' content-type' : ' application/json' // 默认值
36
+ " content-type" : " application/json" // 默认值
40
37
} ,
41
- success : function ( res ) {
38
+ success : function ( res ) {
42
39
wx . hideLoading ( ) ;
43
- resolve ( res . data )
40
+ resolve ( res . data ) ;
44
41
} ,
45
- fail : function ( error ) {
42
+ fail : function ( error ) {
46
43
wx . hideLoading ( ) ;
47
- reject ( false )
44
+ reject ( false ) ;
48
45
} ,
49
- complete : function ( ) {
46
+ complete : function ( ) {
50
47
wx . hideLoading ( ) ;
51
48
}
52
- } )
53
- } )
49
+ } ) ;
50
+ } ) ;
54
51
}
55
52
export function get ( url , data ) {
56
- return request ( url , ' GET' , data )
53
+ return request ( url , " GET" , data ) ;
57
54
}
58
55
export function post ( url , data ) {
59
- return request ( url , ' POST' , data )
56
+ return request ( url , " POST" , data ) ;
60
57
}
61
58
62
59
//-------------------------------------------------------------------------请求的封装
63
60
64
-
65
61
//----------------------------------------------用户是否登录 未登录跳转到登录页面 -------------------------
66
62
67
-
68
63
export function toLogin ( ) {
69
- const userInfo = wx . getStorageSync ( ' userInfo' ) ;
64
+ const userInfo = wx . getStorageSync ( " userInfo" ) ;
70
65
if ( ! userInfo ) {
71
66
wx . navigateTo ( {
72
67
url : "/pages/login/main"
@@ -77,27 +72,23 @@ export function toLogin() {
77
72
}
78
73
79
74
export function login ( ) {
80
- const userInfo = wx . getStorageSync ( ' userInfo' ) ;
75
+ const userInfo = wx . getStorageSync ( " userInfo" ) ;
81
76
if ( userInfo ) {
82
77
return userInfo ;
83
78
}
84
79
}
85
80
86
81
//----------------------------------------------用户是否登录 未登录跳转到登录页面 -------------------------
87
82
88
-
89
83
export function getStorageOpenid ( ) {
90
84
const openId = wx . getStorageSync ( "openId" ) ;
91
85
if ( openId ) {
92
86
return openId ;
93
87
} else {
94
- return ''
88
+ return "" ;
95
89
}
96
90
}
97
91
98
-
99
-
100
-
101
92
export function getOpenid ( ) {
102
93
// wx.login({
103
94
// success: res => {
@@ -119,7 +110,6 @@ export function getOpenid() {
119
110
// } else {
120
111
// console.log('登录失败!' + res.errMsg)
121
112
// }
122
-
123
113
// },
124
114
// fail: () => {},
125
115
// complete: () => {}
0 commit comments