Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
158 lines (158 loc) · 4.39 KB
/
Copy pathapp.js
File metadata and controls
158 lines (158 loc) · 4.39 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//app.js
var app = getApp();
// var wxh = require('../../utils/wxh.js');
App({
onLaunch: function () {
// 展示本地存储能力
var that = this;
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
that.getRoutineStyle();
},
globalData: {
routineStyle:'#ffffff',
uid: null,
openPages:'',
spid:0,
urlImages: '',
url: 'https://api.xzeu.com',
appname: "卓创商城"
},
getRoutineStyle:function(){
var that = this;
wx.request({
url: that.globalData.url + '/routine/login/get_routine_style',
method: 'post',
dataType : 'json',
success: function (res) {
that.globalData.routineStyle = res.data.data.routine_style;
that.setBarColor();
}
})
},
setBarColor:function(){
var that = this;
wx.setNavigationBarColor({
frontColor: '#000000',
backgroundColor: that.globalData.routineStyle,
})
},
setUserInfo : function(){
var that = this;
if (that.globalData.uid == null) {//是否存在用户信息,如果不存在跳转到首页
wx.showToast({
title: '用户信息获取失败',
icon: 'none',
duration: 1500,
})
setTimeout(function () {
wx.navigateTo({
url: '/pages/enter/enter',
})
}, 2000)
}
},
getUserInfo: function () {
var that = this;
wx.getUserInfo({
lang: 'zh_CN',
success: function (res) {
var userInfo = res.userInfo
wx.login({
success: function (res) {
if (res.code) {
userInfo.code = res.code;
userInfo.spid = that.globalData.spid;
// console.log(userInfo);
wx.request({
url: that.globalData.url + '/routine/login/index',
method: 'post',
dataType : 'json',
data: {
info: userInfo
},
success: function (res) {
that.globalData.uid = res.data.data.uid;
if (!res.data.data.status){
wx.redirectTo({
url: '/pages/login-status/login-status',
})
}
if (that.globalData.openPages != '') {
wx.reLaunch({
url: that.globalData.openPages
})
} else {
wx.switchTab({
url: '/pages/index/index'
})
}
},
fail: function () {
console.log('获取用户信息失败');
wx.navigateTo({
url: '/pages/enter/enter',
})
},
})
} else {
console.log('登录失败!' + res.errMsg)
}
},
fail: function () {
console.log('获取用户信息失败');
wx.navigateTo({
url: '/pages/enter/enter',
})
},
})
},
fail:function(){
console.log('获取用户信息失败');
wx.navigateTo({
url: '/pages/enter/enter',
})
},
})
},
getUserInfoEnter: function () {
var that = this;
wx.getUserInfo({
lang: 'zh_CN',
success: function (res) {
var userInfo = res.userInfo
wx.login({
success: function (res) {
if (res.code) {
userInfo.code = res.code;
userInfo.spid = that.globalData.spid;
wx.request({
url: that.globalData.url + '/routine/login/index',
method: 'post',
dataType : 'json',
data: {
info: userInfo
},
success: function (res) {
that.globalData.uid = res.data.data.uid;
if (that.globalData.openPages != '') {
wx.reLaunch({
url: that.globalData.openPages
})
} else {
wx.reLaunch({
url: '/pages/index/index'
})
}
}
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
}
})
},
})