Commit 929abe6c by xinla

移动聊天侧边栏调试

1 parent 69a82bef
......@@ -4,8 +4,8 @@ export default {
name: 'App',
data() {
return {
appId: 'ww38152475d1bca752',
agentId: '1000003',
appId: 'appId',
agentId: '1000005',
}
},
created() {
......
......@@ -15,12 +15,10 @@ export function getTypeList() {
* 素材列表
* @param {*} sideId
*/
export function getMaterialList(sideId) {
export function getMaterialList(params) {
return request({
url: service + '/item/list',
params: {
sideId,
},
params,
})
}
......@@ -28,12 +26,10 @@ export function getMaterialList(sideId) {
* 收藏列表(h5我的)
* @param {*} userId
*/
export function getCollectionList(userId) {
export function getCollectionList(params) {
return request({
url: service + '/collection/list',
params: {
userId,
},
params,
})
}
......@@ -54,7 +50,7 @@ export function addCollection(data) {
}
/**
* 侧边栏抓取素材
* 取消收藏
* @param {*} data
* {
materialId:素材id
......@@ -64,7 +60,7 @@ userId:用户id
export function cancleCollection(data) {
return request({
url: service + '/collection/cancleCollection',
method: 'put',
method: 'post',
data,
})
}
import request from '@/utils/request'
import config from '@/config'
const service = config.services.wecom + '/ticket'
const service = config.services.wecom
/**
* 获取应用的jsapi_ticket
......@@ -8,7 +8,7 @@ const service = config.services.wecom + '/ticket'
*/
export function getAgentTicket(url) {
return request({
url: service + '/getAgentTicket',
url: service + '/ticket/getAgentTicket',
params: {
url,
},
......@@ -21,7 +21,7 @@ export function getAgentTicket(url) {
*/
export function getAppTicket(url) {
return request({
url: service + '/getAppTicket',
url: service + '/ticket/getAppTicket',
params: {
url,
},
......@@ -32,8 +32,11 @@ export function getAppTicket(url) {
* 获取企业的jsapi_ticket
* @param {*} url 页面url
*/
export function getLoginUserId() {
export function getUserInfo(code) {
return request({
url: '/system/user/findCurrentLoginUser',
url: service + '/user/getUserInfo',
params: {
code,
},
})
}
import axios from 'axios'
import { Toast } from 'vant'
function createAxios(baseURL) {
const instance = axios.create({
......@@ -44,10 +45,7 @@ function createAxios(baseURL) {
if (error.response) {
addErrorLog(error.response)
} else {
// Message.error({
// content: `服务器未启动或连接超时`,
// duration: 3
// })
Toast.fail('服务器未启动或连接超时')
console.error('服务器未启动或连接超时')
}
return Promise.reject(error)
......@@ -71,6 +69,7 @@ function createAxios(baseURL) {
process.env.NODE_ENV === 'development'
? console.error(`错误: 路径: ${responseURL}, 返回值 : ${responseText}`)
: console.error(`${JSON.parse(responseText).message}`)
Toast.fail(`${responseText}`)
}
return instance
......
......@@ -16,38 +16,55 @@ export default {
type: String,
default: '',
},
keyword: {
type: String,
default: '',
},
},
data() {
return {
list: [{}],
loading: false,
finished: false,
error: false,
pageSize: 1,
pageNum: 10,
list: [],
collectList: [],
}
},
watch: {},
computed: {},
created() {},
created() {
this.getList()
this.userId && this.getCollectionList()
},
mounted() {},
methods: {
getList() {
getList(page) {
let pageSize = page || this.pageSize++
let pageNum = this.pageNum
let keyword = this.keyword
page == 1 && (this.list = [])
this.loading = true
;(this.sideId
? getMaterialList(this.sideId)
: getCollectionList(this.userId)
? getMaterialList({ sideId: this.sideId, pageSize, pageNum, keyword })
: getCollectionList({ userId: this.userId, pageSize, pageNum, keyword })
)
.then(({ rows, total }) => {
this.list = rows
this.list.push(...rows)
this.loading = false
this.finished = true
// 数据全部加载完成
if (this.list.length >= total) {
this.finished = true
}
})
.catch(() => {
this.loading = false
this.finished = true
this.error = true
})
},
getCollectionList() {
getCollectionList().then(({ rows, total }) => {
let data = { userId: this.userId, pageSize: 1, pageNum: 1000 }
getCollectionList(data).then(({ rows, total }) => {
this.collectList = rows.map((d) => d.id)
})
},
......@@ -117,10 +134,12 @@ export default {
},
collect(materialId) {
;(this.isCollected(materialId) ? cancleCollection : addCollection)({
userId,
userId: this.userId,
materialId,
}).then(({ data }) => {
this.isCollected.splice(this.isCollected.indexOf(materialId), 1)
this.isCollected(materialId)
? this.isCollected.splice(this.isCollected.indexOf(materialId), 1)
: this.isCollected.push(materialId)
})
},
},
......@@ -133,7 +152,9 @@ export default {
v-model="loading"
:finished="finished"
finished-text="没有更多了"
@load="getList"
:error.sync="error"
error-text="请求失败,点击重新加载"
@load="getList()"
>
<div v-for="(item, index) in list" class="list" :key="index">
<div class="title">{{ item.content }}</div>
......@@ -143,7 +164,7 @@ export default {
<div class="fr flex">
<div class="action" @click="send(item)">发送</div>
<div class="action" @click="collect(item.id)">
<div v-if="!!userId" class="action" @click="collect(item.id)">
{{ isCollected(item.id) ? '已' : '' }}收藏
</div>
</div>
......
2
<script>
import { getLoginUserId } from '@/api/common'
import { getUserInfo } from '@/api/common'
import { getTypeList } from '@/api/chat'
import List from './List'
export default {
......@@ -14,13 +15,53 @@ export default {
finished: false,
show: false,
userId: '',
auth_code: '',
auth_code1: '',
}
},
watch: {},
computed: {},
beforeCreate() {
// http://106.13.201.219/?auth_code=xxx#/authWehatCallback
// console.log('routerbeforeCreate', this.$route);
// let auth_code = location.search
// .slice(1)
// .split('&')[0]
// .split('=')[1]
// this.auth_code1 = auth_code
// if (!auth_code) {
// this.$toast('未获得授权')
// return
// }
// getUserInfo(auth_code)
// .then(({ data }) => {
// this.userId = data.userId
// this.$toast('userId:' + this.userId)
// })
// .catch((err) => {
// this.$toast('err:' + err)
// })
},
created() {
let auth_code = location.search
.slice(1)
.split('&')[0]
.split('=')[1]
this.auth_code1 = auth_code
if (!auth_code) {
this.$toast('未获得授权')
return
}
getUserInfo(auth_code)
.then(({ data }) => {
this.userId = data.userId
this.$toast('userId:' + this.userId)
})
.catch((err) => {
this.$toast('err:' + err)
})
this.getList()
this.getUserId()
this.auth_code = location
},
mounted() {},
methods: {
......@@ -29,12 +70,9 @@ export default {
this.list = rows
})
},
getUserId() {
getLoginUserId().then(({ data }) => {
this.userId = data
})
search() {
this.$refs['list' + this.active].getList(1)
},
search() {},
add() {},
},
}
......@@ -52,16 +90,25 @@ export default {
<van-icon name="plus" @click="add" />
</template> -->
</van-search>
<span>{{ auth_code }}</span>
<br />
<span>auth_code:{{ auth_code1 }}</span>
<van-tabs v-model="active">
<van-tab title="我的">
<List :userId="userId"></List>
<van-tab v-if="!!userId" title="我的">
<List ref="list0" :userId="userId" :keyword="keyword"></List>
</van-tab>
<van-tab
:title="item.sideName"
v-for="(item, index) in list"
:key="index"
>
<List :sideId="item.sideId" :userId="userId"></List>
<List
:ref="'list' + (index + 1)"
:sideId="item.sideId"
:userId="userId"
:keyword="keyword"
></List>
</van-tab>
</van-tabs>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!