|
|
@ -1,5 +1,5 @@ |
|
|
|
<template> |
|
|
|
<el-form :model="form" label-width="auto" :rules="rules" ref="elFormRef" style="max-width: 600px"> |
|
|
|
<el-form :model="form" label-width="auto" :rules="rules" ref="elFormRef" style="max-width: 600px"> |
|
|
|
<el-form-item label="文章标题" prop="articleTitle"> |
|
|
|
<el-input v-model="form.articleTitle" /> |
|
|
|
</el-form-item> |
|
|
@ -49,7 +49,7 @@ |
|
|
|
</template> |
|
|
|
<script setup> |
|
|
|
import { reactive, ref } from 'vue' |
|
|
|
import {ElMessage, ElMessageBox, ElForm } from 'element-plus' |
|
|
|
import { ElMessage, ElMessageBox, ElForm } from 'element-plus' |
|
|
|
import { Delete, Plus } from '@element-plus/icons-vue' |
|
|
|
import { useArticleStore } from '@/stores/article' |
|
|
|
import { useUserStore } from '@/stores/user' |
|
|
@ -57,12 +57,12 @@ let elFormRef = ref() |
|
|
|
let optionIndex = ref(3) |
|
|
|
let buttonLoading = ref(false) |
|
|
|
// 切换投票开关 |
|
|
|
const clearVoteInfomation = () =>{ |
|
|
|
optionIndex.value = 3 |
|
|
|
form.voteTitle = ''; |
|
|
|
form.deadlineTime = ''; |
|
|
|
form.multiOption = false |
|
|
|
form.optionList = [] |
|
|
|
const clearVoteInfomation = () => { |
|
|
|
optionIndex.value = 3 |
|
|
|
form.voteTitle = ''; |
|
|
|
form.deadlineTime = ''; |
|
|
|
form.multiOption = false |
|
|
|
form.optionList = [] |
|
|
|
} |
|
|
|
const handleVoteToggle = (value) => { |
|
|
|
clearVoteInfomation() |
|
|
@ -96,7 +96,7 @@ let form = reactive({ |
|
|
|
voteStatus: false, |
|
|
|
voteTitle: '', |
|
|
|
optionList: [], |
|
|
|
multiOption:false, |
|
|
|
multiOption: false, |
|
|
|
deadlineTime: '' |
|
|
|
}) |
|
|
|
const rules = reactive({ |
|
|
@ -144,21 +144,25 @@ const onSubmit = async () => { |
|
|
|
console.log('表单验证失败', error) |
|
|
|
} |
|
|
|
if (valid) { |
|
|
|
buttonLoading.value = true |
|
|
|
buttonLoading.value = true |
|
|
|
console.log('表单验证通过') |
|
|
|
try { |
|
|
|
form.userId = useUserStore().userId |
|
|
|
await useArticleStore().addArticle(form) |
|
|
|
ElMessage.success('发表成功!') |
|
|
|
form.articleTitle = '' |
|
|
|
form.articleContent = '' |
|
|
|
form.voteStatus = false |
|
|
|
clearVoteInfomation() |
|
|
|
let res = await useArticleStore().addArticle(form) |
|
|
|
if (res.status == 200) { |
|
|
|
ElMessage.success('发表成功!') |
|
|
|
form.articleTitle = '' |
|
|
|
form.articleContent = '' |
|
|
|
form.voteStatus = false |
|
|
|
clearVoteInfomation() |
|
|
|
} else { |
|
|
|
ElMessage.error('发布失败,请重试!') |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
ElMessage.error('发布失败,请重试!') |
|
|
|
console.log( error) |
|
|
|
} finally{ |
|
|
|
buttonLoading.value = false |
|
|
|
ElMessage.error('发布失败,请重试!') |
|
|
|
console.log(error) |
|
|
|
} finally { |
|
|
|
buttonLoading.value = false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|