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 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
| <template> <div class="app-container"> <div class="filter-container"> <el-input v-model="listQuery.search" placeholder="路由名称" style="width: 200px" class="filter-item" @keyup.enter.native="handleFilter" /> <el-select v-model="listQuery.notify_type" placeholder="告警媒介" style="width: 120px" class="filter-item" clearable > <el-option v-for="item in notifyTypeOption" :key="item.value" :label="item.text" :value="item.value" /> </el-select> <el-button v-waves class="filter-item" type="primary" style="margin-left: 10px" icon="el-icon-search" circle @click="handleFilter" /> <el-button class="filter-item" style="margin-left: 10px" type="primary" icon="el-icon-edit-outline" @click="handleCreate" >新建规则</el-button> </div> <el-table v-loading="listLoading" :data="list" stripe border fit highlight-current-row style="width: 100%" element-loading-text="加载中" > <el-table-column align="center" label="路由名称" width="150"> <template v-slot="{ row }"> <span v-if="row.name"> {{ row.name }} </span> </template> </el-table-column> <el-table-column align="center" label="关联模板" width="100"> <template v-slot="{ row }"> <span v-if="row.template.name"> {{ row.template.name }} </span> </template> </el-table-column> <el-table-column align="center" label="告警媒介" min-width="60"> <template v-slot="{ row }"> {{ row.notify_type }} </template> </el-table-column> <el-table-column align="center" label="匹配规则" min-width="200"> <template v-slot="{ row }"> <span v-for="(v, k) in row.rules" :key="k"> <el-tag effect="dark">{{ k }}={{ v }}</el-tag> </span> </template> </el-table-column> <el-table-column align="center" label="通知对象" min-width="200"> <template v-slot="{ row }"> {{ row.dingtalk_access }} </template> </el-table-column> <el-table-column align="center" label="手机" min-width="200"> <template v-slot="{ row }"> <span v-for="(v, k) in row.at_someone_or_phone" :key="k"> <el-tag effect="dark">{{ v }}</el-tag> </span> </template> </el-table-column> <el-table-column align="center" label="是否发送恢复告警" width="80"> <template v-slot="{ row }"> <el-tag v-if="row.send_resolved" type="success">是</el-tag> <el-tag v-else type="warning">否</el-tag> </template> </el-table-column> <el-table-column align="center" label="Actions" class-name="small-padding fixed-width" width="180px" fixed="right" > <template v-slot="{ row, $index }"> <el-button icon="el-icon-edit" type="primary" size="small" plain @click="handleUpdate(row)" >编辑 </el-button> <el-button icon="el-icon-delete" type="danger" size="small" plain @click="handleDelete(row, $index)" >删除 </el-button> </template> </el-table-column> </el-table>
<pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.i_really_want_page_size" @pagination="getList" />
<el-dialog v-el-drag-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" center @dragDialog="this.$refs.select.blur()" > <el-form ref="dataForm" :rules="rules" :model="temp" label-position="right" label-width="120px" style="margin: 0 auto" size="small" > <el-form-item label="路由名称" prop="name"> <el-input v-model="temp.name" /> </el-form-item> <el-form-item label="通知类型" prop="notify_type" required> <el-select v-model="temp.notify_type" placeholder="平台" clearable > <el-option v-for="item in notifyTypeOption" :key="item.value" :label="item.text" :value="item.value" /> </el-select> </el-form-item> <el-form-item label="关联模板" prop="notify_type" required> <el-select v-model="temp.template" style="display: block" filterable remote reserve-keyword value-key="id" placeholder="Type to search" :remote-method="asyncGetAlertTemplateList" @remove-tag="templateListChange" > <el-option v-for="(item) in templateList" :key="item.id" :label="item.name" :value="item.id" /> </el-select> </el-form-item> <template v-if="temp.notify_type ==='dingtalk'"> <el-form-item label="机器人Access" prop="dingtalk_access"> <el-input v-model="temp.dingtalk_access" /> </el-form-item> <el-form-item label="机器人Secret" prop="dingtalk_token"> <el-input v-model="temp.dingtalk_token" /> </el-form-item> </template> <el-form-item label="@人员/手机" prop="at_someone_or_phone"> <el-select v-model="temp.at_someone_or_phone" style="display: block" reserve-keyword multiple filterable clearable allow-create > <el-option v-for="item in mobileList" :key="item" :label="item" :value="item" /> </el-select> </el-form-item> <el-form-item label="标签"> <div v-for="(item, index) in tagArr" :key="index" class="filter-item"> <i v-show="show(index)" class="el-icon-remove-outline deleted" @click="deleteItem(index)" /> <el-input v-model.trim="item.label" placeholder="如 app" /> <el-input v-model.trim="item.value" placeholder="如 nginx" /> </div> <el-button type="text" size="small" @click="addItem">+增加</el-button> </el-form-item> <el-form-item label="发送恢复通知" prop="send_resolved"> <el-switch v-model="temp.send_resolved" active-text="是" inactive-text="否" /> </el-form-item> </el-form>
<div slot="footer" class="dialog-footer"> <el-button @click="dialogFormVisible = false"> 取消 </el-button> <el-button type="primary" @click="dialogStatus === 'create' ? createData() : updateData()"> 确认 </el-button> </div> </el-dialog>
</div> </template>
<script> import { createAlertRouter, listAlertRouter, listAlertTemplate, updateAlertRouter, deleteAlertRouter } from '@/api/alerts_list' import Pagination from '@/components/Pagination' import elDragDialog from '@/directive/el-drag-dialog' import waves from '@/directive/waves'
export default { name: 'NotifyTemplate', components: { Pagination }, directives: { elDragDialog, waves }, data() { return { list: [], total: 0, listLoading: false, listQuery: { page: 1, i_really_want_page_size: 10, search: undefined, state: undefined, is_deleted: false, notify_type: undefined, sort: undefined }, notifyTypeOption: [ { text: '钉钉', value: 'dingtalk' }, { text: '短信', value: 'sms' } ], dialogStatus: '', textMap: { update: '编辑', create: '创建' }, temp: { name: undefined, notify_type: undefined, rules: {}, dingtalk_access: undefined, dingtalk_token: undefined, send_resolved: true, template: undefined, at_someone_or_phone: undefined }, tagArr: [], dialogFormVisible: false, templateListQuery: { show_fewer: true, no_pagination: true, search: undefined }, mobileList: [], templateList: [], templateListRemove: [], rules: {} } }, created() { this.getList() }, methods: { getList() { this.listLoading = true listAlertRouter(this.listQuery).then((response) => { this.list = response.data.results this.total = response.data.count this.listLoading = false }) }, asyncGetAlertTemplateList(q) { if (q.trim() !== '') { this.instanceListQuery.search = q.trim() } listAlertTemplate(this.templateListQuery).then((response) => { this.templateList = response.data }) }, templateListChange(v) { this.templateListRemove.push(v) }, handleFilter() { this.listQuery.page = 1 this.getList() }, resetTemp() { this.temp = { name: undefined, notify_type: undefined, rules: {}, dingtalk_access: undefined, dingtalk_token: undefined, send_resolved: true, template: undefined, at_someone_or_phone: undefined } this.tagArr = [] }, handleDelete(row, index) { this.$confirm('此操作将删除该路由规则, 是否继续?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { deleteAlertRouter(row.id).then(() => { this.$notify({ title: 'Success', message: 'Delete Successfully', type: 'success', duration: 2000 }) this.list.splice(index, 1) }) }) }, handleUpdate(row) { this.resetTemp() this.temp = Object.assign({}, row) for (const key in this.temp.rules) { this.tagArr.push({ label: key, value: this.temp.rules[key] }) } this.dialogStatus = 'update' this.dialogFormVisible = true this.$nextTick(() => { this.$refs.dataForm.clearValidate() }) }, updateData() { this.$refs.dataForm.validate((valid) => { this.handleRules() if (valid) { const tempData = Object.assign({}, this.temp) tempData.template = tempData.template.id updateAlertRouter(this.temp.id, tempData).then((response) => { const index = this.list.findIndex((v) => v.id === this.temp.id) this.list.splice(index, 1, response.data) this.dialogFormVisible = false this.$notify({ title: 'Success', message: 'Update Successfully', type: 'success', duration: 2000 }) }) } }) }, handleCreate() { this.dialogFormVisible = true this.dialogStatus = 'create' this.resetTemp() this.tagArr = [{ label: '', value: '' }] this.$nextTick(() => { this.$refs.dataForm.clearValidate() }) }, createData() { this.$refs.dataForm.validate((valid) => { this.handleRules() if (valid) { const tempData = Object.assign({}, this.temp) tempData.template = tempData.template.id createAlertRouter(this.temp).then((response) => { this.list.unshift(response.data) this.dialogFormVisible = false this.$notify({ title: 'Success', message: 'Created Successfully', type: 'success', duration: 2000 }) }) } }) }, show(i) { return !(i < 1) }, deleteItem(i) { delete this.temp.rules[this.tagArr[i].label] this.tagArr.splice(i, 1) }, addItem() { this.tagArr.push({ label: '', value: '' }) }, handleRules() { for (let i = 0; i < this.tagArr.length; i++) { if (this.tagArr[i].label !== '' && this.tagArr[i].value !== '') { this.temp.rules[this.tagArr[i].label] = this.tagArr[i].value } } } } } </script>
<style scoped> .table-expand label { width: 90px; color: #99a9bf; } @media screen and (max-width: 500px) { .el-dialog__wrapper .el-dialog { width: 300px !important; .el-dialog__body{ padding: 10px 20px!important; .el-form-item__label{ width: 68px!important; } .el-select,.el-input{ width: 180px!important; } } } } </style>
|