DeviceList.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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" show-overflow-tooltip>
  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, '管理员')" show-overflow-tooltip></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="isMobile() ? 3 : 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. methods: {
  159. ready() {
  160. this.$watch('q', function(newVal, oldVal) {
  161. this.doDelaySearch();
  162. });
  163. this.$watch('online', function(newVal, oldVal) {
  164. this.doSearch();
  165. });
  166. this.$watch('currentPage', function(newVal, oldVal) {
  167. this.doSearch(newVal);
  168. });
  169. this.timer = setInterval(() => {
  170. this.getDeviceList();
  171. }, 3000);
  172. },
  173. isMobile() {
  174. return videojs.browser.IS_IOS || videojs.browser.IS_ANDROID;
  175. },
  176. doSearch(page = 1) {
  177. var query = {};
  178. if (this.q) query["q"] = this.q;
  179. if (this.online) query["online"] = this.online;
  180. this.$router.replace({
  181. path: `/devices/${page}`,
  182. query: query
  183. });
  184. },
  185. doDelaySearch: _.debounce(function() {
  186. this.doSearch();
  187. }, 500),
  188. getDeviceList() {
  189. this.loading = true;
  190. $.get("/api/v1/device/list", {
  191. q: this.q,
  192. start: (this.currentPage -1) * this.pageSize,
  193. limit: this.pageSize,
  194. online: this.online,
  195. sort: this.sort,
  196. order: this.order
  197. })
  198. .then(ret => {
  199. this.total = ret["DeviceCount"];
  200. this.devices = ret["DeviceList"];
  201. })
  202. .always(() => {
  203. this.loading = false;
  204. });
  205. },
  206. sortChange(data) {
  207. this.sort = data.prop;
  208. this.order = data.order == "ascending" ? "asc" : "desc";
  209. this.getDeviceList();
  210. },
  211. fetchCatalog(row) {
  212. $.ajax("/api/v1/device/fetchcatalog", {
  213. global: false,
  214. data: {
  215. serial: row.ID
  216. }
  217. }).then(() => {
  218. this.$message({
  219. type: "success",
  220. message: "更新通道信息成功"
  221. })
  222. })
  223. },
  224. removeDevice(row) {
  225. this.$confirm(`确认删除 ${row.Name || row.ID}`, "提示").then(() => {
  226. $.get("/api/v1/device/remove", {
  227. serial: row.ID
  228. }).always(() => {
  229. this.getDeviceList();
  230. });
  231. }).catch(() => {});
  232. },
  233. editDevice(row) {
  234. this.$refs["deviceEditDlg"].show({
  235. serial: row.ID,
  236. name: row.Name,
  237. media_transport: row.MediaTransport,
  238. media_transport_mode: row.MediaTransportMode,
  239. recv_stream_ip: row.RecvStreamIP,
  240. contact_ip: row.ContactIP,
  241. sms_id: row.SMSID,
  242. charset: row.Charset,
  243. catalog_interval: row.CatalogInterval,
  244. subscribe_interval: row.SubscribeInterval,
  245. password: row.Password,
  246. record_center: row.RecordCenter,
  247. record_indistinct: row.RecordIndistinct,
  248. civil_code_first: row.CivilCodeFirst,
  249. });
  250. },
  251. formatName(row, col, cell) {
  252. if (cell) return cell;
  253. return "-";
  254. },
  255. formatTransport(row, col, cell) {
  256. var ret = String(row.MediaTransport).toUpperCase();
  257. if(ret == "TCP") {
  258. ret += row.MediaTransportMode == 'active' ? " 主动" : " 被动";
  259. }
  260. return ret;
  261. },
  262. setMediaTransport(cmd) {
  263. cmd.row.MediaTransport = cmd.MediaTransport || cmd.row.MediaTransport;
  264. cmd.row.MediaTransportMode = cmd.MediaTransportMode || cmd.row.MediaTransportMode;
  265. $.get("/api/v1/device/setmediatransport", {
  266. serial: cmd.row.ID,
  267. media_transport: cmd.row.MediaTransport,
  268. media_transport_mode: cmd.row.MediaTransportMode
  269. })
  270. }
  271. },
  272. beforeRouteEnter(to, from, next) {
  273. next(vm => {
  274. vm.q = to.query.q || "";
  275. vm.online = to.query.online || "";
  276. vm.currentPage = parseInt(to.params.page) || 1;
  277. vm.ready();
  278. });
  279. },
  280. beforeRouteLeave(to, from, next) {
  281. if (this.timer) {
  282. clearInterval(this.timer);
  283. this.timer = 0;
  284. }
  285. next();
  286. },
  287. beforeRouteUpdate(to, from, next) {
  288. next();
  289. this.$nextTick(() => {
  290. this.q = to.query.q || "";
  291. this.online = to.query.online || "";
  292. this.currentPage = parseInt(to.params.page) || 1;
  293. this.devices = [];
  294. this.getDeviceList();
  295. });
  296. }
  297. };
  298. </script>