+
-
@@ -43,6 +48,7 @@
import { login } from '@/api/auth'
import { lStorage } from '@/utils/cache'
import { setToken } from '@/utils/token'
+import { useStorage } from '@vueuse/core'
const title = import.meta.env.VITE_APP_TITLE
@@ -50,16 +56,21 @@ const router = useRouter()
const query = unref(router.currentRoute).query
const loginInfo = ref({
- name: 'admin',
- password: '123456',
+ name: '',
+ password: '',
})
-const localLoginInfo = lStorage.get('loginInfo')
-if (localLoginInfo) {
- loginInfo.value.name = localLoginInfo.name || ''
- loginInfo.value.password = localLoginInfo.password || ''
+initLoginInfo()
+
+function initLoginInfo() {
+ const localLoginInfo = lStorage.get('loginInfo')
+ if (localLoginInfo) {
+ loginInfo.value.name = localLoginInfo.name || ''
+ loginInfo.value.password = localLoginInfo.password || ''
+ }
}
+const isRemember = useStorage('isRemember', false)
async function handleLogin() {
const { name, password } = loginInfo.value
if (!name || !password) {
@@ -71,9 +82,12 @@ async function handleLogin() {
const res = await login({ name, password: password.toString() })
if (res.code === 0) {
$message.success('登录成功')
- lStorage.set('loginInfo', { name, password })
setToken(res.data.token)
-
+ if (isRemember.value) {
+ lStorage.set('loginInfo', { name, password })
+ } else {
+ lStorage.remove('loginInfo')
+ }
if (query.redirect) {
const path = query.redirect
Reflect.deleteProperty(query, 'redirect')