diff --git a/src/api/configManage/neManage.ts b/src/api/configManage/neManage.ts index b04c5ca5..b9a8ca0c 100644 --- a/src/api/configManage/neManage.ts +++ b/src/api/configManage/neManage.ts @@ -119,25 +119,24 @@ export async function delNeInfo(data: Record) { } /** - * 查询网元详细 - * @param menuId 网元ID + * 获取网元网元列表 * @returns object */ -export async function getNeType() { +export async function getNelistAll() { // 发起请求 const result = await request({ - url: `/databaseManagement/v1/select/omc_db/ne_info`, + url: `/databaseManagement/v1/elementType/omc_db/objectType/ne_info`, method: 'get', params: { - SQL: `SELECT ne_type,ne_name,ne_id FROM ne_info WHERE status = 0`, + SQL: `SELECT ne_type,ne_name,ne_id,ip FROM ne_info WHERE status = 0`, }, }); // 解析数据 if (result.code === RESULT_CODE_SUCCESS && Array.isArray(result.data.data)) { let data = result.data.data[0]; return Object.assign(result, { - data: parseObjLineToHump(data['ne_info'][0]), + data: parseObjLineToHump(data['ne_info']), }); } return result; -} \ No newline at end of file +} diff --git a/src/store/modules/neinfo.ts b/src/store/modules/neinfo.ts new file mode 100644 index 00000000..901fe0a5 --- /dev/null +++ b/src/store/modules/neinfo.ts @@ -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[]; + /**级联options树结构 */ + neOtions: Record[]; +}; + +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; diff --git a/src/utils/parse-tree-utils.ts b/src/utils/parse-tree-utils.ts index 50866442..0698054c 100644 --- a/src/utils/parse-tree-utils.ts +++ b/src/utils/parse-tree-utils.ts @@ -186,3 +186,38 @@ export function parseTreeNodeKeys( } return treeIds; } + +/** + * 解析数据层级转级联options树结构 + * + * @param data 数组数据 + * @param fieldType 读取节点label字段 默认 'type' + * @param fieldLabel 读取节点label字段 默认 'name' + * @param fieldValue 读取节点value字段 默认 'value' + * @param fieldChildren 设置子节点字段 默认 'children' + * @returns 层级数组 + */ +export function parseDataToOptions( + data: Record[], + fieldType: string = 'type', + fieldLabel: string = 'label', + fieldValue: string = 'value', + fieldChildren: string = 'children' +) { + let options: Record[] = []; + + for (const v of data) { + let vType = v[fieldType]; + let vLabel = v[fieldLabel]; + let vValue = v[fieldValue]; + const vData = { label: vLabel, value: vValue, ...v }; + const item = options.find(i => i.value === vType); + if (item) { + item[fieldChildren].push(vData); + } else { + options.push({ label: vType, value: vType, [fieldChildren]: [vData] }); + } + } + + return options; +}