DeviceEditDlg.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 for="input-serial" 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="readonly" id="input-serial" 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('name')}">
  12. <label for="input-name" class="col-sm-4 control-label">设备名称
  13. </label>
  14. <div class="col-sm-7">
  15. <input type="text" class="form-control" id="input-name" name="name" v-model.trim="form.name" data-vv-as="设备名称" @keydown.enter="$el.querySelector('#input-password').focus()">
  16. </div>
  17. </div>
  18. <div :class="{'form-group':true,'has-error': errors.has('password')}">
  19. <label for="input-password" class="col-sm-4 control-label">接入密码
  20. </label>
  21. <div class="col-sm-7">
  22. <input type="text" class="form-control" id="input-password" name="password" v-model.trim="form.password" placeholder="默认使用 livecms.ini > sip > device_password" data-vv-as="接入密码" @keydown.enter="$el.querySelector('#input-contact-ip').focus()">
  23. </div>
  24. </div>
  25. <div :class="{'form-group':true,'has-error': errors.has('contact_ip')}">
  26. <label for="input-contact-ip" class="col-sm-4 control-label">信令联络 IP
  27. </label>
  28. <div class="col-sm-7">
  29. <input type="text" class="form-control" id="input-contact-ip" name="contact_ip" v-model.trim="form.contact_ip" placeholder="默认使用 livecms.ini > sip > host" data-vv-as="信令联络 IP" @keydown.enter="$el.querySelector('#input-recv-stream-ip').focus()">
  30. </div>
  31. </div>
  32. <div :class="{'form-group':true,'has-error': errors.has('sms_id')}">
  33. <label for="input-sms-id" class="col-sm-4 control-label">SMS
  34. </label>
  35. <div class="col-sm-7">
  36. <select class="form-control" id="input-sms-id" name="sms_id" v-model.trim="form.sms_id" data-vv-as="SMS" v-validate="">
  37. <option value="">自动选择负载最小</option>
  38. <option v-for="(sms, idx) in smsList" :value="sms.id" :key="idx">{{sms.name}}</option>
  39. </select>
  40. </div>
  41. </div>
  42. <div :class="{'form-group':true,'has-error': errors.has('recv_stream_ip')}">
  43. <label for="input-recv-stream-ip" class="col-sm-4 control-label">收流 IP
  44. </label>
  45. <div class="col-sm-7">
  46. <input type="text" class="form-control" id="input-recv-stream-ip" name="recv_stream_ip" v-model.trim="form.recv_stream_ip" placeholder="默认使用 livesms.ini > sip > host" data-vv-as="收流 IP" @keydown.enter="$el.querySelector('#input-catalog-interval').focus()">
  47. </div>
  48. </div>
  49. <div :class="{'form-group':true, 'has-error': errors.has('catalog_interval')}">
  50. <label for="input-catalog-interval" class="col-sm-4 control-label">通道更新周期(秒)
  51. </label>
  52. <div class="col-sm-7">
  53. <input type="text" class="form-control" id="input-catalog-interval" name="catalog_interval" v-model.trim="form.catalog_interval" placeholder="3600" @keydown.enter="$el.querySelector('#input-subscribe-interval').focus()">
  54. </div>
  55. </div>
  56. <div :class="{'form-group':true, 'has-error': errors.has('subscribe_interval')}">
  57. <label for="input-catalog-interval" class="col-sm-4 control-label">订阅周期(秒)
  58. </label>
  59. <div class="col-sm-7">
  60. <input type="text" class="form-control" id="input-subscribe-interval" name="subscribe_interval" v-model.trim="form.subscribe_interval" placeholder="默认不订阅" @keydown.enter="onSubmit">
  61. </div>
  62. </div>
  63. <div :class="{'form-group': true, 'has-error': errors.has('charset')}">
  64. <label for="input-charset" class="col-sm-4 control-label">字符集
  65. </label>
  66. <div class="col-sm-7">
  67. <select class="form-control" id="input-charset" name="charset" v-model.trim="form.charset" data-vv-as="字符集" v-validate="">
  68. <option value="">自动识别</option>
  69. <option value="GB2312">GB2312</option>
  70. <option value="UTF-8">UTF-8</option>
  71. </select>
  72. </div>
  73. </div>
  74. <div :class="{'form-group':true,'has-error': errors.has('media_transport')}">
  75. <label for="input-media-transport" class="col-sm-4 control-label">流传输模式
  76. </label>
  77. <div class="col-sm-7">
  78. <el-radio-group v-model.trim="form.media_transport" size="mini">
  79. <el-radio-button label="TCP"></el-radio-button>
  80. <el-radio-button label="UDP"></el-radio-button>
  81. </el-radio-group>
  82. &nbsp;&nbsp;
  83. <el-radio-group v-model.trim="form.media_transport_mode" size="mini" v-show="form.media_transport == 'TCP'">
  84. <el-radio-button label="passive">被动</el-radio-button>
  85. <el-radio-button label="active">主动</el-radio-button>
  86. </el-radio-group>
  87. </div>
  88. </div>
  89. <div :class="{'form-group':true,'has-error': errors.has('record')}">
  90. <label for="input-record" class="col-sm-4 control-label">设备录像
  91. </label>
  92. <div class="col-sm-7 checkbox">
  93. <el-checkbox style="margin-left:-19px;margin-top:-5px;" size="small" v-model.trim="form.record_center" name="record_center">中心检索</el-checkbox>
  94. &nbsp;&nbsp;&nbsp;&nbsp;
  95. <el-checkbox style="margin-left:-19px;margin-top:-5px;" size="small" v-model.trim="form.record_indistinct" name="record_indistinct">模糊查询</el-checkbox>
  96. </div>
  97. </div>
  98. <div :class="{'form-group':true,'has-error': errors.has('catalog')}">
  99. <label for="input-catalog" class="col-sm-4 control-label">目录结构
  100. </label>
  101. <div class="col-sm-7 checkbox">
  102. <el-checkbox style="margin-left:-19px;margin-top:-5px;" size="small" v-model.trim="form.civil_code_first" name="civil_code_first">行政区域优先</el-checkbox>
  103. </div>
  104. </div>
  105. </FormDlg>
  106. </template>
  107. <script>
  108. import FormDlg from 'components/FormDlg.vue'
  109. import $ from 'jquery'
  110. export default {
  111. data() {
  112. return {
  113. form: this.defForm(),
  114. smsList: [],
  115. }
  116. },
  117. components: {
  118. FormDlg
  119. },
  120. methods: {
  121. defForm() {
  122. return {
  123. serial: '',
  124. name: '',
  125. media_transport: 'UDP',
  126. media_transport_mode: 'passive',
  127. sms_id: '',
  128. recv_stream_ip: '',
  129. contact_ip: '',
  130. charset: '',
  131. catalog_interval: 3600,
  132. subscribe_interval: 600,
  133. record_center: false,
  134. record_indistinct: false,
  135. civil_code_first: false,
  136. password: '',
  137. }
  138. },
  139. onHide() {
  140. this.form = this.defForm();
  141. this.$emit("hide");
  142. },
  143. onShow() {
  144. this.errors.clear();
  145. this.$emit("show");
  146. },
  147. fetchSMSList() {
  148. return new Promise((resolve, reject) => {
  149. $.get("/api/v1/sms/list").then(ret => {
  150. resolve(ret.map(sms => ({
  151. id: sms.Serial||"",
  152. name: sms.Serial||"",
  153. })));
  154. }).fail(() => {
  155. resolve([]);
  156. })
  157. })
  158. },
  159. async onSubmit() {
  160. var ok = await this.$validator.validateAll();
  161. if(!ok) {
  162. var e = this.errors.items[0];
  163. this.$message({
  164. type: 'error',
  165. message: e.msg
  166. })
  167. $(`[name=${e.field}]`).focus();
  168. return;
  169. }
  170. $.get('/api/v1/device/setinfo', this.form).then(data => {
  171. this.$refs['dlg'].hide();
  172. this.$emit("submit");
  173. })
  174. },
  175. async show(data) {
  176. this.errors.clear();
  177. if(data) {
  178. Object.assign(this.form, data);
  179. }
  180. var smsList = await this.fetchSMSList();
  181. var smsid = this.form['sms_id'];
  182. if(smsid && !smsList.some(sms => (sms.id == smsid))) {
  183. smsList.push({
  184. id: smsid,
  185. name: `${smsid}(not found)`,
  186. });
  187. }
  188. this.smsList = smsList;
  189. if(!this.form['subscribe_interval']) {
  190. this.form['subscribe_interval'] = '';
  191. }
  192. this.$nextTick(() => {
  193. this.$refs['dlg'].show();
  194. })
  195. }
  196. }
  197. }
  198. </script>