index.jsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. hideHeader: { type: Boolean, default: undefined },
  15. hideHandler: { type: Boolean, default: undefined }
  16. },
  17. setup (props, { slots }) {
  18. const { closeTab } = useMain()
  19. const formValidateRef = ref()
  20. const waiting = ref(false)
  21. const confirm = async (cb) => {
  22. if (typeof cb !== 'function') cb = props.onConfirm
  23. waiting.value = true
  24. try {
  25. await formValidateRef.value.validate()
  26. // 校验通过
  27. const res = await new Promise((resolve, reject) => {
  28. if (typeof cb === 'function') {
  29. cb(resolve, reject)
  30. } else {
  31. reject(new TypeError('onConfirm is not a function'))
  32. }
  33. })
  34. return res ?? true
  35. } finally {
  36. waiting.value = false
  37. }
  38. }
  39. const cipConfig = useCipConfig()
  40. const usingHideHeader = computed(() => {
  41. if (props.hideHeader !== undefined) {
  42. return props.hideHeader
  43. } else {
  44. return cipConfig.layout.hideHeader === true
  45. }
  46. })
  47. const usingHideHandler = computed(() => {
  48. if (props.hideHandler !== undefined) {
  49. return props.hideHandler
  50. } else {
  51. return cipConfig.layout.hideHandler === true
  52. }
  53. })
  54. const handleBackFn = computed(() => {
  55. return getUsingConfig(props.onBack, closeTab)
  56. })
  57. return () => <div class={'cip-page-layout-handle'} v-loading={props.loading}>
  58. {!usingHideHeader.value && <div class={'cip-page-layout-handle__breadcrumb'}>
  59. <CipBreadcrumb canBack={true} back={() => handleBackFn.value()} />
  60. </div>}
  61. <div class={'cip-page-layout-handle__main'}>
  62. <CipFormValidate ref={formValidateRef}>
  63. {slots.default?.()}
  64. </CipFormValidate>
  65. </div>
  66. <template>
  67. </template>
  68. { !usingHideHandler.value && <div class={'cip-page-layout-handle__handler'} >
  69. {(slots.handler || slots.handle)?.({ waiting: waiting.value, confirm })}
  70. </div>}
  71. </div>
  72. }
  73. }