import { reactive, computed } from 'vue'; export enum type { violationAlarm = 1, platformStatistics = 2, personnelStatistics = 3, } export enum StatisticType { none = 0, week = 1, month = 2, year = 4, custom = 5, } export interface finalReportMessage { type: number; statisticType: StatisticType; dayOfWeek: number monthList: [string]; dayOfMonthList: [string]; pushTimeList: [string]; pushChannel: []; userGroupList: []; designatedUserList: []; customUserList: []; recipientType: number; customPushConfigList: finalCustom[]; } export interface reportMessage { type: number; statisticType: StatisticType; dayOfWeek: number monthList: [string]; monthAndDayList?: [string, string] | any, dayOfMonthList: [string]; pushTimeList: [string]; pushChannel: []; userGroupList: any[]; designatedUserList: any; customUserList: any; recipientType: number|undefined; customPushConfigList: computeCustom[]|any; } export interface finalCustom { // 最终返回给接口的自定义报告类 customStartTime: string; customEndTime: string; customUserList: []; pushTime: string; recipientType: string; userGroupList: []; } export interface computeCustom { // 临时自定义报告类,daterange用于给customStartTime和customEndTime提供计算值,pushDay和pushTime用于给finalPushTime提供计算值 daterange: null; customStartTime: any; customEndTime: any; pushDay: null; pushTime: null; finalPushTime: any; recipientType: string; userGroupList: []; customUserList: []; } interface UserList { id: string; userNickname: string; userId: number; } export const createCustomReport = () => { const newCustomReport = reactive({ daterange: null, customStartTime: computed(() => newCustomReport.daterange === null? null : newCustomReport.daterange[0]), customEndTime: computed(() => newCustomReport.daterange === null? null : newCustomReport.daterange[1]), pushDay: null, pushTime: null, finalPushTime: computed(() => { return (newCustomReport.pushDay === null) || (newCustomReport.pushTime === null)? null :newCustomReport.pushDay + ' ' + newCustomReport.pushTime; }), recipientType: '', userGroupList: [], customUserList: [], }) return newCustomReport }; export const toFinalCustom = (computeCustom: computeCustom) => { return reactive({ customStartTime: computeCustom.customStartTime, customEndTime: computeCustom.customEndTime, customUserList: computeCustom.customUserList, pushTime: computeCustom.finalPushTime, recipientType: computeCustom.recipientType, userGroupList: computeCustom.userGroupList, }) }; export const toReportMessage = (form: reportMessage, receivedData: finalReportMessage) => { form.type = receivedData.type form.statisticType = receivedData.statisticType form.dayOfWeek = receivedData.dayOfWeek form.monthList = receivedData.monthList form.dayOfMonthList = receivedData.dayOfMonthList form.pushTimeList = receivedData.pushTimeList form.pushChannel = receivedData.pushChannel form.userGroupList = receivedData.userGroupList?.map((user:any) => user.id) form.designatedUserList.value = receivedData.designatedUserList form.customUserList.value = receivedData.customUserList form.recipientType = receivedData.recipientType form.customPushConfigList = [] if(form.customUserList.value.length > 0){ form.customUserList.value = form.customUserList.value.map((user) => { return {"id": `u${user.userId}`, "name": user.userNickname, "userId": user.userId} }) } if(form.designatedUserList.value.length > 0){ form.designatedUserList.value = form.designatedUserList.value.map((user) => { return {"id": `u${user.userId}`, "name": user.userNickname, "userId": user.userId} }) } if(receivedData.statisticType === 2){ // form.dayOfMonthList[0] = receivedData.dayOfMonthList[0].toString() form.dayOfMonthList.push(receivedData.dayOfMonthList[0].toString()) // form.dayOfMonthList.splice(0, form.dayOfMonthList.length); // form.dayOfMonthList.push(receivedData.dayOfMonthList[0]) } if(receivedData.statisticType === 4){ form.monthAndDayList.length = 0 form.monthAndDayList?.push(receivedData.monthList[0].toString()) form.monthAndDayList?.push(receivedData.dayOfMonthList[0].toString()) } if(receivedData.statisticType === 5){ let tempconfig = {} let customPushConfigList: any[] = [] for (let config of receivedData.customPushConfigList) { tempconfig['daterange'] = [config.customStartTime.split(" ")[0], config.customEndTime.split(" ")[0]] const customStartTime = computed(() => tempconfig['daterange'][0]) const customEndTime = computed(() => tempconfig['daterange'][1]) let _ = customStartTime.value let __ = customEndTime.value // console.log("customStartTime", customStartTime.value); // 不使customStartTime.value用会报错,离谱,后续再研究 // console.log("customEndTime", customEndTime.value); // tempconfig['customEndTime'] = tempconfig['daterange'][1] tempconfig['customStartTime'] = customStartTime tempconfig['customEndTime'] = customEndTime tempconfig['pushDay'] = config.pushTime.split(" ")[0] tempconfig['pushTime'] = config.pushTime.split(" ")[1] tempconfig['recipientType'] = config.recipientType.toString() tempconfig['userGroupList'] = config.userGroupList tempconfig['pushTime'] = config.pushTime.split(" ")[1] tempconfig['customUserList'] = config.customUserList.map((user:UserList) => { return {"id": `u${user.userId}`, "name": user.userNickname, "userId": user.userId} }) tempconfig['userGroupList'] = config.userGroupList?.map((user:any) => user.id) customPushConfigList.push(tempconfig) tempconfig = {} } for (let index in customPushConfigList){ const finalPushTime = computed(() => customPushConfigList[index]['pushDay'] + ' ' + customPushConfigList[index]['pushTime']) customPushConfigList[index]['finalPushTime'] = finalPushTime } form.customPushConfigList = customPushConfigList } }; export const reportMessageToFinal = (form) => { // 临时表单转为只存在后端需要字段的表单 let tempCustom = {} let customPushConfigList: any[] = [] if (form.customPushConfigList.length > 0){ if (!form.customPushConfigList[0].daterange){ // 如果有值则表示用户填了自定义的表单 return } else{ for (let config of form.customPushConfigList) { console.log("form.customPushConfigList", config); for(let key in config){ if (key === 'daterange' || key === 'pushDay' || key === 'pushTime') { continue } else if(key === 'finalPushTime'){ tempCustom['pushTime'] = config[key] } else if(key === 'customUserList'){ tempCustom['customUserList'] = config[key].map((user) => user.userId) } else{ tempCustom[key] = config[key] } } customPushConfigList.push(tempCustom) tempCustom = {} } } } return { "type": form.type, "statisticType": form.statisticType, "dayOfWeek": form.dayOfWeek, "monthList": form.monthList, "dayOfMonthList": form.dayOfMonthList, "pushTimeList": form.pushTimeList, "pushChannel": form.pushChannel, "userGroupList": form.userGroupList?.map((userOrId) => userOrId.id? userOrId.id :userOrId), // 用户对象和id可能会同时存在列表中 "recipientType": form.recipientType, "customPushConfigList": customPushConfigList, "designatedUserList": form.designatedUserList.value?.map((user) => user.userId), // 只取出id "customUserList": form.customUserList.value?.map((user) => user.userId) } };