<!--
 * [...furl].vue
 * Copyright (C) 2024 veypi <i@veypi.com>
 * 2024-11-05 18:08
 * Distributed under terms of the GPL license.
 -->

<template>
  <div class="w-full h-full">
    <!-- <h1 class="page-h1">文档中心</h1> -->
    <!-- <q-inner-loading :showing="!visible" label="Please wait..." label-class="text-teal" label-style="font-size: 1.1em" /> -->
    <div class="w-full px-8">
      <Editor v-if='doc' eid='doc' preview :content="doc"></Editor>
    </div>
  </div>
</template>
<script lang="ts" setup>
import msg from '@veypi/msg';
import { fs } from '@veypi/oaer';
let doc = ref('')

let route = useRoute()
let router = useRouter()
let typ = computed(() => route.params.typ)
let furl = computed(() => {
  let f = route.params.furl
  if (typ.value === 'pub') {
    return '/doc/' + f
  }
  return f
})

const visible = ref(false)



const render = (url: string) => {
  console.log(url)
  if (!url) {
    return
  }
  if (typ.value === 'pub') {
    fs.download(url).then(t => {
      doc.value = t
      visible.value = true
    }).catch(e => {
      console.warn(e)
      msg.Warn('访问文档地址不存在')
      router.back()
    })
  }
}

watch(furl, (u, o) => {
  if (u && u !== o) {
    render(u as string)
  }
}, { immediate: true })

onMounted(() => {
})
</script>

<style scoped></style>
