| | |
| | | <el-dialog |
| | | v-model="dialogVisible" |
| | | :title="title" |
| | | width="50%" |
| | | width="800px" |
| | | :before-close="handleClose" |
| | | > |
| | | <el-form :model="state.noticeForm" size="default" ref="noticeRef" :rules="title === '新增' || title === '编辑' ? state.formRules : {}" label-width="110px" > |
| | |
| | | <el-input v-model.trim="state.noticeForm.noticeTitle" v-if="!isReview" ></el-input> |
| | | <span v-else>{{state.noticeForm.noticeTitle}}</span> |
| | | </el-form-item> |
| | | <div style="margin: 0 0 15px 30px" v-if="!isReview"> |
| | | <el-upload |
| | | v-model:file-list="fileList" |
| | | class="upload-demo" |
| | | action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15" |
| | | multiple |
| | | :on-preview="handlePreview" |
| | | :on-remove="handleRemove" |
| | | :before-remove="beforeRemove" |
| | | :limit="3" |
| | | > |
| | | <el-button type="primary">附件上传</el-button> |
| | | </el-upload> |
| | | </div> |
| | | <el-form-item v-else label="附件:" > |
| | | <div class="file"> |
| | | <el-link v-for="(item,index) in state.noticeForm.fileList" type="primary" :key="index" :underline="false"> |
| | | <i class="el-icon-paperclip" style="margin-right: 5px;color: #1e6abc"></i>{{item.fileName}} |
| | | </el-link> |
| | | </div> |
| | | </el-form-item> |
| | | <el-form-item v-if="!isReview" style="margin-left: -80px" prop="noticeContent"> |
| | | <editor ref="myQuillEditor" v-model="state.noticeForm.noticeContent" :height="300"></editor> |
| | | <el-form-item label="公告内容:" v-if="showEditor" required> |
| | | <!-- <we-editor ref="myEditor" :propData="state.noticeForm.noticeContent" @childFn="getEditorData" />--> |
| | | <t-editor style="width: 800px" ref="myEditor" :value="state.noticeForm.noticeContent" ></t-editor> |
| | | </el-form-item> |
| | | <el-form-item label="公告内容:" v-else> |
| | | <div class="ql-container ql-snow" style="height: 300px;width: 100%;margin-top: 10px;" > |
| | | <div class="ql-container ql-snow" style="height: 500px;width: 100%;margin-top: 10px;" > |
| | | <div class="ql-editor"> |
| | | <div v-html="state.noticeForm.noticeContent"></div> |
| | | <div class="reviewTable" v-html="state.noticeForm.noticeContent" @click="showFile($event)"></div> |
| | | </div> |
| | | </div> |
| | | </el-form-item> |
| | |
| | | <template #footer v-if="!isReview"> |
| | | <span class="dialog-footer"> |
| | | <el-button @click="handleClose" size="default">取 消</el-button> |
| | | <el-button type="primary" @click="onSubmit" size="default">确认发布</el-button> |
| | | <el-button type="primary" @click="onSubmit" size="default" v-preReClick>确认发布</el-button> |
| | | </span> |
| | | </template> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | <script setup> |
| | | import {reactive, ref, toRefs} from 'vue' |
| | | import Editor from "@/components/Editor/index.vue"; |
| | | import {nextTick, reactive, ref, toRefs, watch} from 'vue' |
| | | import WeEditor from "@/components/WeEditor/index.vue"; |
| | | import TEditor from "@/components/Tinymce/Tinymce.vue" |
| | | import {ElMessage} from "element-plus"; |
| | | import {addNotice, editNotice, getNoticeDetail} from "@/api/backManage/notice"; |
| | | import axios from "axios"; |
| | | import {getToken} from "@/utils/auth"; |
| | | import {handleThemeStyle} from "@/utils/theme"; |
| | | import useSettingsStore from "@/store/modules/settings"; |
| | | |
| | | |
| | | const emit = defineEmits(["getList"]); |
| | | |
| | | const dialogVisible = ref(false); |
| | | const title = ref(""); |
| | | const noticeRef = ref(); |
| | | const fileList = ref([]); |
| | | const myQuillEditor = ref(); |
| | | const myEditor = ref(); |
| | | const isReview = ref(false); |
| | | const showEditor = ref(true); |
| | | const state = reactive({ |
| | | noticeForm: { |
| | | id: '', |
| | | noticeTitle: '', |
| | | noticeContent: '', |
| | | fileList: [] |
| | | }, |
| | | formRules:{ |
| | | noticeTitle: [{ required: true, message: '请填写公告标题', trigger: 'blur' }], |
| | | noticeContent: [{ required: true, message: '请输入公告内容', trigger: 'change' }], |
| | | // noticeContent: [{ required: true, message: '请输入公告内容', trigger: 'blur' }], |
| | | }, |
| | | |
| | | }) |
| | | |
| | | const openDialog = (type, value) => { |
| | | const openDialog = async (type, value) => { |
| | | // state.noticeForm.noticeContent = "" |
| | | isReview.value = false; |
| | | showEditor.value = false |
| | | title.value = type === 'add' ? '新增' : type ==='edit' ? '编辑' : '查看' ; |
| | | if(type === 'edit') { |
| | | state.noticeForm = value; |
| | | if(type === 'edit' || type === 'review') { |
| | | const param = { |
| | | noticeId: value.id |
| | | } |
| | | const res = await getNoticeDetail(param); |
| | | if(res.code === 200){ |
| | | state.noticeForm.id = res.data.id |
| | | state.noticeForm.noticeTitle = res.data.title |
| | | state.noticeForm.noticeContent = res.data.content |
| | | }else{ |
| | | ElMessage.warning(res.message) |
| | | } |
| | | |
| | | } |
| | | if(type === 'review') { |
| | | showEditor.value = false |
| | | isReview.value = true; |
| | | state.noticeForm = value; |
| | | } |
| | | if(type === 'edit' || type === 'add') { |
| | | showEditor.value = true; |
| | | isReview.value = false; |
| | | } |
| | | if(type === 'add'){ |
| | | reset() |
| | | } |
| | | dialogVisible.value = true; |
| | | |
| | | } |
| | | const getEditorData = (val) =>{ |
| | | state.noticeForm.noticeContent = val; |
| | | } |
| | | |
| | | const showFile = (e) => { |
| | | if(e.target.nodeName === 'A'){ |
| | | console.log("e",e) |
| | | e.preventDefault(); |
| | | const file = { |
| | | fileUrl: e.target.href, |
| | | fileName: e.target.download |
| | | } |
| | | axios.get( file.fileUrl,{ |
| | | headers: |
| | | { |
| | | 'Content-Type': 'application/json', |
| | | 'Authorization':getToken(), |
| | | }, |
| | | responseType: 'blob' |
| | | } |
| | | ).then(res=>{ |
| | | if (res) { |
| | | const link = document.createElement('a') |
| | | let blob = new Blob([res.data],{type: res.data.type}) |
| | | link.style.display = "none"; |
| | | link.href = URL.createObjectURL(blob); // 创建URL |
| | | link.setAttribute("download", file.fileName); |
| | | document.body.appendChild(link); |
| | | link.click(); |
| | | document.body.removeChild(link); |
| | | } else { |
| | | this.$message.error('获取文件失败') |
| | | } |
| | | // handleClose(); |
| | | }) |
| | | } |
| | | } |
| | | |
| | | const onSubmit = async () => { |
| | | state.noticeForm.noticeContent = tinyMCE.activeEditor.getContent(); |
| | | console.log("点击提交") |
| | | console.log('data',state.noticeForm.noticeContent) |
| | | // // myEditor.value.submit(); |
| | | const valid = await noticeRef.value.validate(); |
| | | if(valid){ |
| | | if(state.noticeForm.noticeContent === "<p><br></p>"){ |
| | | |
| | | if(state.noticeForm.noticeContent == "") { |
| | | ElMessage({ |
| | | type: 'warning', |
| | | message: '请输入公告内容' |
| | | }); |
| | | return; |
| | | } |
| | | console.log('file, fileList',state.noticeForm.noticeContent); |
| | | noticeRef.value.clearValidate(); |
| | | reset(); |
| | | dialogVisible.value = false; |
| | | |
| | | if(title.value === '新增'){ |
| | | const param = { |
| | | content: state.noticeForm.noticeContent, |
| | | title: state.noticeForm.noticeTitle |
| | | } |
| | | const res = await addNotice(param) |
| | | if(res.code === 200){ |
| | | ElMessage({ |
| | | type: 'success', |
| | | message: '新增成功' |
| | | }); |
| | | }else{ |
| | | ElMessage.warning(res.message) |
| | | } |
| | | emit("getList") |
| | | reset(); |
| | | myEditor.value.clear(); |
| | | noticeRef.value.clearValidate(); |
| | | dialogVisible.value = false; |
| | | }else if(title.value === '编辑') { |
| | | const param = { |
| | | id: state.noticeForm.id, |
| | | content: state.noticeForm.noticeContent, |
| | | title: state.noticeForm.noticeTitle |
| | | } |
| | | const res = await editNotice(param) |
| | | if(res.code === 200){ |
| | | ElMessage({ |
| | | type: 'success', |
| | | message: '编辑成功' |
| | | }); |
| | | }else{ |
| | | ElMessage.warning(res.message) |
| | | } |
| | | emit("getList") |
| | | reset(); |
| | | myEditor.value.clear(); |
| | | noticeRef.value.clearValidate(); |
| | | dialogVisible.value = false; |
| | | } |
| | | } |
| | | } |
| | | |
| | | const handleClose = () => { |
| | | noticeRef.value.clearValidate(); |
| | | reset(); |
| | | dialogVisible.value = false; |
| | | if(title.value ==="新增"|| title.value ==='编辑'){ |
| | | myEditor.value.clear(); |
| | | showEditor.value=false |
| | | } |
| | | |
| | | // reset() |
| | | noticeRef.value.clearValidate(); |
| | | dialogVisible.value = false; |
| | | } |
| | | const reset = () => { |
| | | state.noticeForm = { |
| | | id: '', |
| | | noticeTitle: '', |
| | | noticeContent: '' |
| | | } |
| | | } |
| | | const handleRemove = (file, fileList) => { |
| | | console.log(file, fileList); |
| | | } |
| | | const handlePreview = (uploadFile) => { |
| | | console.log(uploadFile) |
| | | } |
| | | const beforeRemove = (file, fileList) => { |
| | | return this.$confirm(`确定移除 ${ file.name }?`); |
| | | } |
| | | |
| | | |
| | | defineExpose({ |
| | | openDialog |
| | |
| | | align-items: flex-start; |
| | | } |
| | | } |
| | | .reviewTable { |
| | | :deep(table){ |
| | | border: 1px solid #ccc; |
| | | text-align: center; |
| | | } |
| | | :deep(table td){ |
| | | border: 1px solid #ccc; |
| | | text-align: center; |
| | | padding: 0 5px; |
| | | } |
| | | :deep(table th){ |
| | | border: 1px solid #ccc; |
| | | } |
| | | } |
| | | |
| | | |
| | | </style> |