Recommend.vue 4.0 KB
<template>
  <div class="md:mb-12 mb-6">
    <div class="flex mb-6">
      <div
        class="relative bg-black/10 rounded-[50px] p-[3px] overflow-hidden"
        slidertab="sliderTab"
      >
        <ul
          class="flex relative whitespace-nowrap overflow-x-auto rounded-[100px] bg-[#5961f9]"
          style="flex-wrap: inherit; overflow-y: unset"
          role="tablist"
        >
          <li
            class="w-auto h-auto cursor-pointer list-item whitespace-nowrap line-clamp-1"
          >
            <a
              class="h-7 leading-7 px-3 block relative text-white text-center text-sm"
              data-toggle="pill"
              data-action="load_hot_post"
              data-datas='{"data":{"title":"热门工具","type":"sites","order":"views","num":"12","mini":""}}'
            >
              <i
                class="iconfont mr-2 font-bold text-xs"
                :class="[`icon-${navIcon}`]"
              ></i>
              {{ navTitle }}
            </a>
          </li>
        </ul>
      </div>
    </div>

    <div
      class="grid grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 md:gap-6 gap-4"
    >
      <div
        v-for="(item, index) in recommendList"
        :key="index"
        class="bg-white rounded-xl shadow-md overflow-hidden hover:shadow-lg transition-shadow duration-300"
      >
        <el-popconfirm
          v-if="item.isPopup == '1'"
          class="box-item"
          :title="item.popupContent"
          placement="top-start"
          icon-color="#5961f9"
          width="280"
          :icon="Promotion"
          confirm-button-text="确认前往"
          cancel-button-text="取消"
          @confirm="onConfirm(item.id)"
        >
          <template #reference>
            <a
              :href="'/details/' + item.id"
              target="_blank"
              @click.stop="onNuxtLink"
            >
              <div class="group p-3">
                <div class="flex items-start space-x-4">
                  <img
                    :src="config.public.baseUrl + item.image"
                    :alt="item.title"
                    class="w-10 h-10 md:w-14 md:h-14 object-cover rounded-lg"
                  />
                  <div>
                    <h3
                      class="font-bold md:text-base text-sm line-clamp-1 text-gray-800 transition group-hover:text-[#5961f9]"
                    >
                      {{ item.title }}
                    </h3>
                    <p
                      class="text-gray-600 text-xs mt-1 md:line-clamp-2 line-clamp-1"
                    >
                      {{ item.description }}
                    </p>
                  </div>
                </div>
              </div>
            </a>
          </template>
        </el-popconfirm>
        <a v-else :href="'/details/' + item.id" target="_blank">
          <div class="group p-3">
            <div class="flex items-start space-x-4">
              <img
                :src="config.public.baseUrl + item.image"
                :alt="item.title"
                class="w-10 h-10 md:w-14 md:h-14 object-cover rounded-lg"
              />
              <div>
                <h3
                  class="font-bold md:text-base text-sm line-clamp-1 text-gray-800 transition group-hover:text-[#5961f9]"
                >
                  {{ item.title }}
                </h3>
                <p
                  class="text-gray-600 text-xs mt-1 md:line-clamp-2 line-clamp-1"
                >
                  {{ item.description }}
                </p>
              </div>
            </div>
          </div>
        </a>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { Promotion } from "@element-plus/icons-vue";
defineProps<{
  recommendList: any[];
  navTitle: string;
  navIcon: string;
}>();
const config = useRuntimeConfig();
// 阻止默认行为
function onNuxtLink(event: any) {
  event.preventDefault();
}
// 点击确认跳转
function onConfirm(id: number) {
  window.open(`/details/${id}`);
}
</script>