Forráskód Böngészése

完成usda数据相关前端调整

wangyang 4 éve
szülő
commit
6898fcb63b
3 módosított fájl, 31 hozzáadás és 3 törlés
  1. 6 0
      src/router/config.js
  2. 6 0
      src/utils/food-utils.js
  3. 19 3
      src/views/food/index.vue

+ 6 - 0
src/router/config.js

@@ -65,6 +65,12 @@ export const asyncRouterMap = [
         component: () => import('@/views/food/index'),
         meta: { title: 'CFCT', admin: true  }
       },
+      {
+        path: 'usda',
+        name: 'USDA',
+        component: () => import('@/views/food/index'),
+        meta: { title: 'USDA', admin: true  }
+      },
       {
         path: 'create',
         name: '食物创建',

+ 6 - 0
src/utils/food-utils.js

@@ -24,7 +24,13 @@ export function getFoodSourceByUrl(url='') {
     return 'ENTRY'
   } else if (url.indexOf('cfct') > -1) {
     return 'CFCT'
+  } else if (url.indexOf('usda')) {
+    return 'USDA'
   } else {
     return ''
   }
 }
+
+export function isUsda(dataSource) {
+  return dataSource && dataSource.indexOf('USDA') > -1
+}

+ 19 - 3
src/views/food/index.vue

@@ -5,10 +5,13 @@
         <el-input
           v-model="listQuery.query"
           placeholder="请输入检索词"
-          style="width: 60%;"
+          style="width: 40%;"
           class="filter-item"
           @keyup.enter.native="fetchData()"
         />
+        <el-select v-model="usdaType" v-if="isUsda" clearable style="width: 160px;margin-left: 10px;" class="filter-item">
+          <el-option v-for="item in usdaTypes" :key="item.value" :label="item.label" :value="item.value" />
+        </el-select>
         <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-search" @click="fetchData">
           检索
         </el-button>
@@ -200,7 +203,7 @@ import Pagination from '@/components/Pagination'
 import { getList, remove, copyFromSimilarFood } from '@/api/food'
 import axios from 'axios'
 import { getToken } from '@/utils/auth'
-import { getFoodSourceByUrl } from '@/utils/food-utils'
+import { getFoodSourceByUrl, isUsda } from '@/utils/food-utils'
 import store from '@/store'
 import VueQr from 'vue-qr'
 
@@ -235,7 +238,12 @@ export default {
       params: {},
       foodSource: '',
       foodQRDialogVisible: false,
-      foodQRParams: {}
+      foodQRParams: {},
+      isUsda: false,
+      usdaTypes: [{ 'label': '全部', 'value': 'ALL' }, { 'label': 'Foundation', 'value': 'USDA_FOUNDATION' },
+                  { 'label': 'Legacy', 'value': 'USDA_SR_LEGACY' }, { 'label': 'Branded', 'value': 'USDA_BRANDED' },
+                  { 'label': 'FNDDS', 'value': 'USDA_FNDDS' }],
+      usdaType: ''
     }
   },
   created() {
@@ -245,12 +253,20 @@ export default {
     } else {
       this.listQuery.orderBy = 1
     }
+    this.isUsda = isUsda(this.foodSource)
     this.fetchData()
   },
   methods: {
     fetchData() {
       this.listLoading = true
       this.listQuery.foodSource = this.foodSource
+      if (this.foodSource === 'USDA') {
+        if (!this.usdaType || this.usdaType === 'ALL'){
+          this.listQuery.foodSource = 'USDA'
+        } else {
+          this.listQuery.foodSource = this.usdaType
+        }
+      }
       getList(this.listQuery).then(response => {
         this.list = response.data.list
         this.total = response.data.count