index.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { defineComponent, onMounted, PropType, ref, Teleport, toRef, toRefs } from 'vue'
  2. import { Row, Col, Tabs, Space, Button } from 'ant-design-vue'
  3. import { LeftOutlined } from '@ant-design/icons-vue'
  4. import './index.less'
  5. const RealView = defineComponent({
  6. props: {
  7. open: {
  8. type: Boolean,
  9. default: false
  10. },
  11. tabKey: {
  12. type: String,
  13. default: ''
  14. },
  15. tabsList: {
  16. type: Array as PropType<{key: string, tab: string}[]>,
  17. default: () => []
  18. },
  19. footer: {
  20. type: Boolean,
  21. default: false
  22. }
  23. },
  24. emits: ['cancel', 'tabChang', 'ok'],
  25. setup (props, ctx) {
  26. const { open, tabKey, tabsList, footer } = toRefs(props)
  27. const cancel = () => ctx.emit('cancel')
  28. const ok = () => ctx.emit('ok')
  29. const onTabChange = (key) => ctx.emit('tabChang', key)
  30. const TabsRender =
  31. <div class="tabs" key={tabKey.value}>
  32. <Tabs activeKey={tabKey.value} tabBarStyle={{ backgroundColor: 'fff', height: '45px' }} onChange={(key) => onTabChange(key)} >
  33. { tabsList.value.map(item => <Tabs.TabPane key={item.key} tab={item.tab}> </Tabs.TabPane>) }
  34. </Tabs>
  35. </div>
  36. return () => (
  37. <>
  38. {
  39. open.value
  40. ? <Teleport to='#content' >
  41. <div class='real-view' id='real-view'>
  42. <Row class='header' >
  43. <div class="back-button" onClick={() => cancel()} >
  44. <LeftOutlined style={{ fontSize: '18px', color: '#ccc' }} />
  45. <span style={{ fontSize: '18px' }} >返回</span>
  46. </div>
  47. </Row>
  48. <div class="tabs" >
  49. <Tabs activeKey={tabKey.value} tabBarStyle={{ backgroundColor: 'fff', height: '45px' }} onChange={(key) => onTabChange(key)} >
  50. { tabsList.value.map(item => <Tabs.TabPane key={item.key} tab={item.tab}> </Tabs.TabPane>) }
  51. </Tabs>
  52. </div>
  53. <div class='real-view-content' >
  54. {ctx.slots.default?.()}
  55. </div>
  56. {/* footer */}
  57. {
  58. footer.value
  59. ? <Row class='footer' >
  60. <Space>
  61. <Button onClick={() => cancel()}>取消</Button>
  62. <Button type='primary' onClick={() => ok()}>确定</Button>
  63. </Space>
  64. </Row>
  65. : null
  66. }
  67. </div>
  68. </Teleport>
  69. : null
  70. }
  71. </>
  72. )
  73. }
  74. })
  75. export { RealView }