登录页面完善

This commit is contained in:
BianLzhaoMin 2024-11-18 18:28:06 +08:00
parent 186a19dae0
commit 028e3ae4e8
9 changed files with 115 additions and 144 deletions

View File

@ -2,7 +2,7 @@
"version" : "1.0",
"configurations" : [
{
"playground" : "standard",
"playground" : "custom",
"type" : "uni-app:app-android"
},
{

View File

@ -66,14 +66,14 @@
"vue-i18n": "^9.14.1"
},
"devDependencies": {
"@dcloudio/types": "^3.4.8",
"@dcloudio/uni-automator": "3.0.0-4020420240722002",
"@dcloudio/uni-cli-shared": "3.0.0-4020420240722002",
"@dcloudio/uni-stacktracey": "3.0.0-4020420240722002",
"@dcloudio/vite-plugin-uni": "3.0.0-4020420240722002",
"@dcloudio/types": "^3.4.14",
"@dcloudio/uni-automator": "3.0.0-4020920240930001",
"@dcloudio/uni-cli-shared": "3.0.0-4020920240930001",
"@dcloudio/uni-stacktracey": "3.0.0-4020920240930001",
"@dcloudio/vite-plugin-uni": "3.0.0-4020920240930001",
"@eslint/js": "^9.9.0",
"@rollup/rollup-darwin-x64": "^4.27.2",
"@vue/runtime-core": "^3.4.21",
"@vue/runtime-core": "^3.5.13",
"eslint": "^9.9.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-vue": "^9.27.0",

View File

@ -76,20 +76,20 @@ importers:
version: 9.14.1(vue@3.5.13)
devDependencies:
'@dcloudio/types':
specifier: ^3.4.8
specifier: ^3.4.14
version: 3.4.14
'@dcloudio/uni-automator':
specifier: 3.0.0-4020420240722002
version: 3.0.0-4020420240722002(jest-environment-node@27.5.1)(jest@27.0.4)(postcss@8.4.49)(rollup@4.27.2)(vue@3.5.13)
specifier: 3.0.0-4020920240930001
version: 3.0.0-4020920240930001(jest-environment-node@27.5.1)(jest@27.0.4)(postcss@8.4.49)(rollup@4.27.2)(vue@3.5.13)
'@dcloudio/uni-cli-shared':
specifier: 3.0.0-4020420240722002
version: 3.0.0-4020420240722002(postcss@8.4.49)(rollup@4.27.2)(vue@3.5.13)
specifier: 3.0.0-4020920240930001
version: 3.0.0-4020920240930001(postcss@8.4.49)(rollup@4.27.2)(vue@3.5.13)
'@dcloudio/uni-stacktracey':
specifier: 3.0.0-4020420240722002
version: 3.0.0-4020420240722002
specifier: 3.0.0-4020920240930001
version: 3.0.0-4020920240930001
'@dcloudio/vite-plugin-uni':
specifier: 3.0.0-4020420240722002
version: 3.0.0-4020420240722002(postcss@8.4.49)(rollup@4.27.2)(vite@5.2.8(@types/node@22.9.0)(less@4.2.0)(sass@1.32.13)(terser@5.36.0))(vue@3.5.13)
specifier: 3.0.0-4020920240930001
version: 3.0.0-4020920240930001(postcss@8.4.49)(rollup@4.27.2)(vite@5.2.8(@types/node@22.9.0)(less@4.2.0)(sass@1.32.13)(terser@5.36.0))(vue@3.5.13)
'@eslint/js':
specifier: ^9.9.0
version: 9.15.0
@ -97,7 +97,7 @@ importers:
specifier: ^4.27.2
version: 4.27.2
'@vue/runtime-core':
specifier: ^3.4.21
specifier: ^3.5.13
version: 3.5.13
eslint:
specifier: ^9.9.0
@ -737,16 +737,12 @@ packages:
peerDependencies:
'@dcloudio/types': ^3.4.11
'@dcloudio/uni-automator@3.0.0-4020420240722002':
resolution: {integrity: sha512-fgkotGZj/ycS4fElPGe89wXnJeUBaI3VCPyjS1C2qWY77EYfjeyrZDw6l0eHzA9YDOvZmYPhzACMgjwbfsEoLQ==}
'@dcloudio/uni-automator@3.0.0-4020920240930001':
resolution: {integrity: sha512-HsCw/ulfiG8Kavn1cz1bCHOcUiBxCvyphOjMMjnNIJZb/cgQl7HpJQ7PThpQXDpEn2oNRKw/6fKsX2ZTLWfWZA==}
peerDependencies:
jest: 27.0.4
jest-environment-node: 27.5.1
'@dcloudio/uni-cli-shared@3.0.0-4020420240722002':
resolution: {integrity: sha512-cU9iOmHcOSFYQ8Ucy+ipt8AaQWdYeaW+S433aLKfeyv/6Ehqn/C2aFSFjkslqYsKfeQ7ZymqDn6FcCnz7HYSvQ==}
engines: {node: ^14.18.0 || >=16.0.0}
'@dcloudio/uni-cli-shared@3.0.0-4020920240930001':
resolution: {integrity: sha512-DpKcXXtAiyZXX8WxDSSRjl/PuTYFPBvWDcS7UfWR3Vw13gM3TUEu3WPl1URgGlxmwr30x5YLv6ZA6UoXSZ6MNw==}
engines: {node: ^14.18.0 || >=16.0.0}
@ -766,9 +762,6 @@ packages:
'@dcloudio/uni-h5@3.0.0-4020920240930001':
resolution: {integrity: sha512-9M7UqJVVC1KEP6mcmRzmdWX8+VWp3Y+FSKGQ4ymWJ+T0Xest4i3oggj2nLBDTfyhYMEZ3hNFI885o5cUoolMCw==}
'@dcloudio/uni-i18n@3.0.0-4020420240722002':
resolution: {integrity: sha512-AYFfypLBqA6mWqvAsSipboZF8YLk3N6ok6Ud1EtIe4Lk0XthlGNX7EacSyfb8cPVGtt5mamkLP6z+butG+nuZg==}
'@dcloudio/uni-i18n@3.0.0-4020920240930001':
resolution: {integrity: sha512-ltKiciML0ptWRytvbFt1dd4YglEjh4fsUc0D/dY+y5YKNxK7h/V2HT3qkQtP05T1kjEput4KrWNn23fczO3YFg==}
@ -817,20 +810,17 @@ packages:
'@dcloudio/uni-quickapp-webview@3.0.0-4020920240930001':
resolution: {integrity: sha512-P0G/u/DSJyEw+Txnpxbg8fMOJE1nNcRLwdTCWe43KefPBQRiRVo4n/tWWxBgV+tnbryqolPivkxLsLDfi358+w==}
'@dcloudio/uni-shared@3.0.0-4020420240722002':
resolution: {integrity: sha512-kFKmAgUDdlUyS3XBuXvmLQu3tEDAlJX6hQshsbdwP5LsH4MoI5xJVZpO6iloz3injL7+D/3i/UGoreA0qT3jew==}
'@dcloudio/uni-shared@3.0.0-4020920240930001':
resolution: {integrity: sha512-8EEQAaY+Y9BRCZIqpoaI7ciQFTO/sggxPO1kJNVAkxvJs/GVb4mawPlW9UNsMiWEqRvOJlV7KldCu6eMYlyyfg==}
'@dcloudio/uni-stacktracey@3.0.0-4020420240722002':
resolution: {integrity: sha512-SFc5wFqGBd5Gfk3uq0WPl3T1YsPcRP17euilbjJHvrdzAs3U5QlI9Azu6IYYTOBhxsRa5n234dfu+YHjvHysrQ==}
'@dcloudio/uni-stacktracey@3.0.0-4020920240930001':
resolution: {integrity: sha512-YBAHXAWsiZiG4DbIcfle0W0PfILxG8Pymx/Lp2A2+OzMYANRjs2M2kq4S9g73ZVkIyUVxgHqqQRRdGgAwOUbhg==}
'@dcloudio/uni-stat@3.0.0-4020920240930001':
resolution: {integrity: sha512-ZPn4WQPlZ3lObaZM9Q1fryewIsan1XD4qy+oWsqAuGop1kaHDQKUfg2D+jclAOCr4+95u4Jfn+RH0HNqrI0eqg==}
'@dcloudio/vite-plugin-uni@3.0.0-4020420240722002':
resolution: {integrity: sha512-+SYpD22swzwOtyiaOWyknRFpkc2YD8UNFoz+fAVEE6GEK48kvWAP1KpeY8iVsTObkrTs+1Oz4yr8QGZVqE3ksg==}
'@dcloudio/vite-plugin-uni@3.0.0-4020920240930001':
resolution: {integrity: sha512-ZtV5x4Jj8d2FzaK8uamYdfYwzRbMseWY3l6MTUdc94uMNIvnb2fBhJccoY3xexSDYRFRElPKk7+ed6AQ7tYtuw==}
engines: {node: ^14.18.0 || >=16.0.0}
hasBin: true
peerDependencies:
@ -1496,8 +1486,8 @@ packages:
'@types/yargs@16.0.9':
resolution: {integrity: sha512-tHhzvkFXZQeTECenFoRljLBYPZJ7jAVxqqtEI0qTLOmuultnFp4I9yKE17vTuhf7BkhCu7I4XuemPgikDVuYqA==}
'@vitejs/plugin-legacy@5.4.3':
resolution: {integrity: sha512-wsyXK9mascyplcqvww1gA1xYiy29iRHfyciw+a0t7qRNdzX6PdfSWmOoCi74epr87DujM+5J+rnnSv+4PazqVg==}
'@vitejs/plugin-legacy@5.3.2':
resolution: {integrity: sha512-8moCOrIMaZ/Rjln0Q6GsH6s8fAt1JOI3k8nmfX4tXUxE5KAExVctSyOBk+A25GClsdSWqIk2yaUthH3KJ2X4tg==}
engines: {node: ^18.0.0 || >=20.0.0}
peerDependencies:
terser: ^5.4.0
@ -1517,13 +1507,6 @@ packages:
vite: ^5.0.0
vue: ^3.2.25
'@vitejs/plugin-vue@5.2.0':
resolution: {integrity: sha512-7n7KdUEtx/7Yl7I/WVAMZ1bEb0eVvXF3ummWTeLcs/9gvo9pJhuLdouSXGjdZ/MKD1acf1I272+X0RMua4/R3g==}
engines: {node: ^18.0.0 || >=20.0.0}
peerDependencies:
vite: ^5.0.0
vue: ^3.2.25
'@vue/babel-helper-vue-transform-on@1.2.5':
resolution: {integrity: sha512-lOz4t39ZdmU4DJAa2hwPYmKc8EsuGa2U0L9KaZaOJUt0UwQNjNA3AZTq6uEivhOKhhG1Wvy96SvYBoFmCg3uuw==}
@ -4698,9 +4681,9 @@ snapshots:
- ts-node
- vue
'@dcloudio/uni-automator@3.0.0-4020420240722002(jest-environment-node@27.5.1)(jest@27.0.4)(postcss@8.4.49)(rollup@4.27.2)(vue@3.5.13)':
'@dcloudio/uni-automator@3.0.0-4020920240930001(jest-environment-node@27.5.1)(jest@27.0.4)(postcss@8.4.49)(rollup@4.27.2)(vue@3.5.13)':
dependencies:
'@dcloudio/uni-cli-shared': 3.0.0-4020420240722002(postcss@8.4.49)(rollup@4.27.2)(vue@3.5.13)
'@dcloudio/uni-cli-shared': 3.0.0-4020920240930001(postcss@8.4.49)(rollup@4.27.2)(vue@3.5.13)
address: 1.2.2
cross-env: 7.0.3
debug: 4.3.7
@ -4725,64 +4708,6 @@ snapshots:
- utf-8-validate
- vue
'@dcloudio/uni-cli-shared@3.0.0-4020420240722002(postcss@8.4.49)(rollup@4.27.2)(vue@3.5.13)':
dependencies:
'@ampproject/remapping': 2.3.0
'@babel/code-frame': 7.26.2
'@babel/core': 7.26.0
'@babel/parser': 7.26.2
'@babel/types': 7.26.0
'@dcloudio/uni-i18n': 3.0.0-4020420240722002
'@dcloudio/uni-shared': 3.0.0-4020420240722002
'@intlify/core-base': 9.1.9
'@intlify/shared': 9.1.9
'@intlify/vue-devtools': 9.1.9
'@rollup/pluginutils': 5.1.3(rollup@4.27.2)
'@vue/compiler-core': 3.4.21
'@vue/compiler-dom': 3.4.21
'@vue/compiler-sfc': 3.4.21
'@vue/compiler-ssr': 3.4.21
'@vue/server-renderer': 3.4.21(vue@3.5.13)
'@vue/shared': 3.4.21
adm-zip: 0.5.16
autoprefixer: 10.4.20(postcss@8.4.49)
base64url: 3.0.1
chokidar: 3.6.0
compare-versions: 3.6.0
debug: 4.3.7
es-module-lexer: 1.5.4
esbuild: 0.20.2
estree-walker: 2.0.2
fast-glob: 3.3.2
fs-extra: 10.1.0
hash-sum: 2.0.0
isbinaryfile: 5.0.4
jsonc-parser: 3.3.1
lines-and-columns: 2.0.4
magic-string: 0.30.12
merge: 2.1.1
mime: 3.0.0
module-alias: 2.2.3
os-locale-s-fix: 1.0.8-fix-1
picocolors: 1.1.1
postcss-import: 14.1.0(postcss@8.4.49)
postcss-load-config: 3.1.4(postcss@8.4.49)
postcss-modules: 4.3.1(postcss@8.4.49)
postcss-selector-parser: 6.1.2
resolve: 1.22.8
source-map-js: 1.2.1
tapable: 2.2.1
unplugin-auto-import: 0.16.7(rollup@4.27.2)
xregexp: 3.1.0
transitivePeerDependencies:
- '@nuxt/kit'
- '@vueuse/core'
- postcss
- rollup
- supports-color
- ts-node
- vue
'@dcloudio/uni-cli-shared@3.0.0-4020920240930001(postcss@8.4.49)(rollup@4.27.2)(vue@3.5.13)':
dependencies:
'@ampproject/remapping': 2.3.0
@ -4923,8 +4848,6 @@ snapshots:
- ts-node
- vue
'@dcloudio/uni-i18n@3.0.0-4020420240722002': {}
'@dcloudio/uni-i18n@3.0.0-4020920240930001': {}
'@dcloudio/uni-mp-alipay@3.0.0-4020920240930001(postcss@8.4.49)(rollup@4.27.2)(vue@3.5.13)':
@ -5182,15 +5105,11 @@ snapshots:
- ts-node
- vue
'@dcloudio/uni-shared@3.0.0-4020420240722002':
dependencies:
'@vue/shared': 3.4.21
'@dcloudio/uni-shared@3.0.0-4020920240930001':
dependencies:
'@vue/shared': 3.4.21
'@dcloudio/uni-stacktracey@3.0.0-4020420240722002': {}
'@dcloudio/uni-stacktracey@3.0.0-4020920240930001': {}
'@dcloudio/uni-stat@3.0.0-4020920240930001(postcss@8.4.49)(rollup@4.27.2)(vue@3.5.13)':
dependencies:
@ -5206,16 +5125,16 @@ snapshots:
- ts-node
- vue
'@dcloudio/vite-plugin-uni@3.0.0-4020420240722002(postcss@8.4.49)(rollup@4.27.2)(vite@5.2.8(@types/node@22.9.0)(less@4.2.0)(sass@1.32.13)(terser@5.36.0))(vue@3.5.13)':
'@dcloudio/vite-plugin-uni@3.0.0-4020920240930001(postcss@8.4.49)(rollup@4.27.2)(vite@5.2.8(@types/node@22.9.0)(less@4.2.0)(sass@1.32.13)(terser@5.36.0))(vue@3.5.13)':
dependencies:
'@babel/core': 7.26.0
'@babel/plugin-syntax-import-meta': 7.10.4(@babel/core@7.26.0)
'@babel/plugin-transform-typescript': 7.25.9(@babel/core@7.26.0)
'@dcloudio/uni-cli-shared': 3.0.0-4020420240722002(postcss@8.4.49)(rollup@4.27.2)(vue@3.5.13)
'@dcloudio/uni-shared': 3.0.0-4020420240722002
'@dcloudio/uni-cli-shared': 3.0.0-4020920240930001(postcss@8.4.49)(rollup@4.27.2)(vue@3.5.13)
'@dcloudio/uni-shared': 3.0.0-4020920240930001
'@rollup/pluginutils': 5.1.3(rollup@4.27.2)
'@vitejs/plugin-legacy': 5.4.3(terser@5.36.0)(vite@5.2.8(@types/node@22.9.0)(less@4.2.0)(sass@1.32.13)(terser@5.36.0))
'@vitejs/plugin-vue': 5.2.0(vite@5.2.8(@types/node@22.9.0)(less@4.2.0)(sass@1.32.13)(terser@5.36.0))(vue@3.5.13)
'@vitejs/plugin-legacy': 5.3.2(terser@5.36.0)(vite@5.2.8(@types/node@22.9.0)(less@4.2.0)(sass@1.32.13)(terser@5.36.0))
'@vitejs/plugin-vue': 5.1.0(vite@5.2.8(@types/node@22.9.0)(less@4.2.0)(sass@1.32.13)(terser@5.36.0))(vue@3.5.13)
'@vitejs/plugin-vue-jsx': 3.1.0(vite@5.2.8(@types/node@22.9.0)(less@4.2.0)(sass@1.32.13)(terser@5.36.0))(vue@3.5.13)
'@vue/compiler-core': 3.4.21
'@vue/compiler-dom': 3.4.21
@ -6015,7 +5934,7 @@ snapshots:
dependencies:
'@types/yargs-parser': 21.0.3
'@vitejs/plugin-legacy@5.4.3(terser@5.36.0)(vite@5.2.8(@types/node@22.9.0)(less@4.2.0)(sass@1.32.13)(terser@5.36.0))':
'@vitejs/plugin-legacy@5.3.2(terser@5.36.0)(vite@5.2.8(@types/node@22.9.0)(less@4.2.0)(sass@1.32.13)(terser@5.36.0))':
dependencies:
'@babel/core': 7.26.0
'@babel/preset-env': 7.26.0(@babel/core@7.26.0)
@ -6045,11 +5964,6 @@ snapshots:
vite: 5.2.8(@types/node@22.9.0)(less@4.2.0)(sass@1.32.13)(terser@5.36.0)
vue: 3.5.13
'@vitejs/plugin-vue@5.2.0(vite@5.2.8(@types/node@22.9.0)(less@4.2.0)(sass@1.32.13)(terser@5.36.0))(vue@3.5.13)':
dependencies:
vite: 5.2.8(@types/node@22.9.0)(less@4.2.0)(sass@1.32.13)(terser@5.36.0)
vue: 3.5.13
'@vue/babel-helper-vue-transform-on@1.2.5': {}
'@vue/babel-plugin-jsx@1.2.5(@babel/core@7.26.0)':

View File

@ -4,16 +4,14 @@
<uni-forms :modelValue="loginForm" label-position="top" class="login-form">
<h1>用户登录</h1>
<uni-forms-item label="用户名">
<uni-easyinput
v-model="loginForm.userName"
placeholder="请输入账户"
></uni-easyinput>
<uni-easyinput v-model="loginForm.username" placeholder="请输入用户名" />
</uni-forms-item>
<uni-forms-item required label="密码">
<uni-easyinput
v-model="loginForm.passWord"
type="password"
placeholder="请输入密码"
></uni-easyinput>
v-model="loginForm.password"
/>
</uni-forms-item>
<view class="login-btn" @tap="onHandleLogin">登录</view>
@ -23,16 +21,39 @@
<script setup>
import { reactive, ref } from 'vue'
import { appLoginAPI, getUserInfoAPI } from '@/services/index.js'
import { useMemberStore } from '@/stores'
const memberStore = useMemberStore()
//
const loginForm = reactive({
userName: '',
passWord: '',
username: '',
password: '',
loginType: 'USERNAME_PASSWORD',
code: '',
phoneUuid: '',
uuid: '',
verificationCode: '',
})
const onHandleLogin = () => {
console.log('登录---')
uni.switchTab({
url: '/pages/index/index',
})
//
const onHandleLogin = async () => {
const res = await appLoginAPI(loginForm)
if (res.code === 200) {
uni.showToast({ title: '登录成功', icon: 'none' })
// token
memberStore.setToken(res.data.access_token)
//
const result = await getUserInfoAPI()
memberStore.setUserInfo(result.user)
uni.showToast({ title: '登录成功!', icon: 'none' })
setTimeout(() => {
uni.switchTab({
url: '/pages/index/index',
})
}, 500)
}
}
</script>

View File

@ -1,12 +1,20 @@
<template>
<view class="content"> 我的 </view>
<view class="content">
<view class="btn-common" @tap="onExit"> 退出登录 </view>
</view>
</template>
<script setup>
import { ref } from 'vue'
import { useMemberStore } from '@/stores'
const memberStore = useMemberStore()
const onExit = () => {
// token
memberStore.clearUserInfo()
memberStore.clearToken()
uni.navigateTo({ url: '/pages/login/index' })
}
</script>
<style>
.content {
}
</style>
<style></style>

View File

@ -6,7 +6,16 @@ import { http } from '@/utils/http'
export const appLoginAPI = (data) => {
return http({
method: 'POST',
url: '/auth/loginApp',
url: '/auth/login',
data,
})
}
/**
* 获取用户信息
*/
export const getUserInfoAPI = () => {
return http({
method: 'GET',
url: '/system/user/getInfo',
})
}

View File

@ -5,7 +5,8 @@ export const useMemberStore = defineStore(
'member',
() => {
// 定义用户信息
const userInfo = ref({ token: '999', userName: '李师师' })
const userInfo = ref({ token: '', userName: '' })
const token = ref('')
// 存储用户信息
const setUserInfo = (val) => {
userInfo.value = val
@ -14,6 +15,14 @@ export const useMemberStore = defineStore(
const clearUserInfo = () => {
userInfo.value = undefined
}
// 存储 token
const setToken = (val) => {
token.value = val
}
// 清除 token
const clearToken = (val) => {
token.value = undefined
}
// 把数据和方法 return 出去
@ -21,6 +30,8 @@ export const useMemberStore = defineStore(
userInfo,
setUserInfo,
clearUserInfo,
setToken,
clearToken,
}
},

View File

@ -1,4 +1,12 @@
.page-common {
padding: 0 15rpx;
background-color: #f3f6fd;
}
.btn-common {
padding: 18rpx 0;
text-align: center;
background-color: #1989fa;
color: #fff;
border-radius: 10rpx;
}

View File

@ -27,11 +27,11 @@ const httpInterceptor = {
// 'source-client': 'mini',
...options.header,
}
// 4. 增加 token 请求头标识
const memberStore = useMemberStore()
// const token = memberStore.userInfo.token
const token = "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6IjQ2NDdmYjlkLWI5OTItNDRiNy05MTdkLTMwZjg0ZjUxYzM5MCIsInVzZXJuYW1lIjoiYWRtaW4ifQ.9xM5bFhrmHK09-4ZgL5SS8WraNIJjIijuB-1P0lJF-n0KlVM5Bglvyjltk1NQbdqgi1hwRocZS1OU41cLiwuig"
const token = memberStore.token
// const token = "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6IjQ2NDdmYjlkLWI5OTItNDRiNy05MTdkLTMwZjg0ZjUxYzM5MCIsInVzZXJuYW1lIjoiYWRtaW4ifQ.9xM5bFhrmHK09-4ZgL5SS8WraNIJjIijuB-1P0lJF-n0KlVM5Bglvyjltk1NQbdqgi1hwRocZS1OU41cLiwuig"
if (token) {
options.header.Authorization = token
}
@ -66,7 +66,7 @@ export const http = (options) => {
// })
reject(res)
}
console.log(res)
console.log(res)
},
fail(err) {
// uni.showToast({