Browse Source

fix作业,直接完成作业!!!!

DYaiu 4 years ago
parent
commit
941e7f0b18

+ 41 - 0
src/api/report.js

@@ -0,0 +1,41 @@
+import request from '@/utils/axios'
+
+export function reportList() {
+    return request({
+        url: '/report/',
+        method: 'get'
+    })
+}
+
+// 根据id获取日报详情
+export function reportDe(id) {
+    return request({
+        url: '/report/' + id,
+        method: 'get'
+    })
+}
+
+// 根据标题和内容新增一个日报
+export function reportSave(data) {
+    return request({
+        url: '/report/',
+        method: 'post',
+        data: data
+    })
+}
+
+// 根据id删除日报
+export function reportDelete(id) {
+    return request({
+        url: '/report/' + id,
+        method: 'delete',
+    })
+}
+
+export function reportPut(id, data) {
+    return request({
+        url: '/report/' + id + '/',
+        method: 'put',
+        data
+    })
+}

+ 5 - 0
src/router/index.js

@@ -14,6 +14,11 @@ export const constantRoutes = [
         name: 'work',
         title: '作业',
         component: () => import('@/views/work/work')
+    }, {
+        path: '/report',
+        name: 'report',
+        title: '日报',
+        component: () => import('@/views/report/report')
     }
 ]
 

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

@@ -0,0 +1,78 @@
+<template>
+  <div>
+    <el-button type="primary" @click="reportDetailed()">新增</el-button>
+    <el-table :data="tableData" border style="width:100%">
+      <el-table-column prop="id" label="序号" width="180"></el-table-column>
+      <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>
+          <el-button @click="deleteReport(scope.row.id)" type="danger">删除</el-button>
+          <!-- <el-popconfirm
+            okText="是"
+            cancelText="否"
+            @onConfirm="deleteReport(scope.row.id)"
+            title="确认要删除此条内容吗?"
+          >
+            <el-button type="danger">删除</el-button>
+          </el-popconfirm>-->
+        </template>
+      </el-table-column>
+    </el-table>
+    <add-or-up
+      ref="AddOrUpdate"
+      :visible.sync="addOrUpdateVisible"
+      :id="id"
+      @deClose="()=>{addOrUpdateVisible=false}"
+      @getReport="getReport"
+    />
+  </div>
+</template>
+
+<script>
+import { reportList, reportDelete } from "@/api/report";
+import addOrUp from "./reportDetailed";
+export default {
+  name: "report",
+  components: {
+    addOrUp
+  },
+  data() {
+    return { tableData: [], addOrUpdateVisible: false, id: null };
+  },
+  created() {
+    this.getReport();
+  },
+  methods: {
+    getReport: function() {
+      console.log(reportList);
+      reportList().then(res => {
+        this.tableData = res.data.results;
+        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 => {
+        console.log("delete成功");
+        console.log(res);
+        this.$message({
+          message: "删除成功",
+          type: "warning"
+        });
+        this.getReport();
+      });
+    },
+    deClose: function() {
+      this.addOrUpdateVisible = false;
+    }
+  }
+};
+</script>

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

@@ -0,0 +1,98 @@
+<template>
+  <el-dialog
+    :title="id==null ? '新增' : '编辑'"
+    width="520px"
+    :visible="visible"
+    :keyboard="false"
+    @close="handleCancel"
+    :show-close="false"
+    @open="init"
+  >
+    <el-form :model="dataForm" label-width="120px" ref="form">
+      <el-form-item label="标题" :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }" prop="title">
+        <el-input v-model="dataForm.title" />
+      </el-form-item>
+      <el-form-item label="内容" :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }" prop="content">
+        <el-input v-model="dataForm.content" />
+      </el-form-item>
+    </el-form>
+    <template slot="footer">
+      <el-button @click="visible = false">取消</el-button>
+      <el-button type="primary" @click="dataFormSubmitHandle()">保存</el-button>
+    </template>
+  </el-dialog>
+</template>
+
+<script>
+import { reportDe, reportSave, reportPut } from "@/api/report";
+export default {
+  name: "reportDe",
+  props: {
+    visible: {
+      default: false,
+      type: Boolean
+    },
+    id: {
+      default: null,
+      type: Number
+    }
+  },
+  data() {
+    return {
+      dataForm: {
+        title: "",
+        content: ""
+      }
+    };
+  },
+  methods: {
+    //关闭模态框
+    handleCancel() {
+      console.log("关闭弹窗");
+      this.visible = false;
+      // 退出弹窗需要清空对象,否则新增时会有上次编辑的数据
+      this.dataForm = {
+        title: "",
+        content: ""
+      };
+      this.$emit("deClose", {});
+    },
+    dataFormSubmitHandle() {
+      console.log("试图保存");
+      console.log(this.id);
+      if (this.id == null) {
+        reportSave(this.dataForm).then(res => {
+          console.log("新增成功:");
+          console.log(res);
+          this.$message({
+            message: "新增成功",
+            type: "success"
+          });
+          this.handleCancel();
+          this.$emit("getReport", {});
+        });
+      } else {
+        reportPut(this.id, this.dataForm).then(res => {
+          console.log("更新成功");
+          this.$message({
+            message: "更新成功",
+            type: "success"
+          });
+          this.handleCancel();
+          this.$emit("getReport", {});
+        });
+      }
+    },
+    init() {
+      console.log("init:" + this.id);
+      if (this.id == null) {
+        return;
+      }
+      reportDe(this.id).then(res => {
+        this.dataForm.title = res.data.title;
+        this.dataForm.content = res.data.content;
+      });
+    }
+  }
+};
+</script>

+ 0 - 2
src/views/work/work.vue

@@ -38,8 +38,6 @@ export default {
       this.input = chi;
     },
     login: function() {
-      // document.cookie = "csrftoken=";
-      document.cookie = "";
       loginByUsername("linjj", "admin");
     },
     out: function() {