Browse Source

题库管理,问卷管理

guhongwei 2 years ago
parent
commit
611cc320d5

+ 22 - 22
src/main.ts

@@ -1,37 +1,37 @@
-import { createApp } from 'vue'
-import { createPinia } from 'pinia'
-import App from './App.vue'
-import router from './router'
+import { createApp } from 'vue';
+import { createPinia } from 'pinia';
+import App from './App.vue';
+import router from './router';
 // 样式
-import '@/assets/main.css'
+import '@/assets/main.css';
 // 动画
-import 'animate.css'
+import 'animate.css';
 // element
-import ElementPlus from 'element-plus'
-import 'element-plus/dist/index.css'
-import locale from 'element-plus/lib/locale/lang/zh-cn'
-import * as ElementPlusIconsVue from '@element-plus/icons-vue'
+import ElementPlus from 'element-plus';
+import 'element-plus/dist/index.css';
+import locale from 'element-plus/lib/locale/lang/zh-cn';
+import * as ElementPlusIconsVue from '@element-plus/icons-vue';
 // 图标
-import '@common/src/assets/icon/iconfont.css'
+import '@common/src/assets/icon/iconfont.css';
 // moment
-import moment from 'moment'
+import moment from 'moment';
 // lodash
 // import _ from 'lodash';
 
 // 组件
-import frameComponents from '@/components/index'
-const app = createApp(App)
-app.use(createPinia())
-app.use(router)
-app.use(ElementPlus, { locale })
+import frameComponents from '@/components/index';
+const app = createApp(App);
+app.use(createPinia());
+app.use(router);
+app.use(ElementPlus, { locale });
 for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
-  app.component(key, component)
+  app.component(key, component);
 }
-app.config.globalProperties.$moment = moment
+app.config.globalProperties.$moment = moment;
 
 for (const componentItme in frameComponents) {
-  app.component(componentItme, frameComponents[componentItme])
+  app.component(componentItme, frameComponents[componentItme]);
 }
-app.config.globalProperties.$limit = parseInt(import.meta.env.VITE_APP_PAGE_SIZE) || 10
+app.config.globalProperties.$limit = parseInt(import.meta.env.VITE_APP_PAGE_SIZE) || 10;
 
-app.mount('#app')
+app.mount('#app');

+ 15 - 0
src/router/module/admin.ts

@@ -4,11 +4,26 @@ export default [
     meta: { title: '题库管理' },
     component: () => import('@/views/question/index.vue')
   },
+  {
+    path: '/question/detail',
+    meta: { title: '信息管理' },
+    component: () => import('@/views/question/detail.vue')
+  },
   {
     path: '/questionnaire',
     meta: { title: '问卷管理' },
     component: () => import('@/views/questionnaire/index.vue')
   },
+  {
+    path: '/questionnaire/detail',
+    meta: { title: '信息管理' },
+    component: () => import('@/views/questionnaire/detail.vue')
+  },
+  {
+    path: '/questionnaire/questions',
+    meta: { title: '问卷管理-问卷题库' },
+    component: () => import('@/views/questionnaire/questions.vue')
+  },
   {
     path: '/answer',
     meta: { title: '问卷答案管理' },

+ 173 - 0
src/views/question/detail.vue

@@ -0,0 +1,173 @@
+<template>
+  <div id="detail">
+    <el-row>
+      <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
+        <el-col :span="24" class="one">
+          <cSearch :is_title="false" :is_back="true" @toBack="toBack"></cSearch>
+        </el-col>
+        <el-col :span="24" class="two">
+          <cForm :span="24" :fields="fields" :form="form" :rules="rules" @save="toSave" @dataChange="dataChange">
+            <template #type>
+              <el-option v-for="(i, index) in typeList" :key="index" :label="i.label" :value="i.value"></el-option>
+            </template>
+            <template #is_use>
+              <el-option v-for="(i, index) in is_useList" :key="index" :label="i.label" :value="i.value"></el-option>
+            </template>
+            <template #selects>
+              <el-row class="selects">
+                <el-col :span="24" class="selects_1">
+                  <el-button type="primary" @click="seAdd">添加</el-button>
+                  <el-button type="primary" @click="seSort">刷新排序</el-button>
+                </el-col>
+                <el-col :span="24">
+                  <el-table :data="form.selects" style="width: 100%" border>
+                    <el-table-column type="index" label="序号" width="100" align="center"> </el-table-column>
+                    <el-table-column label="标签" align="center">
+                      <template #default="scope: any">
+                        <el-input v-model="scope.row.label" placeholder="请输入标签" clearable />
+                      </template>
+                    </el-table-column>
+                    <el-table-column label="键值" align="center">
+                      <template #default="scope: any">
+                        <el-input v-model="scope.row.value" placeholder="请输入标签" clearable />
+                      </template>
+                    </el-table-column>
+                    <el-table-column label="排序" align="center">
+                      <template #default="scope: any">
+                        <el-input v-model="scope.row.sort" type="number" placeholder="请输入排序" clearable />
+                      </template>
+                    </el-table-column>
+                    <el-table-column label="操作" align="center" width="100">
+                      <template v-slot="scope: any">
+                        <el-button size="mini" type="danger" @click="seDel(scope.row)">删除</el-button>
+                      </template>
+                    </el-table-column>
+                  </el-table>
+                </el-col>
+              </el-row>
+            </template>
+          </cForm>
+        </el-col>
+      </el-col>
+    </el-row>
+  </div>
+</template>
+
+<script setup lang="ts">
+import moment from 'moment';
+import _ from 'lodash';
+import type { Ref } from 'vue';
+import { ref, reactive, onMounted } from 'vue';
+import { useRoute } from 'vue-router';
+import { ElMessage } from 'element-plus';
+import type { FormRules } from 'element-plus';
+
+// 接口
+import { QuestionStore } from '@common/src/stores/question/question'; //
+import { DictDataStore } from '@common/src/stores/system/dictData'; // 字典表
+import type { IQueryResult } from '@/util/types.util';
+const qquesAxios = QuestionStore();
+const dictAxios = DictDataStore();
+
+// 路由
+const route = useRoute();
+
+// 加载中
+const loading = ref(false);
+// 表单
+let form: Ref<any> = ref({ selects: [] });
+let fields: Ref<any[]> = ref([
+  { label: '标题', model: 'title' },
+  { label: '类型', model: 'type', type: 'select' },
+  { label: '是否启用', model: 'is_use', type: 'select' }
+]);
+const rules = reactive<FormRules>({});
+
+// 字典表
+const typeList: Ref<any> = ref([]);
+const is_useList: Ref<any> = ref([]);
+
+onMounted(async () => {
+  loading.value = true;
+  await searchOther();
+  await search();
+  loading.value = false;
+});
+const search = async () => {
+  let id = route.query.id;
+  let res: IQueryResult;
+  let info: any = { selects: [] };
+  if (id) {
+    res = await qquesAxios.fetch(route.query.id);
+    if (res.errcode == 0) {
+      info = res.data;
+      if (info.type == '1' || info.type == '2') {
+        dataChange({ value: info.type, model: 'type' });
+      }
+    }
+  }
+  form.value = info;
+};
+// 选项
+const dataChange = (e: { value; model }) => {
+  if (e.model == 'type') {
+    let data = fields.value.find((i) => i.model == 'selects');
+    if (e.value == '1' || e.value == '2') {
+      if (!data) {
+        fields.value.splice(2, 0, { label: '选项', model: 'selects', custom: true });
+      }
+    } else if (e.value == '3') {
+      if (data) {
+        fields.value = fields.value.filter((i) => i.model != 'selects');
+      }
+    }
+  }
+};
+// 添加
+const seAdd = () => {
+  form.value.selects.push({ id: moment().valueOf(), label: '', value: '', sort: '' });
+};
+// 删除
+const seDel = (data) => {
+  form.value.selects = form.value.selects.filter((i) => i.id != data.id);
+};
+// 刷新排序
+const seSort = () => {
+  let selects = _.sortBy(form.value.selects, ['sort']);
+  form.value.selects = selects;
+};
+// 提交
+const toSave = async (data) => {
+  let res: IQueryResult;
+  if (data._id) res = await qquesAxios.update(data);
+  else res = await qquesAxios.create(data);
+  if (res.errcode == 0) {
+    ElMessage({ type: `success`, message: `维护信息成功` });
+    toBack();
+  }
+};
+// 返回上一页
+const toBack = () => {
+  window.history.go(-1);
+};
+const searchOther = async () => {
+  let res: IQueryResult;
+  // 类型
+  res = await dictAxios.query({ type: 'wenjuan-question-type' });
+  if (res.errcode == '0') {
+    typeList.value = res.data;
+  }
+  // 是否启用
+  res = await dictAxios.query({ type: 'common_use' });
+  if (res.errcode == '0') {
+    is_useList.value = res.data;
+  }
+};
+</script>
+<style scoped lang="scss">
+.selects {
+  .selects_1 {
+    margin: 0 0 10px 0;
+  }
+}
+</style>

+ 112 - 15
src/views/question/index.vue

@@ -2,7 +2,22 @@
   <div id="index">
     <el-row>
       <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
-        <el-col :span="24" class="one">系统首页</el-col>
+        <el-col :span="24" class="one">
+          <cSearch :is_title="false" :is_search="true" :fields="fields" @search="toSearch">
+            <template #type>
+              <el-option v-for="(i, index) in typeList" :key="index" :label="i.label" :value="i.value"></el-option>
+            </template>
+            <template #is_use>
+              <el-option v-for="(i, index) in is_useList" :key="index" :label="i.label" :value="i.value"></el-option>
+            </template>
+          </cSearch>
+        </el-col>
+        <el-col :span="24" class="two">
+          <cButton @toAdd="toAdd()"></cButton>
+        </el-col>
+        <el-col :span="24" class="thr">
+          <cTable :fields="fields" :opera="opera" :list="list" @query="search" :total="total" @edit="toEdit" @del="toDel"> </cTable>
+        </el-col>
       </el-col>
     </el-row>
   </div>
@@ -11,28 +26,110 @@
 <script setup lang="ts">
 // 基础
 import type { Ref } from 'vue';
-// reactive,
 import { onMounted, ref, getCurrentInstance } from 'vue';
+import { useRouter } from 'vue-router';
+import { ElMessage } from 'element-plus';
 // 接口
-//import { TestStore } from '@common/src/stores/test';
-//import type { IQueryResult } from '@/util/types.util';
-//const testAxios = TestStore();
+import { QuestionStore } from '@common/src/stores/question/question'; //
+import { DictDataStore } from '@common/src/stores/system/dictData'; // 字典表
+import type { IQueryResult } from '@/util/types.util';
+const qquesAxios = QuestionStore();
+const dictAxios = DictDataStore();
+
 const { proxy } = getCurrentInstance() as any;
+
+// 路由
+const router = useRouter();
+
 // 加载中
 const loading: Ref<any> = ref(false);
-// 分页数据
-//  const skip = 0;
-//  const limit = proxy.limit;;
+const list: Ref<any> = ref([]);
+const total: Ref<any> = ref(0);
+const skip = 0;
+const limit = proxy.limit;
+const fields: Ref<any[]> = ref([
+  { label: '标题', model: 'title', isSearch: true },
+  { label: '类型', model: 'type', isSearch: true, format: (i) => getDict(i, 'type'), type: 'select' },
+  { label: '是否启用', model: 'is_use', isSearch: true, format: (i) => getDict(i, 'is_use'), type: 'select' }
+]);
+const opera: Ref<any[]> = ref([
+  { label: '修改', method: 'edit' },
+  { label: '删除', method: 'del', confirm: true, type: 'danger' }
+]);
+
+// 查询
+const searchInfo: Ref<any> = ref({});
+
+// 字典表
+const typeList: Ref<any> = ref([]);
+const is_useList: Ref<any> = ref([]);
+
 // 请求
 onMounted(async () => {
   loading.value = true;
-  //  await search({ skip, limit });
+  await searchOther();
+  await search({ skip, limit });
   loading.value = false;
 });
-//const search = async (e: { skip: number; limit: number }) => {
-//  const info = { skip: e.skip, limit: e.limit, ...searchInfo.value  };
-//  const res: IQueryResult = await testAxios.query(info);
-//  console.log(res);
-//};
+const search = async (e: { skip: number; limit: number }) => {
+  const info = { skip: e.skip, limit: e.limit, ...searchInfo.value };
+  const res: IQueryResult = await qquesAxios.query(info);
+  if (res.errcode == '0') {
+    list.value = res.data;
+    total.value = res.total;
+  }
+};
+const toSearch = (query) => {
+  searchInfo.value = query;
+  search({ skip, limit });
+};
+const getDict = (e, model) => {
+  if (model == 'type') {
+    let data: any = typeList.value.find((i: any) => i.value == e);
+    if (data) return data.label;
+    else return '暂无';
+  } else if (model == 'is_use') {
+    let data: any = is_useList.value.find((i: any) => i.value == e);
+    if (data) return data.label;
+    else return '暂无';
+  }
+};
+
+// 新增
+const toAdd = () => {
+  router.push({ path: '/question/detail' });
+};
+// 修改
+const toEdit = async (data) => {
+  router.push({ path: '/question/detail', query: { id: data._id } });
+};
+
+// 删除
+const toDel = async (data) => {
+  let res: IQueryResult = await qquesAxios.del(data._id);
+  if (res.errcode == 0) {
+    ElMessage({ type: `success`, message: `刪除信息成功` });
+    search({ skip, limit });
+  }
+};
+const searchOther = async () => {
+  let res: IQueryResult;
+  // 类型
+  res = await dictAxios.query({ type: 'wenjuan-question-type' });
+  if (res.errcode == '0') {
+    typeList.value = res.data;
+  }
+  // 是否启用
+  res = await dictAxios.query({ type: 'common_use' });
+  if (res.errcode == '0') {
+    is_useList.value = res.data;
+  }
+};
 </script>
-<style scoped lang="scss"></style>
+<style scoped lang="scss">
+.main {
+  .two {
+    margin: 0 0 10px 0;
+  }
+}
+</style>

+ 104 - 0
src/views/questionnaire/detail.vue

@@ -0,0 +1,104 @@
+<template>
+  <div id="detail">
+    <el-row>
+      <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
+        <el-col :span="24" class="one">
+          <cSearch :is_title="false" :is_back="true" @toBack="toBack"></cSearch>
+        </el-col>
+        <el-col :span="24" class="two">
+          <cForm :span="24" :fields="fields" :form="form" :rules="rules" @save="toSave">
+            <template #type>
+              <el-option v-for="(i, index) in typeList" :key="index" :label="i.label" :value="i.value"></el-option>
+            </template>
+            <template #is_use>
+              <el-option v-for="(i, index) in is_useList" :key="index" :label="i.label" :value="i.value"></el-option>
+            </template>
+          </cForm>
+        </el-col>
+      </el-col>
+    </el-row>
+  </div>
+</template>
+
+<script setup lang="ts">
+import type { Ref } from 'vue';
+import { ref, reactive, onMounted } from 'vue';
+import { useRoute } from 'vue-router';
+import { ElMessage } from 'element-plus';
+import type { FormRules } from 'element-plus';
+
+// 接口
+import { QuestionnaireStore } from '@common/src/stores/question/questionnaire'; //
+import { DictDataStore } from '@common/src/stores/system/dictData'; // 字典表
+import type { IQueryResult } from '@/util/types.util';
+const qnaireAxios = QuestionnaireStore();
+const dictAxios = DictDataStore();
+
+// 路由
+const route = useRoute();
+
+// 加载中
+const loading = ref(false);
+// 表单
+let form: Ref<any> = ref({});
+let fields: Ref<any[]> = ref([
+  { label: '类型', model: 'type', type: 'select' },
+  { label: '标题', model: 'title' },
+  { label: '发布时间', model: 'create_date', type: 'date' },
+  { label: '简介', model: 'brief', type: 'textarea' },
+  { label: '是否启用', model: 'is_use', type: 'select' }
+]);
+const rules = reactive<FormRules>({});
+
+// 字典表
+const typeList: Ref<any> = ref([]);
+const is_useList: Ref<any> = ref([]);
+
+onMounted(async () => {
+  loading.value = true;
+  await searchOther();
+  await search();
+  loading.value = false;
+});
+const search = async () => {
+  let id = route.query.id;
+  let res: IQueryResult;
+  let info: any = {};
+  if (id) {
+    res = await aexpertAxios.fetch(route.query.id);
+    if (res.errcode == 0) {
+      info = res.data;
+    }
+  }
+  form.value = info;
+};
+
+// 提交
+const toSave = async (data) => {
+  let res: IQueryResult;
+  if (data._id) res = await qnaireAxios.update(data);
+  else res = await qnaireAxios.create(data);
+  if (res.errcode == 0) {
+    ElMessage({ type: `success`, message: `维护信息成功` });
+    toBack();
+  }
+};
+// 返回上一页
+const toBack = () => {
+  window.history.go(-1);
+};
+const searchOther = async () => {
+  let res: IQueryResult;
+  // 类型
+  res = await dictAxios.query({ type: 'wenjuan-questionnaire-type' });
+  if (res.errcode == '0') {
+    typeList.value = res.data;
+  }
+  // 是否启用
+  res = await dictAxios.query({ type: 'common_use' });
+  if (res.errcode == '0') {
+    is_useList.value = res.data;
+  }
+};
+</script>
+<style scoped lang="scss"></style>

+ 119 - 15
src/views/questionnaire/index.vue

@@ -2,7 +2,22 @@
   <div id="index">
     <el-row>
       <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
-        <el-col :span="24" class="one">系统首页</el-col>
+        <el-col :span="24" class="one">
+          <cSearch :is_title="false" :is_search="true" :fields="fields" @search="toSearch">
+            <template #type>
+              <el-option v-for="(i, index) in typeList" :key="index" :label="i.label" :value="i.value"></el-option>
+            </template>
+            <template #is_use>
+              <el-option v-for="(i, index) in is_useList" :key="index" :label="i.label" :value="i.value"></el-option>
+            </template>
+          </cSearch>
+        </el-col>
+        <el-col :span="24" class="two">
+          <cButton @toAdd="toAdd()"></cButton>
+        </el-col>
+        <el-col :span="24" class="thr">
+          <cTable :fields="fields" :opera="opera" :list="list" @query="search" :total="total" @edit="toEdit" @del="toDel" @ques="toQues"> </cTable>
+        </el-col>
       </el-col>
     </el-row>
   </div>
@@ -11,28 +26,117 @@
 <script setup lang="ts">
 // 基础
 import type { Ref } from 'vue';
-// reactive,
 import { onMounted, ref, getCurrentInstance } from 'vue';
+import { useRouter } from 'vue-router';
+import { ElMessage } from 'element-plus';
 // 接口
-//import { TestStore } from '@common/src/stores/test';
-//import type { IQueryResult } from '@/util/types.util';
-//const testAxios = TestStore();
+import { QuestionnaireStore } from '@common/src/stores/question/questionnaire'; //
+import { DictDataStore } from '@common/src/stores/system/dictData'; // 字典表
+import type { IQueryResult } from '@/util/types.util';
+const qnaireAxios = QuestionnaireStore();
+const dictAxios = DictDataStore();
+
 const { proxy } = getCurrentInstance() as any;
+
+// 路由
+const router = useRouter();
+
 // 加载中
 const loading: Ref<any> = ref(false);
-// 分页数据
-//  const skip = 0;
-//  const limit = proxy.limit;;
+const list: Ref<any> = ref([]);
+const total: Ref<any> = ref(0);
+const skip = 0;
+const limit = proxy.limit;
+const fields: Ref<any[]> = ref([
+  { label: '类型', model: 'type', isSearch: true, format: (i) => getDict(i, 'type'), type: 'select' },
+  { label: '标题', model: 'title', isSearch: true },
+  { label: '发布时间', model: 'create_date' },
+  { label: '简介', model: 'brief' },
+  { label: '是否启用', model: 'is_use', isSearch: true, format: (i) => getDict(i, 'is_use'), type: 'select' }
+]);
+const opera: Ref<any[]> = ref([
+  { label: '修改', method: 'edit' },
+  { label: '删除', method: 'del', confirm: true, type: 'danger' },
+  { label: '问卷题库', method: 'ques' }
+]);
+
+// 查询
+const searchInfo: Ref<any> = ref({});
+
+// 字典表
+const typeList: Ref<any> = ref([]);
+const is_useList: Ref<any> = ref([]);
+
 // 请求
 onMounted(async () => {
   loading.value = true;
-  //  await search({ skip, limit });
+  await searchOther();
+  await search({ skip, limit });
   loading.value = false;
 });
-//const search = async (e: { skip: number; limit: number }) => {
-//  const info = { skip: e.skip, limit: e.limit, ...searchInfo.value  };
-//  const res: IQueryResult = await testAxios.query(info);
-//  console.log(res);
-//};
+const search = async (e: { skip: number; limit: number }) => {
+  const info = { skip: e.skip, limit: e.limit, ...searchInfo.value };
+  const res: IQueryResult = await qnaireAxios.query(info);
+  if (res.errcode == '0') {
+    list.value = res.data;
+    total.value = res.total;
+  }
+};
+const toSearch = (query) => {
+  searchInfo.value = query;
+  search({ skip, limit });
+};
+const getDict = (e, model) => {
+  if (model == 'type') {
+    let data: any = typeList.value.find((i: any) => i.value == e);
+    if (data) return data.label;
+    else return '暂无';
+  } else if (model == 'is_use') {
+    let data: any = is_useList.value.find((i: any) => i.value == e);
+    if (data) return data.label;
+    else return '暂无';
+  }
+};
+
+// 新增
+const toAdd = () => {
+  router.push({ path: '/questionnaire/detail' });
+};
+// 修改
+const toEdit = async (data) => {
+  router.push({ path: '/questionnaire/detail', query: { id: data._id } });
+};
+// 问卷题库
+const toQues = (data) => {
+  router.push({ path: '/questionnaire/questions', query: { id: data._id } });
+};
+
+// 删除
+const toDel = async (data) => {
+  let res: IQueryResult = await qnaireAxios.del(data._id);
+  if (res.errcode == 0) {
+    ElMessage({ type: `success`, message: `刪除信息成功` });
+    search({ skip, limit });
+  }
+};
+const searchOther = async () => {
+  let res: IQueryResult;
+  // 类型
+  res = await dictAxios.query({ type: 'wenjuan-questionnaire-type' });
+  if (res.errcode == '0') {
+    typeList.value = res.data;
+  }
+  // 是否启用
+  res = await dictAxios.query({ type: 'common_use' });
+  if (res.errcode == '0') {
+    is_useList.value = res.data;
+  }
+};
 </script>
-<style scoped lang="scss"></style>
+<style scoped lang="scss">
+.main {
+  .two {
+    margin: 0 0 10px 0;
+  }
+}
+</style>

+ 38 - 0
src/views/questionnaire/questions.vue

@@ -0,0 +1,38 @@
+<template>
+  <div id="questions">
+    <el-row>
+      <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
+        <el-col :span="24" class="one">系统首页</el-col>
+      </el-col>
+    </el-row>
+  </div>
+</template>
+
+<script setup lang="ts">
+// 基础
+import type { Ref } from 'vue';
+// reactive,
+import { onMounted, ref, getCurrentInstance } from 'vue';
+// 接口
+//import { TestStore } from '@common/src/stores/test';
+//import type { IQueryResult } from '@/util/types.util';
+//const testAxios = TestStore();
+const { proxy } = getCurrentInstance() as any;
+// 加载中
+const loading: Ref<any> = ref(false);
+// 分页数据
+//  const skip = 0;
+//  const limit = proxy.limit;;
+// 请求
+onMounted(async () => {
+  loading.value = true;
+  //  await search({ skip, limit });
+  loading.value = false;
+});
+//const search = async (e: { skip: number; limit: number }) => {
+//  const info = { skip: e.skip, limit: e.limit, ...searchInfo.value  };
+//  const res: IQueryResult = await testAxios.query(info);
+//  console.log(res);
+//};
+</script>
+<style scoped lang="scss"></style>