dialog.vue
5.58 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<template>
<el-dialog
class="entryDialog classCUploadDialog"
:title="title"
:visible.sync="outerVisible"
:show-close="false"
width="30%"
:close-on-click-modal="false"
v-loading="loadings.dialogLoading"
@close="close(false)"
>
<div class="modelItem">
<el-form
class="fedexFormStyle"
ref="formData"
:model="formData"
:rules="type == 'roleChange' ? {} : rules"
label-position="top"
:disabled="type == 'roleChange'"
size="small"
>
<el-row :gutter="5">
<!-- 用户ID -->
<el-col :span="24">
<Formitem label="用户ID" prop="userId" type="edit">
<el-input
type="text"
class="inputShadow"
id="inputInner-edit-userId"
resize="none"
v-model="formData.userId"
clearable
placeholder=""
></el-input>
</Formitem>
</el-col>
<!-- key -->
<!-- <el-col :span="12">
<Formitem label="KEY" prop="key" type="edit">
<el-input
type="text"
class="inputShadow"
id="inputInner-edit-key"
resize="none"
v-model="formData.key"
clearable
placeholder=""
></el-input>
</Formitem>
</el-col> -->
<!-- 说明 -->
<el-col :span="24">
<Formitem label="说明" prop="description" type="edit">
<el-input
type="text"
class="inputShadow"
id="inputInner-edit-description"
resize="none"
v-model="formData.description"
clearable
placeholder=""
></el-input>
</Formitem>
</el-col>
</el-row>
</el-form>
</div>
<div class="dialogOption entrySave">
<el-button
class="entrySaveButton"
:disabled="loadings.submitLoading"
@click="submit"
>确 定</el-button
>
<el-button
class="entrySaveButton"
:disabled="loadings.uploadLoading"
@click="close(false)"
>关 闭</el-button
>
</div>
</el-dialog>
</template>
<script>
import { generateKey, updateKeyInfo } from "@/api/api-key.js";
export default {
props: {
outerVisible: {
type: Boolean,
default: false,
},
title: {
type: String,
default: "新增密码机",
},
type: {
type: String,
default: "",
},
active: {
type: Object,
default: null,
},
},
data() {
return {
formData: {
description: "",
userId: "",
key: "",
id: undefined,
},
rules: {
key: [
{
required: true,
trigger: "blur",
message: "用户ID不能为空!",
},
],
userId: [
{
required: true,
trigger: "blur",
message: "KEY不能为空!",
},
],
},
loadings: {
dialogLoading: false,
uploadLoading: false,
submitLoading: false,
},
loadingText: "",
};
},
watch: {
outerVisible(val) {
if (val) {
this.loadings.dialogLoading = false;
if (this.type == "update") {
this.formData = this.active;
}
}
},
},
methods: {
//数据保存
submit() {
this.loadings.dialogLoading = true;
let obj = {};
if (this.type == "add") {
this.$refs.formData.validate((valid) => {
if (valid) {
obj = this.formData;
this.addApi(obj);
} else {
this.loadings.dialogLoading = false;
}
});
} else if (this.type == "update") {
this.$refs.formData.validate((valid) => {
if (valid) {
obj.description = this.formData.description;
obj.userId = this.formData.userId;
obj.key = this.formData.key;
obj.id = this.formData.id;
this.updateapi(obj);
} else {
this.loadings.dialogLoading = false;
}
});
}
},
//新增
addApi(val) {
const { description = "", userId = "", key = "" } = val;
const params = new URLSearchParams();
params.append("description", description);
params.append("userId", userId);
generateKey(params)
.then((res) => {
if (res.code === "200") {
this.msgSuccess(res.message);
this.close(true);
} else {
this.alertWarningMsg(res.message);
this.loadings.dialogLoading = false;
}
})
.catch((err) => {
console.log(err);
this.loadings.dialogLoading = false;
});
},
//修改
updateapi(val) {
updateKeyInfo(val)
.then((res) => {
if (res.code === "200") {
this.msgSuccess(res.message);
this.close(true);
} else {
this.alertWarningMsg(res.message);
this.loadings.dialogLoading = false;
}
})
.catch((err) => {
console.log(err);
this.loadings.dialogLoading = false;
});
},
close(flag) {
this.formData = {
description: "",
userId: "",
key: "",
};
this.$emit("close", flag);
},
},
};
</script>
<style lang="scss" scoped>
@import "@/assets/styles/variables.scss";
</style>