@arkxos/arkos-core 0.1.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 +36 -0
- package/ark_dist/ark-meta.json +45 -0
- package/ark_dist/css/370.fbd21c4a.css +65 -0
- package/ark_dist/index.html +23 -0
- package/ark_dist/js/370.b7feb826.js +3 -0
- package/ark_dist/js/370.b7feb826.js.LICENSE.txt +16 -0
- package/ark_dist/js/370.b7feb826.js.map +1 -0
- package/ark_dist/js/app.87081276.js +1 -0
- package/ark_proxy/entry.js +48 -0
- package/ark_proxy_es/entry.js +18 -0
- package/package.json +114 -0
- package/scripts/check.js +13 -0
- package/scripts/meta.js +21 -0
- package/scripts/prepublishOnly.js +28 -0
- package/src/App.vue +25 -0
- package/src/access/tokenStorage.ts +10 -0
- package/src/api/index.js +13 -0
- package/src/api/model/auth.js +88 -0
- package/src/api/model/common.js +49 -0
- package/src/api/model/demo.js +56 -0
- package/src/api/model/system.js +114 -0
- package/src/api/systemApi.js +16 -0
- package/src/assets/logo.png +0 -0
- package/src/components/HelloWorld.vue +40 -0
- package/src/components/index.ts +12 -0
- package/src/configs/subApp.ts +9 -0
- package/src/core/api/http.ts +490 -0
- package/src/core/apitest/axios_config.js +10 -0
- package/src/core/apitest/index.js +10 -0
- package/src/core/apitest/mock/user.js +10 -0
- package/src/core/config/index.js +84 -0
- package/src/core/config/myConfig.js +14 -0
- package/src/core/i18n/i18nBuilder.ts +41 -0
- package/src/core/puzzle/readme.txt +4 -0
- package/src/core/router/router.js +80 -0
- package/src/core/system.ts +312 -0
- package/src/directive/authDirective.ts +61 -0
- package/src/directive/index.ts +16 -0
- package/src/entrance/libProperties.ts +57 -0
- package/src/entrance/libTypes.ts +47 -0
- package/src/enums/LanguageEnum.ts +5 -0
- package/src/hooks/message.ts +81 -0
- package/src/lang/en_US.ts +28 -0
- package/src/lang/index.ts +73 -0
- package/src/lang/zh_CN.ts +27 -0
- package/src/loadApp.ts +4 -0
- package/src/main.ts +16 -0
- package/src/plugins/access.ts +88 -0
- package/src/plugins/accessPlugin.ts +76 -0
- package/src/plugins/acl/index.js +24 -0
- package/src/plugins/priv.ts +23 -0
- package/src/shims-vue.d.ts +6 -0
- package/src/store/index.ts +22 -0
- package/src/store/modules/systemStore.ts +31 -0
- package/src/types/axios.d.ts +13 -0
- package/src/types/func.ts +14 -0
- package/src/types/global.d.ts +108 -0
- package/src/types/layout.d.ts +59 -0
- package/src/types/mitt.d.ts +42 -0
- package/src/types/pinia.d.ts +94 -0
- package/src/types/views.d.ts +27 -0
- package/src/utils/mitt.ts +8 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|--------------------------------------------------------------------------
|
|
3
|
+
|
|
|
4
|
+
| 这些组件暴露给使用方
|
|
5
|
+
|
|
|
6
|
+
|--------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
import HelloWorld from './HelloWorld.vue'
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
HelloWorld
|
|
12
|
+
}
|
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
import axios, { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
|
2
|
+
import { ElNotification, ElMessageBox, ElMessage, ElLoading } from 'element-plus'
|
|
3
|
+
|
|
4
|
+
import sysConfig from '../config';
|
|
5
|
+
import {
|
|
6
|
+
tool,
|
|
7
|
+
util,
|
|
8
|
+
sessionCache,
|
|
9
|
+
HttpStatusErrorMessage,
|
|
10
|
+
HttpStatus,
|
|
11
|
+
crypto,
|
|
12
|
+
jsencrypt,
|
|
13
|
+
sessionCache as Session
|
|
14
|
+
} from '@arkxos/arkos-util';
|
|
15
|
+
import router from '../router/router';
|
|
16
|
+
import { saveAs } from 'file-saver'
|
|
17
|
+
import { getToken } from '../../access/tokenStorage';
|
|
18
|
+
import { getLanguage } from '../../lang';
|
|
19
|
+
import qs from 'qs';
|
|
20
|
+
const tansParams = util.tansParams;
|
|
21
|
+
const blobValidate = util.blobValidate;
|
|
22
|
+
|
|
23
|
+
const encryptHeader = 'encrypt-key';
|
|
24
|
+
|
|
25
|
+
// 常用header
|
|
26
|
+
export enum CommonHeaderEnum {
|
|
27
|
+
'TENANT_ID' = 'TENANT-ID',
|
|
28
|
+
'ENC_FLAG' = 'Enc-Flag',
|
|
29
|
+
'AUTHORIZATION' = 'Authorization',
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 是否显示重新登录
|
|
33
|
+
export const isRelogin = { show: false };
|
|
34
|
+
|
|
35
|
+
export const globalHeaders = () => {
|
|
36
|
+
return {
|
|
37
|
+
Authorization: 'Bearer ' + getToken(),
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
arkClientId: window.Arkos?.appInfo?.clientId
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
axios.defaults.baseURL = ''
|
|
44
|
+
|
|
45
|
+
axios.defaults.timeout = sysConfig.TIMEOUT
|
|
46
|
+
|
|
47
|
+
axios.defaults.headers['accept'] = 'application/json;charset=utf-8'
|
|
48
|
+
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
|
49
|
+
// 对应国际化资源文件后缀
|
|
50
|
+
axios.defaults.headers['Content-Language'] = 'zh-cn'
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
axios.defaults.headers['arkClientId'] = window.Arkos?.appInfo?.clientId;
|
|
53
|
+
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
if (window.Arkos?.api?.global?.headers) {
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
for (const key in window.Arkos?.api.global.headers) {
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
const value = window.Arkos?.api.global.headers[key]
|
|
60
|
+
axios.defaults.headers[key] = value
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 创建并配置一个 Axios 实例对象
|
|
66
|
+
*/
|
|
67
|
+
const service = axios.create({
|
|
68
|
+
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
|
69
|
+
baseURL: sysConfig.API_URL || '',
|
|
70
|
+
// 超时../../core/api/http
|
|
71
|
+
timeout: sysConfig.TIMEOUT, // 全局超时时间
|
|
72
|
+
paramsSerializer: {
|
|
73
|
+
serialize: (params: any) => {
|
|
74
|
+
return qs.stringify(params, { arrayFormat: 'repeat' });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Axios请求拦截器,对请求进行处理
|
|
81
|
+
* 1. 序列化get请求参数
|
|
82
|
+
* 2. 统一增加Authorization和TENANT-ID请求头
|
|
83
|
+
* 3. 自动适配单体、微服务架构不同的URL
|
|
84
|
+
* @param config AxiosRequestConfig对象,包含请求配置信息
|
|
85
|
+
*/
|
|
86
|
+
service.interceptors.request.use(
|
|
87
|
+
(config: InternalAxiosRequestConfig) => {
|
|
88
|
+
console.log('pre request', config)
|
|
89
|
+
// 对应国际化资源文件后缀
|
|
90
|
+
config.headers['Content-Language'] = getLanguage();
|
|
91
|
+
|
|
92
|
+
const headers: any = config.headers || {};
|
|
93
|
+
|
|
94
|
+
// 是否需要防止数据重复提交
|
|
95
|
+
const isNotRepeatSubmit = headers.repeatSubmit === false
|
|
96
|
+
|
|
97
|
+
const token = getToken();
|
|
98
|
+
|
|
99
|
+
if (token && !headers.skipToken) { // 让每个请求携带自定义token
|
|
100
|
+
config.headers![sysConfig.TOKEN_NAME] = sysConfig.TOKEN_PREFIX + token
|
|
101
|
+
}
|
|
102
|
+
if (!sysConfig.REQUEST_CACHE && config.method == 'get') {
|
|
103
|
+
config.params = config.params || {};
|
|
104
|
+
config.params._ = new Date().getTime();
|
|
105
|
+
}
|
|
106
|
+
Object.assign(config.headers, sysConfig.HEADERS)
|
|
107
|
+
|
|
108
|
+
// get请求映射params参数
|
|
109
|
+
if (config.method === 'get' && config.params) {
|
|
110
|
+
let url = config.url + '?' + tansParams(config.params);
|
|
111
|
+
url = url.slice(0, -1);
|
|
112
|
+
config.params = {};
|
|
113
|
+
config.url = url;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (!isNotRepeatSubmit && (
|
|
117
|
+
config.method === 'post' ||
|
|
118
|
+
config.method === 'put' ||
|
|
119
|
+
config.method === 'delete')) {
|
|
120
|
+
const requestObj = {
|
|
121
|
+
url: config.url,
|
|
122
|
+
method: config.method,
|
|
123
|
+
data: typeof config.data === 'object' ? JSON.stringify(config.data) : config.data,
|
|
124
|
+
time: new Date().getTime()
|
|
125
|
+
}
|
|
126
|
+
console.log('requestObj', requestObj)
|
|
127
|
+
const sessionObj = sessionCache.getJSON('sessionObj')
|
|
128
|
+
console.log('exist sessionObj', sessionObj)
|
|
129
|
+
if (sessionObj === undefined || sessionObj === null || sessionObj === '') {
|
|
130
|
+
sessionCache.setJSON('sessionObj', requestObj)
|
|
131
|
+
} else {
|
|
132
|
+
const s_url = sessionObj.url; // 请求地址
|
|
133
|
+
const s_method = sessionObj.method; // 请求数据
|
|
134
|
+
const s_data = sessionObj.data; // 请求数据
|
|
135
|
+
const s_time = sessionObj.time; // 请求时间
|
|
136
|
+
const interval = 1000; // 间隔时间(ms),小于此时间视为重复提交
|
|
137
|
+
if (s_data === requestObj.data &&
|
|
138
|
+
requestObj.time - s_time < interval &&
|
|
139
|
+
s_url === requestObj.url &&
|
|
140
|
+
s_method === requestObj.method) {
|
|
141
|
+
const message = '数据正在处理,请勿重复操作';
|
|
142
|
+
console.warn(`[${s_url}]: ` + message)
|
|
143
|
+
return Promise.reject(new Error(message))
|
|
144
|
+
} else {
|
|
145
|
+
sessionCache.setJSON('sessionObj', requestObj)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// 是否需要加密
|
|
151
|
+
const isEncrypt = headers.isEncrypt === true;
|
|
152
|
+
// 当开启参数加密
|
|
153
|
+
if (isEncrypt && (config.method === 'post' || config.method === 'put')) {
|
|
154
|
+
// 生成一个 AES 密钥
|
|
155
|
+
const aesKey = crypto.generateAesKey();
|
|
156
|
+
config.headers[encryptHeader] = jsencrypt.encrypt(crypto.encryptBase64(aesKey));
|
|
157
|
+
config.data = typeof config.data === 'object'
|
|
158
|
+
? crypto.encryptWithAes(JSON.stringify(config.data), aesKey)
|
|
159
|
+
: crypto.encryptWithAes(config.data, aesKey);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// FormData数据去请求头Content-Type
|
|
163
|
+
if (config.data instanceof FormData) {
|
|
164
|
+
delete config.headers['Content-Type'];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// 自动适配单体和微服务架构不同的URL
|
|
168
|
+
// config.url = other.adaptationUrl(config.url);
|
|
169
|
+
|
|
170
|
+
return config;
|
|
171
|
+
},
|
|
172
|
+
(error) => {
|
|
173
|
+
return Promise.reject(error);
|
|
174
|
+
}
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
// FIX 多个API同时401时疯狂弹窗BUG
|
|
178
|
+
let MessageBox_401_show = false
|
|
179
|
+
|
|
180
|
+
// HTTP response 拦截器
|
|
181
|
+
/**
|
|
182
|
+
* 响应拦截器处理函数
|
|
183
|
+
* @param response 响应结果
|
|
184
|
+
* @returns 如果响应成功,则返回响应的data属性;否则,抛出错误或者执行其他操作
|
|
185
|
+
*/
|
|
186
|
+
service.interceptors.response.use(
|
|
187
|
+
(response: AxiosResponse) => {
|
|
188
|
+
console.log('http response', response)
|
|
189
|
+
// 加密后的 AES 秘钥
|
|
190
|
+
const keyStr = response.headers[encryptHeader];
|
|
191
|
+
// 加密
|
|
192
|
+
if (keyStr != null && keyStr != '') {
|
|
193
|
+
const data = response.data;
|
|
194
|
+
// 请求体 AES 解密
|
|
195
|
+
const base64Str = jsencrypt.decrypt(keyStr);
|
|
196
|
+
// base64 解码 得到请求头的 AES 秘钥
|
|
197
|
+
const aesKey = crypto.decryptBase64(base64Str.toString());
|
|
198
|
+
// aesKey 解码 data
|
|
199
|
+
const decryptData = crypto.decryptWithAes(data, aesKey);
|
|
200
|
+
// 将结果 (得到的是 JSON 字符串) 转为 JSON
|
|
201
|
+
response.data = JSON.parse(decryptData);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// 未设置状态码则默认成功状态
|
|
205
|
+
let code = HttpStatus.SUCCESS;
|
|
206
|
+
if (response.data?.code) {
|
|
207
|
+
code = response.data.code
|
|
208
|
+
} else if (response?.status) {
|
|
209
|
+
code = response.status
|
|
210
|
+
}
|
|
211
|
+
// 获取错误信息
|
|
212
|
+
const msg = HttpStatusErrorMessage[code] || response.data.msg || HttpStatusErrorMessage.default
|
|
213
|
+
// 二进制数据则直接返回
|
|
214
|
+
if (response.request.responseType === 'blob' || response.request.responseType === 'arraybuffer') {
|
|
215
|
+
return response.data
|
|
216
|
+
}
|
|
217
|
+
// console.log('response data', response.data)
|
|
218
|
+
if (code === 401) {
|
|
219
|
+
console.error('请求401:' + response.config.url);
|
|
220
|
+
ElNotification.error({
|
|
221
|
+
title: '未授权',
|
|
222
|
+
message: 'Status:401,正在请求未授权的地址:' + response.config.url + '!'
|
|
223
|
+
});
|
|
224
|
+
// if (!isRelogin.show) {
|
|
225
|
+
// isRelogin.show = true;
|
|
226
|
+
// ElMessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
|
|
227
|
+
// confirmButtonText: '重新登录', cancelButtonText: '取消', type: 'warning'
|
|
228
|
+
// }).then(() => {
|
|
229
|
+
// isRelogin.show = false;
|
|
230
|
+
// useUserStore().logOut().then(() => {
|
|
231
|
+
// location.href = '/#/index';
|
|
232
|
+
// })
|
|
233
|
+
// }).catch(() => {
|
|
234
|
+
// isRelogin.show = false;
|
|
235
|
+
// });
|
|
236
|
+
// }
|
|
237
|
+
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
|
238
|
+
} else if (code === HttpStatus.TOKEN_EXPIRE) {
|
|
239
|
+
ElMessageBox.confirm('令牌状态已过期,请点击重新登录。', '令牌状态已过期', {
|
|
240
|
+
type: 'error',
|
|
241
|
+
closeOnClickModal: false,
|
|
242
|
+
center: true,
|
|
243
|
+
confirmButtonText: '重新登录'
|
|
244
|
+
}).then(() => {
|
|
245
|
+
Session.clear(); // 清除浏览器全部临时缓存
|
|
246
|
+
window.location.href = '/'; // 去登录页
|
|
247
|
+
}).catch(() => {})
|
|
248
|
+
} else if (code === HttpStatus.SERVER_ERROR) {
|
|
249
|
+
ElMessage({ message: msg, type: 'error' })
|
|
250
|
+
return Promise.reject(new Error(msg))
|
|
251
|
+
} else if (code === HttpStatus.WARN) {
|
|
252
|
+
ElMessage({ message: msg, type: 'warning' })
|
|
253
|
+
return Promise.reject(new Error(msg))
|
|
254
|
+
} else if (code !== HttpStatus.SUCCESS) {
|
|
255
|
+
ElNotification.error({ title: msg })
|
|
256
|
+
return Promise.reject('error')
|
|
257
|
+
} else if (response.data) {
|
|
258
|
+
return Promise.resolve(response.data)
|
|
259
|
+
} else {
|
|
260
|
+
return Promise.resolve(response)
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
(error) => {
|
|
264
|
+
if (error.response) {
|
|
265
|
+
if (error.response.status == 404) {
|
|
266
|
+
ElNotification.error({
|
|
267
|
+
title: '请求错误',
|
|
268
|
+
message: 'Status:404,正在请求不存在的服务器记录!'
|
|
269
|
+
});
|
|
270
|
+
} else if (error.response.status == 500) {
|
|
271
|
+
ElNotification.error({
|
|
272
|
+
title: '请求错误',
|
|
273
|
+
message: error.response.data.message || 'Status:500,服务器发生错误!'
|
|
274
|
+
});
|
|
275
|
+
} else if (error.response.status == 401) {
|
|
276
|
+
if (!MessageBox_401_show) {
|
|
277
|
+
MessageBox_401_show = true
|
|
278
|
+
ElMessageBox.confirm('当前用户已被登出或无权限访问当前资源,请尝试重新登录后再操作。', '无权限访问', {
|
|
279
|
+
type: 'error',
|
|
280
|
+
closeOnClickModal: false,
|
|
281
|
+
center: true,
|
|
282
|
+
confirmButtonText: '重新登录',
|
|
283
|
+
beforeClose: (action, instance, done) => {
|
|
284
|
+
MessageBox_401_show = false
|
|
285
|
+
done()
|
|
286
|
+
}
|
|
287
|
+
}).then(() => {
|
|
288
|
+
router.replace({ path: '/login' });
|
|
289
|
+
}).catch(() => {})
|
|
290
|
+
}
|
|
291
|
+
} else {
|
|
292
|
+
ElNotification.error({
|
|
293
|
+
title: '请求错误',
|
|
294
|
+
message: error.message || `Status:${error.response.status},未知错误!`
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
} else {
|
|
298
|
+
ElNotification.error({
|
|
299
|
+
title: '请求错误',
|
|
300
|
+
message: '请求服务器无响应!'
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
let { message } = error;
|
|
305
|
+
if (message == 'Network Error') {
|
|
306
|
+
message = '后端接口连接异常';
|
|
307
|
+
} else if (message.includes('timeout')) {
|
|
308
|
+
message = '系统接口请求超时';
|
|
309
|
+
} else if (message.includes('Request failed with status code')) {
|
|
310
|
+
message = '系统接口' + message.substr(message.length - 3) + '异常';
|
|
311
|
+
}
|
|
312
|
+
ElMessage({ message: message, type: 'error', duration: 5 * 1000 })
|
|
313
|
+
|
|
314
|
+
return Promise.reject(error);
|
|
315
|
+
}
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
export const http = {
|
|
319
|
+
|
|
320
|
+
request: function (config) {
|
|
321
|
+
return new Promise((resolve, reject) => {
|
|
322
|
+
service(config).then((response) => {
|
|
323
|
+
resolve(response);
|
|
324
|
+
}).catch((error) => {
|
|
325
|
+
reject(error);
|
|
326
|
+
})
|
|
327
|
+
})
|
|
328
|
+
},
|
|
329
|
+
// 通用下载方法
|
|
330
|
+
download: function (url: string, params: any, filename: string, config: any) {
|
|
331
|
+
const downloadLoadingInstance = ElLoading.service({ text: '正在下载数据,请稍候', background: 'rgba(0, 0, 0, 0.7)', })
|
|
332
|
+
return service.post(url, params, {
|
|
333
|
+
transformRequest: [(params) => { return tansParams(params) }],
|
|
334
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
335
|
+
responseType: 'blob',
|
|
336
|
+
...config
|
|
337
|
+
}).then(async (resp) => {
|
|
338
|
+
const isBlob = blobValidate(resp);
|
|
339
|
+
if (isBlob) {
|
|
340
|
+
// @ts-ignore
|
|
341
|
+
const blob = new Blob([resp])
|
|
342
|
+
saveAs(blob, filename)
|
|
343
|
+
} else {
|
|
344
|
+
const resText = await resp.data.text();
|
|
345
|
+
const rspObj = JSON.parse(resText);
|
|
346
|
+
const errMsg = HttpStatusErrorMessage[rspObj.code] || rspObj.msg || HttpStatusErrorMessage.default
|
|
347
|
+
ElMessage.error(errMsg);
|
|
348
|
+
}
|
|
349
|
+
downloadLoadingInstance.close();
|
|
350
|
+
}).catch((r) => {
|
|
351
|
+
console.error(r)
|
|
352
|
+
ElMessage.error('下载文件出现错误,请联系管理员!')
|
|
353
|
+
downloadLoadingInstance.close();
|
|
354
|
+
})
|
|
355
|
+
},
|
|
356
|
+
|
|
357
|
+
/** get 请求
|
|
358
|
+
* @param {string} url 接口地址
|
|
359
|
+
* @param {object} params 请求参数
|
|
360
|
+
* @param {object} config 参数
|
|
361
|
+
*/
|
|
362
|
+
get: function (url, params = {}, config = {}) {
|
|
363
|
+
return new Promise((resolve, reject) => {
|
|
364
|
+
service({
|
|
365
|
+
method: 'get',
|
|
366
|
+
url: url,
|
|
367
|
+
params: params,
|
|
368
|
+
...config
|
|
369
|
+
}).then((response) => {
|
|
370
|
+
resolve(response.data);
|
|
371
|
+
}).catch((error) => {
|
|
372
|
+
reject(error);
|
|
373
|
+
})
|
|
374
|
+
})
|
|
375
|
+
},
|
|
376
|
+
|
|
377
|
+
/** post 请求
|
|
378
|
+
* @param {string} url 接口地址
|
|
379
|
+
* @param {object} data 请求参数
|
|
380
|
+
* @param {object} config 参数
|
|
381
|
+
*/
|
|
382
|
+
post: function (url, data = {}, config = {}) {
|
|
383
|
+
return new Promise((resolve, reject) => {
|
|
384
|
+
service({
|
|
385
|
+
method: 'post',
|
|
386
|
+
url: url,
|
|
387
|
+
data: data,
|
|
388
|
+
...config
|
|
389
|
+
}).then((response) => {
|
|
390
|
+
resolve(response.data);
|
|
391
|
+
}).catch((error) => {
|
|
392
|
+
reject(error);
|
|
393
|
+
})
|
|
394
|
+
})
|
|
395
|
+
},
|
|
396
|
+
|
|
397
|
+
/** put 请求
|
|
398
|
+
* @param {string} url 接口地址
|
|
399
|
+
* @param {object} data 请求参数
|
|
400
|
+
* @param {object} config 参数
|
|
401
|
+
*/
|
|
402
|
+
put: function (url, data = {}, config = {}) {
|
|
403
|
+
return new Promise((resolve, reject) => {
|
|
404
|
+
service({
|
|
405
|
+
method: 'put',
|
|
406
|
+
url: url,
|
|
407
|
+
data: data,
|
|
408
|
+
...config
|
|
409
|
+
}).then((response) => {
|
|
410
|
+
resolve(response.data);
|
|
411
|
+
}).catch((error) => {
|
|
412
|
+
reject(error);
|
|
413
|
+
})
|
|
414
|
+
})
|
|
415
|
+
},
|
|
416
|
+
|
|
417
|
+
/** patch 请求
|
|
418
|
+
* @param {string} url 接口地址
|
|
419
|
+
* @param {object} data 请求参数
|
|
420
|
+
* @param {object} config 参数
|
|
421
|
+
*/
|
|
422
|
+
patch: function (url, data = {}, config = {}) {
|
|
423
|
+
return new Promise((resolve, reject) => {
|
|
424
|
+
service({
|
|
425
|
+
method: 'patch',
|
|
426
|
+
url: url,
|
|
427
|
+
data: data,
|
|
428
|
+
...config
|
|
429
|
+
}).then((response) => {
|
|
430
|
+
resolve(response.data);
|
|
431
|
+
}).catch((error) => {
|
|
432
|
+
reject(error);
|
|
433
|
+
})
|
|
434
|
+
})
|
|
435
|
+
},
|
|
436
|
+
|
|
437
|
+
/** delete 请求
|
|
438
|
+
* @param {string} url 接口地址
|
|
439
|
+
* @param {object} data 请求参数
|
|
440
|
+
* @param {object} config 参数
|
|
441
|
+
*/
|
|
442
|
+
delete: function (url, data = {}, config = {}) {
|
|
443
|
+
return new Promise((resolve, reject) => {
|
|
444
|
+
service({
|
|
445
|
+
method: 'delete',
|
|
446
|
+
url: url,
|
|
447
|
+
data: data,
|
|
448
|
+
...config
|
|
449
|
+
}).then((response) => {
|
|
450
|
+
resolve(response.data);
|
|
451
|
+
}).catch((error) => {
|
|
452
|
+
reject(error);
|
|
453
|
+
})
|
|
454
|
+
})
|
|
455
|
+
},
|
|
456
|
+
|
|
457
|
+
/** jsonp 请求
|
|
458
|
+
* @param {string} url 接口地址
|
|
459
|
+
* @param {string} name JSONP回调函数名称
|
|
460
|
+
*/
|
|
461
|
+
jsonp: function (url, name = 'jsonp') {
|
|
462
|
+
return new Promise((resolve) => {
|
|
463
|
+
const script = document.createElement('script')
|
|
464
|
+
const _id = `jsonp${Math.ceil(Math.random() * 1000000)}`
|
|
465
|
+
script.id = _id
|
|
466
|
+
script.type = 'text/javascript'
|
|
467
|
+
script.src = url
|
|
468
|
+
window[name] = (response) => {
|
|
469
|
+
resolve(response)
|
|
470
|
+
document.getElementsByTagName('head')[0].removeChild(script)
|
|
471
|
+
try {
|
|
472
|
+
delete window[name];
|
|
473
|
+
} catch (e) {
|
|
474
|
+
window[name] = undefined;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
document.getElementsByTagName('head')[0].appendChild(script)
|
|
478
|
+
})
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
export const request = http.request
|
|
483
|
+
export const get = http.get
|
|
484
|
+
export const post = http.post
|
|
485
|
+
export const put = http.put
|
|
486
|
+
export const patch = http.patch
|
|
487
|
+
export const deleted = http.delete
|
|
488
|
+
export const jsonp = http.jsonp
|
|
489
|
+
|
|
490
|
+
export default service;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// 模拟数据
|
|
2
|
+
import user from './mock/user';
|
|
3
|
+
|
|
4
|
+
export const getUser = () =>
|
|
5
|
+
new Promise(resolve =>
|
|
6
|
+
setTimeout(() => {
|
|
7
|
+
if (sessionStorage.getItem('arkos-theme')) { user.theme = JSON.parse(sessionStorage.getItem('arkos-theme')); }
|
|
8
|
+
resolve(user);
|
|
9
|
+
}, 100)
|
|
10
|
+
);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
|
|
2
|
+
// 合并业务配置
|
|
3
|
+
import MY_CONFIG from './myConfig'
|
|
4
|
+
|
|
5
|
+
const DEFAULT_CONFIG = {
|
|
6
|
+
|
|
7
|
+
envModel: 'development',
|
|
8
|
+
|
|
9
|
+
// 标题
|
|
10
|
+
ArkosTitle: 'Ark OS', // process.env.VUE_APP_TITLE,
|
|
11
|
+
|
|
12
|
+
// 首页地址
|
|
13
|
+
DASHBOARD_URL: '/arkui-sample/dashboard',
|
|
14
|
+
|
|
15
|
+
// 版本号
|
|
16
|
+
APP_VER: '1.0.0',
|
|
17
|
+
|
|
18
|
+
// 内核版本号
|
|
19
|
+
CORE_VER: '1.0.0',
|
|
20
|
+
|
|
21
|
+
// 接口地址
|
|
22
|
+
API_URL: '/gateway', // process.env.NODE_ENV === 'development' && process.env.VUE_APP_PROXY === 'true' ? "/api" : process.env.VUE_APP_API_BASEURL,
|
|
23
|
+
|
|
24
|
+
// 请求超时
|
|
25
|
+
TIMEOUT: 30000,
|
|
26
|
+
|
|
27
|
+
// TokenName
|
|
28
|
+
TOKEN_NAME: 'Authorization',
|
|
29
|
+
|
|
30
|
+
// Token前缀,注意最后有个空格,如不需要需设置空字符串
|
|
31
|
+
TOKEN_PREFIX: 'Bearer ',
|
|
32
|
+
|
|
33
|
+
// 追加其他头
|
|
34
|
+
HEADERS: {},
|
|
35
|
+
|
|
36
|
+
// 请求是否开启缓存
|
|
37
|
+
REQUEST_CACHE: false,
|
|
38
|
+
|
|
39
|
+
// 布局 默认:default | 通栏:header | 经典:menu | 功能坞:dock
|
|
40
|
+
// dock将关闭标签和面包屑栏
|
|
41
|
+
LAYOUT: 'header',
|
|
42
|
+
|
|
43
|
+
// 菜单是否折叠
|
|
44
|
+
MENU_IS_COLLAPSE: false,
|
|
45
|
+
|
|
46
|
+
// 菜单是否启用手风琴效果
|
|
47
|
+
MENU_UNIQUE_OPENED: false,
|
|
48
|
+
|
|
49
|
+
// 是否开启多标签
|
|
50
|
+
LAYOUT_TAGS: true,
|
|
51
|
+
|
|
52
|
+
// 语言
|
|
53
|
+
LANG: 'zh-cn',
|
|
54
|
+
|
|
55
|
+
// 主题颜色
|
|
56
|
+
COLOR: '',
|
|
57
|
+
|
|
58
|
+
// 是否加密localStorage, 为空不加密,可填写AES(模式ECB,移位Pkcs7)加密
|
|
59
|
+
LS_ENCRYPTION: '',
|
|
60
|
+
|
|
61
|
+
// localStorageAES加密秘钥,位数建议填写8的倍数
|
|
62
|
+
LS_ENCRYPTION_key: '2XNN4K8LC0ELVWN4',
|
|
63
|
+
|
|
64
|
+
// 控制台首页默认布局
|
|
65
|
+
DEFAULT_GRID: {
|
|
66
|
+
// 默认分栏数量和宽度 例如 [24] [18,6] [8,8,8] [6,12,6]
|
|
67
|
+
layout: [12, 6, 6],
|
|
68
|
+
// 小组件分布,com取值:views/home/components 文件名
|
|
69
|
+
copmsList: [
|
|
70
|
+
['welcome'],
|
|
71
|
+
['about', 'ver'],
|
|
72
|
+
['time', 'progress']
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
Object.assign(DEFAULT_CONFIG, MY_CONFIG)
|
|
77
|
+
|
|
78
|
+
// 如果生产模式,就合并动态的APP_CONFIG
|
|
79
|
+
// public/config.js
|
|
80
|
+
// if(process.env.NODE_ENV === 'production'){
|
|
81
|
+
Object.assign(DEFAULT_CONFIG, ArkosGlobalConfig)
|
|
82
|
+
// }
|
|
83
|
+
|
|
84
|
+
export default DEFAULT_CONFIG
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// 业务配置
|
|
2
|
+
// 会合并至this.$CONFIG
|
|
3
|
+
// 生产模式 public/config.js 同名key会覆盖这里的配置从而实现打包后的热更新
|
|
4
|
+
// 为避免和SCUI框架配置混淆建议添加前缀 MY_
|
|
5
|
+
// 全局可使用 this.$CONFIG.MY_KEY 访问
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
// 是否显示第三方授权登录
|
|
9
|
+
MY_SHOW_LOGIN_OAUTH: true,
|
|
10
|
+
|
|
11
|
+
// 标题
|
|
12
|
+
ArkosTitle: 'ArkX OS', // process.env.VUE_APP_TITLE,
|
|
13
|
+
|
|
14
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
export default (i18nFileData:any) => {
|
|
3
|
+
// 定义变量内容
|
|
4
|
+
const i18nMessage = {};
|
|
5
|
+
|
|
6
|
+
const itemize = { en: [] as any[], 'zh-cn': [] as any[] };
|
|
7
|
+
|
|
8
|
+
// files.keys().forEach((key) => {
|
|
9
|
+
// modules[key.replace(/(\.\/|\.js)/g, '')] = files(key).default
|
|
10
|
+
// })
|
|
11
|
+
|
|
12
|
+
// 对自动引入的 modules 进行分类 en、zh-cn、zh-tw
|
|
13
|
+
// https://vitejs.cn/vite3-cn/guide/features.html#glob-import
|
|
14
|
+
for (const path in i18nFileData) {
|
|
15
|
+
const key = path.match(/(\S+)\/(\S+).ts/);
|
|
16
|
+
const data = i18nFileData[path];
|
|
17
|
+
|
|
18
|
+
if (itemize[key![2]]) itemize[key![2]].push(data);
|
|
19
|
+
else itemize[key![2]] = data;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 合并数组对象(非标准数组对象,数组中对象的每项 key、value 都不同)
|
|
23
|
+
function mergeArrObj<T>(list: T, key: string) {
|
|
24
|
+
let obj = {};
|
|
25
|
+
list[key].forEach((i) => {
|
|
26
|
+
obj = Object.assign({}, obj, i);
|
|
27
|
+
});
|
|
28
|
+
return obj;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
for (const key in itemize) {
|
|
32
|
+
i18nMessage[key] = {
|
|
33
|
+
name: key,
|
|
34
|
+
// el: element[key].el,
|
|
35
|
+
...mergeArrObj(itemize, key),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
console.log('app-system-i18n', i18nMessage)
|
|
39
|
+
|
|
40
|
+
return i18nMessage
|
|
41
|
+
}
|