[+] Shuffle friends

This commit is contained in:
Azalea Gui
2023-03-01 01:10:06 -05:00
parent f1ca319480
commit f0590d6d97
2 changed files with 24 additions and 1 deletions
+18
View File
@@ -89,3 +89,21 @@ export function capitalize(s: string): string
{
return s.charAt(0).toUpperCase() + s.slice(1);
}
export function shuffle(array: any[])
{
let currentIndex = array.length, randomIndex;
// While there remain elements to shuffle.
while (currentIndex != 0)
{
// Pick a remaining element.
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
// And swap it with the current element.
[array[currentIndex], array[randomIndex]] = [array[randomIndex], array[currentIndex]];
}
return array;
}
+6 -1
View File
@@ -2,7 +2,10 @@
<div id="Friends" class="general-page">
<div class="title">
<h2>朋友们</h2>
<div class="subtitle">是小桂桂的朋友们欢迎补充</div>
<div class="subtitle">
是小桂桂的朋友们欢迎补充<br>
每次刷新都会打乱顺序
</div>
</div>
<div class="friends" v-if="friends">
@@ -24,6 +27,7 @@
<script lang="ts">
import {Options, Vue} from 'vue-class-component';
import {fab, hosts} from "@/scripts/constants";
import {shuffle} from "@/scripts/utils";
export interface Friend {
name: string
@@ -52,6 +56,7 @@ export default class Friends extends Vue
if (!f.avatar.startsWith('http')) f.avatar = `${hosts.content}/${f.avatar}`
if (f.banner && !f.banner.startsWith('http')) f.banner = `${hosts.content}/${f.banner}`
})
this.friends = shuffle(this.friends)
}
bgStyle(f: Friend)