Main.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. if (this.collectToken=="" || this.collectUrl==""){
  49. //先登录collcect
  50. this.actions.CollectAction.login(//平台封装好的方法
  51. function( json ){ //服务调用成功的回调函数, json为服务传回的数据
  52. if (json.type && json.type=="success"){
  53. data = json.data; //为变量data赋值
  54. this.collectUrl = data.collectUrl;
  55. this.collectToken = data.collectToken;
  56. this.content.loadHtml(this.viewPath, {"bind": {"lp": this.lp}, "module": this}, function(){
  57. if (!this.options.isRefresh){
  58. this.maxSize(function(){
  59. this.loadIntroduce(callback);
  60. }.bind(this));
  61. }else{
  62. this.loadIntroduce(callback);
  63. }
  64. }.bind(this));
  65. }
  66. }.bind(this),null,false //同步执行
  67. );
  68. }
  69. },
  70. initNodeSize: function(){
  71. this.resizeNodeSize();
  72. this.addEvent("resize", this.resizeNodeSize.bind(this));
  73. },
  74. resizeNodeSize: function(){
  75. var size = this.content.getSize();
  76. var edge = this.introducenode.getEdgeHeight();
  77. var height = size.y - edge;
  78. if (height<this.options.minHeight) height = this.options.minHeight;
  79. this.introducenode.setStyle("height", ""+height+"px");
  80. },
  81. loadIntroduce:function(callback){
  82. this.initNodeSize();
  83. if (this.options.appid){
  84. this.actions.MarketAction.get(this.options.appid,function(json){
  85. if (json.data && json.data.icon){
  86. this.appdata = json.data;
  87. this.setTitle(MWF.xApplication.AppMarketV2.Application.LP.title+"_"+this.appdata.name);
  88. var applicationicon = new Element("div",{"class":"o2_appmarket_application_introduce_icon"}).inject(this.applicationintroduceiconcontain);
  89. applicationicon.setStyle("background-image", "url(data:image/png;base64,"+this.appdata.icon+")");
  90. if (this.applicationintroduceiconcontain.clientWidth<300){
  91. applicationicon.setStyle("width",this.applicationintroduceiconcontain.clientWidth);
  92. applicationicon.setStyle("height",450*this.applicationintroduceiconcontain.clientWidth/300);
  93. }
  94. var price=this.appdata.price>0?this.appdata.price+"":"Free";
  95. this.applicationintroducememofree.set("text",price);
  96. this.applicationintroducememoname.set("text",this.appdata.name);
  97. var grade = this.numberFix(this.appdata.grade,1);
  98. this.applicationintroducememoremarkgrade.set("text",grade);
  99. var intgrade = parseInt(grade);
  100. var dotgrade = grade - intgrade;
  101. for (var tmpnum=0;tmpnum<intgrade;tmpnum++){
  102. new Element("img",{"src":this.iconPath+"blackfiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(this.applicationintroducememoremarkiconangular)
  103. }
  104. if (dotgrade>=0.5){
  105. new Element("img",{"src":this.iconPath+"halffiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(this.applicationintroducememoremarkiconangular);
  106. intgrade++;
  107. }
  108. for (var tmpnum=0;tmpnum<5-intgrade;tmpnum++){
  109. new Element("img",{"src":this.iconPath+"whitefiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(this.applicationintroducememoremarkiconangular);
  110. }
  111. if (!this.appdata.commentCount) this.appdata.commentCount=0;
  112. this.applicationintroducememoremarkcommentcount.set("text","共"+this.appdata.commentCount+"个评分")
  113. //this.applicationintroducememodownload.set("text",this.appdata.downloadCount);
  114. this.applicationintroducememocategory.set("text","分类:"+this.appdata.category);
  115. this.applicationintroducememocontent.set("text",this.appdata.describe);
  116. //this.applicationintroducedownloadprice.set("text","$"+this.appdata.price);
  117. this.applicationintroducedownloadprice.set("text","");
  118. var bottomtext =this.lp.setup;
  119. if (this.appdata.installedVersion && this.appdata.installedVersion!=""){
  120. if (this.appdata.installedVersion==this.appdata.version){
  121. bottomtext = this.lp.setupDone;
  122. }else{
  123. bottomtext = this.lp.update;
  124. }
  125. }
  126. this.applicationintroducedownloadbtntext.set("text",bottomtext);
  127. var _self = this;
  128. this.applicationintroducedownloadbtn.store("data",this.appdata);
  129. this.applicationintroducedownloadbtn.addEvents({
  130. "click": function(e){
  131. //updateorinstall application
  132. var d = this.retrieve("data");
  133. if (d){
  134. _self.installapp(e,d);
  135. }
  136. }
  137. })
  138. //add by xlq @20201104 for adding button which goes to bbs.
  139. this.applicationintroduceforumbtntext.set("text",this.lp.bbsname);
  140. this.applicationintroduceforumbtn.addEvents({
  141. "click": function(e){
  142. //updateorinstall application
  143. window.open(_self.lp.bbslink);
  144. }
  145. })
  146. //this.applicationintroducefavbtntext.set("text","下载");
  147. this.loadIntroduceInfo();
  148. }
  149. this.fireEvent("load");
  150. }.bind(this));
  151. }
  152. if (callback) callback();
  153. },
  154. tabover: function(e){
  155. e.currentTarget.addClass("o2_appmarket_appcategory_tab_over");
  156. },
  157. tabout: function(e){
  158. e.currentTarget.removeClass("o2_appmarket_appcategory_tab_over");
  159. //e.currentTarget.removeClass("mainColor_border").removeClass("mainColor_color");
  160. },
  161. mouseover:function(){
  162. this.addClass("o2_appmarket_appcategory_tab_over");
  163. },
  164. mouseout:function(){
  165. this.removeClass("o2_appmarket_appcategory_tab_over");
  166. },
  167. installapp:function(e,d){
  168. var p = e.target.getPosition();
  169. var tmpe = {"event": {"x": p.x+40, "y": p.y}};
  170. var confirmtitle = d.installedVersion==""?this.lp.confirmsetupTitle:this.lp.confirmupdateTitle;
  171. var confirmcontent = d.installedVersion==""?this.lp.confirmsetupContent:this.lp.confirmupdateContent;
  172. var _self = this;
  173. _self.confirm("warn", tmpe, confirmtitle, confirmcontent, 300, 120, function(){
  174. _self.mask();
  175. //this.createLoading(this.container,true);
  176. //alert("after createLoading")
  177. _self.actions.MarketAction.installOrUpdate(
  178. d.id,
  179. function( json ){
  180. data = json.data;
  181. _self.notice(d.name+" "+_self.lp.setupSuccess, "success");
  182. _self.unmask();
  183. //this.clearLoading()
  184. }.bind(_self),
  185. function( json ){
  186. data = json.data;
  187. _self.unmask();
  188. //this.clearLoading()
  189. }.bind(_self),
  190. true
  191. );
  192. this.close();
  193. }, function(){
  194. this.close();
  195. }, null, null, "o2");
  196. },
  197. loadIntroduceInfo: function(callback){
  198. var _self = this;
  199. 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");
  200. this.applicationintroducesinfoTab.removeClass("o2_appmarket_application_introduce_tab").addClass("mainColor_color").addClass("o2_appmarket_application_introduce_tab_current");
  201. this.applicationintroducecontent.set("html","");
  202. this.applicationintroducecontent.set("html",this.appdata.abort);
  203. this.applicationintroducepicslable.set("html","");
  204. this.applicationintroducepics.set("html","")
  205. this.applicationintroducepicslable.set("html","屏幕截图"); //截图
  206. this.appdata.attList.each(function(peratt,i){
  207. if (peratt.type == "image"){
  208. picdiv = new Element("img",{"class":"o2_appmarket_application_introduce_pic"}).inject(this.applicationintroducepics);
  209. picdiv.setProperty("src", "data:image/png;base64,"+peratt.icon);
  210. picdiv.setProperty("data-original",this.collectUrl +'/o2_collect_assemble/jaxrs/attachment/download/'+peratt.id+"?c-token="+this.collectToken);
  211. picdiv.setProperty("alt",peratt.name);
  212. //picdiv.store("id",peratt.id);
  213. }
  214. }.bind(this));
  215. this.loadImgView(this.appdata.id);
  216. },
  217. loadImgView:function(viewid){
  218. if(this.viewer) this.viewer.destroy();
  219. this.applicationintroducepics.setProperty("id",viewid);
  220. o2.loadCss(this.path+this.options.style+"/viewer.css", this.content,function(){
  221. o2.load(this.path+this.options.style+"/viewer.js", function(){
  222. this.viewer = new Viewer(document.getElementById(viewid), {
  223. url: 'data-original'
  224. });
  225. }.bind(this));
  226. }.bind(this));
  227. },
  228. loadIntroduceDemand:function(callback){
  229. 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");
  230. this.applicationintroducedemandTab.removeClass("o2_appmarket_application_introduce_tab").addClass("mainColor_color").addClass("o2_appmarket_application_introduce_tab_current");
  231. this.applicationintroducecontent.set("html","");
  232. this.applicationintroducepicslable.set("html","");
  233. this.applicationintroducepics.set("html","")
  234. this.applicationintroducecontent.set("html",this.appdata.installSteps);
  235. },
  236. loadIntroduceComment:function(callback){
  237. 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");
  238. this.applicationintroducecommentTab.removeClass("o2_appmarket_application_introduce_tab").addClass("mainColor_color").addClass("o2_appmarket_application_introduce_tab_current");
  239. this.applicationintroducecontent.set("html","");
  240. this.applicationintroducepicslable.set("html","");
  241. this.applicationintroducepics.set("html","");
  242. o2.requireApp("AppMarketV2.Application", "Comment", function(){
  243. new MWF.xApplication.AppMarketV2.Application.Comment(this, this.applicationintroducecontent, {
  244. "onLoad": function(){if (callback) callback();}
  245. });
  246. }.bind(this));
  247. },
  248. recordStatus: function(){
  249. debugger;
  250. return {"appid": this.options.appid,"appname":this.options.appname};x
  251. },
  252. numberFix:function(data,n){
  253. var numbers = '';
  254. // 保留几位小数后面添加几个0
  255. for (var i = 0; i < n; i++) {
  256. numbers += '0';
  257. }
  258. var s = 1 + numbers;
  259. // 如果是整数需要添加后面的0
  260. var spot = "." + numbers;
  261. // Math.round四舍五入
  262. // parseFloat() 函数可解析一个字符串,并返回一个浮点数。
  263. var value = Math.round(parseFloat(data) * s) / s;
  264. // 从小数点后面进行分割
  265. var d = value.toString().split(".");
  266. if (d.length == 1) {
  267. value = value.toString();
  268. return value;
  269. }
  270. if (d.length > 1) {
  271. if (d[1].length < n) {
  272. value = value.toString() + "0";
  273. }
  274. return value;
  275. }
  276. }
  277. });