<template>
	<view class="container userinfo-container">
		<CustomNavbar title="我的" type="center" bgColor="rgba(0,0,0,0)" />
		<view class="bg"></view>
		<view class="content pd-12">
			<view class="fun-list-container">
				<text class="title-name">常用</text>
				<view class="fun-list">
					<view class="fun-item" v-for="(item, index) in menuList" :key="index" @click="toPage(item.path)">
						<image
							class=""
							:src="hanleIamgeUrl(item.iconPath)"
							mode="aspectFit|aspectFill|widthFix"
							lazy-load="false"
							binderror=""
							bindload=""
						/>
						<text>{{ item.name }}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
import { ref, inject } from "vue";
import userApi from "@/api/user";

const menuList = ref([
	{
		name: "我的收藏",
		iconPath: "1",
		path: "/subpackages/my/collect/index",
	},
	{
		name: "医学头条",
		iconPath: "2",
		path: "/pages/home/index",
	},
	{
		name: "我的患者",
		iconPath: "3",
		path: "/subpackages/my/myPatient/index",
	},
	{
		name: "AI调优",
		iconPath: "4",
		path: "/subpackages/my/aiTuning/index",
	},
	{
		name: "知识库",
		iconPath: "5",
		path: "/subpackages/my/knowledgeBase/index",
	},
	{
		name: "我的产权",
		iconPath: "6",
		path: "/subpackages/my/ownership/index",
	},
]);



const $showToast: any = inject("$showToast");

/**
 * 跳转页面
 */
const toPage = (url:string) => {
	if(url.includes('pages')) {
		uni.switchTab({url})
	}else {
		uni.navigateTo({url})
	}
	
}


/**
 * 动态图标
 * @param path
 */
 const hanleIamgeUrl = (path: string) => {
	let url = `/static/images/user_icon_${path}.png`;
	// #ifdef H5
	url = new URL(`/src/static/images/user_icon_${path}.png`, import.meta.url).href;
	// #endif
	// #ifdef MP-WEIXIN
	url = `/static/images/user_icon_${path}.png`;
	// #endif
	return url;
};
</script>

<style lang="scss">
@import "./index.scss";
page {
	background-color: #f5f7fa;
}
</style>
