ai-error-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.
Files changed (34) hide show
  1. package/README.md +33 -0
  2. package/components/demo/api/index.js +84 -0
  3. package/components/demo/index.js +7 -0
  4. package/components/demo/plugins/cache.js +77 -0
  5. package/components/demo/src/chat-tools.vue +289 -0
  6. package/components/demo/src/chat.vue +342 -0
  7. package/components/demo/src/error-chat.vue +247 -0
  8. package/components/demo/src/main.vue +221 -0
  9. package/components/demo/static/bg-img.png +0 -0
  10. package/components/demo/static/cai-active.png +0 -0
  11. package/components/demo/static/cai.png +0 -0
  12. package/components/demo/static/correct.png +0 -0
  13. package/components/demo/static/error.png +0 -0
  14. package/components/demo/static/logo.png +0 -0
  15. package/components/demo/static/robot.png +0 -0
  16. package/components/demo/static/send-icon.png +0 -0
  17. package/components/demo/static/zan-active.png +0 -0
  18. package/components/demo/static/zan.png +0 -0
  19. package/components/demo/utils/aes-utils.js +35 -0
  20. package/components/demo/utils/config.js +88 -0
  21. package/components/demo/utils/constants.js +13 -0
  22. package/components/demo/utils/request.js +69 -0
  23. package/components/index.js +15 -0
  24. package/dist/ai-error-assistant-pro.common.js +12065 -0
  25. package/dist/ai-error-assistant-pro.common.js.map +1 -0
  26. package/dist/ai-error-assistant-pro.css +1 -0
  27. package/dist/ai-error-assistant-pro.umd.js +12084 -0
  28. package/dist/ai-error-assistant-pro.umd.js.map +1 -0
  29. package/dist/ai-error-assistant-pro.umd.min.js +18 -0
  30. package/dist/ai-error-assistant-pro.umd.min.js.map +1 -0
  31. package/dist/demo.html +1 -0
  32. package/dist/img/bg-img.9391d6da.png +0 -0
  33. package/dist/img/robot.7ad12cd4.png +0 -0
  34. package/package.json +44 -0
@@ -0,0 +1,221 @@
1
+ <template>
2
+ <div class="ai-contain" v-if="visible">
3
+ <div class="bg-image"></div>
4
+ <div class="ai-contain-header">
5
+ <div class="logo-title">
6
+ <img src="../static/logo.png" alt="" style="width: 48px; height: 48px">
7
+ <span class="title-font">智能解析</span>
8
+ </div>
9
+ <div class="icon-close" @click="closeMessage">
10
+ <i class="el-icon-close"></i>
11
+ </div>
12
+ </div>
13
+ <div class="ai-main-content">
14
+ <chat ref="chatRef"
15
+ :resId="resId"
16
+ :xtId="xtId"
17
+ :key-word="aiMessageKeyWord"
18
+ :analy-exercise="analyExercise"
19
+ @on-reanser="reanserMethod"
20
+ @on-message-finish="messageFinish" />
21
+ </div>
22
+ <div class="tools-wrap">
23
+ <span @click="clearChat">清空对话</span>
24
+ </div>
25
+ <div class="ai-message-send" @keyup.enter="goChat">
26
+ <el-input v-model="aiMessage" placeholder="可以提出问题..." ></el-input>
27
+ <div class="ai-send-icon" @click="goChat">
28
+ <img src="../static/send-icon.png" alt="" style="width: 24px; height: 24px">
29
+ </div>
30
+ </div>
31
+ <p class="disclaimer">
32
+ 此功能公测期间对正式版用户开放
33
+ </p>
34
+ </div>
35
+ </template>
36
+ <script>
37
+ import Chat from './chat.vue';
38
+ import Cookies from "js-cookie";
39
+ import { getUserInfo } from '../utils/config';
40
+ import { chartClear } from '../api/index';
41
+ export default {
42
+ name: 'AiErrorAssistant',
43
+ components: {
44
+ Chat
45
+ },
46
+ props: {
47
+ visible: true,
48
+ analyExercise: {},
49
+ },
50
+ computed: {
51
+ resId() {
52
+ return this.analyExercise.courseId;
53
+ },
54
+ xtId() {
55
+ return this.analyExercise.busId;
56
+ }
57
+ },
58
+ data() {
59
+ return {
60
+ aiMessage: '', // 页面显示值
61
+ aiMessageKeyWord: '', // 传入组件值
62
+ stop: false
63
+ }
64
+ },
65
+ mounted() {
66
+ if (!Cookies.get("token")) {
67
+ return this.$message.warning('未获取到登录信息,请重新登录');
68
+ }
69
+ getUserInfo(Cookies.get("token"));
70
+ },
71
+ methods: {
72
+ closeMessage() {
73
+ this.$emit('close');
74
+ },
75
+ messageFinish() {
76
+ this.stop = false;
77
+ },
78
+ clearChat() {
79
+ if (!this.stopMessage()) {
80
+ return;
81
+ }
82
+ this.$refs.chatRef.clearChat();
83
+ },
84
+ goChat() {
85
+ if (!this.stopMessage()) {
86
+ return;
87
+ }
88
+ this.aiMessageKeyWord = this.aiMessage;
89
+ this.stop = true;
90
+ setTimeout(() => {
91
+ this.aiMessageKeyWord = this.aiMessage = '';
92
+ }, 300);
93
+ },
94
+ reanserMethod(){
95
+ this.stop = true;
96
+ },
97
+ stopMessage() {
98
+ if (this.stop) {
99
+ this.$message.warning('对话正在进行中,请稍后重试');
100
+ return false;
101
+ }
102
+ return true;
103
+ },
104
+ }
105
+ }
106
+ </script>
107
+ <style lang="scss" scoped>
108
+ .ai-contain {
109
+ width: 1000px;
110
+ height: 100%;
111
+ border-radius: 16px;
112
+ box-shadow: 0 1px 8px rgba(32, 40, 64, 0.32);
113
+ padding: 16px 16px 16px 16px;
114
+ box-sizing: border-box;
115
+ position: relative;
116
+ background-color: rgba(232, 240, 248, 1);
117
+ }
118
+ .ai-contain-header {
119
+ position: relative;
120
+ z-index: 1;
121
+ display: flex;
122
+ justify-content: space-between;
123
+ }
124
+ .logo-title {
125
+ font-weight: 700;
126
+ color: #202840;
127
+ font-size: 18px;
128
+ }
129
+ .title-font {
130
+ display: inline-block;
131
+ vertical-align: top;
132
+ margin-top: 12px;
133
+ margin-left: 12px;
134
+ color: rgb(40, 128, 240);
135
+ }
136
+ .icon-close {
137
+ cursor: pointer;
138
+ position: relative;
139
+ right: 0;
140
+ i {
141
+ font-weight: bold !important;
142
+ }
143
+ }
144
+ .ai-message-send-linear {
145
+ padding: 2px;
146
+ border-radius: 40px;
147
+ }
148
+ .tools-wrap {
149
+ width: calc(100% - 68px - 48px - 24px);
150
+ margin-left: 80px;
151
+ display: flex;
152
+ justify-content: end;
153
+ font-size: 13px;
154
+ margin-bottom: 8px;
155
+ color: #08d;
156
+ span {
157
+ cursor: pointer;
158
+ &:hover {
159
+ color: #0ad;
160
+ }
161
+ }
162
+ }
163
+ .bg-image {
164
+ position: absolute;
165
+ top: 0;
166
+ left: 0;
167
+ width: 100%;
168
+ height: 248px;
169
+ background: linear-gradient(to bottom, rgba(96, 96, 244, .1), rgba(44, 144, 240, 0));
170
+ border-radius: 16px 0;
171
+ }
172
+ .ai-message-send {
173
+ width: calc(100% - 68px - 48px);
174
+ background: linear-gradient(to right, #33cc88, #6699ff, #ff9933);
175
+ padding: 3px;
176
+ border-radius: 40px;
177
+ position: relative;
178
+ margin-left: 68px;
179
+ }
180
+ .ai-send-icon {
181
+ position: absolute;
182
+ right: 14px;
183
+ bottom: 14px;
184
+ width: 40px;
185
+ height: 40px;
186
+ text-align: center;
187
+ line-height: 52px;
188
+ border-radius: 20px;
189
+ cursor: pointer;
190
+ background: linear-gradient(90deg, rgba(0, 144, 240, 1) 0%, rgba(144, 48, 240, 1) 100%);
191
+ }
192
+ .ai-main-content {
193
+ position: relative;
194
+ z-index: 1;
195
+ height: calc(100% - 53px - 86px - 32px - 17px);
196
+ padding: 16px 0 16px 8px;
197
+ }
198
+ .disclaimer {
199
+ margin: 0;
200
+ font-size: 14px;
201
+ color: #cfcfcf;
202
+ text-align: center;
203
+ margin-top: 6px;
204
+ }
205
+ :deep {
206
+ .ai-message-send {
207
+ .el-input__inner {
208
+ height: 60px;
209
+ font-size: 16px;
210
+ color: rgba(51,51,51,.75);
211
+ border: 0;
212
+ border-radius: 40px;
213
+ background: linear-gradient(to bottom, #fff, #d8f0fb);
214
+ padding: 0 24px;
215
+ &::placeholder {
216
+ color: rgba(51,51,51,.75);
217
+ }
218
+ }
219
+ }
220
+ }
221
+ </style>
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,35 @@
1
+ import CryptoJS from 'crypto-js';
2
+ import { Base64 } from 'js-base64';
3
+
4
+ const a = 'RU5D';
5
+ const b = 'ODE';
6
+ const c = 'AE';
7
+ const d = 'S_K';
8
+ const e = 'RVkx';
9
+ const z = Base64.decode(a).concat(b, '_', c, d, Base64.decode(e), '6');
10
+ const f = 'd3d3';
11
+ const g = 'w.e';
12
+ const i = 'mru';
13
+ const j = 'bik';
14
+ const k = 'Y29t';
15
+ const n = Base64.decode(f).concat(g, i, j, '.', Base64.decode(k));
16
+ const key = CryptoJS.enc.Utf8.parse(z);
17
+ const iv = CryptoJS.enc.Utf8.parse(n);
18
+ // 解密方法
19
+ export function decrypt(word) {
20
+ const stringToEncode = 'Hello, World!'; // 要进行 Base64 编码的字符串
21
+ const encodedString = Base64.encode(stringToEncode); // 进行 Base64 编码
22
+ const decodedString = Base64.decode(encodedString); // 进行 Base64 解码
23
+
24
+ let base64 = CryptoJS.enc.Base64.parse(word);
25
+ let src = CryptoJS.enc.Base64.stringify(base64);
26
+
27
+ let decrypt = CryptoJS.AES.decrypt(src, key, {
28
+ iv: iv,
29
+ mode: CryptoJS.mode.CBC,
30
+ padding: CryptoJS.pad.Pkcs7,
31
+ });
32
+
33
+ let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
34
+ return decryptedStr.toString();
35
+ }
@@ -0,0 +1,88 @@
1
+ import { ssoAuth, authUser } from '../api/index';
2
+ import constants from '../utils/constants';
3
+ import cache from '../plugins/cache';
4
+
5
+ export const errorList = [
6
+ {
7
+ name: "格式问题",
8
+ code: "1",
9
+ },
10
+ {
11
+ name: "逻辑问题",
12
+ code: "2",
13
+ },
14
+ {
15
+ name: "有害信息",
16
+ code: "3",
17
+ },
18
+ {
19
+ name: "事实错误",
20
+ code: "4",
21
+ },
22
+ {
23
+ name: "没有帮助",
24
+ code: "5",
25
+ },
26
+ {
27
+ name: "答非所问",
28
+ code: "6",
29
+ },
30
+ ]
31
+
32
+ export const cacheMessageList = [
33
+ {
34
+ type: 'user',
35
+ message: '电磁感应定律是如何描述的?请给出相关公式并解释。'
36
+ },
37
+ {
38
+ type: 'robot',
39
+ message: '电磁感应定律是描述磁场与电场之间关系的物理定律。具体来说,当导体回路中的磁通量发生变化时,会在回路中产生感应电动势。这个感应电动势的大小与磁通量变化的速率成正比,这就是法拉第电磁感应定律。\n' +
40
+ ' 相关的公式是:ε = -dΦ/dt\n' +
41
+ ' 其中,ε 表示感应电动势,Φ 表示磁通量,t 表示时间,dΦ/dt 则表示磁通量对时间的变化率。注意这里的负号,它表示感应电动势的方向与磁通量变化的方向相反,这是楞次定律的体现。\n' +
42
+ ' 解释这个公式时,我们可以理解为:当穿过一个闭合导体回路的磁通量发生变化时,会在回路中产生感应电动势,其大小正比于磁通量变化的速率。这种感应电动势是由于磁场的变化而引发的,它是磁场变化对电场的直接影响,体现了磁场与电场之间的紧密联系。'
43
+ }
44
+ ]
45
+
46
+ // 下方注释为题目示例
47
+ // export const questionStem = {
48
+ // // type: 'single',
49
+ // // type: 'multiple',
50
+ // title: '为了切实兑现中国政府加强保护上海世博会各参展方知识产权的国际承诺,4月15日上海成立了“世博会参展者知识产权服务中心”,并开展了以“创新与知识产权让世博会更精彩”为主题的2010年上海知识产权宣传周活动。下列对知识产权认识正确的是: ( )',
51
+ // options: ['A. 不是商品,因为它没有价值', 'B. 是商品,因为它具有价值和交换价值两个基本属性', 'C. 不是商品,因为它看不见、摸不着', 'D. 是商品,因为它是使用价值和价值的统一体'],
52
+ // answer: ['D. 是商品,因为它是使用价值和价值的统一体'],
53
+ // studentAnswer: ['B. 是商品,因为它具有价值和交换价值两个基本属性'],
54
+ // }
55
+
56
+ // export const questionStem = {
57
+ // type: 'judge',
58
+ // title: '为了切实兑现中国政府加强保护上海世博会各参展方知识产权的国际承诺,4月15日上海成立了“世博会参展者知识产权服务中心”,并开展了以“创新与知识产权让世博会更精彩”为主题的2010年上海知识产权宣传周活动',
59
+ // answer: false,
60
+ // studentAnswer: true,
61
+ // }
62
+
63
+ // export const questionStem = {
64
+ // type: 'gapfilling',
65
+ // title: '为了切实兑现中国政府加强()世博会各参展方知识产权的国际承诺,()上海成立了“世博会参展者知识产权服务中心”,()”为主题的2010年上海知识产权宣传周活动',
66
+ // answer: ['上海世博会', '4月15日', '并开展了以“创新与知识产权让', '主题的2010年上海'],
67
+ // studentAnswer: ['上会', '4月1', '并开展了以“创新权让', '主题的2010'],
68
+ // }
69
+
70
+ // export const questionStem = {
71
+ // type: 'shortanswer',
72
+ // title: '为了切实兑现中国政府加强保护上海世博会各参展方知识产权的国际承诺,4月15日上海成立了“世博会参展者知识产权服务中心”,并开展了以“创新与知识产权让世博会更精彩”为主题的2010年上海知识产权宣传周活动',
73
+ // answer: '正确简答题回答正确简答题回答正确简答题回答,正确简答题回答正确简答题回答正确简答题回答正确简答题回答,正确简答题回答正确简答题回答正确简答题回答,正确简答题回答',
74
+ // studentAnswer: '错误的简答题简答题错误错误的简答题简答题错误错误的简答题简答题错误错误的简答题简答题错误',
75
+ // }
76
+
77
+ export const getUserInfo = async (token) => {
78
+ const ssoRes = await ssoAuth(token);
79
+ const userRes = await authUser({
80
+ 'X-Auth-User': encodeURIComponent(ssoRes.name),
81
+ 'X-Auth-Token': ssoRes.password,
82
+ 'X-Enterprise-Id': `${constants['X-Enterprise-Id']}`,
83
+ 'X-App-Id': `${constants['X-App-Id']}`,
84
+ 'X-App-Secret': `${constants['X-App-Secret']}`,
85
+ 'X-Auth-User-Type': '1',
86
+ });
87
+ cache.session.setJSON('SRKJ_TOKEN_CACHE', userRes);
88
+ }
@@ -0,0 +1,13 @@
1
+ let appId = '601a39a2a4a7cd88d5ddcef5';
2
+ const whiteList = ['/home', '/overview'];
3
+ if (process.env.VITE_APP_BUILD_TYPE === 'aliyun') {
4
+ appId = '6572ba195ec962924cc39951';
5
+ }
6
+
7
+ export default {
8
+ 'X-Enterprise-Id': 'www.hep-zj.com.cn',
9
+ 'X-App-Id': '90403a27c0704259ab7a3c8aab4489b3',
10
+ 'X-App-Secret': 'bc11ce7c44824fcaa23ff301a54b7094',
11
+ appId,
12
+ whiteList,
13
+ };
@@ -0,0 +1,69 @@
1
+ import axios from 'axios'
2
+ import cache from '../plugins/cache'
3
+ import { Message } from 'element-ui'
4
+ const door = sessionStorage.getItem('AI_BASE_URL_FOR_TEST');
5
+ import { decrypt } from './aes-utils';
6
+
7
+ axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
8
+
9
+ const service = axios.create({
10
+ // axios中请求配置有baseURL选项,表示请求URL公共部分
11
+ baseURL: door || 'https://zjyw.icve.com.cn/ai-api',
12
+ // 超时
13
+ timeout: 80000
14
+ })
15
+
16
+ service.interceptors.request.use(config => {
17
+ if (cache.session.getJSON('SRKJ_TOKEN_CACHE')) {
18
+ config.headers["X-Id-Token"] = cache.session.getJSON('SRKJ_TOKEN_CACHE');
19
+ }
20
+ // 是否需要防止数据重复提交
21
+ const isRepeatSubmit = (config.headers || {}).repeatSubmit === false;
22
+ if (!isRepeatSubmit && (config.method === 'post' || config.method === 'put')) {
23
+ const requestObj = {
24
+ url: config.url,
25
+ data: typeof config.data === 'object' ? JSON.stringify(config.data) : config.data,
26
+ time: new Date().getTime()
27
+ }
28
+ const sessionObj = cache.session.getJSON('sessionObj')
29
+ if (sessionObj === undefined || sessionObj === null || sessionObj === '') {
30
+ cache.session.setJSON('sessionObj', requestObj)
31
+ } else {
32
+ const s_url = sessionObj.url; // 请求地址
33
+ const s_data = sessionObj.data; // 请求数据
34
+ const s_time = sessionObj.time; // 请求时间
35
+ const interval = 100; // 间隔时间(ms),小于此时间视为重复提交
36
+ if (s_data === requestObj.data && requestObj.time - s_time < interval && s_url === requestObj.url) {
37
+ } else {
38
+ cache.session.setJSON('sessionObj', requestObj)
39
+ }
40
+ }
41
+ }
42
+ return config
43
+ }, error => {
44
+ Promise.reject(error)
45
+ })
46
+
47
+ service.interceptors.response.use(res => {
48
+ // 二进制数据则直接返回
49
+ if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
50
+ return res.data
51
+ }
52
+ let srkjData = res.data;
53
+ if (srkjData) {
54
+ const respData = decrypt(srkjData);
55
+ try {
56
+ srkjData = JSON.parse(respData);
57
+ } catch (e) {}
58
+ }
59
+ if (res.status === 401) {
60
+ Message.warning(srkjData.message.description);
61
+ return;
62
+ }
63
+ if (!srkjData.resultCode.endsWith('0000')) {
64
+ Message.warning(srkjData.message.description)
65
+ }
66
+ return srkjData.queryData || srkjData.data || srkjData.token;
67
+ })
68
+
69
+ export default service
@@ -0,0 +1,15 @@
1
+ import AiErrorAssistant from './demo'
2
+ const components = {
3
+ AiErrorAssistant
4
+ }
5
+
6
+ const install = function (Vue) {
7
+ if (install.installed) return
8
+ Object.keys(components).forEach(key => {
9
+ Vue.component(components[key].name,components[key])
10
+ });
11
+ }
12
+
13
+ export default {
14
+ install
15
+ }