Commit 104f01cd by xinla

移动侧边栏调试

1 parent f7e8951e
......@@ -32,7 +32,7 @@ export default {
jsApiList: ['sendChatMessage', 'getContext'], //必填
success: (res) => {
// 回调
this.$toast('agentId成功:')
// this.$toast('agentId成功:')
},
fail: (res) => {
this.$toast('agentId失败:' + JSON.stringify(res))
......
......@@ -10,8 +10,9 @@ export default {
props: {
sideId: {
type: String,
default: '0',
default: '',
},
// mediaType 0 图片(image)、1 语音(voice)、2 视频(video),3 普通文件(file) 4 文本 5 海报
mediaType: {
type: String,
default: '0',
......@@ -27,6 +28,7 @@ export default {
},
data() {
return {
refreshing: false,
loading: false,
finished: false,
error: false,
......@@ -34,24 +36,32 @@ export default {
pageSize: 10,
list: [],
collectList: [],
mediaTypeObj: {
'0': '图片',
'1': '语音',
'2': '视频',
'3': '普通文件',
'4': '文本',
'5': '海报',
},
}
},
watch: {},
computed: {},
created() {
this.getList()
this.userId && this.getCollectionList()
// this.userId && this.getCollectionList()
},
mounted() {},
methods: {
getList(page) {
let pageSize = page || this.pageSize++
let pageNum = this.pageNum
let pageNum = page || this.pageNum++
let pageSize = this.pageSize
let keyword = this.keyword
page == 1 && (this.list = [])
this.loading = true
;(this.sideId
? getMaterialList({
userId: this.userId,
sideId: this.sideId,
mediaType: this.mediaType,
pageSize,
......@@ -62,7 +72,9 @@ export default {
)
.then(({ rows, total }) => {
this.list.push(...rows)
this.loading = false
this.refreshing = false
// 数据全部加载完成
if (this.list.length >= +total) {
this.finished = true
......@@ -72,78 +84,82 @@ export default {
this.error = true
})
},
getCollectionList() {
let data = { userId: this.userId, pageSize: 1, pageNum: 1000 }
getCollectionList(data).then(({ rows, total }) => {
this.collectList = rows.map((d) => d.id)
})
},
isCollected(id) {
return this.collectList.includes(id)
},
// getCollectionList() {
// let data = { userId: this.userId, pageSize: 1000, pageNum: 1 }
// getCollectionList(data).then(({ rows, total }) => {
// this.collectList = rows.map((d) => d.materialId)
// })
// },
send(data) {
let entry = undefined
let _this = this
wx.invoke('getContext', {}, function(res) {
if (res.err_msg == 'getContext:ok') {
entry = res.entry //返回进入H5页面的入口类型,目前有normal、contact_profile、single_chat_tools、group_chat_tools
if (
!['single_chat_tools', 'group_chat_tools', 'normal'].includes(entry)
) {
_this.$toast('入口错误:' + entry)
return
}
// mediaType 0 图片(image)、1 语音(voice)、2 视频(video),3 普通文件(file) 4 文本 5 海报
// msgtype 文本(“text”),图片(“image”),视频(“video”),文件(“file”),H5(“news”)和小程序(“miniprogram”)
let mes = {}
let msgtype = {
0: 'image',
2: 'video',
3: 'file',
4: 'text',
5: 'news',
}
switch (data.mediaType) {
case '4':
default:
mes.text = {
content: data.content, //文本内容
}
break
case '0':
case '2':
case '3':
mes[msgtype[data.mediaType]] = {
mediaid: data.materialId, //
}
break
case '5':
mes.news = {
link: '', //H5消息页面url 必填
title: '', //H5消息标题
desc: '', //H5消息摘要
imgUrl: '', //H5消息封面图片URL
}
break
// case '6':
// mes.miniprogram = {
// appid: 'wx8bd80126147df384', //小程序的appid
// title: '_this is title', //小程序消息的title
// imgUrl:
// 'https://search-operate.cdn.bcebos.com/d054b8892a7ab572cb296d62ec7f97b6.png', //小程序消息的封面图。必须带http或者https协议头,否则报错 $apiName$:fail invalid imgUrl
// page: '/index/page.html', //小程序消息打开后的路径,注意要以.html作为后缀,否则在微信端打开会提示找不到页面
// }
// break
entry = res.entry //返回进入H5页面的入口类型,目前 contact_profile、single_chat_tools、group_chat_tools
try {
if (
!['single_chat_tools', 'group_chat_tools', 'normal'].includes(
entry
)
) {
_this.$toast('入口错误:' + entry)
return
}
// mediaType 0 图片(image)、1 语音(voice)、2 视频(video),3 普通文件(file) 4 文本 5 海报
// msgtype 文本(“text”),图片(“image”),视频(“video”),文件(“file”),H5(“news”)和小程序(“miniprogram”)
let mes = {}
let msgtype = {
0: 'image',
2: 'video',
3: 'file',
4: 'text',
5: 'news',
}
switch (data.mediaType) {
case '4':
default:
mes.text = {
content: data.content, //文本内容
}
break
case '0':
case '2':
case '3':
mes[msgtype[data.mediaType]] = {
mediaid: data.materialId, //
}
break
case '5':
mes.news = {
link: '', //H5消息页面url 必填
title: '', //H5消息标题
desc: '', //H5消息摘要
imgUrl: '', //H5消息封面图片URL
}
break
// case '6':
// mes.miniprogram = {
// appid: 'wx8bd80126147df384', //小程序的appid
// title: '_this is title', //小程序消息的title
// imgUrl:
// 'https://search-operate.cdn.bcebos.com/d054b8892a7ab572cb296d62ec7f97b6.png', //小程序消息的封面图。必须带http或者https协议头,否则报错 $apiName$:fail invalid imgUrl
// page: '/index/page.html', //小程序消息打开后的路径,注意要以.html作为后缀,否则在微信端打开会提示找不到页面
// }
// break
}
mes.msgtype = msgtype[data.mediaType]
_this.$dialog({ message: 'mes:' + JSON.stringify(mes) })
} catch (err) {
_this.$dialog({ message: 'err' + JSON.stringify(err) })
}
mes.msgtype = msgtype[data.mediaType]
_this.$dialog({ message: 'mes:' + JSON.stringify(mes) })
wx.invoke('sendChatMessage', mes, function(resSend) {
if (resSend.err_msg == 'sendChatMessage:ok') {
//发送成功
_this.$toast('发送成功')
} else {
//错误处理
_this.$dialog({ message: '发送失败:' + JSON.stringify(resSend) })
// _this.$dialog({ message: '发送失败:' + JSON.stringify(resSend) })
}
})
} else {
......@@ -152,14 +168,13 @@ export default {
}
})
},
collect(materialId) {
;(this.isCollected(materialId) ? cancleCollection : addCollection)({
collect(data) {
// collection 是否收藏 0未收藏 1 已收藏
;(data.collection == 1 || !sideId ? cancleCollection : addCollection)({
userId: this.userId,
materialId,
}).then(({ data }) => {
this.isCollected(materialId)
? this.isCollected.splice(this.isCollected.indexOf(materialId), 1)
: this.isCollected.push(materialId)
materialId: data.materialId,
}).then(() => {
data.collection = [1, 0][data.collection]
this.$toast('操作成功')
})
},
......@@ -169,36 +184,83 @@ export default {
<template>
<div>
<van-list
v-model="loading"
:finished="finished"
finished-text="没有更多了"
:error.sync="error"
error-text="请求失败,点击重新加载"
@load="getList()"
>
<div v-for="(item, index) in list" class="list" :key="index">
<div class="title">
{{ item.mediaType == 4 ? item.content : item.materialName }}
<!-- <ul>
<li class="li bfc-o">
<van-image
width="100"
height="100"
src="https://img01.yzcdn.cn/vant/cat.jpeg"
/>
<span class="title">
afsdafddfasfewgoegoeroigwogjrepgerwgowrgjwoerjgweorgjoerwigjir
</span>
</li>
<div class="info">
sdv类型
<div class="fr flex">
<div class="action" @click="send(item)">发送</div>
<div v-if="!!userId" class="action" @click="collect(item.materialId)">
{{ isCollected(item.materialId) ? '取消' : '' }}收藏
</div>
</div>
<div class="info">
{{ item.content }}
<span>2020/2/4</span>
</div>
</ul> -->
<van-pull-refresh
v-model="refreshing"
success-text="刷新成功"
@refresh="getList(1)"
>
<van-list
v-model="loading"
:finished="finished"
finished-text="没有更多了"
:error.sync="error"
error-text="请求失败,点击重新加载"
@load="getList()"
>
<div v-for="(item, index) in list" class="list" :key="index">
<div class="content bfc-o">
<van-image
v-if="item.mediaType == 0"
width="80"
height="80"
:src="item.materialUrl"
/>
<span class="title">
{{ item.mediaType == 4 ? item.content : item.materialName }}
</span>
</div>
<div class="info">
{{ mediaTypeObj[item.mediaType] }}类型
<span class="time">{{ item.createTime }}</span>
<div class="fr flex">
<div class="action" @click="send(item)">发送</div>
<div
v-if="!!userId"
class="action"
@click="collect(item.materialId)"
>
{{ isCollected(item.materialId) ? '已' : '' }}收藏
<div class="fr flex">
<div class="action" @click="send(item)">发送</div>
<div v-if="!!userId" class="action" @click="collect(item)">
{{ item.collection == 1 || !sideId ? '取消' : '' }}收藏
</div>
</div>
</div>
</div>
</div>
</van-list>
</van-list>
</van-pull-refresh>
</div>
</template>
<style lang="less" scoped></style>
<style lang="less" scoped>
.content {
// display: flex;
.van-image {
float: left;
margin: 0 10px 5px 0;
border: 1px solid #eee;
}
.title {
word-break: break-all;
}
}
.time {
margin-left: 5px;
}
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!