class.ts 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import { reactive, computed } from 'vue';
  2. export enum type {
  3. violationAlarm = 1,
  4. platformStatistics = 2,
  5. personnelStatistics = 3,
  6. }
  7. export enum StatisticType {
  8. none = 0,
  9. week = 1,
  10. month = 2,
  11. year = 4,
  12. custom = 5,
  13. }
  14. export interface finalReportMessage {
  15. type: number;
  16. statisticType: StatisticType;
  17. dayOfWeek: number
  18. monthList: [string];
  19. dayOfMonthList: [string];
  20. pushTimeList: [string];
  21. pushChannel: [];
  22. userGroupList: [];
  23. designatedUserList: [];
  24. customUserList: [];
  25. recipientType: number;
  26. customPushConfigList: finalCustom[];
  27. }
  28. export interface reportMessage {
  29. type: number;
  30. statisticType: StatisticType;
  31. dayOfWeek: number
  32. monthList: [string];
  33. monthAndDayList?: [string, string] | any,
  34. dayOfMonthList: [string];
  35. pushTimeList: [string];
  36. pushChannel: [];
  37. userGroupList: any[];
  38. designatedUserList: any;
  39. customUserList: any;
  40. recipientType: number|undefined;
  41. customPushConfigList: computeCustom[]|any;
  42. }
  43. export interface finalCustom { // 最终返回给接口的自定义报告类
  44. customStartTime: string;
  45. customEndTime: string;
  46. customUserList: [];
  47. pushTime: string;
  48. recipientType: string;
  49. userGroupList: [];
  50. }
  51. export interface computeCustom { // 临时自定义报告类,daterange用于给customStartTime和customEndTime提供计算值,pushDay和pushTime用于给finalPushTime提供计算值
  52. daterange: null;
  53. customStartTime: any;
  54. customEndTime: any;
  55. pushDay: null;
  56. pushTime: null;
  57. finalPushTime: any;
  58. recipientType: string;
  59. userGroupList: [];
  60. customUserList: [];
  61. }
  62. interface UserList {
  63. id: string;
  64. userNickname: string;
  65. userId: number;
  66. }
  67. export const createCustomReport = () => {
  68. const newCustomReport = reactive<computeCustom>({
  69. daterange: null,
  70. customStartTime: computed(() => newCustomReport.daterange === null? null : newCustomReport.daterange[0]),
  71. customEndTime: computed(() => newCustomReport.daterange === null? null : newCustomReport.daterange[1]),
  72. pushDay: null,
  73. pushTime: null,
  74. finalPushTime: computed(() => {
  75. return (newCustomReport.pushDay === null) || (newCustomReport.pushTime === null)? null :newCustomReport.pushDay + ' ' + newCustomReport.pushTime;
  76. }),
  77. recipientType: '',
  78. userGroupList: [],
  79. customUserList: [],
  80. })
  81. return newCustomReport
  82. };
  83. export const toFinalCustom = (computeCustom: computeCustom) => {
  84. return reactive<finalCustom>({
  85. customStartTime: computeCustom.customStartTime,
  86. customEndTime: computeCustom.customEndTime,
  87. customUserList: computeCustom.customUserList,
  88. pushTime: computeCustom.finalPushTime,
  89. recipientType: computeCustom.recipientType,
  90. userGroupList: computeCustom.userGroupList,
  91. })
  92. };
  93. export const toReportMessage = (form: reportMessage, receivedData: finalReportMessage) => {
  94. form.type = receivedData.type
  95. form.statisticType = receivedData.statisticType
  96. form.dayOfWeek = receivedData.dayOfWeek
  97. form.monthList = receivedData.monthList
  98. form.dayOfMonthList = receivedData.dayOfMonthList
  99. form.pushTimeList = receivedData.pushTimeList
  100. form.pushChannel = receivedData.pushChannel
  101. form.userGroupList = receivedData.userGroupList?.map((user:any) => user.id)
  102. form.designatedUserList.value = receivedData.designatedUserList
  103. form.customUserList.value = receivedData.customUserList
  104. form.recipientType = receivedData.recipientType
  105. form.customPushConfigList = []
  106. if(form.customUserList.value.length > 0){
  107. form.customUserList.value = form.customUserList.value.map((user) => {
  108. return {"id": `u${user.userId}`, "name": user.userNickname, "userId": user.userId}
  109. })
  110. }
  111. if(form.designatedUserList.value.length > 0){
  112. form.designatedUserList.value = form.designatedUserList.value.map((user) => {
  113. return {"id": `u${user.userId}`, "name": user.userNickname, "userId": user.userId}
  114. })
  115. }
  116. if(receivedData.statisticType === 2){
  117. // form.dayOfMonthList[0] = receivedData.dayOfMonthList[0].toString()
  118. form.dayOfMonthList.push(receivedData.dayOfMonthList[0].toString())
  119. // form.dayOfMonthList.splice(0, form.dayOfMonthList.length);
  120. // form.dayOfMonthList.push(receivedData.dayOfMonthList[0])
  121. }
  122. if(receivedData.statisticType === 4){
  123. form.monthAndDayList.length = 0
  124. form.monthAndDayList?.push(receivedData.monthList[0].toString())
  125. form.monthAndDayList?.push(receivedData.dayOfMonthList[0].toString())
  126. }
  127. if(receivedData.statisticType === 5){
  128. let tempconfig = {}
  129. let customPushConfigList: any[] = []
  130. for (let config of receivedData.customPushConfigList) {
  131. tempconfig['daterange'] = [config.customStartTime.split(" ")[0], config.customEndTime.split(" ")[0]]
  132. const customStartTime = computed(() => tempconfig['daterange'][0])
  133. const customEndTime = computed(() => tempconfig['daterange'][1])
  134. let _ = customStartTime.value
  135. let __ = customEndTime.value
  136. // console.log("customStartTime", customStartTime.value); // 不使customStartTime.value用会报错,离谱,后续再研究
  137. // console.log("customEndTime", customEndTime.value);
  138. // tempconfig['customEndTime'] = tempconfig['daterange'][1]
  139. tempconfig['customStartTime'] = customStartTime
  140. tempconfig['customEndTime'] = customEndTime
  141. tempconfig['pushDay'] = config.pushTime.split(" ")[0]
  142. tempconfig['pushTime'] = config.pushTime.split(" ")[1]
  143. tempconfig['recipientType'] = config.recipientType.toString()
  144. tempconfig['userGroupList'] = config.userGroupList
  145. tempconfig['pushTime'] = config.pushTime.split(" ")[1]
  146. tempconfig['customUserList'] = config.customUserList.map((user:UserList) => {
  147. return {"id": `u${user.userId}`, "name": user.userNickname, "userId": user.userId}
  148. })
  149. tempconfig['userGroupList'] = config.userGroupList?.map((user:any) => user.id)
  150. customPushConfigList.push(tempconfig)
  151. tempconfig = {}
  152. }
  153. for (let index in customPushConfigList){
  154. const finalPushTime = computed(() => customPushConfigList[index]['pushDay'] + ' ' + customPushConfigList[index]['pushTime'])
  155. customPushConfigList[index]['finalPushTime'] = finalPushTime
  156. }
  157. form.customPushConfigList = customPushConfigList
  158. }
  159. };
  160. export const reportMessageToFinal = (form) => { // 临时表单转为只存在后端需要字段的表单
  161. let tempCustom = {}
  162. let customPushConfigList: any[] = []
  163. if (form.customPushConfigList.length > 0){
  164. if (!form.customPushConfigList[0].daterange){ // 如果有值则表示用户填了自定义的表单
  165. return
  166. }
  167. else{
  168. for (let config of form.customPushConfigList) {
  169. console.log("form.customPushConfigList", config);
  170. for(let key in config){
  171. if (key === 'daterange' || key === 'pushDay' || key === 'pushTime') {
  172. continue
  173. }
  174. else if(key === 'finalPushTime'){
  175. tempCustom['pushTime'] = config[key]
  176. }
  177. else if(key === 'customUserList'){
  178. tempCustom['customUserList'] = config[key].map((user) => user.userId)
  179. }
  180. else{
  181. tempCustom[key] = config[key]
  182. }
  183. }
  184. customPushConfigList.push(tempCustom)
  185. tempCustom = {}
  186. }
  187. }
  188. }
  189. return {
  190. "type": form.type,
  191. "statisticType": form.statisticType,
  192. "dayOfWeek": form.dayOfWeek,
  193. "monthList": form.monthList,
  194. "dayOfMonthList": form.dayOfMonthList,
  195. "pushTimeList": form.pushTimeList,
  196. "pushChannel": form.pushChannel,
  197. "userGroupList": form.userGroupList?.map((userOrId) => userOrId.id? userOrId.id :userOrId), // 用户对象和id可能会同时存在列表中
  198. "recipientType": form.recipientType,
  199. "customPushConfigList": customPushConfigList,
  200. "designatedUserList": form.designatedUserList.value?.map((user) => user.userId), // 只取出id
  201. "customUserList": form.customUserList.value?.map((user) => user.userId)
  202. }
  203. };