feat(projects): 引入mockjs

This commit is contained in:
Soybean
2021-12-25 01:23:44 +08:00
parent c9c5ca9989
commit 9bc682dae8
18 changed files with 363 additions and 83 deletions

View File

@@ -5,6 +5,9 @@
</template>
<script lang="ts" setup>
import { fetchTestMock } from '@/service';
import AppProvider from './AppProvider.vue';
fetchTestMock();
</script>
<style></style>

View File

@@ -1,6 +1,6 @@
import { useAuthStore } from '@/store';
import { useLoading } from '@/hooks';
import { setToken, setRefreshToken, setUserInfo, log } from '@/utils';
import { setToken, setRefreshToken, setUserInfo, consoleLog } from '@/utils';
import type { LoginToken, UserInfo } from '@/interface';
import { useRouterPush, useRouteQuery } from '../common';
@@ -20,7 +20,7 @@ export function useLogin() {
* @returns 是否登录成功
*/
async function login(param: { phone: string; pwdOrCode: string; type: 'pwd' | 'sms' }) {
log(param); // 打印参数(接入接口后去除)
consoleLog(param); // 打印参数(接入接口后去除)
startLoading();
// 1.这里调用登录接口获取token和refreshToken

View File

@@ -0,0 +1,8 @@
import { consoleLog } from '@/utils';
import { mockRequest } from '../request';
/** 测试mock数据 */
export async function fetchTestMock() {
const { data } = await mockRequest.get('/api/getUser');
consoleLog('data: ', data);
}

View File

@@ -1 +1,2 @@
export * from './demo';
export * from './auth';

View File

@@ -5,3 +5,8 @@ export const request = createRequest({
baseURL: import.meta.env.VITE_HTTP_URL,
timeout: REQUEST_TIMEOUT
});
export const mockRequest = createRequest({
baseURL: '',
timeout: REQUEST_TIMEOUT
});

View File

@@ -0,0 +1,16 @@
/* eslint-disable no-console */
/** 打印log */
export function consoleLog(message?: any, ...optionalParams: any[]) {
console.log(message, ...optionalParams);
}
/** 打印警告 */
export function consoleWarn(message?: any, ...optionalParams: any[]) {
console.warn(message, ...optionalParams);
}
/** 打印错误 */
export function consoleError(message?: any, ...optionalParams: any[]) {
console.error(message, ...optionalParams);
}

View File

@@ -2,5 +2,5 @@ export * from './typeof';
export * from './color';
export * from './icon';
export * from './browser';
export * from './log';
export * from './console';
export * from './number';

View File

@@ -1,5 +0,0 @@
/** 打印log */
export function log(data: any) {
// eslint-disable-next-line no-console
console.log(data);
}