Main.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. MWF.xApplication.AppMarketV2.Application.options.multitask = true;
  2. MWF.require("MWF.widget.MaskNode", null, false);
  3. MWF.xApplication.AppMarketV2.Application.Main = new Class({
  4. Extends: MWF.xApplication.Common.Main,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "mvcStyle": "style.css",
  9. "view": "applicationView.html",
  10. "name": "AppMarketV2.Application",
  11. "icon": "icon.png",
  12. "width": "1000",
  13. "height": "700",
  14. "isResize": true,
  15. "isMax": true,
  16. "title": MWF.xApplication.AppMarketV2.Application.LP.title,
  17. "minHeight": 700
  18. },
  19. onQueryLoad: function(){
  20. this.lp = MWF.xApplication.AppMarketV2.Application.LP;
  21. this.actions = MWF.Actions.load("x_program_center");
  22. this.viewPath = this.path+this.options.style+"/"+this.options.view;
  23. this.iconPath = this.path+this.options.style+"/icon/";
  24. this.collectToken = "";
  25. this.collectUrl = "";
  26. if (!this.status) {
  27. } else {
  28. this.options.appid = this.status.appid;
  29. this.options.appname = this.status.appname;
  30. }
  31. this.appdata = {};
  32. },
  33. mask: function(){
  34. if (!this.maskNode){
  35. this.introducenode.setStyle("overflow","hidden");
  36. this.maskNode = new MWF.widget.MaskNode(this.introducenode, {"style": "bam"});
  37. this.maskNode.load();
  38. }
  39. },
  40. unmask: function(){
  41. if (this.maskNode) this.maskNode.hide(function(){
  42. MWF.release(this.maskNode);
  43. this.maskNode = null;
  44. this.introducenode.setStyle("overflow","auto");
  45. }.bind(this));
  46. },
  47. loadApplication: function(callback){
  48. debugger
  49. if (this.collectToken=="" || this.collectUrl==""){
  50. //先登录collcect
  51. this.actions.CollectAction.login(//平台封装好的方法
  52. function( json ){ //服务调用成功的回调函数, json为服务传回的数据
  53. if (json.type && json.type=="success"){
  54. data = json.data; //为变量data赋值
  55. this.collectUrl = data.collectUrl;
  56. this.collectToken = data.collectToken;
  57. this.content.loadHtml(this.viewPath, {"bind": {"lp": this.lp}, "module": this}, function(){
  58. if (!this.options.isRefresh){
  59. this.maxSize(function(){
  60. this.loadIntroduce(callback);
  61. }.bind(this));
  62. }else{
  63. this.loadIntroduce(callback);
  64. }
  65. }.bind(this));
  66. }
  67. }.bind(this),null,false //同步执行
  68. );
  69. }
  70. },
  71. initNodeSize: function(){
  72. this.resizeNodeSize();
  73. this.addEvent("resize", this.resizeNodeSize.bind(this));
  74. },
  75. resizeNodeSize: function(){
  76. var size = this.content.getSize();
  77. var edge = this.introducenode.getEdgeHeight();
  78. var height = size.y - edge;
  79. if (height<this.options.minHeight) height = this.options.minHeight;
  80. this.introducenode.setStyle("height", ""+height+"px");
  81. },
  82. loadIntroduce:function(callback){
  83. this.initNodeSize();
  84. if (this.options.appid){
  85. debugger
  86. this.loadBbsInfo(this);
  87. this.actions.MarketAction.get(this.options.appid,function(json){
  88. if (json.data && json.data.icon){
  89. this.appdata = json.data;
  90. this.setTitle(MWF.xApplication.AppMarketV2.Application.LP.title+"_"+this.appdata.name);
  91. var applicationicon = new Element("div",{"class":"o2_appmarket_application_introduce_icon"}).inject(this.applicationintroduceiconcontain);
  92. applicationicon.setStyle("background-image", "url(data:image/png;base64,"+this.appdata.icon+")");
  93. if (this.applicationintroduceiconcontain.clientWidth<300){
  94. applicationicon.setStyle("width",this.applicationintroduceiconcontain.clientWidth);
  95. applicationicon.setStyle("height",450*this.applicationintroduceiconcontain.clientWidth/300);
  96. }
  97. this.loadCommentsGrade(this.appdata,function( gradeData ){
  98. this.gradeData = gradeData;
  99. var price=this.appdata.price>0?this.appdata.price+"":"Free";
  100. this.applicationintroducememofree.set("text",price);
  101. this.applicationintroducememoname.set("text",this.appdata.name);
  102. debugger;
  103. var commentcount = 0;
  104. var grade = 0;
  105. var totalgrade = 0;
  106. var commentratiolist = this.gradeData.data;
  107. var gradeList = ["0","0","0","0","0"];
  108. commentratiolist.each(function(pergrade){
  109. gradeList[parseInt(pergrade.grade)-1]=pergrade.count;
  110. commentcount +=parseInt(pergrade.count)
  111. }.bind(this));
  112. gradeList.each(function(pergrade,index){
  113. totalgrade += parseInt(pergrade)*(index+1)
  114. })
  115. if (commentcount>0){
  116. grade = this.numberFix(totalgrade/commentcount,1)
  117. }
  118. this.applicationintroducememoremarkgrade.set("text",grade+"");
  119. var intgrade = parseInt(grade);
  120. var dotgrade = grade - intgrade;
  121. /*var grade = this.numberFix(this.appdata.grade,1);
  122. this.applicationintroducememoremarkgrade.set("text",grade);
  123. var intgrade = parseInt(grade);
  124. var dotgrade = grade - intgrade;*/
  125. debugger;
  126. for (var tmpnum=0;tmpnum<intgrade;tmpnum++){
  127. new Element("img",{"src":this.iconPath+"blackfiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(this.applicationintroducememoremarkiconangular)
  128. }
  129. if (dotgrade>=0.5){
  130. new Element("img",{"src":this.iconPath+"halffiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(this.applicationintroducememoremarkiconangular);
  131. intgrade++;
  132. }
  133. for (var tmpnum=0;tmpnum<5-intgrade;tmpnum++){
  134. new Element("img",{"src":this.iconPath+"whitefiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(this.applicationintroducememoremarkiconangular);
  135. }
  136. if (!this.appdata.commentCount) this.appdata.commentCount=0;
  137. this.applicationintroducememoremarkcommentcount.set("text",this.lp.commentCountText.replace("{n}", commentcount))
  138. //this.applicationintroducememodownload.set("text",this.appdata.downloadCount);
  139. this.applicationintroducememocategory.set("text", this.lp.category+":"+this.appdata.category);
  140. this.applicationintroducememocontent.set("text",this.appdata.describe);
  141. //this.applicationintroducedownloadprice.set("text","$"+this.appdata.price);
  142. this.applicationintroducedownloadprice.set("text","");
  143. var bottomtext =this.lp.setup;
  144. if (this.appdata.installedVersion && this.appdata.installedVersion!=""){
  145. if (this.appdata.installedVersion==this.appdata.version){
  146. bottomtext = this.lp.setupDone;
  147. }else{
  148. bottomtext = this.lp.update;
  149. }
  150. }
  151. this.applicationintroducedownloadbtntext.set("text",bottomtext);
  152. var _self = this;
  153. this.applicationintroducedownloadbtn.store("data",this.appdata);
  154. this.applicationintroducedownloadbtn.addEvents({
  155. "click": function(e){
  156. //updateorinstall application
  157. var d = this.retrieve("data");
  158. if (d){
  159. _self.installapp(e,d);
  160. }
  161. }
  162. })
  163. //add by xlq @20201104 for adding button which goes to bbs.
  164. this.applicationintroduceforumbtntext.set("text",this.lp.bbsname);
  165. this.applicationintroduceforumbtn.addEvents({
  166. "click": function(e){
  167. //updateorinstall application
  168. window.open(_self.lp.bbslink);
  169. }
  170. })
  171. }.bind(this)
  172. );
  173. //this.applicationintroducefavbtntext.set("text","下载");
  174. this.loadIntroduceInfo();
  175. }
  176. this.fireEvent("load");
  177. }.bind(this));
  178. }
  179. if (callback) callback();
  180. },
  181. loadBbsInfo: function(content){
  182. debugger;
  183. this.actions.CollectAction.bbs(//平台封装好的方法
  184. function( json ){ //服务调用成功的回调函数, json为服务传回的数据
  185. if (json.type && json.type=="success"){debugger;
  186. data = json.data; //为变量data赋值
  187. this.bbsUrlPath = data.bbsUrlPath;
  188. this.bbsUrl = data.bbsUrl;
  189. }
  190. }.bind(this),null,false //同步执行
  191. );
  192. },
  193. loadCommentsGrade: function(appdata,callback){
  194. debugger;
  195. var json = null;
  196. var commenturl = this.bbsUrlPath +'/x_bbs_assemble_control/jaxrs/subject/statgrade/sectionName/'+encodeURI(this.lp.title)+'/subjectType/'+encodeURI(appdata.name)+'?time='+(new Date()).getMilliseconds();
  197. var res = new Request.JSON({
  198. url: commenturl,
  199. headers : {'x-debugger' : true,'Authorization':this.collectToken,'c-token':this.collectToken},
  200. secure: false,
  201. method: "get",
  202. async: true,
  203. withCredentials: true,
  204. contentType : 'application/json',
  205. crossDomain : true,
  206. onSuccess: function(responseJSON, responseText){
  207. debugger;
  208. //this.gradeData = responseJSON;
  209. if(callback)callback( responseJSON );
  210. }.bind(this)
  211. });
  212. res.send();
  213. },
  214. tabover: function(e){
  215. e.currentTarget.addClass("o2_appmarket_appcategory_tab_over");
  216. },
  217. tabout: function(e){
  218. e.currentTarget.removeClass("o2_appmarket_appcategory_tab_over");
  219. //e.currentTarget.removeClass("mainColor_border").removeClass("mainColor_color");
  220. },
  221. mouseover:function(){
  222. this.addClass("o2_appmarket_appcategory_tab_over");
  223. },
  224. mouseout:function(){
  225. this.removeClass("o2_appmarket_appcategory_tab_over");
  226. },
  227. installapp:function(e,d){
  228. var p = e.target.getPosition();
  229. var tmpe = {"event": {"x": p.x+40, "y": p.y}};
  230. var confirmtitle = d.installedVersion==""?this.lp.confirmsetupTitle:this.lp.confirmupdateTitle;
  231. var confirmcontent = d.installedVersion==""?this.lp.confirmsetupContent:this.lp.confirmupdateContent;
  232. var _self = this;
  233. _self.confirm("warn", tmpe, confirmtitle, confirmcontent, 300, 120, function(){
  234. _self.mask();
  235. //this.createLoading(this.container,true);
  236. //alert("after createLoading")
  237. _self.actions.MarketAction.installOrUpdate(
  238. d.id,
  239. function( json ){
  240. data = json.data;
  241. _self.notice(d.name+" "+_self.lp.setupSuccess, "success");
  242. _self.unmask();
  243. //this.clearLoading()
  244. }.bind(_self),
  245. function( json ){
  246. data = json.data;
  247. _self.unmask();
  248. //this.clearLoading()
  249. }.bind(_self),
  250. true
  251. );
  252. this.close();
  253. }, function(){
  254. this.close();
  255. }, null, null, "o2");
  256. },
  257. loadIntroduceInfo: function(callback){
  258. var _self = this;
  259. this.applicationintroducesinfoTab.getParent().getElements(".o2_appmarket_application_introduce_tab_current").removeClass("mainColor_color").removeClass("o2_appmarket_application_introduce_tab_current").addClass("o2_appmarket_application_introduce_tab");
  260. this.applicationintroducesinfoTab.removeClass("o2_appmarket_application_introduce_tab").addClass("mainColor_color").addClass("o2_appmarket_application_introduce_tab_current");
  261. this.applicationintroducecontent.set("html","");
  262. this.applicationintroducecontent.set("html",this.appdata.abort);
  263. this.applicationintroducepicslable.set("html","");
  264. this.applicationintroducepics.set("html","")
  265. this.applicationintroducepicslable.set("html", this.lp.screenshot); //截图
  266. this.appdata.attList.each(function(peratt,i){
  267. if (peratt.type == "image"){
  268. picdiv = new Element("img",{"class":"o2_appmarket_application_introduce_pic"}).inject(this.applicationintroducepics);
  269. picdiv.setProperty("src", "data:image/png;base64,"+peratt.icon);
  270. picdiv.setProperty("data-original",this.collectUrl +'/o2_collect_assemble/jaxrs/attachment/download/'+peratt.id+"?c-token="+this.collectToken);
  271. picdiv.setProperty("alt",peratt.name);
  272. //picdiv.store("id",peratt.id);
  273. }
  274. }.bind(this));
  275. this.loadImgView(this.appdata.id);
  276. },
  277. loadImgView:function(viewid){
  278. if(this.viewer) this.viewer.destroy();
  279. this.applicationintroducepics.setProperty("id",viewid);
  280. o2.loadCss(this.path+this.options.style+"/viewer.css", this.content,function(){
  281. o2.load(this.path+this.options.style+"/viewer.js", function(){
  282. this.viewer = new Viewer(document.getElementById(viewid), {
  283. url: 'data-original'
  284. });
  285. }.bind(this));
  286. }.bind(this));
  287. },
  288. loadIntroduceDemand:function(callback){
  289. this.applicationintroducedemandTab.getParent().getElements(".o2_appmarket_application_introduce_tab_current").removeClass("mainColor_color").removeClass("o2_appmarket_application_introduce_tab_current").addClass("o2_appmarket_application_introduce_tab");
  290. this.applicationintroducedemandTab.removeClass("o2_appmarket_application_introduce_tab").addClass("mainColor_color").addClass("o2_appmarket_application_introduce_tab_current");
  291. this.applicationintroducecontent.set("html","");
  292. this.applicationintroducepicslable.set("html","");
  293. this.applicationintroducepics.set("html","")
  294. this.applicationintroducecontent.set("html",this.appdata.installSteps);
  295. },
  296. loadIntroduceComment:function(callback){
  297. this.applicationintroducecommentTab.getParent().getElements(".o2_appmarket_application_introduce_tab_current").removeClass("mainColor_color").removeClass("o2_appmarket_application_introduce_tab_current").addClass("o2_appmarket_application_introduce_tab");
  298. this.applicationintroducecommentTab.removeClass("o2_appmarket_application_introduce_tab").addClass("mainColor_color").addClass("o2_appmarket_application_introduce_tab_current");
  299. this.applicationintroducecontent.set("html","");
  300. this.applicationintroducepicslable.set("html","");
  301. this.applicationintroducepics.set("html","");
  302. o2.requireApp("AppMarketV2.Application", "Comment", function(){
  303. new MWF.xApplication.AppMarketV2.Application.Comment(this, this.applicationintroducecontent, {
  304. "onLoad": function(){if (callback) callback();}
  305. });
  306. }.bind(this));
  307. },
  308. recordStatus: function(){
  309. debugger;
  310. return {"appid": this.options.appid,"appname":this.options.appname};
  311. },
  312. numberFix:function(data,n){
  313. var numbers = '';
  314. // 保留几位小数后面添加几个0
  315. for (var i = 0; i < n; i++) {
  316. numbers += '0';
  317. }
  318. var s = 1 + numbers;
  319. // 如果是整数需要添加后面的0
  320. var spot = "." + numbers;
  321. // Math.round四舍五入
  322. // parseFloat() 函数可解析一个字符串,并返回一个浮点数。
  323. var value = Math.round(parseFloat(data) * s) / s;
  324. // 从小数点后面进行分割
  325. var d = value.toString().split(".");
  326. if (d.length == 1) {
  327. value = value.toString();
  328. return value;
  329. }
  330. if (d.length > 1) {
  331. if (d[1].length < n) {
  332. value = value.toString() + "0";
  333. }
  334. return value;
  335. }
  336. }
  337. });