- 工作台新增近 7 日预约趋势与订单状态分布图 - 订单/用户/就诊人/陪诊师支持 CSV 导出,逐页拉取规避接口分页上限 - 订单列表增加状态快筛、筛选条件同步地址栏、加载失败重试 - 订单详情支持指派/更换陪诊师,性别值归一到订单枚举 - 用户列表支持批量锁定/解锁,导出补齐就诊人数量与归属信息 - 抽取 useTableQuery 统一分页、搜索与删除后页码回退 - ESLint 开启 vue/no-undef-properties,修复 EChart 扩展只注册一次的问题
58 lines
1.2 KiB
TypeScript
58 lines
1.2 KiB
TypeScript
import { computed, ref } from 'vue'
|
|
import { useRouter } from 'vue-router'
|
|
|
|
export const useAuth = () => {
|
|
const router = useRouter()
|
|
|
|
const loading = ref(false)
|
|
const error = ref<string | null>(null)
|
|
|
|
const dummyUser = {
|
|
email: 'admin@example.com',
|
|
password: 'password',
|
|
token: 'auth-token',
|
|
}
|
|
|
|
const login = (email: string, password: string) => {
|
|
try {
|
|
loading.value = true
|
|
error.value = null
|
|
|
|
if (email === dummyUser.email && password === dummyUser.password) {
|
|
if (typeof window !== 'undefined') {
|
|
sessionStorage.setItem('token', dummyUser.token)
|
|
}
|
|
router.replace('/')
|
|
} else {
|
|
throw new Error('Invalid email or password')
|
|
}
|
|
} catch (err) {
|
|
error.value = err instanceof Error ? err.message : '登录失败'
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
const logout = () => {
|
|
if (typeof window !== 'undefined') {
|
|
sessionStorage.removeItem('token')
|
|
}
|
|
router.replace('/auth/sign-in')
|
|
}
|
|
|
|
const isAuthenticated = computed(() => {
|
|
if (typeof window !== 'undefined') {
|
|
return !!sessionStorage.getItem('token')
|
|
}
|
|
return false
|
|
})
|
|
|
|
return {
|
|
login,
|
|
logout,
|
|
isAuthenticated,
|
|
loading,
|
|
error,
|
|
}
|
|
}
|