This commit is contained in:
@@ -157,18 +157,22 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 开门流程组件 -->
|
||||
<door-panel ref="doorPanel" :device-id="deviceId" :user-id="userId" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import PageNavBar from '@/components/page-nav-bar/page-nav-bar.vue';
|
||||
import DoorPanel from '@/components/door-panel/door-panel.vue';
|
||||
import config from '@/config/env.js';
|
||||
import { get, gatewayGet } from '@/utils/request.js';
|
||||
import { checkLoginWithPrompt, getCachedUserInfo, isLoggedIn } from '@/utils/auth-guard.js';
|
||||
import { isVConsoleEnabled, showVConsole, hideVConsole } from '@/utils/vconsole';
|
||||
|
||||
export default {
|
||||
components: { PageNavBar },
|
||||
components: { PageNavBar, DoorPanel },
|
||||
data() {
|
||||
return {
|
||||
deviceId: '',
|
||||
@@ -194,6 +198,10 @@ export default {
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
userId() {
|
||||
const info = getCachedUserInfo();
|
||||
return (info && info.user_id) || '';
|
||||
},
|
||||
canGoBack() {
|
||||
// 有上一页,或者从 tab 切换过来的,都可以返回
|
||||
return getCurrentPages().length > 1 || this.fromPage === 'tab';
|
||||
@@ -391,12 +399,47 @@ export default {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
handleOpenDoor() {
|
||||
uni.showModal({
|
||||
title: '开门',
|
||||
content: '确认打开柜门?',
|
||||
success: r => r.confirm && uni.showToast({ title: '柜门已打开', icon: 'success' })
|
||||
});
|
||||
async handleOpenDoor() {
|
||||
// 检查登录状态
|
||||
if (!isLoggedIn()) {
|
||||
checkLoginWithPrompt('door');
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查设备ID
|
||||
if (!this.deviceId) {
|
||||
uni.showToast({ title: '请先扫描设备二维码', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查用户信息,若缓存中没有则调接口获取
|
||||
if (!this.userId) {
|
||||
try {
|
||||
const infoRes = await gatewayGet('/api/v1/user/info', {});
|
||||
const infoData = (infoRes.data || {}).data || {};
|
||||
if (infoData.user_id) {
|
||||
const existing = getCachedUserInfo() || {};
|
||||
uni.setStorageSync('user_info', {
|
||||
...existing,
|
||||
user_id: infoData.user_id,
|
||||
nickname: infoData.nickname || existing.nickname || '',
|
||||
avatar: infoData.avatar || existing.avatar || '',
|
||||
phone: infoData.phone || existing.phone || '',
|
||||
});
|
||||
this.loadUserInfo();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[handleOpenDoor] 获取用户信息失败:', e);
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.userId) {
|
||||
uni.showToast({ title: '无法获取用户信息,请重新登录', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
// 调用组件方法启动开门流程
|
||||
this.$refs.doorPanel.open();
|
||||
},
|
||||
handleMenuClick(item) {
|
||||
switch (item.action) {
|
||||
@@ -666,4 +709,5 @@ page { height: 100%; background-color: #fff; }
|
||||
border: 2rpx solid #2979ff;
|
||||
border-radius: 40rpx;
|
||||
}
|
||||
|
||||
</style>
|
||||
Reference in New Issue
Block a user