aduit-area-tree.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <a-card
  3. :class="[
  4. $style.treewrap,
  5. $style.ywlxtree,
  6. { [$style.collapse]: fold, [$style.single]: single },
  7. ]"
  8. >
  9. <a-form-model>
  10. <a-form-model-item :label="null" prop="orgValue">
  11. <a-select
  12. v-model="allTreeDataKeys"
  13. show-search
  14. :filter-option="filterOption"
  15. @change="onSelectName"
  16. >
  17. <a-select-option v-for="item in allTreeData" :key="item.id" :value="item.id">
  18. {{ item.name }}
  19. </a-select-option>
  20. </a-select>
  21. </a-form-model-item>
  22. </a-form-model>
  23. <a-spin :spinning="spinning" :class="$style.spin" />
  24. <a-empty v-if="empty" />
  25. <a-tree
  26. v-else
  27. ref="auditMaintainCatalogTree"
  28. v-model="checkedKeys"
  29. :block-node="false"
  30. :show-icon="true"
  31. :show-line="showLine"
  32. :check-strictly="true"
  33. :checkable="false"
  34. :tree-data="treeData"
  35. :replace-fields="replaceFields"
  36. :selected-keys="defaultSelectedKeys"
  37. :expanded-keys="expandedKeys"
  38. :default-expanded-keys="defaultTreeExpandedKeys"
  39. :default-selected-keys="defaultSelectedKeys"
  40. @select="treeSelect"
  41. @expand="onExpand"
  42. >
  43. </a-tree>
  44. </a-card>
  45. </template>
  46. <script>
  47. import components from './_import-components/aduit-area-tree-import'
  48. import { Message } from 'ant-design-vue'
  49. import { getUserInfo } from '@/common/store-mixin'
  50. import auditMaintainService from './audit-maintain-service'
  51. export default {
  52. name: 'AduitAreaTree',
  53. metaInfo: {
  54. title: 'AduitAreaTree',
  55. },
  56. components,
  57. props: {
  58. // 默认选中节点
  59. selectedKeys: {
  60. type: Array,
  61. default: function() {
  62. return []
  63. },
  64. },
  65. // 查看模式 manager维护权限 read查看权限
  66. managerType: {
  67. type: String,
  68. default: 'manager',
  69. },
  70. // 是否显示复选框
  71. checkable: {
  72. type: Boolean,
  73. default: true,
  74. },
  75. // 是否可以拖拽
  76. draggable: {
  77. type: Boolean,
  78. default: false,
  79. },
  80. // 是否显示连线
  81. showLine: {
  82. type: Boolean,
  83. default: false,
  84. },
  85. // 根节点名称
  86. topNodeText: {
  87. type: String,
  88. default: '根节点',
  89. },
  90. // 地址树接口数据源
  91. treeparams: {
  92. type: Object,
  93. default: () => {
  94. return {}
  95. },
  96. },
  97. // 默认展开节点id
  98. defaultExpandedKeys: {
  99. type: Array,
  100. default: () => {
  101. return ['0']
  102. },
  103. },
  104. // 是否显示隐藏按钮
  105. showPrimary: {
  106. type: Boolean,
  107. default: true,
  108. },
  109. // 地址树是否单选
  110. single: {
  111. type: Boolean,
  112. default: false,
  113. },
  114. refreshKey: {
  115. type: Number,
  116. default: 0,
  117. },
  118. },
  119. data() {
  120. return {
  121. treeData: [],
  122. allTreeData: [],
  123. allTreeDataKeys: null,
  124. spinning: false,
  125. empty: false,
  126. fold: false,
  127. expandedKeys: [],
  128. defaultTreeExpandedKeys: [],
  129. defaultSelectedKeys: [],
  130. checkedKeys: [],
  131. replaceFields: {
  132. children: 'children',
  133. title: 'name',
  134. key: 'id',
  135. },
  136. }
  137. },
  138. created() {
  139. this.initTreeData()
  140. },
  141. methods: {
  142. // 获取树形图直接显示所有领域数据
  143. initTreeData() {
  144. auditMaintainService.getAreaListAll().then((res) => {
  145. if (res.data.length === 0) {
  146. this.empty = true
  147. return
  148. }
  149. this.allTreeData = res.data
  150. this.treeData = [
  151. {
  152. id: '0',
  153. name: '全部领域',
  154. props: {
  155. isroot: true,
  156. },
  157. children: res.data.map((item) => {
  158. return {
  159. ...item,
  160. props: {
  161. isroot: false,
  162. },
  163. }
  164. }),
  165. },
  166. ]
  167. })
  168. },
  169. // 搜索
  170. filterOption(input, option) {
  171. return option.componentOptions.children[0].name.indexOf(input) >= 0
  172. },
  173. onSelectName(val) {
  174. const onfindData = this.allTreeData.find((item) => item.id === val)
  175. if (!onfindData) return
  176. this.expandedKeys = ['0']
  177. const selectedKeys = [onfindData.id]
  178. const info = {
  179. node: {
  180. dataRef: onfindData,
  181. },
  182. }
  183. this.treeSelect(selectedKeys, info)
  184. },
  185. // 选中节点
  186. treeSelect(selectedKeys, info) {
  187. // id为零传空数组,空对象
  188. this.defaultSelectedKeys = selectedKeys
  189. if (selectedKeys.length === 0 || selectedKeys[0] === '0') {
  190. this.allTreeDataKeys = null
  191. this.$emit('treeSelect', [], {})
  192. return
  193. }
  194. // 选中的节点
  195. this.$emit('treeSelect', selectedKeys, info.node.dataRef)
  196. },
  197. // 点击展开
  198. onExpand(expandedKeys) {
  199. // 用户点击展开时,取消自动展开效果
  200. this.expandedKeys = expandedKeys
  201. },
  202. },
  203. }
  204. </script>
  205. <style module lang="scss">
  206. @use '@/common/design' as *;
  207. .spin {
  208. width: 100%;
  209. line-height: 30;
  210. }
  211. .ywlxtree {
  212. :global(.ant-tree-title) {
  213. display: inline-block;
  214. width: 100%;
  215. overflow: hidden;
  216. text-overflow: ellipsis;
  217. white-space: nowrap;
  218. }
  219. :global(.ant-input-search) {
  220. margin: 8px 0;
  221. overflow: hidden;
  222. }
  223. .active {
  224. color: $primary-color;
  225. }
  226. :global(.ant-select) {
  227. width: 100%;
  228. overflow: hidden;
  229. }
  230. }
  231. .treewrap {
  232. position: relative;
  233. display: flex;
  234. flex-direction: column;
  235. width: 20%;
  236. min-height: 100%;
  237. margin-right: $padding-lg;
  238. transition: width 0.2s;
  239. .fold {
  240. position: absolute;
  241. top: calc(50% - 30px);
  242. right: -15px;
  243. z-index: 2;
  244. width: 15px;
  245. height: 75px;
  246. padding: 0;
  247. border-radius: 0 10px 10px 0;
  248. }
  249. :global(.ant-tree) {
  250. overflow: hidden;
  251. text-overflow: ellipsis;
  252. white-space: nowrap;
  253. }
  254. :global(.ant-card-body) {
  255. background: $white;
  256. }
  257. }
  258. .collapse {
  259. width: 0;
  260. :global(.ant-card-body) {
  261. background: transparent;
  262. :global(.ant-empty) {
  263. display: none;
  264. }
  265. }
  266. }
  267. // 单选样式
  268. .single {
  269. :global .ant-tree-checkbox {
  270. .ant-tree-checkbox-inner {
  271. border-radius: 100px;
  272. &::after {
  273. position: absolute;
  274. top: 3px;
  275. left: 3px;
  276. display: table;
  277. width: 8px;
  278. height: 8px;
  279. content: ' ';
  280. background-color: $primary-color;
  281. border: 0;
  282. border-radius: 8px;
  283. opacity: 0;
  284. transition: all 0.3s cubic-bezier(0.78, 0.14, 0.15, 0.86);
  285. transform: scale(0);
  286. }
  287. }
  288. &.ant-tree-checkbox-checked {
  289. &::after {
  290. position: absolute;
  291. top: 16.67%;
  292. left: 0;
  293. width: 100%;
  294. height: 66.67%;
  295. content: '';
  296. border: 1px solid #1890ff;
  297. border-radius: 50%;
  298. animation: antRadioEffect 0.36s ease-in-out;
  299. animation-fill-mode: both;
  300. }
  301. .ant-tree-checkbox-inner {
  302. background-color: $white;
  303. &::after {
  304. opacity: 1;
  305. transition: all 0.3s cubic-bezier(0.78, 0.14, 0.15, 0.86);
  306. transform: scale(1);
  307. }
  308. }
  309. }
  310. }
  311. }
  312. </style>