Просмотр исходного кода

feat: 去掉日志管理,添加水印

zhangjie 7 месяцев назад
Родитель
Сommit
33c04c2d89

+ 69 - 0
src/modules/paper-export/views/PaperTemplateBuild.vue

@@ -116,6 +116,7 @@
 </template>
 
 <script>
+import { mapState } from "vuex";
 import ElemRichText from "../elements/rich-text/ElemRichText.vue";
 import PaperTemplateView from "../components/PaperTemplateView.vue";
 import PaperBuildConfig from "../components/PaperBuildConfig.vue";
@@ -162,13 +163,18 @@ export default {
       configSources: [],
       prepareDownloadPdf: false,
       actionType: "",
+      watermarkBg: "",
     };
   },
+  computed: {
+    ...mapState({ user: (state) => state.user }),
+  },
   mounted() {
     if (this.viewType === "frame") {
       this.initFrame();
       return;
     }
+
     this.initData();
   },
   methods: {
@@ -262,6 +268,7 @@ export default {
         });
     },
     async initData() {
+      this.watermarkBg = await this.initWatermark();
       await this.getPaperJson();
       await this.getPaperTempList();
 
@@ -424,6 +431,10 @@ export default {
               await this.runAction().catch(() => {});
               this.prepareDownloadPdf = false;
             });
+          } else {
+            this.$nextTick(() => {
+              this.setWatermark();
+            });
           }
         });
       });
@@ -488,11 +499,13 @@ export default {
       }
     },
     async runAction() {
+      this.clearWatermark();
       if (this.actionType === "downloadPdf") {
         await this.downloadPaperPdf();
       } else {
         await this.buildPackage();
       }
+      this.setWatermark();
     },
     async downloadPaperPdf() {
       if (this.downloading) return;
@@ -568,6 +581,59 @@ export default {
       if (!result) return;
       this.$message.success("生成数据包成功!");
     },
+    initWatermark() {
+      const content = this.user.displayName;
+
+      const canvas = document.createElement("canvas");
+      const ctx = canvas.getContext("2d");
+
+      const fontSize = 40;
+      ctx.font = `${fontSize}px serif`;
+      const cInfo = ctx.measureText(content);
+      const cwidth = Math.max(360, cInfo.width) * 1.2;
+      canvas.width = cwidth;
+      canvas.height = cwidth;
+
+      ctx.font = `${fontSize}px serif`;
+      ctx.fillStyle = "rgba(212,212,212,0.5)";
+      ctx.textAlign = "center";
+      ctx.textBaseline = "middle";
+      const angle = (315 * Math.PI) / 180;
+      const x = canvas.width / 2;
+      const y = canvas.height / 2;
+
+      ctx.translate(x, y);
+      ctx.rotate(angle);
+      ctx.fillText(content, 0, 0);
+
+      return new Promise((resolve, reject) => {
+        canvas.toBlob((val) => {
+          if (!val) return reject("获取水印blob错误");
+
+          resolve(window.URL.createObjectURL(val));
+        });
+      });
+    },
+    setWatermark() {
+      const bgSize = 240;
+      document
+        .getElementById("paper-template-view")
+        .querySelectorAll(".page-box")
+        .forEach((dom) => {
+          dom.setAttribute(
+            "style",
+            `background-image: url(${this.watermarkBg});background-repeat: repeat;background-size: ${bgSize}px ${bgSize}px;`
+          );
+        });
+    },
+    clearWatermark() {
+      document
+        .getElementById("paper-template-view")
+        .querySelectorAll(".page-box")
+        .forEach((dom) => {
+          dom.setAttribute("style", undefined);
+        });
+    },
   },
 };
 </script>
@@ -612,4 +678,7 @@ export default {
   z-index: 999;
   visibility: hidden;
 }
+.paper-template-build .page-column-element .element-item {
+  background-color: inherit;
+}
 </style>

+ 1 - 41
src/modules/questions/views/GenPaper.vue

@@ -185,21 +185,9 @@
           prop="updateTime"
         >
         </el-table-column>
-        <el-table-column label="锁定状态" width="90">
-          <template slot-scope="scope">
-            <span>{{ scope.row.locked ? "锁定" : "" }}</span>
-          </template>
-        </el-table-column>
-        <el-table-column label="操作" width="220" fixed="right">
+        <el-table-column label="操作" width="180" fixed="right">
           <template slot-scope="scope">
             <div class="operate_left">
-              <el-button
-                size="medium"
-                type="text"
-                class="normal"
-                @click="lockPaper(scope.row)"
-                >{{ scope.row.locked ? "解锁" : "锁定" }}</el-button
-              >
               <el-button
                 size="medium"
                 type="text"
@@ -851,34 +839,6 @@ export default {
         );
       });
     },
-    async lockPaper(row) {
-      const action = row.locked ? "解锁" : "锁定";
-      const result = await this.$confirm(`确定要${action}试卷吗?`, "提示", {
-        type: "warning",
-      }).catch(() => {});
-      if (result !== "confirm") return;
-
-      const locked = !row.locked;
-      let res = true;
-      await this.$httpWithMsg
-        .post(
-          QUESTION_API + "/paper/lock/",
-          {},
-          {
-            params: {
-              id: row.id,
-              locked,
-            },
-          }
-        )
-        .catch(() => {
-          res = false;
-        });
-      if (!res) return;
-
-      row.locked = locked;
-      this.$message.success("操作成功!");
-    },
     selectChange(row) {
       this.selectedPaperIds = [];
       row.forEach((element) => {

+ 0 - 7
src/modules/statistics/api.js

@@ -11,10 +11,3 @@ export const statisticsExportApi = (data) => {
     responseType: "blob",
   });
 };
-
-export const logQueryApi = (data) => {
-  return $httpWithMsg.post(`${QUESTION_API}/log/page/question/count`, data);
-};
-export const logEnumsApi = () => {
-  return $httpWithMsg.post(`${QUESTION_API}/log/page/question/count`, {});
-};

+ 0 - 6
src/modules/statistics/router/index.js

@@ -7,10 +7,4 @@ export const menuRoutes = [
         /* webpackChunkName: "statistics" */ "../views/StatisticsManage.vue"
       ),
   },
-  {
-    path: "/log/manage",
-    name: "LogManage",
-    component: () =>
-      import(/* webpackChunkName: "statistics" */ "../views/LogManage.vue"),
-  },
 ];

+ 0 - 155
src/modules/statistics/views/LogManage.vue

@@ -1,155 +0,0 @@
-<template>
-  <div class="content action-log-manage">
-    <div class="part-box">
-      <el-form ref="FilterForm" label-position="left" inline>
-        <el-form-item label="操作类型:">
-          <el-select
-            v-model="filter.operationType"
-            placeholder="操作类型"
-            clearable
-          >
-            <el-option
-              v-for="(val, key) in OPERATION_TYPE"
-              :key="key"
-              :value="key"
-              :label="val"
-            ></el-option>
-          </el-select>
-        </el-form-item>
-        <el-form-item label="操作人账号:">
-          <el-input
-            v-model.trim="filter.operatorName"
-            placeholder="操作人账号"
-            clearable
-          ></el-input>
-        </el-form-item>
-        <el-form-item label="操作时间:">
-          <el-date-picker
-            v-model="createTime"
-            type="datetimerange"
-            :picker-options="pickerOptions"
-            range-separator="至"
-            start-placeholder="开始时间"
-            end-placeholder="结束时间"
-            value-format="timestamp"
-            align="right"
-            unlink-panels
-          >
-          </el-date-picker>
-        </el-form-item>
-        <el-form-item label-width="0px">
-          <el-button type="primary" @click="handleCurrentChange(1)"
-            >查询</el-button
-          >
-        </el-form-item>
-      </el-form>
-    </div>
-
-    <div class="part-box">
-      <el-table ref="table" :data="tableData">
-        <el-table-column
-          type="index"
-          label="序号"
-          width="70"
-          :index="indexMethod"
-        ></el-table-column>
-        <el-table-column prop="operatorName" label="操作人" width="180">
-          <span slot-scope="scope">
-            {{ scope.row.loginName }}({{ scope.row.realName }})
-          </span>
-        </el-table-column>
-        <el-table-column prop="operationTypeName" label="操作类型" width="100">
-        </el-table-column>
-        <el-table-column prop="createTime" label="操作时间" width="170">
-          <span slot-scope="scope">
-            {{ scope.row.createTime | timestampFilter }}
-          </span>
-        </el-table-column>
-        <el-table-column prop="detail" label="日志内容"> </el-table-column>
-      </el-table>
-      <div class="part-page">
-        <el-pagination
-          :current-page.sync="currentPage"
-          :page-size.sync="pageSize"
-          :page-sizes="[10, 20, 50, 100, 200, 300]"
-          layout="total, sizes, prev, pager, next, jumper"
-          :total="total"
-          @current-change="handleCurrentChange"
-          @size-change="handleSizeChange"
-        />
-      </div>
-    </div>
-  </div>
-</template>
-
-<script>
-import { logQueryApi, logEnumsApi } from "../api";
-
-import pickerOptions from "@/constants/datePickerOptions";
-
-export default {
-  name: "LogManage",
-  data() {
-    return {
-      filter: {
-        operationType: "",
-        operatorName: "",
-        startTime: "",
-        endTime: "",
-      },
-      currentPage: 1,
-      pageSize: 10,
-      total: 10,
-      tableData: [],
-      OPERATION_TYPE: {},
-      loading: false,
-      pickerOptions,
-      createTime: [],
-    };
-  },
-  async created() {
-    await this.getLogTypes();
-    await this.getList();
-  },
-  methods: {
-    async getLogTypes() {
-      const res = await logEnumsApi();
-      const data = res || [];
-      this.OPERATION_TYPE = {};
-      data.forEach((item) => {
-        this.OPERATION_TYPE[item.code] = item.name;
-      });
-    },
-    async search() {
-      if (this.loading) return;
-      this.loading = true;
-
-      const datas = {
-        ...this.filter,
-        pageNumber: this.currentPage,
-        pageSize: this.pageSize,
-      };
-      if (this.createTime) {
-        datas.startTime = this.createTime[0];
-        datas.endTime = this.createTime[1];
-      }
-      const res = await logQueryApi(datas).catch(() => {});
-
-      this.loading = false;
-      if (!res) return;
-
-      this.tableData = res.data.content;
-      this.total = res.data.totalElements;
-    },
-    handleSizeChange(val) {
-      this.currentPage = 1;
-      this.pageSize = val;
-      this.search();
-    },
-    handleCurrentChange(val) {
-      this.currentPage = val;
-      this.search();
-    },
-  },
-};
-</script>