common.js 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  1. /**
  2. * Created by onlyang on 2017/7/2.
  3. * es5
  4. */
  5. var Steer = {};
  6. (function ($, window, document) {
  7. Steer.utils = {
  8. // 参数Split
  9. paramsSplit: function (sparam, ssplit) {
  10. var sp = '', spd = '';
  11. if (sparam && sparam.length > 0) {
  12. if (!ssplit) { ssplit = ';;'; }
  13. var atp = sparam.split(ssplit);
  14. sp = atp[0];
  15. if (atp.length > 1) { spd = atp[1]; }
  16. }
  17. return [sp, spd];
  18. }
  19. };
  20. var STTable = {
  21. /*
  22. * 初始化表格
  23. * tid: 表格ID
  24. * data: 需要展示的数据
  25. * */
  26. init: function (tid, data) {
  27. mini.parse();
  28. let grid = mini.get(tid);
  29. let $table = $('#' + tid);
  30. if (!data) { data = []; }
  31. grid.setData(data);
  32. // 绑定所有数据
  33. $table.data('mini_all_data', data);
  34. // 过滤关闭按钮
  35. let clase = $('<span>', { class: 'el-icon-circle-close-outline' });
  36. $table.find('.mini-grid-filter').append(clase);
  37. $table.on('click', '.el-icon-circle-close-outline', function () {
  38. $(this).closest('.mini-textbox').find('.mini-textbox-input').val('');
  39. $.STTable.filterData(tid);
  40. });
  41. // 过滤事件
  42. $table.on('keyup', 'input.mini-textbox-input', function (event) {
  43. $.STTable.filterData(tid);
  44. });
  45. // 合计信息
  46. let smInfo = $('<div>', {
  47. class: 'mini-table-sum',
  48. id: tid + '_sum'
  49. });
  50. $table.after(smInfo);
  51. $.STTable.setSumInfo(tid, data.length, data.length);
  52. },
  53. setSumInfo: function (tid, current, all) {
  54. $('#' + tid + '_sum').text(current + ' / ' + all);
  55. },
  56. /*
  57. * 设置表格数据
  58. * tid: 表格ID
  59. * data: 需要展示的数据
  60. * bFilter:不重置过滤条件(默认重置)
  61. * */
  62. setData: function (tid, data, bFilter) {
  63. let grid = mini.get(tid);
  64. if (!data) { data = []; }
  65. grid.setData(data);
  66. grid.scrollIntoView(0);
  67. $.STTable.setSumInfo(tid, data.length, data.length);
  68. // 绑定所有数据
  69. $('#' + tid).data('mini_all_data', data);
  70. if (!bFilter) {
  71. $('#' + tid).find('.mini-grid-filter').find('input.mini-textbox-input').val('');
  72. }
  73. },
  74. filterData: function (tid) {
  75. let $table = $('#' + tid);
  76. let data = $table.data('mini_all_data');
  77. // if (event && event.keyCode === 13) {
  78. let inps = $table.find('input.mini-textbox-input');
  79. let fobjs = {};
  80. $.each(inps, function (i, n) {
  81. let $in = $(n);
  82. let val = $in.val();
  83. if (val && val.length > 0) {
  84. let _name = $in.attr('name');
  85. fobjs[_name] = val;
  86. }
  87. });
  88. let cData = [];
  89. cData = data.filter(function (v) {
  90. let flag = true;
  91. $.each(fobjs, function (ci, cn) {
  92. if ((v[ci] + '').indexOf(cn) < 0) {
  93. flag = false;
  94. return false;
  95. }
  96. });
  97. return flag;
  98. });
  99. let grid = mini.get(tid);
  100. grid.setData(cData);
  101. grid.scrollIntoView(0);
  102. $.STTable.setSumInfo(tid, cData.length, data.length);
  103. }
  104. };
  105. $.STTable = STTable;
  106. /*
  107. * SSlider 模拟Slider
  108. * @param {string} sActive 'show'显示,'hide'隐藏
  109. * @oInit
  110. * title: 标题
  111. * level: 2
  112. * width: 200
  113. * closeCallback: fn
  114. * @example $('#').slider('show');
  115. */
  116. var SSlider = function (sAction, oInit) {
  117. // 执行体
  118. var $thats = this;
  119. if (!$thats || $thats.length <= 0) {
  120. return;
  121. }
  122. var $that = $thats.first();
  123. if (sAction === 'show') {
  124. var iZIndex = 1900;
  125. if (oInit) {
  126. if (oInit.title) {
  127. $that.children('.sui-slider-main').children('.sui-slider-title').find('.sui-slider-title-text').text(oInit.title);
  128. }
  129. if (oInit.level > 1) {
  130. iZIndex += 10 * oInit.level;
  131. var ih = 800;
  132. if (oInit.width > 0) {
  133. ih = oInit.width;
  134. } else {
  135. ih = 800 - 100 * (oInit.level - 1);
  136. if (ih < 200) { ih = 200; }
  137. }
  138. $that.children('.sui-slider-main').css({'width': ih + 'px', 'z-index': iZIndex + 2});
  139. $that.children('.sui-slider-cover').css({'z-index': iZIndex + 1});
  140. }
  141. }
  142. $that.css('z-index', iZIndex);
  143. SSlider.prototype._showSlider($that, oInit);
  144. } else {
  145. SSlider.prototype._hideSlider($that, oInit);
  146. }
  147. };
  148. // 隐藏Slider
  149. SSlider.prototype._hideSlider = function ($slider, oInit) {
  150. $slider.children('.sui-slider-main').removeClass('sui-slider-in').removeClass('sui-slider-active').addClass('sui-slider-out');
  151. setTimeout(function () {
  152. $slider.hide();
  153. // $c.remove(); //移除遮盖层
  154. var sliderActives = $('.sui-slider-active');
  155. if (!sliderActives || sliderActives.length <= 0) {
  156. $('body').removeClass('sui-slider-body');
  157. }
  158. if (oInit && oInit.closeCallback) {
  159. oInit.closeCallback.call(null);
  160. }
  161. }, 300);
  162. };
  163. // 显示Slider
  164. SSlider.prototype._showSlider = function ($slider, oInit) {
  165. $('body').addClass('sui-slider-body');// body不再滚动
  166. // 显示遮盖层及绑定事件
  167. $slider.children('.sui-slider-cover').not('.sui-slider-evented').on('click', function () {
  168. SSlider.prototype._hideSlider($slider, oInit);
  169. }).addClass('sui-slider-evented');
  170. $slider.children('.sui-slider-main').removeClass('sui-slider-out').addClass('sui-slider-in').addClass('sui-slider-active');
  171. $slider.children('.sui-slider-main').children('.sui-slider-title').find('.sui-slider-title-x').not('.sui-slider-evented').on('click', function () {
  172. SSlider.prototype._hideSlider($slider, oInit);
  173. }).addClass('sui-slider-evented');
  174. $slider.show();
  175. };
  176. // jquery aliases 别名
  177. $.fn.slider = SSlider;
  178. }(jQuery, window, document));
  179. /*
  180. * 验证码
  181. * */
  182. (function () {
  183. var randstr = function (length) {
  184. var key = {
  185. str: [
  186. // 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
  187. // 'o', 'p', 'q', 'r', 's', 't', 'x', 'u', 'v', 'y', 'z', 'w', 'n',
  188. '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
  189. ],
  190. randint: function (n, m) {
  191. var c = m - n + 1;
  192. var num = Math.random() * c + n;
  193. return Math.floor(num);
  194. },
  195. randStr: function () {
  196. var _this = this;
  197. var leng = _this.str.length - 1;
  198. var randkey = _this.randint(0, leng);
  199. return _this.str[randkey];
  200. },
  201. create: function (len) {
  202. var _this = this;
  203. var l = len || 10;
  204. var str = '';
  205. for (var i = 0; i < l; i++) {
  206. str += _this.randStr();
  207. }
  208. return str;
  209. }
  210. };
  211. length = length > 0 ? length : 10;
  212. return key.create(length);
  213. };
  214. var randint = function (n, m) {
  215. var c = m - n + 1;
  216. var num = Math.random() * c + n;
  217. return Math.floor(num);
  218. };
  219. var VCode = function (dom, options) {
  220. this.codeDoms = [];
  221. this.lineDoms = [];
  222. this.initOptions(options);
  223. this.dom = dom;
  224. this.init();
  225. this.addEvent();
  226. this.update();
  227. this.mask();
  228. };
  229. VCode.prototype.init = function () {
  230. this.dom.style.position = 'relative';
  231. this.dom.style.overflow = 'hidden';
  232. this.dom.style.cursor = 'pointer';
  233. this.dom.title = '点击更换验证码';
  234. this.dom.style.background = this.options.bgColor;
  235. /*
  236. alert(this.options.width);
  237. alert(this.dom.clientWidth>0?this.dom.clientWidth:40); clientHeight
  238. */
  239. this.w = this.options.width > 0 ? this.options.width : (this.dom.clientWidth > 0 ? this.dom.clientWidth > 0 : 100);
  240. this.h = this.options.height > 0 ? this.options.height : (this.dom.clientHeight > 0 ? this.dom.clientHeight > 0 : 40);
  241. this.uW = this.w / this.options.len;
  242. };
  243. VCode.prototype.mask = function () {
  244. var dom = document.createElement('div');
  245. dom.style.cssText = [
  246. 'width: 100%',
  247. 'height: 100%',
  248. 'left: 0',
  249. 'top: 0',
  250. 'position: absolute',
  251. 'cursor: pointer',
  252. 'z-index: 9999999'
  253. ].join(';');
  254. dom.title = '点击更换验证码';
  255. this.dom.appendChild(dom);
  256. };
  257. VCode.prototype.addEvent = function () {
  258. var _this = this;
  259. _this.dom.addEventListener('click', function () {
  260. // _this.update.call(_this);
  261. _this.update();
  262. });
  263. };
  264. VCode.prototype.initOptions = function (options) {
  265. var FunctionOptons = function () {
  266. this.len = 4;
  267. this.fontSizeMin = 24;
  268. this.fontSizeMax = 28;
  269. this.colors = [
  270. 'green',
  271. 'red',
  272. 'blue',
  273. '#53da33',
  274. '#AA0000',
  275. '#FFBB00'
  276. ];
  277. this.bgColor = '#f6f6f6';
  278. this.fonts = [
  279. 'Times New Roman',
  280. 'Georgia',
  281. 'Serif',
  282. 'sans-serif',
  283. 'arial',
  284. 'tahoma',
  285. 'Hiragino Sans GB'
  286. ];
  287. this.lines = 8;
  288. this.lineColors = [
  289. '#888888',
  290. '#FF7744',
  291. '#888800',
  292. '#008888'
  293. ];
  294. this.lineHeightMin = 1;
  295. this.lineHeightMax = 2;
  296. this.lineWidthMin = 1;
  297. this.lineWidthMax = 30;
  298. };
  299. this.options = new FunctionOptons();
  300. if (typeof options === 'object') {
  301. for (var i in options) {
  302. this.options[i] = options[i];
  303. }
  304. }
  305. };
  306. VCode.prototype.update = function () {
  307. for (var i = 0; i < this.codeDoms.length; i++) {
  308. this.dom.removeChild(this.codeDoms[i]);
  309. }
  310. for (var j = 0; j < this.lineDoms.length; j++) {
  311. this.dom.removeChild(this.lineDoms[j]);
  312. }
  313. this.createCode();
  314. this.draw();
  315. };
  316. VCode.prototype.createCode = function () {
  317. this.code = randstr(this.options.len);
  318. };
  319. VCode.prototype.verify = function (code) {
  320. return this.code === (code ? code.toLowerCase() : code);
  321. };
  322. VCode.prototype.draw = function () {
  323. this.codeDoms = [];
  324. for (var i = 0; i < this.code.length; i++) {
  325. this.codeDoms.push(this.drawCode(this.code[i], i));
  326. }
  327. this.drawLines();
  328. };
  329. VCode.prototype.drawCode = function (code, index) {
  330. var dom = document.createElement('span');
  331. dom.style.cssText = [
  332. 'font-size:' + randint(this.options.fontSizeMin, this.options.fontSizeMax) + 'px',
  333. 'color:' + this.options.colors[randint(0, this.options.colors.length - 1)],
  334. 'position: absolute',
  335. 'left:' + randint(this.uW * index, this.uW * index + this.uW - 15) + 'px',
  336. 'top:' + randint(0, 5) + 'px',
  337. 'transform:rotate(' + randint(-20, 20) + 'deg)',
  338. '-ms-transform:rotate(' + randint(-20, 20) + 'deg)',
  339. '-moz-transform:rotate(' + randint(-20, 20) + 'deg)',
  340. '-webkit-transform:rotate(' + randint(-20, 20) + 'deg)',
  341. '-o-transform:rotate(' + randint(-20, 20) + 'deg)',
  342. 'font-family:' + this.options.fonts[randint(0, this.options.fonts.length - 1)],
  343. 'font-weight:' + randint(500, 900)
  344. ].join(';');
  345. dom.innerHTML = code;
  346. this.dom.appendChild(dom);
  347. return dom;
  348. };
  349. VCode.prototype.drawLines = function () {
  350. this.lineDoms = [];
  351. for (var i = 0; i < this.options.lines; i++) {
  352. var dom = document.createElement('div');
  353. dom.style.cssText = [
  354. 'position: absolute',
  355. 'opacity: ' + randint(3, 5) / 10,
  356. 'width:' + randint(this.options.lineWidthMin, this.options.lineWidthMax) + 'px',
  357. 'height:' + randint(this.options.lineHeightMin, this.options.lineHeightMax) + 'px',
  358. 'background: ' + this.options.lineColors[randint(0, this.options.lineColors.length - 1)],
  359. 'left:' + randint(0, this.w - 20) + 'px',
  360. 'top:' + randint(0, this.h) + 'px',
  361. 'transform:rotate(' + randint(-30, 30) + 'deg)',
  362. '-ms-transform:rotate(' + randint(-30, 30) + 'deg)',
  363. '-moz-transform:rotate(' + randint(-30, 30) + 'deg)',
  364. '-webkit-transform:rotate(' + randint(-30, 30) + 'deg)',
  365. '-o-transform:rotate(' + randint(-30, 30) + 'deg)',
  366. 'font-family:' + this.options.fonts[randint(0, this.options.fonts.length - 1)],
  367. 'font-weight:' + randint(400, 900)
  368. ].join(';');
  369. this.dom.appendChild(dom);
  370. this.lineDoms.push(dom);
  371. }
  372. };
  373. this.VCode = VCode;
  374. }).call(this);
  375. /**
  376. * 组织结构图
  377. * @Author: ouyang
  378. */
  379. (function ($) {
  380. $.fn.jOrgChart = function (options) {
  381. var opts = $.extend({}, $.fn.jOrgChart.defaults, options);
  382. var $this = $(this);
  383. if (!$this || $this.length <= 0) { return false; }
  384. $this.empty();
  385. var $showlist = $("<ul id='org' style='display:none'></ul>");
  386. _showall(options.data, $showlist, opts);
  387. $this.append($showlist);
  388. // build the tree
  389. var $org = $('#org');
  390. var $container = $('<div class="' + opts.chartClass + '"/>');
  391. if ($org.is('ul')) {
  392. buildNode($org.find('li:first'), $container, 0, opts);
  393. } else if ($org.is('li')) {
  394. buildNode($org, $container, 0, opts);
  395. }
  396. $this.append($container);
  397. };
  398. // Option defaults
  399. $.fn.jOrgChart.defaults = {
  400. depth: -1,
  401. chartClass: 'jOrgChart', // CLASS
  402. expandAble: true, // 是否展开/收缩
  403. module: { // 数据模型
  404. id: 'id',
  405. pid: 'pid',
  406. name: 'name',
  407. children: 'children'
  408. }
  409. };
  410. function _showall (oList, $parent, opts) {
  411. $.each(oList, function (index, val) {
  412. var aChildren = val[opts.module.children];
  413. var $a = $('<a title="' + val[opts.module.name] + '" href="javascript:void(0)">' + val[opts.module.name] + '</a>').data('node_data', val);
  414. if (aChildren && aChildren.length > 0) {
  415. var $li = $('<li></li>');
  416. $li.append($a).append('<ul></ul>').appendTo($parent);
  417. // 递归显示
  418. _showall(aChildren, $li.children('ul'), opts);
  419. } else {
  420. $('<li></li>').append($a).appendTo($parent);
  421. }
  422. });
  423. }
  424. var nodeCount = 0;
  425. // Method that recursively builds the tree
  426. function buildNode ($node, $appendTo, level, opts) {
  427. var $table = $('<table cellpadding="0" cellspacing="0" border="0"/>');
  428. var $tbody = $('<tbody/>');
  429. // Construct the node container(s)
  430. var $nodeRow = $('<tr/>').addClass('node-cells');
  431. var $nodeCell = $('<td/>').addClass('node-cell').attr('colspan', 2);
  432. var $childNodes = $node.children('ul:first').children('li');
  433. var $nodeDiv;
  434. if ($childNodes.length > 1) {
  435. $nodeCell.attr('colspan', $childNodes.length * 2);
  436. }
  437. // Draw the node
  438. // Get the contents - any markup except li and ul allowed
  439. var $nodeContent = $node.clone()
  440. .children('ul,li')
  441. .remove()
  442. .end()
  443. .html();
  444. // Increaments the node count which is used to link the source list and the org chart
  445. nodeCount++;
  446. $node.data('tree-node', nodeCount);
  447. $nodeDiv = $('<div>').addClass('node')
  448. .data('tree-node', nodeCount)
  449. .append($nodeContent);
  450. if (opts.clickCallback && typeof opts.clickCallback === 'function') {
  451. $nodeDiv.on('click', function () {
  452. $('.jOrgChart').find('div').css('border-color', 'black')
  453. $('.jOrgChart').find('div a').css('color', 'black')
  454. $nodeDiv.css('border-color', 'red')
  455. $nodeDiv.find('a').css('color', 'red')
  456. opts.clickCallback($node.children('a').data('node_data'));
  457. });
  458. }
  459. // Expand and contract nodes
  460. if (opts.expandAble && $childNodes.length > 0) {
  461. $nodeDiv.on('click', function () {
  462. var $this = $(this);
  463. var $tr = $this.closest('tr');
  464. if ($tr.hasClass('contracted')) {
  465. $this.css('cursor', 'n-resize');
  466. $tr.removeClass('contracted').addClass('expanded');
  467. $tr.nextAll('tr').css('visibility', '');
  468. // Update the <li> appropriately so that if the tree redraws collapsed/non-collapsed nodes
  469. // maintain their appearance
  470. $node.removeClass('collapsed');
  471. } else {
  472. $this.css('cursor', 's-resize');
  473. $tr.removeClass('expanded').addClass('contracted');
  474. $tr.nextAll('tr').css('visibility', 'hidden');
  475. $node.addClass('collapsed');
  476. }
  477. });
  478. }
  479. $nodeCell.append($nodeDiv);
  480. $nodeRow.append($nodeCell);
  481. $tbody.append($nodeRow);
  482. if ($childNodes.length > 0) {
  483. // if it can be expanded then change the cursor
  484. $nodeDiv.css('cursor', 'n-resize');
  485. // recurse until leaves found (-1) or to the level specified
  486. if (opts.depth === -1 || (level + 1 < opts.depth)) {
  487. var $downLineRow = $('<tr/>');
  488. var $downLineCell = $('<td/>').attr('colspan', $childNodes.length * 2);
  489. $downLineRow.append($downLineCell);
  490. // draw the connecting line from the parent node to the horizontal line
  491. var $downLine = $('<div></div>').addClass('line down');
  492. $downLineCell.append($downLine);
  493. $tbody.append($downLineRow);
  494. // Draw the horizontal lines
  495. var $linesRow = $('<tr/>');
  496. $childNodes.each(function () {
  497. var $left = $('<td>&nbsp;</td>').addClass('line left top');
  498. var $right = $('<td>&nbsp;</td>').addClass('line right top');
  499. $linesRow.append($left).append($right);
  500. });
  501. // horizontal line shouldn't extend beyond the first and last child branches
  502. $linesRow.find('td:first')
  503. .removeClass('top')
  504. .end()
  505. .find('td:last')
  506. .removeClass('top');
  507. $tbody.append($linesRow);
  508. var $childNodesRow = $('<tr/>');
  509. $childNodes.each(function () {
  510. var $td = $('<td class="node-container"/>');
  511. $td.attr('colspan', 2);
  512. // recurse through children lists and items
  513. buildNode($(this), $td, level + 1, opts);
  514. $childNodesRow.append($td);
  515. });
  516. }
  517. $tbody.append($childNodesRow);
  518. }
  519. // any classes on the LI element get copied to the relevant node in the tree
  520. // apart from the special 'collapsed' class, which collapses the sub-tree at this point
  521. if ($node.attr('class') !== undefined) {
  522. var classList = $node.attr('class').split(/\s+/);
  523. $.each(classList, function (index, item) {
  524. if (item === 'collapsed') {
  525. // console.log($node);
  526. $nodeRow.nextAll('tr').css('visibility', 'hidden');
  527. $nodeRow.removeClass('expanded');
  528. $nodeRow.addClass('contracted');
  529. $nodeDiv.css('cursor', 's-resize');
  530. } else {
  531. $nodeDiv.addClass(item);
  532. }
  533. });
  534. }
  535. $table.append($tbody);
  536. $appendTo.append($table);
  537. /* Prevent trees collapsing if a link inside a node is clicked */
  538. // $nodeDiv.children('a').click(function(e){
  539. // console.log(e);
  540. // e.stopPropagation();
  541. // });
  542. };
  543. })(jQuery);
  544. /**
  545. * 物料进程图-竖版 : 支持点击展示弹出框
  546. */
  547. (function ($) {
  548. $.fn.jProcessChartCol = function (options) {
  549. var opts = $.extend({}, $.fn.jProcessChartCol.defaults, options);
  550. var $this = $(this);
  551. if (!$this || $this.length <= 0) { return false; }
  552. $this.empty();
  553. var $showlist = $("<ul id='org' style='display:none'></ul>");
  554. _showall(options.data, $showlist, opts);
  555. $this.append($showlist);
  556. // build the tree
  557. var $org = $('#org');
  558. var $container = $('<div class="' + opts.chartClass + '"/>');
  559. if ($org.is('ul')) {
  560. buildNode($org.find('li:first'), $container, 0, opts);
  561. } else if ($org.is('li')) {
  562. buildNode($org, $container, 0, opts);
  563. }
  564. $this.append($container);
  565. };
  566. // Option defaults
  567. $.fn.jProcessChartCol.defaults = {
  568. depth: -1,
  569. chartClass: 'jOrgChart jProcessChartCol', // CLASS
  570. expandAble: true, // 是否展开/收缩
  571. module: { // 数据模型
  572. id: 'id',
  573. pid: 'pid',
  574. current: 'current',
  575. name: 'name',
  576. children: 'children'
  577. }
  578. };
  579. function _showall (oList, $parent, opts) {
  580. $.each(oList, function (index, val) {
  581. var aChildren = val[opts.module.children];
  582. var aSelf = val[opts.module.name];
  583. var aHighLight = val[opts.module.current];
  584. if (aChildren && aChildren.length > 0) {
  585. var $li = $('<li></li>');
  586. var $lidiv = $('<div></div>');
  587. for (let i = 0; i < aSelf.length; i++) {
  588. aSelf[i].remark = aSelf[i].remark ? aSelf[i].remark : '';
  589. aSelf[i].create_time = aSelf[i].create_time ? aSelf[i].create_time : '';
  590. aSelf[i].name = aSelf[i].name ? aSelf[i].name : '';
  591. aSelf[i].object_no = aSelf[i].object_no ? aSelf[i].object_no : '';
  592. aSelf[i].create_man_name = aSelf[i].create_man_name ? aSelf[i].create_man_name : '';
  593. var $a = $('<a title="' + aSelf[i].prc_code_desc + ':' + aSelf[i].create_man_name + '" href="javascript:void(0)"><div class="jProcessChartColDetail" style="display: none">' +
  594. '操作人:' + aSelf[i].create_man_name +
  595. '</br>' + '备注:' + aSelf[i].remark +
  596. '</div></br>' + aSelf[i].prc_code_desc + ':' + aSelf[i].create_man_name + '</br>' + aSelf[i].create_time + '</a>').data('node_data', aSelf[i]);
  597. if (i === 0) { // 每个节点的第一项才显示编号
  598. $a = $('<a title="' + aSelf[i].prc_code_desc + ':' + aSelf[i].create_man_name + '" href="javascript:void(0)"><div class="jProcessChartColDetail" style="display: none"><span>' +
  599. '操作人:' + aSelf[i].create_man_name +
  600. '</span></br><span>' + '备注:' + aSelf[i].remark +
  601. '</span></div>' + aSelf[i].object_no + '</br>' + aSelf[i].prc_code_desc + ':' + aSelf[i].create_man_name + '</br>' + aSelf[i].create_time + '</a>').data('node_data', aSelf[i]);
  602. }
  603. var $lidivchild = $('<div class="jProcessChartColDiv"></div>');
  604. if (aHighLight) { // 高亮
  605. $lidivchild.addClass('jProcessChartColDivCurrent')
  606. }
  607. $lidivchild.append($a).appendTo($lidiv);
  608. $lidivchild.appendTo($lidiv);
  609. }
  610. $lidiv.appendTo($li);
  611. $li.append('<ul></ul>').appendTo($parent);
  612. // 递归显示
  613. _showall(aChildren, $li.children(':eq(1)'), opts);
  614. } else { // 叶子结点
  615. $li = $('<li></li>');
  616. $lidiv = $('<div></div>');
  617. for (let i = 0; i < aSelf.length; i++) {
  618. aSelf[i].remark = aSelf[i].remark ? aSelf[i].remark : '';
  619. aSelf[i].create_time = aSelf[i].create_time ? aSelf[i].create_time : '';
  620. aSelf[i].name = aSelf[i].name ? aSelf[i].name : '';
  621. aSelf[i].object_no = aSelf[i].object_no ? aSelf[i].object_no : '';
  622. aSelf[i].create_man_name = aSelf[i].create_man_name ? aSelf[i].create_man_name : '';
  623. $a = $('<a title="' + aSelf[i].prc_code_desc + ':' + aSelf[i].create_man_name + '" href="javascript:void(0)"><div class="jProcessChartColDetail" style="display: none">' +
  624. '操作人:' + aSelf[i].create_man_name +
  625. '</br>' + '备注:' + aSelf[i].remark +
  626. '</div></br>' + aSelf[i].prc_code_desc + ':' + aSelf[i].create_man_name + '</br>' + aSelf[i].create_time + '</a>').data('node_data', aSelf[i]);
  627. if (i === 0) {
  628. $a = $('<a title="' + aSelf[i].prc_code_desc + ':' + aSelf[i].create_man_name + '" href="javascript:void(0)"><div class="jProcessChartColDetail" style="display: none">' +
  629. '操作人:' + aSelf[i].create_man_name +
  630. '</br>' + '备注:' + aSelf[i].remark +
  631. '</div>' + aSelf[i].object_no + '</br>' + aSelf[i].prc_code_desc + ':' + aSelf[i].create_man_name + '</br>' + aSelf[i].create_time + '</a>').data('node_data', aSelf[i]);
  632. }
  633. $lidivchild = $('<div class="jProcessChartColDiv"></div>');
  634. if (aHighLight) {
  635. $lidivchild.addClass('jProcessChartColDivCurrent')
  636. }
  637. $lidivchild.append($a).appendTo($lidiv);
  638. // $('<li></li>').append($a).appendTo($parent);
  639. }
  640. $lidiv.appendTo($li);
  641. $li.append('<ul></ul>').appendTo($parent);
  642. }
  643. });
  644. }
  645. var nodeCount = 0;
  646. // Method that recursively builds the tree
  647. function buildNode ($node, $appendTo, level, opts) {
  648. var $table = $('<table cellpadding="0" cellspacing="0" border="0"/>');
  649. var $tbody = $('<tbody/>');
  650. // Construct the node container(s)
  651. var $nodeRow = $('<tr/>').addClass('node-cells');
  652. var $nodeCell = $('<td/>').addClass('node-cell').attr('colspan', 2);
  653. var $childNodes = $node.children('ul:first').children('li');
  654. var $nodeDiv;
  655. if ($childNodes.length > 1) {
  656. $nodeCell.attr('colspan', $childNodes.length * 2);
  657. }
  658. // Draw the node
  659. // Get the contents - any markup except li and ul allowed
  660. var $nodeContent = $node.clone()
  661. .children('ul,li')
  662. .remove()
  663. .end()
  664. .html();
  665. // console.log('$nodeContent', $nodeContent);
  666. // Increaments the node count which is used to link the source list and the org chart
  667. nodeCount++;
  668. $node.data('tree-node', nodeCount);
  669. $nodeDiv = $('<div>').addClass('node')
  670. .data('tree-node', nodeCount)
  671. .append($nodeContent);
  672. $nodeDiv.find('.jProcessChartColDiv').on('click', function (e) { // 点击展示弹出框
  673. if ($(e.target).children(':first').css('display') === 'block') {
  674. $(e.target).children(':first').css('display', 'none');
  675. $('.jProcessChartCol').find('.jProcessChartColDetail').hide(); // 关闭其他弹出框
  676. } else {
  677. $('.jProcessChartCol').find('.jProcessChartColDetail').hide(); // 关闭其他弹出框
  678. $(e.target).children(':first').css('display', 'block');
  679. }
  680. });
  681. if (opts.clickCallback && typeof opts.clickCallback === 'function') {
  682. $nodeDiv.on('click', function () {
  683. // $('.jProcessChart').find('div').css('border-color', 'black')
  684. // $('.jProcessChart').find('div a').css('color', 'black')
  685. // $nodeDiv.css('border-color', 'red')
  686. // $nodeDiv.find('a').css('color', 'red')
  687. // opts.clickCallback($node.children('a').data('node_data'));
  688. });
  689. }
  690. // Expand and contract nodes
  691. if (opts.expandAble && $childNodes.length > 0) {
  692. $nodeDiv.on('click', function () {
  693. var $this = $(this);
  694. var $tr = $this.closest('tr');
  695. if ($tr.hasClass('contracted')) {
  696. $this.css('cursor', 'n-resize');
  697. $tr.removeClass('contracted').addClass('expanded');
  698. $tr.nextAll('tr').css('visibility', '');
  699. // Update the <li> appropriately so that if the tree redraws collapsed/non-collapsed nodes
  700. // maintain their appearance
  701. $node.removeClass('collapsed');
  702. } else {
  703. $this.css('cursor', 's-resize');
  704. $tr.removeClass('expanded').addClass('contracted');
  705. $tr.nextAll('tr').css('visibility', 'hidden');
  706. $node.addClass('collapsed');
  707. }
  708. });
  709. }
  710. $nodeCell.append($nodeDiv);
  711. $nodeRow.append($nodeCell);
  712. $tbody.append($nodeRow);
  713. if ($childNodes.length > 0) {
  714. // if it can be expanded then change the cursor
  715. $nodeDiv.css('cursor', 'n-resize');
  716. // recurse until leaves found (-1) or to the level specified
  717. if (opts.depth === -1 || (level + 1 < opts.depth)) {
  718. var $downLineRow = $('<tr/>');
  719. var $downLineCell = $('<td/>').attr('colspan', $childNodes.length * 2);
  720. $downLineRow.append($downLineCell);
  721. // draw the connecting line from the parent node to the horizontal line
  722. var $downLine = $('<div></div>').addClass('line down');
  723. $downLineCell.append($downLine);
  724. $tbody.append($downLineRow);
  725. // Draw the horizontal lines
  726. var $linesRow = $('<tr/>');
  727. $childNodes.each(function () {
  728. var $left = $('<td>&nbsp;</td>').addClass('line left top');
  729. var $right = $('<td>&nbsp;</td>').addClass('line right top');
  730. $linesRow.append($left).append($right);
  731. });
  732. // horizontal line shouldn't extend beyond the first and last child branches
  733. $linesRow.find('td:first')
  734. .removeClass('top')
  735. .end()
  736. .find('td:last')
  737. .removeClass('top');
  738. $tbody.append($linesRow);
  739. var $childNodesRow = $('<tr/>');
  740. $childNodes.each(function () {
  741. var $td = $('<td class="node-container"/>');
  742. $td.attr('colspan', 2);
  743. // recurse through children lists and items
  744. buildNode($(this), $td, level + 1, opts);
  745. $childNodesRow.append($td);
  746. });
  747. }
  748. $tbody.append($childNodesRow);
  749. }
  750. // any classes on the LI element get copied to the relevant node in the tree
  751. // apart from the special 'collapsed' class, which collapses the sub-tree at this point
  752. if ($node.attr('class') !== undefined) {
  753. var classList = $node.attr('class').split(/\s+/);
  754. $.each(classList, function (index, item) {
  755. if (item === 'collapsed') {
  756. // console.log($node);
  757. $nodeRow.nextAll('tr').css('visibility', 'hidden');
  758. $nodeRow.removeClass('expanded');
  759. $nodeRow.addClass('contracted');
  760. $nodeDiv.css('cursor', 's-resize');
  761. } else {
  762. $nodeDiv.addClass(item);
  763. }
  764. });
  765. }
  766. $table.append($tbody);
  767. $appendTo.append($table);
  768. /* Prevent trees collapsing if a link inside a node is clicked */
  769. // $nodeDiv.children('a').click(function(e){
  770. // console.log(e);
  771. // e.stopPropagation();
  772. // });
  773. };
  774. })(jQuery);
  775. /**
  776. * 物料进程图-横版 : 支持点击展示弹出框
  777. */
  778. // (function ($) {
  779. // $.fn.jProcessChartRow = function (options) {
  780. // var opts = $.extend({}, $.fn.jProcessChartRow.defaults, options);
  781. // var $this = $(this);
  782. // if (!$this || $this.length <= 0) { return false; }
  783. // $this.empty();
  784. //
  785. // var $showlist = $("<ul id='org' style='display:none'></ul>");
  786. // _showall(options.data, $showlist, opts);
  787. // $this.append($showlist);
  788. //
  789. // // build the tree
  790. // var $org = $('#org');
  791. // var $container = $('<div class="' + opts.chartClass + '"/>');
  792. // if ($org.is('ul')) {
  793. // buildNode($org.find('li:first'), $container, 0, opts);
  794. // } else if ($org.is('li')) {
  795. // buildNode($org, $container, 0, opts);
  796. // }
  797. // $this.append($container);
  798. // };
  799. //
  800. // // Option defaults
  801. // $.fn.jProcessChartRow.defaults = {
  802. // depth: -1,
  803. // chartClass: 'jOrgChart jProcessChartRow', // CLASS
  804. // expandAble: true, // 是否展开/收缩
  805. // module: { // 数据模型
  806. // id: 'id',
  807. // pid: 'pid',
  808. // name: 'name',
  809. // children: 'children'
  810. // }
  811. // };
  812. //
  813. // function _showall (oList, $parent, opts) {
  814. // $.each(oList, function (index, val) {
  815. // var aChildren = val[opts.module.children];
  816. // var aSelf = val[opts.module.name];
  817. // if (aChildren && aChildren.length > 0) {
  818. // var $li = $('<li></li>');
  819. // var $lidiv = $('<div></div>');
  820. // for (let i = 0; i < aSelf.length; i++) {
  821. // var $a = $('<a title="' + aSelf[i].name + '" href="javascript:void(0)"><div class="jProcessChartRowDetail" style="display: none">xx</div></br>' + aSelf[i].name + '</br>' + aSelf[i].date + '</a>').data('node_data', aSelf[i]);
  822. // if (i === 0) {
  823. // $a = $('<a title="' + aSelf[i].name + '" href="javascript:void(0)"><div class="jProcessChartRowDetail" style="display: none">xx</div>' + aSelf[i].id + '</br>' + aSelf[i].name + '</br>' + aSelf[i].date + '</a>').data('node_data', aSelf[i]);
  824. // }
  825. // var $lidivchild = $('<div class="jProcessChartRowDiv"></div>');
  826. // if (aSelf[i].current) {
  827. // $lidivchild.addClass('jProcessChartRowDivCurrent')
  828. // }
  829. // $lidivchild.append($a).appendTo($lidiv);
  830. // $lidivchild.appendTo($lidiv);
  831. // }
  832. // $lidiv.appendTo($li);
  833. // $li.append('<ul></ul>').appendTo($parent);
  834. // // 递归显示
  835. // _showall(aChildren, $li.children(':eq(1)'), opts);
  836. // } else {
  837. // $li = $('<li></li>');
  838. // $lidiv = $('<div></div>');
  839. // for (let i = 0; i < aSelf.length; i++) {
  840. // $a = $('<a title="' + aSelf[i].name + '" href="javascript:void(0)"><div class="jProcessChartRowDetail" style="display: none">xx</div></br>' + aSelf[i].name + '</br>' + aSelf[i].date + '</a>').data('node_data', aSelf[i]);
  841. // if (i === 0) {
  842. // $a = $('<a title="' + aSelf[i].name + '" href="javascript:void(0)"><div class="jProcessChartRowDetail" style="display: none">xx</div>' + aSelf[i].id + '</br>' + aSelf[i].name + '</br>' + aSelf[i].date + '</a>').data('node_data', aSelf[i]);
  843. // }
  844. // $lidivchild = $('<div class="jProcessChartRowDiv"></div>');
  845. // if (aSelf[i].current) {
  846. // $lidivchild.addClass('jProcessChartRowDivCurrent')
  847. // }
  848. // $lidivchild.append($a).appendTo($lidiv);
  849. // // $('<li></li>').append($a).appendTo($parent);
  850. // }
  851. // $lidiv.appendTo($li);
  852. // $li.append('<ul></ul>').appendTo($parent);
  853. // }
  854. // });
  855. // }
  856. //
  857. // var nodeCount = 0;
  858. // // Method that recursively builds the tree
  859. // function buildNode ($node, $appendTo, level, opts) {
  860. // var $table = $('<table cellpadding="0" cellspacing="0" border="0"/>');
  861. // var $tbody = $('<tbody/>');
  862. //
  863. // // Construct the node container(s)
  864. // var $nodeRow = $('<tr/>').addClass('node-cells');
  865. // var $nodeCell = $('<td/>').addClass('node-cell').attr('colspan', 2);
  866. // var $childNodes = $node.children('ul:first').children('li');
  867. // var $nodeDiv;
  868. //
  869. // if ($childNodes.length > 1) {
  870. // $nodeCell.attr('colspan', $childNodes.length * 2);
  871. // }
  872. // // Draw the node
  873. // // Get the contents - any markup except li and ul allowed
  874. // var $nodeContent = $node.clone()
  875. // .children('ul,li')
  876. // .remove()
  877. // .end()
  878. // .html();
  879. // // console.log('$nodeContent', $nodeContent);
  880. // // Increaments the node count which is used to link the source list and the org chart
  881. // nodeCount++;
  882. // $node.data('tree-node', nodeCount);
  883. // $nodeDiv = $('<div>').addClass('node')
  884. // .data('tree-node', nodeCount)
  885. // .append($nodeContent);
  886. // $nodeDiv.find('.jProcessChartRowDiv').on('click', function (e) {
  887. // if ($(e.target).children(':first').css('display') === 'block') {
  888. // $(e.target).children(':first').css('display', 'none');
  889. // } else {
  890. // $(e.target).children(':first').css('display', 'block');
  891. // }
  892. // })
  893. // if (opts.clickCallback && typeof opts.clickCallback === 'function') {
  894. // $nodeDiv.on('click', function () {
  895. // // $('.jProcessChart').find('div').css('border-color', 'black')
  896. // // $('.jProcessChart').find('div a').css('color', 'black')
  897. // // $nodeDiv.css('border-color', 'red')
  898. // // $nodeDiv.find('a').css('color', 'red')
  899. // // opts.clickCallback($node.children('a').data('node_data'));
  900. // });
  901. // }
  902. //
  903. // // Expand and contract nodes
  904. // if (opts.expandAble && $childNodes.length > 0) {
  905. // $nodeDiv.on('click', function () {
  906. // var $this = $(this);
  907. // var $tr = $this.closest('tr');
  908. //
  909. // if ($tr.hasClass('contracted')) {
  910. // $this.css('cursor', 'n-resize');
  911. // $tr.removeClass('contracted').addClass('expanded');
  912. // $tr.nextAll('tr').css('visibility', '');
  913. //
  914. // // Update the <li> appropriately so that if the tree redraws collapsed/non-collapsed nodes
  915. // // maintain their appearance
  916. // $node.removeClass('collapsed');
  917. // } else {
  918. // $this.css('cursor', 's-resize');
  919. // $tr.removeClass('expanded').addClass('contracted');
  920. // $tr.nextAll('tr').css('visibility', 'hidden');
  921. // $node.addClass('collapsed');
  922. // }
  923. // });
  924. // }
  925. //
  926. // $nodeCell.append($nodeDiv);
  927. // $nodeRow.append($nodeCell);
  928. // $tbody.append($nodeRow);
  929. //
  930. // if ($childNodes.length > 0) {
  931. // // if it can be expanded then change the cursor
  932. // $nodeDiv.css('cursor', 'n-resize');
  933. //
  934. // // recurse until leaves found (-1) or to the level specified
  935. // if (opts.depth === -1 || (level + 1 < opts.depth)) {
  936. // var $downLineRow = $('<tr/>');
  937. // var $downLineCell = $('<td/>').attr('colspan', $childNodes.length * 2);
  938. // $downLineRow.append($downLineCell);
  939. //
  940. // // draw the connecting line from the parent node to the horizontal line
  941. // var $downLine = $('<div></div>').addClass('line down');
  942. // $downLineCell.append($downLine);
  943. // $tbody.append($downLineRow);
  944. //
  945. // // Draw the horizontal lines
  946. // var $linesRow = $('<tr/>');
  947. // $childNodes.each(function () {
  948. // var $left = $('<td>&nbsp;</td>').addClass('line left top');
  949. // var $right = $('<td>&nbsp;</td>').addClass('line right top');
  950. // $linesRow.append($left).append($right);
  951. // });
  952. //
  953. // // horizontal line shouldn't extend beyond the first and last child branches
  954. // $linesRow.find('td:first')
  955. // .removeClass('top')
  956. // .end()
  957. // .find('td:last')
  958. // .removeClass('top');
  959. //
  960. // $tbody.append($linesRow);
  961. // var $childNodesRow = $('<tr/>');
  962. // $childNodes.each(function () {
  963. // var $td = $('<td class="node-container"/>');
  964. // $td.attr('colspan', 2);
  965. // // recurse through children lists and items
  966. // buildNode($(this), $td, level + 1, opts);
  967. // $childNodesRow.append($td);
  968. // });
  969. // }
  970. // $tbody.append($childNodesRow);
  971. // }
  972. //
  973. // // any classes on the LI element get copied to the relevant node in the tree
  974. // // apart from the special 'collapsed' class, which collapses the sub-tree at this point
  975. // if ($node.attr('class') !== undefined) {
  976. // var classList = $node.attr('class').split(/\s+/);
  977. // $.each(classList, function (index, item) {
  978. // if (item === 'collapsed') {
  979. // // console.log($node);
  980. // $nodeRow.nextAll('tr').css('visibility', 'hidden');
  981. // $nodeRow.removeClass('expanded');
  982. // $nodeRow.addClass('contracted');
  983. // $nodeDiv.css('cursor', 's-resize');
  984. // } else {
  985. // $nodeDiv.addClass(item);
  986. // }
  987. // });
  988. // }
  989. //
  990. // $table.append($tbody);
  991. // $appendTo.append($table);
  992. //
  993. // /* Prevent trees collapsing if a link inside a node is clicked */
  994. // // $nodeDiv.children('a').click(function(e){
  995. // // console.log(e);
  996. // // e.stopPropagation();
  997. // // });
  998. // };
  999. // })(jQuery);
  1000. /**
  1001. * 未名所以然
  1002. */
  1003. (function ($, window, document) {
  1004. $.fn.easySlider = function (options) {
  1005. alert('1234');
  1006. }
  1007. }(jQuery, window, document));