Browse Source

文章发布模块的开发

xiaoming_global 5 years ago
parent
commit
672f4ae0f7
4 changed files with 187 additions and 35 deletions
  1. 2 2
      config/dev.env.js
  2. 9 0
      src/api/act/submitinfo.js
  3. 1 0
      src/api/qiniu.js
  4. 175 33
      src/scrm_pages/article/createArticle.vue

+ 2 - 2
config/dev.env.js View File

1
 module.exports = {
1
 module.exports = {
2
   NODE_ENV: '"development"',
2
   NODE_ENV: '"development"',
3
   ENV_CONFIG: '"dev"',
3
   ENV_CONFIG: '"dev"',
4
-  //BASE_API:'"http://api.test1.sgjyun.com"',//'"http://localhost:9534"'
5
-  BASE_API:'"http://localhost:9534"'
4
+  BASE_API:'"http://api.test1.sgjyun.com"',//'"http://localhost:9534"'
5
+  //BASE_API:'"http://localhost:9534"'
6
 
6
 
7
   SSO_HOST: '"http://testsso.sgjyun.com"',
7
   SSO_HOST: '"http://testsso.sgjyun.com"',
8
   SRCM_HOST: '"http://test1.sgjyun.com"',
8
   SRCM_HOST: '"http://test1.sgjyun.com"',

+ 9 - 0
src/api/act/submitinfo.js View File

7
         method: 'Get',
7
         method: 'Get',
8
         params: params
8
         params: params
9
     })
9
     })
10
+}
11
+
12
+export function getArticleType(params){
13
+     console.log("分类信息")
14
+     return request({
15
+         url:'/api/acticle/getArticleType',
16
+         method: 'Get',
17
+         params: params
18
+     })
10
 }
19
 }

+ 1 - 0
src/api/qiniu.js View File

1
 import request from '@/utils/request'
1
 import request from '@/utils/request'
2
 
2
 
3
 export function getToken() {
3
 export function getToken() {
4
+  console.log("加地址")
4
   return request({
5
   return request({
5
     url: '/api/qiniu/uptoken', // 假地址 自行替换
6
     url: '/api/qiniu/uptoken', // 假地址 自行替换
6
     method: 'get'
7
     method: 'get'

+ 175 - 33
src/scrm_pages/article/createArticle.vue View File

7
     <div class="app-container">
7
     <div class="app-container">
8
     <el-tabs type="border-card">
8
     <el-tabs type="border-card">
9
       <el-tab-pane label="文章">
9
       <el-tab-pane label="文章">
10
-        <el-form label-width="80px" class="clearfix" :model="form" ref="form" v-loading="formloading" :element-loading-text="loadingText">
10
+        <el-form label-width="80px" class="clearfix" :model="form" ref="form"  :element-loading-text="loadingText">
11
           <el-row>
11
           <el-row>
12
             <el-col :span="24">
12
             <el-col :span="24">
13
                 <el-form-item label="文章标题:">
13
                 <el-form-item label="文章标题:">
25
                   <el-radio v-model="radio" label="1" @click.native.prevent="select()" >单图</el-radio>
25
                   <el-radio v-model="radio" label="1" @click.native.prevent="select()" >单图</el-radio>
26
                   <el-radio v-model="radio" label="2" @click.native.prevent="clickitem()" >三图</el-radio>
26
                   <el-radio v-model="radio" label="2" @click.native.prevent="clickitem()" >三图</el-radio>
27
               </el-form-item>
27
               </el-form-item>
28
-              <el-form-item prop="org_logo">
28
+              <el-form-item prop="org_log">
29
                 <el-col :span="3">
29
                 <el-col :span="3">
30
                   <div>
30
                   <div>
31
                     <el-upload  
31
                     <el-upload  
45
                 </el-col>
45
                 </el-col>
46
                 <el-col :span="3">
46
                 <el-col :span="3">
47
                   <div v-if="show">
47
                   <div v-if="show">
48
-                    <el-upload 
49
-                     class="avatar-uploader" 
50
-                     :show-file-list="false" 
51
-                     :on-success="handleAvatarSuccess" 
52
-                     :before-upload="beforeAvatarUpload">
53
-                      <img v-if="imageUrl" :src="imageUrl" class="avatar">
48
+                    <el-upload  
49
+                      v-loading="guploading"
50
+                      :element-loading-text="loadingText"
51
+                      class="avatar-uploader"
52
+                      :data="uploadData"
53
+                      action="https://upload.qiniup.com"
54
+                      :show-file-list="false"
55
+                      :on-error="handleAvatartwoError"
56
+                      :on-success="handleAvatartwoSuccess"
57
+                      :before-upload="beforeAvatartwoUpload">
58
+                      <img v-if="imageUrlSecond" :src="imageUrlSecond" class="avatar">
59
+                      <i v-else class="el-icon-plus avatar-uploader-icon"></i>
60
+                    </el-upload>
61
+                  </div>
62
+                </el-col>
63
+                <el-col :span="3">
64
+                  <div v-if="show">
65
+                    <el-upload  
66
+                      v-loading="uploading"
67
+                      :element-loading-text="loadingText"
68
+                      class="avatar-uploader"
69
+                      :data="uploadData"
70
+                      action="https://upload.qiniup.com"
71
+                      :show-file-list="false"
72
+                      :on-error="handleAvatarlastError"
73
+                      :on-success="handleAvatarlastSuccess"
74
+                      :before-upload="beforeAvatarlastUpload">
75
+                      <img v-if="imageUrlLast" :src="imageUrlLast" class="avatar">
54
                       <i v-else class="el-icon-plus avatar-uploader-icon"></i>
76
                       <i v-else class="el-icon-plus avatar-uploader-icon"></i>
55
                     </el-upload>
77
                     </el-upload>
56
                   </div>
78
                   </div>
57
                 </el-col>
79
                 </el-col>
58
               </el-form-item>
80
               </el-form-item>
59
                <el-form-item label="所属分类:">
81
                <el-form-item label="所属分类:">
60
-                 <el-select v-model="value" placeholder="请先选择文章所属分类">
82
+                 <el-select v-model="value" placeholder="请先选择文章所属分类" prop="act_type">
61
                    <el-option
83
                    <el-option
62
                      v-for="item in options"
84
                      v-for="item in options"
63
-                     :key="item.value"
64
-                     :label="item.label"
65
-                     :value="item.value">
85
+                     :key="item.id"
86
+                     :label="item.Name"
87
+                     :value="item.id">
66
                    </el-option>
88
                    </el-option>
67
                  </el-select>
89
                  </el-select>
68
                </el-form-item>
90
                </el-form-item>
72
           <el-row :span="24">
94
           <el-row :span="24">
73
             <el-col :span="24">
95
             <el-col :span="24">
74
                 <el-form-item>
96
                 <el-form-item>
75
-                      <el-button size="small" type="primary" style="width: 100px"  @click="submitForm">发布</el-button>
97
+                      <el-button size="small" type="primary" style="width: 100px"  @click="submitForm" :disabled="formsubmit">发布</el-button>
76
                       <el-button size="small" style="width: 100px">预览</el-button>
98
                       <el-button size="small" style="width: 100px">预览</el-button>
77
                       <el-button size="small" style="width: 100px">保存草稿</el-button>
99
                       <el-button size="small" style="width: 100px">保存草稿</el-button>
78
                   <el-button size="small" style="width: 100px">取消</el-button>
100
                   <el-button size="small" style="width: 100px">取消</el-button>
90
                  <div class="video-select">
112
                  <div class="video-select">
91
                    <el-upload
113
                    <el-upload
92
                    class="upload-demo"
114
                    class="upload-demo"
93
-                   action="https://jsonplaceholder.typicode.com/posts/"
115
+                   action="https://upload.qiniup.com"
94
                    :on-preview="handlePreview"
116
                    :on-preview="handlePreview"
95
                    :on-remove="handleRemove"
117
                    :on-remove="handleRemove"
96
                    :before-remove="beforeRemove"
118
                    :before-remove="beforeRemove"
123
                    </el-upload>
145
                    </el-upload>
124
                  </el-form-item>
146
                  </el-form-item>
125
                   <el-form-item label="所属分类:">
147
                   <el-form-item label="所属分类:">
126
-                    <el-select v-model="value" placeholder="请选择">
148
+                    <el-select v-model="form.act_type" placeholder="请选择">
127
                       <el-option
149
                       <el-option
128
-                      v-for="item in options"
129
-                      :key="item.value"
130
-                      :label="item.label"
131
-                      :value="item.value">
150
+                         v-for="item in options"
151
+                         :key="item.value"
152
+                        :label="item.label"
153
+                         :value="item.value">
132
                       </el-option>
154
                       </el-option>
133
                       </el-select>
155
                       </el-select>
134
                   </el-form-item>
156
                   </el-form-item>
158
   import 'quill/dist/quill.snow.css'
180
   import 'quill/dist/quill.snow.css'
159
   import 'quill/dist/quill.bubble.css'
181
   import 'quill/dist/quill.bubble.css'
160
   import Neditor from '@/components/Neditor'
182
   import Neditor from '@/components/Neditor'
161
-  import {submitForm} from '@/api/act/submitinfo'
183
+  import {submitForm,getArticleType} from '@/api/act/submitinfo'
162
   import { getToken } from '@/api/qiniu'
184
   import { getToken } from '@/api/qiniu'
163
   import { getFileExtension} from '@/utils/tools'
185
   import { getFileExtension} from '@/utils/tools'
164
   export default {
186
   export default {
174
           { path: '/articles/createArticle', name: '发布文章' }
196
           { path: '/articles/createArticle', name: '发布文章' }
175
         ],
197
         ],
176
          radio:'1',
198
          radio:'1',
177
-        imageUrl: '',
178
-        options: [{
179
-          value: '选项1',
180
-          label: '科普教育'
181
-        }, {
182
-          value: '选项2',
183
-          label: '肾病常识'
184
-        }, {
185
-          value: '选项3',
186
-          label: '食物库'
187
-        }],
199
+        options: [],
188
         value: '',
200
         value: '',
189
         show:false,
201
         show:false,
190
         content: '',
202
         content: '',
201
           act_picture:'',
213
           act_picture:'',
202
           act_category:'',
214
           act_category:'',
203
           org_logo:'',
215
           org_logo:'',
216
+          act_type:'',
204
         },
217
         },
218
+         acttypes:[],
219
+         imageUrl:'',
220
+         imageUrlSecond:'',
221
+         imageUrlLast:'',
205
          formloading:false,
222
          formloading:false,
223
+         formsubmit:false,
206
          qiniuDomain: 'https://images.shengws.com/',
224
          qiniuDomain: 'https://images.shengws.com/',
207
          uploading:false,
225
          uploading:false,
208
          loadingText:'',
226
          loadingText:'',
209
          uploadData: { token: '', key: '' },
227
          uploadData: { token: '', key: '' },
228
+         myConfig: {
229
+                // 如果需要上传功能,找后端小伙伴要服务器接口地址
230
+                serverUrl: '/api/web/upload/ueditor',
231
+                // 你的UEditor资源存放的路径,相对于打包后的index.html
232
+                UEDITOR_HOME_URL: '/NEditor/',
233
+                // 编辑器不自动被内容撑高
234
+                autoHeightEnabled: false,
235
+                // 初始容器高度
236
+                initialFrameHeight: 240,
237
+                // 初始容器宽度
238
+                initialFrameWidth: '100%',
239
+                // 关闭自动保存
240
+                enableAutoSave: false
241
+            },
210
       }
242
       }
211
     },
243
     },
244
+    created(){
245
+        this.getArticleType()
246
+    },
212
     methods: {
247
     methods: {
248
+      //第一个图片
213
       handleAvatarSuccess(res, file) {
249
       handleAvatarSuccess(res, file) {
214
-        //this.imageUrl = URL.createObjectURL(file.raw);
250
+        this.imageUrl = URL.createObjectURL(file.raw);
215
         this.form.org_logo = this.qiniuDomain + res.url;
251
         this.form.org_logo = this.qiniuDomain + res.url;
252
+        this.uploading = false
216
       },
253
       },
217
        handleAvatarError(err, file, fileList) {
254
        handleAvatarError(err, file, fileList) {
218
             this.$message.error(err);
255
             this.$message.error(err);
240
             return new Promise((resolve, reject) => {
277
             return new Promise((resolve, reject) => {
241
                 getToken().then(response => {
278
                 getToken().then(response => {
242
                     const token = response.data.data.uptoken
279
                     const token = response.data.data.uptoken
280
+                    console.log("token是什么?",token)
243
                     _self._data.uploadData.token = token
281
                     _self._data.uploadData.token = token
244
                     _self._data.uploadData.key = key
282
                     _self._data.uploadData.key = key
245
                     resolve(true)
283
                     resolve(true)
251
         
289
         
252
           //return isJPG && isLt2M;
290
           //return isJPG && isLt2M;
253
       },
291
       },
292
+      //第二个图片
293
+      handleAvatartwoSuccess(res, file) {
294
+        this.imageUrlSecond = URL.createObjectURL(file.raw);
295
+        this.form.org_logo = this.qiniuDomain + res.url;
296
+        this.uploading = false
297
+      },
298
+       handleAvatartwoError(err, file, fileList) {
299
+            this.$message.error(err);
300
+            this.uploading = false;
301
+            return false
302
+      },
303
+      beforeAvatartwoUpload(file) {
304
+        const isJPG = file.type === 'image/jpeg';
305
+        const isLt2M = file.size / 1024 / 1024 < 2;
306
+
307
+        if (!isJPG) {
308
+          this.$message.error('上传头像图片只能是 JPG 格式!');
309
+        }
310
+        if (!isLt2M) {
311
+          this.$message.error('上传头像图片大小不能超过 2MB!');
312
+        }
313
+        
314
+            var date = new Date()
315
+            var ext = getFileExtension(file.name)
316
+            var key = date.getFullYear() + (date.getMonth() + 1) + date.getDate() + date.getHours()  + date.getMinutes()  + date.getSeconds()  +'_o_' + file.uid + '.' + ext;
317
+            this.uploading = true;
318
+            this.loadingText = '封面图片上传中'
319
+
320
+            const _self = this
321
+            return new Promise((resolve, reject) => {
322
+                getToken().then(response => {
323
+                    const token = response.data.data.uptoken
324
+                    console.log("token是什么?",token)
325
+                    _self._data.uploadData.token = token
326
+                    _self._data.uploadData.key = key
327
+                    resolve(true)
328
+                }).catch(err => {
329
+                    reject(false)
330
+                    this.uploading = false;
331
+                })
332
+            })
333
+        
334
+          //return isJPG && isLt2M;
335
+      },
336
+      
337
+      //第三张图片
338
+      //第二个图片
339
+      handleAvatarlastSuccess(res, file) {
340
+        this.imageUrlLast = URL.createObjectURL(file.raw);
341
+        this.form.org_logo = this.qiniuDomain + res.url;
342
+        this.uploading = false
343
+      },
344
+       handleAvatarlastError(err, file, fileList) {
345
+            this.$message.error(err);
346
+            this.uploading = false;
347
+            return false
348
+      },
349
+      beforeAvatarlastUpload(file) {
350
+        const isJPG = file.type === 'image/jpeg';
351
+        const isLt2M = file.size / 1024 / 1024 < 2;
352
+
353
+        if (!isJPG) {
354
+          this.$message.error('上传头像图片只能是 JPG 格式!');
355
+        }
356
+        if (!isLt2M) {
357
+          this.$message.error('上传头像图片大小不能超过 2MB!');
358
+        }
359
+        
360
+            var date = new Date()
361
+            var ext = getFileExtension(file.name)
362
+            var key = date.getFullYear() + (date.getMonth() + 1) + date.getDate() + date.getHours()  + date.getMinutes()  + date.getSeconds()  +'_o_' + file.uid + '.' + ext;
363
+            this.uploading = true;
364
+            this.loadingText = '封面图片上传中'
365
+
366
+            const _self = this
367
+            return new Promise((resolve, reject) => {
368
+                getToken().then(response => {
369
+                    const token = response.data.data.uptoken
370
+                    console.log("token是什么?",token)
371
+                    _self._data.uploadData.token = token
372
+                    _self._data.uploadData.key = key
373
+                    resolve(true)
374
+                }).catch(err => {
375
+                    reject(false)
376
+                    this.uploading = false;
377
+                })
378
+            })
379
+        
380
+          //return isJPG && isLt2M;
381
+      },
382
+
254
       beforeUpload(file) {
383
       beforeUpload(file) {
255
         var testmsg=file.name.substring(file.name.lastIndexOf('.')+1)
384
         var testmsg=file.name.substring(file.name.lastIndexOf('.')+1)
256
         const extension = testmsg === 'mp4'
385
         const extension = testmsg === 'mp4'
292
         var params  = new Object()
421
         var params  = new Object()
293
         params.act_name = this.form.act_name
422
         params.act_name = this.form.act_name
294
         params.act_content = this.$refs.neditor.content
423
         params.act_content = this.$refs.neditor.content
424
+        params.org_logo = this.form.org_logo
295
         this.formloading=true
425
         this.formloading=true
426
+        this.submitForm =true
296
         console.log("文章标题",params.act_name)
427
         console.log("文章标题",params.act_name)
297
         console.log("文章内容",params.act_content)
428
         console.log("文章内容",params.act_content)
298
         console.log("富文本编辑器的内容",params.act_content)
429
         console.log("富文本编辑器的内容",params.act_content)
430
+        console.log("图片",params.org_logo)
299
         submitForm(params).then(response => {
431
         submitForm(params).then(response => {
300
            if(response.data.state === 1){
432
            if(response.data.state === 1){
301
              this.$message({
433
              this.$message({
305
            }
437
            }
306
         })
438
         })
307
       },
439
       },
308
-
440
+      getArticleType(){
441
+        getArticleType().then(response =>{
442
+            console.log("好嗨我")
443
+            if(response.data.state === 1){
444
+            var category = response.data.data.category
445
+            this.options = response.data.data.category
446
+             console.log("文章内容:",category)
447
+             console.log("文章",this.options)
448
+            }
449
+        })
450
+      }
309
     },
451
     },
310
   }
452
   }
311
 </script>
453
 </script>