WXL
2025-01-15 3a7caf4344d5911a3ee68d232e53887d6cc2ff6b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
<template>
  <div>
    <div
      class="topicxq"
      v-for="item in TargetoptionList"
      v-if="item.isoperation != 3"
    >
      <el-form :inline="true" :rules="rules" :model="item" label-width="80px">
        <el-row :gutter="10">
          <el-col :span="12"
            ><el-form-item prop="targetvalue" label="选项名称">
              <el-input
                type="text"
                placeholder="请输入(必填项)"
                v-model="item.targetvalue"
                show-word-limit
              >
              </el-input> </el-form-item
          ></el-col>
          <el-col :span="12"
            ><el-form-item label="异常提醒">
              <el-radio-group v-model="item.isabnormal">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
              </el-radio-group>
            </el-form-item></el-col
          >
          <!-- <el-col :span="12" v-if="intent"
            ><el-form-item label="选项节点">
              <el-input
                type="text"
                placeholder="请输入节点"
                v-model="item.targetid"
                show-word-limit
              >
              </el-input> </el-form-item
          ></el-col> -->
        </el-row>
        <el-row :gutter="10" v-if="!intent">
          <el-col :span="20"
            ><el-form-item label="选项说明">
              <el-input
                style="width: 500px"
                type="textarea"
                :rows="2"
                placeholder="请输入"
                v-model="item.optiondesc"
                show-word-limit
              >
              </el-input> </el-form-item
          ></el-col>
        </el-row>
        <el-form-item label="结束对话">
          <el-radio-group v-model="item.isEnd">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
 
        <el-row :gutter="10" v-if="intent">
          <el-col :span="12"
            ><el-form-item label="处理">
              <el-input
                type="text"
                placeholder="(默认)无声"
                v-model="item.text"
                maxlength="10"
                show-word-limit
              >
              </el-input> </el-form-item
          ></el-col>
          <el-col :span="12" v-show="branchFlag"
            ><el-form-item label="选中跳转">
              <el-input
                type="text"
                @blur="$emit('branchFlagfn', item.nextQuestion)"
                placeholder="请输入题目节点"
                v-model="item.nextQuestion"
                show-word-limit
              >
              </el-input> </el-form-item
          ></el-col>
        </el-row>
        <el-row :gutter="10" v-if="scriptType == 1">
          <el-form-item label="选中提示">
            <el-input
              style="width: 24vw"
              type="textarea"
              autosize
              placeholder="请输入内容"
              v-model="item.prompt"
            >
            </el-input
          ></el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="关键字(含)" prop="desc" v-if="hasValue">
            <div class="xinz-inf">
              <el-tag
                :key="crux"
                type="success"
                v-for="crux in item.dynamiccruxs"
                closable
                effect="dark"
                :disable-transitions="false"
                @close="handleClosecrux(crux, item, 1)"
              >
                {{ crux }}
              </el-tag>
              <el-select
                v-model="inputValue"
                v-if="item.inputVisible"
                @change="handleInputConfirm(item)"
                filterable
                remote
                allow-create
                reserve-keyword
                default-first-option
                :loading="loading"
                placeholder="请选择"
              >
                <el-option
                  v-for="items in regular"
                  :key="items.label"
                  :label="items.label"
                  :value="items.label"
                >
                </el-option>
              </el-select>
              <el-button
                v-else
                class="button-new-tag"
                size="small"
                @click="showInput(item)"
                >+ 新增</el-button
              >
            </div>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="关键字(非)" prop="adesc" v-if="hasValue">
            <div class="xinz-inf">
              <el-tag
                :key="crux"
                type="warning"
                v-for="crux in item.nodynamiccruxs"
                closable
                effect="dark"
                :disable-transitions="false"
                @close="handleClosecrux(crux, item, 2)"
              >
                {{ crux }}
              </el-tag>
              <el-select
                v-model="inputValue"
                v-if="item.noinputVisible"
                @change="handleInputConfirm(item)"
                filterable
                remote
                allow-create
                reserve-keyword
                default-first-option
                :loading="loading"
                placeholder="请选择"
              >
                <el-option
                  v-for="items in noregular"
                  :key="items.value"
                  :label="items.label"
                  :value="items.label"
                >
                </el-option>
              </el-select>
              <el-button
                v-else
                class="button-new-tag"
                size="small"
                @click="showInputno(item)"
                >+ 新增</el-button
              >
            </div>
          </el-form-item>
        </el-row>
 
        <el-form-item label="选项文件" prop="sickness" v-if="Verbalproblem">
          <div style="width: 40vw">
            <el-upload
              class="upload-demo"
              :action="uploadImgUrl"
              :headers="headers"
              accept=".jpg,.png,image/*"
              :on-success="handleChange.bind(this, item)"
            >
              <el-button size="small" type="primary">点击上传</el-button>
            </el-upload>
            <div style="margin: 20px">
              <el-image
                style="width: 100px; height: 100px"
                :src="item.picturePath"
                :preview-src-list="[...item.picturePath]"
              >
              </el-image>
            </div>
          </div>
        </el-form-item>
 
        <el-row :gutter="10">
          <el-col>
            <div style="text-align: right; padding-right: 10px">
              <el-button
                v-if="controlsc || addoption"
                @click="$emit('addoption', item)"
                type="success"
                icon="el-icon-circle-plus-outline"
                circle
              ></el-button>
              <el-button
                type="danger"
                icon="el-icon-delete"
                circle
                @click="$emit('deloption', item)"
              ></el-button>
              <el-button
                v-if="controlsc"
                @click="$emit('syioption', item)"
                type="primary"
                icon="el-icon-top"
                circle
              ></el-button>
              <el-button
                v-if="controlsc"
                @click="$emit('xiayioption', item)"
                type="primary"
                icon="el-icon-bottom"
                circle
              ></el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>
 
<script>
import store from "@/store";
import { getToken } from "@/utils/auth";
 
export default {
  data() {
    return {
      zz1: "^(?!.不)(.(我|你|他|可以|是|好|知道|没错)+.*)$",
      zz2: "^(?!.不)(?=.?(我|你|他|可以|是|好|知道|没错)).*$",
      fileList: [
        {
          name: "food.jpeg",
          url: "https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100",
        },
      ],
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/uploadSort",
      whether: 1, //1为关键词,2为否定关键词
      inputValue: "",
      inputVisible: false,
      noinputVisible: false,
      loading: false,
      regular: [],
      noregular: [],
      nodynamiccruxs: ["别", "不"],
      dynamiccruxs: ["好"],
      rules: {
        targetvalue: [
          { required: true, message: "请输入选项名称", trigger: "blur" },
        ],
        isabnormal: [
          { required: true, message: "请输入选项名称", trigger: "blur" },
        ],
      },
    };
  },
  props: {
    TargetoptionList: {
      type: Array,
      required: true,
      default: () => [],
    },
    controlsc: {
      type: Boolean,
      default: true,
    },
    scriptType: {
      type: String,
      default: "1",
    },
    addoption: {
      type: Boolean,
      default: false,
    },
    intent: {
      type: Boolean,
      default: true,
    },
    hasValue: {
      type: Boolean,
      default: true,
    },
    Verbalproblem: {
      type: Boolean,
      default: true,
    },
    branchFlag: {
      type: Boolean,
      default: false,
    },
  },
 
  created() {
    this.regular = store.getters.regular;
    this.noregular = store.getters.noregular;
  },
 
  methods: {
    // 生成正则
    generateRegex(row) {
      let index = this.TargetoptionList.indexOf(row);
      console.log(index);
      let regex = "";
      let regexno = "";
      let hostregex = "";
      let hostregexno = "";
 
      for (
        let i = 0;
        i < this.TargetoptionList[index].dynamiccruxs.length;
        i++
      ) {
        regex += `${this.TargetoptionList[index].dynamiccruxs[i]}|`;
      }
      for (
        let i = 0;
        i < this.TargetoptionList[index].nodynamiccruxs.length;
        i++
      ) {
        regexno += `${this.TargetoptionList[index].nodynamiccruxs[i]}|`;
      }
      regex = regex.slice(0, -1);
      regexno = regexno.slice(0, -1);
      if (regexno) {
        hostregexno = "^(?!.*(?:" + `${regexno}` + ")).*$";
      } else {
        hostregexno = "";
      }
      hostregex = "(?=.*(?:" + `${regex}` + ")).*$";
      this.TargetoptionList[index].targetregex = hostregex;
      this.TargetoptionList[index].targetregex2 = hostregexno;
      console.log(hostregex, "确定字匹配");
      console.log(hostregexno, "否定字匹配");
      this.handleSelectionChange();
    },
    // 控制文件
    // handleChange(file, fileList) {
    //   this.fileList = fileList.slice(-3);
    // },
    // 文件超出个数限制时的钩子
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${
          files.length + fileList.length
        } 个文件`
      );
    },
 
    handleClosecrux(crux, item, whether) {
      if (whether == 1) {
        item.dynamiccruxs.splice(item.dynamiccruxs.indexOf(crux), 1);
        console.log(1);
        console.log(item.dynamiccruxs);
        console.log(item.nodynamiccruxs);
      } else {
        console.log(2);
        item.nodynamiccruxs.splice(item.nodynamiccruxs.indexOf(crux), 1);
      }
      this.generateRegex(item);
    },
    handleInputConfirm(row) {
      console.log(this.TargetoptionList, "TargetoptionList");
      let index = this.TargetoptionList.indexOf(row);
      console.log(1112);
      if (this.whether == 1 && this.inputValue) {
        if (
          this.TargetoptionList[index].dynamiccruxs.indexOf(this.inputValue) ==
          -1
        ) {
          this.TargetoptionList[index].dynamiccruxs.push(this.inputValue);
        } else {
          this.$message.error("关键字已存在");
        }
        // this.inputVisible = false;
        this.TargetoptionList[index].inputVisible = false;
      } else if (this.whether == 2 && this.inputValue) {
        console.log(this.inputValue);
        console.log(
          this.TargetoptionList[index].nodynamiccruxs.indexOf(this.inputValue)
        );
        if (
          this.TargetoptionList[index].nodynamiccruxs.indexOf(
            this.inputValue
          ) == -1
        ) {
          this.TargetoptionList[index].nodynamiccruxs.push(this.inputValue);
        } else {
          this.$message.error("关键字已存在");
        }
        // this.noinputVisible = false;
        this.TargetoptionList[index].noinputVisible = false;
      }
      this.generateRegex(row);
 
      this.inputValue = "";
    },
    showInput(row) {
      let index = this.TargetoptionList.indexOf(row);
      // this.TargetoptionList[index].inputVisible = true;
      this.$set(this.TargetoptionList[index], "inputVisible", true);
      this.whether = 1;
    },
    showInputno(row) {
      let index = this.TargetoptionList.indexOf(row);
      // this.TargetoptionList[index].noinputVisible = true;
      this.$set(this.TargetoptionList[index], "noinputVisible", true);
      this.whether = 2;
    },
    handleSelectionChange(selection) {
      console.log(this.TargetoptionList);
      this.$emit("handleSelectionChange", selection);
    },
    // 选项文件上传
    handleChange(item, response, file, fileList) {
      console.log(response, "response");
      console.log(item, "item");
      console.log(this.TargetoptionList, "this.TargetoptionList");
      let index = this.TargetoptionList.findIndex(
        (obj) => obj.guid == item.guid
      );
      console.log(index);
      this.TargetoptionList[index].picturePath = response.url;
    },
  },
};
</script>
 
<style lang="scss" scoped>
.topicxq {
  background-color: #e2f5fc;
  border-radius: 4px;
  margin-top: 10px;
  padding: 10px;
}
 
.el-tag + .el-tag {
  margin-left: 10px;
}
.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}
.input-new-tag {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}
</style>