mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-06 03:57:56 +08:00
chore: 使用on-before-unmount替换on-unmouted
This commit is contained in:
parent
f212be136e
commit
b72e487b58
@ -14,7 +14,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { computed, nextTick, ref, watch } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
import type { SelectProps } from './types';
|
||||
@ -49,14 +49,16 @@ const visibleHandler = (...args: any[]) => {
|
||||
|
||||
const scrollbarWrap = ref<HTMLDivElement | undefined>();
|
||||
|
||||
const unWacth = watch(
|
||||
const unWatch = watch(
|
||||
() => select.value?.scrollbar?.wrap$ || select.value?.scrollbar?.wrapRef,
|
||||
(wrap) => {
|
||||
if (!wrap) {
|
||||
return;
|
||||
}
|
||||
|
||||
nextTick(() => unWatch());
|
||||
|
||||
scrollbarWrap.value = wrap;
|
||||
unWacth();
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
|
@ -48,7 +48,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, inject, onUnmounted, ref } from 'vue';
|
||||
import { computed, inject, onBeforeUnmount, ref } from 'vue';
|
||||
|
||||
import { TMagicButton, TMagicDialog, tMagicMessage, tMagicMessageBox, TMagicTag } from '@tmagic/design';
|
||||
import { ColumnConfig, FormConfig, FormState, MFormBox, MFormDrawer } from '@tmagic/form';
|
||||
@ -85,7 +85,7 @@ const windowReizehandler = () => {
|
||||
|
||||
globalThis.addEventListener('resize', windowReizehandler);
|
||||
|
||||
onUnmounted(() => {
|
||||
onBeforeUnmount(() => {
|
||||
globalThis.removeEventListener('resize', windowReizehandler);
|
||||
});
|
||||
|
||||
|
@ -36,7 +36,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, nextTick, onMounted, onUnmounted, ref } from 'vue';
|
||||
import { computed, nextTick, onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
|
||||
import { MenuButton, MenuComponent } from '@editor/type';
|
||||
|
||||
@ -99,7 +99,7 @@ const clickHandler = () => {
|
||||
hide();
|
||||
};
|
||||
|
||||
const outsideClickhideHandler = (e: MouseEvent) => {
|
||||
const outsideClickHideHandler = (e: MouseEvent) => {
|
||||
if (!props.autoHide) return;
|
||||
|
||||
const target = e.target as HTMLElement | undefined;
|
||||
@ -173,13 +173,13 @@ const mouseenterHandler = () => {
|
||||
onMounted(() => {
|
||||
if (props.isSubMenu) return;
|
||||
|
||||
globalThis.addEventListener('mousedown', outsideClickhideHandler, true);
|
||||
globalThis.addEventListener('mousedown', outsideClickHideHandler, true);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
onBeforeUnmount(() => {
|
||||
if (props.isSubMenu) return;
|
||||
|
||||
globalThis.removeEventListener('mousedown', outsideClickhideHandler, true);
|
||||
globalThis.removeEventListener('mousedown', outsideClickHideHandler, true);
|
||||
});
|
||||
|
||||
defineExpose({
|
||||
|
@ -5,7 +5,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue';
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import Gesto from 'gesto';
|
||||
|
||||
defineOptions({
|
||||
@ -53,7 +53,7 @@ onMounted(() => {
|
||||
bar.value?.addEventListener('wheel', wheelHandler, false);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
onBeforeUnmount(() => {
|
||||
if (gesto) gesto.off();
|
||||
bar.value?.removeEventListener('wheel', wheelHandler, false);
|
||||
});
|
||||
|
@ -23,7 +23,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { isNumber } from '@tmagic/utils';
|
||||
|
||||
@ -94,7 +94,7 @@ onMounted(() => {
|
||||
});
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
onBeforeUnmount(() => {
|
||||
scrollViewer.destroy();
|
||||
});
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue';
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import { OnDrag } from 'gesto';
|
||||
|
||||
import Resizer from './Resizer.vue';
|
||||
@ -110,7 +110,7 @@ onMounted(() => {
|
||||
}
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
onBeforeUnmount(() => {
|
||||
resizerObserver.disconnect();
|
||||
});
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { onMounted, onUnmounted, type Ref, ref } from 'vue';
|
||||
import { onBeforeUnmount, onMounted, type Ref, ref } from 'vue';
|
||||
import Gesto, { type OnDrag } from 'gesto';
|
||||
|
||||
export const useGetSo = (target: Ref<HTMLElement | undefined>, emit: (evt: 'change', e: OnDrag<Gesto>) => void) => {
|
||||
@ -24,7 +24,7 @@ export const useGetSo = (target: Ref<HTMLElement | undefined>, emit: (evt: 'chan
|
||||
});
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
onBeforeUnmount(() => {
|
||||
getso?.unset();
|
||||
isDraging.value = false;
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { onUnmounted, reactive, toRaw, watch } from 'vue';
|
||||
import { onBeforeUnmount, reactive, toRaw, watch } from 'vue';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
|
||||
import type { EventOption } from '@tmagic/core';
|
||||
@ -165,7 +165,7 @@ export const initServiceState = (
|
||||
},
|
||||
);
|
||||
|
||||
onUnmounted(() => {
|
||||
onBeforeUnmount(() => {
|
||||
editorService.resetState();
|
||||
historyService.resetState();
|
||||
propsService.resetState();
|
||||
@ -405,7 +405,7 @@ export const initServiceEvents = (
|
||||
depService.addTarget(createRelatedCompTarget(props.collectorOptions));
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
onBeforeUnmount(() => {
|
||||
depService.off('add-target', targetAddHandler);
|
||||
depService.off('remove-target', targetRemoveHandler);
|
||||
depService.off('dep-update', depUpdateHandler);
|
||||
|
@ -19,7 +19,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
import { onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
import { FullScreen } from '@element-plus/icons-vue';
|
||||
import { throttle } from 'lodash-es';
|
||||
import * as monaco from 'monaco-editor';
|
||||
@ -188,7 +188,7 @@ onMounted(async () => {
|
||||
init();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
onBeforeUnmount(() => {
|
||||
resizeObserver.disconnect();
|
||||
});
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, getCurrentInstance, inject, onMounted, onUnmounted, ref, watchEffect } from 'vue';
|
||||
import { computed, getCurrentInstance, inject, onBeforeUnmount, onMounted, ref, watchEffect } from 'vue';
|
||||
|
||||
import { tMagicMessage } from '@tmagic/design';
|
||||
import type { FormState, FormValue } from '@tmagic/form';
|
||||
@ -64,7 +64,7 @@ onMounted(() => {
|
||||
emit('mounted', internalInstance);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
onBeforeUnmount(() => {
|
||||
services?.propsService.off('props-configs-change', init);
|
||||
});
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, inject, nextTick, onMounted, onUnmounted, ref, toRaw, watch } from 'vue';
|
||||
import { computed, inject, nextTick, onBeforeUnmount, onMounted, ref, toRaw, watch } from 'vue';
|
||||
import { ArrowLeftBold, ArrowRightBold, Plus } from '@element-plus/icons-vue';
|
||||
|
||||
import { NodeType } from '@tmagic/schema';
|
||||
@ -72,7 +72,7 @@ onMounted(() => {
|
||||
pageBar.value && resizeObserver.observe(pageBar.value);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
onBeforeUnmount(() => {
|
||||
resizeObserver.disconnect();
|
||||
});
|
||||
|
||||
|
@ -56,6 +56,8 @@ const unWatch = watch(
|
||||
(stage) => {
|
||||
if (!stage) return;
|
||||
|
||||
nextTick(() => unWatch());
|
||||
|
||||
stage.on('select', (el: HTMLElement, event: MouseEvent) => {
|
||||
const els = stage.renderer.getElementsFromPoint(event) || [];
|
||||
const ids = els.map((el) => el.id).filter((id) => Boolean(id));
|
||||
@ -64,8 +66,6 @@ const unWatch = watch(
|
||||
|
||||
filterTextChangeHandler(ids);
|
||||
});
|
||||
|
||||
unWatch();
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
|
@ -31,7 +31,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, inject, markRaw, nextTick, onMounted, onUnmounted, ref, toRaw, watch, watchEffect } from 'vue';
|
||||
import { computed, inject, markRaw, nextTick, onBeforeUnmount, onMounted, ref, toRaw, watch, watchEffect } from 'vue';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
|
||||
import type { MApp, MContainer } from '@tmagic/schema';
|
||||
@ -140,7 +140,7 @@ onMounted(() => {
|
||||
}
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
onBeforeUnmount(() => {
|
||||
stage?.destroy();
|
||||
resizeObserver.disconnect();
|
||||
services?.editorService.set('stage', null);
|
||||
|
@ -26,7 +26,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { inject, onBeforeMount, Ref, ref, watch, watchEffect } from 'vue';
|
||||
import { inject, nextTick, onBeforeMount, Ref, ref, watch, watchEffect } from 'vue';
|
||||
|
||||
import { TMagicSelect } from '@tmagic/design';
|
||||
import { getValueByKeyPath } from '@tmagic/utils';
|
||||
@ -331,12 +331,15 @@ if (typeof props.config.options === 'function') {
|
||||
}
|
||||
|
||||
if (props.config.remote) {
|
||||
const unWacth = watch(
|
||||
const unWatch = watch(
|
||||
() => tMagicSelect.value?.scrollbarWrap,
|
||||
(scrollbarWrap) => {
|
||||
if (!scrollbarWrap) {
|
||||
return;
|
||||
}
|
||||
|
||||
nextTick(() => unWatch());
|
||||
|
||||
scrollbarWrap.addEventListener('scroll', async (e: Event) => {
|
||||
const el = e.currentTarget as HTMLDivElement;
|
||||
if (moreLoadingVisible.value) {
|
||||
@ -353,7 +356,6 @@ if (props.config.remote) {
|
||||
options.value = await getOptions();
|
||||
moreLoadingVisible.value = false;
|
||||
});
|
||||
unWacth();
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
|
@ -16,7 +16,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { getCurrentInstance, inject, onMounted, onUnmounted } from 'vue';
|
||||
import { getCurrentInstance, inject, onBeforeUnmount, onMounted } from 'vue';
|
||||
|
||||
import Core from '@tmagic/core';
|
||||
|
||||
@ -32,7 +32,7 @@ export default (props: any) => {
|
||||
node?.emit('mounted', vm);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
onBeforeUnmount(() => {
|
||||
node?.emit('destroy', vm);
|
||||
});
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { inject, onMounted, onUnmounted } from 'vue';
|
||||
import { inject, onBeforeUnmount, onMounted } from 'vue';
|
||||
|
||||
import Core from '@tmagic/core';
|
||||
import type { MComponent } from '@tmagic/schema';
|
||||
@ -43,7 +43,7 @@ export default ({ config, methods }: UseAppOptions) => {
|
||||
node?.emit('mounted', emitData);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
onBeforeUnmount(() => {
|
||||
node?.emit('destroy', emitData);
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user