將發送名片的vuex換到pinia

main
Wayne 3 years ago
parent ffea1f6c7c
commit 41bd11ab97

@ -1,13 +1,15 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { getUserData } from "@/api/user"; import { getUserData } from "@/api/user";
import { toggleSendWithAD } from "@/api"; import { toggleSendWithAD,setUserTpl } from "@/api";
export const useUserStore = defineStore('user', { export const useUserStore = defineStore('user', {
state: () => { state: () => {
return { return {
userData: { userData: {
is_send_ad: 0, is_send_ad: 0,
nc_template: 0,
nfc_template: 0,
}, },
} }
}, },
@ -29,13 +31,15 @@ export const useUserStore = defineStore('user', {
return true; return true;
} }
return false; return false;
},
async setUserTpl(payload) {
let res = await setUserTpl(payload);
if (res.code === 200) {
this.userData.nc_template = payload
return true;
} }
// async setUserTpl(context, payload) { return false;
// var res = await setUserTpl(payload); },
// if (res.code === 200) {
// context.commit("setTpl", payload);
// }
// },
}, },
persist: true persist: true
}) })

@ -12,13 +12,17 @@ import { cardFactory } from '@/utils/card'
import { genCard1 } from '@/utils/card2' import { genCard1 } from '@/utils/card2'
import { genVipCard } from '@/utils/vipcard' import { genVipCard } from '@/utils/vipcard'
import { useStore } from 'vuex' import { useStore } from 'vuex'
import { useUserStore } from '@/store/user'
import { useCardStore } from '@/store/card'
const store = useStore() const store = useStore()
const userStore = useUserStore()
const cardStore = useCardStore()
const state = ref({ const state = ref({
// active: 0, // active: 0,
showCusCard: false, showCusCard: false,
card_title: computed(() => store.state.user.userInfo.card_title), card_title: computed(() => cardStore.cusCard.card_title),
vip_card: [], vip_card: [],
flexContent: {}, flexContent: {},
}) })
@ -28,7 +32,7 @@ const activeName = ref('0');
let flexRef = ref(null) let flexRef = ref(null)
const userInfo = computed(() => { const userInfo = computed(() => {
return store.state.user.userInfo return userStore.userData
}) })
onMounted(async () => { onMounted(async () => {
@ -50,7 +54,7 @@ watch(() => activeName.value, function (newVal, oldVal) {
} }
}, { immediate: true }) }, { 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) { if (userInfo.value.level > 1 && newVal.length > 0) {
state.value.showCusCard = true state.value.showCusCard = true
} }
@ -169,7 +173,7 @@ function showChangeTpl() {
} }
const changeTpl = (val) => { const changeTpl = (val) => {
store.dispatch('user/setUserTpl', val) userStore.setUserTpl(val)
showDraw.value = false showDraw.value = false
} }

Loading…
Cancel
Save