master-data-tree.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <a-card :class="[$style.treewrap, $style.ywlxtree]">
  3. <a-tree
  4. :key="key"
  5. ref="auditMaintainCatalogTree"
  6. v-model="checkedKeys"
  7. :check-strictly="true"
  8. :checkable="false"
  9. :tree-data="treeData"
  10. :show-line="true"
  11. :block-node="false"
  12. :replace-fields="replaceFields"
  13. :expanded-keys="expandedKeys"
  14. @expand="onExpand"
  15. @select="treeSelect"
  16. >
  17. </a-tree>
  18. </a-card>
  19. </template>
  20. <script>
  21. import masterDataService from './master-data-service'
  22. export default {
  23. name: 'MasterDataTree',
  24. metaInfo: {
  25. title: 'masterDataTree',
  26. },
  27. data() {
  28. return {
  29. key: 0,
  30. treeData: [],
  31. checkedKeys: [], // 选中的节点数据
  32. replaceFields: {
  33. title: 'text',
  34. key: 'id',
  35. },
  36. expandedKeys: [],
  37. nodeInfo: {},
  38. parentNode: {},
  39. }
  40. },
  41. created() {
  42. this.initTreeData()
  43. },
  44. methods: {
  45. // 初始化地址树
  46. initTreeData() {
  47. masterDataService.getOrgNodeList().then((res) => {
  48. if (res.data.length > 0) {
  49. this.treeData = res.data.map((val) => {
  50. return {
  51. id: val.id,
  52. text: val.text,
  53. isLeaf: false,
  54. props: {
  55. isroot: true,
  56. },
  57. children: [],
  58. key: val.id,
  59. }
  60. })
  61. }
  62. })
  63. },
  64. refreshKey() {
  65. if (this.nodeInfo.id) {
  66. this.getChildNode(this.nodeInfo)
  67. } else {
  68. if (this.expandedKeys.length > 0) {
  69. this.getChildNode(this.parentNode)
  70. }
  71. }
  72. }, // 重新获取数据
  73. getChildNode(node) {
  74. masterDataService.getOrgChildNodeList(node.id).then((res) => {
  75. if (res.data.length > 0) {
  76. node.children = res.data.map((val) => {
  77. return {
  78. id: val.id,
  79. text: val.text,
  80. isLeaf: false,
  81. props: {
  82. isroot: false,
  83. },
  84. children: [],
  85. key: val.id,
  86. }
  87. })
  88. } else {
  89. node.children = []
  90. }
  91. this.key++
  92. })
  93. },
  94. onExpand(expandedKeys, { expanded, node }) {
  95. if (node.dataRef.id === '-1') {
  96. this.parentNode = node.dataRef
  97. }
  98. this.getChildNode(node.dataRef)
  99. this.nodeInfo = node.dataRef
  100. this.expandedKeys = expandedKeys
  101. },
  102. treeSelect(selectedKeys, info) {
  103. this.$emit('treeSelect', selectedKeys, info.node.dataRef)
  104. },
  105. },
  106. }
  107. </script>
  108. <style module lang="scss">
  109. @use '@/common/design' as *;
  110. .spin {
  111. width: 100%;
  112. line-height: 30;
  113. }
  114. .ywlxtree {
  115. :global(.ant-tree-title) {
  116. display: inline-block;
  117. width: 100%;
  118. overflow: hidden;
  119. text-overflow: ellipsis;
  120. white-space: nowrap;
  121. }
  122. :global(.ant-input-search) {
  123. margin: 8px 0;
  124. overflow: hidden;
  125. }
  126. .active {
  127. color: $primary-color;
  128. }
  129. :global(.ant-select) {
  130. width: 100%;
  131. overflow: hidden;
  132. }
  133. }
  134. .treewrap {
  135. position: relative;
  136. display: flex;
  137. flex-direction: column;
  138. width: 20%;
  139. min-height: 100%;
  140. margin-right: $padding-lg;
  141. overflow: auto;
  142. transition: width 0.2s;
  143. .fold {
  144. position: absolute;
  145. top: calc(50% - 30px);
  146. right: -15px;
  147. z-index: 2;
  148. width: 15px;
  149. height: 75px;
  150. padding: 0;
  151. border-radius: 0 10px 10px 0;
  152. }
  153. // :global(.ant-tree) {
  154. // overflow: hidden;
  155. // text-overflow: ellipsis;
  156. // white-space: nowrap;
  157. // }
  158. :global(.ant-card-body) {
  159. background: $white;
  160. }
  161. }
  162. .collapse {
  163. width: 0;
  164. :global(.ant-card-body) {
  165. background: transparent;
  166. :global(.ant-empty) {
  167. display: none;
  168. }
  169. }
  170. }
  171. // 单选样式
  172. .single {
  173. :global .ant-tree-checkbox {
  174. .ant-tree-checkbox-inner {
  175. border-radius: 100px;
  176. &::after {
  177. position: absolute;
  178. top: 3px;
  179. left: 3px;
  180. display: table;
  181. width: 8px;
  182. height: 8px;
  183. content: ' ';
  184. background-color: $primary-color;
  185. border: 0;
  186. border-radius: 8px;
  187. opacity: 0;
  188. transition: all 0.3s cubic-bezier(0.78, 0.14, 0.15, 0.86);
  189. transform: scale(0);
  190. }
  191. }
  192. &.ant-tree-checkbox-checked {
  193. &::after {
  194. position: absolute;
  195. top: 16.67%;
  196. left: 0;
  197. width: 100%;
  198. height: 66.67%;
  199. content: '';
  200. border: 1px solid #1890ff;
  201. border-radius: 50%;
  202. animation: antRadioEffect 0.36s ease-in-out;
  203. animation-fill-mode: both;
  204. }
  205. .ant-tree-checkbox-inner {
  206. background-color: $white;
  207. &::after {
  208. opacity: 1;
  209. transition: all 0.3s cubic-bezier(0.78, 0.14, 0.15, 0.86);
  210. transform: scale(1);
  211. }
  212. }
  213. }
  214. }
  215. }
  216. </style>