// v1.8.3 2019/03/29 16:30
|
// yesApp原生手机 调用函数
|
|
var yesApp = {
|
|
// ================================================================================= 一切的初始, yestv对象检测
|
yestv: function ()
|
{
|
var back = false;
|
try{ if (yestv) { back = true; } else { console.log("yesApp.yestv():yestv未知"); back = false; } }
|
catch (e) { console.log("yesApp.yestv():yestv未知"); back = false; }
|
return back;
|
},
|
|
// ================================================================================= 获取平台(设备类型):Android / ios
|
platformGet: function()
|
{
|
var u = navigator.userAgent;
|
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
|
if (isAndroid) { return "android"; }
|
else { return "ios"; }
|
},
|
|
// ================================================================================= 用户登录
|
login: function ()
|
{
|
if (yesApp.yestv())
|
{
|
try { yestv.login(); }
|
catch(e){ yesApp.showToast("跳转登录失败(请升级到最新版)"); }
|
}
|
},
|
|
// ================================================================================= 用户信息
|
userInfo: function (objC)
|
{
|
// 传递参数处理
|
var objThis = {
|
success: function () {},
|
fail: function () {},
|
};
|
if (typeof(objC)=="object" && typeof(objC.success)=="function") { objThis.success = objC.success; }
|
if (typeof(objC)=="object" && typeof(objC.fail)=="function") { objThis.fail = objC.fail; }
|
|
if (yesApp.yestv())
|
{
|
var back = { id: '' };
|
var uid = '';
|
try{ uid = yestv.getUid(); } catch(e){ yesApp.showToast({ content: "获取用户ID失败(请升级到最新版)" }); }
|
// 获取到id
|
if (uid != '' && uid > 0) { back.id = uid; objThis.success(back); }
|
// 未获取到
|
else { objThis.fail(); }
|
}
|
},
|
|
// ================================================================================= 弹框
|
showToast: function (objC)
|
{
|
// 传递参数处理
|
var objThis = {
|
content: "亲,我很迷茫……", // 要提示的文字内容
|
success: function () {},
|
};
|
if (typeof(objC)=="string") { objThis.content = objC; }
|
else if (typeof(objC)=="object")
|
{
|
if (typeof(objC.content)!="undefined") { objThis.content = objC.content; }
|
if (typeof(objC.success)=="function") { objThis.success = objC.success; }
|
}
|
|
if (yesApp.yestv())
|
{
|
try { yestv.toast(objThis.content); objThis.success(); }
|
catch(e){ console.log("yesApp.showToast():弹出提示框失败"); alert(objThis.content); }
|
}
|
},
|
|
showLoading: function (objC)
|
{
|
// 传递参数处理
|
var objThis = {
|
content: "", // 要提示的文字内容
|
success: function () {},
|
};
|
if (typeof(objC)=="string") { objThis.content = objC; }
|
else if (typeof(objC)=="object")
|
{
|
if (typeof(objC.content)!="undefined") { objThis.content = objC.content; }
|
if (typeof(objC.success)=="function") { objThis.success = objC.success; }
|
}
|
|
if (yesApp.yestv())
|
{
|
try { yestv.showLoading(objThis.content); objThis.success(); }
|
catch(e){ yesApp.showToast("弹出加载框失败(请升级到最新版)"); }
|
}
|
},
|
hideLoading: function (objC)
|
{
|
// 传递参数处理
|
var objThis = {
|
success: function () {},
|
};
|
if (typeof(objC)=="object" && typeof(objC.success)=="function") { objThis.success = objC.success; }
|
|
if (yesApp.yestv())
|
{
|
try { yestv.hideLoading(); objThis.success(); }
|
catch(e){ yesApp.showToast("关闭加载框失败(请升级到最新版)"); }
|
}
|
},
|
|
// ================================================================================= 左上角功能:取消关闭按钮
|
hideClose: function (objC)
|
{
|
// 传递参数处理
|
var objThis = {
|
success: function () {},
|
};
|
if (typeof(objC)=="object" && typeof(objC.success)=="function") { objThis.success = objC.success; }
|
|
if (yesApp.yestv())
|
{
|
try { yestv.hiddenTopMenuCloseBtn(); objThis.success(); }
|
catch(e){ console.log("取消关闭按钮失败(请升级到最新版)"); }
|
}
|
},
|
|
// ================================================================================= 右上角菜单:自定义
|
menuCustom: function (objC)
|
{
|
// 传递参数处理
|
var objThis = {
|
text: "", // (string)文字
|
icon: "", // (string)图片地址
|
"do": "", // (string)要做的事情,如: "doui.showToast();"
|
success: function () {},
|
};
|
if (typeof(objC)=="object" && typeof(objC.text)=="string") { objThis.text = objC.text; }
|
if (typeof(objC)=="object" && typeof(objC.icon)=="string") { objThis.icon = objC.icon; }
|
if (typeof(objC)=="object" && typeof(objC["do"])=="string") { objThis["do"] = objC["do"]; }
|
if (typeof(objC)=="object" && typeof(objC.success)=="function") { objThis.success = objC.success; }
|
|
if (yesApp.yestv())
|
{
|
try{
|
if (objThis.icon.length > 0) { yestv.setTopMenuRightIcon(objThis.icon, objThis["do"]); }
|
else if (objThis.text.length > 0) { yestv.setTopMenuRightText(objThis.text, objThis["do"]); }
|
objThis.success();
|
}
|
catch(e){ console.log("menu:设置失败(请升级到最新版)"); }
|
}
|
},
|
|
// ================================================================================= 右上角菜单:分享
|
menuShare: function (objC)
|
{
|
// 传递参数处理
|
var objThis = {
|
state: 1, // 0-关闭 1-开启
|
success: function () {},
|
};
|
if (typeof(objC)=="object" && typeof(objC.state)!="undefined") { objThis.state = objC.state; }
|
if (typeof(objC)=="object" && typeof(objC.success)=="function") { objThis.success = objC.success; }
|
|
if (yesApp.yestv())
|
{
|
// 获取设备信息
|
var sys = yesApp.platformGet();
|
// 1. 安卓设备
|
if (sys == "android")
|
{
|
try { yestv.setShareBtn(objThis.state); objThis.success(); }
|
catch(e){ console.log("开启分享失败(请升级到最新版)"); }
|
}
|
// 2. IOS设备
|
else if (sys == "ios")
|
{
|
if (objThis.state == 1) { objThis.state = '1'; }
|
else if (objThis.state == 0) { objThis.state = '0'; }
|
// 获取版本号
|
var version = 0;
|
try{ var strNum = yestv.getVersion(); version = parseInt(strNum); }
|
catch(e){ console.log("获取版本号失败(请升级到最新版)"); }
|
// 老版本
|
if (version <= 37) { window.location.href = "yestv://setShareBtn#" + window.btoa(objThis.state); }
|
// 新版本
|
else {
|
try { yestv.setShareBtn(objThis.state); objThis.success(); }
|
catch(e){ console.log("开启分享失败(请升级到最新版)"); }
|
}
|
}
|
}
|
|
},
|
|
// ================================================================================= 设置页面标题
|
menuTitle: function (objC)
|
{
|
// 传递参数处理
|
var objThis = {
|
title: "", // (string)页面标题
|
success: function () {},
|
};
|
if (typeof(objC)=="object" && typeof(objC.title)=="string") { objThis.title = objC.title; }
|
if (typeof(objC)=="object" && typeof(objC.success)=="function") { objThis.success = objC.success; }
|
|
if (yesApp.yestv())
|
{
|
try { yestv.setTitle(objThis.title); objThis.success(); }
|
catch(e){ yesApp.showToast("设置页面标题失败(请升级到最新版)"); }
|
}
|
else { window.location.href = "yestv://setTitle#" + window.btoa(objThis.title); objThis.success(); }
|
},
|
|
// ================================================================================= 友盟数据统计
|
umeng: function (objC)
|
{
|
// 传递参数处理
|
var objThis = {
|
event: "", // 事件标识
|
data: {}, // (JSON)要传递的数据
|
success: function () {},
|
fail: function () {},
|
};
|
if (typeof(objC)=="object" && typeof(objC.event)!="undefined") { objThis.event = objC.event; }
|
if (typeof(objC)=="object" && typeof(objC.data)=="object") { objThis.data = objC.data; }
|
if (typeof(objC)=="object" && typeof(objC.success)=="function") { objThis.success = objC.success; }
|
if (typeof(objC)=="object" && typeof(objC.fail)=="function") { objThis.fail = objC.fail; }
|
|
if (yesApp.yestv())
|
{
|
try {
|
var paramsJSON = JSON.stringify(objThis.data);
|
yestv.umEventCount(objThis.event, paramsJSON);
|
objThis.success();
|
}
|
catch(e){ objThis.fail(); }
|
}
|
},
|
|
// ================================================================================= 生成签名后数据
|
signData: function (objC)
|
{
|
// 传递参数处理
|
var objThis = {
|
type: 1, // 签名方法类型:1-新版 2-旧版方法
|
data: {}, // (JSON)要签名的数据
|
success: function () {},
|
};
|
if (typeof(objC)=="object" && typeof(objC.type)!="undefined") { objThis.type = objC.type; }
|
if (typeof(objC)=="object" && typeof(objC.data)=="object") { objThis.data = objC.data; }
|
if (typeof(objC)=="object" && typeof(objC.success)=="function") { objThis.success = objC.success; }
|
|
if (yesApp.yestv())
|
{
|
// 新版方法
|
if (objThis.type == 1)
|
{
|
try{
|
var strJson = yestv.getRequestBaseParams(JSON.stringify(objThis.data));
|
var back = JSON.parse(strJson);
|
objThis.success(back);
|
}
|
catch (e) { yesApp.showToast("获取签名数据集失败(请升级到最新版)"); }
|
}
|
// 旧版方法
|
else if (objThis.type == 2)
|
{
|
var back = objThis.data;
|
// 提前封装
|
back.time = new Date().getTime();
|
back.version = yestv.getVersion();
|
back.platform = yesApp.platformGet();
|
// 生成组
|
var zu_mo = new Array();
|
for (var k in back) { var jiedian = k + "=" + back[k]; zu_mo.push(jiedian); }
|
zu_mo.sort();
|
// 生成元素字符串
|
var str_mo = "";
|
for (var i = 0; i < zu_mo.length; i++) { str_mo += zu_mo[i] + "&"; }
|
try {
|
// 获取签名
|
var sign = yestv.getSign(str_mo);
|
back.sign = sign;
|
objThis.success(back);
|
}
|
catch (e) { yesApp.showToast("获取sign参数失败(请升级到最新版)"); }
|
}
|
}
|
|
},
|
|
// ================================================================================= 请求淘客推广参数
|
tbPidHttp: "http://flq.yeshitv.com/fanli/api/v1/s11/getTBPidInfo", // 淘客参数请求地址
|
tbPidInfo: null, // 淘客推广参数信息
|
tbPid: function (objC)
|
{
|
// 传递参数处理
|
var objThis = {
|
success: function () {},
|
fail: function () {},
|
};
|
if (typeof(objC)=="object" && typeof(objC.success)=="function") { objThis.success = objC.success; }
|
if (typeof(objC)=="object" && typeof(objC.fail)=="function") { objThis.fail = objC.fail; }
|
|
if (yesApp.yestv())
|
{
|
// 获取用户信息
|
yesApp.userInfo({
|
fail: function () { yesApp.login(); },
|
success: function (user)
|
{
|
// 数据准备
|
yesApp.signData({
|
data: { uid: user.id },
|
success: function (res)
|
{
|
var myurl = yesApp.tbPidHttp;
|
var mydata = res;
|
doui.request({
|
type: 'jsonp',
|
"url": myurl,
|
data: mydata,
|
fail: function () { yesApp.showToast("淘客推广参数request fail"); },
|
success: function (mDa)
|
{
|
if (mDa.code != 0) { yesApp.showToast(mDa.msg); objThis.fail(mDa); }
|
else
|
{
|
// 得到淘客推广参数
|
yesApp.tbPidInfo = JSON.stringify(mDa.data);
|
// 通关回调函数
|
objThis.success();
|
}
|
},
|
});
|
},
|
});
|
},
|
});
|
}
|
|
},
|
|
// ================================================================================= 页面关闭
|
pageClose: function ()
|
{
|
if (yesApp.yestv())
|
{
|
try { yestv.finishPage(); }
|
catch(e){ yesApp.showToast("关闭页面失败(请升级到最新版)"); }
|
}
|
else { window.location.href = "yestv://finishPage"; }
|
},
|
|
// ================================================================================= 页面跳转
|
pageTo: function (objC)
|
{
|
// 传递参数处理
|
var objThis = {
|
type: "navigate", // 跳转方式:navigate-保留当前页面,跳转到应用内的某个页面 redirect-关闭当前页面,跳转到应用内的某个页面
|
placeName: "", // 目的地名字:web-网页 、goods-商品详情、search-搜索页 、invite-邀请、share-商品分享、strategy-新手攻略
|
// 目的地名字:collect-收藏页、history-浏览记录、userUpdate-用户信息修改页面、welfare-福利中心、service-人工客服
|
"url": "",
|
data: {},
|
jumpDetail: {},
|
params: {},
|
greenChannel: false, // 绿色通道,true-一定执行(覆盖) false-等上个关闭才能执行 ,默认:false
|
};
|
if (typeof(objC)=="object" && typeof(objC.type)=="string") { objThis.type = objC.type.toLowerCase(); }
|
if (typeof(objC)=="object" && typeof(objC.placeName)=="string") { objThis.placeName = objC.placeName.toLowerCase(); }
|
if (typeof(objC)=="object" && typeof(objC["url"])=="string") { objThis["url"] = objC["url"]; }
|
if (typeof(objC)=="object" && typeof(objC.data)=="object") { objThis.data = objC.data; }
|
if (typeof(objC)=="object" && typeof(objC.jumpDetail)=="object") { objThis.jumpDetail = objC.jumpDetail; }
|
if (typeof(objC)=="object" && typeof(objC.params)=="object") { objThis.params = objC.params; }
|
if (typeof(objC)=="object" && typeof(objC.greenChannel)=="boolean") { objThis.greenChannel = objC.greenChannel; }
|
|
if (yesApp.yestv())
|
{
|
// 设备平台 ios 还是 安卓
|
var platform = yesApp.platformGet();
|
|
// 构造jumpPage函数的2个参数:pageClassName paramsJSON
|
var pageClassName = "";
|
var paramsJSON = "";
|
|
// 1. 传递了目的地名字的时候
|
// 商品详情
|
if (objThis.placeName == "goods")
|
{
|
if (objThis.data.id == null || objThis.data.id == '') { yesApp.showToast("商品ID格式遵守:{id:1241343243}"); }
|
else
|
{
|
if (platform == 'android') { pageClassName = "com.yeshi.ec.rebate.myapplication.ui.recommend.GoodsBrowserActivity"; }
|
else { pageClassName = "GoodDeTrViewController"; }
|
paramsJSON = JSON.stringify(objThis.data);
|
// 调用跳转方法
|
try{
|
if (objThis.type == "navigate") { yestv.jumpPage(pageClassName, paramsJSON); }
|
else if (objThis.type == "redirect") { yestv.jumpPageWithFinishCurrentPage(pageClassName, paramsJSON); }
|
}
|
catch (e) { yesApp.showToast("进入商品详情失败(请升级到最新版)"); }
|
}
|
}
|
// 人工客服
|
if (objThis.placeName == "service")
|
{
|
if (typeof(objThis.data["from"])=="undefined") { yesApp.showToast("客服数据格式遵守:{from:'如何搜索券'}"); }
|
else
|
{
|
try { yestv.jumpKeFu(objThis.data["from"]); }
|
catch(e){ yesApp.showToast("进入人工客服失败(请升级到最新版)"); }
|
}
|
}
|
// 搜索页
|
else if (objThis.placeName == "search")
|
{
|
if (typeof(objThis.data["content"])=="undefined") { yesApp.showToast("搜索数据格式遵守:{content:'秋冬新款'}"); }
|
else {
|
try { yestv.jumpSearch(objThis.data.content); }
|
catch(e){ yesApp.showToast("进入搜索失败(请升级到最新版)"); }
|
}
|
}
|
// 邀请页
|
else if (objThis.placeName == "invite")
|
{
|
try { yestv.jumpInvite(); }
|
catch(e){ yesApp.showToast("进入邀请失败(请升级到最新版)"); }
|
}
|
// 网页跳转
|
else if (objThis.placeName == "web")
|
{
|
if (platform == 'android') { pageClassName = "com.yeshi.ec.rebate.myapplication.ui.invite.ShareBrowserActivity"; }
|
else { pageClassName = "ShonpingShareViewController"; }
|
// 待传递参数构建
|
var XXXData = "";
|
if (objThis.data)
|
{
|
XXXData = "?";
|
for (var k in objThis.data)
|
{
|
if (typeof(objThis.data[k])=="object") { objThis.data[k] = JSON.stringify(objThis.data[k]); }
|
XXXData += k + "=" + encodeURIComponent(objThis.data[k]) + "&";
|
}
|
XXXData = XXXData.substring(0, XXXData.length - 1);
|
}
|
var data = { url: objThis["url"] + XXXData };
|
paramsJSON = JSON.stringify(data);
|
// 调用跳转方法
|
try{
|
if (objThis.type == "navigate") { yestv.jumpPage(pageClassName, paramsJSON); }
|
else if (objThis.type == "redirect") { yestv.jumpPageWithFinishCurrentPage(pageClassName, paramsJSON); }
|
}
|
catch (e) { yesApp.showToast("跳转Web失败(请升级到最新版)"); }
|
}
|
// 商品分享页
|
else if (objThis.placeName == "share")
|
{
|
if (objThis.data.id == null || objThis.data.id == '') { yesApp.showToast("商品ID格式遵守:{id:1241343243}"); }
|
else
|
{
|
if (platform == 'android') { pageClassName = "com.yeshi.ec.rebate.myapplication.ui.invite.ShareBrowserActivity"; }
|
else { pageClassName = "ShonpingShareViewController"; }
|
var data = { url: "http://flq.yeshitv.com/fanli/client/html/sharegoods/index.html?id=" + objThis.data.id };
|
paramsJSON = JSON.stringify(data);
|
// 调用跳转方法
|
try{
|
if (objThis.type == "navigate") { yestv.jumpPage(pageClassName, paramsJSON); }
|
else if (objThis.type == "redirect") { yestv.jumpPageWithFinishCurrentPage(pageClassName, paramsJSON); }
|
}
|
catch (e) { yesApp.showToast("进入分享失败(请升级到最新版)"); }
|
}
|
}
|
// 收藏页
|
else if (objThis.placeName == "collect")
|
{
|
if (platform == 'android') { pageClassName = "com.yeshi.ec.rebate.myapplication.ui.invite.ShareBrowserActivity"; }
|
else { pageClassName = "ShonpingShareViewController"; }
|
paramsJSON = null;
|
// 调用跳转方法
|
try{
|
if (objThis.type == "navigate") { yestv.jumpPage(pageClassName, paramsJSON); }
|
else if (objThis.type == "redirect") { yestv.jumpPageWithFinishCurrentPage(pageClassName, paramsJSON); }
|
}
|
catch (e) { yesApp.showToast("进入收藏失败(请升级到最新版)"); }
|
}
|
// 福利中心页面
|
else if (objThis.placeName == "welfare")
|
{
|
if (platform == 'android') { pageClassName = "com.yeshi.ec.rebate.myapplication.ui.mine.WelfareCenterActivity"; }
|
else { pageClassName = "WelfareCenterController"; }
|
paramsJSON = null;
|
// 调用跳转方法
|
try{
|
if (objThis.type == "navigate") { yestv.jumpPage(pageClassName, paramsJSON); }
|
else if (objThis.type == "redirect") { yestv.jumpPageWithFinishCurrentPage(pageClassName, paramsJSON); }
|
}
|
catch (e) { yesApp.showToast("进入福利中心失败(请升级到最新版)"); }
|
}
|
// 浏览记录页
|
else if (objThis.placeName == "history")
|
{
|
if (platform == 'android') { pageClassName = "com.yeshi.ec.rebate.myapplication.ui.mine.MyFootmarkActivity"; }
|
else { pageClassName = "FootprintsViewController"; }
|
paramsJSON = null;
|
// 调用跳转方法
|
try{
|
if (objThis.type == "navigate") { yestv.jumpPage(pageClassName, paramsJSON); }
|
else if (objThis.type == "redirect") { yestv.jumpPageWithFinishCurrentPage(pageClassName, paramsJSON); }
|
}
|
catch (e) { yesApp.showToast("进入浏览记录失败(请升级到最新版)"); }
|
}
|
// 用户信息修改页
|
else if (objThis.placeName == "userupdate")
|
{
|
if (platform == 'android') { pageClassName = "com.yeshi.ec.rebate.myapplication.ui.mine.MyInfoActivity"; }
|
else { pageClassName = "userInfoViewController"; }
|
paramsJSON = null;
|
// 调用跳转方法
|
try{
|
if (objThis.type == "navigate") { yestv.jumpPage(pageClassName, paramsJSON); }
|
else if (objThis.type == "redirect") { yestv.jumpPageWithFinishCurrentPage(pageClassName, paramsJSON); }
|
}
|
catch (e) { yesApp.showToast("进入用户信息失败(请升级到最新版)"); }
|
}
|
// 新手攻略页
|
else if (objThis.placeName == "strategy")
|
{
|
if (platform == 'android') { pageClassName = "com.yeshi.ec.rebate.myapplication.ui.mine.weex.WeexApplicationActivity"; }
|
else { pageClassName = "WeexNativeController"; }
|
paramsJSON = JSON.stringify({ url: "http://ec-1255749512.file.myqcloud.com/resource/weex/gonglue.js" });
|
// 调用跳转方法
|
try{
|
if (objThis.type == "navigate") { yestv.jumpPage(pageClassName, paramsJSON); }
|
else if (objThis.type == "redirect") { yestv.jumpPageWithFinishCurrentPage(pageClassName, paramsJSON); }
|
}
|
catch (e) { yesApp.showToast("进入新手攻略失败(请升级到最新版)"); }
|
}
|
|
// 2. 没有任何目的地
|
else if (objThis.placeName.length <= 0)
|
{
|
// 跳到百川
|
if (objThis.jumpDetail.type && objThis.jumpDetail.type == "baichuan")
|
{
|
// 还没有淘客参数,那么去请求
|
if (yesApp.tbPidInfo == null && objThis.greenChannel == false)
|
{
|
yesApp.tbPid({
|
fail: function () {},
|
success: function ()
|
{
|
try { yestv.jumpBaiChuan(yesApp.tbPidInfo, objThis.params.url, objThis.jumpDetail.spId); }
|
catch(e){ yesApp.showToast("跳转百川失败(请升级到最新版)"); }
|
},
|
});
|
}
|
// 已经有淘客参数了
|
else {
|
try { yestv.jumpBaiChuan(yesApp.tbPidInfo, objThis.params.url, objThis.jumpDetail.spId); }
|
catch(e){ yesApp.showToast("跳转百川失败(请升级到最新版)"); }
|
}
|
}
|
// 2. 普通跳转
|
else if (objThis.jumpDetail.activity && objThis.jumpDetail.controller)
|
{
|
// 1. 安卓设备
|
if (platform == "android")
|
{
|
try { yestv.jumpPage(objThis.jumpDetail.activity, JSON.stringify(objThis.params)); }
|
catch(e){ yesApp.showToast("页面跳转失败(请升级到最新版)"); }
|
}
|
// 2. IOS设备
|
else if (platform == "ios")
|
{
|
try { yestv.jumpPage(objThis.jumpDetail.controller, JSON.stringify(objThis.params)); }
|
catch(e){ yesApp.showToast("页面跳转失败(请升级到最新版)"); }
|
}
|
}
|
}
|
|
}
|
|
},
|
|
};
|