chooseChannelForCatalog.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <div id="chooseChannelForCatalog" >
  3. <div style="background-color: #FFFFFF; margin-bottom: 1rem; position: relative; padding: 0.5rem; text-align: left;font-size: 14px;">
  4. <el-tree class="el-scrollbar"
  5. ref="tree"
  6. id="catalogTree"
  7. empty-text="未知节点"
  8. node-key="id"
  9. default-expand-all
  10. :highlight-current="false"
  11. :expand-on-click-node="false"
  12. :props="props"
  13. :load="loadNode"
  14. @node-contextmenu="contextmenuEventHandler"
  15. @node-click="nodeClickHandler"
  16. lazy>
  17. <span class="custom-tree-node" slot-scope="{ node, data }" style="width: 100%">
  18. <el-radio v-if="node.data.type === 0 || node.data.type === -1" style="margin-right: 0" v-model="chooseId" :label="node.data.id">{{''}}</el-radio>
  19. <span v-if="node.data.type === -1 && node.level === 1" style="font-size: 12px" class="iconfont icon-ziyuan"></span>
  20. <span v-if="node.data.type === 0 && node.level === 1" class="el-icon-s-home"></span>
  21. <span v-if="node.data.type === 0 && node.level > 1" class="el-icon-folder-opened"></span>
  22. <span v-if="node.data.type === 1" class="iconfont icon-shexiangtou"></span>
  23. <span v-if="node.data.type === 2" class="iconfont icon-zhibo"></span>
  24. <span style=" padding-left: 1px">{{ node.label }}</span>
  25. <span>
  26. <i style="margin-left: 5rem; color: #9d9d9d; padding-right: 20px" v-if="node.data.id === defaultCatalogIdSign">默认</i>
  27. </span>
  28. </span>
  29. </el-tree>
  30. </div>
  31. <catalogEdit ref="catalogEdit" :platformId="platformId" :platformDeviceId="platformDeviceId"></catalogEdit>
  32. </div>
  33. </template>
  34. <script>
  35. import catalogEdit from './catalogEdit.vue'
  36. export default {
  37. name: 'chooseChannelForCatalog',
  38. props: ['platformId', 'platformDeviceId', 'platformName', 'defaultCatalogId', 'catalogIdChange'],
  39. created() {
  40. this.chooseId = this.defaultCatalogId;
  41. this.defaultCatalogIdSign = this.defaultCatalogId;
  42. this.initData();
  43. setTimeout(()=>{
  44. if (this.catalogIdChange)this.catalogIdChange(this.defaultCatalogId, this.platformName);
  45. }, 100)
  46. },
  47. components: {
  48. catalogEdit,
  49. },
  50. data() {
  51. return {
  52. props: {
  53. label: 'name',
  54. children: 'children',
  55. isLeaf: 'leaf'
  56. },
  57. defaultCatalogIdSign: null,
  58. chooseNode: null,
  59. chooseId: "",
  60. chooseName: "",
  61. catalogTree: null,
  62. contextmenuShow: false
  63. };
  64. },
  65. watch:{
  66. platformId(newData, oldData){
  67. console.log(newData)
  68. this.initData()
  69. },
  70. },
  71. methods: {
  72. initData: function () {
  73. this.getCatalog();
  74. },
  75. getCatalog: function(parentId, callback) {
  76. let that = this;
  77. this.$axios({
  78. method:"get",
  79. url:`/api/platform/catalog`,
  80. params: {
  81. platformId: that.platformId,
  82. parentId: parentId
  83. }
  84. }).then((res)=> {
  85. if (res.data.code === 0) {
  86. if (typeof(callback) === 'function') {
  87. callback(res.data.data)
  88. }
  89. }
  90. })
  91. .catch(function (error) {
  92. console.log(error);
  93. });
  94. },
  95. addCatalog: function (parentId, node){
  96. // 打开添加弹窗
  97. this.$refs.catalogEdit.openDialog(false, null, null, parentId, node.level, ()=>{
  98. node.loaded = false
  99. node.expand();
  100. });
  101. },
  102. refreshCatalog: function (node){
  103. node.loaded = false
  104. node.expand();
  105. },
  106. refreshCatalogById: function (id) {
  107. if (id) {
  108. let node = this.$refs.tree.getNode(id);
  109. this.refreshCatalog(node);
  110. }
  111. },
  112. editCatalog: function (data, node){
  113. // 打开添加弹窗
  114. this.$refs.catalogEdit.openDialog(true, data.id, data.name, data.parentId, node.level, (newData)=>{
  115. node.parent.loaded = false
  116. node.parent.expand();
  117. if (data.id === this.chooseId && newData.name !== data.name) {
  118. if (this.catalogIdChange)this.catalogIdChange(this.chooseId, newData.name);
  119. }
  120. });
  121. },
  122. removeCatalog: function (id, node){
  123. this.$axios({
  124. method:"delete",
  125. url:`/api/platform/catalog/del`,
  126. params: {
  127. id: id,
  128. platformId: this.platformId,
  129. }
  130. }).then((res) => {
  131. if (res.data.code === 0) {
  132. console.log("移除成功")
  133. node.parent.loaded = false
  134. node.parent.expand();
  135. if (res.data.data) {
  136. this.defaultCatalogIdSign = res.data.data;
  137. }
  138. }
  139. })
  140. .catch(function (error) {
  141. console.log(error);
  142. });
  143. },
  144. setDefaultCatalog: function (id){
  145. this.$axios({
  146. method:"post",
  147. url:`/api/platform/catalog/default/update`,
  148. params: {
  149. platformId: this.platformId,
  150. catalogId: id,
  151. }
  152. }).then((res)=> {
  153. if (res.data.code === 0) {
  154. this.defaultCatalogIdSign = id;
  155. }
  156. })
  157. .catch(function (error) {
  158. console.log(error);
  159. });
  160. },
  161. loadNode: function(node, resolve){
  162. console.log("this.platformDeviceId: " + this.platformDeviceId)
  163. if (node.level === 0) {
  164. resolve([
  165. {
  166. name: "未分配",
  167. id: null,
  168. type: -1
  169. },{
  170. name: this.platformName,
  171. id: this.platformDeviceId,
  172. type: 0
  173. }
  174. ]);
  175. }
  176. if (node.level >= 1){
  177. this.getCatalog(node.data.id, resolve)
  178. }
  179. },
  180. contextmenuEventHandler: function (event,data,node,element){
  181. if (node.data.type !== 0) {
  182. data.parentId = node.parent.data.id;
  183. this.$contextmenu({
  184. items: [
  185. {
  186. label: "移除通道",
  187. icon: "el-icon-delete",
  188. disabled: false,
  189. onClick: () => {
  190. this.$axios({
  191. method:"delete",
  192. url:"/api/platform/catalog/relation/del",
  193. data: data
  194. }).then((res)=>{
  195. console.log("移除成功")
  196. node.parent.loaded = false
  197. node.parent.expand();
  198. }).catch(function (error) {
  199. console.log(error);
  200. });
  201. }
  202. }
  203. ],
  204. event, // 鼠标事件信息
  205. customClass: "custom-class", // 自定义菜单 class
  206. zIndex: 3000, // 菜单样式 z-index
  207. });
  208. }else {
  209. this.$contextmenu({
  210. items: [
  211. {
  212. label: "刷新节点",
  213. icon: "el-icon-refresh",
  214. disabled: false,
  215. onClick: () => {
  216. this.refreshCatalog(node);
  217. }
  218. },
  219. {
  220. label: "新建节点",
  221. icon: "el-icon-plus",
  222. disabled: false,
  223. onClick: () => {
  224. this.addCatalog(data.id, node);
  225. }
  226. },
  227. {
  228. label: "修改节点",
  229. icon: "el-icon-edit",
  230. disabled: node.level === 1,
  231. onClick: () => {
  232. this.editCatalog(data, node);
  233. }
  234. },
  235. {
  236. label: "删除节点",
  237. icon: "el-icon-delete",
  238. disabled: node.level === 1,
  239. divided: true,
  240. onClick: () => {
  241. this.$confirm('确定删除?', '提示', {
  242. confirmButtonText: '确定',
  243. cancelButtonText: '取消',
  244. type: 'warning'
  245. }).then(() => {
  246. this.removeCatalog(data.id, node)
  247. }).catch(() => {
  248. });
  249. }
  250. },
  251. {
  252. label: "设为默认",
  253. icon: "el-icon-folder-checked",
  254. disabled: node.data.id === this.defaultCatalogIdSign,
  255. onClick: () => {
  256. this.setDefaultCatalog(data.id)
  257. },
  258. },
  259. // {
  260. // label: "导出",
  261. // icon: "el-icon-download",
  262. // disabled: false,
  263. // children: [
  264. // {
  265. // label: "导出到文件",
  266. // onClick: () => {
  267. //
  268. // },
  269. // },
  270. // {
  271. // label: "导出到其他平台",
  272. // onClick: () => {
  273. //
  274. // },
  275. // }
  276. // ]
  277. // },
  278. ],
  279. event, // 鼠标事件信息
  280. customClass: "custom-class", // 自定义菜单 class
  281. zIndex: 3000, // 菜单样式 z-index
  282. });
  283. }
  284. return false;
  285. },
  286. nodeClickHandler: function (data, node, tree){
  287. console.log(data)
  288. console.log(node)
  289. this.chooseId = data.id;
  290. this.chooseName = data.name;
  291. if (this.catalogIdChange)this.catalogIdChange(this.chooseId, this.chooseName);
  292. }
  293. }
  294. };
  295. </script>
  296. <style>
  297. #catalogTree{
  298. display: inline-block;
  299. }
  300. </style>