peng
2026-03-18 b89df58e3b783f3d718bd85a3e4c6a3bd9ee353c
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
<template>
  <a-drawer :title="title" :maskClosable="true" :width="drawerWidth" placement="right" :closable="true" @close="close" :visible="visible" style="overflow: auto;padding-bottom: 53px;">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">                                                              
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="clientType">
          <a-input placeholder="请输入clientType" v-decorator="['clientType', validatorRules.clientType]"></a-input>
        </a-form-item>                                                              
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="timeValue">
          <a-input-number placeholder="请输入timeValue" v-decorator="['timeValue', validatorRules.timeValue]" style="width: 100%"></a-input-number>
        </a-form-item>                                                              
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="timeUnit">
          <a-input placeholder="请输入timeUnit" v-decorator="['timeUnit', validatorRules.timeUnit]"></a-input>
        </a-form-item>                                                              
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="countType">
          <a-input placeholder="请输入countType" v-decorator="['countType', validatorRules.countType]"></a-input>
        </a-form-item>                                                              
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="countRef">
          <a-input placeholder="请输入countRef" v-decorator="['countRef', validatorRules.countRef]"></a-input>
        </a-form-item>                                                              
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="countNum">
          <a-input-number placeholder="请输入countNum" v-decorator="['countNum', validatorRules.countNum]" style="width: 100%"></a-input-number>
        </a-form-item>                                                  
      </a-form>
    </a-spin>
    <div class="drawer-bottom-button" v-show="!disableSubmit">
      <a-popconfirm title="确定放弃编辑?" @confirm="handleCancel" okText="确定" cancelText="取消">
        <a-button style="margin-right: 0.8rem">取消</a-button>
      </a-popconfirm>
      <a-button @click="handleSubmit" type="primary" :loading="confirmLoading">提交</a-button>
    </div>
  </a-drawer>
</template>
 
<script>
import pick from 'lodash.pick'
import { postAction, putAction } from '@tievd/cube-block/lib/api/manage'
 
export default {
  name: 'ClientConfigModal',
 
  data() {
    return {
      form: this.$form.createForm(this),
      title: '操作',
      visible: false,
      confirmLoading: false,
      drawerWidth: 700,
      disableSubmit: false,
      model: {},
      validatorRules: {                                            
          clientType: {
            rules: [{ required: true, message: 'clientType不能为空' }]
          },                                        
          timeValue: {
            rules: [{ required: true, message: 'timeValue不能为空' }, { pattern: /^[\d]*$/, message: '只能输入数字' }]
          },                                        
          timeUnit: {
            rules: [{ required: true, message: 'timeUnit不能为空' }]
          },                                        
          countType: {
            rules: [{ required: true, message: 'countType不能为空' }]
          },                                        
          countRef: {
            rules: [{ required: true, message: 'countRef不能为空' }]
          },                                        
          countNum: {
            rules: [{ required: true, message: 'countNum不能为空' }, { pattern: /^[\d]*$/, message: '只能输入数字' }]
          },                                            
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
    }
  },
 
  methods: {
    // 根据屏幕变化,设置抽屉尺寸
    resetScreenSize() {
      let screenWidth = document.body.clientWidth
      if (screenWidth < 500) {
        this.drawerWidth = screenWidth
      } else {
        this.drawerWidth = 700
      }
    },
    add() {
      this.edit({})
    },
    edit(record) {
      this.resetScreenSize() // 调用此方法,根据屏幕宽度自适应调整抽屉的宽度
      this.form.resetFields()
      // if (record.id !== undefined) {
      //  // 新增编辑的特殊操作写在这里
      // }
      this.visible = true
      this.model = Object.assign({}, record)
      this.$nextTick(() => {
        this.form.setFieldsValue(
          pick(this.model, 'clientType', 'timeValue', 'timeUnit', 'countType', 'countRef', 'countNum')
        )
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
      this.disableSubmit = false
      this.model = {}
    },
    handleSubmit() {
      // 触发表单验证
      this.form.validateFields(async (err, values) => {
        if (!err) {
          try {
            this.confirmLoading = true
            let formData = Object.assign(this.model, values)
            let res = null
            if (!this.model.id) {
              // 新增
              res = await postAction('/jyz/clientConfig/add', formData)
            } else {
              // 编辑
              res = await putAction('/jyz/clientConfig/edit', formData)
            }
            if (res.success) {
              this.$message.success(res.message)
              this.$emit('ok')
            }
          } catch (err) {
            console.log(err)
          } finally {
            this.confirmLoading = false
            this.close()
          }
        }
      })
    },
    handleCancel() {
      this.close()
    },
  }
}
</script>
 
<style scoped lang="less"></style>