feat(recipe detail page): 菜谱编辑页增加删除按钮
菜谱编辑页增加删除按钮 Signed-off-by: Ching <loooching@gmail.com>
This commit is contained in:
parent
abce5b18fd
commit
83a3bd193b
@ -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,7 +18,7 @@ class RecipeAPI(rest_framework.generics.RetrieveUpdateDestroyAPIView):
|
|||||||
# 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
|
||||||
|
|
||||||
def perform_destroy(self, instance):
|
def perform_destroy(self, instance):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user