Ant design vue 弹窗多选组件


<template>
  <a-dropdown :trigger="['click']" placement="bottomRight"
    overlayClassName="table-column-setting-box"
    v-model="visible">
    <a-icon type='setting' style='cursor: pointer' class="ml-10" />
    <a-menu slot="overlay">
      <a-row class="select-group-box">
        <a-checkbox-group :value="value" @change="handleChange" class="item-checkbox-group">
          <a-row v-for="item in allList" :key="item.name"
              class="item" :class="{'checked': value.includes(String(item.name))}"
              v-show="item.name !== 'action'">
            <a-checkbox :value="item.name"
              :disabled="item.configurable === false
               || item.fixed
               || (value.length <= 4 && value.includes(String(item.name)))"
              class="item-label">{{item.title}}</a-checkbox>
          </a-row>
        </a-checkbox-group>
      </a-row>
      <a-menu-divider />
      <a-row class="btns">
        <a-button @click="handleOk" :disabled="value.length === 0" class="ok">{{t('Save')}}</a-button>
      </a-row>
    </a-menu>
  </a-dropdown>
</template>
<script lang='ts'>
import { Component, Prop, Vue, Model } from 'vue-property-decorator';

@Component
export default class SettingPopBox extends Vue {
  @Model('change', { default: () => [] })
  protected value!: string[];
  // 所有列
  @Prop({type: Array, default: () => []})
  protected allList!: TypeBase.TableColumn[];
  // 当前选中
  protected curSelectedList: string[] = [];
  // 弹窗显示状态
  protected visible: boolean = false;

  // 确认选中
  protected handleOk(): void {
    this.visible = false;
  }
  // 复选框变更事件(勾选或取消勾选)
  protected handleChange(checkedList: string[]) {
    // 固定展示顺序
    const resList = this.allList.reduce((pre: string[], item: TypeBase.TableColumn) => {
      const res: string[] = [];
      if(checkedList.includes(item.name as string)) {
        res.push(item.name as string);
      } 
      return pre.concat(res);
    }, []);
    this.handleEmit(resList);
    
  }
  // 处理分发事件
  protected handleEmit(data: string[]) {
    this.$emit('change', data);
  }
}
</script>
<style lang='scss' scoped>
.table-column-setting-box {
  .select-group-box{
    width: 100%;
    max-height: 320px;
    overflow-y: auto;
    .item-checkbox-group{
      width: 100%;
    }
  }
  .ant-row{
    width: 100%;
    line-height: 40px;
    padding: 0 6px;
    border-radius: 4px;
    user-select: none;
    &.item {
      height: 40px;
      margin-bottom: 2px;
      &.checked{
        background-color: var(--secondary-color1);
        color: var(--brand-secondary-color);
      }
      &.checked .item-label{
        color: var(--brand-secondary-color);
      }
      &:not(.btns):hover{
        background-color: var(--secondary-color1);
        color: var(--brand-secondary-color);
        .item-label{
          color: var(--brand-secondary-color);
        }
      }
    }
    .ant-checkbox-wrapper{
      width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
  .btns{
    height: 42px;
    margin-top: 6px;
    padding: 0 12px;
    text-align: right;
    .ok{
      height: 32px;
      border-radius: 8px;
    }
  }
}
</style>
<style lang="scss">
  .table-column-setting-box .ant-dropdown-menu{
    max-width: 540px;
    padding: 6px 0;
  }
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你想了解有关 Ant Design Vue弹窗的内容吗?Ant Design Vue 是一个基于 Vue.js 的 UI 组件库,它提供了丰富的组件,包括弹窗(Modal)组件。你可以使用 Modal 组件来创建弹窗窗口。 要使用 Ant Design Vue弹窗组件,首先确保你已经按照官方文档中的指导安装和引入了 Ant Design Vue。然后,你可以按照以下步骤来创建一个弹窗: 1. 在你的 Vue 组件中引入 Modal 组件: ```vue <template> <div> <a-button @click="showModal">打开弹窗</a-button> <a-modal v-model="visible" title="这是一个弹窗"> <p>这是弹窗的内容。</p> </a-modal> </div> </template> <script> import { Modal, Button } from 'ant-design-vue'; export default { components: { 'a-modal': Modal, 'a-button': Button, }, data() { return { visible: false, }; }, methods: { showModal() { this.visible = true; }, }, }; </script> ``` 在这个示例中,我们引入了 Modal 和 Button 组件,并在点击按钮时设置 `visible` 变量为 `true`,从而显示弹窗。Modal 组件是一个带有标题和内容的弹窗容器,你可以在其中放置任意内容。 2. 根据你的需求,你可以自定义 Modal 组件的行为和样式。你可以在文档中查找更多关于 Modal 组件的信息,例如如何设置弹窗的宽度、高度、遮罩等。 这就是使用 Ant Design Vue 创建弹窗的基本步骤。你可以根据你的实际需求对弹窗进行进一步的定制和使用。希望这能帮到你!如果你还有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值