<template>
    <page-meta :page-style="$theme.pageStyle">
        <!-- #ifndef H5 -->
        <navigation-bar
            :front-color="$theme.navColor"
            :background-color="$theme.navBgColor"
        />
        <!-- #endif -->
    </page-meta>
    <!-- #ifndef H5 -->
    <web-view :src="url" @message="getMessage" />
    <!-- #endif -->
    <!-- #ifdef H5 -->
    <webview />
    <tabbar />
    <!--    悬浮菜单    -->
    <floating-menu></floating-menu>
    <!-- #endif -->
</template>

<script setup lang="ts">
import { computed } from 'vue'
// #ifdef H5
import webview from './webview.vue'
// #endif
import { useUserStore } from '@/stores/user'
import { getClient, client } from '@/utils/client'
import { ClientEnum } from '@/enums/appEnums'
import { onReady, onLoad } from '@dcloudio/uni-app'
import { getCurrentInstance } from 'vue'
import { base64ToPath } from '@/utils/imgPath.js'
import { useRouter } from 'uniapp-router-next'
import config from '@/config'

const router = useRouter()
const userStore = useUserStore()
const isApp = computed(() => {
    if (getClient() == ClientEnum.ANDROID || getClient() == ClientEnum.IOS) {
        return 'isApp'
    } else {
        return 'noApp'
    }
})

const getMessage = async (event: any) => {
    const data = event.detail.data
    if (data[0].login) {
        router.navigateTo({ path: '/pages/login/login' })
        return
    }
    const path = await base64ToPath(data[0].base64)
    uni.saveImageToPhotosAlbum({
        filePath: path,
        success: (result) => {
            uni.$u.toast('保存成功！')
        },
        fail: (err) => {
            uni.$u.toast('保存失败！')
        }
    })
}

const url = computed(() => {
    const domain = config.baseUrl
    return `${domain}mobile/packages/pages/mind_map/mind_map?is_web_view=1&token=${userStore.token}&isApp=${isApp.value}&client=${client}`
})
console.log(url)
</script>

<style lang="scss">
page {
    height: 100%;
    overflow: hidden;
}
</style>
