Browse Source

feat(login):登录页保存账号密码
style(setting):设置页整理代码结构

HMY 1 năm trước cách đây
mục cha
commit
26f728d3a1
8 tập tin đã thay đổi với 90 bổ sung93 xóa
  1. 4 3
      pages/login.vue
  2. 12 53
      pages/mine/setting/setting.vue
  3. 6 4
      pages/process/index.vue
  4. 10 21
      pages/work/index.vue
  5. 24 10
      store/user.js
  6. 9 0
      utils/auth.js
  7. 2 1
      utils/request.js
  8. 23 1
      utils/ygoa.js

+ 4 - 3
pages/login.vue

@@ -28,11 +28,12 @@ import config from '@/config.js'
 import $modal from '@/plugins/modal.js'
 import $tab from '@/plugins/tab.js'
 import { useUserStore } from '@/store/user.js'
-import { reLogin } from '@/api/login'
+import { getLoginInfo } from '@/utils/auth'
 const userStore = useUserStore()
+
 const loginForm = ref({
-	username: '',
-	password: ''
+	username: getLoginInfo().username,
+	password: getLoginInfo().password
 })
 function handleLogin() {
 	const username = loginForm.value.username

+ 12 - 53
pages/mine/setting/setting.vue

@@ -36,49 +36,18 @@
 
 <script setup lang="ts">
 	import $tab from "@/plugins/tab.js"
-	import { getUserInfo } from '@/utils/auth'
+	import $modal from '@/plugins/modal.js'
 	import { useUserStore } from '@/store/user.js'
+	import {clearCache} from '@/utils/ygoa.js'
 	const userStore = useUserStore()
 	// 退出登录
 	function logOut() {
-		uni.showModal({
-			title: '系统提示',
-			content: '确定注销并退出系统吗?',
-			success: function(res) {
-				if (res.confirm) {
-					userStore.LogOut()
-					$tab.reLaunch('/pages/login')
-				} else if (res.cancel) {
-					console.log('用户点击取消');
-				}
-			}
-		});
+		$modal.confirm('确定注销并退出系统吗?')
+			.then(res=>{
+				userStore.LogOut()
+				$tab.reLaunch('/pages/login')
+			})
 	};
-	// 清理缓存
-	function clearCache() {
-		uni.showModal({
-			title: '系统提示',
-			content: '是否确定要清理缓存?',
-			success: function(res) {
-				if (res.confirm) {
-					const userInfo = getUserInfo()
-					uni.clearStorageSync();
-					uni.setStorageSync('userInfo', userInfo)
-					userStore.user = userInfo
-					userStore.useId = userInfo.useId
-					// 提示用户缓存清理成功
-					uni.showToast({
-						title: '缓存清理成功',
-						icon: 'success',
-						duration: 2000
-					});
-				} else if (res.cancel) {
-					console.log('用户点击取消');
-				}
-			}
-		});
-
-	}
 	// 修改密码
 	function pwdEdit() {
 		$tab.navigateTo('/pages/mine/setting/pwdEdit/pwdEdit');
@@ -90,23 +59,13 @@
 			// 请求完新版本信息的回调
 			if (res.hasUpdate) {
 				updateManager.onUpdateReady(function(res) {
-					uni.showModal({
-						title: '更新提示',
-						content: '新版本已经准备好,是否重启应用?',
-						success(res) {
-							if (res.confirm) {
-								// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
-								updateManager.applyUpdate();
-							}
-						}
-					});
-
+					$modal.confirm('新版本已经准备好,是否重启应用?','更新提示').then(res=>{
+						// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
+						updateManager.applyUpdate();
+					})
 				});
 			} else {
-				uni.showToast({
-					title: '暂无版本更新',
-					icon: 'none'
-				});
+				$modal.showToast('暂无版本更新')
 			}
 		});
 	}

+ 6 - 4
pages/process/index.vue

@@ -45,13 +45,16 @@
 
 <script setup lang="ts">
 import processList from '@/components/ygoa/processList.vue'
-import { reactive, ref,onMounted } from 'vue';
+import { reactive, ref,onMounted, onUpdated } from 'vue';
 import $tab from '@/plugins/tab.js'
 import { getUserProcess, getUserProcessed, getUserProcessing, getUserAllProcess,getUnProcessNum } from '@/api/process';
 import { useUserStore } from '@/store/user';
 import { getUnReadMessageNum } from '@/api/message';
 
-onMounted(()=>{
+// onMounted(()=>{
+// 	showTarBarBadge();
+// })
+onUpdated(()=>{
 	showTarBarBadge();
 })
 function showTarBarBadge(){
@@ -72,8 +75,7 @@ function showTarBarBadge(){
 					})
 				}
 			})
-		})
-		
+		})	
 	}
 const userStore = useUserStore();
 // 分段器选项

+ 10 - 21
pages/work/index.vue

@@ -108,11 +108,11 @@
 			<cui-calculator ref="calculatorPopup" size="normal"></cui-calculator>
 		</view>
 		<!-- 清除缓存弹出层 -->
-		<view class="clear_cache_popup_container">
+		<!-- <view class="clear_cache_popup_container">
 			<uni-popup ref="clearCacheDialog" type="dialog">
 				<uni-popup-dialog title="确认清除缓存" @confirm="clearCache"></uni-popup-dialog>
 			</uni-popup>
-		</view>
+		</view> -->
 	</view>
 </template>
 
@@ -120,11 +120,11 @@
 import cuiCalculator from "@/components/cui-calculator/cui-calculator.vue"
 import { onMounted, ref } from "vue"
 import $tab from "@/plugins/tab.js"
-import { getUserInfo } from '@/utils/auth'
 import { useUserStore } from '@/store/user.js'
 import { getProcessList } from '@/api/work.js'
 import { getUnProcessNum } from "@/api/process"
 import { getUnReadMessageNum } from "@/api/message"
+import { clearCache } from '@/utils/ygoa.js'
 const userStore = useUserStore()
 
 onMounted(() => {
@@ -206,7 +206,8 @@ function changeToolsGrid(e) {
 			openCalculatorPopup() // 打开计算器弹出层
 			break
 		case 2:
-			openClearCachePopup() // 打开清除缓存弹出层
+			clearCache()
+			// openClearCachePopup() // 打开清除缓存弹出层
 			break
 		default:
 	}
@@ -217,24 +218,12 @@ function openCalculatorPopup() { // 打开计算器弹出层
 	calculatorPopup.value.open()
 }
 // 清除缓存
-const clearCacheDialog = ref(null)
-function openClearCachePopup() { // 打开清除缓存弹出层
-	clearCacheDialog.value.open()
-}
+// const clearCacheDialog = ref(null)
+// function openClearCachePopup() { // 打开清除缓存弹出层
+// 	clearCacheDialog.value.open()
+// }
 // const userStore = useUserStore()
-function clearCache() {
-	const userInfo = getUserInfo()
-	uni.clearStorageSync();
-	uni.setStorageSync('userInfo', userInfo)
-	userStore.user = userInfo
-	userStore.useId = userInfo.useId
-	// 提示用户缓存清理成功
-	uni.showToast({
-		title: '缓存清理成功',
-		icon: 'success',
-		duration: 2000
-	});
-}
+
 </script>
 
 <style lang="scss">

+ 24 - 10
store/user.js

@@ -10,17 +10,22 @@ import {
 	logout
 } from '@/api/login.js'
 import {
-	getUserInfo,getSession,setSession
+	getUserInfo,
+	getSession,
+	setSession
 } from '@/utils/auth'
-import { reLogin,keepSession } from '@/api/login.js'
+import {
+	reLogin,
+	keepSession
+} from '@/api/login.js'
 
 
 export const useUserStore = defineStore('user', () => {
 	const user = ref(getUserInfo()) // 用户信息
 	const useId = ref(0) // staffId
-	const timer = ref(true)
+	const timer = ref(true) //定时器
 	function keep() {
-		keepSession().then(res=>{
+		keepSession().then(res => {
 			setTimeout(() => {
 				if (timer.value) {
 					keep()
@@ -32,18 +37,24 @@ export const useUserStore = defineStore('user', () => {
 	function Login(userInfo) {
 		const username = userInfo.username
 		const password = userInfo.password
+		const loginInfo = {
+			username,
+			password
+		}
 		return new Promise((resolve, reject) => {
 			login(username.trim(), password)
 				.then(res => {
 					useId.value = res.returnParams.useId // 设置staffId
 					user.value = res.returnParams
+					//保存账号密码
+					uni.setStorageSync('loginInfo', loginInfo)
 					// setSession(res.session)
-					reLogin(username.trim(), password).then((res)=>{
-						if("ok"===res.data){
+					reLogin(username.trim(), password).then((res) => {
+						if ("ok" === res.data) {
 							setSession(res.cookies[0].split("=")[1].split(";")[0]);
-							timer.value=true
+							timer.value = true
 							keep()
-						}	
+						}
 					})
 					resolve(res)
 				})
@@ -60,8 +71,10 @@ export const useUserStore = defineStore('user', () => {
 					const source = res.returnParams[roleIndex]
 					Object.keys(source).forEach(key => {
 						// 目标对象没有该属性或者该属性为 null,则赋值
-						if (!(key in user.value) || user.value[key] === null || user.value[key] === "") {
-							user.value[key] = source[key] === undefined ? user.value[key] : source[key];
+						if (!(key in user.value) || user.value[key] === null || user.value[
+								key] === "") {
+							user.value[key] = source[key] === undefined ? user.value[key] :
+								source[key];
 						}
 					});
 					// 保存 用户信息
@@ -88,6 +101,7 @@ export const useUserStore = defineStore('user', () => {
 		// })
 	}
 
+
 	return {
 		user,
 		useId,

+ 9 - 0
utils/auth.js

@@ -8,6 +8,11 @@ export function getUserInfo() {
   return uni.getStorageSync('userInfo')
 }
 
+//用户名,密码
+export function getLoginInfo() {
+  return uni.getStorageSync('loginInfo')
+}
+
 export function setSession(session) {
   return uni.setStorageSync(SessionKey, session)
 }
@@ -15,3 +20,7 @@ export function setSession(session) {
 export function removeSession() {
   return uni.removeStorageSync(SessionKey)
 }
+
+
+
+

+ 2 - 1
utils/request.js

@@ -3,6 +3,7 @@ import config from '@/config'
 import { getSession } from '@/utils/auth'
 import errorCode from '@/utils/errorCode'
 import { toast, showConfirm, tansParams } from '@/utils/common'
+import $modal from '@/plugins/modal.js'
 
 let timeout = config.timeout
 const baseUrl = config.baseUrl
@@ -15,7 +16,7 @@ const request = config => {
     if (getSession()) {
       config.header['cookie'] = 'JSESSIONID=' + getSession()
     } else {
-      showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?')
+      $modal.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录?')
         .then(() => {
           uni.reLaunch({ url: '/pages/login' })
         })

+ 23 - 1
utils/ygoa.js

@@ -1,5 +1,9 @@
-export function convertToChineseCurrency(amount) {
+import { getUserInfo,getLoginInfo } from '@/utils/auth'
+import { useUserStore } from '@/store/user';
+import $modal from '@/plugins/modal.js'
+const userStore=useUserStore();
 
+export function convertToChineseCurrency(amount) {
     if (amount === "0" || amount === 0) {
         return "零元整";
     }
@@ -57,4 +61,22 @@ export function convertToChineseCurrency(amount) {
     }
 
     return integerResult + decimalResult;
+}
+
+export function clearCache() {
+	$modal.confirm('是否确定要清理缓存?').then(res=>{
+		const userInfo = getUserInfo();
+		const loginInfo=getLoginInfo();
+		uni.clearStorageSync();
+		uni.setStorageSync('userInfo', userInfo)
+		uni.setStorageSync('loginInfo', loginInfo)
+		userStore.user = userInfo
+		userStore.useId = userInfo.useId
+		// 提示用户缓存清理成功
+		uni.showToast({
+			title: '缓存清理成功',
+			icon: 'success',
+			duration: 2000
+		});
+	})
 }