Commit 21fc1735 by xinla

--no commit message

1 parent a963bda2
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
ENV = 'development' ENV = 'development'
# 基础api(根据实际情况,自行配置,下为示例) # 基础api(根据实际情况,自行配置,下为示例)
VUE_APP_BASE_API = 'http://demo.linkwechat.cn/prod-api' VUE_APP_BASE_API = 'http://demo.linkwechat.cn/dev-api'
# 路由基础路径 # 路由基础路径
VUE_APP_BASE_URL = '/' VUE_APP_BASE_URL = '/'
\ No newline at end of file \ No newline at end of file
# 测试环境配置 # 测试环境配置
ENV = 'test'
# 打包环境变量
NODE_ENV = 'production'
# 运行环境变量
VUE_APP_ENV = 'test'
# 基础api # 基础api
VUE_APP_BASE_API = 'http://demo.linkwechat.cn/dev-api' VUE_APP_BASE_API = 'http://demo.linkwechat.cn/dev-api'
# 路由基础路径 # 路由基础路径
VUE_APP_BASE_URL = '/mobile/' VUE_APP_BASE_URL = '/devMobile/'
...@@ -6,14 +6,14 @@ export default { ...@@ -6,14 +6,14 @@ export default {
name: 'App', name: 'App',
provide() { provide() {
return { return {
reload: this.reload reload: this.reload,
} }
}, },
data() { data() {
return { return {
corpId: '', corpId: '',
agentId: '', agentId: '',
isRouterAlive: true isRouterAlive: true,
} }
}, },
async created() { async created() {
...@@ -30,20 +30,22 @@ export default { ...@@ -30,20 +30,22 @@ export default {
this.agentId = query.agentId this.agentId = query.agentId
// this.$toast('agentId:' + this.agentId) // this.$toast('agentId:' + this.agentId)
this.$router.onReady(() => { this.$router.onReady(async () => {
const noAuth = this.$router.app.$route.meta ? this.$router.app.$route.meta.noAuth : false const noAuth = this.$router.app.$route.meta ? this.$router.app.$route.meta.noAuth : false
if (!code && !noAuth) { if (!code && !noAuth) {
this.$toast('未获得授权') this.$toast('未获得授权')
} }
const noGetUser = this.$router.app.$route.meta ? this.$router.app.$route.meta.noAuth : false
if (!code || noGetUser) {
// this.$toast('未获得授权')
return
}
let { data } = await getUserInfo(code, this.agentId)
this.$store.state.userId = data.userId
}) })
if (!code) {
// this.$toast('未获得授权')
return
}
let { data } = await getUserInfo(code, this.agentId)
this.$store.state.userId = data.userId
// this.$toast('userId:' + this.$store.state.userId) // this.$toast('userId:' + this.$store.state.userId)
}, },
watch: { watch: {
...@@ -53,7 +55,7 @@ export default { ...@@ -53,7 +55,7 @@ export default {
// this.wxConfig() // this.wxConfig()
const noAuth = route.meta ? route.meta.noAuth : false const noAuth = route.meta ? route.meta.noAuth : false
!noAuth && this.wxConfig() !noAuth && this.wxConfig()
} },
}, },
methods: { methods: {
reload() { reload() {
...@@ -82,7 +84,7 @@ export default { ...@@ -82,7 +84,7 @@ export default {
'openEnterpriseChat', 'openEnterpriseChat',
'shareToExternalContact', 'shareToExternalContact',
'shareToExternalChat', 'shareToExternalChat',
'navigateToAddCustomer' 'navigateToAddCustomer',
], //必填 ], //必填
success: (res) => { success: (res) => {
// 回调 // 回调
...@@ -95,10 +97,10 @@ export default { ...@@ -95,10 +97,10 @@ export default {
if (res.errMsg.indexOf('function not exist') > -1) { if (res.errMsg.indexOf('function not exist') > -1) {
alert('版本过低请升级') alert('版本过低请升级')
} }
} },
}) })
} catch (error) {} } catch (error) {}
} },
// 丢弃 // 丢弃
// _wxConfig() { // _wxConfig() {
// // 获取企业的jsapi_ticket // // 获取企业的jsapi_ticket
...@@ -142,7 +144,7 @@ export default { ...@@ -142,7 +144,7 @@ export default {
// }) // })
// }) // })
// }, // },
} },
} }
</script> </script>
<template> <template>
......
...@@ -45,9 +45,24 @@ export function getUserInfo(code, agentId) { ...@@ -45,9 +45,24 @@ export function getUserInfo(code, agentId) {
} }
/** /**
* 获取微信授权用户信息 * 获取授权用户openid
* @param {*} code 授权码 * @param {*} code
* @returns
*/ */
export function getWechatUserInfo(code) { export function getUserOpenid(code) {
return request({ url: `http://demo.linkwechat.cn:8090/weixin/auth/getToken?code=${code}` }) return request({ url: `http://demo.linkwechat.cn:8090/weixin/auth/getToken?code=${code}` })
} }
/**
* 获取微信授权用户信息
* @param {*} openId
*/
export function getWechatUserInfo(openId) {
return request({
url: `http://demo.linkwechat.cn:8090/weixin/auth/getUserInfo`,
params: {
openId,
lang: 'zh_CN',
},
})
}
import request from '@/utils/request' import request from '@/utils/request'
const wecom = window.CONFIG.services.wecom
const service = wecom + '/RedEnvelopes'
export function getList(data) { /**
* 获取企业红包模版
* @param {*} sceneType 1:客户 2:客群
* @returns
*/
export function getList(sceneType) {
return request({ return request({
url: '/wecom/seas/findEmployeeCustomer', url: service + '/findCompanyRedEnvelopes',
params: data, params: {
sceneType,
},
}) })
} }
export function setState(data) { /**
* 为客户发送个人红包
* @param {*} data
* {
"redEnvelopeAmount": "2.00",
"redEnvelopeName": "个人客户红包",
"sendUserId": "45DuXiangShangQingXie",
"externalUserId": "wmiGuBCgAA-3Xa7nUo7-8q492q0nmZ5A"
}
* @returns
*/
export function sendCustomerPersonalRedPacket(data) {
return request({
url: service + '/sendReEnvelopesToCustomer',
method: 'post',
data: data,
})
}
/**
* 为客户发送企业红包
* @param {*} data
{
"redenvelopesId": "1494182309006471169",
"sendUserId": "45DuXiangShangQingXie",
"externalUserId": "wmiGuBCgAA-3Xa7nUo7-8q492q0nmZ5A"
}
* @returns
*/
export function sendCustomerEnterpriseRedPacket(data) {
return request({
url: service + '/sendCompanyEnvelopesToCustomer',
method: 'post',
data: data,
})
}
/**
* 为客户群发送个人红包
* @param {*} data
{
"redEnvelopeAmount": "28", // 红包金额
"redEnvelopeName": "队起单元", // 红包名
"redEnvelopeNum": 45, // 红包数量
"sendUserId": "31", // 发送人id
"redEnvelopesType":1, // 2, 红包类型 1: 普通红包 2:拼手气红包
"chatId": "59" // 群id
}
* @returns
*/
export function sendCustomerGroupPersonalRedPacket(data) {
return request({
url: service + '/sendPersonReEnvelopesToGroup',
method: 'post',
data: data,
})
}
/**
* 为客户群发送企业红包
* @param {*} data
{
"redenvelopesId": "1494182309006471169", // 红包id
"redEnvelopeNum": 17,
"chatId": "88",
"sendUserId": "76",
"redEnvelopesType": 25
}
* @returns
*/
export function sendCustomerGroupEnterpriseRedPacket(data) {
return request({ return request({
url: '/wecom/seas/setState', url: service + '/sendCompanyEnvelopesToGroup',
method: 'post', method: 'post',
data: data, data: data,
}) })
} }
/**
* 红包领取接口
* @param {*} params
{
"orderNo": "1494182309006471169", // 订单id
"openId": 17, // 客户公众号id
"appId": "88", // 微信公众号id
"externalUserid": "76", // 客户企微id
}
* @returns
*/
export function receiveRedPacket(params) {
return request({
url: service + '/receiveRedEnvelopes',
params,
})
}
/**
* 红包领取列表
* @param {*}
{
"orderNo": "1494182309006471169", // 订单id
"chatId": 17, // 群id
"externalUserid": "76", // 客户id
}
* @returns
*/
export function getReceiveList(params) {
return request({
url: service + '/receiveRedEnvelopesLists',
params,
})
}
...@@ -123,7 +123,17 @@ const routes = [ ...@@ -123,7 +123,17 @@ const routes = [
title: '红包', title: '红包',
}, },
}, },
// 红包 // 领取红包
{
path: '/redPacketReceive',
name: 'redPacketReceive',
component: () => import('../views/redPacket/receive'),
meta: {
title: '领取红包',
noAuth: true,
},
},
// 微信授权回调
{ {
path: '/authCallback', path: '/authCallback',
name: 'authCallback', name: 'authCallback',
...@@ -131,6 +141,7 @@ const routes = [ ...@@ -131,6 +141,7 @@ const routes = [
meta: { meta: {
title: '微信授权回调', title: '微信授权回调',
noAuth: true, noAuth: true,
noGetUser: true,
}, },
}, },
] ]
......
import { getUserOpenid, getWechatUserInfo } from '@/api/common'
/** /**
* query请求路径参数转为对象 * query请求路径参数转为对象
* @param {*} url * @param {*} url
...@@ -21,6 +22,21 @@ export function param2Obj(url) { ...@@ -21,6 +22,21 @@ export function param2Obj(url) {
} }
/** /**
* Obj转为路径query请求参数
* @param {*} obj
*/
export function obj2query(obj) {
if (!obj) return ''
return Object.keys(obj)
.map((key) => {
if (obj[key] === undefined) return ''
return key + '=' + obj[key]
})
.filter((e) => !!e)
.join('&')
}
/**
* 获取query请求参数中name对应的值 * 获取query请求参数中name对应的值
* @param string name * @param string name
*/ */
...@@ -40,6 +56,48 @@ export function getQueryValue(name) { ...@@ -40,6 +56,48 @@ export function getQueryValue(name) {
return '' return ''
} }
export function getWxCode() {
let userinfo = localStorage.getItem('userinfo')
//取缓存中的用户信息
if (userinfo) {
try {
userinfo = JSON.parse(userinfo)
} catch (error) {
alert(error)
}
return
}
//缓存中没有用户信息,进入授权流程
let appid = 'wx863c031a74f589a0' // 公众号appid
// let appid = 'wx8bfe6bc2ca5c45ae' // 公众号appid
let code = getQueryValue('code') //是否存在code
let local = window.location.origin.includes('localhost')
? 'http://h5.linkwechat.cn/test.html'
: window.location.href
// let local = 'http://h5.x*****o.com/'
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`
return false
// 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`;
}
// getUserOpenid(code)
// .then(({ data }) => {
// if (data && data.openId) {
// localStorage.setItem('userinfo', JSON.stringify(data))
// return getWechatUserInfo(data.openId)
// }
// })
// .then(({ data }) => {
// let unionId = data.unionId
// })
}
// 日期时间格式化 // 日期时间格式化
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) {
......
<script>
import {
sendCustomerPersonalRedPacket,
sendCustomerEnterpriseRedPacket,
sendCustomerGroupPersonalRedPacket,
sendCustomerGroupEnterpriseRedPacket,
receiveRedPacket,
getReceiveList,
} from '@/api/redPacket.js'
import { param2Obj, getWxCode } from '@/utils/index.js'
export default {
name: '',
components: {},
data() {
return {
list: [],
opened: false,
redPacket: {},
}
},
computed: {},
watch: {},
created() {
this.init()
this.sendRedPacket()
},
mounted() {},
methods: {
init() {
getWxCode()
},
sendRedPacket() {
this.$toast.loading({
duration: 0,
forbidClick: true,
})
let form = {}
let query = param2Obj(window.location.search)
let hash = param2Obj(window.location.hash)
Object.assign(form, query, hash)
this.redPacket = form
let request = ''
if (form.sceneType == 1) {
request = {
personal: sendCustomerPersonalRedPacket,
enterprise: sendCustomerEnterpriseRedPacket,
}[form.redPacketType]
} else {
request = {
personal: sendCustomerGroupPersonalRedPacket,
enterprise: sendCustomerGroupEnterpriseRedPacket,
}[form.redPacketType]
}
request(form).then((res) => {
this.$toast.clear()
})
},
receive() {
this.$toast.loading({
duration: 0,
forbidClick: true,
})
receiveRedPacket()
.then(() => {
return getReceiveList()
})
.then(({ data }) => {
this.opened = true
this.list = data
this.$toast.clear()
})
},
},
}
</script>
<template>
<div class="receive">
<div v-if="!opened" class="redPacketThumb" @click="receive"></div>
<div v-else>
<div class="ac">
<van-image width="80" height="80" :src="11" />
<div class="title">
合肥仟微网络科技有限公司的红包
<span class="red-icon">{{ { 1: '普', 2: '拼' }[redPacket.redEnvelopesType] }}</span>
</div>
<div>{{ { 1: '普通红包', 2: '拼手气红包' }[redPacket.redEnvelopesType] }}</div>
<div>{{ redPacket.redEnvelopeAmount }}</div>
<div>已存入零钱,可直接使用</div>
</div>
<van-cell-group
:title="
`己领取${list.length}/${redPacket.redEnvelopeNum}个红包,共${redPacket.redEnvelopeNum}/${redPacket.redEnvelopeAmount}元`
"
>
<van-cell center v-for="(item, index) in list" :key="index">
<template #title>
<van-image width="80" height="80" :src="item.materialUrl" />
<div class="brf-d">
<div>{{ item.name }}</div>
<div>{{ item.time }}</div>
</div>
</template>
<div class="">
{{ item.money }}
</div>
</van-cell>
</van-cell-group>
</div>
</div>
</template>
<style lang="less" scoped>
.redPacketThumb {
height: calc(100vh - 30px);
margin: 15px;
background: url('../../assets/redPacketThumb.png') center top / 100% auto no-repeat;
}
.red-icon {
margin-left: 20px;
padding: 2px 4px;
border-radius: 3px;
background: #af9565;
}
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!