reloaded 4 years ago
parent
commit
5b53a4be7e

+ 4 - 0
src/store/index.js

@@ -7,6 +7,8 @@ import room from './room';
 import lookuser from './lookuser';
 import gensign from './gensign';
 import chat from './chat';
+import question from './question';
+import questionnaire from './questionnaire';
 import * as ustate from './user/state';
 import * as umutations from './user/mutations';
 
@@ -24,5 +26,7 @@ export default new Vuex.Store({
     lookuser,
     gensign,
     chat,
+    question,
+    questionnaire,
   },
 });

+ 64 - 0
src/store/question.js

@@ -0,0 +1,64 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import _ from 'lodash';
+import axios from 'axios';
+Vue.use(Vuex);
+const api = {
+  interface: `/api/onlive/question`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  async query({ commit }, { skip = 0, limit, ...info } = {}) {
+    const res = await this.$axios.$get(`${api.interface}`, { skip, limit, ...info });
+    return res;
+  },
+  async create({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.interface}`, payload);
+    return res;
+  },
+  async fetch({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.interface}/${payload}`);
+    return res;
+  },
+  async update({ commit }, { id, ...data }) {
+    const res = await this.$axios.$post(`${api.interface}/update/${id}`, data);
+    return res;
+  },
+  async delete({ commit }, payload) {
+    const res = await this.$axios.$delete(`${api.interface}/${payload}`);
+    return res;
+  },
+  async mergeRequest({ commit, dispatch }, { method, data }) {
+    let toRequest = () => {
+      let res = [];
+      for (const i of data) {
+        res.push(dispatch(method, i));
+      }
+      return res;
+    };
+    let result = await axios.all(toRequest());
+    let newFilter = data => {
+      let res = data.map(i => {
+        let type = _.isArray(i);
+        if (!type) {
+          //fetch的多个请求 是object 将errcode为0的data取出来
+          return _.get(i, `data`, i);
+        } else {
+          //query的多个请求 array 将此数据再次走这个方法
+          return newFilter(i);
+        }
+      });
+      return res;
+    };
+    let returns = _.flattenDeep(newFilter(result));
+    return returns;
+  },
+};
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 64 - 0
src/store/questionnaire.js

@@ -0,0 +1,64 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import _ from 'lodash';
+import axios from 'axios';
+Vue.use(Vuex);
+const api = {
+  interface: `/api/onlive/questionnaire`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  async query({ commit }, { skip = 0, limit, ...info } = {}) {
+    const res = await this.$axios.$get(`${api.interface}`, { skip, limit, ...info });
+    return res;
+  },
+  async create({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.interface}`, payload);
+    return res;
+  },
+  async fetch({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.interface}/show/${payload}`);
+    return res;
+  },
+  async update({ commit }, { id, ...data }) {
+    const res = await this.$axios.$post(`${api.interface}/update/${id}`, data);
+    return res;
+  },
+  async delete({ commit }, payload) {
+    const res = await this.$axios.$delete(`${api.interface}/${payload}`);
+    return res;
+  },
+  async mergeRequest({ commit, dispatch }, { method, data }) {
+    let toRequest = () => {
+      let res = [];
+      for (const i of data) {
+        res.push(dispatch(method, i));
+      }
+      return res;
+    };
+    let result = await axios.all(toRequest());
+    let newFilter = data => {
+      let res = data.map(i => {
+        let type = _.isArray(i);
+        if (!type) {
+          //fetch的多个请求 是object 将errcode为0的data取出来
+          return _.get(i, `data`, i);
+        } else {
+          //query的多个请求 array 将此数据再次走这个方法
+          return newFilter(i);
+        }
+      });
+      return res;
+    };
+    let returns = _.flattenDeep(newFilter(result));
+    return returns;
+  },
+};
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 32 - 6
src/views/question/index.vue

@@ -1,18 +1,44 @@
 <template>
   <div id="index">
-    <p>问卷调查</p>
+    <el-row>
+      <el-col :span="24" class="index">
+        <el-col :span="24" class="top">
+          <topInfo :topTitle="pageTitle"></topInfo>
+        </el-col>
+      </el-col>
+      <el-col :span="24">
+        <el-tabs v-model="activeName" @tab-click="handleClick">
+          <el-tab-pane label="问卷统计" name="first"><tongji></tongji></el-tab-pane>
+          <el-tab-pane label="问卷管理" name="second"><wenjuan></wenjuan></el-tab-pane>
+          <el-tab-pane label="题库管理" name="third"><tiku></tiku></el-tab-pane>
+        </el-tabs>
+      </el-col>
+    </el-row>
   </div>
 </template>
-
 <script>
+import topInfo from '@/layout/public/top.vue';
+import tongji from '@/views/question/part/tongji.vue';
+import wenjuan from '@/views/question/part/wenjuan.vue';
+import tiku from '@/views/question/part/tiku.vue';
+import { mapActions, mapState, createNamespacedHelpers } from 'vuex';
 export default {
   name: 'index',
   props: {},
-  components: {},
-  data: () => ({}),
+  components: { topInfo, tongji, wenjuan, tiku },
+  data: () => ({
+    activeName: 'first',
+  }),
   created() {},
-  computed: {},
-  methods: {},
+  computed: {
+    ...mapState(['user']),
+    pageTitle() {
+      return `${this.$route.meta.title}`;
+    },
+  },
+  methods: {
+    handleClick() {},
+  },
 };
 </script>
 

+ 188 - 0
src/views/question/part/tiku.vue

@@ -0,0 +1,188 @@
+<template>
+  <div id="tiku">
+    <el-row>
+      <el-col class="add" :span="24">
+        <el-select v-model="type" placeholder="请选择题目类型">
+          <el-option v-for="item in typeoptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
+        </el-select>
+        <el-select v-model="status" placeholder="请选择题目状态">
+          <el-option v-for="item in statusoptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
+        </el-select>
+        <el-button size="mini" type="primary" @click="search" style="margin-left:10px;">查询</el-button>
+        <el-button size="mini" type="primary" @click="add">添加</el-button>
+      </el-col>
+      <el-col :span="24"
+        ><el-table :data="list" border style="width: 100%">
+          <el-table-column prop="type" label="类型">
+            <template slot-scope="scope">
+              <span>{{ scope.row.type == '0' ? '单选' : scope.row.type == '1' ? '多选' : scope.row.type == '2' ? '问答' : '未识别' }}</span>
+            </template>
+          </el-table-column>
+          <el-table-column prop="topic" label="题目" show-overflow-tooltip> </el-table-column>
+          <el-table-column prop="status" label="状态">
+            <template slot-scope="scope">
+              <span>{{ scope.row.status == '0' ? '弃用' : scope.row.status == '1' ? '正常' : '未识别' }}</span>
+            </template>
+          </el-table-column>
+          <el-table-column label="操作">
+            <template slot-scope="scope">
+              <el-button size="mini" @click="detailBtn(scope.row)">查看</el-button>
+              <el-button size="mini" @click="deleteBtn(scope.row.id)" type="danger">删除</el-button>
+            </template>
+          </el-table-column>
+        </el-table>
+      </el-col>
+      <el-col :span="24" class="page">
+        <el-pagination background layout="prev, pager, next,total" :total="total" @current-change="handleCurrentChange"> </el-pagination>
+      </el-col>
+      <el-dialog title="添加题目" :visible.sync="dialogFormVisible">
+        <el-form size="mini" :model="form" ref="form" label-width="100px" class="demo-dynamic" :rules="rules">
+          <el-form-item prop="type" label="类型">
+            <el-radio-group v-model="form.type">
+              <el-radio :label="'0'">单选</el-radio>
+              <el-radio :label="'1'">多选</el-radio>
+              <el-radio :label="'2'">问答</el-radio>
+            </el-radio-group>
+          </el-form-item>
+          <el-form-item prop="status" label="状态">
+            <el-radio-group v-model="form.status">
+              <el-radio :label="'0'">弃用</el-radio>
+              <el-radio :label="'1'">正常</el-radio>
+            </el-radio-group>
+          </el-form-item>
+          <el-form-item prop="topic" label="题目">
+            <el-input v-model="form.topic"></el-input>
+          </el-form-item>
+          <el-col class="option" v-if="form.type != '2'">
+            <p>选项</p>
+            <el-form-item v-for="(item, index) in form.option" :label="sortNumber(index)" :key="index">
+              <el-input v-model="item.opname"></el-input><el-button @click.prevent="removeDomain(item)">删除</el-button>
+            </el-form-item>
+            <el-form-item>
+              <el-button @click="addDomain">新增选项</el-button>
+            </el-form-item>
+          </el-col>
+        </el-form>
+        <div slot="footer" class="dialog-footer">
+          <el-button @click="dialogFormVisible = false">取 消</el-button>
+          <el-button type="primary" @click="submitFrom">确 定</el-button>
+        </div>
+      </el-dialog>
+    </el-row>
+  </div>
+</template>
+
+<script>
+import { createNamespacedHelpers, mapState } from 'vuex';
+const { mapActions: question } = createNamespacedHelpers('question');
+export default {
+  name: 'tiku',
+  props: {},
+  components: {},
+  data: () => ({
+    list: [],
+    total: 0,
+    dialogFormVisible: false,
+    form: {
+      option: [],
+    },
+    type: null,
+    typeoptions: [
+      { value: '0', label: '单选' },
+      { value: '1', label: '多选' },
+      { value: '2', label: '问答' },
+    ],
+    status: null,
+    statusoptions: [
+      { value: '0', label: '弃用' },
+      { value: '1', label: '正常' },
+    ],
+    rules: {
+      type: { required: true, message: '类型不能为空', trigger: 'blur' },
+      topic: { required: true, message: '题目不能为空', trigger: 'blur' },
+      status: { required: true, message: '状态不能为空', trigger: 'blur' },
+    },
+  }),
+  created() {
+    this.search();
+  },
+  computed: {},
+  methods: {
+    ...question(['create', 'query', 'update', 'delete']),
+    async search({ skip = 0, limit = 10, ...info } = {}) {
+      info = { type: this.type, status: this.status };
+      const list = await this.query({ skip, limit, ...info });
+      this.$set(this, `list`, list.data);
+      this.$set(this, `total`, list.total);
+    },
+    detailBtn(item) {
+      console.log(item);
+      this.$set(this, `form`, item);
+      this.dialogFormVisible = true;
+    },
+    async deleteBtn(id) {
+      let res = await this.delete(id);
+      if (res.errcode == 0) this.search();
+    },
+    handleCurrentChange(val) {
+      this.search({ skip: (val - 1) * 10, limit: val * 10 });
+    },
+    async submitFrom() {
+      let index = 0;
+      for (const option of this.form.option) {
+        option.number = this.sortNumber(index);
+        index++;
+      }
+      if (this.form.type == '2') {
+        delete this.form.option;
+      }
+      let res;
+      if (this.form.id) res = await this.update(this.form);
+      else res = await this.create(this.form);
+      if (res.errcode == 0) {
+        this.dialogFormVisible = false;
+        this.search();
+      }
+    },
+    removeDomain(item) {
+      var index = this.form.option.indexOf(item);
+      if (index !== -1) {
+        this.form.option.splice(index, 1);
+      }
+    },
+    addDomain() {
+      this.form.option.push({
+        opname: '',
+      });
+    },
+    sortNumber(index) {
+      return String.fromCharCode(65 + index);
+    },
+    add() {
+      this.dialogFormVisible = true;
+      this.form = { status: '1', option: [] };
+    },
+  },
+};
+</script>
+
+<style lang="less" scoped>
+.add {
+  margin: 0 0 10px 0;
+}
+.add .el-button:last-child {
+  float: right;
+}
+/deep/.el-dialog {
+  width: 70%;
+}
+.option p {
+  width: 85px;
+  text-align: right;
+  padding: 0 20px 5px 0;
+}
+/deep/.option .el-input {
+  width: 70%;
+  margin: 0 5px 0 0;
+}
+</style>

+ 19 - 0
src/views/question/part/tongji.vue

@@ -0,0 +1,19 @@
+<template>
+  <div id="tongji">
+    <p>tongji</p>
+  </div>
+</template>
+
+<script>
+export default {
+  name: 'tongji',
+  props: {},
+  components: {},
+  data: () => ({}),
+  created() {},
+  computed: {},
+  methods: {},
+};
+</script>
+
+<style lang="less" scoped></style>

+ 19 - 0
src/views/question/part/wenjuan.vue

@@ -0,0 +1,19 @@
+<template>
+  <div id="wenjuan">
+    <p>wenjuan</p>
+  </div>
+</template>
+
+<script>
+export default {
+  name: 'wenjuan',
+  props: {},
+  components: {},
+  data: () => ({}),
+  created() {},
+  computed: {},
+  methods: {},
+};
+</script>
+
+<style lang="less" scoped></style>