Browse Source

新增卷与题

nihao 5 years ago
parent
commit
aa016345b2
4 changed files with 78 additions and 55 deletions
  1. 4 0
      src/store/index.js
  2. 38 0
      src/store/question.js
  3. 6 6
      src/store/questionnaire.js
  4. 30 49
      src/views/question/index.vue

+ 4 - 0
src/store/index.js

@@ -3,6 +3,8 @@ import Vuex from 'vuex';
 import leave from './leave';
 import attendance from './attendance';
 import group from './group';
+import question from './question';
+import questionnaire from './questionnaire';
 Vue.use(Vuex);
 
 export default new Vuex.Store({
@@ -10,6 +12,8 @@ export default new Vuex.Store({
     leave,
     attendance,
     group,
+    question,
+    questionnaire,
   },
   state: {}, //变量
   mutations: {}, //同步方法

+ 38 - 0
src/store/question.js

@@ -0,0 +1,38 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import _ from 'lodash';
+Vue.use(Vuex);
+const api = {
+  questionInfo: `/api/train/question`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  async query({ commit }, { skip = 0, limit, ...info } = {}) {
+    const res = await this.$axios.$get(`${api.questionInfo}`, { skip, limit, ...info });
+    return res;
+  },
+  async create({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.questionInfo}`, payload);
+    return res;
+  },
+  async fetch({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.questionInfo}/${payload}`);
+    return res;
+  },
+  async update({ commit }, { id, ...data }) {
+    const res = await this.$axios.$post(`${api.questionInfo}/update/${id}`, data);
+    return res;
+  },
+  async delete({ commit }, payload) {
+    const res = await this.$axios.$delete(`${api.questionInfo}/${payload}`);
+    return res;
+  },
+};
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 6 - 6
src/store/questionnaire.js

@@ -3,30 +3,30 @@ import Vuex from 'vuex';
 import _ from 'lodash';
 Vue.use(Vuex);
 const api = {
-  questionInfo: `/api/train/questionnaire`,
+  questionnaireInfo: `/api/train/questionnaire`,
 };
 const state = () => ({});
 const mutations = {};
 
 const actions = {
   async query({ commit }, { skip = 0, limit, ...info } = {}) {
-    const res = await this.$axios.$get(`${api.questionInfo}`, { skip, limit, ...info });
+    const res = await this.$axios.$get(`${api.questionnaireInfo}`, { skip, limit, ...info });
     return res;
   },
   async create({ commit }, payload) {
-    const res = await this.$axios.$post(`${api.questionInfo}`, payload);
+    const res = await this.$axios.$post(`${api.questionnaireInfo}`, payload);
     return res;
   },
   async fetch({ commit }, payload) {
-    const res = await this.$axios.$get(`${api.questionInfo}/${payload}`);
+    const res = await this.$axios.$get(`${api.questionnaireInfo}/show/${payload}`);
     return res;
   },
   async update({ commit }, { id, ...data }) {
-    const res = await this.$axios.$post(`${api.questionInfo}/update/${id}`, data);
+    const res = await this.$axios.$post(`${api.questionnaireInfo}/update/${id}`, data);
     return res;
   },
   async delete({ commit }, payload) {
-    const res = await this.$axios.$delete(`${api.questionInfo}/${payload}`);
+    const res = await this.$axios.$delete(`${api.questionnaireInfo}/${payload}`);
     return res;
   },
 };

+ 30 - 49
src/views/question/index.vue

@@ -1,21 +1,24 @@
 <template>
   <div id="index">
-    <el-form :label-position="labelPosition" label-width="80px" :model="formLabelAlign">
-      <el-row>
-        <el-col :span="24" class="text_auto">{{ info.name }}</el-col>
-      </el-row>
-      <el-row>
-        <el-col :span="24" class="text_left" v-for="(item, index) in info.question" :key="index">
-          {{ item.type }}
+    <el-row>
+      <el-col :span="24" class="info">
+        <el-col :span="24" class="top">
+          <topNav></topNav>
         </el-col>
-        <el-col :span="24" class="text_center">456</el-col>
-      </el-row>
-    </el-form>
-    <footInfo></footInfo>
+        <el-col :span="24" class="main">
+          <question :info="info"></question>
+        </el-col>
+        <el-col :span="24" class="foot">
+          <footInfo></footInfo>
+        </el-col>
+      </el-col>
+    </el-row>
   </div>
 </template>
 
 <script>
+import topNav from '@/layout/index/topInfo.vue';
+import question from '@question/src/views/index.vue';
 import footInfo from '@/layout/index/footInfo.vue';
 import { createNamespacedHelpers, mapGetters } from 'vuex';
 const { mapActions: mapQuestion } = createNamespacedHelpers('questionnaire');
@@ -23,13 +26,20 @@ export default {
   name: 'index',
   props: {},
   components: {
+    topNav, //头部导航
     footInfo,
+    question, //问卷调查框架
   },
   data: () => ({
     info: {
       name: '2020年疫情发展问卷调查',
       num: '1',
-      question: [],
+      question: [
+        {
+          type: 'created',
+          name: '测试',
+        },
+      ],
     },
   }),
   created() {
@@ -37,46 +47,17 @@ export default {
   },
   computed: {},
   methods: {
-    ...mapQuestion(['query', 'fetch']),
+    ...mapQuestion(['query', 'fetch', 'update']),
     async searchInfo({ ...info } = {}) {
       const res = await this.query({ ...info });
-      console.log(res.data);
-      // this.$set(this, `leaveList`, res.data);
+      for (const val of res.data) {
+        const result = await this.fetch(val.id);
+        // console.log(result.data.question);
+        console.log(result.data);
+        this.$set(this, `info`, result.data);
+        this.$set(this.info, `question`, result.data.question);
+      }
     },
-    // let result;
-    // for (const val of result.data) {
-    //   console.log(val);
-    //   for (const res of val.question) {
-    //     console.log(id);
-    //     this.$set(this, `question`, res.data);
-    //   }
-    // }
   },
 };
 </script>
-
-<style lang="less" scoped>
-.text_auto {
-  width: 100%;
-  // height: 50px;
-  line-height: 50px;
-  position: relative;
-  text-align: center;
-  border-bottom: 1px dashed #333;
-}
-
-.text_left {
-  width: 100%;
-  // height: 50px;
-  line-height: 50px;
-  position: relative;
-  padding-left: 25px;
-  color: blue;
-}
-.text_center {
-  width: 100%;
-  line-height: 10px;
-  position: relative;
-  padding-left: 50px;
-}
-</style>