Commit 76e8b94d by xinla

移动聊天侧边栏基本完成

1 parent 723f8404
import request from '@/utils/request' import request from '@/utils/request'
const service = window.CONFIG.services.wecom + '/chat' const wecom = window.CONFIG.services.wecom
const service = wecom + '/chat'
const serviceMaterial = wecom + '/material'
/** /**
* 侧边栏列表 * 侧边栏列表
...@@ -67,3 +69,17 @@ export function cancleCollection(data) { ...@@ -67,3 +69,17 @@ export function cancleCollection(data) {
data, data,
}) })
} }
/**
* 获取企业微信素材media_id
* @param {*} params
* url [string] 是 素材路径
type [string] 是 素材类型
name [string] 是 文件名称
*/
export function getMaterialMediaId(params) {
return request({
url: serviceMaterial + '/temporaryMaterialMediaId',
params,
})
}
...@@ -7,7 +7,7 @@ function createAxios(baseURL) { ...@@ -7,7 +7,7 @@ function createAxios(baseURL) {
headers: { headers: {
Auth_token: '', Auth_token: '',
}, },
timeout: 3000, timeout: 10000,
}) })
// 请求拦截 // 请求拦截
instance.interceptors.request.use( instance.interceptors.request.use(
......
...@@ -4,6 +4,7 @@ import { ...@@ -4,6 +4,7 @@ import {
getCollectionList, getCollectionList,
addCollection, addCollection,
cancleCollection, cancleCollection,
getMaterialMediaId,
} from '@/api/chat' } from '@/api/chat'
export default { export default {
components: {}, components: {},
...@@ -46,7 +47,11 @@ export default { ...@@ -46,7 +47,11 @@ export default {
}, },
} }
}, },
watch: {}, watch: {
userId() {
this.getList(1)
},
},
computed: {}, computed: {},
created() { created() {
this.getList() this.getList()
...@@ -71,6 +76,13 @@ export default { ...@@ -71,6 +76,13 @@ export default {
: getCollectionList({ userId: this.userId, pageSize, pageNum, keyword }) : getCollectionList({ userId: this.userId, pageSize, pageNum, keyword })
) )
.then(({ rows, total }) => { .then(({ rows, total }) => {
// 判断我的列表
if (!this.sideId) {
rows.forEach((element) => {
element.collection = 1
})
}
this.list.push(...rows) this.list.push(...rows)
this.loading = false this.loading = false
...@@ -91,24 +103,31 @@ export default { ...@@ -91,24 +103,31 @@ export default {
// }) // })
// }, // },
send(data) { send(data) {
this.$toast.loading({
message: '正在发送...',
duration: 0,
forbidClick: true,
})
let entry = undefined let entry = undefined
let _this = this let _this = this
wx.invoke('getContext', {}, function(res) { wx.invoke('getContext', {}, async function(res) {
if (res.err_msg == 'getContext:ok') { if (res.err_msg == 'getContext:ok') {
entry = res.entry //返回进入H5页面的入口类型,目前 contact_profile、single_chat_tools、group_chat_tools entry = res.entry //返回进入H5页面的入口类型,目前 contact_profile、single_chat_tools、group_chat_tools
let mes = {}
try { try {
if ( if (
!['single_chat_tools', 'group_chat_tools', 'normal'].includes( !['single_chat_tools', 'group_chat_tools', 'normal'].includes(
entry entry
) )
) { ) {
// _this.$toast.clear()
_this.$toast('入口错误:' + entry) _this.$toast('入口错误:' + entry)
return return
} }
// mediaType 0 图片(image)、1 语音(voice)、2 视频(video),3 普通文件(file) 4 文本 5 海报 // mediaType 0 图片(image)、1 语音(voice)、2 视频(video),3 普通文件(file) 4 文本 5 海报
// msgtype 文本(“text”),图片(“image”),视频(“video”),文件(“file”),H5(“news”)和小程序(“miniprogram”) // msgtype 文本(“text”),图片(“image”),视频(“video”),文件(“file”),H5(“news”)和小程序(“miniprogram”)
let mes = {}
let msgtype = { let msgtype = {
0: 'image', 0: 'image',
2: 'video', 2: 'video',
...@@ -126,8 +145,18 @@ export default { ...@@ -126,8 +145,18 @@ export default {
case '0': case '0':
case '2': case '2':
case '3': case '3':
let dataMediaId = {
url: data.materialUrl,
type: msgtype[data.mediaType],
name: data.materialName,
}
let resMaterialId = await getMaterialMediaId(dataMediaId)
if (!resMaterialId.data) {
_this.$toast('获取素材id失败')
return
}
mes[msgtype[data.mediaType]] = { mes[msgtype[data.mediaType]] = {
mediaid: data.materialId, // mediaid: resMaterialId.data.media_id, //
} }
break break
case '5': case '5':
...@@ -149,20 +178,22 @@ export default { ...@@ -149,20 +178,22 @@ export default {
// break // break
} }
mes.msgtype = msgtype[data.mediaType] mes.msgtype = msgtype[data.mediaType]
_this.$dialog({ message: 'mes:' + JSON.stringify(mes) }) // _this.$dialog({ message: 'mes:' + JSON.stringify(mes) })
} catch (err) { } catch (err) {
_this.$dialog({ message: 'err' + JSON.stringify(err) }) _this.$dialog({ message: 'err' + JSON.stringify(err) })
} }
wx.invoke('sendChatMessage', mes, function(resSend) { wx.invoke('sendChatMessage', mes, function(resSend) {
if (resSend.err_msg == 'sendChatMessage:ok') { if (resSend.err_msg == 'sendChatMessage:ok') {
//发送成功 //发送成功
_this.$toast('发送成功') // _this.$toast('发送成功')
} else { } else {
//错误处理 //错误处理
// _this.$dialog({ message: '发送失败:' + JSON.stringify(resSend) }) // _this.$dialog({ message: '发送失败:' + JSON.stringify(resSend) })
} }
}) })
_this.$toast.clear()
} else { } else {
_this.$toast.clear()
//错误处理 //错误处理
_this.$dialog({ message: '进入失败:' + JSON.stringify(res) }) _this.$dialog({ message: '进入失败:' + JSON.stringify(res) })
} }
...@@ -170,7 +201,7 @@ export default { ...@@ -170,7 +201,7 @@ export default {
}, },
collect(data) { collect(data) {
// collection 是否收藏 0未收藏 1 已收藏 // collection 是否收藏 0未收藏 1 已收藏
;(data.collection == 1 || !sideId ? cancleCollection : addCollection)({ ;(data.collection == 1 ? cancleCollection : addCollection)({
userId: this.userId, userId: this.userId,
materialId: data.materialId, materialId: data.materialId,
}).then(() => { }).then(() => {
...@@ -221,12 +252,20 @@ export default { ...@@ -221,12 +252,20 @@ export default {
> >
<div v-for="(item, index) in list" class="list" :key="index"> <div v-for="(item, index) in list" class="list" :key="index">
<div class="content bfc-o"> <div class="content bfc-o">
<!-- 图片 -->
<van-image <van-image
v-if="item.mediaType == 0" v-if="item.mediaType == 0"
width="80" width="80"
height="80" height="80"
:src="item.materialUrl" :src="item.materialUrl"
/> />
<!-- 视频 -->
<van-image
v-if="item.mediaType == 2"
width="80"
height="80"
:src="item.coverUrl"
/>
<span class="title"> <span class="title">
{{ item.mediaType == 4 ? item.content : item.materialName }} {{ item.mediaType == 4 ? item.content : item.materialName }}
</span> </span>
...@@ -238,7 +277,7 @@ export default { ...@@ -238,7 +277,7 @@ export default {
<div class="fr flex"> <div class="fr flex">
<div class="action" @click="send(item)">发送</div> <div class="action" @click="send(item)">发送</div>
<div v-if="!!userId" class="action" @click="collect(item)"> <div v-if="!!userId" class="action" @click="collect(item)">
{{ item.collection == 1 || !sideId ? '取消' : '' }}收藏 {{ item.collection == 1 ? '取消' : '' }}收藏
</div> </div>
</div> </div>
</div> </div>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!