Bläddra i källkod

回显用户最后登陆时间

Zt 1 år sedan
förälder
incheckning
25fa3367c7
3 ändrade filer med 15 tillägg och 4 borttagningar
  1. 4 1
      reado-app/pages/user/index.vue
  2. 2 1
      reado-app/store/getters.js
  3. 9 2
      reado-app/store/modules/user.js

+ 4 - 1
reado-app/pages/user/index.vue

@@ -7,7 +7,7 @@
 					{{userName}}
 				</view>
 				<view class="">
-					登录时间:2023年5月9日 12:00:00
+					登录时间:{{lastLoginTime}}
 				</view>
 			</view>
 		</view>
@@ -44,6 +44,9 @@
 		computed: {
 			userName() {
 				return this.$store.getters.userName
+			},
+			lastLoginTime(){
+				return this.$store.getters.lastLoginTime
 			}
 		},
 		methods: {

+ 2 - 1
reado-app/store/getters.js

@@ -1,6 +1,7 @@
 const getters = {
 	codeUrl: state => state.user.codeUrl,
-	userName: state => state.user.userName
+	userName: state => state.user.userName,
+	lastLoginTime: state => state.user.lastLoginTime
 }
 
 export default getters

+ 9 - 2
reado-app/store/modules/user.js

@@ -19,6 +19,8 @@ const user = {
 		userId: getUid(),
 		// 用户名
 		userName: null,
+		// 最后登陆时间
+		lastLoginTime: null,
 		// 验证码
 		codeUrl: null,
 		// 验证码登录参数
@@ -37,6 +39,9 @@ const user = {
 		SET_USER_NAME: (state, value) => {
 			state.userName = value
 		},
+		SET_LAST_LOGINTIME: (state, value) => {
+			state.lastLoginTime = value
+		},
 		SET_CODE_IMG: (state, value) => {
 			state.codeUrl = 'data:image/gif;base64,' + value
 		},
@@ -104,13 +109,15 @@ const user = {
 						const token = res.data.data.token
 						const {
 							userId,
-							userName
+							userName,
+							lastLoginTime
 						} = res.data.data.user
 						commit('SET_TOKEN', token)
 						setToken(token)
 						commit('SET_USER_ID', userId)
 						setUid(userId)
 						commit('SET_USER_NAME', userName)
+						commit('SET_LAST_LOGINTIME', lastLoginTime)
 					}
 					resolve(res)
 				}).catch(err => {
@@ -150,4 +157,4 @@ export default {
 	state,
 	mutations,
 	actions
-}
+}