Jelajahi Sumber

添加注释

DYaiu 4 tahun lalu
induk
melakukan
ed9bd98036
5 mengubah file dengan 16 tambahan dan 1 penghapusan
  1. 3 0
      .gitignore
  2. 2 0
      src/api/login.js
  3. 1 1
      src/utils/axios.js
  4. 8 0
      src/views/report/report.vue
  5. 2 0
      src/views/report/reportDetailed.vue

+ 3 - 0
.gitignore

@@ -20,3 +20,6 @@ pnpm-debug.log*
 *.njsproj
 *.sln
 *.sw?
+
+axios.rar
+vue.config.rar

+ 2 - 0
src/api/login.js

@@ -1,5 +1,6 @@
 import request from '@/utils/axios'
 
+// 登入接口
 export function loginByUsername(username, password) {
     const data = {
         username,
@@ -12,6 +13,7 @@ export function loginByUsername(username, password) {
     })
 }
 
+// 登出接口,需要token请求头会自动带上
 export function logout() {
     return request({
         url: '/logout/',

+ 1 - 1
src/utils/axios.js

@@ -9,13 +9,13 @@ import { Message } from 'element-ui'
 let config = {
   baseURL: "/report",
   timeout: 60 * 1000, // Timeout
-  withCredentials: true, // Check cross-site Access-Control
 };
 
 const _axios = axios.create(config);
 
 _axios.interceptors.request.use(
   function (config) {
+    // 每次请求的时候带上指定表头token
     config.headers['X-CSRFToken'] = document.cookie.split('=')[1]
     return config;
   },

+ 8 - 0
src/views/report/report.vue

@@ -6,6 +6,7 @@
       <el-table-column prop="title" label="标题" width="180"></el-table-column>
       <el-table-column prop="content" label="内容" width="180"></el-table-column>
       <el-table-column prop="create_at" label="创建时间"></el-table-column>
+
       <el-table-column label="操作">
         <template slot-scope="scope" width="200px0">
           <el-button type="primary" @click="reportDetailed(scope.row.id)">编辑</el-button>
@@ -21,6 +22,7 @@
         </template>
       </el-table-column>
     </el-table>
+    <!-- 分页 -->
     <el-pagination
       background
       layout="total,prev, pager, next"
@@ -28,6 +30,7 @@
       @current-change="handleSizeChange"
       :total="reportTotal"
     ></el-pagination>
+    <!-- 子组件、提供弹窗新增、修改 -->
     <add-or-up
       ref="AddOrUpdate"
       :visible.sync="addOrUpdateVisible"
@@ -60,6 +63,7 @@ export default {
     this.getReport();
   },
   methods: {
+    // 获取所有日报
     getReport: function() {
       console.log(reportList);
       reportList(3, 0).then(res => {
@@ -68,11 +72,13 @@ export default {
         console.log(res);
       });
     },
+    // 打开弹窗
     reportDetailed: function(status) {
       console.log(status);
       this.addOrUpdateVisible = true;
       this.id = status;
     },
+    // 删除日报按钮
     deleteReport: function(id) {
       console.log("delete:" + id);
       reportDelete(id).then(res => {
@@ -85,9 +91,11 @@ export default {
         this.getReport();
       });
     },
+    // 关闭弹窗、给子组件触发
     deClose: function() {
       this.addOrUpdateVisible = false;
     },
+    // 分页组件自动触发、修改分页大小时
     handleSizeChange: function(val) {
       reportList(this.limit, (val - 1) * this.limit).then(res => {
         this.tableData = res.data.results;

+ 2 - 0
src/views/report/reportDetailed.vue

@@ -57,6 +57,7 @@ export default {
       };
       this.$emit("deClose", {});
     },
+    // form提交按钮触发,根据是否有id决定是新增api还是保存api
     dataFormSubmitHandle() {
       console.log("试图保存");
       console.log(this.id);
@@ -83,6 +84,7 @@ export default {
         });
       }
     },
+    // 弹窗组件自动触发,决定是否需要请求某个具体的日报内容
     init() {
       console.log("init:" + this.id);
       if (this.id == null) {