1122
This commit is contained in:
8
cdTMP/src/directives/auth/auth.js
Normal file
8
cdTMP/src/directives/auth/auth.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import { useUserStore } from "@/store"
|
||||
|
||||
const auth = (name) => {
|
||||
const userStore = useUserStore()
|
||||
return (userStore.codes && userStore.codes.includes(name)) || (userStore.codes && userStore.codes.includes("*"))
|
||||
}
|
||||
|
||||
export default auth
|
||||
29
cdTMP/src/directives/auth/index.js
Normal file
29
cdTMP/src/directives/auth/index.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import auth from "./auth"
|
||||
|
||||
const checkAuth = (el, binding) => {
|
||||
const { value } = binding
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
if (value.length > 0) {
|
||||
let isHas = false
|
||||
value.map((item) => {
|
||||
isHas = auth(item)
|
||||
})
|
||||
|
||||
if (!isHas && el.parentNode) {
|
||||
el.parentNode.removeChild(el)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new Error(`need permission! Like v-auth="['admin','user']"`)
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
mounted(el, binding) {
|
||||
checkAuth(el, binding)
|
||||
},
|
||||
updated(el, binding) {
|
||||
checkAuth(el, binding)
|
||||
}
|
||||
}
|
||||
27
cdTMP/src/directives/copy/index.js
Normal file
27
cdTMP/src/directives/copy/index.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import useClipboard from "vue-clipboard3"
|
||||
import { Message } from "@arco-design/web-vue"
|
||||
|
||||
const copy = (el, binding) => {
|
||||
const { value } = binding
|
||||
el.addEventListener("click", async () => {
|
||||
if (value && value !== "") {
|
||||
try {
|
||||
await useClipboard().toClipboard(value)
|
||||
Message.success("已成功复制到剪切板")
|
||||
} catch (e) {
|
||||
Message.error("复制失败")
|
||||
}
|
||||
} else {
|
||||
throw new Error(`need for copy content! Like v-copy="Hello World"`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
mounted(el, binding) {
|
||||
copy(el, binding)
|
||||
},
|
||||
updated(el, binding) {
|
||||
copy(el, binding)
|
||||
}
|
||||
}
|
||||
11
cdTMP/src/directives/index.js
Normal file
11
cdTMP/src/directives/index.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import auth from "./auth/index"
|
||||
import role from "./role/index"
|
||||
import copy from "./copy/index"
|
||||
|
||||
export default {
|
||||
install(Vue) {
|
||||
Vue.directive("auth", auth)
|
||||
Vue.directive("role", role)
|
||||
Vue.directive("copy", copy)
|
||||
}
|
||||
}
|
||||
29
cdTMP/src/directives/role/index.js
Normal file
29
cdTMP/src/directives/role/index.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import role from "./role"
|
||||
|
||||
const checkRole = (el, binding) => {
|
||||
const { value } = binding
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
if (value.length > 0) {
|
||||
let isHas = false
|
||||
value.map((item) => {
|
||||
isHas = role(item)
|
||||
})
|
||||
|
||||
if (!isHas && el.parentNode) {
|
||||
el.parentNode.removeChild(el)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new Error(`need role! Like v-role="['seo', 'cfo']"`)
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
mounted(el, binding) {
|
||||
checkRole(el, binding)
|
||||
},
|
||||
updated(el, binding) {
|
||||
checkRole(el, binding)
|
||||
}
|
||||
}
|
||||
11
cdTMP/src/directives/role/role.js
Normal file
11
cdTMP/src/directives/role/role.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useUserStore } from "@/store"
|
||||
|
||||
const role = (name) => {
|
||||
const userStore = useUserStore()
|
||||
return (
|
||||
(userStore.roles && userStore.roles.includes(name)) ||
|
||||
(userStore.roles && userStore.roles.includes("superAdmin"))
|
||||
)
|
||||
}
|
||||
|
||||
export default role
|
||||
Reference in New Issue
Block a user