mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-27 17:50:53 +01:00
added setup.py
This commit is contained in:
43
frontend/src/store/modules/app.js
Normal file
43
frontend/src/store/modules/app.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
const app = {
|
||||
state: {
|
||||
sidebar: {
|
||||
opened: !+Cookies.get('sidebarStatus'),
|
||||
withoutAnimation: false
|
||||
},
|
||||
device: 'desktop'
|
||||
},
|
||||
mutations: {
|
||||
TOGGLE_SIDEBAR: state => {
|
||||
if (state.sidebar.opened) {
|
||||
Cookies.set('sidebarStatus', 1)
|
||||
} else {
|
||||
Cookies.set('sidebarStatus', 0)
|
||||
}
|
||||
state.sidebar.opened = !state.sidebar.opened
|
||||
state.sidebar.withoutAnimation = false
|
||||
},
|
||||
CLOSE_SIDEBAR: (state, withoutAnimation) => {
|
||||
Cookies.set('sidebarStatus', 1)
|
||||
state.sidebar.opened = false
|
||||
state.sidebar.withoutAnimation = withoutAnimation
|
||||
},
|
||||
TOGGLE_DEVICE: (state, device) => {
|
||||
state.device = device
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
ToggleSideBar: ({ commit }) => {
|
||||
commit('TOGGLE_SIDEBAR')
|
||||
},
|
||||
CloseSideBar ({ commit }, { withoutAnimation }) {
|
||||
commit('CLOSE_SIDEBAR', withoutAnimation)
|
||||
},
|
||||
ToggleDevice ({ commit }, device) {
|
||||
commit('TOGGLE_DEVICE', device)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default app
|
||||
34
frontend/src/store/modules/deploy.js
Normal file
34
frontend/src/store/modules/deploy.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import request from '../../api/request'
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
const state = {
|
||||
deployList: []
|
||||
}
|
||||
|
||||
const getters = {}
|
||||
|
||||
const mutations = {
|
||||
SET_DEPLOY_LIST (state, value) {
|
||||
state.deployList = value
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
getDeployList ({ state, commit }) {
|
||||
request.get('/deploys')
|
||||
.then(response => {
|
||||
commit('SET_DEPLOY_LIST', response.data.items.map(d => {
|
||||
if (d.finish_ts) d.finish_ts = dayjs(d.finish_ts.$date).format('YYYY-MM-DD HH:mm:ss')
|
||||
return d
|
||||
}).sort((a, b) => a.finish_ts < b.finish_ts ? 1 : -1))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
mutations,
|
||||
actions
|
||||
}
|
||||
19
frontend/src/store/modules/dialogView.js
Normal file
19
frontend/src/store/modules/dialogView.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const dialogView = {
|
||||
namespaced: true,
|
||||
state: {
|
||||
dialogType: '',
|
||||
dialogVisible: false
|
||||
},
|
||||
getters: {},
|
||||
mutations: {
|
||||
SET_DIALOG_TYPE (state, value) {
|
||||
state.dialogType = value
|
||||
},
|
||||
SET_DIALOG_VISIBLE (state, value) {
|
||||
state.dialogVisible = value
|
||||
}
|
||||
},
|
||||
actions: {}
|
||||
}
|
||||
|
||||
export default dialogView
|
||||
52
frontend/src/store/modules/file.js
Normal file
52
frontend/src/store/modules/file.js
Normal file
@@ -0,0 +1,52 @@
|
||||
import request from '../../api/request'
|
||||
|
||||
const state = {
|
||||
currentPath: '',
|
||||
fileList: []
|
||||
}
|
||||
|
||||
const getters = {}
|
||||
|
||||
const mutations = {
|
||||
SET_CURRENT_PATH (state, value) {
|
||||
state.currentPath = value
|
||||
},
|
||||
SET_FILE_LIST (state, value) {
|
||||
state.fileList = value
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
getFileList ({ commit }, path) {
|
||||
commit('SET_CURRENT_PATH', path)
|
||||
request.get('/files', { path })
|
||||
.then(response => {
|
||||
let list = []
|
||||
list = list.concat(response.data.folders.map(d => {
|
||||
return { path: d, type: 2 }
|
||||
}))
|
||||
list = list.concat(response.data.files.map(d => {
|
||||
return { path: d, type: 1 }
|
||||
}))
|
||||
commit('SET_FILE_LIST', list)
|
||||
})
|
||||
},
|
||||
getDefaultPath ({ commit }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
request.get('/files/getDefaultPath')
|
||||
.then(response => {
|
||||
commit('SET_CURRENT_PATH', response.data.defaultPath)
|
||||
resolve(response.data.defaultPath)
|
||||
})
|
||||
.catch(reject)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
mutations,
|
||||
actions
|
||||
}
|
||||
99
frontend/src/store/modules/node.js
Normal file
99
frontend/src/store/modules/node.js
Normal file
@@ -0,0 +1,99 @@
|
||||
import request from '../../api/request'
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
const state = {
|
||||
// NodeList
|
||||
nodeList: [],
|
||||
nodeForm: { _id: {} },
|
||||
|
||||
// spider to deploy/run
|
||||
activeSpider: {}
|
||||
}
|
||||
|
||||
const getters = {}
|
||||
|
||||
const mutations = {
|
||||
SET_NODE_FORM (state, value) {
|
||||
state.nodeForm = value
|
||||
},
|
||||
SET_NODE_LIST (state, value) {
|
||||
state.nodeList = value
|
||||
},
|
||||
SET_ACTIVE_SPIDER (state, value) {
|
||||
state.activeSpider = value
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
getNodeList ({ state, commit }) {
|
||||
request.get('/nodes', {})
|
||||
.then(response => {
|
||||
commit('SET_NODE_LIST', response.data.items)
|
||||
})
|
||||
},
|
||||
addNode ({ state, dispatch }) {
|
||||
request.put('/nodes', {
|
||||
name: state.nodeForm.name,
|
||||
ip: state.nodeForm.ip,
|
||||
port: state.nodeForm.port,
|
||||
description: state.nodeForm.description
|
||||
})
|
||||
.then(() => {
|
||||
dispatch('getNodeList')
|
||||
})
|
||||
},
|
||||
editNode ({ state, dispatch }) {
|
||||
request.post(`/nodes/${state.nodeForm._id}`, {
|
||||
name: state.nodeForm.name,
|
||||
ip: state.nodeForm.ip,
|
||||
port: state.nodeForm.port,
|
||||
description: state.nodeForm.description
|
||||
})
|
||||
.then(() => {
|
||||
dispatch('getNodeList')
|
||||
})
|
||||
},
|
||||
deleteNode ({ state, dispatch }, id) {
|
||||
request.delete(`/nodes/${id}`)
|
||||
.then(() => {
|
||||
dispatch('getNodeList')
|
||||
})
|
||||
},
|
||||
getNodeData ({ state, commit }, id) {
|
||||
request.get(`/nodes/${id}`)
|
||||
.then(response => {
|
||||
commit('SET_NODE_FORM', response.data)
|
||||
})
|
||||
},
|
||||
getDeployList ({ state, commit }, id) {
|
||||
return request.get(`/nodes/${id}/get_deploys`)
|
||||
.then(response => {
|
||||
commit('deploy/SET_DEPLOY_LIST',
|
||||
response.data.items.map(d => {
|
||||
if (d.finish_ts) d.finish_ts = dayjs(d.finish_ts.$date).format('YYYY-MM-DD HH:mm:ss')
|
||||
return d
|
||||
}).sort((a, b) => a.finish_ts < b.finish_ts ? 1 : -1),
|
||||
{ root: true })
|
||||
})
|
||||
},
|
||||
getTaskList ({ state, commit }, id) {
|
||||
return request.get(`/nodes/${id}/get_tasks`)
|
||||
.then(response => {
|
||||
commit('task/SET_TASK_LIST',
|
||||
response.data.items.map(d => {
|
||||
if (d.create_ts) d.create_ts = dayjs(d.create_ts.$date).format('YYYY-MM-DD HH:mm:ss')
|
||||
if (d.finish_ts) d.finish_ts = dayjs(d.finish_ts.$date).format('YYYY-MM-DD HH:mm:ss')
|
||||
return d
|
||||
}).sort((a, b) => a.create_ts < b.create_ts ? 1 : -1),
|
||||
{ root: true })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
mutations,
|
||||
actions
|
||||
}
|
||||
127
frontend/src/store/modules/spider.js
Normal file
127
frontend/src/store/modules/spider.js
Normal file
@@ -0,0 +1,127 @@
|
||||
import dayjs from 'dayjs'
|
||||
import request from '../../api/request'
|
||||
|
||||
const state = {
|
||||
// list of spiders
|
||||
spiderList: [],
|
||||
|
||||
// active spider data
|
||||
spiderForm: { _id: {} },
|
||||
|
||||
// node to deploy/run
|
||||
activeNode: {},
|
||||
|
||||
// upload form for importing spiders
|
||||
importForm: {}
|
||||
}
|
||||
|
||||
const getters = {}
|
||||
|
||||
const mutations = {
|
||||
SET_SPIDER_FORM (state, value) {
|
||||
state.spiderForm = value
|
||||
},
|
||||
SET_SPIDER_LIST (state, value) {
|
||||
state.spiderList = value
|
||||
},
|
||||
SET_ACTIVE_NODE (state, value) {
|
||||
state.activeNode = value
|
||||
},
|
||||
SET_IMPORT_FORM (state, value) {
|
||||
state.importForm = value
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
getSpiderList ({ state, commit }) {
|
||||
return request.get('/spiders', {})
|
||||
.then(response => {
|
||||
commit('SET_SPIDER_LIST', response.data.items)
|
||||
})
|
||||
},
|
||||
addSpider ({ state, dispatch }) {
|
||||
return request.put('/spiders', {
|
||||
name: state.spiderForm.name,
|
||||
src: state.spiderForm.src,
|
||||
cmd: state.spiderForm.cmd,
|
||||
type: state.spiderForm.type,
|
||||
lang: state.spiderForm.lang
|
||||
})
|
||||
.then(() => {
|
||||
dispatch('getSpiderList')
|
||||
})
|
||||
},
|
||||
editSpider ({ state, dispatch }) {
|
||||
return request.post(`/spiders/${state.spiderForm._id.$oid}`, {
|
||||
name: state.spiderForm.name,
|
||||
src: state.spiderForm.src,
|
||||
cmd: state.spiderForm.cmd,
|
||||
type: state.spiderForm.type,
|
||||
lang: state.spiderForm.lang
|
||||
})
|
||||
.then(() => {
|
||||
dispatch('getSpiderList')
|
||||
})
|
||||
},
|
||||
deleteSpider ({ state, dispatch }, id) {
|
||||
return request.delete(`/spiders/${id}`)
|
||||
.then(() => {
|
||||
dispatch('getSpiderList')
|
||||
})
|
||||
},
|
||||
getSpiderData ({ state, commit }, id) {
|
||||
return request.get(`/spiders/${id}`)
|
||||
.then(response => {
|
||||
commit('SET_SPIDER_FORM', response.data)
|
||||
})
|
||||
},
|
||||
deploySpider ({ state, dispatch }, { id, nodeId }) {
|
||||
return request.post(`/spiders/${id}/deploy`, {
|
||||
node_id: nodeId
|
||||
})
|
||||
.then(response => {
|
||||
console.log(response.data)
|
||||
})
|
||||
},
|
||||
crawlSpider ({ state, dispatch }, payload) {
|
||||
const { id, nodeId } = payload
|
||||
return request.post(`/spiders/${id}/crawl`, {
|
||||
node_id: nodeId
|
||||
})
|
||||
.then(response => {
|
||||
console.log(response.data)
|
||||
})
|
||||
},
|
||||
getDeployList ({ state, commit }, id) {
|
||||
return request.get(`/spiders/${id}/get_deploys`)
|
||||
.then(response => {
|
||||
commit('deploy/SET_DEPLOY_LIST',
|
||||
response.data.items.map(d => {
|
||||
if (d.finish_ts) d.finish_ts = dayjs(d.finish_ts.$date).format('YYYY-MM-DD HH:mm:ss')
|
||||
return d
|
||||
}).sort((a, b) => a.finish_ts < b.finish_ts ? 1 : -1),
|
||||
{ root: true })
|
||||
})
|
||||
},
|
||||
getTaskList ({ state, commit }, id) {
|
||||
return request.get(`/spiders/${id}/get_tasks`)
|
||||
.then(response => {
|
||||
commit('task/SET_TASK_LIST',
|
||||
response.data.items.map(d => {
|
||||
if (d.create_ts) d.create_ts = dayjs(d.create_ts.$date).format('YYYY-MM-DD HH:mm:ss')
|
||||
if (d.finish_ts) d.finish_ts = dayjs(d.finish_ts.$date).format('YYYY-MM-DD HH:mm:ss')
|
||||
return d
|
||||
}).sort((a, b) => a.create_ts < b.create_ts ? 1 : -1),
|
||||
{ root: true })
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
mutations,
|
||||
actions
|
||||
}
|
||||
161
frontend/src/store/modules/tagsView.js
Normal file
161
frontend/src/store/modules/tagsView.js
Normal file
@@ -0,0 +1,161 @@
|
||||
const tagsView = {
|
||||
state: {
|
||||
visitedViews: [],
|
||||
cachedViews: []
|
||||
},
|
||||
mutations: {
|
||||
ADD_VISITED_VIEW: (state, view) => {
|
||||
if (state.visitedViews.some(v => v.path === view.path)) return
|
||||
state.visitedViews.push(
|
||||
Object.assign({}, view, {
|
||||
title: view.meta.title || 'no-name'
|
||||
})
|
||||
)
|
||||
},
|
||||
ADD_CACHED_VIEW: (state, view) => {
|
||||
if (state.cachedViews.includes(view.name)) return
|
||||
if (!view.meta.noCache) {
|
||||
state.cachedViews.push(view.name)
|
||||
}
|
||||
},
|
||||
|
||||
DEL_VISITED_VIEW: (state, view) => {
|
||||
for (const [i, v] of state.visitedViews.entries()) {
|
||||
if (v.path === view.path) {
|
||||
state.visitedViews.splice(i, 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
},
|
||||
DEL_CACHED_VIEW: (state, view) => {
|
||||
for (const i of state.cachedViews) {
|
||||
if (i === view.name) {
|
||||
const index = state.cachedViews.indexOf(i)
|
||||
state.cachedViews.splice(index, 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
DEL_OTHERS_VISITED_VIEWS: (state, view) => {
|
||||
state.visitedViews = state.visitedViews.filter(v => {
|
||||
return v.meta.affix || v.path === view.path
|
||||
})
|
||||
},
|
||||
DEL_OTHERS_CACHED_VIEWS: (state, view) => {
|
||||
for (const i of state.cachedViews) {
|
||||
if (i === view.name) {
|
||||
const index = state.cachedViews.indexOf(i)
|
||||
state.cachedViews = state.cachedViews.slice(index, index + 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
DEL_ALL_VISITED_VIEWS: state => {
|
||||
// keep affix tags
|
||||
const affixTags = state.visitedViews.filter(tag => tag.meta.affix)
|
||||
state.visitedViews = affixTags
|
||||
},
|
||||
DEL_ALL_CACHED_VIEWS: state => {
|
||||
state.cachedViews = []
|
||||
},
|
||||
|
||||
UPDATE_VISITED_VIEW: (state, view) => {
|
||||
for (let v of state.visitedViews) {
|
||||
if (v.path === view.path) {
|
||||
v = Object.assign(v, view)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
actions: {
|
||||
addView ({ dispatch }, view) {
|
||||
dispatch('addVisitedView', view)
|
||||
dispatch('addCachedView', view)
|
||||
},
|
||||
addVisitedView ({ commit }, view) {
|
||||
commit('ADD_VISITED_VIEW', view)
|
||||
},
|
||||
addCachedView ({ commit }, view) {
|
||||
commit('ADD_CACHED_VIEW', view)
|
||||
},
|
||||
|
||||
delView ({ dispatch, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
dispatch('delVisitedView', view)
|
||||
dispatch('delCachedView', view)
|
||||
resolve({
|
||||
visitedViews: [...state.visitedViews],
|
||||
cachedViews: [...state.cachedViews]
|
||||
})
|
||||
})
|
||||
},
|
||||
delVisitedView ({ commit, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
commit('DEL_VISITED_VIEW', view)
|
||||
resolve([...state.visitedViews])
|
||||
})
|
||||
},
|
||||
delCachedView ({ commit, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
commit('DEL_CACHED_VIEW', view)
|
||||
resolve([...state.cachedViews])
|
||||
})
|
||||
},
|
||||
|
||||
delOthersViews ({ dispatch, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
dispatch('delOthersVisitedViews', view)
|
||||
dispatch('delOthersCachedViews', view)
|
||||
resolve({
|
||||
visitedViews: [...state.visitedViews],
|
||||
cachedViews: [...state.cachedViews]
|
||||
})
|
||||
})
|
||||
},
|
||||
delOthersVisitedViews ({ commit, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
commit('DEL_OTHERS_VISITED_VIEWS', view)
|
||||
resolve([...state.visitedViews])
|
||||
})
|
||||
},
|
||||
delOthersCachedViews ({ commit, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
commit('DEL_OTHERS_CACHED_VIEWS', view)
|
||||
resolve([...state.cachedViews])
|
||||
})
|
||||
},
|
||||
|
||||
delAllViews ({ dispatch, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
dispatch('delAllVisitedViews', view)
|
||||
dispatch('delAllCachedViews', view)
|
||||
resolve({
|
||||
visitedViews: [...state.visitedViews],
|
||||
cachedViews: [...state.cachedViews]
|
||||
})
|
||||
})
|
||||
},
|
||||
delAllVisitedViews ({ commit, state }) {
|
||||
return new Promise(resolve => {
|
||||
commit('DEL_ALL_VISITED_VIEWS')
|
||||
resolve([...state.visitedViews])
|
||||
})
|
||||
},
|
||||
delAllCachedViews ({ commit, state }) {
|
||||
return new Promise(resolve => {
|
||||
commit('DEL_ALL_CACHED_VIEWS')
|
||||
resolve([...state.cachedViews])
|
||||
})
|
||||
},
|
||||
|
||||
updateVisitedView ({ commit }, view) {
|
||||
commit('UPDATE_VISITED_VIEW', view)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default tagsView
|
||||
66
frontend/src/store/modules/task.js
Normal file
66
frontend/src/store/modules/task.js
Normal file
@@ -0,0 +1,66 @@
|
||||
import dayjs from 'dayjs'
|
||||
import request from '../../api/request'
|
||||
|
||||
const state = {
|
||||
// TaskList
|
||||
taskList: [],
|
||||
taskForm: {},
|
||||
taskLog: ''
|
||||
}
|
||||
|
||||
const getters = {}
|
||||
|
||||
const mutations = {
|
||||
SET_TASK_FORM (state, value) {
|
||||
state.taskForm = value
|
||||
},
|
||||
SET_TASK_LIST (state, value) {
|
||||
state.taskList = value
|
||||
},
|
||||
SET_TASK_LOG (state, value) {
|
||||
state.taskLog = value
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
getTaskData ({ state, dispatch, commit }, id) {
|
||||
return request.get(`/tasks/${id}`)
|
||||
.then(response => {
|
||||
let data = response.data
|
||||
if (data.create_ts && data.finish_ts) {
|
||||
data.duration = dayjs(data.finish_ts.$date).diff(dayjs(data.create_ts.$date), 'second')
|
||||
}
|
||||
if (data.create_ts) data.create_ts = dayjs(data.create_ts.$date).format('YYYY-MM-DD HH:mm:ss')
|
||||
if (data.finish_ts) data.finish_ts = dayjs(data.finish_ts.$date).format('YYYY-MM-DD HH:mm:ss')
|
||||
commit('SET_TASK_FORM', data)
|
||||
dispatch('spider/getSpiderData', data.spider_id.$oid, { root: true })
|
||||
dispatch('node/getNodeData', data.node_id, { root: true })
|
||||
})
|
||||
},
|
||||
getTaskList ({ state, commit }) {
|
||||
return request.get('/tasks', {})
|
||||
.then(response => {
|
||||
commit('SET_TASK_LIST', response.data.items)
|
||||
})
|
||||
},
|
||||
deleteTask ({ state, dispatch }, id) {
|
||||
return request.delete(`/tasks/${id}`)
|
||||
.then(() => {
|
||||
dispatch('getTaskList')
|
||||
})
|
||||
},
|
||||
getTaskLog ({ state, commit }, id) {
|
||||
return request.get(`/tasks/${id}/get_log`)
|
||||
.then(response => {
|
||||
commit('SET_TASK_LOG', response.data.log)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
mutations,
|
||||
actions
|
||||
}
|
||||
87
frontend/src/store/modules/user.js
Normal file
87
frontend/src/store/modules/user.js
Normal file
@@ -0,0 +1,87 @@
|
||||
import { login, logout, getInfo } from '@/api/login'
|
||||
import { getToken, setToken, removeToken } from '@/utils/auth'
|
||||
|
||||
const user = {
|
||||
state: {
|
||||
token: getToken(),
|
||||
name: '',
|
||||
avatar: '',
|
||||
roles: []
|
||||
},
|
||||
|
||||
mutations: {
|
||||
SET_TOKEN: (state, token) => {
|
||||
state.token = token
|
||||
},
|
||||
SET_NAME: (state, name) => {
|
||||
state.name = name
|
||||
},
|
||||
SET_AVATAR: (state, avatar) => {
|
||||
state.avatar = avatar
|
||||
},
|
||||
SET_ROLES: (state, roles) => {
|
||||
state.roles = roles
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
// 登录
|
||||
Login ({ commit }, userInfo) {
|
||||
const username = userInfo.username.trim()
|
||||
return new Promise((resolve, reject) => {
|
||||
login(username, userInfo.password).then(response => {
|
||||
const data = response.data
|
||||
setToken(data.token)
|
||||
commit('SET_TOKEN', data.token)
|
||||
resolve()
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
// 获取用户信息
|
||||
GetInfo ({ commit, state }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
getInfo(state.token).then(response => {
|
||||
const data = response.data
|
||||
if (data.roles && data.roles.length > 0) { // 验证返回的roles是否是一个非空数组
|
||||
commit('SET_ROLES', data.roles)
|
||||
} else {
|
||||
reject(new Error('getInfo: roles must be a non-null array !'))
|
||||
}
|
||||
commit('SET_NAME', data.name)
|
||||
commit('SET_AVATAR', data.avatar)
|
||||
resolve(response)
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
// 登出
|
||||
LogOut ({ commit, state }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
logout(state.token).then(() => {
|
||||
commit('SET_TOKEN', '')
|
||||
commit('SET_ROLES', [])
|
||||
removeToken()
|
||||
resolve()
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
// 前端 登出
|
||||
FedLogOut ({ commit }) {
|
||||
return new Promise(resolve => {
|
||||
commit('SET_TOKEN', '')
|
||||
removeToken()
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default user
|
||||
Reference in New Issue
Block a user