bootstrap-table-addrbar.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('core-js/modules/es.array.concat.js'), require('core-js/modules/es.array.iterator.js'), require('core-js/modules/es.object.assign.js'), require('core-js/modules/es.object.entries.js'), require('core-js/modules/es.object.to-string.js'), require('core-js/modules/es.regexp.exec.js'), require('core-js/modules/es.regexp.to-string.js'), require('core-js/modules/es.string.iterator.js'), require('core-js/modules/es.string.search.js'), require('core-js/modules/web.dom-collections.iterator.js'), require('core-js/modules/web.url-search-params.js'), require('jquery')) :
  3. typeof define === 'function' && define.amd ? define(['core-js/modules/es.array.concat.js', 'core-js/modules/es.array.iterator.js', 'core-js/modules/es.object.assign.js', 'core-js/modules/es.object.entries.js', 'core-js/modules/es.object.to-string.js', 'core-js/modules/es.regexp.exec.js', 'core-js/modules/es.regexp.to-string.js', 'core-js/modules/es.string.iterator.js', 'core-js/modules/es.string.search.js', 'core-js/modules/web.dom-collections.iterator.js', 'core-js/modules/web.url-search-params.js', 'jquery'], factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(null, null, null, null, null, null, null, null, null, null, null, global.jQuery));
  5. })(this, (function (es_array_concat_js, es_array_iterator_js, es_object_assign_js, es_object_entries_js, es_object_toString_js, es_regexp_exec_js, es_regexp_toString_js, es_string_iterator_js, es_string_search_js, web_domCollections_iterator_js, web_urlSearchParams_js, $) { 'use strict';
  6. function _arrayLikeToArray(r, a) {
  7. (null == a || a > r.length) && (a = r.length);
  8. for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
  9. return n;
  10. }
  11. function _arrayWithHoles(r) {
  12. if (Array.isArray(r)) return r;
  13. }
  14. function _assertThisInitialized(e) {
  15. if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  16. return e;
  17. }
  18. function _callSuper(t, o, e) {
  19. return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
  20. }
  21. function _classCallCheck(a, n) {
  22. if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
  23. }
  24. function _defineProperties(e, r) {
  25. for (var t = 0; t < r.length; t++) {
  26. var o = r[t];
  27. o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
  28. }
  29. }
  30. function _createClass(e, r, t) {
  31. return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
  32. writable: !1
  33. }), e;
  34. }
  35. function _get() {
  36. return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) {
  37. var p = _superPropBase(e, t);
  38. if (p) {
  39. var n = Object.getOwnPropertyDescriptor(p, t);
  40. return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value;
  41. }
  42. }, _get.apply(null, arguments);
  43. }
  44. function _getPrototypeOf(t) {
  45. return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
  46. return t.__proto__ || Object.getPrototypeOf(t);
  47. }, _getPrototypeOf(t);
  48. }
  49. function _inherits(t, e) {
  50. if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
  51. t.prototype = Object.create(e && e.prototype, {
  52. constructor: {
  53. value: t,
  54. writable: !0,
  55. configurable: !0
  56. }
  57. }), Object.defineProperty(t, "prototype", {
  58. writable: !1
  59. }), e && _setPrototypeOf(t, e);
  60. }
  61. function _isNativeReflectConstruct() {
  62. try {
  63. var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
  64. } catch (t) {}
  65. return (_isNativeReflectConstruct = function () {
  66. return !!t;
  67. })();
  68. }
  69. function _iterableToArrayLimit(r, l) {
  70. var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  71. if (null != t) {
  72. var e,
  73. n,
  74. i,
  75. u,
  76. a = [],
  77. f = !0,
  78. o = !1;
  79. try {
  80. if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
  81. } catch (r) {
  82. o = !0, n = r;
  83. } finally {
  84. try {
  85. if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
  86. } finally {
  87. if (o) throw n;
  88. }
  89. }
  90. return a;
  91. }
  92. }
  93. function _nonIterableRest() {
  94. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  95. }
  96. function _possibleConstructorReturn(t, e) {
  97. if (e && ("object" == typeof e || "function" == typeof e)) return e;
  98. if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
  99. return _assertThisInitialized(t);
  100. }
  101. function _setPrototypeOf(t, e) {
  102. return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
  103. return t.__proto__ = e, t;
  104. }, _setPrototypeOf(t, e);
  105. }
  106. function _slicedToArray(r, e) {
  107. return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
  108. }
  109. function _superPropBase(t, o) {
  110. for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t)););
  111. return t;
  112. }
  113. function _toPrimitive(t, r) {
  114. if ("object" != typeof t || !t) return t;
  115. var e = t[Symbol.toPrimitive];
  116. if (void 0 !== e) {
  117. var i = e.call(t, r );
  118. if ("object" != typeof i) return i;
  119. throw new TypeError("@@toPrimitive must return a primitive value.");
  120. }
  121. return (String )(t);
  122. }
  123. function _toPropertyKey(t) {
  124. var i = _toPrimitive(t, "string");
  125. return "symbol" == typeof i ? i : i + "";
  126. }
  127. function _unsupportedIterableToArray(r, a) {
  128. if (r) {
  129. if ("string" == typeof r) return _arrayLikeToArray(r, a);
  130. var t = {}.toString.call(r).slice(8, -1);
  131. return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
  132. }
  133. }
  134. /**
  135. * @author: general
  136. * @website: note.generals.space
  137. * @email: generals.space@gmail.com
  138. * @github: https://github.com/generals-space/bootstrap-table-addrbar
  139. * @update: zhixin wen <wenzhixin2010@gmail.com>
  140. */
  141. var Utils = $.fn.bootstrapTable.utils;
  142. Object.assign($.fn.bootstrapTable.defaults, {
  143. addrbar: false,
  144. addrPrefix: '',
  145. addrCustomParams: {}
  146. });
  147. $.BootstrapTable = /*#__PURE__*/function (_$$BootstrapTable) {
  148. function _class() {
  149. _classCallCheck(this, _class);
  150. return _callSuper(this, _class, arguments);
  151. }
  152. _inherits(_class, _$$BootstrapTable);
  153. return _createClass(_class, [{
  154. key: "init",
  155. value: function init() {
  156. var _get2;
  157. if (this.options.pagination && this.options.addrbar) {
  158. this.initAddrbar();
  159. }
  160. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  161. args[_key] = arguments[_key];
  162. }
  163. (_get2 = _get(_getPrototypeOf(_class.prototype), "init", this)).call.apply(_get2, [this].concat(args));
  164. }
  165. /*
  166. * Priority order:
  167. * The value specified by the user has the highest priority.
  168. * If it is not specified, it will be obtained from the address bar.
  169. * If it is not obtained, the default value will be used.
  170. */
  171. }, {
  172. key: "getDefaultOptionValue",
  173. value: function getDefaultOptionValue(optionName, prefixName) {
  174. if (this.options[optionName] !== $.BootstrapTable.DEFAULTS[optionName]) {
  175. return this.options[optionName];
  176. }
  177. return this.searchParams.get("".concat(this.options.addrPrefix || '').concat(prefixName)) || $.BootstrapTable.DEFAULTS[optionName];
  178. }
  179. }, {
  180. key: "initAddrbar",
  181. value: function initAddrbar() {
  182. var _this = this;
  183. // 标志位, 初始加载后关闭
  184. this.addrbarInit = true;
  185. this.searchParams = new URLSearchParams(window.location.search.substring(1));
  186. this.options.pageNumber = +this.getDefaultOptionValue('pageNumber', 'page');
  187. this.options.pageSize = +this.getDefaultOptionValue('pageSize', 'size');
  188. this.options.sortOrder = this.getDefaultOptionValue('sortOrder', 'order');
  189. this.options.sortName = this.getDefaultOptionValue('sortName', 'sort');
  190. this.options.searchText = this.getDefaultOptionValue('searchText', 'search');
  191. var prefix = this.options.addrPrefix || '';
  192. var onLoadSuccess = this.options.onLoadSuccess;
  193. var onPageChange = this.options.onPageChange;
  194. this.options.onLoadSuccess = function (data) {
  195. if (_this.addrbarInit) {
  196. _this.addrbarInit = false;
  197. } else {
  198. _this.updateHistoryState(prefix);
  199. }
  200. if (onLoadSuccess) {
  201. onLoadSuccess.call(_this, data);
  202. }
  203. };
  204. this.options.onPageChange = function (number, size) {
  205. _this.updateHistoryState(prefix);
  206. if (onPageChange) {
  207. onPageChange.call(_this, number, size);
  208. }
  209. };
  210. }
  211. }, {
  212. key: "updateHistoryState",
  213. value: function updateHistoryState(prefix) {
  214. var params = {};
  215. params["".concat(prefix, "page")] = this.options.pageNumber;
  216. params["".concat(prefix, "size")] = this.options.pageSize;
  217. params["".concat(prefix, "order")] = this.options.sortOrder;
  218. params["".concat(prefix, "sort")] = this.options.sortName;
  219. params["".concat(prefix, "search")] = this.options.searchText;
  220. for (var _i = 0, _Object$entries = Object.entries(params); _i < _Object$entries.length; _i++) {
  221. var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
  222. key = _Object$entries$_i[0],
  223. value = _Object$entries$_i[1];
  224. if (value === undefined) {
  225. this.searchParams.delete(key);
  226. } else {
  227. this.searchParams.set(key, value);
  228. }
  229. }
  230. var customParams = Utils.calculateObjectValue(this.options, this.options.addrCustomParams, [], {});
  231. for (var _i2 = 0, _Object$entries2 = Object.entries(customParams); _i2 < _Object$entries2.length; _i2++) {
  232. var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
  233. _key2 = _Object$entries2$_i[0],
  234. _value = _Object$entries2$_i[1];
  235. this.searchParams.set(_key2, _value);
  236. }
  237. var url = "?".concat(this.searchParams.toString());
  238. if (location.hash) {
  239. url += location.hash;
  240. }
  241. window.history.pushState({}, '', url);
  242. }
  243. }, {
  244. key: "resetSearch",
  245. value: function resetSearch(text) {
  246. _get(_getPrototypeOf(_class.prototype), "resetSearch", this).call(this, text);
  247. this.options.searchText = text || '';
  248. }
  249. }]);
  250. }($.BootstrapTable);
  251. }));