@zykjcommon/questions 0.0.16 → 0.0.18

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.16",
3
+ "version": "0.0.18",
4
4
  "main": "src/components/questions/entry.js",
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -12,7 +12,7 @@
12
12
  "build:lib": "vue-cli-service build --target lib src/components/questions/buildEntry.js --name zykjcommon-questions"
13
13
  },
14
14
  "dependencies": {
15
- "@zykjcommon/questions": "^0.0.14",
15
+ "@zykjcommon/questions": "^0.0.16",
16
16
  "alife-logger": "^1.8.30",
17
17
  "axios": "^0.26.0",
18
18
  "cookie": "^0.4.1",
@@ -37,6 +37,7 @@
37
37
  "@vue/compiler-sfc": "^3.0.0",
38
38
  "file-loader": "^6.2.0",
39
39
  "image-webpack-loader": "^8.1.0",
40
+ "mobile-detect": "^1.4.5",
40
41
  "postcss": "^8.4.6",
41
42
  "postcss-cssnext": "^3.1.0",
42
43
  "postcss-extend": "^1.0.5",
@@ -4,7 +4,7 @@
4
4
  // import {postWeb} from "./http.js";
5
5
  // import helper from "./helper";
6
6
  import Vue from "vue";
7
-
7
+ let MobileDetect = require('mobile-detect')
8
8
  /**
9
9
  * 字典排序
10
10
  * @param <Object> dict
@@ -863,7 +863,50 @@ function getVueVersion(){
863
863
  return version
864
864
  }
865
865
 
866
+
867
+ function getDeviceEnv(){
868
+ function isIpad() {
869
+ var ua = window.navigator.userAgent
870
+ var IsIPad = false
871
+ if (/ipad/i.test(ua)) {
872
+ IsIPad = true
873
+ }
874
+ // iPad from IOS13
875
+ var macApp = ua.match(/Macintosh/i) != null
876
+ if (macApp) {
877
+ // need to distinguish between Macbook and iPad
878
+ var canvas = document.createElement('canvas')
879
+ if (canvas != null) {
880
+ var context =
881
+ canvas.getContext('webgl') || canvas.getContext('experimental-webgl')
882
+ if (context) {
883
+ var info = context.getExtension('WEBGL_debug_renderer_info')
884
+ if (info) {
885
+ var renderer = context.getParameter(info.UNMASKED_RENDERER_WEBGL)
886
+ if (renderer.indexOf('Apple') != -1) IsIPad = true
887
+ }
888
+ }
889
+ }
890
+ }
891
+ return IsIPad
892
+ }
893
+ let env = ''
894
+ let md= new MobileDetect(window.navigator.userAgent) //初始化mobile-detect
895
+ let os = md.os();//获取系统
896
+ if(os){
897
+ os = os.toLowerCase()
898
+ }
899
+ if(os === 'ios' || os === 'androidos' || isIpad()){
900
+ env = 'mobile'
901
+ }else{
902
+ env = 'pc'
903
+ }
904
+ return env
905
+ }
906
+
907
+
866
908
  export default {
909
+ getDeviceEnv,
867
910
  getVueVersion,
868
911
  getToken,
869
912
  getQueryVariable,
@@ -2,7 +2,7 @@
2
2
  * Created by Allen Liu on 2022/3/31.
3
3
  */
4
4
 
5
- export default function(){
5
+ export let setRem = function(){
6
6
  //动态设置html的font-size ----start
7
7
  let designWidth = 1440;
8
8
  let baseNum = 100;
@@ -30,4 +30,17 @@ export default function(){
30
30
  setRootFontSize();
31
31
  })
32
32
  //动态设置html的font-size ----end
33
+ }
34
+
35
+ export let setRemFixedHeight = function(designWidth=1440,repairH = 0,scale=1){
36
+ let baseNum = 100;
37
+ let winWidth = document.documentElement.clientWidth || document.body.clientWidth;
38
+ let winHeight = document.documentElement.clientHeight || document.body.clientHeight;
39
+ winHeight = winHeight - repairH
40
+ let html = document.getElementsByTagName('html')[0];
41
+ let frameBili = 4 / 3
42
+ let b = frameBili / (winWidth / winHeight)
43
+ let realW = parseInt(winWidth * b)
44
+ html.style.fontSize = (realW / designWidth) * baseNum * scale + 'px';
45
+ console.log(html.style.fontSize);
33
46
  }
@@ -1,3 +1,4 @@
1
+ $greenItemFontSize:0.14rem;
1
2
  .zykjcommon-question{
2
3
  .editor-content{
3
4
  margin-top: 10px;
@@ -66,12 +67,12 @@
66
67
  display: inline-block;
67
68
  width: 16px;
68
69
  height: 16px;
69
- background: url("~@src/assets/img/radio.png") no-repeat center;
70
+ background: url("../../img/radio.png") no-repeat center;
70
71
  background-size: 100% 100%;
71
72
  }
72
73
  &.checked{
73
74
  .radio-bg{
74
- background: url("~@src/assets/img/radio-cur.png") no-repeat center;
75
+ background: url("../../img/radio-cur.png") no-repeat center;
75
76
  background-size: 100% 100%;
76
77
  }
77
78
  }
@@ -90,12 +91,12 @@
90
91
  }
91
92
  .checkbox-bg{
92
93
  width: 16px;height: 16px;display: inline-block;
93
- background: url("~@src/assets/img/checkbox.png") no-repeat center;
94
+ background: url("../../img/checkbox.png") no-repeat center;
94
95
  background-size: 100% 100%;
95
96
  }
96
97
  &.checked{
97
98
  .checkbox-bg{
98
- background: url("~@src/assets/img/checkbox-cur.png") no-repeat center;
99
+ background: url("../../img/checkbox-cur.png") no-repeat center;
99
100
  background-size: 100% 100%;
100
101
  }
101
102
  }
@@ -286,7 +287,7 @@
286
287
  position: absolute;
287
288
  width: 20px;
288
289
  height: 20px;
289
- background:url("~@src/assets/img/tab-mark.png") no-repeat center;
290
+ background:url("../../img/tab-mark.png") no-repeat center;
290
291
  background-size: 100% 100%;
291
292
  right: -3px;
292
293
  top: -5px;
@@ -340,6 +341,157 @@
340
341
  margin-top: -25px;
341
342
  z-index:99999;
342
343
  }
344
+
345
+
346
+ .question-classify{
347
+ margin: 0 auto;
348
+ width: 10rem;
349
+ height: 100%;
350
+ position: relative;
351
+ background: url("../../img/classify-bg-seaworld.png") no-repeat center;
352
+ background-size: 100% 100%;
353
+ overflow: auto;
354
+ .box{
355
+ padding: 0 0.8rem;
356
+ width: 100%;
357
+ display: flex;
358
+ justify-content: space-between;
359
+ margin-top: 0.72rem;
360
+ }
361
+ .box-item{
362
+ width: 4rem;
363
+ height: 4.4rem;
364
+ display: flex;
365
+ flex-direction: column;
366
+ background: url("../../img/classify-boxitem-bg.png") no-repeat center;
367
+ background-size: 100% 100%;
368
+ }
369
+ .main-block{
370
+ margin:0.38rem auto 0;
371
+ width: 1.1rem;
372
+ height: 1.1rem;
373
+ background: #76d2ff;
374
+ border: 1px dashed #ffffff;
375
+ border-radius: 0.11rem;
376
+ flex-shrink: 0;
377
+ }
378
+ .main-content{
379
+ padding: 0 0.28rem 0.15rem 0.35rem;
380
+ flex: 1;
381
+ .main-append{
382
+ /*height: 2.72rem;*/
383
+ height: 2.9rem;
384
+ overflow: auto;
385
+ display: flex;
386
+ flex-wrap: wrap;
387
+ justify-content: space-between;
388
+ align-content: start;
389
+ }
390
+ }
391
+ .append-item{
392
+ background: url("../../img/classify-green-item.png") no-repeat center;
393
+ background-size: 100% 100%;
394
+ width: 1.3rem;
395
+ height: 1.3rem;
396
+ margin-right: 0.1rem;
397
+ flex-shrink: 0;
398
+ cursor: move;
399
+ text-align: center;
400
+ font-size: $greenItemFontSize;
401
+ color:rgb(238,252,149);
402
+ padding:0 0.2rem;
403
+ display: flex;
404
+ justify-content: center;
405
+ align-items: center;
406
+ line-height: 1.2em;
407
+ /*letter-spacing: 0.8px;*/
408
+ .list-item-text{
409
+ margin-top: 0.1rem;
410
+ display: inline-block;
411
+ }
412
+ &:nth-child(2n+1){
413
+ margin-left: 0.2rem;
414
+ }
415
+ &:nth-child(2n){
416
+ margin-right: 0.2rem;
417
+ }
418
+ }
419
+ .list-outter{
420
+ padding: 0 0.33rem;
421
+ height: 1.5rem;
422
+ position: absolute;
423
+ bottom: 0.2rem;
424
+ left:50%;
425
+ margin-left: -4.5rem;
426
+ width: 9rem;
427
+ background: url("../../img/classify-list-bg.png") no-repeat center;
428
+ background-size: 100% 100%;
429
+ .list{
430
+ height: 1.5rem;
431
+ display: flex;
432
+ align-items: center;
433
+ overflow-x: auto;
434
+ width: 100%;
435
+ }
436
+ .prev,.next{
437
+ width: 0.24rem;
438
+ height: 100%;
439
+ display: flex;
440
+ align-items: center;
441
+ position: absolute;
442
+ top:0;
443
+ cursor: pointer;
444
+ }
445
+ .prev{
446
+ left:5px;
447
+ }
448
+ .next{
449
+ right:5px;
450
+ }
451
+ .prev-main,.next-main{
452
+ width: 0.24rem;
453
+ height: 0.28rem;
454
+ top:50%;
455
+ }
456
+ .prev-main{
457
+ background: url("../../img/classify-arrow-left.png") no-repeat center;
458
+ background-size: 100% 100%;
459
+ }
460
+ .next-main{
461
+ background: url("../../img/classify-arrow-right.png") no-repeat center;
462
+ background-size: 100% 100%;
463
+ }
464
+ }
465
+ .list-item{
466
+ background: url("../../img/classify-green-item.png") no-repeat center;
467
+ background-size: 100% 100%;
468
+ width: 1.3rem;
469
+ height: 1.3rem;
470
+ margin-right: 0.1rem;
471
+ flex-shrink: 0;
472
+ cursor: move;
473
+ text-align: center;
474
+ font-size: $greenItemFontSize;
475
+ color:rgb(238,252,149);
476
+ padding:0 0.2rem;
477
+ display: flex;
478
+ justify-content: center;
479
+ align-items: center;
480
+ line-height: 1.2em;
481
+ /*letter-spacing: 0.8px;*/
482
+ .list-item-text{
483
+ margin-top: 0.1rem;
484
+ display: inline-block;
485
+ }
486
+ }
487
+ .list-item.drag{
488
+ border:1px dashed #ddd;
489
+ }
490
+ .append-item.drag{
491
+ border:1px dashed #ddd;
492
+ }
493
+
494
+ }
343
495
  }
344
496
 
345
497
  .imgLookerDialog{
@@ -361,12 +513,12 @@
361
513
  }
362
514
  .prev{
363
515
  left:10px;
364
- background: url("~@src/assets/img/big-pre.png") no-repeat center;
516
+ background: url("../../img/big-pre.png") no-repeat center;
365
517
  background-size: cover;
366
518
  }
367
519
  .next{
368
520
  right:10px;
369
- background: url("~@src/assets/img/big-next.png") no-repeat center;
521
+ background: url("../../img/big-next.png") no-repeat center;
370
522
  background-size: cover;
371
523
  }
372
524
  .close{
@@ -417,4 +569,27 @@
417
569
  &:hover {
418
570
  background-color: #fff;
419
571
  }
572
+ }
573
+ .question-classify-moveDiv{
574
+ position: fixed;
575
+ background: url("../../img/classify-green-item.png") no-repeat center;
576
+ background-size: 100% 100%;
577
+ width: 1.3rem;
578
+ height: 1.3rem;
579
+ margin-right: 0.1rem;
580
+ flex-shrink: 0;
581
+ cursor: move;
582
+ text-align: center;
583
+ font-size: $greenItemFontSize;
584
+ color:rgb(238,252,149);
585
+ padding:0 0.2rem;
586
+ display: flex;
587
+ justify-content: center;
588
+ align-items: center;
589
+ line-height: 1.2em;
590
+ /*letter-spacing: 0.8px;*/
591
+ .list-item-text{
592
+ display: inline-block;
593
+ margin-top: 0.1rem;
594
+ }
420
595
  }
@@ -11,5 +11,6 @@ export let questionMapper:any = {
11
11
  '7':'Question_BriefAnswer',//简答
12
12
  '16':'Question_Programming',//编程
13
13
  '11':'Question_Reading',//阅读
14
- '4':'Question_FillBlank'//填空
14
+ '4':'Question_FillBlank',//填空
15
+ '17':'Question_Classify'//填空
15
16
  }
@@ -0,0 +1,294 @@
1
+ <template>
2
+ <div class="zykjcommon-question" style="width: 100%;height: 100%;">
3
+ <div class="question-classify">
4
+ <div class="box">
5
+ <div class="box-item">
6
+ <div class="main-block"></div>
7
+ <div class="main-content">
8
+ <div class="main-append">
9
+ <!-- <div class="append-item"></div>-->
10
+ </div>
11
+ </div>
12
+ </div>
13
+ <div class="box-item">
14
+ <div class="main-block"></div>
15
+ <div class="main-content">
16
+ <div class="main-append">
17
+ </div>
18
+ </div>
19
+ </div>
20
+ </div>
21
+ <div class="list-outter">
22
+ <div class="prev">
23
+ <div class="prev-main"></div>
24
+ </div>
25
+ <div class="next">
26
+ <div class="next-main"></div>
27
+ </div>
28
+ <div class="list">
29
+ <div class="list-item" v-for="(item,index) in list" :key="index">
30
+ <div class="list-item-text">{{item.name}}</div>
31
+ </div>
32
+ </div>
33
+ </div>
34
+ </div>
35
+ </div>
36
+ </template>
37
+ <script>
38
+ import fun from "../../assets/js/fun";
39
+ import {setRemFixedHeight} from "../../assets/js/rem";
40
+ let env = fun.getDeviceEnv()
41
+ export default {
42
+ name: 'Question_Classify',
43
+ props: {
44
+ questionInfo: {
45
+ type: Object,
46
+ default: {}
47
+ },
48
+ bus: {
49
+ type: Object,
50
+ default: {}
51
+ },
52
+ mode: {
53
+ type: String,
54
+ default: 'exam'
55
+ }
56
+ },
57
+ created() {
58
+ this.setRootFontSize()
59
+ window.addEventListener('resize',this.setRootFontSize)
60
+ },
61
+ unmounted() {
62
+ this.unmountedDo()
63
+ },
64
+ destroyed() {
65
+ this.unmountedDo()
66
+ },
67
+ mounted() {
68
+ this.init()
69
+ this.$watch('list',(nv)=>{
70
+ if(nv && nv.length){
71
+ this.$nextTick(()=>{
72
+ this.dothings()
73
+ })
74
+ }
75
+ })
76
+ setTimeout(()=>{
77
+ this.list = [{name:'每年春夏秋冬季节变化'},{name:'音乐播放10次'},{name:'把10个梨子放进篮子'},{name:'音乐播放9次'},{name:'把9个梨子放进篮子'},{name:'音乐播放8次'},{name:'把8个梨子放进篮子'},{name:'音乐播放6次'}]
78
+ },500)
79
+ },
80
+ data() {
81
+ return {
82
+ analyCorrectAnswer:'',
83
+ exam_options_data:[],
84
+ answerMap:{},
85
+ list:[],
86
+ env,
87
+ p1:{},//存mousedown相关
88
+ p2:{},//存mousemove相关
89
+ listItem:null,
90
+ moveDiv:null,
91
+ timer:null,
92
+ mousedown : env === 'mobile' ? 'touchstart':'mousedown',
93
+ mousemove : env === 'mobile' ? 'touchmove':'mousemove',
94
+ mouseup : env === 'mobile' ? 'touchend':'mouseup',
95
+ dragWay : '',
96
+ flag : false,
97
+ scrollDistance : 3000,//设置一个死的滚动距离,保证能滚到底,目前够用
98
+ };
99
+ },
100
+ watch: {
101
+
102
+ },
103
+ computed:{
104
+ },
105
+ methods: {
106
+ setRootFontSize() {
107
+ setRemFixedHeight(1000,140,1.08)
108
+ },
109
+ unmountedDo(){
110
+ window.removeEventListener('resize',this.setRootFontSize)
111
+ document.removeEventListener('gesturestart', this.gesturestartListener)
112
+ $('.question-classify .append-item').off(this.mousedown)
113
+ $('.question-classify .list-item').off(this.mousedown)
114
+ $(document).off(this.mouseup)
115
+ let html = document.getElementsByTagName("html")[0];
116
+ html.style.fontSize = "";
117
+ },
118
+ gesturestartListener(event){
119
+ event.preventDefault()
120
+ },
121
+ init(){
122
+ //禁止ios10以上缩放页面
123
+ if(env === 'mobile'){
124
+ document.addEventListener('gesturestart', this.gesturestartListener)
125
+ }
126
+ },
127
+ getSpecArr(){
128
+ let self = this
129
+ let specArr = []
130
+ let moveDivLeft = self.moveDiv.offset().left
131
+ let moveDivLeftEnd = moveDivLeft + self.moveDiv.width()
132
+ let moveDivTop = self.moveDiv.offset().top
133
+ let moveDivTopEnd = moveDivTop + self.moveDiv.height()
134
+ $('.box-item').each((index,item)=>{
135
+ let boxItem = $(item)
136
+ let boxLeft = boxItem.offset().left
137
+ let boxLeftEnd = boxLeft + boxItem.width()
138
+ let boxTop = boxItem.offset().top
139
+ let boxTopEnd = boxTop + boxItem.height()
140
+
141
+ if(moveDivLeft > boxLeft && moveDivLeftEnd < boxLeftEnd && moveDivTop > boxTop && moveDivTopEnd < boxTopEnd){
142
+ specArr.push({
143
+ dom:boxItem
144
+ })
145
+ }
146
+ })
147
+ return specArr
148
+ },
149
+ bindDragDomEvent(appendItem,way){
150
+ let self = this
151
+ appendItem.on(this.mousedown,function(e){
152
+ if(self.moveDiv){
153
+ return
154
+ }
155
+ self.flag = false
156
+ self.dragWay = way
157
+ console.log(e);
158
+ e.stopPropagation()
159
+ e.preventDefault()
160
+ self.listItem = $(this)
161
+ self.listItem.addClass('drag')
162
+ self.p1.moveX = self.listItem.offset().left;
163
+ self.p1.moveY = self.listItem.offset().top - 30;
164
+ console.log(this.p1);
165
+ self.moveDiv = $(`<div class="question-classify-moveDiv"><div class="list-item-text">${self.listItem.find('.list-item-text').text()}</div></div>`)
166
+ self.moveDiv.css({left:`${self.p1.moveX}px`,top:`${self.p1.moveY}px`})
167
+ $('body').append(self.moveDiv)
168
+ $(document).on(self.mousemove,function(e2){
169
+ // e2.preventDefault()
170
+ e2.stopPropagation()
171
+ self.p2.moveX = e2.clientX || (e2.originalEvent.touches && e2.originalEvent.touches[0].clientX);
172
+ self.p2.moveY = e2.clientY || (e2.originalEvent.touches && e2.originalEvent.touches[0].clientY);
173
+ let curX = self.p2.moveX - self.moveDiv.width()/2
174
+ let curY = self.p2.moveY - self.moveDiv.height()/2
175
+ self.moveDiv.css({
176
+ left:curX + 'px',
177
+ top:curY + 'px'
178
+ })
179
+
180
+ })
181
+
182
+ })
183
+ },
184
+ appendMoveDiv(options){
185
+ let self = this
186
+ self.listItem.remove()
187
+ let appendItem = $(`<div class="${options.appendItemClassName}"><div class="list-item-text">${self.moveDiv.find('.list-item-text').text()}</div></div>`)
188
+ appendItem.css({opacity:0})
189
+ options.targetList.append(appendItem)
190
+ options.targetList[options.scrollDirection](self.scrollDistance)
191
+ let appendLeft = appendItem.offset().left
192
+ let appendTop = appendItem.offset().top
193
+ //transitionend事件会执行2次,所以使用标记避免
194
+ self.moveDiv.css({
195
+ transition:'all 0.5s',
196
+ left:appendLeft,
197
+ top:appendTop
198
+ }).on('transitionend',function(){
199
+ if(!self.flag){
200
+ self.moveDiv.remove()
201
+ self.moveDiv.off('transitionend')
202
+ self.moveDiv = null
203
+ appendItem.css({opacity:1})
204
+ self.bindDragDomEvent(appendItem,options.op)
205
+ }
206
+ self.flag = true
207
+ })
208
+ },
209
+ bindNextPrevEvent(type){
210
+ $(`.question-classify .${type}`).on('click',function(e){
211
+ e.stopPropagation()
212
+ e.preventDefault()
213
+ let listItem = $('.question-classify .list-item')
214
+ let list = $('.question-classify .list')
215
+ let w = listItem.outerWidth() * (type === 'next' ? 1 : -1)
216
+ let scrollLeft = list.scrollLeft()
217
+ console.log(scrollLeft);
218
+ $('.question-classify .list').stop(true).animate({scrollLeft:scrollLeft + w},500)
219
+ })
220
+ },
221
+ dothings(){
222
+ let self = this
223
+ self.bindDragDomEvent($('.question-classify .list-item'),'go')
224
+ $(document).on(self.mouseup,function(e){
225
+ // e.preventDefault()
226
+ if(self.dragWay === 'go'){
227
+ $(document).off(self.mousemove)
228
+ self.listItem && self.listItem.removeClass('drag')
229
+ if(self.moveDiv){
230
+ let specArr = self.getSpecArr()
231
+ if(specArr.length === 0){
232
+ //没进框内,回到原位
233
+ if(self.moveDiv){
234
+ self.moveDiv.remove()
235
+ self.moveDiv = null
236
+ }
237
+ }else{
238
+ let appendItemBox = specArr[0].dom
239
+ self.appendMoveDiv({
240
+ targetList:appendItemBox.find('.main-append'),
241
+ appendItemClassName:'append-item',
242
+ op:'back',
243
+ scrollDirection:'scrollTop'
244
+ })
245
+ }
246
+ }
247
+ }else if(self.dragWay === 'back'){
248
+ $(document).off(self.mousemove)
249
+ self.listItem && self.listItem.removeClass('drag')
250
+ if(self.moveDiv){
251
+ let specArr = self.getSpecArr()
252
+ //0说明都不在两个框内 1说明在其中一个框内
253
+ if(specArr.length === 0){
254
+ self.appendMoveDiv({
255
+ targetList:$('.question-classify .list'),
256
+ appendItemClassName:'list-item',
257
+ op:'go',
258
+ scrollDirection:'scrollLeft'
259
+ })
260
+ }else{
261
+ let appendItemBox = specArr[0].dom
262
+ let curAppendItemBox = self.listItem.parents('.question-classify .box-item')
263
+ if(appendItemBox.get(0) === curAppendItemBox.get(0)){
264
+ console.log('自己');
265
+ self.moveDiv.remove()
266
+ self.moveDiv = null
267
+ self.listItem && self.listItem.removeClass('drag')
268
+ }else{
269
+ console.log('不是自己');
270
+ self.appendMoveDiv({
271
+ targetList:appendItemBox.find('.main-append'),
272
+ appendItemClassName:'append-item',
273
+ op:'back',
274
+ scrollDirection:'scrollTop'
275
+ })
276
+ console.log('不是自己');
277
+ }
278
+ }
279
+
280
+ console.log(specArr.length);
281
+ }
282
+
283
+
284
+ }
285
+ })
286
+ self.bindNextPrevEvent('next')
287
+ self.bindNextPrevEvent('prev')
288
+ }
289
+ },
290
+ components:{
291
+
292
+ }
293
+ };
294
+ </script>