Commit 104f01cd by xinla

移动侧边栏调试

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