初定登记项目版本 import type { Directive } from 'vue'; import imgNoPermission from '../assets/images/noPermission-bg.png'; const hasPermissionDirective: Directive = { mounted(el, binding) { if (binding.value === undefined) return; const arr = ['测试1']; const permission = binding.value[1]; const type = binding.value[0] as string; // 类型 按钮 组件 if (!arr.includes(permission) && type === 'button') { el.style.display = 'none'; el.parentNode.removeChild(el); console.log(binding); } if (!arr.includes(permission) && type === 'module') { el.style.display = 'flex'; el.style.flexDirection = 'column'; el.style.justifyContent = 'center'; el.style.alignItems = 'center'; el.innerHTML = ''; const img = document.createElement('img'); img.src = imgNoPermission; img.style.height = '50%'; img.style.maxHeight = '200px'; el.appendChild(img); const textSpan = document.createElement('div'); textSpan.innerText = '暂无权限,请申请开通'; textSpan.style.color = '#394D73'; textSpan.style.fontSize = '14px'; textSpan.style.paddingTop = '8px'; el.appendChild(textSpan); } }, }; export default hasPermissionDirective;
|