EditableCell.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <div class="editable-cell">
  3. <div v-if="editable" class="editable-cell-input-wrapper">
  4. <a-input :value="value" @change="handleChange" @pressEnter="check" /><a-icon
  5. type="check"
  6. class="editable-cell-icon-check"
  7. @click="check"
  8. />
  9. </div>
  10. <div v-else class="editable-cell-text-wrapper">
  11. {{ value || ' ' }}
  12. <a-icon type="edit" class="editable-cell-icon" @click="edit" />
  13. </div>
  14. </div>
  15. </template>
  16. <script>
  17. export default {
  18. name: 'EditableCell',
  19. props: {
  20. text: {
  21. type: String,
  22. default: ''
  23. }
  24. },
  25. data () {
  26. return {
  27. value: this.text,
  28. editable: false
  29. }
  30. },
  31. methods: {
  32. handleChange (e) {
  33. this.value = e.target.value
  34. },
  35. check () {
  36. this.editable = false
  37. this.$emit('change', this.value)
  38. },
  39. edit () {
  40. console.log(1111, this.text)
  41. this.editable = true
  42. }
  43. }
  44. }
  45. </script>
  46. <style>
  47. .editable-cell {
  48. position: relative;
  49. }
  50. .editable-cell-input-wrapper,
  51. .editable-cell-text-wrapper {
  52. padding-right: 24px;
  53. }
  54. .editable-cell-text-wrapper {
  55. padding: 5px 24px 5px 5px;
  56. }
  57. .editable-cell-icon,
  58. .editable-cell-icon-check {
  59. position: absolute;
  60. right: 0;
  61. width: 20px;
  62. cursor: pointer;
  63. }
  64. .editable-cell-icon {
  65. line-height: 18px;
  66. display: none;
  67. }
  68. .editable-cell-icon-check {
  69. line-height: 28px;
  70. }
  71. .editable-cell:hover .editable-cell-icon {
  72. display: inline-block;
  73. }
  74. .editable-cell-icon:hover,
  75. .editable-cell-icon-check:hover {
  76. color: #108ee9;
  77. }
  78. .editable-add-btn {
  79. margin-bottom: 8px;
  80. }
  81. </style>