index.vue 9.3 KB

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