Home.vue 9.7 KB

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