Skip to content

Commit

Permalink
Merge pull request #54 from zjutjh/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
RosyrRais authored Aug 15, 2024
2 parents 159ae60 + 2101b66 commit eb8b0bb
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 103 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "text-ci",
"version": "0.1.1",
"version": "0.1.2",
"private": true,
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/apis/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import axios, { type AxiosRequestConfig } from 'axios'
//自动存储cookie

const axiosInstance = axios.create({
baseURL: "https://phlin.top",
baseURL: "/api",
timeout: 10000,
withCredentials: true
})
Expand Down
90 changes: 90 additions & 0 deletions src/pages/DataDisplay/data.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<template>
<div>
<table class="table">
<thead>
<tr>
<th>序号</th>
<th>时间</th>
<th v-for="ans in answers">
{{ ans.title }}
<el-tag type="primary" size="small" class="ml-3">{{ answersType.get(ans.question_type) }}</el-tag>
</th>
</tr>
</thead>
<tbody>
<tr v-for="(t, index) in time">
<th>{{ index+1 }}</th>
<th>{{ t }}</th>
<th v-for="ans in answers">{{ ans.answers[index] }}</th>
</tr>
</tbody>
</table>
<el-pagination
:current-page="pageNum"
layout="prev, pager, next"
:page-count="totalPageNum"
@current-change="handleCurrentChange"
/>
</div>
</template>

<script setup lang="ts">
import {ElNotification, ElPagination} from 'element-plus';
import { getAnswersAPI } from '@/apis';
import { ref, watch } from 'vue';
import { useMainStore } from '@/stores';
import { useRequest } from 'vue-hooks-plus';
const tempStore = useMainStore().useTempStore();
const props = defineProps<{
keyText: string,
isUnique: boolean,
}>();
const answersType = new Map([
[1, '单选'],
[2, '多选'],
[3, '填空'],
[4, '简答'],
[5, '图片'],
]);
const handleCurrentChange = (val: number) => {
pageNum.value = val;
getAnswers();
}
const pageNum = ref(1);
const totalPageNum = ref(2);
const pageSize = ref(10);
const answers = ref();
const time = ref();
const getAnswers = () => {
useRequest(() => getAnswersAPI({
id: tempStore.checkId,
page_num: pageNum.value,
page_size: pageSize.value,
text: props.keyText === "" ? undefined : props.keyText,
unique: props.isUnique,
}), {
debounceWait: 400,
onSuccess(res: any) {
console.log(res);
if(res.code === 200) {
totalPageNum.value = res.data.total_page_num;
answers.value = res.data.answers_data.question_answers;
time.value = res.data.answers_data.time;
}
},
onError(e: any) {
ElNotification.error('获取失败,请重试' + e);
},
})
}
getAnswers();
watch(props, getAnswers);
</script>
111 changes: 10 additions & 101 deletions src/pages/DataDisplay/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,125 +13,32 @@
</div>
<div class="btn btn-sm btn-accent" @click="downloadDatatable">下载数据表格</div>
<div class="btn btn-sm btn-accent" @click="switchCount">统计切换</div>
<div class="btn btn-sm" :class="isUnique ? 'btn-neutral' : 'btn-accent'" @click="changeUnique">展示近期</div>
<span>搜索</span><input class="input input-sm input-bordered" type="text" v-model="keyText">
<div v-show="!isCount" class="btn btn-sm" :class="isUnique ? 'btn-neutral' : 'btn-accent'" @click="changeUnique">展示近期</div>
<span v-show="!isCount">搜索</span><input v-show="!isCount" class="input input-sm input-bordered" type="text" v-model="keyText">
</div>
<div class="overflow-x-auto">
<!-- 填空数据展示 -->
<table class="table" v-show="!isCount">
<thead>
<tr>
<th>序号</th>
<th>时间</th>
<th v-for="ans in answers">{{ ans.title }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(t, index) in time">
<th>{{ index+1 }}</th>
<th>{{ t }}</th>
<th v-for="ans in answers">{{ ans.answers[index] }}</th>
</tr>
</tbody>
</table>
<el-pagination
:current-page="pageNum"
layout="prev, pager, next"
:page-count="totalPageNum"
@current-change="handleCurrentChange"
v-show="!isCount"
/>
<div class="gap-8 m-5 grid grid-cols-2 mt-30" v-show="isCount">
<n-card v-for="obj in staticsData" v-bind:key='obj'>
<div class="font-bold">{{ obj.serial_num }}. {{ obj.question }}</div>
<div v-for="opt in obj.options" class="m-6">
<div class="relative border rounded">
<span class="ml-4">{{ opt.content }}</span>
<span class="absolute right-4">{{ opt.count/totalNum*100 }}%</span>
<div class="inline absolute left-0 rounded bg-cyan-400 h-full opacity-15" :style="{width: 100*opt.count/totalNum+'%'}"></div>
</div>
</div>
</n-card>
</div>
<data-table :key-text="keyText" :is-unique="isUnique" v-show="!isCount"></data-table>
<statics v-show="isCount"></statics>
</div>
</div>
</div>
</template>

<script setup lang="ts">
import { getAnswersAPI, getDatatableAPI, getStaticsDataAPI } from '@/apis';
import {onMounted, ref, watch} from 'vue';
import { getDatatableAPI } from '@/apis';
import { ref } from 'vue';
import { useRequest } from 'vue-hooks-plus';
import router from '@/router';
import {ElNotification, ElPagination} from 'element-plus';
import { useMainStore } from '@/stores';
import { NCard } from 'naive-ui';
import statics from './statics.vue';
import dataTable from './data.vue';
const tempStore = useMainStore().useTempStore();
const pageNum = ref(1);
const totalPageNum = ref(2);
const pageSize = ref(10);
const answers = ref();
const time = ref();
const staticsData = ref();
const totalNum = ref();
const isCount = ref(false);
const isUnique = ref(false);
const keyText = ref("");
onMounted(() => {
getAnswers();
})
const getAnswers = () => {
useRequest(() => getAnswersAPI({
id: tempStore.checkId,
page_num: pageNum.value,
page_size: pageSize.value,
text: keyText.value === "" ? undefined : keyText.value,
unique: isUnique.value,
}), {
debounceWait: 500,
onSuccess(res: any) {
console.log(res);
if(res.code === 200) {
totalPageNum.value = res.data.total_page_num;
answers.value = res.data.answers_data.question_answers;
time.value = res.data.answers_data.time;
}
},
onError(e: any) {
ElNotification.error('获取失败,请重试' + e);
},
})
useRequest(() => getStaticsDataAPI({
id: tempStore.checkId,
page_num: pageNum.value,
page_size: pageSize.value,
}), {
onSuccess(res: any) {
if(res.code === 200) {
staticsData.value = res.data.statistics;
totalNum.value = res.data.total;
}
},
onError(e: any) {
ElNotification.error('获取失败,请重试' + e);
}
})
}
watch(keyText, getAnswers);
watch(isUnique, getAnswers);
const changeUnique = () => { isUnique.value = !isUnique.value; }
const handleCurrentChange = (val: number) => {
pageNum.value = val;
getAnswers();
}
const back = () => {
router.push('/admin');
}
Expand All @@ -152,4 +59,6 @@ const switchCount = () => {
isCount.value = !isCount.value;
}
const changeUnique = () => { isUnique.value = !isUnique.value; }
</script>
64 changes: 64 additions & 0 deletions src/pages/DataDisplay/statics.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<template>
<div>
<div class="gap-8 m-5 grid grid-cols-2 mt-30">
<n-card v-for="obj in staticsData" v-bind:key='obj'>
<div class="font-bold">{{ obj.serial_num }}. {{ obj.question }}</div>
<div v-for="opt in obj.options" class="m-6">
<div class="relative border rounded">
<span class="ml-4">{{ opt.content }}</span>
<span class="absolute right-4">{{ (opt.count/totalNum*100).toFixed(2) }}%</span>
<div class="inline absolute left-0 rounded bg-cyan-400 h-full opacity-15" :style="{width: 100*opt.count/totalNum+'%'}"></div>
</div>
</div>
</n-card>
</div>
<el-pagination
:current-page="pageNum"
layout="prev, pager, next"
:page-count="totalPageNum"
@current-change="handleCurrentChange"
/>
</div>
</template>

<script setup lang="ts">
import { useRequest } from 'vue-hooks-plus';
import { getStaticsDataAPI } from '@/apis';
import { useMainStore } from '@/stores';
import {ElNotification, ElPagination} from 'element-plus';
import { ref } from 'vue';
import { NCard } from 'naive-ui';
const tempStore = useMainStore().useTempStore();
const pageNum = ref(1);
const pageSize = 8;
const totalPageNum = ref();
const totalNum = ref();
const staticsData = ref();
const handleCurrentChange = (val: number) => {
pageNum.value = val;
getAnswers();
}
const getAnswers = () => {
useRequest(() => getStaticsDataAPI({
id: tempStore.checkId,
page_num: pageNum.value,
page_size: pageSize,
}), {
onSuccess(res: any) {
if(res.code === 200) {
staticsData.value = res.data.statistics;
totalNum.value = res.data.total;
totalPageNum.value = res.data.total_sum_page;
}
},
onError(e: any) {
ElNotification.error('获取失败,请重试' + e);
}
})
}
getAnswers();
</script>

0 comments on commit eb8b0bb

Please sign in to comment.