From 2c4b5258b0eebbdbbc6ab918acf3890bc45ab232 Mon Sep 17 00:00:00 2001
From: h_mo <596417202@qq.com>
Date: Sat, 15 Jun 2024 16:45:21 +0800
Subject: [PATCH] =?UTF-8?q?wip:=20=E5=AE=8C=E5=96=84=E9=83=A8=E5=88=86?=
=?UTF-8?q?=E7=A4=BA=E4=BE=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package.json | 2 ++
src/mock/v1/modules/auth.ts | 22 ++++++++++++++++++++--
src/pages/index/index.vue | 10 +++++++---
src/pages/log/index.vue | 13 +++++++++----
src/pages/login/index.vue | 4 ----
src/services/api/user.ts | 15 +++++++++++++--
src/services/model/userModel.d.ts | 18 ++++++++++++++++++
src/stores/modules/auth.ts | 1 -
src/stores/modules/user.ts | 25 ++++++++++++++++++-------
tsconfig.json | 4 +---
vite.config.ts | 20 ++++++++++++++++++++
11 files changed, 108 insertions(+), 26 deletions(-)
diff --git a/package.json b/package.json
index 186ea28..14568e8 100644
--- a/package.json
+++ b/package.json
@@ -50,6 +50,7 @@
"@dcloudio/uni-mp-toutiao": "3.0.0-alpha-4010920240607001",
"@dcloudio/uni-mp-weixin": "3.0.0-alpha-4010920240607001",
"@dcloudio/uni-quickapp-webview": "3.0.0-alpha-4010920240607001",
+ "@multiavatar/multiavatar": "^1.0.7",
"alova": "^2.21.3",
"crypto-js": "^4.2.0",
"lodash-es": "^4.17.21",
@@ -84,6 +85,7 @@
"uni-read-pages-vite": "^0.0.6",
"unocss": "^0.61.0",
"unocss-preset-weapp": "^0.60.1",
+ "unplugin-auto-import": "^0.17.6",
"unplugin-transform-class": "^0.5.3",
"vite": "^5.3.1",
"vite-plugin-restart": "^0.4.0"
diff --git a/src/mock/v1/modules/auth.ts b/src/mock/v1/modules/auth.ts
index b5d3ae6..26e5ca5 100644
--- a/src/mock/v1/modules/auth.ts
+++ b/src/mock/v1/modules/auth.ts
@@ -1,7 +1,9 @@
import { defineMock } from '@alova/mock';
-import { join, sampleSize } from 'lodash-es';
+import { join, random, sampleSize } from 'lodash-es';
+import multiavatar from '@multiavatar/multiavatar';
import { createMock } from '@/mock/utils';
import { ResultEnum } from '@/enums/httpEnum';
+import { getRandomChsString } from '@/utils/character';
function createRandomToken(len = 36 * 6) {
const token = join(sampleSize('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._-', len), '');
@@ -16,7 +18,23 @@ export const authMocks = defineMock({
const token = createRandomToken();
return createMock({ data: { token } });
}
- console.log('模拟登录');
return createMock({ data: [], code: ResultEnum.FAIL, message: '邮箱或密码错误' });
},
+ // 获取用户信息
+ '[GET]/api/users': () => {
+ const generateNicknames = getRandomChsString(random(2, 6));
+ const svgCode = multiavatar(generateNicknames);
+ const base64SVG = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(
+ svgCode,
+ )}`;
+
+ return createMock({
+ data: {
+ id: 1,
+ nickname: generateNicknames,
+ avatar: base64SVG,
+ email: 'uni-app@test.com',
+ },
+ });
+ },
});
diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index 03c31e0..122890d 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -1,11 +1,12 @@
@@ -15,6 +16,9 @@ function onClick() {
+
diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue
index 5b2c043..54e48f8 100644
--- a/src/pages/login/index.vue
+++ b/src/pages/login/index.vue
@@ -1,7 +1,4 @@