search.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <script setup lang="ts">
  2. import { useI18n } from 'vue-i18n'
  3. import SearchSvg from '~/assets/icons/search/search-detail.svg'
  4. import type { UserInfoItemVO } from '~/types/api'
  5. import { userApi } from '~/api/user'
  6. import { useApi } from '~/composables/useApi'
  7. defineOptions({
  8. name: 'SearchPage',
  9. })
  10. definePageMeta({
  11. auth: false,
  12. })
  13. const { t } = useI18n()
  14. const router = useRouter()
  15. const { request } = useApi()
  16. const keyword = ref('')
  17. const list = ref<UserInfoItemVO[]>([])
  18. const searching = ref(false)
  19. const searched = ref(false)
  20. const handleBack = () => {
  21. router.back()
  22. }
  23. const handleClear = () => {
  24. keyword.value = ''
  25. }
  26. const doSearch = async () => {
  27. const q = keyword.value.trim()
  28. if (!q) {
  29. list.value = []
  30. searched.value = true
  31. return
  32. }
  33. searching.value = true
  34. searched.value = true
  35. try {
  36. const res = await request(() => userApi.getUserInfos([q]))
  37. list.value = res?.list ?? []
  38. }
  39. finally {
  40. searching.value = false
  41. }
  42. }
  43. const handleSearch = () => {
  44. doSearch()
  45. }
  46. const handleUserClick = (userNo: string) => {
  47. router.push(`/user/profile?id=${userNo}`)
  48. }
  49. // Follow button is display-only until follow API is available
  50. const toggleFollow = (_item: UserInfoItemVO) => {
  51. // TODO: call follow/unfollow API when available
  52. }
  53. </script>
  54. <template>
  55. <div class="search-page min-h-screen bg-white text-[#1d2129]">
  56. <!-- Search bar: back, input, Search button (Figma 01_搜索页搜索栏) -->
  57. <header class="search-page__bar">
  58. <button
  59. type="button"
  60. class="search-page__back"
  61. aria-label="back"
  62. @click="handleBack"
  63. >
  64. <van-icon
  65. name="arrow-left"
  66. :size="24"
  67. />
  68. </button>
  69. <div class="search-page__input-wrap">
  70. <SearchSvg class="search-page__input-icon" />
  71. <input
  72. v-model="keyword"
  73. type="text"
  74. class="search-page__input"
  75. :placeholder="t('search.placeholder')"
  76. @keydown.enter.prevent="handleSearch"
  77. >
  78. <button
  79. v-if="keyword"
  80. type="button"
  81. class="search-page__clear"
  82. aria-label="clear"
  83. @click="handleClear"
  84. >
  85. <van-icon
  86. name="cross"
  87. :size="16"
  88. />
  89. </button>
  90. </div>
  91. <button
  92. type="button"
  93. class="search-page__btn-search"
  94. @click="handleSearch"
  95. >
  96. {{ t('search.button') }}
  97. </button>
  98. </header>
  99. <!-- Related Contacts -->
  100. <section class="search-page__content">
  101. <h2 class="search-page__section-title">
  102. {{ t('search.relatedContacts') }}
  103. </h2>
  104. <div
  105. v-if="searching"
  106. class="search-page__loading"
  107. >
  108. {{ t('common.loading') }}
  109. </div>
  110. <div
  111. v-else-if="searched && !list.length"
  112. class="search-page__empty"
  113. >
  114. {{ t('search.noResult') }}
  115. </div>
  116. <ul
  117. v-else
  118. class="search-page__list"
  119. >
  120. <li
  121. v-for="item in list"
  122. :key="item.userNo"
  123. class="search-page__row"
  124. @click="handleUserClick(item.userNo)"
  125. >
  126. <div class="search-page__row-left">
  127. <div class="search-page__avatar-wrap">
  128. <NuxtImg
  129. :src="item.avatar"
  130. :alt="item.nickname"
  131. class="search-page__avatar"
  132. loading="lazy"
  133. />
  134. </div>
  135. <div class="search-page__info">
  136. <div class="search-page__name-row">
  137. <span class="search-page__name">{{ item.nickname }}</span>
  138. <CommonGender
  139. :gender="item.gender"
  140. :age="item.age"
  141. />
  142. </div>
  143. <div class="search-page__meta">
  144. <span>ID {{ item.userNo }}</span>
  145. <span>{{ t('search.fansCount', { count: item.fansCount ?? 0 }) }}</span>
  146. </div>
  147. </div>
  148. </div>
  149. <button
  150. type="button"
  151. class="search-page__follow-btn"
  152. :class="{ 'search-page__follow-btn--followed': item.follow }"
  153. @click.stop="toggleFollow(item)"
  154. >
  155. {{ item.follow ? t('search.followed') : t('search.follow') }}
  156. </button>
  157. </li>
  158. </ul>
  159. </section>
  160. </div>
  161. </template>
  162. <style lang="scss" scoped>
  163. .search-page {
  164. padding-top: env(safe-area-inset-top);
  165. padding-bottom: env(safe-area-inset-bottom);
  166. }
  167. .search-page__bar {
  168. display: flex;
  169. align-items: center;
  170. gap: 12px;
  171. height: 54px;
  172. padding: 9px 16px;
  173. background: #fff;
  174. }
  175. .search-page__back {
  176. flex-shrink: 0;
  177. padding: 0;
  178. border: none;
  179. background: transparent;
  180. display: flex;
  181. align-items: center;
  182. justify-content: center;
  183. -webkit-tap-highlight-color: transparent;
  184. }
  185. .search-page__input-wrap {
  186. flex: 1;
  187. min-width: 0;
  188. height: 36px;
  189. display: flex;
  190. align-items: center;
  191. gap: 8px;
  192. padding: 0 10px;
  193. background: #f2f3f5;
  194. border-radius: 20px;
  195. }
  196. .search-page__input-icon {
  197. flex-shrink: 0;
  198. width: 18px;
  199. height: 18px;
  200. }
  201. .search-page__input {
  202. flex: 1;
  203. min-width: 0;
  204. border: none;
  205. background: transparent;
  206. font-size: 12px;
  207. line-height: 16px;
  208. color: #1d2129;
  209. outline: none;
  210. &::placeholder {
  211. color: #c9cdd4;
  212. }
  213. }
  214. .search-page__clear {
  215. flex-shrink: 0;
  216. padding: 0;
  217. border: none;
  218. background: transparent;
  219. display: flex;
  220. align-items: center;
  221. justify-content: center;
  222. color: #86909c;
  223. -webkit-tap-highlight-color: transparent;
  224. }
  225. .search-page__btn-search {
  226. flex-shrink: 0;
  227. padding: 0;
  228. border: none;
  229. background: transparent;
  230. font-size: 14px;
  231. font-weight: 600;
  232. line-height: normal;
  233. color: #1d2129;
  234. -webkit-tap-highlight-color: transparent;
  235. }
  236. .search-page__content {
  237. padding: 0 16px;
  238. padding-top: 10px;
  239. }
  240. .search-page__section-title {
  241. font-size: 14px;
  242. font-weight: 600;
  243. color: #1d2129;
  244. margin: 0 0 10px;
  245. }
  246. .search-page__loading,
  247. .search-page__empty {
  248. padding: 24px 0;
  249. font-size: 12px;
  250. color: #86909c;
  251. text-align: center;
  252. }
  253. .search-page__list {
  254. list-style: none;
  255. margin: 0;
  256. padding: 0;
  257. display: flex;
  258. flex-direction: column;
  259. gap: 20px;
  260. }
  261. .search-page__row {
  262. display: flex;
  263. align-items: center;
  264. justify-content: space-between;
  265. gap: 10px;
  266. min-height: 44px;
  267. }
  268. .search-page__row-left {
  269. display: flex;
  270. align-items: center;
  271. gap: 10px;
  272. min-width: 0;
  273. flex: 1;
  274. }
  275. .search-page__avatar-wrap {
  276. position: relative;
  277. flex-shrink: 0;
  278. width: 44px;
  279. height: 44px;
  280. border-radius: 50%;
  281. overflow: hidden;
  282. border: 0.5px solid #fff;
  283. }
  284. .search-page__avatar {
  285. width: 100%;
  286. height: 100%;
  287. object-fit: cover;
  288. }
  289. .search-page__info {
  290. min-width: 0;
  291. display: flex;
  292. flex-direction: column;
  293. gap: 4px;
  294. }
  295. .search-page__name-row {
  296. display: flex;
  297. align-items: center;
  298. gap: 4px;
  299. }
  300. .search-page__name {
  301. font-size: 14px;
  302. font-weight: 600;
  303. color: #1d2129;
  304. overflow: hidden;
  305. text-overflow: ellipsis;
  306. white-space: nowrap;
  307. }
  308. .search-page__meta {
  309. font-size: 11px;
  310. line-height: 14px;
  311. color: #86909c;
  312. display: flex;
  313. align-items: center;
  314. gap: 7px;
  315. }
  316. .search-page__follow-btn {
  317. flex-shrink: 0;
  318. height: 22px;
  319. padding: 0 10px;
  320. border: none;
  321. border-radius: 200px;
  322. font-size: 12px;
  323. font-weight: 600;
  324. line-height: 22px;
  325. color: #fff;
  326. background: linear-gradient(90deg, #4ed2ff 0%, #b1ef5d 137.08%);
  327. -webkit-tap-highlight-color: transparent;
  328. &--followed {
  329. color: #c9cdd4;
  330. background: #f2f3f5;
  331. font-weight: 400;
  332. font-size: 11px;
  333. }
  334. }
  335. </style>