Zlpt_Portal/src/utils/directive/authBtn.ts

27 lines
663 B
TypeScript
Raw Normal View History

2023-12-09 22:29:54 +08:00
import { ElMessage } from "element-plus"
2023-12-10 01:43:50 +08:00
import { mainStore } from 'store/main'
2023-12-09 22:29:54 +08:00
import router from "@/router"
export default function (app: any) {
app.directive("authBtn", {
mounted(el: any, binding: any, vnode: any) {
console.log("binding", binding.value)
2023-12-10 01:43:50 +08:00
const store = mainStore()
2023-12-09 22:29:54 +08:00
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);
})
2023-12-10 01:43:50 +08:00
} else {
2023-12-09 22:29:54 +08:00
el.addEventListener("click", binding.value())
}
}
})
}