featureSlide.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div class="slide" :style="`width: ${width}px`">
  3. <h4 class="d-flex align-center justify-space-between">
  4. 选择功能模块
  5. <v-btn color="primary" small @click="show = true">
  6. <v-icon left>mdi-plus</v-icon>
  7. 自定义模块
  8. </v-btn>
  9. </h4>
  10. <div class="slide_list">
  11. <v-list dense shaped>
  12. <v-list-item v-for="item in items" :key="item.id" class="pa-0">
  13. <v-list-item-content>
  14. <v-list-item-title>{{ item.label }}</v-list-item-title>
  15. </v-list-item-content>
  16. <v-list-item-action class="flex-row">
  17. <v-btn icon @click="handleClick(item)">
  18. <v-icon :color="+item.active ? 'error' : 'info'">
  19. {{ +item.active ? 'mdi-minus-circle' : 'mdi-plus-circle-outline' }}
  20. </v-icon>
  21. </v-btn>
  22. <!-- <v-btn icon @click="handleDelete(item)">
  23. <v-icon color="error">
  24. mdi-trash-can
  25. </v-icon>
  26. </v-btn> -->
  27. </v-list-item-action>
  28. </v-list-item>
  29. </v-list>
  30. </div>
  31. <m-dialog title="新增自定义模块" :visible.sync="show" @submit="handleSubmit">
  32. <form-list ref="form" :items="formItems"></form-list>
  33. </m-dialog>
  34. </div>
  35. </template>
  36. <script>
  37. import FormList from '@/components/Form/list'
  38. import MDialog from '@/components/Dialog'
  39. import { saveWorkbench } from '@/api/menu'
  40. export default {
  41. name: 'featureSlide',
  42. components: {
  43. MDialog,
  44. FormList
  45. },
  46. props: {
  47. width: {
  48. type: [String, Number],
  49. default: '300'
  50. },
  51. items: {
  52. type: Array,
  53. default: () => []
  54. }
  55. },
  56. data () {
  57. return {
  58. show: false,
  59. formItems: {
  60. options: [
  61. {
  62. type: 'text',
  63. key: 'label',
  64. value: null,
  65. label: '请输入标题 *',
  66. outlined: true,
  67. dense: true,
  68. rules: [v => !!v || '请输入标题']
  69. },
  70. {
  71. type: 'text',
  72. key: 'enName',
  73. value: null,
  74. label: '请输入英文标题',
  75. outlined: true,
  76. dense: true
  77. },
  78. {
  79. type: 'text',
  80. key: 'src',
  81. value: null,
  82. label: '请输入第三方地址 *',
  83. outlined: true,
  84. dense: true,
  85. rules: [v => !!v || '请输入第三方地址']
  86. }
  87. ]
  88. }
  89. }
  90. },
  91. methods: {
  92. async handleSubmit () {
  93. if (!this.$refs.form.validate()) {
  94. return
  95. }
  96. const { src, ...obj } = this.formItems.options.reduce((prev, item) => {
  97. prev[item.key] = item.value
  98. return prev
  99. }, {})
  100. try {
  101. await saveWorkbench({
  102. active: '1',
  103. name: 'iframePage',
  104. ...obj,
  105. sort: 999,
  106. meta: {
  107. homeType: 3,
  108. src
  109. }
  110. })
  111. this.$snackbar.success('新增成功')
  112. this.show = false
  113. this.$emit('refresh')
  114. } catch (error) {
  115. this.$snackbar.error(error)
  116. }
  117. },
  118. handleAdd () {
  119. this.show = true
  120. },
  121. handleClick (item) {
  122. item.active = 1 ^ item.active
  123. }
  124. // 删除节点
  125. // async handleDelete (item) {
  126. // console.log(item)
  127. // this.$confirm('提示', '是否确定删除该模块').then()
  128. // }
  129. }
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. .slide_list {
  134. height: calc(100vh - 112px);
  135. overflow-y: auto;
  136. &::-webkit-scrollbar { // 隐藏滚动条
  137. width: 6px;
  138. height: 6px;
  139. display: none;
  140. }
  141. }
  142. </style>