四零语境前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

332 lines
7.6 KiB

1 month ago
  1. <template>
  2. <view class="search-container">
  3. <!-- 状态栏安全区域 -->
  4. <uv-status-bar></uv-status-bar>
  5. <!-- 顶部搜索栏 -->
  6. <view class="search-header">
  7. <uv-search
  8. v-model="searchKeyword"
  9. placeholder="请输入内容"
  10. :show-action="true"
  11. action-text="搜索"
  12. :action-style="{
  13. color: '#fff',
  14. backgroundColor: '#FFA500',
  15. borderRadius: '198rpx',
  16. width: '100rpx',
  17. height: '64rpx',
  18. textAlign: 'center',
  19. fontSize: '26rpx',
  20. lineHeight: '64rpx',
  21. }"
  22. :customStyle="{
  23. width: '500rpx',
  24. }"
  25. @search="handleSearch"
  26. @custom="handleSearch"
  27. ></uv-search>
  28. </view>
  29. <!-- 分类标签栏 -->
  30. <view class="category-tabs">
  31. <scroll-view scroll-x class="tab-scroll">
  32. <view class="tab-list">
  33. <view
  34. v-for="(tab, index) in categoryTabs"
  35. :key="index"
  36. class="tab-item"
  37. :class="{ active: currentTab === index }"
  38. @click="switchTab(index)"
  39. >
  40. {{ tab }}
  41. </view>
  42. </view>
  43. </scroll-view>
  44. </view>
  45. <!-- 搜索结果列表 -->
  46. <view class="search-results">
  47. <view
  48. v-for="(book, index) in bookList"
  49. :key="index"
  50. class="book-item"
  51. @click="goToDetail(book)"
  52. >
  53. <view class="book-cover">
  54. <image :src="book.cover" mode="aspectFill"></image>
  55. </view>
  56. <view class="book-info">
  57. <view class="book-title">{{ book.title }}</view>
  58. <view class="book-author">{{ book.author }}</view>
  59. <view class="book-meta">
  60. <view class="book-duration">
  61. <image src="/static/播放图标.png" mode="aspectFill" class="book-icon"></image>
  62. <text>{{ book.duration }}</text>
  63. </view>
  64. <view class="book-membership" :class="classMap[book.membershipType]">
  65. {{ book.membership }}
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </template>
  73. <script>
  74. export default {
  75. data() {
  76. return {
  77. searchKeyword: '短文',
  78. currentTab: 0,
  79. categoryTabs: ['为你推荐', '精选', '短文', '专栏', '初中', '四六级'],
  80. // 类型引射表
  81. classMap: {
  82. premium: 'book-membership-premium',
  83. vip: 'book-membership-vip',
  84. basic: 'book-membership-basic',
  85. },
  86. bookList: [
  87. {
  88. cover: '/static/主页图标.png',
  89. title: '短文全脑孩子:12项革命性策略...',
  90. author: 'Daniel J. Siegel / Tina Payne Bryson / Del...',
  91. duration: '03:24',
  92. membership: '蕾朵会员',
  93. membershipType: 'premium'
  94. },
  95. {
  96. cover: '/static/默认图片.png',
  97. title: '精讲短文',
  98. author: 'Daniel J. Siegel / Tina Payne Bryson / Del...',
  99. duration: '03:24',
  100. membership: '盛放会员',
  101. membershipType: 'vip'
  102. },
  103. {
  104. cover: '/static/默认图片.png',
  105. title: '精讲短文',
  106. author: 'Daniel J. Siegel / Tina Payne Bryson / Del...',
  107. duration: '03:24',
  108. membership: '蕾朵会员',
  109. membershipType: 'premium'
  110. },
  111. {
  112. cover: '/static/默认图片.png',
  113. title: '精讲短文',
  114. author: 'Daniel J. Siegel / Tina Payne Bryson / Del...',
  115. duration: '03:24',
  116. membership: '盛放会员',
  117. membershipType: 'vip'
  118. },
  119. {
  120. cover: '/static/默认图片.png',
  121. title: '精讲短文',
  122. author: 'Daniel J. Siegel / Tina Payne Bryson / Del...',
  123. duration: '03:24',
  124. membership: '萌芽会员',
  125. membershipType: 'basic'
  126. },
  127. {
  128. cover: '/static/默认图片.png',
  129. title: '精讲短文',
  130. author: 'Daniel J. Siegel / Tina Payne Bryson / Del...',
  131. duration: '03:24',
  132. membership: '萌芽会员',
  133. membershipType: 'basic'
  134. },
  135. {
  136. cover: '/static/默认图片.png',
  137. title: '精讲短文',
  138. author: 'Daniel J. Siegel / Tina Payne Bryson / Del...',
  139. duration: '03:24',
  140. membership: '萌芽会员',
  141. membershipType: 'basic'
  142. },
  143. {
  144. cover: '/static/默认图片.png',
  145. title: '精讲短文',
  146. author: 'Daniel J. Siegel / Tina Payne Bryson / Del...',
  147. duration: '03:24',
  148. membership: '萌芽会员',
  149. membershipType: 'basic'
  150. },
  151. ]
  152. }
  153. },
  154. methods: {
  155. handleSearch() {
  156. console.log('搜索:', this.searchKeyword)
  157. // 这里添加搜索逻辑
  158. },
  159. switchTab(index) {
  160. this.currentTab = index
  161. console.log('切换分类:', this.categoryTabs[index])
  162. // 这里添加分类切换逻辑
  163. },
  164. goToDetail(book) {
  165. console.log('查看详情:', book)
  166. // 这里添加跳转详情页逻辑
  167. }
  168. }
  169. }
  170. </script>
  171. <style scoped lang="scss">
  172. .search-container {
  173. background: #fff;
  174. min-height: 100vh;
  175. }
  176. .search-header {
  177. padding: 10rpx 32rpx 20rpx;
  178. background: #fff;
  179. }
  180. .category-tabs {
  181. background: #fff;
  182. // border-bottom: 1rpx solid #f0f0f0;
  183. .tab-scroll {
  184. white-space: nowrap;
  185. }
  186. .tab-list {
  187. display: flex;
  188. padding: 0 32rpx;
  189. }
  190. .tab-item {
  191. flex-shrink: 0;
  192. padding: 24rpx 22rpx;
  193. font-size: 32rpx;
  194. color: $secondary-text-color;
  195. position: relative;
  196. &.active {
  197. color: $primary-text-color;
  198. font-weight: 600;
  199. &::after {
  200. content: '';
  201. position: absolute;
  202. bottom: 0;
  203. left: 50%;
  204. transform: translateX(-50%);
  205. width: 22rpx;
  206. height: 4rpx;
  207. background: $primary-text-color;
  208. border-radius: 2rpx;
  209. }
  210. }
  211. }
  212. }
  213. .search-results {
  214. padding: 32rpx;
  215. display: flex;
  216. flex-direction: column;
  217. gap: 32rpx;
  218. }
  219. .book-item {
  220. display: flex;
  221. align-items: center;
  222. // border-bottom: 1rpx solid #f5f5f5;
  223. background: #F8F8F8;
  224. // width: 686rpx;
  225. height: 212rpx;
  226. gap: 16rpx;
  227. border-radius: 16rpx;
  228. padding: 0rpx 16rpx;
  229. &:last-child {
  230. border-bottom: none;
  231. }
  232. .book-cover {
  233. width: 136rpx;
  234. height: 180rpx;
  235. border-radius: 16rpx;
  236. overflow: hidden;
  237. margin-right: 16rpx;
  238. image {
  239. width: 100%;
  240. height: 100%;
  241. }
  242. }
  243. .book-info {
  244. flex: 1;
  245. display: flex;
  246. flex-direction: column;
  247. justify-content: space-between;
  248. }
  249. .book-title {
  250. font-size: 32rpx;
  251. font-weight: 600;
  252. color: $primary-text-color;
  253. line-height: 48rpx;
  254. letter-spacing: 0;
  255. margin-bottom: 12rpx;
  256. overflow: hidden;
  257. text-overflow: ellipsis;
  258. }
  259. .book-author {
  260. font-size: 24rpx;
  261. color: $secondary-text-color;
  262. margin-bottom: 16rpx;
  263. overflow: hidden;
  264. text-overflow: ellipsis;
  265. white-space: nowrap;
  266. }
  267. .book-meta {
  268. display: flex;
  269. align-items: center;
  270. justify-content: space-between;
  271. }
  272. .book-duration {
  273. display: flex;
  274. align-items: center;
  275. font-size: 22rpx;
  276. color: #999;
  277. .book-icon{
  278. width: 18rpx;
  279. height: 18rpx;
  280. }
  281. text {
  282. margin-left: 8rpx;
  283. }
  284. }
  285. .book-membership {
  286. padding: 8rpx 16rpx;
  287. border-radius: 8rpx;
  288. font-size: 24rpx;
  289. color: #211508;
  290. }
  291. }
  292. .book-membership-premium {
  293. background: #E9F1FF;
  294. border: 2rpx solid #C4DAFF
  295. }
  296. .book-membership-vip {
  297. background: #FFF4E9;
  298. border: 2rpx solid #FFE2C4
  299. }
  300. .book-membership-basic {
  301. background: #FFE9E9;
  302. border: 2rpx solid #FFDBC4
  303. }
  304. </style>