gcmsPicture.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /**
  2. * [ONEMAP.M.gcmsPicture]
  3. * @return {[object]}
  4. */
  5. define([
  6. 'html!templates/gcms/gcmsPicture',
  7. 'vendorDir/handlebars/handlebars',
  8. 'css!styles/gcms/gcmsPicture'],
  9. function(tpcLayout,Handlebars){
  10. //数据存放和外部调用
  11. var modValue = {
  12. options:{},
  13. iviewer:null,
  14. pictureUrl:null,
  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. setPictureModal();
  32. }});
  33. //订阅推送
  34. subscribe();
  35. }
  36. function getDetailData(options){
  37. ONEMAP.V.loading.load();
  38. $.ajax({
  39. url: onemapUrlConfig.gcmsServiceUrl+'/show/'+modValue.options['column_name']+'/'+modValue.options['article_id'],
  40. type:"GET",
  41. dataType: 'json'
  42. })
  43. .done(function(data) {
  44. ONEMAP.V.loading.loaded();
  45. if(data.code == 4){
  46. ONEMAP.C.noPermission('getDetailData');
  47. return false;
  48. }
  49. if(data.code == 3){
  50. ONEMAP.C.logout('getDetailData');
  51. }
  52. if(data['data']['record'][modValue.options['field_name']].length == 0){
  53. ONEMAP.C.publisher.publish({ type: 'warning', message: '没有图片数据' }, 'noteBar::add');
  54. remove();
  55. }else {
  56. ONEMAP.D.gcmsCurArticleData = data['data'];
  57. options.callback();
  58. }
  59. if(modValue.options['name']){
  60. $("#gcmsPictureViewerTitleLabel .name").text(modValue.options['name'])
  61. }
  62. if(modValue.options['creater']){
  63. $("#gcmsPictureViewerTitleLabel .creater").text(modValue.options['creater'])
  64. }
  65. if(modValue.options['phone_num']){
  66. $("#gcmsPictureViewerTitleLabel .phone_num").text(modValue.options['phone_num'])
  67. }
  68. if(modValue.options['ext']){
  69. $("#gcmsPictureViewerTitleLabel .ext").text(modValue.options['ext'])
  70. }
  71. })
  72. .fail(function() {
  73. ONEMAP.V.loading.loaded();
  74. });
  75. }
  76. /**
  77. * 设置容器
  78. */
  79. function setPictureModal(){
  80. var pictureData = ONEMAP.D.gcmsCurArticleData['record'][modValue.options['field_name']];
  81. modValue.pictureUrl = onemapUrlConfig.gcmsServiceUrl+'/file'+pictureData+'?jwt='+ONEMAP.D.user.ticket;
  82. $('body').append(tpcLayout);
  83. bindEvent();
  84. $('#gcmsPictureViewer').show();
  85. if(modValue.iviewer){
  86. modValue.iviewer.iviewer('loadImage', modValue.pictureUrl);
  87. return false;
  88. }else {
  89. modValue.iviewer = $("#gcmsPictureViewerBox").iviewer(
  90. {
  91. zoom_max:200,
  92. zoom_min:5,
  93. zoom:100,
  94. src: modValue.pictureUrl,
  95. update_on_resize:true,
  96. onFinishLoad:function(){
  97. modValue.iviewer.iviewer('fit');
  98. }
  99. });
  100. }
  101. }
  102. /**
  103. * 事件绑定
  104. * @return {[type]} [description]
  105. */
  106. function bindEvent(){
  107. layoutResize();
  108. $('#gcmsPictureViewer .close').bind('click', function() {
  109. remove();
  110. });
  111. // $('#gcmsPictureViewer .modal-header').dragmove($('#gcmsPictureViewer'));
  112. var $box2 = $('#gcmsPictureViewer').on('mousedown', '#coorForGcmsPictureViewer', function(e) {
  113. var posix = {
  114. 'w': $box2.width(),
  115. 'h': $box2.height(),
  116. 'x': e.pageX,
  117. 'y': e.pageY
  118. };
  119. $.extend(document, {'move': true, 'call_down': function(e) {
  120. $box2.css({
  121. 'width': Math.max(30, e.pageX - posix.x + posix.w),
  122. 'height': Math.max(30, e.pageY - posix.y + posix.h)
  123. });
  124. var bodyHeight = Math.max(30, e.pageY - posix.y + posix.h )-67;
  125. var bodyWidth = Math.max(30, e.pageX - posix.x + posix.w);
  126. $("#gcmsPictureViewer .modal-body").css({
  127. height:bodyHeight,
  128. width:bodyWidth
  129. });
  130. $("#gcmsPictureViewerBox").iviewer('update');
  131. }});
  132. return false;
  133. });
  134. //拖拽
  135. $("#gcmsPictureViewer .popup-ct").dragmove($('#gcmsPictureViewer'));
  136. }
  137. /**
  138. * 界面布局重置
  139. * @type {Function}
  140. */
  141. function layoutResize(){
  142. $('#gcmsPictureViewer .modal-body').css({
  143. height:$(window).height()/3*2,
  144. width:$(window).width()/2
  145. });
  146. }
  147. /**
  148. * 注册监听
  149. * @type {Function}
  150. */
  151. function subscribe(){
  152. ONEMAP.C.publisher.subscribe(layoutResize,'sideBarLayoutChange');
  153. ONEMAP.C.publisher.subscribe(remove,'gcmsArticleShowRemove');
  154. ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
  155. }
  156. /**
  157. * 取消监听
  158. * @type {Function}
  159. */
  160. function unSubscribe() {
  161. ONEMAP.C.publisher.unSubscribe(layoutResize,'sideBarLayoutChange');
  162. }
  163. /**
  164. * 模块移除
  165. * @return {[type]} [description]
  166. */
  167. function remove(){
  168. $('#gcmsPictureViewer').remove();
  169. unSubscribe();
  170. modValue.iviewer = null;
  171. }
  172. return ONEMAP.M.gcmsPicture = {
  173. init:init,
  174. remove:remove
  175. }
  176. });