import store from "@/store" // 是否拥有管理员角色权限 export function hasRole() { const roleFlag = ["admin", "sysAdmin"] // 管理员的角色字符 const roles = store.getters && store.getters.roles console.log(roles) const isHasRole = roles.some(role => { return roleFlag.includes(role) }) return isHasRole } // 将报警类型转换为汉字 export function convertToKanji(row) { if (row.data && row.data.items && row.data.items.wt) { let { wt } = row.data.items wt = Number(wt.value) if (wt === 0) { return "无" } else if (wt === 1) { return "电机堵转" } else if (wt === 2) { return "角度故障" } else if (wt === 3) { return "低电量禁止控制" } else if (wt === 4) { return "电机初始化未完成" } else if (wt === 5) { return "压力1故障" } else if (wt === 6) { return "压力2故障" } else { return wt.value ? wt.value + "(未知错误)" : "(未知错误)" } } else { return "/" } } // 电量、温度、压力一、压力二 export function showValueFn(row, type) { if (row.data && row.data.items && row.data.items.adcProperty) { let { bb, t, pp1, pp2 } = row.data.items.adcProperty if (type === 1) { return parseInt(bb) > 100 ? 100 : parseInt(bb) } if (type === 2) { return t } if (type === 3) { return pp1 } if (type === 4) { return pp2 } } else { return "" } } export function getYMDHMS(timestamp) { let date = new Date(parseInt(timestamp)) let Year = date.getFullYear() let Moth = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1 let Day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate() let Hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours() let Minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes() let Sechond = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds() let GMT = Year + "-" + Moth + "-" + Day + " " + Hour + ":" + Minute + ":" + Sechond return GMT } const warningTypeText = { "valve": [ "电机堵转", "角度故障", "低电量禁止控制", "电机初始化未完成", "压力1故障", "压力2故障", ], "flapValve": [ "电机堵转", "低电量禁止控制", "压力故障" ] }; export function getWarningTypeText(row) { let wtText = ""; let controllable = true; if (row.data && row.data.items && row.data.items.wt) { let { wt } = row.data.items; let wtArray = Number(wt.value).toString(2).split('').map(Number); wtArray.reverse(); let wtTextArr = []; if (row.deviceValve) { wtTextArr = warningTypeText.valve; if (wtArray.length > 2 && wtArray[2] === 1) { controllable = false; } } else if (row.deviceFlapValve) { wtTextArr = warningTypeText.flapValve; if (wtArray.length > 1 && wtArray[1] === 1) { controllable = false; } } for (var i = 0; i < wtArray.length; i++) { if (wtArray[i] === 1) { if (wtTextArr.length > i) { if (wtText == "") { wtText = wtTextArr[i]; } else { wtText += "," + wtTextArr[i]; } } else { wtText += "未知故障"; break; } } }; } return { controllable: controllable, text: wtText || "/" }; }