123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- <template>
- <div class="content">
- <div class="title" v-if="information.indexOf('毛重') > -1">毛重</div>
- <div class="title" v-else>皮重</div>
- <div class="number" v-if="information.indexOf('毛重') > -1">{{grossWeightVal}} kg</div>
- <div class="number" v-else>{{tareVal}} KG</div>
-
- <div class="btn" @click="sendVal">确定</div>
- </div>
- </template>
- <script>
- export default {
- name: 'balanceAlert',
- props: ['deptBudgetList', 'information'],
- data () {
- return {
- param: 9600,
- grossWeightVal:'',
- tareVal:''
- }
- },
- activated(){
-
- },
- mounted(){
- console.log('11111111111111111111111111111111111')
- console.log(this.deptBudgetList)
- this.openPort()
- },
- computed: {
-
- },
- created () {
-
- },
- methods: {
- sendVal(){
- console.log(this.grossWeightVal)
- console.log(this.tareVal)
- if(this.information.indexOf('毛重') > -1){
- this.$emit('balanceListen',this.grossWeightVal)
- }else{
- this.$emit('balanceListen',this.tareVal)
- }
-
- },
- async closePort() {
- console.log('closePort')
- this.reader.cancel()
- },
- async openPort() {
- console.log('openPort', navigator)
- if ('serial' in navigator) {
- if (!this.$store.state.app.reader) {
- // 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()
- console.log('beforeReader', port)
- console.log('beforeReader', this.reader)
- this.$store.dispatch('app/setReader', this.reader)
- } else {
- console.log('afterport', this.$store.state.app.reader)
- this.reader = this.$store.state.app.reader
- }
- // 监听来自串行设备的数据
- 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
- var flag1 = 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.information != '毛重检斤') {
- // if(parseInt(result)){
- // this.deptBudgetList.grossWeight = parseInt(result)
- // }
- // } else {
- // if(parseInt(result)){
- // this.deptBudgetList.tare = parseInt(result)
- // }
- // }
- console.log('value:', value)
- if (
- this.deptBudgetList.warehouseName &&
- (this.deptBudgetList.warehouseName == '山东诸城迈饶库' ||
- this.deptBudgetList.warehouseName == '克东千红库' ||
- this.deptBudgetList.warehouseName == '鲅鱼圈祥腾库' ||
- this.deptBudgetList.warehouseName == '哈尔滨依兰库'||
- this.deptBudgetList.warehouseName == '龙江金信库')
- ) {
- 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.information.indexOf('毛重') > -1) {
- if (parseInt(result) || parseInt(result) == 0) {
- this.grossWeightVal = parseInt(result)
- }
- } else {
- if (parseInt(result) || parseInt(result) == 0) {
- this.tareVal = parseInt(result)
- }
- }
- } else if (
- this.deptBudgetList.warehouseName &&
- (this.deptBudgetList.warehouseName == '顺诚粮库' ||
- this.deptBudgetList.warehouseName == '鲅鱼圈金信库')
- ) {
- for (var i = value.length - 1; i >= 0; i--) {
- var tmp = String.fromCharCode(value[i])
- console.log(tmp)
- if (String.fromCharCode(value[0]) == '.') {
- flag = true
- }
- if (flag && result.length < 9 && tmp != '=' && tmp != '.') {
- result += tmp
- }
- }
- if (this.information.indexOf('毛重') > -1) {
- if (parseInt(result) || parseInt(result) == 0) {
- this.grossWeightVal = parseInt(result)
- }
- } else {
- if (parseInt(result) || parseInt(result) == 0) {
- this.tareVal = parseInt(result)
- }
- }
- } else {
- for (var i = 0; i < value.length; i++) {
- var tmp = String.fromCharCode(value[i])
- if (value[0] != 49 && value[0] != 2) {
- if (
- value[value.length - 1] == 48 &&
- value[value.length - 2] == 48
- ) {
- flag1 = true
- } else {
- break
- }
- }
- if (tmp == String.fromCharCode(32)) {
- flag = true
- }
- if (
- flag &&
- result.length < 7 &&
- tmp != String.fromCharCode(32) &&
- !(
- value[value.length - 1] == 48 && value[value.length - 2] == 48
- )
- ) {
- result += tmp
- }
- if (flag1 && tmp != String.fromCharCode(32)) {
- if (
- value[value.length - 1] == 48 &&
- value[value.length - 2] == 48
- ) {
- if (i == 0) {
- this.result1 = tmp + '0'
- }
- }
- }
- }
- if (this.information.indexOf('毛重') > -1) {
- if (parseInt(result) || parseInt(result) == 0) {
- this.grossWeightVal = parseInt(
- result + this.result1
- )
- }
- } else {
- if (parseInt(result) || parseInt(result) == 0) {
- this.tareVal = parseInt(result + this.result1)
- }
- }
- }
- // setTimeout(1000)
- // value 是一个 Uint8Array
- }
- await port.close()
- } else {
- console.log('the Web Serial API is not supported.', navigator)
- }
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- .content{
- background: black;
- color: #2AFF7C;
- font-size: 32px;
- text-align: right;
- padding: 20px;
- border-radius: 10px;
- margin: 0 20px 20px 20px;
- }
- .title{
- text-align: center;
- }
- .number{
- // font-size: 60px;
- }
- .btn{
- border: 1px solid #2aff7c;
- width: 50%;
- // margin: 30px auto;
- border-radius: 10px;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- </style>
|