vibe-web-sdk 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/api/application/index.js +38 -0
- package/api/login.js +75 -0
- package/assets/css/css-vars.css +19 -0
- package/assets/css/frame.css +129 -0
- package/assets/futura.ttf +0 -0
- package/assets/images/flags/cn.svg +2 -0
- package/assets/images/flags/de.svg +5 -0
- package/assets/images/flags/gb.svg +15 -0
- package/assets/images/location.png +0 -0
- package/assets/images/logo.png +0 -0
- package/assets/images/moon.png +0 -0
- package/assets/images/sun.png +0 -0
- package/components/selfFooter/index.vue +264 -0
- package/components/selfHeader/index.vue +310 -0
- package/components/siderBar/index.vue +419 -0
- package/components/siderMenu/index.vue +385 -0
- package/index.js +20 -0
- package/lang/en.js +21 -0
- package/lang/zh.js +21 -0
- package/package.json +15 -0
- package/permission/hasPermi.js +23 -0
- package/permission/index.js +12 -0
- package/plugins/auth.js +60 -0
- package/plugins/index.js +14 -0
- package/plugins/modal.js +210 -0
- package/store/getters.js +10 -0
- package/store/index.js +14 -0
- package/store/modules/custom.js +25 -0
- package/store/modules/user.js +89 -0
- package/utils/auth.js +16 -0
- package/utils/cache.js +77 -0
- package/utils/common.js +239 -0
- package/utils/errorCode.js +6 -0
- package/utils/jsencrypt.js +30 -0
- package/utils/request.js +222 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'
|
|
2
|
+
|
|
3
|
+
// 密钥对生成 http://web.chacuo.net/netrsakeypair
|
|
4
|
+
|
|
5
|
+
const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n' +
|
|
6
|
+
'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=='
|
|
7
|
+
|
|
8
|
+
const privateKey = 'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n' +
|
|
9
|
+
'7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n' +
|
|
10
|
+
'PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n' +
|
|
11
|
+
'kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n' +
|
|
12
|
+
'cSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99Ecv\n' +
|
|
13
|
+
'DQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthh\n' +
|
|
14
|
+
'YhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3\n' +
|
|
15
|
+
'UP8iWi1Qw0Y='
|
|
16
|
+
|
|
17
|
+
// 加密
|
|
18
|
+
export function encrypt(txt) {
|
|
19
|
+
const encryptor = new JSEncrypt()
|
|
20
|
+
encryptor.setPublicKey(publicKey) // 设置公钥
|
|
21
|
+
return encryptor.encrypt(txt) // 对数据进行加密
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// 解密
|
|
25
|
+
export function decrypt(txt) {
|
|
26
|
+
const encryptor = new JSEncrypt()
|
|
27
|
+
encryptor.setPrivateKey(privateKey) // 设置私钥
|
|
28
|
+
return encryptor.decrypt(txt) // 对数据进行解密
|
|
29
|
+
}
|
|
30
|
+
|
package/utils/request.js
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { ElLoading, ElMessageBox, ElNotification } from 'element-plus';
|
|
3
|
+
import { saveAs } from 'file-saver';
|
|
4
|
+
import en from "../lang/en";
|
|
5
|
+
import zh from "../lang/zh";
|
|
6
|
+
import { getToken } from "./auth";
|
|
7
|
+
import cache from './cache';
|
|
8
|
+
import { blobValidate, tansParams } from "./common";
|
|
9
|
+
import errorCode from './errorCode';
|
|
10
|
+
|
|
11
|
+
// 创建axios实例
|
|
12
|
+
const service = axios.create({
|
|
13
|
+
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
|
14
|
+
baseURL: process.env.VUE_APP_BASE_API,
|
|
15
|
+
// 超时
|
|
16
|
+
timeout: 10000
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
let downloadLoadingInstance;
|
|
21
|
+
// 是否显示重新登录
|
|
22
|
+
export let isRelogin = { show: false };
|
|
23
|
+
|
|
24
|
+
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
|
25
|
+
|
|
26
|
+
// request拦截器
|
|
27
|
+
service.interceptors.request.use(config => {
|
|
28
|
+
// 是否需要设置 token
|
|
29
|
+
const isToken = (config.headers || {}).isToken === false
|
|
30
|
+
// 是否需要防止数据重复提交
|
|
31
|
+
const isRepeatSubmit = (config.headers || {}).repeatSubmit === false
|
|
32
|
+
// 接口需要携带token
|
|
33
|
+
if (!isToken && getToken()) {
|
|
34
|
+
config.headers['Authorization'] = getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
|
|
35
|
+
}
|
|
36
|
+
// 非匿名接口访问 判断是否是登录请求,如果不是则直接跳转登录页
|
|
37
|
+
else {
|
|
38
|
+
// 非调试模式下需要校验是否登录
|
|
39
|
+
if (process.env.VUE_APP_PROJECT_DEV === "false" || process.env.VUE_APP_PROJECT_DEV === undefined) {
|
|
40
|
+
if (config.url.search("/userLogin/login") === -1) {
|
|
41
|
+
cache.local.remove("frame_user_name");
|
|
42
|
+
let tip = "";
|
|
43
|
+
if (localStorage.getItem("locale") === "zh-CN") {
|
|
44
|
+
tip = zh.unLogin;
|
|
45
|
+
}
|
|
46
|
+
else if (localStorage.getItem("locale") === "en-US") {
|
|
47
|
+
tip = en.unLogin;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
tip = zh.unLogin;
|
|
51
|
+
}
|
|
52
|
+
ElNotification({ message: tip, type: 'error', duration: 5 * 1000 });
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
// get请求映射params参数
|
|
60
|
+
if (config.method === 'get' && config.params) {
|
|
61
|
+
let url = config.url + '?' + tansParams(config.params);
|
|
62
|
+
url = url.slice(0, -1);
|
|
63
|
+
config.params = {};
|
|
64
|
+
config.url = url;
|
|
65
|
+
}
|
|
66
|
+
if (!isRepeatSubmit && (config.method === 'post' || config.method === 'put')) {
|
|
67
|
+
const requestObj = {
|
|
68
|
+
url: config.url,
|
|
69
|
+
data: typeof config.data === 'object' ? JSON.stringify(config.data) : config.data,
|
|
70
|
+
time: new Date().getTime(),
|
|
71
|
+
skipRepeat: config.skipRepeat === undefined ? false : config.skipRepeat
|
|
72
|
+
}
|
|
73
|
+
const sessionObj = cache.session.getJSON('sessionObj')
|
|
74
|
+
if (sessionObj === undefined || sessionObj === null || sessionObj === '') {
|
|
75
|
+
cache.session.setJSON('sessionObj', requestObj)
|
|
76
|
+
} else {
|
|
77
|
+
const s_url = sessionObj.url; // 请求地址
|
|
78
|
+
const s_data = sessionObj.data; // 请求数据
|
|
79
|
+
const s_time = sessionObj.time; // 请求时间
|
|
80
|
+
const interval = 50; // 间隔时间(ms),小于此时间视为重复提交
|
|
81
|
+
if (!requestObj.skipRepeat && s_data === requestObj.data && requestObj.time - s_time < interval && s_url === requestObj.url) {
|
|
82
|
+
let tip = "";
|
|
83
|
+
if (localStorage.getItem("locale") === "zh-CN") {
|
|
84
|
+
tip = zh.repeatSubmitTip;
|
|
85
|
+
}
|
|
86
|
+
else if (localStorage.getItem("locale") === "en-US") {
|
|
87
|
+
tip = en.repeatSubmitTip;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
tip = zh.repeatSubmitTip;
|
|
91
|
+
}
|
|
92
|
+
const message = tip;
|
|
93
|
+
console.warn(`[${s_url}]: ` + message)
|
|
94
|
+
return Promise.reject(new Error(message))
|
|
95
|
+
} else {
|
|
96
|
+
cache.session.setJSON('sessionObj', requestObj)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return config
|
|
101
|
+
}, error => {
|
|
102
|
+
console.log(error)
|
|
103
|
+
Promise.reject(error)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
// 响应拦截器
|
|
107
|
+
service.interceptors.response.use(res => {
|
|
108
|
+
// 未设置状态码则默认成功状态
|
|
109
|
+
const code = Number(res.data.code) || 200;
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
// 获取错误信息
|
|
113
|
+
const msg = res.data.msg || res.data.message || errorCode[code] || errorCode['default'];
|
|
114
|
+
|
|
115
|
+
// 二进制数据则直接返回
|
|
116
|
+
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
|
117
|
+
return res.data
|
|
118
|
+
}
|
|
119
|
+
// 未登录 要求重新登录
|
|
120
|
+
if (code === 999) {
|
|
121
|
+
if (!isRelogin.show) {
|
|
122
|
+
isRelogin.show = true;
|
|
123
|
+
let content = "";
|
|
124
|
+
let cancel = "";
|
|
125
|
+
let reLoginBtn = "";
|
|
126
|
+
let tip = "";
|
|
127
|
+
if (localStorage.getItem("locale") === "zh-CN") {
|
|
128
|
+
cancel = zh.cancel;
|
|
129
|
+
reLoginBtn = zh.confirm;
|
|
130
|
+
content = zh.reLoginTip
|
|
131
|
+
tip = zh.systemTip;
|
|
132
|
+
}
|
|
133
|
+
else if (localStorage.getItem("locale") === "en-US") {
|
|
134
|
+
cancel = en.cancel;
|
|
135
|
+
reLoginBtn = en.confirm;
|
|
136
|
+
content = en.reLoginTip
|
|
137
|
+
tip = en.systemTip;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
cancel = zh.cancel;
|
|
141
|
+
reLoginBtn = zh.confirm;
|
|
142
|
+
content = zh.reLoginTip
|
|
143
|
+
tip = zh.systemTip;
|
|
144
|
+
}
|
|
145
|
+
ElMessageBox.confirm(content, tip, { confirmButtonText: reLoginBtn, cancelButtonText: cancel, type: 'warning' }).then(() => {
|
|
146
|
+
isRelogin.show = false;
|
|
147
|
+
self.location.href = '/home#/login';
|
|
148
|
+
}).catch(() => {
|
|
149
|
+
isRelogin.show = false;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return res.data;
|
|
153
|
+
} else if (code === 500) {
|
|
154
|
+
ElNotification({ message: msg, type: 'warning' })
|
|
155
|
+
return Promise.resolve(new Error(msg))
|
|
156
|
+
} else if (code === 601) {
|
|
157
|
+
ElNotification({ message: msg, type: 'warning' })
|
|
158
|
+
return Promise.resolve('error')
|
|
159
|
+
} else if (code === 404) {
|
|
160
|
+
ElNotification({ message: msg, type: 'warning' })
|
|
161
|
+
return Promise.resolve('error')
|
|
162
|
+
}
|
|
163
|
+
else if (code !== 200) {
|
|
164
|
+
ElNotification.error({ title: msg })
|
|
165
|
+
return Promise.resolve('error')
|
|
166
|
+
} else {
|
|
167
|
+
return res.data
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
error => {
|
|
171
|
+
let { message } = error;
|
|
172
|
+
if (message == "Network Error") {
|
|
173
|
+
message = "Network Error";
|
|
174
|
+
}
|
|
175
|
+
else if (message.includes("timeout")) {
|
|
176
|
+
message = "Request timeout";
|
|
177
|
+
}
|
|
178
|
+
else if (message.includes("Request failed with status code")) {
|
|
179
|
+
if (message.includes("401")) {
|
|
180
|
+
ElNotification({ message: "非法访问,请购买应用证书", type: 'warning', duration: 5 * 1000 });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
else if(message.includes("undefined")) {
|
|
184
|
+
return Promise.resolve(error)
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
if(!message.includes("Request aborted")){
|
|
188
|
+
ElNotification({ message: message, type: 'warning', duration: 5 * 1000 })
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return Promise.resolve(error)
|
|
192
|
+
}
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
// 通用下载方法
|
|
196
|
+
export function download(url, params, filename, config) {
|
|
197
|
+
downloadLoadingInstance = ElLoading.service({ text: "正在下载数据,请稍候", spinner: "el-icon-loading", background: "rgba(0, 0, 0, 0.7)", })
|
|
198
|
+
return service.post(url, params, {
|
|
199
|
+
transformRequest: [(params) => { return tansParams(params) }],
|
|
200
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
201
|
+
responseType: 'blob',
|
|
202
|
+
...config
|
|
203
|
+
}).then(async (data) => {
|
|
204
|
+
const isLogin = await blobValidate(data);
|
|
205
|
+
if (isLogin) {
|
|
206
|
+
const blob = new Blob([data])
|
|
207
|
+
saveAs(blob, filename)
|
|
208
|
+
} else {
|
|
209
|
+
const resText = await data.text();
|
|
210
|
+
const rspObj = JSON.parse(resText);
|
|
211
|
+
const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default']
|
|
212
|
+
ElNotification.error(errMsg);
|
|
213
|
+
}
|
|
214
|
+
downloadLoadingInstance.close();
|
|
215
|
+
}).catch((r) => {
|
|
216
|
+
console.error(r)
|
|
217
|
+
ElNotification.error('下载文件出现错误,请联系管理员!')
|
|
218
|
+
downloadLoadingInstance.close();
|
|
219
|
+
})
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export default service;
|