Commit 0b0758fa by xinla

h5配置修改

1 parent 4ba1ec81
<script> <script>
import { getUserInfo } from '@/api/common'
import { getAgentTicket, getAppTicket } from '@/api/common' import { getAgentTicket, getAppTicket } from '@/api/common'
import { param2Obj } from '@/utils/index'
export default { export default {
name: 'App', name: 'App',
data() { data() {
return { return {
appId: '', corpId: '',
agentId: '1000005', agentId: '',
} }
}, },
created() {}, async created() {
// http://106.13.201.219/?code=xxx&state=linkwechat#/route
// console.log('routerbeforeCreate', this.$route);
// this.$dialog({ message: 'url' + JSON.stringify(window.location) })
let query = param2Obj(window.location.search)
let code = query.code
this.corpId = query.corpId
this.agentId = query.agentId
if (!code) {
this.$toast('未获得授权')
return
}
let { data } = await getUserInfo(code, query.agentId)
this.$store.state.userId = data.userId
// this.$toast('userId:' + this.$store.state.userId)
},
watch: { watch: {
// 通过config接口注入权限验证配置 // 通过config接口注入权限验证配置
// 所有需要使用JS-SDK的页面必须先注入配置信息,否则将无法调用(同一个url仅需调用一次,对于变化url的SPA(single-page application)的web app可在每次url变化时进行调用) // 所有需要使用JS-SDK的页面必须先注入配置信息,否则将无法调用(同一个url仅需调用一次,对于变化url的SPA(single-page application)的web app可在每次url变化时进行调用)
// $route() { $route() {
// this.wxConfig() this.wxConfig()
// }, },
}, },
methods: { methods: {
wxConfig() { wxConfig() {
getAgentTicket(window.location.href.split('#')[0]).then(({ data }) => { getAgentTicket(window.location.href.split('#')[0], this.agentId).then(
({ data }) => {
let { timestamp, nonceStr, signature } = data let { timestamp, nonceStr, signature } = data
wx.agentConfig({ wx.agentConfig({
debug: true, debug: true,
corpid: this.appId, // 必填,企业微信的corpid,必须与当前登录的企业一致 corpid: this.corpId, // 必填,企业微信的corpid,必须与当前登录的企业一致
agentid: this.agentId, // 必填,企业微信的应用id (e.g. 1000247) agentid: this.agentId, // 必填,企业微信的应用id (e.g. 1000247)
timestamp, // 必填,生成签名的时间戳 timestamp, // 必填,生成签名的时间戳
nonceStr, // 必填,生成签名的随机串 nonceStr, // 必填,生成签名的随机串
signature, // 必填,签名,见附录-JS-SDK使用权限签名算法 signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
jsApiList: ['sendChatMessage', 'getContext'], //必填 jsApiList: [
'sendChatMessage',
'getContext',
'getCurExternalContact',
], //必填
success: (res) => { success: (res) => {
// 回调 // 回调
// this.$toast('agentId成功:') // this.$toast('agentId成功:')
...@@ -39,7 +61,8 @@ export default { ...@@ -39,7 +61,8 @@ export default {
} }
}, },
}) })
}) }
)
}, },
// 丢弃 // 丢弃
// _wxConfig() { // _wxConfig() {
...@@ -49,7 +72,7 @@ export default { ...@@ -49,7 +72,7 @@ export default {
// wx.config({ // wx.config({
// beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题 // beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
// debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 // debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
// appId: this.appId, // 必填,企业微信的corpID // corpId: this.corpId, // 必填,企业微信的corpID
// timestamp, // 必填,生成签名的时间戳 // timestamp, // 必填,生成签名的时间戳
// nonceStr, // 必填,生成签名的随机串 // nonceStr, // 必填,生成签名的随机串
// signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法 // signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
...@@ -60,7 +83,7 @@ export default { ...@@ -60,7 +83,7 @@ export default {
// getAgentTicket(window.location.href).then(({ data }) => { // getAgentTicket(window.location.href).then(({ data }) => {
// let { timestamp, nonceStr, signature } = data // let { timestamp, nonceStr, signature } = data
// wx.agentConfig({ // wx.agentConfig({
// corpid: this.appId, // 必填,企业微信的corpid,必须与当前登录的企业一致 // corpid: this.corpId, // 必填,企业微信的corpid,必须与当前登录的企业一致
// agentid: this.agentId, // 必填,企业微信的应用id (e.g. 1000247) // agentid: this.agentId, // 必填,企业微信的应用id (e.g. 1000247)
// timestamp, // 必填,生成签名的时间戳 // timestamp, // 必填,生成签名的时间戳
// nonceStr, // 必填,生成签名的随机串 // nonceStr, // 必填,生成签名的随机串
......
...@@ -6,12 +6,12 @@ const service = config.services.wecom ...@@ -6,12 +6,12 @@ const service = config.services.wecom
* 获取应用的jsapi_ticket * 获取应用的jsapi_ticket
* @param {*} url 页面url * @param {*} url 页面url
*/ */
export function getAgentTicket(url) { export function getAgentTicket(url, agentId) {
return request({ return request({
url: service + '/ticket/getAgentTicket', url: service + '/ticket/getAgentTicket',
params: { params: {
url, url,
agentId: '1000005', agentId,
}, },
}) })
} }
...@@ -33,12 +33,12 @@ export function getAppTicket(url) { ...@@ -33,12 +33,12 @@ export function getAppTicket(url) {
* 获取登录用户id * 获取登录用户id
* @param {*} url 页面url * @param {*} url 页面url
*/ */
export function getUserInfo(code) { export function getUserInfo(code, agentId) {
return request({ return request({
url: service + '/user/getUserInfo', url: service + '/user/getUserInfo',
params: { params: {
code, code,
agentId: '1000005', agentId,
}, },
}) })
} }
import Vue from "vue"; import Vue from 'vue'
import Vuex from "vuex"; import Vuex from 'vuex'
Vue.use(Vuex); Vue.use(Vuex)
export default new Vuex.Store({ export default new Vuex.Store({
state: {}, state: {
userId: '',
},
mutations: {}, mutations: {},
actions: {}, actions: {},
modules: {} modules: {},
}); })
/**
* 请求路径参数转为对象
* @param {*} url
*/
export function param2Obj(url) {
const search = decodeURIComponent(url)
.split('?')[1]
.split('#')[0]
if (!search) {
return {}
}
return JSON.parse(
'{"' +
search
.replace(/"/g, '\\"')
.replace(/&/g, '","')
.replace(/=/g, '":"') +
'"}'
)
}
<script> <script>
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 {
...@@ -13,51 +12,18 @@ export default { ...@@ -13,51 +12,18 @@ export default {
loading: false, loading: false,
finished: false, finished: false,
show: false, show: false,
userId: '', // userId: this.$store.state.userId,
} }
}, },
watch: {}, watch: {},
computed: {}, computed: {
beforeCreate() { userId() {
// http://106.13.201.219/?auth_code=xxx#/authWehatCallback return this.$store.state.userId
// console.log('routerbeforeCreate', this.$route);
// let auth_code = location.search
// .slice(1)
// .split('&')[0]
// .split('=')[1]
// 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)
// })
}, },
},
beforeCreate() {},
created() { created() {
let auth_code = location.search // this.$toast('userId:' + this.$store.state.userId)
.slice(1)
.split('&')[0]
.split('=')[1]
if (!auth_code) {
this.$toast('未获得授权')
return
}
getUserInfo(auth_code)
.then(({ data }) => {
this.userId = data.userId
// this.$toast('userId:' + this.userId)
})
.catch((err) => {
Dialog.confirm({
title: '标题',
message: err,
})
})
this.getList() this.getList()
}, },
mounted() {}, mounted() {},
......
...@@ -341,71 +341,136 @@ export default { ...@@ -341,71 +341,136 @@ export default {
show: false, show: false,
// 客户待办的弹出框开始 // 客户待办的弹出框开始
usershow: false, usershow: false,
conagency: "", // 待办内容 conagency: '', // 待办内容
// 待办日期 // 待办日期
dateagency: "", dateagency: '',
dateshow: false, dateshow: false,
minDate: new Date(2021, 0, 1), minDate: new Date(2021, 0, 1),
maxDate: new Date(2021, 12, 31), maxDate: new Date(2021, 12, 31),
// 待办时间 // 待办时间
timeagency: "", timeagency: '',
starttimeshow: false, starttimeshow: false,
endtimeshow: false, endtimeshow: false,
currentTime: "12:00", currentTime: '12:00',
startTime: "", startTime: '',
endTime: "", endTime: '',
// 客户待办的弹出框结束 // 客户待办的弹出框结束
actions: [{ name: "选项一" }, { name: "选项二" }, { name: "选项三" }], actions: [{ name: '选项一' }, { name: '选项二' }, { name: '选项三' }],
// 步骤条 // 步骤条
active: -1, active: -1,
// 客户轨迹 // 客户轨迹
// 待办动态 // 待办动态
todonewsshow: false, todonewsshow: false,
// 接口开始 // 接口开始
externalUserid: "", // 客户Id externalUserid: '', // 客户Id
userid: "", // 员工Id userId: '', // 员工Id
}
}; },
watch: {
'$store.state.userId'(val) {
this.userId = val
this.getDetail()
},
}, },
methods: { methods: {
getDetail() {
this.$toast.loading({
message: '正在加载...',
duration: 0,
forbidClick: true,
})
let entry = undefined
let _this = this
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',
'contact_profile',
].includes(entry)
) {
// _this.$toast.clear()
_this.$toast('入口错误:' + entry)
return
}
wx.invoke('getCurExternalContact', {}, function(resContact) {
if (resContact.err_msg == 'getCurExternalContact:ok') {
this.externalUserid = resContact.userId //返回当前外部联系人userId
// 获取客户详细信息
getCustomerInfo({
externalUserid: this.externalUserid,
userid: this.userId,
})
.then(({ data }) => {
_this.$toast.clear()
console.log(data)
_this.$dialog({
message: '获取客户失败:' + JSON.stringify(data),
})
})
.catch((err) => {
_this.$toast.clear()
console.log(err)
_this.$dialog({
message: '获取客户失败:' + JSON.stringify(err),
})
})
} else {
_this.$toast.clear()
//错误处理
_this.$dialog({
message: '获取客户id失败:' + JSON.stringify(resContact),
})
}
})
} else {
_this.$toast.clear()
//错误处理
_this.$dialog({ message: '进入失败:' + JSON.stringify(res) })
}
})
},
// 添加代办 // 添加代办
// 表单提交 // 表单提交
onSubmit() {}, onSubmit() {},
// 待办日期 // 待办日期
formatDate(dateagency) { formatDate(dateagency) {
return `${dateagency.getFullYear()}-${dateagency.getMonth() + return `${dateagency.getFullYear()}-${dateagency.getMonth() +
1}-${dateagency.getDate()}`; 1}-${dateagency.getDate()}`
}, },
onConfirm(dateagency) { onConfirm(dateagency) {
this.dateshow = false; this.dateshow = false
this.dateagency = this.formatDate(dateagency); this.dateagency = this.formatDate(dateagency)
}, },
// 待办时间 // 待办时间
timecancel() { timecancel() {
this.starttimeshow = false; this.starttimeshow = false
}, },
starttimeconfirm(value) { starttimeconfirm(value) {
this.startTime = value; this.startTime = value
this.starttimeshow = false; this.starttimeshow = false
this.endtimeshow = true; this.endtimeshow = true
}, },
endtimeconfirm(value) { endtimeconfirm(value) {
this.endTime = value; this.endTime = value
this.endtimeshow = false; this.endtimeshow = false
let time = ""; let time = ''
if (this.startTime > this.endTime) { if (this.startTime > this.endTime) {
time = this.startTime; time = this.startTime
this.startTime = this.endTime; this.startTime = this.endTime
this.endTime = time; this.endTime = time
} }
// console.log(this.startTime, this.endTime); // console.log(this.startTime, this.endTime);
this.endtimeshow = false; this.endtimeshow = false
this.timeagency = this.formatTime(); this.timeagency = this.formatTime()
}, },
formatTime() { formatTime() {
return `${this.startTime}-${this.endTime}`; return `${this.startTime}-${this.endTime}`
}, },
// 待办动态 // 待办动态
// 点击删除按钮 // 点击删除按钮
...@@ -413,44 +478,32 @@ export default { ...@@ -413,44 +478,32 @@ export default {
goRoute() { goRoute() {
this.$router.push({ this.$router.push({
path: "/detail", path: '/detail',
query: { query: {
// type // type
}, },
}); })
}, },
detailGoRoute() { detailGoRoute() {
this.$router.push({ this.$router.push({
path: "/community", path: '/community',
query: { query: {
// type // type
}, },
}); })
}, },
// 第一层标签 // 第一层标签
userLabel() { userLabel() {
console.log(123); console.log(123)
}, },
// 第二层标签 // 第二层标签
changeLabel() { changeLabel() {
console.log(456); console.log(456)
}, },
saveInfo() {}, saveInfo() {},
}, },
created() { created() {},
// 获取客户详细信息 }
getCustomerInfo({
externalUserid: this.externalUserid,
userid: this.userid,
})
.then(({ data }) => {
console.log(data);
})
.catch((err) => {
console.log(err);
});
},
};
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!