@wg-npm/survey-creator 0.3.47 → 0.3.377-8.develop

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,181 +1,269 @@
1
1
  <template>
2
- <Card dis-hover>
3
- <Row type="flex" :gutter="6" slot="title">
4
- <Col>
5
- <div class="text">
6
- {{t('survey_creator.question.evaluation.condition.if') }}
7
- </div>
8
- </Col>
9
- <Col>
10
- <Button type="primary" icon="md-add" @click="onAdd">
11
- {{t('survey_creator.question.evaluation.condition.add_if_template') }}
12
- </Button>
13
- </Col>
14
- </Row>
15
- <a href="#" slot="extra" @click.prevent="onDelete" v-show="deletable">
16
- {{t('survey_creator.common.delete') }}
17
- </a>
2
+ <Card dis-hover>
3
+ <Row type="flex" :gutter="6" slot="title">
4
+ <Col>
5
+ <div class="text">
6
+ {{ t("survey_creator.question.evaluation.condition.if") }}
7
+ </div>
8
+ </Col>
9
+ <Col>
10
+ <Button type="primary" icon="md-add" @click="onAdd">
11
+ {{
12
+ t("survey_creator.question.evaluation.condition.add_if_template")
13
+ }}
14
+ </Button>
15
+ </Col>
16
+ </Row>
17
+ <a href="#" slot="extra" @click.prevent="onDelete" v-show="deletable">
18
+ {{ t("survey_creator.common.delete") }}
19
+ </a>
20
+ <Row type="flex" justify="start" align="middle">
21
+ <Col :span="22">
18
22
  <Row type="flex" justify="start" align="middle">
19
- <Col :span="22">
20
- <Row type="flex" justify="start" align="middle">
21
- <Col class="label">
22
- <Icon type="ios-arrow-forward" color="#2d8cf0"/>
23
- {{t('survey_creator.question.evaluation.condition.requirements') }}
24
- </Col>
25
- <Col :span="16">
26
- <Select v-model="exprConditionType">
27
- <Option v-for="type in exprConditionTypes" :value="type" :key="type">
28
- {{ t(`survey_creator.question.evaluation.condition.type.${type}`) }}
29
- </Option>
30
- </Select>
31
- </Col>
32
- </Row>
33
- </Col>
34
- <Col :span="2">
35
- <Button icon="md-add" class="action" @click="addCondition"></Button>
36
- </Col>
37
- </Row>
38
- <Row type="flex" justify="space-between" align="middle"
39
- v-for="(condition, index) in evaluationItems[position].conditions" :key="index" class="mt-base">
40
- <Col :span="22">
41
- <condition :key="index" :index="index" :type="condition.type" v-model="condition.payload" @expr="expr"
42
- :question="question" :evaluation-items="evaluationItems" :item-index="position"/>
43
- </Col>
44
- <Col :span="2">
45
- <Button icon="md-remove" class="action" style="margin-bottom: 24px;"
46
- @click="removeCondition(index)"></Button>
47
- </Col>
23
+ <Col class="label">
24
+ <Icon type="ios-arrow-forward" color="#2d8cf0" />
25
+ {{ t("survey_creator.question.evaluation.condition.requirements") }}
26
+ </Col>
27
+ <Col :span="16">
28
+ <Select v-model="exprConditionType">
29
+ <Option
30
+ v-for="type in exprConditionTypes"
31
+ :value="type"
32
+ :key="type"
33
+ >
34
+ {{
35
+ t(`survey_creator.question.evaluation.condition.type.${type}`)
36
+ }}
37
+ </Option>
38
+ </Select>
39
+ </Col>
48
40
  </Row>
49
- <Row type="flex" justify="end" align="middle" class="mt-base">
50
- <Col>
51
- <FormItem
52
- :prop="'evaluationItems[' + position + '].text.' + primaryLanguage"
53
- :rules="{required: true, message: t('survey_creator.question.evaluation.condition.evaluation_require_tip')}"
54
- >{{t('survey_creator.question.evaluation.condition.evaluation_label') }}
55
- <Input class="input" v-model.trim="evaluationItems[position].text[primaryLanguage]"/>
56
- </FormItem>
57
- </Col>
58
- </Row>
59
- </Card>
41
+ </Col>
42
+ <Col :span="2">
43
+ <Button
44
+ icon="md-add"
45
+ :disabled="disableAddConditionBtn"
46
+ class="action"
47
+ @click="addCondition"
48
+ ></Button>
49
+ </Col>
50
+ </Row>
51
+ <Row
52
+ type="flex"
53
+ justify="space-between"
54
+ align="middle"
55
+ v-for="(condition, index) in evaluationItems[position].conditions"
56
+ :key="index"
57
+ class="mt-base"
58
+ >
59
+ <Col :span="22">
60
+ <condition
61
+ :key="index"
62
+ :index="index"
63
+ :type="condition.type"
64
+ v-model="condition.payload"
65
+ @expr="expr"
66
+ :question="question"
67
+ :evaluation-items="evaluationItems"
68
+ :item-index="position"
69
+ />
70
+ </Col>
71
+ <Col :span="2">
72
+ <Button
73
+ icon="md-remove"
74
+ class="action"
75
+ style="margin-bottom: 24px"
76
+ @click="removeCondition(index)"
77
+ ></Button>
78
+ </Col>
79
+ </Row>
80
+ <Row type="flex" justify="end" align="middle" class="mt-base">
81
+ <Col>
82
+ <FormItem
83
+ :prop="'evaluationItems[' + position + '].text.' + primaryLanguage"
84
+ :rules="{
85
+ required: true,
86
+ message: t(
87
+ 'survey_creator.question.evaluation.condition.evaluation_require_tip'
88
+ ),
89
+ }"
90
+ >{{
91
+ t("survey_creator.question.evaluation.condition.evaluation_label")
92
+ }}
93
+ <Input
94
+ class="input"
95
+ v-model.trim="evaluationItems[position].text[primaryLanguage]"
96
+ />
97
+ </FormItem>
98
+ </Col>
99
+ </Row>
100
+ </Card>
60
101
  </template>
61
102
  <script lang="ts">
62
- import Vue from "vue";
63
- import QuestionFormMixin from "../../../../../mixins/question-form-mixin";
64
- import {
65
- ExprConditionType,
66
- ExprEvaluationItemType
67
- } from "@wg-npm/survey-core/src/models";
68
- import {Card, Row, Col, Button, Select, Option, Icon, FormItem, Input} from "view-design";
69
- import Condition from "./condition.vue"
70
- import _ from "lodash";
103
+ import Vue from "vue";
104
+ import QuestionFormMixin from "../../../../../mixins/question-form-mixin";
105
+ import {
106
+ ExprConditionType,
107
+ ExprEvaluationItemType,
108
+ } from "@wg-npm/survey-core/src/models";
109
+ import {
110
+ Card,
111
+ Row,
112
+ Col,
113
+ Button,
114
+ Select,
115
+ Option,
116
+ Icon,
117
+ FormItem,
118
+ Input,
119
+ } from "view-design";
120
+ import Condition from "./condition.vue";
121
+ import _ from "lodash";
71
122
 
72
- export default Vue.extend({
73
- name: "if",
74
- mixins: [QuestionFormMixin],
75
- components: {
76
- Card,
77
- Row,
78
- Col,
79
- Select,
80
- Option,
81
- Button,
82
- Icon,
83
- Condition,
84
- FormItem,
85
- Input
86
- },
87
- props: {
88
- value: {
89
- type: Array,
90
- required: true
91
- },
92
- position: {
93
- type: Number,
94
- required: true
95
- }
123
+ export default Vue.extend({
124
+ name: "if",
125
+ mixins: [QuestionFormMixin],
126
+ components: {
127
+ Card,
128
+ Row,
129
+ Col,
130
+ Select,
131
+ Option,
132
+ Button,
133
+ Icon,
134
+ Condition,
135
+ FormItem,
136
+ Input,
137
+ },
138
+ props: {
139
+ value: {
140
+ type: Array,
141
+ required: true,
142
+ },
143
+ position: {
144
+ type: Number,
145
+ required: true,
146
+ },
147
+ },
148
+ data() {
149
+ return {
150
+ evaluationItems: this.value,
151
+ exprConditionType: ExprConditionType.AUTO,
152
+ exprConditionTypes: [
153
+ ExprConditionType.AUTO,
154
+ ExprConditionType.ASSIGN,
155
+ ExprConditionType.SCORE,
156
+ ],
157
+ };
158
+ },
159
+ computed: {
160
+ deletable() {
161
+ return (
162
+ _.size(
163
+ _.filter(
164
+ this.evaluationItems,
165
+ (item) => item.type == ExprEvaluationItemType.IF
166
+ )
167
+ ) > 1
168
+ );
169
+ },
170
+ disableAddConditionBtn() {
171
+ let conditions = this.evaluationItems[this.position].conditions;
172
+ let scoreConditions = _.size(
173
+ _.filter(conditions, (item) => item.type == ExprConditionType.SCORE)
174
+ );
175
+ return (
176
+ this.exprConditionType == ExprConditionType.SCORE && scoreConditions > 0
177
+ );
178
+ },
179
+ },
180
+ methods: {
181
+ onAdd() {
182
+ this.evaluationItems.splice(this.position + 1, 0, {
183
+ id: `Evaluation-Item-${_.now()}-${_.random(0, 9999999)}`,
184
+ type: ExprEvaluationItemType.IF,
185
+ text: {
186
+ "zh-CN": "",
96
187
  },
97
- data() {
98
- return {
99
- evaluationItems: this.value,
100
- exprConditionType: ExprConditionType.AUTO,
101
- exprConditionTypes: [ExprConditionType.AUTO, ExprConditionType.ASSIGN]
102
- };
188
+ conditions: [],
189
+ });
190
+ },
191
+ onDelete() {
192
+ this.evaluationItems.splice(this.position, 1);
193
+ },
194
+ addCondition() {
195
+ this.evaluationItems[this.position].conditions ||
196
+ this.$set(this.evaluationItems[this.position], "conditions", []);
197
+ this.evaluationItems[this.position].conditions.push({
198
+ type: this.exprConditionType,
199
+ payload: this.buildPayloadByType(this.exprConditionType),
200
+ });
201
+ },
202
+ buildPayloadByType(type) {
203
+ if (type == ExprConditionType.SCORE) {
204
+ return {
205
+ payload: {
206
+ minScore: 0,
207
+ operator: "<",
208
+ maxScore: 0,
209
+ },
210
+ };
211
+ }
212
+ return {
213
+ payload: {
214
+ scope: [],
215
+ operator: "=",
216
+ values: [],
217
+ size: 0,
103
218
  },
104
- computed: {
105
- deletable() {
106
- return _.size(_.filter(this.evaluationItems, item => item.type == ExprEvaluationItemType.IF)) > 1;
107
- }
108
- },
109
- methods: {
110
- onAdd() {
111
- this.evaluationItems.splice(this.position + 1, 0, {
112
- "id": `Evaluation-Item-${_.now()}-${_.random(0, 9999999)}`,
113
- "type": ExprEvaluationItemType.IF,
114
- "text": {
115
- "zh-CN": ""
116
- },
117
- "conditions": []
118
- });
119
- },
120
- onDelete() {
121
- this.evaluationItems.splice(this.position, 1);
122
- },
123
- addCondition() {
124
- this.evaluationItems[this.position].conditions || this.$set(this.evaluationItems[this.position], "conditions", []);
125
- this.evaluationItems[this.position].conditions.push({
126
- type: this.exprConditionType,
127
- payload: {
128
- scope: [],
129
- operator: "=",
130
- values: [],
131
- size: 0
132
-
133
- }
134
- });
135
- },
136
- removeCondition(index) {
137
- this.evaluationItems[this.position].conditions.splice(index, 1);
138
- },
139
- expr(index, value) {
140
- _.set(this.evaluationItems[this.position].conditions[index], "expr", value);
141
- }
142
- }
143
- })
219
+ };
220
+ },
221
+ removeCondition(index) {
222
+ this.evaluationItems[this.position].conditions.splice(index, 1);
223
+ },
224
+ expr(index, value) {
225
+ _.set(
226
+ this.evaluationItems[this.position].conditions[index],
227
+ "expr",
228
+ value
229
+ );
230
+ },
231
+ },
232
+ });
144
233
  </script>
145
234
  <style scoped lang="less">
146
- .mt-base {
147
- margin-top: 12px;
148
- }
149
-
150
- .action {
151
- float: right;
152
- }
235
+ .mt-base {
236
+ margin-top: 12px;
237
+ }
153
238
 
154
- .input {
155
- width: 100px;
156
- }
239
+ .action {
240
+ float: right;
241
+ }
157
242
 
158
- .label {
159
- text-align: right;
160
- padding-right: 4px;
161
- }
243
+ .input {
244
+ width: 100px;
245
+ }
162
246
 
163
- .text {
164
- background-color: #ebf7ff;
165
- height: 32px;
166
- padding: 8px 18px;
167
- font-weight: 500;
168
- color: #515a6e;
169
- }
247
+ .label {
248
+ text-align: right;
249
+ padding-right: 4px;
250
+ }
170
251
 
171
- /deep/ .ivu-card .ivu-form-item {
172
- margin-bottom: 4px;
173
- margin-top: 0;
174
- }
252
+ .text {
253
+ background-color: #ebf7ff;
254
+ height: 32px;
255
+ padding: 8px 18px;
256
+ font-weight: 500;
257
+ color: #515a6e;
258
+ }
175
259
 
176
- /deep/ .ivu-card .ivu-form-item-error {
177
- margin-bottom: 24px;
178
- margin-top: 0;
260
+ /deep/ .ivu-card .ivu-form-item {
261
+ margin-bottom: 4px;
262
+ margin-top: 0;
263
+ }
179
264
 
180
- }
265
+ /deep/ .ivu-card .ivu-form-item-error {
266
+ margin-bottom: 24px;
267
+ margin-top: 0;
268
+ }
181
269
  </style>
@@ -0,0 +1,135 @@
1
+ <template>
2
+ <Row type="flex" justify="start" :gutter="6" align="middle">
3
+ <Col class="label">
4
+ {{
5
+ t("survey_creator.question.evaluation.condition.score_condition_title")
6
+ }}
7
+ </Col>
8
+ <Col :span="3">
9
+ <FormItem
10
+ :prop="`evaluationItems[${itemIndex}].conditions[${index}].payload.minScore`"
11
+ :rules="{
12
+ required: true,
13
+ type: 'number',
14
+ trigger: 'change',
15
+ min: 0,
16
+ max: this.totalScore,
17
+ message: t('分值不能为空'),
18
+ }"
19
+ >
20
+ <InputNumber
21
+ v-model="value.minScore"
22
+ :min="0"
23
+ :max="value.maxScore"
24
+ @on-change="rangeChange"
25
+ ></InputNumber>
26
+ </FormItem>
27
+ </Col>
28
+ <Col class="label">
29
+ {{ t("survey_creator.question.scores") }}
30
+ </Col>
31
+ <Col :span="3">
32
+ <FormItem
33
+ :prop="`evaluationItems[${itemIndex}].conditions[${index}].payload.operator`"
34
+ :rules="{
35
+ required: true,
36
+ trigger: 'change',
37
+ message: t('survey_creator.question.notEmpty'),
38
+ }"
39
+ >
40
+ <Select
41
+ v-model="value.operator"
42
+ :placeholder="
43
+ t('survey_creator.question.evaluation.condition.operator')
44
+ "
45
+ >
46
+ <Option
47
+ v-for="(operator, index) in operators"
48
+ :value="operator"
49
+ :key="index"
50
+ >
51
+ {{ operator }}
52
+ </Option>
53
+ </Select>
54
+ </FormItem>
55
+ </Col>
56
+ <Col :span="3">
57
+ <FormItem
58
+ :prop="`evaluationItems[${itemIndex}].conditions[${index}].payload.maxScore`"
59
+ :rules="{
60
+ required: true,
61
+ type: 'number',
62
+ trigger: 'change',
63
+ min: 0,
64
+ max: this.totalScore,
65
+ message: t('分值不能为空'),
66
+ }"
67
+ >
68
+ <InputNumber
69
+ v-model="value.maxScore"
70
+ :min="value.minScore"
71
+ :max="totalScore"
72
+ @on-change="rangeChange"
73
+ ></InputNumber>
74
+ </FormItem>
75
+ </Col>
76
+ <Col class="label">
77
+ {{ t("survey_creator.question.scores") }}
78
+ </Col>
79
+ </Row>
80
+ </template>
81
+ <script lang="ts">
82
+ import Vue from "vue";
83
+ import { Row, Col, Select, Option, FormItem, InputNumber } from "view-design";
84
+ import _ from "lodash";
85
+ import ExprMixin from "./expr-mixin";
86
+ import LocaleMixin from "../../../../../mixins/locale-mixin";
87
+
88
+ export default Vue.extend({
89
+ name: "score",
90
+ mixins: [ExprMixin, LocaleMixin],
91
+ components: {
92
+ Row,
93
+ Col,
94
+ Select,
95
+ Option,
96
+ FormItem,
97
+ InputNumber,
98
+ },
99
+ data() {
100
+ return {
101
+ operators: ["<=", "<"],
102
+ };
103
+ },
104
+ computed: {
105
+ totalScore() {
106
+ return this.$rootComponent.currentSurvey.statistics.maxScore;
107
+ },
108
+ },
109
+ methods: {
110
+ generateExpr() {
111
+ // let ids = `${_.map(this.value.scope, (e) => {
112
+ // return `"` + e + `"`;
113
+ // })}`;
114
+ // let answers = `${_.map(this.value.values, (e) => {
115
+ // return `"` + e + `"`;
116
+ // })}`;
117
+ // return `$count($[id in [${ids}]][answer in [${answers}]]) = ${_.size(
118
+ // this.value.scope
119
+ // )}`;
120
+ let minScore = this.value.minScore;
121
+ let maxScore = this.value.maxScore;
122
+ return `$totalScore ${minScore} ${this.value.operator} ${maxScore}`;
123
+ },
124
+ rangeChange() {
125
+ console.log("222");
126
+ },
127
+ },
128
+ });
129
+ </script>
130
+ <style scoped lang="less">
131
+ .label {
132
+ text-align: right;
133
+ margin-bottom: 24px;
134
+ }
135
+ </style>
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import Vue from 'vue'
6
6
  import deepmerge from 'deepmerge';
7
- import defaultLang from './lang/en-US'
7
+ import defaultLang from './lang/zh-CN'
8
8
 
9
9
  let lang = defaultLang;
10
10
  let merged = false;