Browse Source

feat:完成静态的新增课程弹窗

茫茫燃 4 years ago
parent
commit
01786ea621

+ 1 - 0
src/components/CourseItem.vue

@@ -44,6 +44,7 @@
   border-radius: 8px;
 }
 
+
 .courseItem :hover {
   cursor: pointer;
 }

+ 6 - 0
src/global/register-element.js

@@ -12,6 +12,9 @@ import {
   ElSelect,
   ElIcon,
   ElPagination,
+  ElDialog,
+  ElDatePicker,
+  ElUpload,
 } from "element-plus";
 
 // NOTE 使用到的组件列表,请确保 import 和 component 的一致性
@@ -29,6 +32,9 @@ const components = [
   ElSelect,
   ElIcon,
   ElPagination,
+  ElDialog,
+  ElDatePicker,
+  ElUpload,
 ];
 
 export default function (app) {

+ 4 - 7
src/global/register-icon.js

@@ -1,12 +1,9 @@
-import { Lock, Phone } from "@element-plus/icons";
+import { Lock, Phone, Plus } from "@element-plus/icons";
 
-const icons = [
-  Phone,
-  Lock,
-];
+const icons = [Phone, Lock, Plus];
 
 export default function (app) {
-  Object.keys(icons).forEach(key => {
+  Object.keys(icons).forEach((key) => {
     app.component(key, icons[key]);
   });
-}
+}

+ 139 - 1
src/views/ManagePage/ManagerHome/ManagerHome.vue

@@ -14,7 +14,7 @@
             >
             </el-option>
           </el-select>
-          <el-button plain type="primary ml-16">新增课程</el-button>
+          <el-button plain type="primary ml-16" @click="dialogVisible=true">新增课程</el-button>
         </div>
       </div>
       <div class="courseList">
@@ -28,16 +28,154 @@
       </el-pagination>
     </div>
   </div>
+  <el-dialog
+      v-model="dialogVisible"
+      title="新增课程"
+      width="50%"
+  >
+    <div class="createCourseCard">
+      <div class="newCourseInfo">
+        <div class="mb-16 flex-around">
+          <span>课程名称</span>
+          <el-input v-model="courseInfo.name" placeholder="课程名称"/>
+        </div>
+        <div class="mb-16 flex-around">
+          <span>任课教师</span>
+          <el-input v-model="courseInfo.teacher" placeholder="任课教师"/>
+        </div>
+        <div class="mb-16 flex-around">
+          <span>所属学期</span>
+          <el-input v-model="courseInfo.semester" placeholder="所属学期"/>
+        </div>
+        <div class="mb-16 flex-around">
+          <span>开课时间</span>
+          <el-date-picker v-model="courseInfo.startTime" placeholder="Pick a day" type="date">
+          </el-date-picker>
+        </div>
+        <div class="mb-16 flex-around">
+          <span>邀请码&emsp;</span>
+          <el-input v-model="courseInfo.code" placeholder="邀请码"/>
+        </div>
+        <div class="mb-16 flex-around">
+          <span>外部链接</span>
+          <div class="checkBoxContainer">
+            <el-checkbox
+                v-model="selectMooc"
+                border
+                label="Mooc"
+                size="large"
+            ></el-checkbox>
+          </div>
+        </div>
+        <div v-if="selectMooc" class="mb-16 flex-around">
+          <span>&emsp;&emsp;&emsp;&emsp;</span>
+          <el-input v-model="courseInfo.link" placeholder="Mooc Link"/>
+        </div>
+      </div>
+      <div class="newCoursePic">
+        <div class="upLoad">
+          <el-upload
+              :before-upload="beforeAvatarUpload"
+              :on-success="handleAvatarSuccess"
+              :show-file-list="false"
+              action="https://jsonplaceholder.typicode.com/posts/"
+              class="avatar-uploader"
+          >
+            <img v-if="courseInfo.imgUrl" :src="courseInfo.imgUrl" class="avatar"/>
+            <el-icon v-else class="avatar-uploader-icon">
+              <plus/>
+            </el-icon>
+          </el-upload>
+        </div>
+        <div class="mt-16">
+          <span style="display: block;margin-bottom: 4px">添加简介</span>
+          <el-input
+              v-model="courseInfo.description"
+              :rows="4"
+              placeholder="课程简介"
+              type="textarea"
+          />
+        </div>
+
+      </div>
+
+    </div>
+    <div class="flex-center">
+      <div class="saveNewCourse">
+        <el-button type="primary">保存</el-button>
+        <el-button type="danger" @click="dialogVisible=false">取消</el-button>
+      </div>
+    </div>
+
+  </el-dialog>
 
 </template>
 
 <script setup>
 import GlobalHeader from "@/components/GlobalHeader";
 import CourseItem from "@/components/CourseItem";
+import {Plus} from "@element-plus/icons";
+import {reactive, ref} from "vue";
+
+
+const dialogVisible = ref(false);
+const selectMooc = ref(false);
+let courseInfo = reactive({
+  name: "",
+  teacher: "",
+  semester: "",
+  startTime: "",
+  code: "",
+  link: "",
+  imgUrl: "",
+  description: ""
+});
+
 
 </script>
 
 <style scoped>
 @import "style/managerHome.css";
 
+.el-input {
+  width: 200px;
+}
+
+.flex-around >>> .el-date-editor.el-input {
+  width: 200px;
+}
+
+
+.upLoad >>> .avatar-uploader .el-upload {
+  border: 1px dashed #d9d9d9;
+  border-radius: 6px;
+  cursor: pointer;
+  position: relative;
+  overflow: hidden;
+  width: 100%;
+  background-color: whitesmoke;
+}
+
+.upLoad >>> .avatar-uploader .el-upload:hover {
+  border-color: #409eff;
+}
+
+.upLoad >>> .avatar-uploader-icon {
+  font-size: 28px;
+  color: #8c939d;
+  width: 178px;
+  height: 178px;
+  text-align: center;
+  line-height: 178px;
+}
+
+.upLoad >>> .avatar {
+  width: 178px;
+  height: 178px;
+  display: block;
+}
+
+.saveNewCourse .el-button {
+  width: 88px;
+}
 </style>

+ 66 - 0
src/views/ManagePage/ManagerHome/style/managerHome.css

@@ -31,6 +31,26 @@
     margin-left: 16px;
 }
 
+.mb-16 {
+    margin-bottom: 16px;
+}
+
+.mt-16 {
+    margin-top: 16px;
+}
+
+.flex-around {
+    display: flex;
+    justify-content: space-around;
+    align-items: center;
+}
+
+.flex-center {
+    display: flex;
+    justify-content: center;
+    align-items: center;
+}
+
 .courseList {
     overflow: hidden;
     margin-top: 40px;
@@ -40,6 +60,14 @@
     display: inline-block;
     margin-right: 150px;
     margin-bottom: 40px;
+    transition: all ease-in 0.2s;
+    border-radius: 8px;
+}
+
+.cItem:hover {
+    /*hover可以作用于子元素,故不能在组件中定义hover伪类
+    这会导致组件中的每个元素均受到影响*/
+    box-shadow: 0 4px 16px 0 rgb(0 0 0 / 12%);
 }
 
 .cItem:nth-child(4n) {
@@ -53,3 +81,41 @@
 /*.el-pagination.is-background .el-pager li {*/
 /*    min-width: 36px;*/
 /*}*/
+
+
+.el-dialog__title {
+    font-size: 24px;
+}
+
+.createCourseCard {
+    min-height: 400px;
+    display: flex;
+    justify-content: space-between;
+}
+
+.newCourseInfo {
+    width: 50%;
+    min-width: 50%;
+    font-size: 20px;
+    color: #666666;
+}
+
+.checkBoxContainer {
+    display: inline-block;
+    width: 200px;
+}
+
+
+.newCoursePic {
+    width: 40%;
+    font-size: 20px;
+    color: #666666;
+
+}
+
+.saveNewCourse {
+    width: 220px;
+    display: flex;
+    justify-content: space-between;
+
+}