index.vue 36 KB

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