This repository has been archived by the owner on Mar 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
3,735 additions
and
2,245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.