Files
dvcp_v2_webapp/examples/utils/index.js
aixianling a8dff862d2 初始化
2021-12-14 18:36:19 +08:00

80 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}
/**
* @param { function } func
* @param { number } wait 延迟执行毫秒数
* @param { boolean } immediate true 表立即执行false 表非立即执行
*/
export default {
...tools,
addChildParty,
$confirm,
$permissions,
$decimalCalc
}