|
|
@@ -32,7 +32,7 @@
|
|
|
import { useRoute, useRouter } from 'vue-router';
|
|
|
import { ref, reactive, onMounted } from 'vue';
|
|
|
import { storeToRefs } from 'pinia';
|
|
|
- import { ElMessage } from 'element-plus';
|
|
|
+ import { ElMessage, ElMessageBox } from 'element-plus';
|
|
|
import { useUserStore } from '@/store/modules/user';
|
|
|
import {
|
|
|
addSystemMessage,
|
|
|
@@ -45,7 +45,7 @@
|
|
|
import ContentConfig from './compontents/ContentConfig.vue';
|
|
|
import RightCard from './compontents/RightCard.vue';
|
|
|
|
|
|
- const isDisabled = ref<boolean>(false);
|
|
|
+ const isDisabled = ref<boolean>(false); // 是可编辑还是只查看状态
|
|
|
const useUser = useUserStore();
|
|
|
const { info } = storeToRefs(useUser);
|
|
|
const basicInfoRef = ref<InstanceType<typeof BasicInfo>>();
|
|
|
@@ -56,7 +56,7 @@
|
|
|
bannerUrl: '',
|
|
|
pushChannel: [],
|
|
|
expirationTime: '',
|
|
|
- recipientType: 1, // 全员
|
|
|
+ recipientType: 1, // 默认全员 (FIXME:魔法数字)
|
|
|
userGroupList: [],
|
|
|
customUserList: [],
|
|
|
introduction: '',
|
|
|
@@ -68,9 +68,9 @@
|
|
|
});
|
|
|
|
|
|
// 原始数据副本
|
|
|
- let originalData: RuleFormView = {
|
|
|
- ...ruleForm,
|
|
|
- };
|
|
|
+ // let originalData: RuleFormView = {
|
|
|
+ // ...ruleForm,
|
|
|
+ // };
|
|
|
|
|
|
const router = useRouter();
|
|
|
const rollback = () => {
|
|
|
@@ -79,7 +79,12 @@
|
|
|
const route = useRoute();
|
|
|
const sysId = Number(route.query.id as string);
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取当前系统配置信息
|
|
|
+ */
|
|
|
const fetchSystemMessage = async () => {
|
|
|
+ // 首次暂存后切换到编辑模式,因为路由没有发生变化,组件也不会发生变化,
|
|
|
+ // sysId会一直为undefined,但此时 ruleForm.id 是存在的
|
|
|
const messageId = sysId || ruleForm.id
|
|
|
|
|
|
// 查看 或 编辑状态
|
|
|
@@ -87,6 +92,7 @@
|
|
|
isDisabled.value = true;
|
|
|
const res = await viewSystemMessage(messageId);
|
|
|
if (res.status === SysMessageStatus.DRAFT) {
|
|
|
+ // 如果未发布,还是可以编辑的
|
|
|
isDisabled.value = false;
|
|
|
}
|
|
|
|
|
|
@@ -94,63 +100,60 @@
|
|
|
Object.entries(res).forEach(([key, value]) => {
|
|
|
ruleForm[key] = value;
|
|
|
});
|
|
|
-
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-
|
|
|
- // 取消
|
|
|
+ /**
|
|
|
+ * 取消按钮
|
|
|
+ */
|
|
|
const onCancel = () => {
|
|
|
- // 比对数据
|
|
|
- const changes = compareData(ruleForm, originalData);
|
|
|
- console.log('Object.keys(changes): ', Object.keys(changes));
|
|
|
-
|
|
|
- // ElMessageBox.confirm(
|
|
|
- // '您对系统通知的额操作尚未保存,请问是否暂存?',
|
|
|
- // '提示',
|
|
|
- // {
|
|
|
- // confirmButtonText: '暂存',
|
|
|
- // cancelButtonText: '取消',
|
|
|
- // type: 'warning',
|
|
|
- // }
|
|
|
- // )
|
|
|
- // .then(() => {
|
|
|
- // ElMessage({
|
|
|
- // type: 'success',
|
|
|
- // message: '暂存成功',
|
|
|
- // })
|
|
|
- // })
|
|
|
- // .catch(() => {
|
|
|
- // ElMessage({
|
|
|
- // type: 'info',
|
|
|
- // message: '取消暂存',
|
|
|
- // })
|
|
|
- // })
|
|
|
+ // TODO:比对数据。 暂时不上
|
|
|
+ // const changes = compareData(ruleForm, originalData);
|
|
|
+ // console.log('Object.keys(changes): ', Object.keys(changes));
|
|
|
+
|
|
|
+ ElMessageBox.confirm(
|
|
|
+ '你填写的数据若未及时保存,离开页面后将会丢失',
|
|
|
+ '提示',
|
|
|
+ {
|
|
|
+ confirmButtonText: '确认取消',
|
|
|
+ cancelButtonText: '继续留在页面',
|
|
|
+ type: 'warning',
|
|
|
+ }
|
|
|
+ )
|
|
|
+ .then(() => {
|
|
|
+ router.push('/message/systemNotifications');
|
|
|
+ })
|
|
|
+ .catch(() => {})
|
|
|
};
|
|
|
|
|
|
|
|
|
- // 暂存
|
|
|
+ /**
|
|
|
+ * 暂存功能。 未正式发布之前,可继续编辑
|
|
|
+ */
|
|
|
const onSave = async () => {
|
|
|
- // to save dada
|
|
|
+ // 基础配置信息。
|
|
|
+ // FIXME: validate 返回了数据,不符合单一原则
|
|
|
const baseInfoData = await basicInfoRef.value?.validate();
|
|
|
+ // 内容配置信息。
|
|
|
const contentConfigData = contentConfigRef.value?.buildFormdata();
|
|
|
|
|
|
const params: RuleFormAdd = {
|
|
|
...baseInfoData!,
|
|
|
...contentConfigData,
|
|
|
};
|
|
|
+ // 请求体,不需要 operator 和 status
|
|
|
delete params.operator;
|
|
|
delete params.status;
|
|
|
|
|
|
const messageId = sysId || ruleForm.id;
|
|
|
|
|
|
- if (!messageId) {
|
|
|
+ if (!messageId) { // 首次保存
|
|
|
ruleForm.id = await addSystemMessage(params);
|
|
|
ElMessage.success('暂存成功!');
|
|
|
await router.replace(`/message/sysnotion-config?id=${ruleForm.id}`)
|
|
|
fetchSystemMessage();
|
|
|
|
|
|
- } else {
|
|
|
+ } else { // 继续编辑
|
|
|
await updateSystemMessage(params)
|
|
|
ElMessage.success('编辑成功!');
|
|
|
}
|