home.js 3.72 KB
var initApp = function () {
    "use strict";
    var ref = [
        "xn.common",
        "xn.directive.top",
        "xn.service.interceptor",
        "xn.home.filter",
        "xn.home.service",
        "xn.page",
        "ui.bootstrap",
        "xn.directive.form",
        "xn.directive.location",
        "xn.directive.attachment",
        "xn.directive.select",
        "xn.directive.calendar",

        "xn.directive.progressbar",
        "xn.markdown",
        "xn.directive.comment",
        "xn.directive.card",
        "ngSanitize"
    ];
    var app = angular.module("xn", ref);

    //拦截器
    app.config(["$httpProvider", function ($httpProvider) {
        $httpProvider.interceptors.push("httpInterceptor");
    }]);
    // 全局配置 form提交验证
    app.config(["xnValidatorProvider", function (xnValidatorProvider) {
        // 全局配置
        xnValidatorProvider.config({
            blurTrig: false,
            showError: false,
            removeError: false
        });
        xnValidatorProvider.setRules({

        });
    }]);
    app.value("xnConfig",xnConfig);
    app.controller("BodyController", ["$scope","$location","dialogService",
        function ($scope,$location,dialogService) {
            $scope.$on('navShow', function (e, newNavShow) {
                $scope.navShow = newNavShow;
            });
            $scope.$on('subnavShow', function (e, newNavShow) {
                $scope.subnavShow = newNavShow;
            });

            $scope.global = {loadingInit: false};
            $scope.maxPageSize = 5;
            //日期转换函数
            Date.prototype.format = function (format) {
                var o = {
                    "M+": this.getMonth() + 1, //month
                    "d+": this.getDate(),    //day
                    "h+": this.getHours(),   //hour
                    "m+": this.getMinutes(), //minute
                    "s+": this.getSeconds(), //second
                    "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
                    "S": this.getMilliseconds() //millisecond
                };
                if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
                    (this.getFullYear() + "").substr(4 - RegExp.$1.length));
                for (var k in o)if (new RegExp("(" + k + ")").test(format))
                    format = format.replace(RegExp.$1,
                        RegExp.$1.length == 1 ? o[k] :
                            ("00" + o[k]).substr(("" + o[k]).length));
                return format;
            };
            //关闭错误
            $scope.closeAlert = function (index, form) {
                form.splice(index, 1);
            };
            $scope.upFileClick = function () {
                var upImportFileId = document.getElementById("upImportFileId");
                upImportFileId.onchange = function () {
                    var upImportFile;
                    var upImportFileList = upImportFileId.files;
                    var upImportFilename;
                    if (upImportFileList) {
                        upImportFile = upImportFileList[0];
                        upImportFilename = upImportFile.name;
                    } else {
                        upImportFilename = upImportFileId.value;
                    }
                    var str = upImportFilename.substr(upImportFilename.indexOf(".") + 1);
                    if (!(str == "xls" || str == "xlsx" || str == "et")) {
                        $("#upImportFile").val("");
                        dialogService.tip([{"message": "请上传Excel支持的文件(xls,xlsx,et等)!"}]);
                    } else {
                        $("#upImportFile").val(upImportFilename);
                    }
                };
            };

        }]);
};