Commit 267b1790eca71f1216f923ace83096040b88e2f8

Authored by YunaiV
1 parent 858b4e81

mp:支持发送【视频】消息时,支持新建视频

yudao-ui-admin/src/views/mp/components/wx-reply/main.vue
@@ -4,6 +4,8 @@ @@ -4,6 +4,8 @@
4 芋道源码: 4 芋道源码:
5 ① 移除多余的 rep 为前缀的变量,让 message 消息更简单 5 ① 移除多余的 rep 为前缀的变量,让 message 消息更简单
6 ② 代码优化,补充注释,提升阅读性 6 ② 代码优化,补充注释,提升阅读性
  7 + ③ 优化消息的临时缓存策略,发送消息时,只清理被发送消息的 tab,不会强制切回到 text 输入
  8 + ④ 支持发送【视频】消息时,支持新建视频
7 --> 9 -->
8 <template> 10 <template>
9 <el-tabs type="border-card" v-model="objData.type" @tab-click="handleClick"> 11 <el-tabs type="border-card" v-model="objData.type" @tab-click="handleClick">
@@ -32,6 +34,9 @@ @@ -32,6 +34,9 @@
32 <el-button type="success" @click="openMaterial"> 34 <el-button type="success" @click="openMaterial">
33 素材库选择<i class="el-icon-circle-check el-icon--right"></i> 35 素材库选择<i class="el-icon-circle-check el-icon--right"></i>
34 </el-button> 36 </el-button>
  37 + <el-dialog title="选择图片" :visible.sync="dialogImageVisible" width="90%" append-to-body>
  38 + <wx-material-select :obj-data="objData" @selectMaterial="selectMaterial" />
  39 + </el-dialog>
35 </el-col> 40 </el-col>
36 <!-- 文件上传 --> 41 <!-- 文件上传 -->
37 <el-col :span="12" class="col-add"> 42 <el-col :span="12" class="col-add">
@@ -43,10 +48,6 @@ @@ -43,10 +48,6 @@
43 </el-col> 48 </el-col>
44 </el-row> 49 </el-row>
45 </div> 50 </div>
46 - <!-- 点击选择素材,会打开下面的弹窗 -->  
47 - <el-dialog title="选择图片" :visible.sync="dialogImageVisible" width="90%" append-to-body>  
48 - <wx-material-select :obj-data="objData" @selectMaterial="selectMaterial" />  
49 - </el-dialog>  
50 </el-row> 51 </el-row>
51 </el-tab-pane> 52 </el-tab-pane>
52 <!-- 类型 3:语音 --> 53 <!-- 类型 3:语音 -->
@@ -64,9 +65,16 @@ @@ -64,9 +65,16 @@
64 </div> 65 </div>
65 <div v-else> 66 <div v-else>
66 <el-row style="text-align: center"> 67 <el-row style="text-align: center">
  68 + <!-- 选择素材 -->
67 <el-col :span="12" class="col-select"> 69 <el-col :span="12" class="col-select">
68 - <el-button type="success" @click="openMaterial">素材库选择<i class="el-icon-circle-check el-icon--right"></i></el-button> 70 + <el-button type="success" @click="openMaterial">
  71 + 素材库选择<i class="el-icon-circle-check el-icon--right"></i>
  72 + </el-button>
  73 + <el-dialog title="选择语音" :visible.sync="dialogVoiceVisible" width="90%" append-to-body>
  74 + <WxMaterialSelect :objData="objData" @selectMaterial="selectMaterial"></WxMaterialSelect>
  75 + </el-dialog>
69 </el-col> 76 </el-col>
  77 + <!-- 文件上传 -->
70 <el-col :span="12" class="col-add"> 78 <el-col :span="12" class="col-add">
71 <el-upload :action="actionUrl" :headers="headers" multiple :limit="1" :file-list="fileList" :data="uploadData" 79 <el-upload :action="actionUrl" :headers="headers" multiple :limit="1" :file-list="fileList" :data="uploadData"
72 :before-upload="beforeVoiceUpload" :on-success="handleUploadSuccess"> 80 :before-upload="beforeVoiceUpload" :on-success="handleUploadSuccess">
@@ -76,9 +84,6 @@ @@ -76,9 +84,6 @@
76 </el-col> 84 </el-col>
77 </el-row> 85 </el-row>
78 </div> 86 </div>
79 - <el-dialog title="选择语音" :visible.sync="dialogVoiceVisible" width="90%" append-to-body>  
80 - <WxMaterialSelect :objData="objData" @selectMaterial="selectMaterial"></WxMaterialSelect>  
81 - </el-dialog>  
82 </el-row> 87 </el-row>
83 </el-tab-pane> 88 </el-tab-pane>
84 <!-- 类型 4:视频 --> 89 <!-- 类型 4:视频 -->
@@ -93,13 +98,24 @@ @@ -93,13 +98,24 @@
93 <wx-video-player v-if="objData.url" :url="objData.url" /> 98 <wx-video-player v-if="objData.url" :url="objData.url" />
94 </div> 99 </div>
95 <div style="margin: 20px 0;"></div> 100 <div style="margin: 20px 0;"></div>
96 - <div style="text-align: center">  
97 - <el-button type="success" @click="openMaterial">素材库选择<i class="el-icon-circle-check el-icon--right"></i></el-button>  
98 -<!-- <el-button type="primary" v-if="permissions.wxmp_wxmaterial_add">新建视频<i class="el-icon-upload el-icon&#45;&#45;right"></i></el-button>-->  
99 - </div>  
100 - <el-dialog title="选择视频" :visible.sync="dialogVideoVisible" width="90%" append-to-body>  
101 - <WxMaterialSelect :objData="objData" @selectMaterial="selectMaterial"></WxMaterialSelect>  
102 - </el-dialog> 101 + <el-row style="text-align: center">
  102 + <!-- 选择素材 -->
  103 + <el-col :span="12">
  104 + <el-button type="success" @click="openMaterial">
  105 + 素材库选择<i class="el-icon-circle-check el-icon--right"></i>
  106 + </el-button>
  107 + <el-dialog title="选择视频" :visible.sync="dialogVideoVisible" width="90%" append-to-body>
  108 + <wx-material-select :objData="objData" @selectMaterial="selectMaterial" />
  109 + </el-dialog>
  110 + </el-col>
  111 + <!-- 文件上传 -->
  112 + <el-col :span="12">
  113 + <el-upload :action="actionUrl" :headers="headers" multiple :limit="1" :file-list="fileList" :data="uploadData"
  114 + :before-upload="beforeVideoUpload" :on-success="handleUploadSuccess">
  115 + <el-button type="primary">新建视频<i class="el-icon-upload el-icon--right"></i></el-button>
  116 + </el-upload>
  117 + </el-col>
  118 + </el-row>
103 </el-row> 119 </el-row>
104 </el-tab-pane> 120 </el-tab-pane>
105 <el-tab-pane name="news"> 121 <el-tab-pane name="news">
@@ -123,6 +139,7 @@ @@ -123,6 +139,7 @@
123 </el-dialog> 139 </el-dialog>
124 </el-row> 140 </el-row>
125 </el-tab-pane> 141 </el-tab-pane>
  142 + <!-- 类型 6:音乐 -->
126 <el-tab-pane name="music"> 143 <el-tab-pane name="music">
127 <span slot="label"><i class="el-icon-service"></i> 音乐</span> 144 <span slot="label"><i class="el-icon-service"></i> 音乐</span>
128 <el-row> 145 <el-row>
@@ -139,7 +156,7 @@ @@ -139,7 +156,7 @@
139 </div> 156 </div>
140 </div> 157 </div>
141 <el-dialog title="选择图片" :visible.sync="dialogThumbVisible" width="80%" append-to-body> 158 <el-dialog title="选择图片" :visible.sync="dialogThumbVisible" width="80%" append-to-body>
142 - <WxMaterialSelect :objData="{type:'image'}" @selectMaterial="selectMaterial"></WxMaterialSelect> 159 + <wx-material-select :objData="{type:'image'}" @selectMaterial="selectMaterial" />
143 </el-dialog> 160 </el-dialog>
144 </el-col> 161 </el-col>
145 <el-col :span="18"> 162 <el-col :span="18">
@@ -280,6 +297,22 @@ @@ -280,6 +297,22 @@
280 this.uploadData.accountId = this.objData.accountId; 297 this.uploadData.accountId = this.objData.accountId;
281 return true; 298 return true;
282 }, 299 },
  300 + beforeVideoUpload(file){
  301 + // 校验格式
  302 + const isType = file.type === 'video/mp4';
  303 + if (!isType) {
  304 + this.$message.error('上传视频格式不对!');
  305 + return false;
  306 + }
  307 + // 校验大小
  308 + const isLt = file.size / 1024 / 1024 < 10;
  309 + if (!isLt) {
  310 + this.$message.error('上传视频大小不能超过 10M!');
  311 + return false;
  312 + }
  313 + this.uploadData.accountId = this.objData.accountId;
  314 + return true;
  315 + },
283 handleUploadSuccess(response, file, fileList) { 316 handleUploadSuccess(response, file, fileList) {
284 if (response.code !== 0) { 317 if (response.code !== 0) {
285 this.$message.error('上传出错:' + response.msg) 318 this.$message.error('上传出错:' + response.msg)
@@ -362,10 +395,14 @@ @@ -362,10 +395,14 @@
362 tempObjItem.name = item.name 395 tempObjItem.name = item.name
363 this.objData.name = item.name 396 this.objData.name = item.name
364 // title、introduction:从 item 到 tempObjItem,因为素材里有 title、introduction 397 // title、introduction:从 item 到 tempObjItem,因为素材里有 title、introduction
365 - this.objData.title = item.title || ''  
366 - tempObjItem.title = item.title || ''  
367 - this.objData.description = item.introduction || '' // 消息使用的是 description,素材使用的是 introduction,所以转换下  
368 - tempObjItem.description = item.introduction || '' 398 + if (item.title) {
  399 + this.objData.title = item.title || ''
  400 + tempObjItem.title = item.title || ''
  401 + }
  402 + if (item.introduction) {
  403 + this.objData.description = item.introduction || '' // 消息使用的是 description,素材使用的是 introduction,所以转换下
  404 + tempObjItem.description = item.introduction || ''
  405 + }
369 } else if (this.objData.type === 'text') { 406 } else if (this.objData.type === 'text') {
370 this.objData.content = item.content || '' 407 this.objData.content = item.content || ''
371 } 408 }