f9a0179ae51f985cba5c8f107eb2507f9b9f131a.svn-base 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <a-card title="无痕刷新示例" :bordered="false">
  3. <div style="margin-bottom: 8px;">
  4. <span>启用数据变动特效:</span>
  5. <a-switch v-model="reloadEffect"/>
  6. </div>
  7. <!--
  8. 【即时保存大体思路】:
  9. 1. 该功能依赖于【即时保存】功能,请先看即时保存示例
  10. 2. 必须要有 socket-reload 属性,且设为 true
  11. 3. 必须要有 socket-key 属性,该属性为当前表格的唯一标识,
  12. 系统会自动更新所有 socket-key 相同的表格
  13. 4. 在局部保存 edit-closed 事件中,
  14. 保存成功后调用 socketSendUpdateRow 方法,将当前 row 传递过去即可 (见第 108 行)
  15. -->
  16. <j-vxe-table
  17. ref="table"
  18. row-number
  19. row-selection
  20. keep-source
  21. socket-reload
  22. socket-key="demo-socket-reload"
  23. :reload-effect="reloadEffect"
  24. :height="340"
  25. :loading="loading"
  26. :columns="columns"
  27. :dataSource="dataSource"
  28. @edit-closed="handleEditClosed"
  29. />
  30. </a-card>
  31. </template>
  32. <script>
  33. import { getAction } from '@api/manage'
  34. import { JVXETypes } from '@/components/jeecg/JVxeTable'
  35. // 无痕刷新示例
  36. export default {
  37. name: 'SocketReload',
  38. data() {
  39. return {
  40. loading: false,
  41. dataSource: [],
  42. columns: [
  43. {key: 'num', title: '序号', width: '80px'},
  44. {key: 'ship_name', title: '船名', width: '180px', type: JVXETypes.input},
  45. {key: 'call', title: '呼叫', width: '80px', type: JVXETypes.input},
  46. {key: 'len', title: '长', width: '80px', type: JVXETypes.input},
  47. {key: 'ton', title: '吨', width: '120px', type: JVXETypes.input},
  48. {key: 'payer', title: '付款方', width: '120px', type: JVXETypes.input},
  49. {key: 'count', title: '数', width: '40px'},
  50. {key: 'company', title: '公司', minWidth: '180px', type: JVXETypes.input},
  51. {key: 'trend', title: '动向', width: '120px', type: JVXETypes.input},
  52. ],
  53. // 查询url地址
  54. url: {
  55. getData: '/mock/vxe/getData',
  56. },
  57. // 是否启用日历刷新效果
  58. reloadEffect: false,
  59. }
  60. },
  61. created() {
  62. this.loadData()
  63. },
  64. methods: {
  65. // 加载数据
  66. loadData() {
  67. let formData = {pageNo: 1, pageSize: 200}
  68. this.loading = true
  69. getAction(this.url.getData, formData).then(res => {
  70. if (res.success) {
  71. this.dataSource = res.result.records
  72. } else {
  73. this.$error({title: '主表查询失败', content: res.message})
  74. }
  75. }).finally(() => {
  76. this.loading = false
  77. })
  78. },
  79. // 单元格编辑完成之后触发的事件
  80. handleEditClosed(event) {
  81. let {$table, row, column} = event
  82. let field = column.property
  83. let cellValue = row[field]
  84. // 判断单元格值是否被修改
  85. if ($table.isUpdateByRow(row, field)) {
  86. // 校验当前行
  87. $table.validate(row).then((errMap) => {
  88. // 校验通过
  89. if (!errMap) {
  90. // 【模拟保存】(此处需要替换成真实的请求)
  91. let hideLoading = this.$message.loading(`正在保存"${column.title}"`, 0)
  92. setTimeout(() => {
  93. hideLoading()
  94. this.$message.success(`"${column.title}"保存成功!`)
  95. // 局部更新单元格为已保存状态
  96. $table.reloadRow(row, null, field)
  97. // 发送更新消息
  98. this.$refs.table.socketSendUpdateRow(row)
  99. }, 555)
  100. }
  101. })
  102. }
  103. },
  104. },
  105. }
  106. </script>
  107. <style scoped>
  108. </style>