import {MessageBox} from 'element-ui' import store from '../store' import tools from 'dvcp-ui/lib/js/utils' const addChildParty = (parent, pending) => { let doBeforeCount = pending.length parent["children"] = parent["children"] || [] pending.map((e, index, arr) => { if (e.partyOrgParentId == parent.partyOrgId) { parent.children.push(e) arr.splice(index, 1) addChildParty(parent, arr) } }) if (parent.children.length == 0) { delete parent.children } if (pending.length > 0 && doBeforeCount > pending.length) { parent.children.map(c => addChildParty(c, pending)) } } /** * 封装提示框 */ const $confirm = (content, options) => { return MessageBox.confirm(content, { type: "warning", confirmButtonText: "确认", center: true, title: "提示", dangerouslyUseHTMLString: true, ...options }) } /** * 封装权限判断方法 */ const $permissions = flag => { const buttons = store.state.user.info.buttons if (buttons) return buttons.some(b => b.id == flag || b.permission == flag) else return false } const $decimalCalc = (...arr) => { //确认提升精度 let decimalLengthes = arr.map(e => { let index = ("" + e).indexOf(".") return ("" + e).length - index }) let maxDecimal = Math.max(...decimalLengthes), precision = Math.pow(10, maxDecimal) //计算 let intArr = arr.map(e => (Number(e) || 0) * precision) //返回计算值 return intArr.reduce((t, a) => t + a) / precision } export const waiting = { init(ops, count) { if (document.body) { let div = document.createElement('div') div.id = "ai-waiting" div.className = "el-loading-mask is-fullscreen" div.style.zIndex = '202204271710' div.style.textAlign = 'center' div.style.lineHeight = '100vh' div.style.color = '#26f' div.style.background = 'rgba(0,0,0,.8)' document.body.appendChild(div) } else if (count < 10) { setTimeout(() => this.init(ops, ++count), 500) } }, getDom() { return document.querySelector('#ai-waiting') }, setContent(html) { let div = this.getDom() div.innerHTML = html }, close() { let div = this.getDom() div.parentElement.removeChild(div) } } export default { ...tools, addChildParty, $confirm, $permissions, $decimalCalc, $waiting: waiting }