app //应用入口

directive //自定义指令

require-main //require的主配置文件  存放公共调用的js

service //请求后端数据公有类

controllers所有ctrl文件

|--fun //存放公有ctrl 例如上传逻辑ctrl


require-main.js

requirejs.config({
baseUrl: '/',
paths: {
'jquery': '/lib/jquery/1.9.1/jquery.min',
'angular': '/lib/angular/angular.min',
'angular-file-upload': '/lib/angular/angular-file-upload', 'app': '/js/angular-base/app',
'directive': '/js/angular-base/directive',
'services': '/js/angular-base/services',
'uploadCtrl': '/js/angular-base/controllers/fun/uploadCtrl',
'explainCheckListCtrl': '/js/angular-base/controllers/explainCheckListCtrl',
'storyCheckListCtrl': '/js/angular-base/controllers/storyCheckListCtrl',
'explainOrderListCtrl': '/js/angular-base/controllers/explainOrderListCtrl',
'payOrderListCtrl': '/js/angular-base/controllers/payOrderListCtrl'
},
shim: {
'angular': {
deps: ["jquery"],
exports: 'angular',
},
'angular-file-upload': {
deps: ["angular"],
exports: 'angular-file-upload'
}
}
}); requirejs([
'angular',
'jquery',
'angular-file-upload',
'app',
'services',
'directive',
'uploadCtrl'
], function (angular) {
console.log('angular.bootstrap(document, ["ljkjApp"]); ok !');
angular.bootstrap(document, ["ljkjApp"]);
});

app.js

define(['angular'], function (angular) {
/*
author:zzd
description:angularJs common module
*/
var app = angular.module("ljkjApp", ['angularFileUpload']);
app.value("pageIndex", 1);
app.value("pageSize", 10);
app.constant("configParam", "constant value");
/*
author:zzd
description:config $location request param
*/
app.config(function ($locationProvider) {
$locationProvider.html5Mode({
enabled: true,
rewriteLinks: false
}).hashPrefix('!');
}); return app;
});

service.js

define(['angular', 'app'], function (angular, app) {
/*
author:zzd
description:http request
*/
app.factory('ljkjHttp', function ($http, $log, $q) {
return {
paramData: {
"cmd": "VisitnetWork",
"param": "",
"Name": "",
"function": "",
"languageId": "1",
"downLoadCmd": "{4}",
"timeout": 60000 * 10
},
get: function () {
// the $http API is based on the deferred/promise APIs exposed by the $q service
// so it returns a promise for us by default //避免引用变量重置
var sendParams = angular.copy(this.paramData);
return $http.post("/Handler/YjlyHandler.ashx", sendParams, { timeout: sendParams.timeout, params: sendParams })
.then(function (response) {
if (typeof response.data === 'object') {
switch (response.data.state.toString()) {
case '1'://error info
$log.error(response.data.msg);
$log.error(response.data.ErrorInfo);
break;
case '6'://login invalid
layer.alert(response.data.msg, { icon: 2 }, function (index) {
window.open('/', '_top');
});
break;
}
// success response
return $q.resolve(response.data);
} else {
// invalid response
return $q.reject(response.data);
}
}, function (response) {
// something went wrong
$log.error(response);
return;
});
}
};
});
});

ctrl.js  示例代码

define(['angular', 'app', 'jquery'], function (angular, app, $) {
app.controller('homeCtrl', function (ljkjHttp, $scope, $location, $q) {
//Banner 加载完成后执行代码
$scope.$on('ngRepeatFinishedEvent', function (ngRepeatFinishedEvent) {
var mySwiper = new Swiper('.swiper-container', {
direction: 'horizontal',
loop: true,
// 如果需要分页器
pagination: '.swiper-pagination'
});
}); //通过id选择本地图标
var getIcon = function (id, TemplateID) {
var icon = "";
TemplateID = TemplateID == 1 ? "" : TemplateID;
switch (id) {
case 1:
icon = "img/jiangjie" + TemplateID + ".png";
break;
case 2:
icon = "img/huodong" + TemplateID + ".png";
break;
case 3:
icon = "img/zixun" + TemplateID + ".png";
break;
case 4:
icon = "img/pinglun" + TemplateID + ".png";
break;
case 5:
icon = "img/ditu" + TemplateID + ".png";
break;
case 6:
icon = "img/shipin" + TemplateID + ".png";
break;
case 7:
icon = "img/meishi" + TemplateID + ".png";
break;
case 8:
icon = "img/zhusu" + TemplateID + ".png";
break;
case 9:
icon = "img/WIFI" + TemplateID + ".png";
break;
case 10:
icon = "img/daolantu" + TemplateID + ".png";
break;
}
return icon;
} var initBanner = function () {
ljkjHttp.paramData.param = {
Sid: $location.search().id
};
ljkjHttp.paramData.Name = "IFrAppBannerList";//version
ljkjHttp.paramData.function = "FrOfficialWeb";//cmd
ljkjHttp.get()
.then(function (resData) {
if (resData.state == 0) {
$scope.banners = angular.fromJson(resData.value);
}
});
} var initModel = function (TemplateID) {
ljkjHttp.paramData.param = {
Sid: $location.search().id
};
ljkjHttp.paramData.Name = "IFrAppModularList";//version
ljkjHttp.paramData.function = "FrOfficialWeb";//cmd
ljkjHttp.get()
.then(function (resData) {
if (resData.state == 0) {
$scope.models = angular.fromJson(resData.value);
for (var item in $scope.models) {
$scope.models[item]["icoUrl"] = getIcon($scope.models[item].ModularId, TemplateID);
}
}
});
} var initTemplate = function () {
var delay = $q.defer();
ljkjHttp.paramData.param = {
Sid: $location.search().id
};
ljkjHttp.paramData.Name = "IFrGetTemplateBySid";//version
ljkjHttp.paramData.function = "FrOfficialWeb";//cmd
ljkjHttp.get()
.then(function (resData) {
if (resData.state == 0) {
var obj = angular.fromJson(resData.value);
//微信浏览器中修改title
document.title = obj[0].Name;
var $body = $('body');
var $iframe = $('<iframe src="/favicon.ico"></iframe>');
$iframe.on('load', function () {
setTimeout(function () {
$iframe.off('load').remove();
}, 0);
}).appendTo($body);
delay.resolve(obj[0].TemplateID);
}
}, function (error) {
delay.reject(error);
});
return delay.promise;
}
initBanner();
initTemplate().then(function (res) {
$scope.TemplateID = res;
initModel($scope.TemplateID);
});
});
});

每一个html页面只需要引入自身 ctrl js文件即可

 <script>
require([
'controllers/explainCheckListCtrl'
]);
</script>

angular+require前端项目架构搭建的更多相关文章

  1. mvc项目架构搭建之UI层的搭建

    项目架构搭建之UI层的搭建 Contents 系列一[架构概览] 0.项目简介 1.项目解决方案分层方案 2.所用到的技术 3.项目引用关系 系列二[架构搭建初步] 4.项目架构各部分解析 5.项目创 ...

  2. [Vue 牛刀小试]:第十六章 - 针对传统后端开发人员的前端项目框架搭建

    一.前言 在之前学习 Vue 基础知识点的文章中,我们还是采用传统的方式,通过在 html 页面上引用 vue.js 这个文件,从而将 Vue 引入到我们的项目开发中.伴随着 Node.js 的出现, ...

  3. c#项目架构搭建经验

    读过.Net项目中感觉代码写的不错(备注1)有:bbsMax(可惜唧唧喳喳鸟像消失了一样),Umbraco(国外开源的cms项目),Kooboo(国内做开源cms).本人狭隘,读的代码不多,范围也不广 ...

  4. Luffy之前端项目部署搭建

    1. 搭建前端项目 1.1 创建项目目录 cd 项目目录 vue init webpack lufei 根据需要在生成项目时,我们选择对应的选项, 效果: 根据上面的提示,我们已经把vue项目构建好了 ...

  5. 微服务SpringCloud项目架构搭建入门

    Spring的微服务框架SpringCloud受到众多公司欢迎,给大家带来一篇框架搭建入门.本次采用的版本是Spring Cloud版本为Finchley.RELEASE. 一.SpringCloud ...

  6. Vue前端项目的搭建流程

    1.  安装Vue和Nodejs 2.  创建项目 vue create eduonline-web

  7. mvc项目架构分享系列之架构搭建之Repository和Service

    项目架构搭建之Repository和Service的搭建 Contents 系列一[架构概览] 0.项目简介 1.项目解决方案分层方案 2.所用到的技术 3.项目引用关系 系列二[架构搭建初步] 4. ...

  8. mvc项目架构分享系列之架构搭建之Infrastructure

    项目架构搭建之Infrastructure的搭建 Contents 系列一[架构概览] 0.项目简介 1.项目解决方案分层方案 2.所用到的技术 3.项目引用关系 系列二[架构搭建初步] 4.项目架构 ...

  9. mvc项目架构分享系列之架构搭建初步

    mvc项目架构分享系列之架构搭建初步 Contents 系列一[架构概览] 0.项目简介 1.项目解决方案分层方案 2.所用到的技术 3.项目引用关系 系列二[架构搭建初步] 4.项目架构各部分解析 ...

随机推荐

  1. rsync学习笔记

    转载地址:http://www.cnblogs.com/maxincai/p/5142245.html rsync同步工具 1.rsync介绍 rsync是一款开源的.快速的.多功能的.可实现全量及增 ...

  2. 改变UITableView选中行高亮的颜色

    UIView *backView = [[UIView alloc] initWithFrame:self.contentView.frame]; backView.backgroundColor = ...

  3. greedy算法(python版)

    greedy算法的核心思想是首先计算覆盖面大的部分,然后依次寻找其他覆盖面最大的部分.该算法的使用场景就像他的名字一样,当符合贪婪属性的时候就可以考虑. states_needed = set(['北 ...

  4. 二叉查找树C++实现

    二分查找树特点: (1) 若任意节点的左子树不空,则左子树上所有结点的值均小于它的根结点的值: (2) 任意节点的右子树不空,则右子树上所有结点的值均大于它的根结点的值: (3) 任意节点的左.右子树 ...

  5. junit源码解析--捕获测试结果

    OK,前面的博客我们整理了junit运行完了所有的测试用例,那么OK了,现在开始该收集测试结果了. 在这最后一步中,junit主要是玩一个类,TestResult.这里类中封装了几个参数,在初始化这个 ...

  6. 输入和输出--java的NIO

    Java的NIO 实际开发中NIO使用到的并不多,我并不是说NIO使用情景不多,是说我自己接触的并不是很多,前面我在博客园和CSDN上转载了2篇别人写的文章,这里来大致总结下Java的NIO,大概了解 ...

  7. 腾讯工程师教你玩转 RocksDB

    欢迎大家前往云+社区,获取更多腾讯海量技术实践干货哦~ 作者:腾讯云数据库内核团队 原文标题:[腾讯云CDB]教你玩转MyRocks/RocksDB-STATISTICS与后台线程篇 0. Intro ...

  8. nodejs爬虫笔记(三)---爬取YouTube网站上的视频信息

    思路:通过笔记(二)中代理的设置,已经可以对YouTube的信息进行爬取了,这几天想着爬取网站下的视频信息.通过分析YouTube,发现可以从订阅号入手,先选择几个订阅号,然后爬取订阅号里面的视频分类 ...

  9. 如何使用 highlight.js 高亮代码

    highlight 是一款简单易用的 web 代码高亮插件,可以自动检测编程语言并高亮,兼容各种框架,可以说是十分强大了.下面就简单介绍一下如何使用这款插件. 两种使用方式: 1. 手动选择主题,官网 ...

  10. spring之AspectJ基于注解 AOP编程

    一.前言 使用注解代替之前在spring配置文件中配置目标类.切面类和aop配置. 二.注意 需要注意的是,需要在spring配置文件中引入如下,如果不添加,切面类中的@Aspect注解将不起作用 & ...