feat:增加loading

This commit is contained in:
lixg
2023-03-07 23:07:40 +08:00
parent c68a2ea1af
commit 6b15242ace
2 changed files with 30 additions and 5 deletions

View File

@@ -113,13 +113,13 @@
</template>
<script setup>
import { reactive, toRefs, watch } from "vue";
import { reactive, toRefs, watch, ref } from "vue";
// import TitleHead from "@/components/TitleHead.vue";
import ReturnHead from "@/components/ReturnHead.vue";
import { request, useRequest } from "@/api/request";
import { useRoute } from "vue-router/dist/vue-router";
import { useRouter } from "vue-router";
import { ElMessage } from "element-plus";
import { ElMessage, ElLoading } from "element-plus";
import {
COMMENT_COLLECTION,
COMMENT_PRAISE,
@@ -156,7 +156,17 @@ const {
discussId,
noMore,
} = toRefs(state);
const loading = ref(false); // loading
const openLoading = () => {
loading.value = ElLoading.service({
lock: true,
text: "Loading",
background: "rgba(0, 0, 0, 0.7)",
});
};
const closeLoading = () => {
loading.value.close();
};
//获取讨论详情
const {
query: { id, type },
@@ -186,7 +196,7 @@ function getPostList(discussId) {
current: state.pageNo,
order: 1,
});
openLoading();
request(PostList, {
pid: discussId,
current: state.pageNo,
@@ -210,6 +220,7 @@ function getPostList(discussId) {
if (e.data.records.length === 0 || e.data.records.length < 10) {
state.noMore = true;
}
closeLoading();
})
.catch((err) => {
console.log(err);

View File

@@ -96,7 +96,7 @@ import { useRouter } from "vue-router";
// import UploadImg from "@/components/img/UploadImg.vue";
import FileTypeImg from "@/components/FileTypeImg.vue";
import { useRoute } from "vue-router/dist/vue-router";
import { ElMessage } from "element-plus";
import { ElMessage, ElLoading } from "element-plus";
import ReturnHead from "@/components/ReturnHead.vue";
const fileList = ref([]);
// const fielPath = ref(import.meta.env.VITE_FILE_PATH);
@@ -115,9 +115,22 @@ const {
query: { courseId: workId, type, id: taskId, infoId },
} = useRoute();
// console.log("type", type);
const loading = ref(false); // loading
const openLoading = () => {
loading.value = ElLoading.service({
lock: true,
text: "Loading",
background: "rgba(0, 0, 0, 0.7)",
});
};
openLoading();
const closeLoading = () => {
loading.value.close();
};
const { data } =
taskId && taskId !== "undefined"
? useRequest(TASK_WORK_DETAIL, { workId, taskId, type }, (e) => {
closeLoading();
if (e.code === 6) {
console.log("作业判断", e);
router.push({
@@ -126,6 +139,7 @@ const { data } =
}
})
: useRequest(TASK_WORK_DETAIL, { workId, type }, (e) => {
closeLoading();
if (e.code === 6) {
console.log("作业判断", e);
router.push({