页面分享处理优化、新增百度小程序搜索引擎适配

master
gongfuxiang 2022-04-07 11:21:21 +08:00
parent 66ddaf11e9
commit 8ed19d2fc1
2 changed files with 199 additions and 167 deletions

360
App.vue
View File

@ -2,8 +2,8 @@
import base64 from './common/js/lib/base64.js';
export default {
globalData: {
data: {
//
data: {
//
cache_scene_key: "cache_scene_key",
// uuidkey
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;
}
}
// queryscene
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: {}

View File

@ -3,13 +3,15 @@ export default {
return {
// 设置默认的分享参数、页面可自定义以下数据
// 如果页面不设置share就触发这个默认的分享
// 标题、描述、地址、参数、封面图片
// 标题、关键字、描述、地址、参数、封面图片、视频
share_info: {
title: '',
kds: '',
desc: '',
path: '',
query: '',
img: ''
img: '',
video: ''
}
}
},