update.vue
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<script setup lang="ts" name="notification-update">
import FormContent from '@/views/operation/notification/components/form-content.vue';
import { onBeforeRouteLeave, useRoute, useRouter } from 'vue-router';
import { onMounted, ref } from 'vue';
import { pick } from 'lodash';
import useNotificationApi from '@/http/notification';
import { Message } from '@arco-design/web-vue';
import { AttributeData } from '@/types/global';
const router = useRouter();
const notifyKey = Number(useRoute().params?.id);
const { show, update } = useNotificationApi;
const formValue = ref<any>({});
const onSubmit = (value: AttributeData) =>
update(notifyKey, value).then(() => {
Message.success(`更新通知:${value.title}`);
router.replace({ name: 'operation-notification' });
});
onBeforeRouteLeave((to, from) => {
if (from.meta.from === to.name) {
to.meta.reload = false;
}
});
onMounted(() => {
show(notifyKey).then((res) => {
Object.assign(formValue.value, {
...pick(res, [
'title',
'type',
'cover',
'content',
'rich_content',
'publish_type',
'publish_to',
'link_type',
'link_id',
'link_name',
'is_alert',
]),
publish_count: res.items_count || 0,
publish_at: res.publish_type === 1 ? '' : res.publish_at,
});
});
});
</script>
<template>
<page-view has-bread has-card>
<form-content v-model="formValue" :submit="onSubmit" />
</page-view>
</template>
<style scoped lang="less"></style>