162 lines
4.0 KiB
JavaScript
162 lines
4.0 KiB
JavaScript
import Vue from 'vue'
|
|
import Vuex from 'vuex'
|
|
import Api from '@/common/js/api.js'
|
|
Vue.use(Vuex);
|
|
|
|
//Vuex.Store 构造器选项
|
|
const store = new Vuex.Store({
|
|
state: { //存放状态
|
|
"login": false,
|
|
"info": {
|
|
ft_sum: 0,
|
|
},
|
|
"BarHeight": {
|
|
statusBar: '',
|
|
customBar: '',
|
|
info: '',
|
|
custwidth: '',
|
|
bottompadding: "",
|
|
heightBar: ''
|
|
},
|
|
shopId: null
|
|
},
|
|
getters: {
|
|
is_login(state) {
|
|
return state.login;
|
|
},
|
|
bottomnavigation(state) {
|
|
return state.ationbottomnavigation;
|
|
},
|
|
is_BarHeight(state) {
|
|
//二次修改后的值 或者过滤的
|
|
return state.BarHeight;
|
|
},
|
|
get_info(state) {
|
|
//二次修改后的值 或者过滤的
|
|
return state.info;
|
|
},
|
|
|
|
},
|
|
mutations: {
|
|
SET_SHOPID(state, data) {
|
|
state.shopId = data;
|
|
},
|
|
SET_STATUS_BAR(state, data) {
|
|
state.BarHeight.statusBar = data;
|
|
},
|
|
SET_CUSTOM_BAR(state, data) {
|
|
state.BarHeight.customBar = data;
|
|
},
|
|
Bottom_heightBar(state, data) {
|
|
state.BarHeight.heightBar = data;
|
|
},
|
|
SET_SYSTEM_INFO(state, data) {
|
|
state.BarHeight.info = data;
|
|
},
|
|
Bottom_Padding(state, data) {
|
|
state.BarHeight.bottompadding = data;
|
|
},
|
|
SUS_THIDTH(state, data) {
|
|
state.BarHeight.custwidth = data;
|
|
},
|
|
},
|
|
actions: {
|
|
loginEvent: () => {
|
|
uni.login({
|
|
provider: 'weixin',
|
|
success: (data) => {
|
|
uni.getUserInfo({
|
|
provider: 'weixin',
|
|
success: async (infoRes) => {
|
|
uni.cache.set('weixincode', data.code);
|
|
let res = await Api.userwxlogin({
|
|
code: uni.cache.get('weixincode'), //临时登录凭证
|
|
rawData: infoRes.rawData,
|
|
})
|
|
if (res.code == 0) {
|
|
uni.cache.set('token', res.data.token);
|
|
uni.cache.set('miniAppOpenId', res.data.userInfo
|
|
.miniAppOpenId)
|
|
uni.cache.set('userInfo', res.data.userInfo);
|
|
this.$isResolve()
|
|
}
|
|
},
|
|
fail: (err) => {}
|
|
});
|
|
}
|
|
});
|
|
|
|
},
|
|
set_shopid: async ({
|
|
commit
|
|
}, data) => {
|
|
let res = await Api.productqueryShopIdByTableCode({
|
|
code: uni.cache.get('tableCode')
|
|
})
|
|
if (res.code == 0) {
|
|
commit('SET_SHOPID', res.data)
|
|
}
|
|
},
|
|
HeightActions({
|
|
commit
|
|
}) {
|
|
uni.getSystemInfo({
|
|
success: (e) => {
|
|
let statusBar = 0
|
|
let customBar = 0
|
|
let heightBar = 0
|
|
let custwidth = 0
|
|
let bottomPadding = 0
|
|
// #ifdef MP
|
|
statusBar = e.statusBarHeight
|
|
customBar = e.statusBarHeight + 45
|
|
bottomPadding = (e.screenHeight - e.safeArea.bottom)
|
|
if (e.platform === 'android') {
|
|
commit('SET_SYSTEM_IOSANDROID', false)
|
|
customBar = e.statusBarHeight + 50
|
|
}
|
|
// #endif
|
|
// #ifdef MP-WEIXIN
|
|
Vue.prototype.windowWidth = e.windowWidth;
|
|
Vue.prototype.windowHeight = e.windowHeight;
|
|
statusBar = e.statusBarHeight
|
|
// @ts-ignore
|
|
const custom = wx.getMenuButtonBoundingClientRect()
|
|
// customBar = custom.bottom + custom.top - e.statusBarHeight
|
|
customBar = custom.height
|
|
heightBar = custom.top
|
|
custwidth = custom.width + 10,
|
|
bottomPadding = (e.screenHeight - e.safeArea.bottom)
|
|
// #endif
|
|
// #ifdef MP-ALIPAY
|
|
statusBar = e.statusBarHeight
|
|
customBar = e.statusBarHeight + e.titleBarHeight
|
|
bottomPadding = (e.screenHeight - e.safeArea.bottom)
|
|
// #endif
|
|
// #ifdef APP-PLUS
|
|
console.log('app-plus', e)
|
|
statusBar = e.statusBarHeight
|
|
heightBar = e.statusBarHeight
|
|
customBar = e.statusBarHeight
|
|
bottomPadding = (e.screenHeight - e.safeArea.bottom)
|
|
// customBar = 0
|
|
// #endif
|
|
// #ifdef H5
|
|
statusBar = 0
|
|
customBar = e.statusBarHeight == 0
|
|
bottomPadding = (e.screenHeight - e.safeArea.bottom)
|
|
// #endif
|
|
// console.log(statusBar,customBar,custwidth,e)
|
|
commit('SET_STATUS_BAR', statusBar) //状态栏高度
|
|
commit('SET_CUSTOM_BAR', customBar) //顶部距离
|
|
commit('SUS_THIDTH', custwidth) //胶囊宽度
|
|
commit('Bottom_Padding', bottomPadding) //底部导航栏Padding
|
|
commit('Bottom_heightBar', heightBar) //底部导航栏Padding
|
|
commit('SET_SYSTEM_INFO', e)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
})
|
|
|
|
export default store |