import request from '@/api/request' import { platform } from '@/utils/platform' import funWxShare from '@/utils/wxShare0.0' const state = { userinfo: { user_head_img_url: '', // 用户头像 user_nickname: '', // 用户昵称 user_sex: '', // 用户性别 user_balance: 0, // 用户可提现余额(单位为分) user_crash_balance: 0, // 累计提现(单位为分) user_unreceive_balance: 0, // 用户未结算金额(单位为分) created_at: '', // 注册时间 id: '' // 用户ID }, orderType: [], // 订单类型 inviteId: '' // 邀请人ID,分享链接携带 } const getters = { userinfo (state) { return state.userinfo }, orderType (state) { return state.orderType }, inviteId (state) { return state.inviteId } } const actions = { async getUserInfo ({ commit }) { try { const { status, data } = await request({ method: 'GET', url: '/api/user/info' }) if (status) { commit('UPDATE_USERINFO', data) platform.isWeixin && funWxShare('返不停', '一个省钱、赚钱又返钱的生活平台', `${location.origin}/img/share.png`, `${location.origin}${location.pathname}?invite_id=${data.id}`) } } catch (err) { console.log(err) } }, async getOrdertype ({ commit }) { try { const { status, data } = await request({ method: 'GET', url: '/api/order/type/list' }) if (status) { commit('UPDATE_ORDER_TYPE', data) } } catch (err) { console.log(err) } } } const mutations = { UPDATE_USERINFO (state, value) { state.userinfo = { ...value } }, UPDATE_ORDER_TYPE (state, value) { state.orderType = [...value] }, UPDATE_INVITE_ID (state, value) { state.inviteId = value } } export default { namespaced: true, state, getters, actions, mutations }