Blame view

ant-design-vue-jeecg/src/views/jeecg/JVxeDemo/layout-demo/Template5.vue 7.2 KB
肖超群 authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<template>
  <a-card :bordered="false">

    <a-row :gutter="8">
      <a-col :span="6">
        <!-- 加上 show-line 属性后,展开收起图标自动变成 +- 样式 -->
        <a-tree
          class="template-5-tree"
          :tree-data="treeData"
          show-icon
          show-line
          :expandedKeys="treeExpandedKeys"
          :selectedKeys="[pagination.current]"
          @expand="handleTreeExpand"
          @select="handleTreeSelect"
        >
          <!-- 自定义子节点图标 -->
          <a-icon slot="myIcon" type="unordered-list" style="color:#0c8fcf;"/>
        </a-tree>
      </a-col>
      <a-col :span="18">
        <j-vxe-table
          row-number
          row-selection
          :height="750"
          :loading="loading"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="pagination"
          @pageChange="handleTablePageChange"
        />
      </a-col>
    </a-row>


  </a-card>
</template>

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

  },
}
肖超群 authored
215
216
217
</script>

<style lang="less">
肖超群 authored
218
219
220
221
/** 隐藏文件小图标 */
.template-5-tree.ant-tree {
  li span.ant-tree-switcher.ant-tree-switcher-noop {
    display: none;
肖超群 authored
222
  }
肖超群 authored
223
}
肖超群 authored
224
</style>