chooseChannelForGb.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <div id="chooseChannelForGb" >
  3. <div style="background-color: #FFFFFF; margin-bottom: 1rem; position: relative; padding: 0.5rem; text-align: left;font-size: 14px;">
  4. 搜索: <el-input @input="search" style="margin-right: 1rem; width: auto;" size="mini" placeholder="关键字" prefix-icon="el-icon-search" v-model="searchSrt" clearable> </el-input>
  5. 通道类型: <el-select size="mini" @change="search" style="margin-right: 1rem; width:6rem" v-model="channelType" placeholder="请选择" default-first-option>
  6. <el-option label="全部" value=""></el-option>
  7. <el-option label="设备" value="false"></el-option>
  8. <el-option label="子目录" value="true"></el-option>
  9. </el-select>
  10. 选择状态: <el-select size="mini" style="margin-right: 1rem; width:6rem" v-model="choosed" @change="search" placeholder="请选择" default-first-option>
  11. <el-option label="全部" value=""></el-option>
  12. <el-option label="已选择" value="true"></el-option>
  13. <el-option label="未选择" value="false"></el-option>
  14. </el-select>
  15. 在线状态: <el-select size="mini" style="margin-right: 1rem; width:6rem" @change="search" v-model="online" placeholder="请选择" default-first-option>
  16. <el-option label="全部" value=""></el-option>
  17. <el-option label="在线" value="true"></el-option>
  18. <el-option label="离线" value="false"></el-option>
  19. </el-select>
  20. <el-checkbox @change="shareAllCheckedChange">全部共享</el-checkbox>
  21. </div>
  22. <el-table ref="gbChannelsTable" :data="gbChannels" border style="width: 100%" @selection-change="checkedChange" >
  23. <el-table-column type="selection" width="55" align="center" fixed > </el-table-column>
  24. <el-table-column prop="channelId" label="通道编号" width="210">
  25. </el-table-column>
  26. <el-table-column prop="name" label="通道名称" show-overflow-tooltip>
  27. </el-table-column>
  28. <el-table-column prop="deviceId" label="设备编号" width="210" >
  29. </el-table-column>
  30. <el-table-column label="设备地址" width="180" align="center">
  31. <template slot-scope="scope">
  32. <div slot="reference" class="name-wrapper">
  33. <el-tag size="medium">{{ scope.row.hostAddress }}</el-tag>
  34. </div>
  35. </template>
  36. </el-table-column>
  37. <el-table-column prop="manufacturer" label="厂家" align="center">
  38. </el-table-column>
  39. </el-table>
  40. <el-pagination style="float: right;margin-top: 1rem;" @size-change="handleSizeChange" @current-change="currentChange" :current-page="currentPage" :page-size="count" :page-sizes="[10, 20, 30, 50]" layout="total, sizes, prev, pager, next" :total="total">
  41. </el-pagination>
  42. </div>
  43. </template>
  44. <script>
  45. export default {
  46. name: 'chooseChannelForGb',
  47. computed: {
  48. // getPlayerShared: function () {
  49. // return {
  50. // sharedUrl: window.location.host + '/' + this.videoUrl,
  51. // sharedIframe: '<iframe src="' + window.location.host + '/' + this.videoUrl + '"></iframe>',
  52. // sharedRtmp: this.videoUrl
  53. // };
  54. // }
  55. },
  56. props: ['platformId', 'updateChoosedCallback'],
  57. created() {
  58. this.initData();
  59. },
  60. data() {
  61. return {
  62. gbChannels: [],
  63. gbChoosechannel:{},
  64. searchSrt: "",
  65. channelType: "",
  66. online: "",
  67. choosed: "",
  68. catalogId: null,
  69. currentPage: 1,
  70. count: 10,
  71. total: 0,
  72. eventEnanle: false
  73. };
  74. },
  75. watch:{
  76. platformId(newData, oldData){
  77. console.log(newData)
  78. this.initData()
  79. },
  80. },
  81. methods: {
  82. initData: function() {
  83. this.getChannelList();
  84. },
  85. currentChange: function (val) {
  86. this.currentPage = val;
  87. this.initData();
  88. },
  89. handleSizeChange: function (val) {
  90. this.count = val;
  91. console.log(val)
  92. this.initData();
  93. },
  94. rowcheckedChange: function (val, row) {
  95. console.log(val)
  96. console.log(row)
  97. },
  98. // selectDisable: function (){
  99. // if (this.catalogId == null) {
  100. // return false;
  101. // }
  102. // },
  103. checkedChange: function (val) {
  104. let that = this;
  105. if (!that.eventEnanle) {
  106. return;
  107. }
  108. let newData = {};
  109. let addData = [];
  110. let delData = [];
  111. if (val.length > 0) {
  112. for (let i = 0; i < val.length; i++) {
  113. const element = val[i];
  114. let key = element.deviceId + "_" + element.channelId;
  115. newData[key] = element;
  116. if (!!!that.gbChoosechannel[key]){
  117. addData.push(element)
  118. }else{
  119. delete that.gbChoosechannel[key]
  120. }
  121. }
  122. let oldKeys = Object.keys(that.gbChoosechannel);
  123. if (oldKeys.length > 0) {
  124. for (let i = 0; i < oldKeys.length; i++) {
  125. const key = oldKeys[i];
  126. delData.push(that.gbChoosechannel[key])
  127. }
  128. }
  129. }else{
  130. let oldKeys = Object.keys(that.gbChoosechannel);
  131. if (oldKeys.length > 0) {
  132. for (let i = 0; i < oldKeys.length; i++) {
  133. const key = oldKeys[i];
  134. delData.push(that.gbChoosechannel[key])
  135. }
  136. }
  137. }
  138. that.gbChoosechannel = newData;
  139. if (Object.keys(addData).length >0) {
  140. that.$axios({
  141. method:"post",
  142. url:"/api/platform/update_channel_for_gb",
  143. data:{
  144. platformId: that.platformId,
  145. channelReduces: addData,
  146. catalogId: that.catalogId
  147. }
  148. }).then((res)=>{
  149. console.log("保存成功")
  150. if(that.updateChoosedCallback)that.updateChoosedCallback(that.catalogId)
  151. }).catch(function (error) {
  152. console.log(error);
  153. });
  154. }
  155. if (delData.length >0) {
  156. that.$axios({
  157. method:"delete",
  158. url:"/api/platform/del_channel_for_gb",
  159. data:{
  160. platformId: that.platformId,
  161. channelReduces: delData
  162. }
  163. }).then((res)=>{
  164. console.log("移除成功")
  165. let nodeIds = new Array();
  166. for (let i = 0; i < delData.length; i++) {
  167. nodeIds.push(delData[i].channelId)
  168. }
  169. if(that.updateChoosedCallback)that.updateChoosedCallback(null, nodeIds)
  170. }).catch(function (error) {
  171. console.log(error);
  172. });
  173. }
  174. },
  175. shareAllCheckedChange: function (val) {
  176. this.chooseChanage(null, val)
  177. },
  178. getChannelList: function () {
  179. let that = this;
  180. this.$axios({
  181. method:"get",
  182. url:`/api/platform/channel_list`,
  183. params: {
  184. page: that.currentPage,
  185. count: that.count,
  186. query: that.searchSrt,
  187. online: that.online,
  188. choosed: that.choosed,
  189. platformId: that.platformId,
  190. channelType: that.channelType
  191. }
  192. })
  193. .then(function (res) {
  194. that.total = res.data.total;
  195. that.gbChannels = res.data.list;
  196. that.gbChoosechannel = {};
  197. // 防止出现表格错位
  198. that.$nextTick(() => {
  199. that.$refs.gbChannelsTable.doLayout();
  200. // 默认选中
  201. var chooseGBS = [];
  202. for (let i = 0; i < res.data.list.length; i++) {
  203. const row = res.data.list[i];
  204. console.log(row.platformId)
  205. if (row.platformId == that.platformId) {
  206. that.$refs.gbChannelsTable.toggleRowSelection(row, true);
  207. chooseGBS.push(row)
  208. that.gbChoosechannel[row.deviceId+ "_" + row.channelId] = row;
  209. }
  210. }
  211. that.eventEnanle = true;
  212. // that.checkedChange(chooseGBS)
  213. })
  214. console.log(that.gbChoosechannel)
  215. })
  216. .catch(function (error) {
  217. console.log(error);
  218. });
  219. },
  220. search: function() {
  221. this.initData();
  222. },
  223. handleGBSelectionChange: function() {
  224. this.initData();
  225. },
  226. catalogIdChange: function(id) {
  227. this.catalogId = id;
  228. console.log("通道选择模块收到: " + id)
  229. },
  230. }
  231. };
  232. </script>
  233. <style>
  234. </style>