修改登录,绑定跳转方法。增加路由守卫。
This commit is contained in:
parent
806eae80dc
commit
4a5e422031
122
common/common.js
122
common/common.js
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
import Vue from 'vue'
|
||||
import config from '@/common/config.js'
|
||||
import { navigateTo as routerNavigateTo, navigateBack as routerNavigateBack } from '@/common/router.js'
|
||||
|
||||
// 防止处理多次点击
|
||||
function noMultipleClicks(methods, info) {
|
||||
|
|
@ -444,27 +445,35 @@ export default {
|
|||
return
|
||||
}
|
||||
|
||||
if (Object.keys(query).length > 0) {
|
||||
url += this.qs(query)
|
||||
// 确定跳转类型
|
||||
let navigationType = 'navigateTo';
|
||||
switch (type) {
|
||||
case 2:
|
||||
navigationType = 'redirectTo';
|
||||
break;
|
||||
case 3:
|
||||
navigationType = 'switchTab';
|
||||
break;
|
||||
case 4:
|
||||
navigationType = 'reLaunch';
|
||||
break;
|
||||
default:
|
||||
navigationType = 'navigateTo';
|
||||
}
|
||||
|
||||
const opt = {
|
||||
url,
|
||||
success,
|
||||
fail,
|
||||
complete
|
||||
}
|
||||
|
||||
const dic = {
|
||||
1: uni.navigateTo,
|
||||
2: uni.redirectTo,
|
||||
3: uni.switchTab,
|
||||
4: uni.reLaunch
|
||||
}
|
||||
|
||||
const action = dic[type]
|
||||
|
||||
action(opt)
|
||||
|
||||
// 使用导入的路由方法而不是this.$router
|
||||
return routerNavigateTo(url, query, navigationType)
|
||||
.then(res => {
|
||||
if (typeof success === 'function') success(res);
|
||||
return res;
|
||||
})
|
||||
.catch(err => {
|
||||
if (typeof fail === 'function') fail(err);
|
||||
throw err;
|
||||
})
|
||||
.finally(() => {
|
||||
if (typeof complete === 'function') complete();
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -474,32 +483,17 @@ export default {
|
|||
*/
|
||||
back(e) {
|
||||
/* 判断传入的是否是数字 */
|
||||
let pages = getCurrentPages()
|
||||
console.log('pgaes', pages)
|
||||
if (pages.length >= 2) {
|
||||
if (typeof e === 'number' && !isNaN(e)) {
|
||||
/* 如果要跳转的长度小于页面栈数量 */
|
||||
if (e < pages.length) {
|
||||
uni.navigateBack({
|
||||
delta: e
|
||||
})
|
||||
/* 否则回首页 */
|
||||
} else {
|
||||
uni.switchTab({
|
||||
url: '/pages/shouye/index'
|
||||
})
|
||||
}
|
||||
/* 默认返回上一级 */
|
||||
} else {
|
||||
uni.navigateBack({
|
||||
delta: 1
|
||||
})
|
||||
}
|
||||
} else {
|
||||
uni.switchTab({
|
||||
url: '/pages/shouye/index'
|
||||
})
|
||||
let delta = 1;
|
||||
if (typeof e === 'number' && !isNaN(e)) {
|
||||
delta = e;
|
||||
}
|
||||
|
||||
// 使用导入的routerNavigateBack而不是this.$router
|
||||
routerNavigateBack(delta)
|
||||
.catch(() => {
|
||||
// 如果返回失败,则回到首页
|
||||
routerNavigateTo('/pages/shouye/index', {}, 'switchTab');
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -519,14 +513,11 @@ export default {
|
|||
$navBack(num = 1, time = 0) {
|
||||
// 页面返回
|
||||
setTimeout(() => {
|
||||
uni.navigateBack({
|
||||
delta: num,
|
||||
fail: () => {
|
||||
uni.reLaunch({
|
||||
url: '/pages/shouye/index'
|
||||
})
|
||||
}
|
||||
})
|
||||
routerNavigateBack(num)
|
||||
.catch(() => {
|
||||
// 如果返回失败,则回到首页
|
||||
routerNavigateTo('/pages/shouye/index', {}, 'reLaunch');
|
||||
});
|
||||
}, time * 1000)
|
||||
},
|
||||
/**
|
||||
|
|
@ -617,14 +608,27 @@ export default {
|
|||
// #endif
|
||||
},
|
||||
nav(url) {
|
||||
uni.navigateTo({
|
||||
url: url,
|
||||
fail: () => {
|
||||
uni.switchTab({
|
||||
url: url
|
||||
// 解析URL和参数
|
||||
let urlPath = url;
|
||||
let params = {};
|
||||
|
||||
if (url.includes('?')) {
|
||||
const parts = url.split('?');
|
||||
urlPath = parts[0];
|
||||
|
||||
// 解析参数
|
||||
if (parts[1]) {
|
||||
parts[1].split('&').forEach(param => {
|
||||
const keyValue = param.split('=');
|
||||
if (keyValue.length === 2) {
|
||||
params[keyValue[0]] = decodeURIComponent(keyValue[1]);
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 使用导入的路由方法
|
||||
return routerNavigateTo(urlPath, params);
|
||||
},
|
||||
red(url) {
|
||||
uni.redirectTo({
|
||||
|
|
|
|||
|
|
@ -9,6 +9,35 @@ let configData = null;
|
|||
let isLoading = false;
|
||||
let loadPromise = null;
|
||||
const wx_version = "104";
|
||||
|
||||
// 白名单页面(不需要登录即可访问)
|
||||
export const whiteList = [
|
||||
"pages/shouye/index", // 首页
|
||||
"pages/shouye/detail", // 详情页
|
||||
"pages/shouye/huanxiang", // 换箱页面
|
||||
"pages/mall/index", // 商城首页
|
||||
"pages/shouye/detail_wuxian", // 无限详情页
|
||||
"pages/sangdai/sangdai", // 盒柜页面
|
||||
"pages/infinite/index", // 福利首页
|
||||
"pages/user/index", // 用户中心
|
||||
"pages/infinite/daily_check_in", // 每日签到
|
||||
"pages/infinite/bonus_house", // 福利屋
|
||||
"pages/other/prize_draw", // 每日奖品抽取
|
||||
"pages/shouye/danye", // 单页
|
||||
"pages/guize/guize", // 规则页面
|
||||
"pages/shouye/dada_ranking", // 达达排行榜
|
||||
"pages/shouye/yaoqing_ranking", // 邀请排行榜
|
||||
"pages/user/login" // 登录页面
|
||||
];
|
||||
|
||||
// API白名单(不需要登录即可访问的API)
|
||||
export const apiWhiteList = [
|
||||
'login_record',
|
||||
'api/warehouse_index',
|
||||
'api/user',
|
||||
'api/warehouse_send_record'
|
||||
];
|
||||
|
||||
const defaultConfig = {
|
||||
"good_type": [{ "value": 0, "sort_order": 0, "is_show": 1, "name": "全部", "pay_wechat": 1, "pay_balance": 1, "pay_currency": 1, "pay_currency2": 1, "pay_coupon": 1, "is_deduction": 1 }, { "value": 1, "sort_order": 1, "is_show": 0, "name": "一番赏", "pay_wechat": 1, "pay_balance": 1, "pay_currency": 1, "pay_currency2": 1, "pay_coupon": 1, "is_deduction": 1 }, { "value": 2, "sort_order": 2, "is_show": 1, "name": "无限赏", "pay_wechat": 1, "pay_balance": 1, "pay_currency": 1, "pay_currency2": 1, "pay_coupon": 1, "is_deduction": 1 }, { "value": 3, "sort_order": 3, "is_show": 0, "name": "擂台赏", "pay_wechat": 1, "pay_balance": 1, "pay_currency": 1, "pay_currency2": 1, "pay_coupon": 1, "is_deduction": 1 }, { "value": 5, "sort_order": 4, "is_show": 0, "name": "积分赏", "pay_wechat": 0, "pay_balance": 0, "pay_currency": 0, "pay_currency2": 1, "pay_coupon": 1, "is_deduction": 0 }, { "value": 6, "sort_order": 5, "is_show": 1, "name": "限时活动", "pay_wechat": 1, "pay_balance": 1, "pay_currency": 1, "pay_currency2": 1, "pay_coupon": 1, "is_deduction": 1 }, { "value": 8, "sort_order": 6, "is_show": 1, "name": "领主赏", "pay_wechat": 1, "pay_balance": 1, "pay_currency": 1, "pay_currency2": 1, "pay_coupon": 1, "is_deduction": 1 }, { "value": 9, "sort_order": 7, "is_show": 0, "name": "连击赏", "pay_wechat": 1, "pay_balance": 1, "pay_currency": 1, "pay_currency2": 1, "pay_coupon": 1, "is_deduction": 1 }, { "value": 10, "sort_order": 8, "is_show": 0, "name": "商城赏", "pay_wechat": 1, "pay_balance": 0, "pay_currency": 0, "pay_currency2": 1, "pay_coupon": 0, "is_deduction": 0 }, { "value": 11, "sort_order": 9, "is_show": 0, "name": "自制赏", "pay_wechat": 1, "pay_balance": 1, "pay_currency": 1, "pay_currency2": 1, "pay_coupon": 1, "is_deduction": 1 }, { "value": 15, "sort_order": 15, "is_show": 0, "name": "福利屋", "pay_wechat": 1, "pay_balance": 1, "pay_currency": 0, "pay_currency2": 0, "pay_coupon": 0, "is_deduction": 0 }, { "value": 16, "sort_order": 16, "is_show": 1, "name": "翻倍赏", "pay_wechat": 1, "pay_balance": 1, "pay_currency": 1, "pay_currency2": 1, "pay_coupon": 1, "is_deduction": 1 }, { "value": 17, "sort_order": 17, "is_show": 0, "name": "外卖盒子", "pay_wechat": 1, "pay_balance": 1, "pay_currency": 0, "pay_currency2": 0, "pay_coupon": 0, "is_deduction": 0 }],
|
||||
"app_setting": {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
// import config from '../config.js'
|
||||
// 导入路由模块
|
||||
import { navigateTo as routerNavigateTo } from '@/common/router.js';
|
||||
|
||||
/*导航菜单白名单*/
|
||||
const tabBarLinks = [
|
||||
'/pages/index/index',
|
||||
|
|
@ -28,27 +31,33 @@ export const gotopage = (url, type) => {
|
|||
return false;
|
||||
}
|
||||
|
||||
// 从URL中提取路径和参数
|
||||
let path = url;
|
||||
let params = {};
|
||||
|
||||
// tabBar页面
|
||||
if (type == 'switch') {
|
||||
uni.reLaunch({
|
||||
url: url
|
||||
});
|
||||
} else {
|
||||
if (url.includes('?')) {
|
||||
const [basePath, queryString] = url.split('?');
|
||||
path = basePath;
|
||||
|
||||
if(type == 'redirect'){
|
||||
uni.redirectTo({
|
||||
url: url
|
||||
});
|
||||
}
|
||||
if(type == 'reLaunch'){
|
||||
uni.reLaunch({
|
||||
url: url
|
||||
});
|
||||
}
|
||||
// 普通页面
|
||||
uni.navigateTo({
|
||||
url: url
|
||||
// 解析参数
|
||||
queryString.split('&').forEach(param => {
|
||||
const [key, value] = param.split('=');
|
||||
if (key && value) {
|
||||
params[key] = decodeURIComponent(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 使用新的路由方法进行导航
|
||||
let navigationType = 'navigateTo';
|
||||
if (type === 'switch') {
|
||||
navigationType = 'reLaunch';
|
||||
} else if (type === 'redirect') {
|
||||
navigationType = 'redirectTo';
|
||||
} else if (type === 'reLaunch') {
|
||||
navigationType = 'reLaunch';
|
||||
}
|
||||
|
||||
// 使用导入的路由方法
|
||||
return routerNavigateTo(path, params, navigationType);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@
|
|||
import EnvConfig from '@/common/env.js'
|
||||
import md5 from 'js-md5'
|
||||
import ConfigManager from '@/common/config.js'
|
||||
|
||||
import { apiWhiteList } from '@/common/config.js'
|
||||
import RouterManager from '@/common/router.js'
|
||||
class RequestManager {
|
||||
/**
|
||||
* 判断URL是否在白名单中
|
||||
|
|
@ -14,26 +15,16 @@ class RequestManager {
|
|||
* @returns {Boolean} 是否在白名单中
|
||||
*/
|
||||
static isUrlInWhitelist(url) {
|
||||
// 白名单URL列表
|
||||
const whitelistUrls = [
|
||||
'login_record',
|
||||
'api/warehouse_index',
|
||||
'api/user',
|
||||
'api/warehouse_send_record'
|
||||
]
|
||||
|
||||
|
||||
// 白名单URL列表
|
||||
const whitelistUrls2 = [
|
||||
'login_record',
|
||||
]
|
||||
let iswx = ConfigManager.GetVersion();
|
||||
// let iswx = ConfigManager.GetVersion();
|
||||
|
||||
// // 根据版本使用不同的白名单
|
||||
// if (!iswx) {
|
||||
// // 非微信版本只允许 login_record
|
||||
// return apiWhiteList.includes('login_record') && url.indexOf('login_record') > -1;
|
||||
// }
|
||||
|
||||
if (!iswx) {
|
||||
return whitelistUrls2.some(whiteItem => url.indexOf(whiteItem) > -1)
|
||||
}
|
||||
// 检查URL是否包含白名单中的任一项
|
||||
return whitelistUrls.some(whiteItem => url.indexOf(whiteItem) > -1)
|
||||
return apiWhiteList.some(whiteItem => url.indexOf(whiteItem) > -1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -208,6 +199,7 @@ class RequestManager {
|
|||
data: data,
|
||||
success: res => {
|
||||
console.log("res.data.status", res.data.status)
|
||||
var pages = getCurrentPages()
|
||||
if (res.data.status == 1) {
|
||||
// 请求成功
|
||||
resolve(res.data)
|
||||
|
|
@ -245,19 +237,37 @@ class RequestManager {
|
|||
icon: 'none'
|
||||
})
|
||||
}, 100)
|
||||
|
||||
reject(res.data)
|
||||
} else if (res.data.status < 0) {
|
||||
var pages = getCurrentPages()
|
||||
for (var a = 0; a < pages.length; a++) {
|
||||
console.log(pages[a].route)
|
||||
if (pages[a].route == 'pages/user/index') {
|
||||
uni.setStorageSync('lgurl', pages[a].route)
|
||||
uni.setStorageSync('lgurldata', JSON.stringify(pages[a].options))
|
||||
// 获取当前页面路径和参数
|
||||
var currentPage = pages[pages.length - 1];
|
||||
if (currentPage) {
|
||||
var currentRoute = currentPage.route;
|
||||
var currentParams = currentPage.options || {};
|
||||
|
||||
// 只有非登录页面才保存重定向信息
|
||||
if (currentRoute && currentRoute !== 'pages/user/login') {
|
||||
// 构建完整的重定向URL
|
||||
var redirectPath = '/' + currentRoute;
|
||||
|
||||
// 如果有参数,拼接参数
|
||||
if (Object.keys(currentParams).length > 0) {
|
||||
var paramString = Object.keys(currentParams)
|
||||
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(currentParams[key])}`)
|
||||
.join('&');
|
||||
redirectPath += '?' + paramString;
|
||||
}
|
||||
|
||||
// 保存重定向URL到缓存
|
||||
console.log('保存重定向URL:', redirectPath);
|
||||
uni.setStorageSync('redirect', redirectPath);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(requestUrl);
|
||||
if (RequestManager.isUrlInWhitelist(requestUrl)) {
|
||||
|
||||
reject(res.data)
|
||||
return;
|
||||
}
|
||||
|
|
@ -267,11 +277,13 @@ class RequestManager {
|
|||
icon: 'none'
|
||||
})
|
||||
}, 100)
|
||||
uni.redirectTo({
|
||||
url: '/pages/user/login',
|
||||
// animationType: 'pop-in',
|
||||
// animationDuration: 500
|
||||
})
|
||||
|
||||
// 使用新的路由守卫方法进行跳转
|
||||
RouterManager.navigateTo('/pages/user/login', {}, 'navigateTo')
|
||||
.catch(err => {
|
||||
console.error('登录页面跳转失败:', err);
|
||||
});
|
||||
|
||||
reject(res.data)
|
||||
} else {
|
||||
reject(res.data)
|
||||
|
|
|
|||
253
common/router.js
Normal file
253
common/router.js
Normal file
|
|
@ -0,0 +1,253 @@
|
|||
/**
|
||||
* 通用路由守卫
|
||||
*/
|
||||
|
||||
import { whiteList } from '@/common/config.js'
|
||||
|
||||
/**
|
||||
* 判断用户是否已登录
|
||||
* @returns {Boolean} true表示已登录,false表示未登录
|
||||
*/
|
||||
function isLogin() {
|
||||
// 从本地存储获取用户token或其他登录凭证
|
||||
const token = uni.getStorageSync('token');
|
||||
return !!token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断URL是否在白名单中
|
||||
* @param {String} url 需要检查的URL
|
||||
* @returns {Boolean} 是否在白名单中
|
||||
*/
|
||||
function isInWhiteList(url) {
|
||||
if (!url) return false;
|
||||
|
||||
// 去除URL开头的斜杠,以便与白名单匹配
|
||||
const cleanUrl = url.startsWith('/') ? url.substring(1) : url;
|
||||
|
||||
// 提取路径部分(不含参数)
|
||||
const pathPart = cleanUrl.split('?')[0];
|
||||
|
||||
// 检查是否在白名单中
|
||||
return whiteList.some(item => {
|
||||
// 确保白名单项目不带/开头,以实现一致的比较
|
||||
const cleanItem = item.startsWith('/') ? item.substring(1) : item;
|
||||
return pathPart === cleanItem || pathPart.startsWith(cleanItem + '/') || pathPart.startsWith(cleanItem + '?');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回上一页,如果上一页是登录页则跳过它
|
||||
* @returns {Promise} 返回操作结果的Promise
|
||||
*/
|
||||
export function navigateBack(delta = 1) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const pages = getCurrentPages();
|
||||
|
||||
// 如果页面栈不足,直接返回首页
|
||||
if (pages.length <= 1) {
|
||||
return navigateTo('/pages/shouye/index', {}, 'reLaunch')
|
||||
.then(resolve)
|
||||
.catch(reject);
|
||||
}
|
||||
|
||||
// 查看前一个页面是否是登录页
|
||||
if (pages.length > 1 && pages[pages.length - 2].route === 'pages/user/login') {
|
||||
// 如果前一个页面是登录页,则返回两步
|
||||
uni.navigateBack({
|
||||
delta: 2,
|
||||
success: resolve,
|
||||
fail: reject
|
||||
});
|
||||
} else {
|
||||
// 正常返回
|
||||
uni.navigateBack({
|
||||
delta,
|
||||
success: resolve,
|
||||
fail: reject
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用路由跳转方法
|
||||
* @param {Object} options 跳转配置
|
||||
* @param {String} options.url 跳转地址
|
||||
* @param {Object} options.params 请求参数,可选
|
||||
* @param {String} options.type 跳转方式,可选:navigateTo(默认)、switchTab、redirectTo、reLaunch
|
||||
* @returns {Promise} 返回一个Promise对象
|
||||
*/
|
||||
export function routerTo(options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 处理参数
|
||||
let { url, params, type } = options;
|
||||
|
||||
// 判断url是否存在
|
||||
if (!url || url.length === 0) {
|
||||
reject('跳转地址不能为空');
|
||||
return;
|
||||
}
|
||||
|
||||
// 拼接参数
|
||||
if (params && Object.keys(params).length > 0) {
|
||||
const queryString = Object.keys(params)
|
||||
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
|
||||
.join('&');
|
||||
|
||||
url += (url.indexOf('?') === -1 ? '?' : '&') + queryString;
|
||||
}
|
||||
|
||||
// 检查是否需要登录
|
||||
const needLogin = !isInWhiteList(url);
|
||||
|
||||
if (needLogin && !isLogin()) {
|
||||
// 需要登录但未登录,跳转到登录页面
|
||||
// 先保存当前URL用于登录后重定向
|
||||
uni.setStorageSync('redirect', url);
|
||||
|
||||
// 使用navigateTo而非redirectTo,保留页面栈
|
||||
uni.navigateTo({
|
||||
url: '/pages/user/login',
|
||||
success: () => {
|
||||
console.log('跳转到登录页面成功,保存的重定向地址:', url);
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('跳转到登录页面失败:', err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
|
||||
// 拒绝当前的导航请求
|
||||
return reject(new Error('需要登录'));
|
||||
}
|
||||
|
||||
// 根据type选择跳转方式
|
||||
if (type) {
|
||||
// 指定了跳转方式,直接使用
|
||||
switch (type) {
|
||||
case 'switchTab':
|
||||
uni.switchTab({
|
||||
url,
|
||||
success: resolve,
|
||||
fail: reject
|
||||
});
|
||||
break;
|
||||
case 'redirectTo':
|
||||
uni.redirectTo({
|
||||
url,
|
||||
success: resolve,
|
||||
fail: reject
|
||||
});
|
||||
break;
|
||||
case 'reLaunch':
|
||||
uni.reLaunch({
|
||||
url,
|
||||
success: resolve,
|
||||
fail: reject
|
||||
});
|
||||
break;
|
||||
case 'navigateTo':
|
||||
default:
|
||||
uni.navigateTo({
|
||||
url,
|
||||
success: resolve,
|
||||
fail: reject
|
||||
});
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// 未指定跳转方式,先尝试navigateTo,失败后尝试switchTab
|
||||
uni.navigateTo({
|
||||
url,
|
||||
success: resolve,
|
||||
fail: (err) => {
|
||||
// navigateTo失败,尝试switchTab
|
||||
uni.switchTab({
|
||||
url,
|
||||
success: resolve,
|
||||
fail: (switchErr) => {
|
||||
// 两种方式都失败,返回错误
|
||||
reject(switchErr);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 简化版路由跳转方法
|
||||
* @param {String} url 跳转地址
|
||||
* @param {Object} params 请求参数,可选
|
||||
* @param {String} type 跳转方式,可选
|
||||
* @returns {Promise} 返回Promise对象
|
||||
*/
|
||||
export function navigateTo(url, params = {}, type = '') {
|
||||
return routerTo({
|
||||
url,
|
||||
params,
|
||||
type
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集白名单路径
|
||||
* @param {String} path 需要添加到白名单的路径
|
||||
* @returns {Array} 返回更新后的白名单数组
|
||||
*/
|
||||
export function collectWhitePath(path) {
|
||||
// 缓存的键名
|
||||
const WHITELIST_CACHE_KEY = 'APP_WHITELIST_PATHS';
|
||||
|
||||
// 从缓存中获取现有白名单
|
||||
let cachedWhitelist = uni.getStorageSync(WHITELIST_CACHE_KEY) || [];
|
||||
|
||||
// 如果不是数组,则初始化为空数组
|
||||
if (!Array.isArray(cachedWhitelist)) {
|
||||
cachedWhitelist = [];
|
||||
}
|
||||
|
||||
// 检查路径是否已存在于白名单中
|
||||
if (path && path.trim() && !cachedWhitelist.includes(path)) {
|
||||
// 添加新路径到白名单
|
||||
cachedWhitelist.push(path);
|
||||
|
||||
// 保存更新后的白名单到缓存
|
||||
uni.setStorageSync(WHITELIST_CACHE_KEY, cachedWhitelist);
|
||||
|
||||
console.log('添加白名单路径成功:', path);
|
||||
}
|
||||
|
||||
return cachedWhitelist;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已收集的白名单路径
|
||||
* @returns {Array} 返回缓存中的白名单数组
|
||||
*/
|
||||
export function getCollectedWhitePaths() {
|
||||
const WHITELIST_CACHE_KEY = 'APP_WHITELIST_PATHS';
|
||||
return uni.getStorageSync(WHITELIST_CACHE_KEY) || [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空已收集的白名单路径
|
||||
* @returns {Boolean} 返回操作结果
|
||||
*/
|
||||
export function clearCollectedWhitePaths() {
|
||||
const WHITELIST_CACHE_KEY = 'APP_WHITELIST_PATHS';
|
||||
uni.setStorageSync(WHITELIST_CACHE_KEY, []);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 更新默认导出
|
||||
export default {
|
||||
routerTo,
|
||||
navigateTo,
|
||||
navigateBack,
|
||||
collectWhitePath,
|
||||
getCollectedWhitePaths,
|
||||
clearCollectedWhitePaths
|
||||
};
|
||||
|
|
@ -64,25 +64,14 @@ export default {
|
|||
goBack() {
|
||||
if (this.backUrl) {
|
||||
// 如果指定了返回页面路径,则跳转到指定页面
|
||||
uni.redirectTo({
|
||||
url: this.backUrl,
|
||||
success: () => {
|
||||
|
||||
},
|
||||
fail: (err) => {
|
||||
this.$router.navigateTo(this.backUrl, {}, 'redirectTo')
|
||||
.catch(err => {
|
||||
console.log('返回页面失败', err);
|
||||
uni.switchTab({
|
||||
url: this.backUrl,
|
||||
success: () => {
|
||||
|
||||
},
|
||||
fail: (err) => {
|
||||
this.$router.navigateTo(this.backUrl, {}, 'switchTab')
|
||||
.catch(err => {
|
||||
console.log('返回页面失败1', err);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
} else {
|
||||
var pages = getCurrentPages();
|
||||
if (pages.length > 1) {
|
||||
|
|
@ -93,9 +82,7 @@ export default {
|
|||
}
|
||||
});
|
||||
} else {
|
||||
uni.switchTab({
|
||||
url: '/pages/shouye/index',
|
||||
});
|
||||
this.$router.navigateTo('/pages/shouye/index', {}, 'switchTab');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
3
main.js
3
main.js
|
|
@ -3,6 +3,7 @@ import App from './App'
|
|||
import Mixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js'
|
||||
import common from '@/common/common.js'
|
||||
import { gotopage } from '@/common/gotopage.js'
|
||||
import router from '@/common/router.js'
|
||||
import ConfigManager from '@/common/config.js'
|
||||
import RequestManager from '@/common/request.js'
|
||||
import EnvConfig from '@/common/env.js'
|
||||
|
|
@ -24,6 +25,8 @@ Vue.prototype.$wxloginPage = EnvConfig.wxLoginUrl
|
|||
|
||||
// 公共方法
|
||||
Vue.prototype.gotoPage = gotopage
|
||||
Vue.prototype.$router = router
|
||||
Vue.prototype.$navigateTo = router.navigateTo
|
||||
Vue.prototype.$noMultipleClicks = common.noMultipleClicks
|
||||
Vue.prototype.$c = common
|
||||
// 全局配置管理器
|
||||
|
|
|
|||
|
|
@ -181,9 +181,7 @@
|
|||
})
|
||||
},
|
||||
todetails(e) {
|
||||
uni.navigateTo({
|
||||
url: 'cardDetail?goods_id=' + e.id
|
||||
})
|
||||
this.$router.navigateTo('cardDetail', { goods_id: e.id });
|
||||
},
|
||||
getlist(v) {
|
||||
this.show = v;
|
||||
|
|
|
|||
|
|
@ -60,9 +60,7 @@ export default {
|
|||
getlist(index) {
|
||||
this.current = index
|
||||
if (index == 1) {
|
||||
uni.navigateTo({
|
||||
url: 'UnlimitedOrder'
|
||||
})
|
||||
this.$router.navigateTo('UnlimitedOrder');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -691,9 +691,7 @@ export default {
|
|||
},
|
||||
|
||||
toHome() {
|
||||
uni.reLaunch({
|
||||
url: '/pages/shouye/index'
|
||||
});
|
||||
this.$router.navigateTo('/pages/shouye/index', {}, 'reLaunch');
|
||||
},
|
||||
|
||||
applyPageTransitions() {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<page-container title="福利">
|
||||
<banner :type-id="6" :height="326"></banner>
|
||||
<view class="grid-container" style="width: 100%; padding: 0 32rpx; margin-top: 40rpx;">
|
||||
<view class="grid-item" v-for="(item, index) in list" :key="item.id" @click="toPage(item)" style="height: 184rpx;">
|
||||
<view class="grid-item" v-for="(item, index) in list" :key="item.id" @click="toPage(item)"
|
||||
style="height: 184rpx;">
|
||||
<image v-if="item.image" :src="item.image" mode="aspectFill" class="grid-item-bg"></image>
|
||||
<text v-if="!item.image">{{ item.name }}</text>
|
||||
</view>
|
||||
|
|
@ -13,161 +14,166 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import RequestManager from '@/common/request.js'
|
||||
import PageContainer from '@/components/page-container/page-container.vue'
|
||||
import RequestManager from '@/common/request.js'
|
||||
import PageContainer from '@/components/page-container/page-container.vue'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
PageContainer
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
list: []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 获取福利屋菜单列表
|
||||
getWelfareList() {
|
||||
RequestManager.post('/welfare_house_list')
|
||||
.then(res => {
|
||||
if (res.status === 1 && res.data) {
|
||||
this.list = res.data;
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.msg || '获取福利列表失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('获取福利列表失败:', err);
|
||||
export default {
|
||||
components: {
|
||||
PageContainer
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
list: []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 获取福利屋菜单列表
|
||||
getWelfareList() {
|
||||
RequestManager.post('/welfare_house_list')
|
||||
.then(res => {
|
||||
if (res.status === 1 && res.data) {
|
||||
this.list = res.data;
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '获取福利列表失败',
|
||||
title: res.msg || '获取福利列表失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('获取福利列表失败:', err);
|
||||
uni.showToast({
|
||||
title: '获取福利列表失败',
|
||||
icon: 'none'
|
||||
});
|
||||
},
|
||||
|
||||
//跳转页面
|
||||
toPage(item) {
|
||||
if (item.url) {
|
||||
console.log(item);
|
||||
uni.setStorageSync('fuliwu_title', item.name)
|
||||
this.$c.to({
|
||||
url: item.url
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
this.current = 0
|
||||
const curPages = getCurrentPages()[0]; // 获取当前页面实例
|
||||
if (typeof curPages.getTabBar === 'function' && curPages.getTabBar()) {
|
||||
this.$mp.page.getTabBar().setData({
|
||||
selected: 1
|
||||
});
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.getWelfareList();
|
||||
|
||||
//跳转页面
|
||||
toPage(item) {
|
||||
if (item.url) {
|
||||
console.log(item);
|
||||
uni.setStorageSync('fuliwu_title', item.name)
|
||||
this.$router.navigateTo(item.url);
|
||||
// this.$c.to({
|
||||
// type:1,
|
||||
// url: item.url,
|
||||
|
||||
// });
|
||||
}
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
this.current = 0
|
||||
const curPages = getCurrentPages()[0]; // 获取当前页面实例
|
||||
if (typeof curPages.getTabBar === 'function' && curPages.getTabBar()) {
|
||||
this.$mp.page.getTabBar().setData({
|
||||
selected: 1
|
||||
});
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.getWelfareList();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.grid-container {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 324rpx);
|
||||
/* 三列,每列宽度相等 */
|
||||
gap: 40rpx 42rpx;
|
||||
/* 网格之间的间隔 */
|
||||
animation: fadeIn 0.5s ease-out;
|
||||
.grid-container {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 324rpx);
|
||||
/* 三列,每列宽度相等 */
|
||||
gap: 40rpx 42rpx;
|
||||
/* 网格之间的间隔 */
|
||||
animation: fadeIn 0.5s ease-out;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(20rpx);
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(20rpx);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.grid-item {
|
||||
position: relative;
|
||||
|
||||
text-align: center;
|
||||
border-radius: 16rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
animation: scaleIn 0.5s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
animation-fill-mode: both;
|
||||
transition: all 0.3s ease;
|
||||
|
||||
&:active {
|
||||
transform: scale(0.95);
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.grid-item {
|
||||
position: relative;
|
||||
|
||||
text-align: center;
|
||||
border-radius: 16rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
animation: scaleIn 0.5s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
animation-fill-mode: both;
|
||||
transition: all 0.3s ease;
|
||||
|
||||
&:active {
|
||||
transform: scale(0.95);
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-radius: 50%;
|
||||
transform: translate(-50%, -50%) scale(0);
|
||||
opacity: 0;
|
||||
transition: transform 0.6s ease-out, opacity 0.6s ease-out;
|
||||
}
|
||||
|
||||
&:active::after {
|
||||
transform: translate(-50%, -50%) scale(2);
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes scaleIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: scale(0.8);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
.grid-item-bg {
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 1;
|
||||
transition: transform 0.3s ease;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-radius: 50%;
|
||||
transform: translate(-50%, -50%) scale(0);
|
||||
opacity: 0;
|
||||
transition: transform 0.6s ease-out, opacity 0.6s ease-out;
|
||||
}
|
||||
|
||||
.grid-item text {
|
||||
z-index: 2;
|
||||
color: #333;
|
||||
font-size: 28rpx;
|
||||
transition: all 0.3s ease;
|
||||
text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.1);
|
||||
&:active::after {
|
||||
transform: translate(-50%, -50%) scale(2);
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes scaleIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: scale(0.8);
|
||||
}
|
||||
|
||||
// 为每个网格项添加延迟动画
|
||||
.grid-item {
|
||||
@for $i from 1 through 10 {
|
||||
&:nth-child(#{$i}) {
|
||||
animation-delay: #{$i * 0.1}s;
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
.grid-item-bg {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 1;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.grid-item text {
|
||||
z-index: 2;
|
||||
color: #333;
|
||||
font-size: 28rpx;
|
||||
transition: all 0.3s ease;
|
||||
text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
// 为每个网格项添加延迟动画
|
||||
.grid-item {
|
||||
@for $i from 1 through 10 {
|
||||
&:nth-child(#{$i}) {
|
||||
animation-delay: #{$i * 0.1}s;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
@ -89,9 +89,7 @@ export default {
|
|||
},
|
||||
|
||||
goOrderDetail(item) {
|
||||
uni.navigateTo({
|
||||
url: `/pages/other/order_info?order_num=${item.order_num}`
|
||||
});
|
||||
this.$router.navigateTo('/pages/other/order_info', { order_num: item.order_num });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,9 +229,7 @@
|
|||
setTimeout(() => {
|
||||
that.$refs.order_show.close()
|
||||
//去订单
|
||||
uni.redirectTo({
|
||||
url: '/pages/miaosha/shop_order'
|
||||
})
|
||||
that.$router.navigateTo('/pages/miaosha/shop_order', {}, 'redirectTo');
|
||||
}, 1500)
|
||||
}
|
||||
}
|
||||
|
|
@ -245,9 +243,7 @@
|
|||
setTimeout(() => {
|
||||
that.$refs.order_show.close()
|
||||
//去订单
|
||||
uni.redirectTo({
|
||||
url: '/pages/miaosha/shop_order'
|
||||
})
|
||||
that.$router.navigateTo('/pages/miaosha/shop_order', {}, 'redirectTo');
|
||||
}, 1500)
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -100,21 +100,14 @@
|
|||
},
|
||||
openUrl(e) {
|
||||
if (e.target == 1) {
|
||||
uni.navigateTo({
|
||||
url: '../shouye/detail?id=' + e.goods_id
|
||||
})
|
||||
this.$router.navigateTo('../shouye/detail', { id: e.goods_id });
|
||||
}
|
||||
if (e.target == 2) {
|
||||
uni.navigateTo({
|
||||
url: 'detail?goods_id=' + e.product_id
|
||||
})
|
||||
this.$router.navigateTo('detail', { goods_id: e.product_id });
|
||||
}
|
||||
if (e.target == 3) {
|
||||
uni.navigateTo({
|
||||
url: '../web-view?url=' + e.url
|
||||
})
|
||||
this.$router.navigateTo('../web-view', { url: e.url });
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -107,25 +107,18 @@
|
|||
|
||||
todetail(e) {
|
||||
if (this.type == '3') {
|
||||
uni.redirectTo({
|
||||
url: '/package/index/leitai?goods_id=' +
|
||||
this.id +
|
||||
'&goods_num=' +
|
||||
e +
|
||||
'&type_text=' +
|
||||
this.type_text
|
||||
})
|
||||
this.$router.navigateTo('/package/index/leitai', {
|
||||
goods_id: this.id,
|
||||
goods_num: e,
|
||||
type_text: this.type_text
|
||||
}, 'redirectTo');
|
||||
} else {
|
||||
uni.redirectTo({
|
||||
url: 'detail?goods_id=' +
|
||||
this.id +
|
||||
'&goods_num=' +
|
||||
e +
|
||||
'&type_text=' +
|
||||
this.type_text
|
||||
})
|
||||
this.$router.navigateTo('detail', {
|
||||
goods_id: this.id,
|
||||
goods_num: e,
|
||||
type_text: this.type_text
|
||||
}, 'redirectTo');
|
||||
}
|
||||
|
||||
},
|
||||
change_saixuan(a, b) {
|
||||
this.saixuan_index = a
|
||||
|
|
|
|||
|
|
@ -396,6 +396,10 @@ export default {
|
|||
todetails(e) {
|
||||
// 无限赏
|
||||
let url = "/pages/shouye/detail";
|
||||
let params = {
|
||||
goods_id: e.id,
|
||||
type_text: e.type_text
|
||||
};
|
||||
|
||||
if (e.type == 2 || e.type == 8 || e.type == 16) {
|
||||
url = "/pages/shouye/detail_wuxian";
|
||||
|
|
@ -408,13 +412,7 @@ export default {
|
|||
url = "/package/index/leitai";
|
||||
}
|
||||
|
||||
this.$c.to({
|
||||
url,
|
||||
query: {
|
||||
goods_id: e.id,
|
||||
type_text: e.type_text,
|
||||
},
|
||||
});
|
||||
this.$router.navigateTo(url, params);
|
||||
},
|
||||
getlist(v) {
|
||||
this.tabCur = v;
|
||||
|
|
@ -426,14 +424,10 @@ export default {
|
|||
},
|
||||
|
||||
toRanking() {
|
||||
uni.navigateTo({
|
||||
url: "/pages/shouye/ranking",
|
||||
});
|
||||
this.$router.navigateTo("/pages/shouye/ranking");
|
||||
},
|
||||
toyaqingRanking() {
|
||||
uni.navigateTo({
|
||||
url: "/pages/shouye/yaoqing_ranking",
|
||||
});
|
||||
this.$router.navigateTo("/pages/shouye/yaoqing_ranking");
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -40,9 +40,7 @@
|
|||
// })
|
||||
// } else {
|
||||
if (e.goods_id !== 0) {
|
||||
uni.navigateTo({
|
||||
url: 'detail?goods_id=' + e.goods_id
|
||||
})
|
||||
this.$router.navigateTo('detail', { goods_id: e.goods_id });
|
||||
}
|
||||
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -39,10 +39,14 @@ export default {
|
|||
},
|
||||
methods: {
|
||||
back() {
|
||||
// uni.navigateBack()
|
||||
uni.reLaunch({
|
||||
url: 'index'
|
||||
})
|
||||
// 尝试返回上一页
|
||||
let that = this;
|
||||
uni.navigateBack({
|
||||
fail: function() {
|
||||
// 如果返回失败,表示没有上一页,则跳转到首页
|
||||
that.$router.navigateTo('/pages/user/index', {}, 'reLaunch');
|
||||
}
|
||||
});
|
||||
},
|
||||
getPhoneNumber(e) {
|
||||
// console.log(e)
|
||||
|
|
@ -69,20 +73,13 @@ export default {
|
|||
// var pageurl = uni.getStorageSync(
|
||||
// 'page');
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: 'index'
|
||||
})
|
||||
// console.log(pageurl);
|
||||
// if (pageurl != null &&
|
||||
// pageurl != '') {
|
||||
// console.log(pageurl +
|
||||
// "12321312");
|
||||
// // uni.reLaunch({
|
||||
// // url: pageurl
|
||||
// // })
|
||||
// } else {
|
||||
// uni.navigateBack()
|
||||
// }
|
||||
// 返回上一页而不是跳转到首页
|
||||
uni.navigateBack({
|
||||
fail: function() {
|
||||
// 如果返回失败,表示没有上一页,则跳转到首页
|
||||
that.$router.navigateTo('/pages/user/index', {}, 'reLaunch');
|
||||
}
|
||||
});
|
||||
}, 1000)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -144,9 +144,7 @@
|
|||
|
||||
// 延迟返回
|
||||
setTimeout(() => {
|
||||
uni.redirectTo({
|
||||
url: "./index",
|
||||
});
|
||||
this.$router.navigateTo("./index", {}, 'redirectTo');
|
||||
}, 1000);
|
||||
} else {
|
||||
uni.showToast({
|
||||
|
|
|
|||
|
|
@ -106,9 +106,7 @@
|
|||
methods: {
|
||||
toUse(item) {
|
||||
if (this.pageType == 1) {
|
||||
uni.switchTab({
|
||||
url: '/pages/shouye/index'
|
||||
})
|
||||
this.$router.navigateTo('/pages/shouye/index', {}, 'switchTab');
|
||||
}
|
||||
|
||||
if (this.pageType == 2) {
|
||||
|
|
|
|||
|
|
@ -219,14 +219,13 @@ export default {
|
|||
})
|
||||
},
|
||||
toorder(e) {
|
||||
uni.navigateTo({
|
||||
url: 'order?id=' + e
|
||||
this.$router.navigateTo('/pages/shouye/detail', {
|
||||
goods_id: e,
|
||||
goods_num: 1
|
||||
})
|
||||
},
|
||||
towuliu(e) {
|
||||
uni.navigateTo({
|
||||
url: 'wuliu_detail?id=' + e
|
||||
})
|
||||
this.$router.navigateTo('/pages/shouye/wuliu_detail', { id: e })
|
||||
},
|
||||
getlist(v) {
|
||||
this.show = v
|
||||
|
|
|
|||
|
|
@ -560,16 +560,12 @@ export default {
|
|||
},
|
||||
todetail(a) {
|
||||
if (a.type == 2) {
|
||||
uni.navigateTo({
|
||||
url: '/pages/shouye/detail_wuxian?goods_id=' + a.goods_id
|
||||
})
|
||||
this.$router.navigateTo('/pages/shouye/detail_wuxian', { goods_id: a.goods_id });
|
||||
} else {
|
||||
uni.navigateTo({
|
||||
url: '/pages/shouye/detail?goods_id=' +
|
||||
a.goods_id +
|
||||
'&goods_num=' +
|
||||
a.num
|
||||
})
|
||||
this.$router.navigateTo('/pages/shouye/detail', {
|
||||
goods_id: a.goods_id,
|
||||
goods_num: a.num
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -19,18 +19,18 @@
|
|||
|
||||
<view class="agree-r">
|
||||
我已阅读并同意
|
||||
<text @click.stop="$c.to({ url: '/pages/guize/guize?type=4' })">
|
||||
<text @click.stop="$router.navigateTo('/pages/guize/guize', {type: 4})">
|
||||
《用户协议》
|
||||
</text>
|
||||
和
|
||||
<text @click.stop="$c.to({ url: '/pages/guize/guize?type=5' })">
|
||||
<text @click.stop="$router.navigateTo('/pages/guize/guize', {type: 5})">
|
||||
《隐私政策》
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="btn-list">
|
||||
<view @click="$c.to({ type: 3, url: '/pages/shouye/index' })" class="cancel">
|
||||
<view @click="$router.navigateTo('/pages/shouye/index', {}, 'switchTab')" class="cancel">
|
||||
拒绝
|
||||
</view>
|
||||
|
||||
|
|
@ -80,9 +80,10 @@ export default {
|
|||
//第一授权获取用户信息===》按钮触发
|
||||
getUserProfile(e) {
|
||||
if (!this.isAgree) {
|
||||
return this.$c.toast({
|
||||
title: '请阅读并同意《用户协议》和《隐私政策》'
|
||||
})
|
||||
return uni.showToast({
|
||||
title: '请阅读并同意《用户协议》和《隐私政策》',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
|
|
@ -90,6 +91,56 @@ export default {
|
|||
// #endif
|
||||
|
||||
|
||||
},
|
||||
/**
|
||||
* 处理登录成功后的重定向逻辑
|
||||
* @param {String} redirectUrl 重定向URL
|
||||
*/
|
||||
handleRedirect(redirectUrl) {
|
||||
let that = this;
|
||||
|
||||
// 获取当前页面栈
|
||||
const pages = getCurrentPages();
|
||||
|
||||
// 检查是否有上一页,以及redirect URL是否与上一页相同
|
||||
if (pages.length > 1) {
|
||||
const prevPage = pages[pages.length - 2];
|
||||
// 构建完整的上一页路径(带参数)
|
||||
let prevPageUrl = '/' + prevPage.route;
|
||||
if (prevPage.options && Object.keys(prevPage.options).length > 0) {
|
||||
const paramStr = Object.keys(prevPage.options)
|
||||
.map(key => `${key}=${prevPage.options[key]}`)
|
||||
.join('&');
|
||||
prevPageUrl += '?' + paramStr;
|
||||
}
|
||||
|
||||
// 比较redirect URL和上一页URL
|
||||
const redirectUrlPath = redirectUrl.split('?')[0];
|
||||
const prevPageUrlPath = prevPageUrl.split('?')[0];
|
||||
|
||||
if (redirectUrlPath === prevPageUrlPath) {
|
||||
// 如果路径相同,直接返回上一页
|
||||
console.log('重定向URL与上一页相同,直接返回');
|
||||
setTimeout(() => {
|
||||
uni.navigateBack();
|
||||
}, 1000);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// 重定向到指定URL
|
||||
setTimeout(() => {
|
||||
that.$router.routerTo({
|
||||
url: redirectUrl,
|
||||
type: 'navigateTo'
|
||||
}).catch(err => {
|
||||
console.error('重定向跳转失败:', err)
|
||||
// 失败时跳转到首页
|
||||
that.$router.navigateTo('/pages/user/index', {}, 'navigateTo')
|
||||
})
|
||||
}, 1000);
|
||||
|
||||
return true;
|
||||
},
|
||||
wxUserProfile() {
|
||||
var that = this
|
||||
|
|
@ -112,35 +163,21 @@ export default {
|
|||
if (res.status == 1) {
|
||||
uni.setStorageSync('token', res.data)
|
||||
that.$c.msg("登录成功")
|
||||
var lgurl = uni.getStorageSync('lgurl') //获取页面路径
|
||||
var lgdata = uni.getStorageSync('lgurldata') //获取页面参数
|
||||
if (lgurl) {
|
||||
lgdata = JSON.parse(lgdata)
|
||||
// 拼接参数
|
||||
let param = ''
|
||||
for (let key in lgdata) {
|
||||
param += '&' + key + '=' + lgdata[
|
||||
key]
|
||||
}
|
||||
param = '/' + lgurl + param.replace(
|
||||
'&', '?')
|
||||
uni.setStorageSync('lgurl', '')
|
||||
uni.setStorageSync('lgurldata', '')
|
||||
console.log(param)
|
||||
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: param
|
||||
})
|
||||
}, 1000)
|
||||
|
||||
// 检查重定向URL
|
||||
const redirectUrl = uni.getStorageSync('redirect')
|
||||
|
||||
if (redirectUrl) {
|
||||
// 清除重定向信息
|
||||
uni.removeStorageSync('redirect')
|
||||
|
||||
// 使用公共方法处理重定向
|
||||
that.handleRedirect(redirectUrl);
|
||||
} else {
|
||||
// 无重定向页面,检查是否需要绑定手机号
|
||||
setTimeout(() => {
|
||||
that.getdata();
|
||||
}, 1000)
|
||||
|
||||
// uni.reLaunch({
|
||||
// url: 'index'
|
||||
// })
|
||||
}
|
||||
} else {
|
||||
that.$c.msg("登录失败!" + res.msg)
|
||||
|
|
@ -180,32 +217,21 @@ export default {
|
|||
success: function (res) {
|
||||
if (res.status == 1) {
|
||||
uni.setStorageSync('token', res.data)
|
||||
var lgurl = uni.getStorageSync(
|
||||
'lgurl') //获取页面路径
|
||||
var lgdata = uni.getStorageSync(
|
||||
'lgurldata') //获取页面参数
|
||||
if (lgurl) {
|
||||
lgdata = JSON.parse(lgdata)
|
||||
// 拼接参数
|
||||
let param = ''
|
||||
for (let key in lgdata) {
|
||||
param += '&' + key + '=' + lgdata[
|
||||
key]
|
||||
}
|
||||
param = '/' + lgurl + param.replace(
|
||||
'&', '?')
|
||||
uni.setStorageSync('lgurl', '')
|
||||
uni.setStorageSync('lgurldata', '')
|
||||
console.log(param)
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: param
|
||||
})
|
||||
}, 1000)
|
||||
|
||||
// 检查重定向URL
|
||||
const redirectUrl = uni.getStorageSync('redirect')
|
||||
|
||||
if (redirectUrl) {
|
||||
// 清除重定向信息
|
||||
uni.removeStorageSync('redirect')
|
||||
|
||||
// 使用公共方法处理重定向
|
||||
that.handleRedirect(redirectUrl);
|
||||
} else {
|
||||
uni.reLaunch({
|
||||
url: 'index'
|
||||
})
|
||||
// 无重定向页面,检查是否需要绑定手机号
|
||||
setTimeout(() => {
|
||||
that.getdata();
|
||||
}, 1000)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -224,13 +250,11 @@ export default {
|
|||
success(res) {
|
||||
if (res.status == 1 && res.data.userinfo != null && res.data.userinfo.mobile_is == 0) {
|
||||
console.log("判断用户有没有手机号", res.data.userinfo.mobile_is);
|
||||
uni.reLaunch({
|
||||
url: 'bangding'
|
||||
})
|
||||
// 使用新的路由守卫方法跳转到绑定页面
|
||||
that.$router.navigateTo('/pages/user/bangding', {}, 'navigateTo');
|
||||
} else {
|
||||
uni.reLaunch({
|
||||
url: 'index'
|
||||
})
|
||||
// 使用新的路由守卫方法跳转到用户首页
|
||||
that.$router.navigateTo('/pages/user/index', {}, 'navigateTo');
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user