search.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <template>
  2. <view class="search-page">
  3. <!-- 顶部导航栏 -->
  4. <view class="nav-header">
  5. <view class="nav-left" @click="goBack">
  6. <u-icon name="arrow-leftward" color="rgba(51, 51, 51, 1)" size="42"></u-icon>
  7. </view>
  8. <view class="nav-center">
  9. <text class="nav-title">消息搜索</text>
  10. </view>
  11. <view class="nav-right"></view>
  12. </view>
  13. <!-- 搜索框 -->
  14. <view class="search-container">
  15. <view class="search-box">
  16. <u-icon name="search" color="rgba(153, 153, 153, 1)" size="32" style="margin-right: 20rpx;"></u-icon>
  17. <input
  18. v-model="searchKeyword"
  19. class="search-input"
  20. placeholder="您好"
  21. placeholder-style="color: #999999; font-size: 16px;"
  22. @input="onSearchInput"
  23. @confirm="onSearchConfirm"
  24. />
  25. </view>
  26. <view class="cancel-btn" @click="goBack">
  27. <text class="cancel-text">取消</text>
  28. </view>
  29. </view>
  30. <!-- 加载状态 -->
  31. <view class="loading-state" v-if="loading && !searchKeyword">
  32. <text class="loading-text">加载中...</text>
  33. </view>
  34. <!-- 搜索结果 -->
  35. <view class="search-results" v-if="searchResults.length > 0">
  36. <view class="margin-top-sm content">
  37. <view class="radius padding-lr-sm bg" style="margin-top: 4rpx;" @click="goToChat(item)"
  38. v-for="(item,index) in searchResults" :key='index'>
  39. <view class="flex padding-tb">
  40. <view class="avatar-container">
  41. <u-image shape="circle" width='80rpx' height="80rpx" :src="item.avatar"></u-image>
  42. <view class="online-dot"></view>
  43. </view>
  44. <view class="flex-sub margin-left-sm">
  45. <view class="flex justify-between align-center">
  46. <view class="text-white flex align-center userNameleng">
  47. <view class="text-white" style="font-size: 28rpx;">
  48. {{item.userName}}
  49. </view>
  50. <text class="text-grey"
  51. style="font-size: 22rpx;margin-left: 10rpx;">{{item.stationName}}
  52. </text>
  53. </view>
  54. <view class="text-grey">{{item.messageTime ? getMonthOrDay(item.messageTime) : ''}}</view>
  55. </view>
  56. <view class="flex justify-between" style="margin-top: 10rpx;">
  57. <view class="text-grey" v-if="item.messageType == 1">{{item.content}}</view>
  58. <view class="text-grey" v-else-if="item.messageType == 18">位置</view>
  59. <view class="text-grey" v-else-if="item.messageType == 9">简历请求</view>
  60. <view class="text-grey" v-else-if="item.messageType == 6">微信请求</view>
  61. <view class="text-grey" v-else-if="item.messageType == 5">手机号请求</view>
  62. <view class="text-grey" v-else-if="item.messageType == 2">[图片]</view>
  63. <view class="text-grey" v-else-if="item.messageType == 4">[表情]</view>
  64. <view class="text-grey" v-else-if="item.messageType == 20">[视频通话]</view>
  65. <view class="text-grey" v-else-if="item.messageType == 21">[语音通话]</view>
  66. <view v-if="item.contentCount"
  67. style="height: 32rpx;width: 32rpx;border-radius: 100rpx;background-color: red;color: #FFF;text-align: center;">
  68. {{item.contentCount}}
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. <!-- 无搜索结果 -->
  77. <view class="no-results" v-if="searchKeyword && searchResults.length === 0 && !loading">
  78. <text class="no-results-text">暂无搜索结果</text>
  79. </view>
  80. <!-- 默认状态 -->
  81. <view class="default-state" v-if="!searchKeyword && !loading">
  82. <text class="default-text">请输入关键词搜索消息</text>
  83. </view>
  84. </view>
  85. </template>
  86. <script>
  87. export default {
  88. data() {
  89. return {
  90. searchKeyword: '',
  91. searchResults: [],
  92. allChatList: [], // 存储所有聊天记录
  93. page: 1,
  94. limit: 100,
  95. loading: false,
  96. hasMore: true
  97. }
  98. },
  99. onLoad() {
  100. // 页面加载时获取聊天记录
  101. this.getChatList()
  102. },
  103. // 下拉刷新
  104. onPullDownRefresh() {
  105. this.page = 1
  106. this.hasMore = true
  107. this.getChatList()
  108. setTimeout(() => {
  109. uni.stopPullDownRefresh()
  110. }, 1000)
  111. },
  112. methods: {
  113. goBack() {
  114. uni.navigateBack()
  115. },
  116. onSearchInput(e) {
  117. this.searchKeyword = e.detail.value
  118. this.performSearch()
  119. },
  120. onSearchConfirm() {
  121. this.performSearch()
  122. },
  123. // 获取聊天记录列表
  124. getChatList() {
  125. if (this.loading) return
  126. this.loading = true
  127. this.$Request.get("/app/chat/selectChatConversationPage", {
  128. page: this.page,
  129. limit: this.limit
  130. }).then(res => {
  131. this.loading = false
  132. if (res.code == 0) {
  133. if (this.page === 1) {
  134. this.allChatList = res.data.list || []
  135. } else {
  136. this.allChatList = this.allChatList.concat(res.data.list || [])
  137. }
  138. // 检查是否还有更多数据
  139. if (res.data.list && res.data.list.length < this.limit) {
  140. this.hasMore = false
  141. }
  142. // 如果有搜索关键词,执行搜索
  143. if (this.searchKeyword.trim()) {
  144. this.performSearch()
  145. }
  146. }
  147. }).catch(err => {
  148. this.loading = false
  149. console.error('获取聊天记录失败:', err)
  150. })
  151. },
  152. // 执行搜索
  153. performSearch() {
  154. if (!this.searchKeyword.trim()) {
  155. this.searchResults = []
  156. return
  157. }
  158. console.log('搜索关键词:', this.searchKeyword)
  159. // 从所有聊天记录中搜索,直接使用原始数据结构
  160. this.searchResults = this.allChatList.filter(item => {
  161. const keyword = this.searchKeyword.toLowerCase()
  162. return (
  163. (item.userName && item.userName.toLowerCase().includes(keyword)) ||
  164. (item.content && item.content.toLowerCase().includes(keyword)) ||
  165. (item.stationName && item.stationName.toLowerCase().includes(keyword))
  166. )
  167. })
  168. },
  169. // 把时间转换为月日(与首页保持一致)
  170. getMonthOrDay(time) {
  171. let date = new Date(time) // 获取时间
  172. let month = date.getMonth() + 1 // 获取月
  173. let strDate = date.getDate() // 获取日
  174. return month + '月' + strDate + '日'
  175. },
  176. goToChat(item) {
  177. // 跳转到聊天页面,使用与首页相同的跳转方式
  178. uni.navigateTo({
  179. url: `/pages/msg/im?chatConversationId=${item.chatConversationId}&byUserId=${item.focusedUserId}&postPushId=${item.postPushId}&resumesId=${item.resumesId}`
  180. })
  181. }
  182. }
  183. }
  184. </script>
  185. <style lang="scss" scoped>
  186. .search-page {
  187. min-height: 100vh;
  188. padding: 80rpx 0 0 0;
  189. }
  190. .nav-header {
  191. display: flex;
  192. align-items: center;
  193. justify-content: space-between;
  194. padding: 20rpx 30rpx;
  195. background-color: #ffffff;
  196. .nav-left, .nav-right {
  197. width: 60rpx;
  198. height: 60rpx;
  199. display: flex;
  200. align-items: center;
  201. justify-content: center;
  202. }
  203. .nav-center {
  204. flex: 1;
  205. text-align: center;
  206. }
  207. .nav-title {
  208. color: rgba(51, 51, 51, 1);
  209. font-family: DM Sans;
  210. font-size: 20px;
  211. font-weight: 600;
  212. line-height: 26px;
  213. letter-spacing: undefined;
  214. text-align: center;
  215. }
  216. }
  217. .search-container {
  218. display: flex;
  219. align-items: center;
  220. padding: 20rpx 30rpx;
  221. background-color: #ffffff;
  222. border-bottom: 1rpx solid #f0f0f0;
  223. .search-box {
  224. flex: 1;
  225. display: flex;
  226. align-items: center;
  227. background-color:rgba(241, 241, 241, 1);
  228. border-radius: 38rpx;
  229. padding: 15rpx 30rpx;
  230. margin-right: 20rpx;
  231. .search-input {
  232. color: rgba(153, 153, 153, 1);
  233. font-family: DM Sans;
  234. font-size: 12px;
  235. font-weight: 500;
  236. line-height: 24px;
  237. letter-spacing: undefined;
  238. text-align: left;
  239. }
  240. }
  241. .cancel-btn {
  242. padding: 10rpx 20rpx;
  243. .cancel-text {
  244. color: rgba(153, 153, 153, 1);
  245. font-family: DM Sans;
  246. font-size: 14px;
  247. font-weight: 500;
  248. line-height: 24px;
  249. letter-spacing: undefined;
  250. text-align: center;
  251. }
  252. }
  253. }
  254. .search-results {
  255. padding: 20rpx 0;
  256. .result-item {
  257. display: flex;
  258. align-items: flex-start;
  259. padding: 30rpx;
  260. background-color: #ffffff;
  261. margin-bottom: 2rpx;
  262. &:active {
  263. background-color: #f5f5f5;
  264. }
  265. .avatar-container {
  266. position: relative;
  267. margin-right: 30rpx;
  268. .avatar {
  269. width: 80rpx;
  270. height: 80rpx;
  271. border-radius: 50%;
  272. }
  273. .online-dot {
  274. position: absolute;
  275. bottom: 5rpx;
  276. right: 5rpx;
  277. width: 20rpx;
  278. height: 20rpx;
  279. background-color: #00ff00;
  280. border-radius: 50%;
  281. border: 2rpx solid #ffffff;
  282. }
  283. }
  284. .result-content {
  285. flex: 1;
  286. .result-header {
  287. display: flex;
  288. justify-content: space-between;
  289. align-items: center;
  290. margin-bottom: 10rpx;
  291. .user-name {
  292. font-size: 32rpx;
  293. font-weight: 500;
  294. color: rgba(29, 33, 41, 1);
  295. }
  296. .message-date {
  297. font-size: 24rpx;
  298. color: rgba(153, 153, 153, 1);
  299. }
  300. }
  301. .result-info {
  302. margin-bottom: 10rpx;
  303. .company-info {
  304. font-size: 28rpx;
  305. color: rgba(102, 102, 102, 1);
  306. }
  307. }
  308. .message-preview {
  309. .preview-text {
  310. font-size: 28rpx;
  311. color: rgba(153, 153, 153, 1);
  312. line-height: 1.4;
  313. }
  314. }
  315. }
  316. }
  317. }
  318. // 引入首页的样式
  319. .margin-top-sm {
  320. margin-top: 0 !important;
  321. }
  322. .content {
  323. padding: 0 20rpx;
  324. }
  325. .radius {
  326. border-radius: 15rpx;
  327. }
  328. .padding-lr-sm {
  329. padding-left: 20rpx;
  330. padding-right: 20rpx;
  331. }
  332. .bg {
  333. background-color: #ffffff;
  334. }
  335. .flex {
  336. display: flex;
  337. }
  338. .padding-tb {
  339. padding-top: 20rpx;
  340. padding-bottom: 20rpx;
  341. }
  342. .flex-sub {
  343. flex: 1;
  344. }
  345. .margin-left-sm {
  346. margin-left: 20rpx;
  347. }
  348. .justify-between {
  349. justify-content: space-between;
  350. }
  351. .align-center {
  352. align-items: center;
  353. }
  354. .text-white {
  355. color: #333333;
  356. }
  357. .text-grey {
  358. color: #999999;
  359. }
  360. .userNameleng {
  361. max-width: 400rpx;
  362. overflow: hidden;
  363. text-overflow: ellipsis;
  364. white-space: nowrap;
  365. }
  366. .avatar-container {
  367. position: relative;
  368. }
  369. .online-dot {
  370. position: absolute;
  371. bottom: 5rpx;
  372. right: 5rpx;
  373. width: 20rpx;
  374. height: 20rpx;
  375. background-color: #00ff00;
  376. border-radius: 50%;
  377. border: 2rpx solid #ffffff;
  378. }
  379. .loading-state, .no-results, .default-state {
  380. display: flex;
  381. justify-content: center;
  382. align-items: center;
  383. padding: 100rpx 0;
  384. .loading-text, .no-results-text, .default-text {
  385. font-size: 28rpx;
  386. color: rgba(153, 153, 153, 1);
  387. }
  388. }
  389. </style>