| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- import { message } from 'ant-design-vue';
- import { create, all } from 'mathjs'
- import { useAuthStore } from "@/stores/modules/auth";
- import { useBaseStore } from '@/stores/modules/base'
- import {nextTick} from 'vue'
- import router from "@/router/index";
- const config = {
- number: 'BigNumber',
- precision: 20
- }
- const math = create(all, config)
- let time = null
- const hide = null
- let questArray = [];
- export default {
- // 判断应用是否授权
- hasAuth (app) {
- if (!app) {
- return false
- } else {
- return true
- }
-
- },
- // 检查权限是否存在
- hasPermission (permission) {
- let hasPermission = true
- const store = useAuthStore()
- let appData = store.app
- let auth = appData.meta.auth
- if (appData.meta.auth) {
- hasPermission = auth.some(item=>item.option == permission)
- return hasPermission
- }
-
- },
- // 获取应用表格
- TBLayout (tablename,i) {
- try {
- // 获取应用数据
- const store = useAuthStore()
- const hideAmount = store.hiddenSensitiveFields
- let apps = store.app
- // 获取当前应用表格数据
- if (apps.meta.tables[tablename]) {
- let tablecols = apps.meta.tables[tablename].tablecols.map(e=>{
- return {
- title:e.title,
- filter:e.filter,
- sortable:e.sortable,
- dataIndex:e.columnname,
- sort:0,
- align:e.align?e.align:'left',
- width:e.width == 0?'150':e.width,
- fixed:e.freezetype ? e.freezetype !== '' ? e.freezetype : false:false,
- fn:e.script !=='' ? (data,dataIndex)=>{
-
- try {
- let func = new Function('data','hideAmount',e.script);
- return func(data,hideAmount); // 输出1
- } catch (error) {
- console.log(error)
- }
-
- }:null,
- ellipsis:true
- }
- })
- return tablecols
- }
-
- } catch (error) {
- console.log(error,'tool')
- }
- },
- // 获取表头及表单配置
- FormLayout (name,data) {
- var that = this
- /** 验证数据格式类型 */
- let checkType = (dataformat,value)=>{
- if (dataformat && dataformat.type && dataformat.type !== '' && dataformat.type !== 'none') {
- switch (dataformat.type) {
- case 'number':
- return that.formatAmount(value)
- break;
- case 'mapping':
- dataformat.mapping.some(e=>{
- if (value == e.value) {
- value = e.label
- }
- })
- return value
- break;
- default:
- break;
- }
- } else {
- return value
- }
- }
- try {
- // 获取应用数据
- const store = useAuthStore()
- let apps = store.app
- // 获取当前应用表格数据
- if (apps.meta.forms[name]) {
- let formlat = apps.meta.forms[name].formcols.map(e=>{
- return {
- label:e.title,
- value:checkType(e.dataformat,data[e.columnname]),
- key:e.columnname,
- span:e.span,
- style:e.script !=='' ? ()=>{
- try {
- let func = new Function('data','that',e.script);
- return func(data,that); // 输出1
- } catch (error) {
- console.log(error)
- }
-
- }:null,
- }
- })
- return formlat
- }
-
- } catch (error) {
- console.log(error,'tool')
- }
- },
- TBLayoutID (appname) {
- try {
- // 获取应用数据
- const store = useAuthStore()
- let apps = store.app
- // 获取当前应用表格数据
- if (apps.meta.tables[appname]) {
- let id = apps.meta.tables[appname].tableid
- return id
- }
- } catch (error) {
- console.log(error,'tool')
- }
- },
- // 判断参数隐藏
- hideFields (name,key) {
- try {
- const store = useAuthStore()
- let appData = store.app
- let keyArray = appData.meta.forms[name]
- let isShow = keyArray.formcols.some(e=>key == e.columnname)
- return isShow
- } catch (error) {
-
- }
-
- },
- // 验证按钮状态
- 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) return false
- if (res.code === 1) {
- msg ? message.success({content:msg,key:1}) : ''
- if(time !== null){
- clearTimeout(time);
- }
- time = setTimeout(() => {
- fn ? fn() : ''
- },500)
- } else {
- console.log(res)
- message.error({content:res.data + ':' + res.msg,key:1})
- }
- },
- // 金额格式化
- formatAmount(amount, data) {
- console.log(data)
- if (data && !this.hideFields(data.name,data.key)) return '****'
- let amt = math.format(Number(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)=>{
- console.log(start,value)
- if (!value) return reslove(start)
- 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:"#1677ff"},
- {st:'提交',cl:'#646cff'},
- {st:'审核',cl:'#ff5656'},
- {st:'关闭',cl:'#acbdc5'},
- {st:'预提交',cl:'#005792'},
- {st:'确认',cl:'#01352c'},
- {st:'复核',cl:'#ff9234'},
- {st:'启用',cl:"#1890ff"},
- {st:'停用',cl:'#acbdc5'},
- {st:'发布',cl:'#52c41a'},
- ]
- if (statusArr.find(e=>e.st == status)) {
- return statusArr.find(e=>e.st == status).cl
- } else {
- return '#333'
- }
-
- },
- // 接口防抖
- questArray,
- anti_shake (config, axios) {
- const now_date = new Date().getTime();
-
- const request_info = JSON.parse(sessionStorage.getItem("request_url"));
- sessionStorage.setItem(
- "request_url",
- JSON.stringify({ url: config.type, time: new Date().getTime() })
- );
-
- if (request_info === null) return true;
- if (config.type == 'post') {
- useBaseStore().canPointer = false
- }
- //存储请求队列,判断post请求是否为重复的请求
- if (config.data.id) {
- questArray.push(Number(config.data.id))
- }
- if (now_date - request_info.time < 500 && config.type == 'post') {
- let cancel;
- config.cancelToken = new axios.CancelToken((c) => {
- cancel = c;
- });
- message.error({content:'请求过于频繁,请稍后再试!',duration:1,key:1});
- useBaseStore().canPointer = true
- cancel(`${config.url}请求被中断`);
-
- return false;
- } else {
- return true;
- }
- },
- messageLoading: {
- hide:()=>{
- message.loading({content:'操作正在执行,请稍等..',duration:10,});
- }
- },
- date:{
- yearStart:`${(new Date).getFullYear()-1}-01-01`,
- yearEnd:`${(new Date).getFullYear()}-12-31`,
- }
- }
|