Home.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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; platformUrl = item.categoryUrl;"
  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 { isLogin } from '@/utils/util.js'
  90. import { getCategoryListTree } from '@/api/category.js'
  91. import { getPublishList } from '@/api/publish.js'
  92. import { onMounted,ref, inject } from 'vue'
  93. import { useRouter } from 'vue-router'
  94. import { useI18n } from 'vue-i18n'
  95. const { t } = useI18n() // 获取t函数// 导入useI18n
  96. const categoryListTree = ref([])
  97. onMounted(() => {
  98. console.log('Home mounted')
  99. getCategoryListTreeFn();
  100. getList();
  101. })
  102. const router = useRouter()
  103. const activePlatform = ref('');
  104. const categoryId = ref('');
  105. const list = ref([]);
  106. const workflowTitle = ref('');
  107. const platformUrl = ref('');
  108. // 监听图片加载完成,动态设置轮播图高度
  109. const carouselHeight = ref('auto')
  110. const onImageLoad = (event) => {
  111. const img = event.target
  112. const aspectRatio = img.naturalWidth / img.naturalHeight
  113. const containerWidth = img.offsetWidth
  114. const calculatedHeight = containerWidth / aspectRatio
  115. carouselHeight.value = calculatedHeight + 'px'
  116. }
  117. const goSearchPlatform = () => {
  118. //增加参数名称
  119. router.push({
  120. path: `/search-platform`,
  121. query: {
  122. categoryId: categoryId.value,
  123. activePlatform: activePlatform.value,
  124. metaTitle: activePlatform.value ,
  125. workflowTitle: workflowTitle.value,
  126. platformUrl:platformUrl.value
  127. }
  128. })
  129. };
  130. const openLoginDialog = inject('openLoginDialog')
  131. const goWorkflowAdd = () => {
  132. //判断是否登录
  133. if(!isLogin({callback: openLoginDialog,t})){
  134. return;
  135. }
  136. //增加参数名称
  137. router.push({
  138. path: `workflow-add`,
  139. query: {
  140. }
  141. })
  142. };
  143. const getCategoryListTreeFn = () => {
  144. getCategoryListTree().then(res => {
  145. console.log(res)
  146. categoryListTree.value = res.rows || [];
  147. activePlatform.value = categoryListTree.value[0]?.categoryName || '';
  148. categoryId.value = categoryListTree.value[0]?.categoryId || '';
  149. platformUrl.value = categoryListTree.value[0]?.categoryUrl || '';
  150. })
  151. };
  152. // 查询寻找工作流列表
  153. const getList = async (type) => {
  154. const res = await getPublishList({
  155. pageNum: 1,
  156. pageSize: 8,
  157. orderByColumn: 'publishId',
  158. isAsc: 'desc'
  159. })
  160. if(res.code === 200){
  161. list.value = res.rows || [];
  162. }
  163. };
  164. </script>
  165. <style lang="scss">
  166. .banner {
  167. // margin-top: 140px;
  168. height: calc(100vh - 60px);
  169. min-height: 600px;
  170. .carousel-image {
  171. width: 100%;
  172. height: auto;
  173. // object-fit: cover; // 保持比例填充整个容器
  174. // object-position: center; // 居中显示
  175. }
  176. }
  177. .icon-search{
  178. width: 24px;
  179. height: 24px;
  180. }
  181. .icon-add{
  182. width: 30px;
  183. height: 30px;
  184. }
  185. // 1. 定义全局变量,方便统一修改
  186. $primary-bg: rgba(255, 255, 255, 0.5);
  187. $white: #fff;
  188. $border-radius-base: 8px;
  189. $border-radius-sm: 8px;
  190. $border-radius-xs: 4px;
  191. $text-color-main: #333;
  192. $font-size-base: 14px;
  193. $font-size-sm: 12px;
  194. $gap-base: 8px;
  195. $gap-lg: 16px;
  196. $gap-xl: 24px;
  197. $padding-base: 20px;
  198. $height-btn: 50px;
  199. // 2. 混合器:按钮通用样式
  200. @mixin btn-style($bg-start, $bg-end) {
  201. padding: 0 16px;
  202. color: $white;
  203. border: none;
  204. border-radius: $border-radius-sm;
  205. cursor: pointer;
  206. display: flex;
  207. align-items: center;
  208. gap: $gap-base;
  209. font-size: 18px;
  210. &:hover {
  211. opacity: 0.9;
  212. }
  213. }
  214. // 3. 混合器:平台图标通用样式
  215. @mixin platform-icon-style($bg-color, $color: $white) {
  216. width: 24px;
  217. height: 24px;
  218. border-radius: $border-radius-xs;
  219. color: $color;
  220. display: flex;
  221. align-items: center;
  222. justify-content: center;
  223. }
  224. // 容器样式(SCSS嵌套)
  225. .workflow-container {
  226. padding: $padding-base;
  227. border-radius: $border-radius-base;
  228. width: 1100px;
  229. margin: $padding-base auto;
  230. // 平台区域嵌套
  231. .platforms {
  232. display: flex;
  233. position: relative;
  234. top: px;
  235. .platform-item {
  236. width: 120px;
  237. display: flex;
  238. align-items: center;
  239. justify-content: center;
  240. gap: 6px;
  241. padding: 8px 0;
  242. border-radius: $border-radius-sm $border-radius-sm 0 0;
  243. //手指
  244. cursor: pointer;
  245. &.active{
  246. background-color: $primary-bg;
  247. }
  248. .platform-icon {
  249. &.n8n-icon {
  250. @include platform-icon-style(#2563eb);
  251. font-size: $font-size-base;
  252. }
  253. &.coze-icon {
  254. @include platform-icon-style(#8b5cf6);
  255. font-size: $font-size-base;
  256. }
  257. &.dify-icon {
  258. @include platform-icon-style($white, $text-color-main);
  259. border: 1px solid #eee;
  260. font-size: $font-size-sm;
  261. }
  262. &.fastgpt-icon {
  263. @include platform-icon-style(#1e293b);
  264. font-size: $font-size-sm;
  265. }
  266. }
  267. .platform-name {
  268. font-size: $font-size-base;
  269. color: $text-color-main;
  270. }
  271. }
  272. }
  273. // 搜索创建栏嵌套
  274. .search-create-bar {
  275. display: flex;
  276. align-items: center;
  277. gap: $gap-base;
  278. background-color: $primary-bg;
  279. padding: 16px;
  280. border-radius: 0 $border-radius-base $border-radius-base $border-radius-base;
  281. &.notFirst{
  282. border-radius: $border-radius-base;
  283. }
  284. .search-input {
  285. flex: 1;
  286. height: 60px;
  287. padding: 0 12px;
  288. outline: none;
  289. font-size: 18px;
  290. border-radius:7px;
  291. border: none;
  292. width: 100%;
  293. //占位符的颜色
  294. ::placeholder {
  295. color: #999;
  296. }
  297. }
  298. .search-btn {
  299. height: 50px;
  300. @include btn-style(#0055FE, #2563eb);
  301. }
  302. .create-btn {
  303. height: 56px;
  304. @include btn-style(#a78bfa, #8b5cf6);
  305. }
  306. .search-input-container{
  307. position: relative;
  308. padding: 2px;
  309. border-radius: 8px;
  310. .search-btn{
  311. position: absolute;
  312. top: 6px;
  313. right: 6px;
  314. }
  315. }
  316. }
  317. }
  318. .home-page{
  319. .course-list{
  320. margin-top: 70px;
  321. margin-bottom: 140px;
  322. }
  323. }
  324. </style>