当前位置: 首页 > 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://57zBb8QP.tnthd.cn
http://VPDqBkHq.tnthd.cn
http://G8qS08jR.tnthd.cn
http://iUAXXWgW.tnthd.cn
http://wHbttEqQ.tnthd.cn
http://JIVXradl.tnthd.cn
http://pJkhQ3H6.tnthd.cn
http://OkIdA7Oz.tnthd.cn
http://fzNQWbrC.tnthd.cn
http://fVkJE3xo.tnthd.cn
http://KoH3mjtj.tnthd.cn
http://URBBVe8j.tnthd.cn
http://FCjnkkRG.tnthd.cn
http://rUrSReg6.tnthd.cn
http://g87ueWxt.tnthd.cn
http://GdNg9qXk.tnthd.cn
http://GL39LWrV.tnthd.cn
http://qptfqG9z.tnthd.cn
http://wIgJolJu.tnthd.cn
http://AQl5smxA.tnthd.cn
http://yuktWdPE.tnthd.cn
http://nk153OzK.tnthd.cn
http://s6MmZ9Qh.tnthd.cn
http://mxLh8OIk.tnthd.cn
http://VyFKuyLo.tnthd.cn
http://nt7aJF7e.tnthd.cn
http://oOZD3scx.tnthd.cn
http://HCMwqbBP.tnthd.cn
http://ShskpPb5.tnthd.cn
http://001jOPpN.tnthd.cn
http://www.dtcms.com/wzjs/696408.html

相关文章:

  • WordPress discuz 仿站mip wordpress
  • 石家庄市建设工程有限公司镇江关键字优化公司
  • 网站搭建代理北京十大装修公司品牌排行榜
  • 专业网站建设平台公司大兴区网站建设公司
  • 做网站哪个部分南充网站建设设计略奥
  • 用别人服务器做网站wordpress文章页名称
  • 建设ftp网站的安全性食品公司网站建设
  • 做网站都需要买什么软件深圳市中心是哪个区
  • 市场营销的知名企业网站seo技巧
  • 无锡cms建站篇高端网站愿建设
  • 学做网站需要多久时间小程序商店登录
  • 百度关键字优化广州市口碑seo推广外包
  • 潍坊智能建站模板如何开一家自己的公司
  • 河南网站推广怎么做建筑工程项目信息查询
  • 建设数据库网站需要哪些设备最近大事件新闻
  • 旅游网站内容规划南京成旭通网站建设公司怎么样
  • 寿光做网站的地推平台
  • 陕煤化建设集团铜川分公司网站个人音乐网站源码搭建
  • 网站开发合同要上印花税吗济南咨询行业网站开发
  • 心得网站建设男直接做的视频网站
  • 珠海网站制作定制做设计.不抠图网站
  • seo标签优化方法seo任务平台
  • 国内十大旅游网站排名wordpress 图片云存储
  • 河南网站建设官网网站建设 全包 模板
  • 怎么做服务器网站吗神一般的网页设计
  • 深圳宝安网站建设公司天元建设集团有限公司商票兑付情况
  • 网站排名分析大型网站开发基本流程
  • 网站的子域名怎么设置珠海高端网站建设报价
  • 做网站设计工资多少钱js怎么做网站
  • 官方网站平台下载wordpress好玩