1052 lines
36 KiB
JavaScript
1052 lines
36 KiB
JavaScript
var link = document.location.href
|
||
var refer = document.referrer
|
||
var tool = {
|
||
setCookie: function (cname, cvalue, cday) {
|
||
var d = new Date()
|
||
d.setTime(d.getTime() + cday * 24 * 60 * 60 * 1000)
|
||
var expires = "expires=" + d.toGMTString()
|
||
document.cookie = cname + "=" + cvalue + "; " + expires + ";path=/"
|
||
},
|
||
getCookie: function (cname) {
|
||
var name = cname + "="
|
||
var ca = document.cookie.split(";")
|
||
for (var i = 0; i < ca.length; i++) {
|
||
var c = ca[i].trim()
|
||
if (c.indexOf(name) == 0) return c.substring(name.length, c.length)
|
||
}
|
||
return ""
|
||
},
|
||
checkCookie: function () {
|
||
var qd = this.getCookie("qd")
|
||
if (qd != "") {
|
||
console.log(qd)
|
||
} else {
|
||
console.log(link)
|
||
}
|
||
}
|
||
}
|
||
// 按钮追踪
|
||
var btn = "顶部按钮"
|
||
function toApply(data) {
|
||
if (data == 0) {
|
||
btn = "顶部导航栏按钮"
|
||
} else if (data == 1) {
|
||
btn = "banner按钮"
|
||
} else if (data == 2) {
|
||
btn = "侧边栏按钮"
|
||
} else if (data == 3) {
|
||
btn = "中间按钮"
|
||
} else if (data == 31) {
|
||
btn = "在线版试用按钮"
|
||
} else if (data == 32) {
|
||
btn = "标准版试用按钮"
|
||
} else if (data == 33) {
|
||
btn = "企业版试用按钮"
|
||
} else if (data == 9) {
|
||
btn = "底部按钮"
|
||
} else {
|
||
btn = data
|
||
}
|
||
sessionStorage.setItem("btn", btn)
|
||
tool.setCookie("btn", btn, 1)
|
||
}
|
||
sessionStorage.setItem("currentLink", link)
|
||
tool.setCookie("currentLink", link, 1)
|
||
function IsMobile() { // 判断是否是移动端
|
||
let info = navigator.userAgent
|
||
let agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPod", "iPad"]
|
||
for (let i = 0; i < agents.length; i++) {
|
||
if (info.indexOf(agents[i]) >= 0) return true
|
||
}
|
||
return false
|
||
}
|
||
// 来源链接判断----sessionStorage和cookie--------------重要
|
||
function getSourceUrl() {
|
||
const checkLink = (link, substrings) => substrings.some(substring => link.includes(substring));
|
||
const substrings = ["baidu.com", "medium=CPC", "medium=cpc", "hmsr", "so.com", "sogou.com", "media=sogou", "zhihu", "知乎", "%E7%9F%A5%E4%B9%8E", "sm.cn", "toutiao", "bing.com", "google.com", "weishiwei", "chinaso.com", "bd_vid"];
|
||
const setQd = (qd) => {
|
||
sessionStorage.setItem("qd", qd);
|
||
tool.setCookie("qd", qd, 1);
|
||
}
|
||
const getQd = () => sessionStorage.getItem("qd") || tool.getCookie("qd");
|
||
if (refer == "" || refer == null || checkLink(link, substrings)) {
|
||
setQd(link);
|
||
} else {
|
||
if (!getQd() || checkLink(refer, substrings)) {
|
||
setQd(refer);
|
||
}
|
||
}
|
||
return getQd() || refer || link;
|
||
}
|
||
var sourceUrl = getSourceUrl() //来源链接
|
||
function getUrlData(link = location.href) {//获取url中的参数
|
||
let urlData = {}
|
||
if (link.indexOf("?") != -1) {
|
||
let index = link.lastIndexOf("?")
|
||
let url = link.substring(index, link.length)
|
||
let str = url.substr(1)
|
||
let strs = str.split("&")
|
||
for (let i = 0; i < strs.length; i++) {
|
||
try {
|
||
urlData[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1])
|
||
} catch (error) {
|
||
urlData[strs[i].split("=")[0]] = strs[i].split("=")[1]
|
||
}
|
||
}
|
||
}
|
||
return urlData
|
||
}
|
||
const urlParam = getUrlData(sourceUrl) || {}
|
||
let website_device = "pc"
|
||
if (window.navigator && /Mobile|Android|webOS|iPhone|iPad|Phone/i.test(navigator.userAgent)) {
|
||
website_device = "mobile"
|
||
}
|
||
let website_url = sourceUrl //来源链接
|
||
let website_landing_page_type = "hollycrm," + website_device //落地页类型
|
||
let website_contact_channel = "wxwork" //联络渠道
|
||
/* -------------- 推广媒体 -------------- */
|
||
function websiteMedia() {
|
||
let media = "no"
|
||
if (sourceUrl.indexOf("baidu") > -1 || sourceUrl.indexOf("百度") > -1 || sourceUrl.indexOf("aladdin") > -1) {
|
||
media = "baidu,seo"
|
||
if (sourceUrl.indexOf("medium=cpc") > -1 || sourceUrl.indexOf("zhidao.baidu") > -1 || sourceUrl.indexOf("百度,SEM") > -1) {
|
||
media = "baidu,sem"
|
||
}
|
||
if (sourceUrl.indexOf("aladdin") > -1) {
|
||
media = "baidu,aladdin"
|
||
}
|
||
if (sourceUrl.indexOf("baidufeed") > -1) {
|
||
media = "baidu,baidufeed"
|
||
}
|
||
}
|
||
if (sourceUrl.indexOf("so.com") > -1 || sourceUrl.indexOf("media=360") > -1 || sourceUrl.indexOf("source=360") > -1) {
|
||
media = "360,seo"
|
||
if (sourceUrl.indexOf("medium=cpc") > -1 || sourceUrl.indexOf("360SEM") > -1) {
|
||
media = "360,sem"
|
||
}
|
||
}
|
||
if (sourceUrl.indexOf("sogou.com") > -1 || sourceUrl.indexOf("media=sogou") > -1) {
|
||
media = "sogou,seo"
|
||
if (sourceUrl.indexOf("cpc") > -1) {
|
||
media = "sogou,sem"
|
||
}
|
||
}
|
||
if (sourceUrl.indexOf("zhihu") > -1 || sourceUrl.indexOf("知乎") > -1) {
|
||
media = "zhihu"
|
||
}
|
||
if (sourceUrl.indexOf("google.com") > -1) {
|
||
media = "google"
|
||
}
|
||
if (sourceUrl.indexOf("sm.cn") > -1) {
|
||
media = "sm"
|
||
}
|
||
if (sourceUrl.indexOf("bing.com") > -1 || sourceUrl.indexOf("bing.cn") > -1) {
|
||
media = "bing"
|
||
}
|
||
if (sourceUrl.indexOf("douban.com") > -1) {
|
||
media = "douban"
|
||
}
|
||
if (sourceUrl.indexOf("taobao.com") > -1) {
|
||
media = "taobao"
|
||
}
|
||
if (sourceUrl.indexOf("toutiao") > -1) {
|
||
media = "toutiao"
|
||
}
|
||
if (sourceUrl.indexOf("a6.7x24cc.com") > -1) {
|
||
media = "a6"
|
||
}
|
||
return media
|
||
}
|
||
let website_promotion_media = websiteMedia()
|
||
/* --------------- 关键词 -------------- */
|
||
let website_keywords = urlParam.utm_term || urlParam.word || urlParam.wd || urlParam.hmkw || urlParam.q || urlParam.query || urlParam.keyword || ""
|
||
/* -------------- 计划单元 -------------- */
|
||
let website_plan_unit = ""
|
||
let website_keywords_string = ""
|
||
if (urlParam.plan || urlParam.unit) {
|
||
website_plan_unit = urlParam.plan + "-" + urlParam.unit
|
||
}
|
||
if (website_keywords && website_plan_unit) {
|
||
website_keywords_string = website_plan_unit + "-" + website_keywords // 媒体摘要
|
||
}
|
||
if (!website_plan_unit && website_keywords) {// 只有关键词
|
||
website_keywords_string = website_keywords
|
||
}
|
||
if (website_plan_unit && !website_keywords) {// 只有计划单元
|
||
website_keywords_string = website_plan_unit
|
||
}
|
||
let bd_vid = urlParam.bd_vid || "" // 百度vid
|
||
// 外部判断来源的js............................外部判断来源的js
|
||
var hollycrm = {}// 合力命名空间
|
||
/* ------------- 合力来源对象 ------------- */
|
||
hollycrm.originate = {
|
||
env: hollycrm.env || "product", // 当前运行环境:product:正式环境;test:测试环境
|
||
interfaceUrl: "k8s-im.7x24cc.com/open_platform", // 接口地址
|
||
serviceID: "0",
|
||
param: {},// 客户初始化的参数
|
||
originateInfo: {},// 来源信息数据对象
|
||
tokenID: "",// 请求的token
|
||
/**
|
||
* 获取UUID
|
||
* @return {string} 返回UUID
|
||
*/
|
||
getUuid: function uuid() {
|
||
var s = []
|
||
var hexDigits = "0123456789abcdef"
|
||
for (var i = 0; i < 36; i++) {
|
||
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1)
|
||
}
|
||
s[14] = "4" // bits 12-15 of the time_hi_and_version field to 0010
|
||
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1) // bits 6-7 of the clock_seq_hi_and_reserved to 01
|
||
s[8] = s[13] = s[18] = s[23] = "-"
|
||
var uuid = s.join("")
|
||
return uuid
|
||
},
|
||
/**
|
||
* 获取来源信息
|
||
*/
|
||
getOriginateUrl: function () {
|
||
var self = hollycrm.originate
|
||
var originateUrl = sourceUrl
|
||
function getUrlData(link) { //获取url中的参数
|
||
var urlData = {}
|
||
if (link.indexOf("?") != -1) {
|
||
var index = link.lastIndexOf("?")
|
||
var url = link.substring(index, link.length)
|
||
var str = url.substr(1)
|
||
var strs = str.split("&")
|
||
for (var i = 0; i < strs.length; i++) {
|
||
try {
|
||
urlData[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1])
|
||
} catch (error) {
|
||
urlData[strs[i].split("=")[0]] = strs[i].split("=")[1]
|
||
}
|
||
}
|
||
}
|
||
return urlData
|
||
}
|
||
var urlParam = getUrlData(originateUrl) || {}
|
||
/* -------------- 推广媒体 -------------- */
|
||
var media = "无法判断"
|
||
if (originateUrl.indexOf("baidu") > -1 || originateUrl.indexOf("百度") > -1 || originateUrl.indexOf("aladdin") > -1) {
|
||
media = "百度SEO"
|
||
if (originateUrl.indexOf("medium=cpc") > -1 || originateUrl.indexOf("zhidao.baidu") > -1 || originateUrl.indexOf("百度,SEM") > -1) {
|
||
media = "百度SEM"
|
||
}
|
||
if (originateUrl.indexOf("aladdin") > -1) {
|
||
media = "百度阿拉丁"
|
||
}
|
||
if (originateUrl.indexOf("baidufeed") > -1) {
|
||
media = "百度信息流"
|
||
}
|
||
}
|
||
if (originateUrl.indexOf("so.com") > -1 || originateUrl.indexOf("media=360") > -1 || originateUrl.indexOf("source=360") > -1) {
|
||
media = "360SEO"
|
||
if (originateUrl.indexOf("medium=cpc") > -1 || originateUrl.indexOf("360SEM") > -1) {
|
||
media = "360SEM"
|
||
}
|
||
}
|
||
if (originateUrl.indexOf("sogou.com") > -1 || originateUrl.indexOf("media=sogou") > -1) {
|
||
media = "搜狗SEO"
|
||
if (originateUrl.indexOf("cpc") > -1) {
|
||
media = "搜狗SEM"
|
||
}
|
||
}
|
||
if (originateUrl.indexOf("zhihu") > -1 || originateUrl.indexOf("知乎") > -1 || originateUrl.indexOf("%E7%9F%A5%E4%B9%8E") > -1) {
|
||
media = "知乎"
|
||
}
|
||
if (originateUrl.indexOf("google.com") > -1) {
|
||
media = "谷歌"
|
||
}
|
||
if (originateUrl.indexOf("sm.cn") > -1) {
|
||
media = "神马"
|
||
}
|
||
if (originateUrl.indexOf("bing.com") > -1 || originateUrl.indexOf("bing.cn") > -1) {
|
||
media = "必应"
|
||
}
|
||
if (originateUrl.indexOf("douban.com") > -1) {
|
||
media = "豆瓣"
|
||
}
|
||
if (originateUrl.indexOf("taobao.com") > -1) {
|
||
media = "淘宝"
|
||
}
|
||
if (originateUrl.indexOf("toutiao") > -1) {
|
||
media = "头条"
|
||
}
|
||
if (originateUrl.indexOf("a6.7x24cc.com") > -1) {
|
||
media = "A6系统"
|
||
}
|
||
self.originateInfo.originateId = self.getUuid() // 来源ID
|
||
self.originateInfo.originateType = media // 来源类型
|
||
self.originateInfo.originateKey = urlParam.utm_term || urlParam.word || urlParam.wd || urlParam.hmkw || urlParam.q || urlParam.query || urlParam.keyword || "" // 来源关键词
|
||
self.originateInfo.originateUrl = originateUrl // 来源链接地址
|
||
return self.originateInfo
|
||
},
|
||
/**
|
||
* 获取聊天入口地址
|
||
* @param param 参数
|
||
* @param callback 回调
|
||
*/
|
||
getChatUrl: function (param, callback) {
|
||
var self = hollycrm.originate
|
||
if (!param) {
|
||
console.error("参数[param]不能为空!")
|
||
return
|
||
}
|
||
if (!param.accountID) {
|
||
console.error("参数param里必须要有属性[accountID]!")
|
||
return
|
||
}
|
||
if (!param.channelID) {
|
||
console.error("参数param里必须要有属性[channelID]!")
|
||
return
|
||
}
|
||
self.param = param
|
||
var originateInfo = self.getOriginateUrl() //来源信息
|
||
self.getServiceConf(function () { //获取服务器id
|
||
self.getToken(function () {
|
||
self.saveOriginateInfo(originateInfo, function () {
|
||
self.generateChatUrl(function (chatUrl) {
|
||
if (callback && typeof callback === "function") {
|
||
callback({ chatUrl: chatUrl + "&originateId=" + originateInfo.originateId })
|
||
}
|
||
})
|
||
})
|
||
})
|
||
})
|
||
},
|
||
/**
|
||
* 生成聊天入口地址
|
||
* @param callback 回调
|
||
*/
|
||
generateChatUrl: function (callback) {
|
||
var self = hollycrm.originate
|
||
var url = self.getInterfaceUrl()
|
||
var data = {
|
||
Modual: "ChatConfig",
|
||
Action: "GetChatUrl",
|
||
account: self.param.accountID,
|
||
token: self.tokenID,
|
||
channelId: self.param.channelID
|
||
}
|
||
self.sendAjax(url, data, function (res) {
|
||
if (res && res.Succeed) {
|
||
if (res.chatUrl) {
|
||
var chatUrl = res.chatUrl
|
||
if (self.param.urlParam) {
|
||
for (var key in self.param.urlParam) {
|
||
chatUrl += "&" + key + "=" + self.param.urlParam[key]
|
||
}
|
||
}
|
||
callback(chatUrl)
|
||
} else {
|
||
console.error("获取不到聊天入口的链接地址!")
|
||
}
|
||
} else {
|
||
console.error("请求获取聊天入口的链接地址错误,请检查网络连接!")
|
||
}
|
||
})
|
||
},
|
||
/**
|
||
* 获取接口请求地址
|
||
* @return {String} 请求地址
|
||
*/
|
||
getInterfaceUrl: function () {
|
||
var isHttps = "https:" == document.location.protocol ? true : false
|
||
var url = hollycrm.originate.interfaceUrl
|
||
var env = hollycrm.originate.env
|
||
if (env === "test") {
|
||
url = "/open_platform"
|
||
return url
|
||
}
|
||
if (isHttps) {
|
||
return "https://" + url
|
||
} else {
|
||
return "http://" + url
|
||
}
|
||
},
|
||
/**
|
||
* 获取请求Token
|
||
* @param callback 回调
|
||
*/
|
||
getToken: function (callback) {
|
||
var url = hollycrm.originate.getInterfaceUrl()
|
||
var data = {
|
||
Action: "getNewMediaToken"
|
||
}
|
||
hollycrm.originate.sendAjax(url, data, function (res) {
|
||
if (res) {
|
||
if (res.token) {
|
||
hollycrm.originate.tokenID = res.token
|
||
callback()
|
||
} else {
|
||
console.error("获取合力来源Token失败!")
|
||
}
|
||
}
|
||
})
|
||
},
|
||
/**
|
||
* 保存来源信息到服务器
|
||
* @param originateInfo 来源信息
|
||
* @param callback 回调
|
||
*/
|
||
saveOriginateInfo: function (originateInfo, callback) {
|
||
var self = hollycrm.originate
|
||
var url = self.getInterfaceUrl()
|
||
var data = {
|
||
accountID: self.param.accountID,
|
||
token: self.tokenID,
|
||
Action: "saveOriginateInfo",
|
||
originateId: originateInfo.originateId,
|
||
originateUrl: originateInfo.originateUrl,
|
||
originateKey: originateInfo.originateKey,
|
||
originateType: originateInfo.originateType
|
||
}
|
||
self.sendAjax(url, data, function (res) {
|
||
if (res) {
|
||
if (!res.Succeed) {
|
||
console.error("保存来源信息失败!")
|
||
}
|
||
callback()// 保存失败也不阻塞后续的执行
|
||
}
|
||
})
|
||
},
|
||
/**
|
||
* 发送Ajax信息
|
||
* @param url 请求地址
|
||
* @param data 请求数据
|
||
* @param successFunc 请求成功回调
|
||
*/
|
||
sendAjax: function (url, data, successFunc) {
|
||
var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
|
||
if (hollycrm.originate.serviceID === '8' && data.Action !== "locationServiceConf") {
|
||
url += "chat/" + data.Action;
|
||
}
|
||
xhr.open("POST", url, true)
|
||
if (hollycrm.originate.serviceID === '8' && data.Action !== "locationServiceConf") {
|
||
xhr.setRequestHeader("Content-Type", "application/json");
|
||
}
|
||
xhr.onreadystatechange = function () {
|
||
if (xhr.readyState == 4) {
|
||
if (xhr.status == 200) {
|
||
var data = eval("(" + xhr.responseText + ")")
|
||
if (data.succeed && data.data) {
|
||
Object.assign(data, data.data);
|
||
data.Succeed = true
|
||
}
|
||
successFunc(data)
|
||
} else {
|
||
alert("服务器返回错误!")
|
||
}
|
||
}
|
||
}
|
||
xhr.send(JSON.stringify(data))
|
||
},
|
||
/**
|
||
* 获取getServiceConf
|
||
* @param id 账号id
|
||
* @param callback
|
||
*/
|
||
getServiceConf: function (callback) {
|
||
var self = hollycrm.originate
|
||
var url = self.getInterfaceUrl()
|
||
var data = {
|
||
Account: self.param.accountID,
|
||
Action: "locationServiceConf"
|
||
}
|
||
self.sendAjax(url, data, function (res) {
|
||
if (res.Succeed) {
|
||
hollycrm.originate.serviceID = res.serviceID;
|
||
hollycrm.originate.interfaceUrl = "k8s-im.7x24cc.com/newMedia_" + res.serviceID + "/";
|
||
callback()
|
||
return
|
||
} else {
|
||
console.error("获取服务配置失败失败!")
|
||
}
|
||
})
|
||
}
|
||
}
|
||
// 外部判断来源的js............................外部判断来源的js--end
|
||
/* ---------- 下面是企微活码相关的内容 ---------- */
|
||
var qrCode = "" // 二维码图片地址
|
||
var qrFormCode = "" // 表单后活码地址
|
||
var yinliu_url = "" // 小程序引流链接
|
||
async function getAccessToken() {// 企微活码,获取access_token
|
||
let res = await axios.get("https://a2.xiaomilaile.com/local-commonInte/accessToken?account=N000000001907&appid=xmpavkl4bgs4lihg&secret=120d0781-827c-4320-9104-47cb33a303ae")
|
||
return res.data.accessToken
|
||
}
|
||
async function getCode() { //右侧边栏生成企微活码
|
||
let accessToken = await getAccessToken()
|
||
const data = {
|
||
account: "N000000001907",
|
||
access_token: accessToken,
|
||
id: "5e89b46d-6a41-4dd0-8056-953f33708921",
|
||
website_keywords: website_keywords_string, //媒体摘要 包含计划 单元 关键词
|
||
website_url: website_url, //原始链接
|
||
website_promotion_media: website_promotion_media, //推广媒体 如 百度SEM baidu,sem
|
||
website_contact_channel: website_contact_channel, //联络渠道 如企业微信 wxwork
|
||
website_landing_page_type: website_landing_page_type, //落地页 hollycrm,pc
|
||
processLevel: "undefined,undefined",// 客户分级
|
||
welcome_msg: `您好,欢迎关注合力亿捷。
|
||
|
||
我们专注「营销服」一体化客户联络方案,拥有20年技术积累,产品覆盖零售、金融、汽车、餐饮和制造等行业。
|
||
|
||
您想了解哪个产品呢?
|
||
1、云呼叫中心
|
||
2、在线客服
|
||
3、工单系统
|
||
4、AI语音机器人
|
||
5、企微SCRM
|
||
6、其他`// 欢迎语
|
||
}
|
||
if (bd_vid) {
|
||
data.bd_vid = bd_vid
|
||
}
|
||
await axios({
|
||
method: "post",
|
||
url: "https://a2.xiaomilaile.com/local-commonInte/qywxExternal/get_multi_qrcode",
|
||
data: data
|
||
})
|
||
.then(res => {
|
||
qrCode = res.data.result.qr_code
|
||
})
|
||
.catch(err => {
|
||
console.log(err)
|
||
})
|
||
}
|
||
async function getFormCode() { //表单后企微活码
|
||
let accessToken = await getAccessToken()
|
||
const data = {
|
||
account: "N000000001907",
|
||
access_token: accessToken,
|
||
id: "ab3fa7b4-b92c-4c72-a181-0e18a58cc260",
|
||
fixedPhone: tool.getCookie("applyTel"),
|
||
"eec84370-7a47-11ea-adda-6b777015da5a": tool.getCookie("applyCity"),
|
||
fixedCusName: tool.getCookie("applyCom"),
|
||
website_keywords: website_keywords_string, //媒体摘要 包含计划 单元 关键词
|
||
website_url: website_url, //原始链接
|
||
website_promotion_media: website_promotion_media, //推广媒体 如 百度SEM baidu,sem
|
||
website_contact_channel: website_contact_channel, //联络渠道 如企业微信 wxwork
|
||
website_landing_page_type: website_landing_page_type, //落地页 hollycrm,pc
|
||
processLevel: "undefined,undefined",// 客户分级
|
||
welcome_msg: `您好,欢迎关注合力亿捷。
|
||
|
||
我们专注「营销服」一体化客户联络方案,拥有20年技术积累,产品覆盖零售、金融、汽车、餐饮和制造等行业。`,// 表单后欢迎语
|
||
extend_data: { formId: tool.getCookie("formId") } // A6对接表单id
|
||
}
|
||
if (bd_vid) {
|
||
data.bd_vid = bd_vid
|
||
}
|
||
await axios({
|
||
method: "post",
|
||
url: "https://a2.xiaomilaile.com/local-commonInte/qywxExternal/get_multi_qrcode",
|
||
data: data
|
||
})
|
||
.then(res => {
|
||
qrFormCode = res.data.result.qr_code
|
||
yinliu_url = res.data.result.yinliu_url // 用于表单后活码的引流
|
||
})
|
||
.catch(err => {
|
||
console.log(err)
|
||
})
|
||
}
|
||
async function toweixin() { // 点击跳转小程序活码
|
||
location.href = "https://work.weixin.qq.com/ca/cawcdec1a0cc0f1141";
|
||
// let accessToken = await getAccessToken()
|
||
// const data = {
|
||
// account: "N000000001907",
|
||
// access_token: accessToken,
|
||
// id: "32462733-4f95-492b-8f58-5fc498ecca35",
|
||
// website_keywords: website_keywords_string, //媒体摘要 包含计划 单元 关键词
|
||
// website_url: website_url, //原始链接
|
||
// website_promotion_media: website_promotion_media, //推广媒体 如 百度SEM baidu,sem
|
||
// website_contact_channel: website_contact_channel, //联络渠道 如企业微信 wxwork
|
||
// website_landing_page_type: website_landing_page_type, //落地页 website,hollycrm
|
||
// processLevel: "undefined,undefined"// 客户分级
|
||
// }
|
||
// if (bd_vid) {
|
||
// data.bd_vid = bd_vid
|
||
// }
|
||
// let param = new URLSearchParams()
|
||
// param.append("source", JSON.stringify(data))
|
||
// axios
|
||
// .post("/api/weixin/to_weixin.php", param)
|
||
// .then(res => {
|
||
// // console.log(res.data)
|
||
// if (IsMobile()) {
|
||
// window.location.href = res.data
|
||
// } else {
|
||
// alert("请在手机端打开")
|
||
// }
|
||
// })
|
||
// .catch(error => {
|
||
// console.log(error)
|
||
// })
|
||
}
|
||
function sendNotification(title, body, icon, callback) { // 浏览器通知
|
||
// 先检查浏览器是否支持
|
||
if (!("Notification" in window)) {
|
||
// IE浏览器不支持发送Notification通知!
|
||
return
|
||
}
|
||
if (Notification.permission === "denied") {
|
||
// 如果用户已拒绝显示通知
|
||
return
|
||
}
|
||
if (Notification.permission === "granted") {
|
||
//用户已授权,直接发送通知
|
||
notify()
|
||
} else {
|
||
// 默认,先向用户询问是否允许显示通知
|
||
Notification.requestPermission(function (permission) {
|
||
// 如果用户同意,就可以直接发送通知
|
||
if (permission === "granted") {
|
||
notify()
|
||
}
|
||
})
|
||
}
|
||
function notify() {
|
||
let notification = new Notification(title, {
|
||
icon: icon,
|
||
body: body
|
||
})
|
||
notification.onshow = function () {
|
||
setTimeout(function () {
|
||
notification.close()
|
||
}, 8000)
|
||
}
|
||
notification.onclick = function () {
|
||
notification.close()
|
||
window.focus()
|
||
callback && callback()
|
||
}
|
||
notification.onclose = function () { }
|
||
}
|
||
}
|
||
let mixins = {
|
||
data: {
|
||
headerCss: false, //导航样阴影css
|
||
mobileLogo: "logo.png", //移动端logo
|
||
mobileMenu: "menu_white.png", //移动端menu图片
|
||
mobileFixshow: true, //移动端咨询悬浮显示
|
||
show: false, //在线咨询大框
|
||
showWeekFlag: false, //上面的企微二维码
|
||
slideShow: false, //下面的企微码
|
||
getChatSlideShow: false, //在线咨询小弹窗
|
||
fixChatImgMsg: true, //人像上的1
|
||
chatText: "在线", //在线咨询文字
|
||
toastImg: "", //默认企微二维码
|
||
kefuMaxFlag: JSON.parse(sessionStorage.getItem("kefuMaxFlag")) || false, //客服最大化
|
||
kefuMuteFlag: JSON.parse(sessionStorage.getItem("kefuMuteFlag")) || false, //客服语音
|
||
kefuEndFlag: true
|
||
},
|
||
created() {
|
||
let self = this
|
||
if (sessionStorage.getItem("kefuOpenFlag") === "true") { //在线咨询打开后直接跳转到其它页面
|
||
self.showKefu()
|
||
}
|
||
if (sessionStorage.getItem("kefuOpenFlag") === "close") { //在线咨询关闭后跳转到其它页面
|
||
self.showOtherPageKefu()
|
||
}
|
||
setTimeout(() => { //20秒后显示在线咨询小弹窗
|
||
this.getChatSlideShow = true
|
||
}, 20000)
|
||
this.pushOcpcData() //推送ocpc数据
|
||
},
|
||
mounted() {
|
||
this.navActiveCss() //顶部导航css
|
||
this.changeNumber() //电话号码修改
|
||
this.openAgainKefu() //在线咨询通知提醒
|
||
window.addEventListener("scroll", this.showIcon) //顶部导航logo图片更换
|
||
},
|
||
methods: {
|
||
openAgainKefu() {//在线咨询提醒
|
||
let self = this
|
||
let i = 0
|
||
let timer
|
||
function show() {
|
||
//标题栏闪动
|
||
var title = document.title.replace("【 】", "").replace("【新消息】", "")
|
||
timer = setTimeout(function () {
|
||
if (i % 2 == 0) {
|
||
document.title = "【新消息】" + title
|
||
} else {
|
||
document.title = "【 】" + title
|
||
}
|
||
i++
|
||
show()
|
||
}, 600)
|
||
}
|
||
window.addEventListener("message", function (event) {
|
||
var data = event.data || {}
|
||
if (data.type === "newMessage") {
|
||
//如果收到新消息
|
||
var regInfo = data.data.Content
|
||
var regHtml = new RegExp("</?[^>]*>", "gi")
|
||
if (regInfo.indexOf("emoji") >= 0 || regInfo.indexOf("&") >= 0) {
|
||
regInfo = regInfo
|
||
.replace(/<\s?img[^>]*>/gi, "[图片]")
|
||
.replace(/ /gi, " ")
|
||
.replace(/>/gi, ">")
|
||
.replace(/</gi, "<")
|
||
.replace(/&/gi, "&")
|
||
.replace(regHtml, "")
|
||
sendNotification("您有一条新消息", regInfo, "/assets/images/logo2.png")
|
||
} else {
|
||
if (data.data.Content.indexOf("<img") >= 0) {
|
||
var notifyContent = data.data.Content.replace(/<\s?img[^>]*>/gi, "[图片]")
|
||
.replace(/ /gi, " ")
|
||
.replace(/>/gi, ">")
|
||
.replace(/</gi, "<")
|
||
.replace(/&/gi, "&")
|
||
.replace(regHtml, "")
|
||
sendNotification("您有一条新消息", notifyContent, "/assets/images/logo2.png")
|
||
} else {
|
||
sendNotification("您有一条新消息", data.data.Content, "/assets/images/logo2.png")
|
||
}
|
||
}
|
||
let kefuMuteFlag = sessionStorage.getItem("kefuMuteFlag") || "false"
|
||
if (!self.kefuMuteFlag && kefuMuteFlag === "false") {
|
||
var chatAudio = document.getElementById("chatAudio")
|
||
chatAudio.play()
|
||
}
|
||
clearTimeout(timer)
|
||
document.title = document.title.replace("【 】", "").replace("【新消息】", "")
|
||
show()
|
||
let kefuEndFlag = sessionStorage.getItem("kefuEndFlag") || "false"
|
||
if (!self.show && kefuEndFlag !== "true") {
|
||
// 不显示大框时, 过10秒再显示
|
||
let timeLimit = 10000
|
||
setTimeout(function () {
|
||
self.show = true
|
||
}, timeLimit)
|
||
}
|
||
}
|
||
})
|
||
window.onfocus = function () {
|
||
//窗口获得焦点时, 不闪动
|
||
clearTimeout(timer)
|
||
document.title = document.title.replace("【 】", "").replace("【新消息】", "")
|
||
}
|
||
document.onclick = function () {
|
||
clearTimeout(timer)
|
||
document.title = document.title.replace("【 】", "").replace("【新消息】", "")
|
||
}
|
||
},
|
||
showIcon() {//顶部导航css
|
||
if (/Mobile|Android|webOS|iPhone|iPad|Phone/i.test(navigator.userAgent) || screen.width <= 768) {
|
||
// 移动端
|
||
if (!!document.documentElement.scrollTop && document.documentElement.scrollTop > 50) {
|
||
this.headerCss = true
|
||
this.mobileLogo = "logo1.png"
|
||
} else {
|
||
this.headerCss = false
|
||
this.mobileLogo = "logo.png"
|
||
}
|
||
} else {
|
||
// PC端
|
||
if (!!document.documentElement.scrollTop && document.documentElement.scrollTop > 200) {
|
||
this.headerCss = true
|
||
} else {
|
||
this.headerCss = false
|
||
this.mobileLogo = "logo.png"
|
||
}
|
||
}
|
||
},
|
||
toTop() {//返回顶部
|
||
scrollTo({
|
||
left: 0,
|
||
top: 0,
|
||
behavior: 'smooth'
|
||
});
|
||
},
|
||
navActiveCss() { //顶部导航css
|
||
const linkMap = {
|
||
2: ["com/callcenter", "com/salesplat", "com/webchat", "com/order", "/scrm", "/AIplatform", "com/project", "/solution/customer", "/solution/progress", "/remote", "/AIcall", "com/robot"],
|
||
3: ["/solution/", "/telecom", "/gover", "/express", "/finance", "/auto"],
|
||
4: ["/wincase"],
|
||
5: ["/news", "/help"],
|
||
6: ["/aboutus"]
|
||
};
|
||
for (let key in linkMap) {
|
||
if (linkMap[key].some(item => link.indexOf(item) != -1)) {
|
||
$(`.first-wrap .first:nth-child(${key}) a.first-link`).addClass("hover");
|
||
}
|
||
}
|
||
},
|
||
changeNumber() { // 分渠道修改网站电话
|
||
/* ................. 分渠道修改网站电话 ................ */
|
||
if (sourceUrl && sourceUrl.indexOf("baidu.com") > -1 && sourceUrl.indexOf("medium=cpc") < 0) {
|
||
$(".telNum").each(function () {
|
||
$(this).text("4000-628-505") //百度SEO
|
||
})
|
||
}
|
||
if (sourceUrl && sourceUrl.indexOf("medium=cpc") > -1 && sourceUrl.indexOf("baidu") > -1) {
|
||
$(".telNum").each(function () {
|
||
$(this).text("4006-456-595") //百度SEM
|
||
})
|
||
}
|
||
if (sourceUrl && (sourceUrl.indexOf("aladdin") > -1 || location.href.indexOf("aladdin") > -1)) {
|
||
$(".telNum").each(function () {
|
||
$(this).text("4008-198-638") //阿拉丁
|
||
})
|
||
}
|
||
if (sourceUrl.indexOf("medium=cpc") < 0 && (sourceUrl.indexOf("media=360") > -1 || sourceUrl.indexOf("so.com") > -1 || sourceUrl.indexOf("source=360") > -1)) {
|
||
$(".telNum").each(function () {
|
||
$(this).text("4000-628-505") //360SEO
|
||
})
|
||
}
|
||
if (sourceUrl.indexOf("medium=cpc") > -1 && (sourceUrl.indexOf("media=360") > -1 || sourceUrl.indexOf("so.com") > -1 || sourceUrl.indexOf("source=360") > -1)) {
|
||
$(".telNum").each(function () {
|
||
$(this).text("4006-345-595") //360SEM
|
||
})
|
||
}
|
||
if (sourceUrl.indexOf("medium=cpc") > -1 && (sourceUrl.indexOf("media=sogou") > -1 || sourceUrl.indexOf("sogou.com") > -1)) {
|
||
$(".telNum").each(function () {
|
||
$(this).text("4006-345-595") //搜狗SEM
|
||
})
|
||
}
|
||
if (sourceUrl && (sourceUrl.indexOf("zhihu") > -1 || sourceUrl.indexOf("知乎") > -1 || sourceUrl.indexOf("%E7%9F%A5%E4%B9%8E") > -1)) {
|
||
$(".telNum").each(function () {
|
||
$(this).text("4006-240-256") //知乎
|
||
})
|
||
}
|
||
if (sourceUrl.indexOf("medium=cpc") > -1 && sourceUrl.indexOf("project") > -1) {
|
||
$(".telNum").each(function () {
|
||
$(this).text("4006-345-690") //项目管理页面SEM相关
|
||
})
|
||
}
|
||
if (navigator.userAgent.match(/(iPhone|iPod|Android|ios|iOS|iPad|Backerry|WebOS|Symbian|Windows Phone|Phone)/i)) {
|
||
$(".telNum").each(function () {
|
||
$(this).text("180-4353-0712") //移动端的
|
||
})
|
||
}
|
||
/* ---------- 移动端分渠道修改电话号码 ---------- */
|
||
if (sourceUrl && sourceUrl.indexOf("medium=cpc") > -1 && sourceUrl.indexOf("baidu") > -1 && IsMobile()) {
|
||
$(".telNum").each(function () {
|
||
$(this).text("4006-726-496") //百度SEM
|
||
$(this).attr("href", "tel:4006-726-496")
|
||
})
|
||
$(".telNumber").attr("href", "/apply?type=sem")
|
||
$(".telNumber").html('<img src="/assets/images/mobile_apply.png">免费试用')
|
||
// $(".telNumber").hide();
|
||
// $("#get_chat").css("borderRadius", "0.5rem")
|
||
}
|
||
axios({
|
||
method: "post",
|
||
url: "https://ipapi.co/json/"
|
||
}).then(res => {
|
||
var ipApiCity = res.data.city || ""
|
||
if (ipApiCity.indexOf("Shanghai") > -1) {
|
||
$(".telNum").each(function () {
|
||
$(this).text("021-61897000") //上海区域的
|
||
})
|
||
}
|
||
}).catch(err => {
|
||
console.log("??ip定位 err:", err)
|
||
})
|
||
/* ................. 分渠道修改网站电话end ................ */
|
||
},
|
||
removeChatImgMsg() {// 去除人像上的1
|
||
this.fixChatImgMsg = false
|
||
},
|
||
kefuMax() {//客服最大化
|
||
this.kefuMaxFlag = !this.kefuMaxFlag
|
||
sessionStorage.setItem("kefuMaxFlag", this.kefuMaxFlag)
|
||
},
|
||
kefuMute() {// 客服静音
|
||
this.kefuMuteFlag = !this.kefuMuteFlag
|
||
sessionStorage.setItem("kefuMuteFlag", this.kefuMuteFlag)
|
||
},
|
||
isWorkTime() { // 判断是否是工作时间
|
||
var date = new Date()
|
||
var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()
|
||
var time = Number(date.getHours() + "" + minute)
|
||
return (900 <= time && time <= 1200) || (1330 <= time && time <= 1800)
|
||
},
|
||
createChatFrame() { // 创建聊天框
|
||
if (!$("#olchatframe")[0]) {
|
||
hollycrm.originate.getChatUrl(
|
||
{
|
||
channelID: "hollycrm.com-705d8d50-fa6c-11e6-9d96-b5920273913b",
|
||
accountID: "N000000001907"
|
||
},
|
||
function (callbackData) {
|
||
chatUrl1 = callbackData.chatUrl
|
||
chatUrl1 = chatUrl1.replace("http:", "https:")
|
||
var chatframe = document.createElement("iframe")
|
||
var framebox = document.getElementById("kefu_frame_box")
|
||
chatframe.id = "olchatframe"
|
||
chatframe.src = chatUrl1
|
||
framebox.appendChild(chatframe)
|
||
if (!document.getElementById("chatAudio")) {
|
||
var chatAudio = document.createElement("audio")
|
||
chatAudio.id = "chatAudio"
|
||
chatAudio.src = "/assets/images/msgcall.mp3"
|
||
document.body.appendChild(chatAudio)
|
||
}
|
||
}
|
||
)
|
||
}
|
||
},
|
||
async checkDuty() { //检查值班状态
|
||
try {
|
||
let res = await axios({
|
||
method: "post",
|
||
url: "/api/kefu/webchat.php"
|
||
})
|
||
if (res.data == "onduty") { //值班
|
||
return true
|
||
} else {
|
||
return false
|
||
}
|
||
} catch (err) {
|
||
console.log("?? checkDuty ~ err", err)
|
||
}
|
||
},
|
||
async showKefu() {//显示隐藏在线咨询
|
||
let self = this
|
||
self.chatText == "收起" ? (self.chatText = "在线") : (self.chatText = "收起")// 大咨询框显示与隐藏
|
||
self.removeChatImgMsg() // 去除人像上的1
|
||
self.getChatSlideShow = false // 隐藏小咨询框
|
||
let checkDuty = await self.checkDuty() // 检查值班状态
|
||
if (checkDuty && self.isWorkTime()) { // 工作时间,并且有人值班
|
||
self.show = !self.show
|
||
sessionStorage.setItem("kefuEndFlag", "false");
|
||
sessionStorage.setItem("kefuOpenFlag", self.show ? "true" : "close");
|
||
self.createChatFrame() // 打开在线
|
||
} else { // 非工作时间,或者没人值班
|
||
if (!self.toastImg) {
|
||
self.getQrCode() // 获取企微活码
|
||
}
|
||
self.show = false
|
||
self.showWeekFlag = !self.showWeekFlag
|
||
}
|
||
self.ocpcPush() // 在线ocpc推送
|
||
},
|
||
async showOtherPageKefu() {// 当用户点击了关闭再跳转到其它页面时,在线咨询在后台加载,但不显示
|
||
let self = this
|
||
if (!self.isWorkTime()) return
|
||
let checkDuty = await self.checkDuty()
|
||
if (checkDuty) {
|
||
self.show = false
|
||
self.createChatFrame() // 创建聊天框
|
||
}
|
||
},
|
||
closeFrame() {//关闭在线咨询
|
||
this.show = false
|
||
this.showWeekFlag = false
|
||
this.getChatSlideShow = false
|
||
this.removeChatImgMsg()
|
||
this.chatText = "在线"
|
||
sessionStorage.setItem("kefuOpenFlag", "close")
|
||
},
|
||
kefuEnd() {// 结束在线咨询
|
||
this.kefuEndFlag = true
|
||
this.show = false
|
||
this.showWeekFlag = false
|
||
this.getChatSlideShow = false
|
||
this.removeChatImgMsg()
|
||
this.chatText = "在线"
|
||
sessionStorage.setItem("kefuOpenFlag", "close")
|
||
sessionStorage.setItem("kefuEndFlag", "true")
|
||
},
|
||
chatSlideShow() {//在线咨询小框关闭
|
||
this.getChatSlideShow = false
|
||
this.removeChatImgMsg()
|
||
this.setTimeChatShow()
|
||
},
|
||
setTimeChatShow() {//关闭后小窗40s后再次弹出
|
||
let self = this
|
||
setTimeout(function () {
|
||
self.getChatSlideShow = true
|
||
}, 40000)
|
||
},
|
||
async slideClick() {//显示隐藏企微活码---点击
|
||
if (!this.toastImg) {
|
||
await this.getQrCode() // 获取企微活码
|
||
}
|
||
this.slideShow = !this.slideShow
|
||
},
|
||
async mouseoverSlideClick() {//显示企微活码---鼠标移入
|
||
if (!this.toastImg) {
|
||
await this.getQrCode() // 获取企微活码
|
||
}
|
||
this.slideShow = true
|
||
},
|
||
async mouseoutSlideClick() {//隐藏企微活码---鼠标移出
|
||
this.slideShow = false
|
||
},
|
||
async getQrCode() {// 获取企微活码
|
||
await getCode()
|
||
this.toastImg = qrCode
|
||
},
|
||
pushOcpcData() {// 记录ocpc数据
|
||
if (!bd_vid || sessionStorage.getItem("ocpcFlag") || tool.getCookie("ocpcFlag")) {
|
||
return
|
||
}
|
||
let param = new URLSearchParams()
|
||
param.append("query", "set")
|
||
param.append("site", "呼叫中心站")
|
||
param.append("url", sourceUrl)
|
||
param.append("bd_vid", bd_vid)
|
||
param.append("keywords", website_keywords)
|
||
axios({
|
||
method: "post",
|
||
url: "https://site.hollycrm.com/ocpc/index.php",
|
||
data: param
|
||
}).then(res => {
|
||
sessionStorage.setItem("ocpcFlag", "true")
|
||
tool.setCookie("ocpcFlag", "true", 0.01)
|
||
}).catch(err => {
|
||
console.log(err)
|
||
})
|
||
},
|
||
async ocpcPush() {// ocpc推送到百度
|
||
if (!bd_vid) return // 如果没有bd_vid,不推送
|
||
if (sessionStorage.getItem("webchat_ocpc_push") == "true" || tool.getCookie("webchat_ocpc_push") == "true") { // 如果已经推送过,不推送
|
||
return
|
||
}
|
||
var queryData = {
|
||
query: "queryByVid",
|
||
site: "呼叫中心站",
|
||
"bd_vid": bd_vid,
|
||
}
|
||
queryData = new URLSearchParams(queryData)
|
||
var queryRes = await axios({
|
||
method: "post",
|
||
url: "https://site.hollycrm.com/ocpc/index.php",
|
||
data: queryData
|
||
}).then(res => {
|
||
return res.data
|
||
}).catch(err => {
|
||
return err
|
||
})
|
||
if (queryRes.success && queryRes.row == 0) {
|
||
return
|
||
}
|
||
var data = {
|
||
"query": "back",
|
||
"site": "呼叫中心站",
|
||
"bd_vid": bd_vid,
|
||
"url": sourceUrl,
|
||
"convertType": 1,
|
||
}
|
||
data = new URLSearchParams(data)
|
||
var pushData = axios({
|
||
method: "post",
|
||
url: "https://site.hollycrm.com/ocpc/ocpc.php",
|
||
data: data
|
||
}).then(res => {
|
||
return res.data
|
||
}).catch(err => {
|
||
return err
|
||
})
|
||
if (pushData.success == true) {
|
||
sessionStorage.setItem("webchat_ocpc_push", "true")
|
||
tool.setCookie("webchat_ocpc_push", "true", 0.01)
|
||
}
|
||
}
|
||
}
|
||
}
|