index.vue
5.12 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<template>
<div>
<a-form-model
ref="ruleForm"
:model="form"
:rules="rules"
:label-col="labelCol"
:wrapper-col="wrapperCol"
>
<a-form-model-item label="项目名称" prop="project_title">
<a-input v-model="form.project_title" />
</a-form-model-item>
<a-form-model-item label="开发者名称" prop="developer_name">
<a-input v-model="form.developer_name" />
</a-form-model-item>
<a-form-model-item label="配置名称" prop="config_name">
<a-input v-model="form.config_name" />
</a-form-model-item>
<a-form-model-item label="测试环境地址" prop="test_url">
<a-input v-model="form.test_url" />
</a-form-model-item>
<a-form-model-item label="生产环境地址" prop="product_url">
<a-input v-model="form.product_url" />
</a-form-model-item>
<a-form-model-item label="相关技术栈" prop="technology">
<a-input v-model="form.technology" />
</a-form-model-item>
<a-form-model-item label="git地址" prop="git_url">
<a-input v-model="form.git_url" />
</a-form-model-item>
<a-form-model-item label="git项目ID" prop="git_id">
<a-input v-model="form.git_id" />
</a-form-model-item>
<a-form-model-item label="请输入项目描述" prop="project_description">
<a-input v-model="form.project_description" 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>
export default {
name: "",
data() {
return {
isNewAdd: true,
labelCol: { span: 4 },
wrapperCol: { span: 14 },
form: {
project_title: "",
project_description: "",
developer_name: "",
config_name: "",
test_url: "",
product_url: "",
technology: "",
git_url: "",
git_id: "",
},
rules: {
project_title: [
{ required: true, message: "请输入项目名称", trigger: "blur" },
{ min: 1, max: 30, message: "请输入字符1~50之间", trigger: "blur" },
],
project_description: [
{ required: true, message: "请输入项目描述", trigger: "blur" },
],
developer_name: [
{ required: true, message: "请输入开发者名称", trigger: "blur" },
],
config_name: [
{ required: true, message: "请输入配置名称", trigger: "blur" },
],
test_url: [
{ required: true, message: "请输入测试环境地址", trigger: "blur" },
],
product_url: [
{ required: true, message: "请输入生产环境地址", trigger: "blur" },
],
technology: [
{ required: true, message: "请输入相关技术栈", trigger: "blur" },
],
git_url: [
{ required: true, message: "请输入gitlab地址", trigger: "blur" },
],
git_id: [
{ required: true, message: "请输入项目gitlab id", trigger: "blur" },
],
},
};
},
mounted() {
this.editeItemFn();
},
methods: {
onSubmit() {
this.$refs.ruleForm.validate((valid) => {
if (valid) {
if (this.isNewAdd) {
//新增
this.api.project.create(this.form).then((res) => {
// console.log('res: ', res);
if (res.id) {
this.$message.success("添加成功");
this.closeForm();
this.resetData();
} else {
this.$message.error("添加失败");
}
});
} else {
//编辑
this.api.project.update(this.form).then((res) => {
// console.log("res: ", res);
if (res.id) {
this.$message.success("编辑成功");
this.closeForm();
this.resetData();
} else {
this.$message.error("编辑失败");
}
});
}
} else {
return false;
}
});
},
resetForm() {
this.isNewAdd = true;
this.$refs.ruleForm.resetFields();
// this.resetData();
},
resetData() {
this.form = {
project_title: "",
project_description: "",
developer_name: "",
config_name: "",
test_url: "",
product_url: "",
technology: "",
};
},
closeForm() {
this.to(-1);
},
//编辑项目
editeItemFn() {
const editeItem = this.$route.params;
if (Object.keys(editeItem).length === 0) return;
this.isNewAdd = false;
this.form = {
...editeItem,
};
},
},
// 重置
beforeDestroy() {
this.resetForm();
},
};
</script>
<style scoped lang="scss"></style>