ReportOperation.vue 9.2 KB

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