getCatalog.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <div id="getCatalog" >
  3. <el-dialog title="选择要添加到的节点" v-if="showDialog" width="50%" :append-to-body="true" :close-on-click-modal="false" :visible.sync="showDialog" :destroy-on-close="true" @close="close()" center>
  4. <div>
  5. <el-tree class="el-scrollbar"
  6. ref="tree"
  7. id="catalogTree"
  8. empty-text="未知节点"
  9. node-key="id"
  10. default-expand-all
  11. :highlight-current="false"
  12. :expand-on-click-node="false"
  13. :props="props"
  14. :load="loadNode"
  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. <div style="float: right; height: 13rem">
  32. <el-button type="primary" size="mini" @click="submit()" >确认</el-button>
  33. <el-button @click="close()" size="mini">取消</el-button>
  34. </div>
  35. </el-dialog>
  36. </div>
  37. </template>
  38. <script>
  39. export default {
  40. name: 'getCatalog',
  41. beforeCreate(){
  42. },
  43. created() {
  44. this.chooseId = this.defaultCatalogId;
  45. this.defaultCatalogIdSign = this.defaultCatalogId;
  46. this.initData();
  47. setTimeout(()=>{
  48. if (this.catalogIdChange)this.catalogIdChange(this.defaultCatalogId);
  49. }, 100)
  50. },
  51. props: ['platformId'],
  52. data() {
  53. return {
  54. props: {
  55. label: 'name',
  56. children: 'children',
  57. isLeaf: 'leaf'
  58. },
  59. platformName: null,
  60. defaultCatalogId: null,
  61. catalogIdResult: null,
  62. showDialog: false,
  63. defaultCatalogIdSign: null,
  64. chooseNode: null,
  65. chooseId: "",
  66. catalogTree: null,
  67. contextmenuShow: false,
  68. };
  69. },
  70. methods: {
  71. openDialog(catalogIdResult) {
  72. console.log(this.chooseId)
  73. this.showDialog = true
  74. this.catalogIdResult = catalogIdResult
  75. },
  76. initData: function () {
  77. this.getCatalog();
  78. },
  79. getCatalog: function(parentId, callback) {
  80. let that = this;
  81. this.$axios({
  82. method:"get",
  83. url:`/api/platform/catalog`,
  84. params: {
  85. platformId: that.platformId,
  86. parentId: parentId
  87. }
  88. })
  89. .then((res)=> {
  90. if (res.data.code === 0) {
  91. if (typeof(callback) === 'function') {
  92. callback(res.data.data)
  93. }
  94. }
  95. })
  96. .catch(function (error) {
  97. console.log(error);
  98. });
  99. },
  100. loadNode: function(node, resolve){
  101. if (node.level === 0) {
  102. this.$axios({
  103. method:"get",
  104. url:`/api/platform/info/` + this.platformId,
  105. })
  106. .then((res)=> {
  107. if (res.data.code === 0) {
  108. this.platformName = res.data.data.name;
  109. this.defaultCatalogId = res.data.data.catalogId;
  110. this.defaultCatalogIdSign = res.data.data.catalogId;
  111. this.chooseId = res.data.data.catalogId;
  112. resolve([
  113. {
  114. name: this.platformName,
  115. id: res.data.data.deviceGBId,
  116. type: 0
  117. }
  118. ]);
  119. }
  120. })
  121. .catch(function (error) {
  122. console.log(error);
  123. });
  124. }
  125. if (node.level >= 1){
  126. this.getCatalog(node.data.id, resolve)
  127. }
  128. },
  129. nodeClickHandler: function (data, node, tree){
  130. this.chooseId = data.id;
  131. },
  132. close: function() {
  133. this.chooseId = null;
  134. this.showDialog = false;
  135. },
  136. submit: function() {
  137. console.log(this.chooseId)
  138. if (this.chooseId === null) {
  139. this.$message({
  140. showClose: true,
  141. message: '未选择任何节点,',
  142. type: 'warning'
  143. });
  144. return;
  145. }
  146. if (this.catalogIdResult)this.catalogIdResult(this.chooseId)
  147. this.showDialog = false;
  148. },
  149. }
  150. };
  151. </script>
  152. <style>
  153. #catalogTree{
  154. display: inline-block;
  155. }
  156. </style>