Bläddra i källkod

wip: 登录/登出

王家程 11 månader sedan
förälder
incheckning
c45d88b8de

+ 8 - 1
src/api/userApi.ts

@@ -2,7 +2,7 @@
  * @Author: wjc
  * @Date: 2024-06-12 10:05:12
  * @LastEditors: wjc
- * @LastEditTime: 2024-06-12 17:24:33
+ * @LastEditTime: 2024-06-17 15:09:11
  * @Description:
  */
 import { request } from '@/utils/request'
@@ -23,6 +23,13 @@ export function login(data: ILogin) {
   })
 }
 
+export function logout() {
+  return request<BasicRes<string>>({
+    url: 'auth/logout',
+    method: 'GET',
+  })
+}
+
 export function getUserInfo(data: string) {
   return request<BasicRes<Employees>>({
     url: `auth/employees/${data}`,

+ 1 - 1
src/models/userTypes.ts

@@ -6,7 +6,7 @@
  * @Description:
  */
 export interface UserState {
-  isDialogShowed: boolean
+  isPrivacyShowed: boolean
   isInstall: boolean
   token: string
   userInfo: Employees

+ 29 - 0
src/pages.json

@@ -8,6 +8,29 @@
 			"^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue"
 		}
 	},
+	"tabBar": {
+		"height": "56px",
+		"fontSize": "12px",
+		"iconWidth": "36px",
+		"color": "#7A7E83",
+		"selectedColor": "#3cc51f",
+		"borderStyle": "black",
+		"backgroundColor": "#ffffff",
+		"list": [
+			{
+				"pagePath": "pages/index/index",
+				"iconPath": "static/images/main/work.png",
+				"selectedIconPath": "static/images/main/work_1.png",
+				"text": "工作台"
+			},
+			{
+				"pagePath": "pages/mine/index",
+				"iconPath": "static/images/main/mine.png",
+				"selectedIconPath": "static/images/main/mine_1.png",
+				"text": "我的"
+			}
+		]
+	},
 	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
 		{
 			"path": "pages/splash/index",
@@ -21,6 +44,12 @@
 				"navigationStyle": "custom"
 			}
 		},
+		{
+			"path": "pages/mine/index",
+			"style": {
+				"navigationStyle": "custom"
+			}
+		},
 		{
 			"path": "pages/privacy/index",
 			"style": {

+ 43 - 0
src/pages/mine/index.vue

@@ -0,0 +1,43 @@
+<template>
+  <view>我的</view>
+  <up-button type="primary" class="btn-primary" @click="handleConfirmLogout">退出登录</up-button>
+  <up-modal :show="logoutShow">
+    <view class="text-18px py-24px">确认退出登录?</view>
+    <template #confirmButton>
+      <view class="flex justify-between text-center gap-20px">
+        <view class="btn-default flex-1" @click="handleCancel">取消</view>
+        <view class="btn-primary flex-1" @click="handleConfirm">确定</view>
+      </view>
+    </template>
+  </up-modal>
+</template>
+
+<script setup lang="ts">
+  import { useUserStore } from '@/stores/modules/userStore'
+
+  defineOptions({ name: 'Mine' })
+
+  const userStore = useUserStore()
+  const logoutShow = ref(false)
+
+  const handleCancel = () => {
+    logoutShow.value = false
+  }
+  const handleConfirmLogout = () => {
+    logoutShow.value = true
+  }
+
+  const handleConfirm = () => {
+    onLogout()
+  }
+
+  const onLogout = () => {
+    userStore.logoutAction().then((res) => {
+      if (res) {
+        uni.navigateTo({
+          url: '/pages/login/index',
+        })
+      }
+    })
+  }
+</script>

+ 17 - 9
src/pages/splash/index.vue

@@ -2,7 +2,7 @@
  * @Author: wjc
  * @Date: 2024-06-05 15:04:50
  * @LastEditors: wjc
- * @LastEditTime: 2024-06-06 15:23:27
+ * @LastEditTime: 2024-06-17 14:37:55
  * @Description: 
 -->
 <template>
@@ -31,7 +31,7 @@
   defineOptions({ name: 'Splash' })
 
   const userStore = useUserStore()
-  const isInstall = computed(() => userStore.isInstall)
+  const isInstall = computed(() => userStore.getIsInstall)
   const list = ref([guide1, guide2, guide3])
 
   const onTapSwiper = (index: number) => {
@@ -43,13 +43,21 @@
   }
 
   onMounted(() => {
-    if (isInstall.value) {
-      setTimeout(() => {
-        uni.navigateTo({
-          url: '/pages/login/index',
-        })
-      }, 2000)
-    }
+    userStore.getUserInfoAction().then((res) => {
+      if (res) {
+        if (isInstall.value) {
+          setTimeout(() => {
+            uni.switchTab({
+              url: '/pages/index/index',
+            })
+          }, 2000)
+        } else {
+          uni.reLaunch({
+            url: '/pages/login/index',
+          })
+        }
+      }
+    })
   })
 </script>
 

BIN
src/static/images/main/mine.png


BIN
src/static/images/main/mine_1.png


BIN
src/static/images/main/msg.png


BIN
src/static/images/main/msg_1.png


BIN
src/static/images/main/synergy.png


BIN
src/static/images/main/synergy_1.png


BIN
src/static/images/main/work.png


BIN
src/static/images/main/work_1.png


+ 28 - 4
src/stores/modules/userStore.ts

@@ -2,31 +2,41 @@
  * @Author: wjc
  * @Date: 2024-06-05 17:13:30
  * @LastEditors: wjc
- * @LastEditTime: 2024-06-12 17:08:53
+ * @LastEditTime: 2024-06-17 15:11:47
  * @Description:
  */
 import { defineStore } from 'pinia'
 
 import { UserState, ILogin, LoginRes, Employees } from '@/models/userTypes'
-import { login, getUserInfo } from '@/api/userApi'
+import { login, logout, getUserInfo } from '@/api/userApi'
 
 export const useUserStore = defineStore('user', {
   state: (): UserState => {
     return {
-      isDialogShowed: false,
+      isPrivacyShowed: false,
       isInstall: false,
       token: '',
       userInfo: new Employees({}),
     }
   },
+  getters: {
+    getIsInstall(state) {
+      return state.isInstall || uni.getStorageSync('isInstall')
+    },
+    getIsPrivacyShowed(state) {
+      return state.isPrivacyShowed || uni.getStorageSync('isPrivacyShowed')
+    },
+  },
   actions: {
     loginAction(data: ILogin): Promise<LoginRes> {
       return new Promise((resolve, reject) => {
         login(data)
           .then((res) => {
             if (res && res.data) {
-              this.isDialogShowed = true
+              this.isPrivacyShowed = true
               this.isInstall = true
+              uni.setStorageSync('isPrivacyShowed', this.isPrivacyShowed)
+              uni.setStorageSync('isInstall', this.isInstall)
               uni.setStorageSync('storage-loginInfo', data)
               uni.setStorageSync('storage-user-id', res.data.id)
               resolve(res.data)
@@ -37,6 +47,20 @@ export const useUserStore = defineStore('user', {
           })
       })
     },
+    logoutAction(): Promise<string> {
+      return new Promise((resolve, reject) => {
+        logout()
+          .then((res) => {
+            if (res && res.data) {
+              uni.clearStorageSync()
+              resolve(res.data)
+            }
+          })
+          .catch((error) => {
+            reject(error)
+          })
+      })
+    },
     getUserInfoAction(): Promise<Employees> {
       return new Promise((resolve, reject) => {
         const id = uni.getStorageSync('storage-user-id')