mirror of
https://github.com/ZeroCatDev/Classworks.git
synced 2025-07-04 10:29:23 +00:00
1
This commit is contained in:
parent
4a8f4dc097
commit
3988773341
@ -13,7 +13,7 @@
|
||||
<div class="d-flex flex-column align-start">
|
||||
<v-avatar size="120" class="mb-4">
|
||||
<v-img
|
||||
src="https://github.com/Sunwuyuan.png"
|
||||
src="https://github.com/SunWuyuan.png"
|
||||
alt="Sunwuyuan"
|
||||
/>
|
||||
</v-avatar>
|
||||
|
@ -7,21 +7,16 @@
|
||||
>
|
||||
<v-card-text>
|
||||
<div ref="typewriter" class="typewriter-text"></div>
|
||||
<div ref="sourceWriter" class="source-text text-caption text-grey"></div>
|
||||
<div ref="sourceWriter" class="source-text"></div>
|
||||
</v-card-text>
|
||||
<div class="d-flex align-center">
|
||||
<transition name="fade">
|
||||
<div v-if="currentQuote?.contributor" class="contributor">
|
||||
<v-chip>
|
||||
<v-avatar start>
|
||||
<v-img
|
||||
:src="`https://github.com/${currentQuote.contributor}.png`"
|
||||
></v-img> </v-avatar
|
||||
>{{ currentQuote.contributor }}
|
||||
</v-chip>
|
||||
</div>
|
||||
</transition>
|
||||
</div>
|
||||
<transition name="fade">
|
||||
<v-chip v-if="currentQuote?.contributor" class="contributor">
|
||||
<v-avatar start>
|
||||
<v-img :src="`https://github.com/${currentQuote.contributor}.png`" />
|
||||
</v-avatar>
|
||||
{{ currentQuote.contributor }}
|
||||
</v-chip>
|
||||
</transition>
|
||||
</settings-card>
|
||||
</template>
|
||||
|
||||
@ -30,129 +25,88 @@ import Typewriter from "typewriter-effect/dist/core";
|
||||
import quotes from "@/data/echoChamber.json";
|
||||
import SettingsCard from "@/components/SettingsCard.vue";
|
||||
|
||||
const INITIAL_STATE = {
|
||||
text: "点击此处可以查看 Classworks 用户群里沙雕群友们的发言",
|
||||
author: "点击后会复制当前句子到剪贴板中"
|
||||
};
|
||||
|
||||
const TYPEWRITER_CONFIG = {
|
||||
main: { delay: 50, deleteSpeed: 100 },
|
||||
source: { delay: 10, deleteSpeed: 10, cursor: "" }
|
||||
};
|
||||
|
||||
export default {
|
||||
name: "EchoChamberCard",
|
||||
components: { SettingsCard },
|
||||
data() {
|
||||
return {
|
||||
typewriter: null,
|
||||
sourceWriter: null,
|
||||
currentQuote: {
|
||||
text: this.INITIAL_TEXT,
|
||||
author: this.INITIAL_SOURCE,
|
||||
},
|
||||
showCopySuccess: false,
|
||||
hasClicked: false,
|
||||
INITIAL_TEXT: "点击此处可以查看 Classworks 用户群里沙雕群友们的发言",
|
||||
INITIAL_SOURCE: "点击后会复制当前句子到剪贴板中",
|
||||
};
|
||||
},
|
||||
data: () => ({
|
||||
typewriter: null,
|
||||
sourceWriter: null,
|
||||
currentQuote: INITIAL_STATE,
|
||||
hasClicked: false
|
||||
}),
|
||||
|
||||
mounted() {
|
||||
this.initTypewriters();
|
||||
},
|
||||
|
||||
methods: {
|
||||
getRandomQuote() {
|
||||
const index = Math.floor(Math.random() * quotes.quotes.length);
|
||||
return quotes.quotes[index];
|
||||
},
|
||||
initTypewriters() {
|
||||
// 主文本打字机
|
||||
this.typewriter = new Typewriter(this.$refs.typewriter, {
|
||||
delay: 50,
|
||||
deleteSpeed: 100,
|
||||
loop: false,
|
||||
});
|
||||
|
||||
// 来源文本打字机
|
||||
this.sourceWriter = new Typewriter(this.$refs.sourceWriter, {
|
||||
delay: 10,
|
||||
deleteSpeed: 10,
|
||||
loop: false,
|
||||
cursor: "",
|
||||
});
|
||||
|
||||
// 显示初始提示
|
||||
this.typewriter.typeString(this.INITIAL_TEXT).start();
|
||||
this.sourceWriter.typeString(this.INITIAL_SOURCE).start();
|
||||
this.typewriter = new Typewriter(this.$refs.typewriter, TYPEWRITER_CONFIG.main);
|
||||
this.sourceWriter = new Typewriter(this.$refs.sourceWriter, TYPEWRITER_CONFIG.source);
|
||||
this.typeQuote(INITIAL_STATE);
|
||||
},
|
||||
|
||||
typeQuote(quote) {
|
||||
this.typewriter.deleteAll(30).typeString(quote.text).start();
|
||||
|
||||
if (quote.author) {
|
||||
this.sourceWriter.deleteAll(20).typeString(`${quote.author}`).start();
|
||||
this.sourceWriter.deleteAll(20).typeString(quote.author).start();
|
||||
}
|
||||
},
|
||||
|
||||
refreshQuote() {
|
||||
this.currentQuote = this.getRandomQuote();
|
||||
this.typeQuote(this.currentQuote);
|
||||
},
|
||||
|
||||
async handleClick() {
|
||||
if (!this.hasClicked) {
|
||||
this.hasClicked = true;
|
||||
this.currentQuote = this.getRandomQuote();
|
||||
}
|
||||
await this.copyToClipboard();
|
||||
this.refreshQuote();
|
||||
this.currentQuote = this.getRandomQuote();
|
||||
this.typeQuote(this.currentQuote);
|
||||
},
|
||||
|
||||
getRandomQuote() {
|
||||
return quotes.quotes[Math.floor(Math.random() * quotes.quotes.length)];
|
||||
},
|
||||
|
||||
async copyToClipboard() {
|
||||
if (!this.currentQuote) return;
|
||||
|
||||
const quote = this.currentQuote;
|
||||
const text = `${quote.text}\n${
|
||||
quote.author ? `作者:${quote.author}` : ""
|
||||
}\n${quote.contributor ? `贡献者:${quote.contributor}` : ""}${
|
||||
quote.link
|
||||
? `\n来源:${quote.link}`
|
||||
: quote.contributor
|
||||
? "\n来源:https://github.com/" + quote.contributor
|
||||
: ""
|
||||
}`;
|
||||
const { text, author, contributor, link } = this.currentQuote;
|
||||
const parts = [
|
||||
text,
|
||||
author && `作者:${author}`,
|
||||
contributor && `贡献者:${contributor}`,
|
||||
(link || contributor) && `来源:${link || `https://github.com/${contributor}`}`
|
||||
].filter(Boolean);
|
||||
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
this.showCopySuccess = true;
|
||||
await navigator.clipboard.writeText(parts.join('\n'));
|
||||
} catch (err) {
|
||||
console.error("复制失败:", err);
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
beforeUnmount() {
|
||||
if (this.typewriter) {
|
||||
this.typewriter.stop();
|
||||
}
|
||||
if (this.sourceWriter) {
|
||||
this.sourceWriter.stop();
|
||||
}
|
||||
},
|
||||
[this.typewriter, this.sourceWriter].forEach(writer => writer?.stop());
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.cursor-pointer {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.source-text {
|
||||
.source-text, .contributor {
|
||||
opacity: 0.7;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.contributor {
|
||||
opacity: 0.7;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.fade-enter-active,
|
||||
.fade-leave-active {
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.fade-enter-from,
|
||||
.fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
.fade-enter-active, .fade-leave-active { transition: opacity 0.3s ease; }
|
||||
.fade-enter-from, .fade-leave-to { opacity: 0; }
|
||||
</style>
|
||||
|
Loading…
x
Reference in New Issue
Block a user