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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
| <template>
| <b-modal
| size="md"
| :title="title"
| ref="myModalRef"
| ok-title="保存"
| @ok="handleOk"
| @cancel="clearName"
| cancel-title="取消"
| :hide-header="false"
| :hide-footer="!isShowFooter"
| >
| <div>
| <!-- <h4>{{title}}</h4> -->
| <el-form
| :model="addForm"
| label-position="right"
| :rules="rules"
| ref="addForm"
| label-width="130px"
| >
| <el-form-item label="公网IP地址:" prop="publicIp">
| <el-input v-model="addForm.publicIp" placeholder="请输公网IP地址" :disabled="isDisabled"></el-input>
| </el-form-item>
| <el-form-item label="公网端口:" prop="publicPort">
| <el-input v-model="addForm.publicPort" placeholder="请输公网端口" :disabled="isDisabled"></el-input>
| </el-form-item>
| <div class="text-right mt-2 pt-4 border-top">
| <b-button size="md" class="mx-2" @click="hideModel">取消</b-button>
| <b-button variant="primary" class="mx-2" size="md" @click="submitForm('addForm')">保存</b-button>
| </div>
| </el-form>
| </div>
| </b-modal>
| </template>
|
| <script>
| import {
| Table,
| TableColumn,
| Col,
| Form,
| FormItem,
| Input,
| Checkbox,
| Radio,
| RadioGroup,
| Select,
| Option
| } from 'element-ui'
| import { setPublicUrl } from '@/server/home.js'
| export default {
| props: {
| title: String,
| item: Object,
| isShowFooter: {
| default: false
| }
| },
| components: {
| Table,
| TableColumn,
| elCol: Col,
| elForm: Form,
| elFormItem: FormItem,
| elInput: Input,
| elCheckbox: Checkbox,
| elRadio: Radio,
| elRadioGroup: RadioGroup,
| elSelect: Select,
| elOption: Option
| },
| data() {
| var isIP = (rule, value, callback) => {
| if (!value) {
| return callback(new Error('IP必填'))
| }
| /* 端口 /^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/ */
| const reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
| if (value && !reg.test(value)) {
| return callback(new Error('IP不合法'))
| } else {
| callback()
| }
| }
| return {
| name: '',
| typeList: [],
| addForm: {
| id: '',
| publicIp: '',
| publicPort: ''
| },
| rules: {
| publicIp: [{ required: true, validator: isIP, trigger: 'blur' }],
| publicPort: [
| { required: true, message: '端口必填', trigger: 'blur' },
| {
| pattern: /^([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])$/,
| message: '端口号必须是0-65535的数字',
| trigger: 'blur'
| }
| ]
| }
| }
| },
| computed: {
| isDisabled() {
| return this.$route.query.type === 'check'
| },
| isCamera() {
| return false
| }
| },
| methods: {
| // * 打开modal
| showModel(data) {
| this.$refs.myModalRef.show()
| if (data) {
| this.$nextTick(() => {
| this.reView(data)
| })
| }
| },
| hideModel() {
| this.$refs.myModalRef.hide()
| },
| /* 接口 start */
| async setPublicUrl(json) {
| const res = await setPublicUrl(json)
| if (res.success && res.code === 200 && res.data) {
| /* 成功操作 */
| this.$emit('submit')
| this.hideModel()
| this.$toast({
| type: 'success',
| message: res && res.msg ? res.msg : '配置地址成功'
| })
| } else {
| this.$toast({
| type: 'error',
| message: res && res.msg ? res.msg : '配置地址失败!'
| })
| }
| },
| /* 接口 end */
| submitForm(formName) {
| this.$refs[formName].validate(valid => {
| if (valid) {
| this.setPublicUrl(this.addForm)
| } else {
| console.log('保存接口,参数不合法!!')
| return false
| }
| })
| },
|
| // 回显
| reView(item) {
| console.log(item, '--回显--')
| const { id = '', publicIp = '', publicPort = '' } = item
| this.resetForm('addForm')
| this.addForm = {
| id,
| publicIp,
| publicPort
| }
| },
| // * 提交表单
| handleOk(e) {
| e.preventDefault()
| if (!this.name) {
| this.$toast({
| type: 'warning',
| message: '请输入角色名称'
| })
| return
| }
| this.$emit('submit', this.name, this.item ? this.item.id : '')
| },
| // * 取消
| clearName() {},
| resetForm(formName) {
| this.$refs[formName].resetFields()
| }
| }
| }
| </script>
| <style lang="scss" >
| .colony-table {
| .el-table td {
| padding: 6px !important;
| }
| .has-gutter th {
| padding: 2px !important;
| background: transparent !important;
| }
| .el-table td,
| .el-table th.is-leaf {
| border-bottom: none !important;
| }
| .el-table::before {
| background-color: transparent;
| }
| }
| </style>
|
|