getCatalog.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. this.showDialog = true
  73. this.catalogIdResult = catalogIdResult
  74. },
  75. initData: function () {
  76. this.getCatalog();
  77. },
  78. getCatalog: function(parentId, callback) {
  79. let that = this;
  80. this.$axios({
  81. method:"get",
  82. url:`/api/platform/catalog`,
  83. params: {
  84. platformId: that.platformId,
  85. parentId: parentId
  86. }
  87. })
  88. .then((res)=> {
  89. if (res.data.code === 0) {
  90. if (typeof(callback) === 'function') {
  91. callback(res.data.data)
  92. }
  93. }
  94. })
  95. .catch(function (error) {
  96. console.log(error);
  97. });
  98. },
  99. loadNode: function(node, resolve){
  100. if (node.level === 0) {
  101. this.$axios({
  102. method:"get",
  103. url:`/api/platform/info/` + this.platformId,
  104. })
  105. .then((res)=> {
  106. if (res.data.code === 0) {
  107. this.platformName = res.data.data.name;
  108. this.defaultCatalogId = res.data.data.catalogId;
  109. this.defaultCatalogIdSign = res.data.data.catalogId;
  110. this.chooseId = res.data.data.catalogId;
  111. resolve([
  112. {
  113. name: this.platformName,
  114. id: this.platformId,
  115. type: 0
  116. }
  117. ]);
  118. }
  119. })
  120. .catch(function (error) {
  121. console.log(error);
  122. });
  123. }
  124. if (node.level >= 1){
  125. this.getCatalog(node.data.id, resolve)
  126. }
  127. },
  128. nodeClickHandler: function (data, node, tree){
  129. this.chooseId = data.id;
  130. },
  131. close: function() {
  132. this.showDialog = false;
  133. },
  134. submit: function() {
  135. if (this.catalogIdResult)this.catalogIdResult(this.chooseId)
  136. this.showDialog = false;
  137. },
  138. }
  139. };
  140. </script>
  141. <style>
  142. #catalogTree{
  143. display: inline-block;
  144. }
  145. </style>