classifyDia.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <template>
  2. <div>
  3. <el-dialog
  4. :visible.sync="show"
  5. :close-on-click-modal="false"
  6. :modal-append-to-body="false"
  7. @close="cancelHandle"
  8. custom-class="knowledge-classify"
  9. top="10vh"
  10. v-dialogDrag
  11. title="分类设置"
  12. width="650px"
  13. >
  14. <div class="main">
  15. <el-tree
  16. ref="treeRef"
  17. class="classify-tree"
  18. :data="classifyOptions"
  19. node-key="ClassifyId"
  20. :props="{
  21. value: 'ClassifyId',
  22. label: 'ClassifyName',
  23. children: 'Child',
  24. }"
  25. :expand-on-click-node="false"
  26. check-strictly
  27. empty-text="暂无分类"
  28. draggable
  29. :allow-drop="canDropHandle"
  30. @node-drop="dropOverHandle"
  31. @current-change="handleNodeChange"
  32. >
  33. <div class="custom-tree-node" slot-scope="{ node, data }">
  34. <span
  35. class="text_oneLine node_label"
  36. >
  37. {{ data.ClassifyName }}
  38. </span>
  39. <div v-if="selectItem.ClassifyId===data.ClassifyId">
  40. <img
  41. src="~@/assets/img/data_m/move_ico.png"
  42. class="handle-icon"
  43. />
  44. <!-- 添加子项 -->
  45. <img
  46. src="~@/assets/img/set_m/add.png"
  47. class="handle-icon"
  48. @click.stop="handleAddNode(data,node)"
  49. v-if="node.level<3"
  50. />
  51. <!-- 编辑目录 -->
  52. <img
  53. src="~@/assets/img/set_m/edit.png"
  54. class="handle-icon"
  55. @click.stop="handleEditNode(data,node)"
  56. />
  57. <!-- 删除目录 -->
  58. <el-popconfirm
  59. title="确认删除该分类吗?"
  60. @onConfirm="handleRemoveNode(data)"
  61. >
  62. <img
  63. slot="reference"
  64. src="~@/assets/img/set_m/del_icon.png"
  65. class="handle-icon"
  66. />
  67. </el-popconfirm>
  68. </div>
  69. </div>
  70. </el-tree>
  71. <div class="clasify-add-cont" @click="handleAddNode(null)">
  72. <img
  73. src="~@/assets/img/set_m/add_ico.png"
  74. alt=""
  75. />
  76. <span>添加一级目录</span>
  77. </div>
  78. </div>
  79. </el-dialog>
  80. <!-- 分类编辑弹窗 -->
  81. <el-dialog
  82. :visible.sync="isClassifyEditDia"
  83. :close-on-click-modal="false"
  84. :modal-append-to-body="false"
  85. @close="isClassifyEditDia=false"
  86. top="10vh"
  87. v-dialogDrag
  88. title="分类编辑"
  89. width="650px"
  90. >
  91. <el-form
  92. ref="classifyFormRef"
  93. label-position="right"
  94. label-width="120px"
  95. hide-required-asterisk
  96. :model="classifyForm"
  97. :rules="formRules"
  98. >
  99. <el-form-item label="上级分类" prop="parentClassifyId" v-if="classifyForm.parentClassifyId">
  100. <span>{{classifyForm.parentName}}</span>
  101. </el-form-item>
  102. <el-form-item label="分类名称" prop="classifyName">
  103. <el-input
  104. v-model="classifyForm.classifyName"
  105. style="width: 80%"
  106. placeholder="请输入指标名称"
  107. />
  108. </el-form-item>
  109. </el-form>
  110. <div class="btn-bottom">
  111. <el-button type="primary" plain @click="isClassifyEditDia=false">取消</el-button>
  112. <el-button type="primary" @click="handleSaveClassify">确定</el-button>
  113. </div>
  114. </el-dialog>
  115. </div>
  116. </template>
  117. <script>
  118. import { eventInterface } from '@/api/modules/knowledge';
  119. export default {
  120. props: {
  121. show: {
  122. type: Boolean
  123. },
  124. ResourceType: {
  125. type: Number
  126. }
  127. },
  128. watch: {
  129. show(nval) {
  130. nval && this.getClassify()
  131. }
  132. },
  133. data() {
  134. return {
  135. classifyOptions: [],
  136. selectItem:{},
  137. //编辑分类弹窗
  138. isClassifyEditDia:false,
  139. classifyForm: {
  140. classifyName: '',
  141. classifyId: 0,
  142. parentClassifyId: 0,
  143. }
  144. }
  145. },
  146. mounted(){
  147. },
  148. methods:{
  149. async getClassify() {
  150. const res = await eventInterface.getClassify({
  151. ResourceType: this.ResourceType
  152. })
  153. if(res.Ret !== 200) return
  154. this.classifyOptions = res.Data.List
  155. },
  156. //添加
  157. handleAddNode(data,node) {
  158. console.log(data,node)
  159. this.classifyForm = {
  160. classifyName: '',
  161. classifyId: 0,
  162. parentClassifyId: data?data.ClassifyId:0,
  163. parentName: data?data.ClassifyName:''
  164. }
  165. this.isClassifyEditDia = true
  166. },
  167. //编辑
  168. handleEditNode(data,node) {
  169. this.classifyForm = {
  170. classifyName: data.ClassifyName,
  171. classifyId: data.ClassifyId,
  172. parentClassifyId: data.ParentId,
  173. parentName: node.parent.data.ClassifyName
  174. }
  175. this.isClassifyEditDia = true
  176. },
  177. //删除
  178. async handleRemoveNode({ClassifyId}) {
  179. const res = await eventInterface.delClassifyCheck({ClassifyId, ResourceType: this.ResourceType})
  180. if(res.Ret !== 200) return
  181. if(res.Data.Code!==0) return this.$message.warning(res.Data.Msg)
  182. const delRes = await eventInterface.delClassify({ClassifyId, ResourceType: this.ResourceType})
  183. if(delRes.Ret !== 200) return
  184. this.$message.success('删除成功')
  185. this.getClassify()
  186. },
  187. handleNodeChange(data) {
  188. this.selectItem = data;
  189. },
  190. //保存分类信息
  191. async handleSaveClassify() {
  192. const { classifyName,parentClassifyId,classifyId } = this.classifyForm
  193. let params = {
  194. ResourceType: this.ResourceType,
  195. ClassifyName: classifyName,
  196. ParentId: parentClassifyId
  197. }
  198. const res = classifyId
  199. ? await eventInterface.editClassify({ ClassifyId: classifyId,...params })
  200. : await eventInterface.addClassify(params)
  201. if(res.Ret !==200) return
  202. this.$message.success(classifyId?'编辑成功':'新增成功')
  203. this.getClassify()
  204. this.isClassifyEditDia = false
  205. },
  206. cancelHandle() {
  207. this.$emit('update:show',false)
  208. },
  209. //拖动结束
  210. async dropOverHandle(b,a,i,e) {
  211. // 被拖拽节点对应的 Node、结束拖拽时最后进入的节点、被拖拽节点的放置位置
  212. const classifyId=b.data.ClassifyId
  213. let list=a.parent.childNodes;
  214. let PrevClassifyId=0,NextClassifyId=0,targetIndex=0;
  215. list.forEach((item,index) => {
  216. if(item.data.ClassifyId===classifyId){
  217. targetIndex=index
  218. }
  219. });
  220. if(targetIndex===0){
  221. NextClassifyId=list[1].data.ClassifyId
  222. }else if(targetIndex===list.length-1){
  223. PrevClassifyId=list[list.length-1].data.ClassifyId
  224. }else{
  225. PrevClassifyId=list[targetIndex-1].data.ClassifyId
  226. NextClassifyId=list[targetIndex+1].data.ClassifyId
  227. }
  228. const params={
  229. ClassifyId:classifyId,
  230. PrevClassifyId,
  231. NextClassifyId,
  232. ResourceType: this.ResourceType
  233. }
  234. console.log(params);
  235. const res = await eventInterface.moveClassify(params)
  236. if(res.Ret!==200) return
  237. this.$message.success('移动成功')
  238. this.getClassify()
  239. },
  240. //控制同级拖动
  241. canDropHandle(draggingNode, dropNode, type){
  242. console.log(draggingNode, dropNode, type)
  243. if(type==='inner') return false
  244. if(draggingNode.level!==dropNode.level) return false
  245. if(draggingNode.data.ParentId!=dropNode.data.ParentId) return false
  246. return true
  247. },
  248. },
  249. }
  250. </script>
  251. <style scoped lang='scss'>
  252. .main {
  253. padding: 0 30px;
  254. .classify-tree {
  255. height: 50vh;
  256. min-height: 300px;
  257. overflow-y: auto;
  258. .custom-tree-node {
  259. width: 100%;
  260. display: flex;
  261. justify-content: space-between;
  262. align-items: center;
  263. }
  264. .handle-icon {
  265. width: 16px;
  266. height: 16px;
  267. margin: 0 4px;
  268. }
  269. }
  270. .clasify-add-cont {
  271. margin: 30px 0;
  272. display: flex;
  273. justify-content: center;
  274. color: #409eff;
  275. cursor: pointer;
  276. >img {
  277. width: 16px;
  278. height: 16px;
  279. margin-right: 10px;
  280. }
  281. }
  282. }
  283. .btn-bottom {
  284. display: flex;
  285. justify-content: center;
  286. gap: 20px;
  287. margin: 40px 0;
  288. >.el-button {
  289. width: 120px;
  290. }
  291. }
  292. </style>
  293. <style lang="scss">
  294. .knowledge-classify{
  295. .classify-tree {
  296. .el-tree__drop-indicator {
  297. height: 3px;
  298. background-color: #409eff;
  299. }
  300. .el-tree-node__content {
  301. margin-bottom: 14px !important;
  302. }
  303. .el-tree-node__children {
  304. .el-tree-node {
  305. margin-bottom: 0px !important;
  306. padding-left: 18px;
  307. }
  308. .el-tree-node__content {
  309. margin-bottom: 5px !important;
  310. padding-left: 0 !important;
  311. }
  312. }
  313. .expanded.el-icon-caret-right:before {
  314. content: url('~@/assets/img/set_m/down.png') !important;
  315. }
  316. .el-icon-caret-right:before {
  317. content: url('~@/assets/img/set_m/slide.png') !important;
  318. }
  319. .el-tree-node__expand-icon{
  320. padding-top: 10px;
  321. }
  322. .el-tree-node__expand-icon.is-leaf.el-icon-caret-right:before {
  323. content: '' !important;
  324. }
  325. .el-tree-node__expand-icon.expanded {
  326. -webkit-transform: rotate(0deg);
  327. transform: rotate(0deg);
  328. }
  329. .el-tree-node.is-current>.el-tree-node__content {
  330. background-color: #f0f4ff !important;
  331. }
  332. .el-tree-node__content {
  333. padding-right: 10px !important;
  334. }
  335. }
  336. }
  337. </style>