HomeOld.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <div class="home-page container">
  3. <!-- 使用 BlockNote 编辑器 -->
  4. <BlockNoteEditor v-model="editorContent" @getHtml="getHtml" :editable="true"/>
  5. <!-- <div v-html="editorContent_html"></div> -->
  6. <div class="banner">
  7. <h1>欢迎来到视频学习平台</h1>
  8. <p>发现优质课程,提升你的技能</p>
  9. </div>
  10. <div class="course-list">
  11. <h2>热门课程</h2>
  12. <div class="course-grid">
  13. <div
  14. v-for="course in courseList"
  15. :key="course.id"
  16. class="course-card"
  17. @click="goToCourseDetail(course.id, course.title)"
  18. >
  19. <img :src="course.cover" :alt="course.title" class="course-cover">
  20. <div class="course-info">
  21. <h3>{{ course.title }}</h3>
  22. <p>讲师:{{ course.teacher }}</p>
  23. <div class="course-price">¥{{ course.price }}</div>
  24. </div>
  25. </div>
  26. </div>
  27. </div>
  28. </div>
  29. </template>
  30. <script setup>
  31. import { onMounted,ref } from 'vue'
  32. import { useRouter } from 'vue-router'
  33. import { useCourseStore } from '../pinia/courseStore'
  34. // 导入封装好的 BlockNote 组件
  35. import BlockNoteEditor from '@/components/BlockNoteEditor.vue';
  36. // 绑定编辑器内容
  37. // [
  38. // {
  39. // type: "paragraph",
  40. // content: [{ type: "text", text: "只读模式" }]
  41. // }
  42. // ]
  43. const editorContent = ref(
  44. [
  45. {
  46. type: "paragraph",
  47. content: [{ type: "text", text: "只读模式" }]
  48. },
  49. {
  50. "id": "378ce968-02c2-4856-888b-c35a355aa84b",
  51. "type": "codeBlock",
  52. "props": {
  53. "language": "text"
  54. },
  55. "content": [],
  56. "children": []
  57. }
  58. ]
  59. );
  60. const editorContent_html = ref();
  61. const router = useRouter()
  62. const courseStore = useCourseStore()
  63. const courseList = ref([])
  64. onMounted(() => {
  65. console.log('Home mounted')
  66. courseStore.fetchCourseList()
  67. courseList.value = courseStore.courseList;
  68. })
  69. const getHtml = (html) => {
  70. editorContent_html.value = html
  71. }
  72. const goToCourseDetail = (id,title) => {
  73. //增加参数名称
  74. router.push({
  75. path: `/course/${id}`,
  76. query: {
  77. title: title
  78. }
  79. })
  80. }
  81. </script>
  82. <style scoped lang="scss">
  83. .banner {
  84. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  85. color: white;
  86. padding: 60px 20px;
  87. text-align: center;
  88. border-radius: 8px;
  89. margin-bottom: 40px;
  90. h1 {
  91. font-size: 2.5rem;
  92. margin-bottom: 10px;
  93. }
  94. p {
  95. font-size: 1.2rem;
  96. opacity: 0.9;
  97. }
  98. }
  99. .course-list {
  100. h2 {
  101. font-size: 1.8rem;
  102. margin-bottom: 20px;
  103. border-bottom: 2px solid #eee;
  104. padding-bottom: 10px;
  105. }
  106. .course-grid {
  107. display: grid;
  108. grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  109. gap: 20px;
  110. }
  111. .course-card {
  112. border: 1px solid #eee;
  113. border-radius: 8px;
  114. overflow: hidden;
  115. cursor: pointer;
  116. transition: transform 0.3s;
  117. &:hover {
  118. transform: translateY(-5px);
  119. box-shadow: 0 5px 15px rgba(0,0,0,0.1);
  120. }
  121. .course-cover {
  122. width: 100%;
  123. height: 180px;
  124. object-fit: cover;
  125. }
  126. .course-info {
  127. padding: 15px;
  128. h3 {
  129. margin-bottom: 8px;
  130. font-size: 1.1rem;
  131. }
  132. p {
  133. color: #666;
  134. margin-bottom: 10px;
  135. }
  136. .course-price {
  137. color: #e63946;
  138. font-weight: bold;
  139. }
  140. }
  141. }
  142. }
  143. </style>