<template>
	<up-navbar :title="title" :bgColor="bgColor" :titleStyle="titleStyle">
	    <template #left>
			<view class="u-nav-slot" slot="left" style="display: flex;background-color: transparent;">
				<image v-if="showback" src="https://oss.familydaf.cn/sxsnfile/20251218/f3c3a77b9aa6451991108e2ca6b873d5.png" style="width: 40rpx;height: 40rpx;" @tap="toBack(backUrl)"></image>
			</view>
		</template>
	</up-navbar>
</template>

<script setup lang="ts">
import { ref } from 'vue'

// 定义组件属性
const props = defineProps({
	title: {
		type: String,
		default: ''
	},
	showback: {
		type: Boolean,
		default: true
	},
	backUrl: {
		type: String,
		default: ''
	},
	bgColor: {
		type: String,
		default: '#ffffff'
	},
	leftIconColor: {
		type: String,
		default: '#111111'
	},
	titleStyle: {
		type: Object,
		default: () => ({
			fontSize: '36rpx',
			fontWeight: 'bold',
			color: '#111111'
		})
	},
	backAlert: {
		type: Boolean,
		default: false
	}
})

// 定义组件状态
const tabUrls = ref([
	'/pages/home',
	'/pages/nonprofit',
	'/pages/my'
])

// 导出方法供模板使用
const toBack = (url: string) => {
	if (props.backAlert) {
		
	} else {
		dealBack(url)
	}
}

const dealBack = (url: string) => {
	if (!url) {
		if (uni.getStorageSync('options')) {
			const options = JSON.parse(decodeURIComponent(uni.getStorageSync('options')))
			uni.redirectTo(options)
			uni.removeStorageSync('options')
			return
		}
		const pages = getCurrentPages()
		if (pages && pages.length > 1) {
			uni.navigateBack()
		} else {
			uni.reLaunch({ url: '/pages/home' })
		}
	} else {
		if (tabUrls.value.find(u => u === url)) {
			uni.reLaunch({ url })
		} else {
			uni.redirectTo({ url })
		}
	}
}
</script>

<style lang="scss" scoped>
	.u-navbar--fixed {
		z-index: 99999 !important;
	}
</style>