feat:设备关键件对接接口

master
黄伟杰 1 month ago
parent 1fd1cf21f8
commit 878304b2c9

@ -209,7 +209,8 @@
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { ref, computed } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import {
getEquipmentDetail,
getEquipmentInspectionByDeviceId,
@ -345,11 +346,8 @@ function goBack() {
uni.navigateBack()
}
onMounted(() => {
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
const options = currentPage && currentPage.options ? currentPage.options : {}
const rawId = options.id !== undefined ? options.id : options.code
onLoad((query) => {
const rawId = query && (query.id !== undefined ? query.id : query.code)
const decoded = rawId ? decodeURIComponent(String(rawId)) : ''
deviceId.value = decoded ? decoded : undefined
fetchAll()

@ -7,10 +7,6 @@
</view>
<view class="header-content">
<text class="header-title">关键件详情</text>
<text class="header-code">{{ keypartData.code }}</text>
</view>
<view class="status-badge" :class="'status-' + keypartData.statusType">
<text>{{ keypartData.status }}</text>
</view>
</view>
@ -19,58 +15,24 @@
<view class="card-title">基本信息</view>
<view class="info-list">
<view class="info-row">
<text class="info-label">关键件名称</text>
<text class="info-value">{{ keypartData.name }}</text>
<text class="info-label">编码</text>
<text class="info-value">{{ detailValue(detailData?.code) }}</text>
</view>
<view class="info-row">
<text class="info-label">关键件类型</text>
<text class="info-value">{{ keypartData.type }}</text>
<text class="info-label">名称</text>
<text class="info-value">{{ detailValue(detailData?.name) }}</text>
</view>
<view class="info-row">
<text class="info-label">规格型号</text>
<text class="info-value">{{ keypartData.spec }}</text>
<text class="info-label">描述</text>
<text class="info-value">{{ detailValue(detailData?.description) }}</text>
</view>
<view class="info-row">
<text class="info-label">所属设备</text>
<text class="info-value">{{ keypartData.equipment }}</text>
<text class="info-label">数量</text>
<text class="info-value">{{ detailValue(detailData?.count) }}</text>
</view>
<view class="info-row">
<text class="info-label">安装位置</text>
<text class="info-value">{{ keypartData.location }}</text>
</view>
</view>
</view>
<view class="info-card">
<view class="card-title">维护信息</view>
<view class="info-list">
<view class="info-row">
<text class="info-label">更换周期</text>
<text class="info-value highlight">{{ keypartData.replaceCycle }}</text>
</view>
<view class="info-row">
<text class="info-label">上次更换</text>
<text class="info-value">{{ keypartData.lastReplace }}</text>
</view>
<view class="info-row">
<text class="info-label">下次更换</text>
<text class="info-value warning">{{ keypartData.nextReplace }}</text>
</view>
</view>
</view>
<view class="info-card">
<view class="card-title">维护记录</view>
<view class="record-list">
<view v-for="(record, index) in maintenanceRecords" :key="index" class="record-item">
<view class="record-dot"></view>
<view class="record-content">
<text class="record-title">{{ record.title }}</text>
<text class="record-time">{{ record.time }}</text>
</view>
<view class="record-type" :class="'type-' + record.type">
<text>{{ record.typeText }}</text>
</view>
<text class="info-label">备注</text>
<text class="info-value">{{ detailValue(detailData?.remark) }}</text>
</view>
</view>
</view>
@ -79,41 +41,53 @@
</template>
<script setup>
import { reactive, onMounted } from 'vue';
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import request from '@/utils/request'
const keypartData = reactive({
code: '',
name: '主轴轴承',
type: '旋转部件',
spec: 'NSK-7014CTYNSULP4',
equipment: '数控加工中心-VMC850',
location: '主轴箱内部',
status: '正常',
statusType: 'normal',
replaceCycle: '2000小时',
lastReplace: '2024-01-15',
nextReplace: '2024-04-15'
});
const maintenanceRecords = reactive([
{ title: '定期更换', time: '2024-01-15', type: 'replace', typeText: '更换' },
{ title: '状态检查', time: '2024-02-15', type: 'check', typeText: '检查' },
{ title: '润滑保养', time: '2024-02-01', type: 'maintain', typeText: '保养' },
{ title: '定期更换', time: '2023-07-15', type: 'replace', typeText: '更换' }
]);
const keypartId = ref(undefined)
const loading = ref(false)
const detailData = ref(null)
function goBack() {
uni.navigateBack();
}
onMounted(() => {
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const options = currentPage.options || {};
if (options.code) {
keypartData.code = decodeURIComponent(options.code);
onLoad((query) => {
const rawId = query && (query.id !== undefined ? query.id : query.code)
const decoded = rawId ? decodeURIComponent(String(rawId)) : ''
keypartId.value = decoded ? decoded : undefined
fetchDetail()
})
async function fetchDetail() {
if (!keypartId.value) {
uni.showToast({ title: '缺少关键件ID', icon: 'none' })
return
}
loading.value = true
try {
const res = await request({
url: '/admin-api/mes/critical-component/get',
method: 'get',
params: { id: keypartId.value }
})
detailData.value = res && res.data !== undefined ? res.data : res
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
loading.value = false
}
});
}
function detailValue(v) {
if (v === 0) return '0'
if (v === false) return '否'
if (v === true) return '是'
if (v === null || v === undefined) return '-'
const s = String(v).trim()
return s ? s : '-'
}
</script>
<style lang="scss" scoped>
@ -165,33 +139,9 @@ onMounted(() => {
}
}
.status-badge {
position: absolute;
top: 60rpx;
right: 30rpx;
padding: 12rpx 24rpx;
border-radius: 24rpx;
font-size: 24rpx;
}
.status-normal {
background: rgba(24, 188, 55, 0.2);
color: #18bc37;
}
.status-warning {
background: rgba(255, 140, 0, 0.2);
color: #ff8c00;
}
.status-danger {
background: rgba(255, 77, 79, 0.2);
color: #ff4d4f;
}
.content-section {
padding: 0 30rpx 30rpx;
margin-top: -40rpx;
margin-top: 40rpx;
}
.info-card {
@ -236,77 +186,5 @@ onMounted(() => {
.info-value {
font-size: 28rpx;
color: #333333;
&.highlight {
font-weight: 600;
color: #1a3a5c;
}
&.warning {
color: #ff8c00;
font-weight: 500;
}
}
.record-list {
display: flex;
flex-direction: column;
}
.record-item {
display: flex;
align-items: center;
padding: 24rpx 0;
border-bottom: 1rpx solid #f5f7fa;
&:last-child {
border-bottom: none;
}
}
.record-dot {
width: 16rpx;
height: 16rpx;
border-radius: 50%;
background: #1a3a5c;
margin-right: 20rpx;
}
.record-content {
flex: 1;
.record-title {
display: block;
font-size: 28rpx;
color: #333333;
margin-bottom: 8rpx;
}
.record-time {
display: block;
font-size: 24rpx;
color: #999999;
}
}
.record-type {
padding: 8rpx 16rpx;
border-radius: 8rpx;
font-size: 22rpx;
}
.type-replace {
background: rgba(24, 188, 55, 0.1);
color: #18bc37;
}
.type-check {
background: rgba(74, 144, 194, 0.1);
color: #4a90c2;
}
.type-maintain {
background: rgba(255, 140, 0, 0.1);
color: #ff8c00;
}
</style>

@ -31,10 +31,7 @@
<view class="corner corner-br"></view>
</view>
</view>
<text class="scanning-text">正在扫描中...</text>
<view class="progress-bar">
<view class="progress-fill" :style="{ width: scanProgress + '%' }"></view>
</view>
<text class="scanning-text">正在打开扫码...</text>
</view>
</view>
@ -45,13 +42,13 @@
</view>
<view class="input-section">
<view class="input-label">手动输入关键件编码</view>
<view class="input-label">手动输入关键件ID</view>
<view class="input-wrapper">
<input
v-model="keypartCode"
class="code-input"
type="text"
placeholder="请输入关键件编码"
placeholder="请输入关键件ID"
placeholder-class="input-placeholder"
/>
</view>
@ -68,7 +65,6 @@ import { ref } from 'vue';
const keypartCode = ref('');
const isScanning = ref(false);
const scanProgress = ref(0);
function goBack() {
uni.navigateBack();
@ -76,33 +72,44 @@ function goBack() {
function startScan() {
if (isScanning.value) return;
isScanning.value = true;
scanProgress.value = 0;
const duration = 2000;
const interval = 50;
const steps = duration / interval;
let currentStep = 0;
const timer = setInterval(() => {
currentStep++;
scanProgress.value = Math.min((currentStep / steps) * 100, 100);
if (currentStep >= steps) {
clearInterval(timer);
setTimeout(() => {
isScanning.value = false;
navigateToDetail('KP-SCAN-001');
}, 200);
}
}, interval);
const finish = () => {
isScanning.value = false;
}
uni.scanCode({
onlyFromCamera: true,
scanType: ['qrCode', 'barCode'],
success: (res) => {
const id = String(res?.result || res?.code || res?.qrCode || res?.barCode || '').trim()
if (!id) {
uni.showToast({ title: '未获取到扫码结果', icon: 'none' })
return
}
navigateToDetail(id)
},
fail: (err) => {
const msg = String(err?.errMsg || '')
if (msg.includes('cancel')) {
uni.showToast({ title: '已取消扫码', icon: 'none' })
return
}
if (msg.toLowerCase().includes('not support') || msg.toLowerCase().includes('not supported')) {
uni.showToast({ title: '当前平台不支持扫码', icon: 'none' })
return
}
uni.showToast({ title: '扫码失败', icon: 'none' })
},
complete: finish
})
}
function confirmInput() {
if (keypartCode.value.trim().length === 0) {
uni.showToast({
title: '请输入关键件编码',
title: '请输入关键件ID',
icon: 'none'
});
return;
@ -111,9 +118,9 @@ function confirmInput() {
navigateToDetail(keypartCode.value.trim());
}
function navigateToDetail(code) {
function navigateToDetail(id) {
uni.navigateTo({
url: `/pages_function/pages/keypart/detail?code=${encodeURIComponent(code)}`
url: `/pages_function/pages/keypart/detail?id=${encodeURIComponent(id)}`
});
}
</script>
@ -316,21 +323,6 @@ function navigateToDetail(code) {
margin-bottom: 30rpx;
}
.progress-bar {
width: 400rpx;
height: 8rpx;
background: rgba(255, 255, 255, 0.2);
border-radius: 4rpx;
overflow: hidden;
}
.progress-fill {
height: 100%;
background: #ff8c00;
border-radius: 4rpx;
transition: width 0.05s linear;
}
.divider {
display: flex;
align-items: center;

@ -202,7 +202,8 @@
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { ref, computed } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import {
getMoldDetail,
getMoldInspectionByMoldId,
@ -321,15 +322,12 @@ function goBack() {
uni.navigateBack();
}
onMounted(async () => {
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
const options = currentPage && currentPage.options ? currentPage.options : {}
const rawId = options.id !== undefined ? options.id : options.code
onLoad((query) => {
const rawId = query && (query.id !== undefined ? query.id : query.code)
const decoded = rawId ? decodeURIComponent(String(rawId)) : ''
moldId.value = decoded ? decoded : undefined
fetchAll()
});
})
async function fetchAll() {
if (!moldId.value) {

@ -83,12 +83,15 @@ function startScan() {
onlyFromCamera: true,
scanType: ['qrCode', 'barCode'],
success: (res) => {
const code = String(res?.result || res?.code || res?.qrCode || res?.barCode || '').trim()
if (!code) {
console.log(res)
const info = JSON.parse(res.result)
console.log('info',info)
if (!info) {
uni.showToast({ title: '未获取到扫码结果', icon: 'none' })
return
}
navigateToDetail(code)
console.log('info.id',info.id)
navigateToDetail(info.id)
},
fail: (err) => {
const msg = String(err?.errMsg || '')
@ -118,9 +121,10 @@ function confirmInput() {
navigateToDetail(moldCode.value.trim());
}
function navigateToDetail(code) {
function navigateToDetail(id) {
console.log('id',id)
uni.navigateTo({
url: `/pages_function/pages/mold/detail?id=${encodeURIComponent(code)}`
url: `/pages_function/pages/mold/detail?id=${encodeURIComponent(id)}`
});
}
</script>

Loading…
Cancel
Save