| | |
| | | <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"> |
| | | <!-- <tinymce v-model="state.noticeForm.noticeContent"></tinymce>--> |
| | | <editor ref="myQuillEditor" v-model="state.noticeForm.noticeContent" :height="300"></editor> |
| | | |
| | | <el-form-item label="公告内容:" v-if="showEditor" prop="noticeContent"> |
| | | <we-editor ref="myEditor" :propData="state.noticeForm.noticeContent" @childFn="getEditorData" /> |
| | | </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 v-html="state.noticeForm.noticeContent" @click="showFile($event)"></div> |
| | | </div> |
| | | </div> |
| | | </el-form-item> |
| | |
| | | </template> |
| | | <script setup> |
| | | import {reactive, ref, toRefs} from 'vue' |
| | | import WeEditor from "@/components/WeEditor/index.vue"; |
| | | import Editor from "@/components/Editor/index.vue"; |
| | | import {ElMessage} from "element-plus"; |
| | | import {addNotice, editNotice, getNoticeDetail} from "@/api/backManage/notice"; |
| | | import axios from "axios"; |
| | | import {getToken} from "@/utils/auth"; |
| | | |
| | | |
| | | |
| | | |
| | | 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' }], |
| | |
| | | |
| | | const openDialog = async (type, value) => { |
| | | isReview.value = false; |
| | | showEditor.value = false |
| | | title.value = type === 'add' ? '新增' : type ==='edit' ? '编辑' : '查看' ; |
| | | if(type === 'edit' || type === 'review') { |
| | | const param = { |
| | |
| | | }else{ |
| | | ElMessage.warning(res.message) |
| | | } |
| | | |
| | | } |
| | | if(type === 'review') { |
| | | showEditor.value = false |
| | | isReview.value = true; |
| | | } |
| | | if(type === 'edit' || type === 'add') { |
| | | showEditor.value = true; |
| | | isReview.value = false; |
| | | } |
| | | if(type === 'add'){ |
| | | reset() |
| | | state.noticeForm.noticeContent = " "; |
| | | state.noticeForm.noticeTitle = " "; |
| | | } |
| | | 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('获取文件失败') |
| | | } |
| | | this.handleClose(); |
| | | }) |
| | | } |
| | | } |
| | | const onSubmit = async () => { |
| | | myEditor.value.submit(); |
| | | const valid = await noticeRef.value.validate(); |
| | | if(valid){ |
| | | if(state.noticeForm.noticeContent === "<p><br></p>"){ |
| | | ElMessage({ |
| | | type: 'warning', |
| | | message: '请输入公告内容' |
| | | }); |
| | | return; |
| | | } |
| | | if(title.value === '新增'){ |
| | | const param = { |
| | | content: state.noticeForm.noticeContent, |
| | |
| | | } |
| | | emit("getList") |
| | | reset(); |
| | | // myEditor.value.clear(); |
| | | noticeRef.value.clearValidate(); |
| | | dialogVisible.value = false; |
| | | }else if(title.value === '编辑') { |
| | | const nowDate = new Date() |
| | | const param = { |
| | | id: state.noticeForm.id, |
| | | content: state.noticeForm.noticeContent, |
| | |
| | | } |
| | | emit("getList") |
| | | reset(); |
| | | // myEditor.value.clear(); |
| | | noticeRef.value.clearValidate(); |
| | | dialogVisible.value = false; |
| | | } |
| | |
| | | } |
| | | |
| | | const handleClose = () => { |
| | | if(title ==="新增"|| title ==='编辑'){ |
| | | myEditor.value.clear(); |
| | | showEditor.value=false |
| | | } |
| | | |
| | | noticeRef.value.clearValidate(); |
| | | dialogVisible.value = false; |
| | | } |
| | |
| | | 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 |