1
0

fileModal.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div class="title">目录类型 : </div>
  3. <div class="content">
  4. <template v-for="(tag, index) in state.tags" :key="tag">
  5. <a-tag :closable="index !== 0" @close="handleClose(tag)">
  6. {{ tag }}
  7. </a-tag>
  8. </template>
  9. <a-input
  10. v-if="state.inputVisible"
  11. ref="inputRef"
  12. v-model:value="state.inputValue"
  13. type="text"
  14. size="small"
  15. :style="{ width: '78px' }"
  16. @blur="handleInputConfirm"
  17. @keyup.enter="handleInputConfirm"
  18. />
  19. <a-tag v-else style="background: #fff; border-style: dashed" @click="showInput">
  20. <plus-outlined />
  21. 新增目录
  22. </a-tag>
  23. </div>
  24. <div class="footer">
  25. <a-button style="margin-right: 10px" type="primary" @click="handleSubmit">保存</a-button>
  26. <a-button type="primary" @click="handleSubmit">取消</a-button>
  27. </div>
  28. </template>
  29. <script lang="ts" setup>
  30. import { ref, reactive, toRefs, nextTick } from 'vue';
  31. import { PlusOutlined } from '@ant-design/icons-vue';
  32. components: {
  33. PlusOutlined;
  34. }
  35. // 声明Emits
  36. const emit = defineEmits(['saveOrUpdate']);
  37. const inputRef = ref();
  38. const state = reactive({
  39. tags: ['台账类文件', '法律法规', '其他', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17'],
  40. inputVisible: false,
  41. inputValue: '',
  42. });
  43. const handleClose = (removedTag: string) => {
  44. const tags = state.tags.filter((tag) => tag !== removedTag);
  45. console.log(tags);
  46. state.tags = tags;
  47. };
  48. const showInput = () => {
  49. state.inputVisible = true;
  50. nextTick(() => {
  51. inputRef.value.focus();
  52. });
  53. };
  54. const handleInputConfirm = () => {
  55. const inputValue = state.inputValue;
  56. let tags = state.tags;
  57. if (inputValue && tags.indexOf(inputValue) === -1) {
  58. tags = [...tags, inputValue];
  59. }
  60. console.log(tags);
  61. Object.assign(state, {
  62. tags,
  63. inputVisible: false,
  64. inputValue: '',
  65. });
  66. };
  67. //表单提交事件
  68. async function handleSubmit(v) {
  69. try {
  70. // emit('saveOrUpdate', values);
  71. emit('saveOrUpdate', false);
  72. } finally {
  73. // setModalProps({ confirmLoading: false });
  74. }
  75. }
  76. </script>
  77. <style lang="less" scoped>
  78. .title {
  79. margin-bottom: 10px;
  80. }
  81. .footer {
  82. position: absolute;
  83. right: 20px;
  84. bottom: 20px;
  85. }
  86. ::v-deep .zxm-tag {
  87. margin-bottom: 10px;
  88. border-color: #3ad8ff77;
  89. background-color: #ffffff00 !important;
  90. color: #fff;
  91. }
  92. ::v-deep .zxm-tag-close-icon {
  93. color: #fff;
  94. }
  95. </style>