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

【uniapp】封装一个全局自定义的模态框

【需求描述】

在接口401处,需要实现全局提示并弹出自定义模态框的功能。考虑到uni-app内置的模态框和app原生提示框的自定义能力有限,我决定自行封装全局自定义的模态框,以此为应用程序提供更加统一且个性化的界面。

【效果图】
在这里插入图片描述
【封装】

主要是dom树&css样式
在这里插入图片描述

<template><view @click="close" class="mask"><!-- @click.stop="onClick" --><view class="content"><div class="title box">{{ options.title }}</div><div class="content2 box"><u--text :lines="3" :size="36" align="center" :text="options.content"></u--text><!-- {{  }} --></div><div class="button box" @click.stop="onClick">确定</div></view></view>
</template><script>
export default {data() {return {options: [],};},onLoad(options) {// 获取配置this.options = options;},methods: {onClick(e) {  // 点击确定触发uni.removeStorageSync("token");uni.reLaunch({url: "../index/index",});uni.setStorageSync("isLogin", "yes");console.log(e);// #ifdef APP-NVUEe.stopPropagation();// #endif},close() { // 点击遮罩层触发//为了防止401后再继续调用弹窗uni.setStorageSync("isLogin", "no");// uni.navigateBack();// uni.setStorageSync("isLogin", "yes");console.log("弹窗蒙版");},},
};
</script>
<style>
page {background: transparent;
}
</style><style lang="scss" scoped>
.mask {position: fixed;left: 0;top: 0;right: 0;bottom: 0;/* #ifndef APP-NVUE */display: flex;/* #endif */justify-content: center;align-items: center;background-color: rgba(0, 0, 0, 0.4);
}.content {border-radius: 10px;width: 360px;height: 180px;background-color: #fff496;display: flex;flex-direction: column;padding: 10px;.box {display: flex;justify-content: center;align-items: center;}.title {height: 25%;font-size: 18px;font-weight: 600;}.content2 {height: 50%;font-size: 16px;}.button {height: 25%;border-top: 1px solid white;font-size: 18px;color: #1890ff;}
}
</style>

【引用】

使用isLogin == 'yes’来防止401重复弹出

在这里插入图片描述

let isLogin = uni.getStorageSync('isLogin')
if (args.statusCode == 401 && isLogin == 'yes' && !isRefreshing) {uni.$u.route({url: "/pages/popup/popup",params: {name: "lisa",title: "温馨提示",content: '你的内容',},animationType: "fade-in",animationDuration: 500,});}

【总结】

  • 全局自定义的模态框是一种通用的UI组件,它可以在应用程序的任何位置被触发并弹出来。这个模态框可以包含任何类型的内容,比如文本、图片、视频等。

  • 开发者可以根据自己的需求,设计出符合应用程序整体风格的模态框,包括颜色、字体、布局等。

  • 通过封装全局自定义的模态框,开发者可以大大提高应用程序的用户体验

  • 用户可以更加直观地看到应用程序中的重要信息,并且可以根据提示进行操作。同时,全局自定义的模态框还可以帮助开发者提高应用程序的统一性和品牌形象,增强用户的忠诚度满意度

http://www.lryc.cn/news/120597.html

相关文章:

  • UNIX 入门
  • Golang通过alibabaCanal订阅MySQLbinlog
  • Python flask-restful 框架讲解
  • MySQL_约束、多表关系
  • 在Qt中使用LoadLibrary无法加载DLL
  • 如何将区块链新闻稿发布到海外媒体?
  • 基于 CentOS 7 构建 LVS-DR 群集。
  • 防火墙组建双击热备后,点击管理对端设备,老是打不开,怎么办?
  • 【Kubernetes】Kubernetes之Pod详解
  • 电商与客服系统完美对接指南源码-无缝对接唯一客服系统-提升电商客户体验...
  • 新知识:Monkey 改进版之 App Crawler
  • 黑马头条项目学习--Day3: 自媒体文章发布
  • 使用frp实现内网穿透
  • 安装 opendr 踩坑记
  • 各地区-各行业法人单位、区划数63个指标(2010-2022年)
  • W5500-EVB-PICO作为TCP Client 进行数据回环测试(五)
  • web前端面试--递归(斐波那契数列)
  • Vue3 Props组件简单应用(父组件获取子组件数据)
  • Mybatis查询
  • 如何让ES低成本、高性能?滴滴落地ZSTD压缩算法的实践分享
  • [数据集][目标检测]PCB板缺陷目标检测数据集VOC格式693张6类别
  • Linux 安装中文输入法
  • redisson
  • 源码分析——HashMap(JDK1.8)源码+底层数据结构分析
  • 企业举办活动邀请媒体的意义和重要性
  • 从零开始学python(十六)爬虫集群部署
  • flutter
  • iOS 开发-编译第三方库 openssl及curl
  • 运维监控学习笔记1
  • 由于找不到vcruntime140.dll,无法继续执行代码,三种修复方法