Prechádzať zdrojové kódy

实现食物分享二维码

wangyang 5 rokov pred
rodič
commit
55c2a8e255
5 zmenil súbory, kde vykonal 38 pridanie a 4 odobranie
  1. 3 0
      .env.development
  2. 3 0
      .env.production
  3. 3 0
      .env.test
  4. 3 2
      package.json
  5. 26 2
      src/views/food/index.vue

+ 3 - 0
.env.development

@@ -4,3 +4,6 @@ PORT = '9531'
 
 # base api
 VUE_APP_BASE_API = '//localhost:8084'
+
+# h5 url
+VUE_APP_H5_URL = 'http://localhost/static-web/pages/feuc-test'

+ 3 - 0
.env.production

@@ -4,3 +4,6 @@ PORT = '9531'
 
 # base api
 VUE_APP_BASE_API = '//feuc.liveplus.online'
+
+# h5 url
+VUE_APP_H5_URL = 'https://h5.liveplus.online/static-web/feuc'

+ 3 - 0
.env.test

@@ -4,3 +4,6 @@ PORT = '9532'
 
 # base api
 VUE_APP_BASE_API = '//feuc-test.liveplus.online'
+
+# h5 url
+VUE_APP_H5_URL = 'http://h5.liveplus.online/static-web/feuc-test'

+ 3 - 2
package.json

@@ -23,10 +23,11 @@
     "normalize.css": "7.0.0",
     "nprogress": "0.2.0",
     "path-to-regexp": "2.4.0",
+    "sortablejs": "1.12.0",
     "vue": "2.6.10",
+    "vue-qr": "^2.3.0",
     "vue-router": "3.0.6",
-    "vuex": "3.1.0",
-    "sortablejs": "1.12.0"
+    "vuex": "3.1.0"
   },
   "devDependencies": {
     "@vue/cli-plugin-babel": "4.4.4",

+ 26 - 2
src/views/food/index.vue

@@ -45,6 +45,7 @@
       fit
       highlight-current-row
       style="width: 100%;"
+      @row-click="handleFoodClick"
     >
       <el-table-column type="index" label="序号" align="center" fixed width="60px" />
       <el-table-column label="名称" align="center" fixed width="200px">
@@ -178,6 +179,19 @@
         </el-button>
       </div>
     </el-dialog>
+
+    <el-dialog title="食物二维码" width="250" :visible.sync="foodQRDialogVisible">
+      <vue-qr
+        :text="foodQRParams.url"
+        :bgSrc="foodQRParams.bgImg"
+        :logoSrc="foodQRParams.logoImg"
+        :size="200"
+        :correctLevel="3"
+        colorDark="#000"
+        colorLight="#fff"
+        :dotScale="1"
+      ></vue-qr>
+    </el-dialog>
   </div>
 </template>
 
@@ -188,12 +202,13 @@ import axios from 'axios'
 import { getToken } from '@/utils/auth'
 import { getFoodSourceByUrl } from '@/utils/food-utils'
 import store from '@/store'
+import VueQr from 'vue-qr'
 
 const foodTypes = { 0: '主材', 1: '辅材' }
 
 export default {
   name: 'FoodList',
-  components: { Pagination },
+  components: { Pagination, VueQr },
   filters: {
     foodTypeFilter(value) {
       return foodTypes[value]
@@ -218,7 +233,9 @@ export default {
       uploadLoading: false,
       copyDialogVisible: false,
       params: {},
-      foodSource: ''
+      foodSource: '',
+      foodQRDialogVisible: false,
+      foodQRParams: {}
     }
   },
   created() {
@@ -326,6 +343,13 @@ export default {
     },
     canDelete(data) {
       return store.getters.isAdmin || data && data.userId === store.getters.userId
+    },
+    handleFoodClick(row) {
+      this.foodQRParams = { url: process.env.VUE_APP_H5_URL + `/food/index.html?id=${row.id}`,
+        bgImg: row.mainImage ? row.mainImage : '',
+        logoImg: row.mainImage ? row.mainImage : ''
+      }
+      this.foodQRDialogVisible = true
     }
   }
 }