Browse Source

增加二维码查看

lilei 4 years ago
parent
commit
e1e60773e8
2 changed files with 144 additions and 50 deletions
  1. 143 49
      src/views/equipmentManage/electronicScale/electronicScale.vue
  2. 1 1
      vue.config.js

+ 143 - 49
src/views/equipmentManage/electronicScale/electronicScale.vue

@@ -5,8 +5,8 @@
       <a-form-model :model="searchForm" layout="inline" ref="searchForm" @keyup.enter.native="$refs.table.refresh(true)">
         <a-row :gutter="24">
           <a-col :xs="24" :sm="12" :md="8" :lg="6">
-            <a-form-model-item label="设备MAC码" :label-col="{span:7}" :wrapper-col="{span:17}">
-              <a-input v-model="searchForm.macAddress" placeholder="请输入设备MAC码" :maxLength="12" allowClear/>
+            <a-form-model-item label="设备MAC码" :label-col="{ span: 7 }" :wrapper-col="{ span: 17 }">
+              <a-input v-model="searchForm.macAddress" placeholder="请输入设备MAC码" :maxLength="12" allowClear />
             </a-form-model-item>
           </a-col>
           <a-col :xs="24" :sm="12" :md="8" :lg="6">
@@ -17,22 +17,37 @@
       </a-form-model>
     </div>
     <!-- 新增 -->
-    <div class="electronicScale-container-add">
-      <a-button type="primary" icon="plus" @click="openModal">新增</a-button>
-    </div>
+    <div class="electronicScale-container-add"><a-button type="primary" icon="plus" @click="openModal">新增</a-button></div>
     <!-- 合计 -->
     <a-alert type="info" showIcon style="margin-bottom:15px">
-      <div class="ftext" slot="message">总计<span> {{ totalNum }} 个</span></div>
+      <div class="ftext" slot="message">
+        总计
+        <span>{{ totalNum }} 个</span>
+      </div>
     </a-alert>
     <!-- 列表 -->
-    <s-table ref="table" :rowKey="(record) => record.id" :columns="columns" :data="loadData" bordered>
-      <span slot="action" slot-scope="text,record">
-        <a-icon type="edit" title="编辑" class="actionBtn icon-blues" @click="handleEdit(record)"/>
-        <a-icon type="delete" title="删除" class="actionBtn icon-red" @click="delect(record)"/>
+    <s-table ref="table" :rowKey="record => record.id" :columns="columns" :data="loadData" bordered>
+      <span slot="action" slot-scope="text, record">
+        <a-icon type="qrcode" title="二维码" class="actionBtn icon-green" @click="getQrCode(record)" />
+        <a-icon type="edit" title="编辑" class="actionBtn icon-blues" @click="handleEdit(record)" />
+        <a-icon type="delete" title="删除" class="actionBtn icon-red" @click="delect(record)" />
       </span>
     </s-table>
     <!-- 新增/编辑弹窗 -->
-    <addElectronicScale :visible="isOpenModal" :id="itemId" :deviceCode="itemDeviceCode" @refresh="refreshTable" @close="isOpenModal=false"></addElectronicScale>
+    <addElectronicScale :visible="isOpenModal" :id="itemId" :deviceCode="itemDeviceCode" @refresh="refreshTable" @close="isOpenModal = false"></addElectronicScale>
+    <!-- 查看小程序码 -->
+    <a-modal
+      class="qrCodeModal"
+      title="查看MAC地址二维码"
+      :width="400"
+      :footer="null"
+      :shName="shName"
+      :destroyOnClose="true"
+      @cancel="isQrCodeModal = false"
+      v-model="isQrCodeModal">
+      <img :src="qrCode" width="300" height="300" class="qrCode" />
+      <a-button type="primary" class="downQrCode" @click="downloadCode">下载二维码</a-button>
+    </a-modal>
   </a-card>
 </template>
 
@@ -40,6 +55,7 @@
 import { STable } from '@/components'
 import addElectronicScale from './addElectronicScale.vue'
 import { getDeviceList, delectDevice } from '@/api/electronicScale.js'
+import QRCode from 'qrcode'
 export default {
   components: { STable, addElectronicScale },
   data () {
@@ -50,42 +66,108 @@ export default {
       isOpenModal: false, // 默认弹窗关闭
       itemDeviceCode: '', // 编辑行设备编号
       itemId: '',
-	  totalNum: '',
+      totalNum: '',
+      isQrCodeModal: false,
+      shName: '',
+      qrCode: '',
       // 列表表头
-      columns: [{ title: '序号', dataIndex: 'no', width: 60, align: 'center' },
+      columns: [
+        { title: '序号', dataIndex: 'no', width: 60, align: 'center' },
         { title: '创建时间', dataIndex: 'createDate', width: 100, align: 'center' },
         { title: '设备MAC码', dataIndex: 'macAddress', width: 100, align: 'center' },
-        { title: '设备名称', dataIndex: 'deviceName', width: 100, align: 'center', customRender: (text) => { return text || '--' } },
-        { title: '设备编号', dataIndex: 'deviceCode', width: 100, align: 'center', customRender: (text) => { return text || '--' } },
-        { title: '设备型号', dataIndex: 'deviceModel', width: 100, align: 'center', customRender: (text) => { return text || '--' } },
-        { title: '生产厂家', dataIndex: 'manufacturer', width: 100, align: 'center', customRender: (text) => { return text || '--' } },
+        {
+          title: '设备名称',
+          dataIndex: 'deviceName',
+          width: 100,
+          align: 'center',
+          customRender: text => {
+            return text || '--'
+          }
+        },
+        {
+          title: '设备编号',
+          dataIndex: 'deviceCode',
+          width: 100,
+          align: 'center',
+          customRender: text => {
+            return text || '--'
+          }
+        },
+        {
+          title: '设备型号',
+          dataIndex: 'deviceModel',
+          width: 100,
+          align: 'center',
+          customRender: text => {
+            return text || '--'
+          }
+        },
+        {
+          title: '生产厂家',
+          dataIndex: 'manufacturer',
+          width: 100,
+          align: 'center',
+          customRender: text => {
+            return text || '--'
+          }
+        },
         { title: '操作', dataIndex: 'action', width: 100, align: 'center', scopedSlots: { customRender: 'action' } }
       ],
-	  // 加载数据方法 必须为 Promise 对象
-	  loadData: parameter => {
-	    return getDeviceList(Object.assign(parameter, this.searchForm, { deviceType: 'STEELYARD' })).then(res => {
-	      if (res.status == 200) {
-	        const no = (res.data.pageNo - 1) * res.data.pageSize
-	        for (let i = 0; i < res.data.list.length; i++) {
-	          const _item = res.data.list[i]
-	          _item.no = no + i + 1
-	        }
+      // 加载数据方法 必须为 Promise 对象
+      loadData: parameter => {
+        return getDeviceList(Object.assign(parameter, this.searchForm, { deviceType: 'STEELYARD' })).then(res => {
+          if (res.status == 200) {
+            const no = (res.data.pageNo - 1) * res.data.pageSize
+            for (let i = 0; i < res.data.list.length; i++) {
+              const _item = res.data.list[i]
+              _item.no = no + i + 1
+            }
             this.totalNum = res.data.count
-	        return res.data
-	      } else {
+            return res.data
+          } else {
             this.totalNum = 0
-		  }
-	    })
-	  }
+          }
+        })
+      }
     }
   },
   methods: {
+    //  下载二维码
+    downloadCode (item) {
+      const link = document.createElement('a')
+      link.href = this.qrCode
+      link.download = this.shName + '.png'
+      link.click()
+    },
+    // 查看二维码
+    getQrCode (item) {
+      const _this = this
+      const opts = {
+        errorCorrectionLevel: 'H',
+        type: 'image/jpeg',
+        quality: 0.3,
+        margin: 1.5,
+        width: 240,
+        color: {
+          dark: '#000000',
+          light: '#ffffff'
+        }
+      }
+      const url = item.macAddress
+      _this.shName = item.deviceName
+      if (url) {
+        QRCode.toDataURL(url, opts, function (err, url) {
+          _this.qrCode = url
+          _this.isQrCodeModal = true
+        })
+      }
+    },
     // 重置
     handleReset () {
       this.searchForm = {
         macAddress: ''
       }
-	  this.$refs.table.refresh(true)
+      this.$refs.table.refresh(true)
     },
     // 新增
     openModal () {
@@ -135,24 +217,36 @@ export default {
 </script>
 
 <style lang="less" scoped>
-	.electronicScale-container {
-		.electronicScale-container-searchForm {
-			.ant-form-inline .ant-form-item {
-				width: 100%;
-			}
-		}
+.electronicScale-container {
+  .electronicScale-container-searchForm {
+    .ant-form-inline .ant-form-item {
+      width: 100%;
+    }
+  }
 
-		// 查询按钮
-		.handle-btn {
-			margin-top: 4px;
-		}
+  // 查询按钮
+  .handle-btn {
+    margin-top: 4px;
+  }
 
-		.serach-btn {
-			margin-right: 10px;
-		}
+  .serach-btn {
+    margin-right: 10px;
+  }
 
-		.electronicScale-container-add {
-			margin: 15px 0;
-		}
-	}
+  .electronicScale-container-add {
+    margin: 15px 0;
+  }
+}
+ // 查看小程序码  弹框
+  .qrCodeModal {
+    .qrCode {
+      display: block;
+      max-width: 100%;
+      margin: 0 auto;
+    }
+    .downQrCode {
+      display: block;
+      margin: 30px auto;
+    }
+  }
 </style>

+ 1 - 1
vue.config.js

@@ -108,7 +108,7 @@ const vueConfig = {
     // If you want to turn on the proxy, please remove the mockjs /src/main.jsL11
     proxy: {
       '/api': {
-        target: 'http://192.168.16.134:8301/gc-admin/',
+        target: 'http://192.168.16.105:8301/gc-admin/',
         // target: 'https://lese.test.sxzxyj.net/gc-admin/',
         ws: false,
         changeOrigin: true,