瀏覽代碼

feat: 谱面元素编辑1.4

TIANYONG 1 年之前
父節點
當前提交
5fad79baa6
共有 2 個文件被更改,包括 25 次插入4 次删除
  1. 23 2
      src/view/plugins/move-music-score/index.tsx
  2. 2 2
      vite.config.ts

+ 23 - 2
src/view/plugins/move-music-score/index.tsx

@@ -176,7 +176,7 @@ export const filterMoveData = async () => {
 				const noteIdx = computedDistance(elementX, elementY);
 				// 此元素距离最近音符的x轴,y轴距离
 				const noteRelativeX = elementX - moveData.noteCoords[noteIdx]?.x, noteRelativeY = elementY - moveData.noteCoords[noteIdx]?.y;
-				const item: any = {
+				let item: any = {
 					id: n.id,
 					isMove: n.isMove,
 					isDelete: n.isDelete,
@@ -194,6 +194,11 @@ export const filterMoveData = async () => {
 				if (n.type === "vf-lineGroup") {
 					item.dx = n.dx;
 				}
+				if (n.id.includes('text')) {
+					// let copyDom = document.querySelector("#" + n.id)!.cloneNode(true) as SVGSVGElement
+					const textContent = document.querySelector("#" + n.id)?.querySelector("text")?.innerHTML || ''
+					item.textContent = textContent
+				}
 				return item;
 			});
 		// if (!list.length) {
@@ -472,7 +477,23 @@ export const renderForMoveData = () => {
 		nextTick(() => {
 			console.log("🚀 ~ list", list);
 			list.forEach((item: any) => {
-				const index = moveData.modelList.findIndex((n: any) => n.id === item.id);
+				let index = moveData.modelList.findIndex((n: any) => n.id === item.id);
+				if (item.type === 'vf-text' && item.textContent) {
+					let textValue = document.querySelector("#" + moveData.modelList[index].id)?.querySelector("text")?.innerHTML || ''
+					let targetIndex = index, preEnd = false;
+					while (textValue !== item.textContent) {
+						if (preEnd) {
+							targetIndex = targetIndex + 1
+						} else {
+							targetIndex = targetIndex > 0 ? targetIndex - 1 : targetIndex
+						}
+						if (targetIndex == 0) preEnd = true
+						textValue = document.querySelector("#" + moveData.modelList[targetIndex].id)?.querySelector("text")?.innerHTML || ''
+					}
+					index = targetIndex + 1
+					item.id = `text${index}`
+				}
+				console.log(66666666,index)
 				if (index > -1) {
 					moveData.modelList[index] = {
 						...moveData.modelList[index],

+ 2 - 2
vite.config.ts

@@ -68,8 +68,8 @@ export default defineConfig({
 				// target: "https://test.lexiaoya.cn",
 				// target: "https://dev.kt.colexiu.com",
 				// target: "https://test.resource.colexiu.com", // 内容平台开发环境,内容平台开发,需在url链接上加上isCbs=true
-				// target: "https://test.resource.colexiu.com",
-				target: "https://test.kt.colexiu.com",
+				target: "https://test.resource.colexiu.com",
+				// target: "https://test.kt.colexiu.com",
 				changeOrigin: true,
 				rewrite: (path) => path.replace(/^\/instrument/, ""),
 			},