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)
- 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
- },
- // 验证按钮状态
- 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(msg) : ''
- fn ? fn() : ''
- } else {
- message.error(res.data + ':' + res.msg);
- }
- },
- // 金额格式化
- formatAmount(amount, decimalDigits = 0) {
- amount = Number(amount)
- 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:"#646cff"},
- {st:'启用',cl:"#1890ff"},
- {st:'停用',cl:'#acbdc5'},
- ]
- if (statusArr.find(e=>e.st == status)) {
- return statusArr.find(e=>e.st == status).cl
- } else {
- return '#333'
- }
-
- },
- // 获取app信息
- getAppData (appName,allsystem) {
- function findAppByName(systems, targetName) {
- let foundApp = null;
- function search(systems) {
- for (let i = 0; i < systems.length; i++) {
- const system = systems[i];
- if (system.modules && system.modules.length > 0) {
- search(system.modules); // 递归调用搜索函数
- }
- if (system.apps) {
- const app = system.apps.find((app) => app.name === targetName);
- if (app) {
- foundApp = app;
- break; // 找到目标 app 后停止搜索
- }
- }
- }
- }
- search(systems);
- return foundApp;
- }
- return findAppByName(allsystem,appName)
- }
- }
|