DeviceEditDlg.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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('forbidden')}">
  90. <label for="input-forbidden" 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.forbidden" name="forbidden">禁止接入</el-checkbox>
  94. &nbsp;&nbsp;&nbsp;&nbsp;
  95. <el-checkbox style="margin-left:-19px;margin-top:-5px;" size="small" v-model.trim="form.freeticket" name="freeticket">免密注册</el-checkbox>
  96. </div>
  97. </div> -->
  98. </FormDlg>
  99. </template>
  100. <script>
  101. import FormDlg from 'components/FormDlg.vue'
  102. import $ from 'jquery'
  103. export default {
  104. data() {
  105. return {
  106. form: this.defForm(),
  107. smsList: [],
  108. }
  109. },
  110. components: {
  111. FormDlg
  112. },
  113. methods: {
  114. defForm() {
  115. return {
  116. serial: '',
  117. name: '',
  118. media_transport: 'UDP',
  119. media_transport_mode: 'passive',
  120. sms_id: '',
  121. recv_stream_ip: '',
  122. contact_ip: '',
  123. charset: '',
  124. catalog_interval: 3600,
  125. subscribe_interval: 600,
  126. password: '',
  127. }
  128. },
  129. onHide() {
  130. this.form = this.defForm();
  131. this.$emit("hide");
  132. },
  133. onShow() {
  134. this.errors.clear();
  135. this.$emit("show");
  136. },
  137. fetchSMSList() {
  138. return new Promise((resolve, reject) => {
  139. $.get("/api/v1/sms/list").then(ret => {
  140. resolve(ret.map(sms => ({
  141. id: sms.Serial||"",
  142. name: sms.Serial||"",
  143. })));
  144. }).fail(() => {
  145. resolve([]);
  146. })
  147. })
  148. },
  149. async onSubmit() {
  150. var ok = await this.$validator.validateAll();
  151. if(!ok) {
  152. var e = this.errors.items[0];
  153. this.$message({
  154. type: 'error',
  155. message: e.msg
  156. })
  157. $(`[name=${e.field}]`).focus();
  158. return;
  159. }
  160. $.get('/api/v1/device/setinfo', this.form).then(data => {
  161. this.$refs['dlg'].hide();
  162. this.$emit("submit");
  163. })
  164. },
  165. async show(data) {
  166. this.errors.clear();
  167. if(data) {
  168. Object.assign(this.form, data);
  169. }
  170. var smsList = await this.fetchSMSList();
  171. var smsid = this.form['sms_id'];
  172. if(smsid && !smsList.some(sms => (sms.id == smsid))) {
  173. smsList.push({
  174. id: smsid,
  175. name: `${smsid}(not found)`,
  176. });
  177. }
  178. this.smsList = smsList;
  179. if(!this.form['subscribe_interval']) {
  180. this.form['subscribe_interval'] = '';
  181. }
  182. this.$nextTick(() => {
  183. this.$refs['dlg'].show();
  184. })
  185. }
  186. }
  187. }
  188. </script>