Commit 87360c67 by xinlaa

移动侧边栏

1 parent 4f7ce453
......@@ -8,6 +8,7 @@
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
<script src="./jweixin-1.2.0.js"></script>
<script src="https://open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js"></script>
</head>
<body>
......
......@@ -4,26 +4,82 @@ export default {
name: 'App',
data() {
return {
timestamp: '',
nonceStr: '',
signature: '',
appId: 'ww38152475d1bca752',
agentId: '1000003',
}
},
created() {
// 调取服务端signature
// this.wxConfig()
},
watch: {
// 通过config接口注入权限验证配置
// 所有需要使用JS-SDK的页面必须先注入配置信息,否则将无法调用(同一个url仅需调用一次,对于变化url的SPA(single-page application)的web app可在每次url变化时进行调用)
$router() {
wx.config({
beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: '123456', // 必填,企业微信的corpID
timestamp: this.timestamp, // 必填,生成签名的时间戳
nonceStr: this.nonceStr, // 必填,生成签名的随机串
signature: this.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
jsApiList: [], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
$route() {
this.wxConfig()
},
},
methods: {
wxConfig() {
getAgentTicket(window.location.href.split('#')[0]).then(({ data }) => {
let { timestamp, nonceStr, signature } = data
wx.agentConfig({
corpid: this.appId, // 必填,企业微信的corpid,必须与当前登录的企业一致
agentid: this.agentId, // 必填,企业微信的应用id (e.g. 1000247)
timestamp, // 必填,生成签名的时间戳
nonceStr, // 必填,生成签名的随机串
signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
jsApiList: ['sendChatMessage'], //必填
success: (res) => {
// 回调
},
fail: (res) => {
if (res.errMsg.indexOf('function not exist') > -1) {
alert('版本过低请升级')
}
},
})
})
},
_wxConfig() {
// 获取企业的jsapi_ticket
getAppTicket(window.location.href).then(({ data }) => {
let { timestamp, nonceStr, signature } = data
wx.config({
beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: this.appId, // 必填,企业微信的corpID
timestamp, // 必填,生成签名的时间戳
nonceStr, // 必填,生成签名的随机串
signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
jsApiList: ['getContext', 'sendChatMessage'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
})
wx.ready(() => {
// config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
getAgentTicket(window.location.href).then(({ data }) => {
let { timestamp, nonceStr, signature } = data
wx.agentConfig({
corpid: this.appId, // 必填,企业微信的corpid,必须与当前登录的企业一致
agentid: this.agentId, // 必填,企业微信的应用id (e.g. 1000247)
timestamp, // 必填,生成签名的时间戳
nonceStr, // 必填,生成签名的随机串
signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
jsApiList: ['sendChatMessage'], //必填
success: (res) => {
// 回调
},
fail: (res) => {
if (res.errMsg.indexOf('function not exist') > -1) {
alert('版本过低请升级')
}
},
})
})
})
wx.error(function(res) {
console.error(res)
// config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
})
})
},
},
......
......@@ -5,12 +5,9 @@ const service = window.CONFIG.services.wecom + '/chat'
* 侧边栏列表
* @param {*} params
*/
export function getTypeList(params) {
export function getTypeList() {
return request({
url: service + '/side/list',
params: {
h5: 1,
},
url: service + '/side/h5List',
})
}
......
import request from '@/utils/request'
const service = window.CONFIG.services.wecom + '/ticket'
import config from '@/config'
const service = config.services.wecom + '/ticket'
/**
* 获取应用的jsapi_ticket
......@@ -28,46 +29,11 @@ export function getAppTicket(url) {
}
/**
* 收藏列表(h5我的)
* @param {*} userId
*/
export function getCollectionList(userId) {
return request({
url: service + '/collection/list',
params: {
userId,
},
})
}
/**
* 添加收藏
* @param {*} data
* {
materialId:素材id
userId:用户id
}
*/
export function addCollection(data) {
return request({
url: service + '/collection/addCollection',
method: 'post',
data,
})
}
/**
* 侧边栏抓取素材
* @param {*} data
* {
materialId:素材id
userId:用户id
}
* 获取企业的jsapi_ticket
* @param {*} url 页面url
*/
export function cancleCollection(data) {
export function getLoginUserId() {
return request({
url: service + '/collection/cancleCollection',
method: 'put',
data,
url: '/system/user/findCurrentLoginUser',
})
}
......@@ -24,8 +24,8 @@ function createAxios(baseURL) {
// console.log('res: ' + res)
const { data, status } = res
// code 0:成功,-1/其它:错误
if (status === 200 && data.code === 0) {
return JSON.stringify(data.result) ? data.result : data.data
if (status === 200 && data.code === 200) {
return data
} else if (data.code === 201) {
// Message.error({
// content: `产品已存在`,
......
......@@ -32,7 +32,10 @@ export default {
methods: {
getList() {
this.loading = true
;(this.userId ? getCollectionList : getMaterialList)()
;(this.sideId
? getMaterialList(this.sideId)
: getCollectionList(this.userId)
)
.then(({ rows, total }) => {
this.list = rows
this.loading = false
......@@ -51,7 +54,67 @@ export default {
isCollected(id) {
return this.collectList.includes(id)
},
send() {},
send(data) {
let entry = undefined
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'].includes(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]
wx.invoke('sendChatMessage', mes, function(res) {
if (res.err_msg == 'sendChatMessage:ok') {
//发送成功
}
})
} else {
//错误处理
}
})
},
collect(materialId) {
;(this.isCollected(materialId) ? cancleCollection : addCollection)({
userId,
......@@ -73,13 +136,13 @@ export default {
@load="getList"
>
<div v-for="(item, index) in list" class="list" :key="index">
<div class="title">dsdsds</div>
<div class="title">{{ item.content }}</div>
<div class="info">
素材库
{{ item.content }}
<span>2020/2/4</span>
<div class="fr flex">
<div class="action" @click="send">发送</div>
<div class="action" @click="send(item)">发送</div>
<div class="action" @click="collect(item.id)">
{{ isCollected(item.id) ? '已' : '' }}收藏
</div>
......
<script>
import { getLoginUserId } from '@/api/common'
import { getTypeList } from '@/api/chat'
import List from './List'
export default {
......@@ -7,17 +8,19 @@ export default {
data() {
return {
keywords: '',
active: 2,
active: 0,
list: [],
loading: false,
finished: false,
show: false,
userId: '',
}
},
watch: {},
computed: {},
created() {
this.getList()
this.getUserId()
},
mounted() {},
methods: {
......@@ -26,6 +29,11 @@ export default {
this.list = rows
})
},
getUserId() {
getLoginUserId().then(({ data }) => {
this.userId = data
})
},
search() {},
add() {},
},
......@@ -45,10 +53,16 @@ export default {
</template> -->
</van-search>
<van-tabs v-model="active">
<van-tab title="标签 1">
<List></List>
<van-tab title="我的">
<List :userId="userId"></List>
</van-tab>
<van-tab
:title="item.sideName"
v-for="(item, index) in list"
:key="index"
>
<List :sideId="item.sideId" :userId="userId"></List>
</van-tab>
<van-tab title="标签 2"><List></List></van-tab>
</van-tabs>
<!-- <van-dialog
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!