|
@@ -50,14 +50,14 @@
|
|
|
<ws-input v-model="weighingList.grossWeight" @input="calculation" placeholder="未获取到毛重"
|
|
|
maxlength="100" size="small" :disabled="disabled2" />
|
|
|
</ws-form-item>
|
|
|
- <el-button type="primary" v-if="this.types == 1" @click="chongxin">重新获取</el-button>
|
|
|
+ <el-button type="primary" v-if="this.types == 1" @click="openPort">重新获取</el-button>
|
|
|
|
|
|
<ws-form-item label="皮重(公斤)" span="1" prop="tare">
|
|
|
<!-- <ws-input v-model="weighingList.tare" placeholder="未获取到皮重" maxlength="100" size="small"
|
|
|
disabled /> -->
|
|
|
<ws-input @input="calculation" v-model="weighingList.tare" placeholder="未获取到皮重" maxlength="100" size="small" />
|
|
|
</ws-form-item>
|
|
|
- <el-button type="primary" v-if="this.types == 2 || this.types == null">重新获取</el-button>
|
|
|
+ <el-button type="primary" v-if="this.types == 2 || this.types == null" @click="openPort">重新获取</el-button>
|
|
|
<!-- <div class="formItem"> -->
|
|
|
<ws-form-item label="净重(公斤)" span="1" prop="netWeight" v-if="this.types == 1">
|
|
|
<ws-input v-model="weighingList.netWeight" placeholder="请输入净重" maxlength="100" size="small"
|
|
@@ -116,6 +116,8 @@
|
|
|
addressUrl: '',
|
|
|
buckleMiscellaneous: 0,
|
|
|
compId: sessionStorage.getItem('ws-pf_compId'),
|
|
|
+ grossWeight:'',
|
|
|
+ tare:''
|
|
|
},
|
|
|
disabled: false,
|
|
|
disabled1: false,
|
|
@@ -145,6 +147,8 @@
|
|
|
warehouseId: '', //仓库id
|
|
|
compId: sessionStorage.getItem('ws-pf_compId'),
|
|
|
size: 10,
|
|
|
+ reader:null,
|
|
|
+ param:9600
|
|
|
}
|
|
|
},
|
|
|
activated() {
|
|
@@ -171,10 +175,56 @@
|
|
|
this.getList(id)
|
|
|
},
|
|
|
methods: {
|
|
|
- chongxin() {
|
|
|
- if (this.types == 2 || this.types == 3) {
|
|
|
- return
|
|
|
+ async closePort(){
|
|
|
+ console.log('closePort');
|
|
|
+ this.reader.cancel()
|
|
|
+ },
|
|
|
+ async openPort(){
|
|
|
+ console.log('openPort',navigator);
|
|
|
+ if ('serial' in navigator) {
|
|
|
+ // The Web Serial API is supported.
|
|
|
+ console.log('the Web Serial API is supported.');
|
|
|
+ console.log(this.param);
|
|
|
+ const port = await navigator.serial.requestPort();
|
|
|
+ await port.open({ baudRate: this.param }); // set baud rate
|
|
|
+ this.reader = port.readable.getReader();
|
|
|
+ // 监听来自串行设备的数据
|
|
|
+ while (true) {
|
|
|
+ const { value, done } = await this.reader.read();
|
|
|
+ // console.log("value",value);
|
|
|
+ if (done) {
|
|
|
+ // 允许稍后关闭串口。
|
|
|
+ this.reader.releaseLock();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ var result="";
|
|
|
+ //2。获取16进制字符串
|
|
|
+ // var receData = HexConvert.ByteToString(value);
|
|
|
+ // console.log("receData",receData);
|
|
|
+ var flag = false;
|
|
|
+ for(var i=0;i<value.length;i++){
|
|
|
+ var tmp = String.fromCharCode(value[i])
|
|
|
+ if(tmp == "+"){
|
|
|
+ flag = true
|
|
|
+ }
|
|
|
+ if(flag && result.length <6 && tmp != "+"){
|
|
|
+ result += tmp
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(this.tpyeNo != 2){
|
|
|
+ this.weighingList.grossWeight = parseInt(result)
|
|
|
}
|
|
|
+ else{
|
|
|
+ this.weighingList.tare = parseInt(result)
|
|
|
+ }
|
|
|
+ setTimeout(1000)
|
|
|
+ // value 是一个 Uint8Array
|
|
|
+ }
|
|
|
+ await port.close();
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ console.log('the Web Serial API is not supported.',navigator);
|
|
|
+ }
|
|
|
},
|
|
|
//附件
|
|
|
//上传附件
|