client: refactor components/ripple.vue to composition API

This commit is contained in:
Johann150 2022-09-30 17:57:06 +02:00
parent f571f61c2d
commit be19ea610f
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -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>