|
|
@@ -0,0 +1,302 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <page-header>
|
|
|
+ <GlobalHeader/>
|
|
|
+ <template #actions>
|
|
|
+ <el-button @click="download">
|
|
|
+ 下载
|
|
|
+ </el-button>
|
|
|
+ <el-button
|
|
|
+ variant="danger"
|
|
|
+ @click="this.$store.commit('removeProblem', problem)"
|
|
|
+ >移出试题清单</el-button
|
|
|
+ >
|
|
|
+ <el-button
|
|
|
+ variant="primary"
|
|
|
+ @click="this.$store.commit('addProblem', problem)"
|
|
|
+ >加入试题清单</el-button
|
|
|
+ >
|
|
|
+ <el-button
|
|
|
+ variant="danger-secondary"
|
|
|
+ @click="dialog.delete = true"
|
|
|
+ >
|
|
|
+ 删除题目
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ {{ problem.name }}
|
|
|
+ </page-header>
|
|
|
+ <el-dialog title="确认删除题目" v-model="dialog.delete">
|
|
|
+ <b>确认删除题目吗?</b>
|
|
|
+ <p>题目ID:{{ problem.id }}</p>
|
|
|
+ <p>题目名称:{{ problem.name }}</p>
|
|
|
+ <template #footer>
|
|
|
+ <span class="dialog-footer">
|
|
|
+ <el-button @click="dialog.delete = false">取消</el-button>
|
|
|
+ <el-button
|
|
|
+ type="danger"
|
|
|
+ :loading="loading.delete"
|
|
|
+ @click="deleteProblem"
|
|
|
+ >确定</el-button
|
|
|
+ >
|
|
|
+ </span>
|
|
|
+ </template>
|
|
|
+ </el-dialog>
|
|
|
+ <el-dialog title="更新题目文件" v-model="dialog.update">
|
|
|
+ <el-form label-width="40px">
|
|
|
+ <el-form-item label="路径" prop="name">
|
|
|
+ <div>{{ selectedFile }}</div>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="文件" prop="file">
|
|
|
+ <el-upload
|
|
|
+ ref="file"
|
|
|
+ action=""
|
|
|
+ :auto-upload="false"
|
|
|
+ :limit="1"
|
|
|
+ :on-change="onFileChange"
|
|
|
+ :on-remove="onFileChange"
|
|
|
+ >
|
|
|
+ <el-button size="small" type="primary"
|
|
|
+ >选取</el-button
|
|
|
+ >
|
|
|
+ </el-upload>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <template #footer>
|
|
|
+ <span class="dialog-footer">
|
|
|
+ <el-button @click="cancelUpdate">取消</el-button>
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ :loading="loading.update"
|
|
|
+ :disabled="!updateFiles.length"
|
|
|
+ @click="onSubmit"
|
|
|
+ >确定</el-button
|
|
|
+ >
|
|
|
+ </span>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ </el-dialog>
|
|
|
+ <paper shadow="sm" style="margin-bottom: 20px">
|
|
|
+ <el-descriptions>
|
|
|
+ <el-descriptions-item label="题目名称">
|
|
|
+ {{ problem.name }}
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item label="题目类型">
|
|
|
+ {{ typeTagContent }}
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item label="上传者">
|
|
|
+ {{ problem.creator ? problem.creator.username : '系统' }}
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item label="上传时间">
|
|
|
+ {{ format(problem.createdAt ) }}
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item label="题目描述" :span="3">
|
|
|
+ {{ problem.description }}
|
|
|
+ </el-descriptions-item>
|
|
|
+ </el-descriptions>
|
|
|
+ </paper>
|
|
|
+ <div class="fill-card top-divide">
|
|
|
+ <el-table :data="files">
|
|
|
+ <el-table-column label="文件列表">
|
|
|
+ <template v-slot="scope">
|
|
|
+ <span>{{ scope.row.path }}</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="类型" width="120">
|
|
|
+ <template v-slot="scope">
|
|
|
+ <span>{{ scope.row.type }}</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="操作" width="220">
|
|
|
+ <template v-slot="scope">
|
|
|
+ <el-button
|
|
|
+ type="text"
|
|
|
+ size="small"
|
|
|
+ @click="onGetDetail(scope.row.path)"
|
|
|
+ >
|
|
|
+ 查看详情
|
|
|
+ </el-button>
|
|
|
+ <el-button
|
|
|
+ type="text"
|
|
|
+ size="small"
|
|
|
+ @click="onDialogUpdate(scope.row.path)"
|
|
|
+ >
|
|
|
+ 更新文件
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </div>
|
|
|
+ <el-dialog
|
|
|
+ :title="fileDetailName"
|
|
|
+ width="80%"
|
|
|
+ v-model="fileDetailDialogShow"
|
|
|
+ >
|
|
|
+ <pre>{{ fileDetail }}</pre>
|
|
|
+ </el-dialog>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import PageHeader from "./components/PageHeader.vue";import Paper from "./components/Paper.vue";
|
|
|
+import GlobalHeader from "@/components/GlobalHeader";
|
|
|
+
|
|
|
+const { formatTimestamp } = require("@/utils/coder-utils");
|
|
|
+
|
|
|
+const { problemTypeToTagContent } = require("@/utils/coder-utils");
|
|
|
+
|
|
|
+export default{
|
|
|
+ name: "ProblemDetail",
|
|
|
+ layout: "dashboard",
|
|
|
+ components: {
|
|
|
+ GlobalHeader,
|
|
|
+ Paper,
|
|
|
+ PageHeader,
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ problem: {},
|
|
|
+ files: [],
|
|
|
+ selectedFile: "",
|
|
|
+ updateFiles: [],
|
|
|
+ dialog: {
|
|
|
+ delete: false,
|
|
|
+ update: false
|
|
|
+ },
|
|
|
+ loading: {
|
|
|
+ delete: false,
|
|
|
+ update: false
|
|
|
+ },
|
|
|
+ fileDetailDialogShow: false,
|
|
|
+ fileDetailName: "",
|
|
|
+ fileDetail: ""
|
|
|
+ };
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ typeTagContent(){
|
|
|
+ return problemTypeToTagContent(this.problem.type);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ "$nuxt.$route"() {
|
|
|
+ this.fetchData();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ this.fetchData();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ format(timestamp) {
|
|
|
+ return formatTimestamp(timestamp);
|
|
|
+ },
|
|
|
+ fetchData() {
|
|
|
+ const problemId= this.$route.params.id;
|
|
|
+ this.$apis.getCoderProblemById(problemId)
|
|
|
+ .then((res) => {
|
|
|
+ const data=res.data;
|
|
|
+ this.problem = data.res ?? {};
|
|
|
+ this.listFiles();
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ this.$message.error({
|
|
|
+ message: errorMessage(err),
|
|
|
+ center: true
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ listFiles() {
|
|
|
+ this.files = [
|
|
|
+ ...(this.problem?.publicFiles?.map((item) => ({
|
|
|
+ path: item,
|
|
|
+ type: "Public"
|
|
|
+ })) ?? []),
|
|
|
+ ...(this.problem?.protectedFiles?.map((item) => ({
|
|
|
+ path: item,
|
|
|
+ type: "Protected"
|
|
|
+ })) ?? []),
|
|
|
+ ...(this.problem?.privateFiles?.map((item) => ({
|
|
|
+ path: item,
|
|
|
+ type: "Private"
|
|
|
+ })) ?? [])
|
|
|
+ ];
|
|
|
+ },
|
|
|
+ download() {
|
|
|
+ const problemId = this.problem.id;
|
|
|
+ window.open(`/api/file/problem/${problemId}`);
|
|
|
+ },
|
|
|
+ deleteProblem() {
|
|
|
+ this.$store.commit("removeProblem", this.problem);
|
|
|
+ this.loading.delete = true;
|
|
|
+ const problemId = this.$route.params.id;
|
|
|
+ this.$apis.deleteCoderProblem(problemId)
|
|
|
+ .then(() => {
|
|
|
+ this.$router.push("/problem");
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ this.$message.error({
|
|
|
+ message: errorMessage(err),
|
|
|
+ center: true
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onFileChange(
|
|
|
+ _,
|
|
|
+ fileList
|
|
|
+ ) {
|
|
|
+ this.updateFiles = fileList;
|
|
|
+ },
|
|
|
+ onGetDetail(filename) {
|
|
|
+ this.fileDetail = "";
|
|
|
+ this.fileDetailName = filename;
|
|
|
+ this.fileDetailDialogShow = false;
|
|
|
+
|
|
|
+ const problemId= this.$route.params.id;
|
|
|
+ this.$apis.getFileDetail(problemId, filename)
|
|
|
+ .then((res) => {
|
|
|
+ const data = res.data;
|
|
|
+ console.log(data);
|
|
|
+ this.fileDetail = data.res ?? "";
|
|
|
+ this.fileDetailDialogShow = true;
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ this.$message.error({
|
|
|
+ message: errorMessage(err),
|
|
|
+ center: true
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ cancelUpdate() {
|
|
|
+ const file = this.$refs.file;
|
|
|
+ file.clearFiles();
|
|
|
+ this.updateFiles = [];
|
|
|
+ this.dialog.update = false;
|
|
|
+ },
|
|
|
+ onSubmit() {
|
|
|
+ this.loading.update = true;
|
|
|
+ const body = new FormData();
|
|
|
+ body.append("path", this.selectedFile);
|
|
|
+ body.append("file", this.updateFiles[0].raw);
|
|
|
+ const problemId = this.$route.params.id;
|
|
|
+ this.$apis.updateCoderProblem(problemId, body)
|
|
|
+ .then(() => {
|
|
|
+ this.$message.success({
|
|
|
+ message: "更新成功!",
|
|
|
+ center: true
|
|
|
+ });
|
|
|
+ this.loading.update = false;
|
|
|
+ this.dialog.update = false;
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ this.$message.error({
|
|
|
+ message: errorMessage(err),
|
|
|
+ center: true
|
|
|
+ });
|
|
|
+ this.loading.update = false;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onDialogUpdate(path) {
|
|
|
+ this.selectedFile = path;
|
|
|
+ this.dialog.update = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+</script>
|