cmvr-wms/ruoyi-ui-vue3/src/utils/notice-html.js
lixiaolong 89c962223a feat(warehouse): 优化采购报价权限控制和文件管理功能
- 实现基于角色的采购报价权限检查,仅超级管理员和采购经理角色可查看报价
- 替换原有的仓库采购管理权限检查为新的报价权限函数
- 在采购单据组件中更新报价字段显示权限逻辑
- 集成文件管理功能,支持文档附件上传下载
- 添加移动端应用更新提示和发布功能
- 增强采购历史更正服务的安全访问控制
- 重构报价访问工具类以支持细粒度字段过滤
- 添加单元测试验证新的权限控制逻辑
2026-10-29 09:58:51 +08:00

26 lines
2.2 KiB
JavaScript

import createDOMPurify from 'dompurify'
const purifier=createDOMPurify(window)
const quillClass=/^ql-(?:align-(?:center|right|justify)|direction-rtl|indent-[1-8]|size-(?:small|large|huge)|font-(?:serif|monospace)|syntax|ui)$/
const color=/^(?:#[\da-f]{3,8}|[a-z]+|(?:rgb|hsl)a?\([\d.,%\s]+\))$/i
function safeStyle(value){
const source=document.createElement('span').style;source.cssText=value
const target=document.createElement('span').style
for(const name of ['color','background-color']){const v=source.getPropertyValue(name);if(color.test(v))target.setProperty(name,v)}
const align=source.getPropertyValue('text-align');if(/^(left|right|center|justify)$/.test(align))target.textAlign=align
const size=source.getPropertyValue('font-size'),match=size.match(/^(\d+(?:\.\d+)?)(px|pt|em|rem|%)$/)
if(match){const n=Number(match[1]),unit=match[2],bounds=unit==='em'||unit==='rem'?[.5,4]:unit==='%'?[50,300]:[8,72];if(n>=bounds[0]&&n<=bounds[1])target.fontSize=size}
return target.cssText
}
purifier.addHook('uponSanitizeAttribute',(_node,data)=>{
if(data.attrName==='style'){data.attrValue=safeStyle(data.attrValue);if(!data.attrValue)data.keepAttr=false}
if(data.attrName==='class'){data.attrValue=data.attrValue.split(/\s+/).filter(name=>quillClass.test(name)).join(' ');if(!data.attrValue)data.keepAttr=false}
})
purifier.addHook('afterSanitizeAttributes',node=>{if(node.tagName==='A'&&node.hasAttribute('href')){node.setAttribute('target','_blank');node.setAttribute('rel','noopener noreferrer')}})
/** Keep editor formatting while excluding executable HTML, controls and page-level CSS. */
export function noticeHtml(value){return purifier.sanitize(String(value??''),{
ALLOWED_TAGS:['p','br','div','span','strong','b','em','i','u','s','strike','blockquote','pre','code','h1','h2','h3','h4','h5','h6','ol','ul','li','a','img','table','thead','tbody','tr','th','td','sub','sup','hr'],
ALLOWED_ATTR:['href','target','rel','src','alt','title','class','style','start','value','type','colspan','rowspan','width','height','data-list','data-checked'],
ALLOW_DATA_ATTR:false,ALLOW_ARIA_ATTR:false,FORBID_TAGS:['style','script','iframe','object','embed','form','input','button','textarea','select'],
})}