c9583f63df0fb170c5f41ad1eaf8578a6c0efd46.svn-base 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <j-vxe-table
  3. ref="vTable"
  4. toolbar
  5. row-number
  6. row-selection
  7. keep-source
  8. :height="484"
  9. :loading="loading"
  10. :dataSource="dataSource"
  11. :columns="columns"
  12. :pagination="pagination"
  13. style="margin-top: 8px;"
  14. @pageChange="handlePageChange"
  15. >
  16. <template v-slot:toolbarSuffix>
  17. <a-button @click="handleTableGet">获取值</a-button>
  18. </template>
  19. </j-vxe-table>
  20. </template>
  21. <script>
  22. import moment from 'moment'
  23. import { randomNumber, randomUUID } from '@/utils/util'
  24. import { JVXETypes } from '@/components/jeecg/JVxeTable'
  25. export default {
  26. name: 'JVxeDemo2',
  27. data() {
  28. return {
  29. loading: false,
  30. columns: [
  31. {
  32. title: '下拉框_字典表搜索',
  33. key: 'select_dict_search',
  34. type: JVXETypes.selectDictSearch,
  35. width: '200px',
  36. // 【字典表配置信息】:数据库表名,显示字段名,存储字段名
  37. dict: 'sys_user,realname,username',
  38. },
  39. {
  40. title: 'JPopup',
  41. key: 'popup',
  42. type: JVXETypes.popup,
  43. width: '180px',
  44. popupCode: 'demo',
  45. field: 'name,sex,age',
  46. orgFields: 'name,sex,age',
  47. destFields: 'popup,popup_sex,popup_age'
  48. },
  49. {
  50. title: 'JP-性别',
  51. key: 'popup_sex',
  52. type: JVXETypes.select,
  53. dictCode: 'sex',
  54. disabled: true,
  55. width: '100px',
  56. },
  57. {
  58. title: 'JP-年龄',
  59. key: 'popup_age',
  60. type: JVXETypes.normal,
  61. width: '80px',
  62. },
  63. {
  64. title: '进度条',
  65. key: 'progress',
  66. type: JVXETypes.progress,
  67. minWidth: '120px'
  68. },
  69. {
  70. title: '单选',
  71. key: 'radio',
  72. type: JVXETypes.radio,
  73. width: '130px',
  74. options: [
  75. {text: '男', value: '1'},
  76. {text: '女', value: '2'},
  77. ],
  78. // 允许清除选择(再点一次取消选择)
  79. allowClear: true
  80. },
  81. {
  82. title: '上传',
  83. key: 'upload',
  84. type: JVXETypes.upload,
  85. width: '180px',
  86. btnText: '点击上传',
  87. token: true,
  88. responseName: 'message',
  89. action: window._CONFIG['domianURL'] + '/sys/common/upload'
  90. },
  91. {
  92. title: '图片上传',
  93. key: 'image',
  94. type: JVXETypes.image,
  95. width: '180px',
  96. token: true,
  97. },
  98. {
  99. title: '文件上传',
  100. key: 'file',
  101. type: JVXETypes.file,
  102. width: '180px',
  103. token: true,
  104. },
  105. ],
  106. dataSource: [],
  107. pagination: {
  108. current: 1,
  109. pageSize: 10,
  110. pageSizeOptions: ['10', '20', '30', '100', '200'],
  111. total: 1000,
  112. },
  113. }
  114. },
  115. created() {
  116. this.randomPage(this.pagination.current, this.pagination.pageSize, true)
  117. },
  118. methods: {
  119. // 当分页参数变化时触发的事件
  120. handlePageChange(event) {
  121. // 重新赋值
  122. this.pagination.current = event.current
  123. this.pagination.pageSize = event.pageSize
  124. // 查询数据
  125. this.randomPage(event.current, event.pageSize, true)
  126. },
  127. /** 获取值,忽略表单验证 */
  128. handleTableGet() {
  129. const values = this.$refs.vTable.getTableData()
  130. console.log('获取值:', {values})
  131. this.$message.success('获取值成功,请看控制台输出')
  132. },
  133. /* 随机生成数据 */
  134. randomPage(current, pageSize, loading = false) {
  135. if (loading) {
  136. this.loading = true
  137. }
  138. let randomDatetime = () => {
  139. let time = randomNumber(1000, 9999999999999)
  140. return moment(new Date(time)).format('YYYY-MM-DD HH:mm:ss')
  141. }
  142. let limit = (current - 1) * pageSize
  143. let begin = Date.now()
  144. let values = []
  145. for (let i = 0; i < pageSize; i++) {
  146. let radio = randomNumber(0, 2)
  147. values.push({
  148. id: randomUUID(),
  149. select_dict_search: ['', 'admin', '', 'jeecg', ''][randomNumber(0, 4)],
  150. progress: randomNumber(0, 100),
  151. radio: radio ? radio.toString() : null
  152. })
  153. }
  154. this.dataSource = values
  155. let end = Date.now()
  156. let diff = end - begin
  157. if (loading && diff < pageSize) {
  158. setTimeout(() => {
  159. this.loading = false
  160. }, pageSize - diff)
  161. }
  162. }
  163. }
  164. }
  165. </script>
  166. <style scoped>
  167. </style>