ai-chat-bot-interface 1.6.23 → 1.6.25

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.6.23",
4
+ "version": "1.6.25",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "description": "A AI chat bot interface. (private)",
package/src/App.vue CHANGED
@@ -18,7 +18,7 @@ const handleLog = (log) => {
18
18
  {
19
19
  name: '用户信息',
20
20
  value: 'personalForm',
21
- type: 'chat',
21
+ type: 'simulate',
22
22
  msg: '请为我生成一份个性化的健康的食谱。',
23
23
  },
24
24
  ]"
package/src/ChatUi.vue CHANGED
@@ -356,6 +356,7 @@ const storage = {
356
356
  };
357
357
 
358
358
  onMounted(async () => {
359
+ localStorage.setItem('postToken', props.postToken || '');
359
360
  if (storage.getItem('conversationId')) {
360
361
  conversationId.value = storage.getItem('conversationId');
361
362
  await queryBotInfo();
@@ -844,6 +845,9 @@ const handleTagSel = (info) => {
844
845
  case 'call':
845
846
  Emits('call', { ...info });
846
847
  break;
848
+ case 'simulate':
849
+ simulateChat(info);
850
+ break;
847
851
  }
848
852
  };
849
853
 
@@ -861,10 +865,10 @@ const handleCardTap = ({ type }, info) => {
861
865
  ]);
862
866
  break;
863
867
  case 'personalForm':
864
- handleTagSel({
868
+ simulateChat({
865
869
  msg: '请为我生成一份个性化的健康的食谱',
866
870
  name: '用户信息',
867
- type: 'chat',
871
+ type: 'simulate',
868
872
  value: 'personalForm',
869
873
  });
870
874
  break;
@@ -892,15 +896,55 @@ const handlePlanParse = (list) => {
892
896
  };
893
897
 
894
898
  const scrollToEnd = () => {
895
- nextTick(() => {
896
- endTarget.value.scrollIntoView();
897
- });
899
+ setTimeout(() => {
900
+ nextTick(() => {
901
+ endTarget.value.scrollIntoView();
902
+ });
903
+ }, 100);
898
904
  };
899
905
 
900
906
  const handleTextNeedBtn = (str) => {
901
907
  const regExp = /#全日總熱量:(\d*?)kcal/g;
902
908
  return regExp.test(str);
903
909
  };
910
+
911
+ const simulateChat = (info) => {
912
+ console.log('== simulateChat == ', info);
913
+ historyList.value.push({
914
+ conversation_id: '',
915
+ bot_id: props.botId,
916
+ role: 'user',
917
+ content: info.msg,
918
+ reasoning_content: '',
919
+ status: 'ended',
920
+ extra: [],
921
+ });
922
+ let resInfo = {
923
+ msg: '',
924
+ extra: [],
925
+ };
926
+ switch (info.value) {
927
+ case 'personalForm':
928
+ resInfo.msg =
929
+ '请填写您的身体数据,维小饭将根据你的身体数据智能生成个性化食谱';
930
+ resInfo.extra = [
931
+ {
932
+ showType: 'personalForm',
933
+ },
934
+ ];
935
+ break;
936
+ }
937
+ historyList.value.push({
938
+ conversation_id: '',
939
+ bot_id: props.botId,
940
+ role: 'assistant',
941
+ content: resInfo.msg,
942
+ reasoning_content: '',
943
+ status: 'ended',
944
+ extra: [...resInfo.extra],
945
+ });
946
+ scrollToEnd();
947
+ };
904
948
  </script>
905
949
 
906
950
  <style scoped lang="less">
@@ -79,7 +79,7 @@
79
79
  <video :src="info.skuVideo" width="100%" controls="true" />
80
80
  </div>
81
81
  <div
82
- v-for="(item, index) in info.makeCraftList"
82
+ v-for="(item, index) in makeCraft.makeCraftList"
83
83
  :key="index"
84
84
  class="step_row"
85
85
  >
@@ -103,10 +103,11 @@
103
103
  </template>
104
104
 
105
105
  <script setup>
106
- import { computed, onMounted, ref } from 'vue';
106
+ import { computed, nextTick, onMounted, ref } from 'vue';
107
107
  import { api as viewerApi } from 'v-viewer';
108
108
  import 'viewerjs/dist/viewer.css';
109
109
  import ArrowRight from './icons/ArrowRight.vue';
110
+ import { post } from '../utils/request.js';
110
111
 
111
112
  const props = defineProps({
112
113
  info: {
@@ -125,15 +126,43 @@ const props = defineProps({
125
126
  const isOpen = ref(props.open);
126
127
  const contentRef = ref(null); // 用于引用内容 DOM 元素
127
128
  const contentHeight = ref(0); // 存储内容的实际高度
129
+ const makeCraft = ref([]);
128
130
 
129
- onMounted(() => {
130
- getContentHeight();
131
+ onMounted(async () => {
132
+ if (isOpen.value) {
133
+ await querySkuMakeCraft();
134
+ getContentHeight();
135
+ }
131
136
  });
132
137
 
133
138
  const getContentHeight = () => {
134
- contentHeight.value = hasDetails.value ? contentRef.value.scrollHeight : 0;
139
+ nextTick(async () => {
140
+ const imgList = [];
141
+ if (makeCraft.value.hasOwnProperty('makeCraftList')) {
142
+ makeCraft.value?.makeCraftList.forEach((item) => {
143
+ const imgs = getImageList(item.craftImg);
144
+ imgList.push(...imgs);
145
+ });
146
+ }
147
+ await preloadImages(imgList);
148
+ contentHeight.value = hasDetails.value ? contentRef.value.scrollHeight : 0;
149
+ isOpen.value = true;
150
+ });
135
151
  };
136
152
 
153
+ const preloadImages = (urls) => {
154
+ const promises = [];
155
+ urls.forEach((url) => {
156
+ const img = new Image();
157
+ const promise = new Promise((resolve, reject) => {
158
+ img.onload = () => resolve(img);
159
+ img.onerror = () => reject(new Error(`加载${url}失败`));
160
+ img.src = url;
161
+ });
162
+ promises.push(promise);
163
+ });
164
+ return Promise.all(promises);
165
+ };
137
166
  // const Emits = defineEmits(['update:open']);
138
167
 
139
168
  const subStr = computed(() => {
@@ -146,14 +175,7 @@ const materialText = computed(() => {
146
175
  return (list || []).join('、');
147
176
  });
148
177
  const hasDetails = computed(() => {
149
- let sts = false;
150
- if (
151
- props.info.hasOwnProperty('makeCraftList') &&
152
- props.info.makeCraftList.length > 0
153
- ) {
154
- sts = true;
155
- }
156
- return sts;
178
+ return props.info.hasOwnProperty('cid') && props.info.cid;
157
179
  });
158
180
  const panelHeight = computed(() => {
159
181
  let h = '92px';
@@ -169,11 +191,13 @@ const previewImg = (url) => {
169
191
  });
170
192
  };
171
193
 
172
- const switchOpen = () => {
194
+ const switchOpen = async () => {
173
195
  if (!isOpen.value) {
196
+ await querySkuMakeCraft();
174
197
  getContentHeight();
198
+ } else {
199
+ isOpen.value = false;
175
200
  }
176
- isOpen.value = !isOpen.value;
177
201
  };
178
202
 
179
203
  const getImageList = (str) => {
@@ -186,6 +210,24 @@ const getImageList = (str) => {
186
210
 
187
211
  return list;
188
212
  };
213
+
214
+ const querySkuMakeCraft = async () => {
215
+ if (
216
+ !(
217
+ makeCraft.value.hasOwnProperty('makeCraftList') &&
218
+ makeCraft.value.hasOwnProperty('makeMaterialList')
219
+ )
220
+ ) {
221
+ const res = await post('/api/cn.weis.api.Food/makeCraft', {
222
+ method: 'makeCraft',
223
+ params: [{ cid: props.info.cid }],
224
+ token: localStorage.getItem('postToken'),
225
+ });
226
+ if (res.errCode === 0 && res.obj) {
227
+ makeCraft.value = { ...res.obj };
228
+ }
229
+ }
230
+ };
189
231
  </script>
190
232
 
191
233
  <style scoped lang="less">
@@ -83,7 +83,8 @@ const openSts = ref(false);
83
83
  const handleIsOpen = (info, category) => {
84
84
  if (openSts.value) {
85
85
  return false;
86
- } else if (category !== '01' && info.hasOwnProperty('makeCraftList')) {
86
+ } else if (category !== '01' && info.hasOwnProperty('cid') && info.cid) {
87
+ console.log('=== 6666 ===', info);
87
88
  openSts.value = true;
88
89
  return true;
89
90
  } else {