CategoryMenu.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div id="CategoryMenu" v-loading="loading">
  3. <div style="margin: 0 auto;margin-bottom: 5px">
  4. <span>数据类别:</span>
  5. <span style="float: right;margin-right: 10px;cursor: pointer" title="添加类别" @click="handleAddShow">
  6. <el-icon>
  7. <ElIconPlus />
  8. </el-icon>
  9. </span>
  10. </div>
  11. <el-menu :default-active="firstOption" class="Category-menu" @select="currChange">
  12. <el-menu-item v-for="item in list" :key=item.id :index="item.id+''" >
  13. <el-icon>
  14. <IconPark-list-view/>
  15. </el-icon>
  16. <template #title>
  17. <el-tooltip effect="dark" :content="item.title" placement="right">
  18. <span style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">{{ item.title }}</span>
  19. </el-tooltip>
  20. </template>
  21. </el-menu-item>
  22. </el-menu>
  23. <el-empty v-if="!list || list.length<1" :description="'无类别'" ></el-empty>
  24. </div>
  25. <el-dialog v-if="isAddShow"
  26. :model-value="isAddShow"
  27. title="添加类别"
  28. :width="600"
  29. :close-on-click-modal="false"
  30. :before-close="handleAddClose"
  31. >
  32. <el-form :model="formData" :rules="formDataRules" ref="formData" style="width: 80%;margin: 30px auto 0 auto;">
  33. <el-form-item label="类别名称:" prop="title">
  34. <el-input v-model="formData.title" placeholder="请输入类别名称"/>
  35. </el-form-item>
  36. <el-form-item label="类别描述:" prop="content">
  37. <el-input v-model="formData.content" placeholder="请输入类别描述"/>
  38. </el-form-item>
  39. </el-form>
  40. <template #footer>
  41. <el-button type="primary" @click="addMenu">保存</el-button>
  42. </template>
  43. </el-dialog>
  44. </template>
  45. <script>
  46. import menuApi from "@/api/data/MenuData";
  47. export default {
  48. data() {
  49. return {
  50. firstOption: '',
  51. list: [],
  52. loading: false,
  53. isAddShow: false,
  54. formData: {},
  55. formDataRules: {
  56. "title": [
  57. {required: true, message: '请输入标题', trigger: 'blur'},
  58. {required: true, message: '请输入标题', trigger: 'change'}
  59. ],
  60. "content": [
  61. {required: true, message: '请输入描述', trigger: 'blur'},
  62. {required: true, message: '请输入描述', trigger: 'change'}
  63. ]
  64. }
  65. }
  66. },
  67. props: {
  68. type: String,
  69. currVal: String,
  70. },
  71. watch: {
  72. },
  73. emits: ["update:currVal"],
  74. setup(props, context) {
  75. const methods = {
  76. currChange(index) {
  77. context.emit('update:currVal', index)
  78. },
  79. }
  80. return methods;
  81. },
  82. created() {
  83. this.getMenu();
  84. },
  85. mounted() {
  86. },
  87. methods: {
  88. handleAddShow() {
  89. this.isAddShow = true;
  90. },
  91. handleAddClose() {
  92. this.isAddShow = false;
  93. },
  94. addMenu() {
  95. let app = this;
  96. let params = {};
  97. Object.assign(params, this.formData);
  98. params['type'] = app.$constant.menuIds[app.type];
  99. params['parentId'] = app.$constant.menuIds[app.type];
  100. this.$refs.formData.validate(valid=>{
  101. if (valid) {
  102. menuApi.addMenuData(params).then(res=>{
  103. if (res.code===200) {
  104. app.$message({message: '添加成功', type: 'success'});
  105. app.getMenu();
  106. app.handleAddClose();
  107. }
  108. })
  109. }
  110. })
  111. },
  112. getMenu() {
  113. let app = this;
  114. app.loading = true;
  115. let params = {
  116. type: "1",
  117. parentId: this.$constant.menuIds[this.type],
  118. }
  119. app.list = [];
  120. app.firstOption = '';
  121. menuApi.getMenuData(params).then(res=>{
  122. if (res.code===200) {
  123. app.list = res.content;
  124. if (app.list.length>0) {
  125. app.firstOption = app.list[0].id+'';
  126. app.currChange(app.firstOption);
  127. }
  128. }
  129. app.loading = false
  130. }).catch(()=>{
  131. app.loading = false
  132. })
  133. }
  134. }
  135. }
  136. </script>
  137. <style scoped>
  138. #CategoryMenu {
  139. display: inline-block;
  140. width: 15%;
  141. height: 100%;
  142. margin-right: 1%;
  143. }
  144. #CategoryMenu .el-menu-item {
  145. border-radius: 15px;
  146. margin-right: 5%;
  147. font-weight: normal;
  148. }
  149. .Category-menu .el-menu-item {
  150. height: 40px;
  151. }
  152. .Category-menu .el-menu-item span {
  153. font-size: 16px !important;
  154. }
  155. </style>