From d7872e3cc386f672d2300dd38aa45b29aabed6ea Mon Sep 17 00:00:00 2001 From: ZRMYDYCG <547471919@qq.com> Date: Wed, 5 Mar 2025 13:31:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=EF=B8=8F=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + pnpm-lock.yaml | 29 +------- src/router/index.ts | 2 +- src/store/modules/user.ts | 59 ++++++++++----- src/utils/http/index.ts | 2 +- src/view/login/index.vue | 144 ++++++++++++++++++++++++++++++++++- src/view/register/index.vue | 145 +++++++++++++++++++++++++++++++++++- 7 files changed, 329 insertions(+), 53 deletions(-) diff --git a/package.json b/package.json index 6796b91..e384022 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ } }, "dependencies": { + "@element-plus/icons-vue": "^2.3.1", "@tailwindcss/vite": "^4.0.9", "@vueuse/core": "^12.7.0", "axios": "^1.8.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9017944..d9d586d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: dependencies: + '@element-plus/icons-vue': + specifier: ^2.3.1 + version: 2.3.1(vue@3.5.13(typescript@5.7.3)) '@tailwindcss/vite': specifier: ^4.0.9 version: 4.0.9(vite@6.2.0(@types/node@22.13.8)(jiti@2.4.2)(lightningcss@1.29.1)(yaml@2.7.0)) @@ -108,12 +111,6 @@ importers: lint-staged: specifier: ^15.4.3 version: 15.4.3 - postcss: - specifier: ^8.5.3 - version: 8.5.3 - postcss-nested: - specifier: ^7.0.2 - version: 7.0.2(postcss@8.5.3) prettier: specifier: ^3.2.4 version: 3.5.3 @@ -2052,20 +2049,10 @@ packages: pkg-types@1.3.1: resolution: {integrity: sha512-/Jm5M4RvtBFVkKWRu2BLUTNP8/M2a+UwuAX+ae4770q1qVGtfjG+WTCupoZixokjmHiry8uI+dlY8KXYV5HVVQ==} - postcss-nested@7.0.2: - resolution: {integrity: sha512-5osppouFc0VR9/VYzYxO03VaDa3e8F23Kfd6/9qcZTUI8P58GIYlArOET2Wq0ywSl2o2PjELhYOFI4W7l5QHKw==} - engines: {node: '>=18.0'} - peerDependencies: - postcss: ^8.2.14 - postcss-selector-parser@6.1.2: resolution: {integrity: sha512-Q8qQfPiZ+THO/3ZrOrO0cJJKfpYCagtMUkXbnEfmgUjwXg6z/WBeOyS9APBBPCTSiDV+s4SwQGu8yFsiMRIudg==} engines: {node: '>=4'} - postcss-selector-parser@7.1.0: - resolution: {integrity: sha512-8sLjZwK0R+JlxlYcTuVnyT2v+htpdrjDOKuMcOVdYjt52Lh8hWRYpxBPoKx/Zg+bcjc3wx6fmQevMmUztS/ccA==} - engines: {node: '>=4'} - postcss@8.5.3: resolution: {integrity: sha512-dle9A3yYxlBSrt8Fu+IpjGT8SY8hN0mlaA6GY8t0P5PjIOZemULz/E2Bnm/2dcUOena75OTNkHI76uZBNUUq3A==} engines: {node: ^10 || ^12 || >=14} @@ -4493,21 +4480,11 @@ snapshots: mlly: 1.7.4 pathe: 2.0.3 - postcss-nested@7.0.2(postcss@8.5.3): - dependencies: - postcss: 8.5.3 - postcss-selector-parser: 7.1.0 - postcss-selector-parser@6.1.2: dependencies: cssesc: 3.0.0 util-deprecate: 1.0.2 - postcss-selector-parser@7.1.0: - dependencies: - cssesc: 3.0.0 - util-deprecate: 1.0.2 - postcss@8.5.3: dependencies: nanoid: 3.3.8 diff --git a/src/router/index.ts b/src/router/index.ts index 20dfb51..aedc843 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,4 +1,4 @@ -import useUserStore from '@/store/modules/user' +import { useUserStore } from '@/store/modules/user' import { createRouter, createWebHistory } from 'vue-router' import routes from './routes' diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 465fd99..d4b27b5 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -1,35 +1,60 @@ +import $api from '@/api' +import { HTTP_CODE, HTTP_HOST } from '@/settings/config/http' import { defineStore } from 'pinia' import { ref } from 'vue' -const useUserStore = defineStore('userStore', () => { - const token = ref('has-token') - const userInfo = ref<{ - nickname: string - avatar: string - account: string - }>() +interface UserInfo { + avatar: string + [key: string]: any +} - const updateUserInfo = (user) => { +export const useUserStore = defineStore('userStore', () => { + const userInfo = ref(null) + const updateUserInfo = (user: UserInfo) => { userInfo.value = user + + // 数据持久化 localStorage.setItem('user', JSON.stringify(user)) } - const updateToken = (token) => { - token.value = token - localStorage.setItem('token', JSON.stringify(token)) + const token = ref('') + const updateToken = (value: string) => { + token.value = value + + // 数据持久化 + localStorage.setItem('token', value) } - const loginAction = () => { - return new Promise(() => {}) + // 登录action + const accountLogin = (data: { account: string; password: string }) => { + return new Promise((resolve, reject) => { + ;($api as any).login + .accountLogin(data) + .then((res) => { + const { code, data, message } = res.data + if (code === HTTP_CODE.HTTP_SUCCESS_CODE) { + const { avatar, ...extra } = data.info + updateUserInfo({ + avatar: `${HTTP_HOST}${avatar}`, + ...extra, + }) + updateToken(data.token) + resolve() + } else { + reject(message) + } + }) + .catch(() => { + reject('登录失败') + }) + }) } return { - token, userInfo, updateUserInfo, + token, updateToken, - loginAction, + accountLogin, } }) - -export default useUserStore diff --git a/src/utils/http/index.ts b/src/utils/http/index.ts index c54878d..85430b0 100644 --- a/src/utils/http/index.ts +++ b/src/utils/http/index.ts @@ -1,5 +1,5 @@ import { HTTP_TIMEOUT } from '@/settings/config/http' -import useUserStore from '@/store/modules/user' +import { useUserStore } from '@/store/modules/user' import axios from 'axios' // 创建http axios实例 diff --git a/src/view/login/index.vue b/src/view/login/index.vue index 7f6f978..27cdb5f 100644 --- a/src/view/login/index.vue +++ b/src/view/login/index.vue @@ -1,7 +1,143 @@ - - - + + + diff --git a/src/view/register/index.vue b/src/view/register/index.vue index 7f6f978..0a8e7b7 100644 --- a/src/view/register/index.vue +++ b/src/view/register/index.vue @@ -1,7 +1,144 @@ - - - + + +