我的seajs实例

来源:互联网 发布:三国吴国知乎 编辑:程序博客网 时间:2024/06/13 19:18

define(function( require,exports,module ){
var DetailData = {};
var URL = window.TD.vHosts;
var $App = $("#app");
var promise = require("../index/homepageAjax");
//主体模板
var PageDetailTpl = require( '../tpl/PageDetailTpl' );
//introduce
var IntroduceDetail = require( './IntroduceDetail' );
//API
var ApiDetail = require( './ApiDetail' );
//code
var CodeDetail = require( './CodeDetail' );
//status 
var StatusDetail = require( './StatusDetail' );
//dosage
var DosageDetail = require( './DosageDetail' );
//右侧基本信息
var AboutInfor = require( './AboutInfor' );
//Tabs显示问题
var TabsListDeTail = require( '../tpl/TabsListDetail' );
//headerTable显示
var HeaderDropDown = require( './HeaderDropdown' );
window.TD.Time = 7;
var BuyTestTpl = require('../tpl/BuyAndTest');
var $AppLoading = $(".app-loading");
var severId = "";
window.TD.token=window.TD.util.Cookie.get("tdppt")
var DetailPage = {
//页面入口
init : function(id,hash){
severId = id;
var html = window.template( PageDetailTpl,{} );
$App.html( html );
promise({});
this.$RenderContent = $("#DetailInfor");
this.renderHtml( id );
$AppLoading.show();
$("#PageDetail").show()
},
Tabs : function(){
var $tabs = $("#LeftTabs");
var self = this;//this提前绑定
$tabs.on("click","li",function(){
var me = $(this),
type = me.attr("data-id");
me.addClass("left-tab-selected")
.siblings().removeClass("left-tab-selected");
self.pageContentLoad( type , severId);
})
},
renderTabs : function( data ){
// var buy = data.buy;
console.log(data);
var html = window.template( TabsListDeTail,data );
$("#DetailTabsList").html( html );
},
pageContentLoad : function( type ,severId ){
console.log(type,DetailData.simpleContent)
switch ( type ){
case "introduce" : 
IntroduceDetail.init( DetailData.simpleContent.desc );
// AboutInfor.index = 0;
break;
case "api" : 
ApiDetail.init( DetailData.simpleContent );
// AboutInfor.index = 1;
break;
case "status" :
StatusDetail.init( DetailData.simpleContent.status ); 
// AboutInfor.index = 2;
break;
case "dosage" : 
DosageDetail.init( DetailData.simpleContent.statistics,severId );
break;
}
},
formateSimpleContent : function( data ){
var self =this;
DetailData.headerMap = data.headerMap;
DetailData.simpleContent = data.simpleContent;
if(data.buy == 1){
DetailData.simpleContent.statistics.statistics.table.order = self.ReverseArray(data.simpleContent.statistics.statistics.table.data);
}
},
renderHtml : function( id ){
var self = this;
$AppLoading.show();
$.ajax({
url : URL + '/datamarket/myData/' + id,
type : "get",
data : {
token : window.TD.token,
from : window.TD.vFrom,
beforeDays : window.TD.Time
},
success : function( data ){
if( data.status == 200 ){
data.data.hash = window.TD.Hash;
self.formateSimpleContent( data.data );
self.renderTabs( data.data );
if(window.TD.Hash == "homeindex"){
self.pageContentLoad( 'introduce' );
IntroduceDetail.init( DetailData.simpleContent.desc );
}else{
self.pageContentLoad( 'dosage' );
DosageDetail.init( DetailData.simpleContent.statistics,severId );
}
AboutInfor.init( DetailData,id );
$("#HeaderTitle").html( DetailData.headerMap.name);
$(".triangle").css("display","inline-block");
if(data.data.buy == 1){
$(".triangle").css("display","inline-block");
}else{
$(".triangle").css("display","none");
$("#HeaderDetailDropDown").css("display","none");
}
self.Tabs();
HeaderDropDown.init([{ id : 1, name : "111" }]);
var usehtml = window.template( BuyTestTpl,{data : data.data})
$("#BuyAndUse").html(usehtml);

}
$AppLoading.hide();
},
error : function( err ){
console.warn( err );
}
})
},
ReverseArray : function(arr){
var ReArr = [];
for(var i=arr.length-1;i>-1;i--){
ReArr.push(arr[i]);
}
return ReArr;
}
};
module.exports = DetailPage;//exports向外提供模块接口
})

2.return 一段字符串:

define(function(require,module,exports){
return "<dl style='padding:14px 20px 10px 20px;z-index:99;text-align:center;background-color:#f6f6f6;border-bottom:1px solid #ddd;'>" +
"<dt>" +
"<span class='all_icon' style=\"\"></span>"+
"<a href=\"#homeindex\" style='font-size: 16px;font-weight:600;'>" +
"全部数据类型" +
"</a>" +
"</dt>" +
"</dl>" +
"{{ each data as first f}}" +
"<dl class=\"level\" style=\"background-color:#fbfbfb;padding:5px 0;border-bottom:1px solid #ddd;\">" +
"<dt class=\"levelName\" style=\"text-align:left;\">" +
"<div class='dl_circle' style='width:10px;height:10px;display:inline-block;border-radius:5px;margin-left:34px;margin-right:13px;'></div>"+
"<a  class='a_color header-down-dt' style='font-size:16px;' data-id={{first.type}} >" +
"{{first.type}}" +
"</a>" +
"</dt>" +
"{{if first.nodes && first.nodes.length > 0 }}" +
"<dd class=\"levelName2\" style=\"padding-left: 15px;text-align:left;width:200px;\">" +
"{{ each first.nodes[0] as second s}}" +
"{{if s < 2 }}" +
"<a style=\"padding-right:5px;font-size:12px;color:#9999a5\" class='header-down-dt'  data-id={{second.type}}>" +
"{{second.type}}" +
"</a>" +
"{{/if}}" +
"{{/each}}" +
"</dd>" +
"<dd class=\"sublayer\" style='background-color:#f7f7f7;z-index:99;display:none;'>" +
"{{ each first.nodes[0] as second s}}" +
"{{if s > 1 }}" +
"<a style='font-size:14px;color:#666666;' class='header-down-dt'  data-id={{second.type}}>" +
"{{second.type}}" +
"</a>" +
"{{/if}}" +
"{{/each}}" +
"</dd>" +
"{{/if}}" +
"</dl>" +
"{{/each}}"
})

原创粉丝点击