From cd5747091d7647ffbd2425bdfdeb32910d9d5703 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?TOP=E7=B3=AF=E7=B1=B3?= <1130395124@qq.com>
Date: Fri, 7 Apr 2023 23:39:22 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BA=E8=87=AA=E5=AE=9A?=
=?UTF-8?q?=E4=B9=89toast=E8=BD=BB=E6=8F=90=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/layout/layout.vue | 3 ++
src/components/widgets/toast.vue | 51 ++++++++++++++++++++++++++++++++
src/core/libs/utils.js | 21 +++++++------
src/store/index.js | 2 ++
src/store/modules/toast.js | 17 +++++++++++
5 files changed, 83 insertions(+), 11 deletions(-)
create mode 100644 src/components/widgets/toast.vue
create mode 100644 src/store/modules/toast.js
diff --git a/src/components/layout/layout.vue b/src/components/layout/layout.vue
index 86eb6a0..321a5c2 100644
--- a/src/components/layout/layout.vue
+++ b/src/components/layout/layout.vue
@@ -31,11 +31,13 @@
+
+
+
\ No newline at end of file
diff --git a/src/core/libs/utils.js b/src/core/libs/utils.js
index b163c43..d2777d1 100644
--- a/src/core/libs/utils.js
+++ b/src/core/libs/utils.js
@@ -1,4 +1,5 @@
import $storage from '@/core/storage'
+import $store from '@/store/index'
function time() {
return parseInt(Math.round(new Date() / 1000));
@@ -190,22 +191,20 @@ function toPage(url, options, type) {
}
let toastTimer;
-function toast(title, options) {
- if (typeof options === "undefined") {
- options = {};
- }
+function toast(title, duration) {
+ uni.hideLoading();
return new Promise((resolve, reject) => {
- if (!options.duration) {
- options.duration = 1500;
+ if (typeof duration === "undefined") {
+ duration = 1500;
}
- uni.showToast({
- ...{ title: title, icon: "none" },
- ...options
- });
+ $store.commit('toast/show', true);
+ $store.commit('toast/title', title);
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
+ $store.commit('toast/show', false);
+ $store.commit('toast/title', "");
resolve();
- }, options.duration);
+ }, duration);
})
}
diff --git a/src/store/index.js b/src/store/index.js
index b184fb8..14f8256 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -5,6 +5,7 @@ import system from "@/store/modules/system"
import user from "@/store/modules/user"
import service from "@/store/modules/service"
import cart from "@/store/modules/cart"
+import toast from "@/store/modules/toast"
Vue.use(Vuex)
export default new Vuex.Store({
@@ -13,5 +14,6 @@ export default new Vuex.Store({
user,
service,
cart,
+ toast,
}
})
diff --git a/src/store/modules/toast.js b/src/store/modules/toast.js
new file mode 100644
index 0000000..91f0ac8
--- /dev/null
+++ b/src/store/modules/toast.js
@@ -0,0 +1,17 @@
+export default {
+ namespaced: true,
+ state: {
+ show: false,
+ title: "",
+ },
+ getters: {},
+ mutations: {
+ show(state, data) {
+ state.show = data;
+ },
+ title(state, data) {
+ state.title = data;
+ }
+ },
+ actions: {}
+}