gcmsPictures.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /**
  2. * [ONEMAP.M.gcmsPictures]
  3. * @return {[object]}
  4. */
  5. define([
  6. 'html!templates/gcms/gcmsPictures',
  7. 'vendorDir/handlebars/handlebars',
  8. 'css!styles/gcms/gcmsPictures'],
  9. function(tpcLayout,Handlebars){
  10. //数据存放和外部数据调用
  11. var modValue = {
  12. options:{},
  13. iviewer:null,
  14. picturesData:[]
  15. };
  16. //地图层
  17. //var _map = ONEMAP.M.mapHolder.map;
  18. /**
  19. * 模块初始化
  20. * @return {[type]} [description]
  21. */
  22. function init(options){
  23. remove();
  24. modValue.options = {};
  25. for(var op in options){
  26. modValue.options[op] = options[op];
  27. }
  28. //获取内容数据
  29. getDetailData({callback:function(){
  30. //设置容器布局
  31. setPicturesModal();
  32. bindEvent();
  33. }});
  34. //订阅推送
  35. subscribe();
  36. }
  37. function getDetailData(options){
  38. ONEMAP.V.loading.load();
  39. $.ajax({
  40. url: onemapUrlConfig.gcmsServiceUrl+'/show/'+modValue.options['column_name']+'/'+modValue.options['article_id'],
  41. type:"GET",
  42. dataType: 'json'
  43. })
  44. .done(function(data) {
  45. ONEMAP.V.loading.loaded();
  46. if(data.code == 4){
  47. ONEMAP.C.noPermission('getDetailData');
  48. return false;
  49. }
  50. if(data.code == 3){
  51. ONEMAP.C.logout('getDetailData');
  52. }
  53. if(JSON.parse(data['data']['record'][modValue.options['field_name']]).length == 0){
  54. ONEMAP.C.publisher.publish({ type: 'warning', message: '没有图册数据' }, 'noteBar::add');
  55. remove();
  56. }else {
  57. ONEMAP.D.gcmsCurArticleData = data['data'];
  58. options.callback();
  59. }
  60. if(modValue.options['name']){
  61. $("#gcmsPicturesViewerTitleLabel .name").text(modValue.options['name'])
  62. }
  63. if(modValue.options['creater']){
  64. $("#gcmsPicturesViewerTitleLabel .creater").text(modValue.options['creater'])
  65. }
  66. if(modValue.options['phone_num']){
  67. $("#gcmsPicturesViewerTitleLabel .phone_num").text(modValue.options['phone_num'])
  68. }
  69. })
  70. .fail(function() {
  71. ONEMAP.V.loading.loaded();
  72. });
  73. }
  74. /**
  75. * 设置容器
  76. */
  77. function setPicturesModal(){
  78. var picturesData = JSON.parse(ONEMAP.D.gcmsCurArticleData['record'][modValue.options['field_name']]);
  79. modValue.picturesData = [];
  80. $(picturesData).each(function(index, el) {
  81. modValue.picturesData.push({
  82. title:'图片'+(index+1),
  83. thumbnail_url:onemapUrlConfig.gcmsServiceUrl+'/file/thumbnail'+el+'?w=200&h=100',
  84. img_url:onemapUrlConfig.gcmsServiceUrl+'/file'+el+'?jwt='+ONEMAP.D.user.ticket
  85. })
  86. });
  87. var template = Handlebars.compile(tpcLayout);
  88. $('body').append(template(modValue.picturesData));
  89. $('#gcmsPicturesList').css({
  90. width:modValue.picturesData.length*210
  91. })
  92. if(map23DData.display.map2D){
  93. $('#gcmsPicturesViewer').removeClass('TD');
  94. }else{
  95. $('#gcmsPicturesViewer').addClass('TD');
  96. }
  97. $('#gcmsPicturesModal').show();
  98. setTimeout(function(){
  99. $('#gcmsPicturesModal .modal-body').mCustomScrollbar({
  100. horizontalScroll:true
  101. });
  102. },300);
  103. }
  104. /**
  105. * 事件绑定
  106. * @return {[type]} [description]
  107. */
  108. function bindEvent(){
  109. layoutResize();
  110. $('#gcmsPicturesModal .modal-header .close').bind('click', function() {
  111. remove();
  112. });
  113. $('#gcmsPicturesViewer .modal-header .close').bind('click',function(){
  114. $("#gcmsPicturesViewer").hide();
  115. $('#gcmsPicturesList .selected').removeClass('selected');
  116. modValue.iviewer.iviewer('loadImage', onemapUrlConfig.siteLibUrl+'/images/bg_fff_1.png');
  117. });
  118. $('#gcmsPicturesList li').bind('click', function () {
  119. $('#gcmsPicturesList .selected').removeClass('selected');
  120. $(this).addClass('selected');
  121. $("#gcmsPicturesViewer").show();
  122. $('#gcmsPicturesViewerInfo .title').html(modValue.picturesData[$(this).attr('pid')]['title']);
  123. if(modValue.iviewer){
  124. modValue.iviewer.iviewer('loadImage', modValue.picturesData[$(this).attr('pid')]['img_url']);
  125. return false;
  126. }else {
  127. modValue.iviewer = $("#gcmsPicturesViewerBox").iviewer({
  128. zoom_max:200,
  129. zoom_min:5,
  130. src: modValue.picturesData[$(this).attr('pid')]['img_url'],
  131. onFinishLoad:function(){
  132. modValue.iviewer.iviewer('fit');
  133. }
  134. });
  135. }
  136. });
  137. $('#gcmsPicturesViewer .modal-header').dragmove($('#gcmsPicturesViewer'));
  138. var $box2 = $('#gcmsPicturesViewer').on('mousedown', '#coorForGcmsPicturesViewer', function(e) {
  139. var posix = {
  140. 'w': $box2.width(),
  141. 'h': $box2.height(),
  142. 'x': e.pageX,
  143. 'y': e.pageY
  144. };
  145. $.extend(document, {'move': true, 'call_down': function(e) {
  146. $box2.css({
  147. 'width': Math.max(30, e.pageX - posix.x + posix.w),
  148. 'height': Math.max(30, e.pageY - posix.y + posix.h)
  149. });
  150. var bodyHeight = Math.max(30, e.pageY - posix.y + posix.h )-67;
  151. var bodyWidth = Math.max(30, e.pageX - posix.x + posix.w);
  152. $("#gcmsPicturesViewer .modal-body").css({
  153. height:bodyHeight,
  154. width:bodyWidth
  155. });
  156. $("#gcmsPicturesViewerBox").iviewer('update');
  157. }});
  158. return false;
  159. });
  160. }
  161. /**
  162. * 界面布局重置
  163. * @type {Function}
  164. */
  165. function layoutResize(){
  166. $('#gcmsPicturesViewer .modal-body').css({
  167. height:$(window).height()/3*2,
  168. width:$(window).width()/2
  169. });
  170. }
  171. /**
  172. * 切换23D样式
  173. */
  174. function layoutResizeCSS(cid) {
  175. if (cid == '2d') {
  176. $('#gcmsPicturesViewer').removeClass('TD');
  177. } else {
  178. $('#gcmsPicturesViewer').addClass('TD');
  179. }
  180. }
  181. /**
  182. * 注册监听
  183. * @type {Function}
  184. */
  185. function subscribe(){
  186. ONEMAP.C.publisher.subscribe(layoutResize,'sideBarLayoutChange');
  187. ONEMAP.C.publisher.subscribe(remove,'gcmsArticleShowRemove');
  188. ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
  189. ONEMAP.C.publisher.subscribe(layoutResizeCSS, 'change23D');
  190. }
  191. /**
  192. * 取消监听
  193. * @type {Function}
  194. */
  195. function unSubscribe() {
  196. ONEMAP.C.publisher.unSubscribe(layoutResize,'sideBarLayoutChange');
  197. }
  198. /**
  199. * 模块移除
  200. * @return {[type]} [description]
  201. */
  202. function remove(){
  203. $('#gcmsPicturesModal').remove();
  204. $('#gcmsPicturesViewer').remove();
  205. unSubscribe();
  206. modValue.iviewer = null;
  207. }
  208. return ONEMAP.M.gcmsPictures = {
  209. init:init,
  210. remove:remove
  211. }
  212. });