赞
踩
/** * 显示消息提示框 * @param title * @param options * @constructor */ export function Toast(title: string, options?: Partial<UniApp.ShowToastOptions>) { uni.showToast({ title, duration: 1500, icon: 'none', mask: true, ...options, }); } /** * 隐藏消息提示框 */ export function HideToast() { uni.hideToast(); } /** * 显示 loading 提示框 * @param title * @param options * @constructor */ export function Loading(title: string, options?: Partial<UniApp.ShowLoadingOptions>) { uni.showLoading({ title, mask: true, ...options, }); } /** * 隐藏 loading 提示框 */ export function HideLoading() { uni.hideLoading(); }
export const usePromptStore = defineStore({ id: 'promptStore', state: (): IState => ({ isShowLoading: false, isShowToast: false, }), getters: { getIsShowLoading: (state) => state.isShowLoading, getIsShowToast: (state) => state.isShowToast, }, actions: { setIsShowLoading(val: boolean) { this.isShowLoading = val; }, setIsShowToast(val: boolean) { this.isShowToast = val; }, }, });
/** * 显示消息提示框 * @param title * @param options * @constructor */ export function Toast(title: string, options?: Partial<UniApp.ShowToastOptions>) { const promptStore = usePromptStore(); if (promptStore.disabledToast) return; if (promptStore.isShowLoading) { // Toast优先级更高 HideLoading(); } promptStore.setIsShowToast(true); uni.showToast({ title, duration: 1500, icon: 'none', mask: true, ...options, }); const timer = setTimeout(() => { promptStore.setIsShowToast(false); clearTimeout(timer) }, 1500); } /** * 隐藏消息提示框 */ export function HideToast() { const promptStore = usePromptStore(); promptStore.setIsShowToast(false); uni.hideToast(); } /** * 显示 loading 提示框 * @param title * @param options * @constructor */ export function Loading(title: string, options?: Partial<UniApp.ShowLoadingOptions>) { const promptStore = usePromptStore(); if (promptStore.isShowToast) { // Toast优先级更高 return; } promptStore.setIsShowLoading(true); uni.showLoading({ title, mask: true, ...options, }); } /** * 隐藏 loading 提示框 */ export function HideLoading() { const promptStore = usePromptStore(); if (promptStore.isShowToast) { // Toast优先级更高 return; } promptStore.setIsShowLoading(false); uni.hideLoading(); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。