Util

作者: 秀萝卜 | 来源:发表于2021-08-15 14:20 被阅读0次
    import Vue from 'vue'
    
    var loading;
    //js常用函数
    class Util {
        
        static showLoading() {
            loading = Vue.prototype.$loading({
                lock: true,
                text: "拼命加载中",
                // target: '.main_content', //默认为body
                background: "rgba(0, 0, 0, 0.2)"
            });
        }
        static hideLoading() {
            loading.close();
        }
    
        //加减乘除
        static add(arg1, arg2) {
            var r1, r2, m;
            try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 };
            try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 };
            m = Math.pow(10, Math.max(r1, r2));
            return (arg1 * m + arg2 * m) / m;
        }
    
        static sub(arg1, arg2) {
            var r1, r2, m, n;
            try { r1 = arg1.toString().split(".")[1].length; } catch (e) { r1 = 0; }
            try { r2 = arg2.toString().split(".")[1].length; } catch (e) { r2 = 0; }
            m = Math.pow(10, Math.max(r1, r2));
            n = (r1 >= r2) ? r1 : r2;//动态控制精度长度
            return ((arg1 * m - arg2 * m) / m).toFixed(n);
        }
    
        static mul(arg1, arg2) {
            var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
            try { m += s1.split(".")[1].length } catch (e) { };
            try { m += s2.split(".")[1].length } catch (e) { };
            return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
        }
    
        static success = (that, msg) => that.$message({
            message: msg || '成功',
            type: 'success',
        })
        static warning = (that, msg) => that.$message({
            message: msg || '错误',//用户名或密码
            type: 'warning',
        })
        static cancel = (that, msg) => that.$message({
            message: msg || '取消',//用户名或密码
            type: 'info',
        })
    
    };
    
    export default Util
    

    相关文章

      网友评论

          本文标题:Util

          本文链接:https://www.haomeiwen.com/subject/qvzbvltx.html