Compare commits
No commits in common. "83a3bd193bc71efba4beaebf55015eed917ceaaa" and "1277accf5c1f49b9fb9502fbcda1450b96189659" have entirely different histories.
83a3bd193b
...
1277accf5c
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-row justify="left" gutter="10">
|
<el-row justify="left">
|
||||||
<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,33 +54,13 @@
|
|||||||
<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
|
class="summit-recipe"
|
||||||
class="summit-recipe"
|
@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>
|
||||||
@ -89,8 +69,6 @@
|
|||||||
<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: {
|
||||||
@ -99,7 +77,7 @@ export default {
|
|||||||
this.recipe_id = val.id;
|
this.recipe_id = val.id;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data: function () {
|
data: function() {
|
||||||
return {
|
return {
|
||||||
form: {
|
form: {
|
||||||
name: null,
|
name: null,
|
||||||
@ -126,41 +104,23 @@ export default {
|
|||||||
if (!recipe_id) {
|
if (!recipe_id) {
|
||||||
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) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
axios
|
axios
|
||||||
.put(config.publicPath + '/recipe/recipe/' + recipe_id, data)
|
.put(config.publicPath + '/recipe/recipe/' + recipe_id, data)
|
||||||
.then(function () {
|
.then(function() {
|
||||||
ElMessage({
|
location.reload();
|
||||||
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>
|
||||||
@ -168,6 +128,5 @@ export default {
|
|||||||
<style scoped>
|
<style scoped>
|
||||||
.summit-recipe {
|
.summit-recipe {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -43,47 +43,17 @@
|
|||||||
/>
|
/>
|
||||||
</van-cell-group>
|
</van-cell-group>
|
||||||
<div class="recipe-create">
|
<div class="recipe-create">
|
||||||
<van-row gutter="20">
|
<van-button
|
||||||
<van-col span="12" v-if="recipe_id">
|
round
|
||||||
<van-button
|
type="primary"
|
||||||
class="submit-button"
|
block
|
||||||
round
|
plain
|
||||||
type="primary"
|
hairline
|
||||||
plain
|
:disabled="disable_submit"
|
||||||
hairline
|
@click="onSubmit(recipe_id)"
|
||||||
:disabled="disable_submit"
|
:loading="loading"
|
||||||
@click="onSubmit(recipe_id)"
|
>提交</van-button
|
||||||
:loading="loading"
|
>
|
||||||
>提交</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>
|
||||||
@ -98,8 +68,6 @@ 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';
|
||||||
@ -122,8 +90,6 @@ 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 {
|
||||||
@ -171,20 +137,6 @@ 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>
|
||||||
@ -192,7 +144,4 @@ export default {
|
|||||||
.recipe-create {
|
.recipe-create {
|
||||||
margin: 20px 16px;
|
margin: 20px 16px;
|
||||||
}
|
}
|
||||||
.submit-button {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -1,18 +0,0 @@
|
|||||||
# 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,7 +9,6 @@ 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)
|
||||||
@ -126,12 +125,7 @@ class DailyRecipe(models.Model):
|
|||||||
# meat
|
# meat
|
||||||
for x in range(0, 2):
|
for x in range(0, 2):
|
||||||
while True:
|
while True:
|
||||||
recipe = (
|
recipe = Recipe.objects.filter(recipe_type=const.RECIPE_TYPE_MEAT).order_by('?').first()
|
||||||
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
|
||||||
@ -144,12 +138,7 @@ class DailyRecipe(models.Model):
|
|||||||
# vegetable
|
# vegetable
|
||||||
for x in range(0, 1):
|
for x in range(0, 1):
|
||||||
while True:
|
while True:
|
||||||
recipe = (
|
recipe = Recipe.objects.filter(recipe_type=const.RECIPE_TYPE_VEGETABLE).order_by('?').first()
|
||||||
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
|
||||||
@ -161,12 +150,7 @@ class DailyRecipe(models.Model):
|
|||||||
|
|
||||||
# soup
|
# soup
|
||||||
if random.randint(0, 2):
|
if random.randint(0, 2):
|
||||||
recipe = (
|
recipe = Recipe.objects.filter(recipe_type=const.RECIPE_TYPE_SOUP).order_by('?').first()
|
||||||
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.RetrieveUpdateDestroyAPIView):
|
class RecipeAPI(rest_framework.generics.RetrieveUpdateAPIView):
|
||||||
|
|
||||||
# authentication_classes = (authentication.TokenAuthentication,
|
# authentication_classes = (authentication.TokenAuthentication,
|
||||||
# authentication.SessionAuthentication,
|
# authentication.SessionAuthentication,
|
||||||
@ -21,10 +21,6 @@ class RecipeAPI(rest_framework.generics.RetrieveUpdateDestroyAPIView):
|
|||||||
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):
|
||||||
|
|
||||||
@ -32,7 +28,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.exclude(status=const.RECIPE_STATUS_DELETED)
|
queryset = recipe.models.Recipe.objects.all()
|
||||||
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,9 +11,6 @@ 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