AppUtils.js 3.3 KB
Newer Older
L
lepdou 已提交
1
appUtil.service('AppUtil', ['toastr', '$window', function (toastr, $window) {
L
lepdou 已提交
2

L
abtest  
lepdou 已提交
3 4 5 6 7 8 9 10 11 12
    function parseErrorMsg(response) {
        if (response.status == -1) {
            return "您的登录信息已过期,请刷新页面后重试";
        }
        var msg = "Code:" + response.status;
        if (response.data.message != null) {
            msg += " Msg:" + response.data.message;
        }
        return msg;
    }
L
lepdou 已提交
13
    return {
L
abtest  
lepdou 已提交
14 15 16 17
        errorMsg: parseErrorMsg,
        
        showErrorMsg: function (response, title) {
            toastr.error(parseErrorMsg(response), title);
L
lepdou 已提交
18
        },
L
lepdou 已提交
19 20 21 22 23 24 25 26
        parseParams: function (query, notJumpToHomePage) {
            if (!query) {
                //如果不传这个参数或者false则返回到首页(参数出错)
                if (!notJumpToHomePage) {
                    $window.location.href = '/index.html';
                } else {
                    return {};
                }
L
lepdou 已提交
27
            }
L
lepdou 已提交
28 29
            if (query.indexOf('/') == 0) {
                query = query.substring(1, query.length);
L
lepdou 已提交
30
            }
L
lepdou 已提交
31 32 33 34 35 36

            var anchorIndex = query.indexOf('#');
            if (anchorIndex >= 0) {
                query = query.substring(0, anchorIndex);
            }

L
lepdou 已提交
37
            var params = query.split("&");
L
lepdou 已提交
38 39 40 41 42 43
            var result = {};
            params.forEach(function (param) {
                var kv = param.split("=");
                result[kv[0]] = kv[1];
            });
            return result;
L
lepdou 已提交
44 45 46 47
        },
        collectData: function (response) {
            var data = [];
            response.entities.forEach(function (entity) {
48
                if (entity.code == 200) {
L
lepdou 已提交
49
                    data.push(entity.body);
50
                } else {
L
lepdou 已提交
51 52
                    toastr.warning(entity.message);
                }
53
            });
L
lepdou 已提交
54
            return data;
L
abtest  
lepdou 已提交
55 56 57 58 59 60 61 62 63
        },
        showModal: function (modal) {
            $(modal).modal("show");
        },
        hideModal: function (modal) {
            $(modal).modal("hide");
        },
        checkIPV4:function (ip) {
            return /^(([0-9]|[1-9][0-9]|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