3
0
Fork 0
web-store-retail-h5/store/modules/user.js

122 lines
2.9 KiB
JavaScript
Raw Normal View History

2025-03-23 09:29:40 +08:00
/*
* @Descripttion:
* @version:
* @Author: kBank
* @Date: 2022-10-24 10:45:39
*/
import { getInfo, logout } from '@/config/login.js'
import { removeToken } from '@/config/auth.js'
import { getShoppingCount,getSmallCount } from '@/config/goods'
const getDefaultState = () => {
return {
user: '',
shopCarLength: 0,
smallCarLength: 0
}
}
const state = getDefaultState()
const mutations = {
SET_USER: (state, user) => {
state.user = user
},
shopCarLength: (state, data) => {
state.shopCarLength = data
},
smallCarLength: (state, data) => {
state.smallCarLength = data
}
}
const actions = {
checkFunc({ commit }) {
return new Promise((resolve, reject) => {
// uni.login({
// provider: "weixin",
// success: function (loginRes) {
// // 登录成功
// let data = {
// code: loginRes.code,
// }
// wxSqlogin(data).then(res => {
// console.log("🚀 ~ AdminToken res", res);
// if (res.code == 200) {
// uni.setStorageSync('AdminToken', res.token)
// uni.setStorageSync("User", res.data);
// resolve(true)
// }
// })
// },
// fail: function (err) {
// },
// });
})
},
// 获取用户信息
GetInfo({ commit, state }) {
return new Promise((resolve, reject) => {
getInfo().then(res => {
if (res) {
commit('SET_USER', res.data)
uni.setStorageSync("User", res.data);
resolve(res)
}
}).catch(error => {
reject(error)
})
})
},
// 退出登录
LogOut({ commit, state }) {
return new Promise((resolve, reject) => {
logout(state.token).then(() => {
removeToken()
resolve()
}).catch(error => {
reject(error)
})
})
},
getCarLength({ commit }, data) {
return new Promise((resolve, reject) => {
let pkCountry
let userInfo = uni.getStorageSync('User')
if (data == 1) {
if (uni.getStorageSync('pkCountry')) {
pkCountry = uni.getStorageSync('pkCountry')
} else {
pkCountry = userInfo.pkSettleCountry
}
} else {
pkCountry = userInfo.pkSettleCountry
}
let obj = { specialArea: data, pkCountry: pkCountry }
getShoppingCount(obj).then(res => {
if (res.code == 200) {
// resolve(res)
// commit('shopCarLength', res.data.cont)
// commit('smallCarLength', res.data.smallCount)
getSmallCount(obj).then(res1 => {
if (res.code == 200) {
commit('smallCarLength', res1.data.smallCount)
commit('shopCarLength', res.data.cont)
resolve(res)
}
})
}
})
})
},
}
export default {
state,
mutations,
actions
}