CameraConfigDialog.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <confirm-dialog
  3. ref="dialog"
  4. :title="dialogTitle"
  5. @confirm="onConfirm"
  6. >
  7. <div class="c-grid-form u-align-self--center">
  8. <span class="c-grid-form__label u-required">
  9. 厂商
  10. </span>
  11. <el-select
  12. v-model="item.manufacturerKey"
  13. class="u-width"
  14. placeholder="请选择厂商"
  15. >
  16. <el-option
  17. v-for="(option, index) in manufacturerOptions"
  18. :key="index"
  19. :value="option.manufacturerKey"
  20. :label="option.manufacturerName"
  21. />
  22. </el-select>
  23. <span class="c-grid-form__label u-required">
  24. 型号
  25. </span>
  26. <el-input
  27. v-model.trim="item.model"
  28. placeholder="最多50个字符"
  29. maxlength="50"
  30. clearable
  31. />
  32. <span class="c-grid-form__label u-required">
  33. 标识
  34. </span>
  35. <el-input
  36. v-model.trim="item.identifier"
  37. placeholder="仅支持数字和字母,最多30个字符"
  38. maxlength="30"
  39. clearable
  40. />
  41. <template v-if="!item.id">
  42. <span class="c-grid-form__label u-required">
  43. 账号
  44. </span>
  45. <el-input v-model.trim="item.username" />
  46. <span class="c-grid-form__label u-required">
  47. 密码
  48. </span>
  49. <el-input
  50. v-model.trim="item.password"
  51. class="u-password"
  52. />
  53. </template>
  54. <span class="c-grid-form__label u-required">
  55. 通过视频服务器
  56. </span>
  57. <el-select
  58. v-model="item.throughEvs"
  59. placeholder="请选择"
  60. >
  61. <el-option
  62. label="是"
  63. value="1"
  64. />
  65. <el-option
  66. label="否"
  67. value="0"
  68. />
  69. </el-select>
  70. <template v-if="item.throughEvs == '1'">
  71. <span class="c-grid-form__label u-required">
  72. 服务器通道号
  73. </span>
  74. <el-input-number
  75. v-model="item.evsChannel"
  76. controls-position="right"
  77. />
  78. <span class="c-grid-form__label u-required">
  79. 服务器编号
  80. </span>
  81. <el-input-number
  82. v-model="item.evsLocation"
  83. controls-position="right"
  84. />
  85. </template>
  86. <span class="c-grid-form__label">
  87. 备注
  88. </span>
  89. <div
  90. class="has-info"
  91. data-info="备注将用于多摄像头展示时的区分"
  92. >
  93. <el-input
  94. v-model.trim="item.remark"
  95. placeholder="最多30个字符"
  96. maxlength="30"
  97. clearable
  98. />
  99. </div>
  100. </div>
  101. </confirm-dialog>
  102. </template>
  103. <script>
  104. import {
  105. ThirdPartyDeviceInfo,
  106. CameraToThirdPartyMap
  107. } from '@/constant'
  108. import {
  109. getManufacturersByType,
  110. addCamera,
  111. updateCamera
  112. } from '@/api/external'
  113. export default {
  114. name: 'CameraConfigDialog',
  115. data () {
  116. return {
  117. item: {},
  118. manufacturerOptions: []
  119. }
  120. },
  121. computed: {
  122. dialogTitle () {
  123. return this.item?.id ? '编辑摄像头' : ''
  124. }
  125. },
  126. methods: {
  127. async show (type, options) {
  128. const result = await getManufacturersByType(CameraToThirdPartyMap[type])
  129. this.manufacturerOptions = result.data
  130. if (options) {
  131. this.item = {
  132. id: options.id,
  133. cameraType: type,
  134. identifier: options.identifier,
  135. manufacturerKey: options.manufacturerKey,
  136. model: options.model,
  137. remark: ThirdPartyDeviceInfo[CameraToThirdPartyMap[type]],
  138. username: options.username,
  139. password: options.password,
  140. throughEvs: String(options.throughEvs || 0),
  141. evsChannel: options.evsChannel,
  142. evsLocation: options.evsLocation
  143. }
  144. } else {
  145. this.item = {
  146. cameraType: type,
  147. identifier: '',
  148. manufacturerKey: '',
  149. model: '',
  150. remark: ThirdPartyDeviceInfo[CameraToThirdPartyMap[type]],
  151. username: '',
  152. password: '',
  153. throughEvs: '',
  154. evsChannel: 0,
  155. evsLocation: 0
  156. }
  157. }
  158. this.$refs.dialog.show()
  159. },
  160. getManufacturersByType () {
  161. return getManufacturersByType(CameraToThirdPartyMap[this.item.cameraType])
  162. },
  163. onConfirm (done) {
  164. if (!this.item.manufacturerKey) {
  165. this.$message({
  166. type: 'warning',
  167. message: '请选择厂商'
  168. })
  169. return
  170. }
  171. if (!this.item.model) {
  172. this.$message({
  173. type: 'warning',
  174. message: '请填写型号'
  175. })
  176. return
  177. }
  178. if (!this.item.identifier) {
  179. this.$message({
  180. type: 'warning',
  181. message: '请填写唯一标识'
  182. })
  183. return
  184. }
  185. if (!/^[0-9a-zA-Z]+$/.test(this.item.identifier)) {
  186. this.$message({
  187. type: 'warning',
  188. message: '唯一标识格式错误仅支持数字和字母'
  189. })
  190. return
  191. }
  192. if (!this.item.username && !this.item.id) {
  193. this.$message({
  194. type: 'warning',
  195. message: '请填写账号'
  196. })
  197. return
  198. }
  199. if (!this.item.password && !this.item.id) {
  200. this.$message({
  201. type: 'warning',
  202. message: '请填写密码'
  203. })
  204. return
  205. }
  206. if (!this.item.throughEvs) {
  207. this.$message({
  208. type: 'warning',
  209. message: '请选择是否通过视频服务器'
  210. })
  211. return
  212. }
  213. const key = this.item.manufacturerKey
  214. const isAdd = this.item.id ? updateCamera : addCamera
  215. isAdd({
  216. manufacturerName: this.manufacturerOptions.find(({ manufacturerKey }) => manufacturerKey === key).manufacturerName,
  217. camProvider: 0,
  218. ...this.item
  219. }).then(() => {
  220. done()
  221. this.$emit('confirm', this.item)
  222. })
  223. }
  224. }
  225. }
  226. </script>