Blame view

antis-ncc-admin/src/views/system/notice/Form.vue 3.03 KB
03207d5d   wwk   1
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
  <template>
    <transition name="el-zoom-in-center">
      <div class="NCC-preview-main">
        <div class="NCC-common-page-header">
          <el-page-header @back="goBack" :content="!dataForm.id ? '新建公告' : '编辑公告'" />
          <div class="options">
            <el-button type="primary" :loading="btnLoading" @click="dataFormSubmit()">
              {{$t('common.confirmButton')}}</el-button>
            <el-button @click="goBack()">{{$t('common.cancelButton')}}</el-button>
          </div>
        </div>
        <el-form ref="dataForm" :model="dataForm" :rules="dataRule" v-loading="formLoading"
          label-width="60px" class="main">
          <el-form-item label="标题" prop="title">
            <el-input v-model="dataForm.title" placeholder="公告标题" />
          </el-form-item>
          <el-form-item label="正文" prop="bodyText">
            <NCCQuill v-model="dataForm.bodyText" />
          </el-form-item>
        </el-form>
      </div>
    </transition>
  </template>
  
  <script>
  import NCCQuill from '@/components/NCCEditor/quill'
  import { createNotice, updateNotice, getNoticeInfo } from '@/api/system/message'
  
  export default {
    components: { NCCQuill },
    data() {
      return {
        visible: false,
        formLoading: false,
        btnLoading: false,
        dataForm: {
          id: '',
          title: '',
          bodyText: ''
        },
        dataRule: {
          title: [
            { required: true, message: '公告标题不能为空', trigger: 'blur' }
          ],
          bodyText: [
            { required: true, message: '公告内容不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      goBack() {
        this.$emit('close')
      },
      init(id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.formLoading = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            getNoticeInfo(this.dataForm.id).then(res => {
              this.dataForm = res.data
            })
          }
          this.formLoading = false
        })
      },
      dataFormSubmit() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.btnLoading = true
            const formMethod = this.dataForm.id ? updateNotice : createNotice
            formMethod(this.dataForm).then(res => {
              this.$message({
                message: res.msg,
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.btnLoading = false
                  this.$emit('refreshDataList')
                  this.goBack()
                }
              })
            }).catch(() => {
              this.btnLoading = false
            })
          }
        })
      }
    }
  }
  </script>
  <style lang="scss" scoped>
  .NCC-preview-main {
    .content {
      >>> {
        p {
          line-height: 30px;
          img {
            display: block;
            margin-right: auto;
            margin-left: auto;
          }
        }
      }
    }
    .vab-quill-content {
      >>> {
        .el-form-item__content {
          line-height: normal;
        }
      }
    }
  }
  </style>