/** * 封装加载提示 */ class Loading { /** * 加载进度 */ loading() { this.SetLoading() // 塞入loading的html this.$(".isShow .loading").innerHTML = `
`; this.$(".isShow .back").style = `padding: 0.4rem;` this.show() } /** * 显示toast提示 * @param {*} text 文字 * @param {*} time 自动关闭提示的时间 默认3秒 */ toast(text, time = 3000) { this.SetLoading() this.$(".isShow .loading").innerHTML = `
` // 设置边距 this.$(".isShow .back").style = `padding: 0.14rem 0.4rem;` // 设置内容 this.$(".isShow .back").innerHTML = `${text}`; this.show() setTimeout(()=> this.close(),time) } /** * 弹出框 dialog * @param {*} params */ dialog(params) { params == undefined ? params = {} : null; let defaultParams = { title: '标题', message: '内容', cancelText: '取消', confirmText: '确定', cancelColor: '#323233', confirmColor: '#fb7299' }; defaultParams.title = params.title || defaultParams.title; defaultParams.message = params.message || defaultParams.message; defaultParams.cancelText = params.cancelText || defaultParams.cancelText; defaultParams.confirmText = params.confirmText || defaultParams.confirmText; defaultParams.cancelColor = params.cancelColor || defaultParams.cancelColor; defaultParams.confirmColor = params.confirmColor || defaultParams.confirmColor; this.SetLoading() this.$(".isShow .loading").innerHTML = `
${defaultParams.title}
${defaultParams.message}
`; // 取消按钮被点击的时候 this.$(".isShow .dialog_cancel").onclick = () => { params.cancel && params.cancel() this.close() } // 确定按钮被点击的时候 this.$(".isShow .dialog_confirm").onclick = () => { params.confirm && params.confirm() this.close() } this.$(".isShow .loading").style = 'background: rgba(0, 0, 0, 0.7)' this.show() } /** * 填充loading的html结构 */ SetLoading () { if (this.$(".isShow") == null) { var isShow = document.createElement("div") isShow.className = "isShow" isShow.style = "display: none;" var loading = document.createElement("div") loading.className = "loading"; isShow.appendChild(loading) this.$("body").appendChild(isShow) } } /** * 删除内容,隐藏弹窗 */ close() { this.clearContent() this.$(".isShow").style.display = "none" } /** * 显示弹窗 */ show() { this.$(".isShow").style.display = "block" } /** * 清空弹窗内部的内容 */ clearContent() { this.$(".isShow .loading").style = ""; this.$(".isShow .loading").innerHTML = ""; } $(className) { return document.querySelector(className); } } var Tips = new Loading()