CamList.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <el-row>
  3. <el-row>
  4. <el-button
  5. size="mini"
  6. type="warning"
  7. class="el-icon-document-add"
  8. @click="handleAdd"
  9. >添加</el-button>
  10. <el-table
  11. :data="dataList"
  12. style="width: 100%"
  13. >
  14. <el-table-column
  15. label="No"
  16. type="index"
  17. />
  18. <el-table-column
  19. prop="addAt"
  20. label="添加时间"
  21. width="150"
  22. />
  23. <el-table-column
  24. prop="camName"
  25. label="摄像头名字"
  26. width="150"
  27. >
  28. <template slot-scope="scope">
  29. <router-link style="text-decoration-line: none" target="_blank" :to="`/my/cam/${scope.row.camId}/live`">
  30. {{ scope.row.camName }}
  31. </router-link>
  32. </template>
  33. </el-table-column>
  34. <el-table-column
  35. prop="state"
  36. label="状态"
  37. >
  38. <template slot-scope="scope">
  39. <el-tag v-if="scope.row.state" :type="'success'" disable-transitions>
  40. 推流中
  41. </el-tag>
  42. <el-tag v-else :type="'danger'" disable-transitions>
  43. 离线
  44. </el-tag>
  45. </template>
  46. </el-table-column>
  47. <el-table-column
  48. label="操作"
  49. >
  50. <template slot-scope="scope">
  51. <el-button
  52. size="mini"
  53. @click="handleEdit(scope.$index, scope.row)"
  54. >修改名字</el-button>
  55. <el-button
  56. size="mini"
  57. @click="handleDetail(scope.$index, scope.row)"
  58. >推流地址</el-button>
  59. <el-button
  60. size="mini"
  61. type="danger"
  62. @click="handleDelete(scope.$index, scope.row)"
  63. >删除</el-button>
  64. </template>
  65. </el-table-column>
  66. </el-table>
  67. <!-- 添加摄像头对话框 -->
  68. <el-dialog
  69. append-to-body
  70. :visible.sync="showEditScopeDialog"
  71. width="50%"
  72. center
  73. >
  74. <el-card class="box-card">
  75. <div slot="header" class="clearfix">
  76. <h3>添加摄像头</h3>
  77. </div>
  78. <div class="text item">
  79. <el-form ref="form" :model="addCamForm" label-width="80px">
  80. <el-form-item label="设备 ID">
  81. <el-input v-model="addCamForm.deviceId" />
  82. </el-form-item>
  83. <el-form-item label="设备名字">
  84. <el-input v-model="addCamForm.deviceName" />
  85. </el-form-item>
  86. <el-form-item>
  87. <el-button type="primary" @click="onAddCam">立即添加</el-button>
  88. <el-button>取消</el-button>
  89. </el-form-item>
  90. </el-form>
  91. </div>
  92. </el-card>
  93. </el-dialog>
  94. <!-- 修改摄像头名字对话框 -->
  95. <el-dialog
  96. append-to-body
  97. :visible.sync="showUpdateDialog"
  98. width="50%"
  99. center
  100. >
  101. <el-card class="box-card">
  102. <div slot="header" class="clearfix">
  103. <h3>修改摄像头名字</h3>
  104. </div>
  105. <div class="text item">
  106. <el-form ref="form" :model="updateNameForm" label-width="80px">
  107. <el-form-item label="新名字">
  108. <el-input v-model="updateNameForm.newName" />
  109. </el-form-item>
  110. <el-form-item>
  111. <el-button type="primary" @click="onUpdateCam">立即修改</el-button>
  112. <el-button>取消</el-button>
  113. </el-form-item>
  114. </el-form>
  115. </div>
  116. </el-card>
  117. </el-dialog>
  118. <!-- 摄像头详情对话框 -->
  119. <el-dialog
  120. append-to-body
  121. :visible.sync="showDetailDialog"
  122. width="50%"
  123. center
  124. >
  125. <el-card class="box-card">
  126. <div slot="header" class="clearfix">
  127. <h3>推流地址</h3>
  128. </div>
  129. <div class="text item">
  130. <h3>{{ pushUrl }}</h3>
  131. </div>
  132. </el-card>
  133. </el-dialog>
  134. </el-row>
  135. <el-row>
  136. <el-pagination
  137. background
  138. :small="screenWidth <= 768"
  139. layout="prev, pager, next"
  140. :page-size="pageSize"
  141. :current-page="currentPage"
  142. :total="totalSize"
  143. @current-change="handleCurrentChange"
  144. @prev-click="handleCurrentChange"
  145. @next-click="handleCurrentChange"
  146. />
  147. </el-row>
  148. </el-row>
  149. </template>
  150. <script>
  151. import {
  152. getVideoResource
  153. } from '@/api/video'
  154. import { addCam, deleteCam, getCamPushUrl, getUserCams, updateCamName } from '@/api/cam'
  155. export default {
  156. name: 'CamList',
  157. data() {
  158. return {
  159. // 屏幕宽度, 为了控制分页条的大小
  160. screenWidth: document.body.clientWidth,
  161. currentPage: 1,
  162. pageSize: 20,
  163. totalSize: 0,
  164. dataList: [],
  165. // **********************************************************************
  166. showEditScopeDialog: false,
  167. showUpdateDialog: false,
  168. showDetailDialog: false,
  169. videoResources: [],
  170. addCamForm: {
  171. deviceId: null,
  172. deviceName: null
  173. },
  174. updateNameForm: {
  175. camId: null,
  176. newName: null
  177. },
  178. pushUrl: null
  179. }
  180. },
  181. created() {
  182. document.title = '摄像头列表'
  183. this.getData(this.currentPage)
  184. },
  185. methods: {
  186. handleCurrentChange(pageNumber) {
  187. this.currentPage = pageNumber
  188. this.getData(this.currentPage)
  189. // 回到顶部
  190. scrollTo(0, 0)
  191. },
  192. getData() {
  193. this.dataList = []
  194. getUserCams(this.currentPage).then(resp => {
  195. if (resp.code === 0) {
  196. this.dataList = resp.data.list
  197. this.totalSize = resp.data.totalSize
  198. } else {
  199. this.$notify({
  200. title: '提示',
  201. message: resp.msg,
  202. type: 'warning',
  203. duration: 3000
  204. })
  205. }
  206. }).catch(error => {
  207. this.$notify({
  208. title: '提示',
  209. message: error.message,
  210. type: 'error',
  211. duration: 3000
  212. })
  213. })
  214. },
  215. handleVideoResource(index, row) {
  216. const videoId = row.videoId
  217. getVideoResource(videoId).then(resp => {
  218. if (resp.code === 0) {
  219. this.videoResources = resp.data
  220. }
  221. })
  222. },
  223. handleAdd(index, row) {
  224. this.showEditScopeDialog = true
  225. },
  226. handleEdit(index, row) {
  227. this.updateNameForm.camId = row.camId
  228. this.showUpdateDialog = true
  229. },
  230. handleDetail(index, row) {
  231. getCamPushUrl(row.camId).then(resp => {
  232. if (resp.code === 0) {
  233. this.pushUrl = resp.data
  234. this.showDetailDialog = true
  235. }
  236. })
  237. },
  238. handleDelete(index, row) {
  239. this.$confirm('确定要删除 ' + row.title + '?', '提示', {
  240. confirmButtonText: '确定',
  241. cancelButtonText: '取消',
  242. type: 'warning'
  243. }).then(() => {
  244. deleteCam(row.camId).then(resp => {
  245. if (resp.code === 0) {
  246. this.$notify({
  247. title: '提示',
  248. message: '摄像头已删除',
  249. type: 'warning',
  250. duration: 3000
  251. })
  252. this.$router.go(0)
  253. }
  254. })
  255. }).catch(() => {
  256. this.$message({
  257. type: 'info',
  258. message: '已取消'
  259. })
  260. })
  261. },
  262. onAddCam() {
  263. this.showEditScopeDialog = false
  264. addCam(this.addCamForm).then(resp => {
  265. if (resp.code === 0) {
  266. this.addCamForm = {
  267. deviceId: null,
  268. deviceName: null
  269. }
  270. this.$notify({
  271. title: '提示',
  272. message: '摄像头已添加',
  273. type: 'warning',
  274. duration: 3000
  275. })
  276. }
  277. }).catch(error => {
  278. this.$notify({
  279. title: '提示',
  280. message: error.message,
  281. type: 'warning',
  282. duration: 3000
  283. })
  284. })
  285. },
  286. onUpdateCam() {
  287. this.showUpdateDialog = false
  288. updateCamName(this.updateNameForm).then(resp => {
  289. if (resp.code === 0) {
  290. this.$notify({
  291. title: '提示',
  292. message: '摄像头名字已更新',
  293. type: 'warning',
  294. duration: 3000
  295. })
  296. }
  297. }).catch(error => {
  298. this.$notify({
  299. title: '提示',
  300. message: error.message,
  301. type: 'warning',
  302. duration: 3000
  303. })
  304. })
  305. }
  306. }
  307. }
  308. </script>
  309. <style>
  310. </style>