ScreenChannelListDlg.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <div :class="['modal', {fade: fade}]" data-backdrop="static" data-disable="false" data-keyboard="true" tabindex="-1">
  3. <div :class="['modal-dialog', size]">
  4. <div class="modal-content">
  5. <div class="modal-header">
  6. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  7. <span aria-hidden="true">&times;</span>
  8. </button>
  9. <h4 class="modal-title text-center text-primary"><span>{{title}}</span></h4>
  10. </div>
  11. <div class="modal-body">
  12. <form class="form-inline" autocomplete="off" spellcheck="false">
  13. <div class="form-group form-group-sm">
  14. <label>搜索</label>
  15. <input type="text" class="form-control" placeholder="关键字" v-model.trim="q" @keydown.enter.prevent ref="q">
  16. </div>
  17. </form>
  18. <br>
  19. <el-table :data="channels" stripe @sort-change="sortChange" :max-height="500" @row-click="rowClick" :row-style="rowStyle"
  20. ref="channelTable" v-loading="loading" element-loading-text="加载中...">
  21. <el-table-column prop="DeviceID" label="设备国标编号" min-width="200" show-overflow-tooltip sortable="custom" v-if="hasAnyRole(serverInfo, userInfo, '管理员')" :fixed="!isMobile()"></el-table-column>
  22. <el-table-column prop="ID" label="通道国标编号" min-width="200" show-overflow-tooltip sortable="custom" v-if="hasAnyRole(serverInfo, userInfo, '管理员')" :fixed="!isMobile()"></el-table-column>
  23. <el-table-column prop="Name" label="通道名称" min-width="120" :formatter="formatName" show-overflow-tooltip></el-table-column>
  24. <el-table-column prop="Status" label="在线状态" min-width="100">
  25. <template slot-scope="props">
  26. <span v-if="props.row.SubCount > 0">-</span>
  27. <span v-else-if="props.row.Status == 'ON'" class="text-success">在线</span>
  28. <span v-else>离线</span>
  29. </template>
  30. </el-table-column>
  31. <el-table-column prop="SubCount" label="子节点数" min-width="100" v-if="hasAnyRole(serverInfo, userInfo, '管理员')" sortable="custom"></el-table-column>
  32. <el-table-column prop="Manufacturer" label="厂家" min-width="120" :formatter="formatManufacturer" show-overflow-tooltip></el-table-column>
  33. </el-table>
  34. <el-pagination v-if="total > 0" layout="total,prev,pager,next" :pager-count="5" class="pull-right" :total="total" :page-size.sync="pageSize" :current-page.sync="currentPage"></el-pagination>
  35. <div class="clearfix"></div>
  36. </div>
  37. <div class="modal-footer">
  38. <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
  39. </div>
  40. </div>
  41. <!-- /.modal-content -->
  42. </div>
  43. <!-- /.modal-dialog -->
  44. </div>
  45. </template>
  46. <script>
  47. import _ from 'lodash'
  48. import $ from 'jquery'
  49. import "jquery-ui/ui/widgets/draggable"
  50. import { mapState } from "vuex"
  51. export default {
  52. props: {
  53. title: {
  54. default: ''
  55. },
  56. size: {
  57. type: String,
  58. default: 'modal-lg'
  59. },
  60. fade: {
  61. type: Boolean,
  62. default: false
  63. }
  64. },
  65. data() {
  66. return {
  67. q: "",
  68. total: 0,
  69. pageSize: 10,
  70. currentPage: 1,
  71. sort: "",
  72. order: "",
  73. loading: false,
  74. channels: [],
  75. index: 0,
  76. };
  77. },
  78. computed: {
  79. ...mapState(["userInfo", "serverInfo"])
  80. },
  81. watch: {
  82. q: function(newVal, oldVal) {
  83. this.doDelaySearch();
  84. },
  85. currentPage: function(newVal, oldVal) {
  86. this.doSearch(newVal);
  87. },
  88. pageSize: function(newVal, oldVal) {
  89. this.doSearch();
  90. }
  91. },
  92. mounted() {
  93. $(this.$el).find('.modal-content').draggable({
  94. handle: '.modal-header',
  95. cancel: ".modal-title span",
  96. addClasses: false,
  97. containment: 'document',
  98. delay: 100,
  99. opacity: 0.5
  100. });
  101. $(this.$el).on("shown.bs.modal", () => {
  102. this.$emit("show");
  103. }).on("hidden.bs.modal", () => {
  104. this.errors.clear();
  105. // this.reset();
  106. this.$emit("hide");
  107. })
  108. },
  109. methods: {
  110. sortChange(data) {
  111. this.sort = data.prop;
  112. this.order = data.order == "ascending" ? "asc" : "desc";
  113. this.getChannels();
  114. },
  115. doSearch(page = 1) {
  116. this.currentPage = page;
  117. this.getChannels();
  118. },
  119. doDelaySearch: _.debounce(function() {
  120. this.doSearch();
  121. }, 500),
  122. formatName(row, col, cell) {
  123. return row.CustomName || row.Name || "-";
  124. },
  125. formatManufacturer(row, col, cell) {
  126. if (cell) return cell;
  127. return "-";
  128. },
  129. getChannels() {
  130. this.loading = true;
  131. $.get("/api/v1/device/channellist", {
  132. q: this.q,
  133. start: (this.currentPage -1) * this.pageSize,
  134. limit: this.pageSize,
  135. channel_type: "device",
  136. online: "true",
  137. sort: this.sort,
  138. order: this.order
  139. }).then(ret => {
  140. this.total = ret.ChannelCount;
  141. this.channels = ret.ChannelList || [];
  142. }).always(() => {
  143. this.loading = false;
  144. });
  145. },
  146. rowClick(row, event, column) {
  147. if(row.Status !== "ON") return;
  148. this.$emit("selected", this.index, row);
  149. this.hide();
  150. },
  151. rowStyle({row, rowIndex}) {
  152. if(row.Status === "ON") {
  153. return "cursor:pointer";
  154. }
  155. return "";
  156. },
  157. reset() {
  158. this.index = 0;
  159. this.channels = [];
  160. this.q = "";
  161. this.currentPage = 1;
  162. this.pageSize = 10;
  163. },
  164. show(index) {
  165. this.index = index;
  166. $(this.$el).modal("show");
  167. this.getChannels();
  168. },
  169. hide() {
  170. $(this.$el).modal("hide");
  171. },
  172. }
  173. };
  174. </script>
  175. <style lang="less" scoped>
  176. label.el-switch {
  177. margin-bottom: -10px;
  178. }
  179. </style>