UserChannelListDlg.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. <span class="hidden-xs">&nbsp;&nbsp;</span>
  18. <div class="form-group form-group-sm">
  19. <label>通道类型</label>
  20. <select class="form-control" v-model.trim="channel_type">
  21. <option value="">全部</option>
  22. <option value="device">设备</option>
  23. <option value="dir">子目录</option>
  24. </select>
  25. </div>
  26. <span class="hidden-xs">&nbsp;&nbsp;</span>
  27. <div class="form-group form-group-sm">
  28. <div class="checkbox">
  29. <el-checkbox style="margin-top:-5px;padding-left:0;" size="small" v-model.trim="related" name="Related">
  30. 只看已选({{relateCnt}})
  31. </el-checkbox>
  32. </div>
  33. </div>
  34. <span class="hidden-xs">&nbsp;&nbsp;</span>
  35. <div class="form-group form-group-sm" v-if="!userInfo || userInfo.HasAllChannel">
  36. <div class="checkbox">
  37. <el-checkbox style="margin-top:-5px;padding-left:0;" size="small" v-model="hasAllChannel" @change="toggleHasAllChannel" name="HasAllChannel">全部关联</el-checkbox>
  38. </div>
  39. </div>
  40. </form>
  41. <br>
  42. <el-table :data="channels" stripe @sort-change="sortChange" @select="select" @select-all="selectAll" :max-height="500"
  43. ref="channelTable" v-loading="loading" element-loading-text="加载中...">
  44. <el-table-column type="selection" width="55" fixed :selectable="selectable"></el-table-column>
  45. <el-table-column prop="DeviceID" label="设备国标编号" min-width="200" show-overflow-tooltip sortable="custom"></el-table-column>
  46. <el-table-column prop="ID" label="通道国标编号" min-width="200" show-overflow-tooltip sortable="custom"></el-table-column>
  47. <el-table-column prop="Name" label="通道名称" min-width="120" :formatter="formatName" show-overflow-tooltip></el-table-column>
  48. <!-- <el-table-column prop="Status" label="在线状态" min-width="100">
  49. <template slot-scope="props">
  50. <span v-if="props.row.SubCount > 0">-</span>
  51. <span v-else-if="props.row.Status == 'ON'" class="text-success">在线</span>
  52. <span v-else>离线</span>
  53. </template>
  54. </el-table-column> -->
  55. <!-- <el-table-column prop="SubCount" label="子节点数" min-width="100" sortable="custom"></el-table-column> -->
  56. <el-table-column prop="Manufacturer" label="厂家" min-width="120" :formatter="formatManufacturer" show-overflow-tooltip></el-table-column>
  57. </el-table>
  58. <el-pagination v-if="total > 0" layout="total,prev,pager,next,sizes" :pager-count="5" class="pull-right" :total="total" :page-size.sync="pageSize" :current-page.sync="currentPage"></el-pagination>
  59. <div class="clearfix"></div>
  60. </div>
  61. <div class="modal-footer">
  62. <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. </template>
  68. <script>
  69. import 'jquery-ui/ui/widgets/draggable'
  70. import $ from 'jquery'
  71. import _ from "lodash";
  72. import { mapState } from "vuex"
  73. export default {
  74. props: {
  75. title: {
  76. default: ''
  77. },
  78. size: {
  79. type: String,
  80. default: ''
  81. },
  82. fade: {
  83. type: Boolean,
  84. default: false
  85. }
  86. },
  87. data() {
  88. return {
  89. q: "",
  90. channel_type: "",
  91. total: 0,
  92. relateCnt: 0,
  93. pageSize: 10,
  94. currentPage: 1,
  95. sort: "",
  96. order: "",
  97. related: false,
  98. hasAllChannel: false,
  99. loading: false,
  100. channels: [],
  101. selection: [],
  102. id: '', //外部关联id
  103. }
  104. },
  105. watch: {
  106. q: function(newVal, oldVal) {
  107. this.doDelaySearch();
  108. },
  109. channel_type: function(newVal, oldVal) {
  110. this.doSearch();
  111. },
  112. related: function(newVal, oldVal) {
  113. this.doSearch();
  114. },
  115. currentPage: function(newVal, oldVal) {
  116. this.doSearch(newVal);
  117. },
  118. pageSize: function(newVal, oldVal) {
  119. this.doSearch();
  120. }
  121. },
  122. computed: {
  123. ...mapState(['userInfo', 'serverInfo']),
  124. },
  125. mounted() {
  126. $(this.$el).find('.modal-content').draggable({
  127. handle: '.modal-header',
  128. cancel: ".modal-title span",
  129. addClasses: false,
  130. containment: 'document',
  131. delay: 100,
  132. opacity: 0.5
  133. });
  134. $(this.$el).on("shown.bs.modal", () => {
  135. this.$emit("show");
  136. }).on("hidden.bs.modal", () => {
  137. this.errors.clear();
  138. this.reset();
  139. this.$emit("hide");
  140. })
  141. },
  142. methods: {
  143. sortChange(data) {
  144. this.sort = data.prop;
  145. this.order = data.order == "ascending" ? "asc" : "desc";
  146. this.getChannels();
  147. },
  148. select(selection, row) {
  149. var idx = selection.indexOf(row);
  150. if(idx >= 0) {
  151. $.get("/api/v1/user/savechannels", {
  152. id: this.id,
  153. channels: [`${row.DeviceID}:${row.ID}`]
  154. }).always(() => {
  155. this.getChannels();
  156. })
  157. } else {
  158. $.get("/api/v1/user/removechannels", {
  159. id: this.id,
  160. channels: [`${row.DeviceID}:${row.ID}`]
  161. }).always(() => {
  162. this.getChannels();
  163. })
  164. }
  165. },
  166. selectAll(selection) {
  167. if(this.hasAllChannel) return;
  168. var keys = [];
  169. if(selection.length) {
  170. for(var row of selection) {
  171. var idx = this.selection.indexOf(row);
  172. if(idx < 0) {
  173. keys.push(`${row.DeviceID}:${row.ID}`)
  174. }
  175. }
  176. $.get("/api/v1/user/savechannels", {
  177. id: this.id,
  178. channels: keys,
  179. }).always(() => {
  180. this.getChannels();
  181. })
  182. } else {
  183. for(var row of this.selection) {
  184. keys.push(`${row.DeviceID}:${row.ID}`)
  185. }
  186. $.get("/api/v1/user/removechannels", {
  187. id: this.id,
  188. channels: keys,
  189. }).always(() => {
  190. this.getChannels();
  191. })
  192. }
  193. },
  194. doSearch(page = 1) {
  195. this.currentPage = page;
  196. this.getChannels();
  197. },
  198. doDelaySearch: _.debounce(function() {
  199. this.doSearch();
  200. }, 500),
  201. formatName(row, col, cell) {
  202. return row.CustomName || row.Name || "-";
  203. },
  204. formatManufacturer(row, col, cell) {
  205. if (cell) return cell;
  206. return "-";
  207. },
  208. selectable(row, index) {
  209. if(!this.hasAllChannel) {
  210. return true;
  211. }
  212. return false;
  213. },
  214. getChannels() {
  215. if(!this.id) return;
  216. this.loading = true;
  217. $.get("/api/v1/user/channellist", {
  218. id: this.id,
  219. q: this.q,
  220. start: (this.currentPage -1) * this.pageSize,
  221. limit: this.pageSize,
  222. channel_type: this.channel_type,
  223. related: this.related,
  224. sort: this.sort,
  225. order: this.order
  226. }).then(ret => {
  227. this.$refs["channelTable"].clearSelection();
  228. this.total = ret.ChannelCount;
  229. this.relateCnt = ret.ChannelRelateCount;
  230. this.hasAllChannel = !!ret.HasAllChannel;
  231. this.channels = ret.ChannelList || [];
  232. this.selection = [];
  233. this.$nextTick(() => {
  234. this.channels.forEach(row => {
  235. var sel = row.UserID !== 0;
  236. this.$refs["channelTable"].toggleRowSelection(row, sel);
  237. if(sel) {
  238. this.selection.push(row);
  239. }
  240. })
  241. })
  242. }).always(() => {
  243. this.loading = false;
  244. });
  245. },
  246. reset() {
  247. this.id = '';
  248. this.$refs["channelTable"].clearSelection();
  249. this.channels = [];
  250. this.selection = [];
  251. this.q = "";
  252. this.channel_type = "";
  253. this.related = false;
  254. this.hasAllChannel = false;
  255. this.currentPage = 1;
  256. this.pageSize = 10;
  257. },
  258. toggleHasAllChannel(val) {
  259. $.get("/api/v1/user/sethasallchannel", {
  260. id: this.id,
  261. hasallchannel: val,
  262. }).always(() => {
  263. this.doSearch();
  264. })
  265. },
  266. show(id) {
  267. this.id = id;
  268. $(this.$el).modal("show");
  269. this.getChannels();
  270. },
  271. hide() {
  272. $(this.$el).modal("hide");
  273. }
  274. }
  275. }
  276. </script>
  277. <style lang="less" scoped>
  278. label.el-switch {
  279. margin-bottom: -10px;
  280. }
  281. </style>