mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-28 17:50:56 +01:00
* 增加Docker开发环境
* 更新Dockerfile构建文件,升级NodeJS依赖版本。 * 遵循ESLint重新格式化代码,修复部分警告 * 登录Token失效增加登出提示 * 网络请求问题增加错误错误提示 * 升级UI依赖库
This commit is contained in:
@@ -31,10 +31,10 @@ const app = {
|
||||
ToggleSideBar: ({ commit }) => {
|
||||
commit('TOGGLE_SIDEBAR')
|
||||
},
|
||||
CloseSideBar ({ commit }, { withoutAnimation }) {
|
||||
CloseSideBar({ commit }, { withoutAnimation }) {
|
||||
commit('CLOSE_SIDEBAR', withoutAnimation)
|
||||
},
|
||||
ToggleDevice ({ commit }, device) {
|
||||
ToggleDevice({ commit }, device) {
|
||||
commit('TOGGLE_DEVICE', device)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,13 +7,13 @@ const state = {
|
||||
const getters = {}
|
||||
|
||||
const mutations = {
|
||||
SET_DEPLOY_LIST (state, value) {
|
||||
SET_DEPLOY_LIST(state, value) {
|
||||
state.deployList = value
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
getDeployList ({ state, commit }) {
|
||||
getDeployList({ state, commit }) {
|
||||
request.get('/deploys')
|
||||
.then(response => {
|
||||
commit('SET_DEPLOY_LIST', response.data.items.map(d => {
|
||||
|
||||
@@ -6,10 +6,10 @@ const dialogView = {
|
||||
},
|
||||
getters: {},
|
||||
mutations: {
|
||||
SET_DIALOG_TYPE (state, value) {
|
||||
SET_DIALOG_TYPE(state, value) {
|
||||
state.dialogType = value
|
||||
},
|
||||
SET_DIALOG_VISIBLE (state, value) {
|
||||
SET_DIALOG_VISIBLE(state, value) {
|
||||
state.dialogVisible = value
|
||||
}
|
||||
},
|
||||
|
||||
@@ -7,13 +7,13 @@ const state = {
|
||||
const getters = {}
|
||||
|
||||
const mutations = {
|
||||
SET_DOC_DATA (state, value) {
|
||||
SET_DOC_DATA(state, value) {
|
||||
state.docData = value
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
async getDocData ({ commit }) {
|
||||
async getDocData({ commit }) {
|
||||
const res = await request.get('/docs')
|
||||
|
||||
const data = JSON.parse(res.data.data.string)
|
||||
@@ -22,8 +22,8 @@ const actions = {
|
||||
const cache = {}
|
||||
|
||||
// iterate paths
|
||||
for (let path in data) {
|
||||
if (data.hasOwnProperty(path)) {
|
||||
for (const path in data) {
|
||||
if (Object.prototype.hasOwnProperty.call(data, path)) {
|
||||
const d = data[path]
|
||||
if (path.match(/\/$/)) {
|
||||
cache[path] = d
|
||||
|
||||
@@ -9,19 +9,20 @@ const state = {
|
||||
const getters = {}
|
||||
|
||||
const mutations = {
|
||||
SET_CURRENT_PATH (state, value) {
|
||||
SET_CURRENT_PATH(state, value) {
|
||||
state.currentPath = value
|
||||
},
|
||||
SET_FILE_LIST (state, value) {
|
||||
|
||||
SET_FILE_LIST(state, value) {
|
||||
state.fileList = value
|
||||
},
|
||||
SET_FILE_CONTENT (state, value) {
|
||||
SET_FILE_CONTENT(state, value) {
|
||||
state.fileContent = value
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
getFileList ({ commit, rootState }, payload) {
|
||||
getFileList({ commit, rootState }, payload) {
|
||||
const { path } = payload
|
||||
const spiderId = rootState.spider.spiderForm._id
|
||||
commit('SET_CURRENT_PATH', path)
|
||||
@@ -36,7 +37,7 @@ const actions = {
|
||||
)
|
||||
})
|
||||
},
|
||||
getFileContent ({ commit, rootState }, payload) {
|
||||
getFileContent({ commit, rootState }, payload) {
|
||||
const { path } = payload
|
||||
const spiderId = rootState.spider.spiderForm._id
|
||||
return request.get(`/spiders/${spiderId}/file`, { path })
|
||||
@@ -44,30 +45,32 @@ const actions = {
|
||||
commit('SET_FILE_CONTENT', response.data.data)
|
||||
})
|
||||
},
|
||||
saveFileContent ({ state, rootState }, payload) {
|
||||
saveFileContent({ state, rootState }, payload) {
|
||||
const { path } = payload
|
||||
const spiderId = rootState.spider.spiderForm._id
|
||||
return request.post(`/spiders/${spiderId}/file`, { path, content: state.fileContent })
|
||||
return request.post(`/spiders/${spiderId}/file`,
|
||||
{ path, content: state.fileContent })
|
||||
},
|
||||
addFile ({ rootState }, payload) {
|
||||
addFile({ rootState }, payload) {
|
||||
const { path } = payload
|
||||
const spiderId = rootState.spider.spiderForm._id
|
||||
return request.put(`/spiders/${spiderId}/file`, { path })
|
||||
},
|
||||
addDir ({ rootState }, payload) {
|
||||
addDir({ rootState }, payload) {
|
||||
const { path } = payload
|
||||
const spiderId = rootState.spider.spiderForm._id
|
||||
return request.put(`/spiders/${spiderId}/dir`, { path })
|
||||
},
|
||||
deleteFile ({ rootState }, payload) {
|
||||
deleteFile({ rootState }, payload) {
|
||||
const { path } = payload
|
||||
const spiderId = rootState.spider.spiderForm._id
|
||||
return request.delete(`/spiders/${spiderId}/file`, { path })
|
||||
},
|
||||
renameFile ({ rootState }, payload) {
|
||||
renameFile({ rootState }, payload) {
|
||||
const { path, newPath } = payload
|
||||
const spiderId = rootState.spider.spiderForm._id
|
||||
return request.post(`/spiders/${spiderId}/file/rename`, { path, new_path: newPath })
|
||||
return request.post(`/spiders/${spiderId}/file/rename`,
|
||||
{ path, new_path: newPath })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ const state = {
|
||||
}
|
||||
|
||||
const getters = {
|
||||
lang (state) {
|
||||
lang(state) {
|
||||
if (state.lang === 'en') {
|
||||
return 'English'
|
||||
} else if (state.lang === 'zh') {
|
||||
@@ -15,7 +15,7 @@ const getters = {
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
SET_LANG (state, value) {
|
||||
SET_LANG(state, value) {
|
||||
state.lang = value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,16 +12,16 @@ const state = {
|
||||
const getters = {}
|
||||
|
||||
const mutations = {
|
||||
SET_NODE_FORM (state, value) {
|
||||
SET_NODE_FORM(state, value) {
|
||||
state.nodeForm = value
|
||||
},
|
||||
SET_NODE_LIST (state, value) {
|
||||
SET_NODE_LIST(state, value) {
|
||||
state.nodeList = value
|
||||
},
|
||||
SET_ACTIVE_SPIDER (state, value) {
|
||||
SET_ACTIVE_SPIDER(state, value) {
|
||||
state.activeSpider = value
|
||||
},
|
||||
SET_NODE_SYSTEM_INFO (state, payload) {
|
||||
SET_NODE_SYSTEM_INFO(state, payload) {
|
||||
const { id, systemInfo } = payload
|
||||
for (let i = 0; i < state.nodeList.length; i++) {
|
||||
if (state.nodeList[i]._id === id) {
|
||||
@@ -33,54 +33,48 @@ const mutations = {
|
||||
}
|
||||
|
||||
const actions = {
|
||||
getNodeList ({ state, commit }) {
|
||||
request.get('/nodes', {})
|
||||
.then(response => {
|
||||
commit('SET_NODE_LIST', response.data.data.map(d => {
|
||||
d.systemInfo = {
|
||||
os: '',
|
||||
arch: '',
|
||||
num_cpu: '',
|
||||
executables: []
|
||||
}
|
||||
return d
|
||||
}))
|
||||
})
|
||||
},
|
||||
editNode ({ state, dispatch }) {
|
||||
request.post(`/nodes/${state.nodeForm._id}`, state.nodeForm)
|
||||
.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.data)
|
||||
})
|
||||
},
|
||||
getTaskList ({ state, commit }, id) {
|
||||
return request.get(`/nodes/${id}/tasks`)
|
||||
.then(response => {
|
||||
if (response.data.data) {
|
||||
commit('task/SET_TASK_LIST',
|
||||
response.data.data.map(d => d)
|
||||
.sort((a, b) => a.create_ts < b.create_ts ? 1 : -1),
|
||||
{ root: true })
|
||||
getNodeList({ state, commit }) {
|
||||
request.get('/nodes', {}).then(response => {
|
||||
commit('SET_NODE_LIST', response.data.data.map(d => {
|
||||
d.systemInfo = {
|
||||
os: '',
|
||||
arch: '',
|
||||
num_cpu: '',
|
||||
executables: []
|
||||
}
|
||||
})
|
||||
return d
|
||||
}))
|
||||
})
|
||||
},
|
||||
getNodeSystemInfo ({ state, commit }, id) {
|
||||
return request.get(`/nodes/${id}/system`)
|
||||
.then(response => {
|
||||
commit('SET_NODE_SYSTEM_INFO', { id, systemInfo: response.data.data })
|
||||
})
|
||||
editNode({ state, dispatch }) {
|
||||
request.post(`/nodes/${state.nodeForm._id}`, state.nodeForm).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.data)
|
||||
})
|
||||
},
|
||||
getTaskList({ state, commit }, id) {
|
||||
return request.get(`/nodes/${id}/tasks`).then(response => {
|
||||
if (response.data.data) {
|
||||
commit('task/SET_TASK_LIST',
|
||||
response.data.data.map(d => d)
|
||||
.sort((a, b) => a.create_ts < b.create_ts ? 1 : -1),
|
||||
{ root: true })
|
||||
}
|
||||
})
|
||||
},
|
||||
getNodeSystemInfo({ state, commit }, id) {
|
||||
return request.get(`/nodes/${id}/system`).then(response => {
|
||||
commit('SET_NODE_SYSTEM_INFO', { id, systemInfo: response.data.data })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ const mutations = {
|
||||
}
|
||||
|
||||
const actions = {
|
||||
getProjectList ({ state, commit }, payload) {
|
||||
getProjectList({ state, commit }, payload) {
|
||||
return request.get('/projects', payload)
|
||||
.then(response => {
|
||||
if (response.data.data) {
|
||||
@@ -32,7 +32,7 @@ const actions = {
|
||||
}
|
||||
})
|
||||
},
|
||||
getProjectTags ({ state, commit }) {
|
||||
getProjectTags({ state, commit }) {
|
||||
return request.get('/projects/tags')
|
||||
.then(response => {
|
||||
if (response.data.data) {
|
||||
@@ -40,13 +40,13 @@ const actions = {
|
||||
}
|
||||
})
|
||||
},
|
||||
addProject ({ state }) {
|
||||
addProject({ state }) {
|
||||
return request.put('/projects', state.projectForm)
|
||||
},
|
||||
editProject ({ state }, id) {
|
||||
editProject({ state }, id) {
|
||||
return request.post(`/projects/${id}`, state.projectForm)
|
||||
},
|
||||
removeProject ({ state }, id) {
|
||||
removeProject({ state }, id) {
|
||||
return request.delete(`/projects/${id}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import request from '../../api/request'
|
||||
|
||||
const state = {
|
||||
scheduleList: [],
|
||||
scheduleForm: {
|
||||
@@ -9,16 +10,16 @@ const state = {
|
||||
const getters = {}
|
||||
|
||||
const mutations = {
|
||||
SET_SCHEDULE_LIST (state, value) {
|
||||
SET_SCHEDULE_LIST(state, value) {
|
||||
state.scheduleList = value
|
||||
},
|
||||
SET_SCHEDULE_FORM (state, value) {
|
||||
SET_SCHEDULE_FORM(state, value) {
|
||||
state.scheduleForm = value
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
getScheduleList ({ state, commit }) {
|
||||
getScheduleList({ state, commit }) {
|
||||
request.get('/schedules')
|
||||
.then(response => {
|
||||
if (response.data.data) {
|
||||
@@ -31,19 +32,19 @@ const actions = {
|
||||
}
|
||||
})
|
||||
},
|
||||
addSchedule ({ state }) {
|
||||
addSchedule({ state }) {
|
||||
request.put('/schedules', state.scheduleForm)
|
||||
},
|
||||
editSchedule ({ state }, id) {
|
||||
editSchedule({ state }, id) {
|
||||
request.post(`/schedules/${id}`, state.scheduleForm)
|
||||
},
|
||||
removeSchedule ({ state }, id) {
|
||||
removeSchedule({ state }, id) {
|
||||
request.delete(`/schedules/${id}`)
|
||||
},
|
||||
enableSchedule ({ state, dispatch }, id) {
|
||||
enableSchedule({ state, dispatch }, id) {
|
||||
return request.post(`/schedules/${id}/enable`)
|
||||
},
|
||||
disableSchedule ({ state, dispatch }, id) {
|
||||
disableSchedule({ state, dispatch }, id) {
|
||||
return request.post(`/schedules/${id}/disable`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,13 +7,13 @@ const state = {
|
||||
const getters = {}
|
||||
|
||||
const mutations = {
|
||||
SET_SETTING (state, value) {
|
||||
SET_SETTING(state, value) {
|
||||
state.setting = value
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
async getSetting ({ commit }) {
|
||||
async getSetting({ commit }) {
|
||||
const res = await request.get('/setting')
|
||||
commit('SET_SETTING', res.data.data)
|
||||
|
||||
|
||||
@@ -26,37 +26,37 @@ const state = {
|
||||
const getters = {}
|
||||
|
||||
const mutations = {
|
||||
SET_KEYWORD (state, value) {
|
||||
SET_KEYWORD(state, value) {
|
||||
state.keyword = value
|
||||
},
|
||||
SET_SITE_LIST (state, value) {
|
||||
SET_SITE_LIST(state, value) {
|
||||
state.siteList = value
|
||||
},
|
||||
SET_PAGE_NUM (state, value) {
|
||||
SET_PAGE_NUM(state, value) {
|
||||
state.pageNum = value
|
||||
},
|
||||
SET_PAGE_SIZE (state, value) {
|
||||
SET_PAGE_SIZE(state, value) {
|
||||
state.pageSize = value
|
||||
},
|
||||
SET_TOTAL_COUNT (state, value) {
|
||||
SET_TOTAL_COUNT(state, value) {
|
||||
state.totalCount = value
|
||||
},
|
||||
SET_MAIN_CATEGORY_LIST (state, value) {
|
||||
SET_MAIN_CATEGORY_LIST(state, value) {
|
||||
state.mainCategoryList = value
|
||||
},
|
||||
SET_CATEGORY_LIST (state, value) {
|
||||
SET_CATEGORY_LIST(state, value) {
|
||||
state.categoryList = value
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
editSite ({ state, dispatch }, payload) {
|
||||
editSite({ state, dispatch }, payload) {
|
||||
const { id, category } = payload
|
||||
return request.post(`/sites/${id}`, {
|
||||
category
|
||||
})
|
||||
},
|
||||
getSiteList ({ state, commit }) {
|
||||
getSiteList({ state, commit }) {
|
||||
return request.get('/sites', {
|
||||
page_num: state.pageNum,
|
||||
page_size: state.pageSize,
|
||||
@@ -71,13 +71,13 @@ const actions = {
|
||||
commit('SET_TOTAL_COUNT', response.data.total_count)
|
||||
})
|
||||
},
|
||||
getMainCategoryList ({ state, commit }) {
|
||||
getMainCategoryList({ state, commit }) {
|
||||
return request.get('/sites/get/get_main_category_list')
|
||||
.then(response => {
|
||||
commit('SET_MAIN_CATEGORY_LIST', response.data.items)
|
||||
})
|
||||
},
|
||||
getCategoryList ({ state, commit }) {
|
||||
getCategoryList({ state, commit }) {
|
||||
return request.get('/sites/get/get_category_list', {
|
||||
'main_category': state.filter.mainCategory || undefined
|
||||
})
|
||||
|
||||
@@ -19,9 +19,6 @@ const state = {
|
||||
// spider scrapy pipelines
|
||||
spiderScrapyPipelines: [],
|
||||
|
||||
// scrapy errors
|
||||
spiderScrapyErrors: {},
|
||||
|
||||
// node to deploy/run
|
||||
activeNode: {},
|
||||
|
||||
@@ -62,110 +59,94 @@ const state = {
|
||||
const getters = {}
|
||||
|
||||
const mutations = {
|
||||
SET_SPIDER_TOTAL (state, value) {
|
||||
SET_SPIDER_TOTAL(state, value) {
|
||||
state.spiderTotal = value
|
||||
},
|
||||
SET_SPIDER_FORM (state, value) {
|
||||
SET_SPIDER_FORM(state, value) {
|
||||
state.spiderForm = value
|
||||
},
|
||||
SET_SPIDER_LIST (state, value) {
|
||||
SET_SPIDER_LIST(state, value) {
|
||||
state.spiderList = value
|
||||
},
|
||||
SET_ACTIVE_NODE (state, value) {
|
||||
SET_ACTIVE_NODE(state, value) {
|
||||
state.activeNode = value
|
||||
},
|
||||
SET_IMPORT_FORM (state, value) {
|
||||
SET_IMPORT_FORM(state, value) {
|
||||
state.importForm = value
|
||||
},
|
||||
SET_OVERVIEW_STATS (state, value) {
|
||||
SET_OVERVIEW_STATS(state, value) {
|
||||
state.overviewStats = value
|
||||
},
|
||||
SET_STATUS_STATS (state, value) {
|
||||
SET_STATUS_STATS(state, value) {
|
||||
state.statusStats = value
|
||||
},
|
||||
SET_DAILY_STATS (state, value) {
|
||||
SET_DAILY_STATS(state, value) {
|
||||
state.dailyStats = value
|
||||
},
|
||||
SET_NODE_STATS (state, value) {
|
||||
SET_NODE_STATS(state, value) {
|
||||
state.nodeStats = value
|
||||
},
|
||||
SET_FILTER_SITE (state, value) {
|
||||
SET_FILTER_SITE(state, value) {
|
||||
state.filterSite = value
|
||||
},
|
||||
SET_PREVIEW_CRAWL_DATA (state, value) {
|
||||
SET_PREVIEW_CRAWL_DATA(state, value) {
|
||||
state.previewCrawlData = value
|
||||
},
|
||||
SET_SPIDER_FORM_CONFIG_SETTINGS (state, payload) {
|
||||
SET_SPIDER_FORM_CONFIG_SETTINGS(state, payload) {
|
||||
const settings = {}
|
||||
payload.forEach(row => {
|
||||
settings[row.name] = row.value
|
||||
})
|
||||
Vue.set(state.spiderForm.config, 'settings', settings)
|
||||
},
|
||||
SET_TEMPLATE_LIST (state, value) {
|
||||
SET_TEMPLATE_LIST(state, value) {
|
||||
state.templateList = value
|
||||
},
|
||||
SET_FILE_TREE (state, value) {
|
||||
SET_FILE_TREE(state, value) {
|
||||
state.fileTree = value
|
||||
},
|
||||
SET_SPIDER_SCRAPY_SETTINGS (state, value) {
|
||||
SET_SPIDER_SCRAPY_SETTINGS(state, value) {
|
||||
state.spiderScrapySettings = value
|
||||
},
|
||||
SET_SPIDER_SCRAPY_ITEMS (state, value) {
|
||||
SET_SPIDER_SCRAPY_ITEMS(state, value) {
|
||||
state.spiderScrapyItems = value
|
||||
},
|
||||
SET_SPIDER_SCRAPY_PIPELINES (state, value) {
|
||||
SET_SPIDER_SCRAPY_PIPELINES(state, value) {
|
||||
state.spiderScrapyPipelines = value
|
||||
},
|
||||
SET_CONFIG_LIST_TS (state, value) {
|
||||
SET_CONFIG_LIST_TS(state, value) {
|
||||
state.configListTs = value
|
||||
},
|
||||
SET_SPIDER_SCRAPY_ERRORS (state, value) {
|
||||
for (let key in value) {
|
||||
if (value.hasOwnProperty(key)) {
|
||||
Vue.set(state.spiderScrapyErrors, key, value[key])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
getSpiderList ({ state, commit }, params = {}) {
|
||||
getSpiderList({ state, commit }, params = {}) {
|
||||
return request.get('/spiders', params)
|
||||
.then(response => {
|
||||
commit('SET_SPIDER_LIST', response.data.data.list)
|
||||
commit('SET_SPIDER_TOTAL', response.data.data.total)
|
||||
})
|
||||
},
|
||||
editSpider ({ state, dispatch }) {
|
||||
editSpider({ state, dispatch }) {
|
||||
return request.post(`/spiders/${state.spiderForm._id}`, state.spiderForm)
|
||||
},
|
||||
deleteSpider ({ state, dispatch }, id) {
|
||||
deleteSpider({ state, dispatch }, id) {
|
||||
return request.delete(`/spiders/${id}`)
|
||||
},
|
||||
getSpiderData ({ state, commit }, id) {
|
||||
getSpiderData({ state, commit }, id) {
|
||||
return request.get(`/spiders/${id}`)
|
||||
.then(response => {
|
||||
let data = response.data.data
|
||||
const data = response.data.data
|
||||
commit('SET_SPIDER_FORM', data)
|
||||
})
|
||||
},
|
||||
async getSpiderScrapySpiders ({ state, commit }, id) {
|
||||
async getSpiderScrapySpiders({ state, commit }, id) {
|
||||
const res = await request.get(`/spiders/${id}/scrapy/spiders`)
|
||||
if (res.data.error) {
|
||||
commit('SET_SPIDER_SCRAPY_ERRORS', { spiders: res.data.error })
|
||||
return
|
||||
}
|
||||
state.spiderForm.spider_names = res.data.data
|
||||
commit('SET_SPIDER_FORM', state.spiderForm)
|
||||
commit('SET_SPIDER_SCRAPY_ERRORS', { spiders: '' })
|
||||
},
|
||||
async getSpiderScrapySettings ({ state, commit }, id) {
|
||||
async getSpiderScrapySettings({ state, commit }, id) {
|
||||
const res = await request.get(`/spiders/${id}/scrapy/settings`)
|
||||
if (res.data.error) {
|
||||
commit('SET_SPIDER_SCRAPY_ERRORS', { settings: res.data.error })
|
||||
return
|
||||
}
|
||||
commit('SET_SPIDER_SCRAPY_SETTINGS', res.data.data.map(d => {
|
||||
const key = d.key
|
||||
const value = d.value
|
||||
@@ -183,17 +164,13 @@ const actions = {
|
||||
type
|
||||
}
|
||||
}))
|
||||
commit('SET_SPIDER_SCRAPY_ERRORS', { settings: '' })
|
||||
},
|
||||
async saveSpiderScrapySettings ({ state }, id) {
|
||||
return request.post(`/spiders/${id}/scrapy/settings`, state.spiderScrapySettings)
|
||||
async saveSpiderScrapySettings({ state }, id) {
|
||||
return request.post(`/spiders/${id}/scrapy/settings`,
|
||||
state.spiderScrapySettings)
|
||||
},
|
||||
async getSpiderScrapyItems ({ state, commit }, id) {
|
||||
async getSpiderScrapyItems({ state, commit }, id) {
|
||||
const res = await request.get(`/spiders/${id}/scrapy/items`)
|
||||
if (res.data.error) {
|
||||
commit('SET_SPIDER_SCRAPY_ERRORS', { items: res.data.error })
|
||||
return
|
||||
}
|
||||
let nodeId = 0
|
||||
commit('SET_SPIDER_SCRAPY_ITEMS', res.data.data.map(d => {
|
||||
d.id = nodeId++
|
||||
@@ -210,36 +187,33 @@ const actions = {
|
||||
})
|
||||
return d
|
||||
}))
|
||||
commit('SET_SPIDER_SCRAPY_ERRORS', { items: '' })
|
||||
},
|
||||
async saveSpiderScrapyItems ({ state }, id) {
|
||||
return request.post(`/spiders/${id}/scrapy/items`, state.spiderScrapyItems.map(d => {
|
||||
d.name = d.label
|
||||
d.fields = d.children.map(f => f.label)
|
||||
return d
|
||||
}))
|
||||
async saveSpiderScrapyItems({ state }, id) {
|
||||
return request.post(`/spiders/${id}/scrapy/items`,
|
||||
state.spiderScrapyItems.map(d => {
|
||||
d.name = d.label
|
||||
d.fields = d.children.map(f => f.label)
|
||||
return d
|
||||
}))
|
||||
},
|
||||
async getSpiderScrapyPipelines ({ state, commit }, id) {
|
||||
async getSpiderScrapyPipelines({ state, commit }, id) {
|
||||
const res = await request.get(`/spiders/${id}/scrapy/pipelines`)
|
||||
if (res.data.error) {
|
||||
commit('SET_SPIDER_SCRAPY_ERRORS', { pipelines: res.data.error })
|
||||
return
|
||||
}
|
||||
commit('SET_SPIDER_SCRAPY_PIPELINES', res.data.data)
|
||||
commit('SET_SPIDER_SCRAPY_ERRORS', { pipelines: '' })
|
||||
},
|
||||
async saveSpiderScrapyPipelines ({ state }, id) {
|
||||
return request.post(`/spiders/${id}/scrapy/pipelines`, state.spiderScrapyPipelines)
|
||||
async saveSpiderScrapyPipelines({ state }, id) {
|
||||
return request.post(`/spiders/${id}/scrapy/pipelines`,
|
||||
state.spiderScrapyPipelines)
|
||||
},
|
||||
async getSpiderScrapySpiderFilepath ({ state, commit }, payload) {
|
||||
async getSpiderScrapySpiderFilepath({ state, commit }, payload) {
|
||||
const { id, spiderName } = payload
|
||||
return request.get(`/spiders/${id}/scrapy/spider/filepath`, { spider_name: spiderName })
|
||||
return request.get(`/spiders/${id}/scrapy/spider/filepath`,
|
||||
{ spider_name: spiderName })
|
||||
},
|
||||
addSpiderScrapySpider ({ state }, payload) {
|
||||
addSpiderScrapySpider({ state }, payload) {
|
||||
const { id, form } = payload
|
||||
return request.put(`/spiders/${id}/scrapy/spiders`, form)
|
||||
},
|
||||
crawlSpider ({ state, dispatch }, payload) {
|
||||
crawlSpider({ state, dispatch }, payload) {
|
||||
const { spiderId, runType, nodeIds, param } = payload
|
||||
return request.put(`/tasks`, {
|
||||
spider_id: spiderId,
|
||||
@@ -248,7 +222,7 @@ const actions = {
|
||||
param: param
|
||||
})
|
||||
},
|
||||
crawlSelectedSpiders ({ state, dispatch }, payload) {
|
||||
crawlSelectedSpiders({ state, dispatch }, payload) {
|
||||
const { taskParams, runType, nodeIds } = payload
|
||||
return request.post(`/spiders-run`, {
|
||||
task_params: taskParams,
|
||||
@@ -256,7 +230,7 @@ const actions = {
|
||||
node_ids: nodeIds
|
||||
})
|
||||
},
|
||||
getTaskList ({ state, commit }, id) {
|
||||
getTaskList({ state, commit }, id) {
|
||||
return request.get(`/spiders/${id}/tasks`)
|
||||
.then(response => {
|
||||
commit('task/SET_TASK_LIST',
|
||||
@@ -266,18 +240,18 @@ const actions = {
|
||||
{ root: true })
|
||||
})
|
||||
},
|
||||
getDir ({ state, commit }, path) {
|
||||
getDir({ state, commit }, path) {
|
||||
const id = state.spiderForm._id
|
||||
return request.get(`/spiders/${id}/dir`)
|
||||
.then(response => {
|
||||
commit('')
|
||||
})
|
||||
},
|
||||
importGithub ({ state }) {
|
||||
importGithub({ state }) {
|
||||
const url = state.importForm.url
|
||||
return request.post('/spiders/import/github', { url })
|
||||
},
|
||||
getSpiderStats ({ state, commit }) {
|
||||
getSpiderStats({ state, commit }) {
|
||||
return request.get(`/spiders/${state.spiderForm._id}/stats`)
|
||||
.then(response => {
|
||||
commit('SET_OVERVIEW_STATS', response.data.data.overview)
|
||||
@@ -286,33 +260,35 @@ const actions = {
|
||||
// commit('SET_NODE_STATS', response.data.task_count_by_node)
|
||||
})
|
||||
},
|
||||
getPreviewCrawlData ({ state, commit }) {
|
||||
getPreviewCrawlData({ state, commit }) {
|
||||
return request.post(`/spiders/${state.spiderForm._id}/preview_crawl`)
|
||||
.then(response => {
|
||||
commit('SET_PREVIEW_CRAWL_DATA', response.data.items)
|
||||
})
|
||||
},
|
||||
extractFields ({ state, commit }) {
|
||||
extractFields({ state, commit }) {
|
||||
return request.post(`/spiders/${state.spiderForm._id}/extract_fields`)
|
||||
},
|
||||
postConfigSpiderConfig ({ state }) {
|
||||
return request.post(`/config_spiders/${state.spiderForm._id}/config`, state.spiderForm.config)
|
||||
postConfigSpiderConfig({ state }) {
|
||||
return request.post(`/config_spiders/${state.spiderForm._id}/config`,
|
||||
state.spiderForm.config)
|
||||
},
|
||||
saveConfigSpiderSpiderfile ({ state, rootState }) {
|
||||
saveConfigSpiderSpiderfile({ state, rootState }) {
|
||||
const content = rootState.file.fileContent
|
||||
return request.post(`/config_spiders/${state.spiderForm._id}/spiderfile`, { content })
|
||||
return request.post(`/config_spiders/${state.spiderForm._id}/spiderfile`,
|
||||
{ content })
|
||||
},
|
||||
addConfigSpider ({ state }) {
|
||||
addConfigSpider({ state }) {
|
||||
return request.put(`/config_spiders`, state.spiderForm)
|
||||
},
|
||||
addSpider ({ state }) {
|
||||
addSpider({ state }) {
|
||||
return request.put(`/spiders`, state.spiderForm)
|
||||
},
|
||||
async getTemplateList ({ state, commit }) {
|
||||
async getTemplateList({ state, commit }) {
|
||||
const res = await request.get(`/config_spiders_templates`)
|
||||
commit('SET_TEMPLATE_LIST', res.data.data)
|
||||
},
|
||||
async getScheduleList ({ state, commit }, payload) {
|
||||
async getScheduleList({ state, commit }, payload) {
|
||||
const { id } = payload
|
||||
const res = await request.get(`/spiders/${id}/schedules`)
|
||||
let data = res.data.data
|
||||
@@ -326,7 +302,7 @@ const actions = {
|
||||
}
|
||||
commit('schedule/SET_SCHEDULE_LIST', data, { root: true })
|
||||
},
|
||||
async getFileTree ({ state, commit }, payload) {
|
||||
async getFileTree({ state, commit }, payload) {
|
||||
const id = payload ? payload.id : state.spiderForm._id
|
||||
const res = await request.get(`/spiders/${id}/file/tree`)
|
||||
commit('SET_FILE_TREE', res.data.data)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const state = {}
|
||||
const getters = {
|
||||
useStats () {
|
||||
useStats() {
|
||||
return localStorage.getItem('useStats')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,18 +72,18 @@ const tagsView = {
|
||||
|
||||
},
|
||||
actions: {
|
||||
addView ({ dispatch }, view) {
|
||||
addView({ dispatch }, view) {
|
||||
dispatch('addVisitedView', view)
|
||||
dispatch('addCachedView', view)
|
||||
},
|
||||
addVisitedView ({ commit }, view) {
|
||||
addVisitedView({ commit }, view) {
|
||||
commit('ADD_VISITED_VIEW', view)
|
||||
},
|
||||
addCachedView ({ commit }, view) {
|
||||
addCachedView({ commit }, view) {
|
||||
commit('ADD_CACHED_VIEW', view)
|
||||
},
|
||||
|
||||
delView ({ dispatch, state }, view) {
|
||||
delView({ dispatch, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
dispatch('delVisitedView', view)
|
||||
dispatch('delCachedView', view)
|
||||
@@ -93,20 +93,20 @@ const tagsView = {
|
||||
})
|
||||
})
|
||||
},
|
||||
delVisitedView ({ commit, state }, view) {
|
||||
delVisitedView({ commit, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
commit('DEL_VISITED_VIEW', view)
|
||||
resolve([...state.visitedViews])
|
||||
})
|
||||
},
|
||||
delCachedView ({ commit, state }, view) {
|
||||
delCachedView({ commit, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
commit('DEL_CACHED_VIEW', view)
|
||||
resolve([...state.cachedViews])
|
||||
})
|
||||
},
|
||||
|
||||
delOthersViews ({ dispatch, state }, view) {
|
||||
delOthersViews({ dispatch, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
dispatch('delOthersVisitedViews', view)
|
||||
dispatch('delOthersCachedViews', view)
|
||||
@@ -116,20 +116,20 @@ const tagsView = {
|
||||
})
|
||||
})
|
||||
},
|
||||
delOthersVisitedViews ({ commit, state }, view) {
|
||||
delOthersVisitedViews({ commit, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
commit('DEL_OTHERS_VISITED_VIEWS', view)
|
||||
resolve([...state.visitedViews])
|
||||
})
|
||||
},
|
||||
delOthersCachedViews ({ commit, state }, view) {
|
||||
delOthersCachedViews({ commit, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
commit('DEL_OTHERS_CACHED_VIEWS', view)
|
||||
resolve([...state.cachedViews])
|
||||
})
|
||||
},
|
||||
|
||||
delAllViews ({ dispatch, state }, view) {
|
||||
delAllViews({ dispatch, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
dispatch('delAllVisitedViews', view)
|
||||
dispatch('delAllCachedViews', view)
|
||||
@@ -139,20 +139,20 @@ const tagsView = {
|
||||
})
|
||||
})
|
||||
},
|
||||
delAllVisitedViews ({ commit, state }) {
|
||||
delAllVisitedViews({ commit, state }) {
|
||||
return new Promise(resolve => {
|
||||
commit('DEL_ALL_VISITED_VIEWS')
|
||||
resolve([...state.visitedViews])
|
||||
})
|
||||
},
|
||||
delAllCachedViews ({ commit, state }) {
|
||||
delAllCachedViews({ commit, state }) {
|
||||
return new Promise(resolve => {
|
||||
commit('DEL_ALL_CACHED_VIEWS')
|
||||
resolve([...state.cachedViews])
|
||||
})
|
||||
},
|
||||
|
||||
updateVisitedView ({ commit }, view) {
|
||||
updateVisitedView({ commit }, view) {
|
||||
commit('UPDATE_VISITED_VIEW', view)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,20 +36,20 @@ const state = {
|
||||
}
|
||||
|
||||
const getters = {
|
||||
taskResultsColumns (state) {
|
||||
taskResultsColumns(state) {
|
||||
if (!state.taskResultsData || !state.taskResultsData.length) {
|
||||
return []
|
||||
}
|
||||
const keys = []
|
||||
const item = state.taskResultsData[0]
|
||||
for (const key in item) {
|
||||
if (item.hasOwnProperty(key)) {
|
||||
if (Object.prototype.hasOwnProperty.call(item, key)) {
|
||||
keys.push(key)
|
||||
}
|
||||
}
|
||||
return keys
|
||||
},
|
||||
logData (state) {
|
||||
logData(state) {
|
||||
const data = state.taskLog
|
||||
.map((d, i) => {
|
||||
return {
|
||||
@@ -71,7 +71,7 @@ const getters = {
|
||||
}
|
||||
return data
|
||||
},
|
||||
errorLogData (state, getters) {
|
||||
errorLogData(state, getters) {
|
||||
const idxList = getters.logData.map(d => d._id)
|
||||
return state.errorLogData.map(d => {
|
||||
const idx = idxList.indexOf(d._id)
|
||||
@@ -82,82 +82,82 @@ const getters = {
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
SET_TASK_FORM (state, value) {
|
||||
SET_TASK_FORM(state, value) {
|
||||
state.taskForm = value
|
||||
},
|
||||
SET_TASK_LIST (state, value) {
|
||||
SET_TASK_LIST(state, value) {
|
||||
state.taskList = value
|
||||
},
|
||||
SET_TASK_LOG (state, value) {
|
||||
SET_TASK_LOG(state, value) {
|
||||
state.taskLog = value
|
||||
},
|
||||
SET_TASK_LOG_TOTAL (state, value) {
|
||||
SET_TASK_LOG_TOTAL(state, value) {
|
||||
state.taskLogTotal = value
|
||||
},
|
||||
SET_CURRENT_LOG_INDEX (state, value) {
|
||||
SET_CURRENT_LOG_INDEX(state, value) {
|
||||
state.currentLogIndex = value
|
||||
},
|
||||
SET_TASK_RESULTS_DATA (state, value) {
|
||||
SET_TASK_RESULTS_DATA(state, value) {
|
||||
state.taskResultsData = value
|
||||
},
|
||||
SET_TASK_RESULTS_COLUMNS (state, value) {
|
||||
SET_TASK_RESULTS_COLUMNS(state, value) {
|
||||
state.taskResultsColumns = value
|
||||
},
|
||||
SET_PAGE_NUM (state, value) {
|
||||
SET_PAGE_NUM(state, value) {
|
||||
state.pageNum = value
|
||||
},
|
||||
SET_PAGE_SIZE (state, value) {
|
||||
SET_PAGE_SIZE(state, value) {
|
||||
state.pageSize = value
|
||||
},
|
||||
SET_TASK_LIST_TOTAL_COUNT (state, value) {
|
||||
SET_TASK_LIST_TOTAL_COUNT(state, value) {
|
||||
state.taskListTotalCount = value
|
||||
},
|
||||
SET_RESULTS_PAGE_NUM (state, value) {
|
||||
SET_RESULTS_PAGE_NUM(state, value) {
|
||||
state.resultsPageNum = value
|
||||
},
|
||||
SET_RESULTS_PAGE_SIZE (state, value) {
|
||||
SET_RESULTS_PAGE_SIZE(state, value) {
|
||||
state.resultsPageSize = value
|
||||
},
|
||||
SET_TASK_RESULTS_TOTAL_COUNT (state, value) {
|
||||
SET_TASK_RESULTS_TOTAL_COUNT(state, value) {
|
||||
state.taskResultsTotalCount = value
|
||||
},
|
||||
SET_LOG_KEYWORD (state, value) {
|
||||
SET_LOG_KEYWORD(state, value) {
|
||||
state.logKeyword = value
|
||||
},
|
||||
SET_ERROR_LOG_DATA (state, value) {
|
||||
SET_ERROR_LOG_DATA(state, value) {
|
||||
state.errorLogData = value
|
||||
},
|
||||
SET_TASK_LOG_PAGE (state, value) {
|
||||
SET_TASK_LOG_PAGE(state, value) {
|
||||
state.taskLogPage = value
|
||||
},
|
||||
SET_TASK_LOG_PAGE_SIZE (state, value) {
|
||||
SET_TASK_LOG_PAGE_SIZE(state, value) {
|
||||
state.taskLogPageSize = value
|
||||
},
|
||||
SET_IS_LOG_AUTO_SCROLL (state, value) {
|
||||
SET_IS_LOG_AUTO_SCROLL(state, value) {
|
||||
state.isLogAutoScroll = value
|
||||
},
|
||||
SET_IS_LOG_AUTO_FETCH (state, value) {
|
||||
SET_IS_LOG_AUTO_FETCH(state, value) {
|
||||
state.isLogAutoFetch = value
|
||||
},
|
||||
SET_IS_LOG_FETCH_LOADING (state, value) {
|
||||
SET_IS_LOG_FETCH_LOADING(state, value) {
|
||||
state.isLogFetchLoading = value
|
||||
},
|
||||
SET_ACTIVE_ERROR_LOG_ITEM (state, value) {
|
||||
SET_ACTIVE_ERROR_LOG_ITEM(state, value) {
|
||||
state.activeErrorLogItem = value
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
getTaskData ({ state, dispatch, commit }, id) {
|
||||
getTaskData({ state, dispatch, commit }, id) {
|
||||
return request.get(`/tasks/${id}`)
|
||||
.then(response => {
|
||||
let data = response.data.data
|
||||
const data = response.data.data
|
||||
commit('SET_TASK_FORM', data)
|
||||
dispatch('spider/getSpiderData', data.spider_id, { root: true })
|
||||
dispatch('node/getNodeData', data.node_id, { root: true })
|
||||
})
|
||||
},
|
||||
getTaskList ({ state, commit }) {
|
||||
getTaskList({ state, commit }) {
|
||||
return request.get('/tasks', {
|
||||
page_num: state.pageNum,
|
||||
page_size: state.pageSize,
|
||||
@@ -171,24 +171,24 @@ const actions = {
|
||||
commit('SET_TASK_LIST_TOTAL_COUNT', response.data.total)
|
||||
})
|
||||
},
|
||||
deleteTask ({ state, dispatch }, id) {
|
||||
deleteTask({ state, dispatch }, id) {
|
||||
return request.delete(`/tasks/${id}`)
|
||||
.then(() => {
|
||||
dispatch('getTaskList')
|
||||
})
|
||||
},
|
||||
deleteTaskMultiple ({ state }, ids) {
|
||||
deleteTaskMultiple({ state }, ids) {
|
||||
return request.delete(`/tasks`, {
|
||||
ids: ids
|
||||
})
|
||||
},
|
||||
restartTask ({ state, dispatch }, id) {
|
||||
restartTask({ state, dispatch }, id) {
|
||||
return request.post(`/tasks/${id}/restart`)
|
||||
.then(() => {
|
||||
dispatch('getTaskList')
|
||||
})
|
||||
},
|
||||
getTaskLog ({ state, commit }, { id, keyword }) {
|
||||
getTaskLog({ state, commit }, { id, keyword }) {
|
||||
return request.get(`/tasks/${id}/log`, {
|
||||
keyword,
|
||||
page_num: state.taskLogPage,
|
||||
@@ -199,18 +199,20 @@ const actions = {
|
||||
commit('SET_TASK_LOG_TOTAL', response.data.total || 0)
|
||||
|
||||
// auto switch to next page if not reaching the end
|
||||
if (state.isLogAutoScroll && state.taskLogTotal > (state.taskLogPage * state.taskLogPageSize)) {
|
||||
commit('SET_TASK_LOG_PAGE', Math.ceil(state.taskLogTotal / state.taskLogPageSize))
|
||||
if (state.isLogAutoScroll && state.taskLogTotal >
|
||||
(state.taskLogPage * state.taskLogPageSize)) {
|
||||
commit('SET_TASK_LOG_PAGE',
|
||||
Math.ceil(state.taskLogTotal / state.taskLogPageSize))
|
||||
}
|
||||
})
|
||||
},
|
||||
getTaskErrorLog ({ state, commit }, id) {
|
||||
getTaskErrorLog({ state, commit }, id) {
|
||||
return request.get(`/tasks/${id}/error-log`, {})
|
||||
.then(response => {
|
||||
commit('SET_ERROR_LOG_DATA', response.data.data || [])
|
||||
})
|
||||
},
|
||||
getTaskResults ({ state, commit }, id) {
|
||||
getTaskResults({ state, commit }, id) {
|
||||
return request.get(`/tasks/${id}/results`, {
|
||||
page_num: state.resultsPageNum,
|
||||
page_size: state.resultsPageSize
|
||||
@@ -221,10 +223,11 @@ const actions = {
|
||||
commit('SET_TASK_RESULTS_TOTAL_COUNT', response.data.total)
|
||||
})
|
||||
},
|
||||
async getTaskResultExcel ({ state, commit }, id) {
|
||||
const { data } = await request.request('GET', '/tasks/' + id + '/results/download', {}, {
|
||||
responseType: 'blob' // important
|
||||
})
|
||||
async getTaskResultExcel({ state, commit }, id) {
|
||||
const { data } = await request.request('GET',
|
||||
'/tasks/' + id + '/results/download', {}, {
|
||||
responseType: 'blob' // important
|
||||
})
|
||||
const downloadUrl = window.URL.createObjectURL(new Blob([data]))
|
||||
|
||||
const link = document.createElement('a')
|
||||
@@ -237,7 +240,7 @@ const actions = {
|
||||
link.click()
|
||||
link.remove()
|
||||
},
|
||||
cancelTask ({ state, dispatch }, id) {
|
||||
cancelTask({ state, dispatch }, id) {
|
||||
return new Promise(resolve => {
|
||||
request.post(`/tasks/${id}/cancel`)
|
||||
.then(res => {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import request from '../../api/request'
|
||||
import { getToken, setToken, removeToken } from '@/utils/auth'
|
||||
|
||||
const user = {
|
||||
namespaced: true,
|
||||
|
||||
state: {
|
||||
// token: getToken(),
|
||||
token: getToken(),
|
||||
name: '',
|
||||
avatar: '',
|
||||
roles: [],
|
||||
@@ -22,13 +23,13 @@ const user = {
|
||||
},
|
||||
|
||||
getters: {
|
||||
userInfo (state) {
|
||||
userInfo(state) {
|
||||
if (state.userInfo) return state.userInfo
|
||||
const userInfoStr = window.localStorage.getItem('user_info')
|
||||
if (!userInfoStr) return {}
|
||||
return JSON.parse(userInfoStr)
|
||||
},
|
||||
token () {
|
||||
token() {
|
||||
return window.localStorage.getItem('token')
|
||||
}
|
||||
},
|
||||
@@ -71,43 +72,41 @@ const user = {
|
||||
|
||||
actions: {
|
||||
// 登录
|
||||
async login ({ commit }, userInfo) {
|
||||
async login({ commit }, userInfo) {
|
||||
const username = userInfo.username.trim()
|
||||
let res
|
||||
res = await request.post('/login', { username, password: userInfo.password })
|
||||
const res = await request.post('/login',
|
||||
{ username, password: userInfo.password })
|
||||
if (res.status === 200) {
|
||||
const token = res.data.data
|
||||
commit('SET_TOKEN', token)
|
||||
window.localStorage.setItem('token', token)
|
||||
setToken(token)
|
||||
}
|
||||
return res
|
||||
},
|
||||
|
||||
// 获取用户信息
|
||||
getInfo ({ commit, state }) {
|
||||
return request.get('/me')
|
||||
.then(response => {
|
||||
// ensure compatibility
|
||||
if (!response.data.data.setting.max_error_log) {
|
||||
response.data.data.setting.max_error_log = 1000
|
||||
}
|
||||
if (!response.data.data.setting.log_expire_duration) {
|
||||
response.data.data.setting.log_expire_duration = 3600 * 24
|
||||
}
|
||||
commit('SET_USER_INFO', response.data.data)
|
||||
window.localStorage.setItem('user_info', JSON.stringify(response.data.data))
|
||||
})
|
||||
async getInfo({ commit, state }) {
|
||||
const response = await request.get('/me')
|
||||
|
||||
// ensure compatibility
|
||||
if (!response.data.data.setting.max_error_log) {
|
||||
response.data.data.setting.max_error_log = 1000
|
||||
}
|
||||
commit('SET_USER_INFO', response.data.data)
|
||||
window.localStorage.setItem('user_info',
|
||||
JSON.stringify(response.data.data))
|
||||
},
|
||||
|
||||
// 修改用户信息
|
||||
postInfo ({ commit }, form) {
|
||||
postInfo({ commit }, form) {
|
||||
return request.post('/me', form)
|
||||
},
|
||||
|
||||
// 注册
|
||||
register ({ dispatch, commit, state }, userInfo) {
|
||||
register({ dispatch, commit, state }, userInfo) {
|
||||
return new Promise((resolve, reject) => {
|
||||
request.put('/users', { username: userInfo.username, password: userInfo.password })
|
||||
request.put('/users',
|
||||
{ username: userInfo.username, password: userInfo.password })
|
||||
.then(() => {
|
||||
resolve()
|
||||
})
|
||||
@@ -118,7 +117,7 @@ const user = {
|
||||
},
|
||||
|
||||
// 登出
|
||||
logout ({ commit, state }) {
|
||||
logout({ commit, state }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.localStorage.removeItem('token')
|
||||
window.localStorage.removeItem('user_info')
|
||||
@@ -128,9 +127,13 @@ const user = {
|
||||
resolve()
|
||||
})
|
||||
},
|
||||
|
||||
async resetToken({ commit }) {
|
||||
commit('SET_TOKEN', '')
|
||||
commit('SET_ROLES', [])
|
||||
removeToken()
|
||||
},
|
||||
// 获取用户列表
|
||||
getUserList ({ commit, state }) {
|
||||
getUserList({ commit, state }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
request.get('/users', {
|
||||
page_num: state.pageNum,
|
||||
@@ -144,34 +147,34 @@ const user = {
|
||||
},
|
||||
|
||||
// 删除用户
|
||||
deleteUser ({ state }, id) {
|
||||
deleteUser({ state }, id) {
|
||||
return request.delete(`/users/${id}`)
|
||||
},
|
||||
|
||||
// 编辑用户
|
||||
editUser ({ state }) {
|
||||
editUser({ state }) {
|
||||
return request.post(`/users/${state.userForm._id}`, state.userForm)
|
||||
},
|
||||
|
||||
// 添加用户
|
||||
addUser ({ dispatch, commit, state }) {
|
||||
addUser({ dispatch, commit, state }) {
|
||||
return request.put('/users-add', state.userForm)
|
||||
},
|
||||
// 新增全局变量
|
||||
addGlobalVariable ({ commit, state }) {
|
||||
addGlobalVariable({ commit, state }) {
|
||||
return request.put(`/variable`, state.globalVariableForm)
|
||||
.then(() => {
|
||||
state.globalVariableForm = {}
|
||||
})
|
||||
},
|
||||
// 获取全局变量列表
|
||||
getGlobalVariable ({ commit, state }) {
|
||||
getGlobalVariable({ commit, state }) {
|
||||
request.get('/variables').then((response) => {
|
||||
commit('SET_GLOBAL_VARIABLE_LIST', response.data.data)
|
||||
})
|
||||
},
|
||||
// 删除全局变量
|
||||
deleteGlobalVariable ({ commit, state }, id) {
|
||||
deleteGlobalVariable({ commit, state }, id) {
|
||||
return request.delete(`/variable/${id}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ const mutations = {
|
||||
}
|
||||
|
||||
const actions = {
|
||||
async getLatestRelease ({ commit }) {
|
||||
async getLatestRelease({ commit }) {
|
||||
const res = await request.get('/releases/latest')
|
||||
if (!res.data.error) {
|
||||
commit('SET_LATEST_RELEASE', res.data.data)
|
||||
|
||||
Reference in New Issue
Block a user