vue-ops-chat 1.0.0
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 +46 -0
- package/dist/dist/index.css +860 -0
- package/dist/index.esm.js +1 -0
- package/dist/index.umd.js +1 -0
- package/package.json +37 -0
- package/src/App.vue +21 -0
- package/src/api/chat.js +67 -0
- package/src/api/index.js +7 -0
- package/src/api/service.js +155 -0
- package/src/api/urls.js +33 -0
- package/src/assets/logo.png +0 -0
- package/src/components/AgentAssistant/ChatModal.vue +500 -0
- package/src/components/AgentAssistant/FloatingTrigger.vue +138 -0
- package/src/components/AgentAssistant/Icons/SvgIcon.vue +60 -0
- package/src/components/AgentAssistant/Icons/iconPaths.js +176 -0
- package/src/components/AgentAssistant/Icons/index.js +22 -0
- package/src/components/AgentAssistant/ImagePreview.vue +109 -0
- package/src/components/AgentAssistant/ImagePreviewModal.vue +473 -0
- package/src/components/AgentAssistant/MessageBubble.vue +153 -0
- package/src/components/AgentAssistant/MessageImages.vue +113 -0
- package/src/components/AgentAssistant/MessageList.vue +101 -0
- package/src/components/AgentAssistant/UploadButton.vue +159 -0
- package/src/components/AgentAssistant/WelcomeMessage.vue +77 -0
- package/src/components/AgentAssistant/index.vue +470 -0
- package/src/components/AgentAssistant/props.js +68 -0
- package/src/constants/messages.js +45 -0
- package/src/index.js +71 -0
- package/src/main.js +4 -0
- package/src/utils/__tests__/auth.test.js +56 -0
- package/src/utils/auth.js +63 -0
- package/src/utils/version.js +42 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 认证管理器测试
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import authManager from '../utils/auth';
|
|
6
|
+
|
|
7
|
+
describe('AuthManager', () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
// 清理localStorage
|
|
10
|
+
localStorage.clear();
|
|
11
|
+
// 重置认证管理器状态
|
|
12
|
+
authManager.clearCertificate();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
localStorage.clear();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('应该能够设置和获取证书', () => {
|
|
20
|
+
const certificate = 'test-certificate-123';
|
|
21
|
+
authManager.setCertificate(certificate);
|
|
22
|
+
|
|
23
|
+
expect(authManager.getCertificate()).toBe(certificate);
|
|
24
|
+
expect(authManager.isAuth()).toBe(true);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('应该能够从localStorage恢复证书', () => {
|
|
28
|
+
const certificate = 'persistent-certificate-456';
|
|
29
|
+
localStorage.setItem('chat_certificate', certificate);
|
|
30
|
+
|
|
31
|
+
// 清空内存中的证书
|
|
32
|
+
authManager.certificate = '';
|
|
33
|
+
authManager.isAuthenticated = false;
|
|
34
|
+
|
|
35
|
+
// 重新获取应该从localStorage读取
|
|
36
|
+
expect(authManager.getCertificate()).toBe(certificate);
|
|
37
|
+
expect(authManager.isAuth()).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('应该能够清除证书', () => {
|
|
41
|
+
authManager.setCertificate('some-certificate');
|
|
42
|
+
authManager.clearCertificate();
|
|
43
|
+
|
|
44
|
+
expect(authManager.getCertificate()).toBe('');
|
|
45
|
+
expect(authManager.isAuth()).toBe(false);
|
|
46
|
+
expect(localStorage.getItem('chat_certificate')).toBeNull();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('空证书应该被视为未认证', () => {
|
|
50
|
+
authManager.setCertificate('');
|
|
51
|
+
expect(authManager.isAuth()).toBe(false);
|
|
52
|
+
|
|
53
|
+
authManager.setCertificate(null);
|
|
54
|
+
expect(authManager.isAuth()).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 认证管理工具
|
|
3
|
+
* 用于存储和管理全局身份认证信息
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
class AuthManager {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.certificate = '';
|
|
9
|
+
this.isAuthenticated = false;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 设置身份认证证书
|
|
14
|
+
* @param {string} certificate - 身份认证证书
|
|
15
|
+
*/
|
|
16
|
+
setCertificate(certificate) {
|
|
17
|
+
this.certificate = certificate || '';
|
|
18
|
+
this.isAuthenticated = !!this.certificate;
|
|
19
|
+
// 存储到localStorage以便持久化
|
|
20
|
+
if (this.certificate) {
|
|
21
|
+
localStorage.setItem('chat_certificate', this.certificate);
|
|
22
|
+
} else {
|
|
23
|
+
localStorage.removeItem('chat_certificate');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 获取身份认证证书
|
|
29
|
+
* @returns {string} 身份认证证书
|
|
30
|
+
*/
|
|
31
|
+
getCertificate() {
|
|
32
|
+
// 如果内存中没有,尝试从localStorage获取
|
|
33
|
+
if (!this.certificate) {
|
|
34
|
+
this.certificate = localStorage.getItem('chat_certificate') || '';
|
|
35
|
+
this.isAuthenticated = !!this.certificate;
|
|
36
|
+
}
|
|
37
|
+
return this.certificate;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 清除身份认证信息
|
|
42
|
+
*/
|
|
43
|
+
clearCertificate() {
|
|
44
|
+
this.certificate = '';
|
|
45
|
+
this.isAuthenticated = false;
|
|
46
|
+
localStorage.removeItem('chat_certificate');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 检查是否已认证
|
|
51
|
+
* @returns {boolean} 是否已认证
|
|
52
|
+
*/
|
|
53
|
+
isAuth() {
|
|
54
|
+
return this.isAuthenticated;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 创建全局单例实例
|
|
59
|
+
const authManager = new AuthManager();
|
|
60
|
+
|
|
61
|
+
// 导出实例和类
|
|
62
|
+
export default authManager;
|
|
63
|
+
export { AuthManager };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 判断 Vue 版本(2/3)
|
|
3
|
+
* @param {Object} VueOrApp - Vue2 构造函数 / Vue3 app 实例
|
|
4
|
+
* @returns {number} 2 | 3
|
|
5
|
+
*/
|
|
6
|
+
export function getVueVersion(VueOrApp) {
|
|
7
|
+
// 更准确的Vue版本检测
|
|
8
|
+
if (!VueOrApp) return 2; // 默认认为是Vue2
|
|
9
|
+
|
|
10
|
+
// 检查是否是Vue3
|
|
11
|
+
if (VueOrApp.version && VueOrApp.version.startsWith) {
|
|
12
|
+
return VueOrApp.version.startsWith('3.') ? 3 : 2;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// 检查是否存在_createVNode方法(Vue3特有)
|
|
16
|
+
if (VueOrApp._createVNode || (VueOrApp.constructor && VueOrApp.constructor.name === 'App')) {
|
|
17
|
+
return 3;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 检查是否是Vue2
|
|
21
|
+
if (VueOrApp.util && VueOrApp.set) {
|
|
22
|
+
return 2;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 默认返回2
|
|
26
|
+
return 2;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 适配全局属性挂载(Vue2 prototype / Vue3 globalProperties)
|
|
31
|
+
* @param {Object} VueOrApp - Vue2 构造函数 / Vue3 app 实例
|
|
32
|
+
* @param {string} key - 全局属性名(如 $myPlugin)
|
|
33
|
+
* @param {any} value - 挂载的值
|
|
34
|
+
*/
|
|
35
|
+
export function mountGlobalProperty(VueOrApp, key, value) {
|
|
36
|
+
const version = getVueVersion(VueOrApp);
|
|
37
|
+
if (version === 3) {
|
|
38
|
+
VueOrApp.config.globalProperties[key] = value;
|
|
39
|
+
} else {
|
|
40
|
+
VueOrApp.prototype[key] = value;
|
|
41
|
+
}
|
|
42
|
+
}
|