bootstrap-table-vue.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  3. typeof define === 'function' && define.amd ? define(factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.BootstrapTable = factory());
  5. })(this, (function () { 'use strict';
  6. //
  7. //
  8. //
  9. //
  10. const $ = window.jQuery;
  11. const deepCopy = arg => {
  12. if (arg === undefined) {
  13. return arg
  14. }
  15. return $.extend(true, Array.isArray(arg) ? [] : {}, arg)
  16. };
  17. var script = {
  18. name: 'BootstrapTable',
  19. props: {
  20. columns: {
  21. type: Array,
  22. require: true
  23. },
  24. data: {
  25. type: [Array, Object],
  26. default () {
  27. return undefined
  28. }
  29. },
  30. options: {
  31. type: Object,
  32. default () {
  33. return {}
  34. }
  35. }
  36. },
  37. mounted () {
  38. this.$table = $(this.$el);
  39. this.$table.on('all.bs.table', (e, name, args) => {
  40. let eventName = $.fn.bootstrapTable.events[name];
  41. eventName = eventName.replace(/([A-Z])/g, '-$1').toLowerCase();
  42. this.$emit('on-all', ...args);
  43. this.$emit(eventName, ...args);
  44. });
  45. this._initTable();
  46. },
  47. methods: {
  48. _initTable () {
  49. const options = {
  50. ...deepCopy(this.options),
  51. columns: deepCopy(this.columns),
  52. data: deepCopy(this.data)
  53. };
  54. if (!this._hasInit) {
  55. this.$table.bootstrapTable(options);
  56. this._hasInit = true;
  57. } else {
  58. this.refreshOptions(options);
  59. }
  60. },
  61. ...(() => {
  62. const res = {};
  63. for (const method of $.fn.bootstrapTable.methods) {
  64. res[method] = function (...args) {
  65. return this.$table.bootstrapTable(method, ...args)
  66. };
  67. }
  68. return res
  69. })()
  70. },
  71. watch: {
  72. options: {
  73. handler () {
  74. this._initTable();
  75. },
  76. deep: true
  77. },
  78. columns: {
  79. handler () {
  80. this._initTable();
  81. },
  82. deep: true
  83. },
  84. data: {
  85. handler () {
  86. this.load(deepCopy(this.data));
  87. },
  88. deep: true
  89. }
  90. }
  91. };
  92. function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier /* server only */, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) {
  93. if (typeof shadowMode !== 'boolean') {
  94. createInjectorSSR = createInjector;
  95. createInjector = shadowMode;
  96. shadowMode = false;
  97. }
  98. // Vue.extend constructor export interop.
  99. const options = typeof script === 'function' ? script.options : script;
  100. // render functions
  101. if (template && template.render) {
  102. options.render = template.render;
  103. options.staticRenderFns = template.staticRenderFns;
  104. options._compiled = true;
  105. // functional template
  106. if (isFunctionalTemplate) {
  107. options.functional = true;
  108. }
  109. }
  110. // scopedId
  111. if (scopeId) {
  112. options._scopeId = scopeId;
  113. }
  114. let hook;
  115. if (moduleIdentifier) {
  116. // server build
  117. hook = function (context) {
  118. // 2.3 injection
  119. context =
  120. context || // cached call
  121. (this.$vnode && this.$vnode.ssrContext) || // stateful
  122. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext); // functional
  123. // 2.2 with runInNewContext: true
  124. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  125. context = __VUE_SSR_CONTEXT__;
  126. }
  127. // inject component styles
  128. if (style) {
  129. style.call(this, createInjectorSSR(context));
  130. }
  131. // register component module identifier for async chunk inference
  132. if (context && context._registeredComponents) {
  133. context._registeredComponents.add(moduleIdentifier);
  134. }
  135. };
  136. // used by ssr in case component is cached and beforeCreate
  137. // never gets called
  138. options._ssrRegister = hook;
  139. }
  140. else if (style) {
  141. hook = shadowMode
  142. ? function (context) {
  143. style.call(this, createInjectorShadow(context, this.$root.$options.shadowRoot));
  144. }
  145. : function (context) {
  146. style.call(this, createInjector(context));
  147. };
  148. }
  149. if (hook) {
  150. if (options.functional) {
  151. // register for functional component in vue file
  152. const originalRender = options.render;
  153. options.render = function renderWithStyleInjection(h, context) {
  154. hook.call(context);
  155. return originalRender(h, context);
  156. };
  157. }
  158. else {
  159. // inject component registration as beforeCreate hook
  160. const existing = options.beforeCreate;
  161. options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
  162. }
  163. }
  164. return script;
  165. }
  166. /* script */
  167. const __vue_script__ = script;
  168. /* template */
  169. var __vue_render__ = function () {
  170. var _vm = this;
  171. var _h = _vm.$createElement;
  172. var _c = _vm._self._c || _h;
  173. return _c("table")
  174. };
  175. var __vue_staticRenderFns__ = [];
  176. __vue_render__._withStripped = true;
  177. /* style */
  178. const __vue_inject_styles__ = undefined;
  179. /* scoped */
  180. const __vue_scope_id__ = undefined;
  181. /* module identifier */
  182. const __vue_module_identifier__ = undefined;
  183. /* functional template */
  184. const __vue_is_functional_template__ = false;
  185. /* style inject */
  186. /* style inject SSR */
  187. /* style inject shadow dom */
  188. const __vue_component__ = /*#__PURE__*/normalizeComponent(
  189. { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
  190. __vue_inject_styles__,
  191. __vue_script__,
  192. __vue_scope_id__,
  193. __vue_is_functional_template__,
  194. __vue_module_identifier__,
  195. false,
  196. undefined,
  197. undefined,
  198. undefined
  199. );
  200. return __vue_component__;
  201. }));