forked from FoundKeyGang/FoundKey
client: refactor components/ripple.vue to composition API
This commit is contained in:
parent
f571f61c2d
commit
be19ea610f
1 changed files with 35 additions and 47 deletions
|
@ -56,59 +56,47 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineComponent, onMounted } from 'vue';
|
import { onMounted } from 'vue';
|
||||||
import * as os from '@/os';
|
import * as os from '@/os';
|
||||||
|
|
||||||
export default defineComponent({
|
const props = withDefaults(defineProps<{
|
||||||
props: {
|
x: number;
|
||||||
x: {
|
y: number;
|
||||||
type: Number,
|
particle?: boolean;
|
||||||
required: true,
|
}>(), {
|
||||||
},
|
particle: true,
|
||||||
y: {
|
});
|
||||||
type: Number,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
particle: {
|
|
||||||
type: Boolean,
|
|
||||||
required: false,
|
|
||||||
default: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
emits: ['end'],
|
|
||||||
setup(props, context) {
|
|
||||||
const particles = [];
|
|
||||||
const origin = 64;
|
|
||||||
const colors = ['#FF1493', '#00FFFF', '#FFE202'];
|
|
||||||
|
|
||||||
if (props.particle) {
|
const emit = defineEmits<{
|
||||||
for (let i = 0; i < 12; i++) {
|
(ev: 'end'): void;
|
||||||
const angle = Math.random() * (Math.PI * 2);
|
}>();
|
||||||
const pos = Math.random() * 16;
|
|
||||||
const velocity = 16 + (Math.random() * 48);
|
|
||||||
particles.push({
|
|
||||||
size: 4 + (Math.random() * 8),
|
|
||||||
xA: origin + (Math.sin(angle) * pos),
|
|
||||||
yA: origin + (Math.cos(angle) * pos),
|
|
||||||
xB: origin + (Math.sin(angle) * (pos + velocity)),
|
|
||||||
yB: origin + (Math.cos(angle) * (pos + velocity)),
|
|
||||||
color: colors[Math.floor(Math.random() * colors.length)],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
const zIndex = os.claimZIndex('high');
|
||||||
window.setTimeout(() => {
|
const particles = [];
|
||||||
context.emit('end');
|
const origin = 64;
|
||||||
}, 1100);
|
const colors = ['#FF1493', '#00FFFF', '#FFE202'];
|
||||||
|
|
||||||
|
if (props.particle) {
|
||||||
|
for (let i = 0; i < 12; i++) {
|
||||||
|
const angle = Math.random() * (Math.PI * 2);
|
||||||
|
const pos = Math.random() * 16;
|
||||||
|
const velocity = 16 + (Math.random() * 48);
|
||||||
|
particles.push({
|
||||||
|
size: 4 + (Math.random() * 8),
|
||||||
|
xA: origin + (Math.sin(angle) * pos),
|
||||||
|
yA: origin + (Math.cos(angle) * pos),
|
||||||
|
xB: origin + (Math.sin(angle) * (pos + velocity)),
|
||||||
|
yB: origin + (Math.cos(angle) * (pos + velocity)),
|
||||||
|
color: colors[Math.floor(Math.random() * colors.length)],
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
onMounted(() => {
|
||||||
particles,
|
window.setTimeout(() => {
|
||||||
zIndex: os.claimZIndex('high'),
|
emit('end');
|
||||||
};
|
}, 1100);
|
||||||
},
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue