116 lines
3.3 KiB
TypeScript
116 lines
3.3 KiB
TypeScript
import { defineStore } from 'pinia';
|
|
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
|
import { listAllNeInfo } from '@/api/ne/neInfo';
|
|
import { parseDataToOptions } from '@/utils/parse-tree-utils';
|
|
import { getNeTraceInterfaceAll } from '@/api/trace/task';
|
|
import { getNePerformanceList } from '@/api/perfManage/taskManage';
|
|
|
|
/**网元信息类型 */
|
|
type NeInfo = {
|
|
/**网元列表 */
|
|
neList: Record<string, any>[];
|
|
/**级联options树结构 */
|
|
neCascaderOptions: Record<string, any>[];
|
|
/**选择器单级父类型 */
|
|
neSelectOtions: Record<string, any>[];
|
|
/**跟踪接口列表 */
|
|
traceInterfaceList: Record<string, any>[];
|
|
/**性能测量数据集 */
|
|
perMeasurementList: Record<string, any>[];
|
|
};
|
|
|
|
const useNeInfoStore = defineStore('neinfo', {
|
|
state: (): NeInfo => ({
|
|
neList: [],
|
|
neCascaderOptions: [],
|
|
neSelectOtions: [],
|
|
traceInterfaceList: [],
|
|
perMeasurementList: [],
|
|
}),
|
|
getters: {
|
|
/**
|
|
* 获取级联options树结构
|
|
* @param state 内部属性不用传入
|
|
* @returns 级联options
|
|
*/
|
|
getNeCascaderOptions(state) {
|
|
return state.neCascaderOptions;
|
|
},
|
|
/**
|
|
* 选择器单级父类型
|
|
* @param state 内部属性不用传入
|
|
* @returns 级联options
|
|
*/
|
|
getNeSelectOtions(state) {
|
|
return state.neSelectOtions;
|
|
},
|
|
},
|
|
actions: {
|
|
// 刷新网元列表
|
|
async fnRefreshNelist() {
|
|
this.neList = [];
|
|
const res = await this.fnNelist();
|
|
return res;
|
|
},
|
|
// 获取网元列表
|
|
async fnNelist() {
|
|
// 有数据不请求
|
|
if (this.neList.length > 0) {
|
|
return { code: 1, data: this.neList, msg: 'success' };
|
|
}
|
|
const res = await listAllNeInfo({
|
|
bandStatus: false,
|
|
});
|
|
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) {
|
|
// 原始列表
|
|
this.neList = JSON.parse(JSON.stringify(res.data));
|
|
|
|
// 转级联数据
|
|
const options = parseDataToOptions(
|
|
res.data,
|
|
'neType',
|
|
'neName',
|
|
'neId'
|
|
);
|
|
this.neCascaderOptions = options;
|
|
|
|
// 转选择器单级父类型
|
|
this.neSelectOtions = options.map(item => item);
|
|
}
|
|
return res;
|
|
},
|
|
// 刷新跟踪接口列表
|
|
async fnRefreshNeTraceInterface() {
|
|
this.traceInterfaceList = [];
|
|
const res = await this.fnNeTraceInterface();
|
|
return res;
|
|
},
|
|
// 获取跟踪接口列表
|
|
async fnNeTraceInterface() {
|
|
// 有数据不请求
|
|
if (this.traceInterfaceList.length > 0) {
|
|
return { code: 1, data: this.traceInterfaceList, msg: 'success' };
|
|
}
|
|
const res = await getNeTraceInterfaceAll();
|
|
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) {
|
|
this.traceInterfaceList = res.data;
|
|
}
|
|
return res;
|
|
},
|
|
// 获取性能测量数据集列表
|
|
async fnNeTaskPerformance() {
|
|
// 有数据不请求
|
|
if (this.perMeasurementList.length > 0) {
|
|
return { code: 1, data: this.perMeasurementList, msg: 'success' };
|
|
}
|
|
const res = await getNePerformanceList();
|
|
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) {
|
|
this.perMeasurementList = res.data;
|
|
}
|
|
return res;
|
|
},
|
|
},
|
|
});
|
|
|
|
export default useNeInfoStore;
|