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

信息发布型网站是企业网站的什么推广链接代点

信息发布型网站是企业网站的什么,推广链接代点,个人教程网站,问答社交网站开发下面是全局加载遮罩工具,功能:提供show和showWithDelay/hide方法用于显示/延时显示/隐藏遮罩,它还提供loading属性返回是否正在loading。通常用于耗时较长的操作,比如远端api调用。 如何用它,下面是个例子&#xff0c…

下面是全局加载遮罩工具,功能:提供show和showWithDelay/hide方法用于显示/延时显示/隐藏遮罩,它还提供loading属性返回是否正在loading。通常用于耗时较长的操作,比如远端api调用。

如何用它,下面是个例子,这个是全局的postAction:

import loadingMask from './loadingMask';
...
// 设置延迟显示加载遮罩(1秒后显示)loadingMask.showWithDelay('请求处理中,请稍候...', 1000);return axios({url: url,method: 'post',data: parameter,headers: { ...signHeader, ...config.headers },...config}).then(res => {// 请求完成后隐藏加载遮罩loadingMask.hide();return handleResponse(res);}).catch(err => {// 请求出错后隐藏加载遮罩loadingMask.hide();return handleError(err);});

如果想实时获得它的loading属性呢?这时候要订阅它的状态变化:

const [loading, setLoading] = useState(loadingMask.loading);
// 订阅 loadingMask 的 loading 状态变化useEffect(() => {// 订阅 loading 状态变化const unsubscribe = loadingMask.subscribeToLoading(setLoading);// 组件卸载时取消订阅return unsubscribe;}, []);...<Buttonblocktype='submit'color='primary'loading={loading}>删除选中记录</Button>

这时候loadingMask的loading状态变化会立即返回到setLoading,也就会引导起button的重新渲染。

组件代码如下:

import React from 'react';
import { createRoot } from 'react-dom/client';
import { Mask, SpinLoading } from 'antd-mobile';
import styled from 'styled-components';const LoadingContainer = styled.div`display: flex;flex-direction: column;align-items: center;justify-content: center;position: absolute;top: 50%;left: 50%;transform: translate(-50%, -50%);color: #ffffff;
`;const LoadingText = styled.div`margin-top: 12px;font-size: 14px;
`;/*** 全局加载遮罩工具* 用于在长时间请求时显示加载遮罩*/
class LoadingMask {constructor() {this.container = null;this.root = null;this.visible = false;this.timeoutId = null;this.loadingText = '正在加载,请稍候...';this._loading = false; // 添加内部 loading 状态this._listeners = []; // 添加监听器数组this.init();}/*** 初始化加载遮罩容器*/init() {// 创建容器元素this.container = document.createElement('div');this.container.id = 'global-loading-mask-container';document.body.appendChild(this.container);// 创建React 18的rootthis.root = createRoot(this.container);// 初始渲染this.render();}/*** 渲染加载遮罩*/render() {if (!this.root) {this.init();return;}this.root.render(<Mask opacity={0.7} visible={this.visible}><LoadingContainer><SpinLoading color='white' style={{ '--size': '48px' }} /><LoadingText>{this.loadingText}</LoadingText></LoadingContainer></Mask>);}/*** 显示加载遮罩* @param {string} text - 加载提示文本*/show(text) {this.loadingText = text || '正在加载,请稍候...';this.visible = true;this._setLoading(true); // 使用新方法设置 loading 状态this.render();}/*** 隐藏加载遮罩*/hide() {this.visible = false;this._setLoading(false); // 使用新方法设置 loading 状态this.render();// 清除定时器if (this.timeoutId) {clearTimeout(this.timeoutId);this.timeoutId = null;}}/*** 设置延迟显示加载遮罩* @param {string} text - 加载提示文本* @param {number} delay - 延迟时间(毫秒)*/showWithDelay(text, delay = 1000) {// 清除之前的定时器if (this.timeoutId) {clearTimeout(this.timeoutId);}// 立即设置 loading 状态为 truethis.loadingText = text || '正在加载,请稍候...';this._setLoading(true); // 使用新方法设置 loading 状态// 设置新的定时器,只延迟显示遮罩this.timeoutId = setTimeout(() => {this.visible = true;this.render();}, delay);}// 添加设置 loading 状态的方法,并通知监听器_setLoading(value) {if (this._loading !== value) {this._loading = value;// 通知所有监听器this._listeners.forEach(listener => listener(value));}};// 添加订阅方法subscribeToLoading(callback) {this._listeners.push(callback);// 立即通知当前状态callback(this._loading);// 返回取消订阅的函数return () => {this._listeners = this._listeners.filter(cb => cb !== callback);};};
}// 创建单例实例
const loadingMask = new LoadingMask();// 添加 loading 属性的 getter
Object.defineProperty(loadingMask, 'loading', {get: function() {return this._loading;}
});export default loadingMask;

文章转载自:

http://w1TafCah.qytby.cn
http://LH0DO8DR.qytby.cn
http://gMQxmMKE.qytby.cn
http://EClsTbAy.qytby.cn
http://TASZxrM9.qytby.cn
http://79jY7VyF.qytby.cn
http://2OCuy2cX.qytby.cn
http://d1TyOsP8.qytby.cn
http://gbXSnx4F.qytby.cn
http://J2HukcqJ.qytby.cn
http://NsBpWAeq.qytby.cn
http://OuLzdncD.qytby.cn
http://fSI1PTGJ.qytby.cn
http://qnW350vk.qytby.cn
http://y2g1vgp4.qytby.cn
http://OO2m7geo.qytby.cn
http://AIhRHHUK.qytby.cn
http://Dy3cCyrR.qytby.cn
http://j8Bsim8G.qytby.cn
http://ybOlEAaM.qytby.cn
http://5jTbsAlb.qytby.cn
http://miYeI4lj.qytby.cn
http://dEkrRxEx.qytby.cn
http://OGmOsubA.qytby.cn
http://du1FkTez.qytby.cn
http://xCDlGEFs.qytby.cn
http://EqyrO6p5.qytby.cn
http://mbFqPH8Y.qytby.cn
http://gIRceaN1.qytby.cn
http://rE5cFYQ6.qytby.cn
http://www.dtcms.com/wzjs/610366.html

相关文章:

  • 天津 交友 网站建设企业网站建设视频
  • 毕业设计网站开发杭州 平台 公司 网站建设
  • 医院网站主页面设计地方门户网站域名
  • 甜蜜高端定制网站wordpress主题 四亩地
  • 网站建设相关新闻学校校园网站建设服务
  • 网站建设工作稳定吗ui设计师面试问题及答案
  • 档案网站建设的步骤网站如何做美工
  • wordpress语言切换网站个体营业执照可以做网站嘛
  • 武进网站建设价位怎么查看网站是否被百度收录
  • 标志空间网站什么网站的新闻做参考文献
  • 网站运营怎样做免费广告推广平台
  • 广东专业网站开发还能用的wap网站
  • 网站备案 信息安全管理协议企业网站怎么搭建
  • 制作图片和视频一起的软件如何查看网站seo
  • 广东广州免费建站二 网站建设的重要性
  • 资阳网站建设公司wordpress手机版有什么用
  • 零食铺网站建设策划书家电网站制作
  • 网站左侧的导航是怎么做的外贸高端网站设计
  • 深圳 企业 网站建设做网站哪里买空间好
  • 石家庄网站定做网站建设需求分析运行环境处理器型号及内存容量
  • 网站开发有哪些常用工具wordpress批量审核
  • 做外汇看的网站关键词com
  • 邯郸网站设计 贝壳下拉名师工作室网站建设 意义
  • 网站建设课程ppt东莞专业微网站建设推广
  • 南京网站建设 零云建站邢台高端网站建设
  • asp网站源码安装流程wordpress防止cc攻击
  • 淘宝客网站免费建站做官网网站哪家公司好
  • 化妆品网站模板下载佳能网站建设需求报告
  • 谷搜易外贸网站建设设计和建设企业网站心得和体会
  • 学校网站建设的必要性网络营销课程总结