food/src/store/modules/app.js
szdot 78c2d7de21 【类 型】:feat
【原  因】:增加 系统设置 控制模块显示 隐藏
【过  程】:
【影  响】:

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
2025-06-23 03:02:54 +08:00

143 lines
5.0 KiB
JavaScript

// 默认模块显示配置
const defaultModuleVisibilityMap = {
home: true,
model: true,
register: true,
product: true,
route: true,
planes: true,
site: true,
shop: true,
admin: true,
category: true,
broadcast: true,
order: true,
nofly: true
}
// 从 localStorage 读取已有配置,合并覆盖默认配置
const savedVisibility = JSON.parse(localStorage.getItem('moduleVisibilityMap') || '{}')
const moduleVisibilityMap = { ...defaultModuleVisibilityMap, ...savedVisibility }
const state = {
mqttState: false, // mqtt连接状态
isCollapse: localStorage.getItem('isCollapse') ? !!+localStorage.getItem('isCollapse') : true, // 侧边导航栏 显隐
isMobile: null, // 是否是pc端 true电脑端 false为移动端
isWideScreen: window.innerWidth < 480, // 屏幕宽度是否小于480
defaultLonLat: null, // 地图默认经纬度
defaultZoom: null, // 地图默认缩放
moduleVisibilityMap, // 使用合并后的 moduleVisibilityMap 初始化
/* 页面参数 */
orderSerch: null, // 订单列表页搜索条件
toMessageIdArr: [], // 用户管理 发布公告页面 id临时传参
toFlyDataIdArr: [], // 飞机飞行数据 临时传参
swarmIdArr: []// 选中的 集群控制飞机ID组
}
const mutations = {
// 设置 模块显示隐藏参数
setModuleVisibility (state, { key, visible }) {
state.moduleVisibilityMap[key] = visible
localStorage.setItem('moduleVisibilityMap', JSON.stringify(state.moduleVisibilityMap))
},
setAllModuleVisibility (state, visibilityMap) {
state.moduleVisibilityMap = visibilityMap
localStorage.setItem('moduleVisibilityMap', JSON.stringify(state.moduleVisibilityMap))
},
// 导航栏 显隐
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
}
}
},
// 设置地图默认经纬度
setDefaultLonLat (state, lonLat) {
state.defaultLonLat = lonLat
localStorage.setItem('defaultLonLat', JSON.stringify(lonLat))
},
// 设置地图默认缩放值
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))
},
/* 临时传参 */
// 管理员管理 发布公告页面 传递id数组
setToMessageIdArr (state, idArr) {
state.toMessageIdArr = idArr
},
// 飞机飞行数据 传递id数组
setToFlyDataIdArr (state, idArr) {
state.toFlyDataIdArr = idArr
},
// 设置 '选取的集群飞机'id组
setSwarmIdArr (state, idArr) {
state.swarmIdArr = idArr
}
}
const actions = {
}
const getters = {
// 获取地图默认经纬度 缓存中没有从 localStorage中获取 也没有设置为0
getDefaultLonLat () {
return state.defaultLonLat !== null ? state.defaultLonLat : localStorage.getItem('defaultLonLat') !== null ? JSON.parse(localStorage.getItem('defaultLonLat')) : { lon: 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
}