Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
feat: 服务监控页面
Browse files Browse the repository at this point in the history
  • Loading branch information
buqiyuan committed Dec 19, 2021
1 parent 58b9275 commit 0c3d61f
Show file tree
Hide file tree
Showing 43 changed files with 3,735 additions and 2,245 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [react 版 coding](https://github.com/buqiyuan/react-antd-admin)
- [vue-cli](https://github.com/buqiyuan/vite-vue3-admin)
- [gitee 地址](https://gitee.com/buqiyuan/vite-vue3-admin)
- 根据 JSON 生成 typescript 的工具:[http://json2ts.com/](http://json2ts.com/)

## vscode 配置

Expand Down
20 changes: 20 additions & 0 deletions mock/_createProductionServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createProdMockServer } from 'vite-plugin-mock/es/createProdMockServer';

const modules = import.meta.globEager('./**/*.ts');

const mockModules: any[] = [];
Object.keys(modules).forEach((key) => {
if (key.includes('/_')) {
return;
}
mockModules.push(...modules[key].default);
});

/**
* Used in a production environment. Need to manually import all modules
*/
export function setupProdMockServer() {
console.log('mockModules', mockModules);

createProdMockServer(mockModules);
}
64 changes: 64 additions & 0 deletions mock/_util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Interface data format used to return a unified format

export function resultSuccess<T = Recordable>(data: T, { message = 'ok' } = {}) {
return {
code: 200,
data,
message,
type: 'success',
};
}

export function resultPageSuccess<T = any>(
page: number,
pageSize: number,
list: T[],
{ message = 'ok' } = {},
) {
const pageData = pagination(page, pageSize, list);

return {
...resultSuccess({
list: pageData,
pagination: {
page: ~~page,
size: ~~pageSize,
total: list.length,
},
}),
message,
};
}

export function resultError(message = 'Request failed', { code = -1, result = null } = {}) {
return {
code,
result,
message,
type: 'error',
};
}

export function pagination<T = any>(page: number, pageSize: number, array: T[]): T[] {
const offset = (page - 1) * Number(pageSize);
const ret =
offset + Number(pageSize) >= array.length
? array.slice(offset, array.length)
: array.slice(offset, offset + Number(pageSize));
return ret;
}

export interface requestParams {
method: string;
body: any;
headers?: { authorization?: string };
query: any;
}

/**
* @description 本函数用于从request数据中获取token,请根据项目的实际情况修改
*
*/
export function getRequestToken({ headers }: requestParams): string | undefined {
return headers?.authorization;
}

0 comments on commit 0c3d61f

Please sign in to comment.