audit-class-tree.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <template>
  2. <a-card :class="[$style.treewrap, $style.ywlxtree]" style="width: calc(100% - 20px);">
  3. <!-- 选择部门 -->
  4. <!-- <a-select v-model="depvalue" :options="depOptions" @change="changedep"> </a-select> -->
  5. <!-- <a-empty v-if="empty" /> -->
  6. <a-tree
  7. :key="key"
  8. ref="auditMaintainCatalogTree"
  9. v-model="checkedKeys"
  10. :block-node="false"
  11. :show-icon="true"
  12. :show-line="showLine"
  13. :check-strictly="true"
  14. :checkable="false"
  15. :draggable="draggable"
  16. :tree-data="treeData"
  17. :replace-fields="replaceFields"
  18. :selected-keys="defaultSelectedKeys"
  19. :expanded-keys="expandedKeys"
  20. :default-expanded-keys="defaultTreeExpandedKeys"
  21. @select="treeSelect"
  22. @expand="onExpand"
  23. >
  24. </a-tree>
  25. </a-card>
  26. </template>
  27. <script>
  28. import { Message } from 'ant-design-vue'
  29. import dataService from './data-config'
  30. export default {
  31. name: 'AuditClassTree',
  32. metaInfo: {
  33. title: 'AuditClassTree',
  34. },
  35. props: {
  36. // 默认选中节点
  37. selectedKeys: {
  38. type: Array,
  39. default: function() {
  40. return []
  41. },
  42. },
  43. // 查看模式 manager维护权限 read查看权限
  44. managerType: {
  45. type: String,
  46. default: 'manager',
  47. },
  48. // 是否显示复选框
  49. checkable: {
  50. type: Boolean,
  51. default: true,
  52. },
  53. // 是否可以拖拽
  54. draggable: {
  55. type: Boolean,
  56. default: false,
  57. },
  58. // 是否显示连线
  59. showLine: {
  60. type: Boolean,
  61. default: false,
  62. },
  63. // 根节点名称
  64. topNodeText: {
  65. type: String,
  66. default: '根节点',
  67. },
  68. // 地址树接口数据源
  69. treeparams: {
  70. type: Object,
  71. default: () => {
  72. return {}
  73. },
  74. },
  75. // 默认展开节点id
  76. defaultExpandedKeys: {
  77. type: Array,
  78. default: () => {
  79. return ['0']
  80. },
  81. },
  82. // 是否显示隐藏按钮
  83. showPrimary: {
  84. type: Boolean,
  85. default: true,
  86. },
  87. // 地址树是否单选
  88. single: {
  89. type: Boolean,
  90. default: false,
  91. },
  92. refreshKey: {
  93. type: Number,
  94. default: 0,
  95. },
  96. /**
  97. * 是否展示部门下拉列表
  98. */
  99. isSelectDep: {
  100. type: Boolean,
  101. default: false,
  102. },
  103. cate: {
  104. type: Boolean,
  105. default: false,
  106. },
  107. isSelect: {
  108. type: Boolean,
  109. default: false,
  110. },
  111. },
  112. data() {
  113. return {
  114. treeData: [],
  115. defaultTreeExpandedKeys: ['0'],
  116. defaultSelectedKeys: ['0'],
  117. checkedKeys: [], // 选中的节点数据
  118. dataList: [], // 数组dataList,搜索要用
  119. spinning: true,
  120. empty: false,
  121. icontype: 'left',
  122. fold: false,
  123. replaceFields: {
  124. title: 'text',
  125. key: 'id',
  126. },
  127. expandedKeys: ['0'],
  128. backupsExpandedKeys: [],
  129. autoExpandParent: false,
  130. defaultTopNodeText: '审计事项分类',
  131. defaultTopNodeId: '0',
  132. key: 0,
  133. newtree: [],
  134. depOptions: [], // 部门下拉框列表值
  135. edit: true, // 当前节点是否可编辑
  136. depvalue: '', // 选择的组织数据
  137. orgValue: '',
  138. orgId: null,
  139. }
  140. },
  141. created() {
  142. // 如果有默认展开节点,则赋值
  143. if (this.defaultExpandedKeys) {
  144. this.defaultTreeExpandedKeys = [...this.defaultExpandedKeys]
  145. }
  146. // 如果有传根节点名称,则赋值
  147. if (this.topNodeText) {
  148. this.defaultTopNodeText = this.topNodeText
  149. }
  150. // 如果有传默认选中节点,则赋值
  151. if (this.selectedKeys.length > 0) {
  152. this.defaultSelectedKeys = [...this.selectedKeys]
  153. }
  154. this.initTreeData()
  155. },
  156. methods: {
  157. onExpand(expandedKeys, { expanded, node }) {
  158. if (node.dataRef.sort === 1) return
  159. this.expandedKeys = expandedKeys
  160. // 根据父节点id 获取子节点内容
  161. if (expanded && node.dataRef.children.length === 0) {
  162. dataService.findIamAuditMaintainCategoryTree(node.dataRef.id).then((res) => {
  163. if (res.data.length > 0) {
  164. node.dataRef.children = res.data.map((val) => {
  165. return {
  166. id: val.id,
  167. text: val.text,
  168. isLeaf: false,
  169. props: {
  170. isroot: false,
  171. ...val.props,
  172. },
  173. slots: { icon: 'meh' },
  174. children: [],
  175. sort: 0,
  176. key: val.id,
  177. }
  178. })
  179. this.setTreeIndexData(node)
  180. } else {
  181. this.setTreeIndexData(node)
  182. }
  183. })
  184. }
  185. },
  186. // 设置索引数据
  187. setTreeIndexData(node) {
  188. const params = {
  189. columns:
  190. 'sortNum,id,indexName,indexRemark,systemName,indexSource,type,categoryName,categoryId',
  191. maxResults: 50,
  192. startPosition: 0,
  193. expressions: [
  194. {
  195. dataType: 'str',
  196. name: 'categoryId',
  197. op: 'like',
  198. stringValue: '%' + node.dataRef.props.categoryId + '%',
  199. },
  200. ],
  201. buttonExpressions: [],
  202. formId: 'iamSearchCategoryidIndexname',
  203. }
  204. dataService.findIndexList(params).then((res2) => {
  205. const indexList = res2.data.data.map((val) => {
  206. return {
  207. id: val.id,
  208. text: val.indexName,
  209. isLeaf: true,
  210. disabled: true,
  211. props: {
  212. isroot: false,
  213. },
  214. key: val.id,
  215. sort: 1,
  216. }
  217. })
  218. node.dataRef.children = [...indexList, ...node.dataRef.children]
  219. // sort为1的排序在前面
  220. node.dataRef.children.sort((a, b) => {
  221. return b.sort - a.sort
  222. })
  223. })
  224. },
  225. // 初始化地址树
  226. initTreeData() {
  227. this.treeData = []
  228. dataService.findIamAuditMaintainCategoryTree(0).then((res) => {
  229. this.spinning = false
  230. const treeNode = [
  231. {
  232. id: '0',
  233. text: '全部分类',
  234. isLeaf: false,
  235. props: {
  236. isroot: true,
  237. },
  238. slots: { icon: 'meh' },
  239. children: [],
  240. key: '0',
  241. sort: 0,
  242. },
  243. ]
  244. // if (this.isSelect) {
  245. // treeNode[0].children = res.data
  246. // treeNode[0].children.map((val) => {
  247. // dataService.findIamAuditMaintainCategoryTree(val.id).then((res) => {
  248. // val.children = res.data
  249. // return val
  250. // })
  251. // })
  252. // } else {
  253. treeNode[0].children = res.data.map((val) => {
  254. return {
  255. id: val.id,
  256. text: val.text,
  257. isLeaf: false,
  258. props: {
  259. isroot: false,
  260. isType: 1,
  261. ...val.props,
  262. },
  263. children: [],
  264. slots: { icon: 'meh' },
  265. sort: 0,
  266. key: val.id,
  267. }
  268. })
  269. // }
  270. this.expandedKeys = this.defaultTreeExpandedKeys
  271. this.empty = false
  272. this.treeData = treeNode
  273. })
  274. },
  275. // 点击树
  276. treeSelect(selectedKeys, info) {
  277. if (info.node.dataRef.sort === 1) return
  278. this.defaultSelectedKeys = selectedKeys
  279. this.$emit('treeSelect', selectedKeys, info)
  280. },
  281. },
  282. }
  283. </script>
  284. <style module lang="scss">
  285. @use '@/common/design' as *;
  286. .spin {
  287. // width: 100%;
  288. line-height: 30;
  289. }
  290. .ywlxtree {
  291. width: calc(100% - 20px);
  292. :global(.ant-tree-title) {
  293. display: inline-block;
  294. // width: 100%;
  295. overflow: hidden;
  296. text-overflow: ellipsis;
  297. white-space: nowrap;
  298. }
  299. :global(.ant-input-search) {
  300. margin: 8px 0;
  301. overflow: hidden;
  302. }
  303. .active {
  304. color: $primary-color;
  305. }
  306. :global(.ant-select) {
  307. width: 100%;
  308. overflow: hidden;
  309. }
  310. }
  311. .treewrap {
  312. position: relative;
  313. display: flex;
  314. flex-direction: column;
  315. width: 20%;
  316. height: 100%;
  317. min-height: 100%;
  318. margin-right: $padding-lg;
  319. overflow-y: auto;
  320. transition: width 0.2s;
  321. .fold {
  322. position: absolute;
  323. top: calc(50% - 30px);
  324. right: -15px;
  325. z-index: 2;
  326. width: 15px;
  327. height: 75px;
  328. padding: 0;
  329. border-radius: 0 10px 10px 0;
  330. }
  331. :global(.ant-tree) {
  332. overflow: hidden;
  333. text-overflow: ellipsis;
  334. white-space: nowrap;
  335. }
  336. :global(.ant-card-body) {
  337. background: $white;
  338. }
  339. }
  340. .collapse {
  341. width: 0;
  342. :global(.ant-card-body) {
  343. background: transparent;
  344. :global(.ant-empty) {
  345. display: none;
  346. }
  347. }
  348. }
  349. // 单选样式
  350. .single {
  351. :global .ant-tree-checkbox {
  352. .ant-tree-checkbox-inner {
  353. border-radius: 100px;
  354. &::after {
  355. position: absolute;
  356. top: 3px;
  357. left: 3px;
  358. display: table;
  359. width: 8px;
  360. height: 8px;
  361. content: ' ';
  362. background-color: $primary-color;
  363. border: 0;
  364. border-radius: 8px;
  365. opacity: 0;
  366. transition: all 0.3s cubic-bezier(0.78, 0.14, 0.15, 0.86);
  367. transform: scale(0);
  368. }
  369. }
  370. &.ant-tree-checkbox-checked {
  371. &::after {
  372. position: absolute;
  373. top: 16.67%;
  374. left: 0;
  375. width: 100%;
  376. height: 66.67%;
  377. content: '';
  378. border: 1px solid #1890ff;
  379. border-radius: 50%;
  380. animation: antRadioEffect 0.36s ease-in-out;
  381. animation-fill-mode: both;
  382. }
  383. .ant-tree-checkbox-inner {
  384. background-color: $white;
  385. &::after {
  386. opacity: 1;
  387. transition: all 0.3s cubic-bezier(0.78, 0.14, 0.15, 0.86);
  388. transform: scale(1);
  389. }
  390. }
  391. }
  392. }
  393. }
  394. </style>