// src/directives/model-permission.js export default { inserted(el, binding) { // 从sessionStorage获取设备型号 let publicConfig = sessionStorage.getItem('publicConfig') let { model } = publicConfig ? JSON.parse(publicConfig) : {} const { value } = binding if (!value) return // 没有配置权限,默认显示 if (Array.isArray(value)) { // 允许的型号列表 if (!value.includes(model)) { el.parentNode?.removeChild(el) } } else if (typeof value === 'string') { // 单个允许的型号 if (model !== value) { el.parentNode?.removeChild(el) } } else if (typeof value === 'object') { // 复杂配置:{ allow: [], deny: [] } const { allow, deny } = value if (allow && !allow.includes(model)) { el.parentNode?.removeChild(el) } if (deny && deny.includes(model)) { el.parentNode?.removeChild(el) } } }, // update(el, binding) { // const { value, oldValue } = binding // if (value !== oldValue) { // const elClone = el.cloneNode(true) // el.parentNode?.replaceChild(elClone, el) // this.inserted(elClone, binding) // } // } }