leftCat.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <div class="content-container">
  3. <div class="list-group">
  4. <el-row class="title-bar">
  5. <p class="page-title">信息中心</p>
  6. <span class="right-icon" @click="handleAddTop">
  7. <i class="icon el-icon-plus" />
  8. </span>
  9. </el-row>
  10. <vuescroll :ops="ops" style="height: calc(100% - 90px);">
  11. <el-tree
  12. :expand-on-click-node="false"
  13. :default-expand-all="true"
  14. :data="treeData"
  15. :props="defaultProps"
  16. @node-click="handleNodeClick"
  17. >
  18. <template v-slot="{ node, data }">
  19. <span class="custom-tree-node">
  20. <span class="label">{{ node.label }}</span>
  21. <span class="right-icon" @click="event => clickItem(event,data)">
  22. <i class="icon el-icon-caret-bottom" />
  23. </span>
  24. </span>
  25. </template>
  26. </el-tree>
  27. </vuescroll>
  28. </div>
  29. <art-cat ref="AddTopArtCat" title="添加分类" @formSuccess="getData" />
  30. <art-cat ref="AddArtCat" title="添加分类" @formSuccess="getData" />
  31. <art-cat ref="UpdateArtCat" title="修改类别" @formSuccess="getData" />
  32. </div>
  33. </template>
  34. <script>
  35. import { getArtCatByList, deleteArtCatById } from '@/api/system/artCatApi'
  36. import { toTree } from '@/utils/build-tree'
  37. import ArtCat from './artCat'
  38. import Vuescroll from 'vuescroll'
  39. export default {
  40. components: { Vuescroll, ArtCat },
  41. data() {
  42. return {
  43. ops: {
  44. bar: {
  45. keepShow: false,
  46. background: 'rgba(144, 147, 153, 0.4)',
  47. onlyShowBarOnScroll: false
  48. }
  49. },
  50. listLoading: false,
  51. treeData: [],
  52. defaultProps: {
  53. children: 'children',
  54. label: 'artCatTitle'
  55. }
  56. }
  57. },
  58. mounted() {
  59. this.getData()
  60. },
  61. methods: {
  62. getData() {
  63. this.listLoading = true
  64. getArtCatByList().then((resp) => {
  65. this.listLoading = false
  66. const { code, data } = resp
  67. if (code === 0) {
  68. const temp = toTree(data, {
  69. value: 'artCatId',
  70. name: 'artCatTitle',
  71. pValue: 'parentId'
  72. }, {
  73. value: 'artCatId',
  74. name: 'artCatTitle',
  75. pValue: 'parentId'
  76. })
  77. this.treeData = temp
  78. if (temp.length > 0) { this.handleTreeInit(temp[0]) }
  79. }
  80. }).catch((error) => {
  81. console.log(error)
  82. })
  83. },
  84. clickItem(event, data) {
  85. this.$contextmenu({
  86. items: [
  87. {
  88. label: '添加类别', divided: true, onClick: () => {
  89. this.handleAdd(data)
  90. }
  91. },
  92. {
  93. label: '修改类别', divided: true, onClick: () => {
  94. this.handleUpdate(data)
  95. }
  96. },
  97. {
  98. label: '删除', divided: false, onClick: () => {
  99. this.handleDelete(data)
  100. }
  101. }
  102. ],
  103. event,
  104. // x: event.clientX,
  105. // y: event.clientY,
  106. customClass: 'class-a',
  107. zIndex: 3,
  108. minWidth: 230
  109. })
  110. return false
  111. },
  112. // 添加一线
  113. handleAddTop() {
  114. this.$refs['AddTopArtCat'].showAddModel(0)
  115. },
  116. // 添加
  117. handleAdd(data) {
  118. const { artCatId } = data
  119. this.$refs['AddArtCat'].showAddModel(artCatId)
  120. },
  121. // 更新
  122. handleUpdate(data) {
  123. const { artCatId } = data
  124. this.$refs['UpdateArtCat'].showEditModel(artCatId)
  125. },
  126. // 删除
  127. handleDelete(data) {
  128. this.$confirm(`此操作将删除该数据${data.artCatTitle}, 是否继续?`, '提示', {
  129. confirmButtonText: '确定',
  130. cancelButtonText: '取消',
  131. type: 'warning'
  132. }).then(() => {
  133. deleteArtCatById(data.artCatId).then((resp) => {
  134. const { code, msg } = resp
  135. if (code === 0) {
  136. this.getData()
  137. this.$message.success(msg)
  138. } else {
  139. this.$message.error(msg)
  140. }
  141. }).catch((error) => {
  142. console.log(error)
  143. })
  144. }).catch(() => {
  145. this.$message({ type: 'info', message: '已取消删除' })
  146. })
  147. },
  148. // Click
  149. handleNodeClick(data) {
  150. this.$emit('nodeClick', data)
  151. },
  152. // 初始化
  153. handleTreeInit(data) {
  154. this.$emit('treeInit', data)
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss" scoped>
  160. .content-container {
  161. margin: 10px 0 10px 10px;
  162. height: calc(100vh - 90px);
  163. .title-bar {
  164. position: relative;
  165. border-left: 6px solid #36556B;
  166. height: 40px;
  167. line-height: 40px;
  168. text-indent: 15px;
  169. background: #113849;
  170. margin-bottom: 0px;
  171. .page-title {
  172. font-size: 16px;
  173. font-width: bold;
  174. color: #FFF;
  175. margin: 0;
  176. background: linear-gradient(0deg, #FFFFFF 0%, #98A8B7 100%);
  177. -webkit-background-clip: text;
  178. -webkit-text-fill-color: transparent;
  179. }
  180. .right-icon {
  181. position: absolute;
  182. right: 15px;
  183. top: 14px;
  184. color: #5181A2;
  185. width: 14px;
  186. height: 14px;
  187. line-height: 14px;
  188. cursor: pointer;
  189. .icon {
  190. position: absolute;
  191. right: 0;
  192. top: 0;
  193. font-size: 14px;
  194. font-weight: bolder;
  195. }
  196. }
  197. }
  198. .btn-group {
  199. width: 100%;
  200. margin-bottom: 15px;
  201. .send-menu {
  202. width: 100%;
  203. background: #3D5F76;
  204. color: #FFF;
  205. border-color: #3D5F76;
  206. &:hover {
  207. background: #283c4c;
  208. color: #FFF;
  209. border-color: #283c4c;
  210. }
  211. }
  212. }
  213. .list-group {
  214. height: calc(100vh - 110px);
  215. background: #193142;
  216. .list-item {
  217. height: 40px;
  218. line-height: 40px;
  219. color: #FFF;
  220. padding: 0 30px;
  221. font-size: 14px;
  222. &.active {
  223. color: #08A6DC;
  224. position: relative;
  225. &::after {
  226. position: absolute;
  227. content: "";
  228. width: 0;
  229. height: 0;
  230. top: calc(50% - 3.5px);
  231. right: -3px;
  232. border-left: 7px solid transparent;
  233. border-right: 7px solid transparent;
  234. border-bottom: 7px solid #08A6DC;
  235. transform: rotate(270deg);
  236. }
  237. }
  238. }
  239. }
  240. .custom-tree-node {
  241. position: relative;
  242. width: 100%;
  243. .right-icon {
  244. position: absolute;
  245. right: 10px;
  246. top: 14px;
  247. background: #5181A2;
  248. color: #FFFFFF;
  249. width: 14px;
  250. height: 14px;
  251. border: 1px solid #3D6F91;
  252. line-height: 14px;
  253. font-size: 10px;
  254. display: none;
  255. cursor: pointer;
  256. .icon {
  257. position: relative;
  258. top: -2px;
  259. }
  260. }
  261. &:hover {
  262. .right-icon {
  263. display: block;
  264. }
  265. }
  266. }
  267. }
  268. </style>