index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <script setup lang="ts">
  2. import carousalApi from '@/api/carousal'
  3. import CardList from '../src/components/CardList.vue'
  4. // const searchValue = ref('')
  5. import bg from '@/static/image/feed-plan/bg.png'
  6. import circle from '@/static/image/feed-plan/circle.png'
  7. import message from '@/static/image/feed-plan/message.png'
  8. import ToolApi from '@/utils'
  9. interface ListItem {
  10. img: string
  11. title: string
  12. desc: string
  13. time: string
  14. }
  15. interface Item {
  16. content: string
  17. }
  18. interface DotStyle {
  19. backgroundColor: string
  20. selectedBackgroundColor: string
  21. selectedBorder: string
  22. border: string
  23. }
  24. interface TypeItem {
  25. name: string
  26. isClick: boolean
  27. }
  28. const titleName = ref<string>('养宠手册')
  29. const listModel = ref<ListItem[]>([
  30. {
  31. img: bg,
  32. title: '猫咪食物禁忌',
  33. desc: '1 饮食不慎 2 寄生虫\n 3 病毒感染 4 细菌和毒素感染',
  34. time: '2025年1月1日',
  35. },
  36. {
  37. img: bg,
  38. title: '猫咪食物禁忌',
  39. desc: '1 饮食不慎 2 寄生虫\n 3 病毒感染 4 细菌和毒素感染',
  40. time: '2025年1月1日',
  41. },
  42. {
  43. img: bg,
  44. title: '猫咪食物禁忌',
  45. desc: '1 饮食不慎 2 寄生虫\n 3 病毒感染 4 细菌和毒素感染',
  46. time: '2025年1月1日',
  47. },
  48. {
  49. img: bg,
  50. title: '猫咪食物禁忌',
  51. desc: '1 饮食不慎 2 寄生虫\n 3 病毒感染 4 细菌和毒素感染',
  52. time: '2025年1月1日',
  53. },
  54. {
  55. img: bg,
  56. title: '猫咪食物禁忌',
  57. desc: '1 饮食不慎 2 寄生虫\n 3 病毒感染 4 细菌和毒素感染',
  58. time: '2025年1月1日',
  59. },
  60. {
  61. img: bg,
  62. title: '猫咪食物禁忌',
  63. desc: '1 饮食不慎 2 寄生虫\n 3 病毒感染 4 细菌和毒素感染',
  64. time: '2025年1月1日',
  65. },
  66. {
  67. img: bg,
  68. title: '猫咪食物禁忌',
  69. desc: '1 饮食不慎 2 寄生虫\n 3 病毒感染 4 细菌和毒素感染',
  70. time: '2025年1月1日',
  71. },
  72. ])
  73. const safeHeight = ToolApi.getSafeHeight()
  74. const searchValue = ref<string>('')
  75. const info = ref<Item[]>([
  76. { content: '内容 A' },
  77. { content: '内容 B' },
  78. { content: '内容 C' },
  79. ])
  80. const current = ref<number>(0)
  81. const dotStyle = ref<DotStyle>({
  82. backgroundColor: '#DCDCDC',
  83. selectedBackgroundColor: '#0052D9',
  84. selectedBorder: 'none',
  85. border: 'none',
  86. })
  87. function change(e: CustomEvent<{ current: number }>): void {
  88. current.value = e.detail.current
  89. }
  90. const typeList = ref<TypeItem[]>([
  91. { name: '趣味科普', isClick: true },
  92. { name: '科学喂养', isClick: false },
  93. { name: '科学喂养', isClick: false },
  94. { name: '科学喂养', isClick: false },
  95. ])
  96. function handleClickType(item: TypeItem) {
  97. typeList.value.forEach(i => (i.isClick = false))
  98. item.isClick = true
  99. }
  100. const isSearch = ref<boolean>(true)
  101. function handleSearchFocus() {
  102. isSearch.value = false
  103. }
  104. function handleCancel() {
  105. isSearch.value = true
  106. }
  107. const historyList = ref<{ name: string }[]>([
  108. { name: '猫' },
  109. { name: '狗' },
  110. { name: '烘培粮' },
  111. ])
  112. const findList = ref<{ name: string }[]>([
  113. { name: '宠物吃饭慢' },
  114. { name: '猫咪尿闭怎么办' },
  115. ])
  116. function onLoad() {
  117. carousalApi.getCarousalList().then((res) => {
  118. console.log(res)
  119. })
  120. }
  121. onLoad()
  122. </script>
  123. <template>
  124. <TitleBar :title-name="titleName" />
  125. <view class="flex flex-col bg-[#F5F6F7] overflow-y-auto" :style="`height:calc(100vh - ${safeHeight}px)`">
  126. <view class="mx-[6px]">
  127. <uni-search-bar
  128. v-model="searchValue"
  129. placeholder="请搜索你想要的内容"
  130. bg-color="white" clear-button="auto"
  131. :cancel-button="isSearch ? 'none' : 'always'"
  132. :radius="20"
  133. @focus="handleSearchFocus"
  134. @cancel="handleCancel"
  135. />
  136. </view>
  137. <view v-show="!isSearch" class="mx-4 mt-4">
  138. <view>
  139. <text class="text-[18px] font-600">
  140. 历史记录
  141. </text>
  142. <view class="mt-4 flex gap-2 flex-wrap text-[12px] text-[#999] font-400 leading-5">
  143. <view v-for="(item, index) in historyList" :key="index" class="px-2 py-0.5 flex justify-center items-center bg-[white] rounded-sm">
  144. {{ item.name }}
  145. </view>
  146. </view>
  147. <view class="mt-8">
  148. <text class="text-[18px] font-600">
  149. 搜索发现
  150. </text>
  151. <view class="mt-4 flex gap-2 flex-wrap text-[12px] text-[#999] font-400 leading-5">
  152. <view v-for="(item, index) in findList" :key="index" class="px-2 py-0.5 flex justify-center items-center bg-[white] rounded-sm gap-1">
  153. <view class="flex items-center justify-center">
  154. <uni-icons color="#999999" size="14" type="search" />
  155. </view>
  156. <view class="flex items-center justify-center">
  157. {{ item.name }}
  158. </view>
  159. </view>
  160. </view>
  161. </view>
  162. </view>
  163. </view>
  164. <view v-show="isSearch">
  165. <view class="ml-4 mt-4 text-[20px] font-600">
  166. 热门推荐
  167. </view>
  168. <view class="mx-4 mt-4">
  169. <uni-swiper-dot :info="info" :current="current" field="content" mode="dot" :dots-styles="dotStyle">
  170. <swiper class="swiper-box" @change="change">
  171. <swiper-item v-for="(item, index) in info" :key="index" style="background: rgba(0, 0, 0, 0.20)">
  172. <view class="swiper-item">
  173. {{ item.content }}
  174. </view>
  175. </swiper-item>
  176. </swiper>
  177. </uni-swiper-dot>
  178. </view>
  179. <view class="ml-4 mt-5 text-[20px] font-600">
  180. 养宠贴士
  181. </view>
  182. <view class="mx-4">
  183. <scroll-view class="scroll mt-2" scroll-x="auto">
  184. <view class="group h-[40px] mt-1">
  185. <view
  186. v-for="(item, index) in typeList" :key="index" class="item h-[30px] w-[28%] rounded-15px relative" style="border: 1px solid #E7E7E7"
  187. @tap="handleClickType(item)"
  188. >
  189. <view v-if="item.isClick">
  190. <image :src="message" class="absolute w-full" style="height: calc(100% + 5px)" />
  191. <image :src="circle" class="w-[14px] h-[14px] absolute right-2 top-[-4px]" />
  192. </view>
  193. <view class="w-full h-full flex items-center justify-center text-[14px] z-20 relative font-600" :class="item.isClick ? 'type_select_span' : 'type_span'">
  194. {{ item.name }}
  195. </view>
  196. </view>
  197. </view>
  198. </scroll-view>
  199. </view>
  200. <CardList :card-list="listModel" />
  201. </view>
  202. </view>
  203. </template>
  204. <style scoped>
  205. .scroll{
  206. box-sizing: border-box;
  207. .group{
  208. white-space: nowrap;
  209. .item{
  210. display: inline-block;
  211. margin-right: 10px;
  212. }
  213. }
  214. }
  215. .type_span{
  216. color:#999
  217. }
  218. .type_select_span{
  219. color:#FFF
  220. }
  221. </style>