useSysMessage.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. import { ref, reactive } from 'vue';
  2. import { defHttp } from '/@/utils/http/axios';
  3. import { getDictItemsByCode } from '/@/utils/dict/index';
  4. import { useRouter, useRoute } from 'vue-router';
  5. import { useAppStore } from '/@/store/modules/app';
  6. import { useTabs } from '/@/hooks/web/useTabs';
  7. import { useModal } from '/@/components/Modal';
  8. import { useMessage } from '/@/hooks/web/useMessage';
  9. /**
  10. * 列表接口
  11. * @param params
  12. */
  13. const queryMessageList = (params) => {
  14. const url = '/sys/annountCement/vue3List';
  15. return defHttp.get({ url, params });
  16. };
  17. /**
  18. * 获取消息列表数据
  19. */
  20. export function useSysMessage() {
  21. const { createMessage } = useMessage();
  22. const rangeDateArray = getDictItemsByCode('rangeDate');
  23. console.log('+++++++++++++++++++++');
  24. console.log('rangeDateArray', rangeDateArray);
  25. console.log('+++++++++++++++++++++');
  26. const messageList = ref<any[]>([]);
  27. const pageNo = ref(1);
  28. const pageSize = 10;
  29. const searchParams = reactive({
  30. fromUser: '',
  31. rangeDateKey: '',
  32. rangeDate: [],
  33. starFlag: '',
  34. });
  35. function getQueryParams() {
  36. const { fromUser, rangeDateKey, rangeDate, starFlag } = searchParams;
  37. const params = {
  38. fromUser,
  39. starFlag,
  40. rangeDateKey,
  41. beginDate: '',
  42. endDate: '',
  43. pageNo: pageNo.value,
  44. pageSize,
  45. };
  46. if (rangeDateKey == 'zdy') {
  47. params.beginDate = rangeDate[0] + ' 00:00:00';
  48. params.endDate = rangeDate[1] + ' 23:59:59';
  49. }
  50. return params;
  51. }
  52. // 数据是否加载完了
  53. const loadEndStatus = ref(false);
  54. //请求数据
  55. async function loadData() {
  56. if (loadEndStatus.value === true) {
  57. return;
  58. }
  59. const params = getQueryParams();
  60. const data = await queryMessageList(params);
  61. console.log('获取结果', data);
  62. if (!data || data.length <= 0) {
  63. loadEndStatus.value = true;
  64. return;
  65. }
  66. if (data.length < pageSize) {
  67. loadEndStatus.value = true;
  68. }
  69. pageNo.value = pageNo.value + 1;
  70. const temp: any[] = messageList.value;
  71. temp.push(...data);
  72. messageList.value = temp;
  73. }
  74. //重置
  75. function reset() {
  76. messageList.value = [];
  77. pageNo.value = 1;
  78. loadEndStatus.value = false;
  79. }
  80. //标星
  81. async function updateStarMessage(item) {
  82. const url = '/sys/sysAnnouncementSend/edit';
  83. let starFlag = '1';
  84. if (item.starFlag == starFlag) {
  85. starFlag = '0';
  86. }
  87. const params = {
  88. starFlag,
  89. id: item.sendId,
  90. };
  91. //update-begin-author:taoyan date:2023-3-6 for: QQYUN-4491【应用】一些小问题 4、标星不需要提示吧
  92. const data: any = await defHttp.put({ url, params }, { isTransformResponse: false });
  93. if (data.success === true) {
  94. } else {
  95. createMessage.warning(data.message);
  96. }
  97. //update-end-author:taoyan date:2023-3-6 for: QQYUN-4491【应用】一些小问题 4、标星不需要提示吧
  98. }
  99. const loadingMoreStatus = ref(false);
  100. async function onLoadMore() {
  101. loadingMoreStatus.value = true;
  102. await loadData();
  103. loadingMoreStatus.value = false;
  104. }
  105. function noRead(item) {
  106. if (item.readFlag === '1') {
  107. return false;
  108. }
  109. return true;
  110. }
  111. // 消息类型
  112. function getMsgCategory(item) {
  113. if (item.busType == 'email') {
  114. return '邮件提醒:';
  115. } else if (item.busType == 'bpm') {
  116. return '流程催办:';
  117. } else if (item.busType == 'bpm_cc') {
  118. return '流程抄送:';
  119. } else if (item.busType == 'bpm_task') {
  120. return '流程任务:';
  121. } else if (item.msgCategory == '2') {
  122. return '系统消息:';
  123. } else if (item.msgCategory == '1') {
  124. return '通知公告:';
  125. }
  126. return '';
  127. }
  128. return {
  129. messageList,
  130. reset,
  131. loadData,
  132. loadEndStatus,
  133. searchParams,
  134. updateStarMessage,
  135. onLoadMore,
  136. noRead,
  137. getMsgCategory,
  138. };
  139. }
  140. /**
  141. * 用于消息跳转
  142. */
  143. export function useMessageHref(emit, props) {
  144. const messageHrefArray: any[] = getDictItemsByCode('messageHref');
  145. const router = useRouter();
  146. const appStore = useAppStore();
  147. const rt = useRoute();
  148. const { close: closeTab, closeSameRoute } = useTabs();
  149. // const defaultPath = '/monitor/mynews';
  150. //const bpmPath = '/task/handle/'
  151. async function goPage(record, openModalFun?) {
  152. if (!record.busType || record.busType == 'msg_node') {
  153. if (!openModalFun) {
  154. // 从首页的消息通知跳转
  155. await goPageFromOuter(record);
  156. } else {
  157. // 从消息页面列表点击详情查看 直接打开modal
  158. openModalFun();
  159. }
  160. } else {
  161. await goPageWithBusType(record);
  162. }
  163. /* busId: "1562035005173587970"
  164. busType: "email"
  165. openPage: "modules/eoa/email/modals/EoaEmailInForm"
  166. openType: "component"*/
  167. }
  168. /**
  169. * 根据busType不同跳转不同页面
  170. * @param record
  171. */
  172. async function goPageWithBusType(record) {
  173. const { busType, busId, msgAbstract } = record;
  174. const temp = messageHrefArray.filter((item) => item.value === busType);
  175. if (!temp || temp.length == 0) {
  176. console.error('当前业务类型不识别', busType);
  177. return;
  178. }
  179. let path = temp[0].text;
  180. path = path.replace('{DETAIL_ID}', busId);
  181. //固定参数 detailId 用于查询表单数据
  182. const query: any = {
  183. detailId: busId,
  184. };
  185. // 额外参数处理
  186. if (msgAbstract) {
  187. try {
  188. const json = JSON.parse(msgAbstract);
  189. Object.keys(json).map((k) => {
  190. query[k] = json[k];
  191. });
  192. } catch (e) {
  193. console.error('msgAbstract参数不是JSON格式', msgAbstract);
  194. }
  195. }
  196. // 跳转路由
  197. appStore.setMessageHrefParams(query);
  198. if (rt.path.indexOf(path) >= 0) {
  199. await closeTab();
  200. await router.replace({ path: path, query: { time: new Date().getTime() } });
  201. } else {
  202. closeSameRoute(path);
  203. await router.push({ path: path });
  204. }
  205. }
  206. /**
  207. * 从首页的消息通知跳转消息列表打开modal
  208. * @param record
  209. */
  210. async function goPageFromOuter(record) {
  211. //没有定义业务类型 直接跳转我的消息页面
  212. emit('detail', record);
  213. }
  214. return {
  215. goPage,
  216. };
  217. }