Commit a4a765a9 authored by 崔佳豪's avatar 崔佳豪

fix: 登录获取网站配置同时获取mqtt配置

parent 0e5b9e51
Pipeline #47037 skipped with stages
...@@ -558,7 +558,6 @@ class Notifier { ...@@ -558,7 +558,6 @@ class Notifier {
mqtt_IsSSL: true mqtt_IsSSL: true
}; };
if (Array.isArray(res.getMe) && res.getMe.length > 0) { if (Array.isArray(res.getMe) && res.getMe.length > 0) {
debugger
if (res.getMe[0]) { if (res.getMe[0]) {
const data = res.getMe[0]; const data = res.getMe[0];
mqttConfig.mqtt_IsSSL = self._siteConfig.IsSSL = data.IsSSL ? data.IsSSL : false; mqttConfig.mqtt_IsSSL = self._siteConfig.IsSSL = data.IsSSL ? data.IsSSL : false;
...@@ -583,14 +582,14 @@ class Notifier { ...@@ -583,14 +582,14 @@ class Notifier {
mqttConfig.mqtt_iotIP = self._siteConfig.mqtt_iotIP = mqttConfig.mqtt_mess.TcpIP + ":" + mqttConfig.mqtt_mess.TcpPort; mqttConfig.mqtt_iotIP = self._siteConfig.mqtt_iotIP = mqttConfig.mqtt_mess.TcpIP + ":" + mqttConfig.mqtt_mess.TcpPort;
self.props.updateConfig && self.props.updateConfig(Object.assign({}, self.props.global, { // self.props.updateConfig && self.props.updateConfig(Object.assign({}, self.props.global, {
...mqttConfig // ...mqttConfig
})) // }))
// 应用共享状态只在initMicro中更新了一次,异步修改了的globalConfig,子应用读取到的是旧的,需要更新一下应用共享状态 // 应用共享状态只在initMicro中更新了一次,异步修改了的globalConfig,子应用读取到的是旧的,需要更新一下应用共享状态
setGlobalState({ // setGlobalState({
globalConfig: window.globalConfig // globalConfig: window.globalConfig
}); // });
} }
} else { } else {
Logger.info('获取mqtt服务器参数失败'); Logger.info('获取mqtt服务器参数失败');
......
...@@ -6,7 +6,7 @@ import Cookies from 'js-cookie'; ...@@ -6,7 +6,7 @@ import Cookies from 'js-cookie';
import sha1 from 'sha1'; import sha1 from 'sha1';
import { SlideVerify } from '@wisdom-utils/components'; import { SlideVerify } from '@wisdom-utils/components';
import { appService } from '@/api'; import { appService, noticeService } from '@/api';
import { getUserInfo, getWebSiteConfig } from '@/api/service/base'; import { getUserInfo, getWebSiteConfig } from '@/api/service/base';
import { import {
SERVICE_APP_LOGIN_MODE, SERVICE_APP_LOGIN_MODE,
...@@ -14,6 +14,7 @@ import { ...@@ -14,6 +14,7 @@ import {
WX_REDIRECT_URI, WX_REDIRECT_URI,
} from '@/constants'; } from '@/constants';
import store from '@/stores'; import store from '@/stores';
import { DEFAULT_MQTT_PATH, DEFAULT_TCP_IP, DEFAULT_TCP_PORT, DEFAULT_PARSE_LEVEL } from '@/components/Notifier/constants';
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
const Logger = logger('login'); const Logger = logger('login');
...@@ -23,7 +24,7 @@ class Login { ...@@ -23,7 +24,7 @@ class Login {
this.events = window.share.event; this.events = window.share.event;
this.globalConfig = props.global; this.globalConfig = props.global;
// this.updateConfig = props.updateConfig; // this.updateConfig = props.updateConfig;
this.updateConfig = (config) => { props.updateConfig(config); this.globalConfig = getGlobalConfig(); console.log('11') } this.updateConfig = (config) => { props.updateConfig(config); this.globalConfig = getGlobalConfig(); }
this.createContext = props.createContext; this.createContext = props.createContext;
this.history = props.history; this.history = props.history;
this.callback = callback; this.callback = callback;
...@@ -210,13 +211,55 @@ class Login { ...@@ -210,13 +211,55 @@ class Login {
const self = this; const self = this;
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
getWebSiteConfig({ // 获取网站配置的同时,预先获取到mqtt配置,注册进子应用
client: self.globalConfig.client, Promise.all([
token, noticeService.getMqttSiteCode({ 'request.preventCache': Date.now() }),
'request.preventCache': Date.now(), getWebSiteConfig({
}) client: self.globalConfig.client,
.then(response => { token,
debugger 'request.preventCache': Date.now(),
})
]).then(results => {
const res = results[0] ?? {};
if (res && res.say.statusCode === '0000') {
let mqttConfig = {
mqtt_mess: {},
mqtt_path: DEFAULT_MQTT_PATH,
nginxStart: false,
mqtt_IsSSL: true
};
if (Array.isArray(res.getMe) && res.getMe.length > 0) {
if (res.getMe[0]) {
const data = res.getMe[0];
mqttConfig.mqtt_IsSSL = data.IsSSL ? data.IsSSL : false;
mqttConfig.mqtt_mess.site_code = data.SiteCode || self.globalConfig.userInfo.site;
mqttConfig.mqtt_mess.TcpIP = data.TcpIP;
mqttConfig.mqtt_mess.TcpPort = data.TcpPort ? parseInt(data.TcpPort) : 8083;
mqttConfig.mqtt_mess.MessageLevel = data.MessageLevel ? data.MessageLevel : DEFAULT_PARSE_LEVEL;
if (data.NginxStart) {
mqttConfig.NginxStart = data.NginxStart;
mqttConfig.mqtt_mess.TcpIP = window.location.hostname;
mqttConfig.mqtt_mess.TcpPort = parseInt(window.location.port);
mqttConfig.mqtt_path = '/ws/';
} else {
mqttConfig.nginxStart = data.NginxStart
}
}else {
mqttConfig.mqtt_mess.TcpIP = DEFAULT_TCP_IP;
mqttConfig.mqtt_mess.TcpPort = DEFAULT_TCP_PORT;
mqttConfig.mqtt_IsSSL = mqttConfig.mqtt_mess.TcpIP + ":" + mqttConfig.mqtt_mess.TcpPort;
}
mqttConfig.mqtt_iotIP = mqttConfig.mqtt_mess.TcpIP + ":" + mqttConfig.mqtt_mess.TcpPort;
self.globalConfig = Object.assign(self.globalConfig, { ...mqttConfig });
}
} else {
Logger.info('获取mqtt服务器参数失败');
}
return results;
}).then(results => {
const response = results[1] ?? {};
const result = const result =
response && response.code === SERVICE_INTERFACE_SUCCESS_CODE response && response.code === SERVICE_INTERFACE_SUCCESS_CODE
? Array.isArray(response.data) ? Array.isArray(response.data)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment