소스 검색

还原uni-tool的修改

shmily1213 1 개월 전
부모
커밋
3251b71c4b
1개의 변경된 파일4개의 추가작업 그리고 33개의 파일을 삭제
  1. 4 33
      src/utils/uni-tool.ts

+ 4 - 33
src/utils/uni-tool.ts

@@ -24,7 +24,7 @@ export interface IModalOptions {
 /**
  * 工具函数接口
  */
-export interface IeTool extends Record<string, any> {
+export interface IeTool {
   /** 是否显示加载提示 */
   loading: boolean,
   /** 加载提示开始时间 */
@@ -98,40 +98,18 @@ const defaultModalOptions: IModalOptions = {
 
 const tool: IeTool = {
   loading: false,
-  _hasToast: false,
-  _hideToastTimer: null as NodeJS.Timeout | null,
   loadingStartTime: 0,
   minLoadingTime: 500, // 最小显示时间,单位毫秒
   showToast(title: string = '') {
     // 先立即隐藏,避免上一个 toast存在导致下次的 toast 很快关闭
-    if (this._hasToast) {
-      try {
-        if (this._hideToastTimer !== null) {
-          clearTimeout(this._hideToastTimer);
-          this._hideToastTimer = null;
-        }
-        uni.hideToast();
-        this._hideToast();
-      } catch (error) {
-        console.log(error);
-      }
-    }
-
+    uni.hideToast();
     setTimeout(() => {
-      this._hasToast = true;
       uni.showToast({
         title,
         icon: 'none'
       });
-      this._hideToastTimer = setTimeout(() => {
-        this._hideToast();
-        this._hideToastTimer = null;
-      }, 1500);
     }, 50);
   },
-  _hideToast() {
-    this._hasToast = false;
-  },
   showSuccess(title: string = '') {
     uni.showToast({
       title,
@@ -149,15 +127,10 @@ const tool: IeTool = {
     uni.showLoading({
       title,
       mask: true,
-      success: () => {
-        this.loading = true;
-       }
+      success: () => { }
     });
   },
   hideLoading() {
-    if (!this.loading) {
-      return;
-    }
     const currentTime = Date.now();
     const elapsedTime = currentTime - this.loadingStartTime;
     const remainingTime = Math.max(0, this.minLoadingTime - elapsedTime);
@@ -165,11 +138,9 @@ const tool: IeTool = {
     if (remainingTime > 0) {
       setTimeout(() => {
         uni.hideLoading();
-        this.loading = false;
       }, remainingTime);
     } else {
       uni.hideLoading();
-      this.loading = false;
     }
   },
   showModal(params: IModalOptions) {
@@ -204,7 +175,7 @@ const tool: IeTool = {
         success: (res) => {
           /* 这里不要动,就是这样的。形成await showConfirm的效果 2026.1.13 */
           /* 如果有必须接收true/false的写法,请使用showModal */
-          if (res.confirm) (resolve(true))
+          if(res.confirm)(resolve(true))
           else reject(false)
         },
         fail: reject