UNPKG

ipink-util

Version:

util.js

2 lines (1 loc) 3.2 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./config.js"),htmlToast=(t,e=3e3,o,n,i,c)=>{let a={};try{let removeChild=function(){let t=document.getElementsByClassName("toast_container")&&document.getElementsByClassName("toast_container")[0];t&&(t.parentElement.removeChild(t),n&&startTouchEvent())},touchDefault=function(t){t.stopPropagation(),t.preventDefault()},stopTouchEvent=function(){document.addEventListener("touchstart",touchDefault,!1),document.addEventListener("touchmove",touchDefault,!1),document.addEventListener("touchend",touchDefault,!1)},startTouchEvent=function(){document.removeEventListener("touchstart",touchDefault,!1),document.removeEventListener("touchmove",touchDefault,!1),document.removeEventListener("touchend",touchDefault,!1)};"undefined"!=typeof document&&document.createElement||(a={t:"不支持【document】对象!"},c&&c(a),o&&o(a)),n&&stopTouchEvent();const r="\n\t\t\t.toast_container { }\n\t\t\t.toast-box { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 99998; text-align: center; animation: toast-fadein 3s forwards; -webkit-animation: toast-fadein 3s forwards; background: rgba(17,17,17,.8); font-size: calc(100vw / 750); max-width: 85vw; white-space:normal; padding: 10px 15px; border-radius: 5px; box-sizing:content-box; line-height: calc(100vw / 750 * 42px); }\n\t\t\t.toast-content { padding: 0; font-size: 28em !important; overflow: hidden; position: relative; color: #ffffff; word-break: break-all; }\n\t\t\t@keyframes toast-fadein { 0% {opacity: 0.1;} 10% {opacity: 1;} 30% { opacity: 1; } 60% { opacity: 1; } 90% { opacity: 1; } 100% { opacity: 0; } }\n\t\t",m=document.createElement("style");if(m.type="text/css",m.id="toast-style",m.innerHTML=r,!document.querySelector("div.toast-box")){var u=document.createElement("div");u.className="toast_container";var s=document.createElement("div");u.appendChild(m),u.appendChild(s),s.className="toast-box",s.style.cssText=`animation-duration: ${e/1e3}s;`;var d=document.createElement("p");d.className="toast-content",d.innerHTML=t,s.appendChild(d),(document.getElementsByTagName("uni-app")&&document.getElementsByTagName("uni-app")[0]||document.body).appendChild(u);let n=setTimeout((function(){clearTimeout(n),removeChild(),o&&o(),i&&i()}),e);"undefined"!=typeof uni&&(uni.addInterceptor("navigateTo",{o(t){clearTimeout(n),removeChild()}}),uni.addInterceptor("navigateBack",{o(t){clearTimeout(n),removeChild()}}))}}catch(r){c&&c(r),o&&o(r)}};exports.htmlToast=htmlToast,exports.showModal=e=>new Promise((o=>{if(t.i()){("undefined"!=typeof uni?uni.showModal:wx.showModal)({...e||{},o:t=>{e?.o&&e.o(t),o(!0)},u:t=>{e?.u&&e.u(t),o(!1)}})}else o(!0)})),exports.toast=e=>{let{title:o="",icon:n="none",mask:i=!1,duration:c=t.l.m,complete:a,o:u,u:s,...d}=e||{};if("string"==typeof e&&(o=e),!o)return"";if(t.l.p&&"undefined"!=typeof document&&document.createElement&&document.removeEventListener)return htmlToast(o,c,a,i,u,s);let r={title:o,icon:n,mask:i,duration:c,o:u,u:s,...d,complete:a};if(t.i())"undefined"!=typeof uni?uni.showToast(r):wx.showToast(r);else{let t={t:"不支持【document】对象!"};s&&s(t),a&&a(t)}};