Commit 1441e845 by xinla

移动侧边栏调试

1 parent 279e13a0
...@@ -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,23 +84,24 @@ export default { ...@@ -72,23 +84,24 @@ 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
try {
if ( if (
!['single_chat_tools', 'group_chat_tools', 'normal'].includes(entry) !['single_chat_tools', 'group_chat_tools', 'normal'].includes(
entry
)
) { ) {
_this.$toast('入口错误:' + entry) _this.$toast('入口错误:' + entry)
return return
...@@ -137,13 +150,16 @@ export default { ...@@ -137,13 +150,16 @@ export default {
} }
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) {
_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) })
} }
}) })
} 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,6 +184,33 @@ export default { ...@@ -169,6 +184,33 @@ export default {
<template> <template>
<div> <div>
<!-- <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>
</ul> -->
<van-pull-refresh
v-model="refreshing"
success-text="刷新成功"
@refresh="getList(1)"
>
<van-list <van-list
v-model="loading" v-model="loading"
:finished="finished" :finished="finished"
...@@ -178,27 +220,47 @@ export default { ...@@ -178,27 +220,47 @@ export default {
@load="getList()" @load="getList()"
> >
<div v-for="(item, index) in list" class="list" :key="index"> <div v-for="(item, index) in list" class="list" :key="index">
<div class="title"> <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 }} {{ item.mediaType == 4 ? item.content : item.materialName }}
</span>
</div> </div>
<div class="info"> <div class="info">
{{ item.content }} {{ mediaTypeObj[item.mediaType] }}类型
<span>2020/2/4</span> <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"
@click="collect(item.materialId)"
>
{{ isCollected(item.materialId) ? '已' : '' }}收藏
</div> </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!