ai-assistant-pro 0.0.1

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/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # ai-questtion
2
+
3
+ ## Project setup
4
+ ```
5
+ npm install
6
+ ```
7
+
8
+ ### Compiles and minifies for production
9
+ ```
10
+ npm run build
11
+ ```
12
+
13
+ ### Customize configuration
14
+ See [Configuration Reference](https://cli.vuejs.org/config/).
15
+
16
+
17
+ ### test-project是测试组件项目
18
+
19
+ ### 公司自用组件 npm i ai-question
20
+
21
+ ### 调用方法
22
+ ...
23
+
24
+ this.$refs.name.showAddQuestion()
25
+ ...
26
+
27
+ ### top控制侧边弹框到顶部的距离
28
+
29
+ ### knowledgeList根据elment传参格式传入树形数据
30
+
31
+ ### propFormat知识点传参格式修改 {value : 'xxx',label : 'xxx','children' : 'xxx'}
32
+
33
+ ### join加入题库
@@ -0,0 +1,99 @@
1
+ import request from '../utils/request'
2
+ import { fetchEventSource } from '@microsoft/fetch-event-source';
3
+ const baseURL = sessionStorage.getItem('AI_BASE_URL_FOR_TEST') || 'https://zjyw.icve.com.cn/ai-api';
4
+ const prefix = sessionStorage.getItem('AI_PRE_FIX_FOR_TEST') || '/heatp';
5
+ import cache from '../plugins/cache';
6
+ export const ssoAuth = (token) => {
7
+ return request({
8
+ url: prefix + '/sso/assistant',
9
+ method: 'get',
10
+ params: {
11
+ token: token,
12
+ },
13
+ });
14
+ }
15
+
16
+ export const authUser = (headers) => {
17
+ return request({
18
+ url: '/uc/authuser',
19
+ method: 'get',
20
+ headers: headers,
21
+ });
22
+ }
23
+
24
+ export const newChat = (resId) => {
25
+ return request({
26
+ url: prefix + '/assistant/addChat',
27
+ method: 'post',
28
+ params: {
29
+ resId
30
+ }
31
+ });
32
+ }
33
+
34
+ export const chartClear = (chatId) => {
35
+ return request({
36
+ url: prefix + `/assistant/chartClear/${chatId}`,
37
+ method: 'post',
38
+ });
39
+ }
40
+
41
+ export const stopChat = (chatId) => {
42
+ return request({
43
+ url: prefix + `/assistant/stop/${chatId}`,
44
+ method: 'post',
45
+ });
46
+ }
47
+
48
+ export const chatEvaluateAdd = (params) => {
49
+ return request({
50
+ url: prefix + `/assistant/chatEvaluateAdd`,
51
+ method: 'post',
52
+ data: params
53
+ });
54
+ }
55
+
56
+ export const chatEvaluateCancel = (params) => {
57
+ return request({
58
+ url: prefix + `/assistant/chatEvaluateCancel`,
59
+ method: 'post',
60
+ data: params
61
+ });
62
+ }
63
+
64
+ export const pustReanswerToTeacher = (params) => {
65
+ return request({
66
+ url: prefix + `/assistant/push`,
67
+ method: 'post',
68
+ data: params
69
+ });
70
+ }
71
+
72
+ export const getDetailList = (resId) => {
73
+ return request({
74
+ url: prefix + `/assistant/detail/v2/${resId}`,
75
+ method: 'get',
76
+ });
77
+ }
78
+
79
+ export const countAccess = (resId) => {
80
+ return request({
81
+ url: prefix + `/assistant/access`,
82
+ method: 'post',
83
+ params: { resId },
84
+ });
85
+ }
86
+
87
+ export async function sendMessageEventSource(params, signal, onmessage) {
88
+ return fetchEventSource(`${baseURL}${prefix}/assistant/conversation`, {
89
+ method: 'POST',
90
+ signal: signal,
91
+ openWhenHidden: true,
92
+ headers: {
93
+ 'Content-Type': 'application/json',
94
+ 'X-Id-Token': cache.session.getJSON('SRKJ_TOKEN_CACHE'),
95
+ },
96
+ body: JSON.stringify(params),
97
+ onmessage,
98
+ });
99
+ }
@@ -0,0 +1,7 @@
1
+ import AiAssistant from './src/main.vue'
2
+
3
+ AiAssistant.install = function (Vue) {
4
+ Vue.component(AiAssistant.name,AiAssistant)
5
+ }
6
+
7
+ export default AiAssistant
@@ -0,0 +1,77 @@
1
+ const sessionCache = {
2
+ set (key, value) {
3
+ if (!sessionStorage) {
4
+ return
5
+ }
6
+ if (key != null && value != null) {
7
+ sessionStorage.setItem(key, value)
8
+ }
9
+ },
10
+ get (key) {
11
+ if (!sessionStorage) {
12
+ return null
13
+ }
14
+ if (key == null) {
15
+ return null
16
+ }
17
+ return sessionStorage.getItem(key)
18
+ },
19
+ setJSON (key, jsonValue) {
20
+ if (jsonValue != null) {
21
+ this.set(key, JSON.stringify(jsonValue))
22
+ }
23
+ },
24
+ getJSON (key) {
25
+ const value = this.get(key)
26
+ if (value != null) {
27
+ return JSON.parse(value)
28
+ }
29
+ },
30
+ remove (key) {
31
+ sessionStorage.removeItem(key);
32
+ }
33
+ }
34
+ const localCache = {
35
+ set (key, value) {
36
+ if (!localStorage) {
37
+ return
38
+ }
39
+ if (key != null && value != null) {
40
+ localStorage.setItem(key, value)
41
+ }
42
+ },
43
+ get (key) {
44
+ if (!localStorage) {
45
+ return null
46
+ }
47
+ if (key == null) {
48
+ return null
49
+ }
50
+ return localStorage.getItem(key)
51
+ },
52
+ setJSON (key, jsonValue) {
53
+ if (jsonValue != null) {
54
+ this.set(key, JSON.stringify(jsonValue))
55
+ }
56
+ },
57
+ getJSON (key) {
58
+ const value = this.get(key)
59
+ if (value != null) {
60
+ return JSON.parse(value)
61
+ }
62
+ },
63
+ remove (key) {
64
+ localStorage.removeItem(key);
65
+ }
66
+ }
67
+
68
+ export default {
69
+ /**
70
+ * 会话级缓存
71
+ */
72
+ session: sessionCache,
73
+ /**
74
+ * 本地缓存
75
+ */
76
+ local: localCache
77
+ }
@@ -0,0 +1,299 @@
1
+ <template>
2
+ <div class="robot-tools">
3
+ <div class="robot-reanswer"
4
+ style="margin-bottom: 8px"
5
+ v-if="listData.stop || listData.finish"
6
+ @click="reAnswer(listData)">
7
+ <i class="el-icon-refresh-right"></i>
8
+ 重新回答
9
+ </div>
10
+ <div class="stopMsg" style="color: #cfcfcf; cursor: default" v-if="listData.stop">已停止生成</div>
11
+ <div class="stopMsg"
12
+ @click="stopChat(listData)"
13
+ v-if="!listData.stop && !listData.finish">停止输出</div>
14
+ <div class="right-tools">
15
+ <el-tooltip content="赞" effect="light" placement="top">
16
+ <div class="tools-icon" @click="doZan(listData)">
17
+ <img src="../static/zan.png" alt="" v-if="!listData.zan" />
18
+ <img alt="" src="../static/zan-active.png" v-else />
19
+ </div>
20
+ </el-tooltip>
21
+ <el-popover v-model="popover" placement="top-start" trigger="manual">
22
+ <div slot="reference">
23
+ <el-tooltip content="踩" effect="light" placement="bottom">
24
+ <div class="tools-icon" @click="openPopover" v-if="!listData.cai">
25
+ <img alt="" src="../static/cai.png">
26
+ </div>
27
+ <div class="tools-icon" v-else @click="doCai(listData)">
28
+ <img alt="" src="../static/cai-active.png">
29
+ </div>
30
+ </el-tooltip>
31
+ </div>
32
+ <div class="popover-box">
33
+ <div class="pop-title">
34
+ 你的反馈将 <br/>
35
+ 帮助职教一问优化进步
36
+ </div>
37
+ <i class="el-icon-close" style="font-size: 2rem"
38
+ @click="cancelPopover()"></i>
39
+ <div class="error-list">
40
+ <el-checkbox-group v-model="errors">
41
+ <el-checkbox v-for="item in errorList"
42
+ :key="item.code"
43
+ :label="item.code"
44
+ border
45
+ class="check">
46
+ {{ item.name }}
47
+ </el-checkbox>
48
+ </el-checkbox-group>
49
+ <el-input v-model="input" :rows="4"
50
+ maxlength="30"
51
+ placeholder="其他"
52
+ resize="none"
53
+ type="textarea" />
54
+ <div class="sumit-button">
55
+ <el-button :disabled="canSubmit" @click="doCai(listData)">提交</el-button>
56
+ </div>
57
+ </div>
58
+ </div>
59
+ </el-popover>
60
+ </div>
61
+ </div>
62
+ </template>
63
+ <script>
64
+ import { errorList } from "../utils/config";
65
+ import { chatEvaluateAdd, stopChat, chatEvaluateCancel, pustReanswerToTeacher } from '../api/index';
66
+ export default {
67
+ name: 'ChatTools',
68
+ props: {
69
+ detailData: {
70
+ type: Object,
71
+ default: () => {}
72
+ },
73
+ chatId: {
74
+ type: String,
75
+ default: '',
76
+ },
77
+ },
78
+ data() {
79
+ return {
80
+ input: "",
81
+ popover: false,
82
+ errors: [],
83
+ errorList: errorList,
84
+ }
85
+ },
86
+ computed: {
87
+ canSubmit() {
88
+ return this.errors.length === 0 && this.input === "";
89
+ },
90
+ listData() {
91
+ return this.detailData;
92
+ },
93
+ },
94
+ methods: {
95
+ cancelPopover() {
96
+ this.popover = false;
97
+ },
98
+ openPopover() {
99
+ this.popover = true;
100
+ },
101
+ async stopChat(list) {
102
+ const { msgId } = list;
103
+ await stopChat(msgId);
104
+ list.stop = true;
105
+ this.$emit('on-stop-chat', list)
106
+ },
107
+ async reAnswer(list) {
108
+ list.reAnswerCount += 1;
109
+ if (list.reAnswerCount >= 3) {
110
+ this.$confirm('对于回答是否依旧不满意,是否需要给教师负责人发送请求信息,由老师进行回答?', '提示', {
111
+ confirmButtonText: '确定',
112
+ cancelButtonText: '取消',
113
+ type: 'warning'
114
+ }).then(async () => {
115
+ await pustReanswerToTeacher({
116
+ chatId: this.chatId,
117
+ msgId: list.chatId,
118
+ parentMsgId: list.parentMsgId,
119
+ });
120
+ this.$message.success('已发送给老师')
121
+ }).catch(() => {});
122
+ }
123
+ this.$emit('on-reanswer', list);
124
+ },
125
+ async doZan(list) {
126
+ const param = {
127
+ chatId: this.chatId,
128
+ msgId: list.msgId,
129
+ type: 1,
130
+ }
131
+ list.zan ? await chatEvaluateCancel(param) : await chatEvaluateAdd(param);
132
+ list.zan = !list.zan;
133
+ list.cai = false;
134
+ },
135
+ async doCai(list) {
136
+ let caiOption = {};
137
+ if (!list.cai) {
138
+ caiOption = {
139
+ desc: this.input,
140
+ tags: this.errors
141
+ }
142
+ }
143
+ const param = {
144
+ chatId: this.chatId,
145
+ msgId: list.msgId,
146
+ type: 2,
147
+ ...caiOption
148
+ }
149
+ list.cai ? await chatEvaluateCancel(param) : await chatEvaluateAdd(param);
150
+ list.cai = !list.cai;
151
+ list.zan = false;
152
+ if (list.cai) {
153
+ this.$message.success('感谢您的反馈');
154
+ }
155
+ this.popover = false;
156
+ this.input = '';
157
+ this.errors = [];
158
+ }
159
+ }
160
+ }
161
+ </script>
162
+ <style lang="scss" scoped>
163
+ .robot-tools {
164
+ position: relative;
165
+ margin-top: 8px;
166
+ .robot-reanswer {
167
+ width: 104px;
168
+ height: 32px;
169
+ background-color: rgba(32, 40, 64, 0.078);
170
+ border-radius: 16px;
171
+ font-size: 13px;
172
+ text-align: center;
173
+ line-height: 32px;
174
+ cursor: pointer;
175
+
176
+ &:hover {
177
+ background: #ced0f0;
178
+ }
179
+
180
+ i {
181
+ font-size: 18px;
182
+ vertical-align: middle;
183
+ }
184
+ }
185
+ .stopMsg {
186
+ cursor: pointer;
187
+ height: 20px;
188
+ width: 100px;
189
+ font-size: 14px;
190
+ color: #316cff;
191
+ }
192
+ .tools-icon {
193
+ width: 40px;
194
+ height: 32px;
195
+ background-color: rgba(32, 40, 64, 0.078);
196
+ border-radius: 16px;
197
+ text-align: center;
198
+ line-height: 34px;
199
+ cursor: pointer;
200
+ margin-right: 8px;
201
+
202
+ &:hover {
203
+ background: #ced0f0;
204
+ }
205
+ }
206
+ .right-tools {
207
+ position: absolute;
208
+ right: 0;
209
+ top: 0;
210
+ display: flex;
211
+ }
212
+ }
213
+ .popover-box {
214
+ width: 380px;
215
+ height: 450px;
216
+ border-radius: 20px;
217
+ padding: 20px;
218
+ box-sizing: border-box;
219
+ position: relative;
220
+
221
+ .pop-title {
222
+ width: 220px;
223
+ height: 60px;
224
+ font-family: PingFangSC, PingFang SC;
225
+ font-weight: 500;
226
+ font-size: 22px;
227
+ color: #333333;
228
+ line-height: 30px;
229
+ text-align: left;
230
+ font-style: normal;
231
+ }
232
+
233
+ .el-icon-close {
234
+ position: absolute;
235
+ right: 0;
236
+ top: 0;
237
+ color: #333333;
238
+ cursor: pointer;
239
+ transition: all 0.3s;
240
+
241
+ &:hover {
242
+ transform: rotate(-180deg);
243
+ }
244
+ }
245
+
246
+ .error-list {
247
+ display: flex;
248
+ flex-wrap: wrap;
249
+ margin-top: 20px;
250
+
251
+ .el-textarea__inner {
252
+ resize: none;
253
+ }
254
+
255
+ .sumit-button {
256
+ margin-top: 20px;
257
+ margin-left: 114px;
258
+
259
+ .el-button {
260
+ width: 112px;
261
+ height: 42px;
262
+ background: linear-gradient(180deg, #5fa5ff 0%, #316cff 100%);
263
+ border-radius: 21px;
264
+ color: #fff;
265
+ }
266
+ }
267
+
268
+ label {
269
+ text-align: center;
270
+ }
271
+
272
+ .check.is-bordered {
273
+ margin-right: 0;
274
+ width: 165px;
275
+ height: 42px;
276
+ background: #f3f7ff;
277
+ border-radius: 6px;
278
+ margin-left: 0;
279
+ margin-bottom: 10px;
280
+
281
+ &:nth-child(2n-1) {
282
+ margin-right: 10px;
283
+ }
284
+
285
+ ::v-deep .el-checkbox__inner {
286
+ display: none;
287
+ }
288
+ }
289
+ }
290
+
291
+ ::v-deep .el-checkbox.is-bordered.is-checked {
292
+ border-color: #316cff;
293
+ }
294
+
295
+ ::v-deep .el-checkbox__input.is-checked+.el-checkbox__label {
296
+ color: #316cff;
297
+ }
298
+ }
299
+ </style>