Browse Source

食物菜单栏按来源分子菜单

wangyang 5 năm trước cách đây
mục cha
commit
b5e059a335

+ 16 - 2
src/router/config.js

@@ -44,12 +44,26 @@ export const asyncRouterMap = [
   {
     path: '/food',
     component: Layout,
+    name: '食物列表',
+    meta: { title: '食物列表', icon: 'food' },
     children: [
       {
         path: '',
-        name: '食物列表',
+        name: '全部',
         component: () => import('@/views/food/index'),
-        meta: { title: '食物列表', icon: 'food' }
+        meta: { title: '全部' }
+      },
+      {
+        path: 'entry',
+        name: '录入',
+        component: () => import('@/views/food/index'),
+        meta: { title: '录入' }
+      },
+      {
+        path: 'cfct',
+        name: 'CFCT',
+        component: () => import('@/views/food/index'),
+        meta: { title: 'CFCT' }
       },
       {
         path: 'create',

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

@@ -0,0 +1,30 @@
+
+/**
+ * 计算食物来源对应的path
+ * @param {string} dataSource
+ * @returns {String}
+ */
+export function getFoodUrl(dataSource='') {
+  if (dataSource.indexOf('ENTRY') > -1) {
+    return '/food/entry'
+  } else if (dataSource.indexOf('CFCT') > -1) {
+    return '/food/cfct'
+  } else {
+    return '/food'
+  }
+}
+
+/**
+ * 根据url判断食物来源
+ * @param url
+ * @returns {string}
+ */
+export function getFoodSourceByUrl(url='') {
+  if (url.indexOf('entry') > -1){
+    return 'ENTRY'
+  } else if (url.indexOf('cfct') > -1) {
+    return 'CFCT'
+  } else {
+    return ''
+  }
+}

+ 2 - 1
src/views/food/components/FoodDetail.vue

@@ -119,6 +119,7 @@ import SingleImage from '@/components/Upload/SingleImage'
 import FloatingWindow from '@/components/FloatingWindow'
 import { getNutrientTemplates } from '@/api/nutrientTemplate'
 import { getFoodCategories } from '@/api/foodCategory'
+import { getFoodUrl } from '@/utils/food-utils'
 
 export default {
   name: "FoodDetail",
@@ -286,7 +287,7 @@ export default {
       } else if (value === 'modifier') {
         path = `/food/${this.foodId}/modifier`
       } else if (value === 'list') {
-        path = `/food`
+        path = '/food'
       }
       if (path) {
         this.$router.push({ path: path })

+ 5 - 1
src/views/food/index.vue

@@ -181,6 +181,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'
 
 const foodTypes = { 0: '主材', 1: '辅材' }
 
@@ -210,15 +211,18 @@ export default {
       uploadFile: null,
       uploadLoading: false,
       copyDialogVisible: false,
-      params: {}
+      params: {},
+      foodSource: ''
     }
   },
   created() {
+    this.foodSource = getFoodSourceByUrl(this.$route.path)
     this.fetchData()
   },
   methods: {
     fetchData() {
       this.listLoading = true
+      this.listQuery.foodSource = this.foodSource
       getList(this.listQuery).then(response => {
         this.list = response.data.list
         this.total = response.data.count