ReportOperation.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <div class="page">
  3. <div class="top">
  4. <div class="topLeft" @click="clickBack">
  5. <img src="./img/rollback.png" style="margin-right: 8px" /><span>返回</span>
  6. </div>
  7. <div class="topRight">
  8. <span>{{ OperationTypeNames[pageType] }}报表配置</span>
  9. </div>
  10. </div>
  11. <div class="content">
  12. <div class="left">
  13. <el-form
  14. ref="ruleFormRef"
  15. style="max-width: 1000px"
  16. :model="form"
  17. :rules="rules"
  18. label-width="auto"
  19. class="demo-ruleForm"
  20. :size="formSize"
  21. :label-position="labelPosition"
  22. >
  23. <el-form-item
  24. v-if="form.type === PushMessageTypeEnum.DESIGNEE_ACCESS_DATA"
  25. label="指定人员:"
  26. required
  27. prop="designatedUserList"
  28. style="width: 660px"
  29. :rules="{ required: true, message: '请选择人员', trigger: 'change' }"
  30. >
  31. <el-col :span="18">
  32. <DesignatedPersonSelection :form="form" :disableType="disableType" />
  33. </el-col>
  34. </el-form-item>
  35. <el-form-item label="报表周期:" prop="statisticType" required>
  36. <el-radio-group v-model="form.statisticType" :disabled="disableType.statisticTypeDisable">
  37. <StatisticOption
  38. v-for="option in ReportOptions"
  39. :key="option.value"
  40. :value="option.value"
  41. :tooltip-content="option.tooltipContent"
  42. :tooltip-placement="option.tooltipPlacement"
  43. :label="option.label"
  44. />
  45. </el-radio-group>
  46. </el-form-item>
  47. <component :is="currentComponent" :form="form" :disableType="disableType" />
  48. <div v-if="Number(form.statisticType) === StatisticTypeEnum.CUSTOM_REPORT" class="custom-report">
  49. <CustomReport
  50. ref="CustomReportComponent"
  51. :form="form"
  52. :disableType="disableType"
  53. :ruleFormRef="ruleFormRef"
  54. />
  55. </div>
  56. <el-form-item label="推送渠道:" prop="pushChannel" required>
  57. <el-checkbox-group v-model="form.pushChannel" :disabled="disableType.contentDisable">
  58. <el-col :span="2">
  59. <el-checkbox :value="1" name="channel"> 蓝信推送 </el-checkbox>
  60. </el-col>
  61. <el-col :span="2">
  62. <el-checkbox :value="2" name="channel"> 平台推送 </el-checkbox>
  63. </el-col>
  64. </el-checkbox-group>
  65. </el-form-item>
  66. <el-form-item label="操作人:" style="margin-left: 10px">
  67. <el-input style="width: 425px; margin-left: -10px" disabled :placeholder="operater" />
  68. </el-form-item>
  69. </el-form>
  70. <div class="two-btns">
  71. <el-button @click="clickBack">取消</el-button>
  72. <el-button type="primary" @click="submitForm(ruleFormRef)" :disabled="disableType.contentDisable">
  73. 确定
  74. </el-button>
  75. </div>
  76. </div>
  77. <div class="right">
  78. <TemplateExample :form="form" :disableType="disableType" />
  79. </div>
  80. </div>
  81. </div>
  82. </template>
  83. <script lang="ts" setup>
  84. import { reactive, ref, onBeforeMount, computed } from 'vue';
  85. import { useRoute, useRouter } from 'vue-router';
  86. import { storeToRefs } from 'pinia';
  87. import { ElMessage } from 'element-plus';
  88. import type { FormInstance, FormProps } from 'element-plus';
  89. import { debounce } from 'lodash-es';
  90. import { addMassage, searchMassage, editMassage } from '@/api/message/report-message';
  91. import { useUserStore } from '@/store/modules/user';
  92. import { useFormList } from './store/useFormList';
  93. import { reportMessage, toReportMessage, reportMessageToFinal } from './class';
  94. import {
  95. OperationTypeEnum,
  96. StatisticTypeEnum,
  97. OperationTypeNames,
  98. PushMessageTypeEnum,
  99. Default_Value,
  100. ReportOptions,
  101. } from '@/types/message/constant';
  102. import StatisticOption from './components/StatisticOption.vue';
  103. import DesignatedPersonSelection from './components/DesignatedPersonSelection.vue';
  104. import TemplateExample from './TemplateExample.vue';
  105. import WeekReport from './WeekReport.vue';
  106. import MonthReport from './MonthReport.vue';
  107. import YearReport from './YearReport.vue';
  108. import CustomReport from './CustomReport.vue';
  109. const labelPosition = ref<FormProps['labelPosition']>('left');
  110. const useUser = useUserStore();
  111. const FormList = useFormList();
  112. const { info } = storeToRefs(useUser);
  113. const { type } = storeToRefs(FormList);
  114. let operater = info.value.realname;
  115. let disableType = ref({ statisticTypeDisable: false, contentDisable: false }); // 控制是否可编辑
  116. const formSize = ref('default'); // 校验表单
  117. const ruleFormRef = ref();
  118. const route = useRoute();
  119. const router = useRouter();
  120. // 功能类型:1是新增,2是查询,3是编辑
  121. const pageType = ref<number>(route.query.operationType ? Number(route.query.operationType) : Default_Value);
  122. // 报表类型:1是违规报警,2是平台访问,3是指定人员访问
  123. const reportType = ref<number>(route.query.type ? Number(route.query.type) : Default_Value);
  124. // 统计时间段类型:1-周报 2-月报 3-季报 4-年报 5-自定义
  125. const statisticType = ref<number>(route.query.statisticType ? Number(route.query.statisticType) : Default_Value);
  126. let queryType = { type: reportType.value, statisticType: statisticType.value };
  127. const form = reactive<reportMessage>({
  128. configIdList: null,
  129. type: Default_Value,
  130. statisticType: Default_Value,
  131. monthAndDayList: ['1', '1'],
  132. dayOfWeek: 1,
  133. monthList: [''],
  134. dayOfMonthList: ['1'],
  135. pushTimeList: ['09:00:00'],
  136. pushChannel: [],
  137. userGroupList: [],
  138. designatedUserList: [],
  139. recipientType: undefined,
  140. customPushConfigList: [],
  141. customUserList: [],
  142. });
  143. // 根据报表周期展示不同组件
  144. const ComponentEnum = {
  145. [StatisticTypeEnum.WEEK_REPORT]: WeekReport,
  146. [StatisticTypeEnum.MONTH_REPORT]: MonthReport,
  147. [StatisticTypeEnum.YEAR_REPORT]: YearReport,
  148. };
  149. // 当前组件
  150. const currentComponent = computed(() => ComponentEnum[form.statisticType]);
  151. form.customUserList.value = []; // 防止进入页面开始就显示校验错误
  152. form.designatedUserList = [];
  153. const rules = reactive({
  154. statisticType: [{ required: true, message: '请选择统计时间段', trigger: 'change, blur' }],
  155. pushChannel: [{ required: true, message: '请选择推送渠道', trigger: 'change' }],
  156. dayOfWeek: [{ required: true, message: '请选择推送日期', trigger: 'change' }],
  157. dayOfMonthList: [{ required: true, message: '请选择推送日', trigger: 'change' }],
  158. recipientType: [{ required: true, message: '请选择推送对象', trigger: ['blur', 'change'] }],
  159. userGroupList: [{ required: true, message: '请选择推送分组', trigger: 'change' }],
  160. });
  161. const addDebounce = debounce((form) => {
  162. addMassage(form).then(() => {
  163. ElMessage.success('新增成功');
  164. clickBack();
  165. });
  166. }, 500);
  167. const editDebounce = debounce((form) => {
  168. editMassage(form).then(() => {
  169. ElMessage.success('修改成功');
  170. clickBack();
  171. });
  172. }, 500);
  173. const submitForm = async (formEl: FormInstance | undefined) => {
  174. if (!formEl) return;
  175. await formEl.validate((valid) => {
  176. if (valid) {
  177. let submitForm = reportMessageToFinal(form);
  178. if (pageType.value != OperationTypeEnum.EDIT) {
  179. addDebounce(submitForm);
  180. } else {
  181. editDebounce(submitForm);
  182. }
  183. }
  184. });
  185. };
  186. const clickBack = () => {
  187. type.value = reportType.value;
  188. router.back();
  189. };
  190. const getDisableType = (pageType) => {
  191. if (pageType === OperationTypeEnum.ADD) {
  192. // 新增
  193. disableType.value.statisticTypeDisable = false;
  194. disableType.value.contentDisable = false;
  195. } else if (pageType === OperationTypeEnum.SEARCH) {
  196. // 查询
  197. disableType.value.statisticTypeDisable = true;
  198. disableType.value.contentDisable = true;
  199. } else if (pageType === OperationTypeEnum.EDIT) {
  200. // 编辑
  201. disableType.value.statisticTypeDisable = true;
  202. disableType.value.contentDisable = false;
  203. }
  204. };
  205. onBeforeMount(() => {
  206. getDisableType(pageType.value);
  207. if (pageType.value === OperationTypeEnum.SEARCH || pageType.value === OperationTypeEnum.EDIT) {
  208. searchMassage(queryType).then((res) => {
  209. toReportMessage(form, res);
  210. return res;
  211. });
  212. }
  213. form.type = reportType.value;
  214. });
  215. </script>
  216. <style lang="scss" scoped>
  217. .page {
  218. height: calc(100vh - 64px - 18px);
  219. background-color: rgba(255, 255, 255, 1);
  220. .top {
  221. display: flex;
  222. padding: 16px 0 15px 20px;
  223. border-bottom: 1px solid #e9e9e9;
  224. .topLeft {
  225. display: flex;
  226. align-items: center;
  227. cursor: pointer;
  228. a {
  229. display: flex;
  230. align-items: center;
  231. }
  232. }
  233. .topRight {
  234. margin-left: 20px;
  235. }
  236. }
  237. .content {
  238. display: flex;
  239. height: calc(100vh - 130px);
  240. .left {
  241. display: flex;
  242. flex-direction: column;
  243. position: relative;
  244. padding: 20px 0 0 32px;
  245. width: 769px;
  246. border-right: 1px solid rgba(0, 0, 0, 0.06);
  247. overflow-y: auto;
  248. .custom-report {
  249. max-height: calc(100vh - 450px);
  250. overflow-y: auto;
  251. }
  252. .two-btns {
  253. position: absolute;
  254. right: 33px;
  255. bottom: 32px;
  256. }
  257. }
  258. .right {
  259. height: 299px;
  260. width: 363px;
  261. margin-left: 31px;
  262. margin-top: 20px;
  263. background: #ffffff;
  264. border-radius: 4px 4px 0px 0px;
  265. border: 1px solid #e9e9e9;
  266. }
  267. }
  268. }
  269. </style>