index.vue 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  1. <template>
  2. <view>
  3. <view class="msg-box" :style="{ paddingTop: BarHeight + 'px' }">
  4. <!-- <view class="msg-box"> -->
  5. <!-- 顶部导航栏 -->
  6. <view class="nav-header">
  7. <view class="nav-left">
  8. <!-- <u-icon name="search" color="rgba(56, 58, 63, 1)" size="40"></u-icon> -->
  9. </view>
  10. <view class="nav-center">
  11. <text class="nav-title">消息</text>
  12. </view>
  13. <view class="nav-right">
  14. <!-- <u-icon name="bell" color="rgba(56, 58, 63, 1)" size="40" style="margin-right: 20rpx;"></u-icon> -->
  15. <u-icon name="setting" color="rgba(56, 58, 63, 1)" size="40" v-if="isLogin" @click="showSettingsModal"></u-icon>
  16. </view>
  17. </view>
  18. <!-- 系统通知 -->
  19. <view class="system-message-wrapper flex align-center" @click="goMsg">
  20. <view class="system-message-image flex align-center justify-center">
  21. <image src="/static/im/letter.svg" class="letter-icon"></image>
  22. </view>
  23. <view class="system-message-wrapper-r flex align-center justify-between">
  24. <view class="flex align-center">
  25. <text class="message-text">系统消息</text>
  26. <text class="message-count" v-if="systemCount">{{ systemCount }}</text>
  27. </view>
  28. <view class="system-message-time" v-if="systemCount">{{ systemMessageTime || '' }}</view>
  29. </view>
  30. </view>
  31. <!-- 搜索栏 -->
  32. <view class="search-bar flex align-center" v-if="isLogin" @click="goSearch">
  33. <image src="@/static/images/svg/search.svg" class="search-icon"></image>
  34. 搜索聊天记录
  35. </view>
  36. <!-- tabs -->
  37. <view class="tabs-wrapper flex align-center justify-between" v-if="isLogin">
  38. <view
  39. class="tab"
  40. v-for="(tab, index) in prevTabs"
  41. :class="{ 'active-tab': selectedTab == tab.type }"
  42. :key="tab.type + index"
  43. @click="changeTab(tab.type, 'fixed')">
  44. {{ tab.name }}
  45. <template v-if="userType == 1 && unreadCount && tab.type == 'unread'">
  46. ({{ unreadCount }})
  47. <view class="red-dot"></view>
  48. </template>
  49. </view>
  50. <view
  51. class="tab"
  52. v-for="(tab, index) in midTabs"
  53. :class="{ 'active-tab': selectedTab == tab.type }"
  54. :key="tab.type + index"
  55. @click="changeTab(tab.type)">{{ tab.name }}</view>
  56. <view class="icon-wrapper">
  57. <image src="/static/im/more.svg" class="more-icon" @click="showTabModal = true"></image>
  58. <u-mask :show="showTabModal" @click="showTabModal = false">
  59. <view class="tabs-list" :style="{ top: `calc(${BarHeight}px + 370rpx)` }">
  60. <view class="tab-item" v-for="(tab, index) in endTabs" :key="tab.type + index" @click.stop="changeTab(tab.type)">{{ tab.name }}</view>
  61. </view>
  62. </u-mask>
  63. </view>
  64. </view>
  65. <!-- 聊天列表 -->
  66. <template v-if="chatList.length">
  67. <scroll-view
  68. class="scroll-view"
  69. :style="{ height: `calc(100vh - 380rpx - ${BarHeight}px)` }"
  70. :scroll-y="true"
  71. :refresher-threshold="100"
  72. :refresher-enabled="true"
  73. :refresher-triggered="isRefreshing"
  74. scroll-with-animation="true"
  75. @refresherrefresh="handleRefresh">
  76. <view class="list">
  77. <view
  78. class="chat-item flex justify-between"
  79. v-for="item in chatList"
  80. :key="item.chatConversationId"
  81. @click="goIM(item)"
  82. @longpress="confirmDelete(item)">
  83. <view class="avatar-wrapper">
  84. <image :src="item.avatar || '/static/logo.png'" mode="aspectFill" class="avatar"></image>
  85. <view class="online-dot" v-if="item.onlineStatus == 'ONLINE'"></view>
  86. </view>
  87. <view class="chat-info-wrapper flex justify-between">
  88. <view class="chat-info-wrapper-l">
  89. <view class="chat-info-wrapper-l-t flex align-center">
  90. <view class="user-name">{{ item.userName }}</view>
  91. <view class="tip-wrapper">
  92. <text class="text-tip" v-if="item.companyName">{{ item.companyName }}</text>
  93. <text class="text-tip" style="margin: 0 6rpx;" v-if="item.companyName && item.stationName"> | </text>
  94. <text class="text-tip" v-if="item.stationName">{{ item.stationName }}</text>
  95. </view>
  96. </view>
  97. <view class="chat-info-wrapper-l-b">
  98. <template v-if="item.messageType == 1">{{item.content}}</template>
  99. <template v-else-if="item.messageType == 10">简历已发送</template>
  100. <template v-else-if="item.messageType == 18">位置</template>
  101. <template v-else-if="item.messageType == 9">简历请求</template>
  102. <template v-else-if="item.messageType == 6">微信请求</template>
  103. <template v-else-if="item.messageType == 5">手机号请求</template>
  104. <template v-else-if="item.messageType == 2">[图片]</template>
  105. <template v-else-if="item.messageType == 3">[语音]</template>
  106. <template v-else-if="item.messageType == 7">[交换手机]</template>
  107. <template v-else-if="item.messageType == 8">[交换微信]</template>
  108. <template v-else-if="item.messageType == 12">{{item.content}}已拒绝</template>
  109. <template v-else-if="item.messageType == 4">
  110. <image
  111. class="chat-listitem-text"
  112. v-if="item.content && item.messageType === 4"
  113. :src="ossUrl +item.content"
  114. style="height: 40rpx;width: 40rpx;"
  115. ></image>
  116. </template>
  117. <template v-else-if="item.messageType == 20">[视频通话]</template>
  118. <template v-else-if="item.messageType == 21">[语音通话]</template>
  119. <template v-else-if="item.messageType == 99">[面试邀约]</template>
  120. <template v-else-if="item.messageType == 98">[{{item.content}}]</template>
  121. <template v-else-if="item.messageType == 96 || item.messageType == 97">[{{item.content}}]</template>
  122. <template v-else>[其他消息类型]</template>
  123. </view>
  124. </view>
  125. <view class="chat-info-wrapper-r">
  126. <view class="chat-info-wrapper-r-t">
  127. <image src="/static/im/toUp.svg" class="up-icon" v-if="showIsTop(item)"></image>
  128. </view>
  129. <view class="chat-time" v-if="item.messageTime">{{ getMonthOrDay(item.messageTime) }}</view>
  130. <view class="count-wrapper">
  131. <view class="count" v-if="item.contentCount">{{ item.contentCount }}</view>
  132. </view>
  133. </view>
  134. </view>
  135. </view>
  136. </view>
  137. </scroll-view>
  138. </template>
  139. <empty v-if="!chatList.length" content='暂无消息'></empty>
  140. </view>
  141. <!-- <view class="chat-title">聊天</view> -->
  142. <!-- <view v-if="msgList.length" class="margin-topW">
  143. <view class="flex padding-tb radius padding-lr-sm bg" @click="goMsg" v-for="(item,index) in msgList"
  144. :key='index'>
  145. <view>
  146. <image style="width: 80rpx;height: 80rpx;border-radius: 80rpx;"
  147. src="../../static/images/msg/msg.png"></image>
  148. </view>
  149. <view class="flex-sub margin-left-sm">
  150. <view class="flex justify-between">
  151. <view class="text-white">{{item.title?item.title: '系统消息'}}</view>
  152. <view v-if="messageCount>0"
  153. style="height: 32rpx;width: 32rpx;border-radius: 100rpx;background-color: red;color: #FFF;text-align: center;">
  154. {{messageCount}}
  155. </view>
  156. </view>
  157. <view>
  158. <view class="text-grey">{{item.content}}</view>
  159. </view>
  160. </view>
  161. </view>
  162. </view> -->
  163. <!-- <view v-if="chatList.length" class="margin-top-sm content ">
  164. <view class="radius padding-lr-sm bg" style="margin-top: 4rpx;" @click="goIM(item)" @longpress="confirmDelete(item)"
  165. v-for="(item,index) in chatList" :key='index'>
  166. <view class="flex padding-tb ">
  167. <view class="avatar-container">
  168. <u-image shape="circle" width='80rpx' height="80rpx" :src="item.avatar"></u-image>
  169. </view>
  170. <view class="flex-sub margin-left-sm" style="overflow: hidden;">
  171. <view class="flex justify-between align-center">
  172. <view class="text-white flex align-center" style="flex: 1;overflow: hidden;">
  173. <view class="text-white" style="font-size: 30rpx;">
  174. {{item.userName}}
  175. </view>
  176. <text class="text-grey userNameleng" style="font-size: 26rpx;margin-left: 10rpx;">
  177. <text v-if="item.companyName">{{item.companyName}} |</text>
  178. {{item.stationName}}
  179. </text>
  180. </view>
  181. <view class="text-grey" style="flex-shrink: 0;margin-left: 10rpx;">
  182. {{item.messageTime?getMonthOrDay(item.messageTime):''}}</view>
  183. </view>
  184. <view class="flex justify-between" style="margin-top: 10rpx;">
  185. <view class="text-grey" v-if="item.messageType == 1">{{item.content}}</view>
  186. <view class="text-grey" v-else-if="item.messageType == 10">简历已发送</view>
  187. <view class="text-grey" v-else-if="item.messageType == 18">位置</view>
  188. <view class="text-grey" v-else-if="item.messageType == 9">简历请求</view>
  189. <view class="text-grey" v-else-if="item.messageType == 6">微信请求</view>
  190. <view class="text-grey" v-else-if="item.messageType == 5">手机号请求</view>
  191. <view class="text-grey" v-else-if="item.messageType == 2">[图片]</view>
  192. <view class="text-grey" v-else-if="item.messageType == 3">[语音]</view>
  193. <view class="text-grey" v-else-if="item.messageType == 7">[交换手机]</view>
  194. <view class="text-grey" v-else-if="item.messageType == 8">[交换微信]</view>
  195. <view class="text-grey" v-else-if="item.messageType == 12">{{item.content}}已拒绝</view>
  196. <view class="text-grey" v-else-if="item.messageType == 4"><image class="chat-listitem-text"
  197. v-if="item.content && item.messageType === 4"
  198. :src="ossUrl +item.content"
  199. style="height: 40rpx;width: 40rpx;"></image></view>
  200. <view class="text-grey" v-else-if="item.messageType == 20">[视频通话]</view>
  201. <view class="text-grey" v-else-if="item.messageType == 21">[语音通话]</view>
  202. <view class="text-grey" v-else-if="item.messageType == 99">[面试邀约]</view>
  203. <view class="text-grey" v-else-if="item.messageType == 98">[{{item.content}}]</view>
  204. <view class="text-grey" v-else-if="item.messageType == 96 || item.messageType == 97">[{{item.content}}]</view>
  205. <view class="text-grey" v-else>[其他消息类型]</view>
  206. <view v-if="item.contentCount"
  207. style="height: 32rpx;width: 32rpx;border-radius: 100rpx;background-color: red;color: #FFF;text-align: center;">
  208. {{item.contentCount}}
  209. </view>
  210. </view>
  211. </view>
  212. </view>
  213. </view>
  214. </view> -->
  215. <!-- <empty v-if="!chatList.length" content='暂无消息'></empty> -->
  216. <!-- 消息设置弹窗 -->
  217. <u-popup v-model="showSettings" mode="bottom" :mask-close-able="true" border-radius="20">
  218. <view class="settings-modal">
  219. <view class="modal-drag-bar"></view>
  220. <view class="modal-title">消息设置</view>
  221. <!-- 消息通知开关 -->
  222. <view class="setting-item setting-item-first">
  223. <view class="setting-left">
  224. <view class="setting-title-row">
  225. <view class="setting-label">消息通知开关</view>
  226. <view class="setting-desc">关闭后将不再向你推送消息通知</view>
  227. </view>
  228. <view class="switch-status" :class="{ 'status-on': notificationEnabled, 'status-off': !notificationEnabled }">
  229. {{ notificationEnabled ? 'On' : 'Off' }}
  230. </view>
  231. </view>
  232. <view class="setting-right">
  233. <u-switch v-model="notificationEnabled" active-color="#007AFF" @change="toggleNotification"></u-switch>
  234. </view>
  235. </view>
  236. <!-- 招呼语设置 -->
  237. <view class="setting-item" @click="goGreetingSettings">
  238. <view class="setting-left">
  239. <view class="setting-label">招呼语设置</view>
  240. </view>
  241. <view class="setting-right">
  242. <view class="setting-desc">设置后,沟通时可自动发送设置的招呼语</view>
  243. <u-icon name="arrow-right" color="rgba(29, 33, 41, 1)" size="24"></u-icon>
  244. </view>
  245. </view>
  246. <!-- 常用语设置 -->
  247. <view class="setting-item" @click="goCommonPhrases">
  248. <view class="setting-left">
  249. <view class="setting-label">常用语设置</view>
  250. </view>
  251. <view class="setting-right">
  252. <u-icon name="arrow-right" color="rgba(29, 33, 41, 1)" size="24"></u-icon>
  253. </view>
  254. </view>
  255. </view>
  256. </u-popup>
  257. </view>
  258. </template>
  259. <script>
  260. import empty from '../../components/empty.vue'
  261. import configData from '../../common/config.js'
  262. // 求职端tabs
  263. // 显示:全部(固定)、未读(固定)、新招呼、仅沟通、有交换、有面试
  264. const JobApplicationTab = [
  265. {
  266. type: '',
  267. name: '全部'
  268. },
  269. {
  270. type: 'unread',
  271. name: '未读'
  272. },
  273. {
  274. type: 'new',
  275. name: '新招呼'
  276. },
  277. {
  278. type: 'communicating',
  279. name: '仅沟通'
  280. },
  281. {
  282. type: 'exchanged',
  283. name: '有交换'
  284. },
  285. {
  286. type: 'interview',
  287. name: '有面试'
  288. },
  289. ]
  290. // 招聘端tabs
  291. // 显示:全部(固定)、新招呼(固定)、沟通中、已约面、已获取简历、已交换电话、已交换微信、收藏
  292. const RecruitmentTab = [
  293. {
  294. type: '',
  295. name: '全部'
  296. },
  297. {
  298. type: 'new',
  299. name: '新招呼'
  300. },
  301. {
  302. type: 'communicating',
  303. name: '沟通中'
  304. },
  305. {
  306. type: 'interview',
  307. name: '已约面'
  308. },
  309. {
  310. type: 'gotResume',
  311. name: '已获取简历'
  312. },
  313. {
  314. type: 'gotPhone',
  315. name: '已交换电话'
  316. },
  317. {
  318. type: 'gotWx',
  319. name: '已交换微信'
  320. },
  321. {
  322. type: 'collected',
  323. name: '收藏'
  324. },
  325. ]
  326. export default {
  327. components: {
  328. empty
  329. },
  330. data() {
  331. return {
  332. BarHeight: 0,
  333. page: 1,
  334. limit: 100,
  335. chatList: [],
  336. msgList: [],
  337. time: '',
  338. messageCount: 0,
  339. // userCount: 0,
  340. arr: [],
  341. showModal: true,
  342. showSettings: false, // 控制设置弹窗显示
  343. notificationEnabled: true, // 消息通知开关状态
  344. ossUrl:configData.ossUrl,
  345. tabs: [],
  346. selectedTab: '',
  347. isRefreshing: false,
  348. total: 0,
  349. userType: null,
  350. showTabModal: false,
  351. systemCount: 0, // 系统消息数量
  352. systemMessageTime: '', // 系统消息时间
  353. refreshTime: '', // 更新时间戳
  354. isLogin: false,
  355. unreadCount: 0
  356. }
  357. },
  358. computed: {
  359. prevTabs() {
  360. return this.tabs.slice(0, 2)
  361. },
  362. midTabs() {
  363. return this.tabs.slice(2, 4)
  364. },
  365. endTabs() {
  366. return this.tabs.slice(4)
  367. }
  368. },
  369. onLoad() {
  370. // #ifdef APP-PLUS
  371. let systemInfo = uni.getSystemInfoSync();
  372. this.BarHeight = systemInfo.statusBarHeight;
  373. // #endif
  374. uni.$on('chatUnreadCount', (data) => {
  375. if (this.userType === 1) {
  376. this.unreadCount = data
  377. }
  378. })
  379. },
  380. onUnload() {
  381. uni.$off('chatUnreadCount')
  382. },
  383. // //下拉刷新
  384. // onPullDownRefresh() {
  385. // let that = this
  386. // if (uni.getStorageSync('token')) {
  387. // that.getweiduMsg();
  388. // that.getChatList()
  389. // that.getMsgList()
  390. // that.$nextTick(function() {
  391. // that.messageCount = uni.getStorageSync('messageCount')
  392. // })
  393. // }
  394. // },
  395. onShow() {
  396. if (uni.getStorageSync('token')) {
  397. const userType = uni.getStorageSync('userType') || null
  398. if (this.userType != userType) {
  399. this.userType = userType
  400. this.init()
  401. } else {
  402. // if (this.userType == 1) {
  403. // this.getUnreadCount()
  404. // }
  405. this.getChatList()
  406. this.getMsgList()
  407. }
  408. this.isLogin = true
  409. this.time = setInterval(() => {
  410. const newTime = (new Date()).getTime()
  411. // 判断上一次请求是否大于3s
  412. if (this.refreshTime + 3000 < newTime) {
  413. // this.getweiduMsg();
  414. // if (this.userType == 1) {
  415. // this.getUnreadCount()
  416. // }
  417. this.getChatList()
  418. this.getMsgList()
  419. this.$nextTick(() => {
  420. this.messageCount = uni.getStorageSync('messageCount')
  421. })
  422. }
  423. }, 3000)
  424. this.$Request.getT('/app/common/type/310').then(res => { //消息未读提醒
  425. if (res.code == 0) {
  426. if (res.data && res.data.value) {
  427. this.arr.push(res.data.value)
  428. }
  429. }
  430. })
  431. this.$Request.getT('/app/common/type/337').then(res => { //预约成功通知(通用)
  432. if (res.code == 0) {
  433. if (res.data && res.data.value) {
  434. this.arr.push(res.data.value)
  435. }
  436. }
  437. })
  438. this.$Request.getT('/app/common/type/338').then(res => { //订单状态通知
  439. if (res.code == 0) {
  440. if (res.data && res.data.value) {
  441. this.arr.push(res.data.value)
  442. }
  443. }
  444. })
  445. // // #ifdef MP-WEIXIN
  446. // if (this.showModal) {
  447. // this.openMsg()
  448. // }
  449. // // #endif
  450. } else {
  451. this.isLogin = false
  452. this.chatList = []
  453. this.msgList = []
  454. }
  455. },
  456. onHide() {
  457. clearInterval(this.time)
  458. },
  459. methods: {
  460. // 初始化
  461. init() {
  462. // if (this.userType == 1) {
  463. // this.getUnreadCount()
  464. // }
  465. this.setTabs()
  466. this.getChatList()
  467. this.getMsgList()
  468. },
  469. // 设置tabs
  470. setTabs() {
  471. const userType = this.$queue.getData('userType')
  472. if (userType == 1) {
  473. this.tabs = JobApplicationTab
  474. } else if (userType == 2) {
  475. this.tabs = RecruitmentTab
  476. }
  477. },
  478. changeTab(type, isFixed = '') {
  479. if (!isFixed) {
  480. const index = this.tabs.findIndex(tab => tab.type == type)
  481. if (index > -1) {
  482. const tabItem = this.tabs.splice(index, 1)
  483. this.tabs.splice(2, 0, ...tabItem)
  484. }
  485. }
  486. if (this.showTabModal) {
  487. this.showTabModal = false
  488. }
  489. this.selectedTab = type
  490. this.page = 1
  491. this.getChatList()
  492. },
  493. confirmDelete(item){
  494. uni.showModal({
  495. title: '提示',
  496. content: '是否删除这条消息?',
  497. cancelText: '取消',
  498. confirmText: '删除',
  499. success: (res) => {
  500. if (res.confirm) {
  501. this.$Request.get(`/app/chat/deleteConversation?chatConversationId=${item.chatConversationId}`).then(res => {
  502. if(res.code == 0){
  503. uni.showToast({
  504. title: res.msg,
  505. icon: 'none'
  506. })
  507. }else{
  508. uni.showToast({
  509. title: res.msg || '删除失败',
  510. icon: 'none'
  511. })
  512. }
  513. });
  514. }
  515. }
  516. });
  517. },
  518. // 显示置顶
  519. showIsTop(item) {
  520. if (this.userType == 1) {
  521. return Boolean(item.isTop)
  522. } else if (this.userType == 2) {
  523. return Boolean(item.isTopQiye)
  524. }
  525. return false
  526. },
  527. //把时间转换为月日
  528. getMonthOrDay(data) {
  529. // 1️⃣ 手动解析字符串,避免 iOS 时区问题
  530. let timePublish;
  531. if (typeof data === 'string') {
  532. // 格式:2026-01-05 18:46:39
  533. const parts = data.split(/[- :]/);
  534. // 注意:月份从 0 开始
  535. timePublish = new Date(parts[0], parts[1] - 1, parts[2], parts[3] || 0, parts[4] || 0, parts[5] || 0);
  536. } else {
  537. timePublish = new Date(data);
  538. }
  539. const timeNow = new Date();
  540. const publishYear = timePublish.getFullYear();
  541. const publishMonth = timePublish.getMonth() + 1;
  542. const publishDate = timePublish.getDate();
  543. const publishHour = timePublish.getHours().toString().padStart(2, '0');
  544. const publishMinute = timePublish.getMinutes().toString().padStart(2, '0');
  545. const oneDay = 1000 * 60 * 60 * 24;
  546. // 用本地时间差计算天数
  547. const diffDays = Math.floor((timeNow.setHours(0, 0, 0, 0) - timePublish.setHours(0, 0, 0, 0)) / oneDay);
  548. const weekDays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
  549. const weekStr = weekDays[timePublish.getDay()];
  550. const sameYear = publishYear === timeNow.getFullYear();
  551. let result = '';
  552. if (diffDays === 0) {
  553. result = `${publishHour}:${publishMinute}`;
  554. } else if (diffDays === 1) {
  555. result = `昨天 ${publishHour}:${publishMinute}`;
  556. } else if (diffDays < 7) {
  557. result = `${weekStr} ${publishHour}:${publishMinute}`;
  558. } else if (sameYear) {
  559. result = `${publishMonth}月${publishDate}日 ${publishHour}:${publishMinute}`;
  560. } else {
  561. result = `${publishYear}年${publishMonth}月${publishDate}日 ${publishHour}:${publishMinute}`;
  562. }
  563. return result;
  564. },
  565. // // 开启订阅消息
  566. // openMsg() {
  567. // console.log('订阅消息')
  568. // var that = this
  569. // uni.getSetting({
  570. // withSubscriptions: true, //是否获取用户订阅消息的订阅状态,默认false不返回
  571. // success(ret) {
  572. // console.log(ret.subscriptionsSetting.itemSettings, '*************************************')
  573. // // if (ret.subscriptionsSetting.itemSettings && Object.keys(ret.subscriptionsSetting.itemSettings).length == 2) {
  574. // if (ret.subscriptionsSetting.itemSettings) {
  575. // uni.setStorageSync('sendMsg', true)
  576. // uni.openSetting({ // 打开设置页
  577. // success(rea) {
  578. // console.log(rea.authSetting)
  579. // }
  580. // });
  581. // } else { // 用户没有点击“总是保持以上,不再询问”则每次都会调起订阅消息
  582. // uni.setStorageSync('sendMsg', false)
  583. // uni.showModal({
  584. // title: '提示',
  585. // content: '为了更好的体验,请绑定消息推送',
  586. // confirmText: '确定',
  587. // cancelText: '取消',
  588. // confirmColor: '#016BF6',
  589. // success: function(res) {
  590. // if (res.confirm) {
  591. // wx.requestSubscribeMessage({
  592. // tmplIds: that.arr,
  593. // success(re) {
  594. // console.log(JSON.stringify(re),
  595. // '++++++++++++++')
  596. // var datas = JSON.stringify(re);
  597. // if (datas.indexOf("accept") != -1) {
  598. // console.log(re)
  599. // // uni.setStorageSync('sendMsg', true)
  600. // }
  601. // },
  602. // fail: (res) => {
  603. // console.log(res)
  604. // }
  605. // })
  606. // // uni.setStorageSync('sendMsg', true)
  607. // console.log('确认')
  608. // that.showModal = false
  609. // } else if (res.cancel) {
  610. // console.log('取消')
  611. // // uni.setStorageSync('sendMsg', false)
  612. // that.showModal = true
  613. // }
  614. // }
  615. // })
  616. // }
  617. // }
  618. // })
  619. // },
  620. // getweiduMsg() {
  621. // this.$Request.get("/app/chats/userCount").then(res => {
  622. // uni.stopPullDownRefresh()
  623. // if (res.code == 0) {
  624. // this.userCount = res.data
  625. // }
  626. // });
  627. // },
  628. //在线客服
  629. goChat() {
  630. // uni.navigateTo({
  631. // url:'/my/setting/chat'
  632. // })
  633. // #ifdef MP-WEIXIN
  634. if (uni.getStorageSync('sendMsg')) {
  635. // console.log('授权+1')
  636. wx.requestSubscribeMessage({
  637. tmplIds: this.arr,
  638. success(re) {
  639. // console.log(JSON.stringify(re), 111111111111)
  640. var datas = JSON.stringify(re);
  641. if (datas.indexOf("accept") != -1) {
  642. // console.log(re)
  643. }
  644. },
  645. fail: (res) => {
  646. // console.log(res)
  647. }
  648. })
  649. }
  650. // #endif
  651. let that = this
  652. if (uni.getStorageSync('userType') == 1) { //用户端
  653. // #ifdef MP-WEIXIN
  654. wx.openCustomerServiceChat({
  655. extInfo: {
  656. url: that.$queue.getData('kefu')
  657. },
  658. corpId: that.$queue.getData('kefuAppid'),
  659. success(res) {
  660. console.log(res)
  661. },
  662. })
  663. // #endif
  664. // #ifdef H5
  665. window.location.href = that.$queue.getData('kefu');
  666. // #endif
  667. // #ifdef APP
  668. let kefu = that.$queue.getData('kefu')
  669. console.log(kefu)
  670. plus.runtime.openURL(kefu, function(res) {});
  671. // #endif
  672. } else { //企业端
  673. // #ifdef MP-WEIXIN
  674. wx.openCustomerServiceChat({
  675. extInfo: {
  676. url: that.$queue.getData('kefuq')
  677. },
  678. corpId: that.$queue.getData('kefuAppidq'),
  679. success(res) {
  680. console.log(res)
  681. },
  682. })
  683. // #endif
  684. // #ifdef H5
  685. window.location.href = that.$queue.getData('kefuq');
  686. // #endif
  687. // #ifdef APP
  688. let kefu = that.$queue.getData('kefuq')
  689. console.log(kefu)
  690. plus.runtime.openURL(kefu, function(res) {});
  691. // #endif
  692. }
  693. },
  694. getChatList() {
  695. this.refreshTime = (new Date()).getTime()
  696. this.$Request.get("/app/chat/selectChatConversationPage", {
  697. page: this.page,
  698. limit: this.limit,
  699. type: this.selectedTab
  700. }).then(res => {
  701. // uni.stopPullDownRefresh()
  702. if (res.code == 0) {
  703. this.chatList = this.page != 1 ? [...this.chatList, ...res.data.list] : res.data.list
  704. this.total = res.data.totalCount
  705. }
  706. }).finally(() => {
  707. this.refreshTime = (new Date()).getTime()
  708. this.isRefreshing = false
  709. });
  710. },
  711. getMsgList() {
  712. this.$Request.get("/app/message/selectMessageCountByUserId").then(res => {
  713. // uni.stopPullDownRefresh()
  714. if (res.code == 0) {
  715. // this.msgList = res.data.list
  716. this.systemCount = res.data.count
  717. this.systemMessageTime = res.data.lastTime
  718. }
  719. });
  720. },
  721. goIM(e) {
  722. // #ifdef MP-WEIXIN
  723. if (uni.getStorageSync('sendMsg')) {
  724. // console.log('授权+1')
  725. wx.requestSubscribeMessage({
  726. tmplIds: this.arr,
  727. success(re) {
  728. // console.log(JSON.stringify(re), 111111111111)
  729. var datas = JSON.stringify(re);
  730. if (datas.indexOf("accept") != -1) {
  731. // console.log(re)
  732. }
  733. },
  734. fail: (res) => {
  735. // console.log(res)
  736. }
  737. })
  738. }
  739. // #endif
  740. let userId = '';
  741. let userType = uni.getStorageSync('userType')
  742. if (userType == 2) { //当前登录用户为企业
  743. userId = e.userId
  744. } else { //当前登录用户为用户
  745. userId = e.focusedUserId
  746. }
  747. if (uni.getStorageSync('userType') == 1) {
  748. uni.navigateTo({
  749. url: '/pages/msg/im?chatConversationId=' + e.chatConversationId + '&byUserId=' + userId +
  750. '&postPushId=' + e.postPushId + '&resumesId=' + e.resumesId
  751. })
  752. } else {
  753. uni.navigateTo({
  754. url: '/pages/msg/im?chatConversationId=' + e.chatConversationId + '&byUserId=' + userId +
  755. '&resumesId=' + e.resumesId + '&postPushId=' + e.postPushId
  756. })
  757. }
  758. },
  759. goMsg() {
  760. if (!this.isLogin) return
  761. uni.navigateTo({
  762. url: '/pages/msg/message'
  763. })
  764. },
  765. // 显示设置弹窗
  766. showSettingsModal() {
  767. this.showSettings = true
  768. },
  769. // 切换通知开关
  770. toggleNotification() {
  771. // 开关状态已经通过v-model自动更新,这里可以添加其他逻辑
  772. console.log('通知开关状态:', this.notificationEnabled)
  773. },
  774. // 招呼语设置
  775. goGreetingSettings() {
  776. uni.navigateTo({
  777. url: '/pages/msg/addmsg'
  778. })
  779. },
  780. // 常用语设置
  781. goCommonPhrases() {
  782. uni.navigateTo({
  783. url: '/pages/msg/addmsg'
  784. })
  785. },
  786. // 搜索功能
  787. goSearch() {
  788. uni.navigateTo({
  789. url: '/pages/msg/search'
  790. })
  791. },
  792. // 刷新
  793. handleRefresh() {
  794. if (!uni.getStorageSync('token')) {
  795. return this.isRefreshing = false
  796. }
  797. if (this.isRefreshing) return
  798. this.isRefreshing = true
  799. this.page = 1
  800. this.getChatList()
  801. this.getMsgList()
  802. },
  803. // // 加载更多
  804. // loadMore() {
  805. // console.log('加载更多')
  806. // if (this.loading || this.chatList.length >= this.total || !uni.getStorageSync('token')) return
  807. // this.page++
  808. // this.getChatList()
  809. // },
  810. // // 获取未读消息数量
  811. // getUnreadCount() {
  812. // this.$Request.getT('/app/message/selectMessageCountByUserId')
  813. // .then(res => {
  814. // if (res.code == 0) {
  815. // this.unreadCount = res.data.count
  816. // }
  817. // })
  818. // }
  819. }
  820. }
  821. </script>
  822. <style lang="scss" scoped>
  823. .msg-box {
  824. display: flex;
  825. flex-direction: column;
  826. // height: 400px;
  827. font-family: DM Sans;
  828. .chat-title {
  829. background: linear-gradient(180deg, rgba(13, 39, 247, 1) 0%, rgb(191, 194, 201) 100%);
  830. -webkit-background-clip: text;
  831. background-clip: text;
  832. -webkit-text-fill-color: transparent;
  833. color: transparent;
  834. font-family: DM Sans;
  835. font-size: 42rpx;
  836. font-weight: 500;
  837. line-height: 28px;
  838. letter-spacing: 0%;
  839. text-align: left;
  840. margin: 20rpx 0 20rpx 20rpx;
  841. }
  842. .margin-top-sm {
  843. margin-top: 0 !important;
  844. }
  845. .nav-header {
  846. height: 80rpx;
  847. display: flex;
  848. align-items: center;
  849. justify-content: space-between;
  850. padding: 0 20rpx;
  851. }
  852. .nav-left {
  853. width: 60rpx;
  854. display: flex;
  855. justify-content: flex-start;
  856. }
  857. .nav-center {
  858. flex: 1;
  859. display: flex;
  860. justify-content: center;
  861. }
  862. .nav-title {
  863. font-size: 36rpx;
  864. font-weight: 600;
  865. color: #333333;
  866. }
  867. .nav-right {
  868. width: 60rpx;
  869. display: flex;
  870. justify-content: flex-end;
  871. align-items: center;
  872. }
  873. // 系统通知
  874. .system-message-wrapper {
  875. padding: 10rpx 0 0 32rpx;
  876. .system-message-image {
  877. width: 80rpx;
  878. height: 80rpx;
  879. background: linear-gradient(90.00deg, rgba(13, 39, 247, 1),rgba(19, 193, 234, 1));
  880. border-radius: 50%;
  881. margin-right: 32rpx;
  882. .letter-icon {
  883. width: 36rpx;
  884. height: 28rpx;
  885. }
  886. }
  887. .system-message-wrapper-r {
  888. flex: 1;
  889. height: 100%;
  890. padding: 20rpx 32rpx 20rpx 16rpx;
  891. border-bottom: 1px solid rgba(235, 236, 240, 1);
  892. .message-text {
  893. color: rgba(21, 22, 26, 1);
  894. font-size: 32rpx;
  895. font-weight: 400;
  896. }
  897. .message-count {
  898. min-width: 32rpx;
  899. height: 32rpx;
  900. line-height: 32rpx;
  901. padding: 0 10rpx;
  902. color: #fff;
  903. font-size: 20rpx;
  904. background: rgba(240, 35, 35, 1);
  905. border-radius: 32rpx;
  906. box-sizing: border-box;
  907. margin-left: 20rpx;
  908. }
  909. .system-message-time {
  910. color: rgba(189, 191, 198, 1);
  911. font-size: 20rpx;
  912. font-weight: 400;
  913. }
  914. }
  915. }
  916. // 搜索栏
  917. .search-bar {
  918. border: 1px solid rgba(231, 230, 228, 1);
  919. border-radius: 12rpx;
  920. background: rgba(237, 237, 237, 1);
  921. padding: 16rpx 24rpx;
  922. color: rgba(188, 188, 188, 1);
  923. font-size: 28rpx;
  924. margin: 24rpx 32rpx 24rpx;
  925. .search-icon {
  926. width: 32rpx;
  927. height: 32rpx;
  928. margin-right: 16rpx;
  929. }
  930. }
  931. // tabs
  932. .tabs-wrapper {
  933. padding: 8rpx 32rpx;
  934. margin-bottom: 16rpx;
  935. .tab {
  936. position: relative;
  937. padding: 8rpx 24rpx;
  938. border-radius: 50rpx;
  939. background: rgba(0, 0, 0, 0.04);
  940. color: rgba(102, 102, 102, 1);
  941. font-size: 24rpx;
  942. font-weight: 400;
  943. line-height: 28rpx;
  944. &.active-tab {
  945. font-weight: 500;
  946. color: rgba(1, 107, 246, 1);
  947. background: rgba(1, 107, 246, 0.1);
  948. }
  949. .red-dot {
  950. position: absolute;
  951. top: 2px;
  952. right: 2px;
  953. width: 8px;
  954. height: 8px;
  955. border-radius: 8px;
  956. background: #f53f3f;
  957. }
  958. }
  959. .icon-wrapper {
  960. position: relative;
  961. padding: 8rpx;
  962. .more-icon {
  963. width: 36rpx;
  964. height: 36rpx;
  965. }
  966. .tabs-list {
  967. position: absolute;
  968. right: 30rpx;
  969. width: 268rpx;
  970. background: #fff;
  971. border-radius: 4px;
  972. box-shadow: 0px 3px 6px -4px rgba(0, 0, 0, 0.12),0px 6px 16px 0px rgba(0, 0, 0, 0.08),0px 9px 28px 8px rgba(0, 0, 0, 0.05);
  973. z-index: 10;
  974. .tab-item {
  975. text-align: center;
  976. color: rgba(102, 102, 102, 1);
  977. font-size: 14px;
  978. font-weight: 400;
  979. line-height: 34px;
  980. }
  981. }
  982. }
  983. }
  984. // 聊天列表
  985. .scroll-view {
  986. .chat-item {
  987. padding-left: 32rpx;
  988. padding-bottom: 16rpx;
  989. margin-bottom: 20rpx;
  990. .avatar-wrapper {
  991. position: relative;
  992. width: 96rpx;
  993. height: 128rpx;
  994. margin-right: 16rpx;
  995. padding-top: 32rpx;
  996. .avatar {
  997. display: block;
  998. width: 100%;
  999. height: 100%;
  1000. border: 1px solid #eee;
  1001. border-radius: 50%;
  1002. }
  1003. .online-dot {
  1004. position: absolute;
  1005. right: 8rpx;
  1006. bottom: 0;
  1007. width: 16rpx;
  1008. height: 16rpx;
  1009. border: 1px solid rgba(255, 255, 255, 1);
  1010. background: rgba(0, 180, 42, 1);
  1011. border-radius: 50%;
  1012. }
  1013. }
  1014. .chat-info-wrapper {
  1015. flex: 1;
  1016. padding-right: 32rpx;
  1017. padding-bottom: 24rpx;
  1018. border-bottom: 1px solid rgba(235, 236, 240, 1);
  1019. .chat-info-wrapper-l {
  1020. flex: 1;
  1021. width: 400rpx;
  1022. padding-top: 28rpx;
  1023. }
  1024. .user-name {
  1025. // max-width: 130rpx;
  1026. max-width: 70%;
  1027. color: rgba(21, 22, 26, 1);
  1028. font-size: 32rpx;
  1029. font-weight: 400;
  1030. margin-right: 16rpx;
  1031. overflow: hidden;
  1032. text-overflow: ellipsis;
  1033. white-space: nowrap;
  1034. }
  1035. .tip-wrapper {
  1036. max-width: 70%;
  1037. overflow: hidden;
  1038. text-overflow: ellipsis;
  1039. white-space: nowrap;
  1040. }
  1041. .text-tip {
  1042. color: rgba(117, 119, 124, 1);
  1043. font-size: 20rpx;
  1044. font-weight: 400;
  1045. }
  1046. .chat-info-wrapper-l-b {
  1047. width: 100%;
  1048. color: rgba(117, 119, 124, 1);
  1049. font-size: 24rpx;
  1050. font-weight: 400;
  1051. line-height: 36rpx;
  1052. overflow: hidden;
  1053. text-overflow: ellipsis;
  1054. white-space: nowrap;
  1055. }
  1056. .chat-info-wrapper-r-t {
  1057. display: flex;
  1058. justify-content: flex-end;
  1059. width: 100%;
  1060. height: 40rpx;
  1061. .up-icon {
  1062. display: block;
  1063. width: 40rpx;
  1064. height: 40rpx;
  1065. }
  1066. }
  1067. .chat-time {
  1068. color: rgba(189, 191, 198, 1);
  1069. font-size: 24rpx;
  1070. font-weight: 400;
  1071. line-height: 40rpx;
  1072. }
  1073. .count-wrapper {
  1074. display: flex;
  1075. justify-content: flex-end;
  1076. width: 100%;
  1077. height: 32rpx;
  1078. .count {
  1079. min-width: 32rpx;
  1080. line-height: 32rpx;
  1081. border-radius: 32rpx;
  1082. color: #fff;
  1083. font-size: 20rpx;
  1084. padding: 0 10rpx;
  1085. background: rgba(245, 63, 63, 1);
  1086. }
  1087. }
  1088. }
  1089. &:last-child {
  1090. .chat-info-wrapper {
  1091. border-bottom: 0;
  1092. }
  1093. }
  1094. }
  1095. }
  1096. // .bg {
  1097. // background: #FFFFFF;
  1098. // }
  1099. // .userNameleng {
  1100. // // width: 80%;
  1101. // flex: 1;
  1102. // overflow: hidden;
  1103. // white-space: nowrap;
  1104. // text-overflow: ellipsis;
  1105. // -o-text-overflow: ellipsis;
  1106. // }
  1107. // .avatar-container {
  1108. // position: relative;
  1109. // display: inline-block;
  1110. // }
  1111. // .online-dot {
  1112. // position: absolute;
  1113. // bottom: 2rpx;
  1114. // right: 2rpx;
  1115. // width: 20rpx;
  1116. // height: 20rpx;
  1117. // background-color: #00FF00;
  1118. // border-radius: 50%;
  1119. // border: 2rpx solid #FFFFFF;
  1120. // }
  1121. }
  1122. // 设置弹窗样式
  1123. .settings-modal {
  1124. background: #FFFFFF;
  1125. border-radius: 20rpx 20rpx 0 0;
  1126. padding: 0 30rpx 40rpx 30rpx;
  1127. min-width: 100%;
  1128. .modal-drag-bar {
  1129. width: 60rpx;
  1130. height: 8rpx;
  1131. background: #E5E5E5;
  1132. border-radius: 4rpx;
  1133. margin: 20rpx auto 30rpx auto;
  1134. }
  1135. .modal-title {
  1136. margin: 0 auto;
  1137. color: rgba(34, 37, 42, 1);
  1138. font-family: DM Sans;
  1139. font-size: 36rpx;
  1140. font-weight: 500;
  1141. line-height: 23px;
  1142. letter-spacing: 0px;
  1143. text-align: center;
  1144. padding-bottom: 20rpx;
  1145. border-bottom: 1rpx solid rgba(219, 218, 218, 1);
  1146. }
  1147. .setting-item {
  1148. display: flex;
  1149. align-items: center;
  1150. justify-content: space-between;
  1151. padding: 12rpx 32rpx;
  1152. margin-bottom: 30rpx;
  1153. border: 1px solid rgba(227, 231, 236, 1);
  1154. border-radius: 6px;
  1155. &:active {
  1156. background-color: #F8F8F8;
  1157. }
  1158. &.setting-item-first {
  1159. border: none;
  1160. padding: 40rpx 32rpx;
  1161. }
  1162. .setting-left {
  1163. display: flex;
  1164. flex-direction: column;
  1165. align-items: flex-start;
  1166. flex: 1;
  1167. .setting-title-row {
  1168. display: flex;
  1169. align-items: center;
  1170. justify-content: flex-start;
  1171. width: 100%;
  1172. margin-bottom: 16rpx;
  1173. .setting-label {
  1174. color: rgba(21, 22, 26, 1);
  1175. font-family: DM Sans;
  1176. font-size: 32rpx;
  1177. font-weight: 600;
  1178. line-height: 26px;
  1179. letter-spacing: 0%;
  1180. text-align: left;
  1181. margin-right: 16rpx;
  1182. }
  1183. .setting-desc {
  1184. color: rgba(153, 153, 153, 1);
  1185. font-family: DM Sans;
  1186. font-size: 22rpx;
  1187. font-weight: 400;
  1188. line-height: 13px;
  1189. letter-spacing: 0%;
  1190. text-align: left;
  1191. }
  1192. }
  1193. .switch-status {
  1194. font-size: 32rpx;
  1195. &.status-on {
  1196. color: #007AFF;
  1197. }
  1198. &.status-off {
  1199. color: #999999;
  1200. }
  1201. }
  1202. }
  1203. .setting-right {
  1204. display: flex;
  1205. align-items: center;
  1206. justify-content: flex-end;
  1207. .u-switch {
  1208. margin-top: 20rpx;
  1209. transform: scale(1.2); // 放大开关到1.5倍
  1210. }
  1211. .setting-desc {
  1212. color: rgba(153, 153, 153, 1);
  1213. font-family: DM Sans;
  1214. font-size: 22rpx;
  1215. font-weight: 400;
  1216. line-height: 13px;
  1217. letter-spacing: 0%;
  1218. text-align: left;
  1219. margin-right: 16rpx;
  1220. }
  1221. }
  1222. }
  1223. }
  1224. </style>