91 lines
3.5 KiB
JavaScript
91 lines
3.5 KiB
JavaScript
const state = {
|
|
mqttState: false, // mqtt连接状态
|
|
isCollapse: localStorage.getItem('isCollapse') ? !!+localStorage.getItem('isCollapse') : true, // 侧边导航栏 显隐
|
|
isMobile: null, // 是否是pc端 true电脑端 false为移动端
|
|
isWideScreen: window.innerWidth < 480, // 屏幕宽度是否小于480
|
|
defaultLngLat: null, // 地图默认经纬度
|
|
defaultZoom: null, // 地图默认缩放
|
|
orderSerch: null// 订单列表页搜索条件
|
|
}
|
|
|
|
const mutations = {
|
|
// 导航栏 显隐
|
|
setCollapse () {
|
|
state.isCollapse = !state.isCollapse
|
|
if (state.isCollapse) {
|
|
localStorage.setItem('isCollapse', 1)
|
|
} else {
|
|
localStorage.setItem('isCollapse', 0)
|
|
}
|
|
},
|
|
// 判断是否pc端 还是移动端 true电脑端 false移动端
|
|
setIsMobile () {
|
|
const userAgentInfo = navigator.userAgent
|
|
const agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod']
|
|
for (let i = 0; i < agents.length; i++) {
|
|
if (userAgentInfo.indexOf(agents[i]) > 0) {
|
|
state.isMobile = false
|
|
break
|
|
} else {
|
|
state.isMobile = true
|
|
}
|
|
}
|
|
},
|
|
// 设置地图默认经纬度
|
|
setDefaultLngLat (state, lngLat) {
|
|
state.defaultLngLat = lngLat
|
|
localStorage.setItem('defaultLngLat', JSON.stringify(lngLat))
|
|
},
|
|
// 设置地图默认缩放值
|
|
setDefaultZoom (state, zoom) {
|
|
state.defaultZoom = zoom
|
|
localStorage.setItem('defaultZoom', zoom)
|
|
},
|
|
// 设置订单页面搜索默认值
|
|
setOrderSerch (state, partialSerchObj) {
|
|
state.orderSerch = state.orderSerch || {} // 设置默认值
|
|
|
|
// 深层合并传递的部分对象到当前的 state.orderSerch
|
|
state.orderSerch = { ...state.orderSerch, ...partialSerchObj }
|
|
|
|
// 存储到 localStorage
|
|
localStorage.setItem('orderSerch', JSON.stringify(state.orderSerch))
|
|
}
|
|
}
|
|
|
|
const actions = {
|
|
}
|
|
const getters = {
|
|
// 获取地图默认经纬度 缓存中没有从 localStorage中获取 也没有设置为0
|
|
getDefaultLngLat () {
|
|
return state.defaultLngLat !== null ? state.defaultLngLat : localStorage.getItem('defaultLngLat') !== null ? JSON.parse(localStorage.getItem('defaultLngLat')) : { lng: 0, lat: 0 }
|
|
},
|
|
// 获取地图默认缩放值 缓存中没有从 localStorage中获取 也没有设置为1
|
|
getDefaultZoom () {
|
|
return state.defaultZoom !== null ? state.defaultZoom : localStorage.getItem('defaultZoom') !== null ? localStorage.getItem('defaultZoom') : 1
|
|
},
|
|
// 获取订单页面搜索条件
|
|
getOrderSerch (state) {
|
|
const defaultValues = {
|
|
shop_id: localStorage.getItem('shop_id'), // 搜索条件 商铺id
|
|
start_time: Math.floor(new Date(new Date().setHours(0, 0, 0, 0)).getTime() / 1000), // 搜索条件 起始时间 默认为今天凌晨0点
|
|
end_time: Math.floor(new Date(new Date().setHours(23, 59, 59, 999)).getTime() / 1000), // 搜索条件 结束时间 默认为今天23点59分59秒
|
|
main_status: [], // 搜索条件 主状态
|
|
shipment_status: [], // 搜索条件 执行状态
|
|
refund_status: [], // 搜索条件 退款状态
|
|
search: ['orderSn', '']// 搜索条件 搜索
|
|
}
|
|
// 深层合并 state.orderSerch 和默认值 取值得时候对象里面如果有得属性 会被保留 没有得会用defaultValues的属性进行填充
|
|
// 缓存中没有 从本地拿 本地也没有 给一个默认空对象
|
|
return { ...defaultValues, ...state.orderSerch } || JSON.parse(localStorage.getItem('orderSerch')) || defaultValues
|
|
}
|
|
}
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state,
|
|
mutations,
|
|
actions,
|
|
getters
|
|
}
|