china
2023-05-11 c7bc3eb18e1fda4254ca0195e2133d2ed978de11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
<template>
  <div class="app-container">
    <el-aside class="sidebar-box" style="padding: 0;">
      <div class="sidebar">
        <el-card class="box-card" shadow="never">
          <div slot="header" class="clearfix">
            <span>
              <svg-icon icon-class="nested" style="margin-top: -2px;" />题库分类
            </span>
            <el-button style="float: right; padding: 3px 0" type="text" @click="expandedAll">收起</el-button>
          </div>
          <el-input v-model="filterText" clearable placeholder="关键字过滤" />
          <el-tree ref="treeRef" :data="treeData" :default-expanded-keys="defaultExpandedKeys" :filter-node-method="filterNode" :props="defaultProps" highlight-current node-key="id" @node-click="handleNodeClick" />
        </el-card>
      </div>
    </el-aside>
 
    <div class="flex-1">
      <el-card shadow="never" class="box-card filter-card">
        <!--搜索条件-->
        <div class="filter-container">
          <el-form :inline="true" :model="filterForm" size="small">
            <el-form-item label="顶级单位">
              <el-select v-model="filterForm.orgId" placeholder="选择顶级单位" @change="search(1)">
                <el-option
                  v-for="org in this.rootOrgList" :key="org.id" :label="org.dept_name" :value="org.id"/>
              </el-select>
            </el-form-item>
            <el-form-item label="试题类型">
              <el-select v-model="filterForm.questionType" placeholder="试题类型">
                <el-option v-for="d in this.questionTypeList" :key="d.key" :label="d.value" :value="d.key"/>
              </el-select>
            </el-form-item>
            <el-form-item label="试题题目">
              <el-input v-model="filterForm.content" placeholder="试题内容" clearable/>
            </el-form-item>
            <el-form-item>
              <my-button-v2 site="filter" name="搜索" @click="search(1)" />
              <my-button-v2 site="filter" name="重置" @click="reset()" />
            </el-form-item>
          </el-form>
        </div>
      </el-card>
 
      <!--列表-->
      <my-table-v3 ref="myTable" :filter="filterForm" :table="table" />
    </div>
    <!--添加/编辑弹窗-->
    <add v-if="editSetting.show" :setting="editSetting" @search="search()" @close="editSetting.show=false"/>
    <!-- 导入窗口-->
    <my-import :import-setting="importSetting" :dialog-show="importSetting.dialogShow" :dialog-title="importSetting.dialogTitle"/>
  </div>
</template>
 
<script>
  import { getToken } from '@/utils/auth'
  import {listOrgRoot} from '@/api/system/dept'
  import {clear, listCatalogTreeList, listQuestionType} from '@/api/etaa/question_bank'
  import myTableV3 from '@/views/components/myTableV3';
  import myButtonV2 from '@/views/components/myButtonV2'
  import myImport from '@/views/components/myImport'
  import {isEmptyValue} from "@/utils/StringUtils";
  import add from './add'
 
  export default {
    components: {myTableV3, myButtonV2, add, myImport},
  name: "questionBank",
  data() {
    return {
      /** 树配置*/
      defaultExpandedKeys: [1], // 默认展开的key
      filterText: '',
      treeData: [],
      /** 分类树数据结构 */
      defaultProps: {
        children: "children",
        label: "label"
      },
 
      /** 搜索条件*/
      filterForm: {
        orgId: null,
        questionType: null,
        content: null
      },
 
      table: {
        // size: "small",
        autoLoad: false,
        showIndex: false, // 是否显示序号
        expand: false, // 是否显示详情数据
        checkBox: false, // 是否显示复选框
        url: globalConf.baseUrl + '/etaa/question_bank/list', // 请求地址
        // 工具条
        tools: {
          columnsCtrl: {// 列控制按钮
            show: true
          },
          generalExport: {// 通用导出按钮
            show: false
          },
          custom: [ // 自定义工具条按钮
            {
              name: '添加试题',
              // checkPermission: 'system:config:remove',
              myType: 'danger',
              mySize: 'mini',
              click: ()=> {
                this.handleAdd();
              }
            },
            {
              name: '导入',
              click: ()=> {
                this.handleImport();
              }
            },
            {
              name: '清空题库',
              checkPermission: 'etaa:question_bank:clear',
              myType: 'info',
              mySize: 'mini',
              click: ()=> {
                this.handleClear();
              }
            }
          ]
        },
        columns: [
          { title: 'ID', field: 'id', align: 'left', width: 80 },
          { title: '归属', field: 'parameter.orgName', align: 'left', width: 130 },
          { title: '大类', field: 'parameter.rootCatalogName', align: 'left', width: 150 },
          { title: '子分类', field: 'parameter.majorCatalogName', align: 'left', width: 160},
          { title: '题目', field: 'content', align: 'left', width: 230 },
          { title: '题型', field: 'parameter.questionTypeName', align: 'left', width: 80 },
          { title: '创建人', field: 'createUserId', align: 'left', width: 80 },
          { title: '创建时间', field: 'parameter.createTimeName', align: 'left', width: 160 }
        ],
        // 操作信息
        operation: {
          show: true, // 显示操作列
          width: '100', // 列宽
          attr: [
            {
              title: '编辑',
              checkPermission: 'system:config:edit',
              events: row => {
                this.handleUpdate(row)
              }
            }
          ]
        },
        paging: {
          show: true, // 显示分页
          // 分页信息
          page: {
            small: false,
            pageNum: 1,
            pageSize: platformPageSize,
            total: 0
          }
        }
      },
 
      // 2022-12-30 根机构列表,个人只能列出自己所在根机构
      rootOrgList:[],
      // 2022-12-30 超级管理员选择的顶级机构ID
      selectedRootOrgId: undefined,
      // 试题类别列表,2023-03-11
      questionTypeList: [],
 
      // 添加&编辑窗口
      editSetting: {
        id: null,
        title: '',
        show: false
      },
 
      // 导入
      importSetting: {
        dialogTitle: '导入',
        dialogShow: false,
        fileSettings: {
          uploadUrl: globalConf.baseUrl + "/etaa/question_bank/select/import?Authorization=" + getToken(), // 上传地址
          accept: '.xlsx,.csv', // 格式
          type: 'text', // 回显形式
          loading: false // 导入效果
        },
        /* 模板下载 */
        templateSettings: {
          templateName: '题库导入模板.xlsx', // 名称
          templateUrl: globalConf.baseUrl + '/etaa/question_bank/select/downloadTemplate?Authorization=' + getToken() // 下载地址
        },
        onSuccess: null
      },
    };
  },
 
  created() {
    this.getRootOrgList();
    this.getQuestionTypeList();
  },
  methods: {
    // 树节点过滤
    filterNode(value, data) {
      if (!value) return true;
      console.log("value = " + value + ", data = " + data);
      return data.label.indexOf(value) !== -1;
    },
    // 树节点收起
    expandedAll() {
      const nodes = this.$refs.treeRef.store._getAllNodes()
      for (let i = 0; i < nodes.length; i++) {
        nodes[i].expanded = false
      }
      // 编辑页面
      // this.editSetting.orgId = null
      // this.editSetting.orgName = '无'
      this.reset()
    },
 
    // 重置
    reset() {
      this.filterForm = {
        orgId: this.selectedRootOrgId,
        questionType: null,
        content: null
      }
      this.search(1)
    },
 
    // 查询table列表
    search(pageNum) {
      if(isEmptyValue(this.filterForm.orgId)){
        return;
      } else {
        // console.log("-----------" + this.filterForm.orgId);
        if (pageNum != undefined) {
          this.$refs.myTable.search({ pageNum: pageNum })
        } else {
          this.$refs.myTable.search()
        }
      }
    },
 
    /** 获取试题类别集合 2023-03-11 */
    getQuestionTypeList(){
      listQuestionType().then(response => {
        // console.log(response.data);
        this.questionTypeList = response.data;
      });
    },
    /** 获取顶级机构列表选择框 2022-12-30 */
    getRootOrgList(){
      listOrgRoot().then(response => {
        this.rootOrgList = response.data;
        this.selectedRootOrgId = this.rootOrgList[0].id;
        this.filterForm.orgId = this.selectedRootOrgId;
      }).then(() => {
        this.listCatalogTree();
        this.search(1);
      }).catch(function() {
      });
    },
 
    // 试题类别树
    listCatalogTree(){
      listCatalogTreeList("question_root_catalog").then(response => {
        // console.log(response.data);
        this.treeData = response.data;
      });
    },
 
    // 节点单击事件
    handleNodeClick(data) {
      // 保持已展开的菜单刷新后依旧展开
      this.defaultExpandedKeys = [data.id];
      this.filterForm.catalogId = data.id;
      this.search(1);
    },
 
    /** 任务详细信息 */
    handleView(row) {
      // getJob(row.id).then(response => {
      //   this.form = response.data;
      //   this.openView = true;
      // });
    },
    /** 新增按钮操作 */
    handleAdd() {
      if(isEmptyValue(this.selectedRootOrgId)){
        this.$message.warning("请先选择一个顶级机构");
        return;
      }
      if(isEmptyValue(this.filterForm.catalogId)){
        this.$message.warning("请先选择题库分类");
        return;
      }
      this.editSetting.id = null;
      this.editSetting.title = "添加试题";
      this.editSetting.catalogId = this.filterForm.catalogId;
      this.editSetting.orgId = this.selectedRootOrgId;
      this.editSetting.show = true;
    },
 
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getJob(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改试题库";
      });
    },
 
    handleClear(){
      this.$modal.confirm('要清空题库吗?通常只有测试阶段需要使用!').then(function() {
        return clear();
      }).then(() => {
        this.search(1);
        this.$modal.msgSuccess("操作成功");
      }).catch(() => {});
    },
 
    handleImport(){
      this.importSetting.dialogShow = true
      this.importSetting.onSuccess = (response, callBack) => {
        console.log(response);
        if(response.code != 1){
          this.$message.error('导入失败' || response.msg);
          callBack();
          return;
        }
 
        if(isEmptyValue(response.data)){
          // 没有返回错误记录文件
          this.$message.success("导入成功");
          this.search();
          callBack();
          return;
        }
 
        this.$confirm("请查看导入错误,文件:" + response.data, '导入完成', {
          confirmButtonText: '确定',
          type: 'warning'
        }).then(() => {
          this.search()
        });
        // user.importUser(response.data[0]).then(response => {
        //   if (response.code === 10000) {
        //     this.importSetting.dialogShow = false
        //     if (response.data.errorInfo.length === 0) {
        //       this.$message.success(response.data.info)
        //       this.search()
        //     } else {
        //       const errorInfoList = response.data.errorInfo
        //       var errorInfo = errorInfoList.join('')
        //       this.$confirm(errorInfo, '提示', {
        //         confirmButtonText: '确定',
        //         type: 'warning'
        //       }).then(() => {
        //         this.search()
        //       })
        //     }
        //   } else {
        //     this.$message.error('导入失败' || response.description)
        //     this.search()
        //   }
        //   callBack()
        // })
      }
    },
 
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateJob(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addJob(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const jobIds = row.id || this.ids;
      this.$modal.confirm('是否确认删除编号为"' + jobIds + '"的数据项?').then(function() {
        return delJob(jobIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('monitor/job/export', {
        ...this.queryParams
      }, `job_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scope lang="scss">
  .info-main{
    min-height: calc( 100vh - 50px);
  }
  .flex-1{
    flex:1;
  }
</style>