chooseChannelForCatalog.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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"></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', 'treeType'],
  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. let that = this;
  97. console.log(this.treeType)
  98. // 打开添加弹窗
  99. that.$refs.catalogEdit.openDialog(false, null, null, parentId, this.treeType, node.level, ()=>{
  100. node.loaded = false
  101. node.expand();
  102. });
  103. },
  104. refreshCatalog: function (node){
  105. node.loaded = false
  106. node.expand();
  107. },
  108. refreshCatalogById: function (id) {
  109. if (id) {
  110. let node = this.$refs.tree.getNode(id);
  111. this.refreshCatalog(node);
  112. }
  113. },
  114. editCatalog: function (data, node){
  115. let that = this;
  116. // 打开添加弹窗
  117. that.$refs.catalogEdit.openDialog(true, data.id, data.name, data.parentId, (newData)=>{
  118. node.parent.loaded = false
  119. node.parent.expand();
  120. if (data.id === this.chooseId && newData.name !== data.name) {
  121. if (this.catalogIdChange)this.catalogIdChange(this.chooseId, newData.name);
  122. }
  123. });
  124. },
  125. removeCatalog: function (id, node){
  126. this.$axios({
  127. method:"delete",
  128. url:`/api/platform/catalog/del`,
  129. params: {
  130. id: id,
  131. platformId: this.platformId,
  132. }
  133. }).then((res) => {
  134. if (res.data.code === 0) {
  135. console.log("移除成功")
  136. node.parent.loaded = false
  137. node.parent.expand();
  138. if (res.data.data) {
  139. this.defaultCatalogIdSign = res.data.data;
  140. }
  141. }
  142. })
  143. .catch(function (error) {
  144. console.log(error);
  145. });
  146. },
  147. setDefaultCatalog: function (id){
  148. this.$axios({
  149. method:"post",
  150. url:`/api/platform/catalog/default/update`,
  151. params: {
  152. platformId: this.platformId,
  153. catalogId: id,
  154. }
  155. }).then((res)=> {
  156. if (res.data.code === 0) {
  157. this.defaultCatalogIdSign = id;
  158. }
  159. })
  160. .catch(function (error) {
  161. console.log(error);
  162. });
  163. },
  164. loadNode: function(node, resolve){
  165. console.log("this.platformDeviceId: " + this.platformDeviceId)
  166. if (node.level === 0) {
  167. resolve([
  168. {
  169. name: "未分配",
  170. id: null,
  171. type: -1
  172. },{
  173. name: this.platformName,
  174. id: this.platformDeviceId,
  175. type: 0
  176. }
  177. ]);
  178. }
  179. if (node.level >= 1){
  180. this.getCatalog(node.data.id, resolve)
  181. }
  182. },
  183. contextmenuEventHandler: function (event,data,node,element){
  184. if (node.data.type !== 0) {
  185. data.parentId = node.parent.data.id;
  186. this.$contextmenu({
  187. items: [
  188. {
  189. label: "移除通道",
  190. icon: "el-icon-delete",
  191. disabled: false,
  192. onClick: () => {
  193. this.$axios({
  194. method:"delete",
  195. url:"/api/platform/catalog/relation/del",
  196. data: data
  197. }).then((res)=>{
  198. console.log("移除成功")
  199. node.parent.loaded = false
  200. node.parent.expand();
  201. }).catch(function (error) {
  202. console.log(error);
  203. });
  204. }
  205. }
  206. ],
  207. event, // 鼠标事件信息
  208. customClass: "custom-class", // 自定义菜单 class
  209. zIndex: 3000, // 菜单样式 z-index
  210. });
  211. }else {
  212. this.$contextmenu({
  213. items: [
  214. {
  215. label: "刷新节点",
  216. icon: "el-icon-refresh",
  217. disabled: false,
  218. onClick: () => {
  219. this.refreshCatalog(node);
  220. }
  221. },
  222. {
  223. label: "新建节点",
  224. icon: "el-icon-plus",
  225. disabled: false,
  226. onClick: () => {
  227. this.addCatalog(data.id, node);
  228. }
  229. },
  230. {
  231. label: "修改节点",
  232. icon: "el-icon-edit",
  233. disabled: node.level === 1,
  234. onClick: () => {
  235. this.editCatalog(data, node);
  236. }
  237. },
  238. {
  239. label: "删除节点",
  240. icon: "el-icon-delete",
  241. disabled: node.level === 1,
  242. divided: true,
  243. onClick: () => {
  244. this.$confirm('确定删除?', '提示', {
  245. confirmButtonText: '确定',
  246. cancelButtonText: '取消',
  247. type: 'warning'
  248. }).then(() => {
  249. this.removeCatalog(data.id, node)
  250. }).catch(() => {
  251. });
  252. }
  253. },
  254. {
  255. label: "设为默认",
  256. icon: "el-icon-folder-checked",
  257. disabled: node.data.id === this.defaultCatalogIdSign,
  258. onClick: () => {
  259. this.setDefaultCatalog(data.id)
  260. },
  261. },
  262. // {
  263. // label: "导出",
  264. // icon: "el-icon-download",
  265. // disabled: false,
  266. // children: [
  267. // {
  268. // label: "导出到文件",
  269. // onClick: () => {
  270. //
  271. // },
  272. // },
  273. // {
  274. // label: "导出到其他平台",
  275. // onClick: () => {
  276. //
  277. // },
  278. // }
  279. // ]
  280. // },
  281. ],
  282. event, // 鼠标事件信息
  283. customClass: "custom-class", // 自定义菜单 class
  284. zIndex: 3000, // 菜单样式 z-index
  285. });
  286. }
  287. return false;
  288. },
  289. nodeClickHandler: function (data, node, tree){
  290. console.log(data)
  291. console.log(node)
  292. this.chooseId = data.id;
  293. this.chooseName = data.name;
  294. if (this.catalogIdChange)this.catalogIdChange(this.chooseId, this.chooseName);
  295. }
  296. }
  297. };
  298. </script>
  299. <style>
  300. #catalogTree{
  301. display: inline-block;
  302. }
  303. </style>