@wg-npm/survey-creator 0.3.4004 → 0.3.4075

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.
@@ -64,6 +64,8 @@ var defaultLang = {
64
64
  sub_questions: "子题",
65
65
  score: "分值",
66
66
  scores: "分",
67
+ totalScores: "总分",
68
+ selectScore: "请选择分值",
67
69
  questionRequired: "此题必填",
68
70
  titleRequiredTip: "请填写题目名称",
69
71
  textTitleRequiredTip: "请填写文字说明",
@@ -150,7 +152,7 @@ var defaultLang = {
150
152
  other: "其他",
151
153
  assign_template: `{0} 项为 {1} {2} {3}项`,
152
154
  auto_template: `{0} 项为 {1}`,
153
- score_template: `总分数范围为: {0}{1}{2}分`,
155
+ score_template: `总分数范围为: {0}{1} 总分 {2}{3}`,
154
156
  },
155
157
  },
156
158
  },
@@ -1800,7 +1802,12 @@ var script$t = Vue.extend({
1800
1802
  getDesc(condition) {
1801
1803
  let payload = condition.payload;
1802
1804
  if (condition.type == "SCORE") {
1803
- return this.t("survey_creator.question.evaluation.condition.score_template", [payload.minScore, payload.operator, payload.maxScore]);
1805
+ return this.t("survey_creator.question.evaluation.condition.score_template", [
1806
+ payload.minScore,
1807
+ payload.leftOperator,
1808
+ payload.rightOperator,
1809
+ payload.maxScore,
1810
+ ]);
1804
1811
  }
1805
1812
  else {
1806
1813
  let numbers = new ExprEvaluationQuestion(this.questions, payload.scope).calculateNumbers();
@@ -3148,89 +3155,29 @@ var script$d = Vue.extend({
3148
3155
  Select,
3149
3156
  Option,
3150
3157
  FormItem,
3151
- InputNumber
3158
+ InputNumber,
3152
3159
  },
3153
3160
  data() {
3154
3161
  return {
3155
- leftMin: 0,
3156
- leftMax: 0,
3157
- rightMin: 0,
3158
- rightMax: 0,
3159
- operators: ["<=", "<"]
3162
+ operators: ["<=", "<"],
3160
3163
  };
3161
3164
  },
3162
- created() {
3163
- this.leftMax = this.totalScore - 1;
3164
- this.rightMax = this.totalScore;
3165
- },
3165
+ created() { },
3166
3166
  computed: {
3167
3167
  totalScore() {
3168
3168
  return this.$rootComponent.currentSurvey.statistics.maxScore;
3169
3169
  },
3170
+ scores() {
3171
+ return _.range(1, this.totalScore + 1, 1);
3172
+ },
3170
3173
  otherConditions() {
3171
3174
  let otherEvaluationItems = _.filter(_.map(this.evaluationItems, (item, index) => {
3172
3175
  return _.extend({}, item, { index: index });
3173
3176
  }), (item) => item.index != this.itemIndex);
3174
3177
  return _.filter(_.flatMap(otherEvaluationItems, "conditions"), (item) => item.type == "SCORE");
3175
3178
  },
3176
- otherMin() {
3177
- _.min(_.map(this.otherConditions, (item) => _.get(item, "payload.minScore", 0)));
3178
- },
3179
- otherMax() {
3180
- _.max(_.map(this.otherConditions, (item) => _.get(item, "payload.maxScore", 0)));
3181
- },
3182
3179
  },
3183
3180
  methods: {
3184
- checkValueInOtherRange(value, conditions) {
3185
- let otherRange = _.map(conditions, (item) => {
3186
- return {
3187
- min: _.get(item, "payload.minScore"),
3188
- max: _.get(item, "payload.maxScore"),
3189
- };
3190
- });
3191
- return _.some(otherRange, function (o) {
3192
- return value >= o.min && value <= o.max;
3193
- });
3194
- },
3195
- generateExpr() {
3196
- let minScore = this.value.minScore;
3197
- let maxScore = this.value.maxScore;
3198
- return `${minScore} ${this.value.operator} score and score ${this.value.operator} ${maxScore}`;
3199
- },
3200
- leftChange(value) {
3201
- this.rangeChange(value, "left");
3202
- },
3203
- rightChange(value) {
3204
- this.rangeChange(value, "right");
3205
- },
3206
- rangeChange(value, type) {
3207
- let valueInOtherRange = this.checkValueInOtherRange(value, this.otherConditions);
3208
- let usableRanges = this.getUsableRanges();
3209
- let firstUsableRange = usableRanges[0];
3210
- let valueInRange = this.getSelectedRangeByValue(value, usableRanges);
3211
- let currentRange = valueInOtherRange ? firstUsableRange : valueInRange;
3212
- let min = valueInOtherRange ? firstUsableRange[0] : _.get(valueInRange, 'min', 0);
3213
- let max = valueInOtherRange ? firstUsableRange[1] : _.get(currentRange, 'max', this.totalScore);
3214
- if (valueInOtherRange) {
3215
- this.$Message.error("该值在其他区间范围内,请重新输入");
3216
- this.$set(this.value, "minScore", min);
3217
- this.$set(this.value, "maxScore", max);
3218
- this.rightMin = min;
3219
- this.rightMax = max;
3220
- this.leftMin = min;
3221
- this.leftMax = max;
3222
- }
3223
- else {
3224
- if (type == "left") {
3225
- this.rightMin = value + 1;
3226
- this.rightMax = max;
3227
- }
3228
- if (type == "right") {
3229
- this.leftMin = min;
3230
- this.leftMax = value - 1;
3231
- }
3232
- }
3233
- },
3234
3181
  getSelectedRangeByValue(value, ranges) {
3235
3182
  let otherRange = _.map(ranges, (item) => {
3236
3183
  return {
@@ -3255,6 +3202,10 @@ var script$d = Vue.extend({
3255
3202
  let item = [0, first];
3256
3203
  usableRange.push(item);
3257
3204
  }
3205
+ if (usedRange[length - 1][1] != globalMax) {
3206
+ usableRange.push([usedRange[length - 1][1], globalMax]);
3207
+ }
3208
+ return usableRange;
3258
3209
  }
3259
3210
  else {
3260
3211
  let other = usedRange.reduce((a, v) => {
@@ -3283,10 +3234,40 @@ var script$d = Vue.extend({
3283
3234
  if (usedRange[length - 1][1] != globalMax) {
3284
3235
  other.push([usedRange[length - 1][1], globalMax]);
3285
3236
  }
3237
+ return other;
3286
3238
  }
3287
- return usableRange;
3288
3239
  },
3289
- }
3240
+ disabledScoreOption(value, type) {
3241
+ if (this.checkValueInOtherRange(value)) {
3242
+ return true;
3243
+ }
3244
+ let currentMin = _.get(this.value, "minScore", 0);
3245
+ let currentMax = _.get(this.value, "maxScore", this.totalScore);
3246
+ _.get(this.value, "maxScore", this.totalScore);
3247
+ if (type == "left" && value >= currentMax) {
3248
+ return true;
3249
+ }
3250
+ if (type == "right" && value <= currentMin) {
3251
+ return true;
3252
+ }
3253
+ },
3254
+ checkValueInOtherRange(value) {
3255
+ let otherRange = _.map(this.otherConditions, (item) => {
3256
+ return {
3257
+ min: _.get(item, "payload.minScore", 0),
3258
+ max: _.get(item, "payload.maxScore", 0),
3259
+ };
3260
+ });
3261
+ return _.some(otherRange, function (o) {
3262
+ return value >= o.min && value <= o.max;
3263
+ });
3264
+ },
3265
+ generateExpr() {
3266
+ let minScore = this.value.minScore;
3267
+ let maxScore = this.value.maxScore;
3268
+ return `${minScore} ${this.value.leftOperator} score and score ${this.value.rightOperator} ${maxScore}`;
3269
+ },
3270
+ },
3290
3271
  });
3291
3272
 
3292
3273
  /* script */
@@ -3294,34 +3275,34 @@ const __vue_script__$d = script$d;
3294
3275
 
3295
3276
  /* template */
3296
3277
  var __vue_render__$d = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('Row',{attrs:{"type":"flex","justify":"start","gutter":6,"align":"middle"}},[_c('Col',{staticClass:"label"},[_vm._v("\n "+_vm._s(_vm.t("survey_creator.question.evaluation.condition.score_condition_title"))+"\n ")]),_vm._v(" "),_c('Col',{attrs:{"span":3}},[_c('FormItem',{attrs:{"prop":("evaluationItems[" + _vm.itemIndex + "].conditions[" + _vm.index + "].payload.minScore"),"rules":{
3297
- min:_vm.leftMin,
3298
- max:_vm.leftMax,
3299
- required: true,
3300
- type: 'number',
3301
- trigger: 'change',
3302
- message: _vm.t('分值不正确'),
3303
- }}},[_c('InputNumber',{attrs:{"active-change":false,"min":_vm.leftMin,"max":_vm.leftMax,"formatter":function (value) { return ("" + value + (_vm.t('survey_creator.question.scores'))); },"parser":function (value) { return value.replace(("" + (_vm.t('survey_creator.question.scores'))), ''); }},on:{"on-change":_vm.leftChange},model:{value:(_vm.value.minScore),callback:function ($$v) {_vm.$set(_vm.value, "minScore", $$v);},expression:"value.minScore"}})],1)],1),_vm._v(" "),_c('Col',{attrs:{"span":3}},[_c('FormItem',{attrs:{"prop":("evaluationItems[" + _vm.itemIndex + "].conditions[" + _vm.index + "].payload.operator"),"rules":{
3278
+ required: true,
3279
+ type: 'number',
3280
+ trigger: 'change',
3281
+ message: _vm.t('survey_creator.question.scoreRequiredTip'),
3282
+ }}},[_c('Select',{attrs:{"placeholder":_vm.t('survey_creator.question.selectScore')},model:{value:(_vm.value.minScore),callback:function ($$v) {_vm.$set(_vm.value, "minScore", $$v);},expression:"value.minScore"}},_vm._l((_vm.scores),function(score){return _c('Option',{key:score,attrs:{"value":score,"disabled":_vm.disabledScoreOption(score, 'left')}},[_vm._v("\n "+_vm._s(score)+"\n ")])}),1)],1)],1),_vm._v(" "),_c('Col',{staticClass:"label",attrs:{"span":1}},[_vm._v("\n "+_vm._s(_vm.t("survey_creator.question.scores"))+"\n ")]),_vm._v(" "),_c('Col',{attrs:{"span":2}},[_c('FormItem',{attrs:{"prop":("evaluationItems[" + _vm.itemIndex + "].conditions[" + _vm.index + "].payload.leftOperator"),"rules":{
3304
3283
  required: true,
3305
3284
  trigger: 'change',
3306
3285
  message: _vm.t('survey_creator.question.notEmpty'),
3307
- }}},[_c('Select',{attrs:{"placeholder":_vm.t('survey_creator.question.evaluation.condition.operator')},model:{value:(_vm.value.operator),callback:function ($$v) {_vm.$set(_vm.value, "operator", $$v);},expression:"value.operator"}},_vm._l((_vm.operators),function(operator,index){return _c('Option',{key:index,attrs:{"value":operator}},[_vm._v("\n "+_vm._s(operator)+"\n ")])}),1)],1)],1),_vm._v(" "),_c('Col',{attrs:{"span":2}},[_c('FormItem',{attrs:{"prop":("evaluationItems[" + _vm.itemIndex + "].conditions[" + _vm.index + "].payload.maxScore"),"rules":{
3308
- min:_vm.rightMin,
3309
- max:_vm.rightMax,
3286
+ }}},[_c('Select',{attrs:{"placeholder":_vm.t('survey_creator.question.evaluation.condition.operator')},model:{value:(_vm.value.leftOperator),callback:function ($$v) {_vm.$set(_vm.value, "leftOperator", $$v);},expression:"value.leftOperator"}},_vm._l((_vm.operators),function(operator,index){return _c('Option',{key:index,attrs:{"value":operator}},[_vm._v("\n "+_vm._s(operator)+"\n ")])}),1)],1)],1),_vm._v(" "),_c('Col',{staticClass:"label"},[_vm._v("\n "+_vm._s(_vm.t("survey_creator.question.totalScores"))+"\n ")]),_vm._v(" "),_c('Col',{attrs:{"span":2}},[_c('FormItem',{attrs:{"prop":("evaluationItems[" + _vm.itemIndex + "].conditions[" + _vm.index + "].payload.rightOperator"),"rules":{
3287
+ required: true,
3288
+ trigger: 'change',
3289
+ message: _vm.t('survey_creator.question.notEmpty'),
3290
+ }}},[_c('Select',{attrs:{"placeholder":_vm.t('survey_creator.question.evaluation.condition.operator')},model:{value:(_vm.value.rightOperator),callback:function ($$v) {_vm.$set(_vm.value, "rightOperator", $$v);},expression:"value.rightOperator"}},_vm._l((_vm.operators),function(operator,index){return _c('Option',{key:index,attrs:{"value":operator}},[_vm._v("\n "+_vm._s(operator)+"\n ")])}),1)],1)],1),_vm._v(" "),_c('Col',{attrs:{"span":3}},[_c('FormItem',{attrs:{"prop":("evaluationItems[" + _vm.itemIndex + "].conditions[" + _vm.index + "].payload.maxScore"),"rules":{
3310
3291
  required: true,
3311
3292
  type: 'number',
3312
3293
  trigger: 'change',
3313
- message: _vm.t('分值不正确'),
3314
- }}},[_c('InputNumber',{attrs:{"active-change":false,"min":_vm.rightMin,"max":_vm.rightMax,"formatter":function (value) { return ("" + value + (_vm.t('survey_creator.question.scores'))); },"parser":function (value) { return value.replace(("" + (_vm.t('survey_creator.question.scores'))), ''); }},on:{"on-change":_vm.rightChange},model:{value:(_vm.value.maxScore),callback:function ($$v) {_vm.$set(_vm.value, "maxScore", $$v);},expression:"value.maxScore"}})],1)],1)],1)};
3294
+ message: _vm.t('survey_creator.question.scoreRequiredTip'),
3295
+ }}},[_c('Select',{attrs:{"placeholder":_vm.t('survey_creator.question.selectScore')},model:{value:(_vm.value.maxScore),callback:function ($$v) {_vm.$set(_vm.value, "maxScore", $$v);},expression:"value.maxScore"}},_vm._l((_vm.scores),function(score){return _c('Option',{key:score,attrs:{"value":score,"disabled":_vm.disabledScoreOption(score, 'right')}},[_vm._v("\n "+_vm._s(score)+"\n ")])}),1)],1)],1),_vm._v(" "),_c('Col',{staticClass:"label",attrs:{"span":1}},[_vm._v("\n "+_vm._s(_vm.t("survey_creator.question.scores"))+"\n ")])],1)};
3315
3296
  var __vue_staticRenderFns__$d = [];
3316
3297
 
3317
3298
  /* style */
3318
3299
  const __vue_inject_styles__$d = function (inject) {
3319
3300
  if (!inject) return
3320
- inject("data-v-2e725872_0", { source: ".label[data-v-2e725872]{text-align:right;margin-bottom:24px}", map: undefined, media: undefined });
3301
+ inject("data-v-0d3d3556_0", { source: ".label[data-v-0d3d3556]{text-align:right;margin-bottom:24px}", map: undefined, media: undefined });
3321
3302
 
3322
3303
  };
3323
3304
  /* scoped */
3324
- const __vue_scope_id__$d = "data-v-2e725872";
3305
+ const __vue_scope_id__$d = "data-v-0d3d3556";
3325
3306
  /* module identifier */
3326
3307
  const __vue_module_identifier__$d = undefined;
3327
3308
  /* functional template */
@@ -3469,6 +3450,9 @@ var script$b = Vue.extend({
3469
3450
  };
3470
3451
  },
3471
3452
  computed: {
3453
+ totalScore() {
3454
+ return this.$rootComponent.currentSurvey.statistics.maxScore;
3455
+ },
3472
3456
  deletable() {
3473
3457
  return (_.size(_.filter(this.evaluationItems, (item) => item.type == "IF")) > 1);
3474
3458
  },
@@ -3503,9 +3487,10 @@ var script$b = Vue.extend({
3503
3487
  buildPayloadByType(type) {
3504
3488
  if (type == "SCORE") {
3505
3489
  return {
3506
- minScore: 0,
3507
- operator: "<",
3508
- maxScore: 0,
3490
+ minScore: null,
3491
+ leftOperator: "<",
3492
+ rightOperator: "<",
3493
+ maxScore: null,
3509
3494
  };
3510
3495
  }
3511
3496
  return {
@@ -3539,11 +3524,11 @@ var __vue_staticRenderFns__$b = [];
3539
3524
  /* style */
3540
3525
  const __vue_inject_styles__$b = function (inject) {
3541
3526
  if (!inject) return
3542
- inject("data-v-199a51dd_0", { source: ".mt-base[data-v-199a51dd]{margin-top:12px}.action[data-v-199a51dd]{float:right}.input[data-v-199a51dd]{width:100px}.label[data-v-199a51dd]{text-align:right;padding-right:4px}.text[data-v-199a51dd]{background-color:#ebf7ff;height:32px;padding:8px 18px;font-weight:500;color:#515a6e}[data-v-199a51dd] .ivu-card .ivu-form-item{margin-bottom:4px;margin-top:0}[data-v-199a51dd] .ivu-card .ivu-form-item-error{margin-bottom:24px;margin-top:0}", map: undefined, media: undefined });
3527
+ inject("data-v-bb232856_0", { source: ".mt-base[data-v-bb232856]{margin-top:12px}.action[data-v-bb232856]{float:right}.input[data-v-bb232856]{width:100px}.label[data-v-bb232856]{text-align:right;padding-right:4px}.text[data-v-bb232856]{background-color:#ebf7ff;height:32px;padding:8px 18px;font-weight:500;color:#515a6e}[data-v-bb232856] .ivu-card .ivu-form-item{margin-bottom:4px;margin-top:0}[data-v-bb232856] .ivu-card .ivu-form-item-error{margin-bottom:24px;margin-top:0}", map: undefined, media: undefined });
3543
3528
 
3544
3529
  };
3545
3530
  /* scoped */
3546
- const __vue_scope_id__$b = "data-v-199a51dd";
3531
+ const __vue_scope_id__$b = "data-v-bb232856";
3547
3532
  /* module identifier */
3548
3533
  const __vue_module_identifier__$b = undefined;
3549
3534
  /* functional template */
@@ -4539,7 +4524,7 @@ var script = Vue.extend({
4539
4524
  components: { Card, Row, Col, Button, Toolbar, SurveyInternalPreviewer },
4540
4525
  provide() {
4541
4526
  return {
4542
- $rootComponent: this
4527
+ $rootComponent: this.$rootComponent
4543
4528
  };
4544
4529
  },
4545
4530
  props: {
@@ -4620,6 +4605,7 @@ class SurveyCreatorPlugin {
4620
4605
  Vue.$surveyLanguage = options.locale;
4621
4606
  Vue.component('survey-creator', SurveyCreator);
4622
4607
  Vue.component('survey-previewer', SurveyPreviewer);
4608
+ Vue.component("question-edit-drawer", QuestionEditDrawer);
4623
4609
  }
4624
4610
  }
4625
4611
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wg-npm/survey-creator",
3
- "version": "0.3.4004",
3
+ "version": "0.3.4075",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -12,8 +12,8 @@
12
12
  "lint-fix": "eslint \"**/*.ts\" \"**/*.vue\" --fix --no-error-on-unmatched-pattern"
13
13
  },
14
14
  "peerDependencies": {
15
- "@wg-npm/survey-core": "0.3.4004",
16
- "@wg-npm/survey-service-api": "0.3.4004",
15
+ "@wg-npm/survey-core": "0.3.4075",
16
+ "@wg-npm/survey-service-api": "0.3.4075",
17
17
  "axios": "^0.19.2",
18
18
  "camelcase": "^6.0.0",
19
19
  "deepmerge": "^4.2.2",
@@ -38,8 +38,8 @@
38
38
  "@typescript-eslint/eslint-plugin": "^3.6.0",
39
39
  "@typescript-eslint/parser": "^3.6.0",
40
40
  "@vue/eslint-config-prettier": "^6.0.0",
41
- "@wg-npm/survey-core": "0.3.4004",
42
- "@wg-npm/survey-service-api": "0.3.4004",
41
+ "@wg-npm/survey-core": "0.3.4075",
42
+ "@wg-npm/survey-service-api": "0.3.4075",
43
43
  "acorn": "^7.3.1",
44
44
  "axios": "^0.19.2",
45
45
  "babelrc-rollup": "^3.0.0",
@@ -45,7 +45,12 @@ export default Vue.extend({
45
45
  if (condition.type == ExprConditionType.SCORE) {
46
46
  return this.t(
47
47
  "survey_creator.question.evaluation.condition.score_template",
48
- [payload.minScore, payload.operator, payload.maxScore]
48
+ [
49
+ payload.minScore,
50
+ payload.leftOperator,
51
+ payload.rightOperator,
52
+ payload.maxScore,
53
+ ]
49
54
  );
50
55
  } else {
51
56
  let numbers = new ExprEvaluationQuestion(
@@ -157,6 +157,9 @@ export default Vue.extend({
157
157
  };
158
158
  },
159
159
  computed: {
160
+ totalScore() {
161
+ return this.$rootComponent.currentSurvey.statistics.maxScore;
162
+ },
160
163
  deletable() {
161
164
  return (
162
165
  _.size(
@@ -202,9 +205,10 @@ export default Vue.extend({
202
205
  buildPayloadByType(type) {
203
206
  if (type == ExprConditionType.SCORE) {
204
207
  return {
205
- minScore: 0,
206
- operator: "<",
207
- maxScore: 0,
208
+ minScore: null,
209
+ leftOperator: "<",
210
+ rightOperator: "<",
211
+ maxScore: null,
208
212
  };
209
213
  }
210
214
  return {
@@ -7,94 +7,130 @@
7
7
  </Col>
8
8
  <Col :span="3">
9
9
  <FormItem
10
- :prop="`evaluationItems[${itemIndex}].conditions[${index}].payload.minScore`"
11
- :rules="{
12
- min:leftMin,
13
- max:leftMax,
14
- required: true,
15
- type: 'number',
16
- trigger: 'change',
17
- message: t('分值不正确'),
18
- }"
10
+ :prop="`evaluationItems[${itemIndex}].conditions[${index}].payload.minScore`"
11
+ :rules="{
12
+ required: true,
13
+ type: 'number',
14
+ trigger: 'change',
15
+ message: t('survey_creator.question.scoreRequiredTip'),
16
+ }"
19
17
  >
20
- <InputNumber
21
- v-model="value.minScore"
22
- :active-change="false"
23
- :min="leftMin"
24
- :max="leftMax"
25
- :formatter="
26
- (value) => `${value}${t('survey_creator.question.scores')}`
27
- "
28
- :parser="
29
- (value) =>
30
- value.replace(`${t('survey_creator.question.scores')}`, '')
31
- "
32
- @on-change="leftChange"
33
- ></InputNumber>
18
+ <Select
19
+ v-model="value.minScore"
20
+ :placeholder="t('survey_creator.question.selectScore')"
21
+ >
22
+ <Option
23
+ v-for="score in scores"
24
+ :value="score"
25
+ :key="score"
26
+ :disabled="disabledScoreOption(score, 'left')"
27
+ >
28
+ {{ score }}
29
+ </Option>
30
+ </Select>
34
31
  </FormItem>
35
32
  </Col>
36
- <Col :span="3">
33
+ <Col class="label" :span="1">
34
+ {{ t("survey_creator.question.scores") }}
35
+ </Col>
36
+ <Col :span="2">
37
37
  <FormItem
38
- :prop="`evaluationItems[${itemIndex}].conditions[${index}].payload.operator`"
39
- :rules="{
38
+ :prop="`evaluationItems[${itemIndex}].conditions[${index}].payload.leftOperator`"
39
+ :rules="{
40
40
  required: true,
41
41
  trigger: 'change',
42
42
  message: t('survey_creator.question.notEmpty'),
43
43
  }"
44
44
  >
45
45
  <Select
46
- v-model="value.operator"
47
- :placeholder="
46
+ v-model="value.leftOperator"
47
+ :placeholder="
48
48
  t('survey_creator.question.evaluation.condition.operator')
49
49
  "
50
50
  >
51
51
  <Option
52
- v-for="(operator, index) in operators"
53
- :value="operator"
54
- :key="index"
52
+ v-for="(operator, index) in operators"
53
+ :value="operator"
54
+ :key="index"
55
55
  >
56
56
  {{ operator }}
57
57
  </Option>
58
58
  </Select>
59
59
  </FormItem>
60
60
  </Col>
61
+ <Col class="label">
62
+ {{ t("survey_creator.question.totalScores") }}
63
+ </Col>
61
64
  <Col :span="2">
62
65
  <FormItem
63
- :prop="`evaluationItems[${itemIndex}].conditions[${index}].payload.maxScore`"
64
- :rules="{
65
- min:rightMin,
66
- max:rightMax,
66
+ :prop="`evaluationItems[${itemIndex}].conditions[${index}].payload.rightOperator`"
67
+ :rules="{
67
68
  required: true,
68
- type: 'number',
69
69
  trigger: 'change',
70
- message: t('分值不正确'),
70
+ message: t('survey_creator.question.notEmpty'),
71
71
  }"
72
72
  >
73
- <InputNumber
74
- :active-change="false"
75
- v-model="value.maxScore"
76
- :min="rightMin"
77
- :max="rightMax"
78
- :formatter="
79
- (value) => `${value}${t('survey_creator.question.scores')}`
80
- "
81
- :parser="
82
- (value) =>
83
- value.replace(`${t('survey_creator.question.scores')}`, '')
73
+ <Select
74
+ v-model="value.rightOperator"
75
+ :placeholder="
76
+ t('survey_creator.question.evaluation.condition.operator')
84
77
  "
85
- @on-change="rightChange"
86
- ></InputNumber>
78
+ >
79
+ <Option
80
+ v-for="(operator, index) in operators"
81
+ :value="operator"
82
+ :key="index"
83
+ >
84
+ {{ operator }}
85
+ </Option>
86
+ </Select>
87
+ </FormItem>
88
+ </Col>
89
+ <Col :span="3">
90
+ <FormItem
91
+ :prop="`evaluationItems[${itemIndex}].conditions[${index}].payload.maxScore`"
92
+ :rules="{
93
+ required: true,
94
+ type: 'number',
95
+ trigger: 'change',
96
+ message: t('survey_creator.question.scoreRequiredTip'),
97
+ }"
98
+ >
99
+ <Select
100
+ v-model="value.maxScore"
101
+ :placeholder="t('survey_creator.question.selectScore')"
102
+ >
103
+ <Option
104
+ v-for="score in scores"
105
+ :value="score"
106
+ :key="score"
107
+ :disabled="disabledScoreOption(score, 'right')"
108
+ >
109
+ {{ score }}
110
+ </Option>
111
+ </Select>
87
112
  </FormItem>
88
113
  </Col>
114
+ <Col class="label" :span="1">
115
+ {{ t("survey_creator.question.scores") }}
116
+ </Col>
89
117
  </Row>
90
118
  </template>
91
119
  <script lang="ts">
92
120
  import Vue from "vue";
93
- import {Col, FormItem, InputNumber, Message, Option, Row, Select} from "view-design";
121
+ import {
122
+ Col,
123
+ FormItem,
124
+ InputNumber,
125
+ Message,
126
+ Option,
127
+ Row,
128
+ Select,
129
+ } from "view-design";
94
130
  import _ from "lodash";
95
131
  import ExprMixin from "./expr-mixin";
96
132
  import LocaleMixin from "../../../../../mixins/locale-mixin";
97
- import {ExprConditionType} from "@wg-npm/survey-core/src/models";
133
+ import { ExprConditionType } from "@wg-npm/survey-core/src/models";
98
134
 
99
135
  Vue.prototype.$Message = Message;
100
136
 
@@ -107,120 +143,35 @@ export default Vue.extend({
107
143
  Select,
108
144
  Option,
109
145
  FormItem,
110
- InputNumber
146
+ InputNumber,
111
147
  },
112
148
  data() {
113
- const validateScore = (rule, value, callback) => {
114
- let checkfunc = function checkValueInRange(value) {
115
- let otherRange = _.map(this.otherConditions, (item) => {
116
- return {
117
- min: _.get(item, "payload.minScore"),
118
- max: _.get(item, "payload.maxScore"),
119
- };
120
- });
121
- return _.some(otherRange, function (o) {
122
- return value > o.min && value < o.max;
123
- });
124
- };
125
- let rangeInValid = checkfunc(value);
126
- if (value === "") {
127
- callback(new Error("分值不能为空"));
128
- } else {
129
- if (rangeInValid) {
130
- callback(new Error("分值在别的条件中已存在"));
131
- }
132
- callback();
133
- }
134
- };
135
149
  return {
136
- leftMin: 0,
137
- leftMax: 0,
138
- rightMin: 0,
139
- rightMax: 0,
140
- operators: ["<=", "<"]
150
+ operators: ["<=", "<"],
141
151
  };
142
152
  },
143
- created() {
144
- this.leftMax = this.totalScore - 1;
145
- this.rightMax = this.totalScore;
146
- },
153
+ created() {},
147
154
  computed: {
148
155
  totalScore() {
149
156
  return this.$rootComponent.currentSurvey.statistics.maxScore;
150
157
  },
158
+ scores() {
159
+ return _.range(1, this.totalScore + 1, 1);
160
+ },
151
161
  otherConditions() {
152
162
  let otherEvaluationItems = _.filter(
153
- _.map(this.evaluationItems, (item, index) => {
154
- return _.extend({}, item, {index: index});
155
- }),
156
- (item) => item.index != this.itemIndex
163
+ _.map(this.evaluationItems, (item, index) => {
164
+ return _.extend({}, item, { index: index });
165
+ }),
166
+ (item) => item.index != this.itemIndex
157
167
  );
158
168
  return _.filter(
159
- _.flatMap(otherEvaluationItems, "conditions"),
160
- (item) => item.type == ExprConditionType.SCORE
161
- );
162
- },
163
- otherMin() {
164
- _.min(
165
- _.map(this.otherConditions, (item) => _.get(item, "payload.minScore", 0))
166
- );
167
- },
168
- otherMax() {
169
- _.max(
170
- _.map(this.otherConditions, (item) => _.get(item, "payload.maxScore", 0))
169
+ _.flatMap(otherEvaluationItems, "conditions"),
170
+ (item) => item.type == ExprConditionType.SCORE
171
171
  );
172
172
  },
173
173
  },
174
174
  methods: {
175
- checkValueInOtherRange(value, conditions) {
176
- let otherRange = _.map(conditions, (item) => {
177
- return {
178
- min: _.get(item, "payload.minScore"),
179
- max: _.get(item, "payload.maxScore"),
180
- };
181
- });
182
- return _.some(otherRange, function (o) {
183
- return value >= o.min && value <= o.max;
184
- });
185
- },
186
- generateExpr() {
187
- let minScore = this.value.minScore;
188
- let maxScore = this.value.maxScore;
189
- return `${minScore} ${this.value.operator} score and score ${this.value.operator} ${maxScore}`;
190
- },
191
- leftChange(value) {
192
- this.rangeChange(value, "left");
193
- },
194
- rightChange(value) {
195
- this.rangeChange(value, "right");
196
- },
197
- rangeChange(value, type) {
198
- let valueInOtherRange = this.checkValueInOtherRange(value, this.otherConditions);
199
- let usableRanges = this.getUsableRanges();
200
- let firstUsableRange = usableRanges[0];
201
- let valueInRange = this.getSelectedRangeByValue(value, usableRanges);
202
- let currentRange = valueInOtherRange ? firstUsableRange : valueInRange;
203
- let min = valueInOtherRange ? firstUsableRange[0] : _.get(valueInRange, 'min', 0);
204
- let max = valueInOtherRange ? firstUsableRange[1] : _.get(currentRange, 'max', this.totalScore);
205
- if (valueInOtherRange) {
206
- this.$Message.error("该值在其他区间范围内,请重新输入");
207
- this.$set(this.value, "minScore", min);
208
- this.$set(this.value, "maxScore", max);
209
- this.rightMin = min;
210
- this.rightMax = max;
211
- this.leftMin = min;
212
- this.leftMax = max;
213
- } else {
214
- if (type == "left") {
215
- this.rightMin = value + 1;
216
- this.rightMax = max;
217
- }
218
- if (type == "right") {
219
- this.leftMin = min;
220
- this.leftMax = value - 1;
221
- }
222
- }
223
- },
224
175
  getSelectedRangeByValue(value, ranges) {
225
176
  let otherRange = _.map(ranges, (item) => {
226
177
  return {
@@ -228,9 +179,11 @@ export default Vue.extend({
228
179
  max: _.get(item, "payload.maxScore"),
229
180
  };
230
181
  });
231
- return _.head(_.filter(otherRange, function (o) {
232
- return value > o.min && value < o.max;
233
- }));
182
+ return _.head(
183
+ _.filter(otherRange, function (o) {
184
+ return value > o.min && value < o.max;
185
+ })
186
+ );
234
187
  },
235
188
  getUsableRanges() {
236
189
  let usedRange = _.map(this.otherConditions, (item) => {
@@ -241,11 +194,15 @@ export default Vue.extend({
241
194
  // arr must sorted asc
242
195
  let usableRange = new Array();
243
196
  if (usedRange.length == 1) {
244
- let first = usedRange[0][0] -1
197
+ let first = usedRange[0][0] - 1;
245
198
  if (usedRange[0][0] !== 0) {
246
- let item = [0, first]
247
- usableRange.push(item)
199
+ let item = [0, first];
200
+ usableRange.push(item);
248
201
  }
202
+ if (usedRange[length - 1][1] != globalMax) {
203
+ usableRange.push([usedRange[length - 1][1], globalMax]);
204
+ }
205
+ return usableRange;
249
206
  } else {
250
207
  let other = usedRange.reduce((a, v) => {
251
208
  if (typeof a[0] == "number") {
@@ -270,10 +227,40 @@ export default Vue.extend({
270
227
  if (usedRange[length - 1][1] != globalMax) {
271
228
  other.push([usedRange[length - 1][1], globalMax]);
272
229
  }
230
+ return other;
231
+ }
232
+ },
233
+ disabledScoreOption(value, type) {
234
+ if (this.checkValueInOtherRange(value)) {
235
+ return true;
236
+ }
237
+ let currentMin = _.get(this.value, "minScore", 0);
238
+ let currentMax = _.get(this.value, "maxScore", this.totalScore);
239
+ _.get(this.value, "maxScore", this.totalScore);
240
+ if (type == "left" && value >= currentMax) {
241
+ return true;
242
+ }
243
+ if (type == "right" && value <= currentMin) {
244
+ return true;
273
245
  }
274
- return usableRange;
275
246
  },
276
- }
247
+ checkValueInOtherRange(value) {
248
+ let otherRange = _.map(this.otherConditions, (item) => {
249
+ return {
250
+ min: _.get(item, "payload.minScore", 0),
251
+ max: _.get(item, "payload.maxScore", 0),
252
+ };
253
+ });
254
+ return _.some(otherRange, function (o) {
255
+ return value >= o.min && value <= o.max;
256
+ });
257
+ },
258
+ generateExpr() {
259
+ let minScore = this.value.minScore;
260
+ let maxScore = this.value.maxScore;
261
+ return `${minScore} ${this.value.leftOperator} score and score ${this.value.rightOperator} ${maxScore}`;
262
+ },
263
+ },
277
264
  });
278
265
  </script>
279
266
  <style scoped lang="less">
@@ -36,7 +36,7 @@
36
36
  components: {Card, Row, Col, Button, Toolbar, SurveyInternalPreviewer},
37
37
  provide() {
38
38
  return {
39
- $rootComponent: this
39
+ $rootComponent: this.$rootComponent
40
40
  };
41
41
  },
42
42
  props: {
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import {VueConstructor as _Vue} from 'vue';
2
2
  import SurveyCreator from './components/survey-creator.vue';
3
+ import QuestionEditDrawer from "./components/editor/question-edit-drawer.vue";
3
4
  import SurveyPreviewer from './components/survey-previewer.vue';
4
5
  import locale from './locale';
5
6
  export class SurveyCreatorOptions {
@@ -14,6 +15,7 @@ export default class SurveyCreatorPlugin {
14
15
  Vue.$surveyLanguage = options.locale;
15
16
  Vue.component('survey-creator', SurveyCreator);
16
17
  Vue.component('survey-previewer', SurveyPreviewer);
18
+ Vue.component("question-edit-drawer", QuestionEditDrawer)
17
19
  }
18
20
  }
19
21
 
@@ -58,6 +58,8 @@ export default {
58
58
  sub_questions: "Sub Question",
59
59
  score: "Score",
60
60
  scores: "Score",
61
+ totalScores: "Total Score",
62
+ selectScore: "Please Input Score",
61
63
  questionRequired: "Required",
62
64
  titleRequiredTip: "Please Input Question Title",
63
65
  scoreRequiredTip: "Score Required",
@@ -144,7 +146,7 @@ export default {
144
146
  other: "Other",
145
147
  assign_template: `{0} questions answer is {1} count {2} {3}`,
146
148
  auto_template: `{0} questions answer is {1}`,
147
- score_template: `总分数范围为:{0}{1}, {2}`,
149
+ score_template: `Total Score Range: {0}{1} Total Score {2}{3}`,
148
150
  },
149
151
  },
150
152
  },
@@ -58,6 +58,8 @@ export default {
58
58
  sub_questions: "子题",
59
59
  score: "分值",
60
60
  scores: "分",
61
+ totalScores: "总分",
62
+ selectScore: "请选择分值",
61
63
  questionRequired: "此题必填",
62
64
  titleRequiredTip: "请填写题目名称",
63
65
  textTitleRequiredTip: "请填写文字说明",
@@ -144,7 +146,7 @@ export default {
144
146
  other: "其他",
145
147
  assign_template: `{0} 项为 {1} {2} {3}项`,
146
148
  auto_template: `{0} 项为 {1}`,
147
- score_template: `总分数范围为: {0}{1}{2}分`,
149
+ score_template: `总分数范围为: {0}{1} 总分 {2}{3}`,
148
150
  },
149
151
  },
150
152
  },