|
|
@@ -1,5 +1,19 @@
|
|
|
<template>
|
|
|
- <div class="createPost-container">
|
|
|
+ <div class="createPost-container" style="position: relative">
|
|
|
+
|
|
|
+ <floating-window :class="{'is_fixed': isFixed}" >
|
|
|
+ <el-dropdown @command="handleCommand">
|
|
|
+ <img width="50px" height="50px" src="@/assets/navigation.png" alt="导航.png" />
|
|
|
+ <el-dropdown-menu slot="dropdown">
|
|
|
+ <el-dropdown-item command="detail">食物更新</el-dropdown-item>
|
|
|
+ <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="130px" class="form-container">
|
|
|
<div class="createPost-main-container">
|
|
|
<el-checkbox @change="checkboxChange" :disabled="isEdit" v-model="isDefaultModifier" style="margin: 0 0 10px 100px">默认规格</el-checkbox>
|
|
|
@@ -72,6 +86,7 @@
|
|
|
|
|
|
<script>
|
|
|
import Dropzone from '@/components/Dropzone'
|
|
|
+import FloatingWindow from '@/components/FloatingWindow'
|
|
|
import { addFoodModifier, updateFoodModifier, getFoodModifier } from '@/api/food'
|
|
|
import { getList as getUnits } from '@/api/unit'
|
|
|
|
|
|
@@ -83,7 +98,7 @@ export default {
|
|
|
default: false
|
|
|
}
|
|
|
},
|
|
|
- components: { Dropzone },
|
|
|
+ components: { Dropzone, FloatingWindow },
|
|
|
data() {
|
|
|
return {
|
|
|
defaultModifierName: '-',
|
|
|
@@ -92,9 +107,18 @@ export default {
|
|
|
loading: false,
|
|
|
foodId: '',
|
|
|
modifierId: '',
|
|
|
- isDefaultModifier: false
|
|
|
+ isDefaultModifier: false,
|
|
|
+ isFixed: false,
|
|
|
+ offsetTop: 0
|
|
|
}
|
|
|
},
|
|
|
+ mounted() {
|
|
|
+ window.addEventListener('scroll', this.initHeight);
|
|
|
+ },
|
|
|
+ //回调中移除监听
|
|
|
+ destroyed() {
|
|
|
+ window.removeEventListener('scroll', this.handleScroll)
|
|
|
+ },
|
|
|
created() {
|
|
|
this.foodId = this.$route.params && this.$route.params.id
|
|
|
if (this.isEdit) {
|
|
|
@@ -169,6 +193,29 @@ export default {
|
|
|
checkboxChange(value) {
|
|
|
const name = value ? this.defaultModifierName : ''
|
|
|
this.$set(this.postForm, 'name', name)
|
|
|
+ },
|
|
|
+ initHeight() {
|
|
|
+ // 设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离 (被卷曲的高度)
|
|
|
+ const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
|
|
|
+ //如果被卷曲的高度大于吸顶元素到顶端位置 的距离
|
|
|
+ this.isFixed = scrollTop > this.offsetTop;
|
|
|
+ },
|
|
|
+ handleCommand(value) {
|
|
|
+ let path = ''
|
|
|
+ if (value === 'detail') {
|
|
|
+ path = `/food/edit/${this.foodId}`
|
|
|
+ } else if (value === 'unit') {
|
|
|
+ path = `/food/${this.foodId}/unit`
|
|
|
+ } else if (value === 'nutrient') {
|
|
|
+ path = `/food/${this.foodId}/nutrient`
|
|
|
+ } else if (value === 'modifier') {
|
|
|
+ path = `/food/${this.foodId}/modifier`
|
|
|
+ } else if (value === 'list') {
|
|
|
+ path = `/food`
|
|
|
+ }
|
|
|
+ if (path) {
|
|
|
+ this.$router.push({ path: path })
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|