SectionItem.vue
2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!--
* @Date: 2026-01-30 20:12:45
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-01-31 15:21:37
* @FilePath: /manulife-weapp/src/components/SectionItem.vue
* @Description: 展示项目组件,包含图标、标题、副标题和右侧箭头
-->
<template>
<view class="flex items-center justify-between px-[40rpx] mt-[56rpx] cursor-pointer" @tap="handleClick">
<view class="flex items-center">
<view class="w-[96rpx] h-[96rpx] mr-[32rpx] flex items-center justify-center bg-gray-50 rounded-full">
<image
:src="iconUrl"
class="w-[48rpx] h-[48rpx]"
mode="aspectFit"
/>
</view>
<view class="flex flex-col">
<text class="text-[#1f2937] text-[28rpx] font-normal leading-[40rpx]">{{ title }}</text>
<text class="text-[#6b7280] text-[24rpx] mt-[8rpx] leading-[32rpx]">{{ subtitle }}</text>
</view>
</view>
<IconFont name="rect-right" class="text-gray-400" size="16" />
</view>
</template>
<script setup>
import { computed } from 'vue'
import IconFont from '@/components/IconFont.vue'
import defaultIcon from '@/assets/images/icon/文案.svg'
/**
* Section Item Component
* @description 单个展示项目组件,包含图标、标题、副标题和右侧箭头
* @example
* <SectionItem
* title="产品资料"
* subtitle="查看全部产品资料"
* />
* <!-- 默认使用文案图标 -->
*
* <SectionItem
* :icon="remoteIconUrl"
* title="远程图标"
* subtitle="从接口获取的图标"
* />
*/
const props = defineProps({
/**
* 图标
* - 不传或传空字符串:使用默认的"文案"图标
* - 传远程 URL(http/https 开头):使用远程图片
* @example undefined, '', 'https://example.com/icon.png'
*/
icon: {
type: String,
default: ''
},
/**
* 标题
*/
title: {
type: String,
required: true
},
/**
* 副标题/描述
*/
subtitle: {
type: String,
default: ''
},
/**
* 路由路径(可选,用于跳转)
*/
route: {
type: String,
default: ''
}
})
/**
* 计算图标 URL
* @description 判断是远程 URL 还是使用默认图标
* @returns {string} 图标的完整路径
*/
const iconUrl = computed(() => {
// 如果是远程 URL(http/https 开头),直接返回
if (props.icon && (props.icon.startsWith('http://') || props.icon.startsWith('https://'))) {
return props.icon
}
// 否则使用默认的本地 SVG 图标
return defaultIcon
})
const emit = defineEmits(['click'])
/**
* 处理点击事件
*/
const handleClick = () => {
emit('click')
}
</script>
<script>
export default {
name: 'SectionItem'
}
</script>