From 41bd11ab970d4b502a3de9d15c85c9358ede3da3 Mon Sep 17 00:00:00 2001 From: Wayne Date: Sat, 18 Nov 2023 13:56:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=87=E7=99=BC=E9=80=81=E5=90=8D=E7=89=87?= =?UTF-8?q?=E7=9A=84vuex=E6=8F=9B=E5=88=B0pinia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/user.js | 20 ++++++++++++-------- src/views/Send/index.vue | 12 ++++++++---- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/store/user.js b/src/store/user.js index 8b909a1..1a25034 100644 --- a/src/store/user.js +++ b/src/store/user.js @@ -1,13 +1,15 @@ import { defineStore } from 'pinia' import { getUserData } from "@/api/user"; -import { toggleSendWithAD } from "@/api"; +import { toggleSendWithAD,setUserTpl } from "@/api"; export const useUserStore = defineStore('user', { state: () => { return { userData: { is_send_ad: 0, + nc_template: 0, + nfc_template: 0, }, } }, @@ -29,13 +31,15 @@ export const useUserStore = defineStore('user', { return true; } return false; - } - // async setUserTpl(context, payload) { - // var res = await setUserTpl(payload); - // if (res.code === 200) { - // context.commit("setTpl", payload); - // } - // }, + }, + async setUserTpl(payload) { + let res = await setUserTpl(payload); + if (res.code === 200) { + this.userData.nc_template = payload + return true; + } + return false; + }, }, persist: true }) \ No newline at end of file diff --git a/src/views/Send/index.vue b/src/views/Send/index.vue index 517a21a..d1874c5 100644 --- a/src/views/Send/index.vue +++ b/src/views/Send/index.vue @@ -12,13 +12,17 @@ import { cardFactory } from '@/utils/card' import { genCard1 } from '@/utils/card2' import { genVipCard } from '@/utils/vipcard' import { useStore } from 'vuex' +import { useUserStore } from '@/store/user' +import { useCardStore } from '@/store/card' const store = useStore() +const userStore = useUserStore() +const cardStore = useCardStore() const state = ref({ // active: 0, showCusCard: false, - card_title: computed(() => store.state.user.userInfo.card_title), + card_title: computed(() => cardStore.cusCard.card_title), vip_card: [], flexContent: {}, }) @@ -28,7 +32,7 @@ const activeName = ref('0'); let flexRef = ref(null) const userInfo = computed(() => { - return store.state.user.userInfo + return userStore.userData }) onMounted(async () => { @@ -50,7 +54,7 @@ watch(() => activeName.value, function (newVal, oldVal) { } }, { immediate: true }) -watch(() => userInfo.value.cus_card, function (newVal, oldVal) { +watch(() => cardStore.cusCard.cus_card, function (newVal, oldVal) { if (userInfo.value.level > 1 && newVal.length > 0) { state.value.showCusCard = true } @@ -169,7 +173,7 @@ function showChangeTpl() { } const changeTpl = (val) => { - store.dispatch('user/setUserTpl', val) + userStore.setUserTpl(val) showDraw.value = false }