|
@@ -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>
|