網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
本文實(shí)例為大家分享了React封裝全屏彈框的具體代碼,供大家參考,具體內(nèi)容如下
web開(kāi)發(fā)過(guò)程中,需要用到彈框的地方很多,有時(shí)候,產(chǎn)品經(jīng)理的原型是全屏彈框,而常用的組件庫(kù)里封裝的一般都不是全屏的。
如下圖所示:這就是一個(gè)全屏彈框。
廢話(huà)不多說(shuō),直接上代碼:
// ?FullScreen.tsx
import React, { memo, useEffect } from 'react';
import { Spin } from '@/components/antd';
import IconUrl from '@/assets/icon/closeIcon.png';
import './index.scss';
/*
?*全屏表格自適配組件
?*@title 標(biāo)題
?*@visible 是否顯示
?*@handleCancel 取消事件
?*@content 組件內(nèi)容
?*@loadding 狀態(tài)
?*/
function FullScreen({ title, visible, handleCancel, content, loadding = false }: any) {
? const collapsed = localStorage.getItem('collapsed');
? const collapse = collapsed ?? '1';
? useEffect(() => {
? ? return () => {
? ? ? localStorage.removeItem('collapsed');
? ? };
? }, []);
? return (
? ? visible && (
? ? ? ? <div id="commonModal" style={+collapse === 1 ? { left: 210,top:93 } : { left: 100,top:93 }}>
? ? ? ? ? {/*<!-- 頂部 -->*/}
? ? ? ? ? <div className="modalTop">
? ? ? ? ? ? <div className="modal_title">
? ? ? ? ? ? ? <div className="topTitle">{title}</div>
? ? ? ? ? ? </div>
? ? ? ? ? ? <img className="topIcon" onClick={handleCancel} src={IconUrl} alt="" />
? ? ? ? ? </div>
? ? ? ? ? <Spin spinning={loadding} tip="Loading..." size="large" delay={500}>
? ? ? ? ? ? <div className="modalMain">{content}</div>
? ? ? ? ? </Spin>
? ? ? ? </div>
? ? )
? );
}
export default memo(FullScreen);
這個(gè)是相關(guān)的css樣式 – index.scss
// index.scss
#commonModal {
? position: fixed;
? bottom: 0px;
? right: 0px;
? background: white;
? border-radius: 5px;
? // width: 100%;
? // height: 100%;
? // height: 95vh;
? z-index: 10;
? .modalTop {
? ? width: 100%;
? ? height: 46px;
? ? border-radius: 5px 5px 0 0;
? ? display: flex;
? ? background: white;
? ? justify-content: space-between;
? ? align-items: center;
? ? border-bottom: 1px solid #dbe3e5;
? ? box-sizing: border-box;
? ? padding: 0 20px;
? ? .modal_title {
? ? ? display: flex;
? ? ? align-items: center;
? ? ? .topTitle {
? ? ? ? color: #333545;
? ? ? ? font-weight: bold;
? ? ? ? font-size: 18px;
? ? ? }
? ? }
? ? .topIcon {
? ? ? width: 24px;
? ? ? height: 24px;
? ? ? cursor: pointer;
? ? }
? }
? .modalMain {
? ? height: 100%;
? ? padding-bottom: 30px;
? ? // height: calc(100vh - 80px);
? ? // height: calc(90vh - 120px);
? ? ::-webkit-scrollbar {
? ? ? // height: 8px;
? ? ? // width: 10px;
? ? }
? }
}
// .modal_mask {
// ? position: fixed;
// ? width: 100%;
// ? height: 100%;
// ? left: 0;
// ? top: 0;
// ? // background-color: rgba(0, 0, 0, 0.5);
// ? z-index: 10;
// }
在相關(guān)頁(yè)面中進(jìn)行使用:
import FullScreen from '@/components/FullScreen/FullScreen';
const test = (props) => {
?? ?return (
?? ??? ?<Fragment>
? ? ? ? ? ? <FullScreen loadding={isLoading} title={'新增'} content={content} visible={visible} handleCancel={handleCancel} />
? ? ? ? </Fragment>
?? ?)
}
content 一般是表單元素
原文鏈接:https://blog.csdn.net/qq_41131745/article/details/125807506
相關(guān)推薦
- 2022-06-06 Anaconda安裝pytorch和paddle的方法步驟_python
- 2022-05-09 如何將Python列表轉(zhuǎn)換為字符串_python
- 2022-05-22 ansible管理工具的環(huán)境及部署安裝_服務(wù)器其它
- 2022-11-04 Android自定義View實(shí)現(xiàn)時(shí)鐘功能_Android
- 2022-02-20 Spring Boot 打包報(bào)錯(cuò)Failed to execute goal org.apache.
- 2023-03-26 詳解C/C++中低耦合代碼的設(shè)計(jì)實(shí)現(xiàn)_C 語(yǔ)言
- 2022-06-09 FreeRTOS實(shí)時(shí)操作系統(tǒng)的任務(wù)通知方法_操作系統(tǒng)
- 2023-06-21 Docker安裝部署Redis數(shù)據(jù)庫(kù)的實(shí)現(xiàn)步驟_docker
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門(mén)
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支