Compare commits
2 Commits
1277accf5c
...
83a3bd193b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83a3bd193b | ||
|
|
abce5b18fd |
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-row justify="left">
|
<el-row justify="left" gutter="10">
|
||||||
<el-col>
|
<el-col>
|
||||||
<el-form :rules="rules" ref="form" :model="form" label-position="left">
|
<el-form :rules="rules" ref="form" :model="form" label-position="left">
|
||||||
<el-form-item label="名字" prop="name">
|
<el-form-item label="名字" prop="name">
|
||||||
@ -54,6 +54,7 @@
|
|||||||
<el-input type="textarea" v-model="form.note"></el-input>
|
<el-input type="textarea" v-model="form.note"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
|
<el-col :span="12" v-if="recipe_id">
|
||||||
<el-button
|
<el-button
|
||||||
type="primary"
|
type="primary"
|
||||||
plain
|
plain
|
||||||
@ -61,6 +62,25 @@
|
|||||||
@click="onSubmit(recipe_id)"
|
@click="onSubmit(recipe_id)"
|
||||||
>提交</el-button
|
>提交</el-button
|
||||||
>
|
>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="24" v-else>
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
plain
|
||||||
|
class="summit-recipe"
|
||||||
|
@click="onSubmit(recipe_id)"
|
||||||
|
>提交</el-button
|
||||||
|
>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="12" v-if="recipe_id">
|
||||||
|
<el-button
|
||||||
|
type="danger"
|
||||||
|
plain
|
||||||
|
class="summit-recipe"
|
||||||
|
@click="onSubmitDelete(recipe_id)"
|
||||||
|
>删除</el-button
|
||||||
|
>
|
||||||
|
</el-col>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
</el-col>
|
</el-col>
|
||||||
@ -69,6 +89,8 @@
|
|||||||
<script>
|
<script>
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import config from '@/config/index';
|
import config from '@/config/index';
|
||||||
|
import { ElMessage } from 'element-plus';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: ['recipe_'],
|
props: ['recipe_'],
|
||||||
watch: {
|
watch: {
|
||||||
@ -105,6 +127,10 @@ export default {
|
|||||||
axios
|
axios
|
||||||
.post(config.publicPath + '/recipe/recipe/', data)
|
.post(config.publicPath + '/recipe/recipe/', data)
|
||||||
.then(function () {
|
.then(function () {
|
||||||
|
ElMessage({
|
||||||
|
message: '创建成功.',
|
||||||
|
type: 'success',
|
||||||
|
});
|
||||||
location.reload();
|
location.reload();
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
@ -114,13 +140,27 @@ export default {
|
|||||||
axios
|
axios
|
||||||
.put(config.publicPath + '/recipe/recipe/' + recipe_id, data)
|
.put(config.publicPath + '/recipe/recipe/' + recipe_id, data)
|
||||||
.then(function () {
|
.then(function () {
|
||||||
location.reload();
|
ElMessage({
|
||||||
|
message: '修改成功.',
|
||||||
|
type: 'success',
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onSubmitDelete(recipe_id) {
|
||||||
|
axios
|
||||||
|
.delete(config.publicPath + '/recipe/recipe/' + recipe_id)
|
||||||
|
.then(function () {
|
||||||
|
ElMessage.error('删除成功.');
|
||||||
|
location.reload();
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@ -128,5 +168,6 @@ export default {
|
|||||||
<style scoped>
|
<style scoped>
|
||||||
.summit-recipe {
|
.summit-recipe {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -43,10 +43,12 @@
|
|||||||
/>
|
/>
|
||||||
</van-cell-group>
|
</van-cell-group>
|
||||||
<div class="recipe-create">
|
<div class="recipe-create">
|
||||||
|
<van-row gutter="20">
|
||||||
|
<van-col span="12" v-if="recipe_id">
|
||||||
<van-button
|
<van-button
|
||||||
|
class="submit-button"
|
||||||
round
|
round
|
||||||
type="primary"
|
type="primary"
|
||||||
block
|
|
||||||
plain
|
plain
|
||||||
hairline
|
hairline
|
||||||
:disabled="disable_submit"
|
:disabled="disable_submit"
|
||||||
@ -54,6 +56,34 @@
|
|||||||
:loading="loading"
|
:loading="loading"
|
||||||
>提交</van-button
|
>提交</van-button
|
||||||
>
|
>
|
||||||
|
</van-col>
|
||||||
|
<van-col span="24" v-else>
|
||||||
|
<van-button
|
||||||
|
class="submit-button"
|
||||||
|
round
|
||||||
|
type="primary"
|
||||||
|
plain
|
||||||
|
hairline
|
||||||
|
:disabled="disable_submit"
|
||||||
|
@click="onSubmit(recipe_id)"
|
||||||
|
:loading="loading"
|
||||||
|
>提交</van-button
|
||||||
|
>
|
||||||
|
</van-col>
|
||||||
|
<van-col span="12" v-if="recipe_id">
|
||||||
|
<van-button
|
||||||
|
class="submit-button"
|
||||||
|
round
|
||||||
|
type="danger"
|
||||||
|
plain
|
||||||
|
hairline
|
||||||
|
:disabled="disable_submit"
|
||||||
|
@click="onSubmitDelete(recipe_id)"
|
||||||
|
:loading="loading"
|
||||||
|
>删除</van-button
|
||||||
|
>
|
||||||
|
</van-col>
|
||||||
|
</van-row>
|
||||||
</div>
|
</div>
|
||||||
</van-form>
|
</van-form>
|
||||||
</template>
|
</template>
|
||||||
@ -68,6 +98,8 @@ import {
|
|||||||
Rate,
|
Rate,
|
||||||
Button,
|
Button,
|
||||||
Toast,
|
Toast,
|
||||||
|
Col,
|
||||||
|
Row,
|
||||||
} from 'vant';
|
} from 'vant';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import config from '@/config/index';
|
import config from '@/config/index';
|
||||||
@ -90,6 +122,8 @@ export default {
|
|||||||
[RadioGroup.name]: RadioGroup,
|
[RadioGroup.name]: RadioGroup,
|
||||||
[Rate.name]: Rate,
|
[Rate.name]: Rate,
|
||||||
[Button.name]: Button,
|
[Button.name]: Button,
|
||||||
|
[Col.name]: Col,
|
||||||
|
[Row.name]: Row,
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@ -137,6 +171,20 @@ export default {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onSubmitDelete(recipe_id) {
|
||||||
|
if (!this.form.name) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.loading = true;
|
||||||
|
axios.delete(config.publicPath + '/recipe/recipe/' + recipe_id).then(
|
||||||
|
(Toast.success({
|
||||||
|
message: '删除成功',
|
||||||
|
forbidClick: true,
|
||||||
|
duration: 500,
|
||||||
|
}),
|
||||||
|
(this.loading = false))
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@ -144,4 +192,7 @@ export default {
|
|||||||
.recipe-create {
|
.recipe-create {
|
||||||
margin: 20px 16px;
|
margin: 20px 16px;
|
||||||
}
|
}
|
||||||
|
.submit-button {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
18
recipe/migrations/0003_recipe_status.py
Normal file
18
recipe/migrations/0003_recipe_status.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.2.6 on 2022-02-04 16:13
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('recipe', '0002_auto_20211002_1926'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='recipe',
|
||||||
|
name='status',
|
||||||
|
field=models.CharField(default='active', max_length=32),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -9,6 +9,7 @@ import utils
|
|||||||
class Recipe(models.Model):
|
class Recipe(models.Model):
|
||||||
name = models.CharField(max_length=128)
|
name = models.CharField(max_length=128)
|
||||||
recipe_type = models.CharField(max_length=32, default=const.RECIPE_TYPE_MEAT)
|
recipe_type = models.CharField(max_length=32, default=const.RECIPE_TYPE_MEAT)
|
||||||
|
status = models.CharField(max_length=32, default=const.RECIPE_STATUS_ACTIVE)
|
||||||
note = models.TextField(null=True)
|
note = models.TextField(null=True)
|
||||||
rate = models.IntegerField(default=0)
|
rate = models.IntegerField(default=0)
|
||||||
difficulty = models.IntegerField(default=0)
|
difficulty = models.IntegerField(default=0)
|
||||||
@ -125,7 +126,12 @@ class DailyRecipe(models.Model):
|
|||||||
# meat
|
# meat
|
||||||
for x in range(0, 2):
|
for x in range(0, 2):
|
||||||
while True:
|
while True:
|
||||||
recipe = Recipe.objects.filter(recipe_type=const.RECIPE_TYPE_MEAT).order_by('?').first()
|
recipe = (
|
||||||
|
Recipe.objects.filter(recipe_type=const.RECIPE_TYPE_MEAT)
|
||||||
|
.exclude(status=const.RECIPE_STATUS_DELETED)
|
||||||
|
.order_by('?')
|
||||||
|
.first()
|
||||||
|
)
|
||||||
if recipe and recipe.id not in recipes and recipe.id not in prev_recipes:
|
if recipe and recipe.id not in recipes and recipe.id not in prev_recipes:
|
||||||
recipes.append(recipe.id)
|
recipes.append(recipe.id)
|
||||||
break
|
break
|
||||||
@ -138,7 +144,12 @@ class DailyRecipe(models.Model):
|
|||||||
# vegetable
|
# vegetable
|
||||||
for x in range(0, 1):
|
for x in range(0, 1):
|
||||||
while True:
|
while True:
|
||||||
recipe = Recipe.objects.filter(recipe_type=const.RECIPE_TYPE_VEGETABLE).order_by('?').first()
|
recipe = (
|
||||||
|
Recipe.objects.filter(recipe_type=const.RECIPE_TYPE_VEGETABLE)
|
||||||
|
.exclude(status=const.RECIPE_STATUS_DELETED)
|
||||||
|
.order_by('?')
|
||||||
|
.first()
|
||||||
|
)
|
||||||
if recipe and recipe.id not in recipes and recipe.id not in prev_recipes:
|
if recipe and recipe.id not in recipes and recipe.id not in prev_recipes:
|
||||||
recipes.append(recipe.id)
|
recipes.append(recipe.id)
|
||||||
break
|
break
|
||||||
@ -150,7 +161,12 @@ class DailyRecipe(models.Model):
|
|||||||
|
|
||||||
# soup
|
# soup
|
||||||
if random.randint(0, 2):
|
if random.randint(0, 2):
|
||||||
recipe = Recipe.objects.filter(recipe_type=const.RECIPE_TYPE_SOUP).order_by('?').first()
|
recipe = (
|
||||||
|
Recipe.objects.filter(recipe_type=const.RECIPE_TYPE_SOUP)
|
||||||
|
.exclude(status=const.RECIPE_STATUS_DELETED)
|
||||||
|
.order_by('?')
|
||||||
|
.first()
|
||||||
|
)
|
||||||
# if recipe not in recipes and recipe not in prev_recipes:
|
# if recipe not in recipes and recipe not in prev_recipes:
|
||||||
if recipe:
|
if recipe:
|
||||||
recipes.append(recipe.id)
|
recipes.append(recipe.id)
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import recipe.serializers
|
|||||||
from utils import const
|
from utils import const
|
||||||
|
|
||||||
|
|
||||||
class RecipeAPI(rest_framework.generics.RetrieveUpdateAPIView):
|
class RecipeAPI(rest_framework.generics.RetrieveUpdateDestroyAPIView):
|
||||||
|
|
||||||
# authentication_classes = (authentication.TokenAuthentication,
|
# authentication_classes = (authentication.TokenAuthentication,
|
||||||
# authentication.SessionAuthentication,
|
# authentication.SessionAuthentication,
|
||||||
@ -21,6 +21,10 @@ class RecipeAPI(rest_framework.generics.RetrieveUpdateAPIView):
|
|||||||
queryset = recipe.models.Recipe.objects.all()
|
queryset = recipe.models.Recipe.objects.all()
|
||||||
serializer_class = recipe.serializers.RecipeSerializer
|
serializer_class = recipe.serializers.RecipeSerializer
|
||||||
|
|
||||||
|
def perform_destroy(self, instance):
|
||||||
|
instance.status = const.RECIPE_STATUS_DELETED
|
||||||
|
instance.save(update_fields=['status'])
|
||||||
|
|
||||||
|
|
||||||
class RecipeListAPI(rest_framework.generics.ListAPIView, rest_framework.generics.CreateAPIView):
|
class RecipeListAPI(rest_framework.generics.ListAPIView, rest_framework.generics.CreateAPIView):
|
||||||
|
|
||||||
@ -28,7 +32,7 @@ class RecipeListAPI(rest_framework.generics.ListAPIView, rest_framework.generics
|
|||||||
# authentication.SessionAuthentication,
|
# authentication.SessionAuthentication,
|
||||||
# authentication.BasicAuthentication)
|
# authentication.BasicAuthentication)
|
||||||
# permission_classes = (permissions.IsAuthenticated,)
|
# permission_classes = (permissions.IsAuthenticated,)
|
||||||
queryset = recipe.models.Recipe.objects.all()
|
queryset = recipe.models.Recipe.objects.exclude(status=const.RECIPE_STATUS_DELETED)
|
||||||
serializer_class = recipe.serializers.RecipeSerializer
|
serializer_class = recipe.serializers.RecipeSerializer
|
||||||
filterset_fields = {
|
filterset_fields = {
|
||||||
'recipe_type': const.FILTER_EXACT,
|
'recipe_type': const.FILTER_EXACT,
|
||||||
|
|||||||
@ -11,6 +11,9 @@ RECIPE_TYPE_MEAT = 'meat'
|
|||||||
RECIPE_TYPE_VEGETABLE = 'vegetable'
|
RECIPE_TYPE_VEGETABLE = 'vegetable'
|
||||||
RECIPE_TYPE_SOUP = 'soup'
|
RECIPE_TYPE_SOUP = 'soup'
|
||||||
|
|
||||||
|
RECIPE_STATUS_ACTIVE = 'active'
|
||||||
|
RECIPE_STATUS_DELETED = 'deleted'
|
||||||
|
|
||||||
RECIPE_TYPE_CHOICE = [RECIPE_TYPE_MEAT, RECIPE_TYPE_VEGETABLE, RECIPE_TYPE_SOUP]
|
RECIPE_TYPE_CHOICE = [RECIPE_TYPE_MEAT, RECIPE_TYPE_VEGETABLE, RECIPE_TYPE_SOUP]
|
||||||
|
|
||||||
FILTER_EXACT = ['exact']
|
FILTER_EXACT = ['exact']
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user