diff --git a/src/api/home/index.js b/src/api/home/index.js new file mode 100644 index 0000000..d0d3a8f --- /dev/null +++ b/src/api/home/index.js @@ -0,0 +1,99 @@ +import request from '@/utils/request.js'; +// 获取头部数据 今日访客 今日订单 今日销售额 近七天销售额 +export const summary = () => { + return request({ + url: '/mall/base/frontPage/getHeaderData', + method: 'get', + }); +}; +// 获取待处理事务数据 +export const order = () => { + return request({ + url: '/mall/base/frontPage/getWaitHandleAffairs', + method: 'get', + }); +}; + +// 获取商品总览数据 +export const product = () => { + return request({ + url: '/mall/base/frontPage/getProductOverview', + method: 'get', + }); +}; +// 获取用户总览数据 +export const customer = () => { + return request({ + url: '/mall/base/frontPage/getUserOverviewData', + method: 'get', + }); +}; + +// 获取订单数量同比增长数据 +export const orderInfo = () => { + return request({ + url: '/mall/base/frontPage/getOrderTotal', + method: 'get', + }); +}; +// 获取订单统计数据 +export const orderSummary = (params) => { + return request({ + url: '/mall/base/frontPage/listOrderStatistics', + method: 'get', + params, + }); +}; +// 获取今日订单统计数据 +export const orderToday = () => { + return request({ + url: '/mall/base/frontPage/listOrderStatistics', + method: 'get', + }); +}; + +// 获取访客数量同比增长数据 +export const customerInfo = () => { + return request({ + url: '/mall/base/frontPage/getVisitorTotal', + method: 'get', + }); +}; +// 获取访客统计数据 +export const customerSummary = (params) => { + return request({ + url: '/mall/base/frontPage/listVisitorStatistics', + method: 'get', + params, + }); +}; +// 获取今日访客统计数据 +export const customerToday = () => { + return request({ + url: '/mall/base/frontPage/listTodayVisitorStatistics', + method: 'get', + }); +}; + +// 获取销售额同比增长数据 +export const moneyInfo = () => { + return request({ + url: '/mall/base/frontPage/getSalesTotal', + method: 'get', + }); +}; +// 获取销售额统计数据 +export const moneySummary = (params) => { + return request({ + url: '/mall/base/frontPage/listSalesStatistics', + method: 'get', + params, + }); +}; +// 获取今日销售额统计数据 +export const moneyToday = () => { + return request({ + url: '/mall/base/frontPage/listTodaySalesStatistics', + method: 'get', + }); +}; diff --git a/src/store/modules/home/home.js b/src/store/modules/home/home.js index 5fb709c..976ee94 100644 --- a/src/store/modules/home/home.js +++ b/src/store/modules/home/home.js @@ -1,8 +1,6 @@ -import * as api from '@/api/system/notify.js'; -import { ElMessage, ElMessageBox } from '@/plugins/element-plus'; +import * as api from '@/api/home/index.js'; const state = () => ({ opts: { - init: false, summary: [ { label: '今日访客数', @@ -150,95 +148,153 @@ const state = () => ({ value: 5000, }, ], - }, - chart: [ - [ - { label: '1月', value: 152 }, - { label: '2月', value: 215 }, - { label: '3月', value: 198 }, - { label: '4月', value: 348 }, - { label: '5月', value: 111 }, - ], - [ - { label: '1月', value: 152 }, - { label: '2月', value: 215 }, - { label: '3月', value: 198 }, - { label: '4月', value: 348 }, - { label: '5月', value: 111 }, - ], - [ - { label: '1月', value: 152 }, - { label: '2月', value: 215 }, - { label: '3月', value: 198 }, - { label: '4月', value: 348 }, - { label: '5月', value: 111 }, + chart: [ + { + info: {}, + data: [ + { label: '1月', value: 152 }, + { label: '2月', value: 215 }, + { label: '3月', value: 198 }, + { label: '4月', value: 348 }, + { label: '5月', value: 111 }, + ], + }, + { + info: {}, + data: [ + { label: '1月', value: 152 }, + { label: '2月', value: 215 }, + { label: '3月', value: 198 }, + { label: '4月', value: 348 }, + { label: '5月', value: 111 }, + ], + }, + { + info: {}, + data: [ + { label: '1月', value: 152 }, + { label: '2月', value: 215 }, + { label: '3月', value: 198 }, + { label: '4月', value: 348 }, + { label: '5月', value: 111 }, + ], + }, ], - ], + }, + condition1: { + today: false, + beginDateTime: null, + endDateTime: null, + }, + condition2: { + today: false, + beginDateTime: null, + endDateTime: null, + }, + condition3: { + today: false, + beginDateTime: null, + endDateTime: null, + }, }); const getters = {}; const mutations = { - setCode: (state, data) => (state.code = data), - setCondition: (state, data) => (state.condition = data), - setList: (state, data) => (state.list = data), - setTotal: (state, data) => (state.total = data), - setOpts: (state, data) => (state.opts = data), + setSummary: (state, data) => { + state.opts.summary[0].value = data.todayVisitorCount || 0; + state.opts.summary[1].value = data.todayOrderCount || 0; + state.opts.summary[2].value = data.todaySales || 0; + state.opts.summary[3].value = data.lastSevenDaysSales || 0; + }, + setOrder: (state, data) => { + state.opts.order[0].value = data.waitPayCount || 0; + state.opts.order[1].value = data.waitRefundCount || 0; + state.opts.order[2].value = data.waitShipCount || 0; + state.opts.order[3].value = data.waitReturnGoodsCount || 0; + state.opts.order[4].value = data.shippedCount || 0; + }, + setProduct: (state, data) => { + state.opts.product[0].value = data.onTheShelfCount || 0; + state.opts.product[1].value = data.takeDownCount || 0; + state.opts.product[2].value = data.stockLessCount || 0; + state.opts.product[3].value = data.allCount || 0; + }, + setCustomer: (state, data) => { + state.opts.customer[0].value = data.todayIncreaseCount || 0; + state.opts.customer[1].value = data.yesterdayIncreaseCount || 0; + state.opts.customer[2].value = data.monthIncreaseCount || 0; + state.opts.customer[3].value = data.allCount || 0; + }, + setChartInfo1: (state, data) => (state.opts.chart[0].info = data), + setChartInfo2: (state, data) => (state.opts.chart[1].info = data), + setChartInfo3: (state, data) => (state.opts.chart[2].info = data), + setChartData1: (state, data) => (state.opts.chart[0].data = data), + setChartData2: (state, data) => (state.opts.chart[1].data = data), + setChartData3: (state, data) => (state.opts.chart[2].data = data), }; const actions = { - search: async ({ state, commit, rootGetters }) => { - let data = { ...state.condition }; - data.startReleaseTime = data.dateRange?.[0]; - data.endReleaseTime = data.dateRange?.[1]; - delete data.dateRange; - let res = await api.search({ ...rootGetters['local/page'](state.code), ...state.condition }); - if (res) { - commit('setList', res.records); - commit('setTotal', res.total); - } else { - ElMessage.error('查询失败'); - commit('setList', []); - } + loadSummary: async ({ commit }) => { + let res = await api.summary(); + commit('setSummary', res); + return res; + }, + loadOrder: async ({ commit }) => { + let res = await api.order(); + commit('setOrder', res); + return res; + }, + loadProduct: async ({ commit }) => { + let res = await api.product(); + commit('setProduct', res); + return res; + }, + loadCustomer: async ({ commit }) => { + let res = await api.customer(); + commit('setCustomer', res); return res; }, - load: async ({ commit }) => { - commit('setOpts', { - init: true, - }); + loadChartInfo1: async ({ commit }) => { + let res = await api.customerInfo(); + commit('setChartInfo1', res); + return res; + }, + loadChartInfo2: async ({ commit }) => { + let res = await api.orderInfo(); + commit('setChartInfo2', res); + return res; + }, + loadChartInfo3: async ({ commit }) => { + let res = await api.moneyInfo(); + commit('setChartInfo3', res); + return res; + }, + loadChartData1: async ({ state, commit }) => { + let res = await (state.condition1.today ? api.customerToday : api.customerSummary)(state.condition1); + commit('setChartData1', res); + return res; }, - detail: async (context, id) => { - let res = await api.detail(id); - if (!res) { - ElMessage.error('加载详情失败'); - } + loadChartData2: async ({ state, commit }) => { + let res = await (state.condition2.today ? api.orderToday : api.orderSummary)(state.condition2); + commit('setChartData2', res); return res; }, - save: async ({ dispatch }, data) => { - let save = data.id ? api.update : api.create; - let res = await save(data); - if (res) { - ElMessage.success('保存成功'); - dispatch('search'); - } else { - ElMessage.error('保存失败'); - } + loadChartData3: async ({ state, commit }) => { + let res = await (state.condition3.today ? api.orderToday : api.orderSummary)(state.condition3); + commit('setChartData3', res); return res; }, - remove: async ({ dispatch }, idList) => { - if (!idList.length) { - ElMessage.warning('请选择要删除的数据'); - } else { - try { - await ElMessageBox.confirm('数据删除后无法恢复,确定要删除吗?', '危险操作'); - let res = await api.remove(idList.join(',')); - if (res) { - ElMessage.success('删除成功'); - dispatch('search'); - } else { - ElMessage.error('删除失败'); - } - } catch (e) { - console.info('取消删除', e); - } - } + load: async ({ dispatch }) => { + return await Promise.all([ + dispatch('loadSummary'), + dispatch('loadOrder'), + dispatch('loadProduct'), + dispatch('loadCustomer'), + dispatch('loadChartInfo1'), + dispatch('loadChartInfo2'), + dispatch('loadChartInfo3'), + dispatch('loadChartData1'), + dispatch('loadChartData2'), + dispatch('loadChartData3'), + ]); }, }; export default { diff --git a/src/views/home/index.vue b/src/views/home/index.vue index f5872ac..851235a 100644 --- a/src/views/home/index.vue +++ b/src/views/home/index.vue @@ -166,7 +166,6 @@ const router = useRouter(); const store = useStore(); const opts = computed(() => store.state.home.opts); - const chartData = computed(() => store.state.home.chart); const handleRoute = (route) => router.push(route); const handleChart = (selector, color, name, data) => { const chart = echarts.init(document.querySelector(selector)); @@ -228,10 +227,11 @@ }; chart.setOption(option); }; - onMounted(() => { - handleChart('.row-5 .chart', '#80FFA5', '访客数量', unref(chartData)[0]); - handleChart('.row-6 .chart', '#00DDFF', '订单数量', unref(chartData)[1]); - handleChart('.row-7 .chart', '#37A2FF', '销售额', unref(chartData)[2]); + onActivated(async () => { + await store.dispatch('home/load'); + handleChart('.row-5 .chart', '#80FFA5', '访客数量', unref(opts).chart[0].data); + handleChart('.row-6 .chart', '#00DDFF', '订单数量', unref(opts).chart[1].data); + handleChart('.row-7 .chart', '#37A2FF', '销售额', unref(opts).chart[2].data); }); diff --git a/src/views/sales/product/form/step2.vue b/src/views/sales/product/form/step2.vue index 6cdb942..228d4e4 100644 --- a/src/views/sales/product/form/step2.vue +++ b/src/views/sales/product/form/step2.vue @@ -83,9 +83,9 @@ - + @@ -186,7 +186,7 @@ stock: 0, stockChange: 0, costPrice: 0, - warn: 100, + stockWarn: 100, isEnable: true, name: [], attributeSymbolList: [],