eoss-ui 0.5.10 → 0.5.12
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/lib/button-group.js +246 -157
- package/lib/button.js +185 -108
- package/lib/card.js +2 -2
- package/lib/cascader.js +2 -2
- package/lib/checkbox-group.js +184 -108
- package/lib/clients.js +2 -2
- package/lib/data-table-form.js +183 -107
- package/lib/data-table.js +216 -131
- package/lib/date-picker.js +190 -113
- package/lib/dialog.js +192 -116
- package/lib/enterprise.js +2 -2
- package/lib/eoss-ui.common.js +506 -642
- package/lib/error-page.js +2 -2
- package/lib/flow-group.js +183 -106
- package/lib/flow-list.js +218 -116
- package/lib/flow.js +218 -125
- package/lib/form.js +308 -323
- package/lib/handle-user.js +186 -109
- package/lib/handler.js +184 -107
- package/lib/icons.js +4 -4
- package/lib/index.js +1 -1
- package/lib/input-number.js +185 -108
- package/lib/input.js +187 -110
- package/lib/label.js +2 -2
- package/lib/layout.js +4 -4
- package/lib/login.js +186 -110
- package/lib/main.js +311 -385
- package/lib/menu.js +2 -2
- package/lib/nav.js +185 -108
- package/lib/notify.js +2 -2
- package/lib/page.js +185 -108
- package/lib/pagination.js +2 -2
- package/lib/player.js +191 -114
- package/lib/qr-code.js +187 -110
- package/lib/radio-group.js +188 -111
- package/lib/retrial-auth.js +185 -108
- package/lib/select-ganged.js +183 -106
- package/lib/select.js +184 -107
- package/lib/selector-panel.js +184 -108
- package/lib/selector.js +185 -108
- package/lib/sizer.js +187 -110
- package/lib/steps.js +185 -108
- package/lib/switch.js +185 -108
- package/lib/table-form.js +197 -136
- package/lib/tabs-panel.js +2 -2
- package/lib/tabs.js +188 -111
- package/lib/theme-chalk/index.css +1 -1
- package/lib/theme-chalk/pagination.css +1 -1
- package/lib/theme-chalk/toolbar.css +1 -1
- package/lib/tips.js +185 -108
- package/lib/toolbar.js +21 -11
- package/lib/tree-group.js +183 -106
- package/lib/tree.js +183 -106
- package/lib/upload.js +186 -110
- package/lib/utils/util.js +35 -94
- package/lib/utils/webSocket.js +134 -0
- package/lib/wujie.js +185 -108
- package/lib/wxlogin.js +185 -108
- package/package.json +1 -1
- package/packages/data-table/src/main.vue +16 -8
- package/packages/data-table/src/sizer.vue +1 -1
- package/packages/flow/src/main.vue +2 -0
- package/packages/flow/src/processForm.vue +23 -9
- package/packages/flow-list/src/main.vue +25 -2
- package/packages/form/src/main.vue +11 -46
- package/packages/form/src/table.vue +6 -11
- package/packages/main/src/main.vue +25 -164
- package/packages/radio-group/src/main.vue +1 -5
- package/packages/theme-chalk/lib/index.css +1 -1
- package/packages/theme-chalk/lib/pagination.css +1 -1
- package/packages/theme-chalk/lib/toolbar.css +1 -1
- package/packages/theme-chalk/src/pagination.scss +8 -0
- package/packages/theme-chalk/src/toolbar.scss +1 -0
- package/packages/toolbar/src/main.vue +17 -8
- package/src/index.js +1 -1
- package/src/utils/util.js +58 -115
- package/src/utils/webSocket.js +103 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
.es-pagination .el-select .el-input{width:56px}.es-pagination:not(.is-background) .btn-next,.es-pagination:not(.is-background) .btn-prev,.es-pagination:not(.is-background) li{background-color:transparent!important}
|
|
1
|
+
.es-pagination .el-select .el-input{width:56px}.es-pagination:not(.is-background) .btn-next,.es-pagination:not(.is-background) .btn-prev,.es-pagination:not(.is-background) li{background-color:transparent!important}.es-pagination button,.es-pagination span:not([class*=suffix]){height:26px;line-height:26px}.es-pagination .el-input__suffix{line-height:26px}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
@charset "UTF-8";.es-toolbar{padding:6px 12px;border-bottom:1px solid #d9d9d9;position:relative;background-color:#fff}.es-toolbar .es-toolbar-content{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-pack:end;-ms-flex-pack:end;justify-content:flex-end}.es-toolbar .es-toolbar-content .es-button-content{-webkit-box-flex:1;-ms-flex:1;flex:1}.es-toolbar .es-toolbar-content .es-form{background:0 0}.es-toolbar .es-toolbar-content .es-form .es-form-content{padding:0}.es-toolbar .es-toolbar-content .es-form .el-form-item{margin-bottom:0}.es-toolbar .es-toolbar-content .es-advanced-btn{margin-left:12px}.es-toolbar .es-toolbar-content .es-toolbar-text{line-height:32px}.es-toolbar .es-toolbar-content .es-toolbar-info{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center}.es-toolbar .es-toolbar-content .es-toolbar-info .es-info{font-size:13px;margin-left:20px}.es-toolbar .es-toolbar-content .el-menu--horizontal{border-bottom:0;position:relative;bottom:-6px}.es-toolbar .es-toolbar-content .el-menu-item{height:32px;line-height:24px}.es-toolbar .es-toolbar-content .el-input__inner,.es-toolbar .es-toolbar-content .es-checkbox-group{height:32px;line-height:32px}.es-toolbar .es-toolbar-content .es-radio-group,.es-toolbar .es-toolbar-content .es-switch-content{line-height:32px}.es-toolbar .es-toolbar-content .el-switch{top:-2px}.es-toolbar .es-toolbar-content .el-button span{line-height:14px}.es-toolbar .es-toolbar-content .el-checkbox:not(:last-child),.es-toolbar .es-toolbar-content .el-radio:not(:last-child){margin-right:8px}.es-toolbar .es-toolbar-content .el-form-item.es-toolbar-item-checkbox+.el-form-item,.es-toolbar .es-toolbar-content .el-form-item.es-toolbar-item-radio+.el-form-item,.es-toolbar .es-toolbar-content .el-form-item.es-toolbar-item-switch+.el-form-item{margin-left:16px}.es-toolbar .es-toolbar-content .el-form-item .el-input__icon{line-height:32px;vertical-align:top}.es-toolbar .es-toolbar-content .es-form-search-small .el-input__inner{width:100%;max-width:156px}.es-toolbar .es-toolbar-content .es-form-search-small .el-input__inner.el-date-editor--daterange{max-width:300px}.es-toolbar .es-toolbar-content .es-form-search-small .el-input__inner.el-date-editor--daterange .el-input__icon,.es-toolbar .es-toolbar-content .es-form-search-small .el-input__inner.el-date-editor--daterange .el-range-separator{line-height:24px}.es-toolbar .es-advanced-filter{margin-top:20px;z-index:9}.es-toolbar .es-advanced-filter.es-absolute{position:absolute;left:0;top:45px;right:0;margin-top:0;-webkit-box-shadow:0 1px 10px rgba(0,0,0,.05),0 4px 5px rgba(0,0,0,.08),0 2px 4px -1px rgba(0,0,0,.12);box-shadow:0 1px 10px rgba(0,0,0,.05),0 4px 5px rgba(0,0,0,.08),0 2px 4px -1px rgba(0,0,0,.12);border-bottom-left-radius:6px;border-bottom-right-radius:6px}.es-toolbar .es-advanced-filter.es-absolute .es-form{background-color:#fff;border:1px solid #d9d9d9;border-bottom-left-radius:6px;border-bottom-right-radius:6px;border-top:0;padding:20px 20px 20px 10px}.es-toolbar .el-form-item__content
|
|
1
|
+
@charset "UTF-8";.es-toolbar{padding:6px 12px;border-bottom:1px solid #d9d9d9;position:relative;background-color:#fff}.es-toolbar .es-toolbar-content{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-pack:end;-ms-flex-pack:end;justify-content:flex-end}.es-toolbar .es-toolbar-content .es-button-content{-webkit-box-flex:1;-ms-flex:1;flex:1}.es-toolbar .es-toolbar-content .es-form{background:0 0}.es-toolbar .es-toolbar-content .es-form .es-form-content{padding:0}.es-toolbar .es-toolbar-content .es-form .el-form-item{margin-bottom:0}.es-toolbar .es-toolbar-content .es-advanced-btn{margin-left:12px}.es-toolbar .es-toolbar-content .es-toolbar-text{line-height:32px}.es-toolbar .es-toolbar-content .es-toolbar-info{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center}.es-toolbar .es-toolbar-content .es-toolbar-info .es-info{font-size:13px;margin-left:20px}.es-toolbar .es-toolbar-content .el-menu--horizontal{border-bottom:0;position:relative;bottom:-6px}.es-toolbar .es-toolbar-content .el-menu-item{height:32px;line-height:24px}.es-toolbar .es-toolbar-content .el-input__inner,.es-toolbar .es-toolbar-content .es-checkbox-group{height:32px;line-height:32px}.es-toolbar .es-toolbar-content .es-radio-group,.es-toolbar .es-toolbar-content .es-switch-content{line-height:32px}.es-toolbar .es-toolbar-content .el-switch{top:-2px}.es-toolbar .es-toolbar-content .el-button span{line-height:14px}.es-toolbar .es-toolbar-content .el-checkbox:not(:last-child),.es-toolbar .es-toolbar-content .el-radio:not(:last-child){margin-right:8px}.es-toolbar .es-toolbar-content .el-form-item.es-toolbar-item-checkbox+.el-form-item,.es-toolbar .es-toolbar-content .el-form-item.es-toolbar-item-radio+.el-form-item,.es-toolbar .es-toolbar-content .el-form-item.es-toolbar-item-switch+.el-form-item{margin-left:16px}.es-toolbar .es-toolbar-content .el-form-item .el-input__icon{line-height:32px;vertical-align:top}.es-toolbar .es-toolbar-content .es-form-search-small .el-input__inner{width:100%;max-width:156px}.es-toolbar .es-toolbar-content .es-form-search-small .el-input__inner.el-date-editor--daterange{max-width:300px}.es-toolbar .es-toolbar-content .es-form-search-small .el-input__inner.el-date-editor--daterange .el-input__icon,.es-toolbar .es-toolbar-content .es-form-search-small .el-input__inner.el-date-editor--daterange .el-range-separator{line-height:24px}.es-toolbar .es-advanced-filter{margin-top:20px;z-index:9}.es-toolbar .es-advanced-filter.es-absolute{position:absolute;left:0;top:45px;right:0;margin-top:0;-webkit-box-shadow:0 1px 10px rgba(0,0,0,.05),0 4px 5px rgba(0,0,0,.08),0 2px 4px -1px rgba(0,0,0,.12);box-shadow:0 1px 10px rgba(0,0,0,.05),0 4px 5px rgba(0,0,0,.08),0 2px 4px -1px rgba(0,0,0,.12);border-bottom-left-radius:6px;border-bottom-right-radius:6px}.es-toolbar .es-advanced-filter.es-absolute .es-form{background-color:#fff;border:1px solid #d9d9d9;border-bottom-left-radius:6px;border-bottom-right-radius:6px;border-top:0;padding:20px 20px 20px 10px}.es-toolbar .el-form-item__content{line-height:32px!important}.es-toolbar .el-form-item__label{line-height:32px!important;height:32px}.es-toolbar .el-button.es-upload{padding:0!important;border:0!important}
|
|
@@ -41,6 +41,14 @@ export default {
|
|
|
41
41
|
small: {
|
|
42
42
|
type: Boolean,
|
|
43
43
|
default: true
|
|
44
|
+
},
|
|
45
|
+
showLabel: {
|
|
46
|
+
type: Boolean,
|
|
47
|
+
default: false
|
|
48
|
+
},
|
|
49
|
+
labelWidth: {
|
|
50
|
+
type: String,
|
|
51
|
+
default: 'auto'
|
|
44
52
|
}
|
|
45
53
|
},
|
|
46
54
|
computed: {
|
|
@@ -226,6 +234,7 @@ export default {
|
|
|
226
234
|
)
|
|
227
235
|
]);
|
|
228
236
|
}
|
|
237
|
+
let { config, ...other } = items;
|
|
229
238
|
if (items.type === 'search') {
|
|
230
239
|
let itemClass = {
|
|
231
240
|
radio: 'es-toolbar-item-radio',
|
|
@@ -237,14 +246,12 @@ export default {
|
|
|
237
246
|
class: [
|
|
238
247
|
'es-form-search',
|
|
239
248
|
this.small ? 'es-form-search-small' : '',
|
|
240
|
-
this.
|
|
249
|
+
this.showLabel ? 'es-form-search-nobtn' : ''
|
|
241
250
|
],
|
|
242
251
|
props: {
|
|
243
|
-
showButton: items.showButton,
|
|
244
|
-
formatSubmit: items.formatSubmit,
|
|
245
|
-
...(items.config || {}),
|
|
246
252
|
size: 'medium',
|
|
247
|
-
showLabel:
|
|
253
|
+
showLabel: this.showLabel,
|
|
254
|
+
labelWidth: this.labelWidth,
|
|
248
255
|
closeDialog: false,
|
|
249
256
|
model: this.searchData,
|
|
250
257
|
contents: items.contents,
|
|
@@ -252,7 +259,9 @@ export default {
|
|
|
252
259
|
inline: true,
|
|
253
260
|
search: true,
|
|
254
261
|
isReset: items.reset,
|
|
255
|
-
showButton: this.showFormBtn
|
|
262
|
+
showButton: this.showFormBtn,
|
|
263
|
+
...other,
|
|
264
|
+
...(config || {})
|
|
256
265
|
},
|
|
257
266
|
on: {
|
|
258
267
|
submit: (data) => {
|
|
@@ -326,8 +335,8 @@ export default {
|
|
|
326
335
|
class: 'es-form-search',
|
|
327
336
|
ref: 'filter',
|
|
328
337
|
props: {
|
|
329
|
-
|
|
330
|
-
...(
|
|
338
|
+
...other,
|
|
339
|
+
...(config || {}),
|
|
331
340
|
size: 'medium',
|
|
332
341
|
closeDialog: false,
|
|
333
342
|
model: this.advancedData,
|
package/src/index.js
CHANGED
package/src/utils/util.js
CHANGED
|
@@ -7,12 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
/* eslint-disable indent */
|
|
9
9
|
const sm2 = require('sm-crypto').sm2;
|
|
10
|
-
import { authCenter
|
|
10
|
+
import { authCenter } from '../config/api';
|
|
11
11
|
import axios from 'axios';
|
|
12
12
|
import qs from 'qs';
|
|
13
13
|
import JSONbig from 'json-bigint';
|
|
14
|
-
import
|
|
15
|
-
import Stomp from 'stompjs';
|
|
14
|
+
import WebSocket from './webSocket';
|
|
16
15
|
|
|
17
16
|
const win = window.__WUJIE_RAW_WINDOW__ ? window.__WUJIE_RAW_WINDOW__ : window;
|
|
18
17
|
|
|
@@ -663,6 +662,7 @@ const delUrlParam = function ({ url, key }) {
|
|
|
663
662
|
key.forEach(item => {
|
|
664
663
|
if (param.hasOwnProperty(item)) {
|
|
665
664
|
let reg = `${item}=${param[item]}`;
|
|
665
|
+
console.log(reg);
|
|
666
666
|
if (src.indexOf(reg + '&') > -1) {
|
|
667
667
|
src = src.replace(reg + '&', '');
|
|
668
668
|
} else if (src.indexOf('&' + reg) > -1) {
|
|
@@ -1876,7 +1876,6 @@ const isLogined = function ({
|
|
|
1876
1876
|
from,
|
|
1877
1877
|
next,
|
|
1878
1878
|
exclude = [],
|
|
1879
|
-
open,
|
|
1880
1879
|
cookie,
|
|
1881
1880
|
loginPage,
|
|
1882
1881
|
redirect
|
|
@@ -1884,24 +1883,24 @@ const isLogined = function ({
|
|
|
1884
1883
|
if (cookie === undefined) {
|
|
1885
1884
|
cookie = getParams({ name: 'cookie' });
|
|
1886
1885
|
}
|
|
1886
|
+
let pathname = win.top.location.pathname;
|
|
1887
1887
|
if (loginPage) {
|
|
1888
1888
|
sessionStorage.setItem('loginPage', loginPage);
|
|
1889
1889
|
if (!startWith(loginPage, ['http', '/'], true)) {
|
|
1890
|
-
let pathname = win.top.location.pathname;
|
|
1891
1890
|
if (pathname !== '/') {
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
loginPage =
|
|
1891
|
+
let path = pathname.split('/');
|
|
1892
|
+
path.splice(pathname.length - 1);
|
|
1893
|
+
path = path.join('/');
|
|
1894
|
+
loginPage = path + '/' + loginPage.replace('./', '');
|
|
1896
1895
|
} else {
|
|
1897
1896
|
loginPage = pathname + loginPage.replace('./', '');
|
|
1898
1897
|
}
|
|
1899
1898
|
}
|
|
1900
1899
|
}
|
|
1901
1900
|
const token = getStorage('token') || getStorage('Authorization');
|
|
1902
|
-
const logined = getStorage('logined');
|
|
1901
|
+
// const logined = getStorage('logined');
|
|
1903
1902
|
// eslint-disable-next-line eqeqeq
|
|
1904
|
-
if (token ||
|
|
1903
|
+
if (token || cookie == true || cookie == 1) {
|
|
1905
1904
|
next && next();
|
|
1906
1905
|
} else {
|
|
1907
1906
|
if (
|
|
@@ -1927,40 +1926,25 @@ const isLogined = function ({
|
|
|
1927
1926
|
deviceUnique: results.deviceUnique
|
|
1928
1927
|
}
|
|
1929
1928
|
});
|
|
1930
|
-
|
|
1929
|
+
let url = delUrlParam({
|
|
1930
|
+
url: win.top.location.href,
|
|
1931
|
+
key: ['serverId', 'authType', 'code', 'sessionId']
|
|
1932
|
+
});
|
|
1933
|
+
win.top.location.href = url;
|
|
1934
|
+
setTimeout(() => {
|
|
1935
|
+
win.top.location.reload();
|
|
1936
|
+
}, 200);
|
|
1931
1937
|
break;
|
|
1932
1938
|
case 1:
|
|
1933
1939
|
break;
|
|
1934
1940
|
case 2:
|
|
1935
1941
|
break;
|
|
1936
1942
|
case 3:
|
|
1937
|
-
let url = win.top.location.href;
|
|
1938
1943
|
const href = results.authorizeUrl.replace(
|
|
1939
1944
|
'{redirectUri}',
|
|
1940
|
-
encodeURIComponent(
|
|
1945
|
+
encodeURIComponent(win.top.location.href)
|
|
1941
1946
|
);
|
|
1942
|
-
|
|
1943
|
-
switch (to.query.openType) {
|
|
1944
|
-
case 'self':
|
|
1945
|
-
win.location.href = href;
|
|
1946
|
-
break;
|
|
1947
|
-
case 'blank':
|
|
1948
|
-
win.open(href);
|
|
1949
|
-
break;
|
|
1950
|
-
case 'top':
|
|
1951
|
-
win.top.location.href = href;
|
|
1952
|
-
break;
|
|
1953
|
-
case 'parent':
|
|
1954
|
-
win.parent.location.href = href;
|
|
1955
|
-
break;
|
|
1956
|
-
}
|
|
1957
|
-
} else {
|
|
1958
|
-
if (open) {
|
|
1959
|
-
win.open(href);
|
|
1960
|
-
} else {
|
|
1961
|
-
win.top.location.href = href;
|
|
1962
|
-
}
|
|
1963
|
-
}
|
|
1947
|
+
win.top.location.href = href;
|
|
1964
1948
|
break;
|
|
1965
1949
|
case 4:
|
|
1966
1950
|
MessageBox.alert(
|
|
@@ -2010,30 +1994,31 @@ const isLogined = function ({
|
|
|
2010
1994
|
);
|
|
2011
1995
|
}
|
|
2012
1996
|
}).catch(e => { });
|
|
2013
|
-
} else
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
if (loginPage) {
|
|
2028
|
-
win.top.location.replace(loginPage);
|
|
2029
|
-
} else if (document.referrer) {
|
|
2030
|
-
win.top.location.replace(document.referrer);
|
|
2031
|
-
} else if (win.top.location.href.indexOf('main.html') > -1) {
|
|
2032
|
-
win.top.location.href = './login.html';
|
|
1997
|
+
} else
|
|
1998
|
+
if (
|
|
1999
|
+
token ||
|
|
2000
|
+
to.path === '/' ||
|
|
2001
|
+
to.path === '/404' ||
|
|
2002
|
+
exclude.indexOf(to.path) > -1 || exclude.indexOf(to.name) > -1 ||
|
|
2003
|
+
to.path === '/login' ||
|
|
2004
|
+
(token && to.path === '/main')
|
|
2005
|
+
) {
|
|
2006
|
+
if (redirect && (to.path === '/main' || to.path === '/login')) {
|
|
2007
|
+
window.location.replace(urlJoinParams({ url: `.${to.path}.html`, param: to.query }));
|
|
2008
|
+
} else {
|
|
2009
|
+
next();
|
|
2010
|
+
}
|
|
2033
2011
|
} else {
|
|
2034
|
-
|
|
2012
|
+
if (loginPage) {
|
|
2013
|
+
win.top.location.replace(loginPage);
|
|
2014
|
+
} else if (document.referrer) {
|
|
2015
|
+
win.top.location.replace(document.referrer);
|
|
2016
|
+
} else if (win.top.location.href.indexOf('main.html') > -1) {
|
|
2017
|
+
win.top.location.href = './login.html';
|
|
2018
|
+
} else {
|
|
2019
|
+
next('/login');
|
|
2020
|
+
}
|
|
2035
2021
|
}
|
|
2036
|
-
}
|
|
2037
2022
|
}
|
|
2038
2023
|
};
|
|
2039
2024
|
const isLogged = function (res) {
|
|
@@ -2486,67 +2471,25 @@ const setStorage = function ({ type, key, value }) {
|
|
|
2486
2471
|
* @author huangbo
|
|
2487
2472
|
* @date 2022年5月7日
|
|
2488
2473
|
* @param {String} [url] - 连接地址
|
|
2474
|
+
* @param {String} [send] - 是否发送消息
|
|
2489
2475
|
* @param {String} [take] - 订阅地址
|
|
2490
2476
|
* @param {String} [debug] - 调试
|
|
2491
2477
|
* @param {String} [interval] - 重连间隔时间
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
interval: 20
|
|
2503
|
-
};
|
|
2504
|
-
let websocket = win.websocket || {};
|
|
2505
|
-
if (options && isObject(options)) {
|
|
2506
|
-
option = { ...option, ...options };
|
|
2507
|
-
}
|
|
2508
|
-
let key = window.btoa(option.url);
|
|
2509
|
-
if (!websocket[key]) {
|
|
2510
|
-
websocket[key] = { socket: new SockJS(option.url) };
|
|
2511
|
-
win.websocket = websocket;
|
|
2512
|
-
}
|
|
2513
|
-
|
|
2514
|
-
let client = websocket[key] ? websocket[key].client : null;
|
|
2515
|
-
if (!client) {
|
|
2516
|
-
client = websocket[key].client = Stomp.over(websocket[key].socket);
|
|
2517
|
-
!option.debug && (client.debug = null);
|
|
2478
|
+
* @param {Function} [success] - 调试
|
|
2479
|
+
* @param {Function} [error] - 重连间隔时间
|
|
2480
|
+
**/
|
|
2481
|
+
function socket(option, vm) {
|
|
2482
|
+
let options = {};
|
|
2483
|
+
for (let i in option) {
|
|
2484
|
+
if (i === 'send') {
|
|
2485
|
+
options['isSend'] = option[i];
|
|
2486
|
+
} else {
|
|
2487
|
+
options[i] = option[i];
|
|
2518
2488
|
}
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
let res = JSON.parse(response.body);
|
|
2524
|
-
resolve(res, () => {
|
|
2525
|
-
client.disconnect();
|
|
2526
|
-
win.top.websocket && win.top.websocket[key] && delete win.top.websocket[key];
|
|
2527
|
-
}, client, websocket[key]);
|
|
2528
|
-
});
|
|
2529
|
-
},
|
|
2530
|
-
(error) => {
|
|
2531
|
-
let diffSecond = parseInt((new Date() - nextDate) / 1000, 10);
|
|
2532
|
-
if (connect > 5 && diffSecond < option.interval) {
|
|
2533
|
-
client.disconnect();
|
|
2534
|
-
if (win.top.websocket) {
|
|
2535
|
-
if (Object.keys(win.top.websocket).length > 1) {
|
|
2536
|
-
delete win.top.websocket[key];
|
|
2537
|
-
} else {
|
|
2538
|
-
delete win.top.websocket;
|
|
2539
|
-
}
|
|
2540
|
-
}
|
|
2541
|
-
} else {
|
|
2542
|
-
win.top.websocket && win.top.websocket[key] && setTimeout(() => {
|
|
2543
|
-
socket(options);
|
|
2544
|
-
}, 5000);
|
|
2545
|
-
}
|
|
2546
|
-
reject(error);
|
|
2547
|
-
}
|
|
2548
|
-
);
|
|
2549
|
-
});
|
|
2489
|
+
}
|
|
2490
|
+
const socket = new WebSocket();
|
|
2491
|
+
socket.init(options, vm);
|
|
2492
|
+
return socket;
|
|
2550
2493
|
}
|
|
2551
2494
|
/**
|
|
2552
2495
|
* sum
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import SockJS from 'sockjs-client';
|
|
2
|
+
import Stomp from 'stompjs';
|
|
3
|
+
class WebSocket {
|
|
4
|
+
// 构造函数
|
|
5
|
+
constructor() {
|
|
6
|
+
this.host = sessionStorage.getItem('wshost') || '';
|
|
7
|
+
this.tryTimes = 1; // 重连次数
|
|
8
|
+
this.callback = null; // 回调函数
|
|
9
|
+
this.client = null; // stomp对象
|
|
10
|
+
this.reconTimeout = null; // 重连延时器
|
|
11
|
+
this.debug = true; // 调试
|
|
12
|
+
this.interval = 20; // 重连间隔时间
|
|
13
|
+
this.vm = null;
|
|
14
|
+
this.nextDate = 0;
|
|
15
|
+
this.connects = 1;
|
|
16
|
+
this.recon = false;
|
|
17
|
+
this.sendTimeout = null;
|
|
18
|
+
this.isSend = false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** socket连接 */
|
|
22
|
+
connect() {
|
|
23
|
+
if (!this.client) {
|
|
24
|
+
// 连接SockJS
|
|
25
|
+
let socket = new SockJS(this.host + this.url);
|
|
26
|
+
// 获取STOMP子协议的客户端对象
|
|
27
|
+
this.client = Stomp.over(socket);
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 日志不打印
|
|
32
|
+
if (!this.debug) {
|
|
33
|
+
console.log(111);
|
|
34
|
+
this.client.debug = () => {};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 向服务器发起websocket连接
|
|
38
|
+
this.client.connect({}, () => {
|
|
39
|
+
this.recon = true;
|
|
40
|
+
// tryTimes定义重置
|
|
41
|
+
this.connects = 1;
|
|
42
|
+
// 订阅消息
|
|
43
|
+
// if (!this.isSend) {
|
|
44
|
+
this.subscribe();
|
|
45
|
+
// }
|
|
46
|
+
}, (error) => {
|
|
47
|
+
let diffSecond = parseInt((new Date() - this.nextDate) / 1000, 10);
|
|
48
|
+
if (this.connects > 5 && diffSecond < this.interval) {
|
|
49
|
+
this.client.disconnect();
|
|
50
|
+
this.error && this.error(error);
|
|
51
|
+
} else {
|
|
52
|
+
this.reconTimeout = setTimeout(() => {
|
|
53
|
+
this.connect();
|
|
54
|
+
this.connects++;
|
|
55
|
+
}, 5000);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/** 订阅服务端 */
|
|
60
|
+
subscribe() {
|
|
61
|
+
// 订阅服务端提供的某个topic
|
|
62
|
+
this.client.subscribe(this.take, (response) => {
|
|
63
|
+
if (response && (this.callback || this.success)) {
|
|
64
|
+
let callback = this.callback || this.success;
|
|
65
|
+
callback(JSON.parse(response.body));
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** 赋值、初始化socket */
|
|
71
|
+
init(option, vm) {
|
|
72
|
+
for (let i in option) {
|
|
73
|
+
this[i] = option[i];
|
|
74
|
+
}
|
|
75
|
+
this.vm = vm;
|
|
76
|
+
// 初始化连接
|
|
77
|
+
this.connect();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** 发送消息 */
|
|
81
|
+
send(data) {
|
|
82
|
+
if (this.recon) {
|
|
83
|
+
clearTimeout(this.sendTimeout);
|
|
84
|
+
this.client.send(this.take, {}, typeof data === 'string' ? data : JSON.stringify(data));
|
|
85
|
+
} else {
|
|
86
|
+
this.sendTimeout = setTimeout(() => {
|
|
87
|
+
this.send(data);
|
|
88
|
+
}, 1000);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** 销毁 */
|
|
93
|
+
destroy() {
|
|
94
|
+
// 断开连接,清除定时器
|
|
95
|
+
if (this.client) {
|
|
96
|
+
this.client.disconnect();
|
|
97
|
+
};
|
|
98
|
+
this.reconTimeout && clearTimeout(this.reconTimeout);
|
|
99
|
+
this.sendTimeout && clearTimeout(this.sendTimeout);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export default WebSocket;
|