index.vue 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  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 - 480rpx - ${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. font-family: DM Sans;
  827. .chat-title {
  828. background: linear-gradient(180deg, rgba(13, 39, 247, 1) 0%, rgb(191, 194, 201) 100%);
  829. -webkit-background-clip: text;
  830. background-clip: text;
  831. -webkit-text-fill-color: transparent;
  832. color: transparent;
  833. font-family: DM Sans;
  834. font-size: 42rpx;
  835. font-weight: 500;
  836. line-height: 28px;
  837. letter-spacing: 0%;
  838. text-align: left;
  839. margin: 20rpx 0 20rpx 20rpx;
  840. }
  841. .margin-top-sm {
  842. margin-top: 0 !important;
  843. }
  844. .nav-header {
  845. height: 80rpx;
  846. display: flex;
  847. align-items: center;
  848. justify-content: space-between;
  849. padding: 0 20rpx;
  850. }
  851. .nav-left {
  852. width: 60rpx;
  853. display: flex;
  854. justify-content: flex-start;
  855. }
  856. .nav-center {
  857. flex: 1;
  858. display: flex;
  859. justify-content: center;
  860. }
  861. .nav-title {
  862. font-size: 36rpx;
  863. font-weight: 600;
  864. color: #333333;
  865. }
  866. .nav-right {
  867. width: 60rpx;
  868. display: flex;
  869. justify-content: flex-end;
  870. align-items: center;
  871. }
  872. // 系统通知
  873. .system-message-wrapper {
  874. padding: 10rpx 0 0 32rpx;
  875. .system-message-image {
  876. width: 80rpx;
  877. height: 80rpx;
  878. background: linear-gradient(90.00deg, rgba(13, 39, 247, 1),rgba(19, 193, 234, 1));
  879. border-radius: 50%;
  880. margin-right: 32rpx;
  881. .letter-icon {
  882. width: 36rpx;
  883. height: 28rpx;
  884. }
  885. }
  886. .system-message-wrapper-r {
  887. flex: 1;
  888. height: 100%;
  889. padding: 20rpx 32rpx 20rpx 16rpx;
  890. border-bottom: 1px solid rgba(235, 236, 240, 1);
  891. .message-text {
  892. color: rgba(21, 22, 26, 1);
  893. font-size: 32rpx;
  894. font-weight: 400;
  895. }
  896. .message-count {
  897. min-width: 32rpx;
  898. height: 32rpx;
  899. line-height: 32rpx;
  900. padding: 0 10rpx;
  901. color: #fff;
  902. font-size: 20rpx;
  903. background: rgba(240, 35, 35, 1);
  904. border-radius: 32rpx;
  905. box-sizing: border-box;
  906. margin-left: 20rpx;
  907. }
  908. .system-message-time {
  909. color: rgba(189, 191, 198, 1);
  910. font-size: 20rpx;
  911. font-weight: 400;
  912. }
  913. }
  914. }
  915. // 搜索栏
  916. .search-bar {
  917. border: 1px solid rgba(231, 230, 228, 1);
  918. border-radius: 12rpx;
  919. background: rgba(237, 237, 237, 1);
  920. padding: 16rpx 24rpx;
  921. color: rgba(188, 188, 188, 1);
  922. font-size: 28rpx;
  923. margin: 24rpx 32rpx 24rpx;
  924. .search-icon {
  925. width: 32rpx;
  926. height: 32rpx;
  927. margin-right: 16rpx;
  928. }
  929. }
  930. // tabs
  931. .tabs-wrapper {
  932. padding: 8rpx 32rpx;
  933. margin-bottom: 16rpx;
  934. .tab {
  935. position: relative;
  936. padding: 8rpx 24rpx;
  937. border-radius: 50rpx;
  938. background: rgba(0, 0, 0, 0.04);
  939. color: rgba(102, 102, 102, 1);
  940. font-size: 24rpx;
  941. font-weight: 400;
  942. line-height: 28rpx;
  943. &.active-tab {
  944. font-weight: 500;
  945. color: rgba(1, 107, 246, 1);
  946. background: rgba(1, 107, 246, 0.1);
  947. }
  948. .red-dot {
  949. position: absolute;
  950. top: 2px;
  951. right: 2px;
  952. width: 8px;
  953. height: 8px;
  954. border-radius: 8px;
  955. background: #f53f3f;
  956. }
  957. }
  958. .icon-wrapper {
  959. position: relative;
  960. padding: 8rpx;
  961. .more-icon {
  962. width: 36rpx;
  963. height: 36rpx;
  964. }
  965. .tabs-list {
  966. position: absolute;
  967. right: 30rpx;
  968. width: 268rpx;
  969. background: #fff;
  970. border-radius: 4px;
  971. 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);
  972. z-index: 10;
  973. .tab-item {
  974. text-align: center;
  975. color: rgba(102, 102, 102, 1);
  976. font-size: 14px;
  977. font-weight: 400;
  978. line-height: 34px;
  979. }
  980. }
  981. }
  982. }
  983. // 聊天列表
  984. .scroll-view {
  985. .chat-item {
  986. padding-left: 32rpx;
  987. padding-bottom: 16rpx;
  988. margin-bottom: 20rpx;
  989. .avatar-wrapper {
  990. position: relative;
  991. width: 96rpx;
  992. height: 128rpx;
  993. margin-right: 16rpx;
  994. padding-top: 32rpx;
  995. .avatar {
  996. display: block;
  997. width: 100%;
  998. height: 100%;
  999. border: 1px solid #eee;
  1000. border-radius: 50%;
  1001. }
  1002. .online-dot {
  1003. position: absolute;
  1004. right: 8rpx;
  1005. bottom: 0;
  1006. width: 16rpx;
  1007. height: 16rpx;
  1008. border: 1px solid rgba(255, 255, 255, 1);
  1009. background: rgba(0, 180, 42, 1);
  1010. border-radius: 50%;
  1011. }
  1012. }
  1013. .chat-info-wrapper {
  1014. flex: 1;
  1015. padding-right: 32rpx;
  1016. padding-bottom: 24rpx;
  1017. border-bottom: 1px solid rgba(235, 236, 240, 1);
  1018. .chat-info-wrapper-l {
  1019. flex: 1;
  1020. width: 400rpx;
  1021. padding-top: 28rpx;
  1022. }
  1023. .user-name {
  1024. // max-width: 130rpx;
  1025. max-width: 70%;
  1026. color: rgba(21, 22, 26, 1);
  1027. font-size: 32rpx;
  1028. font-weight: 400;
  1029. margin-right: 16rpx;
  1030. overflow: hidden;
  1031. text-overflow: ellipsis;
  1032. white-space: nowrap;
  1033. }
  1034. .tip-wrapper {
  1035. max-width: 70%;
  1036. overflow: hidden;
  1037. text-overflow: ellipsis;
  1038. white-space: nowrap;
  1039. }
  1040. .text-tip {
  1041. color: rgba(117, 119, 124, 1);
  1042. font-size: 20rpx;
  1043. font-weight: 400;
  1044. }
  1045. .chat-info-wrapper-l-b {
  1046. width: 100%;
  1047. color: rgba(117, 119, 124, 1);
  1048. font-size: 24rpx;
  1049. font-weight: 400;
  1050. line-height: 36rpx;
  1051. overflow: hidden;
  1052. text-overflow: ellipsis;
  1053. white-space: nowrap;
  1054. }
  1055. .chat-info-wrapper-r-t {
  1056. display: flex;
  1057. justify-content: flex-end;
  1058. width: 100%;
  1059. height: 40rpx;
  1060. .up-icon {
  1061. display: block;
  1062. width: 40rpx;
  1063. height: 40rpx;
  1064. }
  1065. }
  1066. .chat-time {
  1067. color: rgba(189, 191, 198, 1);
  1068. font-size: 24rpx;
  1069. font-weight: 400;
  1070. line-height: 40rpx;
  1071. }
  1072. .count-wrapper {
  1073. display: flex;
  1074. justify-content: flex-end;
  1075. width: 100%;
  1076. height: 32rpx;
  1077. .count {
  1078. min-width: 32rpx;
  1079. line-height: 32rpx;
  1080. border-radius: 32rpx;
  1081. color: #fff;
  1082. font-size: 20rpx;
  1083. padding: 0 10rpx;
  1084. background: rgba(245, 63, 63, 1);
  1085. }
  1086. }
  1087. }
  1088. &:last-child {
  1089. .chat-info-wrapper {
  1090. border-bottom: 0;
  1091. }
  1092. }
  1093. }
  1094. }
  1095. // .bg {
  1096. // background: #FFFFFF;
  1097. // }
  1098. // .userNameleng {
  1099. // // width: 80%;
  1100. // flex: 1;
  1101. // overflow: hidden;
  1102. // white-space: nowrap;
  1103. // text-overflow: ellipsis;
  1104. // -o-text-overflow: ellipsis;
  1105. // }
  1106. // .avatar-container {
  1107. // position: relative;
  1108. // display: inline-block;
  1109. // }
  1110. // .online-dot {
  1111. // position: absolute;
  1112. // bottom: 2rpx;
  1113. // right: 2rpx;
  1114. // width: 20rpx;
  1115. // height: 20rpx;
  1116. // background-color: #00FF00;
  1117. // border-radius: 50%;
  1118. // border: 2rpx solid #FFFFFF;
  1119. // }
  1120. }
  1121. // 设置弹窗样式
  1122. .settings-modal {
  1123. background: #FFFFFF;
  1124. border-radius: 20rpx 20rpx 0 0;
  1125. padding: 0 30rpx 40rpx 30rpx;
  1126. min-width: 100%;
  1127. .modal-drag-bar {
  1128. width: 60rpx;
  1129. height: 8rpx;
  1130. background: #E5E5E5;
  1131. border-radius: 4rpx;
  1132. margin: 20rpx auto 30rpx auto;
  1133. }
  1134. .modal-title {
  1135. margin: 0 auto;
  1136. color: rgba(34, 37, 42, 1);
  1137. font-family: DM Sans;
  1138. font-size: 36rpx;
  1139. font-weight: 500;
  1140. line-height: 23px;
  1141. letter-spacing: 0px;
  1142. text-align: center;
  1143. padding-bottom: 20rpx;
  1144. border-bottom: 1rpx solid rgba(219, 218, 218, 1);
  1145. }
  1146. .setting-item {
  1147. display: flex;
  1148. align-items: center;
  1149. justify-content: space-between;
  1150. padding: 12rpx 32rpx;
  1151. margin-bottom: 30rpx;
  1152. border: 1px solid rgba(227, 231, 236, 1);
  1153. border-radius: 6px;
  1154. &:active {
  1155. background-color: #F8F8F8;
  1156. }
  1157. &.setting-item-first {
  1158. border: none;
  1159. padding: 40rpx 32rpx;
  1160. }
  1161. .setting-left {
  1162. display: flex;
  1163. flex-direction: column;
  1164. align-items: flex-start;
  1165. flex: 1;
  1166. .setting-title-row {
  1167. display: flex;
  1168. align-items: center;
  1169. justify-content: flex-start;
  1170. width: 100%;
  1171. margin-bottom: 16rpx;
  1172. .setting-label {
  1173. color: rgba(21, 22, 26, 1);
  1174. font-family: DM Sans;
  1175. font-size: 32rpx;
  1176. font-weight: 600;
  1177. line-height: 26px;
  1178. letter-spacing: 0%;
  1179. text-align: left;
  1180. margin-right: 16rpx;
  1181. }
  1182. .setting-desc {
  1183. color: rgba(153, 153, 153, 1);
  1184. font-family: DM Sans;
  1185. font-size: 22rpx;
  1186. font-weight: 400;
  1187. line-height: 13px;
  1188. letter-spacing: 0%;
  1189. text-align: left;
  1190. }
  1191. }
  1192. .switch-status {
  1193. font-size: 32rpx;
  1194. &.status-on {
  1195. color: #007AFF;
  1196. }
  1197. &.status-off {
  1198. color: #999999;
  1199. }
  1200. }
  1201. }
  1202. .setting-right {
  1203. display: flex;
  1204. align-items: center;
  1205. justify-content: flex-end;
  1206. .u-switch {
  1207. margin-top: 20rpx;
  1208. transform: scale(1.2); // 放大开关到1.5倍
  1209. }
  1210. .setting-desc {
  1211. color: rgba(153, 153, 153, 1);
  1212. font-family: DM Sans;
  1213. font-size: 22rpx;
  1214. font-weight: 400;
  1215. line-height: 13px;
  1216. letter-spacing: 0%;
  1217. text-align: left;
  1218. margin-right: 16rpx;
  1219. }
  1220. }
  1221. }
  1222. }
  1223. </style>