Sfoglia il codice sorgente

管理后台-订座管理:座位模板,二维码下载

panyong 3 anni fa
parent
commit
e689d73fc7
1 ha cambiato i file con 36 aggiunte e 11 eliminazioni
  1. 36 11
      htmldev/manage/src/views/business/place/list/index.vue

+ 36 - 11
htmldev/manage/src/views/business/place/list/index.vue

@@ -43,14 +43,9 @@
           <el-button type="text"
                      @click="edit(scope.row)">编辑
           </el-button>
-          <!--todo 图片单张下载还是ZIP包-->
-          <el-dropdown class="el-dropdown"
-                       @command="handleCommand">
-            <span class="el-dropdown-link">下载二维码<i class="el-icon-arrow-down el-icon--right"></i></span>
-            <el-dropdown-menu slot="dropdown">
-              <el-dropdown-item command="111">黄金糕</el-dropdown-item>
-            </el-dropdown-menu>
-          </el-dropdown>
+          <el-button type="text"
+                     @click="download(scope.row)">下载点单二维码
+          </el-button>
           <el-button type="text"
                      @click="del(scope.row)">删除
           </el-button>
@@ -78,6 +73,7 @@
 <script>
 import page from '@/mixin/page'
 import detail from './details'
+import axios from 'axios'
 
 export default {
   mixins: [page],
@@ -105,9 +101,6 @@ export default {
       this.detailsDialog.exData = row
       this.detailsDialog.show = true
     },
-    handleCommand (val) {
-      console.log(val)
-    },
     del (row) {
       this.$confirm('确定要删除吗', '确认', {
         confirmButtonText: '确定',
@@ -120,6 +113,38 @@ export default {
           this.init()
         }
       }).catch(() => {})
+    },
+    download (row) {
+      axios({
+        method: 'GET',
+        url: '/v1/bar/place/template/download',
+        params: {
+          id: row.id
+        },
+        responseType: 'blob',
+        headers: { 'Content-Type': 'application/json; application/octet-stream' }
+      }).then(response => {
+        if (response.data.type === 'application/octet-stream') {
+          /* 兼容ie内核,360浏览器的兼容模式 */
+          if (window.navigator && window.navigator.msSaveOrOpenBlob) {
+            const blob = new Blob([response.data], { type: 'application/zip' })
+            window.navigator.msSaveOrOpenBlob(blob)
+          } else {
+            /* 火狐谷歌的文件下载方式 */
+            const blob = new Blob([response.data], { type: 'application/zip' })
+            const url = window.URL.createObjectURL(blob)
+            const aTag = document.createElement('a')
+            aTag.href = url
+            aTag.download = ''
+            aTag.click()
+            URL.revokeObjectURL(url) // 释放内存
+          }
+        } else {
+          this.$message.error('下载出错,请联系管理员')
+        }
+      }).catch(error => {
+        this.$message.error(JSON.stringify(error))
+      })
     }
   },
   mounted () {