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