index.vue 35 KB

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