const fs = require("fs");
const path = "D:/骅锋/mall/layouts/admin/components/AdminHeader.uvue";

let text = fs.readFileSync(path, "utf-8");

const targetScript = `<script setup lang="uts">
import { ref, computed } from 'vue'
import {
  toggleSubSider,
  showSubSider,
  layoutMode,
  isOverlayVisible,
  isMobileMenuOpen,
  openRoute
} from '@/layouts/admin/store/adminNavStore.uts'
import { state, logout } from '@/utils/store.uts'

const showUserMenu = ref(false)
const userName = computed((): string => state.userProfile.username || state.userProfile.email || 'admin')

let menuTimer: number | null = null

function handleMouseEnter() {
  if (menuTimer !== null) {
    clearTimeout(menuTimer)
    menuTimer = null
  }
  showUserMenu.value = true
}

function handleMouseLeave() {
  menuTimer = setTimeout(() => {
    showUserMenu.value = false
  }, 300) as unknown as number
}

function toggleUserMenu() {
  showUserMenu.value = !showUserMenu.value
}

function goToUserCenter() {
  showUserMenu.value = false
  openRoute('home_user_center')
}

function handleLogout() {
  showUserMenu.value = false
  uni.showModal({
    title: '提示',
    content: '确定要退出登录吗？',
    success: (res) => {
      if (res.confirm) {
        logout()
        uni.removeStorageSync('adminRole')
        uni.removeStorageSync('token')
        uni.reLaunch({
          url: '/pages/user/login'
        })
      }
    }
  })
}

const props = defineProps<{`;

text = text.replace(
  /<script setup lang=["']uts["']>[\s\S]*?const props = defineProps</,
  targetScript + "",
);

fs.writeFileSync(path, text, "utf-8");
console.log("Done");
