// 跳转
route(url,types,e){
if(types.split(":")[1]){
uni.vibrateShort();
}
let type = types.split(":")[0]
if(!type){
if(url){
const jsonString = JSON.stringify(url);
console.log(jsonString);
this.route(jsonString.url,jsonString.type,e)
return;
}
}
if (this.timer) {
clearInterval(this.timer);
this.timer = null; // 重置定时器变量
}
let _this = this;
// 保留当前页面跳转
if(type == 'navigateTo'){
if(!url)return;
uni.navigateTo({
url:url,
})
}
// 保留当前页面跳转APP
if(type == 'navigateToApp'){
if(!url)return;
let type = types.split(":")[0]
uni.navigateTo({
url:url.url,
animationType:url.animationType,
animationDuration:url.animationDuration,
})
}
// 弹出层
if(type == 'layer'){
if(!url)return;
this.list.layer = url;
}
// 打开手电筒
if(type == 'sdOpen'){
if(this.sd == false){
this.sd = true;
this.onTorch()
}else{
this.sd = false;
this.offTorch()
}
}
// 关闭弹出层
if(type == 'layerClosed'){
if(!url)return;
this.layerClosed();
}
// 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面。
if(type == 'switchTab'){
if(!url)return;
uni.switchTab({
url: url,
});
}
// 关闭所有页面跳转
if(type == 'reLaunch'){
if(!url)return;
uni.reLaunch({
url:url,
});
}
// 关闭当前页面
if(type == 'navigateBack'){
if(!url)return;
uni.navigateBack();
}
// 关闭当前页面去某个页面
if(type == 'redirectTo'){
if(!url)return;
uni.redirectTo({
url: url
});
}
//获取用户信息
if(type == 'getUserProfile'){
if(!url)return;
uni.showLoading({
title: '请稍后..',
mask:true
});
console.log(url);
wx.getUserProfile({
desc:'用于完善用户信息',
success: (res) => {
console.log(res);
wx.login({
success: da => {
uni.request({
url:uni.getStorageSync('GetUrl')+url,
data: {
res:res,
code:da.code,
getkey: uni.getStorageSync('key'),
type: uni.getStorageSync('type'),
banben: uni.getStorageSync('banben'),
lng: uni.getStorageSync('lng'),
lat: uni.getStorageSync('lat'),
UniqueId: uni.getStorageSync('UniqueId'),
config: _this.config,
data: _this.list.dataModel,
},
method: 'POST',
success: (_res) => {
uni.hideLoading();
if(_res.data.code == 1){
_this.showCustomToast(_res.data.msg,{
showSuccessIcon: '/static/img/success.png',
duration: 1000,
},
);
setTimeout(function () {
_this.route(_res.data.url,_res.data.type);
}, 1000);
}else if(_res.data.code == 0){
_this.showCustomToast(_res.data.msg,{
showSuccessIcon: '/static/img/tips.png',
duration: 1000,
});
}
if(_res.data.key){
uni.setStorageSync('key', _res.data.key);
}
}
});
},fail: (err) => {
uni.hideLoading();
_this.showCustomToast('微信登陆失败',{
showSuccessIcon: '/static/img/error.png',
duration: 1000,
});
console.log('微信登陆失败:', err);
}
});
},fail: (err) => {
uni.hideLoading();
_this.showCustomToast('获取用户信息失败',{
showSuccessIcon: '/static/img/error.png',
duration: 1000,
});
console.log('获取用户信息失败:', err);
}
})
}
// 保存图片到相册
if(type == 'saveImageToPhotosAlbum'){
if(!url)return;
let result = _this.$refs.permissionRef.ensurePermission('album');
if (result) {
// uni.hideLoading();
uni.showLoading({
title: '保存中...'
});
uni.downloadFile({
url: url,
success: function (res) {
if (res.statusCode === 200) {
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: () => {
uni.hideLoading();
uni.showToast({
title: '保存成功',
icon: 'success'
});
},
fail: err => {
uni.hideLoading();
uni.showToast({
title: '保存失败',
icon: 'none'
});
}
});
}
},complete: (res) => {
uni.hideLoading();
}
});
}
}
// 微信小程序跳转
if(type == 'weixin'){
if(!url)return;
// #ifdef MP-WEIXIN
uni.navigateToMiniProgram(url)
// #endif
}
// 获取位置
if(type == 'chooseLocation'){
uni.chooseLocation({
success: function (res) {
let value = {
res:res,
diqu:res.address,
address:res.address,
title:res.name,
lat:res.latitude,
lng:res.longitude,
}
uni.setStorageSync(url.key, value);
if(url.data){
this.route(url.data.url,url.data.type,e)
}else{
uni.navigateBack();
}
}
});
}
// 扫码
if(type == 'saoma'){
// 修改后的调用方式
_this.$refs.permissionRef.ensurePermission('camera')
.then(hasPermission => {
if (hasPermission) {
uni.scanCode({
success: function (res) {
if(url.model){
_this.list.dataModel[url.model] = res.result
}else{
if (res.result.includes('https://')) {
if (res.result.includes('/pages')) {
let resUrl = res.result.match(/\/pages\/.*$/);
uni.navigateTo({
url:resUrl[0],
})
}else{
uni.setStorageSync('get_src', res.result);
uni.navigateTo({
url:'/pages/mi/url'
});
}
}else{
if (res.result.includes('/pages')) {
uni.navigateTo({
url:res.result,
})
}else{
uni.setStorageSync('get_src', res.result);
uni.navigateTo({
url:'/pages/mi/url'
});
}
}
}
}
});
}
});
}
if(type == 'previewImage'){
if(!url)return;
uni.previewImage({
urls: url,
current: url[e]
});
}
if(type == 'image'){
if(!url)return;
uni.previewImage({
urls: [url],
current: url
});
}
// 弹出提示
if(type == 'tips'){
uni.showActionSheet({
title:'提示',
itemList: url.map(item => item.name),
success: function (_res) {
url.forEach(function(value, key) {
if(_res.tapIndex == key){
_this.route(value.url,value.type)
}
});
}
});
}
// 提示
if(type == 'showToast'){
_this.showCustomToast(url);
}
if(type == 'showToastSuccess'){
_this.showCustomToast(url.title,{
showSuccessIcon: '/static/img/success.png',
duration: 1000,
});
if(url.data){
setTimeout(function () {
_this.route(url.data.url,url.data.type,e)
}, 1000);
}
}
if(type == 'showToastDiy'){
_this.showCustomToast(url.title,{
showSuccessIcon: url.icon,
duration: url.duration,
});
if(url.data){
setTimeout(function () {
_this.route(url.data.url,url.data.type,e)
}, 1000);
}
}
// 将页面滚动到目标位置
if(type == 'scroll'){
uni.pageScrollTo({
scrollTop: url,
duration: 300,
})
}
// 电话
if(type == 'tel'){
let result = _this.$refs.permissionRef.ensurePermission('phone');
if(result){
uni.makePhoneCall({
phoneNumber: url,
});
}
}
// 请求跳转
if(type == 'get'){
if(!url)return;
this.GetJson(url);
}
// 请求跳转清除某个数值
if(type == 'getun'){
if(!url)return;
this.list.data[url.id].lists = [];
this.GetJson(url.url);
}
// 设置值
if(type == 'setStorageSync'){
if(!url)return;
uni.setStorageSync(url.key, url.value);
if(url.data){
this.route(url.data.url,url.data.type,e)
}
}
// 访问地图
if(type == 'ditu'){
if(!url)return;
console.log(url);
uni.openLocation({
latitude:url.lat,
longitude:url.lng,
name:url.name,
address:url.address,
success: function (e) {
console.log(e);
}
});
}
// 退出登陆
if(type == 'tuichu'){
uni.setStorageSync('key', '');
if(!url)return;
uni.showLoading({
title: '退出成功'
});
setTimeout(function () {
uni.hideLoading();
uni.navigateTo({
url:url,
})
}, 500);
}
if(type == 'copy'){
if(!url)return;
// 复制
uni.setClipboardData({
data: url,
success: function () {
}
});
}
// 表单提交
if(type == 'getAdd'){
if(!url)return;
this.GetAdd(url);
}
// 获取验证码
if(type == 'code'){
if(!url)return;
if(this.timer)return;
this.getCode(url);
}
// 跳转到网页
if(type == 'location'){
if(!url)return;
window.location.replace(url)
}
// h5和app支付微信支付宝
if(type == 'pay'){
if(!url)return;
// this.get_dingdan(res.data.oid)
/*#ifndef APP-PLUS*/
// 不是app
uni.setStorageSync('get_src', url);
uni.navigateTo({
url:'/pages/mi/url'
});
/*#endif*/
/*#ifdef APP-PLUS*/
// 是app
this.webviewStyles = url;
/*#endif*/
}
if(type == 'url'){
if(!url)return;
uni.setStorageSync('get_src', url);
uni.navigateTo({
url:'/pages/mi/url'
});
}
// 微信小程序
if(type == 'pay_weixin'){
if(!url)return;
this.payHandler(url)
}
// 微信客服
if(type == 'kefu'){
if(!url)return;
uni.openCustomerServiceChat({
extInfo: {
url: url.url,
},
corpId: url.id,
sessionFrom: url.title
});
}
if(type == 'wxLogin'){
if(!url)return;
this.wxLogin(url,e)
}
if(type == 'openURL'){
if(!url)return;
plus.runtime.openURL(url);
}
if(type == 'downloadFile'){
if(!url)return;
// 匹配最后一个点后的内容,直到遇到问号、哈希或字符串结束
const match = url.match(/\.([^./?#]+)(?:[?#]|$)/i);
// 修复语法错误: const ext = match...
const ext = match ? match[1].toLowerCase() : '';
// 修复拼写错误: jpge -> jpeg
if (ext === 'png' || ext === 'jpg' || ext === 'jpeg' || ext === 'gif' || ext === 'webp') {
uni.previewImage({
current: 0, // 当前显示图片的索引
urls: [url] // 需要预览的图片URL列表
});
return true; // 返回true表示这是一个图片并已预览
}
uni.showLoading({
title: '下载中..',
mask:true
});
uni.downloadFile({
url: url,
success: (_res) => {
if (_res.statusCode === 200) {
uni.openDocument({
filePath: _res.tempFilePath,
// fileType: 'pdf',
// fileType: 'doc',
success: function (res) {
console.log('打开文档成功');
},
fail: function (err) {
console.log('打开文档失败', err);
}
});
}else{
plus.runtime.openURL(_res.data.url);
}
},complete: (res) => {
setTimeout(function () {
uni.hideLoading();
}, 10);
}
});
}
// 删除
if(type == 'un'){
if(!url)return;
let length = _this.list.data.length - 1;
if(_this.list.data[length].type == 'tab'){
length = length - 1;
}
console.log(length);
console.log(e);
uni.showActionSheet({
title:'是否删除',
itemList: ['确定'],
success: function (_res) {
uni.request({
url:uni.getStorageSync('GetUrl')+url,
data: {
getkey: uni.getStorageSync('key'),
type: uni.getStorageSync('type'),
banben: uni.getStorageSync('banben'),
lng: uni.getStorageSync('lng'),
lat: uni.getStorageSync('lat'),
UniqueId: uni.getStorageSync('UniqueId'),
config: _this.config,
},
method: 'POST',
success: (res) => {
if(res.data.code == 1){
_this.list.data[length].lists.splice(e,1);
_this.showCustomToast(res.data.msg,{
showSuccessIcon: '/static/img/success.png',
duration: 1000,
});
}else{
_this.showCustomToast(res.data.msg);
}
}
});
}
});
}
if(type == 'unid'){
if(!url)return;
uni.showActionSheet({
title:'是否删除',
itemList: ['确定'],
success: function (_res) {
uni.request({
url:uni.getStorageSync('GetUrl')+url.url,
data: {
getkey: uni.getStorageSync('key'),
type: uni.getStorageSync('type'),
banben: uni.getStorageSync('banben'),
lng: uni.getStorageSync('lng'),
lat: uni.getStorageSync('lat'),
UniqueId: uni.getStorageSync('UniqueId'),
config: _this.config,
},
method: 'POST',
success: (res) => {
if(res.data.code == 1){
_this.list.data[url.un].lists.splice(url.unid,1)
_this.showCustomToast(res.data.msg,{
showSuccessIcon: '/static/img/success.png',
duration: 1000,
});
}else{
_this.showCustomToast(res.data.msg);
}
}
});
}
});
}
// 分享
// https://uniapp.dcloud.net.cn/api/plugins/share.html#%E5%88%86%E4%BA%AB
if(type == 'share'){
uni.share(url);
}
// 新增静态设置模板数据
if(type == 'setlist'){
// _this.list[url.id] = url.data
_this.list[url.id] = Object.assign(_this.list[url.id], url.data);
}
if(type == 'setlists'){
_this.list[url.id] = url.data
}
// 新增设置某个表单值
if(type == 'setlistDataModel'){
_this.list.dataModel[url.id] = url.data
}
// 新增设置某个内容
if(type == 'setlistData'){
_this.list.data[url.id] = url.data
}
// 新增diy设置任意值
if(type == 'setlistDiy'){
// 'url' => array(
// 'id' => 'dataModel:ks', // 用:分隔多级键名
// 'data' => '879', // 直接赋值ks的目标值
// ),
// 拆分多级键名(以:为分隔符)
const keys = url.id.split(':');
let target = _this.list;
for (let i = 0; i < keys.length - 1; i++) {
const key = keys[i];
target = target[key];
}
// 给最后一个键赋值
const lastKey = keys[keys.length - 1];
target[lastKey] = url.data;
}
},