Clean the code via prettier.

This commit is contained in:
yuanhau 2025-05-12 21:05:45 +08:00
parent 57aa0aba18
commit eaa9b15b2d
10 changed files with 177 additions and 165 deletions

View file

@ -1,5 +1,5 @@
<script setup lang="ts">
import { useThrottleFn } from '@vueuse/core'
import { useThrottleFn } from "@vueuse/core";
const props = defineProps<{
title: string;
@ -10,44 +10,52 @@ const props = defineProps<{
}>();
const emit = defineEmits(["close", "min", "maximize", "restore"]);
const title = computed(() => props.title || 'Draggable Window');
const title = computed(() => props.title || "Draggable Window");
const isDragging = ref(false);
const position = ref({
x: props.initialX || Math.floor(window.innerWidth / 2 - (parseInt(props.width || '400') / 2)),
y: props.initialY || Math.floor(window.innerHeight / 2 - (parseInt(props.height || '300') / 2)),
x:
props.initialX ||
Math.floor(window.innerWidth / 2 - parseInt(props.width || "400") / 2),
y:
props.initialY ||
Math.floor(window.innerHeight / 2 - parseInt(props.height || "300") / 2),
});
const offset = ref({ x: 0, y: 0 });
const doDrag = useThrottleFn((e: MouseEvent) => {
if (!isDragging.value) return
if (!isDragging.value) return;
requestAnimationFrame(() => {
position.value = {
x: Math.max(0, Math.min(window.innerWidth - 400, e.clientX - offset.value.x)),
y: Math.max(0, Math.min(window.innerHeight - 300, e.clientY - offset.value.y))
}
})
x: Math.max(
0,
Math.min(window.innerWidth - 400, e.clientX - offset.value.x),
),
y: Math.max(
0,
Math.min(window.innerHeight - 300, e.clientY - offset.value.y),
),
};
});
}, 16);
const startDrag = (e: MouseEvent) => {
isDragging.value = true
isDragging.value = true;
offset.value = {
x: e.clientX - position.value.x,
y: e.clientY - position.value.y
}
document.addEventListener('mousemove', doDrag)
document.addEventListener('mouseup', stopDrag)
}
y: e.clientY - position.value.y,
};
document.addEventListener("mousemove", doDrag);
document.addEventListener("mouseup", stopDrag);
};
const stopDrag = () => {
isDragging.value = false
document.removeEventListener('mousemove', doDrag)
document.removeEventListener('mouseup', stopDrag)
}
isDragging.value = false;
document.removeEventListener("mousemove", doDrag);
document.removeEventListener("mouseup", stopDrag);
};
</script>
<template>

View file

@ -11,7 +11,6 @@ try {
} catch (error) {
console.error("Error:", error);
}
</script>
<template>
<div

View file

@ -3,36 +3,36 @@ import sha512 from "crypto-js/sha512";
const userAccount = ref("");
const userPassword = ref("");
const submitUserPassword = async () => {
// Encrypt password during transit
const password = sha512(userPassword.value).toString();
// Encrypt password during transit
const password = sha512(userPassword.value).toString();
// Send data.
const sendData = await fetch("/api/user/login", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
username: userAccount.value,
password: password,
}),
})
const res = await sendData.json();
// Send data.
const sendData = await fetch("/api/user/login", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
username: userAccount.value,
password: password,
}),
});
const res = await sendData.json();
if (res.status === "ok") {
// Store the token in local storage
localStorage.setItem("token", res.token);
// Redirect to the home page
window.location.href = "/";
success.value = true;
} else {
alert("Login failed");
error.value = true;
}
// Clear the input fields
userAccount.value = "";
userPassword.value = "";
}
if (res.status === "ok") {
// Store the token in local storage
localStorage.setItem("token", res.token);
// Redirect to the home page
window.location.href = "/";
success.value = true;
} else {
alert("Login failed");
error.value = true;
}
// Clear the input fields
userAccount.value = "";
userPassword.value = "";
};
</script>
<template>
<div class="flex flex-col items-center justify-center h-full">

View file

@ -1,22 +1,26 @@
<script setup lang="ts">
const { t, locale } = useI18n();
const { data: source, pending, error } = await useFetch("/api/getData/fetchSources", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: {
lang: locale,
},
const {
data: source,
pending,
error,
} = await useFetch("/api/getData/fetchSources", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: {
lang: locale,
},
});
</script>
<template>
<div >
<div v-for="item in source?.data" :key="item.id">
<h1>{{ item.title }}</h1>
<span>{{ item.description }}</span>
<a :href="item.url">{{ item.url }}</a>
</div>
<div>
<div v-for="item in source?.data" :key="item.id">
<h1>{{ item.title }}</h1>
<span>{{ item.description }}</span>
<a :href="item.url">{{ item.url }}</a>
</div>
</template>
</div>
</template>