sdutyplate.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. (function () {
  2. 'use strict';
  3. var app = angular.module('dsfapp');
  4. app.directive('onFinishRenderFilters', function ($timeout) {
  5. return {
  6. restrict: 'A',
  7. link: function (scope, element, attr) {
  8. if (scope.$last === true) {
  9. $timeout(function () {
  10. scope.$emit('ngRepeatFinished', scope);
  11. });
  12. }
  13. }
  14. };
  15. }).directive('bsLvtree1', function ($filter, $timeout, $ocLazyLoad, $compile) {
  16. //生成树型结构
  17. var bindtree = function (vtree, model) {
  18. angular.forEach(vtree, function (val, key) {
  19. val.children = $filter('filter')(model.data, function (fdata) {
  20. return fdata.pid == val.id;
  21. });
  22. model.treelength++;
  23. //默认不显示按钮
  24. val.showbtn = false;
  25. //查看最后一级
  26. if (model.xAxis[model.xAxis.length - 1].id == val.xid) {
  27. val.islast = true;
  28. } else {
  29. val.islast = false;
  30. }
  31. bindtree(val.children, model);
  32. });
  33. };
  34. var htmlXaxisbind = function (xaxis, $xAxispanel) {
  35. angular.forEach(xaxis, function (xval) {
  36. $xAxispanel.append('<div data-id="' + xval.id + '">' + xval.name + '</div>');
  37. });
  38. }
  39. //树形结构加入dom
  40. var htmltreebind = function (vtrees, $treepanel) {
  41. angular.forEach(vtrees, function (vtval) {
  42. var htmln = '<div class="tree_node" data-id="' + vtval.id + '" data-xid="' + vtval.xid + '">\r';
  43. htmln += '<div class="tree_head">\r';
  44. htmln += '\t<div data-id="' + vtval.id + '" ng-mouseover="overItem(this)" ng-mouseleave="leaveItem(this)" class="item_panel">\r';
  45. //第一排
  46. htmln += '<div class="item_col1">';
  47. htmln += '\t\t<a ng-click="btnclick(\'' + vtval.id + '\',1)" title="新增同级"><span class="glyphicon glyphicon-plus-sign"></span></a>';
  48. htmln += '</div >'
  49. //第二排
  50. htmln += '<div class="item_col2">';
  51. if (vtval.islast) {
  52. htmln += '\t\t<div class="item_chk"><input type="checkbox" name="chk" value="' + vtval.id + '" /></div>'
  53. }
  54. if (!vtval.islast) {
  55. htmln += '\t\t<a title="新增子级" ng-click="btnclick(\'' + vtval.id + '\',2)" class="item_col2_addchild"><span class="glyphicon glyphicon-chevron-right"></span></a>'
  56. }
  57. htmln += '\t\t<a ng-click="btnclick(\'' + vtval.id + '\',4)" title="' + vtval.name + '" class="item_div btn btn-success">' + vtval.name + '</a>\r';
  58. htmln += '</div >';
  59. //第三排
  60. htmln += '<div class="item_col3">';
  61. htmln += '\t\t<a ng-click="btnclick(\'' + vtval.id + '\',3)" title="删除节点"><span class="glyphicon glyphicon-minus-sign"></span></a>';
  62. htmln += '</div >';
  63. htmln += '\t\t</div>\r';
  64. htmln += '\t</div>\r';
  65. htmln += '</div>\r';
  66. var $tnode = $(htmln), $tpanel;
  67. $treepanel.append($tnode);
  68. if (vtval.children && vtval.children.length > 0) {
  69. $tpanel = $('<div class="tree_body"></div>');
  70. $tnode.append($tpanel);
  71. htmltreebind(vtval.children, $tpanel);
  72. }
  73. });
  74. };
  75. //画中间线
  76. var drawxAxisLine = function (ctx, xAxis, pheigth) {
  77. ctx.beginPath();
  78. ctx.lineWidth = 1;
  79. ctx.shadowBlur = 0;
  80. //ctx.setLineDash = [15,5];
  81. ctx.strokeStyle = '#000000';
  82. for (var i = 1; i < xAxis.length; i++) {
  83. ctx.moveTo(250 * i, 0);
  84. ctx.lineTo(250 * i, pheigth);
  85. ctx.stroke();
  86. }
  87. ctx.closePath();
  88. };
  89. //画对象之间的联线
  90. var drawRectToRectLine = function (ctx, vtreeit) {
  91. var $it, $cit;
  92. ctx.lineWidth = 1;
  93. ctx.shadowBlur = 0;
  94. ctx.strokeStyle = 'green';
  95. if (vtreeit.children && vtreeit.children.length > 0) {
  96. $it = $('.item_panel[data-id="' + vtreeit.id + '"]');
  97. angular.forEach(vtreeit.children, function (cv, ck) {
  98. $cit = $('.item_panel[data-id="' + cv.id + '"]');
  99. ctx.moveTo($it.position().left + $it.width() - 15, $it.position().top + $('.x_axis_div').height() + $it.height() / 2 - 9);
  100. ctx.lineTo($cit.position().left, $cit.position().top + $('.x_axis_div').height() + $cit.height() / 2 - 9);
  101. ctx.stroke();
  102. drawRectToRectLine(ctx, cv);
  103. });
  104. }
  105. };
  106. return {
  107. restrict: 'EA',
  108. require: '?ngModel',
  109. templateUrl: '../js/setting/sysduty/lv_tree.html',
  110. scope: {ngModel: '='},
  111. controller: function ($scope) {
  112. $ocLazyLoad.load('../js/setting/sysduty/sdutyplate.css');
  113. $scope.ngModel.xAxis = $filter('orderBy')($scope.ngModel.xAxis, '+id') || [{id: 0, name: '根节点'}];
  114. //第一层节点
  115. $scope.ngModel.treeNodes = $filter('filter')($scope.ngModel.data, function (val) {
  116. return val.xid == $scope.ngModel.xAxis[0].id;
  117. });
  118. $scope.ngModel.treelength = 0;
  119. $scope.ngModel.treeloadlength = 0;
  120. bindtree($scope.ngModel.treeNodes, $scope.ngModel);
  121. //btntype:{1:'新增同级',2:'新增子级',3:'删除节点',4:'查看节点'}
  122. $scope.btnclick = function (titem, btntype) {
  123. if ($scope.ngModel.btnclick) {
  124. $scope.ngModel.btnclick(titem, btntype);
  125. }
  126. };
  127. $scope.loadIncrease = function () {
  128. $scope.ngModel.treeloadlength++;
  129. };
  130. },
  131. link: function ($scope, $elem, $attrs) {
  132. //htmlXaxisbind($scope.ngModel.showxAxis, $elem.find('.x_axis_div'));
  133. //开始添加节点
  134. //htmltreebind($scope.ngModel.treeNodes, $elem.find('.tree_div'));
  135. //$compile($elem.find('.tree_div'))($scope);
  136. $scope.$watch('ngModel.treeloadlength', function () {
  137. if ($scope.ngModel.treelength == $scope.ngModel.treeloadlength) {
  138. $timeout(function () {
  139. //开始画图
  140. var cvs = $elem.find('.dutypanel>canvas')[0];
  141. cvs.width = $elem.find('.dutypanel').width();
  142. cvs.height = $elem.find('.dutypanel').height();
  143. var ctx = cvs.getContext('2d');
  144. drawxAxisLine(ctx, $scope.ngModel.xAxis, cvs.height);
  145. ctx.beginPath();
  146. angular.forEach($scope.ngModel.treeNodes, function (tn, tk) {
  147. drawRectToRectLine(ctx, tn);
  148. });
  149. ctx.closePath();
  150. ctx.save();
  151. }, 50);
  152. }
  153. });
  154. }
  155. }
  156. }).controller("sysDutyListCtrl1", function ($scope) {
  157. $scope.option = {
  158. xAxis: [{id: 0, name: '系统'}, {id: 1, name: '模块'}, {id: 2, name: '应用'}, {id: 3, name: '功能点'}],
  159. data: [{id: 'xx01', xid: 0, pid: null, name: '协同办公平台'}, {
  160. id: 'xx11',
  161. xid: 1,
  162. pid: 'xx01',
  163. name: '业务支持中心'
  164. }, {id: 'xx12', xid: 1, pid: 'xx01', name: '开发易'}, {
  165. id: 'xx111',
  166. xid: 2,
  167. pid: 'xx11',
  168. name: '数据修改'
  169. }, {id: 'xx112', xid: 2, pid: 'xx11', name: '数据查询'},
  170. {id: 'xx1111', xid: 3, pid: 'xx111', name: '工作台'}, {
  171. id: 'xx1112',
  172. xid: 3,
  173. pid: 'xx111',
  174. name: '修改申请'
  175. }, {id: 'xx1113', xid: 3, pid: 'xx111', name: '查询修改'}
  176. ],
  177. canEdit: false,
  178. canChecked: false
  179. };
  180. });
  181. //$(function () {
  182. //var ctx = $('#myCanvas')[0].getContext("2d");
  183. //ctx.strokeStyle = "#0000ff";
  184. //ctx.lineWidth = 1;
  185. //ctx.strokeRect(5, 5, 80, 60);
  186. //ctx.fillText("Hello World!",10,10);
  187. //ctx.save();
  188. //lvTree(option);
  189. //});
  190. //function lvTree(option) {
  191. // if (!option) {
  192. // return;
  193. // }
  194. // if (option.xAxis) {
  195. // var html_lv = '', html_sys = '', html_duty = '';
  196. // //添加标题头
  197. // $.each(option.xAxis, function (i, n) {
  198. // html_lv += '<div>'+ n.name+'</div>';
  199. // });
  200. // $('.x_axis_div').append(html_lv);
  201. // //添加系统
  202. // html_sys += '<div data-id="xx01" class="sys_div">';
  203. // $.each(option.xAxis, function (i, n) {
  204. // html_sys += '<div data-xid="'+ n.id +'"></div>';
  205. // });
  206. // html_sys += '</div>';
  207. // $('.x_axis_div').after(html_sys);
  208. // TreeItemAppend($('.dutypanel'), 0, option.data);
  209. // }
  210. //}
  211. //function TreeItemAppend($ParentTreeNode,xid,data) {
  212. // var htmlTree = '';
  213. // $.each(data, function (i, n) {
  214. // if (n.xid == xid) {
  215. // htmlTree += '<div class="tree_div tree_node" data-id="' + n.id + '" data-xid="' + n.xid + '">';
  216. // //treehead
  217. // htmlTree += '<div class="tree_head tree_div"><div class="item_div" data-id="' + n.id + '">' + n.name + '</div></div>';
  218. // htmlTree += '</div>';
  219. // $ParentTreeNode.append(htmlTree);
  220. // $.each(data, function (ci, cn) {
  221. // if (cn.pid == n.id) {
  222. // }
  223. // });
  224. // }
  225. // });
  226. //}
  227. })();