This commit is contained in:
PQZ 2025-07-04 15:38:41 +08:00
parent b4a3aa567e
commit 3d3564850c
7 changed files with 143 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

@ -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', "ws://localhost:8099/ws/asset/"+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
@ -48,6 +49,7 @@ Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.selectDictLabels = selectDictLabels
Vue.prototype.download = download
Vue.prototype.handleTree = handleTree
Vue.prototype.$websocket=websocket;
// 全局组件挂载
Vue.component('DictTag', DictTag)

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', "ws://localhost:8099/ws/asset/"+this.loginForm.username)
listAllSite().then(response => {
if (response.data && response.data.length > 0) {
response.data.map((item) => {