RoleForm.vue
2.92 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
<template>
<a-spin :spinning="submitted">
<a-form v-if="formState" :model="formState" :label-col="labelCol" :wrapper-col="wrapperCol" ref="formRef">
<a-form-item label="角色名称" name="roleName"
:rules="[{ required: true, message: '请输入角色名称' }]">
<a-input v-model:value="formState.roleName"
placeholder="请输入角色名称" :maxlength="64"/>
</a-form-item>
<a-form-item label="角色编码" name="roleCode"
:rules="[{ required: true, message: '请输入角色编码' },rule_pattern( /^[a-zA-Z][0-9a-zA-Z_]{1,}$/,'只能输入字符和数字')]">
<a-input v-model:value="formState.roleCode" :disabled="action!=='add'"
placeholder="请输入角色编码" :maxlength="32"/>
</a-form-item>
<a-form-item label="备注" name="remark" :rules="[rule_max(120,'string')]">
<a-textarea v-model:value="formState.remark" :maxlength="255" :rows="6"
placeholder="请输入备注"/>
</a-form-item>
</a-form>
</a-spin>
</template>
<script lang="ts">
import {Component} from "vue-facing-decorator";
import {message} from 'ant-design-vue';
import {reactive} from 'vue';
import {SmileOutlined} from "@ant-design/icons-vue";
import {EnhanceFormComponent} from "@/core/form/EnhanceFormComponent";
import {SecurityController} from "@/api/SecurityController";
import {Role} from "lib/src/entity/security/entity/Role";
@Component({
components: {SmileOutlined},
})
export default class RoleForm extends EnhanceFormComponent<Role> {
/**
* 初始化配置
*/
created(): void {
switch (this.action) {
case 'add':
this.formState = reactive<Role>(new Role());
break;
case 'edit':
SecurityController.getRoleById(this.axios, this.id as number).then(response => {
this.formState = reactive<Role>(response.data);
});
break;
}
}
onValidSuccess(formValue: Role): void {
switch (this.action) {
case 'add':
formValue.enabled = true;
SecurityController.addRole(this.axios, formValue).then(() => {
message.success(this.$t('common.save_success'));
this.$emit('handleOk');
});
break;
case 'edit':
formValue.roleId = this.id as number;
SecurityController.updateRole(this.axios, formValue).then(() => {
message.success(this.$t('common.modify_success'));
this.$emit('handleOk');
});
break;
}
}
}
</script>
<style scoped>
.tree {
overflow-y: auto;
border: 1px solid #f0f0f0;
padding: 16px;
}
</style>