封装左侧抽屉可拖拽组件【可多个】

news2024/9/28 10:26:26

一、案例效果

在这里插入图片描述
在这里插入图片描述

二、案例代码

  • 封装抽屉组件
<template>
  <div class="drag-drawer">
    <div class="out-box" :style="style">
      <mtd-tooltip
        :content="collapse ? '展开面板' : '收起面板'"
        class="tool-tip"
        :placement="mode === 'right' ? 'left' : 'right'"
        :show-arrow="false"
      >
        <div class="switch" @mousedown="onSwitchDragStart($event)"></div>
      </mtd-tooltip>
    </div>
    <div
      class="border"
      @mousedown="onDragStart($event)"
      :style="borderStyle"
    ></div>
    <div
      class="wrapper"
      v-if="!collapse"
      :style="{ width: currentWidth + 'px', paddingLeft: '20px' }"
    >
      <slot name="content"></slot>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';

@Component
export default class DragDrawer extends Vue {
  @Prop({ type: String, default: 'right' }) public mode!: string;
  @Prop({ type: Boolean, default: false }) private hasTab?: boolean;
  @Prop({ type: Number, default: 0 }) private leftMargin: number;

  private collapse = false;
  private currentWidth = 400;
  private fromPage = '';

  get style() {
    if (!this.isLeft) {
      return {
        right: this.collapse ? '-3px' : `${this.currentWidth - 2}px`,
      };
    } else {
      return {
        left: this.collapse
          ? -3 + this.leftMargin + 'px'
          : `${this.currentWidth - 2}px`,
        transform: 'rotate(180deg)',
      };
    }
  }

  // drawer是否在左侧
  get isLeft() {
    return this.mode === 'left';
  }

  get borderStyle() {
    if (this.isLeft) {
      return {
        right: 0,
      };
    } else {
      return {
        left: 0,
      };
    }
  }
  private onDragStart(e: any) {
    const startWidth = this.currentWidth;
    const pageX = e.pageX;
    let isMoving = false;

    const moveCb = (ev: any) => {
      if (this.collapse) {
        return;
      }
      const currentWidth = this.isLeft
        ? startWidth + (ev.pageX - pageX)
        : startWidth + pageX - ev.pageX;
      if (currentWidth > 360 && currentWidth <= 800) {
        this.currentWidth = currentWidth;
      }
      isMoving = true;
    };
    const upCb = () => {
      this.$store.state.paint.key++;

      document.removeEventListener('mousemove', moveCb);
      document.removeEventListener('mouseup', upCb);
    };

    document.addEventListener('mousemove', moveCb);
    document.addEventListener('mouseup', upCb);
  }

  private onSwitchDragStart(e: any) {
    const startWidth = this.currentWidth;
    const pageX = e.pageX;
    let isMoving = false;
    const moveCb = (ev: any) => {
      if (this.collapse) {
        return;
      }
      const currentWidth = this.isLeft
        ? startWidth + (ev.pageX - pageX)
        : startWidth + pageX - ev.pageX;

      if (currentWidth > 360 && currentWidth <= 800) {
        this.currentWidth = currentWidth;
      }
      isMoving = true;
    };
    const upCb = () => {
      document.removeEventListener('mousemove', moveCb);
      document.removeEventListener('mouseup', upCb);
      if (!isMoving) {
        this.collapse = !this.collapse;
      }
    };

    document.addEventListener('mousemove', moveCb);
    document.addEventListener('mouseup', upCb);
  }
}
</script>

<style scoped lang="less">
.drag-drawer {
  background: #fff;
  position: relative;
  width: 100%;
  height: 100%;
  .out-box {
    font-size: 20px;
    cursor: pointer;
    width: 18px;
    z-index: 999;
    position: absolute;
    background: #edededfd;
    top: 0;
    bottom: 0;
    height: 100%;
    .tool-tip {
      display: inline-block;
      width: 20px;
      height: 40px;
      position: relative;
      top: 93%;
      .switch {
        height: 100%;
        background: url('../../../assets/paintSwitch.png') no-repeat center
          center;
        background-size: cover;
        -moz-user-select: none; /* Firefox私有属性 */
        -webkit-user-select: none; /* WebKit内核私有属性 */
        -ms-user-select: none; /* IE私有属性(IE10及以后) */
        -khtml-user-select: none; /* KHTML内核私有属性 */
        -o-user-select: none; /* Opera私有属性 */
        user-select: none; /* CSS3属性 */
        &:hover {
          background-image: url('../../../assets/paintSwitchHover.png');
        }
      }
    }

    .nav {
      position: absolute;
      right: 10px;
      text-decoration: none;
      display: inline-block;
      width: 25px;
      height: 25px;
      cursor: pointer;
      padding: 3px 0 0 6px;
      .text {
        font-size: 12px;
        width: 25px;
        transform: rotate(-180deg);
      }
      &:hover {
        color: dodgerblue;
      }
    }
    .nav::after {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: #fff;
      border: 1px solid #edededfd;
      border-right: none;
      border-radius: 5px 0 0 5px;
      box-shadow: -3px -3px 5px #edededfd;
      transform: perspective(10px) scale(1.1, 1.3) rotateY(-15deg);
      z-index: -1;
    }
    .tab_s {
      color: dodgerblue;
    }
  }

  .border {
    width: 1px;
    background: rgba(0, 0, 0, 0.12);
    box-sizing: border-box;
    position: absolute;
    top: 0;
    bottom: 0;
    cursor: col-resize;
    z-index: 9999;
  }

  .wrapper {
    height: 100%;
  }
}
</style>

  • 使用组件
 <DragDrawer ref="drawer" mode="left">
  <template slot="content"> 抽屉内容1 </template>
</DragDrawer>
<DragDrawer ref="drawer" mode="left" :leftMargin="21">
  <template slot="content"> 抽屉内容2 </template>
</DragDrawer>

三、 使用的图片

可换成icon哦
在这里插入图片描述
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2173184.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

828华为云征文|部署敏捷项目管理系统工具 ZenTao

828华为云征文&#xff5c;部署敏捷项目管理系统工具 ZenTao 一、Flexus云服务器X实例介绍二、Flexus云服务器X实例配置2.1 重置密码2.2 服务器连接2.3 安全组配置2.4 Docker 环境搭建 三、Flexus云服务器X实例部署 ZenTao3.1 ZenTao 介绍3.2 ZenTao 部署3.3 ZenTao 使用 四、总…

云 安 全 (Cloud Security)

&#x1f49d;&#x1f49d;&#x1f49d;欢迎来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 本人主要分享计算机核心技…

robomimic基础教程(四)——开源数据集

robomimic开源了大量数据集及仿真环境&#xff0c;数据集标准格式为HDF5 目录 一、基础要求 二、使用步骤 1. 下载数据集 2. 后处理 3. 训练 4. 查看训练结果 三、HDF5数据集结构与可视化 1. 数据集结构 &#xff08;1&#xff09;根级别&#xff08;data 组 group&a…

overlayscrollbars使用

官网 https://github.com/KingSora/OverlayScrollbars 使用 <link href"https://cdn.bootcdn.net/ajax/libs/overlayscrollbars/2.10.0/styles/overlayscrollbars.css" rel"stylesheet"> <script src"https://cdn.bootcdn.net/ajax/libs/…

AP配置(leaderAP组网模式)

1.前言 由于业务需求&#xff0c;临时组建一个网络环境使用 网络设备&#xff1a;华为 AirEngine 5762-10、5762S-12 2.网络结构 参考文档&#xff0c;使用leader ap组网模式 使用一台5862S-12作为leaderAP&#xff0c;AP通电后默认是fit模式&#xff0c;需要进入修改 如果…

HA Peer-mode非对称路由配置

目录 前言 一、组网拓扑 二、配置步骤 1.Hillstone-A 2.Hillstone-B 总结 前言 网络环境有非对称流量且需要双活部署时&#xff0c;防火墙可配置HA的peer-mode非对称路由模式进行实现。 一、组网拓扑 数据流量的路径是非对称的&#xff08;即 Flow0和Flow1是两条不同流量…

线性代数~行列式计算

来自b站博主&#xff0c;我爱一高数

【系统交付资料】软件文档交付清单整理套用原件(Word,PPT,Excel)

软件文档交付清单是指在软件开发项目完成后&#xff0c;开发团队需要准备的一份详细清单&#xff0c;用于确保交付的软件产品符合客户需求并达到预期的质量标准。以下是软件文档交付清单中可能包含的一些关键要素 软件资料清单列表部分文档清单&#xff1a;工作安排任务书&…

音视频入门基础:FLV专题(7)——Tag header简介

一、引言 从《音视频入门基础&#xff1a;FLV专题&#xff08;3&#xff09;——FLV header简介》中可以知道&#xff0c; 在FLV header之后&#xff0c;FLV文件剩下的部分应由PreviousTagSize和Tag组成。FLV文件 FLV header PreviousTagSize0 Tag1 PreviousTagSize1 Ta…

顺序表算法题 —— 移除元素、删除有序数组中的重复项、合并两个有序数组

目录 一、顺序表算法题 1、移除元素 2、删除有序数组中的重复项 3、 合并两个有序数组 二、顺序表问题与思考 一、顺序表算法题 1、移除元素 移除元素 - 力扣&#xff08;LeetCode&#xff09; 思路分析&#xff1a; 思路一&#xff1a;创建一个新数组&#xff0c;开辟…

828华为云征文|在Flexus X实例上安装JDK和Tomcat保姆教学

目录 一、Flexus云服务器X实例 1.1 Flexus X实例概述 1.2 Flexus X实例场景优势 1.3 其他型号与Flexus X实例比较 二、Flexus X实例上安装JDK 2.1 确定安装版本 2.2 yum命令直接安装 2.3 查看版本 三、Flexus X实例上安装tomcat 3.1 上传安装包到Flexus X实例服务器 …

拯救Air780EP模块紧急项目:异常断链的吐血经历。。。

小编最近被老板驱使&#xff0c;要用Air780EP模块做几个紧急项目 并且由于时间紧任务重&#xff0c;遇到了一些棘手问题&#xff0c;简直呕心沥血…… 左思右想&#xff0c;还是在这里把遇到的问题&#xff0c;排查记录下来 也许可以帮到因遇到类似的问题&#xff0c;并且一…

你要的Air201录音和播放录音功能?直接拿去!

最近拼拼收到同学们的疑问&#xff1a;Air201是否支持录音、播放录音功能&#xff1f; 必须支持&#xff01;Air201可是高集成化设计&#xff0c;并且Air201自带了ES8311音频解码芯片&#xff08;Audio Codec&#xff09;及MIC麦克&#xff0c;可支持本地的录音功能&#xff1…

掌握编码最佳实践

你准备好把你的编程技能提升到一个新的水平了吗&#xff1f;在本文中&#xff0c;我们将探讨秘密破坏您的生产力的常见编码错误&#xff0c;并分享您需要了解的优化工作流程的最佳实践。 通过实施这些技巧&#xff0c;您将更快&#xff0c;更智能地编码&#xff0c;并在创纪录…

预训练词向量的使用

目录 1.代码实现 2.知识点&#xff1a; 两个网站可以下载预训练词向量 GloVe网站&#xff1a;GloVe: Global Vectors for Word RepresentationfastText网站&#xff1a;https://fasttext.cc 1.代码实现 import os import torch from torch import nn import dltools class …

文章解读与仿真程序复现思路——中国电机工程学报EI\CSCD\北大核心《考虑异步区域调频资源互济的电能、惯性与一次调频联合优化出清模型》

本专栏栏目提供文章与程序复现思路&#xff0c;具体已有的论文与论文源程序可翻阅本博主免费的专栏栏目《论文与完整程序》 论文与完整源程序_电网论文源程序的博客-CSDN博客https://blog.csdn.net/liang674027206/category_12531414.html 电网论文源程序-CSDN博客电网论文源…

Web后端开发原理!!!什么是自动配置???什么是起动依赖???

引言&#xff1a; 当然&#xff0c;在我们学习的过程中&#xff0c;得知其然&#xff0c;还得知其所以然。So理解了其原理&#xff0c;更能让我们对其开发的理解&#xff0c;遇到问题&#xff0c;也更能快速找到解决办法&#xff01;&#xff01;&#xff01; 1. SprngBoot-配…

网站建设中,营销型网站与普通网站有什么区别

营销型网站与普通网站在建站目的、交互设计以及结构优化等方面存在区别。以下是具体分析&#xff1a; 建站目的 营销型网站&#xff1a;以销售和转化为主要目标&#xff0c;通过专业的市场分析和策划来吸引潜在客户&#xff0c;并促使其采取购买行动。普通网站&#xff1a;通常…

Golang | Leetcode Golang题解之第441题排列硬币

题目&#xff1a; 题解&#xff1a; func arrangeCoins(n int) int {return sort.Search(n, func(k int) bool { k; return k*(k1) > 2*n }) }

Python in Excel作图分析实战!

Excel 中的 Python 现已正式发布&#xff0c;适用于 Microsoft 365 商业版和企业版的 Windows 用户。去年 8 月&#xff0c;微软与 Anaconda 合作&#xff0c;通过集成 Python 为 Excel 引入了一个令人兴奋的新增功能&#xff0c;从而可以将 Python 和 Excel 分析无缝结合到同一…