增加扫码页/增加环境配置
This commit is contained in:
+109
-10
@@ -69,6 +69,10 @@
|
||||
<!-- 底部导航栏 -->
|
||||
<view class="tab-bar">
|
||||
<view class="tab-item" :class="{ active: currentTab === 'home' }" @click="switchTab('home')">
|
||||
<view class="home-icon">
|
||||
<view class="home-roof"></view>
|
||||
<view class="home-body"></view>
|
||||
</view>
|
||||
<text class="tab-text">首页</text>
|
||||
</view>
|
||||
|
||||
@@ -77,6 +81,10 @@
|
||||
</view>
|
||||
|
||||
<view class="tab-item" :class="{ active: currentTab === 'mine' }" @click="switchTab('mine')">
|
||||
<view class="mine-icon">
|
||||
<view class="mine-head"></view>
|
||||
<view class="mine-body"></view>
|
||||
</view>
|
||||
<text class="tab-text">我的</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -130,15 +138,13 @@
|
||||
|
||||
<script>
|
||||
import PageNavBar from '@/components/page-nav-bar/page-nav-bar.vue';
|
||||
|
||||
const API_BASE = 'http://192.168.0.23:4000';
|
||||
const DEVICE_ID = 'A1036';
|
||||
const BEARER_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImRlZXB2ZW5kaW5nIiwic3ViIjoiMTY0MDI0MTEyNiIsImZyb20iOiJwb3MiLCJyb2xlIjoicG9zIiwibWFpbmJvYXJkX2lkIjoiVDEwMDIiLCJwb3Nfc24iOiIxNjQwMjQxMTI2IiwiaWF0IjoxNzc3NTI5MjYzLCJleHAiOjE3NzgxMzQwNjN9.I7eL2oL2rmkaJKH4R6aylUloyJh0dUS3vXLvKueX28I';
|
||||
import config from '@/config/env.js';
|
||||
|
||||
export default {
|
||||
components: { PageNavBar },
|
||||
data() {
|
||||
return {
|
||||
deviceId: '',
|
||||
currentTab: 'home',
|
||||
showQrcodePopup: false,
|
||||
loading: false,
|
||||
@@ -151,7 +157,7 @@ export default {
|
||||
{ title: '联系客服', action: 'call' },
|
||||
{ title: '公众号信息', action: 'qrcode' }
|
||||
],
|
||||
servicePhone: '13264706088'
|
||||
servicePhone: config.servicePhone
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -174,8 +180,19 @@ export default {
|
||||
return cat ? cat.products || [] : [];
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.fetchProducts();
|
||||
onLoad(options) {
|
||||
// 支持通过 tab 参数切换到"我的"页面
|
||||
if (options.tab === 'mine') {
|
||||
this.currentTab = 'mine';
|
||||
}
|
||||
|
||||
if (options.device_id) {
|
||||
this.deviceId = options.device_id;
|
||||
this.fetchProducts();
|
||||
} else if (!options.tab) {
|
||||
// 无设备编号且非 tab 跳转,跳回扫码页
|
||||
uni.redirectTo({ url: '/pages/index/scan' });
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
switchTab(tab) { this.currentTab = tab; },
|
||||
@@ -190,15 +207,27 @@ export default {
|
||||
},
|
||||
async fetchProducts() {
|
||||
this.loading = true;
|
||||
const url = config.apiBaseUrl + '/device-product/getProductList';
|
||||
const params = { device_id: this.deviceId };
|
||||
|
||||
if (config.enableRequestLog) {
|
||||
console.log('[API] GET', url, params);
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await uni.request({
|
||||
url: API_BASE + '/device-product/getProductList',
|
||||
url,
|
||||
method: 'GET',
|
||||
data: { device_id: DEVICE_ID },
|
||||
data: params,
|
||||
header: {
|
||||
Authorization: 'Bearer ' + BEARER_TOKEN
|
||||
Authorization: 'Bearer ' + config.bearerToken
|
||||
}
|
||||
});
|
||||
|
||||
if (config.enableRequestLog) {
|
||||
console.log('[API] Response:', res.data);
|
||||
}
|
||||
|
||||
const ret = res.data || {};
|
||||
if (ret.code === 0 && Array.isArray(ret.data)) {
|
||||
this.categoryList = ret.data;
|
||||
@@ -206,6 +235,9 @@ export default {
|
||||
uni.showToast({ title: ret.message || '获取商品失败', icon: 'none' });
|
||||
}
|
||||
} catch (e) {
|
||||
if (config.enableRequestLog) {
|
||||
console.error('[API] Error:', e);
|
||||
}
|
||||
uni.showToast({ title: '网络请求失败', icon: 'none' });
|
||||
} finally {
|
||||
this.loading = false;
|
||||
@@ -282,6 +314,73 @@ page { height: 100%; background-color: #fff; }
|
||||
.tab-bar .tab-item { flex: 1; display: flex; align-items: center; justify-content: center; height: 100%; }
|
||||
.tab-bar .tab-text { font-size: 28rpx; color: #999; font-weight: normal; }
|
||||
.tab-bar .tab-item.active .tab-text { color: #2979ff; }
|
||||
|
||||
/* 首页图标 */
|
||||
.tab-bar .home-icon {
|
||||
width: 40rpx;
|
||||
height: 36rpx;
|
||||
position: relative;
|
||||
margin-bottom: 6rpx;
|
||||
}
|
||||
.tab-bar .home-roof {
|
||||
width: 0;
|
||||
height: 0;
|
||||
border-left: 22rpx solid transparent;
|
||||
border-right: 22rpx solid transparent;
|
||||
border-bottom: 18rpx solid #999;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
.tab-bar .home-body {
|
||||
width: 30rpx;
|
||||
height: 18rpx;
|
||||
background-color: #999;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
border-radius: 0 0 3rpx 3rpx;
|
||||
}
|
||||
.tab-bar .tab-item.active .home-roof {
|
||||
border-bottom-color: #2979ff;
|
||||
}
|
||||
.tab-bar .tab-item.active .home-body {
|
||||
background-color: #2979ff;
|
||||
}
|
||||
|
||||
/* 我的图标(与扫一扫页共用) */
|
||||
.tab-bar .mine-icon {
|
||||
width: 40rpx;
|
||||
height: 36rpx;
|
||||
position: relative;
|
||||
margin-bottom: 6rpx;
|
||||
}
|
||||
.tab-bar .mine-head {
|
||||
width: 16rpx;
|
||||
height: 16rpx;
|
||||
border-radius: 50%;
|
||||
background-color: #999;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
.tab-bar .mine-body {
|
||||
width: 28rpx;
|
||||
height: 16rpx;
|
||||
border-radius: 14rpx 14rpx 0 0;
|
||||
background-color: #999;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
.tab-bar .tab-item.active .mine-head,
|
||||
.tab-bar .tab-item.active .mine-body {
|
||||
background-color: #2979ff;
|
||||
}
|
||||
.door-btn-wrapper { position: relative; display: flex; align-items: center; justify-content: center; margin-top: -80rpx; }
|
||||
.door-btn { width: 160rpx; height: 160rpx; border-radius: 50%; background: linear-gradient(135deg, #2979ff, #1e60e0); color: #fff; font-size: 38rpx; font-weight: bold; display: flex; align-items: center; justify-content: center; box-shadow: 0 10rpx 36rpx rgba(41,121,255,0.55); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user