index.js
1.74 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
// import util from '~/utils/util'
// import { getNavigationBarTitleText } from '~/utils/cache/storageApi'
import USER from '~/api/usersApi/index'
import {
Storage
} from '~/utils/cache/storage'
const $Storage = new Storage()
export function setPageParams(options) {
function setPageParmas(query) {
if (query.merchantId) $Storage.set('srcm_shopmall_merchant_id', query.merchantId)
if (query.customerId) $Storage.set('srcm_shopmall_customer_id', query.customerId)
}
Object.keys(options.query).map(e => {
let params = decodeURIComponent(e).split('&')
params.map(i => {
let [key, val] = i.split('=')
if (!val) val = options.query[key]
setPageParmas({
[key]: val
})
})
})
}
export async function login() {
return new Promise(async (resolve) => {
try {
const {
code,
data,
message
} = await USER.login()
wx.$isGroup = data.group
wx.$authStatus = code != 0
if (data) wx.setStorageSync('merchant_info', {
merchantId: data.merchantId,
merchantName: data.merchantName
})
if (code == '0') {
wx.$storage.rm('userInfo')
wx.$storage.rm('sessionId')
wx.$util.setUserInfo(data)
wx.$util.setSessionId(data.sessionId)
let customerId = wx.$storage.get('srcm_shopmall_customer_id')
if (customerId) USER.updataCustomerPhone()
wx.$util.customerbehavior()
// 登录完加载权益会员信息接口(目前只针对权益商品页面)
wx.$eventbus.emit('EQUITYGOODS', true)
}
resolve({
code,
data,
message
})
} catch (error) {
console.log('jslogin 登录失败')
console.error(error)
wx.$authStatus = true
}
})
}