You need to sign in or sign up before continuing.
SectionItem.vue 2.65 KB
<!--
 * @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>