index.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { Button, Col, Row, Space, Steps, Modal, Card } from 'ant-design-vue'
  2. import { defineComponent, PropType, computed, ref, createApp } from 'vue'
  3. import './index.less'
  4. interface Steps {
  5. title: string,
  6. description?: string
  7. subTitle?: string
  8. }
  9. export const StepModal = defineComponent({
  10. name: 'step-modal',
  11. props: {
  12. steps: {
  13. type: Array as PropType<Steps[]>,
  14. default: () => []
  15. },
  16. step: {
  17. type: Number,
  18. default: 0
  19. },
  20. visible: {
  21. type: Boolean,
  22. default: false
  23. }
  24. },
  25. emits: ['next', 'pre', 'ok', 'close', 'submit'],
  26. setup (props, ctx) {
  27. const isLastStep = computed(() => props.step + 1 === props.steps.length)
  28. // 已经填写过的step的下标
  29. const writeSteped = ref([0])
  30. // 是否允许当前进行下一步
  31. const nextStep = () => {
  32. if (isLastStep.value) {
  33. ctx.emit('submit')
  34. } else {
  35. writeSteped.value.push(writeSteped.value.length)
  36. ctx.emit('next')
  37. }
  38. }
  39. const close = () => {
  40. ctx.emit('close')
  41. }
  42. const preStep = () => {
  43. ctx.emit('pre')
  44. }
  45. return () => (
  46. <Modal
  47. class='step-modal'
  48. visible={props.visible}
  49. title={false}
  50. closable={false}
  51. footer={null}
  52. >
  53. <Row class='steps' >
  54. <Steps
  55. size="small"
  56. current={props.step}
  57. items={props.steps}
  58. ></Steps>
  59. </Row>
  60. <Row class='step-modal-content' >
  61. {ctx.slots.default!()}
  62. </Row>
  63. <Row class='footer' align='middle' justify='space-between' >
  64. <Col>
  65. <Space>
  66. <Button disabled={props.step === 0} onClick={preStep} >上一步</Button>
  67. <Button onClick={nextStep} >{isLastStep.value ? '提交' : '下一步'}</Button>
  68. <Button onClick={close} >取消</Button>
  69. </Space>
  70. </Col>
  71. </Row>
  72. </Modal>
  73. )
  74. }
  75. })