Files
crawlab/frontend/src/store/modules/doc.js
yaziming aeaa4493a7 * 增加Docker开发环境
* 更新Dockerfile构建文件,升级NodeJS依赖版本。
 * 遵循ESLint重新格式化代码,修复部分警告
 * 登录Token失效增加登出提示
 * 网络请求问题增加错误错误提示
 * 升级UI依赖库
2020-06-19 16:57:00 +08:00

62 lines
1.2 KiB
Go

import request from '../../api/request'
const state = {
docData: []
}
const getters = {}
const mutations = {
SET_DOC_DATA(state, value) {
state.docData = value
}
}
const actions = {
async getDocData({ commit }) {
const res = await request.get('/docs')
const data = JSON.parse(res.data.data.string)
// init cache
const cache = {}
// iterate paths
for (const path in data) {
if (Object.prototype.hasOwnProperty.call(data, path)) {
const d = data[path]
if (path.match(/\/$/)) {
cache[path] = d
cache[path].children = []
} else if (path.match(/\.html$/)) {
const parentPath = path.split('/')[0] + '/'
cache[parentPath].children.push(d)
}
}
}
commit('SET_DOC_DATA', Object.values(cache).map(d => {
d.level = 1
d.label = d.title
d.fullUrl = process.env.VUE_APP_DOC_URL + '/' + d.url
if (d.children) {
d.children = d.children.map(c => {
c.level = 2
c.label = c.title
c.fullUrl = process.env.VUE_APP_DOC_URL + '/' + c.url
return c
})
}
return d
}))
}
}
export default {
namespaced: true,
state,
getters,
mutations,
actions
}