DeviceSettingPopover.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <a-popover :visible="state.sVisible" trigger="click" v-bind="$attrs" :overlay-class-name="overlayClassName"
  3. placement="bottom" @visibleChange=";" v-on="$attrs">
  4. <template #content>
  5. <div class="title-content">
  6. </div>
  7. <slot name="formContent"></slot>
  8. <div class="uranus-popconfirm-btns">
  9. <a-button size="sm" @click="onCancel">
  10. {{ cancelText || '取消' }}
  11. </a-button>
  12. <a-button size="sm" :loading="loading" type="primary" class="confirm-btn" @click="onConfirm">
  13. {{ okText || '确定' }}
  14. </a-button>
  15. </div>
  16. </template>
  17. <template v-if="$slots.default">
  18. <slot></slot>
  19. </template>
  20. </a-popover>
  21. </template>
  22. <script lang="ts" setup>
  23. import { reactive, watch, computed } from 'vue'
  24. const props = defineProps<{
  25. visible?: boolean,
  26. loading?: Boolean,
  27. disabled?: Boolean,
  28. title?: String,
  29. okText?: String,
  30. cancelText?: String,
  31. width?: Number,
  32. }>()
  33. const emit = defineEmits(['cancel', 'confirm'])
  34. const state = reactive({
  35. sVisible: false,
  36. loading: false,
  37. })
  38. watch(() => props.visible, (val) => {
  39. state.sVisible = val || false
  40. })
  41. const loading = computed(() => {
  42. return props.loading
  43. })
  44. const okLabel = computed(() => {
  45. return props.loading ? '' : '确定'
  46. })
  47. const overlayClassName = computed(() => {
  48. const classList = ['device-setting-popconfirm']
  49. return classList.join(' ')
  50. })
  51. function onConfirm(e: Event) {
  52. if (props.disabled) {
  53. return
  54. }
  55. emit('confirm', e)
  56. }
  57. function onCancel(e: Event) {
  58. state.sVisible = false
  59. emit('cancel', e)
  60. }
  61. </script>
  62. <style lang="scss">
  63. .device-setting-popconfirm {
  64. min-width: 300px;
  65. .uranus-popconfirm-btns {
  66. display: flex;
  67. padding: 10px 0px;
  68. justify-content: flex-end;
  69. .confirm-btn {
  70. margin-left: 10px;
  71. }
  72. }
  73. .form-content {
  74. display: inline-flex;
  75. align-items: center;
  76. .form-label {
  77. padding-right: 10px;
  78. }
  79. }
  80. }
  81. </style>