food/src/store/index.js

411 lines
12 KiB
JavaScript
Raw Normal View History

2023-09-20 21:33:11 +08:00
import Vue from 'vue'
import Vuex from 'vuex'
import app from './modules/app'
import settings from './modules/settings'
import user from './modules/user'
import api from '@/utils/api'
import { Message, MessageBox } from 'element-ui'
Vue.use(Vuex)
const store = new Vuex.Store({
state: {
adminList: [], // 管理员列表
airList: [], // 所有飞机列表
siteList: [], // 站点列表
routeList: [], // 航线列表
questList: [], // 订单列表
logList: [], // 操作日志列表
crosFrequency: null // 对频macadd
},
mutations: {
/**
* @description: 设置管理员列表
*/
setAdminList (state, list) {
state.adminList = list
},
/**
* @description: 设置飞机列表
*/
setAirList (state, list) {
state.airList = list
},
/**
* @description: 设置站点列表
*/
setSiteList (state, list) {
state.siteList = list
},
/**
* @description: 设置航线列表
*/
setRouteList (state, list) {
state.routeList = list
},
/**
* @description: 设置订单列表
*/
setQuestList (state, list) {
state.questList = list
},
/**
* @description: 向操作日志列表最后插入新的信息
* @param {*} logData
*/
insertNewLog (state, logData) {
state.logList.push(logData)
},
/**
* @description: 登记对频信息
*/
setCrosFrequency (state, macAdd) {
state.crosFrequency = macAdd
}
},
actions: {
/**
* @description: 获取管理员列表
*/
async fetchAdminList ({ commit }) {
const res = await api.get('getAdminList')
if (res.data.status === 1) {
commit('setAdminList', res.data.adminList)
} else {
Message.error(res.data.msg)
}
},
/**
* @description: 获取飞机列表
*/
async fetchAirList ({ commit, state }) {
const res = await api.get('getAirList')
res.data.airList.forEach(plane => {
plane.planeState = { // 飞机状态初始化字段
heartBeat: null, // 心跳
heartRandom: null, // 每次接收到心跳创建一个随机数 用于watch监听
voltagBattery: null, // 电压信息
currentBattery: null, // 电流信息
batteryRemaining: null, // 电池电量
positionAlt: null, // 高度信息
groundSpeed: null, // 对地速度
satCount: null, // 卫星数量
latitude: null, // 纬度
longitude: null, // 经度
fixType: null, // 定位状态
state: 1, // 飞机状态 默认初始状态为1
pingNet: null, // 网速测试
getPlaneMode: null, // 飞机模式
loadweight: null, // 重量
hookstatus: null, // 钩子状态
position: []// [[经度,维度,海拔高度]]累计数组
}
})
if (res.data.status === 1) {
commit('setAirList', res.data.airList)
} else {
commit('setSiteList', [])
Message.warning(res.data.msg)
}
return res.data.airList
},
/**
* @description: 创建新飞机
* @param {*} form 表单.飞机信息
* @return {*} 服务器返回信息
*/
async fetchAddAir ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('shop_id', form.shop_id)
params.append('name', form.name)
params.append('date', form.date)
if (form.state) {
params.append('state', '1')
} else {
params.append('state', '0')
}
params.append('desc', form.desc)
const res = await api.post('addAir', params)
if (res.data.status === 1) {
await dispatch('fetchAirList')// 刷新飞机列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 更新新飞机数据
* @param {*} form 表单.飞机信息
* @return {*} 服务器返回信息
*/
async fetchSaveAir ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('shop_id', form.shop_id)
params.append('name', form.name)
params.append('date', form.date)
if (form.state) {
params.append('state', '1')
} else {
params.append('state', '0')
}
params.append('desc', form.desc)
params.append('id', form.id)
const res = await api.post('saveAir', params)
if (res.data.status === 1) {
await dispatch('fetchAirList')// 刷新飞机列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 删除指定序号飞机
* @param {*} idArray 飞机序号数组
*/
fetchDelAir ({ dispatch }, idArr) {
if (idArr.length === 0) {
Message.error('未勾选记录')
} else {
MessageBox.confirm('请谨慎操作 确认删除?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const params = new URLSearchParams()
params.append('idArr', idArr)
api.post('deleteAir', params).then(res => {
if (res.data.status === 1) {
Message.success(res.data.msg)
dispatch('fetchAirList')// 刷新飞机列表
} else {
Message.error(res.data.msg)
}
})
}).catch(() => {
Message.info('取消操作')
})
}
},
/**
* @description: 获取站点列表
*/
async fetchSiteList ({ commit }) {
const res = await api.get('getSiteList')
if (res.data.status === 1) {
commit('setSiteList', res.data.siteList)
} else {
commit('setSiteList', [])
Message.warning(res.data.msg)
}
},
/**
* @description: 锁定站点
* @param {*} form 表单.站点信息
* @return {*} 服务器返回信息
*/
async fetchLockSite ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('id', form.id)
params.append('runing', form.runing)
const res = await api.post('lockSite', params)
if (res.data.status === 1) {
await dispatch('fetchSiteList')// 刷新站点列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 创建新站点
* @param {*} form 表单.站点信息
* @return {*} 服务器返回信息
*/
async fetchAddSite ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('shop_id', form.shop_id)
params.append('sitename', form.sitename)
params.append('desc', form.desc)
params.append('upFile', form.upFile)
params.append('size', form.size)
params.append('bindroute', form.bindroute)
const res = await api.post('addSite', params)
if (res.data.status === 1) {
await dispatch('fetchSiteList')// 刷新站点列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 创建新站点
* @param {*} form 表单.站点信息
* @return {*} 服务器返回信息
*/
async fetchSaveSite ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('id', form.id)
params.append('shop_id', form.shop_id)
params.append('sitename', form.sitename)
params.append('desc', form.desc)
params.append('upFile', form.upFile)
params.append('size', form.size)
params.append('bindroute', form.bindroute)
const res = await api.post('saveSite', params)
if (res.data.status === 1) {
await dispatch('fetchSiteList')// 刷新站点列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 删除指定序号站点
* @param {*} idArray 站点序号数组
*/
fetchDelSite ({ dispatch }, idArr) {
if (idArr.length === 0) {
Message.error('未勾选记录')
} else {
MessageBox.confirm('请谨慎操作 确认删除?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const params = new URLSearchParams()
params.append('idArr', idArr)
api.post('deleteSite', params).then(res => {
if (res.data.status === 1) {
Message.success(res.data.msg)
dispatch('fetchSiteList')// 刷新站点列表
} else {
Message.error(res.data.msg)
}
})
}).catch(() => {
Message.info('取消操作')
})
}
},
/**
* @description: 获取航线列表
*/
async fetchRouteList ({ commit }) {
const res = await api.get('getRouteList')
if (res.data.status === 1) {
commit('setRouteList', res.data.routeList)
} else {
Message.warning(res.data.msg)
}
return res.data.routeList
},
/**
* @description: 创建新航线
* @param {*} form 表单.航线信息
* @return {*} 服务器返回信息
*/
async fetchAddRoute ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('shop_id', form.shop_id)
params.append('name', form.name)
params.append('desc', form.desc)
params.append('upFile', form.upFile)
const res = await api.post('addRoute', params)
if (res.data.status === 1) {
await dispatch('fetchRouteList')// 刷新站点列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 更新航线
* @param {*} form 表单.航线信息
* @return {*} 服务器返回信息
*/
async fetchSaveRoute ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('id', form.id)
params.append('shop_id', form.shop_id)
params.append('name', form.name)
params.append('desc', form.desc)
params.append('upFile', form.upFile)
const res = await api.post('saveRoute', params)
if (res.data.status === 1) {
await dispatch('fetchRouteList')// 刷新站点列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 删除指定序号航线
* @param {*} idArray 航线序号数组
*/
fetchDelRoute ({ dispatch }, idArr) {
if (idArr.length === 0) {
Message.error('未勾选记录')
} else {
MessageBox.confirm('请谨慎操作 确认删除?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const params = new URLSearchParams()
params.append('idArr', idArr)
api.post('deleteRoute', params).then(res => {
if (res.data.status === 1) {
Message.success(res.data.msg)
dispatch('fetchRouteList')// 刷新航线列表
dispatch('fetchSiteList')// 刷新站点列表
} else {
Message.error(res.data.msg)
}
})
}).catch(() => {
Message.info('取消操作')
})
}
},
/**
* @description: 获取订单列表 ps:待发货及待收货 并且不是退款成功状态
* @return {*} 列表
*/
async fetchQuestList ({ commit }) {
const res = await api.get('getQuestList')
if (res.data.status === 1) {
commit('setQuestList', res.data.questList)
}
return res
},
/**
* @description: 向操作日志插入信息 并在积攒多条之后 向服务器提交
* @param {logData} content 日志内容 logData.color 时间
* @param {logData} color 标点颜色 默认#409EFF
* @param {logData} timestamp 插入时间 默认当前时间
*/
fetchLog ({ commit }, logData) {
/* 插入日志 */
logData.color = typeof logData.color !== 'undefined' ? logData.color : '#409EFF'
logData.timestamp = typeof logData.timestamp !== 'undefined' ? logData.color : new Date().getTime()
commit('insertNewLog', logData)
/* 积攒 向服务器提交 日志 待续写... */
}
},
modules: {
app,
settings,
user
},
getters: {
}
})
export default store