index.jsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import CipBreadcrumb from '@cip/components/main/cip-main-breadcrumb'
  2. import './index.less'
  3. import { computed, ref } from 'vue'
  4. import { useMain } from '@cip/hooks/use-main'
  5. import { useCipConfig } from '@cip/components/hooks/use-cip-config'
  6. import CipFormValidate from '@cip/components/cip-form-validate'
  7. import { getUsingConfig } from '@cip/utils/util'
  8. export default {
  9. name: 'CipPageLayoutHandle',
  10. props: {
  11. loading: Boolean,
  12. onConfirm: Function,
  13. onBack: Function,
  14. canBack: {type: Boolean, default: true},
  15. hideHeader: { type: Boolean, default: undefined },
  16. hideHandler: { type: Boolean, default: undefined }
  17. },
  18. setup (props, { slots }) {
  19. const { closeTab } = useMain()
  20. const formValidateRef = ref()
  21. const waiting = ref(false)
  22. const confirm = async (cb) => {
  23. if (typeof cb !== 'function') cb = props.onConfirm
  24. waiting.value = true
  25. try {
  26. await formValidateRef.value.validate()
  27. // 校验通过
  28. const res = await new Promise((resolve, reject) => {
  29. if (typeof cb === 'function') {
  30. cb(resolve, reject)
  31. } else {
  32. reject(new TypeError('onConfirm is not a function'))
  33. }
  34. })
  35. return res ?? true
  36. } finally {
  37. waiting.value = false
  38. }
  39. }
  40. const cipConfig = useCipConfig()
  41. const usingHideHeader = computed(() => {
  42. if (props.hideHeader !== undefined) {
  43. return props.hideHeader
  44. } else {
  45. return cipConfig.layout.hideHeader === true
  46. }
  47. })
  48. const usingHideHandler = computed(() => {
  49. if (props.hideHandler !== undefined) {
  50. return props.hideHandler
  51. } else {
  52. return cipConfig.layout.hideHandler === true
  53. }
  54. })
  55. const handleBackFn = computed(() => {
  56. return getUsingConfig(props.onBack, closeTab)
  57. })
  58. return () => <div class={'cip-page-layout-handle'} v-loading={props.loading}>
  59. {!usingHideHeader.value && <div class={'cip-page-layout-handle__breadcrumb'}>
  60. <CipBreadcrumb canBack={props.canBack} back={() => handleBackFn.value()} />
  61. </div>}
  62. <div class={'cip-page-layout-handle__main'}>
  63. <CipFormValidate ref={formValidateRef}>
  64. {slots.default?.()}
  65. </CipFormValidate>
  66. </div>
  67. <template>
  68. </template>
  69. { !usingHideHandler.value && <div class={'cip-page-layout-handle__handler'} >
  70. {(slots.handler || slots.handle)?.({ waiting: waiting.value, confirm })}
  71. </div>}
  72. </div>
  73. }
  74. }