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

添加用于投票的 VotePage.vue

reghao 7 месяцев назад
Родитель
Сommit
24485c5e4c

+ 2 - 0
src/router/index.js

@@ -7,6 +7,7 @@ import MallRouter from './mall'
 import VodRouter from './vod'
 import MapRouter from './map'
 import ChartRouter from './chart'
+import VoteRouter from './vote'
 
 // 懒加载引入页面组件,es6语法
 // ********************************************************************************************************************
@@ -44,6 +45,7 @@ const routes = [
   MapRouter,
   VodRouter,
   ChartRouter,
+  VoteRouter,
   {
     path: '/login',
     name: 'Login',

+ 3 - 3
src/router/map.js

@@ -16,19 +16,19 @@ export default {
       path: '',
       name: '地图',
       component: AMap,
-      meta: { needAuth: true }
+      meta: { needAuth: false }
     },
     {
       path: '/map/photo',
       name: '照片地图',
       component: PhotoMap,
-      meta: { needAuth: true }
+      meta: { needAuth: false }
     },
     {
       path: '/map/trail',
       name: '轨迹地图',
       component: TrailMap,
-      meta: { needAuth: true }
+      meta: { needAuth: false }
     }
   ]
 }

+ 23 - 0
src/router/vote.js

@@ -0,0 +1,23 @@
+const VoteIndex = () => import('views/vote/VoteIndex')
+const VotePage = () => import('views/vote/VotePage')
+
+export default {
+  path: '/vote',
+  name: 'VoteIndex',
+  component: VoteIndex,
+  meta: { needAuth: false },
+  children: [
+    {
+      path: '',
+      name: 'VotePage',
+      component: VotePage,
+      meta: { needAuth: false }
+    },
+    {
+      path: '/vote/map',
+      name: 'VotePage',
+      component: VotePage,
+      meta: { needAuth: false }
+    }
+  ]
+}

+ 0 - 1
src/utils/auth.js

@@ -94,5 +94,4 @@ export function removeAll() {
   localStorage.removeItem(USER_ACCESS_TOKEN)
   localStorage.removeItem(USER_REFRESH_TOKEN)
   localStorage.removeItem(USER_INFO)
-  console.log('删除 localstorage')
 }

+ 28 - 20
src/views/map/MapIndex.vue

@@ -28,26 +28,34 @@
         </el-menu>
       </el-col>
       <el-col :md="2">
-        <el-dropdown>
-          <img
-            :src="user.avatarUrl"
-            class="el-avatar--circle el-avatar--medium"
-            style="margin-right: 10px; margin-top: 15px"
-            alt=""
-          >
-          <el-dropdown-menu slot="dropdown">
-            <el-dropdown-item
-              icon="el-icon-s-platform"
-              class="size"
-              @click.native="goToHome"
-            >主站</el-dropdown-item>
-            <el-dropdown-item
-              icon="el-icon-error"
-              class="size"
-              @click.native="goToLogout"
-            >退出</el-dropdown-item>
-          </el-dropdown-menu>
-        </el-dropdown>
+        <ul class="el-menu--horizontal el-menu">
+          <li class="el-menu-item">
+            <el-dropdown v-if="user">
+              <img
+                :src="user.avatarUrl"
+                class="el-avatar--circle el-avatar--medium"
+                style="margin-right: 10px; margin-top: 15px"
+                alt=""
+              >
+              <el-dropdown-menu slot="dropdown">
+                <el-dropdown-item
+                  icon="el-icon-s-platform"
+                  class="size"
+                  @click.native="goToHome"
+                >主站</el-dropdown-item>
+                <el-dropdown-item
+                  icon="el-icon-error"
+                  class="size"
+                  @click.native="goToLogout"
+                >退出</el-dropdown-item>
+              </el-dropdown-menu>
+            </el-dropdown>
+            <span
+              v-else
+              style="color: #007bff"
+            >登录</span>
+          </li>
+        </ul>
       </el-col>
     </el-header>
     <el-container>

+ 90 - 0
src/views/vote/VoteIndex.vue

@@ -0,0 +1,90 @@
+<template>
+  <el-container style="border: 1px solid #eee">
+    <el-header style="text-align: right; font-size: 12px">
+      <el-col :md="2">
+        <ul class="el-menu--horizontal el-menu">
+          <li class="el-menu-item">
+            <a href="/vote" style="text-decoration-line: none">
+              <img src="@/assets/img/icon/logo.png" class="el-avatar--circle el-avatar--medium" alt="img">
+              vote
+            </a>
+          </li>
+        </ul>
+      </el-col>
+      <el-col :md="20">
+        <el-menu
+          :default-active="this.$route.path"
+          router
+          mode="horizontal"
+        >
+          <el-menu-item index="/vote/map">
+            <i class="el-icon-map-location" />
+            <span slot="title">vote</span>
+          </el-menu-item>
+        </el-menu>
+      </el-col>
+      <el-col :md="2">
+        <ul class="el-menu--horizontal el-menu">
+          <li class="el-menu-item">
+            <el-dropdown v-if="user">
+              <img
+                :src="user.avatarUrl"
+                class="el-avatar--circle el-avatar--medium"
+                style="margin-right: 10px; margin-top: 15px"
+                alt=""
+              >
+              <el-dropdown-menu slot="dropdown">
+                <el-dropdown-item
+                  icon="el-icon-s-platform"
+                  class="size"
+                  @click.native="goToHome"
+                >主站</el-dropdown-item>
+                <el-dropdown-item
+                  icon="el-icon-error"
+                  class="size"
+                  @click.native="goToLogout"
+                >退出</el-dropdown-item>
+              </el-dropdown-menu>
+            </el-dropdown>
+            <span
+              v-else
+              style="color: #007bff"
+            >登录</span>
+          </li>
+        </ul>
+      </el-col>
+    </el-header>
+    <el-container>
+      <el-main>
+        <router-view />
+      </el-main>
+    </el-container>
+  </el-container>
+</template>
+
+<script>
+import { userMixin } from 'assets/js/mixin'
+import { getAuthedUser } from '@/utils/auth'
+
+export default {
+  name: 'VoteIndex',
+  mixins: [userMixin],
+  data() {
+    return {
+      user: null
+    }
+  },
+  watch: {
+    // 地址栏 url 发生变化时重新加载本页面
+    $route() {
+      this.$router.go()
+    }
+  },
+  created() {
+    this.user = getAuthedUser()
+  }
+}
+</script>
+
+<style>
+</style>

+ 243 - 0
src/views/vote/VotePage.vue

@@ -0,0 +1,243 @@
+<template>
+  <div>
+    <el-row class="movie-list">
+      <el-col :md="12" :sm="12" :xs="12">
+        <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
+          <el-card class="box-card">
+            <div slot="header" class="clearfix">
+              <span>投票</span>
+              <el-button style="float: right; padding: 5px; color: red" type="text" @click="createVote">创建投票</el-button>
+            </div>
+            <div class="text item" />
+          </el-card>
+        </el-row>
+      </el-col>
+      <el-col :md="12" :sm="12" :xs="12">
+        <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
+          <el-card v-if="vote !== null" class="box-card">
+            <div slot="header" class="clearfix">
+              <span>{{ vote.title }}</span>
+              <el-button style="float: right; padding: 5px; color: blue" type="text" @click="submit">提交投票</el-button>
+            </div>
+            <div class="text item">
+              <el-radio-group
+                v-for="(voteOption, index1) in vote.options"
+                :key="index1"
+                v-model="checkedRadio"
+                class="movie-list"
+                @change="singleCheckChange(voteOption)"
+              >
+                <el-radio :label="voteOption.value" border size="medium">
+                  <span>{{ voteOption.name }}</span>
+                </el-radio>
+              </el-radio-group>
+            </div>
+          </el-card>
+        </el-row>
+      </el-col>
+    </el-row>
+
+    <el-dialog
+      title="创建投票"
+      :visible.sync="showVoteDialog"
+      :close-on-click-modal="false"
+      width="50%"
+      center
+      @close="onCloseDialog"
+    >
+      <el-card>
+        <el-form ref="addQuForm" :model="addQuForm" :rules="addQuFormRules">
+          <el-form-item label="投票名称" label-width="120px" prop="title">
+            <el-input
+              v-model="addQuForm.title"
+              style="margin-left: 5px"
+              clearable
+            />
+          </el-form-item>
+          <el-form-item label="结束时间" label-width="120px" prop="endTime">
+            <el-date-picker
+              v-model="addQuForm.endTime"
+              type="date"
+              style="margin-left: 5px"
+              placeholder="选择结束时间"
+            />
+          </el-form-item>
+          <el-form-item label="预期人数" label-width="120px" prop="expectNum">
+            <el-input-number v-model="addQuForm.expectNum" :min="2" :max="10000" style="margin-left: 5px" />
+          </el-form-item>
+          <el-button
+            type="primary"
+            plain
+            size="small"
+            icon="el-icon-plus"
+            style="margin-left: 40px"
+            @click="addVoteOption"
+          >
+            添加投票选项
+          </el-button>
+          <!--存放答案表单的信息-->
+          <el-form-item prop="options">
+            <el-table :data="addQuForm.options" border style="width: 96%;margin-left: 40px;margin-top: 10px">
+              <el-table-column label="选项内容">
+                <template slot-scope="scope">
+                  <el-input
+                    v-model="scope.row.name"
+                    style="margin-left: 5px"
+                    clearable
+                  />
+                </template>
+              </el-table-column>
+              <el-table-column label="操作">
+                <template slot-scope="scope">
+                  <el-button type="danger" icon="el-icon-delete" size="mini" circle @click="delVoteOption(scope.row.id)" />
+                  <el-button type="danger" icon="el-icon-plus" size="mini" circle @click="addVoteOption" />
+                </template>
+              </el-table-column>
+            </el-table>
+          </el-form-item>
+        </el-form>
+      </el-card>
+      <div slot="footer" class="dialog-footer">
+        <el-button type="primary" @click="addVote">添 加</el-button>
+        <el-button @click="showVoteDialog = false">取 消</el-button>
+      </div>
+    </el-dialog>
+  </div>
+</template>
+
+<script>
+export default {
+  name: 'VotePage',
+  data() {
+    return {
+      // 屏幕宽度, 为了控制分页条的大小
+      screenWidth: document.body.clientWidth,
+      checkedRadio: '',
+      selectedOption: null,
+      vote: null,
+      showVoteDialog: false,
+      // 添加试题的表单信息
+      addQuForm: {
+        title: '',
+        endTime: null,
+        expectNum: 0,
+        options: []
+      },
+      // 添加试题表单的验证规则
+      addQuFormRules: {
+        title: [
+          {
+            required: true,
+            message: '请输入投票名称',
+            trigger: 'blur'
+          }
+        ],
+        endTime: [
+          {
+            required: true,
+            message: '请选择投票的结束时间',
+            trigger: 'blur'
+          }
+        ],
+        expectNum: [
+          {
+            required: true,
+            message: '请选择期望投票的人数',
+            trigger: 'blur'
+          }
+        ]
+      }
+    }
+  },
+  created() {
+    document.title = 'VotePage'
+    this.getData()
+  },
+  methods: {
+    getData() {
+      this.$message.info('get vote')
+    },
+    createVote() {
+      this.showVoteDialog = true
+    },
+    onCloseDialog() {
+    },
+    addVote() {
+      this.$message.info('创建投票')
+      console.log(this.addQuForm)
+      this.vote = this.addQuForm
+      this.showVoteDialog = false
+      this.addQuForm = {
+        title: '',
+        endTime: null,
+        expectNum: 0,
+        options: []
+      }
+    },
+    addVoteOption() {
+      this.addQuForm.options.push({
+        optionId: this.addQuForm.options.length,
+        name: '',
+        value: this.addQuForm.options.length + 1,
+        pos: this.addQuForm.options.length
+      })
+    },
+    delVoteOption(id) {
+      this.addQuForm.options.map((item, index) => {
+        if (item.optionId === id) this.addQuForm.options.splice(index, 1)
+      })
+    },
+    singleCheckChange(val) {
+      this.selectedOption = val
+    },
+    submit() {
+      if (this.selectedOption === null) {
+        this.$message.info('请先选择')
+        return
+      }
+
+      const confirmText = '确认选择 [' + this.selectedOption.name + ']?'
+      this.$confirm(confirmText, '提示', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(() => {
+        this.$message.info('提交数据')
+        console.log(this.selectedOption)
+      }).catch(() => {
+        this.$message({
+          type: 'info',
+          message: '已取消'
+        })
+      })
+    }
+  }
+}
+</script>
+
+<style scoped>
+/*处于手机屏幕时*/
+@media screen and (max-width: 768px) {
+  .movie-list {
+    padding-top: 8px;
+    padding-left: 0.5%;
+    padding-right: 0.5%;
+  }
+}
+
+.movie-list {
+  padding-top: 15px;
+  padding-left: 6%;
+  padding-right: 6%;
+}
+
+.clearfix:before,
+.clearfix:after {
+  display: table;
+  content: "";
+}
+
+.clearfix:after {
+  clear: both;
+}
+</style>