xiangpei
2025-04-18 7feee0463330ee014b0ac1a6f8e31118bb699f12
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
<template>
  <div>
    <el-dialog :title="dialogTitle" :visible.sync="dialogFormVisible" @close="closeDialog" :destroy-on-close="true" :append-to-body="true" :close-on-click-modal="false">
      <el-form :model="dictTypeForm" :rules="dictTypeRules" ref="dictTypeForm" size="small">
        <el-form-item label="字典类型" :label-width="formLabelWidth" prop="dictTypeName">
          <el-input v-model="dictTypeForm.dictTypeName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="字典key" :label-width="formLabelWidth" prop="dictTypeKey">
          <el-input v-model="dictTypeForm.dictTypeKey" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="备注" :label-width="formLabelWidth" prop="remark">
          <el-input v-model="dictTypeForm.remark" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="排序" :label-width="formLabelWidth" prop="dictSort">
          <el-input v-model="dictTypeForm.dictSort" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="状态" :label-width="formLabelWidth" prop="dictStatus">
          <el-radio-group v-model="dictTypeForm.dictStatus">
            <el-radio label="0">正常</el-radio>
            <el-radio label="1">禁用</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeDialog" size="small">取 消</el-button>
        <el-button type="primary" @click="addOrEditDictType" size="small">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import {Message} from "element-ui";
import {addDictType, editDictType, getDictTypes} from "@/api/dict-type";
 
export default {
  name: "RoleDialog",
  data() {
    return {
      formLabelWidth: '120px',
      dictTypeRules: {
        dictTypeName: [
          { required: true, message: '请输入角色名称', trigger: 'blur' }
        ],
        dictTypeKey: [
          { required: true, message: '请输入角色key', trigger: 'blur' }
        ],
        dictStatus: [
          { required: true, message: '请选择角色状态', trigger: 'change' }
        ],
      }
    }
  },
  computed: {
    dialogFormVisible: {
      get() {
        return this.$store.state.dictType.dialogFormVisible;
      },
      set(value) {
        this.$store.state.dictType.dialogFormVisible = value;
      }
    },
    dialogTitle() {
      return this.$store.state.dictType.dialogTitle;
    },
    dictTypeForm: {
      get() {
        return this.$store.state.dictType.dictTypeForm;
      },
      set(value) {
        this.$store.state.dictType.dictTypeForm = value;
      }
    }
  },
  methods: {
    refreshData() {
      var params = {
        "current": this.$store.state.dictType.currentPage,
        "size": this.$store.state.dictType.pageSize
      };
      // 刷新
      getDictTypes(params).then((res) => {
        this.$store.state.dictType.tableData = res.data.data;
        this.$store.state.dictType.total = res.data.total;
        this.clearForm();
      })
    },
    clearForm() {
      Object.keys(this.dictTypeForm).forEach((key) => {
        this.dictTypeForm[key] = null;
      })
    },
    closeDialog() {
      this.$store.state.dictType.dialogFormVisible = false;
      this.clearForm();
    },
    addOrEditDictType() {
      this.$refs["dictTypeForm"].validate((valid) => {
        if (valid) {
          if (this.dialogTitle === "添加字典类型") {
            addDictType(this.dictTypeForm).then((res) => {
              Message.success(res.data.msg);
              this.dialogFormVisible = false;
              this.refreshData();
            })
          } else {
            editDictType(this.dictTypeForm).then((res) => {
              Message.success(res.data.msg);
              this.dialogFormVisible = false;
              this.refreshData();
            })
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    }
  }
}
</script>
 
<style scoped>
 
</style>