Blame view

src/views/tool/build/TreeNodeDialog.vue 3.19 KB
yuanshuhui authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<template>
  <div>
    <el-dialog
      v-bind="$attrs"
      :close-on-click-modal="false"
      :modal-append-to-body="false"
      v-on="$listeners"
      @open="onOpen"
      @close="onClose"
    >
      <el-row :gutter="0">
        <el-form
          ref="elForm"
          :model="formData"
          :rules="rules"
          size="small"
          label-width="100px"
        >
          <el-col :span="24">
yuanshuhui authored
20
            <el-form-item label="选项名" prop="label">
yuanshuhui authored
21
22
23
24
25
26
27
28
              <el-input
                v-model="formData.label"
                placeholder="请输入选项名"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
yuanshuhui authored
29
            <el-form-item label="选项值" prop="value">
yuanshuhui authored
30
31
32
33
34
35
36
37
              <el-input
                v-model="formData.value"
                placeholder="请输入选项值"
                clearable
              >
                <el-select
                  slot="append"
                  v-model="dataType"
yuanshuhui authored
38
                  :style="{ width: '100px' }"
yuanshuhui authored
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
                >
                  <el-option
                    v-for="(item, index) in dataTypeOptions"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    :disabled="item.disabled"
                  />
                </el-select>
              </el-input>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div slot="footer">
yuanshuhui authored
54
55
        <el-button type="primary" @click="handelConfirm"> 确定 </el-button>
        <el-button @click="close"> 取消 </el-button>
yuanshuhui authored
56
57
58
59
60
      </div>
    </el-dialog>
  </div>
</template>
<script>
yuanshuhui authored
61
import { isNumberStr } from "@/utils/index";
yuanshuhui authored
62
63
64
65
66
67
68
69
70
71

export default {
  components: {},
  inheritAttrs: false,
  props: [],
  data() {
    return {
      id: 100,
      formData: {
        label: undefined,
yuanshuhui authored
72
        value: undefined,
yuanshuhui authored
73
74
75
76
77
      },
      rules: {
        label: [
          {
            required: true,
yuanshuhui authored
78
79
80
            message: "请输入选项名",
            trigger: "blur",
          },
yuanshuhui authored
81
82
83
84
        ],
        value: [
          {
            required: true,
yuanshuhui authored
85
86
87
88
            message: "请输入选项值",
            trigger: "blur",
          },
        ],
yuanshuhui authored
89
      },
yuanshuhui authored
90
      dataType: "string",
yuanshuhui authored
91
92
      dataTypeOptions: [
        {
yuanshuhui authored
93
94
          label: "字符串",
          value: "string",
yuanshuhui authored
95
96
        },
        {
yuanshuhui authored
97
98
99
100
101
          label: "数字",
          value: "number",
        },
      ],
    };
yuanshuhui authored
102
103
104
105
  },
  computed: {},
  watch: {
    // eslint-disable-next-line func-names
yuanshuhui authored
106
107
108
    "formData.value": function (val) {
      this.dataType = isNumberStr(val) ? "number" : "string";
    },
yuanshuhui authored
109
110
111
112
113
114
115
  },
  created() {},
  mounted() {},
  methods: {
    onOpen() {
      this.formData = {
        label: undefined,
yuanshuhui authored
116
117
        value: undefined,
      };
yuanshuhui authored
118
119
120
    },
    onClose() {},
    close() {
yuanshuhui authored
121
      this.$emit("update:visible", false);
yuanshuhui authored
122
123
    },
    handelConfirm() {
yuanshuhui authored
124
125
126
127
      this.$refs.elForm.validate((valid) => {
        if (!valid) return;
        if (this.dataType === "number") {
          this.formData.value = parseFloat(this.formData.value);
yuanshuhui authored
128
        }
yuanshuhui authored
129
130
131
132
133
134
135
        this.formData.id = this.id++;
        this.$emit("commit", this.formData);
        this.close();
      });
    },
  },
};
yuanshuhui authored
136
</script>