huang
2025-11-26 792236ef78c2cdd3a989fb40a7f2e2487c4e17b6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<template>
  <div class="workstation-scanner-config">
    <el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="扫码间隔(秒)">
          <el-input-number
            v-model="scanIntervalSeconds"
            :min="1"
            :max="60"
            :step="1"
            style="width: 100%;"
          />
          <span class="form-tip">定时扫描MES写区的时间间隔,默认10秒</span>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="产线编号">
          <el-input-number
            v-model="config.workLine"
            :min="1"
            :max="100"
            :step="1"
            style="width: 100%;"
          />
          <span class="form-tip">产线编号,用于过滤玻璃信息</span>
        </el-form-item>
      </el-col>
    </el-row>
  </div>
</template>
 
<script setup>
import { ref, watch } from 'vue'
 
const props = defineProps({
  modelValue: {
    type: Object,
    default: () => ({})
  }
})
 
const emit = defineEmits(['update:modelValue'])
 
// 配置数据
const config = ref({
  scanIntervalMs: 10000,
  workLine: null
})
 
// 时间字段(秒)- 用于前端显示和输入
const scanIntervalSeconds = ref(10)
 
// 监听props变化
watch(() => props.modelValue, (newVal) => {
  if (newVal && Object.keys(newVal).length > 0) {
    config.value = {
      scanIntervalMs: newVal.scanIntervalMs ?? 10000,
      workLine: newVal.workLine ?? null
    }
    // 将毫秒转换为秒用于显示
    scanIntervalSeconds.value = (config.value.scanIntervalMs ?? 10000) / 1000
  }
}, { immediate: true, deep: true })
 
// 监听秒字段变化,转换为毫秒并更新config
watch(scanIntervalSeconds, (val) => {
  config.value.scanIntervalMs = Math.round(val * 1000)
  emit('update:modelValue', { ...config.value })
})
 
// 监听config其他字段变化,同步到父组件
watch(() => [
  config.value.workLine
], () => {
  emit('update:modelValue', { ...config.value })
}, { deep: true })
</script>
 
<style scoped>
.form-tip {
  margin-left: 10px;
  font-size: 12px;
  color: #909399;
}
</style>