class.ts 8.0 KB

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