This commit is contained in:
Vinjor 2025-07-04 17:30:07 +08:00
commit 1b42cf8172
10 changed files with 151 additions and 1 deletions

View File

@ -111,7 +111,7 @@ public class SecurityConfig
.authorizeHttpRequests((requests) -> {
permitAllUrl.getUrls().forEach(url -> requests.antMatchers(url).permitAll());
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
requests.antMatchers("/login","/wxLogin", "/register", "/captchaImage","/sys/ueditor/exec").permitAll()
requests.antMatchers("/login","/wxLogin", "/register", "/captchaImage","/sys/ueditor/exec","/ws/asset/**").permitAll()
//相关配置参数可匿名访问
.antMatchers("/base/config/getConfigByCode").permitAll()
.antMatchers("/base/category/getByCodeInfo").permitAll()

View File

@ -9,3 +9,6 @@ VUE_APP_BASE_API = '/dev-api'
# 路由懒加载
VUE_CLI_BABEL_TRANSPILE_MODULES = true
# websocket
VUE_APP_WEBSOCKET = 'ws://localhost:8099/ws/asset/'

View File

@ -6,3 +6,6 @@ ENV = 'production'
# 通告快接管理后台/生产环境
VUE_APP_BASE_API = 'https://www.ddtg.site/noticeApi'
# websocket
VUE_APP_WEBSOCKET = 'ws://localhost:8099/ws/asset/'

View File

@ -10,3 +10,6 @@ ENV = 'staging'
# 成事达管理平台/测试环境
VUE_APP_BASE_API = '/stage-api'
# websocket
VUE_APP_WEBSOCKET = 'ws://localhost:8099/ws/asset/'

View File

@ -7,10 +7,23 @@
<script>
import ThemePicker from "@/components/ThemePicker";
import Cookies from "js-cookie";
export default {
name: "App",
components: { ThemePicker },
data(){
return{
b:false,
}
},
destroyed: function () { //
this.$websocket.dispatch('websocket_close');
},
created () {
const username = Cookies.get('username')
this.$store.dispatch('websocket_init', process.env.VUE_APP_WEBSOCKET+username)
},
metaInfo() {
return {
title: this.$store.state.settings.dynamicTitle && this.$store.state.settings.title,

View File

@ -37,6 +37,7 @@ import DictTag from '@/components/DictTag'
import VueMeta from 'vue-meta'
// 字典数据组件
import DictData from '@/components/DictData'
import websocket from "./store/websocket";
// 全局方法挂载
Vue.prototype.getDicts = getDicts

View File

@ -3,6 +3,7 @@ import Vuex from 'vuex'
import app from './modules/app'
import dict from './modules/dict'
import user from './modules/user'
import websocket from './modules/websocket'
import tagsView from './modules/tagsView'
import permission from './modules/permission'
import settings from './modules/settings'
@ -15,6 +16,7 @@ const store = new Vuex.Store({
app,
dict,
user,
websocket,
tagsView,
permission,
settings

View File

@ -0,0 +1,60 @@
const websocket = {
state: {
websock:null,
message:[],
count:"0",
notice:[]
},
mutations: {
WEBSOCKET_INIT(state,url){
console.log(url);
state.websock = new WebSocket(url);
state.websock.onopen=function () {
console.log("WebSocket连接成功");
};
state.websock.onmessage = function (e) {
if (e.data.startsWith("C")) {
state.count = e.data;
}
else if (e.data.startsWith("系统通知")){
state.notice.push(e.data);
console.log(state.notice);
}
else {
state.message.push(JSON.parse(e.data));
// console.log(state.message);
}
};
state.websock.onerror= function () {
console.log("WebSocket连接发生错误");
};
state.websock.onclose = function (e) {
console.log("connection closed (" + e.code + ")");
};
},
WEBSOCKET_SEND(state,msg){
state.websock.send(msg);
},
WEBSOCKET_CLOSE(state){
state.websock.close();
}
},
actions: {
websocket_init({commit}, url) {
commit('WEBSOCKET_INIT', url)
},
websocket_send({commit}, msg) {
commit('WEBSOCKET_SEND', msg)
},
websocket_close({commit}){
commit('WEBSOCKET_CLOSE')
}
}
}
export default websocket

View File

@ -0,0 +1,64 @@
// import Vue from 'vue'
// import Vuex from 'vuex'
//
// Vue.use(Vuex)
//
// export default new Vuex.Store({
// //定义全局变量
// state: {
// websock:null,
// message:[],
// count:"0",
// notice:[]
// },
// //改变state的值必须经过
// mutations: {
// WEBSOCKET_INIT(state,url){
// console.log(url);
// state.websock = new WebSocket(url);
// state.websock.onopen=function () {
// console.log("WebSocket连接成功");
// };
// state.websock.onmessage = function (e) {
// if (e.data.startsWith("C")) {
// state.count = e.data;
//
// }
// else if (e.data.startsWith("系统通知")){
// state.notice.push(e.data);
// console.log(state.notice);
// }
// else {
// state.message.push(JSON.parse(e.data));
// // console.log(state.message);
// }
//
// };
// state.websock.onerror= function () {
// console.log("WebSocket连接发生错误");
// };
// state.websock.onclose = function (e) {
// console.log("connection closed (" + e.code + ")");
// };
// },
// WEBSOCKET_SEND(state,msg){
// state.websock.send(msg);
// },
// WEBSOCKET_CLOSE(state){
// state.websock.close();
// }
// },
// actions: {
// websocket_init({commit}, url) {
// commit('WEBSOCKET_INIT', url)
// },
// websocket_send({commit}, msg) {
// commit('WEBSOCKET_SEND', msg)
// },
// websocket_close({commit}){
// commit('WEBSOCKET_CLOSE')
// }
// },
// modules: {
// }
// })

View File

@ -189,6 +189,7 @@ export default {
Cookies.remove('rememberMe')
}
this.$store.dispatch('Login', this.loginForm).then(() => {
this.$store.dispatch('websocket_init', process.env.VUE_APP_WEBSOCKET+this.loginForm.username)
listAllSite().then(response => {
if (response.data && response.data.length > 0) {
response.data.map((item) => {