mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-07-01 12:11:13 +00:00
feat: Completed early communication testing.
data-table has serious performance problem.
This commit is contained in:
parent
6554be6b6d
commit
a11ef70021
@ -16,7 +16,12 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Lyrics\Providers\Kugeci" />
|
||||
<Folder Include="Lyrics\Providers\KuWo" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Lyrics\Providers\Kugeci\KugeciDownloader.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -30,7 +30,7 @@ WebApplication? RegisterAndConfigureServices()
|
||||
|
||||
insideApp.UseAuthorization();
|
||||
insideApp.MapControllers();
|
||||
insideApp.Lifetime.ApplicationStarted.Register(OpenBrowser);
|
||||
// insideApp.Lifetime.ApplicationStarted.Register(OpenBrowser);
|
||||
|
||||
return insideApp;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using SuperSocket.WebSocket.Server;
|
||||
using Newtonsoft.Json;
|
||||
using SuperSocket.WebSocket.Server;
|
||||
|
||||
namespace ZonyLrcTools.LocalServer;
|
||||
|
||||
@ -7,9 +8,65 @@ public class SuperSocketListener
|
||||
public async Task ListenAsync()
|
||||
{
|
||||
var host = WebSocketHostBuilder.Create()
|
||||
.UseWebSocketMessageHandler(async (session, message) => { await session.SendAsync(message.Message); })
|
||||
.UseWebSocketMessageHandler(async (session, message) =>
|
||||
{
|
||||
await session.SendAsync(JsonConvert.SerializeObject(new CommunicateEvent<OutputEvent>
|
||||
{
|
||||
Action = "output",
|
||||
Type = ActionType.ResponseAction,
|
||||
Data = new OutputEvent()
|
||||
}));
|
||||
|
||||
for (int index = 0; index < 50; index++)
|
||||
{
|
||||
var data = new List<GetFileInfoEvent>();
|
||||
for (int j = 0; j < 500; j++)
|
||||
{
|
||||
data.Add(new GetFileInfoEvent
|
||||
{
|
||||
Name = j.ToString(),
|
||||
Size = j.ToString()
|
||||
});
|
||||
}
|
||||
|
||||
await session.SendAsync(JsonConvert.SerializeObject(new CommunicateEvent<List<GetFileInfoEvent>>
|
||||
{
|
||||
Action = "getFileInfo",
|
||||
Type = ActionType.ResponseAction,
|
||||
Data = data
|
||||
}));
|
||||
}
|
||||
|
||||
await Task.Delay(100);
|
||||
})
|
||||
.Build();
|
||||
|
||||
await host.StartAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public class CommunicateEvent<T> where T : class
|
||||
{
|
||||
[JsonProperty("action")] public string? Action { get; set; }
|
||||
|
||||
[JsonProperty("type")] public ActionType Type { get; set; }
|
||||
|
||||
[JsonProperty("data")] public T? Data { get; set; }
|
||||
}
|
||||
|
||||
public class OutputEvent
|
||||
{
|
||||
[JsonProperty("text")] public string Text => DateTime.Now.ToString("HH:mm:ss");
|
||||
}
|
||||
|
||||
public class GetFileInfoEvent
|
||||
{
|
||||
[JsonProperty("name")] public string Name { get; set; }
|
||||
[JsonProperty("size")] public string Size { get; set; }
|
||||
}
|
||||
|
||||
public enum ActionType
|
||||
{
|
||||
RequestAction,
|
||||
ResponseAction
|
||||
}
|
@ -25,6 +25,10 @@
|
||||
<EmbeddedResource Include="UiStaticResources\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ZonyLrcTools.Common\ZonyLrcTools.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- <ItemGroup>-->
|
||||
<!-- <ProjectReference Include="..\ZonyLrcTools.Cli\ZonyLrcTools.Cli.csproj" />-->
|
||||
<!-- </ItemGroup>-->
|
||||
|
5
src/ui/src/communication/eventbus.js
Normal file
5
src/ui/src/communication/eventbus.js
Normal file
@ -0,0 +1,5 @@
|
||||
import Vue from "vue";
|
||||
|
||||
const eventBus = new Vue();
|
||||
|
||||
export default eventBus;
|
@ -1,4 +1,5 @@
|
||||
import Vue from 'vue'
|
||||
import eventBus from "@/communication/eventbus";
|
||||
|
||||
// const wsUrl = process.env.VUE_APP_WS_URL;
|
||||
const wsUrl = "ws://127.0.0.1:50001"
|
||||
@ -13,10 +14,11 @@ const emitter = new Vue({
|
||||
}, connect() {
|
||||
socket = new WebSocket(wsUrl);
|
||||
socket.onmessage = (msg) => {
|
||||
this.$emit('message', msg.data);
|
||||
let event = JSON.parse(msg.data);
|
||||
eventBus.$emit(event.action, event);
|
||||
};
|
||||
socket.onerror = (err) => {
|
||||
this.$emit('error', err);
|
||||
eventBus.$emit('error', err);
|
||||
};
|
||||
socket.onclose = () => {
|
||||
emitter.connect()
|
||||
|
@ -1,6 +1,5 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import ws from './ws'
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
@ -9,5 +8,5 @@ export default new Vuex.Store({
|
||||
getters: {},
|
||||
mutations: {},
|
||||
actions: {},
|
||||
modules: {ws}
|
||||
modules: {}
|
||||
})
|
||||
|
@ -1,21 +0,0 @@
|
||||
export const state = {
|
||||
wsRes: {}
|
||||
};
|
||||
|
||||
export const actions = {};
|
||||
|
||||
export const mutations = {
|
||||
setWsRes(newState, payload) {
|
||||
state.wsRes = payload;
|
||||
}
|
||||
};
|
||||
|
||||
export const getters = {};
|
||||
|
||||
export default {
|
||||
state,
|
||||
actions,
|
||||
mutations,
|
||||
getters,
|
||||
namespaced: true
|
||||
}
|
@ -21,15 +21,15 @@
|
||||
</template>
|
||||
</v-data-table>
|
||||
<div class="output mt-8">
|
||||
<v-textarea disabled outlined label="日志信息" value="输出"/>
|
||||
<v-textarea disabled outlined label="日志信息" :value='outputText'/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {mapState} from 'vuex'
|
||||
import Socket from '@/communication/socket'
|
||||
import eventBus from "@/communication/eventbus";
|
||||
|
||||
export default {
|
||||
name: 'Home',
|
||||
@ -52,14 +52,9 @@ export default {
|
||||
size: 159,
|
||||
status: 'success',
|
||||
action: 4.0,
|
||||
},
|
||||
{
|
||||
name: 'Ice cream sandwich',
|
||||
size: 237,
|
||||
status: 'error',
|
||||
action: 4.3,
|
||||
},
|
||||
}
|
||||
],
|
||||
outputText: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@ -70,15 +65,25 @@ export default {
|
||||
})
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapState({
|
||||
wsRes: state => state.ws.wsRes
|
||||
})
|
||||
},
|
||||
watch: {
|
||||
wsRes(val) {
|
||||
console.log('echo from server: ', val)
|
||||
}
|
||||
computed: {},
|
||||
mounted() {
|
||||
// eventBus.$on('getFile', (msgData) => {
|
||||
// console.log(msgData);
|
||||
// });
|
||||
eventBus.$on('getFileInfo', (msgData) => {
|
||||
this.items = [...this.items, ...msgData.data.map(item => {
|
||||
return {
|
||||
name: item.name,
|
||||
size: item.size,
|
||||
status: 'success',
|
||||
action: 4.0,
|
||||
}
|
||||
})]
|
||||
});
|
||||
|
||||
eventBus.$on('output', (msgData) => {
|
||||
this.outputText = this.outputText.concat(msgData.data.text).concat('\n');
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user