fix: 修复websocket

This commit is contained in:
2025-12-30 16:29:06 +08:00
parent 4c3e383827
commit 398ca28efb
4 changed files with 299 additions and 11 deletions

View File

@@ -454,6 +454,12 @@
"navigationBarTitleText": "客服中心"
}
},
{
"path": "setup/developer",
"style": {
"navigationBarTitleText": "开发者选项"
}
},
{
"path": "chat/chat",
"style": {

View File

@@ -21,21 +21,54 @@ const sensitiveData = [
const isDev = checkDev('dev');
// 环境URL配置
const ENV_URLS = {
// 生产环境
prod: {
main: "https://app.xiaokang88.com/member",
xkApi: "https://api.xiaokang88.com/api/mobile",
shop: "https://shop.xiaokang88.com/member",
im: "https://api.ws.g.xiaokang88.com/api"
},
// 测试环境
test: {
main: "https://test.xk.app.nailaoyun.cn/member",
xkApi: "https://test.xk.api.nailaoyun.cn/api/mobile",
shop: "https://test.xk.shop.nailaoyun.cn/member",
im: "https://api.ws.g.nailaoyun.cn/api"
},
// 本地开发环境
local: {
main: "http://127.0.0.1:18000/member",
xkApi: "http://127.0.0.1:18001/api/mobile",
shop: "http://127.0.0.1:18018/member",
im: "http://127.0.0.1:12080/api"
}
};
// 获取当前环境配置
function getEnvUrls() {
// 如果是本地开发环境,使用本地配置
if (isDev === true) {
return ENV_URLS.local;
}
// 检查是否开启了开发者测试模式
const devMode = uni.getStorageSync('dev_mode');
return devMode ? ENV_URLS.test : ENV_URLS.prod;
}
function request(url, params, method = 0) {
let baseURL = isDev === true? 'http://127.0.0.1:18000/member': "https://app.xiaokang88.com/member"
// let baseURL = "http://127.0.0.1:18000/member"
const envUrls = getEnvUrls();
let baseURL = envUrls.main;
if (url.split('/').indexOf('imApi') !== -1) {
// baseURL = "http://127.0.0.1:12080/api"
// baseURL = isDev === true? 'http://127.0.0.1:12080/api': "http://im.xiaokang88.com/api"
baseURL = isDev === true? 'http://127.0.0.1:12080/api': "https://api.ws.g.xiaokang88.com/api"
// baseURL = "https://api.ws.g.xiaokang88.com/api"
baseURL = envUrls.im;
}
if (url.split('/').indexOf('newApi') !== -1) {
baseURL = isDev === true? 'http://127.0.0.1:18018/member': "https://shop.xiaokang88.com/member"
baseURL = envUrls.shop;
}
if (url.split('/').indexOf('xkApi') !== -1) {
baseURL = isDev === true? 'http://127.0.0.1:18001/api/mobile': "https://api.xiaokang88.com/api/mobile"
// baseURL = "http://127.0.0.1:18001/api/mobile"
baseURL = envUrls.xkApi;
}
url = url.replace('/oldApi', '');
url = url.replace('/newApi', '');

View File

@@ -0,0 +1,215 @@
<template>
<view class="container">
<view class="header">
<text class="title">开发者选项</text>
<text class="subtitle">仅供开发测试使用</text>
</view>
<view class="card">
<view class="item">
<view class="item-left">
<text class="item-title">测试环境</text>
<text class="item-desc">{{ devMode ? '已开启' : '已关闭' }}</text>
</view>
<switch :checked="devMode" @change="onDevModeChange" color="#1777FF" />
</view>
</view>
<view class="card info-card">
<view class="info-title">当前环境配置</view>
<view class="info-item" v-if="!devMode">
<text class="info-label">主API:</text>
<text class="info-value">app.xiaokang88.com</text>
</view>
<view class="info-item" v-if="!devMode">
<text class="info-label">新API:</text>
<text class="info-value">api.xiaokang88.com</text>
</view>
<view class="info-item" v-if="!devMode">
<text class="info-label">商城API:</text>
<text class="info-value">shop.xiaokang88.com</text>
</view>
<view class="info-item" v-if="!devMode">
<text class="info-label">WebSocket:</text>
<text class="info-value">api.ws.g.xiaokang88.com</text>
</view>
<view class="info-item" v-if="devMode">
<text class="info-label">主API:</text>
<text class="info-value test">test.xk.app.nailaoyun.cn</text>
</view>
<view class="info-item" v-if="devMode">
<text class="info-label">新API:</text>
<text class="info-value test">test.xk.api.nailaoyun.cn</text>
</view>
<view class="info-item" v-if="devMode">
<text class="info-label">商城API:</text>
<text class="info-value test">test.xk.shop.nailaoyun.cn</text>
</view>
<view class="info-item" v-if="devMode">
<text class="info-label">WebSocket:</text>
<text class="info-value test">api.ws.g.nailaoyun.cn</text>
</view>
</view>
<view class="tips">
<text class="tips-text">提示切换环境后需要重新启动小程序才能生效</text>
</view>
<view class="btn-restart" @click="restartApp">
重启小程序
</view>
</view>
</template>
<script>
export default {
data() {
return {
devMode: false
}
},
onLoad() {
// 读取缓存中的开发模式状态
this.devMode = uni.getStorageSync('dev_mode') || false;
},
methods: {
onDevModeChange(e) {
this.devMode = e.detail.value;
// 保存到缓存
uni.setStorageSync('dev_mode', this.devMode);
uni.showToast({
title: this.devMode ? '已切换到测试环境' : '已切换到生产环境',
icon: 'none',
duration: 2000
});
},
restartApp() {
uni.showModal({
title: '提示',
content: '确定要重启小程序吗?',
success: (res) => {
if (res.confirm) {
// 重启小程序
uni.reLaunch({
url: '/pages/home/index'
});
}
}
});
}
}
}
</script>
<style lang="scss" scoped>
.container {
min-height: 100vh;
background-color: #F5F6FA;
padding: 32rpx;
}
.header {
text-align: center;
padding: 40rpx 0;
.title {
display: block;
font-size: 40rpx;
font-weight: bold;
color: #333;
margin-bottom: 16rpx;
}
.subtitle {
display: block;
font-size: 26rpx;
color: #999;
}
}
.card {
background: #FFFFFF;
border-radius: 16rpx;
padding: 32rpx;
margin-bottom: 24rpx;
.item {
display: flex;
justify-content: space-between;
align-items: center;
.item-left {
.item-title {
display: block;
font-size: 32rpx;
font-weight: 500;
color: #333;
margin-bottom: 8rpx;
}
.item-desc {
display: block;
font-size: 24rpx;
color: #999;
}
}
}
}
.info-card {
.info-title {
font-size: 28rpx;
font-weight: 500;
color: #666;
margin-bottom: 24rpx;
padding-bottom: 16rpx;
border-bottom: 1rpx solid #EFEFEF;
}
.info-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 16rpx 0;
.info-label {
font-size: 26rpx;
color: #666;
}
.info-value {
font-size: 24rpx;
color: #333;
&.test {
color: #FF6B00;
}
}
}
}
.tips {
padding: 24rpx;
text-align: center;
.tips-text {
font-size: 24rpx;
color: #FF6B00;
}
}
.btn-restart {
width: 100%;
height: 88rpx;
background: #1777FF;
border-radius: 44rpx;
font-size: 32rpx;
color: #FFFFFF;
text-align: center;
line-height: 88rpx;
margin-top: 48rpx;
}
</style>

View File

@@ -21,7 +21,7 @@
<text class="iconfont icon-jiantou1"></text>
</view>
<view class="box">
<view class="box" @touchstart="onDevPressStart" @touchend="onDevPressEnd" @touchcancel="onDevPressEnd">
<view class="title">
客服热线
</view>
@@ -44,13 +44,47 @@
export default {
data() {
return {
msg: ""
msg: "",
devPressTimer: null // 开发者入口长按计时器
}
},
onLoad() {
},
methods: {
// 开发者入口 - 长按开始
onDevPressStart() {
this.devPressTimer = setTimeout(() => {
this.showDevPasswordDialog();
}, 20000); // 20秒
},
// 开发者入口 - 长按结束
onDevPressEnd() {
if (this.devPressTimer) {
clearTimeout(this.devPressTimer);
this.devPressTimer = null;
}
},
// 显示开发者密码输入框
showDevPasswordDialog() {
uni.showModal({
title: '开发者验证',
editable: true,
placeholderText: '请输入密码',
success: (res) => {
if (res.confirm && res.content === 'xk666@') {
uni.navigateTo({
url: '/subPackages/setup/developer'
});
} else if (res.confirm) {
uni.showToast({
title: '密码错误',
icon: 'none'
});
}
}
});
},
goserved() {
uni.navigateTo({
url: '/subPackages/setup/fw-serve'