ai-chat-bot-interface 1.1.3 → 1.1.5

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,7 +1,7 @@
1
1
  {
2
2
  "name": "ai-chat-bot-interface",
3
3
  "private": false,
4
- "version": "1.1.3",
4
+ "version": "1.1.5",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "description": "A AI chat bot interface. (private)",
@@ -22,8 +22,8 @@
22
22
  "devDependencies": {
23
23
  "@vitejs/plugin-vue": "^5.2.1",
24
24
  "less": "^4.2.2",
25
- "vite": "^6.1.0",
26
- "prettier": "^2.6.2"
25
+ "prettier": "^2.6.2",
26
+ "vite": "^6.1.0"
27
27
  },
28
28
  "author": "lin_26",
29
29
  "license": "MIT"
package/src/App.vue CHANGED
@@ -4,7 +4,7 @@ import ChatUi from './ChatUi.vue';
4
4
 
5
5
  <template>
6
6
  <div style="width: 100vw; height: 100vh">
7
- <chat-ui bot-id="266666" token="pat_8888" uid="262598" />
7
+ <chat-ui bot-id="0000" token="pat_888" uid="262598" />
8
8
  </div>
9
9
  </template>
10
10
  <style></style>
package/src/ChatUi.vue CHANGED
@@ -47,7 +47,7 @@
47
47
  v-for="(item, idx) in botInfo.onboarding_info.suggested_questions"
48
48
  :key="idx"
49
49
  class="board_sug"
50
- @click.stop="chatConv({ code: item, text: item })"
50
+ @click.stop="chatConv([{ content: item, text: item }])"
51
51
  >{{ item }}</span
52
52
  >
53
53
  </div>
@@ -65,6 +65,13 @@
65
65
  <p class="text" v-html="conv.content"></p>
66
66
  <div v-if="conv.extra.length && !isAnswering">
67
67
  <template v-for="(comp, idx) in conv.extra" :key="idx">
68
+ <!-- <p
69
+ v-if="comp.showType === 'plan' && comp.planParse"
70
+ class="text"
71
+ style="margin-top: 1em"
72
+ >
73
+ {{ comp.planParse }}
74
+ </p>-->
68
75
  <dishes-list
69
76
  v-if="comp.showType === 'card'"
70
77
  :sku-list="comp.skuList"
@@ -72,6 +79,7 @@
72
79
  />
73
80
  <plan-card
74
81
  v-if="comp.showType === 'plan'"
82
+ :info="comp"
75
83
  @select="handleCardTap({ type: 'match' }, comp)"
76
84
  />
77
85
  </template>
@@ -90,6 +98,9 @@
90
98
  </div>
91
99
  <div class="box">
92
100
  <p class="text" v-html="conv.content"></p>
101
+ <div v-if="conv.extra.length">
102
+ <imge-list :list="conv.extra" />
103
+ </div>
93
104
  </div>
94
105
  </div>
95
106
  </div>
@@ -98,6 +109,8 @@
98
109
  </div>
99
110
  <operate-module
100
111
  v-model="inputText"
112
+ :token="token"
113
+ :tag-list="tagList"
101
114
  @send="chatConv"
102
115
  @tag="handleTagSel"
103
116
  />
@@ -120,6 +133,7 @@ import BackIcon from './components/icons/BackIcon.vue';
120
133
  import NewChat from './components/icons/newChat.vue';
121
134
  import LoadingIcon from './components/icons/loadingIcon.vue';
122
135
  import LoadingIcon2 from './components/icons/loadingIcon2.vue';
136
+ import ImgeList from './components/imgeList.vue';
123
137
 
124
138
  const chatOptions = computed(() => {
125
139
  return {
@@ -159,6 +173,14 @@ const props = defineProps({
159
173
  type: String,
160
174
  required: true,
161
175
  },
176
+ tagList: {
177
+ type: Array,
178
+ default: () => [
179
+ { name: '人工客服', value: 'kefu', type: 'chat', msg: '人工客服' },
180
+ { name: '查看菜单', value: 'menu', type: 'call', msg: '查看菜单' },
181
+ { name: '体检报告', value: 'exam', type: 'upload', msg: '体检报告' },
182
+ ],
183
+ },
162
184
  });
163
185
 
164
186
  const Emits = defineEmits(['call']);
@@ -228,22 +250,65 @@ const createConv = async () => {
228
250
  },
229
251
  );
230
252
  };*/
253
+
231
254
  const chatConv = async (data) => {
232
- let isInCode = data.hasOwnProperty('text') && data.hasOwnProperty('code');
255
+ let isInCode = Array.isArray(data); // data.hasOwnProperty('text') && data.hasOwnProperty('code');
256
+ console.log('=========', isInCode, data);
257
+ let botId = props.botId;
233
258
  if (!(!isAnswering.value && (inputText.value || isInCode))) {
234
259
  return;
235
260
  }
236
261
  const inText = inputText.value;
237
262
  console.log('== user send ==', isInCode, data, inText);
238
263
  isAnswering.value = true;
239
- historyList.value.push({
264
+
265
+ const additional_messages = [];
266
+ const uObj = {
240
267
  conversation_id: conversationId.value,
241
- bot_id: props.botId,
268
+ bot_id: botId,
242
269
  role: 'user',
243
- content: isInCode ? data.text : inText,
270
+ content: '',
244
271
  status: 'ended',
245
272
  extra: [],
273
+ };
274
+ const markStr = `chat_${new Date().getTime()};`;
275
+ data.forEach((item) => {
276
+ if (item.hasOwnProperty('content') && item.content) {
277
+ if (item.hasOwnProperty('type') && item.type === 'object_string') {
278
+ console.log('=== item ====', item);
279
+ botId = '7474884145253023795';
280
+ additional_messages.push({
281
+ content: JSON.stringify(
282
+ item.content.map((con) => ({
283
+ type: con.type,
284
+ file_id: con.file_id,
285
+ })),
286
+ ),
287
+ content_type: 'object_string',
288
+ role: 'user',
289
+ meta_data: {
290
+ chat_group: markStr,
291
+ },
292
+ });
293
+ uObj.extra = item.content.map((con) => ({
294
+ ...con,
295
+ showType: con.type,
296
+ }));
297
+ } else {
298
+ uObj.content = item.text;
299
+ additional_messages.push({
300
+ content: item.content,
301
+ content_type: 'text',
302
+ role: 'user',
303
+ meta_data: {
304
+ chat_group: markStr,
305
+ },
306
+ });
307
+ }
308
+ }
246
309
  });
310
+
311
+ historyList.value.push(uObj);
247
312
  const res = await fetch(
248
313
  `https://api.coze.cn/v3/chat?conversation_id=${conversationId.value}`,
249
314
  {
@@ -253,17 +318,22 @@ const chatConv = async (data) => {
253
318
  // 'Content-Type': 'text/event-stream',
254
319
  },
255
320
  body: JSON.stringify({
256
- bot_id: props.botId,
321
+ bot_id: botId,
257
322
  user_id: props.uid,
258
323
  stream: true,
259
324
  connector_id: '999',
260
- additional_messages: [
325
+ additional_messages /*[
326
+ {
327
+ content: '[{"type":"image","file_id":"7475569020654436390"}]',
328
+ content_type: 'object_string',
329
+ role: 'user',
330
+ },
261
331
  {
262
332
  role: 'user',
263
333
  content_type: 'text',
264
334
  content: isInCode ? data.code : inText, // '配餐1600kcal,身高173,体重60kg,生成一天的套餐',
265
335
  },
266
- ],
336
+ ]*/,
267
337
  custom_variables: {
268
338
  uid: props.uid,
269
339
  },
@@ -330,6 +400,7 @@ const chatConv = async (data) => {
330
400
  historyList.value[idx].content = handleText(
331
401
  historyList.value[idx].content + strObj.content,
332
402
  );
403
+ scrollToEnd();
333
404
  } else if (
334
405
  strObj.hasOwnProperty('type') &&
335
406
  strObj.type === 'tool_response'
@@ -343,6 +414,7 @@ const chatConv = async (data) => {
343
414
  historyList.value[idx].extra.push({ ...modelObj });
344
415
  }
345
416
  }
417
+ scrollToEnd();
346
418
  }
347
419
  }
348
420
  });
@@ -359,6 +431,7 @@ const queryHistoryList = async () => {
359
431
  if (res.code === 0 && res.data && res.data.length) {
360
432
  historyList.value = [];
361
433
  const cardList = [];
434
+ const userFileList = [];
362
435
  res.data.forEach((row) => {
363
436
  if (row.hasOwnProperty('content_type')) {
364
437
  if (row.content_type === 'text') {
@@ -367,6 +440,7 @@ const queryHistoryList = async () => {
367
440
  conversation_id: row.conversation_id,
368
441
  bot_id: row.bot_id,
369
442
  role: row.role,
443
+ meta_data: row.meta_data,
370
444
  content: handleText(row.content),
371
445
  status: 'ended',
372
446
  extra: [],
@@ -395,19 +469,44 @@ const queryHistoryList = async () => {
395
469
  }
396
470
  }
397
471
  } catch (e) {
398
- console.log('== 解析错误 ==');
472
+ console.log('== 解析错误 sys==');
473
+ }
474
+ } else if (
475
+ row.content_type === 'object_string' &&
476
+ row.role === 'user'
477
+ ) {
478
+ try {
479
+ const strObj = JSON.parse(row.content);
480
+ cardList.push({
481
+ chat_id: row.chat_id,
482
+ conversation_id: row.conversation_id,
483
+ bot_id: row.bot_id,
484
+ role: row.role,
485
+ meta_data: row.meta_data,
486
+ extra: strObj.map((item) => ({ ...item, showType: item.type })),
487
+ });
488
+ } catch (e) {
489
+ console.log('== 解析错误 user==');
399
490
  }
400
491
  }
401
492
  }
402
493
  });
403
494
  cardList.forEach((card) => {
404
- const idx = historyList.value.findIndex(
405
- (c) => c.chat_id === card.chat_id && c.role === 'assistant',
406
- );
495
+ const idx =
496
+ card.role === 'user'
497
+ ? historyList.value.findIndex(
498
+ (c) =>
499
+ c.meta_data.chat_group === card.meta_data.chat_group &&
500
+ c.role === card.role,
501
+ )
502
+ : historyList.value.findIndex(
503
+ (c) => c.chat_id === card.chat_id && c.role === card.role,
504
+ );
407
505
  if (idx > -1) {
408
506
  historyList.value[idx].extra = [...card.extra];
409
507
  }
410
508
  });
509
+
411
510
  console.log(historyList.value, cardList);
412
511
  }
413
512
  };
@@ -437,7 +536,7 @@ const handleBack = () => {
437
536
  const handleTagSel = (info) => {
438
537
  switch (info.type) {
439
538
  case 'chat':
440
- chatConv({ code: info.msg, text: info.msg });
539
+ chatConv([{ content: info.msg, text: info.msg }]);
441
540
  break;
442
541
  case 'call':
443
542
  Emits('call', { ...info });
@@ -448,16 +547,25 @@ const handleTagSel = (info) => {
448
547
  const handleCardTap = ({ type }, info) => {
449
548
  switch (type) {
450
549
  case 'change':
451
- chatConv({ code: '換一套菜品', text: '換一套菜品' });
550
+ chatConv([{ content: '換一套菜品', text: '換一套菜品' }]);
452
551
  break;
453
552
  case 'match':
454
- chatConv({ code: '請用以上方案為我配餐', text: '請用以上方案為我配餐' });
553
+ chatConv([
554
+ { content: '請用以上方案為我配餐', text: '請用以上方案為我配餐' },
555
+ ]);
455
556
  break;
456
557
  default:
457
558
  Emits('call', { type, info });
458
559
  }
459
560
  };
460
561
 
562
+ const handlePlanParse = (list) => {
563
+ const pIdx = list.findIndex((p) => p.showType === 'plan');
564
+ return pIdx > -1
565
+ ? { show: true, text: list[pIdx].planParse }
566
+ : { show: false };
567
+ };
568
+
461
569
  const scrollToEnd = () => {
462
570
  nextTick(() => {
463
571
  endTarget.value.scrollIntoView();
@@ -22,7 +22,7 @@ const props = defineProps({
22
22
  });
23
23
 
24
24
  const subStr = computed(() => {
25
- return `热量${props.info.energy}kcal,蛋白质${props.info.protein}g,脂肪${props.info.fat}g,碳水${props.info.carbonwater}g`;
25
+ return `熱量${props.info.energy}kcal,蛋白質${props.info.protein}g,脂肪${props.info.fat}g,碳水${props.info.carbonwater}g`;
26
26
  });
27
27
  </script>
28
28
 
@@ -22,11 +22,11 @@
22
22
  </template>
23
23
  <div class="btn_group">
24
24
  <div class="btn btn_1" @click.stop="handleBtn('ship_order')">
25
- <span class="name">配送下单</span>
25
+ <span class="name">配送下單</span>
26
26
  <span class="sub">(直送到府)</span>
27
27
  </div>
28
28
  <div class="btn btn_2" @click.stop="handleBtn('pick_order')">
29
- <span class="name">自提點餐</span>
29
+ <span class="name">自提下單</span>
30
30
  <span class="sub">(免運費)</span>
31
31
  </div>
32
32
  </div>
@@ -0,0 +1,165 @@
1
+ @import '../assets/styles/public';
2
+ .om {
3
+ &_wrap {
4
+ box-sizing: border-box;
5
+ width: 100%;
6
+ padding: 10px;
7
+ background-color: #fff;
8
+ }
9
+ &_quick {
10
+ display: grid;
11
+ grid-auto-flow: column;
12
+ gap: 10px;
13
+ overflow-x: auto;
14
+ justify-content: start;
15
+ scroll-behavior: smooth;
16
+ scrollbar-width: none; /* 隐藏滚动条(Firefox) */
17
+ &::-webkit-scrollbar {
18
+ display: none;
19
+ }
20
+
21
+ .tag {
22
+ .flexrsc();
23
+ cursor: pointer;
24
+ width: fit-content;
25
+ white-space: nowrap;
26
+ font-weight: 400;
27
+ font-size: 12px;
28
+ color: #333;
29
+ line-height: 16px;
30
+ text-align: left;
31
+ padding: 6px 10px;
32
+ border-radius: 10px;
33
+ border: 1px solid #d0d0d0;
34
+ }
35
+ .icon {
36
+ font-size: 16px;
37
+ color: @primary-color;
38
+ }
39
+ }
40
+ &_operate {
41
+ display: grid;
42
+ grid-template-columns: 1fr auto;
43
+ background: #fff;
44
+ align-items: center;
45
+ &_wrap {
46
+ margin: 10px 0;
47
+ width: 100%;
48
+ min-height: 48px;
49
+ padding: 10px;
50
+ border-radius: 24px;
51
+ box-sizing: border-box;
52
+ box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.2);
53
+ .file_card {
54
+ width: 64px;
55
+ height: 64px;
56
+ border-radius: 15px;
57
+ background-color: #f7f7f7;
58
+ position: relative;
59
+ .img {
60
+ width: 100%;
61
+ height: 100%;
62
+ object-fit: contain;
63
+ }
64
+ .close {
65
+ cursor: pointer;
66
+ font-size: 16px;
67
+ color: #fff;
68
+ position: absolute;
69
+ top: 0;
70
+ right: 0;
71
+ z-index: 5;
72
+ }
73
+ .process {
74
+ .flexrcc();
75
+ width: 100%;
76
+ height: 100%;
77
+ background-color: rgba(0, 0, 0, 0.6);
78
+ position: absolute;
79
+ top: 0;
80
+ left: 0;
81
+ z-index: 8;
82
+ }
83
+ }
84
+ .file_add {
85
+ .flexrcc();
86
+ .file_card();
87
+ cursor: pointer;
88
+ font-size: 24px;
89
+ }
90
+ .file_list {
91
+ .flexrsc();
92
+ gap: 10px;
93
+ padding-bottom: 10px;
94
+ position: relative;
95
+ &_box {
96
+ transition: all 200ms ease-in-out;
97
+ overflow: hidden;
98
+ height: 74px;
99
+ opacity: 1;
100
+ &.hidden {
101
+ height: 0;
102
+ opacity: 0;
103
+ }
104
+ }
105
+ }
106
+ .file_close {
107
+ .flexrcc();
108
+ cursor: pointer;
109
+ color: #fff;
110
+ width: 20px;
111
+ height: 20px;
112
+ border-radius: 50%;
113
+ background-color: rgba(0, 0, 0, 0.5);
114
+ position: absolute;
115
+ right: 0;
116
+ top: 0;
117
+ z-index: 10;
118
+ }
119
+ }
120
+ .input {
121
+ font-size: 16px;
122
+ line-height: 24px;
123
+ overflow-y: auto;
124
+ resize: none;
125
+ padding: 0 0 0 10px;
126
+ border-radius: 24px;
127
+ border: none;
128
+ &:focus-visible {
129
+ outline: none;
130
+ }
131
+ }
132
+ .btn {
133
+ .flexrcc();
134
+ height: 100%;
135
+ color: @primary-color;
136
+ font-size: 32px;
137
+ padding: 0 10px;
138
+ &_group {
139
+ }
140
+ }
141
+ }
142
+ &_extra {
143
+ .flexrss();
144
+ gap: 10px;
145
+ padding: 10px 0 20px;
146
+ .card {
147
+ text-align: center;
148
+ }
149
+ .text {
150
+ color: #666;
151
+ font-size: 14px;
152
+ line-height: 24px;
153
+ margin-top: 6px;
154
+ }
155
+ .icon {
156
+ .flexrcc();
157
+ width: 72px;
158
+ height: 72px;
159
+ color: #000;
160
+ font-size: 24px;
161
+ background-color: #f7f7f7;
162
+ border-radius: 15px;
163
+ }
164
+ }
165
+ }
@@ -7,24 +7,87 @@
7
7
  :key="item.value"
8
8
  @click.stop="handleTag(item)"
9
9
  >
10
- <tag-icon class="icon" />{{ item.name }}
10
+ <tag-icon class="icon" />
11
+ {{ item.name }}
11
12
  </div>
12
13
  </div>
13
- <div class="om_operate">
14
- <textarea
15
- v-model="textValue"
16
- ref="txtEle"
17
- class="input"
18
- rows="1"
19
- placeholder="發消息⋯"
20
- @input="handleInput"
21
- @keyup.enter="sendMsg"
14
+ <div class="om_operate_wrap">
15
+ <div class="file_list_box" :class="{ hidden: !uploadPlane }">
16
+ <div class="file_list">
17
+ <div
18
+ v-for="(item, index) in uFileList"
19
+ :key="index"
20
+ class="file_card"
21
+ >
22
+ <img class="img" :src="item.file_url" width="100%" alt="img" />
23
+ <div v-if="item.percent < 100" class="process">
24
+ <progress-ring :percent="item.percent" />
25
+ </div>
26
+ <close-border-icon
27
+ v-else
28
+ class="close"
29
+ @click.stop="clearFile(index)"
30
+ />
31
+ </div>
32
+ <div
33
+ v-if="uFileList.length < 4"
34
+ class="file_add"
35
+ @click.stop="triggerUploadInput"
36
+ >
37
+ <add-icon />
38
+ </div>
39
+ <div class="file_close" @click.stop="closeUpload">
40
+ <close-icon />
41
+ </div>
42
+ </div>
43
+ </div>
44
+
45
+ <div class="om_operate">
46
+ <textarea
47
+ v-model="textValue"
48
+ ref="txtEle"
49
+ class="input"
50
+ rows="1"
51
+ placeholder="發消息⋯"
52
+ @input="handleInput"
53
+ @keyup.enter="sendMsg"
54
+ />
55
+ <div class="btn_group">
56
+ <div class="btn" @click.stop="sendMsg">
57
+ <send-icon :style="{ color: textValue ? '#039938' : '#ccc' }" />
58
+ </div>
59
+ </div>
60
+ </div>
61
+ </div>
62
+ <div class="om_extra" style="display: none">
63
+ <input
64
+ ref="captureInput"
65
+ type="file"
66
+ accept="image/*"
67
+ capture="environment"
68
+ style="display: none"
69
+ @change="handleFile"
22
70
  />
23
- <div class="btn_group">
24
- <div class="btn" @click.stop="sendMsg">
25
- <send-icon :style="{ color: textValue ? '#039938' : '#ccc' }" />
71
+
72
+ <input
73
+ ref="uploadInput"
74
+ type="file"
75
+ accept="image/*"
76
+ style="display: none"
77
+ @change="handleFileChange"
78
+ />
79
+ <div
80
+ v-for="card in extraList"
81
+ :key="card.type"
82
+ class="card"
83
+ @click.stop="triggerUploadInput"
84
+ >
85
+ <div class="icon">
86
+ <component :is="card.icon" />
26
87
  </div>
88
+ <div class="text">{{ card.name }}</div>
27
89
  </div>
90
+ <progress-ring :percent="15" />
28
91
  </div>
29
92
  </div>
30
93
  </template>
@@ -33,24 +96,51 @@
33
96
  import TagIcon from './icons/tagIcon.vue';
34
97
  import SendIcon from './icons/SendIcon.vue';
35
98
  import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue';
99
+ import CameraIcon from './icons/cameraIcon.vue';
100
+ import PictureIcon from './icons/pictureIcon.vue';
101
+ import FileIcon from './icons/fileIcon.vue';
102
+ import ProgressRing from './icons/progressRing.vue';
103
+ import AddIcon from './icons/addIcon.vue';
104
+ import CloseBorderIcon from './icons/closeBorderIcon.vue';
105
+ import CloseIcon from './icons/CloseIcon.vue';
106
+
107
+ const extraList = [
108
+ // { name: '相機', icon: CameraIcon, type: 'camera' },
109
+ { name: '相冊', icon: PictureIcon, type: 'photo' },
110
+ { name: '文件', icon: FileIcon, type: 'file' },
111
+ ];
36
112
 
37
113
  const txtEle = ref(null);
114
+ const uploadInput = ref(null);
115
+ const captureInput = ref(null);
116
+ const uploadPlane = ref(false);
38
117
 
118
+ const uFileList = ref([]);
39
119
  const props = defineProps({
40
120
  modelValue: {
41
121
  type: String,
42
122
  default: '',
43
123
  },
124
+ token: {
125
+ type: String,
126
+ required: true,
127
+ },
44
128
  tagList: {
45
129
  type: Array,
46
- default: () => [
47
- { name: '人工客服', value: 'kefu', type: 'chat', msg: '人工客服' },
48
- { name: '查看菜单', value: 'menu', type: 'call', msg: '查看菜单' },
49
- ],
130
+ required: true,
50
131
  },
51
132
  });
52
133
  const Emits = defineEmits(['update:modelValue', 'send', 'tag']);
53
134
 
135
+ const fetchOptions = computed(() => {
136
+ return {
137
+ headers: {
138
+ Authorization: `Bearer ${props.token}`,
139
+ 'Content-Type': 'multipart/form-data',
140
+ },
141
+ };
142
+ });
143
+
54
144
  watch(
55
145
  () => props.modelValue,
56
146
  () => {
@@ -82,12 +172,110 @@ const handleInput = (event) => {
82
172
  textValue.value = event.target.value.replace(/^\n+|\n+$/g, '');
83
173
  };
84
174
  const handleTag = (info) => {
85
- Emits('tag', { ...info });
175
+ if (info.type === 'upload') {
176
+ showUpload();
177
+ } else {
178
+ Emits('tag', { ...info });
179
+ }
180
+ };
181
+ const sendMsg = (e) => {
182
+ const list = [{ content: textValue.value, text: textValue.value }];
183
+ if (uFileList.value.length) {
184
+ console.log(uFileList.value);
185
+ list.push({
186
+ type: 'object_string',
187
+ content: uFileList.value.map((file) => ({
188
+ type: 'image',
189
+ file_id: file.data.id,
190
+ file_url: file.file_url,
191
+ })),
192
+ });
193
+ }
194
+ Emits('send', [...list]);
195
+ clearAllFile();
86
196
  };
87
- const sendMsg = () => {
88
- // console.log('=== send msg ===', textValue.value);
89
- Emits('send', textValue.value);
197
+ const handleFile = (e) => {
198
+ const file = e.target.files[0];
199
+ const reader = new FileReader();
200
+ reader.onload = () => (previewUrl.value = reader.result);
201
+ reader.readAsDataURL(file);
90
202
  };
203
+ const triggerUploadInput = () => {
204
+ uploadInput.value ? uploadInput.value.click() : '';
205
+ };
206
+
207
+ const handleFileChange = (e) => {
208
+ const selFile = e.target.files[0];
209
+
210
+ if (selFile) {
211
+ uFileList.value.push({
212
+ file: selFile,
213
+ file_url: URL.createObjectURL(selFile),
214
+ size: (selFile.size / 1024).toFixed(2),
215
+ percent: 0,
216
+ data: {},
217
+ });
218
+ console.log('=== 文件列表 ===', uFileList.value);
219
+ handleUpload(uFileList.value.length - 1);
220
+ }
221
+ };
222
+ const handleUpload = async (idx) => {
223
+ const file = uFileList.value[idx].file;
224
+ console.log('========', file);
225
+ if (!textValue.value) {
226
+ textValue.value = '請根據我上傳的體檢報告為我生成飲食方案';
227
+ }
228
+ const formDate = new FormData();
229
+ formDate.append('file', file);
230
+ const xhr = new XMLHttpRequest();
231
+ xhr.open('POST', 'https://api.coze.cn/v1/files/upload');
232
+ xhr.setRequestHeader(
233
+ 'Authorization',
234
+ fetchOptions.value.headers.Authorization,
235
+ );
236
+ xhr.upload.onprogress = (e) => {
237
+ if (e.lengthComputable) {
238
+ const percent = Math.round((e.loaded / e.total) * 100);
239
+ console.log(`======进度======:${percent}%`);
240
+ uFileList.value[idx].percent = percent;
241
+ }
242
+ };
243
+ xhr.onreadystatechange = function () {
244
+ console.log('============', xhr);
245
+ if (xhr.readyState === XMLHttpRequest.DONE) {
246
+ if (xhr.status === 200) {
247
+ console.log('上传成功:', xhr.responseText);
248
+ const res = JSON.parse(xhr.response);
249
+ uFileList.value[idx].data = res.data;
250
+ } else {
251
+ console.error('上传失败:', xhr.status);
252
+ }
253
+ }
254
+ };
255
+ xhr.send(formDate);
256
+ };
257
+ const showUpload = () => {
258
+ clearAllFile(true);
259
+ uploadPlane.value = true;
260
+ };
261
+ const closeUpload = () => {
262
+ clearAllFile(true);
263
+ uploadPlane.value = false;
264
+ };
265
+ const clearAllFile = (deep = false) => {
266
+ if (deep) {
267
+ for (let i = uFileList.value.length - 1; i >= 0; i -= 1) {
268
+ clearFile(i);
269
+ }
270
+ }
271
+ uFileList.value = [];
272
+ };
273
+
274
+ const clearFile = (idx) => {
275
+ URL.revokeObjectURL(uFileList.value[idx].file_url);
276
+ uFileList.value.splice(idx, 1);
277
+ };
278
+
91
279
  const resizeTextarea = () => {
92
280
  nextTick(() => {
93
281
  if (txtEle.value) {
@@ -100,78 +288,5 @@ const resizeTextarea = () => {
100
288
  </script>
101
289
 
102
290
  <style scoped lang="less">
103
- @import '../assets/styles/public';
104
- .om {
105
- &_wrap {
106
- box-sizing: border-box;
107
- width: 100%;
108
- padding: 10px;
109
- background-color: #fff;
110
- }
111
- &_quick {
112
- display: grid;
113
- grid-auto-flow: column;
114
- gap: 10px;
115
- overflow-x: auto;
116
- justify-content: start;
117
- scroll-behavior: smooth;
118
- scrollbar-width: none; /* 隐藏滚动条(Firefox) */
119
- &::-webkit-scrollbar {
120
- display: none;
121
- }
122
-
123
- .tag {
124
- .flexrsc();
125
- cursor: pointer;
126
- width: fit-content;
127
- white-space: nowrap;
128
- font-weight: 400;
129
- font-size: 12px;
130
- color: #333;
131
- line-height: 16px;
132
- text-align: left;
133
- padding: 6px 10px;
134
- border-radius: 10px;
135
- border: 1px solid #d0d0d0;
136
- }
137
- .icon {
138
- font-size: 16px;
139
- color: @primary-color;
140
- }
141
- }
142
- &_operate {
143
- display: grid;
144
- grid-template-columns: 1fr auto;
145
- box-sizing: border-box;
146
- margin: 10px 0;
147
- width: 100%;
148
- min-height: 48px;
149
- padding: 10px;
150
- background: #fff;
151
- box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.2);
152
- border-radius: 24px;
153
- align-items: center;
154
- .input {
155
- font-size: 16px;
156
- line-height: 24px;
157
- overflow-y: auto;
158
- resize: none;
159
- padding: 0 0 0 10px;
160
- border-radius: 24px;
161
- border: none;
162
- &:focus-visible {
163
- outline: none;
164
- }
165
- }
166
- .btn {
167
- .flexrcc();
168
- height: 100%;
169
- color: @primary-color;
170
- font-size: 32px;
171
- padding: 0 10px;
172
- &_group {
173
- }
174
- }
175
- }
176
- }
291
+ @import './OperateModule';
177
292
  </style>
@@ -1,10 +1,52 @@
1
1
  <template>
2
+ <div class="card" style="margin-top: 15px">
3
+ <div class="row">
4
+ <div class="name">每日攝入能量</div>
5
+ <div class="content">{{ info.totalIntake }} kcal</div>
6
+ </div>
7
+ </div>
8
+ <div v-for="cate in info.planDetailList" :key="category" class="card">
9
+ <div class="title">{{ textMap[cate.category] }}</div>
10
+ <div class="row">
11
+ <div class="name">{{ textMap[cate.category] }}熱量</div>
12
+ <div class="content">{{ cate.totalKcal }} kcal</div>
13
+ </div>
14
+ <div class="sep" />
15
+ <div class="row">
16
+ <div class="name">{{ textMap.carbohydrateTotal }}</div>
17
+ <div class="content">{{ cate.carbohydrateTotal }} g</div>
18
+ </div>
19
+ <div class="row">
20
+ <div class="name">{{ textMap.proteinTotal }}</div>
21
+ <div class="content">{{ cate.proteinTotal }} g</div>
22
+ </div>
23
+ <div class="row">
24
+ <div class="name">{{ textMap.fatTotal }}</div>
25
+ <div class="content">{{ cate.fatTotal }} g</div>
26
+ </div>
27
+ </div>
2
28
  <div class="btn_group">
3
29
  <div class="btn btn_2" @click.stop="handleSel">用該方案配餐</div>
4
30
  </div>
5
31
  </template>
6
32
 
7
33
  <script setup>
34
+ const textMap = {
35
+ '01': '早餐',
36
+ '02': '午餐',
37
+ '03': '晚餐',
38
+ '04': '加餐',
39
+ carbohydrateTotal: '碳水化合物',
40
+ proteinTotal: '蛋白質',
41
+ fatTotal: '脂肪',
42
+ };
43
+
44
+ const props = defineProps({
45
+ info: {
46
+ type: Object,
47
+ required: true,
48
+ },
49
+ });
8
50
  const Emits = defineEmits(['select']);
9
51
  const handleSel = () => {
10
52
  Emits('select', {});
@@ -12,6 +54,35 @@ const handleSel = () => {
12
54
  </script>
13
55
 
14
56
  <style scoped lang="less">
57
+ .card {
58
+ padding: 10px 15px;
59
+ margin-bottom: 10px;
60
+ background-color: #fff;
61
+ border-radius: 10px;
62
+ .title {
63
+ font-size: 14px;
64
+ font-weight: 600;
65
+ line-height: 24px;
66
+ }
67
+ .row {
68
+ .flexrbc();
69
+ margin: 10px 0;
70
+ }
71
+ .sep {
72
+ border-bottom: 1px solid #ddd;
73
+ }
74
+ .name {
75
+ font-weight: 400;
76
+ font-size: 14px;
77
+ color: #666;
78
+ line-height: 24px;
79
+ }
80
+ .content {
81
+ .name();
82
+ color: #000;
83
+ font-weight: 600;
84
+ }
85
+ }
15
86
  .btn {
16
87
  cursor: pointer;
17
88
  width: 100%;
@@ -0,0 +1,18 @@
1
+ <template>
2
+ <svg
3
+ width="1em"
4
+ height="1em"
5
+ viewBox="0 0 24 24"
6
+ fill="none"
7
+ xmlns="http://www.w3.org/2000/svg"
8
+ >
9
+ <path
10
+ d="M13.5 4.5C13.5 3.67157 12.8284 3 12 3C11.1716 3 10.5 3.67157 10.5 4.5L10.5 10.5H4.5C3.67157 10.5 3 11.1716 3 12C3 12.8284 3.67157 13.5 4.5 13.5H10.5L10.5 19.5C10.5 20.3284 11.1716 21 12 21C12.8284 21 13.5 20.3284 13.5 19.5V13.5H19.5C20.3284 13.5 21 12.8284 21 12C21 11.1716 20.3284 10.5 19.5 10.5H13.5V4.5Z"
11
+ fill="currentColor"
12
+ />
13
+ </svg>
14
+ </template>
15
+
16
+ <script></script>
17
+
18
+ <style scoped></style>
@@ -0,0 +1,22 @@
1
+ <template>
2
+ <svg
3
+ width="1em"
4
+ height="1em"
5
+ viewBox="0 0 25 24"
6
+ fill="none"
7
+ xmlns="http://www.w3.org/2000/svg"
8
+ >
9
+ <path
10
+ d="M6.03791 5.43733C4.02837 5.73154 2.36942 7.19356 2.01374 9.19314C1.80186 10.3843 1.625 11.7046 1.625 12.7932C1.625 14.1142 1.88543 15.7626 2.15286 17.1069C2.47288 18.7157 3.53388 20.0703 5.08995 20.5892C6.81466 21.1644 9.4087 21.7782 12.6246 21.7782C15.8579 21.7782 18.4626 21.1577 20.1872 20.5799C21.7264 20.0641 22.781 18.729 23.1036 17.138C23.3774 15.788 23.6415 14.1244 23.6242 12.7932C23.6125 11.8974 23.4692 10.8334 23.2896 9.83524C22.9086 7.71845 21.2484 6.11084 19.1702 5.55694C18.4877 5.37505 17.8729 4.99872 17.4004 4.47375L16.4669 3.4365C15.7716 2.66386 14.7809 2.22266 13.7415 2.22266H11.5077C10.4683 2.22266 9.47763 2.66385 8.78228 3.4365L7.85962 4.46171C7.38473 4.98939 6.74034 5.3345 6.03791 5.43733ZM15.0694 12.6113C15.0694 13.9614 13.975 15.0558 12.625 15.0558C11.275 15.0558 10.1805 13.9614 10.1805 12.6113C10.1805 11.2613 11.275 10.1669 12.625 10.1669C13.975 10.1669 15.0694 11.2613 15.0694 12.6113ZM17.5139 12.6113C17.5139 15.3114 15.325 17.5002 12.625 17.5002C9.92493 17.5002 7.7361 15.3114 7.7361 12.6113C7.7361 9.91127 9.92493 7.72244 12.625 7.72244C15.325 7.72244 17.5139 9.91127 17.5139 12.6113Z"
11
+ fill="currentColor"
12
+ />
13
+ </svg>
14
+ </template>
15
+
16
+ <script>
17
+ export default {
18
+ name: 'camreIcon',
19
+ };
20
+ </script>
21
+
22
+ <style scoped></style>
@@ -0,0 +1,35 @@
1
+ <template>
2
+ <svg
3
+ width="1em"
4
+ height="1em"
5
+ viewBox="0 0 16 16"
6
+ fill="none"
7
+ xmlns="http://www.w3.org/2000/svg"
8
+ >
9
+ <rect
10
+ x="0.5"
11
+ y="0.5"
12
+ width="15"
13
+ height="15"
14
+ rx="7.5"
15
+ fill="black"
16
+ fill-opacity="0.5"
17
+ />
18
+ <rect
19
+ x="0.5"
20
+ y="0.5"
21
+ width="15"
22
+ height="15"
23
+ rx="7.5"
24
+ stroke="currentColor"
25
+ />
26
+ <path
27
+ d="M10.8284 6.58588C11.2189 6.19535 11.2189 5.56219 10.8284 5.17167C10.4379 4.78114 9.80471 4.78114 9.41419 5.17167L8 6.58586L6.58581 5.17167C6.19529 4.78114 5.56212 4.78114 5.1716 5.17167C4.78107 5.56219 4.78107 6.19535 5.1716 6.58588L6.58579 8.00007L5.17155 9.41431C4.78103 9.80483 4.78103 10.438 5.17155 10.8285C5.56207 11.219 6.19524 11.219 6.58576 10.8285L8 9.41428L9.41424 10.8285C9.80476 11.219 10.4379 11.219 10.8285 10.8285C11.219 10.438 11.219 9.80483 10.8285 9.41431L9.41421 8.00007L10.8284 6.58588Z"
28
+ fill="currentColor"
29
+ />
30
+ </svg>
31
+ </template>
32
+
33
+ <script></script>
34
+
35
+ <style scoped></style>
@@ -0,0 +1,18 @@
1
+ <template>
2
+ <svg
3
+ width="1em"
4
+ height="1em"
5
+ viewBox="0 0 24 24"
6
+ fill="none"
7
+ xmlns="http://www.w3.org/2000/svg"
8
+ >
9
+ <path
10
+ d="M18.0849 10.6565C19.9734 8.76795 19.9734 5.70607 18.0849 3.81756C16.1964 1.92905 13.1345 1.92905 11.246 3.81756L5.05399 10.0096C2.55177 12.5118 2.55177 16.5687 5.05399 19.0709C7.55622 21.5732 11.6131 21.5732 14.1154 19.0709L20.2421 12.9442C20.6326 12.5537 20.6326 11.9205 20.2421 11.53C19.8516 11.1394 19.2184 11.1394 18.8279 11.53L12.7011 17.6567C10.98 19.3779 8.18938 19.3779 6.46821 17.6567C4.74703 15.9355 4.74703 13.145 6.4682 11.4238L12.6602 5.23178C13.7677 4.12431 15.5632 4.12431 16.6707 5.23178C17.7781 6.33924 17.7781 8.13478 16.6707 9.24224L10.5401 15.3729C10.0481 15.8648 9.25051 15.8648 8.75856 15.3729C8.26661 14.8809 8.26661 14.0833 8.75856 13.5913L13.9435 8.40645C14.334 8.01592 14.334 7.38276 13.9435 6.99223C13.5529 6.60171 12.9198 6.60171 12.5292 6.99223L7.34435 12.1771C6.07135 13.4501 6.07135 15.5141 7.34435 16.7871C8.61735 18.0601 10.6813 18.0601 11.9543 16.7871L18.0849 10.6565Z"
11
+ fill="currentColor"
12
+ />
13
+ </svg>
14
+ </template>
15
+
16
+ <script></script>
17
+
18
+ <style scoped></style>
@@ -0,0 +1,22 @@
1
+ <template>
2
+ <svg
3
+ width="1em"
4
+ height="1em"
5
+ viewBox="0 0 24 24"
6
+ fill="none"
7
+ xmlns="http://www.w3.org/2000/svg"
8
+ >
9
+ <path
10
+ d="M2.875 6C2.875 4.34315 4.21815 3 5.875 3H19.875C21.5319 3 22.875 4.34315 22.875 6V18C22.875 19.6569 21.5319 21 19.875 21H5.875C4.21815 21 2.875 19.6569 2.875 18V6ZM5.875 5C5.32272 5 4.875 5.44772 4.875 6V16.0852L10.475 11.8852C11.8972 10.8185 13.8528 10.8185 15.275 11.8852L20.875 16.0852V6C20.875 5.44772 20.4273 5 19.875 5H5.875ZM8.28442 10.0852C9.11285 10.0852 9.78442 9.41363 9.78442 8.58521C9.78442 7.75678 9.11285 7.08521 8.28442 7.08521C7.456 7.08521 6.78442 7.75678 6.78442 8.58521C6.78442 9.41363 7.456 10.0852 8.28442 10.0852Z"
11
+ fill="currentColor"
12
+ />
13
+ </svg>
14
+ </template>
15
+
16
+ <script>
17
+ export default {
18
+ name: 'pictureIcon',
19
+ };
20
+ </script>
21
+
22
+ <style scoped></style>
@@ -0,0 +1,63 @@
1
+ <template>
2
+ <svg
3
+ :width="size"
4
+ :height="size"
5
+ viewBox="0 0 100 100"
6
+ xmlns="http://www.w3.org/2000/svg"
7
+ >
8
+ <!-- 绘制底层浅色圆环 -->
9
+ <circle
10
+ cx="50"
11
+ cy="50"
12
+ r="45"
13
+ fill="none"
14
+ :stroke="bgColor"
15
+ stroke-width="8"
16
+ />
17
+ <!-- 绘制上层白色圆弧(带圆角端点) -->
18
+ <path
19
+ id="progressPath"
20
+ d="M 50 5
21
+ a 45 45 0 1 1 0 90
22
+ a 45 45 0 1 1 0 -90"
23
+ fill="none"
24
+ :stroke="color"
25
+ stroke-width="10"
26
+ stroke-linecap="round"
27
+ :stroke-dasharray="num.l"
28
+ :stroke-dashoffset="num.p"
29
+ />
30
+ </svg>
31
+ </template>
32
+
33
+ <script setup>
34
+ import { computed } from 'vue';
35
+
36
+ const props = defineProps({
37
+ percent: {
38
+ type: Number,
39
+ default: 75,
40
+ },
41
+ size: {
42
+ type: Number,
43
+ default: 48,
44
+ },
45
+ color: {
46
+ type: String,
47
+ default: '#fff',
48
+ },
49
+ bgColor: {
50
+ type: String,
51
+ default: '#888',
52
+ },
53
+ });
54
+
55
+ const num = computed(() => {
56
+ return {
57
+ l: 2 * Math.PI * 45,
58
+ p: (2 * Math.PI * 45 * (100 - props.percent)) / 100,
59
+ };
60
+ });
61
+ </script>
62
+
63
+ <style scoped></style>
@@ -0,0 +1,39 @@
1
+ <template>
2
+ <div class="img_wrap" :class="list.length > 1 ? 'grid_2' : 'grid_1'">
3
+ <img
4
+ v-for="info in list"
5
+ :key="info.file_id"
6
+ class="img"
7
+ width="100%"
8
+ :src="info.file_url"
9
+ :alt="info.name"
10
+ />
11
+ </div>
12
+ </template>
13
+
14
+ <script setup>
15
+ const props = defineProps({
16
+ list: {
17
+ type: Array,
18
+ required: true,
19
+ },
20
+ });
21
+ </script>
22
+
23
+ <style scoped lang="less">
24
+ .img_wrap {
25
+ display: grid;
26
+ gap: 10px;
27
+ justify-content: right;
28
+ padding: 10px 0;
29
+ .img {
30
+ }
31
+ &.grid_1 {
32
+ grid-template-columns: 200px;
33
+ }
34
+ &.grid_2 {
35
+ display: grid;
36
+ grid-template-columns: 100px 100px;
37
+ }
38
+ }
39
+ </style>
@@ -0,0 +1,20 @@
1
+ export const useDeviceDetect = () => {
2
+ const device = {
3
+ isMobile: false,
4
+ isIOS: false,
5
+ isAndroid: false,
6
+ isPC: false,
7
+ };
8
+ const ua = navigator.userAgent;
9
+ const mobileRegex =
10
+ /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
11
+ const iosRegex = /iPhone|iPad|iPod/i;
12
+ // 移动端检测
13
+ device.isMobile = mobileRegex.test(ua);
14
+ // iOS检测
15
+ device.isIOS = iosRegex.test(ua) && !ua.match(/CriOS/);
16
+ // Android检测
17
+ device.isAndroid = /Android/i.test(ua);
18
+ device.isPC = !device.isMobile;
19
+ return device;
20
+ };