index.vue 12 KB

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