grid-extend.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. /******/ (function(modules) { // webpackBootstrap
  2. /******/ // The module cache
  3. /******/ var installedModules = {};
  4. /******/
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/
  8. /******/ // Check if module is in cache
  9. /******/ if(installedModules[moduleId]) {
  10. /******/ return installedModules[moduleId].exports;
  11. /******/ }
  12. /******/ // Create a new module (and put it into the cache)
  13. /******/ var module = installedModules[moduleId] = {
  14. /******/ i: moduleId,
  15. /******/ l: false,
  16. /******/ exports: {}
  17. /******/ };
  18. /******/
  19. /******/ // Execute the module function
  20. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  21. /******/
  22. /******/ // Flag the module as loaded
  23. /******/ module.l = true;
  24. /******/
  25. /******/ // Return the exports of the module
  26. /******/ return module.exports;
  27. /******/ }
  28. /******/
  29. /******/
  30. /******/ // expose the modules object (__webpack_modules__)
  31. /******/ __webpack_require__.m = modules;
  32. /******/
  33. /******/ // expose the module cache
  34. /******/ __webpack_require__.c = installedModules;
  35. /******/
  36. /******/ // define getter function for harmony exports
  37. /******/ __webpack_require__.d = function(exports, name, getter) {
  38. /******/ if(!__webpack_require__.o(exports, name)) {
  39. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  40. /******/ }
  41. /******/ };
  42. /******/
  43. /******/ // define __esModule on exports
  44. /******/ __webpack_require__.r = function(exports) {
  45. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  46. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  47. /******/ }
  48. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  49. /******/ };
  50. /******/
  51. /******/ // create a fake namespace object
  52. /******/ // mode & 1: value is a module id, require it
  53. /******/ // mode & 2: merge all properties of value into the ns
  54. /******/ // mode & 4: return value when already ns object
  55. /******/ // mode & 8|1: behave like require
  56. /******/ __webpack_require__.t = function(value, mode) {
  57. /******/ if(mode & 1) value = __webpack_require__(value);
  58. /******/ if(mode & 8) return value;
  59. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  60. /******/ var ns = Object.create(null);
  61. /******/ __webpack_require__.r(ns);
  62. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  63. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  64. /******/ return ns;
  65. /******/ };
  66. /******/
  67. /******/ // getDefaultExport function for compatibility with non-harmony modules
  68. /******/ __webpack_require__.n = function(module) {
  69. /******/ var getter = module && module.__esModule ?
  70. /******/ function getDefault() { return module['default']; } :
  71. /******/ function getModuleExports() { return module; };
  72. /******/ __webpack_require__.d(getter, 'a', getter);
  73. /******/ return getter;
  74. /******/ };
  75. /******/
  76. /******/ // Object.prototype.hasOwnProperty.call
  77. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  78. /******/
  79. /******/ // __webpack_public_path__
  80. /******/ __webpack_require__.p = "/";
  81. /******/
  82. /******/
  83. /******/ // Load entry module and return exports
  84. /******/ return __webpack_require__(__webpack_require__.s = 1);
  85. /******/ })
  86. /************************************************************************/
  87. /******/ ({
  88. /***/ "./resources/assets/dcat/extra/grid-extend.js":
  89. /*!****************************************************!*\
  90. !*** ./resources/assets/dcat/extra/grid-extend.js ***!
  91. \****************************************************/
  92. /*! no static exports found */
  93. /***/ (function(module, exports) {
  94. (function (w, $) {
  95. var Dcat = w.Dcat;
  96. function Tree(opts) {
  97. this.options = $.extend({
  98. button: null,
  99. table: null,
  100. url: '',
  101. perPage: '',
  102. showNextPage: '',
  103. pageQueryName: '',
  104. parentIdQueryName: '',
  105. tierQueryName: '',
  106. showIcon: 'fa-angle-right',
  107. hideIcon: 'fa-angle-down',
  108. loadMoreIcon: '<i class="feather icon-more-horizontal"></i>'
  109. }, opts);
  110. this.key = this.tier = this.row = this.data = this._req = null;
  111. this._init();
  112. }
  113. Tree.prototype = {
  114. _init: function _init() {
  115. this._bindClick();
  116. },
  117. _bindClick: function _bindClick() {
  118. var _this = this,
  119. opts = _this.options;
  120. $(opts.button).off('click').click(function () {
  121. if (_this._req) {
  122. return;
  123. }
  124. var $this = $(this),
  125. _i = $("i", this),
  126. shown = _i.hasClass(opts.showIcon);
  127. _this.key = $this.data('key');
  128. _this.tier = $this.data('tier');
  129. _this.row = $this.closest('tr');
  130. if ($this.data('inserted') == '0') {
  131. _this._request(1);
  132. $this.data('inserted', 1);
  133. }
  134. _i.toggleClass(opts.showIcon + ' ' + opts.hideIcon);
  135. var children = [];
  136. getChildren(_this.row.nextAll(), _this.row).forEach(function (v) {
  137. if (getTier(v) !== _this.tier + 1) {
  138. return;
  139. }
  140. children.push(v);
  141. shown ? $(v).show() : $(v).hide();
  142. });
  143. children.forEach(function (v) {
  144. if (shown) {
  145. return;
  146. }
  147. var icon = $(v).find('a[data-tier=' + getTier(v) + '] i');
  148. if (icon.hasClass(opts.hideIcon)) {
  149. icon.parent().click();
  150. }
  151. });
  152. });
  153. },
  154. _request: function _request(page, after) {
  155. var _this = this,
  156. row = _this.row,
  157. key = _this.key,
  158. tier = _this.tier,
  159. tableSelector = _this.options.table;
  160. if (_this._req) {
  161. return;
  162. }
  163. _this._req = 1;
  164. Dcat.loading();
  165. var data = {
  166. _token: Dcat.token
  167. };
  168. data[_this.options.parentIdQueryName] = key;
  169. data[_this.options.tierQueryName] = tier + 1;
  170. data[_this.options.pageQueryName.replace(':key', key)] = page;
  171. $.ajax({
  172. url: _this.options.url,
  173. type: 'GET',
  174. data: data,
  175. headers: {
  176. 'X-PJAX': true
  177. },
  178. success: function success(resp) {
  179. after && after();
  180. Dcat.loading(false);
  181. _this._req = 0; // 获取最后一行
  182. var children = getChildren(row.nextAll(), row);
  183. row = children.length ? $(children.pop()) : row;
  184. var _body = $('<div>' + resp + '</div>'),
  185. _tbody = _body.find(tableSelector + ' tbody'),
  186. lastPage = _body.find('last-page').text(),
  187. nextPage = _body.find('next-page').text(); // 标记子节点行
  188. _tbody.find('tr').each(function (_, v) {
  189. $(v).attr('data-tier', tier + 1);
  190. });
  191. if (_this.options.showNextPage && _tbody.find('tr').length == _this.options.perPage && lastPage >= page) {
  192. // 加载更多
  193. var loadMore = $("<tr data-tier=\"".concat(tier + 1, "\" data-page=\"").concat(nextPage, "\">\n <td colspan=\"").concat(row.find('td').length, "\" align=\"center\" style=\"cursor: pointer\"> \n <a href=\"#\" style=\"font-size: 1.5rem\">").concat(_this.options.loadMoreIcon, "</a> \n </td>\n </tr>"));
  194. row.after(loadMore); // 加载更多
  195. loadMore.click(function () {
  196. var _t = $(this);
  197. _this._request(_t.data('page'), function () {
  198. _t.remove();
  199. });
  200. });
  201. } // 附加子节点
  202. row.after(_tbody.html()); // 附加子节点js脚本以及触发子节点js脚本执行
  203. _body.find('script').each(function (_, v) {
  204. row.after(v);
  205. }); // 主动触发ready事件,执行子节点附带的js脚本
  206. Dcat.triggerReady();
  207. },
  208. error: function error(a, b, c) {
  209. after && after();
  210. Dcat.loading(false);
  211. _this._req = 0;
  212. if (a.status != 404) {
  213. Dcat.handleAjaxError(a, b, c);
  214. }
  215. }
  216. });
  217. }
  218. };
  219. function Orderable(opts) {
  220. this.options = $.extend({
  221. button: null,
  222. url: ''
  223. }, opts);
  224. this.direction = this.key = this.tier = this.row = this._req = null;
  225. this._init();
  226. }
  227. Orderable.prototype = {
  228. _init: function _init() {
  229. this._bindClick();
  230. },
  231. _bindClick: function _bindClick() {
  232. var _this = this;
  233. $(_this.options.button).off('click').click(function () {
  234. if (_this._req) {
  235. return;
  236. }
  237. _this._req = 1;
  238. Dcat.loading();
  239. var $this = $(this);
  240. _this.key = $this.data('id');
  241. _this.direction = $this.data('direction');
  242. _this.row = $this.closest('tr');
  243. _this.tier = getTier(_this.row);
  244. _this._request();
  245. });
  246. },
  247. _request: function _request() {
  248. var _this = this,
  249. key = _this.key,
  250. row = _this.row,
  251. tier = _this.tier,
  252. direction = _this.direction,
  253. prevAll = row.prevAll(),
  254. nextAll = row.nextAll(),
  255. prev = row.prevAll('tr').first(),
  256. next = row.nextAll('tr').first();
  257. $.ajax({
  258. type: 'POST',
  259. url: _this.options.url.replace(':key', key),
  260. data: {
  261. _method: 'PUT',
  262. _token: Dcat.token,
  263. _orderable: direction
  264. },
  265. success: function success(data) {
  266. Dcat.loading(false);
  267. _this._req = 0;
  268. if (!data.status) {
  269. return data.message && Dcat.warning(data.message);
  270. }
  271. Dcat.success(data.message);
  272. if (direction) {
  273. var prevRow = sibling(prevAll, tier);
  274. if (swapable(prevRow, tier) && prev.length && getTier(prev) >= tier) {
  275. prevRow.before(row); // 把所有子节点上移
  276. getChildren(nextAll, row).forEach(function (v) {
  277. prevRow.before(v);
  278. });
  279. }
  280. } else {
  281. var nextRow = sibling(nextAll, tier),
  282. nextRowChildren = nextRow ? getChildren(nextRow.nextAll(), nextRow) : [];
  283. if (swapable(nextRow, tier) && next.length && getTier(next) >= tier) {
  284. nextAll = row.nextAll();
  285. if (nextRowChildren.length) {
  286. nextRow = $(nextRowChildren.pop());
  287. } // 把所有子节点下移
  288. var all = [];
  289. getChildren(nextAll, row).forEach(function (v) {
  290. all.unshift(v);
  291. });
  292. all.forEach(function (v) {
  293. nextRow.after(v);
  294. });
  295. nextRow.after(row);
  296. }
  297. }
  298. },
  299. error: function error(a, b, c) {
  300. _this._req = 0;
  301. Dcat.loading(false);
  302. Dcat.handleAjaxError(a, b, c);
  303. }
  304. });
  305. }
  306. };
  307. function isTr(v) {
  308. return $(v).prop('tagName').toLocaleLowerCase() === 'tr';
  309. }
  310. function getTier(v) {
  311. return parseInt($(v).data('tier') || 0);
  312. }
  313. function isChildren(parent, child) {
  314. return getTier(child) > getTier(parent);
  315. }
  316. function getChildren(all, parent) {
  317. var arr = [],
  318. isBreak = false,
  319. firstTr;
  320. all.each(function (_, v) {
  321. // 过滤非tr标签
  322. if (!isTr(v) || isBreak) return;
  323. firstTr || (firstTr = $(v)); // 非连续的子节点
  324. if (firstTr && !isChildren(parent, firstTr)) {
  325. return;
  326. }
  327. if (isChildren(parent, v)) {
  328. arr.push(v);
  329. } else {
  330. isBreak = true;
  331. }
  332. });
  333. return arr;
  334. }
  335. function swapable(_o, tier) {
  336. if (_o && _o.length && tier === getTier(_o)) {
  337. return true;
  338. }
  339. }
  340. function sibling(all, tier) {
  341. var next;
  342. all.each(function (_, v) {
  343. if (getTier(v) === tier && !next && isTr(v)) {
  344. next = $(v);
  345. }
  346. });
  347. return next;
  348. }
  349. Dcat.grid.Tree = function (opts) {
  350. return new Tree(opts);
  351. };
  352. Dcat.grid.Orderable = function (opts) {
  353. return new Orderable(opts);
  354. };
  355. })(window, jQuery);
  356. /***/ }),
  357. /***/ 1:
  358. /*!**********************************************************!*\
  359. !*** multi ./resources/assets/dcat/extra/grid-extend.js ***!
  360. \**********************************************************/
  361. /*! no static exports found */
  362. /***/ (function(module, exports, __webpack_require__) {
  363. module.exports = __webpack_require__(/*! D:\php-project\laravel\laraveladmin\github-test\pck-dcat-admin\dcat-admin\resources\assets\dcat\extra\grid-extend.js */"./resources/assets/dcat/extra/grid-extend.js");
  364. /***/ })
  365. /******/ });