-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.js
146 lines (142 loc) · 3.9 KB
/
store.js
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
import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from "vuex-persistedstate"
Vue.use(Vuex)
const store = new Vuex.Store({
plugins: [createPersistedState({
storage: {
getItem: key => uni.getStorageSync(key),
setItem: (key, value) => uni.setStorageSync(key, value),
removeItem: key => uni.removeStorageSync(key)
}
})],
state: {
count: 0,
user: {}
},
mutations: {
add(state, n = 1) {
state.count += n
},
updateUser(state, payload) {
state.user = payload;
}
},
actions: {
add({
commit
}, count) {
commit('add', count)
},
lineLogin({
commit
}, params) {
const {
clientId,
baseUrl
} = params;
let response_type = 'code';
let redirectUri = `${baseUrl}/user/line/callback`;
let state = '12345abcde';
let scope = 'profile%20openid';
let nonce = '09876xyz';
window.location.href = 'https://access.line.me/oauth2/v2.1/authorize?response_type=' +
response_type +
'&client_id=' + clientId +
'&redirect_uri=' + redirectUri +
'&state=' + state +
'&scope=' + scope +
'&nonce=' + nonce;
},
async bindEtc({
commit
}, params) {
const {
baseUrl,
token,
model
} = params
return await uni.request({
method: 'POST',
url: `${baseUrl}/myetc/bind/etc`,
data: model,
header: {
"x-auth-token": token
}
})
},
async bindPoint({
commit
}, params) {
const {
baseUrl,
token,
model
} = params
return await uni.request({
method: 'POST',
url: `${baseUrl}/myetc/bind/point`,
data: model,
header: {
"x-auth-token": token
}
})
},
async getUserInfo({
commit
}, params) {
const {
baseUrl,
token
} = params;
console.log(`用户己经登陆line,获取用户数据`);
const res = await uni.request({
url: `${baseUrl}/user/info`,
header: {
"x-auth-token": token
}
})
const user = res.data.data;
user.token = token;
if (user) {
commit('updateUser', user);
}
return user;
},
async getPoints({
commit
}, params) {
const {
baseUrl,
token
} = params
return await uni.request({
method: 'GET',
url: `${baseUrl}/myetc/point`,
header: {
"x-auth-token": token
}
})
},
async getSummary({
commit
}, params) {
const {
baseUrl,
token,
type
} = params
return await uni.request({
method: 'GET',
url: `${baseUrl}/myetc/summary`,
header: {
"x-auth-token": token,
},
data: {
type: type
}
})
},
}
})
export default store