Skip to content

Commit

Permalink
feat: enable hash locate
Browse files Browse the repository at this point in the history
  • Loading branch information
Xecades committed Feb 5, 2024
1 parent e6756a9 commit 2d276de
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/assets/js/leancloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function createCourseRaw(data) {

async function createCourse(data) {
let course = createCourseRaw(data);
await course.save();
return await course.save();
}

async function clearAllCourses() {
Expand All @@ -88,7 +88,7 @@ function createRemarkRaw(data) {

async function createRemark(data) {
let remark = createRemarkRaw(data);
await remark.save();
return await remark.save();
}

async function clearAllRemarks() {
Expand Down
9 changes: 7 additions & 2 deletions src/components/RemarkComp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@ const md = markdownit({
const parsed = ref("");
const setHash = () => {
location.hash = `#${$.data.objectId}`;
};
onMounted(() => {
parsed.value = md.render($.data.comment);
});
</script>

<template>
<el-card shadow="hover">
<el-card shadow="hover" :id="data.objectId">
<template #header>
<el-text size="large" type="info" class="info">
<el-text size="large" type="primary">{{ data.score }} 分</el-text>
<el-text size="large" type="primary" style="cursor: pointer;" @click="setHash">{{ data.score }}
分</el-text>
· {{ data.name || "匿名" }} · {{ data.grade }} · {{ data.course }}
</el-text>
</template>
Expand Down
3 changes: 2 additions & 1 deletion src/components/WriteComp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ const uploadRemark = async () => {
comment: form.comment,
course: isCreate.value ? form.newc : course.value,
};
await lc.createRemark(d);
let ret = await lc.createRemark(d);
d.objectId = ret.id;
await notify.createdRemark(d);
};
Expand Down
26 changes: 22 additions & 4 deletions src/views/HomeView.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { onMounted, ref, watch } from "vue";
import { onMounted, ref } from "vue";
import lc from "@/assets/js/leancloud";
import util from "@/assets/js/util";
Expand Down Expand Up @@ -49,17 +49,35 @@ const handlePathChange = async () => {
}
};
const findReview = async (hash) => {
if (!hash) return false;
const r = (await lc.searchRemarks("objectId", hash))[0];
if (!r) return false;
const c = (await lc.searchCourses("name", r.course))[0];
return [c.type, c.category, c.name];
};
onMounted(async () => {
await fetchCourses();
let hash = location.hash.substring(1);
let hashPath = await findReview(hash);
let localPath = localStorage.getItem("path");
if (localPath) path.value = JSON.parse(localPath);
if (hashPath) path.value = hashPath;
else if (localPath) path.value = JSON.parse(localPath);
else {
let lv1 = courses.value[0].value;
let lv2 = courses.value[0].children[0].value;
let lv3 = courses.value[0].children[0].children[0].value;
path.value = [lv1, lv2, lv3];
}
await updateRemarks();
if (hashPath) {
let el = document.getElementById(hash);
el.scrollIntoView({ behavior: "smooth" });
}
});
</script>

Expand All @@ -68,13 +86,13 @@ onMounted(async () => {
<div class="main">
<div class="title">通识课程评价系统</div>
<div class="subtitle">浙江大学图灵班</div>

<el-cascader-panel class="panel" @change="handlePathChange" v-model="path" :options="courses" />
<WriteComp class="write" v-if="path" @refresh="updateRemarks" @course-created="cced" :path="path" />
<div v-loading="loading">
<RemarkComp class="remark" v-for="r in remarks" :key="r.objectId" :data="r" />
</div>

<div class="copyright">
Developed by <a href="https://xecades.xyz/">Xecades</a> &copy; {{ nowYear }} ·
<RouterLink to="/admin">Admin</RouterLink>
Expand Down

0 comments on commit 2d276de

Please sign in to comment.