feat: 网元类型记录数据
This commit is contained in:
59
src/store/modules/neinfo.ts
Normal file
59
src/store/modules/neinfo.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||
import { getNelistAll } from '@/api/configManage/neManage';
|
||||
import { parseDataToOptions } from '@/utils/parse-tree-utils';
|
||||
|
||||
/**网元信息类型 */
|
||||
type NeInfo = {
|
||||
/**网元列表 */
|
||||
nelist: Record<string, any>[];
|
||||
/**级联options树结构 */
|
||||
neOtions: Record<string, any>[];
|
||||
};
|
||||
|
||||
const useNeInfoStore = defineStore('neinfo', {
|
||||
state: (): NeInfo => ({
|
||||
nelist: [],
|
||||
neOtions: [],
|
||||
}),
|
||||
getters: {
|
||||
/**
|
||||
* 获取级联options树结构
|
||||
* @param state 内部属性不用传入
|
||||
* @returns 级联options
|
||||
*/
|
||||
getNeOtions(state) {
|
||||
return state.neOtions;
|
||||
},
|
||||
},
|
||||
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 getNelistAll();
|
||||
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) {
|
||||
// 转级联数据
|
||||
const options = parseDataToOptions(
|
||||
res.data,
|
||||
'neType',
|
||||
'neName',
|
||||
'neId'
|
||||
);
|
||||
|
||||
this.neOtions = options;
|
||||
}
|
||||
return res;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default useNeInfoStore;
|
||||
Reference in New Issue
Block a user