From ec20b7391ef8a6ce56d3a350ee9d044064f8bc03 Mon Sep 17 00:00:00 2001 From: ronger Date: Mon, 14 Mar 2022 14:51:20 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=BC=80=E6=94=BE=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/layouts/pc/header.vue | 6 + pages/open-data.vue | 181 +++++++++++++++++++++++++++++++ store/open-data.js | 79 ++++++++++++++ 3 files changed, 266 insertions(+) create mode 100644 pages/open-data.vue create mode 100644 store/open-data.js diff --git a/components/layouts/pc/header.vue b/components/layouts/pc/header.vue index 67bb54b..e7fdd9f 100644 --- a/components/layouts/pc/header.vue +++ b/components/layouts/pc/header.vue @@ -24,6 +24,7 @@ + 开放数据 @@ -250,6 +251,11 @@ export default { case 'taobao': window.open("https://rymcu.taobao.com?utm_source=rymcu.com"); break; + case 'open-data': + _ts.$router.push({ + path: '/open-data' + }) + break; default: _ts.$router.push( { diff --git a/pages/open-data.vue b/pages/open-data.vue new file mode 100644 index 0000000..9932273 --- /dev/null +++ b/pages/open-data.vue @@ -0,0 +1,181 @@ + + + + + diff --git a/store/open-data.js b/store/open-data.js new file mode 100644 index 0000000..ecdeb9a --- /dev/null +++ b/store/open-data.js @@ -0,0 +1,79 @@ +import {DASHBOARD_API_PATH} from "@/store/dashboard"; + +/** + * Created on 2022/3/14 13:54. + * @author ronger + * @email ronger-x@outlook.com + */ +export const OPEN_DATA_API_PATH = '/api/open-data' + + +const getDefaultDashboardData = () => { + return { + dashboard: {} + } +} + +const getDefaultLastThirtyDaysData = () => { + return { + dates: [], + visits: [], + visitIps: [] + } +} + +export const state = () => { + return { + fetching: false, + data: getDefaultDashboardData(), + lastThirtyDays: getDefaultLastThirtyDaysData(), + history: getDefaultLastThirtyDaysData() + } +} + +export const mutations = { + updateDashboardFetching(state, action) { + state.fetching = action + }, + updateDashboardData(state, action) { + state.data = action + }, + updateLastThirtyDaysData(state, action) { + state.lastThirtyDays = action + } +} + +export const actions = { + fetchDashboard({commit}, params = {}) { + // 清空已有数据 + commit('updateDashboardData', getDefaultDashboardData()) + commit('updateDashboardFetching', true) + + return this.$axios + .$get(`${OPEN_DATA_API_PATH}/dashboard`) + .then(response => { + commit('updateDashboardFetching', false); + commit('updateDashboardData', response); + }) + .catch(error => { + console.log(error); + commit('updateDashboardFetching', false); + }); + }, + fetchLastThirtyDays({commit}, params = {}) { + // 清空已有数据 + commit('updateLastThirtyDaysData', getDefaultLastThirtyDaysData()) + commit('updateDashboardFetching', true) + + return this.$axios + .$get(`${OPEN_DATA_API_PATH}/last-thirty-days`) + .then(response => { + commit('updateDashboardFetching', false); + commit('updateLastThirtyDaysData', response); + }) + .catch(error => { + console.log(error); + commit('updateDashboardFetching', false); + }); + } +}