|
4 | 4 | 芋道源码:
|
5 | 5 | ① 移除多余的 rep 为前缀的变量,让 message 消息更简单
|
6 | 6 | ② 代码优化,补充注释,提升阅读性
|
| 7 | + ③ 优化消息的临时缓存策略,发送消息时,只清理被发送消息的 tab,不会强制切回到 text 输入 |
| 8 | + ④ 支持发送【视频】消息时,支持新建视频 |
7 | 9 | -->
|
8 | 10 | <template>
|
9 | 11 | <el-tabs type="border-card" v-model="objData.type" @tab-click="handleClick">
|
|
32 | 34 | <el-button type="success" @click="openMaterial">
|
33 | 35 | 素材库选择<i class="el-icon-circle-check el-icon--right"></i>
|
34 | 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 | 40 | </el-col>
|
36 | 41 | <!-- 文件上传 -->
|
37 | 42 | <el-col :span="12" class="col-add">
|
|
43 | 48 | </el-col>
|
44 | 49 | </el-row>
|
45 | 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 | 51 | </el-row>
|
51 | 52 | </el-tab-pane>
|
52 | 53 | <!-- 类型 3:语音 -->
|
|
64 | 65 | </div>
|
65 | 66 | <div v-else>
|
66 | 67 | <el-row style="text-align: center">
|
| 68 | + <!-- 选择素材 --> |
67 | 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 | 76 | </el-col>
|
| 77 | + <!-- 文件上传 --> |
70 | 78 | <el-col :span="12" class="col-add">
|
71 | 79 | <el-upload :action="actionUrl" :headers="headers" multiple :limit="1" :file-list="fileList" :data="uploadData"
|
72 | 80 | :before-upload="beforeVoiceUpload" :on-success="handleUploadSuccess">
|
|
76 | 84 | </el-col>
|
77 | 85 | </el-row>
|
78 | 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 | 87 | </el-row>
|
83 | 88 | </el-tab-pane>
|
84 | 89 | <!-- 类型 4:视频 -->
|
|
93 | 98 | <wx-video-player v-if="objData.url" :url="objData.url" />
|
94 | 99 | </div>
|
95 | 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--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 | 119 | </el-row>
|
104 | 120 | </el-tab-pane>
|
105 | 121 | <el-tab-pane name="news">
|
|
123 | 139 | </el-dialog>
|
124 | 140 | </el-row>
|
125 | 141 | </el-tab-pane>
|
| 142 | + <!-- 类型 6:音乐 --> |
126 | 143 | <el-tab-pane name="music">
|
127 | 144 | <span slot="label"><i class="el-icon-service"></i> 音乐</span>
|
128 | 145 | <el-row>
|
|
139 | 156 | </div>
|
140 | 157 | </div>
|
141 | 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 | 160 | </el-dialog>
|
144 | 161 | </el-col>
|
145 | 162 | <el-col :span="18">
|
|
280 | 297 | this.uploadData.accountId = this.objData.accountId;
|
281 | 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 | 316 | handleUploadSuccess(response, file, fileList) {
|
284 | 317 | if (response.code !== 0) {
|
285 | 318 | this.$message.error('上传出错:' + response.msg)
|
|
362 | 395 | tempObjItem.name = item.name
|
363 | 396 | this.objData.name = item.name
|
364 | 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 | 406 | } else if (this.objData.type === 'text') {
|
370 | 407 | this.objData.content = item.content || ''
|
371 | 408 | }
|
|
0 commit comments