@wg-npm/survey-response 1.78.511900 → 1.78.511938

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.
@@ -1,6 +1,6 @@
1
1
  import Vue from 'vue';
2
2
  import _ from 'lodash';
3
- import { Row, Input as Input$1, Icon, FormItem, CheckboxGroup, Checkbox, Col, RadioGroup, Radio, Tooltip as Tooltip$1, Card, Slider, InputNumber, Form, Message } from 'view-design';
3
+ import { Row, Input as Input$1, Icon, FormItem, CheckboxGroup, Checkbox, Col, RadioGroup, Radio, InputNumber, Tooltip as Tooltip$1, Card, Slider, Form, Message } from 'view-design';
4
4
  import { CUSTOM_INPUT_REG, formatTitle, translate } from '@wg-npm/survey-core';
5
5
  import deepmerge from 'deepmerge';
6
6
 
@@ -3022,7 +3022,7 @@ function setCacheAdd(value) {
3022
3022
  * @name has
3023
3023
  * @memberOf SetCache
3024
3024
  * @param {*} value The value to search for.
3025
- * @returns {boolean} Returns `true` if `value` is found, else `false`.
3025
+ * @returns {number} Returns `true` if `value` is found, else `false`.
3026
3026
  */
3027
3027
  function setCacheHas(value) {
3028
3028
  return this.__data__.has(value);
@@ -16360,6 +16360,8 @@ var defaultLang = {
16360
16360
  noQuestion: "还未添加题目!",
16361
16361
  input_text_limit: "输入项字数不少于{0}字",
16362
16362
  choice_required: "此项必填",
16363
+ matrix_title_score: "分数",
16364
+ matrix_title_score_range_tip: "请输入{0}到{1}之间的分值",
16363
16365
  },
16364
16366
  },
16365
16367
  };
@@ -17133,7 +17135,7 @@ var __vue_staticRenderFns__$5 = [];
17133
17135
 
17134
17136
  var script$7 = Vue.extend({
17135
17137
  name: "matrix",
17136
- mixins: [OptionLayoutMixin],
17138
+ mixins: [OptionLayoutMixin, LocaleMixin],
17137
17139
  inject: ["responseStatus", "$rootComponent"],
17138
17140
  components: {
17139
17141
  FormItem,
@@ -17141,6 +17143,7 @@ var script$7 = Vue.extend({
17141
17143
  Radio,
17142
17144
  Row,
17143
17145
  Col,
17146
+ InputNumber,
17144
17147
  },
17145
17148
  props: {
17146
17149
  question: {
@@ -17171,6 +17174,25 @@ var script$7 = Vue.extend({
17171
17174
  this.initData();
17172
17175
  },
17173
17176
  },
17177
+ computed: {
17178
+ isTitleScoringEnabled() {
17179
+ return !!_.get(this.question, "options.titleScoringEnabled", false);
17180
+ },
17181
+ isTitleRequired() {
17182
+ return !!_.get(this.question, "options.required", false);
17183
+ },
17184
+ isSubRequired() {
17185
+ const opts = this.question.options;
17186
+ return opts.subRequired !== undefined
17187
+ ? !!opts.subRequired
17188
+ : !!opts.required;
17189
+ },
17190
+ answerTitleProp() {
17191
+ return this.isMoreSurvey
17192
+ ? `moreSurveyAnswers[${this.surveyIndex}].answers[${this.index}].titleScore`
17193
+ : `answers[${this.index}].titleScore`;
17194
+ },
17195
+ },
17174
17196
  methods: {
17175
17197
  answerProp(subIndex) {
17176
17198
  return this.isMoreSurvey
@@ -17178,6 +17200,9 @@ var script$7 = Vue.extend({
17178
17200
  : `answers[${this.index}].answer[${subIndex}].answer`;
17179
17201
  },
17180
17202
  initData() {
17203
+ if (this.isTitleScoringEnabled && this.value.titleScore === undefined) {
17204
+ this.$set(this.value, "titleScore", null);
17205
+ }
17181
17206
  let subAnswers = {};
17182
17207
  _.each(this.value.answer, (data) => {
17183
17208
  _.set(subAnswers, data.questionId, data);
@@ -17196,8 +17221,30 @@ var script$7 = Vue.extend({
17196
17221
  this.value.answer.push(_answer);
17197
17222
  });
17198
17223
  },
17224
+ validateTitleScore(rule, value, callback) {
17225
+ if (value === null || value === undefined) {
17226
+ callback();
17227
+ return;
17228
+ }
17229
+ const min = this.question.options.scoreMin;
17230
+ const max = this.question.options.scoreMax;
17231
+ if (min !== null && min !== undefined && value < min) {
17232
+ const tip = this.t("survey_response.question.matrix_title_score_range_tip");
17233
+ callback(new Error(tip.replace("{0}", min).replace("{1}", max)));
17234
+ return;
17235
+ }
17236
+ if (max !== null && max !== undefined && value > max) {
17237
+ const tip = this.t("survey_response.question.matrix_title_score_range_tip");
17238
+ callback(new Error(tip.replace("{0}", min).replace("{1}", max)));
17239
+ return;
17240
+ }
17241
+ callback();
17242
+ },
17199
17243
  selChange() {
17200
17244
  let score = 0;
17245
+ if (this.isTitleScoringEnabled && this.value.titleScore != null) {
17246
+ score += parseFloat(this.value.titleScore) || 0;
17247
+ }
17201
17248
  _.each(this.value.answer, (sub_answer, index) => {
17202
17249
  _.each(this.question.choices, (choice) => {
17203
17250
  if (choice.id == sub_answer.answer) {
@@ -17214,6 +17261,7 @@ var script$7 = Vue.extend({
17214
17261
  this.value.answer[subIndex].answer = _.isEmpty(subAnswer)
17215
17262
  ? subValue
17216
17263
  : subAnswer;
17264
+ this.selChange();
17217
17265
  }
17218
17266
  },
17219
17267
  },
@@ -17223,26 +17271,33 @@ var script$7 = Vue.extend({
17223
17271
  const __vue_script__$7 = script$7;
17224
17272
 
17225
17273
  /* template */
17226
- var __vue_render__$6 = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',_vm._l((_vm.question.subQuestions),function(subQuestion,subIndex){return _c('div',{key:subIndex,staticClass:"sub-question"},[_c('span',{staticClass:"number"},[_vm._v("\n "+_vm._s(_vm.question.header.number)+"-"+_vm._s(subQuestion.number)+".")]),_vm._v(" "),_c('span',{staticClass:"title"},[_vm._v(" "+_vm._s(_vm.i18nText(subQuestion.text))+" ")]),_vm._v(" "),_c('FormItem',{attrs:{"prop":_vm.answerProp(subIndex),"rules":{
17227
- required: _vm.question.options.required && !_vm.question.options.disabled,
17274
+ var __vue_render__$6 = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',[(_vm.isTitleScoringEnabled)?_c('div',{staticClass:"title-score-section"},[_c('FormItem',{attrs:{"prop":_vm.answerTitleProp,"rules":[
17275
+ {
17276
+ required: _vm.isTitleRequired && !_vm.question.options.disabled,
17277
+ message: _vm.t('survey_response.question.question_required'),
17278
+ },
17279
+ { validator: _vm.validateTitleScore } ]}},[_c('div',{staticClass:"title-score-input-row"},[_c('span',{staticClass:"title-score-label"},[_vm._v(_vm._s(_vm.t('survey_response.question.matrix_title_score'))+":")]),_vm._v(" "),_c('InputNumber',{attrs:{"min":_vm.question.options.scoreMin != null ? _vm.question.options.scoreMin : 0,"max":_vm.question.options.scoreMax != null ? _vm.question.options.scoreMax : (_vm.question.options.score || 100),"disabled":_vm.question.options.disabled},on:{"on-change":_vm.selChange},model:{value:(_vm.value.titleScore),callback:function ($$v) {_vm.$set(_vm.value, "titleScore", $$v);},expression:"value.titleScore"}})],1)])],1):_vm._e(),_vm._v(" "),_vm._l((_vm.question.subQuestions),function(subQuestion,subIndex){return _c('div',{key:subIndex,staticClass:"sub-question"},[(_vm.isSubRequired)?_c('label',{staticClass:"require-label"},[_vm._v("*")]):_vm._e(),_vm._v(" "),_c('span',{staticClass:"number"},[_vm._v("\n "+_vm._s(_vm.question.header.number)+"-"+_vm._s(subQuestion.number)+".")]),_vm._v(" "),_c('span',{staticClass:"title"},[_vm._v(" "+_vm._s(_vm.i18nText(subQuestion.text))+" ")]),_vm._v(" "),_c('FormItem',{attrs:{"prop":_vm.answerProp(subIndex),"rules":{
17280
+ required: _vm.isSubRequired && !_vm.question.options.disabled,
17228
17281
  message: _vm.t('survey_response.question.question_required'),
17229
17282
  }}},[_c('RadioGroup',{on:{"on-change":_vm.selChange},model:{value:(_vm.value.answer[subIndex].answer),callback:function ($$v) {_vm.$set(_vm.value.answer[subIndex], "answer", $$v);},expression:"value.answer[subIndex].answer"}},[_c('Row',{attrs:{"type":"flex","justify":"start","gutter":60}},_vm._l((_vm.question.choices),function(choice){return _c('Col',{key:choice.id,class:_vm.optionLayout},[_c('Radio',{key:choice.id,attrs:{"label":choice.id,"disabled":subQuestion.options.readonly || _vm.question.options.disabled},nativeOn:{"click":function($event){return _vm.toggleAnswer(
17230
17283
  choice.id,
17231
17284
  subIndex,
17232
17285
  subQuestion.options.readonly || _vm.question.options.disabled
17233
- )}}},[_c('span',[_vm._v(_vm._s(_vm.i18nText(choice.text)))])])],1)}),1)],1)],1)],1)}),0)};
17286
+ )}}},[_c('span',[_vm._v(_vm._s(_vm.i18nText(choice.text)))])])],1)}),1)],1)],1)],1)})],2)};
17234
17287
  var __vue_staticRenderFns__$6 = [];
17235
17288
 
17236
17289
  /* style */
17237
- const __vue_inject_styles__$7 = undefined;
17290
+ const __vue_inject_styles__$7 = function (inject) {
17291
+ if (!inject) return
17292
+ inject("data-v-02dfeb56_0", { source: ".require-label[data-v-02dfeb56]{color:#ed4014}.title-score-section[data-v-02dfeb56]{margin-bottom:12px}.title-score-section .title-score-input-row[data-v-02dfeb56]{display:flex;align-items:center;gap:8px}.title-score-section .title-score-input-row .title-score-label[data-v-02dfeb56]{font-size:14px;color:#515a6e;white-space:nowrap}", map: undefined, media: undefined });
17293
+
17294
+ };
17238
17295
  /* scoped */
17239
- const __vue_scope_id__$7 = undefined;
17296
+ const __vue_scope_id__$7 = "data-v-02dfeb56";
17240
17297
  /* module identifier */
17241
17298
  const __vue_module_identifier__$7 = undefined;
17242
17299
  /* functional template */
17243
17300
  const __vue_is_functional_template__$7 = false;
17244
- /* style inject */
17245
-
17246
17301
  /* style inject SSR */
17247
17302
 
17248
17303
  /* style inject shadow dom */
@@ -17257,7 +17312,7 @@ var __vue_staticRenderFns__$6 = [];
17257
17312
  __vue_is_functional_template__$7,
17258
17313
  __vue_module_identifier__$7,
17259
17314
  false,
17260
- undefined,
17315
+ createInjector,
17261
17316
  undefined,
17262
17317
  undefined
17263
17318
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wg-npm/survey-response",
3
- "version": "1.78.511900",
3
+ "version": "1.78.511938",
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": "1.78.511900",
16
- "@wg-npm/survey-service-api": "1.78.511900",
15
+ "@wg-npm/survey-core": "1.78.511938",
16
+ "@wg-npm/survey-service-api": "1.78.511938",
17
17
  "axios": "^0.19.2",
18
18
  "deepmerge": "^4.2.2",
19
19
  "lodash": "^4.17.15",
@@ -34,8 +34,8 @@
34
34
  "@typescript-eslint/parser": "^3.6.0",
35
35
  "@vue/eslint-config-prettier": "^6.0.0",
36
36
  "@vue/eslint-config-typescript": "^5.0.2",
37
- "@wg-npm/survey-core": "1.78.511900",
38
- "@wg-npm/survey-service-api": "1.78.511900",
37
+ "@wg-npm/survey-core": "1.78.511938",
38
+ "@wg-npm/survey-service-api": "1.78.511938",
39
39
  "acorn": "^7.3.1",
40
40
  "axios": "^0.19.2",
41
41
  "babelrc-rollup": "^3.0.0",
@@ -72,7 +72,7 @@
72
72
  "publishConfig": {
73
73
  "access": "public"
74
74
  },
75
- "gitHead": "51b5c6a6eff6f9ff420a037e671ffb4fe3bf3ed2",
75
+ "gitHead": "ad10a00e012ea9db36e51202b7a24265681d8630",
76
76
  "rollup": {
77
77
  "external": [
78
78
  "vue",
@@ -1,10 +1,36 @@
1
1
  <template>
2
2
  <div>
3
+ <!-- Main title score input (when titleScoringEnabled) -->
4
+ <div v-if="isTitleScoringEnabled" class="title-score-section">
5
+ <FormItem
6
+ :prop="answerTitleProp"
7
+ :rules="[
8
+ {
9
+ required: isTitleRequired && !question.options.disabled,
10
+ message: t('survey_response.question.question_required'),
11
+ },
12
+ { validator: validateTitleScore },
13
+ ]"
14
+ >
15
+ <div class="title-score-input-row">
16
+ <span class="title-score-label">{{ t('survey_response.question.matrix_title_score') }}:</span>
17
+ <InputNumber
18
+ v-model="value.titleScore"
19
+ :min="question.options.scoreMin != null ? question.options.scoreMin : 0"
20
+ :max="question.options.scoreMax != null ? question.options.scoreMax : (question.options.score || 100)"
21
+ :disabled="question.options.disabled"
22
+ @on-change="selChange"
23
+ />
24
+ </div>
25
+ </FormItem>
26
+ </div>
27
+
3
28
  <div
4
29
  v-for="(subQuestion, subIndex) in question.subQuestions"
5
30
  :key="subIndex"
6
31
  class="sub-question"
7
32
  >
33
+ <label v-if="isSubRequired" class="require-label">*</label>
8
34
  <span class="number">
9
35
  {{ question.header.number }}-{{ subQuestion.number }}.</span
10
36
  >
@@ -12,7 +38,7 @@
12
38
  <FormItem
13
39
  :prop="answerProp(subIndex)"
14
40
  :rules="{
15
- required: question.options.required && !question.options.disabled,
41
+ required: isSubRequired && !question.options.disabled,
16
42
  message: t('survey_response.question.question_required'),
17
43
  }"
18
44
  >
@@ -54,11 +80,12 @@
54
80
  import Vue from "vue";
55
81
  import _ from "lodash";
56
82
  import OptionLayoutMixin from "../../../mixins/option-layout-mixin";
57
- import { FormItem, RadioGroup, Radio, Row, Col } from "view-design";
83
+ import LocaleMixin from "../../../mixins/locale-mixin";
84
+ import { FormItem, RadioGroup, Radio, Row, Col, InputNumber } from "view-design";
58
85
 
59
86
  export default Vue.extend({
60
87
  name: "matrix",
61
- mixins: [OptionLayoutMixin],
88
+ mixins: [OptionLayoutMixin, LocaleMixin],
62
89
  inject: ["responseStatus", "$rootComponent"],
63
90
 
64
91
  components: {
@@ -67,6 +94,7 @@ export default Vue.extend({
67
94
  Radio,
68
95
  Row,
69
96
  Col,
97
+ InputNumber,
70
98
  },
71
99
  props: {
72
100
  question: {
@@ -97,6 +125,28 @@ export default Vue.extend({
97
125
  this.initData();
98
126
  },
99
127
  },
128
+ computed: {
129
+ isTitleScoringEnabled() {
130
+ // @ts-ignore
131
+ return !!_.get(this.question, "options.titleScoringEnabled", false);
132
+ },
133
+ isTitleRequired() {
134
+ // @ts-ignore
135
+ return !!_.get(this.question, "options.required", false);
136
+ },
137
+ isSubRequired() {
138
+ const opts = this.question.options;
139
+ // subRequired is the new field; fall back to required for backward compat
140
+ return opts.subRequired !== undefined
141
+ ? !!opts.subRequired
142
+ : !!opts.required;
143
+ },
144
+ answerTitleProp() {
145
+ return this.isMoreSurvey
146
+ ? `moreSurveyAnswers[${this.surveyIndex}].answers[${this.index}].titleScore`
147
+ : `answers[${this.index}].titleScore`;
148
+ },
149
+ },
100
150
  methods: {
101
151
  answerProp(subIndex) {
102
152
  return this.isMoreSurvey
@@ -104,6 +154,11 @@ export default Vue.extend({
104
154
  : `answers[${this.index}].answer[${subIndex}].answer`;
105
155
  },
106
156
  initData() {
157
+ // Init main title score field
158
+ if (this.isTitleScoringEnabled && this.value.titleScore === undefined) {
159
+ this.$set(this.value, "titleScore", null);
160
+ }
161
+
107
162
  let subAnswers = {};
108
163
  // @ts-ignore
109
164
  _.each(this.value.answer, (data) => {
@@ -128,8 +183,33 @@ export default Vue.extend({
128
183
  this.value.answer.push(_answer);
129
184
  });
130
185
  },
186
+ validateTitleScore(rule, value, callback) {
187
+ if (value === null || value === undefined) {
188
+ callback();
189
+ return;
190
+ }
191
+ const min = this.question.options.scoreMin;
192
+ const max = this.question.options.scoreMax;
193
+ if (min !== null && min !== undefined && value < min) {
194
+ const tip = this.t("survey_response.question.matrix_title_score_range_tip");
195
+ callback(new Error(tip.replace("{0}", min).replace("{1}", max)));
196
+ return;
197
+ }
198
+ if (max !== null && max !== undefined && value > max) {
199
+ const tip = this.t("survey_response.question.matrix_title_score_range_tip");
200
+ callback(new Error(tip.replace("{0}", min).replace("{1}", max)));
201
+ return;
202
+ }
203
+ callback();
204
+ },
205
+
131
206
  selChange() {
132
207
  let score = 0;
208
+ // Add main title score
209
+ if (this.isTitleScoringEnabled && this.value.titleScore != null) {
210
+ score += parseFloat(this.value.titleScore) || 0;
211
+ }
212
+ // Add sub-question choice scores
133
213
  // @ts-ignore
134
214
  _.each(this.value.answer, (sub_answer, index) => {
135
215
  // @ts-ignore
@@ -150,8 +230,31 @@ export default Vue.extend({
150
230
  this.value.answer[subIndex].answer = _.isEmpty(subAnswer)
151
231
  ? subValue
152
232
  : subAnswer;
233
+ this.selChange();
153
234
  }
154
235
  },
155
236
  },
156
237
  });
157
238
  </script>
239
+
240
+ <style scoped lang="less">
241
+ .require-label {
242
+ color: #ed4014;
243
+ }
244
+
245
+ .title-score-section {
246
+ margin-bottom: 12px;
247
+
248
+ .title-score-input-row {
249
+ display: flex;
250
+ align-items: center;
251
+ gap: 8px;
252
+
253
+ .title-score-label {
254
+ font-size: 14px;
255
+ color: #515a6e;
256
+ white-space: nowrap;
257
+ }
258
+ }
259
+ }
260
+ </style>
@@ -28,6 +28,8 @@ export default {
28
28
  input_text_limit:
29
29
  "The number of characters in the entry should not be less than{0}",
30
30
  choice_required: "This item is required",
31
+ matrix_title_score: "Score",
32
+ matrix_title_score_range_tip: "Please enter a value between {0} and {1}",
31
33
  },
32
34
  },
33
35
  };
@@ -26,6 +26,8 @@ export default {
26
26
  noQuestion: "还未添加题目!",
27
27
  input_text_limit: "输入项字数不少于{0}字",
28
28
  choice_required: "此项必填",
29
+ matrix_title_score: "分数",
30
+ matrix_title_score_range_tip: "请输入{0}到{1}之间的分值",
29
31
  },
30
32
  },
31
33
  };