index.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <!-- 多选对话框 -->
  2. <template>
  3. <div>
  4. <el-dialog
  5. title="选择服务器"
  6. :visible="visible"
  7. width="48%"
  8. :modal-append-to-body="false"
  9. center
  10. @close="handleCloseDialog"
  11. >
  12. <el-button-group>
  13. <el-button
  14. size="mini"
  15. plain
  16. type="primary"
  17. @click="handleSelectAll"
  18. >全选</el-button>
  19. <el-button
  20. size="mini"
  21. plain
  22. type="primary"
  23. @click="handleDeselectAll"
  24. >全不选</el-button>
  25. </el-button-group>
  26. <div style="margin: 30px 0" />
  27. <el-checkbox-group v-model="checkedServer" @change="handleCheckedId">
  28. <el-checkbox
  29. v-for="item in serverOptions"
  30. :key="item.value"
  31. :label="item.value"
  32. :vlaue="item.value"
  33. >{{ item.text }}</el-checkbox>
  34. </el-checkbox-group>
  35. <template #footer>
  36. <el-button type="primary" size="small" @click="handleConfirm">确 认</el-button>
  37. <el-button size="small" @click="handleCloseDialog">取 消</el-button>
  38. </template>
  39. </el-dialog>
  40. </div>
  41. </template>
  42. <script>
  43. export default {
  44. props: {
  45. visible: Boolean,
  46. serverOptions: {
  47. type: Array,
  48. default: () => []
  49. }
  50. },
  51. data() {
  52. return {
  53. checkedServer: [] // 选中的服务器
  54. }
  55. },
  56. methods: {
  57. // 全选
  58. handleSelectAll() {
  59. this.checkedServer = this.serverOptions.map((item) => item.value)
  60. },
  61. // 全不选
  62. handleDeselectAll() {
  63. this.checkedServer = []
  64. },
  65. // 选中的服务器ID
  66. handleCheckedId(val) {
  67. this.checkedServer = val
  68. },
  69. // 确认按钮
  70. handleConfirm() {
  71. this.$emit('checkedId', this.checkedServer)
  72. },
  73. // 关闭弹窗
  74. handleCloseDialog() {
  75. this.$emit('update:visible', false)
  76. }
  77. }
  78. }
  79. </script>