DeviceList.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <div>
  3. <div class="box box-primary">
  4. <div class="box-header">
  5. <h4 class="text-primary text-center">设备列表</h4>
  6. </div>
  7. <div class="box-body">
  8. <form class="form-inline" autocomplete="off" spellcheck="false">
  9. <div class="form-group form-group-sm">
  10. <label>搜索</label>
  11. <input type="text" class="form-control" placeholder="关键字" v-model.trim="q" @keydown.enter.prevent ref="q">
  12. </div>
  13. <span class="hidden-xs">&nbsp;&nbsp;</span>
  14. <div class="form-group form-group-sm">
  15. <label>在线状态</label>
  16. <select class="form-control" v-model.trim="online">
  17. <option value="">全部</option>
  18. <option value="true">在线</option>
  19. <option value="false">离线</option>
  20. </select>
  21. </div>
  22. <!-- <div class="form-group pull-right">
  23. <router-link :to="`/devices/tree`" class="btn btn-default btn-sm">
  24. <i class="fa fa-sitemap"></i> 树视图
  25. </router-link>
  26. </div> -->
  27. </form>
  28. <br>
  29. <div class="clearfix"></div>
  30. <el-table :data="devices" stripe :default-sort="{prop: 'ID', order: 'ascending'}" @sort-change="sortChange">
  31. <el-table-column prop="ID" label="设备国标编号" min-width="200" sortable="custom" v-if="hasAnyRole(serverInfo, userInfo, '管理员')">
  32. <template slot-scope="props">
  33. <span>{{props.row.ID}}</span>
  34. </template>
  35. </el-table-column>
  36. <el-table-column label="操作" :min-width="hasAnyRole(serverInfo, userInfo, '管理员') ? 240 : 120" v-if="isMobile()">
  37. <template slot-scope="props">
  38. <div class="btn-group btn-group-xs">
  39. <router-link class="btn btn-info" :to="`/devices/channels/${props.row.ID}/1`" v-if="props.row.ChannelCount > 0">
  40. 查看通道
  41. </router-link>
  42. <button type="button" class="btn btn-primary" @click.prevent="fetchCatalog(props.row)" v-if="props.row.Online && hasAnyRole(serverInfo, userInfo, '管理员')">
  43. <i class="fa fa-refresh"></i> 更新通道
  44. </button>
  45. <button type="button" class="btn btn-warning" @click.prevent="editDevice(props.row)" v-if="hasAnyRole(serverInfo, userInfo, '管理员')">
  46. <i class="fa fa-edit"></i> 编辑
  47. </button>
  48. <button type="button" class="btn btn-danger" @click.prevent="removeDevice(props.row)" v-if="!props.row.Online && hasAnyRole(serverInfo, userInfo, '管理员')">
  49. <i class="fa fa-remove"></i> 删除
  50. </button>
  51. </div>
  52. </template>
  53. </el-table-column>
  54. <el-table-column prop="Name" label="名称" min-width="140" :formatter="formatName" show-overflow-tooltip></el-table-column>
  55. <el-table-column prop="CommandTransport" label="信令传输" min-width="120" :formatter="formatName" v-if="hasAnyRole(serverInfo, userInfo, '管理员')" show-overflow-tooltip></el-table-column>
  56. <el-table-column prop="MediaTransport" label="流传输模式" min-width="140" v-if="hasAnyRole(serverInfo, userInfo, '管理员')">
  57. <template slot-scope="props">
  58. <el-dropdown size="small" trigger="click" v-if="hasAnyRole(serverInfo, userInfo, '管理员')" @command="setMediaTransport">
  59. <span class="el-dropdown-link">
  60. {{formatTransport(props.row)}} <i class="el-icon-arrow-down el-icon--right"></i>
  61. </span>
  62. <el-dropdown-menu slot="dropdown">
  63. <el-dropdown-item :command="{row: props.row, MediaTransport: 'UDP', MediaTransportMode: 'passive'}">UDP</el-dropdown-item>
  64. <el-dropdown-item :command="{row: props.row, MediaTransport: 'TCP', MediaTransportMode: 'passive'}">TCP 被动</el-dropdown-item>
  65. <el-dropdown-item :command="{row: props.row, MediaTransport: 'TCP', MediaTransportMode: 'active'}">TCP 主动</el-dropdown-item>
  66. </el-dropdown-menu>
  67. </el-dropdown>
  68. <span v-else>{{formatTransport(props.row)}}</span>
  69. </template>
  70. </el-table-column>
  71. <el-table-column prop="ChannelCount" label="通道数" min-width="100" sortable="custom" v-if="hasAnyRole(serverInfo, userInfo, '管理员')"></el-table-column>
  72. <el-table-column prop="Online" label="在线状态" min-width="100">
  73. <template slot-scope="props">
  74. <span class="text-success" v-if="props.row.Online">在线</span>
  75. <span class="text-gray" v-else>离线</span>
  76. </template>
  77. </el-table-column>
  78. <el-table-column prop="RemoteIP" label="出口IP" min-width="140" v-if="hasAnyRole(serverInfo, userInfo, '管理员')"></el-table-column>
  79. <el-table-column prop="RemotePort" label="端口" min-width="100" v-if="hasAnyRole(serverInfo, userInfo, '管理员')"></el-table-column>
  80. <el-table-column prop="Manufacturer" label="厂家" min-width="120" :formatter="formatName" show-overflow-tooltip></el-table-column>
  81. <el-table-column prop="LastKeepaliveAt" label="最近心跳" min-width="160" v-if="hasAnyRole(serverInfo, userInfo, '管理员')" sortable="custom"></el-table-column>
  82. <el-table-column prop="LastRegisterAt" label="最近注册" min-width="160" v-if="hasAnyRole(serverInfo, userInfo, '管理员')" sortable="custom"></el-table-column>
  83. <el-table-column prop="UpdatedAt" label="更新时间" min-width="160" v-if="hasAnyRole(serverInfo, userInfo, '管理员')" sortable="custom"></el-table-column>
  84. <el-table-column prop="CreatedAt" label="创建时间" min-width="160" v-if="hasAnyRole(serverInfo, userInfo, '管理员')" sortable="custom"></el-table-column>
  85. <el-table-column label="操作" :min-width="hasAnyRole(serverInfo, userInfo, '管理员') ? 240 : 120" fixed="right" v-if="!isMobile()">
  86. <template slot-scope="props">
  87. <div class="btn-group btn-group-xs">
  88. <router-link class="btn btn-info" :to="`/devices/channels/${props.row.ID}/1`" v-if="props.row.ChannelCount > 0">
  89. <i class="fa fa-info"></i> 查看通道
  90. </router-link>
  91. <button type="button" class="btn btn-primary" @click.prevent="fetchCatalog(props.row)" v-if="props.row.Online && hasAnyRole(serverInfo, userInfo, '管理员')">
  92. <i class="fa fa-refresh"></i> 更新通道
  93. </button>
  94. <button type="button" class="btn btn-warning" @click.prevent="editDevice(props.row)" v-if="hasAnyRole(serverInfo, userInfo, '管理员')">
  95. <i class="fa fa-edit"></i> 编辑
  96. </button>
  97. <button type="button" class="btn btn-danger" @click.prevent="removeDevice(props.row)" v-if="!props.row.Online && hasAnyRole(serverInfo, userInfo, '管理员')">
  98. <i class="fa fa-remove"></i> 删除
  99. </button>
  100. </div>
  101. </template>
  102. </el-table-column>
  103. </el-table>
  104. </div>
  105. <div class="box-footer" v-if="total > 0">
  106. <el-pagination layout="total,prev,pager,next" :pager-count="5" class="pull-right" :total="total" :page-size.sync="pageSize" :current-page.sync="currentPage"></el-pagination>
  107. </div>
  108. </div>
  109. <div class="alert text-center" v-if="serverInfo.IsDemo">
  110. <small>
  111. <strong><i class="fa fa-info-circle"></i> 提示 : </strong>
  112. 可向 Redis 订阅 device 消息以获取设备实时状态 > SUBSCRIBE device; 消息内容为 "设备国标编号 ON/OFF"
  113. </small>
  114. </div>
  115. <DeviceEditDlg ref="deviceEditDlg" @submit="getDeviceList"></DeviceEditDlg>
  116. </div>
  117. </template>
  118. <script>
  119. import _ from "lodash";
  120. import url from "url";
  121. import DeviceEditDlg from 'components/DeviceEditDlg.vue'
  122. import { mapState } from "vuex"
  123. export default {
  124. props: {},
  125. data() {
  126. return {
  127. q: "",
  128. online: "",
  129. total: 0,
  130. pageSize: 10,
  131. currentPage: 1,
  132. sort: "ID",
  133. order: "asc",
  134. devices: [],
  135. loading: false,
  136. timer: 0
  137. };
  138. },
  139. components: {
  140. DeviceEditDlg
  141. },
  142. computed: {
  143. ...mapState(["userInfo", "serverInfo"])
  144. },
  145. mounted() {
  146. // this.$refs["q"].focus();
  147. // this.getDeviceList();
  148. this.timer = setInterval(() => {
  149. this.getDeviceList();
  150. }, 3000);
  151. },
  152. beforeDestroy() {
  153. if (this.timer) {
  154. clearInterval(this.timer);
  155. this.timer = 0;
  156. }
  157. },
  158. watch: {
  159. q: function(newVal, oldVal) {
  160. this.doDelaySearch();
  161. },
  162. online: function(newVal, oldVal) {
  163. this.doSearch();
  164. },
  165. currentPage: function(newVal, oldVal) {
  166. this.doSearch(newVal);
  167. },
  168. },
  169. methods: {
  170. isMobile() {
  171. return videojs.browser.IS_IOS || videojs.browser.IS_ANDROID;
  172. },
  173. doSearch(page = 1) {
  174. var query = {};
  175. if (this.q) query["q"] = this.q;
  176. if (this.online) query["online"] = this.online;
  177. this.$router.replace({
  178. path: `/devices/${page}`,
  179. query: query
  180. });
  181. },
  182. doDelaySearch: _.debounce(function() {
  183. this.doSearch();
  184. }, 500),
  185. getDeviceList() {
  186. this.loading = true;
  187. $.get("/api/v1/device/list", {
  188. q: this.q,
  189. start: (this.currentPage -1) * this.pageSize,
  190. limit: this.pageSize,
  191. online: this.online,
  192. sort: this.sort,
  193. order: this.order
  194. })
  195. .then(ret => {
  196. this.total = ret["DeviceCount"];
  197. this.devices = ret["DeviceList"];
  198. })
  199. .always(() => {
  200. this.loading = false;
  201. });
  202. },
  203. sortChange(data) {
  204. this.sort = data.prop;
  205. this.order = data.order == "ascending" ? "asc" : "desc";
  206. this.getDeviceList();
  207. },
  208. fetchCatalog(row) {
  209. $.ajax("/api/v1/device/fetchcatalog", {
  210. global: false,
  211. data: {
  212. serial: row.ID
  213. }
  214. }).then(() => {
  215. this.$message({
  216. type: "success",
  217. message: "更新通道信息成功"
  218. })
  219. })
  220. },
  221. removeDevice(row) {
  222. this.$confirm(`确认删除 ${row.Name || row.ID}`, "提示").then(() => {
  223. $.get("/api/v1/device/remove", {
  224. serial: row.ID
  225. }).always(() => {
  226. this.getDeviceList();
  227. });
  228. }).catch(() => {});
  229. },
  230. editDevice(row) {
  231. this.$refs["deviceEditDlg"].show({
  232. serial: row.ID,
  233. name: row.Name,
  234. media_transport: row.MediaTransport,
  235. media_transport_mode: row.MediaTransportMode,
  236. recv_stream_ip: row.RecvStreamIP,
  237. contact_ip: row.ContactIP,
  238. sms_id: row.SMSID,
  239. charset: row.Charset,
  240. catalog_interval: row.CatalogInterval,
  241. subscribe_interval: row.SubscribeInterval,
  242. password: row.Password,
  243. });
  244. },
  245. formatName(row, col, cell) {
  246. if (cell) return cell;
  247. return "-";
  248. },
  249. formatTransport(row, col, cell) {
  250. var ret = String(row.MediaTransport).toUpperCase();
  251. if(ret == "TCP") {
  252. ret += row.MediaTransportMode == 'active' ? " 主动" : " 被动";
  253. }
  254. return ret;
  255. },
  256. setMediaTransport(cmd) {
  257. cmd.row.MediaTransport = cmd.MediaTransport || cmd.row.MediaTransport;
  258. cmd.row.MediaTransportMode = cmd.MediaTransportMode || cmd.row.MediaTransportMode;
  259. $.get("/api/v1/device/setmediatransport", {
  260. serial: cmd.row.ID,
  261. media_transport: cmd.row.MediaTransport,
  262. media_transport_mode: cmd.row.MediaTransportMode
  263. })
  264. }
  265. },
  266. beforeRouteEnter(to, from, next) {
  267. next(vm => {
  268. vm.q = to.query.q || "";
  269. vm.online = to.query.online || "";
  270. vm.currentPage = parseInt(to.params.page) || 1;
  271. });
  272. },
  273. beforeRouteLeave(to, from, next) {
  274. if (this.timer) {
  275. clearInterval(this.timer);
  276. this.timer = 0;
  277. }
  278. next();
  279. },
  280. beforeRouteUpdate(to, from, next) {
  281. next();
  282. this.$nextTick(() => {
  283. this.q = to.query.q || "";
  284. this.online = to.query.online || "";
  285. this.currentPage = parseInt(to.params.page) || 1;
  286. this.devices = [];
  287. this.getDeviceList();
  288. });
  289. }
  290. };
  291. </script>