This commit is contained in:
zpc 2025-06-16 19:37:27 +08:00
parent 985a938757
commit f8ca55c118
6 changed files with 155 additions and 298 deletions

View File

@ -12,7 +12,9 @@ const development = {
// 登录页面URL
loginPage: 'https://testapi.zfunbox.cn/login.html',
// 微信APPID
wxAppId: 'wx0e33d80d35e4a3b1'
wxAppId: 'wx0e33d80d35e4a3b1',
routeMapSecretKey: 'g6R@9!zB2fL#1cVm',
normalizeResponseKeys: 'g6R@9!zB2fL#1cVm'
};
// 生产环境配置
@ -21,21 +23,27 @@ const production = {
baseUrl: 'https://api.zfunbox.cn',
imageUrl: 'https://image.zfunbox.cn',
loginPage: 'https://api.zfunbox.cn/login.html',
wxAppId: 'wx0e33d80d35e4a3b1'
wxAppId: 'wx0e33d80d35e4a3b1',
routeMapSecretKey: 'g6R@9!zB2fL#1cVm',
normalizeResponseKeys: 'g6R@9!zB2fL#1cVm'
};
const production_wz = {
// baseUrl: 'https://youda.zfunbox.cn',
baseUrl: 'https://youda.zfunbox.cn',
imageUrl: 'https://image.zfunbox.cn',
loginPage: 'https://youda.zfunbox.cn/login.html',
wxAppId: 'wx0e33d80d35e4a3b1'
wxAppId: 'wx0e33d80d35e4a3b1',
routeMapSecretKey: 'g6R@9!zB2fL#1cVm',
normalizeResponseKeys: 'g6R@9!zB2fL#1cVm'
};
// 测试环境配置
const testing = {
baseUrl: 'https://testapi.zfunbox.cn',
imageUrl: 'https://image.zfunbox.cn',
loginPage: 'https://testapi.zfunbox.cn/login.html',
wxAppId: 'wx0e33d80d35e4a3b1'
wxAppId: 'wx0e33d80d35e4a3b1',
routeMapSecretKey: 'g6R@9!zB2fL#1cVm',
normalizeResponseKeys: 'g6R@9!zB2fL#1cVm'
};

View File

@ -9,6 +9,8 @@ import CryptoJS from 'crypto-js';
import { apiWhiteList } from '@/common/config.js'
import RouterManager from '@/common/router.js'
import { platform } from '@/common/platform/PlatformFactory'
import { normalizeResponseKeys, getRouteMap } from '@/common/routeMap.js'
// import route_map from '@/common/route_map.js'
class RequestManager {
// 缓存对象
static cache = {
@ -141,8 +143,9 @@ class RequestManager {
} else {
// 否则拼接基础URL和相对路径
// 确保基础URL以/结尾,而请求路径不以/开头
const baseUrlWithSlash = apiBaseUrl.endsWith('/') ? apiBaseUrl : apiBaseUrl + '/'
const path = url.startsWith('/') ? url.substring(1) : url
const baseUrlWithSlash = apiBaseUrl.endsWith('/') ? apiBaseUrl : apiBaseUrl + '/';
let routeMap = getRouteMap(url);
const path = routeMap.startsWith('/') ? routeMap.substring(1) : routeMap;
requestUrl = baseUrlWithSlash + path
}
@ -247,7 +250,7 @@ class RequestManager {
header: header,
data: data,
success: res => {
res = RequestManager.normalizeResponseKeys(res);
res = normalizeResponseKeys(res);
console.log("res.data.status", res.data.status)
var pages = getCurrentPages()
if (res.data.status == 1) {
@ -397,72 +400,7 @@ class RequestManager {
Loading: !showLoading
})
}
/**
* 转换接口返回的字段名为统一结构
* 支持安卓特有字段 => 通用字段
*
* @param {Object} res 接口返回的数据对象
* @returns {Object} 处理后的对象直接修改原对象
*/
static normalizeResponseKeys(res) {
if (!res || typeof res !== 'object') return res;
// 安全处理 res.data
if (!res.data || typeof res.data !== 'object') {
res.data = {};
}
// 将安卓专属字段映射为通用字段
if (res.data.ret != null) {
res.data.status = res.data.ret;
}
if (res.data.note != null) {
res.data.msg = res.data.note;
}
// 解密 payload 字段(如果存在)
if (res.data.payload != null && typeof res.data.payload === 'string') {
try {
const base64EncryptedData = res.data.payload;
// 先 base64 解码CryptoJS 需要的是 WordArray
const encryptedHexStr = CryptoJS.enc.Base64.parse(base64EncryptedData);
// 解密 key 和 iv
const secretKey = 'g6R@9!zB2fL#1cVm';
const key = CryptoJS.enc.Utf8.parse(secretKey);
const iv = CryptoJS.enc.Utf8.parse(CryptoJS.MD5(secretKey).toString().substring(0, 16));
// 进行解密
const decrypted = CryptoJS.AES.decrypt(
{ ciphertext: encryptedHexStr },
key,
{
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
}
);
const decryptedText = decrypted.toString(CryptoJS.enc.Utf8);
try {
res.data.data = JSON.parse(decryptedText);
} catch (e) {
res.data.data = decryptedText;
}
} catch (e) {
console.error('解密 payload 失败:', res.data.payload, e);
res.data.data = null; // 解密失败时给 null 或原值
}
}
if (res.data.ts != null) {
res.data.timestamp = res.data.ts;
}
return res;
}
}
export default RequestManager;

121
common/routeMap.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -21,13 +21,13 @@ function isLogin() {
*/
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 => {
// 确保白名单项目不带/开头,以实现一致的比较
@ -43,14 +43,14 @@ function isInWhiteList(url) {
export function navigateBack(delta = 1) {
return new Promise((resolve, reject) => {
const pages = getCurrentPages();
// 如果页面栈不足,直接返回首页
if (pages.length <= 1) {
return navigateTo('/pages/main/index', {}, 'reLaunch')
.then(resolve)
.catch(reject);
}
// 查看前一个页面是否是登录页
if (pages.length > 1 && pages[pages.length - 2].route === 'pages/users/login') {
// 如果前一个页面是登录页,则返回两步
@ -82,30 +82,30 @@ 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/users/login',
@ -117,7 +117,7 @@ export function routerTo(options) {
reject(err);
}
});
// 拒绝当前的导航请求
return reject(new Error('需要登录'));
}
@ -158,7 +158,7 @@ export function routerTo(options) {
}
} else {
// console.log('url',url,params,type,isInWhiteList(url),isLogin());
// 未指定跳转方式先尝试navigateTo失败后尝试switchTab
uni.navigateTo({
url,
@ -187,6 +187,9 @@ export function routerTo(options) {
* @returns {Promise} 返回Promise对象
*/
export function navigateTo(url, params = {}, type = '') {
if (url.includes("shouye")) {
url = url.replace("shouye", "main");
}
return routerTo({
url,
params,

View File

@ -1,194 +0,0 @@
<!--
* @Date: 2022-06-28 10:24:32
* @LastEditTime: 2022-06-29 11:37:17
* @Description: 自定义tabbar
-->
<template>
<view class="_tab-bar fade" >
<view class="_tab-bar-content" ></view>
<view class="_tab-bar-inner">
<view class="_tab-bar-inner-bg"></view>
<view @click="toPage(item)" v-for="(item, i) of list" :key="i" class="_tab-bar-inner-item">
<image v-if="index+1 == item.id" :src="item.actIcon" mode="scaleToFill" />
<image v-else :src="item.icon" mode="scaleToFill" />
<view :style="index+1 == item.id ? 'color:#70EDE8' : 'color:#999'">{{item.title}}</view>
</view>
</view>
</view>
</template>
<script>
export default {
name: 'tab-bar',
props: {
index: {
type: [String, Number],
default: 0
}
},
data() {
return {
list: []
}
},
methods: {
/**
* @description: 跳转页面
* @return {*}
*/
toPage(e) {
uni.redirectTo({
url: e.path
})
}
},
created() {
let that = this
this.req({
url: 'open_card',
success(res) {
// uni.setStorageSync('empty', res.data.userinfo.is_y_quota)
console.log('aaaaaaaaaaaaaaaa');
if (res.data.data.open_card == 1) {
that.list = [{
id: 1,
icon: '/static/tabbar/chousang.png',
actIcon: '/static/tabbar/chousang_sel.png',
title: '首页',
path: '/pages/main/index'
},
{
id: 2,
icon: '/static/tabbar/wuxian.png',
actIcon: '/static/tabbar/wuxian_sel.png',
title: '无限赏',
path: '/pages/infinite/index'
},
{
id: 3,
icon: '/static/tabbar/ka.png',
actIcon: '/static/tabbar/ka_sel.png',
title: '抽卡',
path: '/pages/DrawCard/index'
},
{
id: 4,
icon: '/static/tabbar/hegui.png',
actIcon: '/static/tabbar/hegui_sel.png',
title: '盒柜',
path: '/pages/kit/kit'
},
{
id: 5,
icon: '/static/tabbar/mine.png',
actIcon: '/static/tabbar/mine_sel.png',
title: '我的',
path: '/pages/users/index'
}
]
} else {
that.list = [{
id: 1,
icon: '/static/tabbar/chousang.png',
actIcon: '/static/tabbar/chousang_sel.png',
title: '首页',
path: '/pages/main/index'
},
{
id: 2,
icon: '/static/tabbar/shop.png',
actIcon: '/static/tabbar/shop_sel.png',
title: '商城',
path: '/pages/shop/index'
},
{
id: 3,
icon: '/static/tabbar/hegui.png',
actIcon: '/static/tabbar/hegui_sel.png',
title: '盒柜',
path: '/pages/kit/kit'
},
{
id: 4,
icon: '/static/tabbar/wuxian.png',
actIcon: '/static/tabbar/wuxian_sel.png',
title: '无限赏',
path: '/pages/infinite/index'
},
{
id: 5,
icon: '/static/tabbar/mine.png',
actIcon: '/static/tabbar/mine_sel.png',
title: '我的',
path: '/pages/users/index'
}
]
}
}
})
},
mounted() {
// console.log(uni.getStorageSync('empty'));
}
}
</script>
<style lang="scss" scoped>
._tab-bar {
image {
width: 50rpx;
height: 50rpx;
}
width: 100%;
&-content {
width: 100%;
height: 100rpx;
}
&-inner {
width: 100%;
padding-top: 20rpx;
display: flex;
justify-content: space-around;
align-items: center;
position: fixed;
left: 0;
bottom: 0;
z-index: 518;
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
&-bg {
width: 100%;
height: 98rpx;
position: absolute;
left: 0;
bottom: 0;
z-index: 0;
background: #0A0A0A;
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
}
&-item {
position: relative;
z-index: 1;
width: 100rpx;
height: 98rpx;
top: 10rpx;
color: #999;
display: flex;
align-items: center;
flex-direction: column;
font-size: 20rpx;
}
}
}
</style>

View File

@ -204,7 +204,6 @@
<view class="goods-item" v-for="(item, i) in handelList" :key="i">
<view class="pic">
<image :src="item.goodslist_imgurl" lazy-load></image>
<!-- <view class="type">{{ item.shang_title }}</view> -->
<view class="num center">{{ item.chooseNum }}</view>
</view>
@ -352,14 +351,6 @@ export default {
id: 1,
title: '赏品'
},
// {
// id: 5,
// title: ''
// },
// {
// id:3,
// title: ''
// },
{
id: 4,
title: '保险柜'
@ -368,10 +359,6 @@ export default {
id: 2,
title: '预售'
}
// {
// id: 6,
// title: ''
// }
],
subTabCur: 0,
listData: [],
@ -393,12 +380,6 @@ export default {
}
this.canReload && this.tabChange(this.tabCur)
this.canReload = true
const curPages = getCurrentPages()[0]; //
if (typeof curPages.getTabBar === 'function' && curPages.getTabBar()) {
this.$mp.page.getTabBar().setData({
selected: 3
});
}
this.$platform.getOrderNo(this).then(order_num => {
if (order_num != null && order_num != "") {
this.$common.msg("支付成功~")