Skip to content

Commit 7dfed64

Browse files
committed
调整gitignore
1 parent 80b058a commit 7dfed64

File tree

5 files changed

+453
-1
lines changed

5 files changed

+453
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
*.zip
22
dist
33
node_modules
4-
apidoc
4+
/apidoc
55

66
# local env files
77
.env.local

src/store/modules/Apidoc/helper.ts

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
import { ApiDataInfo, ApiItem } from "@/api/interface/apiData";
2+
import { MenuItemType } from "@/components/Menu/src/interface";
3+
import { createApiPageKey } from "@/utils";
4+
import { ApiAnalysisData } from "@/store/modules/Apidoc/interface";
5+
import { MdMenuItem } from "@/api/interface/markdown";
6+
import { ConfigAppItem } from "@/api/interface/config";
7+
8+
interface ReturnHandleApiData {
9+
apiList: ApiItem[];
10+
apiMenus: MenuItemType[];
11+
apiObject: ApiObject;
12+
apiAnalysis: ApiAnalysisData;
13+
}
14+
15+
interface ApiObject {
16+
[key: string]: ApiItem;
17+
}
18+
19+
/**
20+
* 处理apiData接口响应数据
21+
* @param data
22+
* @param appKey
23+
* @returns
24+
*/
25+
export function handleApiData(data: ApiDataInfo, appKey: string): ReturnHandleApiData {
26+
const apiData = data.data;
27+
const res: ReturnHandleApiData = {
28+
apiList: [],
29+
apiMenus: [],
30+
apiObject: {},
31+
apiAnalysis: {
32+
apiCount: 0,
33+
apiMethodTotal: {},
34+
controllerGroupTotal: {},
35+
apiGroupTotal: {},
36+
apiTagTotal: {},
37+
apiAuthorTotal: {},
38+
},
39+
};
40+
// 递归处理数据
41+
function renderApiData(list: ApiItem[]): MenuItemType[] {
42+
const apiMenus = list.map((item) => {
43+
let key = "";
44+
const method = item.method as string;
45+
let methodList: string[] = [];
46+
47+
let type = "folder";
48+
if (item.controller) {
49+
type = "controller";
50+
} else if (method && method.indexOf(",") > -1) {
51+
type = "multiple";
52+
methodList = method.split(",");
53+
} else if (method) {
54+
type = "api";
55+
methodList = [method];
56+
}
57+
if (type === "controller" && item.group) {
58+
// 控制器分组
59+
const groupName = item.group;
60+
// 分组下的api数量
61+
const childrenApiCount = item.children && item.children.length ? item.children.length : 0;
62+
if (res.apiAnalysis.apiGroupTotal[groupName]) {
63+
res.apiAnalysis.apiGroupTotal[groupName] =
64+
res.apiAnalysis.apiGroupTotal[groupName] + childrenApiCount;
65+
} else {
66+
res.apiAnalysis.apiGroupTotal[groupName] = childrenApiCount;
67+
}
68+
// 分组下的控制器数量
69+
if (res.apiAnalysis.controllerGroupTotal[groupName]) {
70+
res.apiAnalysis.controllerGroupTotal[groupName] =
71+
res.apiAnalysis.controllerGroupTotal[groupName] + 1;
72+
} else {
73+
res.apiAnalysis.controllerGroupTotal[groupName] = 1;
74+
}
75+
} else if (item.url) {
76+
// api接口存入list和object
77+
res.apiList.push(item);
78+
key = createApiPageKey({
79+
appKey: appKey as string,
80+
method: method as string,
81+
url: item.url as string,
82+
});
83+
res.apiObject[key] = item;
84+
// 接口总数
85+
res.apiAnalysis.apiCount++;
86+
// 统计请求类型数量
87+
if (methodList && methodList.length) {
88+
for (let i = 0; i < methodList.length; i++) {
89+
const methodItem = methodList[i];
90+
if (res.apiAnalysis.apiMethodTotal[methodItem]) {
91+
res.apiAnalysis.apiMethodTotal[methodItem] =
92+
res.apiAnalysis.apiMethodTotal[methodItem] + 1;
93+
} else {
94+
res.apiAnalysis.apiMethodTotal[methodItem] = 1;
95+
}
96+
}
97+
}
98+
// tag统计
99+
if (item.tag && item.tag.length) {
100+
for (let i = 0; i < item.tag.length; i++) {
101+
const tagItem = item.tag[i];
102+
if (res.apiAnalysis.apiTagTotal[tagItem]) {
103+
res.apiAnalysis.apiTagTotal[tagItem] = res.apiAnalysis.apiTagTotal[tagItem] + 1;
104+
} else {
105+
res.apiAnalysis.apiTagTotal[tagItem] = 1;
106+
}
107+
}
108+
}
109+
// 作者接口数量统计
110+
if (item.author) {
111+
if (res.apiAnalysis.apiAuthorTotal[item.author]) {
112+
res.apiAnalysis.apiAuthorTotal[item.author] =
113+
res.apiAnalysis.apiAuthorTotal[item.author] + 1;
114+
} else {
115+
res.apiAnalysis.apiAuthorTotal[item.author] = 1;
116+
}
117+
}
118+
}
119+
// api接口菜单数据
120+
const menuItem: MenuItemType = {
121+
title: item.title,
122+
menu_key: item.menu_key,
123+
type: type,
124+
method: item.method as string,
125+
url: item.url,
126+
tag: item.tag,
127+
key,
128+
};
129+
if (item.children && item.children.length) {
130+
menuItem.children = renderApiData(item.children);
131+
}
132+
return menuItem;
133+
});
134+
135+
return apiMenus;
136+
}
137+
res.apiMenus = renderApiData(apiData);
138+
return res;
139+
}
140+
141+
export function handleMdMenusData(data: MdMenuItem[]): any {
142+
let result = {
143+
menus: [],
144+
count: 0,
145+
};
146+
function renderMdMenuData(list: MdMenuItem[]): any {
147+
const mdMenus = list.map((item) => {
148+
if (item.path) {
149+
result.count++;
150+
}
151+
if (item.children && item.children.length) {
152+
item.children = renderMdMenuData(item.children);
153+
}
154+
return item;
155+
});
156+
return mdMenus;
157+
}
158+
result.menus = renderMdMenuData(data);
159+
return result;
160+
}
161+
162+
export function handleConfigAppsData(data: ConfigAppItem[]): any {
163+
let result = {
164+
count: 0,
165+
};
166+
function renderAppsData(list: ConfigAppItem[]): any {
167+
const mdMenus = list.map((item) => {
168+
if (item.folder && !(item.items && item.items.length)) {
169+
result.count++;
170+
}
171+
if (item.items && item.items.length) {
172+
item.items = renderAppsData(item.items);
173+
}
174+
return item;
175+
});
176+
return mdMenus;
177+
}
178+
renderAppsData(data);
179+
return result;
180+
}

src/store/modules/Apidoc/index.ts

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import { Module } from "vuex";
2+
import { GlobalState } from "../../index";
3+
import * as Types from "./types";
4+
import {
5+
ApidocState,
6+
MdMenuItemState,
7+
ApiObjectState,
8+
GlobalParamsState,
9+
AuthDataState,
10+
ApiAnalysisData,
11+
} from "./interface";
12+
import * as API from "@/api";
13+
import { handleApiData, handleMdMenusData } from "./helper";
14+
import { GetApiDataState, ApiItem } from "@/api/interface/apiData";
15+
import { MenuItemType } from "@/components/Menu/src/interface";
16+
import Cache from "@/utils/cache";
17+
import { ConfigAppItem } from "@/api/interface/config";
18+
19+
const state: ApidocState = {
20+
groups: [],
21+
data: [],
22+
tags: [],
23+
mdMenus: [],
24+
apiMenus: [],
25+
apiList: [],
26+
apiObject: {},
27+
globalParams: {
28+
header: [],
29+
params: [],
30+
},
31+
authData: {},
32+
apiAnalysis: {
33+
apiCount: 0,
34+
apiMethodTotal: {},
35+
controllerGroupTotal: {},
36+
apiGroupTotal: {},
37+
apiTagTotal: {},
38+
apiAuthorTotal: {},
39+
docsCount: 0,
40+
appCount: 0,
41+
},
42+
currentApp: {
43+
folder: "",
44+
path: "",
45+
title: "",
46+
},
47+
};
48+
49+
const apidoc: Module<ApidocState, GlobalState> = {
50+
namespaced: true,
51+
state,
52+
actions: {
53+
// 获取api文档数据
54+
[Types.GET_API_DATA]({ commit }, params: GetApiDataState) {
55+
return new Promise((resolve, reject) => {
56+
API.getApiData(params)
57+
.then((res) => {
58+
const { apiList, apiMenus, apiObject, apiAnalysis } = handleApiData(
59+
res.data.data,
60+
params.appKey
61+
);
62+
commit(Types.SET_API_LIST, apiList);
63+
commit(Types.SET_API_OBJECT, apiObject);
64+
commit(Types.SET_API_MENUS, apiMenus);
65+
commit(Types.SET_API_TAGS, res.data.data.tags);
66+
commit(Types.SET_API_ANALYSIS, apiAnalysis);
67+
commit(Types.SET_CURRENT_APP, res.data.data.app);
68+
// commit(Types.SET_API_DATA, res.data.data);
69+
resolve(res.data.data);
70+
})
71+
.catch((err) => {
72+
reject(err);
73+
});
74+
});
75+
},
76+
// 获取md文档数据
77+
[Types.GET_MD_MENUS]({ commit }, params) {
78+
return new Promise((resolve, reject) => {
79+
API.getMdMenus(params)
80+
.then((res) => {
81+
const { menus, count } = handleMdMenusData(res.data.data);
82+
const apiAnalysis = {
83+
...state.apiAnalysis,
84+
docsCount: count,
85+
};
86+
commit(Types.SET_API_ANALYSIS, apiAnalysis);
87+
commit(Types.GET_MD_MENUS, menus);
88+
resolve(res.data.data);
89+
})
90+
.catch((err) => {
91+
reject(err);
92+
});
93+
});
94+
},
95+
// 设置全局参数
96+
[Types.SET_GLOBAL_PARAMS]({ commit }, data: GlobalParamsState) {
97+
Cache.set(Types.GLOBAL_PARAMS, data);
98+
commit(Types.SET_GLOBAL_PARAMS, data);
99+
},
100+
// 设置权限token
101+
[Types.SET_AUTH_DATA]({ commit }, data: AuthDataState) {
102+
Cache.set(Types.AUTH_DATA, data);
103+
commit(Types.SET_AUTH_DATA, data);
104+
},
105+
// 设置api分析数据
106+
[Types.SET_API_ANALYSIS]({ commit }, data: ApiAnalysisData) {
107+
commit(Types.SET_API_ANALYSIS, data);
108+
},
109+
},
110+
mutations: {
111+
// 设置api数据
112+
[Types.SET_API_DATA](state, data: ApidocState) {
113+
state.groups = data.groups;
114+
state.data = data.data;
115+
state.tags = data.tags;
116+
},
117+
// 设置md菜单数据
118+
[Types.GET_MD_MENUS](state, data: MdMenuItemState[]) {
119+
state.mdMenus = data;
120+
},
121+
122+
// 设置api接口数据列表
123+
[Types.SET_API_LIST](state, data: ApiItem[]) {
124+
state.apiList = data;
125+
},
126+
// 设置api接口数据对象
127+
[Types.SET_API_OBJECT](state, data: ApiObjectState) {
128+
state.apiObject = data;
129+
},
130+
// 设置api接口数据列表
131+
[Types.SET_API_MENUS](state, data: MenuItemType[]) {
132+
state.apiMenus = data;
133+
},
134+
// 设置可选的tags
135+
[Types.SET_API_TAGS](state, tags: string[]) {
136+
state.tags = tags;
137+
},
138+
// 设置全局参数
139+
[Types.SET_GLOBAL_PARAMS](state, data: GlobalParamsState) {
140+
state.globalParams = data;
141+
},
142+
// 设置权限token
143+
[Types.SET_AUTH_DATA](state, data: AuthDataState) {
144+
state.authData = data;
145+
},
146+
// 设置api分析数据
147+
[Types.SET_API_ANALYSIS](state, data: ApiAnalysisData) {
148+
state.apiAnalysis = { ...state.apiAnalysis, ...data };
149+
},
150+
// 设置当前app的参数
151+
[Types.SET_CURRENT_APP](state, data: ConfigAppItem) {
152+
state.currentApp = data;
153+
},
154+
},
155+
};
156+
157+
export default apidoc;

0 commit comments

Comments
 (0)