Commit 929abe6c by xinla

移动聊天侧边栏调试

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