PageConfig.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <!--
  2. * @Author: WangJiaCheng
  3. * @Date: 2021-05-11 11:18:32
  4. * @LastEditors: WangJiaCheng
  5. * @LastEditTime: 2021-07-29 16:04:02
  6. * @Description: 页面配置
  7. -->
  8. <template>
  9. <div class="page-edit">
  10. <el-form
  11. ref="pageForm"
  12. :rules="rules"
  13. :model="formData"
  14. label-width="120px"
  15. >
  16. <el-form-item label="页面Tab名称" prop="tabName">
  17. <el-input v-model="formData.tabName" />
  18. </el-form-item>
  19. <el-form-item label="Header 描述" prop="headerDesc">
  20. <el-input v-model="formData.headerDesc" />
  21. </el-form-item>
  22. <el-form-item label="Header 按钮">
  23. <el-tag
  24. v-for="tag in btnTags"
  25. :key="tag"
  26. closable
  27. :disable-transitions="false"
  28. @close="handleClose(tag)"
  29. >
  30. {{ tag }}
  31. </el-tag>
  32. <el-input
  33. v-if="inputVisible"
  34. ref="saveTagInput"
  35. v-model="inputValue"
  36. class="input-new-tag"
  37. size="small"
  38. @keyup.enter.native="handleInputConfirm"
  39. @blur="handleInputConfirm"
  40. />
  41. <el-button v-else class="button-new-tag" size="small" @click="showInput">
  42. 添加按钮
  43. </el-button>
  44. </el-form-item>
  45. <el-form-item label="路由" prop="route">
  46. <el-input v-model="formData.route" />
  47. </el-form-item>
  48. <el-form-item>
  49. <el-button type="primary" @click="next">下一步</el-button>
  50. <el-button type="primary" @click="previewCode">预览入口组件代码</el-button>
  51. </el-form-item>
  52. </el-form>
  53. </div>
  54. </template>
  55. <script>
  56. import { mapMutations } from 'vuex'
  57. export default {
  58. name: 'PageConfig',
  59. data() {
  60. return {
  61. formData: {},
  62. rules: {
  63. tabName: [
  64. { required: true, message: '请输入Tab名称' }
  65. ],
  66. headerDesc: [
  67. { required: true, message: '请输入Header描述' }
  68. ]
  69. },
  70. btnTags: [],
  71. inputVisible: false,
  72. inputValue: ''
  73. }
  74. },
  75. methods: {
  76. ...mapMutations('page', ['setPageConfig', 'setActiveTab']),
  77. handleClose(tag) {
  78. this.btnTags.splice(this.btnTags.indexOf(tag), 1)
  79. },
  80. showInput() {
  81. this.inputVisible = true
  82. this.$nextTick(_ => {
  83. this.$refs.saveTagInput.$refs.input.focus()
  84. })
  85. },
  86. handleInputConfirm() {
  87. const { inputValue } = this
  88. if (inputValue) {
  89. this.btnTags.push(inputValue)
  90. }
  91. this.inputVisible = false
  92. this.inputValue = ''
  93. },
  94. next() {
  95. this.$refs.pageForm.validate(valid => {
  96. if (valid) {
  97. this.setPageConfig({ ...this.formData, btn: this.btnTags })
  98. this.setActiveTab('form')
  99. }
  100. })
  101. },
  102. previewCode() {
  103. this.$refs.pageForm.validate(valid => {
  104. if (valid) {
  105. this.$emit('preview', this.formData)
  106. }
  107. })
  108. }
  109. }
  110. }
  111. </script>
  112. <style lang="less">
  113. .page-edit {
  114. .el-tag + .el-tag {
  115. margin-left: 10px;
  116. }
  117. .button-new-tag {
  118. margin-left: 10px;
  119. height: 32px;
  120. line-height: 30px;
  121. padding-top: 0;
  122. padding-bottom: 0;
  123. }
  124. .input-new-tag {
  125. width: 90px;
  126. margin-left: 10px;
  127. vertical-align: bottom;
  128. }
  129. }
  130. </style>