
<template>
<div class="random">
<div
v-for="(item, index) in tags"
:key="index"
class="tag-body-tags-li"
>
<a
class="tag-item"
v-for="(tag, elIndex) in item"
:key="elIndex"
:style="{ color: $RandomColor(), 'font-size': $RandomFontSize() }"
>
<span>{{ tag }}</span>
<span class="tagNum">1/15</span>
</a>
</div>
</div>
</template>
<script>
const $NormalSort = function(arr) {
var temp = [],
i = 0,
l = arr.length,
leftTo = 0,
rightTo = 0,
sortArr = arr.sort(function(a, b) {
return b - a;
});
while (arr.length > 1) {
let a = arr.pop();
let b = arr.pop();
if (leftTo < rightTo) {
temp[i] = b;
temp[l - (i + 1)] = a;
} else {
temp[i] = b;
temp[l - (i + 1)] = a;
}
i++;
}
return temp;
};
const $RandomSplit = function(total, nums, max) {
let rest = total;
let result = Array.apply(null, { length: nums })
.map((n, i) => nums - i)
.map((n) => {
const v = 1 + Math.floor(Math.random() * (max | ((rest / n) * 2 - 1)));
rest -= v;
return v;
});
result[nums - 1] += rest;
return result;
};
const $Normal = function(mean, sigma) {
var u = 0.0,
v = 0.0,
w = 0.0,
c = 0.0;
do {
u = Math.random() * 2 - 1.0;
v = Math.random() * 2 - 1.0;
w = u * u + v * v;
} while (w == 0.0 || w >= 1.0);
c = Math.sqrt((-2 * Math.log(w)) / w);
return mean + u * c * sigma;
};
const $RandomColor = function() {
var r = Math.floor(Math.random() * 256);
var g = Math.floor(Math.random() * 256);
var b = Math.floor(Math.random() * 256);
return "rgb(" + r + "," + g + "," + b + ")";
};
const $RandomColor2 = function() {
return (
"hsl(" +
Math.round(Math.random() * 360) +
"," +
Math.round(Math.random() * 100) +
"%," +
Math.round(Math.random() * 80) +
"%)"
);
};
const $RandomFontSize = function() {
return `${Math.floor(Math.random() * 10 + 12)}px`;
};
export default {
name: "Page404",
data: () => {
return {
testList: [],
tagList: [
"前端开发",
"UI设计",
"后端开发",
"Python",
"JAVA",
"Vue",
"React",
"Angular",
"Javascript",
"Goland",
"前端开发",
"UI设计",
"后端开发",
"Python",
"JAVA",
"Vue",
"React",
"Angular",
"Javascript",
"Goland",
]
}
},
computed: {
tags() {
const testList = {
value: this.testList
}
const tagList = {
value: this.tagList
}
testList.value = $NormalSort($RandomSplit(tagList.value.length, 6));
let temp = tagList.value.sort(function(a, b) {
return Math.random() > 0.5 ? -1 : 1;
})
.concat();
return testList.value.map((v, k) => {
return temp.splice(0, v);
});
}
},
methods: {
$RandomColor: $RandomColor,
$RandomFontSize: $RandomFontSize
}
}
</script>
<style lang="scss" scoped>
.random {
height: 300px !important;
.tag-body-tags-li {
display: flex;
align-items: center;
justify-content: center;
.tag-item {
margin: 10px;
display: inline-block;
position: relative;
.tagNum {
position: absolute;
bottom: 0;
left: 50%;
transform: translate(-50%, 100%);
font-size: 12px;
width: 100%;
text-align: center;
display: inline-block
}
}
}
}
</style>