1. 新增修改密码页面 (my/ChangePassword.vue) - 支持输入旧密码、新密码、确认密码 - 密码验证:至少6位、两次输入一致性校验 - 修改成功后自动清除登录信息并跳转到登录页 2. 新增API接口 (updatePassword) - PUT /sys/profile/password - 参数: oldPassword, newPassword, confirmPassword 3. 更新路由配置 - 新增 /my/change-password 路由 4. 更新我的页面 - 修改密码点击跳转到修改密码页面
140 lines
3.7 KiB
TypeScript
140 lines
3.7 KiB
TypeScript
import { createRouter, createWebHistory } from 'vue-router'
|
||
import { useTenantStore } from '@/stores/tenant'
|
||
|
||
const router = createRouter({
|
||
history: createWebHistory(import.meta.env.BASE_URL),
|
||
routes: [
|
||
{
|
||
path: '/',
|
||
name: 'Home',
|
||
component: () => import('@/views/Home.vue'),
|
||
meta: { title: '首页', requiresAuth: true }
|
||
},
|
||
// 需求工单
|
||
{
|
||
path: '/requirement',
|
||
name: 'RequirementList',
|
||
component: () => import('@/views/requirement/List.vue'),
|
||
meta: { title: '需求工单', requiresAuth: true }
|
||
},
|
||
{
|
||
path: '/requirement/add',
|
||
name: 'RequirementAdd',
|
||
component: () => import('@/views/requirement/Add.vue'),
|
||
meta: { title: '新增需求工单', requiresAuth: true }
|
||
},
|
||
// 支出管理
|
||
{
|
||
path: '/expense',
|
||
name: 'ExpenseList',
|
||
component: () => import('@/views/expense/List.vue'),
|
||
meta: { title: '支出管理', requiresAuth: true }
|
||
},
|
||
{
|
||
path: '/expense/add',
|
||
name: 'ExpenseAdd',
|
||
component: () => import('@/views/expense/Add.vue'),
|
||
meta: { title: '新增支出', requiresAuth: true }
|
||
},
|
||
// 应收款管理
|
||
{
|
||
path: '/receivable',
|
||
name: 'ReceivableList',
|
||
component: () => import('@/views/receivable/List.vue'),
|
||
meta: { title: '应收款管理', requiresAuth: true }
|
||
},
|
||
{
|
||
path: '/receivable/add',
|
||
name: 'ReceivableAdd',
|
||
component: () => import('@/views/receivable/Add.vue'),
|
||
meta: { title: '新增应收款', requiresAuth: true }
|
||
},
|
||
// 项目管理
|
||
{
|
||
path: '/project',
|
||
name: 'ProjectList',
|
||
component: () => import('@/views/project/List.vue'),
|
||
meta: { title: '项目管理', requiresAuth: true }
|
||
},
|
||
{
|
||
path: '/project/add',
|
||
name: 'ProjectAdd',
|
||
component: () => import('@/views/project/Add.vue'),
|
||
meta: { title: '新增项目', requiresAuth: true }
|
||
},
|
||
// 客户管理
|
||
{
|
||
path: '/customer',
|
||
name: 'CustomerList',
|
||
component: () => import('@/views/customer/List.vue'),
|
||
meta: { title: '客户管理', requiresAuth: true }
|
||
},
|
||
{
|
||
path: '/customer/add',
|
||
name: 'CustomerAdd',
|
||
component: () => import('@/views/customer/Add.vue'),
|
||
meta: { title: '新增客户', requiresAuth: true }
|
||
},
|
||
// 我的
|
||
{
|
||
path: '/my',
|
||
name: 'My',
|
||
component: () => import('@/views/my/Index.vue'),
|
||
meta: { title: '我的', requiresAuth: true }
|
||
},
|
||
{
|
||
path: '/my/change-password',
|
||
name: 'ChangePassword',
|
||
component: () => import('@/views/my/ChangePassword.vue'),
|
||
meta: { title: '修改密码', requiresAuth: true }
|
||
},
|
||
// 登录
|
||
{
|
||
path: '/login',
|
||
name: 'Login',
|
||
component: () => import('@/views/Login.vue'),
|
||
meta: { title: '登录', requiresAuth: false }
|
||
}
|
||
]
|
||
})
|
||
|
||
// 路由守卫
|
||
router.beforeEach((to, _from, next) => {
|
||
// 处理租户ID(从URL的query参数获取,如 /login?tid=2)
|
||
const tenantStore = useTenantStore()
|
||
const tidQuery = to.query.tid as string | undefined
|
||
if (tidQuery) {
|
||
tenantStore.setTenantId(tidQuery)
|
||
} else {
|
||
// 如果URL没有tid参数,初始化为默认值(会从localStorage读取或使用默认值1)
|
||
tenantStore.init()
|
||
}
|
||
|
||
// 设置页面标题
|
||
if (to.meta.title) {
|
||
document.title = to.meta.title as string
|
||
}
|
||
|
||
// 检查是否需要登录
|
||
if (to.meta.requiresAuth) {
|
||
const token = localStorage.getItem('token')
|
||
if (!token) {
|
||
next('/login')
|
||
return
|
||
}
|
||
}
|
||
|
||
// 已登录用户不能访问登录页
|
||
if (to.path === '/login') {
|
||
const token = localStorage.getItem('token')
|
||
if (token) {
|
||
next('/')
|
||
return
|
||
}
|
||
}
|
||
|
||
next()
|
||
})
|
||
|
||
export default router
|