WhiteEditDlg.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <FormDlg title="编辑白名单" @hide="onHide" @show="onShow" @submit="onSubmit" ref="dlg" :disabled="errors.any()">
  3. <div :class="{'form-group':true,'has-error': errors.has('serial')}">
  4. <label class="col-sm-4 control-label">设备国标编号
  5. <span class="text-red">*</span>
  6. </label>
  7. <div class="col-sm-7">
  8. <input type="text" class="form-control" :readonly="form.oper == 'edit'" name="serial" v-model.trim="form.serial" data-vv-as="设备编号" v-validate="'required'">
  9. </div>
  10. </div>
  11. <div :class="{'form-group':true,'has-error': errors.has('password')}">
  12. <label class="col-sm-4 control-label">接入密码
  13. </label>
  14. <div class="col-sm-7">
  15. <input type="text" class="form-control" name="password" v-model.trim="form.password" placeholder="为空时免密接入" data-vv-as="接入密码">
  16. </div>
  17. </div>
  18. <div :class="{'form-group':true,'has-error': errors.has('remote_ip')}">
  19. <label class="col-sm-4 control-label">接入IP
  20. </label>
  21. <div class="col-sm-7">
  22. <input type="text" class="form-control" name="remote_ip" v-model.trim="form.remote_ip" placeholder="为空时不限接入IP" data-vv-as="接入IP">
  23. </div>
  24. </div>
  25. <div :class="{'form-group':true,'has-error': errors.has('remote_port')}">
  26. <label class="col-sm-4 control-label">接入端口
  27. </label>
  28. <div class="col-sm-7">
  29. <input type="text" class="form-control" name="remote_port" v-model.trim="form.remote_port" placeholder="为空时不限接入端口" v-validate="'numeric'" data-vv-as="接入端口">
  30. </div>
  31. </div>
  32. <div :class="{'form-group':true,'has-error': errors.has('description')}">
  33. <label class="col-sm-4 control-label">描述
  34. </label>
  35. <div class="col-sm-7">
  36. <input type="text" class="form-control" name="description" v-model.trim="form.description" data-vv-as="描述信息">
  37. </div>
  38. </div>
  39. </FormDlg>
  40. </template>
  41. <script>
  42. import FormDlg from 'components/FormDlg.vue'
  43. import $ from 'jquery'
  44. export default {
  45. data() {
  46. return {
  47. form: this.defForm()
  48. }
  49. },
  50. components: {
  51. FormDlg
  52. },
  53. methods: {
  54. defForm() {
  55. return {
  56. oper : 'edit',
  57. serial: '',
  58. description: '',
  59. password: '',
  60. remote_ip: '',
  61. remote_port: '',
  62. }
  63. },
  64. onHide() {
  65. this.form = this.defForm();
  66. this.$emit("hide");
  67. },
  68. onShow() {
  69. this.errors.clear();
  70. this.$emit("show");
  71. if (!this.form.serial) {
  72. this.form.oper = 'add';
  73. this.$el.querySelector('[name=serial]').focus();
  74. }
  75. },
  76. async onSubmit() {
  77. var ok = await this.$validator.validateAll();
  78. if (!ok) {
  79. var e = this.errors.items[0];
  80. this.$message({
  81. type: 'error',
  82. message: e.msg
  83. })
  84. $(`[name=${e.field}]`).focus();
  85. return;
  86. }
  87. $.get('/api/v1/white/save', this.form).then(data => {
  88. this.$refs['dlg'].hide();
  89. this.$emit("submit");
  90. })
  91. },
  92. show(data) {
  93. this.errors.clear();
  94. if (data) {
  95. Object.assign(this.form, data);
  96. if (this.form.remote_port === 0) {
  97. this.form.remote_port = '';
  98. }
  99. }
  100. this.$nextTick(() => {
  101. this.$refs['dlg'].show();
  102. })
  103. }
  104. }
  105. }
  106. </script>