EditPopover.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <el-popover
  3. v-bind="$attrs"
  4. :trigger="$attrs.trigger || 'click'"
  5. :width="$attrs.width || '240px'"
  6. popper-class="le-edit-popper"
  7. :visible="comp_visible"
  8. @update:visible="visibleChange"
  9. >
  10. <template #reference>
  11. <slot name="reference">
  12. <el-button icon="Edit" />
  13. </slot>
  14. </template>
  15. <div class="le-edit-popper_content-wrap">
  16. <slot>
  17. <div class="title">模拟标题</div>
  18. <el-scrollbar max-height="400px">
  19. <div class="content">
  20. <div v-for="(_, i) of Array.from({ length: 40 })" :key="i">
  21. 我是内容 <br />
  22. {{ i }}
  23. </div>
  24. </div>
  25. </el-scrollbar>
  26. </slot>
  27. <div v-if="showFooter" class="footer">
  28. <el-button @click="onCancel">{{ $t('le.btn.cancel') }}</el-button>
  29. <el-button type="primary" style="margin-left: 8px" @click="onSubmit">{{ $t('le.btn.confirm') }}</el-button>
  30. </div>
  31. </div>
  32. </el-popover>
  33. </template>
  34. <script setup name="LeEditPopover" lang="ts">
  35. defineOptions({ name: 'LeEditPopover' })
  36. import { computed, ref, watch } from 'vue'
  37. const emit = defineEmits(['update:visible', 'getCurRow'])
  38. const props = defineProps({
  39. visible: {
  40. type: Boolean,
  41. default: null
  42. },
  43. showFooter: {
  44. type: Boolean,
  45. default: true
  46. },
  47. submit: {
  48. type: Function,
  49. default: () => console.warn('请添加 submit 进行确定')
  50. },
  51. cancel: {
  52. type: Function
  53. }
  54. })
  55. const localVisible = ref(false)
  56. const comp_visible = computed(() => {
  57. if (typeof props.visible !== 'boolean') return localVisible.value
  58. return props.visible
  59. })
  60. watch(
  61. comp_visible,
  62. (bool: boolean) => {
  63. // 提示更新当前row数据
  64. if (bool) {
  65. emit('getCurRow')
  66. }
  67. },
  68. {
  69. immediate: true
  70. }
  71. )
  72. const visibleChange = (visible: boolean) => {
  73. emit('update:visible', visible)
  74. localVisible.value = visible
  75. }
  76. const onCancel = () => {
  77. if (props.cancel) props.cancel()
  78. visibleChange(false)
  79. }
  80. const onSubmit = () => {
  81. props.submit?.()
  82. visibleChange(false)
  83. }
  84. </script>
  85. <style lang="scss">
  86. // le-edit-popper
  87. .#{$prefix}edit-popper {
  88. &_content-wrap {
  89. position: relative;
  90. .title {
  91. //border-bottom: 1px solid
  92. //border-bottom: 1px solid var(--el-card-border-color);
  93. border-bottom: 1px solid var(--el-border-color-light);
  94. margin: -12px;
  95. margin-bottom: 12px;
  96. font-size: 15px;
  97. padding: 10px 12px;
  98. color: var(--el-text-color-primary);
  99. font-weight: 500;
  100. //margin-right: -12px;
  101. //margin-left: - var(--el-popover-padding);
  102. //margin-right: - var(--el-popover-padding);
  103. }
  104. .footer {
  105. padding-top: 10px;
  106. text-align: right;
  107. }
  108. }
  109. }
  110. </style>