create.vue 1.22 KB
<script setup lang="ts" name="notification-create">
  import { ref } from 'vue';
  import FormContent from '@/views/operation/notification/components/form-content.vue';
  import { Message } from '@arco-design/web-vue';
  import { onBeforeRouteLeave, useRouter } from 'vue-router';
  import useNotificationApi from '@/http/notification';
  import { AttributeData } from '@/types/global';

  const { create } = useNotificationApi;

  const formValue = ref({
    title: '',
    type: 1,
    content: '',
    cover: '',
    publish_type: 1,
    publish_at: '',
    publish_to: [],
    publish_count: 0,
    link_type: 'none',
    link_id: 0,
    link_name: '',
    rich_content: '',
    is_alert: 0,
  }) as any;

  const router = useRouter();

  const onSubmit = (value: AttributeData) =>
    create(formValue.value).then(() => {
      Message.success(`添加通知:${value.title}`);
      router.replace({ name: 'operation-notification' });
    });

  onBeforeRouteLeave((to, from) => {
    if (from.meta.from === to.name) {
      to.meta.reload = false;
    }
  });
</script>

<template>
  <page-view has-bread has-card>
    <form-content v-model="formValue" :submit="onSubmit" />
  </page-view>
</template>

<style scoped lang="less"></style>