From b8a9e43033ba23b82da736fbbfa7e81ab14a68c7 Mon Sep 17 00:00:00 2001 From: Jay Date: Fri, 17 Aug 2018 23:59:19 +0800 Subject: [PATCH] add files --- src/store/actions.js | 25 +++++++++++++++++++++++++ src/store/mutations.js | 5 +++++ src/tools.js | 1 + 3 files changed, 31 insertions(+) create mode 100644 src/store/actions.js create mode 100644 src/store/mutations.js create mode 100644 src/tools.js diff --git a/src/store/actions.js b/src/store/actions.js new file mode 100644 index 0000000..7df911f --- /dev/null +++ b/src/store/actions.js @@ -0,0 +1,25 @@ +import axios from 'axios' +import {apiUrl} from '@/tools' + +const client = axios.create({ + baseURL: apiUrl, + withCredentials: true +}) + +export default { + async checkSession ({commit}, cb = null) { + commit('toggleLoading', true) + let flag = false + try { + await client({ + method: 'get', + url: '/api/session' + }) + flag = true + } catch (err) { + flag = false + } + if (typeof cb === 'function') cb(flag) + commit('toggleLoading', false) + } +} diff --git a/src/store/mutations.js b/src/store/mutations.js new file mode 100644 index 0000000..c23c6cc --- /dev/null +++ b/src/store/mutations.js @@ -0,0 +1,5 @@ +export default { + toggleLoading (state, loading = null) { + state.loading = !!loading + } +} diff --git a/src/tools.js b/src/tools.js new file mode 100644 index 0000000..c55365d --- /dev/null +++ b/src/tools.js @@ -0,0 +1 @@ +export const apiUrl = 'https://bot.trj.tw' \ No newline at end of file