SysnotionConfig.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <div class="sysnotion-config">
  3. <div class="tophead">
  4. <div @click="rollback()"
  5. ><img src="@/views/message/reportmessage/img/rollback.png" />返回</div
  6. >
  7. <span v-if="!isDisabled">新建系统通知</span>
  8. <span v-else>查看系统通知</span>
  9. </div>
  10. <div class="content">
  11. <div class="left">
  12. <!-- 基本配置 -->
  13. <BasicInfo ref="basicInfoRef" :data-soure="ruleForm" :is-disabled="isDisabled" />
  14. <!-- 内容配置区域 -->
  15. <ContentConfig ref="contentConfigRef" :data-soure="ruleForm" :is-disabled="isDisabled" />
  16. <!-- 按钮区域 -->
  17. <div class="btns" v-if="!isDisabled">
  18. <div style="position: absolute; right: 0; bottom: 0">
  19. <el-button @click="onCancel">取消</el-button>
  20. <el-button @click="onSave">暂存</el-button>
  21. <el-button type="primary" @click="submitForm">确定</el-button>
  22. </div>
  23. </div>
  24. </div>
  25. <!-- 实时预览 -->
  26. <RightCard :rule-form="ruleForm" />
  27. </div>
  28. </div>
  29. </template>
  30. <script lang="ts" setup>
  31. import { useRoute, useRouter } from 'vue-router';
  32. import { ref, reactive, onMounted, computed } from 'vue';
  33. import { storeToRefs } from 'pinia';
  34. import { ElMessage } from 'element-plus';
  35. import { useUserStore } from '@/store/modules/user';
  36. import {
  37. addSystemMessage,
  38. confirmReportConfig,
  39. updateSystemMessage,
  40. viewSystemMessage,
  41. } from '@/api/message/sysnotion-config';
  42. import { RuleFormView, MessageTypeEnum, ContentTypeEnum, RuleFormAdd } from './type';
  43. import BasicInfo from './compontents/BasicInfo.vue';
  44. import ContentConfig from './compontents/ContentConfig.vue';
  45. import RightCard from './compontents/RightCard.vue';
  46. const isDisabled = ref<boolean>(false);
  47. const useUser = useUserStore();
  48. const { info } = storeToRefs(useUser);
  49. const basicInfoRef = ref<InstanceType<typeof BasicInfo>>();
  50. const contentConfigRef = ref<InstanceType<typeof ContentConfig>>();
  51. const ruleForm = reactive<RuleFormView>({
  52. messageType: MessageTypeEnum.BANNER,
  53. title: '',
  54. bannerUrl: '',
  55. pushChannel: [],
  56. expirationTime: '',
  57. recipientType: 1, // 全员
  58. userGroupList: [],
  59. customUserList: [],
  60. introduction: '',
  61. contentType: ContentTypeEnum.RICHTEXT,
  62. content: '',
  63. contentUrl: '',
  64. operator: info.value.nickname,
  65. });
  66. // 原始数据副本
  67. let originalData: RuleFormView = {
  68. ...ruleForm,
  69. };
  70. const router = useRouter();
  71. const rollback = () => {
  72. router.back();
  73. };
  74. const route = useRoute();
  75. const sysId = route.query.id;
  76. onMounted(() => {
  77. if (sysId) {
  78. isDisabled.value = true;
  79. viewSystemMessage(Number(sysId)).then((res) => {
  80. if (!res?.status) {
  81. isDisabled.value = false;
  82. }
  83. ruleForm.id = Number(sysId);
  84. ruleForm.title = res.title;
  85. ruleForm.introduction = res.introduction ? res.introduction : '';
  86. ruleForm.messageType = res.messageType;
  87. ruleForm.content = res.content ? res.content : ' ';
  88. ruleForm.pushChannel = res.pushChannel;
  89. ruleForm.recipientType = res.recipientType;
  90. if (res.recipientType === 2) {
  91. // 若选择分组
  92. ruleForm.userGroupList = res.userGroupList;
  93. } else if (res.recipientType === 3) {
  94. // 若选择自定义
  95. ruleForm.customUserList = res.customUserList;
  96. }
  97. });
  98. }
  99. });
  100. // 取消
  101. const onCancel = () => {
  102. // 比对数据
  103. const changes = compareData(ruleForm, originalData);
  104. console.log('Object.keys(changes): ', Object.keys(changes));
  105. // ElMessageBox.confirm(
  106. // '您对系统通知的额操作尚未保存,请问是否暂存?',
  107. // '提示',
  108. // {
  109. // confirmButtonText: '暂存',
  110. // cancelButtonText: '取消',
  111. // type: 'warning',
  112. // }
  113. // )
  114. // .then(() => {
  115. // ElMessage({
  116. // type: 'success',
  117. // message: '暂存成功',
  118. // })
  119. // })
  120. // .catch(() => {
  121. // ElMessage({
  122. // type: 'info',
  123. // message: '取消暂存',
  124. // })
  125. // })
  126. };
  127. // 暂存
  128. const onSave = async () => {
  129. // to save dada
  130. const baseInfoData = await basicInfoRef.value?.validate();
  131. const contentConfigData = contentConfigRef.value?.buildFormdata();
  132. console.log('baseInfoData', baseInfoData);
  133. console.log('contentConfigData', contentConfigData);
  134. const params: RuleFormAdd = {
  135. ...baseInfoData!,
  136. ...contentConfigData,
  137. };
  138. delete params.operator;
  139. if (!sysId) {
  140. addSystemMessage(params).then((res) => {
  141. if (res) {
  142. ruleForm.id = res;
  143. ElMessage({
  144. message: '暂存成功!',
  145. type: 'success',
  146. });
  147. }
  148. });
  149. } else {
  150. updateSystemMessage(params).then(() => {
  151. ElMessage({
  152. message: '编辑成功!',
  153. type: 'success',
  154. });
  155. });
  156. }
  157. };
  158. const submitForm = () => {
  159. if (!ruleForm.id) {
  160. ElMessage({
  161. message: '暂存后才能下发!',
  162. type: 'warning',
  163. });
  164. return;
  165. }
  166. confirmReportConfig(ruleForm.id).then(() => {
  167. ElMessage({
  168. message: '下发成功!',
  169. type: 'success',
  170. });
  171. router.back();
  172. });
  173. };
  174. // 比对方法
  175. const compareData = (newData: RuleFormView, oldData: RuleFormView) => {
  176. const diff: Partial<Omit<RuleFormView, 'content'>> = {};
  177. for (const key in newData) {
  178. if (newData[key as keyof RuleFormView] !== oldData[key as keyof RuleFormView]) {
  179. diff[key as keyof RuleFormView] = newData[key as keyof RuleFormView];
  180. }
  181. }
  182. return diff;
  183. };
  184. </script>
  185. <style lang="scss" scoped>
  186. .sysnotion-config {
  187. position: relative;
  188. height: calc(100vh - 64px - 18px);
  189. background-color: rgba(255, 255, 255, 1);
  190. box-sizing: border-box !important;
  191. .tophead {
  192. display: flex;
  193. gap: 20px;
  194. width: 100%;
  195. height: 50px;
  196. padding: 16px 0 14px 21px;
  197. border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  198. div {
  199. display: flex;
  200. align-items: center;
  201. font-weight: 400;
  202. font-size: 14px;
  203. color: #303133;
  204. line-height: 22px;
  205. cursor: pointer;
  206. img {
  207. margin-right: 4px;
  208. }
  209. }
  210. }
  211. .content {
  212. display: flex;
  213. width: 100%;
  214. height: calc(100vh - 64px - 18px - 50px);
  215. padding: 0 30px 0 0;
  216. .left {
  217. display: flex;
  218. flex-direction: column;
  219. flex: 1;
  220. position: relative;
  221. padding: 21px;
  222. border-right: 1px solid rgba(0, 0, 0, 0.06);
  223. overflow-y: auto;
  224. .el-form-outer {
  225. display: flex;
  226. flex-direction: column;
  227. gap: 32px;
  228. }
  229. .transprant {
  230. :deep(.el-form-item__label::before) {
  231. content: '**';
  232. opacity: 0;
  233. }
  234. }
  235. .btns {
  236. margin-top: 35px;
  237. flex: 1;
  238. width: 100%;
  239. position: relative;
  240. }
  241. }
  242. }
  243. }
  244. </style>