LiuJ 1 долоо хоног өмнө
parent
commit
0952014cb5

+ 22 - 23
src/views/news/addNotice.vue

@@ -23,8 +23,8 @@
             </el-radio-group>
             </el-radio-group>
           </el-form-item>
           </el-form-item>
           <el-form-item label="内容:" prop="content" class="custom-align-right">
           <el-form-item label="内容:" prop="content" class="custom-align-right">
-            <el-input v-model="form.content" maxlength="500" autocomplete="off" placeholder="请输入内容" type="textarea"
-              rows="10"></el-input>
+            <!--这里是富文本-->
+            <myEditor ref="myEditor" v-model="form.content"></myEditor>
           </el-form-item>
           </el-form-item>
           <el-form-item label="发布范围:" prop="city_arr_id" class="custom-align-right">
           <el-form-item label="发布范围:" prop="city_arr_id" class="custom-align-right">
             <el-cascader :key="cascaderKey" v-model="form.city_arr_id" placeholder="请选择发布范围" :props="cityData"
             <el-cascader :key="cascaderKey" v-model="form.city_arr_id" placeholder="请选择发布范围" :props="cityData"
@@ -57,9 +57,9 @@
                   </div>
                   </div>
                 </div>
                 </div>
               </el-upload>
               </el-upload>
-              <input type="hidden" v-model="form.imgurl">
+              <input type="hidden" v-model="form.file">
               <span class="photo_tips">支持文件形式pdf,word,jpg,文件最大2M。</span>
               <span class="photo_tips">支持文件形式pdf,word,jpg,文件最大2M。</span>
-              <div v-if="hovering && imgUrl" class="delete-button" @click="handleDelete">
+              <div v-if="hovering && form.file" class="delete-button" @click="handleDelete">
                 <i class="el-icon-delete"></i>
                 <i class="el-icon-delete"></i>
               </div>
               </div>
             </div>
             </div>
@@ -93,9 +93,11 @@ import tableTitle from './components/tableTitle';
 import '@/styles/global.less';
 import '@/styles/global.less';
 //格式化时间
 //格式化时间
 import { formatLocalDate } from '@/utils/public';
 import { formatLocalDate } from '@/utils/public';
-
+//引入富文本编辑器
+import myEditor from '../../components/edit/myEditor.vue';
 export default {
 export default {
   components: {
   components: {
+    myEditor,
     tableTitle
     tableTitle
   },
   },
   data() {
   data() {
@@ -138,10 +140,9 @@ export default {
       userType: 1, //用户类型 1:普通用户,
       userType: 1, //用户类型 1:普通用户,
       pickerOptions: {
       pickerOptions: {
         selectableRange: '1900-01-01 to 2100-12-31', // 允许选择的日期范围
         selectableRange: '1900-01-01 to 2100-12-31', // 允许选择的日期范围
-        // disabledDate(time) {
-        //   return time.getTime() < Date.now() - 86400000; // 禁用今天之前的日期
-        // },
+
       },
       },
+      imgUrl: '', //图片地址
 
 
       //提交表单
       //提交表单
       form: {
       form: {
@@ -152,7 +153,6 @@ export default {
         city_arr_id: [],//行政区划
         city_arr_id: [],//行政区划
         city_id: '',//城市id
         city_id: '',//城市id
         content: "",
         content: "",
-        timelist: "",
         file: "",//文件路径
         file: "",//文件路径
         department_arr_id: [],//部门id
         department_arr_id: [],//部门id
         department_id: '',//部门id
         department_id: '',//部门id
@@ -231,7 +231,6 @@ export default {
         }
         }
       },
       },
 
 
-      imgurl: [],
       //获取父级导航池
       //获取父级导航池
       parentKey: 0,//获取父级导航
       parentKey: 0,//获取父级导航
       parentData: {
       parentData: {
@@ -339,10 +338,7 @@ export default {
       const isPdf = file.type === 'application/pdf' || file.type === 'application/x-pdf' || file.type === 'application/acrobat' || file.type === 'pdf' || file.type === 'text/x-pdf' || file.type === 'application/x-download' || file.type === 'application/octet-stream';
       const isPdf = file.type === 'application/pdf' || file.type === 'application/x-pdf' || file.type === 'application/acrobat' || file.type === 'pdf' || file.type === 'text/x-pdf' || file.type === 'application/x-download' || file.type === 'application/octet-stream';
       const isLt2M = file.size / 1024 / 1024 < 2;
       const isLt2M = file.size / 1024 / 1024 < 2;
       console.log(this.imgurl.length, '-0--------------------------------')
       console.log(this.imgurl.length, '-0--------------------------------')
-      if (this.imgurl.length > 4) {
-        this.$message.warning('只能上传5张图片');
-        return false;
-      }
+
 
 
       if (!isJPG && !isPNG && !isWord && !isPdf) {
       if (!isJPG && !isPNG && !isWord && !isPdf) {
         this.$message.error('上传文件只能是 JPG、PNG、WORD、PDF 格式!');
         this.$message.error('上传文件只能是 JPG、PNG、WORD、PDF 格式!');
@@ -384,7 +380,6 @@ export default {
           if (this.form.city_arr_id.length == 0) {
           if (this.form.city_arr_id.length == 0) {
             this.form.city_id = 0;
             this.form.city_id = 0;
           }
           }
-          console.log(typeof this.form.city_arr_id, '---=-==-=')
           if (typeof this.form.city_arr_id == 'object') {
           if (typeof this.form.city_arr_id == 'object') {
             this.form.city_id = this.form.city_arr_id.at(-1) || 0;
             this.form.city_id = this.form.city_arr_id.at(-1) || 0;
             this.form.city_arr_id = JSON.stringify(this.form.city_arr_id);
             this.form.city_arr_id = JSON.stringify(this.form.city_arr_id);
@@ -393,8 +388,6 @@ export default {
             this.form.department_id = this.form.department_arr_id.at(-1) || 0;
             this.form.department_id = this.form.department_arr_id.at(-1) || 0;
             this.form.department_arr_id = JSON.stringify(this.form.department_arr_id);
             this.form.department_arr_id = JSON.stringify(this.form.department_arr_id);
           }
           }
-          console.log(typeof this.form.time, '---=-==-=')
-          console.log(this.form.time.length, '---=-==-=')
           if (typeof this.form.time == 'object' && this.form.time.length > 0) {
           if (typeof this.form.time == 'object' && this.form.time.length > 0) {
             this.form.start = this.formatDate(this.form.time[0]);
             this.form.start = this.formatDate(this.form.time[0]);
             this.form.end = this.formatDate(this.form.time[1]);
             this.form.end = this.formatDate(this.form.time[1]);
@@ -404,7 +397,6 @@ export default {
           delete this.form.timelist;
           delete this.form.timelist;
           delete this.form.catid;
           delete this.form.catid;
           this.form.file = this.file;
           this.form.file = this.file;
-          console.log(this.form, 'this.form-----------------')
           if (this.userType == 10000) {
           if (this.userType == 10000) {
             this.form.status = 2
             this.form.status = 2
           } else {
           } else {
@@ -479,7 +471,10 @@ export default {
         this.form.city_id = res.data.city_id;
         this.form.city_id = res.data.city_id;
         this.form.department_id = res.data.department_id;
         this.form.department_id = res.data.department_id;
         this.form.cat_id = res.data.cat_id;
         this.form.cat_id = res.data.cat_id;
-        this.form.time = [res.data.start, res.data.end];
+        // res.data.start 可能null,变成''
+        if (res.data.start != null && res.data.end != null) {
+          this.form.time = [res.data.start, res.data.end];
+        }
         this.form.file = res.data.file;
         this.form.file = res.data.file;
         this.file = res.data.file;
         this.file = res.data.file;
         const filePath = res.data.file;
         const filePath = res.data.file;
@@ -538,7 +533,7 @@ export default {
           if (this.form.city_arr_id.length == 0) {
           if (this.form.city_arr_id.length == 0) {
             this.form.city_id = 0;
             this.form.city_id = 0;
           }
           }
-          console.log(typeof this.form.city_arr_id, '---=-==-=')
+          console.log(this.form, '---=-==-=')
           if (typeof this.form.city_arr_id == 'object') {
           if (typeof this.form.city_arr_id == 'object') {
             this.form.city_id = this.form.city_arr_id.at(-1) || 0;
             this.form.city_id = this.form.city_arr_id.at(-1) || 0;
             this.form.city_arr_id = JSON.stringify(this.form.city_arr_id);
             this.form.city_arr_id = JSON.stringify(this.form.city_arr_id);
@@ -548,7 +543,7 @@ export default {
             this.form.department_arr_id = JSON.stringify(this.form.department_arr_id);
             this.form.department_arr_id = JSON.stringify(this.form.department_arr_id);
           }
           }
           console.log(typeof this.form.time, '---=-==-=')
           console.log(typeof this.form.time, '---=-==-=')
-          if (typeof this.form.time == 'object' && this.form.time.length > 0) {
+          if (typeof this.form.time == 'object' && this.form.time.length > 0 && this.form.time[0] != '' && this.form.time[1] != '') {
             this.form.start = this.formatDate(this.form.time[0]);
             this.form.start = this.formatDate(this.form.time[0]);
             this.form.end = this.formatDate(this.form.time[1]);
             this.form.end = this.formatDate(this.form.time[1]);
             delete this.form.time;
             delete this.form.time;
@@ -557,8 +552,6 @@ export default {
           delete this.form.timelist;
           delete this.form.timelist;
           delete this.form.catid;
           delete this.form.catid;
           this.form.file = this.file;
           this.form.file = this.file;
-          console.log(this.form, 'this.form-----------------')
-
           if (this.userType == 10000) {
           if (this.userType == 10000) {
             this.form.status = 2
             this.form.status = 2
           } else {
           } else {
@@ -583,10 +576,16 @@ export default {
               type: 'info',
               type: 'info',
               message: '网络错误,请重试!'
               message: '网络错误,请重试!'
             });
             });
+            this.getMainData();
           })
           })
         }
         }
       })
       })
     },
     },
+    handleDelete() {
+      // 删除图片
+      this.file = ''; // 清空图片 URL
+      this.form.file = ''; // 清空表单中的图片 URL
+    },
     //跳转操作 end ------------------------------------------------------------>
     //跳转操作 end ------------------------------------------------------------>
     //4.富文本编辑器 start ------------------------------------------------------------>
     //4.富文本编辑器 start ------------------------------------------------------------>
     //4.1 编辑器点击上传图片
     //4.1 编辑器点击上传图片