region.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <div id="region" style="width: 100%">
  3. <el-container v-loading="loading">
  4. <el-aside width="400px">
  5. <RegionTree ref="regionTree" :showHeader=true :edit="true" :clickEvent="treeNodeClickEvent"
  6. :onChannelChange="onChannelChange" :enableAddChannel="true" :addChannelToCivilCode="addChannelToCivilCode"></RegionTree>
  7. </el-aside>
  8. <el-main style="padding: 5px;">
  9. <div class="page-header">
  10. <div class="page-title">
  11. <el-breadcrumb separator="/" v-if="regionParents.length > 0">
  12. <el-breadcrumb-item v-for="key in regionParents" key="key">{{ key }}</el-breadcrumb-item>
  13. </el-breadcrumb>
  14. <div v-else style="color: #00c6ff">未选择行政区划</div>
  15. </div>
  16. <div class="page-header-btn">
  17. <div style="display: inline;">
  18. 搜索:
  19. <el-input @input="search" style="margin-right: 1rem; width: auto;" size="mini" placeholder="关键字"
  20. prefix-icon="el-icon-search" v-model="searchSrt" clearable></el-input>
  21. 在线状态:
  22. <el-select size="mini" style="width: 8rem; margin-right: 1rem;" @change="search" v-model="online"
  23. placeholder="请选择"
  24. default-first-option>
  25. <el-option label="全部" value=""></el-option>
  26. <el-option label="在线" value="true"></el-option>
  27. <el-option label="离线" value="false"></el-option>
  28. </el-select>
  29. 类型:
  30. <el-select size="mini" style="width: 8rem; margin-right: 1rem;" @change="getChannelList" v-model="channelType" placeholder="请选择"
  31. default-first-option>
  32. <el-option label="全部" value=""></el-option>
  33. <el-option label="国标设备" :value="0"></el-option>
  34. <el-option label="推流设备" :value="1"></el-option>
  35. <el-option label="拉流代理" :value="2"></el-option>
  36. </el-select>
  37. <el-button size="mini" type="primary" @click="add()">
  38. 添加通道
  39. </el-button>
  40. <el-button v-bind:disabled="multipleSelection.length === 0" size="mini" type="danger" @click="remove()">
  41. 移除通道
  42. </el-button>
  43. <el-button icon="el-icon-refresh-right" circle size="mini" @click="getChannelList()"></el-button>
  44. </div>
  45. </div>
  46. </div>
  47. <el-table size="medium" ref="channelListTable" :data="channelList" :height="winHeight" style="width: 100%"
  48. header-row-class-name="table-header" @selection-change="handleSelectionChange"
  49. @row-dblclick="rowDblclick">
  50. <el-table-column type="selection" width="55">
  51. </el-table-column>
  52. <el-table-column prop="gbName" label="名称" min-width="180">
  53. </el-table-column>
  54. <el-table-column prop="gbDeviceId" label="编号" min-width="180">
  55. </el-table-column>
  56. <el-table-column prop="gbManufacturer" label="厂家" min-width="100">
  57. </el-table-column>
  58. <el-table-column label="类型" min-width="100">
  59. <template v-slot:default="scope">
  60. <div slot="reference" class="name-wrapper">
  61. <el-tag size="medium" effect="plain" v-if="scope.row.gbDeviceDbId">国标设备</el-tag>
  62. <el-tag size="medium" effect="plain" type="success" v-if="scope.row.streamPushId">推流设备</el-tag>
  63. <el-tag size="medium" effect="plain" type="warning" v-if="scope.row.streamProxyId">拉流代理</el-tag>
  64. </div>
  65. </template>
  66. </el-table-column>
  67. <el-table-column label="状态" min-width="100">
  68. <template v-slot:default="scope">
  69. <div slot="reference" class="name-wrapper">
  70. <el-tag size="medium" v-if="scope.row.gbStatus === 'ON'">在线</el-tag>
  71. <el-tag size="medium" type="info" v-if="scope.row.gbStatus !== 'ON'">离线</el-tag>
  72. </div>
  73. </template>
  74. </el-table-column>
  75. </el-table>
  76. <el-pagination
  77. style="text-align: right"
  78. @size-change="handleSizeChange"
  79. @current-change="currentChange"
  80. :current-page="currentPage"
  81. :page-size="count"
  82. :page-sizes="[15, 25, 35, 50]"
  83. layout="total, sizes, prev, pager, next"
  84. :total="total">
  85. </el-pagination>
  86. </el-main>
  87. </el-container>
  88. <GbChannelSelect ref="gbChannelSelect" dataType="civilCode"></GbChannelSelect>
  89. </div>
  90. </template>
  91. <script>
  92. import uiHeader from '../layout/UiHeader.vue'
  93. import DeviceService from "./service/DeviceService";
  94. import RegionTree from "./common/RegionTree.vue";
  95. import GbChannelSelect from "./dialog/GbChannelSelect.vue";
  96. export default {
  97. name: 'channelList',
  98. components: {
  99. GbChannelSelect,
  100. uiHeader,
  101. RegionTree,
  102. },
  103. data() {
  104. return {
  105. channelList: [],
  106. searchSrt: "",
  107. channelType: "",
  108. online: "",
  109. winHeight: window.innerHeight - 180,
  110. currentPage: 1,
  111. count: 15,
  112. total: 0,
  113. loading: false,
  114. loadSnap: {},
  115. regionId: "",
  116. regionDeviceId: "",
  117. regionParents: [],
  118. multipleSelection: []
  119. };
  120. },
  121. created() {
  122. this.initData();
  123. },
  124. destroyed() {
  125. },
  126. methods: {
  127. initData: function () {
  128. this.getChannelList();
  129. },
  130. currentChange: function (val) {
  131. this.currentPage = val;
  132. this.initData();
  133. },
  134. handleSizeChange: function (val) {
  135. this.count = val;
  136. this.getChannelList();
  137. },
  138. getChannelList: function () {
  139. this.$axios({
  140. method: 'get',
  141. url: `/api/common/channel/civilcode/list`,
  142. params: {
  143. page: this.currentPage,
  144. count: this.count,
  145. query: this.searchSrt,
  146. online: this.online,
  147. channelType: this.channelType,
  148. civilCode: this.regionDeviceId
  149. }
  150. }).then((res) => {
  151. if (res.data.code === 0) {
  152. this.total = res.data.data.total;
  153. this.channelList = res.data.data.list;
  154. // 防止出现表格错位
  155. this.$nextTick(() => {
  156. this.$refs.channelListTable.doLayout();
  157. })
  158. }
  159. }).catch((error) => {
  160. console.log(error);
  161. });
  162. },
  163. handleSelectionChange: function (val) {
  164. this.multipleSelection = val;
  165. },
  166. rowDblclick: function (row, rowIndex) {
  167. // if (row.gbCivilCode) {
  168. // this.$refs.regionTree.refresh(row.gbCivilCode)
  169. // }
  170. },
  171. add: function (row) {
  172. if (this.regionDeviceId === "") {
  173. this.$message.info({
  174. showClose: true,
  175. message: "请选择左侧行政区划"
  176. })
  177. return;
  178. }
  179. this.$refs.gbChannelSelect.openDialog((data) => {
  180. console.log("选择的数据")
  181. console.log(data)
  182. this.addChannelToCivilCode(this.regionDeviceId, data)
  183. })
  184. },
  185. addChannelToCivilCode: function (regionDeviceId, data) {
  186. if (data.length === 0) {
  187. return;
  188. }
  189. let channels = []
  190. for (let i = 0; i < data.length; i++) {
  191. channels.push(data[i].gbId)
  192. }
  193. this.loading = true
  194. this.$axios({
  195. method: 'post',
  196. url: `/api/common/channel/region/add`,
  197. data: {
  198. civilCode: regionDeviceId,
  199. channelIds: channels
  200. }
  201. }).then((res) => {
  202. if (res.data.code === 0) {
  203. this.$message.success({
  204. showClose: true,
  205. message: "保存成功"
  206. })
  207. this.getChannelList()
  208. } else {
  209. this.$message.error({
  210. showClose: true,
  211. message: res.data.msg
  212. })
  213. }
  214. this.loading = false
  215. }).catch((error) => {
  216. this.$message.error({
  217. showClose: true,
  218. message: error
  219. })
  220. this.loading = false
  221. });
  222. },
  223. remove: function (row) {
  224. let channels = []
  225. for (let i = 0; i < this.multipleSelection.length; i++) {
  226. channels.push(this.multipleSelection[i].gbId)
  227. }
  228. if (channels.length === 0) {
  229. this.$message.info({
  230. showClose: true,
  231. message: "请选择通道"
  232. })
  233. return;
  234. }
  235. this.loading = true
  236. this.$axios({
  237. method: 'post',
  238. url: `/api/common/channel/region/delete`,
  239. data: {
  240. channelIds: channels
  241. }
  242. }).then((res) => {
  243. if (res.data.code === 0) {
  244. this.$message.success({
  245. showClose: true,
  246. message: "保存成功"
  247. })
  248. this.getChannelList()
  249. // 刷新树节点
  250. this.$refs.regionTree.refresh(this.regionId)
  251. } else {
  252. this.$message.error({
  253. showClose: true,
  254. message: res.data.msg
  255. })
  256. }
  257. this.loading = false
  258. }).catch((error) => {
  259. this.$message.error({
  260. showClose: true,
  261. message: error
  262. })
  263. this.loading = false
  264. });
  265. },
  266. getSnap: function (row) {
  267. let baseUrl = window.baseUrl ? window.baseUrl : "";
  268. return ((process.env.NODE_ENV === 'development') ? process.env.BASE_API : baseUrl) + '/api/device/query/snap/' + this.deviceId + '/' + row.deviceId;
  269. },
  270. search: function () {
  271. this.currentPage = 1;
  272. this.total = 0;
  273. this.initData();
  274. },
  275. refresh: function () {
  276. this.initData();
  277. },
  278. treeNodeClickEvent: function (region) {
  279. this.regionDeviceId = region.deviceId;
  280. if (region.deviceId === "") {
  281. this.channelList = []
  282. this.regionParents = [];
  283. }
  284. this.initData();
  285. // 获取regionDeviceId对应的节点信息
  286. this.$axios({
  287. method: 'get',
  288. url: `/api/region/path`,
  289. params: {
  290. deviceId: this.regionDeviceId,
  291. }
  292. }).then((res) => {
  293. if (res.data.code === 0) {
  294. let path = []
  295. for (let i = 0; i < res.data.data.length; i++) {
  296. path.push(res.data.data[i].name)
  297. }
  298. this.regionParents = path;
  299. }
  300. }).catch((error) => {
  301. console.log(error);
  302. });
  303. },
  304. gbChannelSelectEnd: function (selectedData) {
  305. console.log(selectedData);
  306. },
  307. onChannelChange: function (deviceId) {
  308. //
  309. },
  310. }
  311. };
  312. </script>