SideMenu.vue 9.5 KB

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