chooseChannelForGb.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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="shareAllCheckedChanage">全部共享</el-checkbox>
  21. </div>
  22. <el-table ref="gbChannelsTable" :data="gbChannels" border style="width: 100%" @selection-change="checkedChanage" >
  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. props: {},
  48. computed: {
  49. // getPlayerShared: function () {
  50. // return {
  51. // sharedUrl: window.location.host + '/' + this.videoUrl,
  52. // sharedIframe: '<iframe src="' + window.location.host + '/' + this.videoUrl + '"></iframe>',
  53. // sharedRtmp: this.videoUrl
  54. // };
  55. // }
  56. },
  57. props: ['platformId'],
  58. created() {
  59. this.initData();
  60. },
  61. data() {
  62. return {
  63. gbChannels: [],
  64. gbChoosechannel:{},
  65. searchSrt: "",
  66. channelType: "",
  67. online: "",
  68. choosed: "",
  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. rowcheckedChanage: function (val, row) {
  95. console.log(val)
  96. console.log(row)
  97. },
  98. checkedChanage: function (val) {
  99. var that = this;
  100. if (!that.eventEnanle) {
  101. return;
  102. }
  103. var tabelData = JSON.parse(JSON.stringify(this.$refs.gbChannelsTable.data));
  104. console.log("checkedChanage")
  105. console.log(val)
  106. var newData = {};
  107. var addData = [];
  108. var delData = [];
  109. if (val.length > 0) {
  110. for (let i = 0; i < val.length; i++) {
  111. const element = val[i];
  112. var key = element.deviceId + "_" + element.channelId;
  113. newData[key] = element;
  114. if (!!!that.gbChoosechannel[key]){
  115. addData.push(element)
  116. }else{
  117. delete that.gbChoosechannel[key]
  118. }
  119. }
  120. var oldKeys = Object.keys(that.gbChoosechannel);
  121. if (oldKeys.length > 0) {
  122. for (let i = 0; i < oldKeys.length; i++) {
  123. const key = oldKeys[i];
  124. delData.push(that.gbChoosechannel[key])
  125. }
  126. }
  127. }else{
  128. var oldKeys = Object.keys(that.gbChoosechannel);
  129. if (oldKeys.length > 0) {
  130. for (let i = 0; i < oldKeys.length; i++) {
  131. const key = oldKeys[i];
  132. delData.push(that.gbChoosechannel[key])
  133. }
  134. }
  135. }
  136. that.gbChoosechannel = newData;
  137. if (Object.keys(addData).length >0) {
  138. that.$axios({
  139. method:"post",
  140. url:"/api/platform/update_channel_for_gb",
  141. data:{
  142. platformId: that.platformId,
  143. channelReduces: addData
  144. }
  145. }).then((res)=>{
  146. console.log("保存成功")
  147. }).catch(function (error) {
  148. console.log(error);
  149. });
  150. }
  151. if (Object.keys(delData).length >0) {
  152. that.$axios({
  153. method:"delete",
  154. url:"/api/platform/del_channel_for_gb",
  155. data:{
  156. platformId: that.platformId,
  157. channelReduces: delData
  158. }
  159. }).then((res)=>{
  160. console.log("移除成功")
  161. }).catch(function (error) {
  162. console.log(error);
  163. });
  164. }
  165. },
  166. shareAllCheckedChanage: function (val) {
  167. this.chooseChanage(null, val)
  168. },
  169. getChannelList: function () {
  170. let that = this;
  171. this.$axios({
  172. method:"get",
  173. url:`/api/platform/channel_list`,
  174. params: {
  175. page: that.currentPage,
  176. count: that.count,
  177. query: that.searchSrt,
  178. online: that.online,
  179. choosed: that.choosed,
  180. platformId: that.platformId,
  181. channelType: that.channelType
  182. }
  183. })
  184. .then(function (res) {
  185. that.total = res.data.total;
  186. that.gbChannels = res.data.list;
  187. that.gbChoosechannel = {};
  188. // 防止出现表格错位
  189. that.$nextTick(() => {
  190. that.$refs.gbChannelsTable.doLayout();
  191. // 默认选中
  192. var chooseGBS = [];
  193. for (let i = 0; i < res.data.list.length; i++) {
  194. const row = res.data.list[i];
  195. console.log(row.platformId)
  196. if (row.platformId == that.platformId) {
  197. that.$refs.gbChannelsTable.toggleRowSelection(row, true);
  198. chooseGBS.push(row)
  199. that.gbChoosechannel[row.deviceId+ "_" + row.channelId] = row;
  200. }
  201. }
  202. that.eventEnanle = true;
  203. // that.checkedChanage(chooseGBS)
  204. })
  205. console.log(that.gbChoosechannel)
  206. })
  207. .catch(function (error) {
  208. console.log(error);
  209. });
  210. },
  211. search: function() {
  212. this.initData();
  213. },
  214. handleGBSelectionChange: function() {
  215. this.initData();
  216. },
  217. }
  218. };
  219. </script>
  220. <style>
  221. </style>