SideMenu.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <template>
  2. <div class="side-catalog-wrap">
  3. <el-scrollbar class="side-catalog-box">
  4. <div
  5. class="side-catalog-all side-catalog-item"
  6. :class="{ 'active-catalog': isAll }"
  7. @click="clickAllCatalog()"
  8. >
  9. 全部
  10. </div>
  11. <div
  12. v-for="(catalog, index) in catalogList"
  13. :key="index"
  14. class="side-catalog-item"
  15. :class="{
  16. 'active-catalog': activeCatalog.code === catalog.code && !isAll
  17. }"
  18. @mouseenter="mouseenter(catalog.code)"
  19. @mouseleave="mouseleave"
  20. @click="clickCatalog(catalog)"
  21. >
  22. <span class="catalog-name">{{ catalog.name }}</span>
  23. <el-dropdown
  24. :class="{
  25. 'dropdown-show':
  26. (showDropdown && hoverItem === catalog.code) ||
  27. activeCatalog.code === catalog.code
  28. }"
  29. class="page-list-dropdown"
  30. placement="bottom-start"
  31. node-key="id"
  32. trigger="click"
  33. >
  34. <span class="el-dropdown-link menu-dropdown-link">
  35. <i
  36. class="el-icon-more"
  37. :class="{
  38. 'active-icon-more':
  39. activeCatalog.code === catalog.code && !isAll
  40. }"
  41. />
  42. <el-dropdown-menu
  43. slot="dropdown"
  44. class="dropdown-menu-box bs-el-dropdown-menu"
  45. >
  46. <el-dropdown-item @click.native="catalogEdit()">
  47. 编辑
  48. </el-dropdown-item>
  49. <el-dropdown-item
  50. class="delete-item"
  51. @click.native="catalogDel(catalog)"
  52. >
  53. 删除
  54. </el-dropdown-item>
  55. </el-dropdown-menu>
  56. </span>
  57. </el-dropdown>
  58. </div>
  59. </el-scrollbar>
  60. <div
  61. class="add-catalog-box"
  62. @click="catalogAdd"
  63. >
  64. <i class="el-icon-plus" />
  65. <div>新增分组</div>
  66. </div>
  67. <!-- 新增或编辑目录弹窗 -->
  68. <el-dialog
  69. :title="currentCatalog.code ? '编辑分组' : '新增分组'"
  70. :visible.sync="catalogVisible"
  71. custom-class="bs-el-dialog"
  72. width="30%"
  73. class="bs-dialog-wrap bs-el-dialog"
  74. @close="handleClose"
  75. >
  76. <el-form
  77. ref="form"
  78. :model="currentCatalog"
  79. label-width="80px"
  80. :rules="formRules"
  81. class="bs-el-form"
  82. >
  83. <el-form-item
  84. label="分组名称"
  85. prop="name"
  86. >
  87. <el-input
  88. v-model.trim="currentCatalog.name"
  89. class="bs-el-input"
  90. clearable
  91. />
  92. </el-form-item>
  93. <el-form-item label="排序">
  94. <el-input-number
  95. v-model="currentCatalog.orderNum"
  96. :min="0"
  97. :max="30000"
  98. controls-position="right"
  99. class="bs-el-input-number"
  100. />
  101. </el-form-item>
  102. </el-form>
  103. <span
  104. slot="footer"
  105. class="dialog-footer"
  106. >
  107. <el-button
  108. class="bs-el-button-default"
  109. @click="catalogVisible = false"
  110. >
  111. 取消
  112. </el-button>
  113. <el-button
  114. type="primary"
  115. @click="addOrEditCatalog"
  116. >
  117. 确定
  118. </el-button>
  119. </span>
  120. </el-dialog>
  121. </div>
  122. </template>
  123. <script>
  124. import cloneDeep from 'lodash/cloneDeep'
  125. export default {
  126. components: {},
  127. data () {
  128. const validateName = (rule, value, callback) => {
  129. this.$dataRoomAxios.post('/bigScreen/type/nameRepeat', {
  130. id: this.currentCatalog.id,
  131. name: value,
  132. type: 'resourceCatalog'
  133. }, true).then((r) => {
  134. if (r.data) {
  135. callback(new Error('分组名称已存在'))
  136. } else {
  137. callback()
  138. }
  139. })
  140. }
  141. return {
  142. showDropdown: false,
  143. hoverItem: null,
  144. isAll: true,
  145. catalogList: [
  146. {
  147. name: 'LOGO',
  148. code: 'LOGO'
  149. },
  150. {
  151. name: '商务科技',
  152. code: '商务科技'
  153. },
  154. {
  155. name: '卡通手绘',
  156. code: '卡通手绘'
  157. },
  158. {
  159. name: '简约背景',
  160. code: '简约背景'
  161. },
  162. {
  163. name: '大屏背景',
  164. code: '大屏背景'
  165. }
  166. ],
  167. catalogVisible: false,
  168. activeCatalog: {
  169. // 激活的目录,点击其他非目录按钮时需要保持当前的菜单激活状态
  170. name: '',
  171. id: '',
  172. code: ''
  173. },
  174. currentCatalog: {
  175. // 选中目录
  176. name: '',
  177. id: '',
  178. code: ''
  179. },
  180. formRules: {
  181. name: [
  182. { required: true, message: '分组名称不能为空', trigger: 'blur' },
  183. { validator: validateName, trigger: 'blur' }
  184. ]
  185. }
  186. }
  187. },
  188. mounted () {
  189. this.getCatalogList()
  190. },
  191. methods: {
  192. catalogAdd () {
  193. this.catalogVisible = true
  194. this.currentCatalog = {
  195. // 选中目录
  196. name: '',
  197. id: '',
  198. code: '',
  199. orderNum: 0
  200. }
  201. },
  202. mouseenter (code) {
  203. this.showDropdown = true
  204. this.hoverItem = code
  205. },
  206. mouseleave () {
  207. this.showDropdown = false
  208. },
  209. // 点击全部
  210. clickAllCatalog () {
  211. this.isAll = true
  212. this.$emit('getPageInfo', {
  213. isAll: true,
  214. page: { id: '', code: '', name: '' }
  215. })
  216. },
  217. // 关闭目录弹窗
  218. handleClose () {
  219. this.catalogVisible = false
  220. this.$refs.form.clearValidate()
  221. },
  222. // 新增编辑目录(点击确定)
  223. addOrEditCatalog () {
  224. this.$refs.form.validate(async (valid) => {
  225. if (!valid) {
  226. return
  227. }
  228. if (!this.currentCatalog.id) {
  229. this.$dataRoomAxios.post('/bigScreen/type/add', {
  230. ...this.currentCatalog,
  231. type: 'resourceCatalog'
  232. })
  233. .then((data) => {
  234. this.catalogVisible = false
  235. this.getCatalogList()
  236. this.flag = true
  237. // 关闭页面菜单的弹窗
  238. this.closePageMenuDialog()
  239. })
  240. .catch(() => {})
  241. } else {
  242. this.$dataRoomAxios.post('/bigScreen/type/update', {
  243. ...this.currentCatalog,
  244. type: 'resourceCatalog'
  245. })
  246. .then((data) => {
  247. this.catalogVisible = false
  248. this.getCatalogList()
  249. })
  250. .catch(() => {})
  251. }
  252. })
  253. },
  254. // 点击目录
  255. clickCatalog (catalog) {
  256. this.currentCatalog = cloneDeep(catalog)
  257. this.activeCatalog = cloneDeep(catalog)
  258. this.isAll = false
  259. this.$emit('getPageInfo', { isAll: false, page: catalog })
  260. },
  261. // 编辑目录
  262. catalogEdit () {
  263. this.currentCatalog = cloneDeep(this.currentCatalog)
  264. this.catalogVisible = true
  265. },
  266. // 删除目录
  267. catalogDel (catalog) {
  268. this.$confirm('分组删除后,分组下的资源会被归纳至全部中,确定删除该分组?', '提示', {
  269. confirmButtonText: '确定',
  270. cancelButtonText: '取消',
  271. type: 'warning',
  272. customClass: 'bs-el-message-box'
  273. })
  274. .then(async () => {
  275. this.$dataRoomAxios.post(`/bigScreen/type/delete/${catalog.id}`)
  276. .then(() => {
  277. this.$message({
  278. type: 'success',
  279. message: '删除成功'
  280. })
  281. this.getCatalogList()
  282. })
  283. .catch(() => {
  284. this.$message({
  285. type: 'error',
  286. message: '删除失败!'
  287. })
  288. })
  289. })
  290. .catch()
  291. },
  292. // 获取目录的列表
  293. getCatalogList () {
  294. this.pageLoading = true
  295. this.$dataRoomAxios.get('/bigScreen/type/list/resourceCatalog')
  296. .then((data) => {
  297. this.catalogList = data
  298. })
  299. .catch(() => {})
  300. .finally(() => {
  301. this.pageLoading = false
  302. })
  303. }
  304. }
  305. }
  306. </script>
  307. <style lang="scss" scoped>
  308. @import '../assets/style/bsTheme.scss';
  309. .side-catalog-wrap {
  310. // padding-top: 16px;
  311. width: 220px;
  312. // height: 100%;
  313. // margin-bottom: 16px;
  314. box-sizing: border-box;
  315. color: var(--bs-el-title);
  316. background-color: var(--bs-background-2);
  317. .side-catalog-box {
  318. height: calc(100% - 50px);
  319. overflow-y: auto;
  320. .side-catalog-all {
  321. font-weight: bold;
  322. }
  323. .side-catalog-item {
  324. width: 100%;
  325. padding: 0px 16px;
  326. line-height: 36px;
  327. display: flex;
  328. justify-content: space-between;
  329. &:hover {
  330. cursor: pointer;
  331. }
  332. .el-icon-more {
  333. transform: rotate(90deg);
  334. color: var(--bs-el-title);
  335. font-weight: 400;
  336. }
  337. .active-icon-more {
  338. color: var(--bs-el-text);
  339. }
  340. .catalog-name {
  341. overflow: hidden;
  342. white-space: nowrap;
  343. text-overflow: ellipsis;
  344. -o-text-overflow: ellipsis;
  345. }
  346. .page-list-dropdown {
  347. opacity: 0;
  348. }
  349. .dropdown-show {
  350. opacity: 1;
  351. }
  352. }
  353. /*菜单激活时的样式*/
  354. .active-catalog {
  355. position: relative;
  356. background-color: rgba(var(--bs-el-color-primary-active), 0.4);
  357. color: var(--bs-el-text);
  358. &::before{
  359. content: '';
  360. position: absolute;
  361. left: 0;
  362. width: 4px;
  363. height: 36px;
  364. background-color: var(--bs-el-color-primary);
  365. }
  366. }
  367. }
  368. .add-catalog-box {
  369. padding: 10px 0;
  370. box-sizing: border-box;
  371. display: flex;
  372. justify-content: center;
  373. align-items: center;
  374. border-radius: 10px;
  375. margin: 0 8px;
  376. &:hover {
  377. background-color: var(--bs-background-1);
  378. cursor: pointer;
  379. color: var(--bs-el-text);
  380. }
  381. .el-icon-plus {
  382. padding: 0 5px;
  383. }
  384. }
  385. }
  386. .dropdown-menu-box {
  387. left: 50%;
  388. transform: translateX(-40%);
  389. width: 100px !important;
  390. ::v-deep .el-dropdown-menu__item {
  391. text-align: center;
  392. padding: 5px;
  393. }
  394. ::v-deep .popper__arrow {
  395. left: 50% !important;
  396. transform: translateX(-50%) !important;
  397. }
  398. }
  399. </style>