quanyawei
2024-05-13 08633f23e4955c7e5f79d19912741cc22ef3f1e0
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
<template>
  <a-form style="margin-top: 8px">
    <a-modal
      title="编辑-字典"
      destroyOnClose
      :visible="visible"
      @cancel="handleCancel"
      @ok="handleOk"
      okText="保存"
    >
      <a-form style="margin-top: 8px">
        <a-form-item
          :labelCol="{ span: 5 }"
          :wrapperCol="{ span: 15 }"
          label="key"
          fieldDecoratorId="userName"
        >
          <a-input placeholder="请输入key" v-model="editTableInform.key"  disabled/>
        </a-form-item>
        <a-form-item
          :labelCol="{ span: 5 }"
          :wrapperCol="{ span: 15 }"
          label="value"
          fieldDecoratorId="mobile"
        >
          <a-input placeholder="请输入value" v-model="editTableInform.value" />
        </a-form-item>
 
      </a-form>
    </a-modal>
  </a-form>
</template>
 
<script lang="ts">
import {
  Component,
  Prop,
  Vue,
  Emit,
  Model,
  Watch
} from "vue-property-decorator";
import { State, Mutation, namespace } from "vuex-class";
 
import { get, post } from "@/util/request";
 
@Component({
  components: {}
})
export default class dictionaryManage extends Vue {
  private editTableInform: any = {
    key: null,
    value: null,
    id:null
  };
  @Prop({
    type: Boolean,
    default: false
  })
  private visible!: boolean;
 
  @Prop({
    type: Object,
    default() {
      return {};
    }
  })
  private record!: any;
 
  private handleCancel(): void {
     this.editTableInform.key = this.record.key;
    this.editTableInform.value = this.record.value;
    this.updateVisible(false);
  }
  // 保存 更新数据库
  private handleOk(): void {
    if(this.editTableInform.key!==this.record.key||this.editTableInform.value!==this.record.value){
      post("dict/data/update",
        {
          id: this.editTableInform.id,
          key: this.editTableInform.key==this.record.key?null:this.editTableInform.key,
          value: this.editTableInform.value==this.record.value?null:this.editTableInform.value,
        }).then(res => {
        if(res.data.code!=0){
          this.$message.error(res.data.message)
        }else{
        //保存成功,组件刷新数据
        this.$emit("updateData");
        this.$message.success(res.data.message)
        this.updateVisible(false);
        }
      })
      .catch(err => {
        console.log(err);
      });
    }else {
      this.$message.warning('未修改!')
    }
 
  }
 
  private updateVisible(visible: boolean): void {
    this.$emit("update:visible", visible);
  }
 
  //监听编辑回调值
  @Watch("record", {
    immediate: true, //监听开始后是否立即调用该回调函数;
    deep: true //深度监听
  })
  //监听编辑逻辑赋值
  private recordChange(value: any, oldValue: any): void {
    this.editTableInform.key = this.record.key;
    this.editTableInform.value = this.record.value;
    this.editTableInform.id=this.record.id
  }
}
</script>