首页 > 其他分享 >封装一个Drawers 抽屉弹窗组件

封装一个Drawers 抽屉弹窗组件

时间:2023-10-31 22:00:54浏览次数:29  
标签:searchForm 5px width Drawers rgba 组件 封装 弹窗

elementui Drawer组件封装一个Drawers抽屉弹窗组件,里面新增了一些属性,例如框的宽度等

红色为Drawers组件

封装一个Drawers 抽屉弹窗组件_弹框

子组件Drawers

<template>
  <el-drawer
    v-if="showable"
    :visible.sync="showable"
    direction="rtl"
    :wrapperClosable="false"
    size="80%"
    :withHeader="false"
    :append-to-body="appendToBody"
    :modal="false"
    :destroy-on-close="true"
    :before-close="handleDrawerClose"
  >
    <slot></slot>

    <div class="close-box">
      <el-button
        class="btn_themeColor"
        type="primary"
        icon="el-icon-close"
        @click="handleDrawerClose"
      ></el-button>
    </div>
  </el-drawer>
  <!-- </div> -->
</template>
<script>
export default {
  props: {
    size: "",
    visible: {
      type: Boolean,
      default: false,
    },
    appendToBody: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      show: false,
      width: 0,
    };
  },
  created() {
    this.computedClosePos();
  },
  mounted() {},
  computed: {
    showable() {
      return this.show || this.visible;
    },
  },
  methods: {
    computedClosePos() {
      try {
        let right = (window.innerWidth * this.size.substr(0, 2)) / 100 + 50;
        this.width = right;
        document.querySelector(".el-drawer").style.minWidth = right + "px";
      } catch (error) {}
    },
    handleDrawerClose() {
      this.show = false;
      this.$emit("close");
      this.$emit("update:visible", false);
    },
  },
};
</script>
<style lang="scss" scoped>
@import "../../styles/variables.scss";

.btn_themeColor {
  background: $mainBgRs !important;
  border-color: $mainBgRs !important;
}

/deep/.el-drawer {
  padding-left: 50px;
  background: none;
  -webkit-box-shadow: none;
  box-shadow: none;
  min-width: 1000px !important;
}

/deep/.el-drawer__body {
  padding: 30px;
  background-color: #fff;
  overflow-y: auto;
  -webkit-box-shadow: 0 8px 10px -5px rgba(0, 0, 0, 0.2),
    0 16px 24px 2px rgba(0, 0, 0, 0.14), 0 6px 30px 5px rgba(0, 0, 0, 0.12);
  box-shadow: 0 8px 10px -5px rgba(0, 0, 0, 0.2),
    0 16px 24px 2px rgba(0, 0, 0, 0.14), 0 6px 30px 5px rgba(0, 0, 0, 0.12);
}

/deep/.el-drawer__header {
  display: none;
}

.close-box {
  display: inline-block;
  width: 50px;
  height: 50px;
  position: absolute;
  top: 100px;
  left: 0;

  button {
    width: 50px;
    height: 50px;
    font-size: 20px;
    text-align: center;
  }
}

.title {
  height: 40px;
  margin-bottom: 20px;

  span {
    font-weight: bold;
    font-size: 16px;
    color: #101010;
    padding: 5px 10px;
    border-bottom: 4px solid #1e90ff;
  }
}

.btns {
  width: 100%;
  text-align: center;
  position: absolute;
  bottom: 30px;
}
</style>

父组件展示图片

封装一个Drawers 抽屉弹窗组件_Drawers抽屉_02

父组件使用

<template>
	<div>
  	<div @click="clickView">查看</div>
    ...其他元素
    <Drawers ref="infoView" size="75%" @close="getDataList">
    	//其他元素
      <div>弹框内要展示的内容</div>
      //其他放在弹框内的子组件
    </Drawers>
  </div>
</template>

<script>
import Drawers from "@/components/Drawers/index.vue";
components: {Drawers,},
created() {
	this.getDataList()
},
methods: {
	// 获取数据列表
	getDataList() {
		this.dataListLoading = true

		if(this.searchForm.timeArray.length===2&&this.searchForm.timeArray[1]!==''&&this.searchForm.timeArray[1]!==null){

			this.searchForm.timeArray[1]=this.searchForm.timeArray[1].substring(0,10)+' 23:59:59';
	}

    fetchList(Object.assign({
    ...this.searchForm
    })).then(response => {
      this.dataList = response.data.data.records
      this.totalPage = response.data.data.total

      //导出使用
      this.tableNameSpace = this.$refs.table.columns;
      this.responseURL = response; //请求的链接
      this.filterCriteria = this.$refs.searchForm.fields;
    })
    this.dataListLoading = false
  },
   //新查看
    clickView() {
      this.$refs.infoView.show = true;
    },
}
  
</script>


标签:searchForm,5px,width,Drawers,rgba,组件,封装,弹窗
From: https://blog.51cto.com/u_15694202/8114490

相关文章

  • 封装高精板子
    #include<bits/stdc++.h>usingnamespacestd;constintmaxn=5005;structbign{intlen,s[MAXN];bign(){memset(s,0,sizeof(s));len=1;}bign(intnum){*this=num;}bign(constch......
  • 封装a-select下拉增加复选框,支持全选和取消全选
    由于select下拉框中内容过多,使用下拉一个一个选取太过于麻烦,所以在下拉中增加全选和取消全选操作,增加复选框选择。版本  vue3   [email protected].我们在看AntDesignVue官网中,可以发现这个dropdownRender,它可以定义下拉框中的内容。 2.封装vue组件<template......
  • JS点击空白关闭弹窗的方式
    12$(document).mouseup(function(e){3varpop=$('popDialog');4if(!pop.is(e.target)&&pop.has(e.target).length===0){5//可以在这里关闭弹窗6somecode...7}8});9判断点击事件发生在区域外的两个条件:点......
  • 【RuoYi移动端】HbuilderX实现底部弹窗示例
    一、单选样式弹窗选择1、View页面代码<uni-popupref="textBox"type="bottom"> <viewclass="select_box"> <viewclass="select_row"v-for="(item,index)instatus"@click="selectClick(item.id)"&g......
  • 用go封装一下临时token
    用go封装一下临时token本篇为用go设计开发一个自己的轻量级登录库/框架吧的临时token篇,会讲讲临时token的实现,给库/框架增加新的功能。Github:https://github.com/weloe/token-go临时token也算是比较常见的业务,例如登录验证码信息,邀请链接等等,都属于临时token的范畴。在token-......
  • ASEMI高压二极管CL08-RG210参数,CL08-RG210封装
    编辑-ZCL08-RG210参数描述:型号:CL08-RG210反向重复峰值电压VRRM:8000V反向工作峰值电压VRWM:8000V正向平均电流IF:0.5A正向(不重复)浪涌电流IFSM:20A反向恢复时间trr:80ns正向峰值电压VFM:12V反向峰值电流IR:2uA工作环境和存贮温度Ta,TSTG:-40to+150℃  CL08-RG210封装大......
  • redis缓存更新策略,缓存穿透,缓存雪崩,缓存击穿。封装redis工具类
    (redis缓存)缓存是存储数据的临时地方,一般读写性能高1.给商铺添加缓存思路:在对应的serviceImpl里写逻辑@OverridepublicResultqueryById(Longid){Stringkey=CACHE_SHOP_KEY+id;//1.从redis查询商铺缓存StringshopJSON=stringRedisTemplate.opsF......
  • ASEMI高压二极管CL08-RG210参数,CL08-RG210封装
    编辑-ZCL08-RG210参数描述:型号:CL08-RG210反向重复峰值电压VRRM:8000V反向工作峰值电压VRWM:8000V正向平均电流IF:0.5A正向(不重复)浪涌电流IFSM:20A反向恢复时间trr:80ns正向峰值电压VFM:12V反向峰值电流IR:2uA工作环境和存贮温度Ta,TSTG:-40to+150℃ CL08-RG210封装大小:直径:7.5mm长度:2......
  • 如何使用SHC对Shell脚本进行二进制编译和封装
    在许多情况下,我们需要保护我们的shell脚本源码不被别人轻易查看。这时,使用shc工具将shell脚本编译成二进制文件是一个有效的方法。本文将详细介绍如何在线和离线条件下安装shc,并将其用于编译你的脚本。什么是SHC?shc是一个由C语言编写的Shell脚本加密程序,它可以将你的脚本编译成......
  • 如何使用SHC对Shell脚本进行封装和源码隐藏
    在许多情况下,我们需要保护我们的shell脚本源码不被别人轻易查看。这时,使用shc工具将shell脚本编译成二进制文件是一个有效的方法。本文将详细介绍如何在线和离线条件下安装shc,并将其用于编译你的脚本。什么是SHC?shc是一个由C语言编写的Shell脚本加密程序,它可以将你的脚本编译成......