Jelajahi Sumber

feat: 修复保存磁贴异常问题
1. 修复了磁贴保存时重复触发为编辑模式的问题
2. message组件的使用, 以及渲染目标调整

kindring 8 bulan lalu
induk
melakukan
b9663659ba
4 mengubah file dengan 26 tambahan dan 14 penghapusan
  1. 3 0
      src/App.vue
  2. 19 13
      src/components/magnets/magnetView.vue
  3. 1 1
      src/components/window/macWindow.vue
  4. 3 0
      src/main.ts

+ 3 - 0
src/App.vue

@@ -41,6 +41,9 @@ const pageKey = ref(homePageKey);
 const editMode = ref(false);
 function editModeChange() {
   editMode.value = !editMode.value;
+  if(!editMode.value){
+    // 重新加载磁贴数据
+  }
 }
 
 const navAction = (actionCode:string) => {

+ 19 - 13
src/components/magnets/magnetView.vue

@@ -18,9 +18,10 @@ import {ErrorCode, ResponseData} from "@/types/apiTypes.ts";
 import MagnetTable from "@/components/magnets/magnetTable.vue";
 import KuiDialog from "@/components/public/kui-dialog.vue";
 
-
 import TimeManger from "@/components/magnets/timeMagnet.vue"
 
+import kuiMessage from "@/components/public/kui/message"
+
 initComponents()
 function initComponents() {
   initTypeComponent(timeMagnetInfo.type, TimeManger)
@@ -56,8 +57,8 @@ function eventHandler(magnetEmit: MagnetEmit<any>){
       daySelect(magnetEmit.data)
     break;
     default:
-      console.log('no match event')
-      console.log(magnetEmit)
+      kuiMessage.warning('no match event')
+      console.warn(magnetEmit)
     break;
   }
 }
@@ -175,7 +176,6 @@ function moveInitHandle(drag: Drag)
 {
   // 获取父元素的最大可用宽度
   maxWidth = comMaxWidth(drag.parent.width) || 10
-  console.log(`maxWidth ${maxWidth}`)
 }
 
 function moveHandle(magnet: Magnet, moveInfo: MoveInfo){
@@ -238,8 +238,7 @@ function saveMagnet(){
     if(magnet.changed) changeMagnets.push(magnet)
   }
   // 存储数据
-  console.log(`修改的位置的组件有 ${changeMagnets.length}`)
-
+  saveMagnets(true)
 }
 
 
@@ -247,17 +246,18 @@ async function deleteMagnetHandle(magnet: Magnet) {
   console.log(`移除磁贴 ${magnet.id}`)
   let result: ResponseData<boolean> = await deleteMagnet(magnet.id);
   if( result.code !== ErrorCode.success){
-    console.log(result.msg)
+    kuiMessage.log(result.msg)
     return
   }
   // 移除元素
   let idx = magnetItems.findIndex(item => item.id === magnet.id)
   if (idx < 0)
   {
-    console.log(`no match magnet ${magnet.id}`)
+    kuiMessage.error(`no match magnet ${magnet.id}`)
     return
   }
   magnetItems.splice(idx, 1)
+  kuiMessage.success(`移除磁贴成功`);
   // magnetItems.
 }
 
@@ -279,7 +279,7 @@ function setIsSite(value: boolean = false) {
 
 async function addMagnetHandle(addMagnetInfo: AddMagnetInfo)
 {
-  console.log(`add magnet type:${addMagnetInfo.type} size:${addMagnetInfo.size}`)
+  // console.log(`add magnet type:${addMagnetInfo.type} size:${addMagnetInfo.size}`)
   setIsSite(false)
   setIsOpen(false)
   // 生成新的组件
@@ -313,11 +313,17 @@ async function addMagnetHandle(addMagnetInfo: AddMagnetInfo)
   myEditMode.value = true;
 }
 
-async function saveMagnets(){
+async function saveMagnets(isOut: boolean = false){
   let result = await changeMagnets(magnetItems);
-  console.log('保存完成');
-  console.log(result);
-  emit('editModeChange')
+
+  if(result.code !== ErrorCode.success){
+    kuiMessage.error(`保存磁贴失败 ${result.msg}`)
+    return
+  }
+  kuiMessage.success('保存磁贴成功')
+  if(!isOut){
+    emit('editModeChange')
+  }
 }
 
 </script>

+ 1 - 1
src/components/window/macWindow.vue

@@ -94,7 +94,7 @@ onMounted(()=>{
           </div>
         </div>
       </div>
-      <div class="window-content" id="kui-dialog">
+      <div class="window-content" id="kui-root">
         <slot></slot>
       </div>
     </div>

+ 3 - 0
src/main.ts

@@ -6,12 +6,15 @@ import {bindIconSvg} from "@/components/public/icon/iconSvg.ts";
 import magnetInfos from "@/components/magnets/magnetInfo.ts";
 import TimeMagnet from "@/components/magnets/timeMagnet.vue";
 
+import kuiMessage from "@/components/public/kui/message"
+
 
 const app: App = createApp(AppPage)
 
 windowInit(app, "main");
 bindIconSvg(app);
 
+kuiMessage.install(app);
 
 app.mount('#app');
 app.component(magnetInfos.timeMagnetInfo.type, TimeMagnet);