TableOptions.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <div class="_fc_table_opt">
  3. <el-table :data="modelValue" border size="small" style="width: 100%">
  4. <template v-for="(col, idx) in column" :key="col.label + idx">
  5. <el-table-column :label="col.label">
  6. <template #default="scope">
  7. <el-input
  8. size="small"
  9. :model-value="scope.row[col.key] || ''"
  10. @Update:modelValue="n => ((scope.row[col.key] = n), onInput(scope.row))"
  11. ></el-input>
  12. </template>
  13. </el-table-column>
  14. </template>
  15. <el-table-column min-width="50" align="center" fixed="right" :label="t('tableOptions.handle')">
  16. <template #default="scope">
  17. <i class="fc-icon icon-delete" @click="del(scope.$index)"></i>
  18. </template>
  19. </el-table-column>
  20. </el-table>
  21. <el-button link type="primary" @click="add"> <i class="fc-icon icon-add"></i> {{ t('tableOptions.add') }} </el-button>
  22. </div>
  23. </template>
  24. <script>
  25. import { defineComponent } from 'vue'
  26. export default defineComponent({
  27. name: 'TableOptions',
  28. inject: ['designer'],
  29. inheritAttrs: false,
  30. props: {
  31. modelValue: [Object, Array, String]
  32. },
  33. data() {
  34. return {
  35. column: [
  36. { label: 'label', key: 'label' },
  37. { label: 'value', key: 'value' }
  38. ],
  39. t: this.designer.setupState.t
  40. }
  41. },
  42. created() {
  43. if (!Array.isArray(this.modelValue)) {
  44. this.$emit('input', [])
  45. }
  46. },
  47. methods: {
  48. onInput(item) {
  49. if (item.label && item.value) {
  50. this.input()
  51. }
  52. },
  53. input() {
  54. this.$emit('update:modelValue', this.modelValue)
  55. },
  56. add() {
  57. this.modelValue.push(
  58. this.column.reduce((initial, v) => {
  59. initial[v.key] = ''
  60. return initial
  61. }, {})
  62. )
  63. },
  64. del(idx) {
  65. this.modelValue.splice(idx, 1)
  66. this.input(this.modelValue)
  67. }
  68. }
  69. })
  70. </script>
  71. <style scoped>
  72. ._fc_table_opt {
  73. width: 100%;
  74. }
  75. </style>