Zlpt_Portal/src/utils/directive/authBtn.ts

27 lines
659 B
TypeScript
Raw Normal View History

2023-12-09 22:29:54 +08:00
import { ElMessage } from "element-plus"
import { useStore } from 'store/main'
import router from "@/router"
export default function (app: any) {
app.directive("authBtn", {
mounted(el: any, binding: any, vnode: any) {
console.log("binding", binding.value)
const store = useStore()
if (!store.token) {
el.addEventListener("click", () => {
ElMessage({
type: "warning",
2023-12-09 22:32:31 +08:00
message: '暂无访问权限'
2023-12-09 22:29:54 +08:00
})
setTimeout(() => {
router.push('/login')
}, 300);
})
}else{
el.addEventListener("click", binding.value())
}
}
})
}