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