Refactor App.vue to improve item validation, enhance UI layout with Element Plus, and update button functionality

This commit is contained in:
HoshinoKoji 2025-03-03 13:38:47 +08:00
parent 0d7e7c105e
commit 10e6944532

View File

@ -29,6 +29,7 @@
data() { data() {
return { return {
title: undefined, title: undefined,
started: undefined,
items: [], items: [],
currentTitle: undefined, currentTitle: undefined,
currentIdx: undefined, currentIdx: undefined,
@ -60,6 +61,7 @@
this.currentIdx = 0; this.currentIdx = 0;
this.updateItem(); this.updateItem();
this.started = new Date().getTime();
} }
}); });
}, },
@ -96,8 +98,8 @@
}, },
iterOptions() { iterOptions() {
return this.currentItem.optTexts.map((optText, index) => [ return this.currentItem.optTexts.map((optText, index) => [
index,
optText, optText,
this.currentItem.optValues ? this.currentItem.optValues[index] : optText,
]); ]);
}, },
clickNext() { clickNext() {
@ -132,7 +134,12 @@
refilled: item.refilled, refilled: item.refilled,
responseTime: item.responseTime, responseTime: item.responseTime,
})); }));
window.parent.postMessage({ type: 'response', results }, window.origin); window.parent.postMessage({
type: 'response',
started: this.started,
ended: new Date().getTime(),
results
}, window.origin);
const elem = document.createElement('a'); const elem = document.createElement('a');
elem.href = 'data:text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(results)); elem.href = 'data:text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(results));
elem.download = 'results.json'; elem.download = 'results.json';
@ -144,52 +151,79 @@
<template> <template>
<div v-if="!isReady">Loading...</div> <div v-if="!isReady">Loading...</div>
<div id="container" v-if="isReady"> <el-container id="main" v-if="isReady">
<span id="display-title">{{ currentTitle }}</span> <el-header height=22pt id="display-title">{{ currentTitle }}</el-header>
<div id="display-content"> <el-container id="display-desc" v-if="true">
<el-text class="mx-1" size="large">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit
anim id est laborum.</el-text>
</el-container>
<el-main id="display-content">
<template v-if="currentItem.type === 'text'"> <template v-if="currentItem.type === 'text'">
<el-input v-model="currentAnswer" style="width: 240px" placeholder="Please input" /> <el-input v-model="currentAnswer" autosize placeholder="Please input" />
</template> </template>
<template v-else-if="currentItem.type === 'radio'"> <template v-else-if="currentItem.type === 'radio'">
<div> <el-radio-group v-model="currentAnswer" v-for="[index, optText] in iterOptions()" :key="index"
<el-radio-group @change="autoNext">
v-model="currentAnswer" <el-radio-button :label="optText" :value="index" />
v-for="[optText, optValue] in iterOptions()"
:key="optValue"
@change="autoNext"
>
<el-radio-button :label="optText" :value="optValue" />
</el-radio-group> </el-radio-group>
</div>
</template> </template>
</div> </el-main>
<div id="display-buttons"> <el-footer id="display-buttons">
<el-button-group> <el-button-group>
<el-button type="primary" round :disabled="uiStatus.backButtonDisabled" @click="clickBack"> <el-button type="info" round :disabled="uiStatus.backButtonDisabled" @click="clickBack">
<el-icon class="el-icon--left"><ArrowLeft /></el-icon>Back <el-icon class="el-icon--left">
<ArrowLeft />
</el-icon>Back
</el-button> </el-button>
<el-button :type="uiStatus.nextButtonStatus" round @click="clickNext"> <el-button :type="uiStatus.nextButtonStatus" round @click="clickNext">
{{ uiStatus.nextButtonText }}<el-icon class="el-icon--right"><ArrowRight /></el-icon> {{ uiStatus.nextButtonText }}<el-icon class="el-icon--right">
<ArrowRight />
</el-icon>
</el-button> </el-button>
</el-button-group> </el-button-group>
</div> </el-footer>
</div> </el-container>
</template> </template>
<style scoped> <style scoped>
#container { #main {
text-align: left; width: 50%;
width: 100%; background-color: #FAFCFF;
margin: 10% 25%;
padding-top: 4ex;
padding-left: 2ex;
padding-right: 2ex;
border-radius: var(--el-border-radius-round);
box-shadow: var(--el-box-shadow-dark);
font-family: var(--el-font-family);
} }
#display-title { #display-title {
font-size: 20px; text-align: left;
font-size: 18pt;
font-weight: bold; font-weight: bold;
color: rgb(51.2, 126.4, 204);
} }
#display-content {
margin-top: 1ex; #display-desc {
margin-bottom: 2ex; width: 90%;
margin: 1ex auto;
} }
#display-buttons { #display-buttons {
text-align: center; text-align: center;
} }
#display-content {
padding-top: 1ex;
}
#display-content el-input {
width: 100%;
font-size: 16pt;
}
</style> </style>