[+] Shuffle friends
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user