<template>
  <uni-nav-bar
    fixed
    shadow
    background-color="#fff"
    color="#0A1F13"
    :border="false"
    :left-icon="leftIcon ? 'left' : ''"
    :title="title"
    @clickLeft="onLeftClick"
  >
    <template #right> <slot></slot> </template>
  </uni-nav-bar>
</template>
<script setup lang="ts">
const props = defineProps({
  title: {
    type: String,
    default: '',
  },
  leftIcon: {
    type: Boolean,
    default: true,
  },
  custom: {
    type: Boolean,
    default: false,
  },
});

const emits = defineEmits(['back']);
function onLeftClick() {
  emits('back');
  if (props.custom) {
    console.log('自定义返回路径');
    return;
  }
  console.log('默认组件返回路径');
  const canNavBack = getCurrentPages();
  if (canNavBack && canNavBack.length > 1) {
    uni.navigateBack({
      delta: 1,
    });
    // if (canNavBack[canNavBack.length - 1].route === canNavBack[canNavBack.length - 2].route) {
    //   uni.navigateTo({
    //     url: `/${canNavBack[canNavBack.length - 3].route}`,
    //   });
    // } else {
    //   uni.navigateBack({
    //     delta: 1,
    //   });
    // }
  } else {
    history.back();
  }
}
</script>
