Blame view

ant-design-vue-jeecg/src/views/jeecg/JVxeDemo/JVxeDemo2.vue 4.41 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
<template>
  <j-vxe-table
    ref="vTable"
    toolbar
    row-number
    row-selection
    keep-source
    :height="484"
    :loading="loading"
    :dataSource="dataSource"
    :columns="columns"
    :pagination="pagination"
    style="margin-top: 8px;"
    @pageChange="handlePageChange"
  >

    <template v-slot:toolbarSuffix>
      <a-button @click="handleTableGet">获取值</a-button>
    </template>

  </j-vxe-table>
</template>

<script>
肖超群 authored
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import moment from 'moment'
import {randomNumber, randomUUID} from '@/utils/util'
import {JVXETypes} from '@/components/jeecg/JVxeTable'

export default {
  name: 'JVxeDemo2',
  data() {
    return {
      loading: false,
      columns: [
        {
          title: '下拉框_字典表搜索',
          key: 'select_dict_search',
          type: JVXETypes.selectDictSearch,
          width: '200px',
          // 【字典表配置信息】:数据库表名,显示字段名,存储字段名
          dict: 'sys_user,realname,username',
肖超群 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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
        {
          title: 'JPopup',
          key: 'popup',
          type: JVXETypes.popup,
          width: '180px',
          popupCode: 'demo',
          field: 'name,sex,age',
          orgFields: 'name,sex,age',
          destFields: 'popup,popup_sex,popup_age'
        },
        {
          title: 'JP-性别',
          key: 'popup_sex',
          type: JVXETypes.select,
          dictCode: 'sex',
          disabled: true,
          width: '100px',
        },
        {
          title: 'JP-年龄',
          key: 'popup_age',
          type: JVXETypes.normal,
          width: '80px',
        },
        {
          title: '进度条',
          key: 'progress',
          type: JVXETypes.progress,
          minWidth: '120px'
        },
        {
          title: '单选',
          key: 'radio',
          type: JVXETypes.radio,
          width: '130px',
          options: [
            {text: '男', value: '1'},
            {text: '女', value: '2'},
          ],
          // 允许清除选择(再点一次取消选择)
          allowClear: true
        },
        {
          title: '上传',
          key: 'upload',
          type: JVXETypes.upload,
          width: '180px',
          btnText: '点击上传',
          token: true,
          responseName: 'message',
          action: window._CONFIG['domianURL'] + '/sys/common/upload'
        },
        {
          title: '图片上传',
          key: 'image',
          type: JVXETypes.image,
          width: '180px',
          token: true,
        },
        {
          title: '文件上传',
          key: 'file',
          type: JVXETypes.file,
          width: '180px',
          token: true,
        },
      ],
      dataSource: [],
      pagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30', '100', '200'],
        total: 1000,
      },
    }
肖超群 authored
118
肖超群 authored
119
120
121
122
123
124
125
126
127
128
129
130
131
132
  },

  created() {
    this.randomPage(this.pagination.current, this.pagination.pageSize, true)
  },
  methods: {

    // 当分页参数变化时触发的事件
    handlePageChange(event) {
      // 重新赋值
      this.pagination.current = event.current
      this.pagination.pageSize = event.pageSize
      // 查询数据
      this.randomPage(event.current, event.pageSize, true)
肖超群 authored
133
134
    },
肖超群 authored
135
136
137
138
139
    /** 获取值,忽略表单验证 */
    handleTableGet() {
      const values = this.$refs.vTable.getTableData()
      console.log('获取值:', {values})
      this.$message.success('获取值成功,请看控制台输出')
肖超群 authored
140
141
    },
肖超群 authored
142
143
144
145
146
    /* 随机生成数据 */
    randomPage(current, pageSize, loading = false) {
      if (loading) {
        this.loading = true
      }
肖超群 authored
147
肖超群 authored
148
149
150
151
      let randomDatetime = () => {
        let time = randomNumber(1000, 9999999999999)
        return moment(new Date(time)).format('YYYY-MM-DD HH:mm:ss')
      }
肖超群 authored
152
肖超群 authored
153
154
155
156
157
158
159
160
161
162
163
164
      let limit = (current - 1) * pageSize

      let begin = Date.now()
      let values = []
      for (let i = 0; i < pageSize; i++) {
        let radio = randomNumber(0, 2)
        values.push({
          id: randomUUID(),
          select_dict_search: ['', 'admin', '', 'jeecg', ''][randomNumber(0, 4)],
          progress: randomNumber(0, 100),
          radio: radio ? radio.toString() : null
        })
肖超群 authored
165
      }
肖超群 authored
166
167
168
169
170
171
172
173
174
175
176

      this.dataSource = values
      let end = Date.now()
      let diff = end - begin

      if (loading && diff < pageSize) {
        setTimeout(() => {
          this.loading = false
        }, pageSize - diff)
      }
肖超群 authored
177
178
    }
  }
肖超群 authored
179
}
肖超群 authored
180
181
182
183
184
</script>

<style scoped>

</style>