Home.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <div class="home-page">
  3. <div class="banner flex-center">
  4. <el-carousel :height="carouselHeight" style="width: 100%;">
  5. <el-carousel-item>
  6. <img
  7. :src="bannerImage"
  8. class="carousel-image"
  9. @load="onImageLoad"
  10. />
  11. </el-carousel-item>
  12. <el-carousel-item>
  13. <img
  14. :src="bannerImage"
  15. class="carousel-image"
  16. @load="onImageLoad"
  17. />
  18. </el-carousel-item>
  19. </el-carousel>
  20. </div>
  21. <!-- 中间搜索区域 -->
  22. <div class="workflow-container">
  23. <!-- 平台标识区域 -->
  24. <div class="platforms">
  25. <div class="platform-item" v-for="item in categoryListTree" :key="item.categoryId"
  26. @click="activePlatform = item.categoryName; categoryId = item.categoryId;"
  27. :class="{'active': categoryId === item.categoryId}">
  28. <img :src="n8Icon" alt="" class="platform-icon n8n-icon bg_color_f5" v-if="item.categoryName === 'n8n'">
  29. <img :src="cozeIcon" alt="" class="platform-icon coze-icon bg_color_f5" v-if="item.categoryName === 'coze'">
  30. <img :src="difyIcon" alt="" class="platform-icon dify-icon bg_color_f5" v-if="item.categoryName === 'dify'">
  31. <img :src="fastgptIcon" alt="" class="platform-icon fastgpt-icon bg_color_f5" v-if="item.categoryName === 'fastGpt'">
  32. <span class="platform-name">{{item.categoryName}}</span>
  33. </div>
  34. <!-- <div class="platform-item" @click="activePlatform = 'n8n'" :class="{'active': activePlatform === 'n8n'}">
  35. <img :src="n8Icon" alt="" class="platform-icon n8n-icon">
  36. <span class="platform-name">n8n</span>
  37. </div>
  38. <div class="platform-item" @click="activePlatform = 'coze'" :class="{'active': activePlatform === 'coze'}">
  39. <img :src="cozeIcon" alt="" class="platform-icon n8n-icon">
  40. <span class="platform-name">Coze</span>
  41. </div>
  42. <div class="platform-item" @click="activePlatform = 'dify'" :class="{'active': activePlatform === 'dify'}">
  43. <img :src="difyIcon" alt="" class="platform-icon n8n-icon">
  44. <span class="platform-name">Dify</span>
  45. </div>
  46. <div class="platform-item" @click="activePlatform = 'fastgpt'" :class="{'active': activePlatform === 'fastgpt'}">
  47. <img :src="fastgptIcon" alt="" class="platform-icon n8n-icon">
  48. <span class="platform-name">FastGPT</span>
  49. </div> -->
  50. </div>
  51. <!-- 搜索与创建区域 -->
  52. <div class="search-create-bar" :class="{'notFirst': categoryId !== categoryListTree[0]?.categoryId}">
  53. <div class="search-input-container flex_1 gradient">
  54. <input
  55. type="text"
  56. :placeholder="$t('common.qingshuruyaosousuodegongzuoliu')"
  57. class="search-input"
  58. v-model="workflowTitle"
  59. />
  60. <button class="search-btn gradient" @click.stop.prevent="goSearchPlatform">
  61. <img :src="searchIcon" alt="" class="icon-search">
  62. {{$t('common.shousuo')}}
  63. </button>
  64. </div>
  65. <button class="create-btn gradient" @click.stop.prevent="goWorkflowAdd">
  66. <img :src="addIcon" alt="" class="icon-add">
  67. {{$t('common.chuangjiangongzuoliu')}}
  68. </button>
  69. </div>
  70. </div>
  71. <!-- 工作流列表 -->
  72. <div class="course-list">
  73. <div class="course-grid">
  74. <CourseCard v-for="item in list" :key="item.workflowId" :info="item" fromPage="home"/>
  75. </div>
  76. </div>
  77. </div>
  78. </template>
  79. <script setup>
  80. import bannerImage from '@/assets/imgs/banner.png'
  81. import searchIcon from '@/assets/imgs/search.png'
  82. import addIcon from '@/assets/imgs/add.png'
  83. import n8Icon from '@/assets/imgs/8n8.png'
  84. import cozeIcon from '@/assets/imgs/coze.png'
  85. import difyIcon from '@/assets/imgs/dify.png'
  86. import fastgptIcon from '@/assets/imgs/FastGPT.png'
  87. import detailIcon from '@/assets/imgs/detail.png'
  88. import CourseCard from '@/components/course-card.vue'
  89. import { getCategoryListTree } from '@/api/category.js'
  90. import { getPublishList } from '@/api/publish.js'
  91. import { onMounted,ref } from 'vue'
  92. import { useRouter } from 'vue-router'
  93. import { useI18n } from 'vue-i18n'
  94. const { t } = useI18n() // 获取t函数// 导入useI18n
  95. const categoryListTree = ref([])
  96. onMounted(() => {
  97. console.log('Home mounted')
  98. getCategoryListTreeFn();
  99. getList();
  100. })
  101. const router = useRouter()
  102. const activePlatform = ref('');
  103. const categoryId = ref('');
  104. const list = ref([]);
  105. const workflowTitle = ref('');
  106. // 监听图片加载完成,动态设置轮播图高度
  107. const carouselHeight = ref('auto')
  108. const onImageLoad = (event) => {
  109. const img = event.target
  110. const aspectRatio = img.naturalWidth / img.naturalHeight
  111. const containerWidth = img.offsetWidth
  112. const calculatedHeight = containerWidth / aspectRatio
  113. carouselHeight.value = calculatedHeight + 'px'
  114. }
  115. const goSearchPlatform = () => {
  116. //增加参数名称
  117. router.push({
  118. path: `/search-platform`,
  119. query: {
  120. categoryId: categoryId.value,
  121. activePlatform: activePlatform.value,
  122. metaTitle: activePlatform.value ,
  123. workflowTitle: workflowTitle.value,
  124. }
  125. })
  126. };
  127. const goWorkflowAdd = () => {
  128. //增加参数名称
  129. router.push({
  130. path: `workflow-add`,
  131. query: {
  132. }
  133. })
  134. };
  135. const getCategoryListTreeFn = () => {
  136. getCategoryListTree().then(res => {
  137. console.log(res)
  138. categoryListTree.value = res.rows || [];
  139. activePlatform.value = categoryListTree.value[0]?.categoryName || '';
  140. categoryId.value = categoryListTree.value[0]?.categoryId || '';
  141. })
  142. };
  143. // 查询寻找工作流列表
  144. const getList = async (type) => {
  145. const res = await getPublishList({
  146. pageNum: 1,
  147. pageSize: 8,
  148. })
  149. if(res.code === 200){
  150. list.value = res.rows || [];
  151. }
  152. };
  153. </script>
  154. <style lang="scss">
  155. .banner {
  156. // margin-top: 140px;
  157. height: calc(100vh - 60px);
  158. min-height: 600px;
  159. .carousel-image {
  160. width: 100%;
  161. height: auto;
  162. // object-fit: cover; // 保持比例填充整个容器
  163. // object-position: center; // 居中显示
  164. }
  165. }
  166. .icon-search{
  167. width: 24px;
  168. height: 24px;
  169. }
  170. .icon-add{
  171. width: 30px;
  172. height: 30px;
  173. }
  174. // 1. 定义全局变量,方便统一修改
  175. $primary-bg: rgba(255, 255, 255, 0.5);
  176. $white: #fff;
  177. $border-radius-base: 8px;
  178. $border-radius-sm: 8px;
  179. $border-radius-xs: 4px;
  180. $text-color-main: #333;
  181. $font-size-base: 14px;
  182. $font-size-sm: 12px;
  183. $gap-base: 8px;
  184. $gap-lg: 16px;
  185. $gap-xl: 24px;
  186. $padding-base: 20px;
  187. $height-btn: 50px;
  188. // 2. 混合器:按钮通用样式
  189. @mixin btn-style($bg-start, $bg-end) {
  190. padding: 0 16px;
  191. color: $white;
  192. border: none;
  193. border-radius: $border-radius-sm;
  194. cursor: pointer;
  195. display: flex;
  196. align-items: center;
  197. gap: $gap-base;
  198. font-size: 18px;
  199. &:hover {
  200. opacity: 0.9;
  201. }
  202. }
  203. // 3. 混合器:平台图标通用样式
  204. @mixin platform-icon-style($bg-color, $color: $white) {
  205. width: 24px;
  206. height: 24px;
  207. border-radius: $border-radius-xs;
  208. color: $color;
  209. display: flex;
  210. align-items: center;
  211. justify-content: center;
  212. }
  213. // 容器样式(SCSS嵌套)
  214. .workflow-container {
  215. padding: $padding-base;
  216. border-radius: $border-radius-base;
  217. width: 1100px;
  218. margin: $padding-base auto;
  219. // 平台区域嵌套
  220. .platforms {
  221. display: flex;
  222. position: relative;
  223. top: px;
  224. .platform-item {
  225. width: 120px;
  226. display: flex;
  227. align-items: center;
  228. justify-content: center;
  229. gap: 6px;
  230. padding: 8px 0;
  231. border-radius: $border-radius-sm $border-radius-sm 0 0;
  232. //手指
  233. cursor: pointer;
  234. &.active{
  235. background-color: $primary-bg;
  236. }
  237. .platform-icon {
  238. &.n8n-icon {
  239. @include platform-icon-style(#2563eb);
  240. font-size: $font-size-base;
  241. }
  242. &.coze-icon {
  243. @include platform-icon-style(#8b5cf6);
  244. font-size: $font-size-base;
  245. }
  246. &.dify-icon {
  247. @include platform-icon-style($white, $text-color-main);
  248. border: 1px solid #eee;
  249. font-size: $font-size-sm;
  250. }
  251. &.fastgpt-icon {
  252. @include platform-icon-style(#1e293b);
  253. font-size: $font-size-sm;
  254. }
  255. }
  256. .platform-name {
  257. font-size: $font-size-base;
  258. color: $text-color-main;
  259. }
  260. }
  261. }
  262. // 搜索创建栏嵌套
  263. .search-create-bar {
  264. display: flex;
  265. align-items: center;
  266. gap: $gap-base;
  267. background-color: $primary-bg;
  268. padding: 16px;
  269. border-radius: 0 $border-radius-base $border-radius-base $border-radius-base;
  270. &.notFirst{
  271. border-radius: $border-radius-base;
  272. }
  273. .search-input {
  274. flex: 1;
  275. height: 60px;
  276. padding: 0 12px;
  277. outline: none;
  278. font-size: 18px;
  279. border-radius:7px;
  280. border: none;
  281. width: 100%;
  282. //占位符的颜色
  283. ::placeholder {
  284. color: #999;
  285. }
  286. }
  287. .search-btn {
  288. height: 50px;
  289. @include btn-style(#0055FE, #2563eb);
  290. }
  291. .create-btn {
  292. height: 56px;
  293. @include btn-style(#a78bfa, #8b5cf6);
  294. }
  295. .search-input-container{
  296. position: relative;
  297. padding: 2px;
  298. border-radius: 8px;
  299. .search-btn{
  300. position: absolute;
  301. top: 6px;
  302. right: 6px;
  303. }
  304. }
  305. }
  306. }
  307. .home-page{
  308. .course-list{
  309. margin-top: 70px;
  310. margin-bottom: 140px;
  311. }
  312. }
  313. </style>