53227b862c613b6d2adbf0caa82b6a7e216f838a.svn-base 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <a-card :bordered="false">
  3. <a-row :gutter="8">
  4. <a-col :span="6">
  5. <!-- 加上 show-line 属性后,展开收起图标自动变成 +- 样式 -->
  6. <a-tree
  7. class="template-5-tree"
  8. :tree-data="treeData"
  9. show-icon
  10. show-line
  11. :expandedKeys="treeExpandedKeys"
  12. :selectedKeys="[pagination.current]"
  13. @expand="handleTreeExpand"
  14. @select="handleTreeSelect"
  15. >
  16. <!-- 自定义子节点图标 -->
  17. <a-icon slot="myIcon" type="unordered-list" style="color:#0c8fcf;"/>
  18. </a-tree>
  19. </a-col>
  20. <a-col :span="18">
  21. <j-vxe-table
  22. row-number
  23. row-selection
  24. :height="750"
  25. :loading="loading"
  26. :columns="columns"
  27. :dataSource="dataSource"
  28. :pagination="pagination"
  29. @pageChange="handleTablePageChange"
  30. />
  31. </a-col>
  32. </a-row>
  33. </a-card>
  34. </template>
  35. <script>
  36. import { getAction } from '@api/manage'
  37. import { JVXETypes } from '@/components/jeecg/JVxeTable'
  38. // 【多种布局模板】左侧为树,右侧为行编辑
  39. export default {
  40. name: 'Template5',
  41. data() {
  42. return {
  43. // 是否正在加载
  44. loading: false,
  45. // 分页器参数
  46. pagination: {
  47. // 当前页码
  48. current: 1,
  49. // 每页的条数
  50. pageSize: 50,
  51. // 可切换的条数
  52. pageSizeOptions: ['50'],
  53. // 数据总数(目前并不知道真实的总数,所以先填写0,在后台查出来后再赋值)
  54. total: 0,
  55. },
  56. // 选择的行
  57. selectedRows: [],
  58. // 数据源,控制表格的数据
  59. dataSource: [],
  60. // 列配置,控制表格显示的列
  61. columns: [
  62. {key: 'num', title: '序号', width: '80px'},
  63. {
  64. // 字段key,跟后台数据的字段名匹配
  65. key: 'ship_name',
  66. // 列的标题
  67. title: '船名',
  68. // 列的宽度
  69. width: '180px',
  70. // 如果加上了该属性,就代表当前单元格是可编辑的,type就是表单的类型,input就是简单的输入框
  71. type: JVXETypes.input
  72. },
  73. {key: 'call', title: '呼叫', width: '80px', type: JVXETypes.input},
  74. {key: 'len', title: '长', width: '80px', type: JVXETypes.input},
  75. {key: 'ton', title: '吨', width: '120px', type: JVXETypes.input},
  76. {key: 'payer', title: '付款方', width: '120px', type: JVXETypes.input},
  77. {key: 'count', title: '数', width: '40px'},
  78. {
  79. key: 'company',
  80. title: '公司',
  81. // 最小宽度,与宽度不同的是,这个不是固定的宽度,如果表格有多余的空间,会平均分配给设置了 minWidth 的列
  82. // 如果要做占满表格的列可以这么写
  83. minWidth: '180px',
  84. type: JVXETypes.input
  85. },
  86. {key: 'trend', title: '动向', width: '120px', type: JVXETypes.input},
  87. ],
  88. // 树的数据,这里模拟分页固定数据,实际情况应该是后台查出来的数据
  89. treeData: [
  90. // 第1级数据
  91. {
  92. title: '1-10页',
  93. key: '1-10',
  94. // 第2级数据
  95. children: [
  96. {title: '第 1 页', key: 1, slots: {icon: 'myIcon'}},
  97. {title: '第 2 页', key: 2, slots: {icon: 'myIcon'}},
  98. {
  99. title: '第 3 页',
  100. key: 3,
  101. slots: {icon: 'myIcon'},
  102. // 第3级数据
  103. children: [
  104. {title: '第 333 页', key: 333, slots: {icon: 'myIcon'}},
  105. {title: '第 444 页', key: 444, slots: {icon: 'myIcon'}},
  106. {title: '第 555 页', key: 555, slots: {icon: 'myIcon'}},
  107. // 第4第5级以此类推,加上 children 属性即可
  108. ],
  109. },
  110. {title: '第 4 页', key: 4, slots: {icon: 'myIcon'}},
  111. {title: '第 5 页', key: 5, slots: {icon: 'myIcon'}},
  112. {title: '第 6 页', key: 6, slots: {icon: 'myIcon'}},
  113. {title: '第 7 页', key: 7, slots: {icon: 'myIcon'}},
  114. {title: '第 8 页', key: 8, slots: {icon: 'myIcon'}},
  115. {title: '第 9 页', key: 9, slots: {icon: 'myIcon'}},
  116. {title: '第 10 页', key: 10, slots: {icon: 'myIcon'}},
  117. ],
  118. slots: {icon: 'myIcon'},
  119. },
  120. {
  121. title: '11-20页',
  122. key: '11-20',
  123. children: [
  124. {title: '第 11 页', key: 11, slots: {icon: 'myIcon'}},
  125. {title: '第 12 页', key: 12, slots: {icon: 'myIcon'}},
  126. {title: '第 13 页', key: 13, slots: {icon: 'myIcon'}},
  127. {title: '第 14 页', key: 14, slots: {icon: 'myIcon'}},
  128. {title: '第 15 页', key: 15, slots: {icon: 'myIcon'}},
  129. {title: '第 16 页', key: 16, slots: {icon: 'myIcon'}},
  130. {title: '第 17 页', key: 17, slots: {icon: 'myIcon'}},
  131. {title: '第 18 页', key: 18, slots: {icon: 'myIcon'}},
  132. {title: '第 19 页', key: 19, slots: {icon: 'myIcon'}},
  133. {title: '第 20 页', key: 20, slots: {icon: 'myIcon'}},
  134. ],
  135. slots: {icon: 'myIcon'},
  136. },
  137. ],
  138. // 树展开的列,默认 1-10
  139. treeExpandedKeys: ['1-10'],
  140. // 查询url地址
  141. url: {
  142. getData: '/mock/vxe/getData',
  143. },
  144. }
  145. },
  146. created() {
  147. this.loadData()
  148. },
  149. methods: {
  150. // 加载行编辑的数据
  151. loadData() {
  152. // 封装查询条件
  153. let formData = {
  154. pageNo: this.pagination.current,
  155. pageSize: this.pagination.pageSize
  156. }
  157. // 调用查询数据接口
  158. this.loading = true
  159. getAction(this.url.getData, formData).then(res => {
  160. if (res.success) {
  161. // 后台查询回来的 total,数据总数量
  162. this.pagination.total = res.result.total
  163. // 将查询的数据赋值给 dataSource
  164. this.dataSource = res.result.records
  165. // 重置选择
  166. this.selectedRows = []
  167. } else {
  168. this.$error({title: '主表查询失败', content: res.message})
  169. }
  170. }).finally(() => {
  171. // 这里是无论成功或失败都会执行的方法,在这里关闭loading
  172. this.loading = false
  173. })
  174. },
  175. handleTablePageChange(event) {
  176. // 重新赋值
  177. this.pagination.current = event.current
  178. this.pagination.pageSize = event.pageSize
  179. // 查询数据
  180. this.loadData()
  181. // 判断树展开的key
  182. if (event.current <= 10) {
  183. this.treeExpandedKeys = ['1-10']
  184. } else {
  185. this.treeExpandedKeys = ['11-20']
  186. }
  187. },
  188. // 树被选择触发的事件
  189. handleTreeSelect(selectedKeys) {
  190. let key = selectedKeys[0]
  191. if (typeof key === 'string') {
  192. // 控制树展开为当前选择的列
  193. this.treeExpandedKeys = selectedKeys
  194. } else {
  195. this.pagination.current = key
  196. this.loadData()
  197. }
  198. },
  199. // 树被选择触发的事件
  200. handleTreeExpand(expandedKeys) {
  201. this.treeExpandedKeys = expandedKeys
  202. },
  203. },
  204. }
  205. </script>
  206. <style lang="less">
  207. /** 隐藏文件小图标 */
  208. .template-5-tree.ant-tree {
  209. li span.ant-tree-switcher.ant-tree-switcher-noop {
  210. display: none;
  211. }
  212. }
  213. </style>