Parcourir la source

完成录入员权限控制

wangyang il y a 5 ans
Parent
commit
93cc285565

+ 7 - 7
src/router/config.js

@@ -23,7 +23,7 @@ export const asyncRouterMap = [
         path: '',
         name: '菜谱列表',
         component: () => import('@/views/recipe/index'),
-        meta: { title: '菜谱列表', icon: 'recipe' }
+        meta: { title: '菜谱列表', icon: 'recipe', admin: true }
       },
       {
         path: ':id/food',
@@ -51,7 +51,7 @@ export const asyncRouterMap = [
         path: '',
         name: '全部',
         component: () => import('@/views/food/index'),
-        meta: { title: '全部' }
+        meta: { title: '全部', admin: true  }
       },
       {
         path: 'entry',
@@ -63,7 +63,7 @@ export const asyncRouterMap = [
         path: 'cfct',
         name: 'CFCT',
         component: () => import('@/views/food/index'),
-        meta: { title: 'CFCT' }
+        meta: { title: 'CFCT', admin: true  }
       },
       {
         path: 'create',
@@ -125,7 +125,7 @@ export const asyncRouterMap = [
         path: '',
         name: '营养素列表',
         component: () => import('@/views/nutrient/index'),
-        meta: { title: '营养素列表', icon: 'nutrient' }
+        meta: { title: '营养素列表', icon: 'nutrient', admin: true  }
       }
     ]
   },
@@ -138,7 +138,7 @@ export const asyncRouterMap = [
         path: '',
         name: '单位列表',
         component: () => import('@/views/unit/index'),
-        meta: { title: '单位列表', icon: 'unit' }
+        meta: { title: '单位列表', icon: 'unit', admin: true  }
       }
     ]
   },
@@ -152,7 +152,7 @@ export const asyncRouterMap = [
         path: '',
         name: '用户列表',
         component: () => import('@/views/user/index'),
-        meta: { title: '用户列表', icon: 'user' }
+        meta: { title: '用户列表', icon: 'user', admin: true  }
       }
     ]
   },
@@ -185,7 +185,7 @@ export const asyncRouterMap = [
         path: '',
         name: '食物种类管理',
         component: () => import('@/views/foodCategory/index'),
-        meta: { title: '食物种类管理', icon: 'category' }
+        meta: { title: '食物种类管理', icon: 'category', admin: true  }
       }
     ]
   },

+ 10 - 5
src/views/food/components/FoodDetail.vue

@@ -8,11 +8,12 @@
           <el-dropdown-item command="nutrient">营养素关联</el-dropdown-item>
           <el-dropdown-item command="unit">单位管理</el-dropdown-item>
           <el-dropdown-item command="modifier">规格管理</el-dropdown-item>
+          <el-dropdown-item command="list">食物列表</el-dropdown-item>
         </el-dropdown-menu>
       </el-dropdown>
     </floating-window>
 
-    <el-form ref="postForm" :model="postForm" :rules="rules" label-position="right" label-width="90px" class="form-container">
+    <el-form :disabled="!canEdit" ref="postForm" :model="postForm" :rules="rules" label-position="right" label-width="90px" class="form-container">
       <div class="createPost-main-container">
         <el-form-item label="自定义ID:" style="margin-bottom: 40px;width: 60%" prop="id2">
           <el-input v-model="postForm.id2" placeholder="请输入自定义ID" />
@@ -119,7 +120,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'
+import store from '@/store'
 
 export default {
   name: "FoodDetail",
@@ -149,7 +150,8 @@ export default {
       importLoading: false,
       importType: 0,
       importId: '',
-      importItems: []
+      importItems: [],
+      canEdit: true
     }
   },
   mounted() {
@@ -171,6 +173,9 @@ export default {
     fetchData(id) {
       getDetail(id).then(res => {
         this.postForm = res.data
+        if (!store.getters.isAdmin && this.postForm.userId !== store.getters.userId){
+          this.canEdit = false
+        }
       })
     },
     fetchCategories() {
@@ -186,7 +191,7 @@ export default {
           resultPromise.then((res) => {
             this.$notify.success('提交成功')
             this.loading = false
-            const nextPath = this.isEdit ? '/food' : `/food/${res.data}/nutrient`
+            const nextPath = this.isEdit ? '/food/entry' : `/food/${res.data}/nutrient`
             this.$router.push({ path: nextPath })
           }).catch(res => {
             this.$message.error(res.data.message)
@@ -287,7 +292,7 @@ export default {
       } else if (value === 'modifier') {
         path = `/food/${this.foodId}/modifier`
       } else if (value === 'list') {
-        path = '/food'
+        path = store.getters.isAdmin ? '/food' : '/food/entry'
       }
       if (path) {
         this.$router.push({ path: path })

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

@@ -97,6 +97,11 @@
           <span>{{ row.dataSource }}</span>
         </template>
       </el-table-column>
+      <el-table-column label="创建人" align="center" width="100px">
+        <template slot-scope="{row}">
+          <span>{{ row.userName }}</span>
+        </template>
+      </el-table-column>
       <el-table-column label="创建时间" width="180px" align="center">
         <template slot-scope="{row}">
           <span>{{ row.createTime }}</span>
@@ -114,12 +119,12 @@
               操作<i class="el-icon-arrow-down el-icon--right"></i>
             </el-button>
             <el-dropdown-menu slot="dropdown">
-              <el-dropdown-item :command="{row: row, command: 'update'}">更新</el-dropdown-item>
+              <el-dropdown-item :command="{row: row, command: 'update'}">更新/查看</el-dropdown-item>
               <el-dropdown-item :command="{row: row, command: 'copy'}">复制</el-dropdown-item>
               <el-dropdown-item :command="{row: row, command: 'manageNutrients'}">营养素关联</el-dropdown-item>
               <el-dropdown-item :command="{row: row, command: 'manageUnits'}">单位管理</el-dropdown-item>
               <el-dropdown-item :command="{row: row, command: 'manageModifiers'}">规格管理</el-dropdown-item>
-              <el-dropdown-item :command="{row: row, command: 'delete'}">删除</el-dropdown-item>
+              <el-dropdown-item :disabled="!canDelete(row)" :command="{row: row, command: 'delete'}">删除</el-dropdown-item>
             </el-dropdown-menu>
           </el-dropdown>
         </template>
@@ -182,6 +187,7 @@ import { getList, remove, copyFromSimilarFood } from '@/api/food'
 import axios from 'axios'
 import { getToken } from '@/utils/auth'
 import { getFoodSourceByUrl } from '@/utils/food-utils'
+import store from '@/store'
 
 const foodTypes = { 0: '主材', 1: '辅材' }
 
@@ -317,6 +323,9 @@ export default {
           this.handleDelete(data.row)
           break
       }
+    },
+    canDelete(data) {
+      return store.getters.isAdmin || data && data.userId === store.getters.userId
     }
   }
 }

+ 19 - 7
src/views/food/nutrient.vue

@@ -104,6 +104,7 @@
           class="filter-item"
           style="margin-left: 10px;"
           type="primary"
+          :disabled="!canEdit"
           @click="addNutrient">
           添加
         </el-button>
@@ -111,6 +112,7 @@
           class="filter-item"
           style="margin-left: 10px;"
           type="success"
+          :disabled="!canEdit"
           @click="handleImport">
           导入营养素
         </el-button>
@@ -246,10 +248,10 @@
             </el-button>
           </template>
           <template v-else>
-            <el-button size="mini" type="primary" @click="handleEdit(row)">编辑</el-button>
-            <el-button size="mini" type="primary" @click="updateSort(row, 0)">上移</el-button>
-            <el-button size="mini" type="primary" @click="updateSort(row, 1)">下移</el-button>
-            <el-button size="mini" type="danger" @click="confirmRemoveNutrient(row)">
+            <el-button size="mini" type="primary" :disabled="!canEdit" @click="handleEdit(row)">编辑</el-button>
+            <el-button size="mini" type="primary" :disabled="!canEdit" @click="updateSort(row, 0)">上移</el-button>
+            <el-button size="mini" type="primary" :disabled="!canEdit" @click="updateSort(row, 1)">下移</el-button>
+            <el-button size="mini" type="danger" :disabled="!canEdit" @click="confirmRemoveNutrient(row)">
               删除
             </el-button>
           </template>
@@ -292,11 +294,12 @@
 <script>
 import { getNutrientList, addFoodNutrient, updateFoodNutrient, removeFoodNutrient,
   updateFoodNutrientSort, confirmDeleteFoodNutrient, importNutrientsFromTemplate,
-  getList as getFoodList, importNutrientFromSimilarFood } from '@/api/food'
+  getList as getFoodList, importNutrientFromSimilarFood, getDetail } from '@/api/food'
 import FloatingWindow from '@/components/FloatingWindow'
 import { getList, getNutrientUnits, getNutrientSources } from '@/api/nutrient'
 import { getList as getUnits } from '@/api/unit'
 import { getNutrientTemplates } from '@/api/nutrientTemplate'
+import store from '@/store'
 
 // 特殊营养素 若单位不为baseUnit,则需要填写来源
 const SPECIAL_NUTRIENT_NAMES = ['维生素A', '维生素D', '维生素E', '烟酸', '叶酸']
@@ -353,7 +356,8 @@ export default {
       showNutrientSource: false,
       showRowNutrientSource: false,
       nutrientSources: [],
-      showNRV: false
+      showNRV: false,
+      canEdit: true
     }
   },
   methods: {
@@ -370,6 +374,11 @@ export default {
           this.$set(this.params, 'nvSpecUnit', '克')
         }
       })
+      getDetail(this.foodId).then(res => {
+        if (!store.getters.isAdmin && res.data.userId !== store.getters.userId) {
+          this.canEdit = false
+        }
+      })
     },
     addNutrient() {
       this.params.foodId = this.foodId
@@ -456,6 +465,9 @@ export default {
       };
     },
     handleEdit(row) {
+      if (!this.canEdit) {
+        return
+      }
       this.$set(row, 'edit', true)
       if (row.quantityMax || row.quantityMin) {
         this.$set(row, 'radio', 1)
@@ -560,7 +572,7 @@ export default {
       } else if (value === 'modifier') {
         path = `/food/${this.foodId}/modifier`
       } else if (value === 'list') {
-        path = `/food`
+        path = store.getters.isAdmin ? '/food' : '/food/entry'
       }
       if (path) {
         this.$router.push({ path: path })

+ 13 - 5
src/views/food/unit.vue

@@ -35,6 +35,7 @@
         class="filter-item"
         style="margin-left: 10px;"
         type="primary"
+        :disabled="!canEdit"
         @click="addFoodUnit"
       >
         添加
@@ -78,7 +79,7 @@
           >
             提交
           </el-button>
-          <el-button v-else size="mini" type="primary" @click="row.edit=true">编辑</el-button>
+          <el-button v-else size="mini" type="primary" :disabled="!canEdit" @click="row.edit=true">编辑</el-button>
           <el-button
             v-if="row.edit"
             type="danger"
@@ -87,7 +88,7 @@
           >
             取消
           </el-button>
-          <el-button v-else size="mini" type="danger" @click="removeFoodUnit(row)">
+          <el-button v-else size="mini" type="danger" :disabled="!canEdit" @click="removeFoodUnit(row)">
             删除
           </el-button>
         </template>
@@ -98,8 +99,9 @@
 
 <script>
 import { getBaseUnits, getList } from '@/api/unit'
-import { getFoodUnits, createOrUpdateFoodUnit, removeFoodUnit } from '@/api/food'
+import { getFoodUnits, createOrUpdateFoodUnit, removeFoodUnit, getDetail } from '@/api/food'
 import FloatingWindow from '@/components/FloatingWindow'
+import store from '@/store'
 
 export default {
   name: 'FoodUnit',
@@ -111,7 +113,8 @@ export default {
       listLoading: false,
       list: [],
       isFixed: false,
-      offsetTop: 0
+      offsetTop: 0,
+      canEdit: true
     }
   },
   mounted() {
@@ -136,6 +139,11 @@ export default {
       getFoodUnits(this.foodId).then(res => {
         this.list = res.data.list
       })
+      getDetail(this.foodId).then(res => {
+        if (!store.getters.isAdmin && res.data.userId !== store.getters.userId) {
+          this.canEdit = false
+        }
+      })
     },
     addFoodUnit() {
       this.params.foodId = this.foodId
@@ -191,7 +199,7 @@ export default {
       } else if (value === 'modifier') {
         path = `/food/${this.foodId}/modifier`
       } else if (value === 'list') {
-        path = `/food`
+        path = store.getters.isAdmin ? '/food' : '/food/entry'
       }
       if (path) {
         this.$router.push({ path: path })

+ 2 - 1
src/views/foodModifier/components/ModifierDetail.vue

@@ -101,6 +101,7 @@ import Dropzone from '@/components/Dropzone'
 import FloatingWindow from '@/components/FloatingWindow'
 import { addFoodModifier, updateFoodModifier, getFoodModifier } from '@/api/food'
 import { getList as getUnits } from '@/api/unit'
+import store from '@/store'
 
 export default {
   name: "ModifierDetail",
@@ -231,7 +232,7 @@ export default {
       } else if (value === 'modifier') {
         path = `/food/${this.foodId}/modifier`
       } else if (value === 'list') {
-        path = `/food`
+        path = store.getters.isAdmin ? '/food' : '/food/entry'
       }
       if (path) {
         this.$router.push({ path: path })

+ 16 - 9
src/views/foodModifier/index.vue

@@ -7,6 +7,7 @@
         style="margin: 0 10px 20px 0; float: left;"
         type="success"
         icon="el-icon-circle-plus-outline"
+        :disabled="!canEdit"
         @click="handleCreate"
       >
         新建
@@ -16,6 +17,7 @@
         style="margin: 0 10px 20px 0; float: left;"
         type="success"
         icon="el-icon-circle-plus-outline"
+        :disabled="!canEdit"
         @click="importDialogVisible = true"
       >
         从近似食物导入
@@ -113,16 +115,16 @@
       </el-table-column>
       <el-table-column label="操作" align="center" class-name="small-padding" fixed="right" width="320">
         <template slot-scope="{row}">
-          <el-button type="primary" size="mini" @click.stop="handleUpdate(row)">
-            更新
+          <el-button type="primary" size="mini" :disabled="!canEdit" @click.stop="handleUpdate(row)">
+            更新/查看
           </el-button>
-          <el-button type="primary" size="mini" @click.stop="updateSort(row, 0)">
+          <el-button type="primary" size="mini" :disabled="!canEdit"  @click.stop="updateSort(row, 0)">
             上移
           </el-button>
-          <el-button type="primary" size="mini" @click.stop="updateSort(row, 1)">
+          <el-button type="primary" size="mini" :disabled="!canEdit"  @click.stop="updateSort(row, 1)">
             下移
           </el-button>
-          <el-button size="mini" type="danger" @click.stop="handleDelete(row)">
+          <el-button size="mini" type="danger" :disabled="!canEdit"  @click.stop="handleDelete(row)">
             删除
           </el-button>
         </template>
@@ -140,10 +142,11 @@
 </template>
 
 <script>
-import { getFoodModifiers, removeFoodModifier, updateFoodModifierSort, convertFoodUnit, getNutrientList,
-  getDetail, calculateNutrientsContent } from '@/api/food'
+import { getFoodModifiers, removeFoodModifier, updateFoodModifierSort, getDetail,
+  calculateNutrientsContent } from '@/api/food'
 import FloatingWindow from '@/components/FloatingWindow'
 import ModifierImport from './components/ModifierImport'
+import store from '@/store'
 
 const STATUS_MAP = { 0: '下架', 1: '上架' }
 
@@ -165,7 +168,8 @@ export default {
       dialogFormVisible: false,
       isFixed: false,
       offsetTop: 0,
-      importDialogVisible: false
+      importDialogVisible: false,
+      canEdit: true
     }
   },
   mounted() {
@@ -199,6 +203,9 @@ export default {
     fetchFood() {
       getDetail(this.foodId).then(res => {
         this.food = res.data
+        if (!store.getters.isAdmin && this.food.userId !== store.getters.userId) {
+          this.canEdit = false
+        }
       })
     },
     fetchData() {
@@ -244,7 +251,7 @@ export default {
       } else if (value === 'modifier') {
         path = `/food/${this.foodId}/modifier`
       } else if (value === 'list') {
-        path = `/food`
+        path = store.getters.isAdmin ? '/food' : '/food/entry'
       }
       if (path) {
         this.$router.push({ path: path })

+ 16 - 4
src/views/nutrientTemplate/detail.vue

@@ -62,6 +62,7 @@
           class="filter-item"
           style="margin-left: 10px;"
           type="primary"
+          :disabled="!canEdit"
           @click="addNutrient"
         >
           添加
@@ -170,8 +171,8 @@
               </el-button>
             </template>
             <template v-else>
-              <el-button size="mini" type="primary" @click="handleEdit(row)">编辑</el-button>
-              <el-button size="mini" type="danger" @click="removeNutrient(row)">
+              <el-button size="mini" type="primary" :disabled="!canEdit" @click="handleEdit(row)">编辑</el-button>
+              <el-button size="mini" type="danger" :disabled="!canEdit" @click="removeNutrient(row)">
                 删除
               </el-button>
             </template>
@@ -186,8 +187,9 @@
 import { getList, getNutrientUnits, getNutrientSources } from '@/api/nutrient'
 import { getList as getUnits } from '@/api/unit'
 import { getNutrients, addTemplateNutrient, updateTemplateNutrient, removeNutrient,
-  updateTemplateNutrientSort, updateBatchDetailSorts } from '@/api/nutrientTemplate'
+  updateTemplateNutrientSort, updateBatchDetailSorts, getNutrientTemplate } from '@/api/nutrientTemplate'
 import Sortable from 'sortablejs'
+import store from '@/store'
 
 // 特殊营养素 若单位不为baseUnit,则需要填写来源
 const SPECIAL_NUTRIENT_NAMES = ['维生素A', '维生素D', '维生素E', '烟酸', '叶酸']
@@ -210,7 +212,8 @@ export default {
       sortable: null,
       showNutrientSource: false,
       showRowNutrientSource: false,
-      nutrientSources: []
+      nutrientSources: [],
+      canEdit: true
     }
   },
   created() {
@@ -221,11 +224,20 @@ export default {
     }
     this.fetchNutrients()
     this.queryNutrients()
+    this.fetchData()
     this.$nextTick(() => {
       this.setSort()
     })
   },
   methods: {
+    fetchData() {
+      getNutrientTemplate(this.templateId).then(res => {
+        if (!store.getters.isAdmin && res.data.userId !== store.getters.userId) {
+          this.canEdit = false
+          this.sortable.option('disabled', true)
+        }
+      })
+    },
     addNutrient() {
       if (this.params.nutrientId) {
         addTemplateNutrient(this.templateId, this.params).then(res => {

+ 3 - 3
src/views/nutrientTemplate/index.vue

@@ -64,8 +64,8 @@
               操作<i class="el-icon-arrow-down el-icon--right"></i>
             </el-button>
             <el-dropdown-menu slot="dropdown">
-              <el-dropdown-item :disabled="!canUpdate(row.userId)" :command="{row: row, command: 'update'}">更新</el-dropdown-item>
-              <el-dropdown-item :disabled="!canUpdate(row.userId)" :command="{row: row, command: 'manage'}">管理营养素</el-dropdown-item>
+              <el-dropdown-item :command="{row: row, command: 'update'}">更新/查看</el-dropdown-item>
+              <el-dropdown-item :command="{row: row, command: 'manage'}">管理营养素</el-dropdown-item>
               <el-dropdown-item :disabled="!canUpdate(row.userId)" :command="{row: row, command: 'moveUp'}">上移</el-dropdown-item>
               <el-dropdown-item :disabled="!canUpdate(row.userId)" :command="{row: row, command: 'moveDown'}">下移</el-dropdown-item>
               <el-dropdown-item :disabled="!canUpdate(row.userId)" :command="{row: row, command: 'moveTop'}">置顶</el-dropdown-item>
@@ -98,7 +98,7 @@
         <el-button @click="dialogFormVisible = false">
           取消
         </el-button>
-        <el-button type="primary" @click="createOrUpdateData">
+        <el-button type="primary" :disabled="dialogStatus === 'update' && !canUpdate(params.userId)" @click="createOrUpdateData">
           提交
         </el-button>
       </div>