@zykjcommon/questions 0.0.30 → 0.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zykjcommon/questions",
3
- "version": "0.0.30",
3
+ "version": "0.0.32",
4
4
  "main": "src/components/questions/entry.js",
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -10,7 +10,7 @@
10
10
  </div>
11
11
  <div class="main-content">
12
12
  <div class="main-append">
13
- <!-- <div class="append-item"></div>-->
13
+ <!-- <div class="append-item"></div>-->
14
14
  </div>
15
15
  </div>
16
16
  </div>
@@ -74,8 +74,10 @@ export default {
74
74
  this.unmountedDo()
75
75
  },
76
76
  mounted() {
77
- this.setRootFontSize()
78
- window.addEventListener('resize',this.setRootFontSize)
77
+ this.intervalFindEl().then(()=>{
78
+ this.setRootFontSize()
79
+ window.addEventListener('resize',this.setRootFontSize)
80
+ })
79
81
  this.init()
80
82
  this.$watch('optionList',(nv)=>{
81
83
  if(nv && nv.length){
@@ -167,6 +169,20 @@ export default {
167
169
  let correct = this.questionInfo.answerMap.is_correct === '1' ? true : false
168
170
  return correct
169
171
  },
172
+ intervalFindEl(){
173
+ return new Promise((resolve,reject)=>{
174
+ if(this.$el){
175
+ resolve()
176
+ }else{
177
+ let interval = setInterval(()=>{
178
+ if(this.$el){
179
+ clearInterval(interval)
180
+ resolve()
181
+ }
182
+ },50)
183
+ }
184
+ })
185
+ },
170
186
  parseLists(nv){
171
187
  this.classify_question_info = nv.classify_question_info
172
188
  let exam_options_data = nv.exam_options_data
@@ -13,6 +13,103 @@ import Question_Classify from './Question_Classify.vue'
13
13
  import {questionMapper} from "./const";
14
14
  import fun from "../../assets/js/fun";
15
15
  import storeOptions from './store'
16
+ let parseQuestionListItem = function(mode,question_list,answer_map,parentIndex = undefined){
17
+ function parseContent(arr,contentWidth){
18
+ arr.forEach((item)=>{
19
+ if(item['<>'] === 'img'){
20
+ if(item.hasOwnProperty('width')){
21
+ let width = Number(item.width)
22
+ if(width > contentWidth){
23
+ item.width = Math.floor(contentWidth)
24
+ item.height && delete item.height
25
+ }
26
+ }
27
+ }
28
+ if(item.html && item.html.length){
29
+ parseContent(item.html,contentWidth)
30
+ }
31
+ })
32
+ }
33
+ question_list.forEach((item,index)=>{
34
+ item.questionComponent = questionMapper[item.question_type]
35
+ // item.questionIndex = index + 1
36
+ if(parentIndex === undefined){
37
+ item.questionIndex = index + 1
38
+ }else{
39
+ item.questionIndex = (parentIndex + 1) + '-' + (index + 1)
40
+ item.questionIndex2 = index + 1
41
+ }
42
+ if(answer_map && answer_map.hasOwnProperty(item.question_id)){
43
+ item.answerMap = answer_map[item.question_id]
44
+ if(mode === 'analysis'){
45
+ //analysis页面特殊处理
46
+ if(item.answerMap.user_coding_file){
47
+ item.answerMap.oss_temp_url = item.answerMap.user_coding_file
48
+ }
49
+ //analysis页面特殊处理score字段为 answerMap.question_max_score
50
+ item.score = item.answerMap.question_max_score
51
+ //预览接口学生答案以user_开头,为适配考试的学生答案,做处理
52
+ let answerMapKeys = Object.keys(item.answerMap)
53
+ let reg = /^user_/ig
54
+ answerMapKeys.forEach((answerMapKeysItem)=>{
55
+ if(reg.test(answerMapKeysItem)){
56
+ let newProp = answerMapKeysItem.replace(reg,'')
57
+ item.answerMap[newProp] = item.answerMap[answerMapKeysItem]
58
+ }
59
+ })
60
+ }
61
+ }else{
62
+ item.answerMap = null
63
+ }
64
+ let question_type = item.question_type
65
+ if(question_type == 3){
66
+ //判断题手动构造选项数组
67
+ item.exam_options_data = [
68
+ {
69
+ index:1,data:{
70
+ name:'正确'
71
+ }
72
+ },
73
+ {
74
+ index:2,data:{
75
+ name:'错误'
76
+ }
77
+ }
78
+ ]
79
+ }else{
80
+ if(item.exam_options_data && item.exam_options_data.length){
81
+ item.exam_options_data.forEach((subItem,subIndex)=>{
82
+ subItem.enIndex = fun.indexToEnIndex(subIndex+1)
83
+ })
84
+ }
85
+ }
86
+ //转化content富文本
87
+ try{
88
+
89
+ let contentArr = JSON.parse(item.content)
90
+ let contentWidth = jQuery('.question-list').width() - 30
91
+ //图片宽度超出框架的时候把宽度设置成框架大小
92
+ parseContent(contentArr,contentWidth)
93
+ item.htmlContent = $.json2html({}, contentArr);
94
+ }catch(e){
95
+ item.htmlContent = item.content
96
+ }
97
+ //转化analysis富文本
98
+ try{
99
+ if(item.analysis){
100
+ item.analysisHtmlContent = $.json2html({}, JSON.parse(item.analysis));
101
+ }else{
102
+ item.analysisHtmlContent = ''
103
+ }
104
+ }catch(e){
105
+ item.analysisHtmlContent = item.analysis
106
+ }
107
+ //如果是阅读题要递归解析
108
+ if(item.sub_questions && item.sub_questions.length){
109
+ this.parseQuestionListItem(mode,item.sub_questions,answer_map,index)
110
+ }
111
+ })
112
+ }
16
113
  export default function(store){
17
114
  //动态注册store
18
115
  store.registerModule('zykjcommonQuestions',storeOptions)
@@ -22,103 +119,7 @@ export default function(store){
22
119
  Vue.mixin({
23
120
  methods: {
24
121
  //公共解析questionItem方法
25
- parseQuestionListItem(mode,question_list,answer_map,parentIndex = undefined){
26
- function parseContent(arr,contentWidth){
27
- arr.forEach((item)=>{
28
- if(item['<>'] === 'img'){
29
- if(item.hasOwnProperty('width')){
30
- let width = Number(item.width)
31
- if(width > contentWidth){
32
- item.width = Math.floor(contentWidth)
33
- item.height && delete item.height
34
- }
35
- }
36
- }
37
- if(item.html && item.html.length){
38
- parseContent(item.html,contentWidth)
39
- }
40
- })
41
- }
42
- question_list.forEach((item,index)=>{
43
- item.questionComponent = questionMapper[item.question_type]
44
- // item.questionIndex = index + 1
45
- if(parentIndex === undefined){
46
- item.questionIndex = index + 1
47
- }else{
48
- item.questionIndex = (parentIndex + 1) + '-' + (index + 1)
49
- item.questionIndex2 = index + 1
50
- }
51
- if(answer_map && answer_map.hasOwnProperty(item.question_id)){
52
- item.answerMap = answer_map[item.question_id]
53
- if(mode === 'analysis'){
54
- //analysis页面特殊处理
55
- if(item.answerMap.user_coding_file){
56
- item.answerMap.oss_temp_url = item.answerMap.user_coding_file
57
- }
58
- //analysis页面特殊处理score字段为 answerMap.question_max_score
59
- item.score = item.answerMap.question_max_score
60
- //预览接口学生答案以user_开头,为适配考试的学生答案,做处理
61
- let answerMapKeys = Object.keys(item.answerMap)
62
- let reg = /^user_/ig
63
- answerMapKeys.forEach((answerMapKeysItem)=>{
64
- if(reg.test(answerMapKeysItem)){
65
- let newProp = answerMapKeysItem.replace(reg,'')
66
- item.answerMap[newProp] = item.answerMap[answerMapKeysItem]
67
- }
68
- })
69
- }
70
- }else{
71
- item.answerMap = null
72
- }
73
- let question_type = item.question_type
74
- if(question_type == 3){
75
- //判断题手动构造选项数组
76
- item.exam_options_data = [
77
- {
78
- index:1,data:{
79
- name:'正确'
80
- }
81
- },
82
- {
83
- index:2,data:{
84
- name:'错误'
85
- }
86
- }
87
- ]
88
- }else{
89
- if(item.exam_options_data && item.exam_options_data.length){
90
- item.exam_options_data.forEach((subItem,subIndex)=>{
91
- subItem.enIndex = fun.indexToEnIndex(subIndex+1)
92
- })
93
- }
94
- }
95
- //转化content富文本
96
- try{
97
-
98
- let contentArr = JSON.parse(item.content)
99
- let contentWidth = jQuery('.question-list').width() - 30
100
- //图片宽度超出框架的时候把宽度设置成框架大小
101
- parseContent(contentArr,contentWidth)
102
- item.htmlContent = $.json2html({}, contentArr);
103
- }catch(e){
104
- item.htmlContent = item.content
105
- }
106
- //转化analysis富文本
107
- try{
108
- if(item.analysis){
109
- item.analysisHtmlContent = $.json2html({}, JSON.parse(item.analysis));
110
- }else{
111
- item.analysisHtmlContent = ''
112
- }
113
- }catch(e){
114
- item.analysisHtmlContent = item.analysis
115
- }
116
- //如果是阅读题要递归解析
117
- if(item.sub_questions && item.sub_questions.length){
118
- this.parseQuestionListItem(mode,item.sub_questions,answer_map,index)
119
- }
120
- })
121
- }
122
+ parseQuestionListItem
122
123
  }
123
124
  })
124
125
  Vue.component('Question_SingleChoice',Question_SingleChoice)
@@ -129,6 +130,7 @@ export default function(store){
129
130
  Vue.component('Question_Programming',Question_Programming)
130
131
  Vue.component('Question_Classify',Question_Classify)
131
132
  },
133
+ parseQuestionListItem,
132
134
  questionMapper,
133
135
  Question_SingleChoice,
134
136
  Question_MultipleChoice,
@@ -12,6 +12,103 @@ import Question_Classify from './Question_Classify.vue'
12
12
  import {questionMapper} from "./const";
13
13
  import fun from "../../assets/js/fun";
14
14
  import storeOptions from './store'
15
+ let parseQuestionListItem = function(mode,question_list,answer_map,parentIndex = undefined){
16
+ function parseContent(arr,contentWidth){
17
+ arr.forEach((item)=>{
18
+ if(item['<>'] === 'img'){
19
+ if(item.hasOwnProperty('width')){
20
+ let width = Number(item.width)
21
+ if(width > contentWidth){
22
+ item.width = Math.floor(contentWidth)
23
+ item.height && delete item.height
24
+ }
25
+ }
26
+ }
27
+ if(item.html && item.html.length){
28
+ parseContent(item.html,contentWidth)
29
+ }
30
+ })
31
+ }
32
+ question_list.forEach((item,index)=>{
33
+ item.questionComponent = questionMapper[item.question_type]
34
+ // item.questionIndex = index + 1
35
+ if(parentIndex === undefined){
36
+ item.questionIndex = index + 1
37
+ }else{
38
+ item.questionIndex = (parentIndex + 1) + '-' + (index + 1)
39
+ item.questionIndex2 = index + 1
40
+ }
41
+ if(answer_map && answer_map.hasOwnProperty(item.question_id)){
42
+ item.answerMap = answer_map[item.question_id]
43
+ if(mode === 'analysis'){
44
+ //analysis页面特殊处理
45
+ if(item.answerMap.user_coding_file){
46
+ item.answerMap.oss_temp_url = item.answerMap.user_coding_file
47
+ }
48
+ //analysis页面特殊处理score字段为 answerMap.question_max_score
49
+ item.score = item.answerMap.question_max_score
50
+ //预览接口学生答案以user_开头,为适配考试的学生答案,做处理
51
+ let answerMapKeys = Object.keys(item.answerMap)
52
+ let reg = /^user_/ig
53
+ answerMapKeys.forEach((answerMapKeysItem)=>{
54
+ if(reg.test(answerMapKeysItem)){
55
+ let newProp = answerMapKeysItem.replace(reg,'')
56
+ item.answerMap[newProp] = item.answerMap[answerMapKeysItem]
57
+ }
58
+ })
59
+ }
60
+ }else{
61
+ item.answerMap = null
62
+ }
63
+ let question_type = item.question_type
64
+ if(question_type == 3){
65
+ //判断题手动构造选项数组
66
+ item.exam_options_data = [
67
+ {
68
+ index:1,data:{
69
+ name:'正确'
70
+ }
71
+ },
72
+ {
73
+ index:2,data:{
74
+ name:'错误'
75
+ }
76
+ }
77
+ ]
78
+ }else{
79
+ if(item.exam_options_data && item.exam_options_data.length){
80
+ item.exam_options_data.forEach((subItem,subIndex)=>{
81
+ subItem.enIndex = fun.indexToEnIndex(subIndex+1)
82
+ })
83
+ }
84
+ }
85
+ //转化content富文本
86
+ try{
87
+
88
+ let contentArr = JSON.parse(item.content)
89
+ let contentWidth = jQuery('.question-list').width() - 30
90
+ //图片宽度超出框架的时候把宽度设置成框架大小
91
+ parseContent(contentArr,contentWidth)
92
+ item.htmlContent = $.json2html({}, contentArr);
93
+ }catch(e){
94
+ item.htmlContent = item.content
95
+ }
96
+ //转化analysis富文本
97
+ try{
98
+ if(item.analysis){
99
+ item.analysisHtmlContent = $.json2html({}, JSON.parse(item.analysis));
100
+ }else{
101
+ item.analysisHtmlContent = ''
102
+ }
103
+ }catch(e){
104
+ item.analysisHtmlContent = item.analysis
105
+ }
106
+ //如果是阅读题要递归解析
107
+ if(item.sub_questions && item.sub_questions.length){
108
+ this.parseQuestionListItem(mode,item.sub_questions,answer_map,index)
109
+ }
110
+ })
111
+ }
15
112
  export default function(store){
16
113
  //动态注册store
17
114
  store.registerModule('zykjcommonQuestions',storeOptions)
@@ -21,103 +118,7 @@ export default function(store){
21
118
  Vue.mixin({
22
119
  methods: {
23
120
  //公共解析questionItem方法
24
- parseQuestionListItem(mode,question_list,answer_map,parentIndex = undefined){
25
- function parseContent(arr,contentWidth){
26
- arr.forEach((item)=>{
27
- if(item['<>'] === 'img'){
28
- if(item.hasOwnProperty('width')){
29
- let width = Number(item.width)
30
- if(width > contentWidth){
31
- item.width = Math.floor(contentWidth)
32
- item.height && delete item.height
33
- }
34
- }
35
- }
36
- if(item.html && item.html.length){
37
- parseContent(item.html,contentWidth)
38
- }
39
- })
40
- }
41
- question_list.forEach((item,index)=>{
42
- item.questionComponent = questionMapper[item.question_type]
43
- // item.questionIndex = index + 1
44
- if(parentIndex === undefined){
45
- item.questionIndex = index + 1
46
- }else{
47
- item.questionIndex = (parentIndex + 1) + '-' + (index + 1)
48
- item.questionIndex2 = index + 1
49
- }
50
- if(answer_map && answer_map.hasOwnProperty(item.question_id)){
51
- item.answerMap = answer_map[item.question_id]
52
- if(mode === 'analysis'){
53
- //analysis页面特殊处理
54
- if(item.answerMap.user_coding_file){
55
- item.answerMap.oss_temp_url = item.answerMap.user_coding_file
56
- }
57
- //analysis页面特殊处理score字段为 answerMap.question_max_score
58
- item.score = item.answerMap.question_max_score
59
- //预览接口学生答案以user_开头,为适配考试的学生答案,做处理
60
- let answerMapKeys = Object.keys(item.answerMap)
61
- let reg = /^user_/ig
62
- answerMapKeys.forEach((answerMapKeysItem)=>{
63
- if(reg.test(answerMapKeysItem)){
64
- let newProp = answerMapKeysItem.replace(reg,'')
65
- item.answerMap[newProp] = item.answerMap[answerMapKeysItem]
66
- }
67
- })
68
- }
69
- }else{
70
- item.answerMap = null
71
- }
72
- let question_type = item.question_type
73
- if(question_type == 3){
74
- //判断题手动构造选项数组
75
- item.exam_options_data = [
76
- {
77
- index:1,data:{
78
- name:'正确'
79
- }
80
- },
81
- {
82
- index:2,data:{
83
- name:'错误'
84
- }
85
- }
86
- ]
87
- }else{
88
- if(item.exam_options_data && item.exam_options_data.length){
89
- item.exam_options_data.forEach((subItem,subIndex)=>{
90
- subItem.enIndex = fun.indexToEnIndex(subIndex+1)
91
- })
92
- }
93
- }
94
- //转化content富文本
95
- try{
96
-
97
- let contentArr = JSON.parse(item.content)
98
- let contentWidth = jQuery('.question-list').width() - 30
99
- //图片宽度超出框架的时候把宽度设置成框架大小
100
- parseContent(contentArr,contentWidth)
101
- item.htmlContent = $.json2html({}, contentArr);
102
- }catch(e){
103
- item.htmlContent = item.content
104
- }
105
- //转化analysis富文本
106
- try{
107
- if(item.analysis){
108
- item.analysisHtmlContent = $.json2html({}, JSON.parse(item.analysis));
109
- }else{
110
- item.analysisHtmlContent = ''
111
- }
112
- }catch(e){
113
- item.analysisHtmlContent = item.analysis
114
- }
115
- //如果是阅读题要递归解析
116
- if(item.sub_questions && item.sub_questions.length){
117
- this.parseQuestionListItem(mode,item.sub_questions,answer_map,index)
118
- }
119
- })
120
- }
121
+ parseQuestionListItem
121
122
  }
122
123
  })
123
124
  Vue.component('Question_SingleChoice',Question_SingleChoice)
@@ -128,6 +129,7 @@ export default function(store){
128
129
  Vue.component('Question_Programming',Question_Programming)
129
130
  Vue.component('Question_Classify',Question_Classify)
130
131
  },
132
+ parseQuestionListItem,
131
133
  questionMapper,
132
134
  Question_SingleChoice,
133
135
  Question_MultipleChoice,