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 @@ 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 @@