Skip to content

Commit

Permalink
chore(完善框架): 完善框架
Browse files Browse the repository at this point in the history
完善框架
  • Loading branch information
jianfengtheboy committed Aug 19, 2024
1 parent 56bcd0d commit 67354e0
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 28 deletions.
2 changes: 0 additions & 2 deletions src/layout/LayoutDefault.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import SideBar from './components/SideBar/index.vue'
import HeaderBar from './components/HeaderBar/index.vue'
import TabBar from './components/TabBar/index.vue'
import Main from './components/Main/index.vue'
defineOptions({ name: 'Layout' })
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const constantRoutes: RouteRecordRaw[] = [
{
path: '/home',
component: () => import('@/views/main/home/index.vue'),
name: 'Home',
name: 'HomeIndex',
meta: {
title: '首页',
icon: 'icon-dashboard',
Expand Down
8 changes: 4 additions & 4 deletions src/store/modules/base/app.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { resetRouter } from '@/router'
import { setToken, clearToken } from '@/utils/auth'
import { getToken, setToken, clearToken } from '@/utils/auth'
import { resetHasRouteFlag } from '@/router/permission'
import request from '@/request'
import { AppStoreName } from '@/config/domain'
import { IUserInfo } from '@/model/user'

interface IState {
// token
token: string
token: string | null
// 用户信息
userInfo: Pick<IUserInfo, 'id' | 'userName' | 'nickName' | 'avatar' | 'gender'>
// 角色
Expand All @@ -18,13 +18,13 @@ interface IState {

export const useAppStore = defineStore('app', {
state: (): IState => ({
token: '',
token: getToken(),
userInfo: {
id: '',
userName: '',
nickName: '',
avatar: '',
gender: 0
gender: 3
},
roles: [],
permissions: []
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/base/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const storeSetup = () => {
export const useRouteStore = defineStore('route', storeSetup, {
persist: {
key: `${AppStoreName}_ROUTE`,
paths: ['routes'],
paths: ['routes', 'asyncRoutes'],
storage: localStorage
}
})
14 changes: 6 additions & 8 deletions src/views/common/error/components/errorPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,30 @@ const props = withDefaults(defineProps<IProps>(), {
code: 403
})
const router = useRouter()
const countDownTime = ref(5)
let timer = ref()
onMounted(() => {
onCountDownTime()
})
onBeforeUnmount(() => {
clearInterval(timer.value)
clearInterval(timer)
})
// 返回页面
const router = useRouter()
const back = () => {
router.replace({ path: '/' })
}
// 倒计时
const countDownTime = ref(5)
let timer: NodeJS.Timer
const onCountDownTime = () => {
timer.value = setInterval(() => {
timer = setInterval(() => {
if (countDownTime.value) {
countDownTime.value--
} else {
back()
clearInterval(timer.value)
clearInterval(timer)
}
}, 1000)
}
Expand Down
5 changes: 1 addition & 4 deletions src/views/common/redirect/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ const router = useRouter()
const { params, query } = route
const { path } = params
router.replace({
path: '/' + path,
query,
})
router.replace({ path: `/${path}`, query })
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion src/views/public/login/components/cornerBottom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ interface Props {
withDefaults(defineProps<Props>(), {
startColor: '#28aff0',
endColor: '#120fc4',
endColor: '#120fc4'
})
</script>
4 changes: 1 addition & 3 deletions src/views/public/login/components/cornerTop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ interface Props {
withDefaults(defineProps<Props>(), {
startColor: '#28aff0',
endColor: '#120fc4',
endColor: '#120fc4'
})
</script>

<style scoped></style>
12 changes: 8 additions & 4 deletions src/views/public/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Cookies from 'js-cookie'
import { useAppStore } from '@/store'
import { useLoading, useDevice } from '@/hooks'
import { SystemName, AppStoreName } from '@/config/domain'
import * as Regexp from '@/utils/regexp'
import LoginBg from './components/index.vue'
import loginImg from '@/assets/images/login/login-img.svg'
Expand All @@ -22,7 +23,10 @@ const formData = reactive({
})
const formRules: FormInstance['rules'] = {
username: [{ required: true, message: '请输入账号' }],
password: [{ required: true, message: '请输入密码' }],
password: [
{ required: true, message: '请输入密码' },
{ match: Regexp.Code_6, message: '密码格式不正确' }
],
code: [{ required: true, message: '请输入验证码' }]
}
Expand Down Expand Up @@ -57,8 +61,8 @@ const errorMessage = ref('')
const formRef = ref<FormInstance>()
const handleLogin = async () => {
try {
const flag = await formRef.value?.validate()
if (flag) return
const valid = await formRef.value?.validate()
if (valid) return
setLoading(true)
const params = window.$_.cloneDeep(formData)
Expand All @@ -73,7 +77,7 @@ const handleLogin = async () => {
})
Message.success('登录成功')
} catch (error) {
errorMessage.value = error as string
errorMessage.value = (error as Error).message
setTimeout(() => {
loadCaptcha()
}, 500)
Expand Down

0 comments on commit 67354e0

Please sign in to comment.