From a1ccac5b4175b493d99a313e7a972d70772ede5b Mon Sep 17 00:00:00 2001
From: xiangshu233
Date: Sun, 23 Oct 2022 17:17:07 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=94=A8=20=E4=BF=AE=E5=A4=8D?=
=?UTF-8?q?=E7=BA=BF=E4=B8=8A=20Mock=20=E6=8A=A5=E9=94=99=E7=9A=84?=
=?UTF-8?q?=E9=97=AE=E9=A2=98=20docs:=20=F0=9F=93=94=20README=20=E6=96=B0?=
=?UTF-8?q?=E5=A2=9E=E7=BA=BF=E4=B8=8A=E9=A2=84=E8=A7=88?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 17 +++++++-
mock/_createProductionServer.ts | 2 +-
mock/user/user.ts | 70 ++++++++++++++++-----------------
src/utils/domUtils.ts | 1 +
4 files changed, 51 insertions(+), 39 deletions(-)
diff --git a/README.md b/README.md
index 08b75b4..81d669c 100644
--- a/README.md
+++ b/README.md
@@ -25,7 +25,7 @@
-
+
@@ -35,10 +35,23 @@
-
+
+## 线上预览
+- [vue3-vant4-mobile](https://vue3-vant4-mobile.xiangshu233.cn/)
+
+账号:admin,密码:123456
+
+账号:test,密码:123456
+
+
+或者扫描以下二维码进入手机演示
+
+
+
+
## 基础知识
既然你搜了 `vue3`、`vant4` 此类关键词,则默认你会用这些配套技术栈。
diff --git a/mock/_createProductionServer.ts b/mock/_createProductionServer.ts
index de81d38..74125af 100644
--- a/mock/_createProductionServer.ts
+++ b/mock/_createProductionServer.ts
@@ -1,6 +1,6 @@
import { createProdMockServer } from 'vite-plugin-mock/es/createProdMockServer';
-const modules: Recordable = import.meta.glob('./**/*.ts');
+const modules = import.meta.glob('./**/*.ts', { eager: true }) as any;
const mockModules: any[] = [];
Object.keys(modules).forEach((key) => {
diff --git a/mock/user/user.ts b/mock/user/user.ts
index cf6f938..48dd380 100644
--- a/mock/user/user.ts
+++ b/mock/user/user.ts
@@ -2,39 +2,37 @@ import { MockMethod } from 'vite-plugin-mock';
import { getRequestToken, requestParams, resultError, resultSuccess } from '../_util';
import { ResultEnum } from '@/enums/httpEnum';
-export function createFakeUserList() {
- return [
- {
- userId: 1,
- username: 'admin',
- password: '123456',
- nickname: '一条咸鱼',
- realname: 'administrator',
- avatar: 'https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg',
- cover: '',
- sign: '一年精通三年熟练五年入门',
- industry: 4,
- gender: 0,
- phone: '15758791450',
- token: 'fakeToken1',
- },
- {
- userId: 2,
- username: 'test',
- password: '123456',
- nickname: '萝卜头',
- realname: 'test user',
- avatar:
- 'https://link.jscdn.cn/1drv/aHR0cHM6Ly8xZHJ2Lm1zL3UvcyFBaFhWN0U3bHBTaWtsbkNaWjYxY0lLczdEUGlpP2U9Yldkd0Fp.jpg',
- cover: '',
- sign: '这个家伙很懒,什么都没有写~',
- industry: 7,
- gender: 1,
- phone: '18822137893',
- token: 'fakeToken2',
- },
- ];
-}
+const fakeUserList = [
+ {
+ userId: 1,
+ username: 'admin',
+ password: '123456',
+ nickname: '一条咸鱼',
+ realname: 'administrator',
+ avatar: 'https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg',
+ cover: '',
+ sign: '一年精通三年熟练五年入门',
+ industry: 4,
+ gender: 0,
+ phone: '15758791450',
+ token: 'fakeToken1',
+ },
+ {
+ userId: 2,
+ username: 'test',
+ password: '123456',
+ nickname: '萝卜头',
+ realname: 'test user',
+ avatar:
+ 'https://link.jscdn.cn/1drv/aHR0cHM6Ly8xZHJ2Lm1zL3UvcyFBaFhWN0U3bHBTaWtsbkNaWjYxY0lLczdEUGlpP2U9Yldkd0Fp.jpg',
+ cover: '',
+ sign: '这个家伙很懒,什么都没有写~',
+ industry: 7,
+ gender: 1,
+ phone: '18822137893',
+ token: 'fakeToken2',
+ },
+];
export default [
{
@@ -43,7 +41,7 @@ export default [
method: 'post',
response: ({ body }) => {
const { username, password } = body;
- const checkUser = createFakeUserList().find(
+ const checkUser = fakeUserList.find(
(item) => item.username === username && password === item.password
);
if (!checkUser) {
@@ -66,7 +64,7 @@ export default [
response: (request: requestParams) => {
const token = getRequestToken(request);
if (!token) return resultError('无效令牌');
- const checkUser = createFakeUserList().find((item) => item.token === token);
+ const checkUser = fakeUserList.find((item) => item.token === token);
if (!checkUser) {
return resultError('没有获取到对应的用户信息', {
code: ResultEnum.TOKEN_EXPIRED,
@@ -82,7 +80,7 @@ export default [
response: (request: requestParams) => {
const token = getRequestToken(request);
if (!token) return resultError('无效令牌');
- const checkUser = createFakeUserList().find((item) => item.token === token);
+ const checkUser = fakeUserList.find((item) => item.token === token);
if (!checkUser) {
return resultError('无效令牌');
}
diff --git a/src/utils/domUtils.ts b/src/utils/domUtils.ts
index 126a114..ead55d5 100644
--- a/src/utils/domUtils.ts
+++ b/src/utils/domUtils.ts
@@ -158,6 +158,7 @@ export function off(
export function once(el: HTMLElement, event: string, fn: EventListener): void {
const listener = function (this: any, ...args: unknown[]) {
if (fn) {
+ // @ts-ignore
fn.apply(this, args);
}
off(el, event, listener);