search.vue 10 KB

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