This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
cyber-narrator-cn-ui/src/utils/api.js

120 lines
3.6 KiB
JavaScript
Raw Normal View History

2021-06-11 23:00:33 +08:00
/**
* @author 陈劲松
* @date 2021/6/11
* @description 1.定义api2.定义通用查询方法函数名应为 获取详情getItem获取列表getItemList例如getUsergetUserList
2021-06-11 23:00:33 +08:00
*/
import { get, post } from '@/utils/http'
import { sortByOrderNum } from '@/permission'
2021-06-11 23:00:33 +08:00
2021-06-15 09:25:10 +08:00
export const api = {
// 系统相关
permission: '/sys/user/permissions',
i18n: '/sys/i18n/lang',
dict: '/sys/dict',
// 业务
2021-06-15 09:25:10 +08:00
panel: '/visual/panel',
2021-07-07 22:58:52 +08:00
chart: '/visual/chart',
entityIpFilter: '/interface/entity/ip/filter',
entityDomainFilter: '/interface/entity/domain/filter',
entityAppFilter: '/interface/entity/app/filter',
entityIpList: '/interface/entity/ip/list',
entityDomainList: '/interface/entity/domain/list',
entityAppList: '/interface/entity/app/list'
2021-06-15 09:25:10 +08:00
}
/* panel */
2021-06-11 23:00:33 +08:00
export async function getPanelList (params) {
2021-06-15 09:25:10 +08:00
return await getData(api.panel, params, true)
2021-06-11 23:00:33 +08:00
}
export async function getPanel (id) {
return await getData(`${api.chart}/${id}`)
}
/* chart */
export async function getChartList (params) {
return await getData(api.chart, params, true)
}
export async function getChart (id) {
return await getData(`${api.chart}/${id}`)
2021-06-11 23:00:33 +08:00
}
2021-07-07 22:58:52 +08:00
/* ip类型entity过滤器数据 */
export async function getEntityIpFilterList (params) {
return await getData(api.entityIpFilter, params, true)
}
/* domain类型entity过滤器数据 */
export async function getEntityDomainFilterList (params) {
return await getData(api.entityDomainFilter, params, true)
}
/* app类型entity过滤器数据 */
export async function getEntityAppFilterList (params) {
return await getData(api.entityAppFilter, params, true)
}
/* ip类型entity列表 */
export async function getEntityIpList (params) {
return await getData(api.entityIpList, params, true)
}
/* domain类型entity列表 */
export async function getEntityDomainList (params) {
return await getData(api.entityDomainList, params, true)
}
/* app类型entity列表 */
export async function getEntityAppList (params) {
return await getData(api.entityAppList, params, true)
}
/* 字典 */
export async function getDictList (params) {
return await getData(api.dict, params, true)
}
2021-06-11 23:00:33 +08:00
export async function getData (url, params = {}, isQueryList) {
const request = new Promise(resolve => {
2021-06-11 23:00:33 +08:00
get(url, params).then(response => {
if (response.code === 200) {
2021-07-07 22:58:52 +08:00
resolve(isQueryList ? response.data.list || response.data.result : response.data || response.data.result)
2021-06-11 23:00:33 +08:00
}
})
})
return await request
}
export async function getConfigJson () {
const request = new Promise(resolve => {
get(`${process.env.BASE_URL}config.json?Timestamp=${new Date().getTime()}`).then(config => {
resolve(config)
})
})
return await request
}
export async function getPermission () {
const request = new Promise(resolve => {
post(api.permission, { token: sessionStorage.getItem('cn-token') }).then(response => {
resolve({
menuList: sortByOrderNum(response.data.menus),
buttonList: response.data.buttons,
roleList: response.data.roles
})
})
})
return await request
}
export async function getI18n () {
const dictData = await getDictList()
const langs = dictData.map(d => d.value).join(',')
const request = new Promise(resolve => {
get(api.i18n, { l: langs }).then(response => {
resolve(response.data)
})
})
return await request
}
2021-07-01 15:39:48 +08:00
2021-07-05 17:40:43 +08:00
/* 获得原始的3611-2 json字符串数据 */
export async function getIso36112JsonData (suffix) {
const request = new Promise(resolve => {
get(`${process.env.BASE_URL}geojson/${suffix}`).then(response => {
resolve(JSON.stringify(response))
})
2021-07-01 15:39:48 +08:00
})
2021-07-05 17:40:43 +08:00
return await request
2021-07-01 15:39:48 +08:00
}