SysnotionConfig.vue 6.5 KB

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