| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- import { message } from 'ant-design-vue';
- import { create, all } from 'mathjs'
- import { useAuthStore } from "@/stores/modules/auth";
- const config = {
- number: 'BigNumber',
- precision: 20
- }
- const math = create(all, config)
- let time = null
- export default {
- // 检查权限是否存在
- hasPermission (permission) {
- let hasPermission = true
- let appData = JSON.parse(sessionStorage.getItem('app'))
- let auth = appData.meta.auth
- hasPermission = auth.some(item=>item.option == permission)
- return hasPermission
- },
- // 获取应用表格
- TBLayout (appname) {
- try {
- // 获取应用数据
- let apps = JSON.parse(sessionStorage.getItem('app'))
- // 获取当前应用表格数据
- let tablecols = apps.meta.tables[appname].tablecols.map(e=>{
- return {
- title:e.title,
- filter:e.filter,
- dataIndex:e.columnname,
- width:e.width == 0?'150':e.width,
- ellipsis:true,
- fixed:e.columnname == 'operation'?'right':''
- }
- })
- return tablecols
- } catch (error) {
- console.log(error,'tool')
- }
- },
- // 验证按钮状态
- isDisabled (status,arr,fn) {
- let rs = false
- if (fn) return fn
- rs = arr.some(item=>item == status)
- return rs
- },
- // 数据消息提醒
-
- message (res,msg,fn) {
- if (res.code === 1) {
- msg ? message.success({content:msg,key:1}) : ''
- if(time !== null){
- clearTimeout(time);
- }
- time = setTimeout(() => {
- fn ? fn() : ''
- },500)
- } else {
- message.error({content:res.data + ':' + res.msg,key:1})
- }
- },
- // 金额格式化
- formatAmount(amount, decimalDigits = 0) {
- const { hiddenSensitiveFields } = useAuthStore()
- if (hiddenSensitiveFields) return '****'
- let amt = math.format(amount, {notation: 'fixed',precision: 2})
- const amountStr = String(amt)
- const reg = /\B(?=(?:\d{3})+$)/g
- // 是否是小数
- const isDecimal = amountStr.indexOf('.') > -1
- if (isDecimal) {
- // 整数部分
- const integerPart = amountStr.substring(0, amountStr.indexOf('.'))
- // 小数部分
- const decimalPart = amountStr.substring(amountStr.length, amountStr.indexOf('.'))
- return `${integerPart.replace(reg, ',')}${decimalPart}`
- } else {
- return amountStr.replace(reg, ',')
- }
- },
- // 验证数字输入框手动输入的值是否合法
- validateInputNumber (start,value,step) {
- return new Promise((reslove,reject)=>{
- if ((value * 100 - start * 100) % (step * 100) === 0) {
- reslove(value)
- } else {
- message.error(value?`输入的值${value}不符合规则,已修正!`:`输入的值不能为空!`);
- let val = value - ((value - start) % step)
- reslove(val)
- }
- })
- },
- // 设置状态颜色
- statusAndColor(status) {
- let statusArr = [
- {st:'新建',cl:"#1890ff"},
- {st:'提交',cl:'#646cff'},
- {st:'审核',cl:'#ff5656'},
- {st:'关闭',cl:'#acbdc5'},
- {st:'预提交',cl:'#005792'},
- {st:'确认',cl:'#01352c'},
- {st:'复核',cl:'#ff9234'},
- {st:'启用',cl:"#1890ff"},
- {st:'停用',cl:'#acbdc5'},
- ]
- if (statusArr.find(e=>e.st == status)) {
- return statusArr.find(e=>e.st == status).cl
- } else {
- return '#333'
- }
-
- },
-
- }
|