From 26e7a101474c790262063facecd96a6ec7d09870 Mon Sep 17 00:00:00 2001 From: KarolChang Date: Wed, 5 Jan 2022 09:54:41 +0800 Subject: [PATCH] add cocos settings --- src/views/Home.vue | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/src/views/Home.vue b/src/views/Home.vue index e95802d..6e2ecb3 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -16,6 +16,33 @@ const records = ref([]) const thisMonthData = ref(new MonthData()) const lastMonthData = ref(new MonthData()) +// cocos settings +/** 外部帶進來的param */ +let URLscheme: any = [] +const onLoad = async function () { + let url = window.location.search + if (url.indexOf('?') !== -1) { + let str: string = url.substr(1) + let strs: any[] = str.split('&') + for (let i = 0; i < strs.length; i++) { + URLscheme[strs[i].split('=')[0]] = unescape(strs[i].split('=')[1]) + } + } + CallParent('_alert', '我愛豬涵') +} +const CallParent = async function (method: string, ...param: any[]) { + let target: string = URLscheme['host'] + if (target) { + window.parent.postMessage( + { + method: method, + value: param + }, + target + ) + } +} + // methods const fetchRecords = async function () { try { @@ -30,6 +57,8 @@ const fetchRecords = async function () { nowMonth - 1 === 0 ? 12 : nowMonth - 1 ) isLoading.value = false + // cocos settings + CallParent('_closeBG') } catch (error) { console.error('error', error) } @@ -61,24 +90,13 @@ const calculateMonthData = (year: number, month: number) => { } } -// test -// const btnClick = async function () { -// try { -// const input = { message: 'HELLO', userId: 'Ub3557f7c812e4e78293959fe4fccd414' } -// const { data } = await lineBotAPI.pushMsg(input) -// console.log('data', data) -// } catch (error) { -// console.error('error', error) -// } -// } - +// created fetchRecords() +onLoad()