123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <template>
- <a-modal v-model:visible="openAddModel" :title="title" ok-text="提交" cancel-text="取消" @ok="sumbitForm"
- @cancel="cancelModal" width="50%">
- <a-form :model="createForm" layout="vertical">
- <a-row gutter="20">
- <a-col span="24">
- <a-form-item required label="文章标题" name="title">
- <a-input v-model:value="createForm.title" placeholder="请输入文章标题" />
- </a-form-item>
- </a-col>
- <a-col span="24">
- <a-form-item required label="封面图">
- <upload-one upload_txt="上传封面图" @uploadSuccess="uploadSuccess" :success_image="success_img"
- images_length="1"></upload-one>
- </a-form-item>
- </a-col>
- <a-col span="24">
- <a-form-item label="上传文件">
- <a-switch v-model:checked="showUplaod"> </a-switch>
- <div v-if="showUplaod" style="margin-top: 10px;">
- <upload-file @uploadSuccess="uploadDocSuccess"></upload-file>
- <a-typography-paragraph v-if="createForm.doc_url" :copyable="{ text: imageprefix+createForm.doc_url}">
- {{imageprefix+createForm.doc_url}}
- </a-typography-paragraph>
- </div>
- </a-form-item>
- </a-col>
- <a-col span="24">
- <a-form-item required label="上级栏目" name="parent_id">
- <search-select placeholder="请选择上级栏目" :list="section_list" :select_value="addOtherForm.name"
- @searchData="sectionSearch" @getSelectValue="getSectionValue"
- :select_disabled="false"></search-select>
- </a-form-item>
- </a-col>
- <a-col span="24">
- <a-form-item required label="文章内容" name="content">
- <QuillEditor theme="snow" :options="options" toolbar="full"
- v-model:content="addOtherForm.content" @update:content="onEditorUpdate($event)"
- contentType="html" />
- </a-form-item>
- </a-col>
- <a-col span="24">
- <a-form-item required label="是否置顶" name="stick_top">
- <a-radio-group v-model:value="createForm.stick_top" button-style="solid">
- <a-radio-button :value="1">否</a-radio-button>
- <a-radio-button :value="2">是</a-radio-button>
- </a-radio-group>
- </a-form-item>
- </a-col>
- <a-col span="24">
- <a-form-item label="成为热门" name="hot">
- <a-radio-group v-model:value="createForm.hot" button-style="solid">
- <a-radio-button :value="1">普通</a-radio-button>
- <a-radio-button :value="2">热门推荐</a-radio-button>
- </a-radio-group>
- </a-form-item>
- </a-col>
- <a-col span="24">
- <a-form-item label="作者" name="author">
- <a-input v-model:value="createForm.author" placeholder="请输入作者" />
- </a-form-item>
- </a-col>
- </a-row>
- </a-form>
- </a-modal>
- </template>
-
- <script setup lang="ts">
- import { ref, onMounted, computed, defineProps, watch, defineEmits } from 'vue';
- import { addArticle, updateArticle, listSection } from '@/apis/models';
- import he from 'he';
- import { dataForm, otherDataForm, reset } from '@/views/information/section/add/data.ts';
- import { useCommon } from '@/hooks/useCommon';
- let { store, openAddModel, hideModal, message, richOption, imageprefix } = useCommon();
- const emit = defineEmits();
- let props = defineProps(['edit_record']);
- let title = ref<String>('新增文章');
- let selectDisabled = ref<Boolean>(false)
- let success_img = ref<String>('')
- const options = ref(richOption)
- let showUplaod = ref<Boolean>(false)
-
- let createForm = ref<InformationArticleType.addFormType>(dataForm)
- let addOtherForm = ref<InformationArticleType.addOtherFormType>(otherDataForm)
-
-
- onMounted(() => {
- sectionSearch({ page: 1, pagesize: 100 })
- })
-
- // 上传图片
- const uploadSuccess = (data : Object) => {
- success_img.value = imageprefix + data
- createForm.value.cover_img = data
- }
-
- // 上传文件
- const uploadDocSuccess = (data : Object) => {
- createForm.value.doc_url = data
- }
-
- // 选择栏目/频道
- let section_list = ref<Object[]>([])
- const sectionSearch = (val : Object) => {
- listSection(val).then((res : object) => {
- const data = res.data.sections.map((item : object) => ({
- label: item.name,
- value: item.id,
- }));
- section_list.value = data;
- })
- }
- const getSectionValue = (val : Object) => {
- createForm.value.parent_id = val.key;
- }
-
- // 富文本
- const onEditorUpdate = (data) => {
- createForm.value.content = data
- }
-
-
- const sumbitForm = () => {
- if (createForm.value.title && createForm.value.cover_img && createForm.value.section_id && createForm.value.content) {
- if (!createForm.value.id) {
- addArticle(createForm.value).then(res => {
- message.success('新增文章成功');
- hideModal();
- resetForm();
- emit('successAdd');
- }).catch(err => {
- })
- } else {
- updateArticle(createForm.value).then(res => {
- message.success('修改文章成功');
- hideModal();
- resetForm();
- emit('successAdd');
- }).catch(err => {
- })
- }
-
- } else {
- message.warning('请补充完整信息');
- }
- }
-
- const resetForm = () => {
- addOtherForm.value = reset().otherDataForm;
- createForm.value = reset().dataForm;
- }
- const cancelModal = () => {
- emit('closeAdd');
- resetForm();
- hideModal();
- }
-
-
- openAddModel = computed(() => {
- return store.state.openAddModel;
- })
-
- watch(() => props.edit_record, (newVal) => {
- if (newVal) {
- title.value = '编辑文章';
- addOtherForm.value = {
- name: newVal.section_id,
- content: he.decode(newVal.content)
- }
- success_img.value = imageprefix + newVal.cover_img;
-
- createForm.value = {
- id: newVal.id,
- title: newVal.title,
- cover_img: newVal.cover_img,
- section_id: newVal.section_id,
- content: newVal.content,
- author: newVal.author,
- stick_top:newVal.stick_top,
- hot: newVal.hot,
- }
- } else {
- title.value = '新增文章';
- }
- })
- </script>
-
- <style>
-
- </style>
|