|
@@ -8,8 +8,8 @@ import { onMounted, onUnmounted, reactive, toRefs } from 'vue';
|
|
|
export const useSpeak = (musicContent?: string, selectionCouser?: string) => {
|
|
|
const _musicContent = musicContent ? '#' + musicContent : '#musicContent';
|
|
|
const _selectionCouser = selectionCouser
|
|
|
- ? selectionCouser
|
|
|
- : 'selectionCouser';
|
|
|
+ ? '#' + selectionCouser
|
|
|
+ : '#selectionCouser';
|
|
|
const state = reactive({
|
|
|
showDom: false,
|
|
|
synth: null as any,
|
|
@@ -85,7 +85,8 @@ export const useSpeak = (musicContent?: string, selectionCouser?: string) => {
|
|
|
return 'up';
|
|
|
}
|
|
|
};
|
|
|
- const getSelectText = () => {
|
|
|
+ const getSelectText = (event: any) => {
|
|
|
+ event.preventDefault();
|
|
|
const selection: any = window.getSelection();
|
|
|
const range = selection.rangeCount > 0 ? selection.getRangeAt(0) : null;
|
|
|
|
|
@@ -160,6 +161,7 @@ export const useSpeak = (musicContent?: string, selectionCouser?: string) => {
|
|
|
} else {
|
|
|
state.showDom = false;
|
|
|
}
|
|
|
+
|
|
|
|
|
|
setTimeout(() => {
|
|
|
if (selection.type !== 'Range') {
|
|
@@ -173,6 +175,7 @@ export const useSpeak = (musicContent?: string, selectionCouser?: string) => {
|
|
|
const rects = range.getClientRects();
|
|
|
|
|
|
if (rects.length > 0) {
|
|
|
+ console.log(rects, 'rects');
|
|
|
const firstRect = rects[rects.length - 1];
|
|
|
const x = firstRect.right;
|
|
|
const y = firstRect.top;
|
|
@@ -180,44 +183,52 @@ export const useSpeak = (musicContent?: string, selectionCouser?: string) => {
|
|
|
const fHeight = firstRect.height;
|
|
|
const musicContent: any = document.querySelector(_musicContent);
|
|
|
const parentRect: any = musicContent?.getBoundingClientRect();
|
|
|
- const showDom: any = document.getElementById(_selectionCouser);
|
|
|
+ const showDom: any = document.querySelector(_selectionCouser);
|
|
|
const showDomRect = showDom?.getBoundingClientRect();
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- showDom.style.top =
|
|
|
- (
|
|
|
- y -
|
|
|
- parentRect?.top +
|
|
|
- (showDomRect.height + fHeight / 2) +
|
|
|
- musicContent?.scrollTop
|
|
|
- ).toFixed(2) + 'px';
|
|
|
-
|
|
|
-
|
|
|
- console.log({
|
|
|
- aa: parentRect?.width - showDomRect.width,
|
|
|
- PWidth: parentRect?.width,
|
|
|
- PLeft: parentRect?.left,
|
|
|
- PRight: parentRect?.right,
|
|
|
- x,
|
|
|
- diff: parentRect?.right - x
|
|
|
- });
|
|
|
-
|
|
|
- if (parentRect?.right - x >= parentRect?.width - showDomRect.width) {
|
|
|
- showDom.style.right =
|
|
|
- (parentRect?.width - showDomRect.width).toFixed(2) + 'px';
|
|
|
- showDom.style.left = 'auto';
|
|
|
- } else {
|
|
|
- showDom.style.right = (parentRect?.right - x - 6).toFixed(2) + 'px';
|
|
|
- showDom.style.left = 'auto';
|
|
|
+ if (showDom) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ showDom.style.top =
|
|
|
+ (
|
|
|
+ y -
|
|
|
+ parentRect?.top +
|
|
|
+ (showDomRect.height + fHeight / 2) +
|
|
|
+ musicContent?.scrollTop
|
|
|
+ ).toFixed(2) + 'px';
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (parentRect?.right - x >= parentRect?.width - showDomRect.width) {
|
|
|
+ showDom.style.right =
|
|
|
+ (parentRect?.width - showDomRect.width).toFixed(2) + 'px';
|
|
|
+ showDom.style.left = 'auto';
|
|
|
+ } else {
|
|
|
+ showDom.style.right = (parentRect?.right - x - 6).toFixed(2) + 'px';
|
|
|
+ showDom.style.left = 'auto';
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -482,13 +493,17 @@ export const useSpeak = (musicContent?: string, selectionCouser?: string) => {
|
|
|
|
|
|
const onDestory = () => {
|
|
|
document.removeEventListener('mouseup', getSelectText);
|
|
|
- document.addEventListener('touchend', getSelectText);
|
|
|
+ document.removeEventListener('touchend', getSelectText);
|
|
|
+ document.removeEventListener('touchmove', getSelectText);
|
|
|
onCloseSpeak();
|
|
|
};
|
|
|
|
|
|
onMounted(async () => {
|
|
|
document.addEventListener('mouseup', getSelectText);
|
|
|
document.addEventListener('touchend', getSelectText);
|
|
|
+ document.addEventListener('touchmove', () => {
|
|
|
+ console.log(11111);
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
onUnmounted(() => {
|