index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <div class="basic-steps__wrapper">
  3. <el-steps :active="stepActive" class="basic-steps" :simple="config.simple" :align-center="config.alignCenter" finish-status="success">
  4. <template v-for="(option,optionIndex) in options" :key="optionIndex">
  5. <el-step :title="option.title" :icon="option.icon"/>
  6. </template>
  7. </el-steps>
  8. <div class="basic-steps-content__wrapper" v-if="!outerKey">
  9. <template v-for="({children: step,...stepConfig},optionIndex) in options" :key="optionIndex">
  10. <div v-show="optionIndex === active" class="basic-step-content">
  11. <div class="basic-step-content__title">{{stepConfig.title}}</div>
  12. <slot
  13. name="item"
  14. :optionIndex="optionIndex"
  15. :children="step"
  16. :is-show="optionIndex === active"
  17. :addOptionChild="addOptionChild"
  18. :deleteOptionChild="deleteOptionChild"
  19. :copyOptionChild="copyOptionChild"
  20. :updateOptionChildren="updateOptionChildren"
  21. :updateOptionChild="updateOptionChild"></slot>
  22. </div>
  23. </template>
  24. </div>
  25. <div class="basic-steps__handle" v-if="!outerKey">
  26. <cip-button-text v-if="config.cancel && active === 0" @click="beforeCancel">{{config.cancelText || '取消'}}</cip-button-text>
  27. <cip-button-text @click="prevStep" v-if="active>0" :disabled="false">上一步</cip-button-text>
  28. <cip-button-text type="primary" @click="nextStep" v-if="active<options.length-1" :disabled="false">下一步</cip-button-text>
  29. <cip-button-text v-if="config.finish && active === options.length-1" @click="beforeFinish">{{config.finishText || '完成'}}</cip-button-text>
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. import { computed, ref } from 'vue'
  35. import { ElSteps, ElStep, ElMessage } from 'element-plus'
  36. import CipButtonText from '@cip/components/cip-button-text'
  37. import { layoutProps } from '../layout-props'
  38. import { useFormLayoutOptions } from '../../hooks/use-form-layout'
  39. export default {
  40. name: 'BasicGrid',
  41. props: layoutProps,
  42. components: {
  43. ElSteps, ElStep, CipButtonText
  44. },
  45. emits: ['validate', 'submit', 'cancel'],
  46. setup (props, { emit }) {
  47. const formLayoutOptions = useFormLayoutOptions({ props, emit })
  48. // 内部步骤
  49. const active = ref(0)
  50. const outerKey = computed(() => {
  51. return props.config?.outerKey ?? ''
  52. })
  53. const stepActive = computed(() => {
  54. return outerKey.value ? props.model[outerKey.value] : active.value
  55. })
  56. const prevStep = () => {
  57. active.value--
  58. }
  59. const validate = (result, cb) => {
  60. if (result) {
  61. cb()
  62. } else {
  63. ElMessage.warning('请正确的填写表单内容')
  64. }
  65. }
  66. const nextStep = () => {
  67. if (props.config.validate) {
  68. emit('validate', (result) => {
  69. validate(result, () => {
  70. active.value++
  71. })
  72. })
  73. } else {
  74. active.value++
  75. }
  76. }
  77. const beforeFinish = () => {
  78. emit('validate', (result) => {
  79. validate(result, () => {
  80. emit('submit')
  81. })
  82. })
  83. }
  84. const beforeCancel = () => {
  85. emit('cancel')
  86. }
  87. return {
  88. active,
  89. prevStep,
  90. nextStep,
  91. beforeFinish,
  92. beforeCancel,
  93. stepActive,
  94. outerKey,
  95. ...formLayoutOptions
  96. }
  97. }
  98. }
  99. </script>
  100. <style lang="less">
  101. .basic-steps__wrapper{
  102. padding: 20px;
  103. background: transparent;
  104. }
  105. .basic-steps{
  106. &.el-steps--simple{
  107. overflow: hidden;
  108. background: #fff;
  109. border: 1px solid #ddd;
  110. //padding: 12px;
  111. }
  112. }
  113. .basic-steps-content__wrapper{
  114. margin-top:12px;
  115. background: #fff;
  116. padding: 20px;
  117. border: 1px solid #ddd;
  118. border-radius: 4px;
  119. .basic-step-content{
  120. &__title{
  121. margin-bottom: 12px;
  122. }
  123. }
  124. }
  125. .basic-steps__handle{
  126. text-align: center;
  127. margin-top:12px;
  128. padding: 12px;
  129. background: #fff;
  130. border: 1px solid #ddd;
  131. border-radius: 4px;
  132. }
  133. .form-drawing-layout{ // 仅在设计时展示的样式
  134. .basic-steps__handle{
  135. margin-bottom: 20px;
  136. }
  137. }
  138. </style>