Commit 4a86b426 authored by 小费同学阿's avatar 小费同学阿 💬

uhf功能搭建

parent 5d974337
...@@ -8,6 +8,54 @@ export const openCamera = (params) => { ...@@ -8,6 +8,54 @@ export const openCamera = (params) => {
}) })
}) })
} }
// 开始识别
export const startPower = (params) => {
return new Promise(resolve => {
DS_BRIDGE.call('startPower', params, res => {
resolve(res)
})
})
}
// 停止识别
export const stopPower = (params) => {
return new Promise(resolve => {
DS_BRIDGE.call('stopPower', params, res => {
resolve(res)
})
})
}
// 设置功率
export const setPower = (params) => {
return new Promise(resolve => {
DS_BRIDGE.call('setPower', params, res => {
resolve(res)
})
})
}
// 设置功率
export const clearPower = (params) => {
return new Promise(resolve => {
DS_BRIDGE.call('clearPower', params, res => {
resolve(res)
})
})
}
// 增加声音
export const addVolume = (params) => {
return new Promise(resolve => {
DS_BRIDGE.call('addVolume', params, res => {
resolve(res)
})
})
}
// 减小声音
export const reduceVolume = (params) => {
return new Promise(resolve => {
DS_BRIDGE.call('reduceVolume', params, res => {
resolve(res)
})
})
}
// 拍照取相册 实现调用存储功能(带相册,文件资源功能) // 拍照取相册 实现调用存储功能(带相册,文件资源功能)
export const openCameraStorage = (params) => { export const openCameraStorage = (params) => {
return new Promise(resolve => { return new Promise(resolve => {
...@@ -35,7 +83,14 @@ export const openScan = (params) => { ...@@ -35,7 +83,14 @@ export const openScan = (params) => {
export const WebView = { export const WebView = {
openCamera, openCamera,
startPower,
stopPower,
clearPower,
setPower,
addVolume,
reduceVolume,
openCameraStorage, openCameraStorage,
openCameraAll, openCameraAll,
openScan openScan,
DS_BRIDGE
} }
<template>
<!-- uhf扫码枪按钮操控 -->
<div class="setup_module">
<div class="button_row" style="display: flex;">
<el-button class="button_rowBtn" type="primary" @click="handleStartPower">开始识别</el-button>
<el-button class="button_rowBtn" type="primary" @click="handleStopPower">停止识别</el-button>
</div>
<div class="button_row" style="display: flex;">
<el-button class="button_rowBtn" type="primary" @click="handleClearPower">清空数据</el-button>
<el-button class="button_rowBtn" type="primary" @click="handleSetPower">设置功率</el-button>
</div>
<!-- <div class="button_row">-->
<!-- <el-button class="button_rowBtn" type="primary" @click="handleAddVolume">音量+</el-button>-->
<!-- </div>-->
<!-- <div class="button_row">-->
<!-- <el-button class="button_rowBtn" type="primary" @click="handleReduceVolume">音量-</el-button>-->
<!-- </div>-->
<!--展示页-->
<div class="" style="margin-bottom: 10px">共计:{{ resultInfo.length }}条数据</div>
<el-table :data="resultInfo" style="width: 100%">
<el-table-column prop="typeId" label="ID" min-width="210rpx" />
<el-table-column prop="rssi" label="RSSI" min-width="60rpx" />
</el-table>
<!-- <div v-for="(item, index) in resultInfo" :key="index">-->
<!-- <div class="">{{ item.typeId }}</div>-->
<!-- <div class="">{{ item.rssi }}</div>-->
<!-- </div>-->
<!-- 对话框 -->
<el-form ref="formRef" :model="form" :rules="rules" class="dialog-form">
<el-dialog
:visible.sync="dialogVisible"
title="请输入内容"
width="30%"
:before-close="handleClose"
>
<el-form-item prop="inputValue">
<!-- 数量限制1-30-->
<el-input
v-model="form.inputValue"
placeholder="请输入功率值"
clearable
oninput="value=value.replace(/[^0-9.]/g,'')"
style="margin-bottom: 20px;"
type="number"
:min="1"
:max="30"
:step="1"
@input="validateInput"
@change="watchInput"
@clear="clearInput"
/>
</el-form-item>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="confirmInput">确认</el-button>
</span>
</el-dialog>
</el-form>
</div>
</template>
<script>
import { getToken } from '@/utils/auth'
export default {
name: 'Index',
data() {
return {
dialogVisible: false, // 控制对话框显示与隐藏
startState: false, // 是否正在开启开始识别
form: {
inputValue: ''
},
rules: {
inputValue: [
{ required: true, message: '功率值不能为空!', trigger: 'blur' }
]
},
resultInfo: []
}
},
created() {
this.startState = false
// 组件创建时,也可以从缓存中读取值
const storedValue = localStorage.getItem('inputValue')
if (storedValue !== null) {
this.form.inputValue = storedValue
} else {
this.form.inputValue = 30
}
// 扫描结果
this.$WebView.DS_BRIDGE.register('resultInfo', args => {
console.log('扫出来的结果啊:', args)
this.resultInfo = JSON.parse(args)
})
},
methods: {
// 输入效率值校验
validateInput(value) {
if (value === '' || value === null) {
this.form.inputValue = '' // 允许清空输入
} else if (!Number.isInteger(+value) || value < 1 || value > 999) {
this.form.inputValue = 1 // 如果输入不合法或包含小数,重置为1或其他默认值
} else {
this.form.inputValue = value // 合法输入,更新formData
}
},
watchInput(event) {
const value = event.target.value
const numberValue = +value // 尝试将输入转换为数字
if (!Number.isInteger(numberValue) || numberValue < 1 || numberValue > 9) {
// 如果输入包含小数或不在这个范围内,重置输入框
event.target.value = this.form.inputValue
}
},
/** 开始识别按钮*/
handleStartPower() {
this.startState = true
const params = {
flag: 'startPower',
tokenMsg: getToken()
}
this.$WebView.startPower(params).then(res => {
this.imgUrlForm = JSON.parse(res)
})
},
/** 清空数据按钮*/
handleClearPower() {
const params = {
flag: 'clearPower',
tokenMsg: getToken()
}
this.$WebView.clearPower(params).then(res => {
this.imgUrlForm = JSON.parse(res)
})
},
/** 停止识别按钮*/
handleStopPower() {
this.startState = false
console.log('调用前', getToken())
const params = {
flag: 'stopPower',
tokenMsg: getToken()
}
this.$WebView.stopPower(params).then(res => {
this.imgUrlForm = JSON.parse(res)
})
},
// clear按钮
clearInput() {
this.form.inputValue = '' // 清除输入框内容
this.$nextTick(() => {
// 手动触发表单验证,但忽略错误提示
this.$refs.formRef.validateField('inputValue', valid => {
// 这里不进行任何操作,只是为了避免自动验证
})
})
},
/** 确认按钮*/
confirmInput() {
this.$refs.formRef.validate((valid) => {
if (valid) {
// 表单验证通过
this.dialogVisible = false
// 存储值到localStorage
localStorage.setItem('inputValue', this.form.inputValue)
// 未开启
const paramsNone = {
flag: 'setPowerNone',
// 设置的功率值
msg: this.form.inputValue,
tokenMsg: getToken()
}
// 开启中
const paramsScand = {
flag: 'setPowerScand',
// 设置的功率值
msg: this.form.inputValue,
tokenMsg: getToken()
}
if (this.startState) {
this.$WebView.setPower(paramsScand).then(res => {
this.imgUrlForm = JSON.parse(res)
})
} else {
// 没开
this.$WebView.setPower(paramsNone).then(res => {
this.imgUrlForm = JSON.parse(res)
})
}
} else {
// 表单验证失败
console.error('功率值不能为空!')
return false
}
})
},
/** 关闭弹窗*/
handleClose() {
console.log('对话框被关闭')
this.dialogVisible = false // 关闭对话框
},
/** 设置功率按钮*/
handleSetPower() {
this.dialogVisible = true // 显示对话框
// 从localStorage中读取值
const storedValue = localStorage.getItem('inputValue')
if (storedValue !== null) {
this.form.inputValue = storedValue
}
this.dialogVisible = true // 显示对话框
},
/** 增加音量按钮*/
handleAddVolume() {
console.log('调用前', getToken())
const params = {
flag: 'addVolume',
subPath: 'jbcheck',
tokenMsg: getToken()
}
this.$WebView.addVolume(params).then(res => {
console.log('addVolume', res)
console.log('addVolume', JSON.parse(res))
this.imgUrlForm = JSON.parse(res)
})
},
/** 减小音量按钮*/
handleReduceVolume() {
console.log('调用前', getToken())
const params = {
flag: 'reduceVolume',
subPath: 'jbcheck',
tokenMsg: getToken()
}
this.$WebView.reduceVolume(params).then(res => {
console.log('reduceVolume', res)
console.log('reduceVolume', JSON.parse(res))
this.imgUrlForm = JSON.parse(res)
})
}
}
}
</script>
<style scoped lang="scss">
.setup_module{
padding: 0px 20px 20px 20px;
.button_row{
margin: 0px 20px 20px 20px;
.button_rowBtn{
font-size: 17px;
width: 160px;
}
.button_rowText{
margin-top: 10px;
}
}
}
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment