Commit 035a3d9b by xinla

--no commit message

1 parent 22005fef
...@@ -31,7 +31,8 @@ export function getAppTicket(url) { ...@@ -31,7 +31,8 @@ export function getAppTicket(url) {
/** /**
* 获取登录用户id * 获取登录用户id
* @param {*} url 页面url * @param {*} code 授权码
* @param {*} agentId 应用agentId
*/ */
export function getUserInfo(code, agentId) { export function getUserInfo(code, agentId) {
return request({ return request({
...@@ -41,4 +42,12 @@ export function getUserInfo(code, agentId) { ...@@ -41,4 +42,12 @@ export function getUserInfo(code, agentId) {
agentId, agentId,
}, },
}) })
}
\ No newline at end of file \ No newline at end of file
}
/**
* 获取微信授权用户信息
* @param {*} code 授权码
*/
export function getWechatUserInfo(code) {
return request({ url: `http://demo.linkwechat.cn:8090/weixin/auth/getToken?code=${code}` })
}
...@@ -67,6 +67,11 @@ const routes = [ ...@@ -67,6 +67,11 @@ const routes = [
{ {
path: '/task', path: '/task',
// name: 'task', // name: 'task',
hidden: true,
meta: {
title: '',
noAuth: true,
},
component: () => import('../views/communityOperating/task/index'), component: () => import('../views/communityOperating/task/index'),
children: [ children: [
{ {
...@@ -89,11 +94,6 @@ const routes = [ ...@@ -89,11 +94,6 @@ const routes = [
}, },
}, },
], ],
hidden: true,
meta: {
title: '',
noAuth: true,
},
}, },
// 关键词群 // 关键词群
{ {
...@@ -123,6 +123,16 @@ const routes = [ ...@@ -123,6 +123,16 @@ const routes = [
title: '红包', title: '红包',
}, },
}, },
// 红包
{
path: '/authCallback',
name: 'authCallback',
component: () => import('../views/authCallback'),
meta: {
title: '微信授权回调',
noAuth: true,
},
},
] ]
const router = new VueRouter({ const router = new VueRouter({
......
...@@ -20,6 +20,26 @@ export function param2Obj(url) { ...@@ -20,6 +20,26 @@ export function param2Obj(url) {
) )
} }
/**
* 获取query请求参数中name对应的值
* @param string name
*/
export function getQueryValue(name) {
let url = window.location.href
let search = decodeURIComponent(url).split('?')[1]
search = search && search.split('#')[0]
if (!search) {
return ''
}
let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
let r = search.match(reg)
if (r != null) {
return r[2]
}
return ''
}
// 日期时间格式化 // 日期时间格式化
export function dateFormat(dateString, fmt = 'yyyy-MM-dd hh:mm:ss') { export function dateFormat(dateString, fmt = 'yyyy-MM-dd hh:mm:ss') {
if (!dateString) { if (!dateString) {
...@@ -34,7 +54,7 @@ export function dateFormat(dateString, fmt = 'yyyy-MM-dd hh:mm:ss') { ...@@ -34,7 +54,7 @@ export function dateFormat(dateString, fmt = 'yyyy-MM-dd hh:mm:ss') {
's+': date.getSeconds(), //秒 's+': date.getSeconds(), //秒
'q+': Math.floor((date.getMonth() + 3) / 3), //季度 'q+': Math.floor((date.getMonth() + 3) / 3), //季度
'S+': date.getMilliseconds(), //毫秒 'S+': date.getMilliseconds(), //毫秒
'w+': '星期' + '日一二三四五六'.charAt(date.getDay()) //星期 'w+': '星期' + '日一二三四五六'.charAt(date.getDay()), //星期
} }
if (/(y+)/.test(fmt)) { if (/(y+)/.test(fmt)) {
...@@ -43,7 +63,10 @@ export function dateFormat(dateString, fmt = 'yyyy-MM-dd hh:mm:ss') { ...@@ -43,7 +63,10 @@ export function dateFormat(dateString, fmt = 'yyyy-MM-dd hh:mm:ss') {
for (var k in o) { for (var k in o) {
if (new RegExp('(' + k + ')').test(fmt)) { if (new RegExp('(' + k + ')').test(fmt)) {
fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 || String(o[k]).length > 1 ? o[k] : '0' + o[k]) fmt = fmt.replace(
RegExp.$1,
RegExp.$1.length == 1 || String(o[k]).length > 1 ? o[k] : '0' + o[k]
)
} }
} }
......
<template>
<div class="home">
<div class="logo ac">linkWeCh13at</div>
</div>
</template>
<script>
import { getQueryValue } from '@/utils/index'
import { getWechatUserInfo } from '@/api/common'
export default {
name: 'authCallback',
data() {
return {
keyword: '',
active: 0,
list: [],
loading: false,
finished: false,
show: false,
// userId: this.$store.state.userId,
}
},
created() {
alert(1)
this.getWxCode()
},
methods: {
getWxCode() {
try {
let appid = 'wx863c031a74f589a0' // 公众号appid
// let appid = 'wx8bfe6bc2ca5c45ae' // 公众号appid
alert(2)
let code = getQueryValue('code') //是否存在code
alert(3)
let local = window.location.origin.includes('localhost')
? 'http://h5.linkwechat.cn/test.html'
: window.location.href
// let local = 'http://h5.x*****o.com/'
alert(code)
if (!code) {
//不存在就打开上面的地址进行授权
window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent(
local
)}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
// window.location.href =
// `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent(local)}&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect`;
} else {
this.getUserInfo(code)
}
} catch (error) {
alert(error)
this.$toast(JSON.stringify(error))
}
},
getUserInfo(code) {
getWechatUserInfo(code).then(({ data }) => {
if (data && data.openId) {
localStorage.setItem('userinfo', JSON.stringify(data))
alert(data.openId)
}
})
},
},
}
</script>
<style lang="less" scoped>
.logo {
margin: 0 auto;
width: 150px;
height: 50px;
line-height: 50px;
border: 2px solid #6582ff;
border-radius: 50px;
}
.router-link {
display: block;
text-align: center;
line-height: 40px;
}
</style>
...@@ -8,7 +8,8 @@ export function getUrlParam(name) { ...@@ -8,7 +8,8 @@ export function getUrlParam(name) {
return null return null
} }
export function getWxCode() { export function getWxCode() {
let appid = 'wx8bfe6bc2ca5c45ae' // 公众号appid let appid = 'wx863c031a74f589a0' // 公众号appid
// let appid = 'wx8bfe6bc2ca5c45ae' // 公众号appid
let code = getUrlParam('code') //是否存在code let code = getUrlParam('code') //是否存在code
let local = window.location.origin.includes('localhost') let local = window.location.origin.includes('localhost')
? 'http://h5.linkwechat.cn/test.html' ? 'http://h5.linkwechat.cn/test.html'
......
...@@ -7,8 +7,8 @@ export default { ...@@ -7,8 +7,8 @@ export default {
props: { props: {
type: { type: {
type: String, type: String,
default: '' default: '',
} },
}, },
data() { data() {
return { return {
...@@ -16,23 +16,23 @@ export default { ...@@ -16,23 +16,23 @@ export default {
timeRange: 7, timeRange: 7,
legend: { legend: {
num: ['员工单聊数'], num: ['员工单聊数'],
time: ['平均首次回复时长'] time: ['平均首次回复时长'],
}, },
// 日期范围 // 日期范围
dateRange: [], dateRange: [],
// 查询参数 // 查询参数
query: { query: {
beginTime: undefined, beginTime: undefined,
endTime: undefined endTime: undefined,
}, },
num: { num: {
xData: [], xData: [],
series: [] series: [],
}, },
time: { time: {
xData: [], xData: [],
series: [] series: [],
} },
} }
}, },
computed: {}, computed: {},
...@@ -48,17 +48,17 @@ export default { ...@@ -48,17 +48,17 @@ export default {
this.loading = true this.loading = true
getUserChatRank(this.query) getUserChatRank(this.query)
.then(({ rows }) => { .then(({ data }) => {
this.num.series = rows.map((e) => e.chatCnt) this.num.series = data.map((e) => e.chatCnt)
this.num.xData = rows.map((e) => e.userName) this.num.xData = data.map((e) => e.userName)
}) })
.catch((e) => { .catch((e) => {
console.error(e) console.error(e)
}) })
getUserAvgReplyTimeRank(this.query) getUserAvgReplyTimeRank(this.query)
.then(({ rows }) => { .then(({ data }) => {
this.time.series = rows.map((e) => e.avgReplyTime) this.time.series = data.map((e) => e.avgReplyTime)
this.time.xData = rows.map((e) => e.userName) this.time.xData = data.map((e) => e.userName)
this.loading = false this.loading = false
}) })
.catch((e) => { .catch((e) => {
...@@ -83,8 +83,8 @@ export default { ...@@ -83,8 +83,8 @@ export default {
} else { } else {
this.dateRange = null this.dateRange = null
} }
} },
} },
} }
</script> </script>
...@@ -120,7 +120,7 @@ export default { ...@@ -120,7 +120,7 @@ export default {
:series="time.series" :series="time.series"
:option="{ :option="{
xAxis: [{ type: 'value' }], xAxis: [{ type: 'value' }],
yAxis: [{ type: 'category', data: time.xData }] yAxis: [{ type: 'category', data: time.xData }],
}" }"
></ChartBar> ></ChartBar>
</el-col> </el-col>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!