|
|
@@ -0,0 +1,105 @@
|
|
|
+<template>
|
|
|
+ <tab-side-component>
|
|
|
+ <back-title>{{noticeId === 0 || isEmpty(noticeId) ? '新建' : '编辑' }}课程公告</back-title>
|
|
|
+ <div class="sub-title">公告标题</div>
|
|
|
+ <c-input v-model="title" placeholder="标题长度上限为 50 个字,请保持简短" :maxlength="50" class="mb-16"></c-input>
|
|
|
+ <div class="sub-title">公告内容</div>
|
|
|
+ <textarea v-model="content" placeholder="内容长度上限为 1000 字" :maxlength="1000" class="mb-16"></textarea>
|
|
|
+ <c-button theme="green" standout icon="check" @click="handleSubmit">确认提交</c-button>
|
|
|
+ <c-button v-if="noticeId !== 0 && !isEmpty(noticeId)" :left="8" theme="red" icon="close" @click="handleDelete">删除公告</c-button>
|
|
|
+ </tab-side-component>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import CButton from '@/components/Basic/CButton'
|
|
|
+import CInput from '@/components/Basic/CInput'
|
|
|
+import TabSideComponent from '@/components/Layouts/TabSideComponent'
|
|
|
+import BackTitle from '@/components/Basic/BackTitle'
|
|
|
+import { createNotice, deleteNotice, getNoticeByNoticeId, modifyNotice } from '@/server/notice'
|
|
|
+import { isEmpty } from '@/utils/types'
|
|
|
+
|
|
|
+export default {
|
|
|
+ components: { BackTitle, TabSideComponent, CInput, CButton },
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ noticeId: this.$route.params.noticeId,
|
|
|
+ courseId: this.$route.params.courseId,
|
|
|
+ title: '',
|
|
|
+ content: ''
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mounted () {
|
|
|
+ if (this.noticeId !== 0) {
|
|
|
+ getNoticeByNoticeId({ noticeId: this.noticeId }).then(res => {
|
|
|
+ console.log(res)
|
|
|
+ this.title = res.title
|
|
|
+ this.content = res.content
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ isEmpty,
|
|
|
+ handleSubmit () {
|
|
|
+ // noticeId 为 0 表示notice不存在,处理逻辑按新建处理
|
|
|
+ if (this.noticeId === 0 || isEmpty(this.noticeId)) {
|
|
|
+ createNotice({ courseId: this.courseId, title: this.title, content: this.content }).then(res => {
|
|
|
+ this.$setSuccessMessage('新建公告成功')
|
|
|
+ this.$router.go(-1)
|
|
|
+ }).catch(err => {
|
|
|
+ this.$setErrorMessage(err.response.data.msg)
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ modifyNotice({ id: this.noticeId, title: this.title, content: this.content }).then(res => {
|
|
|
+ this.$setSuccessMessage('修改公告内容成功')
|
|
|
+ this.$router.go(-1)
|
|
|
+ }).catch(err => {
|
|
|
+ this.$setErrorMessage(err.response.data.msg)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ handleDelete () {
|
|
|
+ const msg = '确定删除该公告吗?'
|
|
|
+ if (confirm(msg)) {
|
|
|
+ deleteNotice({ noticeId: this.noticeId }).then(() => {
|
|
|
+ this.$setSuccessMessage('删除成功')
|
|
|
+ this.$router.go(-1)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+@import '~@/style/theme.scss';
|
|
|
+
|
|
|
+textarea {
|
|
|
+ box-sizing: border-box;
|
|
|
+ font-size: 16px;
|
|
|
+ font-weight: bold;
|
|
|
+ color: #3a4a5a;
|
|
|
+ background: $input-background-color;
|
|
|
+ border-radius: 8px;
|
|
|
+ border: none;
|
|
|
+ outline: none;
|
|
|
+ width: 100%;
|
|
|
+ min-height: 260px;
|
|
|
+ height: 100%;
|
|
|
+ line-height: 1.5;
|
|
|
+ padding: 0 12px 0 12px;
|
|
|
+ transition: .2s;
|
|
|
+
|
|
|
+ &:hover {
|
|
|
+ background: $input-hover-background-color;
|
|
|
+ }
|
|
|
+
|
|
|
+ &::placeholder {
|
|
|
+ color: #8a9aaa;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+textarea {
|
|
|
+ padding: 6px 12px;
|
|
|
+ resize: none;
|
|
|
+}
|
|
|
+</style>
|