当前位置: 首页 > article >正文

封装 WBXpopup 组件

这是Popup组件基于微博小程序,需要改变标签,以及一写方法

支持四个方向抽屉,以及中间弹出功能

// 用法
<template>
  <wbx-view style="height: 100vh;">
 <!-- 对话框组件 -->
  <wbx-view>
    <wbx-text @click="openpup()">打开</wbx-text>
  </wbx-view>
    <WBXpopup
      ref="popupRef"
      positionType="center"
      popupWidth="300px"
      popupHeight="400px"
    >
      <template slot="popupContent">
        <wbx-view ref="drawer" style="padding: 16px;box-sizing: border-box; display: flex;flex-direction:column;justify-items: center;align-items: center;">
          <wbx-text style="font-size: 18px;height:26px;line-height: 26px;font-weight: 500;color:#000">我们仍在生成您的AI新身份</wbx-text>
          <wbx-view
            @click="guan()"
            style="width: 70px; height: 70px; border: 2px solid #000"
          ></wbx-view>
        </wbx-view>
      </template>
    </WBXpopup>
  </wbx-view>
</template>

<script>
/**
 * @type WBXAppOption
 */
import WBXpopup from "../../commpents/wbx-popup/index.vue"
const pageOptions = {
  data() {
    return {

    };
  },
  methods: {
    openpup() {
      this.$refs.popupRef.openFn();
    },
    guan() {
      this.$refs.popupRef.closeFn();
    },
  },
  components: {
    WBXpopup,//弹出框
  },
  wbox: {
    onLoad() { },
    onShow() {
      // 页面显示/切入前台时触发
    },
    onHide() {
      // 页面隐藏时触发
    },
    onUnload() {
      // 页面退出时触发
    },
  },
  mounted() { },
};
export default pageOptions;
</script>

<style></style>
  //封装的组件
<template>
  <wbx-view>
    <wbx-view
      v-if="showPopup"
      @click="closeFn()"
      style="
        background-color: rgba(0, 0, 0, 0.5);
        position: fixed;
        width: 100vw;
        height: 100vh;
        top: 0px;
        left: 0;
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: center;
        transition: all 0.5s ease;
        z-index: 1;
      "
    >
    <wbx-view :style="{width:popupWidth,height:popupHeight}" style=" transition: all 0.5s ease;z-index: 2; background-color: #fff;" v-if="positionType=='center'" >
        <slot name="popupContent"></slot>
      </wbx-view>
      <wbx-view :style="drawerStyle" v-else>
        <slot name="popupContent"></slot>
      </wbx-view>
    </wbx-view>
  </wbx-view>
</template>

<script>
/*
  openFn() 打开对话框
  closeFn() 关闭对话框
  positionType  从那边出来,抽屉的方向  left right bottom top center 
  popupWidth: 对话框的宽
  popupHeight: 对话框的高
*/
export default {
  data() {
    return {
      showPopup: false,
      isOpen: false,
    };
  },
  props: {
    positionType: {
      type: String,
      default: "right",
    },
    popupWidth: {
      type: String,
      default: "300px",
    },
    popupHeight: {
      type: String,
      default: "300px",
    },
  },
  computed: {
    drawerStyle() {
      const style = {
        transition: "all 0.5s",
        zIndex: 2,
        backgroundColor: "#fff",
        position: "fixed",
      };
      if (this.positionType === "left" || this.positionType === "right") {
        style.width = this.popupWidth;
        style.height = "100vh";
        style[this.positionType] = this.isOpen ? "0px" : `-${this.popupWidth}`;
      } else  {
        style.width = "100vw";
        style.height = this.popupHeight;
        style[this.positionType] = this.isOpen ? "0" : `-${this.popupHeight}`;
      } 
      return style;
    },
  },
  methods: {
    openFn() {
      this.showPopup = true;
      this.$nextTick(() => {
        setTimeout(() => {
          this.isOpen = true;
        }, 50);
      });
    },
    closeFn() {
      this.isOpen = false;
      setTimeout(() => {
        this.showPopup = false;
      }, 500);
    },
  },
};
</script>
<style></style>


http://www.kler.cn/news/317449.html

相关文章:

  • 【C#】垃圾回收
  • 项目总结,路径匹配的业务逻辑
  • Docker使用指南
  • HTML常用的文本标签
  • Docker + Win 10 学习记录
  • OpenAI GPT o1技术报告阅读(3)-英文阅读及理解
  • 828华为云征文 | 云服务器Flexus X实例:RAG 开源项目 FastGPT 部署,玩转大模型
  • 数据结构-C语言实现线性表的顺序存储结构
  • Python Web日志管理与监控实践指南
  • OpenCV特征检测(12)检测图像中的潜在角点函数preCornerDetect()的使用
  • 使用ffmpeg实现音视频文件格式转换
  • C语言从头学62——学习头文件stdlib.h(一)
  • 如何通过蜂巢(容器安全)管理内部部署数据安全产品与云数据安全产品?
  • 【Android】 IconFont的使用
  • 一体化运维监控管理平台的全面监控能力
  • 使用Hutool-poi封装Apache POI进行Excel的上传与下载
  • 单线服务器是什么?单线服务器有什么优点?
  • 掌握 Flutter 中的 `Overlay` 和 `OverlayEntry`:弹窗管理的艺术
  • 如何将Vue项目部署至 nginx
  • 力扣最热一百题——最小覆盖子串
  • 【优选算法之前缀和】No.6--- 经典前缀和算法
  • Unity webgl跨域问题 unity使用nginx设置跨域 ,修改请求头
  • 基于微信小程序的宠物寄养平台的设计与实现+ssm(lw+演示+源码+运行)
  • Adams与Matlab通过FMI联合仿真
  • 我的AI工具箱Tauri版-FunAsr音频转文本
  • git 删除 git push 失败的记录
  • 阿里开源多模态大模型Ovis1.6,重塑出海电商AI格局
  • python自学笔记
  • 价格便宜又好用的云电脑挑选:ToDesk云电脑 vs 青椒云
  • oracle rac多个实例就相当于多个数据库系统程序