index.vue
3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<template>
<div>
<a-form-model
ref="ruleForm"
:model="form"
:rules="rules"
:label-col="labelCol"
:wrapper-col="wrapperCol"
>
<a-form-model-item label="文档标题" prop="docTitle">
<a-input v-model="form.docTitle" />
</a-form-model-item>
<a-form-model-item label="文档地址" prop="docUrl">
<a-input v-model="form.docUrl" />
</a-form-model-item>
<a-form-model-item label="文档描述" prop="docDescription">
<a-input v-model="form.docDescription" type="textarea" />
</a-form-model-item>
<a-form-model-item :wrapper-col="{ span: 14, offset: 4 }">
<a-button type="primary" @click="onSubmit"
>{{ isNewAdd ? "创建" : "提交" }}
</a-button>
<a-button style="margin-left: 10px" @click="resetForm"> 重置 </a-button>
<a-button style="margin-left: 10px" @click="closeForm"> 关闭 </a-button>
</a-form-model-item>
</a-form-model>
</div>
</template>
<script type="text/ecmascript-6">
export default {
name: "",
data() {
return {
isNewAdd: true,
labelCol: { span: 4 },
wrapperCol: { span: 14 },
form: {
docTitle: "",
docUrl: "",
docDescription: "",
},
rules: {
docTitle: [
{ required: true, message: "请输入文档名称", trigger: "blur" },
{ min: 1, max: 30, message: "请输入字符1~50之间", trigger: "blur" },
],
docUrl: [
{ required: true, message: "请输入文档地址", trigger: "blur" },
],
docDescription: [
{ required: true, message: "请输入文档描述", trigger: "blur" },
],
},
};
},
mounted() {
this.editeItemFn();
},
methods: {
onSubmit() {
this.$refs.ruleForm.validate((valid) => {
if (valid) {
if (this.isNewAdd) {
//新增
this.api.documentation.create(this.form).then((res) => {
// console.log(res);
if (res.id) {
this.$message.success("添加成功");
this.closeForm();
this.resetForm();
} else {
this.$message.error("添加失败");
}
});
} else {
//编辑
this.api.documentation.update(this.form).then((res) => {
console.log(res);
if (res.id) {
this.$message.success("编辑成功");
this.closeForm();
this.resetForm();
} else {
this.$message.error("编辑失败");
}
});
}
} else {
return false;
}
});
},
resetForm() {
this.isNewAdd = true;
this.$refs.ruleForm.resetFields();
},
closeForm() {
this.to(-1);
},
//编辑项目
editeItemFn() {
const editeItem = this.$route.params;
console.log('editeItem: ', editeItem);
if (Object.keys(editeItem).length === 0) return;
this.isNewAdd = false;
this.form = {
docTitle: editeItem.doc_title,
docUrl: editeItem.doc_url,
docDescription: editeItem.doc_description,
id: editeItem.id,
};
},
},
// 重置
beforeDestroy() {
this.resetForm();
},
};
</script>
<style scoped lang="scss"></style>