food/src/store/index.js
air 2d44b5f54f 【类 型】:feat
【原  因】:地图样式删除功能
【过  程】:
【影  响】:
2025-09-23 14:19:27 +08:00

1322 lines
44 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Vue from 'vue'
import Vuex from 'vuex'
// import router from '@/router'
import app from './modules/app'
import settings from './modules/settings'
import user from './modules/user'
import api from '@/utils/api'
import { Message, MessageBox, Notification } from 'element-ui'
import { parseTime } from '@/utils/index'
// 把vuex作为插件引入到Vue示例中 ps:注册
Vue.use(Vuex)
const store = new Vuex.Store({
state: {
shopList: [], // 商铺列表
adminList: [], // 管理员列表
airList: [], // 所有飞机列表
planeClassList: [], // 机型列表
siteList: [], // 站点列表
routeList: [], // 航线列表
noflyData: [[], [], []], // [0]禁飞区数据 [1]限制飞区 [2]限飞区高度
categoryList: [], // 分类列表(小程序)
spuList: [], // 商品spu列表
skuList: [], // 商品sku列表
paidOrderList: [], // 已付款 和已退款但是发货状态为 已发货 订单列表
logList: [], // 操作日志列表
messageList: [], // 管理员公告列表
mapStyleList: [], // 地图样式列表
crosFrequency: null, // 对频macadd
ADSBList: [] // 存放当前活跃的 ADSB 飞机数据
},
mutations: {
updatePlanePosition (state, { planeId, position }) {
const plane = state.airList.find(p => p.id === planeId)
if (plane) {
if (!plane.planeState) {
Vue.set(plane, 'planeState', {})
}
if (!plane.planeState.position) {
Vue.set(plane.planeState, 'position', [])
}
// 追加新点
plane.planeState.position.push(...position)
}
},
/**
* @description: 设置商铺列表
*/
setShopList (state, list) {
state.shopList = list
},
/**
* @description: 设置管理员列表
*/
setAdminList (state, list) {
state.adminList = list
},
/**
* @description: 设置飞机列表
*/
setAirList (state, list) {
state.airList = list
},
/**
* @description:更新飞机的 parameterValue
*/
updateParameterValue (state, { planeId, parameterValue }) {
const plane = state.airList.find(plane => plane.id === planeId) // 根据 planeId 查找飞机
if (plane) {
plane.planeState.parameterValue = parameterValue // 更新 parameterValue
}
},
/**
* @description: 设置站点列表
*/
setSiteList (state, list) {
state.siteList = list
},
/**
* @description: 设置航线列表
*/
setRouteList (state, list) {
state.routeList = list
},
/**
* @description: 设置机型列表
*/
setPlaneClassList (state, list) {
state.planeClassList = list
},
/**
* @description: 设置禁飞区列表
*/
setNoflyData (state, payload) {
if (payload && payload.nofly_data && payload.restrictfly_data && payload.restrictfly_height) {
state.noflyData = [
JSON.parse(payload.nofly_data || '[]'),
JSON.parse(payload.restrictfly_data || '[]'),
JSON.parse(payload.restrictfly_height || '[]')
]
} else {
state.noflyData = [[], [], []]
}
},
/**
* @description: 设置分类列表
*/
setCategoryList (state, list) {
state.categoryList = list
},
/**
* @description: 设置商品spu列表
*/
setSpuList (state, list) {
state.spuList = list
},
/**
* @description: 设置商品sku列表
*/
setSkuList (state, list) {
state.skuList = list
},
/**
* @description: 设置 已付款 和已退款但是发货状态为 已发货 订单列表
*/
setPaidOrderList (state, list) {
state.paidOrderList = list
},
/**
* @description: 向操作日志列表最后插入新的信息
* @param {*} logData
*/
insertNewLog (state, logData) {
state.logList.push(logData)
},
/**
* @description: 向管理员公告列表最后插入新的信息
* @param {*} list
*/
setMessageList (state, list) {
state.messageList = list
},
/**
* @description: 登记对频信息
*/
setCrosFrequency (state, macAdd) {
state.crosFrequency = macAdd
},
/**
* @description: 设置当前活跃的 ADSB 飞机数据
* @param {*} ADSB
*/
setADSBList (state, ADSB) {
const index = state.ADSBList.findIndex(i => i.icao === ADSB.icao)
if (index > -1) {
// 更新已有
state.ADSBList[index] = { ...ADSB, timestamp: Date.now() }
} else {
// 新增
state.ADSBList.push({ ...ADSB, timestamp: Date.now() })
}
},
/**
* @description: 设置地图样式列表
* @param {*} list 地图样式列表
*/
setMapStyleList (state, list) {
state.mapStyleList = list
},
/**
* @description: 清除过期的 ADSB 数据
*/
cleanExpiredADSBList (state) {
const now = Date.now()
state.ADSBList = state.ADSBList.filter(i => now - i.timestamp < 20000)
}
},
actions: {
/**
* @description: 获取商铺列表
*/
async fetchShopList ({ commit }) {
const res = await api.get('getShopList', 'Admin')
if (res.data.status === 1) {
res.data.shopList.forEach((shop, index) => {
shop.remark_presup = JSON.parse(shop.remark_presup)// 反序列化 remark_presup字段
shop.refund_remark_presup = JSON.parse(shop.refund_remark_presup)// 反序列化 refund_remark_presup字段
shop.logo = JSON.parse(shop.logo)// 反序列化 photo字段
shop.logo.forEach((logo, i) => {
res.data.shopList[index].logo[i] = settings.state.logoPath + logo // 把绝对路径加上
})
})
commit('setShopList', res.data.shopList)
} else {
commit('setShopList', [])
Message.error(res.data.msg)
}
},
/**
* @description: 添加商铺
* @param {*} 商铺信息表单
* @return {*} 服务器返回值
*/
async fetchAddShop ({ dispatch }, form) {
console.log('fetchAddShop', form)
const params = new URLSearchParams()
params.append('admin_name', form.admin_name)
params.append('pwd', form.pwd)
params.append('name', form.name)
params.append('waiter', form.waiter)
params.append('service_wx', form.service_wx)
params.append('tel', form.tel)
params.append('email', form.email)
params.append('price_min', form.price_min)
params.append('weight_max', form.weight_max)
params.append('default_transport_price', form.default_transport_price)
params.append('default_pack_price', form.default_pack_price)
params.append('remark_presup', JSON.stringify(form.remark_presup))
params.append('refund_remark_presup', JSON.stringify(form.refund_remark_presup))
params.append('desc', form.desc)
params.append('upFile', form.upFile)
params.append('opening_time', form.opening_time)
params.append('closeing_time', form.closeing_time)
const res = await api.post('addShop', params, 'Admin')
if (res.data.status === 1) {
await dispatch('fetchShopList')// 刷新商铺列表
await dispatch('fetchAdminList')// 刷新用户列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 更新管商铺信息
* @param {*} 商铺信息表单
* @return {*} 服务器返回值
*/
async fetchSaveShop ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('shop_id', form.shop_id)
params.append('name', form.name)
params.append('waiter', form.waiter)
params.append('service_wx', form.service_wx)
params.append('tel', form.tel)
params.append('email', form.email)
params.append('price_min', form.price_min)
params.append('weight_max', form.weight_max)
params.append('default_transport_price', form.default_transport_price)
params.append('default_pack_price', form.default_pack_price)
params.append('remark_presup', JSON.stringify(form.remark_presup))
params.append('refund_remark_presup', JSON.stringify(form.refund_remark_presup))
params.append('desc', form.desc)
params.append('upFile', form.upFile)
params.append('oldFile', form.oldFile)
params.append('opening_time', form.opening_time)
params.append('closeing_time', form.closeing_time)
const res = await api.post('saveShop', params, 'Admin')
if (res.data.status === 1) {
await dispatch('fetchShopList')// 刷新商铺列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 获取管理员列表
*/
async fetchAdminList ({ commit }) {
const res = await api.get('getAdminList', 'Admin')
if (res.data.status === 1) {
res.data.adminList.forEach((item, index) => {
// 判断如果是当前登录用户 最后登录时间字段 从本地缓存中获取 PS:既登陆前缓存到本地的“最后登陆时间” 因为登录后 服务端会把当前登录的时间刷到lasttime字段
if (item.shop_id === store.state.user.shop_id) {
item.lasttime = store.state.user.lasttime
}
// 头像字段反序列化
item.photo = JSON.parse(item.photo)// 反序列化 photo字段
item.photo.forEach((photo, i) => {
res.data.adminList[index].photo[i] = settings.state.photoPath + photo // 把绝对路径加上
})
})
commit('setAdminList', res.data.adminList)
} else {
commit('setAdminList', [])
Message.error(res.data.msg)
}
},
/**
* @description: 添加新的管理员
* @param {*} 管理员信息表单
* @return {*} 服务器返回值
*/
async fetchAddAdmin ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('name', form.name)
params.append('uname', form.uname)
params.append('pwd', form.pwd)
params.append('role', form.role === 'admin' ? 5 : 6)
params.append('shop_id', form.shop_id)
params.append('upFile', form.upFile)
const res = await api.post('addAdmin', params, 'Admin')
if (res.data.status === 1) {
await dispatch('fetchAdminList')// 刷新用户列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 更新管理员账号信息
* @param {*} 管理员信息表单
* @return {*} 服务器返回值
*/
async fetchSaveAdmin ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('id', form.id)
params.append('shop_id', form.shop_id)
params.append('uname', form.uname)
params.append('pwd', form.pwd)
params.append('role', form.role === 'admin' ? 5 : 6)
params.append('upFile', form.upFile)
params.append('oldFile', form.oldFile)
const res = await api.post('saveAdmin', params, 'Admin')
if (res.data.status === 1) {
await dispatch('fetchAdminList')// 刷新用户列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 删除账号
* @param {*} 多选id组
*/
async fetchDelAdmin ({ 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('deleteAdmin', params, 'Admin').then(res => {
if (res.data.status === 1) {
Message.success(res.data.msg)
dispatch('fetchAdminList')// 刷新管理员列表
} else {
Message.error(res.data.msg)
}
})
}).catch(() => {
Message.info('取消操作')
})
}
},
/**
* @description: 获取飞机列表
*/
async fetchAirList ({ commit, state }) {
const res = await api.get('getAirList')
res.data.airList.forEach(plane => {
plane.planeState = { // 飞机状态初始化字段
isUnlock: false, // 飞机解锁标记成真
flyDataSave: { // 飞机加锁截至 待上传飞行数据之后 再清空此值
startTime: null, // 解锁时的时间戳(秒)
endTime: null, // 加锁时的时间戳(秒)
startBattery: null, // 解锁时的电池电量(百分比)
endBattery: null, // 加锁时的电池电量(百分比)
path: [] // 飞行路径数组,每项是 [lon, lat, alt]
},
heartBeat: null, // 心跳
heartRandom: null, // 每次接收到心跳创建一个随机数 用于watch监听
online: false, // 是否在线
onlineTimeout: null, // 存放定时器引用
voltagBattery: null, // 电压信息
currentBattery: null, // 电流信息
batteryRemaining: null, // 电池电量
positionAlt: null, // 海拔高度信息
groundSpeed: null, // 对地速度
satCount: null, // 卫星数量
fixType: null, // 定位状态
completionPct: 0, // 磁罗盘校准进度
reportCal: null, // 磁罗盘校准结果
questState: 1, // 飞机状态 默认初始状态为1
acceState: null, // 加速度计校准状态
getPlaneMode: null, // 飞机模式
loadweight: null, // 重量
hasGoods: false, // 是否有货
hookstatus: null, // 钩子状态
position: [], // [[经度,维度,相对高度]]累计数组
battCapacity: null, // 电池容量
homePosition: null, // 返航点位置
wpnavSpeed: null, // 飞机返航速度 米/秒
parameterValue: null// 请求的参数键值对 需要序列化
}
})
if (res.data.status === 1) {
commit('setAirList', res.data.airList)
} else {
commit('setAirList', [])
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)
params.append('onoff', form.onoff ? '1' : '0')
params.append('desc', form.desc)
params.append('bind_class_id', form.bind_class_id) // ✅ 添加机型绑定字段
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)
params.append('onoff', form.onoff ? '1' : '0')
params.append('desc', form.desc)
params.append('id', form.id)
params.append('bind_class_id', form.bind_class_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 fetchPlaneClassList ({ commit }) {
const res = await api.get('getPlaneClassList')
if (res.data.status === 1) {
commit('setPlaneClassList', res.data.planeClassList)
} else {
commit('setPlaneClassList', [])
Message.warning(res.data.msg)
}
return res.data.planeClassList
},
/**
* @description: 创建新机型
* @param {*} form 表单.机型信息
* @return {*} 服务器返回信息
*/
async fetchAddPlaneClass ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('shop_id', form.shop_id)
params.append('class_name', form.class_name)
params.append('wheelbase', form.wheelbase)
params.append('category', form.category)
params.append('weight_max', form.weight_max)
params.append('describe', form.describe)
const res = await api.post('addPlaneClass', params)
if (res.data.status === 1) {
await dispatch('fetchPlaneClassList')// 刷新 机型列表
await dispatch('fetchAirList')// 刷新飞机列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 创建新机型
* @param {*} form 表单.机型信息
* @return {*} 服务器返回信息
*/
async fetchSavePlaneClass ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('id', form.id)
params.append('shop_id', form.shop_id)
params.append('class_name', form.class_name)
params.append('wheelbase', form.wheelbase)
params.append('category', form.category)
params.append('weight_max', form.weight_max)
params.append('describe', form.describe)
const res = await api.post('savePlaneClass', params)
if (res.data.status === 1) {
await dispatch('fetchPlaneClassList')// 刷新 机型列表
await dispatch('fetchAirList')// 刷新飞机列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 删除指定序号 机型
* @param {*} idArray 机型序号数组
*/
fetchDelPlaneClass ({ 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('deletePlaneClass', params).then(res => {
if (res.data.status === 1) {
Message.success(res.data.msg)
dispatch('fetchPlaneClassList')// 刷新 机型列表
} else {
Message.error(res.data.msg)
}
})
}).catch(() => {
Message.info('取消操作')
})
}
},
/**
* @description: 获取站点列表
*/
async fetchSiteList ({ commit }) {
const res = await api.get('getSiteList')
if (res.data.status === 1) {
res.data.siteList.forEach((site, index) => {
site.qr = settings.state.qrPath + site.qr // 把绝对路径加上
})
commit('setSiteList', res.data.siteList)
} else {
commit('setSiteList', [])
Message.warning(res.data.msg)
}
},
/**
* @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')// 刷新站点列表
dispatch('fetchRouteList')// 刷新航线列表
dispatch('fetchPaidOrderList')// 刷订单点列表
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')// 刷新站点列表
dispatch('fetchRouteList')// 刷新航线列表
dispatch('fetchPaidOrderList')// 刷订单点列表
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')// 刷新站点列表
dispatch('fetchRouteList')// 刷新航线列表
dispatch('fetchPaidOrderList')// 刷订单点列表
} 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 {
commit('setRouteList', [])
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')// 刷新航线列表
dispatch('fetchSiteList')// 刷新站点列表
dispatch('fetchPaidOrderList')// 刷订单点列表
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')// 刷新航线列表
dispatch('fetchSiteList')// 刷新站点列表
dispatch('fetchPaidOrderList')// 刷订单点列表
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')// 刷新站点列表
dispatch('fetchPaidOrderList')// 刷订单点列表
} else {
Message.error(res.data.msg)
}
})
}).catch(() => {
Message.info('取消操作')
})
}
},
/**
* @description: 获取禁飞区数据
* @param {str} shopId 需要传shopId总管理员调用其他商铺禁飞区
*/
async fetchNoflyData ({ commit }, shopId) {
const params = new FormData()
params.append('shop_id', shopId)
const res = await api.post('getNoflyData', params, 'Plane')
if (res.data.status === 1) {
commit('setNoflyData', res.data.noflyData)
} else {
commit('setNoflyData', [[], [], []])
Message.warning(res.data.msg || '暂无禁飞区数据')
}
return res
},
/**
* @description: 获取分类列表
* @return {*} 列表
*/
async fetchCategoryList ({ commit }) {
const res = await api.get('getCategoryList', 'Admin')
if (res.data.status === 1) {
res.data.categoryList.forEach((category, index) => {
category.photo = JSON.parse(category.photo)// 反序列化 photo字段
category.photo.forEach((photo, i) => {
res.data.categoryList[index].photo[i] = settings.state.listPath + photo // 把绝对路径加上
})
})
commit('setCategoryList', res.data.categoryList)
} else {
commit('setCategoryList', [])
}
return res
},
/**
* @description: 添加分类信息
* @param {*} 分类信息表单
* @return {*} 服务器返回值
*/
async fetchAddCategory ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('shop_id', form.shop_id)
params.append('id', form.id)
params.append('path', form.path)
params.append('name', form.name)
params.append('sort', form.sort)
params.append('show', form.show)
params.append('desc', form.desc)
params.append('upFile', form.upFile)
const res = await api.post('addCategory', params, 'Admin')
if (res.data.status === 1) {
await dispatch('fetchCategoryList')// 刷新商铺列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 更新分类信息
* @param {*} 分类信息表单
* @return {*} 服务器返回值
*/
async fetchSaveCategory ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('shop_id', form.shop_id)
params.append('id', form.id)
params.append('name', form.name)
params.append('sort', form.sort)
params.append('show', form.show)
params.append('desc', form.desc)
params.append('upFile', form.upFile)
params.append('oldFile', form.oldFile)
const res = await api.post('saveCategory', params, 'Admin')
if (res.data.status === 1) {
await dispatch('fetchCategoryList')// 刷新商铺列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 删除账号
* @param {*} 多选id组
*/
// eslint-disable-next-line camelcase
async fetchDelCategory ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('delIdArr', form.delIdArr)
params.append('shop_id', form.shop_id)
api.post('deleteCategory', params, 'Admin').then(res => {
if (res.data.status === 1) {
Message.success(res.data.msg)
dispatch('fetchCategoryList')// 刷新分类列表
} else {
Message.error(res.data.msg)
}
})
},
/**
* @description: 获取商品spu列表
* @return {*} 列表
*/
async fetchSpuList ({ commit }) {
const res = await api.get('getSpuList', 'Admin')
if (res.data.status === 1) {
res.data.spuList.forEach((spu, index) => {
spu.pro_tag = JSON.parse(spu.pro_tag)// 反序列化 pro_tag字段
spu.bind_sku = JSON.parse(spu.bind_sku)// 反序列化 bind_sku字段
spu.photo = JSON.parse(spu.photo)// 反序列化 photo字段
spu.photo.forEach((photo, i) => {
res.data.spuList[index].photo[i] = settings.state.spuPath + photo // 把绝对路径加上
})
})
commit('setSpuList', res.data.spuList)
} else {
commit('setSpuList', [])
}
return res
},
/**
* @description: spu排序
* @param {*} spu信息
*/
async fetchOrderSpu ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('shop_id', form.shop_id)
params.append('id', form.id)
params.append('sort', form.sort)
const res = await api.post('orderSpu', params, 'Admin')
if (res.data.status === 1) {
await dispatch('fetchSpuList')// 刷新商品列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 商品前端显示隐藏
* @param {*} 商品信息
*/
async fetchShowSpu ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('shop_id', form.shop_id)
params.append('id', form.id)
params.append('show', form.show)
const res = await api.post('showSpu', params, 'Admin')
if (res.data.status === 1) {
await dispatch('fetchSpuList')// 刷新商品列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 商品前端推荐位
* @param {*} 商品信息
*/
async fetchRecommendSpu ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('shop_id', form.shop_id)
params.append('id', form.id)
params.append('recommend', form.recommend)
const res = await api.post('recommendSpu', params, 'Admin')
if (res.data.status === 1) {
await dispatch('fetchSpuList')// 刷新商品列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 添加商品 spu
* @param {*} form 表单.商品信息
* @return {*} 服务器返回信息
*/
async fetchAddSpu ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('shop_id', form.shop_id)
params.append('path', form.path)
params.append('name', form.name)
params.append('spu_number', form.spu_number)
params.append('sort', form.sort)
params.append('hot', form.hot)
params.append('pro_tag', JSON.stringify(form.pro_tag))
params.append('bind_sku', JSON.stringify(form.bind_sku))
params.append('upFile', form.upFile)
if (form.recommend) {
params.append('recommend', '1')
} else {
params.append('recommend', '0')
}
if (form.show) {
params.append('show', '1')
} else {
params.append('show', '0')
}
const res = await api.post('addSpu', params, 'Admin')
if (res.data.status === 1) {
await dispatch('fetchSpuList')// 刷新商品列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 更新商品 spu
* @param {*} form 表单.商品信息
* @return {*} 服务器返回信息
*/
async fetchSaveSpu ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('id', form.id)
params.append('shop_id', form.shop_id)
params.append('path', form.path)
params.append('name', form.name)
params.append('spu_number', form.spu_number)
params.append('sort', form.sort)
params.append('hot', form.hot)
params.append('pro_tag', JSON.stringify(form.pro_tag))
params.append('bind_sku', JSON.stringify(form.bind_sku))
params.append('oldFile', form.oldFile)
params.append('upFile', form.upFile)
if (form.recommend) {
params.append('recommend', '1')
} else {
params.append('recommend', '0')
}
if (form.show) {
params.append('show', '1')
} else {
params.append('show', '0')
}
const res = await api.post('saveSpu', params, 'Admin')
if (res.data.status === 1) {
await dispatch('fetchSpuList')// 刷新商品列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 删除spu
* @param {*} 多选id组
*/
async fetchDelSpu ({ 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('deleteSpu', params, 'Admin').then(res => {
if (res.data.status === 1) {
Message.success(res.data.msg)
dispatch('fetchSpuList')// 刷新列表
} else {
Message.error(res.data.msg)
}
})
}).catch(() => {
Message.info('取消操作')
})
}
},
/**
* @description: 获取商品sku列表
* @return {*} 列表
*/
async fetchSkuList ({ commit }) {
const res = await api.get('getSkuList', 'Admin')
if (res.data.status === 1) {
res.data.skuList.forEach((sku, index) => {
sku.photo = JSON.parse(sku.photo)// 反序列化 photo字段
sku.photo.forEach((photo, i) => {
res.data.skuList[index].photo[i] = settings.state.skuPath + photo // 把绝对路径加上
})
})
commit('setSkuList', res.data.skuList)
} else {
commit('setSkuList', [])
}
return res
},
/**
* @description: 添加商品 sku
* @param {*} form 表单.商品信息
* @return {*} 服务器返回信息
*/
async fetchAddSku ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('shop_id', form.shop_id)
params.append('name', form.name)
params.append('sku_number', form.sku_number)
params.append('price', form.price)
params.append('unit', form.unit)
params.append('weight', form.weight)
params.append('stock', form.stock)
params.append('purchase_channel', form.purchase_channel)
params.append('upFile', form.upFile)
const res = await api.post('addSku', params, 'Admin')
if (res.data.status === 1) {
await dispatch('fetchSkuList')// 刷新商品列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 更新商品 sku
* @param {*} form 表单.商品信息
* @return {*} 服务器返回信息
*/
async fetchSaveSku ({ 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('sku_number', form.sku_number)
params.append('price', form.price)
params.append('unit', form.unit)
params.append('weight', form.weight)
params.append('stock', form.stock)
params.append('purchase_channel', form.purchase_channel)
params.append('oldFile', form.oldFile)
params.append('upFile', form.upFile)
const res = await api.post('saveSku', params, 'Admin')
if (res.data.status === 1) {
await dispatch('fetchSkuList')// 刷新商品列表
Message.success(res.data.msg)
} else {
Message.error(res.data.msg)
}
return res
},
/**
* @description: 删除sku
* @param {*} 多选id组
*/
async fetchDelSku ({ 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('deleteSku', params, 'Admin').then(res => {
if (res.data.status === 1) {
Message.success(res.data.msg)
dispatch('fetchSkuList')// 刷新列表
} else {
Message.error(res.data.msg)
}
})
}).catch(() => {
Message.info('取消操作')
})
}
},
/**
* @description: 获取已付款 和已退款但是发货状态为 已发货 订单列表
* @return {*} 列表
*/
async fetchPaidOrderList ({ commit }) {
const res = await api.get('getPaidOrderList', 'Admin')
if (res.data.status === 1) {
const list = res.data.paidOrderList
list.forEach((item, index) => { // 拿到订单列表数据 直接把订单列表数据反序列化
if (item.product_snapshot !== '') {
list[index].product_snapshot = JSON.parse(item.product_snapshot)
}
})
commit('setPaidOrderList', list)
} else {
commit('setPaidOrderList', [])
}
return res
},
/**
* @description: 异步获取管理员消息列表 成功获取之后 弹出通知框 显示列表
*/
async fetchMessageList ({ commit }) {
const res = await api.get('getMessageList', 'Admin')
if (res.data.status === 1) {
const list = res.data.messageList || []
commit('setMessageList', list)
// 弹出通知
list.forEach((item, index) => {
const formattedTime = parseTime(item.add_time, '{m}-{d} {h}:{i}')
const sender = item.admin_uname || '管理员'
setTimeout(() => {
Notification({
title: item.tit || '通知',
message: `
<div>
<div>${item.message || ''}</div>
<div style="display: flex; justify-content: flex-end;">
<div style="color: #aaa;">BY. ${sender} ${formattedTime}</span>
</div>
</div>
`,
duration: 8000,
dangerouslyUseHTMLString: true // 启用 HTML 格式
})
}, index * 800)
})
} else {
Message.error(res.data.msg || '获取消息失败')
commit('setMessageList', [])
}
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)
/* 积攒 向服务器提交 日志 待续写... */
},
/**
* @description: 获取地图样式列表
* @param {*} param0.rootState 传this.$store.state.settings.host 即云端存放sprite 的地址
*/
async fetchMapStyleList ({ commit, rootState }) {
const res = await api.get('getMapStyleList', 'Plane')
if (res.data.status === 1) {
const host = rootState.settings.host
const list = res.data.mapStyleList.map(style => {
const tiles = Array.isArray(style.tiles) ? style.tiles : JSON.parse(style.tiles)
const sourceKey = 'default'
const spriteUrl = style.sprite && String(style.sprite).trim() ? style.sprite : `${host}/Public/map/sprite`
return {
// 附带原始字段,便于管理端展示和操作
id: style.id,
is_active: Number(style.is_active ?? 1),
sort_order: Number(style.sort_order ?? 0),
name: style.name,
sprite: spriteUrl,
glyphs: 'mapbox://fonts/mapbox/{fontstack}/{range}.pbf',
version: 8,
sources: {
[sourceKey]: {
type: 'raster',
tileSize: 256,
tiles,
attribution: ''
}
},
layers: [{
id: `${sourceKey}Layer`,
type: 'raster',
source: sourceKey
}]
}
})
commit('setMapStyleList', list)
} else {
commit('setMapStyleList', [])
Message.error(res.data.msg || '地图样式获取失败')
}
},
/**
* @description: 地图样式排序
* @param {*} form { id, sort_order }
*/
async fetchOrderMapStyle ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('id', form.id)
params.append('sort_order', form.sort_order)
const res = await api.post('orderMapStyle', params, 'Plane')
if (res.data.status === 1) {
await dispatch('fetchMapStyleList') // 刷新样式列表
Message.success(res.data.msg || '排序已更新')
} else {
Message.error(res.data.msg || '排序更新失败')
}
return res
},
/**
* @description: 删除地图样式
* @param {Array} idArr 需要删除的样式ID数组
*/
async fetchDelMapStyle ({ dispatch }, idArr) {
if (!idArr || !idArr.length) {
Message.warning('请选择要删除的样式')
return Promise.reject(new Error('未选择要删除的样式'))
}
try {
await MessageBox.confirm(
`确定要删除选中的 ${idArr.length} 个地图样式吗?删除后不可恢复!`,
'提示',
{
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
closeOnClickModal: false
}
)
const params = new URLSearchParams()
params.append('id', idArr.join(','))
const res = await api.post('delMapStyle', params, 'Plane')
if (res.data.status === 1) {
Message.success(res.data.msg || '删除成功')
// 重新获取样式列表
await dispatch('fetchMapStyleList')
} else {
Message.error(res.data.msg || '删除失败')
}
return res
} catch (error) {
if (error !== 'cancel') {
console.error('删除样式失败:', error)
Message.error('删除失败')
throw error
}
return Promise.reject(new Error('用户取消删除'))
}
}
},
modules: {
app,
settings,
user
},
getters: {
}
})
export default store