index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. <template>
  2. <page-meta root-font-size="system" />
  3. <view class="index_container">
  4. <uni-nav-bar dark :border="false" :fixed="true" :title="config.companyName">
  5. </uni-nav-bar>
  6. <!-- 待办消息列表 -->
  7. <uni-collapse :accordion="true">
  8. <uni-collapse-item title-border="show" :border="true" :show-animation="true"
  9. :open="unProcessNum > 0 || false">
  10. <template v-slot:title>
  11. <uni-section title="待办" type="line" titleFontSize="1.3rem">
  12. <template v-slot:right>
  13. <uni-badge :text="unProcessNum" class="unReadBadge" v-if="unProcessNum > 0"></uni-badge>
  14. </template>
  15. </uni-section>
  16. </template>
  17. <view class="process_container">
  18. <view class="process_list">
  19. <process-list ref="processListRef" @clickSegment="getProcessData"
  20. @clickItem="handleToProcessDetail" @scrollToBottom="getProcessPage" :current="0" :pSize="5"
  21. :pageNo="1" contentHeight="63.5vh"></process-list>
  22. </view>
  23. </view>
  24. </uni-collapse-item>
  25. <!-- 公告列表 -->
  26. <uni-collapse-item title-border="show" :border="true" :show-animation="true"
  27. :open="unReadMsgNum > 0 || false">
  28. <template v-slot:title>
  29. <uni-section title="公告" type="line" titleFontSize="1.3rem">
  30. </uni-section>
  31. </template>
  32. <view class="notice_list">
  33. <message-list @clickSegment="getNoticeData" @clickItem="handleToNoticeDetail"
  34. @scrollToBottom="getNoticePage" :pSize="5" :pageNo="1" :anime="true"
  35. :open="false"></message-list>
  36. </view>
  37. </uni-collapse-item>
  38. <!-- 消息列表 -->
  39. <uni-collapse-item title-border="show" :border="true" :show-animation="true"
  40. :open="unReadMsgNum > 0 || false">
  41. <template v-slot:title>
  42. <uni-section title="消息" type="line" titleFontSize="1.3rem">
  43. <template v-slot:right>
  44. <uni-badge :text="unReadMsgNum"
  45. v-if="unReadMsgNum !== undefined && unReadMsgNum > 0"></uni-badge>
  46. <button @click.stop="setAllMsgRead" class="read_button" v-if="unReadMsgNum !== undefined" :disabled="unReadMsgNum === 0">一键阅读</button>
  47. </template>
  48. </uni-section>
  49. </template>
  50. <view class="message_list">
  51. <message-list ref="msgListRef" @clickSegment="getMessageData" @clickItem="handleToMessageDetail"
  52. @scrollToBottom="getMessagePage" :defaultCurrent="1" :pSize="5" :pageNo="1"
  53. :segments="{ '全部': '', '未读': '0', '已读': '1' }"></message-list>
  54. </view>
  55. </uni-collapse-item>
  56. </uni-collapse>
  57. <!-- 跳转打卡页按钮 -->
  58. <view class="fab_button">
  59. <view class="toClockInBtn">
  60. <uni-fab :pattern="{ icon: 'map-pin-ellipse' }" :popMenu="false" horizontal="right"
  61. @fabClick="toClockInBtn"></uni-fab>
  62. </view>
  63. <!-- AI咨询按钮 -->
  64. <view class="toAiBtn">
  65. <uni-fab :pattern="{ buttonText: 'headphones' }" :popMenu="false" horizontal="right" @fabClick="clickFabButton"></uni-fab>
  66. </view>
  67. </view>
  68. </view>
  69. </template>
  70. <script setup lang="ts">
  71. import { onBeforeMount, onMounted, onUpdated, ref } from 'vue';
  72. import { onLoad, onShow } from '@dcloudio/uni-app'
  73. import { getMessageList, getNoticeList, getUnReadMessageNum, setMsgIsRead } from '@/api/message.js';
  74. import { getUserProcess, getUnProcessNum, getTacheInfo } from '@/api/process';
  75. import $tab from '@/plugins/tab.js';
  76. import $modal from '@/plugins/modal.js';
  77. import processList from '@/components/ygoa/processList.vue'
  78. import messageList from '@/components/ygoa/messageList.vue'
  79. import { useUserStore } from '@/store/user.js'
  80. import { getLoginInfo } from '@/utils/auth';
  81. import config from '@/config';
  82. const userStore = useUserStore()
  83. const processListRef = ref(null)
  84. onMounted(() => {
  85. uni.$on('showTabBarBadge', showTabBarBadge)
  86. uni.$on('ReloadProcessData', () => {
  87. new Promise((resolve, reject) => {
  88. processListRef.value.onClickItem()
  89. })
  90. })
  91. })
  92. onLoad((options) => {
  93. // 是否跳转打卡页
  94. if (options.to == 'clockIn'){
  95. toClockIn()
  96. }else if(options.noticeId){
  97. $tab.navigateTo('/pages/message/detail/index?noticeId=' + options.noticeId)
  98. }
  99. })
  100. onShow(() => {
  101. showTabBarBadge();
  102. })
  103. onBeforeMount(() => {
  104. uni.removeTabBarBadge({
  105. index: 0
  106. })
  107. })
  108. // 跳转打卡页
  109. function toClockIn() {
  110. // 确认是否跳转打卡页
  111. $modal.confirm('当前未打卡,是否前往打卡').then(() => {
  112. $tab.navigateTo('/pages/mine/clockIn/clockIn')
  113. }).catch(() => { })
  114. }
  115. //子组件
  116. const msgListRef = ref(null)
  117. // 获取待办消息列表数据
  118. function getProcessData({ pSize, pageNo }, callback) {
  119. const params = {
  120. staffId: userStore.user.useId,
  121. page: pageNo,
  122. pageNum: pSize,
  123. modelId: "",
  124. control: 1
  125. }
  126. getUserProcess(params).then(({ returnParams }) => {
  127. callback(returnParams.list, returnParams.total, pageNo)
  128. });
  129. }
  130. // 分页获取待办消息列表数据
  131. function getProcessPage({ pSize, pageNo }, callback) {
  132. const params = {
  133. staffId: userStore.user.useId,
  134. page: pageNo,
  135. pageNum: pSize,
  136. modelId: "",
  137. control: 1
  138. }
  139. getUserProcess(params).then(({ returnParams }) => {
  140. callback(returnParams.list, returnParams.total, pageNo)
  141. });
  142. }
  143. // 点击待办消息列表项
  144. function handleToProcessDetail({ insId, tinsId, insName, control }) {
  145. $tab.navigateTo('/pages/process/detail/index?insId=' + insId + '&tinsId=' + tinsId + '&insName=' + insName + '&control=' + control)
  146. }
  147. // 获取公告列表数据
  148. function getNoticeData({ pSize, pageNo }, callback) {
  149. const params = {
  150. notice_title: "",
  151. p: pageNo,
  152. pSize,
  153. userId: userStore.user.useId,
  154. unitId: userStore.user.unitId,
  155. }
  156. getNoticeList(params).then(({ returnParams }) => {
  157. // 通知子组件加载完成
  158. callback(returnParams.noticelist.list, returnParams.total, pageNo)
  159. })
  160. }
  161. // 分页获取公告数据
  162. function getNoticePage({ pSize, pageNo }, callback) {
  163. const params = {
  164. notice_title: "",
  165. p: pageNo,
  166. pSize,
  167. userId: userStore.user.useId,
  168. unitId: userStore.user.unitId,
  169. }
  170. getNoticeList(params).then(({ returnParams }) => {
  171. // 通知子组件加载完成
  172. callback(returnParams.noticelist.list, returnParams.total, pageNo)
  173. })
  174. }
  175. // 点击公告列表项
  176. function handleToNoticeDetail(notice) {
  177. $tab.navigateTo('/pages/message/detail/index?noticeId=' + notice.id)
  178. }
  179. // 消息列表
  180. // const messages = ref([])
  181. // 获取消息列表数据
  182. const msgPoint = ref(0)
  183. function getMessageData({ pSize, pageNo, type, segmentValue }, callback) {
  184. const flag = msgPoint.value = new Date().getTime()
  185. const params = {
  186. currentUser: userStore.user.useId,
  187. isRead: segmentValue,
  188. pSize: pSize,
  189. type: type,
  190. p: pageNo,
  191. }
  192. getMessageList(params).then(({ returnParams }) => {
  193. returnParams.list.forEach(item => {
  194. if ('(流程提醒)您有一个流程' == item.title.substring(0, 12)) {
  195. item.title = '(流程提醒)' + item.title.slice(12)
  196. }
  197. })
  198. // 通知子组件加载完成
  199. if (flag == msgPoint.value) {
  200. callback(returnParams.list, returnParams.total, pageNo)
  201. }
  202. })
  203. }
  204. // 分页获取消息数据
  205. function getMessagePage({ pSize, pageNo, type, segmentValue }, callback) {
  206. const params = {
  207. currentUser: userStore.user.useId,
  208. isRead: segmentValue,
  209. pSize: pSize,
  210. type: type,
  211. p: pageNo,
  212. }
  213. getMessageList(params).then(({ returnParams }) => {
  214. returnParams.list.forEach(item => {
  215. if ('(流程提醒)您有一个流程' == item.title.substring(0, 12)) {
  216. item.title = '(流程提醒)' + item.title.slice(12)
  217. }
  218. // return item
  219. })
  220. // 通知子组件加载完成
  221. callback(returnParams.list, returnParams.total, pageNo)
  222. })
  223. }
  224. //点击消息列表项
  225. function handleToMessageDetail({ messageid, universalid, jump_id, title }) {
  226. // 设置消息已读
  227. setMsgIsRead(universalid + ',').then((res) => {
  228. if (Number.isInteger(res)) {
  229. msgListRef.value.reload();//调用子组件刷新数据
  230. } else {
  231. $modal.confirm('登录状态失效,您可以继续留在该页面,或者重新登录?').then(res => {
  232. const loginInfo = getLoginInfo();
  233. userStore.LogOut().then(res => {
  234. uni.setStorageSync('loginInfo', loginInfo)
  235. $tab.reLaunch('/pages/login?type=autoLogin')
  236. })
  237. }).catch(() => { })
  238. }
  239. })
  240. debugger
  241. if(jump_id) {
  242. try {
  243. // 解析jump_id JSON字符串
  244. // const jumpInfo = JSON.parse(jump_id);
  245. const { modelId, insId, tinsId, opType, insName } = jump_id;
  246. if (opType === 'process') {
  247. getTacheInfo(tinsId).then(({returnParams}) => {
  248. if(returnParams.oldTacheStatus == 1) {
  249. //跳到流程办理页面
  250. $tab.navigateTo('/pages/process/detail/index?insId=' + insId + '&tinsId=' + tinsId + '&insName=' + insName + '&control=1')
  251. } else {
  252. //跳到流程到流程查看页面
  253. $tab.navigateTo('/pages/process/detail/index?insId=' + insId + '&insName=' + insName + '&control=0')
  254. }
  255. })
  256. } else if (opType === 'view') {
  257. //跳到流程到流程查看页面
  258. $tab.navigateTo('/pages/process/detail/index?insId=' + insId + '&insName=' + insName + '&control=0')
  259. } else {
  260. // 未知操作类型,跳转到消息详情页
  261. $tab.navigateTo('/pages/message/detail/index?messageId=' + messageid + '&universalId=' + universalid)
  262. }
  263. } catch (error) {
  264. console.error('jump_id解析失败:', error);
  265. // 解析失败,跳转到消息详情页
  266. $tab.navigateTo('/pages/message/detail/index?messageId=' + messageid + '&universalId=' + universalid)
  267. }
  268. } else {
  269. // jump_id为空,跳转到消息详情页
  270. $tab.navigateTo('/pages/message/detail/index?messageId=' + messageid + '&universalId=' + universalid)
  271. }
  272. }
  273. // AI咨询按钮
  274. function clickFabButton() {
  275. // console.log('clickFabButton');
  276. $tab.navigateTo('/pages/message/chat/index')
  277. }
  278. //跳转打卡页
  279. function toClockInBtn() {
  280. $tab.navigateTo('/pages/mine/clockIn/clockIn')
  281. }
  282. //待办流程数
  283. const unProcessNum = ref(0)
  284. //未读消息数
  285. const unReadMsgNum = ref(0)
  286. //待阅消息数+待办流程数(用于tarbar导航栏)
  287. const unReadNum = ref(0)
  288. function showTabBarBadge() {
  289. getUnProcessNum(userStore.user.useId, "").then(res => {
  290. if ("failed" == res.returnMsg) {
  291. $modal.showToast('待办流程数获取失败')
  292. return
  293. } else {
  294. unProcessNum.value = parseInt(res.returnParams?.total || 0, 10);
  295. }
  296. getUnReadMessageNum(userStore.user.useId).then(res => {
  297. unReadMsgNum.value = parseInt(res.returnParams ?? 0, 10);
  298. unReadNum.value = unReadMsgNum.value + unProcessNum.value;
  299. setThisTabBarBadge(0,unReadNum.value)
  300. setThisTabBarBadge(1,unProcessNum.value)
  301. })
  302. })
  303. }
  304. // 提取通用 badge 设置逻辑
  305. function setThisTabBarBadge(index, count) {
  306. if (count <= 0) {
  307. uni.removeTabBarBadge({ index });
  308. } else {
  309. uni.setTabBarBadge({
  310. index,
  311. text: count > 99 ? "99+" : String(count)
  312. });
  313. }
  314. }
  315. // 设置所有消息已读
  316. function setAllMsgRead() {
  317. $modal.confirm('是否全部已读').then(res => {
  318. if (res) {
  319. const params = {
  320. currentUser: userStore.user.useId,
  321. isRead: "0",
  322. pSize: unReadMsgNum.value,
  323. type: "",
  324. p: 1,
  325. }
  326. getMessageList(params).then(({ returnParams }) => {
  327. const unReadMsgIds = returnParams.ids === "" ? "" : returnParams.ids + ",";
  328. setMsgIsRead(unReadMsgIds).then((res) => {
  329. if (Number.isInteger(res)) {
  330. switch (res) {
  331. case -1:
  332. $modal.msgError('操作失败')
  333. break
  334. case -2:
  335. case 0:
  336. $modal.msg('不存在未读消息')
  337. msgListRef.value.reload();// 调用子组件刷新数据
  338. showTabBarBadge()
  339. break
  340. default:
  341. $modal.msgSuccess('操作成功')
  342. //刷新页面
  343. msgListRef.value.reload();// 调用子组件刷新数据
  344. showTabBarBadge()
  345. }
  346. } else {
  347. $modal.confirm('登录状态失效,您可以继续留在该页面,或者重新登录?').then(res => {
  348. userStore.LogOut().then(res => {
  349. uni.reLaunch({ url: '/pages/login?type=autoLogin' })
  350. })
  351. }).catch(() => { })
  352. }
  353. })
  354. })
  355. }
  356. }).catch(() => { })
  357. }
  358. </script>
  359. <style lang="scss" scoped>
  360. // @import "@/static/font/ygoa/iconfont.css";
  361. ::v-deep .uni-badge {
  362. height: calc(1.5rem + 0px) !important;
  363. min-width: calc(1.5rem + 0px) !important;
  364. line-height: calc(1.375rem + 0px) !important;
  365. font-size: calc(1.125rem + 0px) !important;
  366. }
  367. ::v-deep .process_container {
  368. .process_list {
  369. .process_contant {
  370. font-size: calc(14px + .5*(1rem - 16px));
  371. }
  372. .flow_step_section {
  373. .uni-section .uni-section-header {
  374. padding: 5px 10px;
  375. }
  376. }
  377. .flow_step_container {
  378. min-height: 60px;
  379. margin: 10px 15px;
  380. .u-steps {
  381. .u-steps-item {
  382. padding-bottom: 11px;
  383. .u-text__value--content {
  384. font-size: calc(13px + .5*(1rem - 16px)) !important;
  385. }
  386. .u-text__value--main {
  387. font-size: calc(13px + .5*(1rem - 16px)) !important;
  388. font-weight: 500 !important;
  389. }
  390. .u-text__value--tips {
  391. font-size: calc(12px + .5*(1rem - 16px)) !important;
  392. }
  393. .redcontent {
  394. .u-text__value--content {
  395. color: #ff4500;
  396. }
  397. }
  398. .active_step_circle {
  399. width: 20px;
  400. height: 20px;
  401. box-sizing: border-box;
  402. flex-shrink: 0;
  403. border-radius: 100px;
  404. border-width: 1px;
  405. border-color: #A78BFA;
  406. background-color: #A78BFA;
  407. border-style: solid;
  408. display: flex;
  409. flex-direction: row;
  410. align-items: center;
  411. justify-content: center;
  412. transition: background-color .3s;
  413. .active_step_text {
  414. color: #fff;
  415. font-size: 11px;
  416. display: flex;
  417. flex-direction: row;
  418. align-items: center;
  419. justify-content: center;
  420. text-align: center;
  421. line-height: 11px;
  422. }
  423. }
  424. }
  425. .u-steps-item view:last-of-type {
  426. margin-top: 0 !important;
  427. }
  428. }
  429. }
  430. }
  431. }
  432. ::v-deep .notice_list {
  433. .msg_list_container {
  434. .zp-l-text-rpx {
  435. font-size: calc(30rpx + .5*(1rem - 16px));
  436. }
  437. }
  438. }
  439. .read_button {
  440. position: absolute;
  441. top: calc(12px + .5 * (1rem - 16px));
  442. right: 3.125rem;
  443. height: calc(1.75rem + 0px);
  444. line-height: 1.75rem;
  445. font-size: calc(0.875rem + 0px);
  446. background-color: #007aff;
  447. color: #fff;
  448. }
  449. .read_button[disabled] {
  450. background-color: #f5f5f5;
  451. color: #666;
  452. opacity: 0.5;
  453. }
  454. ::v-deep .message_list {
  455. .msg_list_container {
  456. .segmented_control_container {
  457. .segmented-control__text {
  458. font-size: calc(14px + .5*(1rem - 16px));
  459. }
  460. }
  461. .zp-paging-container-content {
  462. .zp-l-text-rpx {
  463. font-size: calc(30rpx + .5*(1rem - 16px));
  464. }
  465. }
  466. }
  467. }
  468. ::v-deep .fab_button {
  469. .toClockInBtn {
  470. .uni-fab__circle--rightBottom {
  471. bottom: 100px;
  472. }
  473. }
  474. .toAiBtn {
  475. uni-icons {
  476. text {
  477. font-family: 'ygoa_work_icon' !important;
  478. }
  479. text:before {
  480. content: "\e660" !important;
  481. }
  482. }
  483. }
  484. .uni-fab__circle {
  485. width: calc(55px + .5*(1rem - 16px)) !important;
  486. height: calc(55px + .5*(1rem - 16px)) !important;
  487. .uni-icons {
  488. font-size: calc(32px + .5*(1rem - 16px)) !important;
  489. }
  490. }
  491. }
  492. </style>