//两组数据对比是否有相同属性,生成新的对象
const obj = {
viewLimits: 'VIEW_LIMITS', //查看权限
shareLimits: 'SHARE_LIMITS', //分享权限
downloadLimits: 'DOWNLOAD_LIMITS', //下载权限,
clickLimits: 'CLICK_LIMITS', //点击权限
};
const list = ['VIEW_LIMITS', 'SHARE_LIMITS', 'DOWNLOAD_LIMITS', 'COPY_LIMITS'];
export const limitsObj = (list = []) => {
return Object.keys(obj).reduce((acc, cur) => {
acc[cur] = list?.includes(obj[cur]) ? true : false;
console.log(acc, 'hhhhhhhh'); //{downloadLimits: true,shareLimits: true,viewLimits: true,clickLimits: false}
return acc;
}, {});
};
limitsObj(list);