页面分享处理优化、新增百度小程序搜索引擎适配
parent
66ddaf11e9
commit
8ed19d2fc1
360
App.vue
360
App.vue
|
|
@ -2,8 +2,8 @@
|
|||
import base64 from './common/js/lib/base64.js';
|
||||
export default {
|
||||
globalData: {
|
||||
data: {
|
||||
// 场景值
|
||||
data: {
|
||||
// 场景值
|
||||
cache_scene_key: "cache_scene_key",
|
||||
// uuid缓存key
|
||||
cache_user_uuid_key: "cache_user_uuid_key",
|
||||
|
|
@ -30,10 +30,10 @@
|
|||
// 成功圆形提示图片
|
||||
default_round_success_icon: "/static/images/common/round-success-icon.png",
|
||||
// 错误圆形提示图片
|
||||
default_round_error_icon: "/static/images/common/round-error-icon.png",
|
||||
// 分享及转发使用页面设置的默认图片及系统默认图片(0 否, 1 是)
|
||||
is_share_use_image: 1,
|
||||
// 商品详情页底部导航是否开启购物车功能(0 否, 1 是)
|
||||
default_round_error_icon: "/static/images/common/round-error-icon.png",
|
||||
// 分享及转发使用页面设置的默认图片及系统默认图片(0 否, 1 是)
|
||||
is_share_use_image: 1,
|
||||
// 商品详情页底部导航是否开启购物车功能(0 否, 1 是)
|
||||
is_goods_bottom_opt_cart: 1,
|
||||
// tabbar页面
|
||||
tabbar_pages: [
|
||||
|
|
@ -68,52 +68,52 @@
|
|||
/**
|
||||
* 启动参数处理
|
||||
*/
|
||||
launch_params_handle(params) {
|
||||
// 原有缓存
|
||||
var cache_params = this.get_launch_cache_info();
|
||||
|
||||
launch_params_handle(params) {
|
||||
// 原有缓存
|
||||
var cache_params = this.get_launch_cache_info();
|
||||
|
||||
// 当前参数、从query读取覆盖
|
||||
if ((params.query || null) != null) {
|
||||
params = params.query;
|
||||
}
|
||||
}
|
||||
// query下scene参数解析处理
|
||||
if ((params.scene || null) != null) {
|
||||
params = this.url_params_to_json(decodeURIComponent(params.scene));
|
||||
}
|
||||
|
||||
// 原始缓存是否存在邀请id、邀请使用最开始的用户id
|
||||
if(cache_params != null && (cache_params.referrer || null) != null) {
|
||||
params['referrer'] = cache_params.referrer;
|
||||
}
|
||||
}
|
||||
|
||||
// 原始缓存是否存在邀请id、邀请使用最开始的用户id
|
||||
if(cache_params != null && (cache_params.referrer || null) != null) {
|
||||
params['referrer'] = cache_params.referrer;
|
||||
}
|
||||
|
||||
return params;
|
||||
},
|
||||
|
||||
/**
|
||||
* 当前是否单页模式
|
||||
*/
|
||||
is_current_single_page() {
|
||||
var scene = this.get_scene_data();
|
||||
// #ifdef MP-WEIXIN
|
||||
return (scene == 1154) ? 1 : 0;
|
||||
// #endif
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* 场景值获取
|
||||
*/
|
||||
get_scene_data() {
|
||||
return uni.getStorageSync(this.data.cache_scene_key) || 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* 场景值设置
|
||||
*/
|
||||
set_scene_data(params) {
|
||||
var scene = ((params.scene || null) == null) ? 0 : parseInt(params.scene);
|
||||
uni.setStorageSync(this.data.cache_scene_key, scene);
|
||||
return scene;
|
||||
},
|
||||
|
||||
/**
|
||||
* 当前是否单页模式
|
||||
*/
|
||||
is_current_single_page() {
|
||||
var scene = this.get_scene_data();
|
||||
// #ifdef MP-WEIXIN
|
||||
return (scene == 1154) ? 1 : 0;
|
||||
// #endif
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* 场景值获取
|
||||
*/
|
||||
get_scene_data() {
|
||||
return uni.getStorageSync(this.data.cache_scene_key) || 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* 场景值设置
|
||||
*/
|
||||
set_scene_data(params) {
|
||||
var scene = ((params.scene || null) == null) ? 0 : parseInt(params.scene);
|
||||
uni.setStorageSync(this.data.cache_scene_key, scene);
|
||||
return scene;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -128,9 +128,9 @@
|
|||
info = this.set_system_info() || null;
|
||||
} else {
|
||||
info = uni.getStorageSync(this.data.cache_system_info_key) || null;
|
||||
}
|
||||
if(info == null || (key|| null) == null) {
|
||||
return info;
|
||||
}
|
||||
if(info == null || (key|| null) == null) {
|
||||
return info;
|
||||
}
|
||||
return (info[key] == undefined) ? (dv == undefined ? null : dv) : info[key];
|
||||
},
|
||||
|
|
@ -138,8 +138,8 @@
|
|||
/**
|
||||
* 设置设备信息
|
||||
*/
|
||||
set_system_info() {
|
||||
var system_info = uni.getSystemInfoSync();
|
||||
set_system_info() {
|
||||
var system_info = uni.getSystemInfoSync();
|
||||
uni.setStorageSync(this.data.cache_system_info_key, system_info);
|
||||
return system_info;
|
||||
},
|
||||
|
|
@ -169,25 +169,25 @@
|
|||
if (params != "" && params.substr(0, 1) != "&") {
|
||||
params = "&" + params;
|
||||
}
|
||||
|
||||
// 参数处理
|
||||
var url = this.data.request_url + (group || "api")+".php?s=" + c + "/" + a + plugins_params;
|
||||
|
||||
// 参数处理
|
||||
var url = this.data.request_url + (group || "api")+".php?s=" + c + "/" + a + plugins_params;
|
||||
return this.request_params_handle(url) + "&ajax=ajax" + params;
|
||||
},
|
||||
|
||||
/**
|
||||
* 请求参数处理
|
||||
* url url地址
|
||||
*/
|
||||
request_params_handle(url) {
|
||||
// 用户信息
|
||||
var user = this.get_user_cache_info();
|
||||
var token = user == false ? '' : user.token || '';
|
||||
var uuid = this.request_uuid();
|
||||
var client_value = this.application_client_type();
|
||||
// 拼接标识
|
||||
var join = (url.indexOf('?') == -1) ? '?' : '&';
|
||||
return url + join + "application=app&application_client_type="+ client_value + "&token=" + token + "&uuid=" + uuid;
|
||||
},
|
||||
|
||||
/**
|
||||
* 请求参数处理
|
||||
* url url地址
|
||||
*/
|
||||
request_params_handle(url) {
|
||||
// 用户信息
|
||||
var user = this.get_user_cache_info();
|
||||
var token = user == false ? '' : user.token || '';
|
||||
var uuid = this.request_uuid();
|
||||
var client_value = this.application_client_type();
|
||||
// 拼接标识
|
||||
var join = (url.indexOf('?') == -1) ? '?' : '&';
|
||||
return url + join + "application=app&application_client_type="+ client_value + "&token=" + token + "&uuid=" + uuid;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -251,15 +251,15 @@
|
|||
*/
|
||||
get_launch_cache_info() {
|
||||
return uni.getStorageSync(this.data.cache_launch_info_key) || null;
|
||||
},
|
||||
|
||||
/**
|
||||
* 系统参数设置
|
||||
*/
|
||||
set_launch_cache_info(params) {
|
||||
params = this.launch_params_handle(params);
|
||||
uni.setStorageSync(this.data.cache_launch_info_key, params);
|
||||
return params;
|
||||
},
|
||||
|
||||
/**
|
||||
* 系统参数设置
|
||||
*/
|
||||
set_launch_cache_info(params) {
|
||||
params = this.launch_params_handle(params);
|
||||
uni.setStorageSync(this.data.cache_launch_info_key, params);
|
||||
return params;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -785,32 +785,40 @@
|
|||
}
|
||||
},
|
||||
|
||||
// 显示分享菜单
|
||||
show_share_menu() {
|
||||
// 页面分享处理
|
||||
page_share_handle(share = null) {
|
||||
// 当前页面
|
||||
var pages = getCurrentPages();
|
||||
var obj = pages[pages.length-1];
|
||||
|
||||
// 分享信息
|
||||
var share = this.share_content_handle(obj.share_info || {});
|
||||
// 分享信息、是否指定参数
|
||||
if((share || null) == null) {
|
||||
share = {}
|
||||
}
|
||||
// 从页面对象获取参数
|
||||
if(Object.keys(share).length <= 0) {
|
||||
share = obj.share_info || {};
|
||||
}
|
||||
// 参数处理
|
||||
share = this.share_content_handle(share);
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
// 微信小程序展示系统分享好友和朋友圈按钮
|
||||
// 其他端小程序不用展示会调起分享窗口
|
||||
var not_pages = ['/pages/user/user', '/pages/cart/cart'];
|
||||
if(not_pages.indexOf(share.url) == -1) {
|
||||
uni.showShareMenu({
|
||||
withShareTicket: true,
|
||||
title: share.title,
|
||||
desc: share.desc,
|
||||
path: share.path + share.query,
|
||||
imageUrl: share.img,
|
||||
menus: ['shareAppMessage', 'shareTimeline']
|
||||
});
|
||||
} else {
|
||||
wx.hideShareMenu({
|
||||
menus: ['shareTimeline']
|
||||
});
|
||||
// 其他端小程序不用展示会调起分享窗口
|
||||
var not_pages = ['/pages/user/user', '/pages/cart/cart'];
|
||||
if(not_pages.indexOf(share.url) == -1) {
|
||||
uni.showShareMenu({
|
||||
withShareTicket: true,
|
||||
title: share.title,
|
||||
desc: share.desc,
|
||||
path: share.path + share.query,
|
||||
imageUrl: share.img,
|
||||
menus: ['shareAppMessage', 'shareTimeline']
|
||||
});
|
||||
} else {
|
||||
wx.hideShareMenu({
|
||||
menus: ['shareTimeline']
|
||||
});
|
||||
}
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
|
|
@ -870,6 +878,22 @@
|
|||
});
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-BAIDU
|
||||
// 百度小程序wab化搜索引擎数据设置
|
||||
uni.setPageInfo({
|
||||
title: share.title,
|
||||
keywords: share.kds || share.desc,
|
||||
articleTitle: share.title,
|
||||
description: share.desc,
|
||||
image: share.img,
|
||||
video: ((share.video || null) == null) ? [] : [{
|
||||
url: share.video,
|
||||
duration: '100',
|
||||
image: share.img
|
||||
}]
|
||||
});
|
||||
// #endif
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -896,19 +920,19 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 默认值
|
||||
if(value == null && default_value != undefined) {
|
||||
value = default_value;
|
||||
}
|
||||
// 无数据则处理自定义字段定义的数据
|
||||
if(value == null) {
|
||||
switch(key) {
|
||||
// 货币符号
|
||||
case 'currency_symbol' :
|
||||
value = this.data.currency_symbol;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 默认值
|
||||
if(value == null && default_value != undefined) {
|
||||
value = default_value;
|
||||
}
|
||||
// 无数据则处理自定义字段定义的数据
|
||||
if(value == null) {
|
||||
switch(key) {
|
||||
// 货币符号
|
||||
case 'currency_symbol' :
|
||||
value = this.data.currency_symbol;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
},
|
||||
|
|
@ -1234,8 +1258,7 @@
|
|||
// 获取当前页面地址、不含?后面的参数
|
||||
get_page_url(is_whole) {
|
||||
// #ifdef MP || APP
|
||||
var pages = getCurrentPages();
|
||||
var url = pages[pages.length-1].$page.fullPath;
|
||||
var url = this.current_page();
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
var url = window.location.href;
|
||||
|
|
@ -1330,67 +1353,74 @@
|
|||
}
|
||||
}
|
||||
return ((query || null) == null) ? '' : '?'+query;
|
||||
},
|
||||
|
||||
// 是否朋友圈单页访问提示
|
||||
is_single_page_check() {
|
||||
if(this.is_current_single_page() == 1) {
|
||||
this.showToast('请前往小程序使用完整服务');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
// 进入客服
|
||||
chat_entry_handle(url) {
|
||||
if((url || null) == null) {
|
||||
this.showToast("客服地址有误");
|
||||
} else {
|
||||
// 拼接基础参数
|
||||
url = this.request_params_handle(url);
|
||||
|
||||
// 来源地址、拼接当前小程序页面
|
||||
var pages = getCurrentPages();
|
||||
var page = pages[pages.length-1];
|
||||
var route = page.route;
|
||||
var options = page.options || {};
|
||||
var query = '';
|
||||
if(JSON.stringify(options) != '{}') {
|
||||
for(var i in options) {
|
||||
query += '&'+i+'='+options[i];
|
||||
}
|
||||
}
|
||||
if((query || null) != null) {
|
||||
route += '?'+query.substr(1);
|
||||
}
|
||||
url += '&source='+encodeURIComponent(base64.encode(route).replace(new RegExp(/=/g), ''));
|
||||
|
||||
// 打开webview
|
||||
this.open_web_view(url);
|
||||
}
|
||||
},
|
||||
|
||||
// 是否朋友圈单页访问提示
|
||||
is_single_page_check() {
|
||||
if(this.is_current_single_page() == 1) {
|
||||
this.showToast('请前往小程序使用完整服务');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
// 当前页面地址
|
||||
current_page() {
|
||||
// 来源地址、拼接当前小程序页面
|
||||
var pages = getCurrentPages();
|
||||
var page = pages[pages.length-1];
|
||||
var route = page.route;
|
||||
var options = page.options || {};
|
||||
var query = '';
|
||||
if(JSON.stringify(options) != '{}') {
|
||||
for(var i in options) {
|
||||
query += '&'+i+'='+options[i];
|
||||
}
|
||||
}
|
||||
if((query || null) != null) {
|
||||
route += '?'+query.substr(1);
|
||||
}
|
||||
return route;
|
||||
},
|
||||
|
||||
// 进入客服
|
||||
chat_entry_handle(url) {
|
||||
if((url || null) == null) {
|
||||
this.showToast("客服地址有误");
|
||||
} else {
|
||||
// 拼接基础参数
|
||||
url = this.request_params_handle(url);
|
||||
|
||||
// 拼接当前页面地址
|
||||
var route = this.current_page();
|
||||
url += '&source='+encodeURIComponent(base64.encode(route).replace(new RegExp(/=/g), ''));
|
||||
|
||||
// 打开webview
|
||||
this.open_web_view(url);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 小程序初始化
|
||||
*/
|
||||
onLaunch(params) {},
|
||||
|
||||
/**
|
||||
* 小程序页面显示
|
||||
*/
|
||||
onShow(params) {
|
||||
// 初始化配置
|
||||
this.globalData.init_config();
|
||||
|
||||
// 设置设备信息
|
||||
this.globalData.set_system_info();
|
||||
|
||||
// 参数处理+缓存
|
||||
this.globalData.set_launch_cache_info(params);
|
||||
|
||||
// 场景值
|
||||
this.globalData.set_scene_data(params);
|
||||
onLaunch(params) {},
|
||||
|
||||
/**
|
||||
* 小程序页面显示
|
||||
*/
|
||||
onShow(params) {
|
||||
// 初始化配置
|
||||
this.globalData.init_config();
|
||||
|
||||
// 设置设备信息
|
||||
this.globalData.set_system_info();
|
||||
|
||||
// 参数处理+缓存
|
||||
this.globalData.set_launch_cache_info(params);
|
||||
|
||||
// 场景值
|
||||
this.globalData.set_scene_data(params);
|
||||
},
|
||||
|
||||
methods: {}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,15 @@ export default {
|
|||
return {
|
||||
// 设置默认的分享参数、页面可自定义以下数据
|
||||
// 如果页面不设置share,就触发这个默认的分享
|
||||
// 标题、描述、地址、参数、封面图片
|
||||
// 标题、关键字、描述、地址、参数、封面图片、视频
|
||||
share_info: {
|
||||
title: '',
|
||||
kds: '',
|
||||
desc: '',
|
||||
path: '',
|
||||
query: '',
|
||||
img: ''
|
||||
img: '',
|
||||
video: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue