SimpleEditDynamicStringList.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <div>
  3. <div>
  4. <a-button @click="() => value?.push('')">
  5. 添加 <template #icon><PlusOutlined /></template>
  6. </a-button>
  7. <a-popconfirm
  8. v-if="value && value.length > 0"
  9. title="真的要清空所有条目吗?"
  10. @confirm="value?.splice(0, value.length)"
  11. >
  12. <a-button class="ml-3" danger >
  13. <template #icon>
  14. <CloseSquareOutlined />
  15. </template>
  16. 清空
  17. </a-button>
  18. </a-popconfirm>
  19. </div>
  20. <div class="mt-2 position-relative" v-for="(v, k) in value" :key="k">
  21. <input
  22. class="display-inline-block ant-input"
  23. style="width:calc(100% - 100px)"
  24. v-model="value[k]"
  25. :maxlength="maxLength"
  26. :disabled="disabled"
  27. :placeholder="placeholder" />
  28. <a-popconfirm
  29. title="确定删除此条目吗?"
  30. @confirm="value?.slice(value.indexOf(v), 1)"
  31. >
  32. <a-button class="ml-3">
  33. <template #icon><DeleteOutlined /></template>
  34. </a-button>
  35. </a-popconfirm>
  36. </div>
  37. </div>
  38. </template>
  39. <script lang="ts">
  40. import { defineComponent, type PropType } from 'vue'
  41. import { PlusOutlined, DeleteOutlined, CloseSquareOutlined } from '@ant-design/icons-vue'
  42. /**
  43. * 简单的字符串列表动态表单
  44. */
  45. export default defineComponent({
  46. name: 'SimpleEditDynamicStringList',
  47. components: {
  48. PlusOutlined,
  49. DeleteOutlined,
  50. CloseSquareOutlined,
  51. },
  52. emits: [
  53. 'update:value',
  54. 'blur',
  55. ],
  56. props: {
  57. /**
  58. * ID
  59. */
  60. id: {
  61. required: false
  62. },
  63. /**
  64. * 参数数组
  65. */
  66. value: {
  67. type: Object as PropType<Array<string>>
  68. },
  69. /**
  70. * 输入框 placeholder
  71. */
  72. placeholder: {
  73. type: String,
  74. default: '请输入参数值',
  75. },
  76. /**
  77. * 输入框最大输入长度
  78. */
  79. maxLength: {
  80. type: Number,
  81. default: 50,
  82. },
  83. /**
  84. * sf
  85. */
  86. disabled: {
  87. type: Boolean,
  88. default: false,
  89. },
  90. },
  91. data() {
  92. return {
  93. deleteConfirm: false,
  94. }
  95. },
  96. })
  97. </script>