<script setup lang="ts">
import {ref} from 'vue'
import PageRenderEngine from "./engine/PageRenderEngine.vue";
import {onLoad} from "@dcloudio/uni-app";

const pageOptions = ref({})
const pageId = ref<string>()
const debugMode = ref(false)

function navBack() {
  try {
    uni.navigateBack({
      delta: 1,
      success: () => {
        console.log('返回成功')
      },
      fail: () => {
        // 如果返回失败，跳转到首页
        uni.redirectTo({
          url: '/pages/index/index'
        })
      }
    })
  } catch (error) {
    console.log('返回失败:', error)
    uni.redirectTo({
      url: '/pages/index/index'
    })
  }
}

onLoad((options) => {
  pageOptions.value = options
  pageId.value = options.id
  debugMode.value = options.debugMode
})

</script>

<template>
  <PageRenderEngine :id="pageId" :debug-mode="debugMode" />
  <image class="btn-back" src="@/assets/images/back-btn.png" mode="aspectFit" @click="navBack"/>
</template>

<style scoped lang="less">
.btn-back {
  position: fixed;
  left: 20rpx;
  top: 70rpx;
  width: 60rpx;
  height: 60rpx;
}
</style>