index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <!--
  2. @Modular:表格组件
  3. @Author: zouwf
  4. @Date: 2019-03-23
  5. -->
  6. <template>
  7. <dg-table
  8. ref="grid"
  9. row-key="id"
  10. border
  11. :expand-row-keys="expands"
  12. @change-current="handleChangeCurrent"
  13. @change-size="handleChangeSize"
  14. @selection-change="handleSelectionChange"
  15. @expand-change="handleExpandChange"
  16. @row-click="handleRowClick"
  17. @cell-click="handleCellClick"
  18. :url="url"
  19. :condition="condition"
  20. :pagination="pagination"
  21. :pagination-props="paginationProps"
  22. :mapping="mapping"
  23. :lazyLoad="lazyLoad"
  24. highlight-current-row
  25. :before-search="_beforeSearch"
  26. :before-quest="beforeQuest"
  27. >
  28. <!--序号-->
  29. <dg-table-column type="index" width="70" label="序号" align="center" fixed="left" />
  30. <!--复选框情况-->
  31. <dg-table-column type="selection" width="55" v-if="selection" />
  32. <slot name="expand" />
  33. <template v-for="(item, indexs) in headerData">
  34. <dg-table-column :key="indexs" v-bind="item" align="center">
  35. <template slot-scope="scope">
  36. <slot v-if="item.custom" v-bind:row="scope.row" :name="item.prop"></slot>
  37. </template>
  38. </dg-table-column>
  39. </template>
  40. <!--操作栏-->
  41. <slot></slot>
  42. </dg-table>
  43. </template>
  44. <script>
  45. import moment from 'moment';
  46. export default {
  47. name: 'Ltable',
  48. props: {
  49. lazyLoad: {
  50. type: Boolean,
  51. default: false
  52. },
  53. data: {
  54. type: Array,
  55. default: () => []
  56. },
  57. // 表头配置
  58. headerData: {
  59. type: Array,
  60. default: () => []
  61. },
  62. // 开启复选
  63. selection: {
  64. type: Boolean,
  65. default: false
  66. },
  67. // 开启复选
  68. url: {
  69. type: String,
  70. default: '',
  71. require: true
  72. },
  73. // 表格查询参数
  74. condition: {
  75. type: Object,
  76. default: () => {}
  77. },
  78. sort: {
  79. type: Object,
  80. default: () => {}
  81. },
  82. // 是否开启分页
  83. pagination: {
  84. type: Boolean,
  85. default: true
  86. },
  87. // 分页选项
  88. paginationProps: {
  89. type: Object,
  90. default: () => {
  91. return {
  92. currentPage: 1,
  93. pageSizes: [10, 20, 30],
  94. pageSize: 10,
  95. layout: 'total, sizes, prev, pager, next, jumper'
  96. };
  97. }
  98. },
  99. // 最大高度
  100. maxheight: {
  101. type: [Number, String],
  102. default: ''
  103. },
  104. converter: Function,
  105. beforeSearch: {
  106. type: Function,
  107. default: (conditions) => conditions
  108. },
  109. tableName: {
  110. type: String,
  111. default: '表格'
  112. }
  113. },
  114. // 页面数据绑定
  115. data() {
  116. return {
  117. expands: [],
  118. mapping: {
  119. list: 'content',
  120. total: 'totalPages'
  121. }
  122. };
  123. },
  124. mounted() {},
  125. // 方法
  126. methods: {
  127. _beforeSearch(conditions) {
  128. conditions = this.beforeSearch(conditions);
  129. let tmpCond = JSON.parse(conditions.searchCondition);
  130. let result = [];
  131. tmpCond.map((item, i) => {
  132. if (item.op === 'between') {
  133. if (item.value[0]) {
  134. // tmpCond.splice(i, 1);
  135. result.push({ ...item, op: '>=', value: item.value[0] });
  136. result.push({ ...item, op: '<=', value: item.value[1] });
  137. }
  138. } else {
  139. result.push(item);
  140. }
  141. });
  142. conditions.searchCondition = JSON.stringify(result);
  143. conditions.sort = JSON.stringify(this.sort);
  144. return conditions;
  145. },
  146. /**
  147. * 页码切换
  148. * @current 切换值
  149. * */
  150. handleChangeCurrent(current) {
  151. this.$emit('handleChangeCurrent', current);
  152. },
  153. /**
  154. * 页面切换
  155. * @current 切换值
  156. * */
  157. handleChangeSize(size) {
  158. this.$emit('handleChangeSize', size);
  159. },
  160. /**
  161. * 页码切换
  162. * @data 选中数据数组
  163. * */
  164. handleSelectionChange(data) {
  165. this.$emit('handleSelectionChange', data);
  166. },
  167. handleExpandChange(row, expanded) {
  168. const that = this;
  169. if (expanded.length) {
  170. that.expands = [];
  171. if (row) {
  172. that.expands.push(row.id);
  173. this.$emit('expand', row, expanded);
  174. }
  175. } else {
  176. that.expands = [];
  177. }
  178. },
  179. /**
  180. * 查询
  181. * */
  182. handleSearchClick() {
  183. this.$refs.grid.searchForm();
  184. },
  185. /**
  186. * 表格某行被点击
  187. * */
  188. handleRowClick(row, column, event) {
  189. this.$refs.grid.setCurrentRow(row);
  190. this.$emit('handleRowClick', { row, column });
  191. },
  192. // 某单元格被点击
  193. handleCellClick(row, column, cell, event) {
  194. this.$emit('handleCellClick', { row, column });
  195. },
  196. /*
  197. * 切换勾选状态
  198. * */
  199. toggleRowSelection(row, bool = false) {
  200. return this.$refs.grid.toggleRowSelection(row, bool);
  201. },
  202. getReqSearchCondition() {
  203. return this.$refs.grid.getReqSearchCondition();
  204. },
  205. beforeQuest(res) {
  206. const { content, totalElements } = res.data;
  207. const result = {
  208. data: {
  209. content,
  210. totalElements
  211. }
  212. };
  213. this.$emit('getTotalElements', { totalElements, tableName: this.tableName });
  214. return result;
  215. }
  216. },
  217. created() {}
  218. };
  219. </script>
  220. <style scoped lang="scss">
  221. </style>