|
@@ -2,67 +2,139 @@ import {ExtractPropTypes, ref} from 'vue'
|
|
|
import {useCyNamespace} from "@/utils/xiaochan-element-plus";
|
|
|
import {useResizeObserver} from "@vueuse/core";
|
|
|
import {useDraggable} from "element-plus";
|
|
|
+import {ClosingMethod, compList} from "@/components/js-dialog-comp/useDialogToJs";
|
|
|
+import {isPromise} from "@/utils/public";
|
|
|
|
|
|
-
|
|
|
-export const CyDialogProps = buildProps({
|
|
|
+export const CyDialogProps = {
|
|
|
title: String,
|
|
|
fullScreen: {
|
|
|
type: Boolean,
|
|
|
default: false
|
|
|
+ },
|
|
|
+ confirmText: {
|
|
|
+ type: String,
|
|
|
+ default: '确认',
|
|
|
+ },
|
|
|
+ cancelText: {
|
|
|
+ type: String,
|
|
|
+ default: '取消',
|
|
|
+ },
|
|
|
+ confirmClick: {
|
|
|
+ type: Function,
|
|
|
+ default: null
|
|
|
+ },
|
|
|
+ cancelClick: {
|
|
|
+ type: Function,
|
|
|
+ default: null
|
|
|
+ },
|
|
|
+ bodyHeight: {
|
|
|
+ type: [Number, String],
|
|
|
+ default: '500px'
|
|
|
+ },
|
|
|
+ bodyWidth: {
|
|
|
+ type: [Number, String],
|
|
|
+ default: '500px'
|
|
|
}
|
|
|
-})
|
|
|
+}
|
|
|
|
|
|
export type IsCyDialog = ExtractPropTypes<typeof CyDialogProps>
|
|
|
|
|
|
export function UseCyDialog(props: IsCyDialog) {
|
|
|
- const ns = useCyNamespace('combo-grid')
|
|
|
+ const ns = useCyNamespace('dialog')
|
|
|
const headerRef = ref()
|
|
|
const footerRef = ref()
|
|
|
const containerRef = ref()
|
|
|
const boxRef = ref()
|
|
|
const bodyRef = ref()
|
|
|
+ const ctx = getCurrentInstance()
|
|
|
|
|
|
- const observerHeight = ref({
|
|
|
- headerHeight: 0,
|
|
|
- footerHeight: 0,
|
|
|
- boxHeight: 0,
|
|
|
+ const state = reactive({
|
|
|
bodySize: {
|
|
|
height: 0,
|
|
|
width: 0
|
|
|
- }
|
|
|
+ },
|
|
|
+ headerHeight: 0,
|
|
|
+ footerHeight: 0,
|
|
|
+ })
|
|
|
+
|
|
|
+ const draggable = computed(() => {
|
|
|
+ return true;
|
|
|
})
|
|
|
|
|
|
const bodyHeightStyle = computed(() => {
|
|
|
- return {
|
|
|
- height: observerHeight.value.boxHeight - observerHeight.value.headerHeight - observerHeight.value.footerHeight + 'px'
|
|
|
+ if (props.fullScreen) {
|
|
|
+ return {
|
|
|
+ height: `calc(100% - ${state.headerHeight}px - ${state.footerHeight}px)`
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return {
|
|
|
+ height: props.bodyHeight
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
|
|
|
useResizeObserver(headerRef, (entries) => {
|
|
|
- observerHeight.value.headerHeight = entries[0].target.offsetHeight
|
|
|
- })
|
|
|
-
|
|
|
- useResizeObserver(boxRef, (entries) => {
|
|
|
- observerHeight.value.boxHeight = entries[0].target.offsetHeight
|
|
|
+ state.headerHeight = entries[0].target.offsetHeight
|
|
|
})
|
|
|
|
|
|
useResizeObserver(footerRef, (entries) => {
|
|
|
- observerHeight.value.footerHeight = entries[0].target.offsetHeight
|
|
|
+ state.footerHeight = entries[0].target.offsetHeight
|
|
|
})
|
|
|
|
|
|
useResizeObserver(bodyRef, (entries) => {
|
|
|
- observerHeight.value.bodySize = {
|
|
|
+ state.bodySize = {
|
|
|
height: entries[0].target.offsetHeight,
|
|
|
width: entries[0].target.offsetWidth,
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- const draggable = computed(() => {
|
|
|
- return true;
|
|
|
- })
|
|
|
-
|
|
|
useDraggable(boxRef, headerRef, draggable)
|
|
|
|
|
|
+ function closed(closingMethod, ...val) {
|
|
|
+ compList.value[ctx?.attrs.id].onClosed(closingMethod, val)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function handleConfirm() {
|
|
|
+ let value = null
|
|
|
+ let isDone = true
|
|
|
+
|
|
|
+ function next(val) {
|
|
|
+ isDone = false
|
|
|
+ closed(ClosingMethod.CONFIRM, val)
|
|
|
+ }
|
|
|
+
|
|
|
+ if (props.confirmClick) {
|
|
|
+ isDone = false
|
|
|
+ props.confirmClick(next)
|
|
|
+ }
|
|
|
+
|
|
|
+ isDone && next(value)
|
|
|
+ }
|
|
|
+
|
|
|
+ function handleCancel() {
|
|
|
+ let value = null
|
|
|
+ let isDone = true
|
|
|
+
|
|
|
+ function next(val) {
|
|
|
+ isDone = false
|
|
|
+ closed(ClosingMethod.CANCEL, val)
|
|
|
+ }
|
|
|
+
|
|
|
+ if (props.cancelClick) {
|
|
|
+ isDone = false
|
|
|
+ props.cancelClick(next)
|
|
|
+ }
|
|
|
+
|
|
|
+ isDone && next(value)
|
|
|
+ }
|
|
|
+
|
|
|
+ function onFocusoutPrevented(event: CustomEvent) {
|
|
|
+ if (event.detail?.focusReason === 'pointer') {
|
|
|
+ event.preventDefault()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
return {
|
|
|
ns,
|
|
@@ -72,6 +144,9 @@ export function UseCyDialog(props: IsCyDialog) {
|
|
|
containerRef,
|
|
|
boxRef,
|
|
|
bodyRef,
|
|
|
- observerHeight
|
|
|
+ state,
|
|
|
+ handleConfirm,
|
|
|
+ handleCancel,
|
|
|
+ onFocusoutPrevented
|
|
|
}
|
|
|
}
|