修改send頁面 > 以pinia方式處理、新增名片廣告及判斷

main
bruce68410 2 years ago
parent d07a8c2f8d
commit e7a0d071ce

@ -152,7 +152,7 @@ strong {
margin: 0 7px; margin: 0 7px;
} }
.LyMe .T1 { .LyMe .T1 {
border-radius: 17px; border-radius: 5px;
} }
.LyKi .T1 { .LyKi .T1 {
border-radius: 10px; border-radius: 10px;

@ -75,6 +75,9 @@ export const getMovie = async () =>
export const getMarquee = async () => export const getMarquee = async () =>
ajax(`/ads/getMarquee`); ajax(`/ads/getMarquee`);
export const getFlexcard = async () =>
ajax(`/ads/getFlexcard`);
//通訊錄 //通訊錄
export const getUserFaviList = async (params) => export const getUserFaviList = async (params) =>
ajax(`/UserFavi/getUserFaviList`, params , "GET"); ajax(`/UserFavi/getUserFaviList`, params , "GET");

@ -1,19 +1,85 @@
import { genCard } from "./card/index"; function genAdCard(ctx,option) {
const { json5: vcard } = ctx;
function genAdCard (option) { return {
// const { json5: vcard } = ctx; type: "flex",
altText: "廣告卡片",
// return { contents: {
// type: "flex", type: "carousel",
// altText: vcard.altText, contents: [
// contents: { ctx.contents,
// type: "carousel", {
// contents: ctx "type": "bubble",
// }, "size":"mega",
// }; "hero": {
"type": "image",
console.log(option,"test"); "url": option.ad_image,
return option; "size": "full",
"aspectMode": "cover",
"aspectRatio": "19:11",
"action": {
"type": "uri",
"uri": option.link
}
},
"body": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": option.ad_title,
"weight": "bold",
"size": "xl",
"color": "#333333"
},
{
"type": "text",
"text": option.ad_desc,
"color": "#666666",
"size": "md",
"wrap": true
}
]
},
"footer": {
"type": "box",
"layout": "vertical",
"spacing": "sm",
"color": "#6c6664",
"contents": [
{
"type": "button",
"style": "primary",
"height": "sm",
"color": "#6c6664",
"action": {
"type": "uri",
"label": "test link",
"uri": "https://linecorp.com"
}
},
{
"type": "box",
"layout": "vertical",
"contents": [],
"margin": "sm"
}
],
"flex": 0
},
"styles": {
"body": {
"backgroundColor": "#eeeeee"
},
"footer": {
"backgroundColor": "#eeeeee"
}
}
}
]
},
};
} }
export { genAdCard} export { genAdCard };

@ -1,7 +1,6 @@
import { genCard } from "./card/index"; import { genCard } from "./card/index";
function cardFactory(option) { function cardFactory(option) {
console.log(genCard(option));
return genCard(option); return genCard(option);
} }

@ -3,23 +3,28 @@ import liff from "@line/liff";
import { showToast,showSuccessToast } from 'vant'; import { showToast,showSuccessToast } from 'vant';
import { onMounted, reactive, ref, toRefs, computed, watch } from 'vue' import { onBeforeMount, onMounted, reactive, ref, toRefs, computed, watch } from 'vue'
import { getCard, getCusCard, getVipCard, updateSendCount } from '@/api' import { getCard, getCusCard, getVipCard, updateSendCount, getFlexcard } from '@/api'
import { cardFactory } from '@/utils/card' 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 { genAdCard } from '@/utils/adcard' import { genAdCard } from '@/utils/adcard'
import { useStore } from 'vuex'
const store = useStore() import { useUserStore } from '@/store/user';
import { useCardStore } from '@/store/card';
const userStore = useUserStore();
const cardStore = useCardStore();
const imageUrl = ref(import.meta.env.VITE_APP_BASE_URL)
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(() => cusCardInfo.value.card_title),
vip_card: [], vip_card: [],
flexContent: {}, flexContent: {},
}) })
@ -29,14 +34,24 @@ const activeName = ref('0');
let flexRef = ref(null) let flexRef = ref(null)
const userInfo = computed(() => { const userInfo = computed(() => {
console.log(store.state.user.userInfo,"AA"); return userStore.userData;
return store.state.user.userInfo });
})
onMounted(async () => { const cusCardInfo = computed(() => {
return cardStore.cusCard;
});
// const vipCardInfo = computed(() => {
// return cardStore.vipCard;
// });
onBeforeMount(async () => {
// console.log('liff',liff) // console.log('liff',liff)
await liff.init({ liffId: import.meta.env.VITE_APP_LINE_LIFF_ID }); await liff.init({ liffId: import.meta.env.VITE_APP_LINE_LIFF_ID });
await userStore.getUserData();
await cardStore.getCardData();
if (userInfo.value.level > 2) { if (userInfo.value.level > 2) {
let vipCardRes = await getVipCard({ userid: sessionStorage.getItem('uid') }) let vipCardRes = await getVipCard({ userid: sessionStorage.getItem('uid') })
state.value.vip_card = vipCardRes.data state.value.vip_card = vipCardRes.data
@ -45,41 +60,51 @@ onMounted(async () => {
} }
}) })
onMounted(async () => {
//tab //tab
watch(() => activeName.value, function (newVal, oldVal) { watch(() => activeName.value, function (newVal, oldVal) {
if (newVal !== oldVal) { if (newVal !== oldVal) {
showFlex(newVal) showFlex(newVal)
} }
}, { immediate: true }) }, { immediate: true })
//
watch(() => userInfo.value.cus_card, function (newVal, oldVal) { watch(() => userInfo.value.cus_card, function (newVal, oldVal) {
if (userInfo.value.level > 1 && newVal.length > 0) { // if (userInfo.value.level > 1 && newVal > 0) {
if (userInfo.value.level > 1) {
state.value.showCusCard = true state.value.showCusCard = true
} }
}, { immediate: true }) }, { immediate: true })
// //NFC
watch(() => userInfo.value.nc_template, function (newVal, oldVal) { watch(() => userInfo.value.nc_template, function (newVal, oldVal) {
showFlex('0') showFlex('0')
}) })
})
async function showFlex(id) { async function showFlex(id) {
switch (id) { switch (id) {
case '0': case '0':
let { data: res } = await getCard({ userid: sessionStorage.getItem('uid') }) let { data: res } = await getCard({ userid: sessionStorage.getItem('uid') })
let { card } = cardFactory({ tid: userInfo.value.nc_template, vcard: res }) let { card } = cardFactory({ tid: userInfo.value.nc_template, vcard: res })
// state.value.flexContent = genAdCard(JSON.parse(card));
if(userInfo.value.status === 1 && userInfo.value.is_send_ad === 0){ // &
state.value.flexContent = JSON.parse(card) state.value.flexContent = JSON.parse(card)
}else{
let res2 = await getFlexcard();
if (res2.code === 200) {
let data = res2.data;
data.ad_image = imageUrl.value + data.ad_image;
state.value.flexContent = genAdCard(JSON.parse(card),data);
}
}
flexRef.value.innerHTML = '' flexRef.value.innerHTML = ''
flex2html("flex", state.value.flexContent) flex2html("flex", state.value.flexContent)
// console.log(flex2html("flex", state.value.flexContent),"flex2html");
document.getElementById("flex").append('testAAA');
break break
case '1': case '1':
@ -130,9 +155,6 @@ const sendEcard = async () => {
let content = JSON.parse(JSON.stringify(state.value.flexContent)) let content = JSON.parse(JSON.stringify(state.value.flexContent))
console.log(JSON.stringify(state.value.flexContent))
let res let res
if (activeName.value === '0') { if (activeName.value === '0') {
@ -178,8 +200,8 @@ function showChangeTpl() {
showDraw.value = true showDraw.value = true
} }
const changeTpl = (val) => { const changeTpl = async (val) => {
store.dispatch('user/setUserTpl', val) userStore.setUserTpl(val)
showDraw.value = false showDraw.value = false
} }

Loading…
Cancel
Save