Commit 948fdad3 authored by 陈冲's avatar 陈冲

commit

parent 285e540b
......@@ -2,6 +2,8 @@
declare module 'crypto-js';
declare const __APP_DOMAIN__: string;
interface ImportMetaEnv {
readonly VITE_ASSET_BASE_URL?: string;
readonly VITE_ASSET_DEV_LOCAL?: string;
......
......@@ -4,4 +4,6 @@ import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
localStorage.setItem('domain', __APP_DOMAIN__)
createApp(App).use(router).mount('#app')
......@@ -40,7 +40,7 @@ const loginHandler = async () => {
telephone: '13111223344',
avatar: '13111223344',
});
await router.replace('/h5/game1')
await router.replace('/game1')
}
</script>
......
......@@ -12,15 +12,15 @@ const router = createRouter({
routes: [
{
path: '/',
redirect: () => (getWechatId() ? '/h5/game1' : '/h5/login'),
redirect: () => (getWechatId() ? '/game1' : '/login'),
},
{
path: '/h5/login',
path: '/login',
name: 'Login',
component: Login,
},
{
path: '/h5/game1',
path: '/game1',
name: 'Game1',
component: Game1,
meta: {
......@@ -38,7 +38,7 @@ router.beforeEach((to) => {
const wechatId = getWechatId()
if (to.meta.requiresAuth && !wechatId) {
return '/h5/login'
return '/login'
}
return true
......
......@@ -6,6 +6,8 @@ import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
const buildDomain = 'https://hddpserver.guocai365.org.cn'
function copyImageAssets() {
return {
name: 'copy-image-assets',
......@@ -25,6 +27,9 @@ function copyImageAssets() {
export default defineConfig(({ command }) => ({
base: command === 'build' ? '/cc/h5/' : '/',
define: {
__APP_DOMAIN__: JSON.stringify(command === 'build' ? buildDomain : ''),
},
plugins: [
vue(),
vueDevTools(),
......
......@@ -2,6 +2,8 @@
declare module 'crypto-js';
declare const __APP_DOMAIN__: string;
interface ImportMetaEnv {
readonly VITE_ASSET_BASE_URL?: string;
readonly VITE_ASSET_DEV_LOCAL?: string;
......
......@@ -6,7 +6,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>小游戏-大屏</title>
<style>body{background: #FA6047;}</style>
<script>localStorage.setItem('domain', '');</script>
</head>
<body>
<div id="app"></div>
......
......@@ -74,8 +74,9 @@ export function $read_socket_storge(): any {
let token = $read('token', '');
const socket_path = $read('socket_path', '');
const client_ns = $read('client_ns', '')
const domain = localStorage.getItem('domain') || ''
return {
passphrase, token, socket_path, client_ns
passphrase, token, socket_path, client_ns, domain
}
}
......@@ -91,4 +92,4 @@ export function $is_run_local(): boolean {
return true;
}
return false;
}
\ No newline at end of file
}
......@@ -34,8 +34,12 @@ export function initSocket(args: SocketInitArgs): Socket | null {
if (socket) {
if (socket.connected) {
args.onConnect?.(socket);
return socket;
}
return socket;
socket.removeAllListeners();
socket.disconnect();
socket = null;
}
socket = io(args.client_ns, {
......
......@@ -58,7 +58,7 @@ export function useAdminGameSocket(options: AdminGameSocketOptions) {
offSocketMessage = onSocketMessage(async (evt, payload: SocketPayload) => {
const { msg, state, data } = payload
if ($goto_login(evt, router, options.loginRedirectPath ?? '/pc/game1')) {
if ($goto_login(evt, router, options.loginRedirectPath ?? '/game1')) {
return
}
......
......@@ -4,4 +4,6 @@ import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
localStorage.setItem('domain', __APP_DOMAIN__)
createApp(App).use(router).mount('#app')
<script setup lang="ts">
import CryptoJS from 'crypto-js';
import { $save } from '@/commons/utils.ts';
import { ref, onUnmounted } from 'vue'
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import DesignStage from '@/components/DesignStage.vue'
import { initSocket, onSocketMessage, sendSocketMessage } from '@/commons/ws.ts';
let offSocketMessage: (() => void) | undefined;
const router = useRouter()
const username = ref('')
const password = ref('')
......@@ -40,38 +36,8 @@ const loginHandler = async () => {
for (let i in data) {
$save(i, data[i]);
}
let domain = localStorage.getItem('domain') || '';
initSocket({
socket_path: `${domain}${data.socket_path}`,
client_ns: data.client_ns,
auth: {
userid: data.token,
validuser: CryptoJS.AES.encrypt(data.token, data.passphrase).toString(),
},
onConnect: async () => {
setTimeout(() => {
sendSocketMessage('room_create', 1);
}, 200);
},
onDisconnect: (reason: string) => { },
onError: (error: any) => { },
});
await router.replace('/game1')
}
offSocketMessage = onSocketMessage(async (evt, { msg, state, data }) => {
if (state == 0) {
alert(msg);
return;
}
switch (evt) {
case 'room_create_result': {
await router.replace('/pc/game1')
break;
}
}
});
onUnmounted(() => {
offSocketMessage?.();
});
</script>
<template>
......
......@@ -97,7 +97,7 @@ function handleRoomState(data: any) {
const { startGame, createRoom, requestRoomState } = useAdminGameSocket({
gameId: 'game1',
loginRedirectPath: '/pc/game1',
// loginRedirectPath: '/game1',
onGameStartRejected: gotoLoading,
onRoomState: handleRoomState,
onRoomJoin: (data) => {
......
......@@ -8,15 +8,15 @@ const router = createRouter({
routes: [
{
path: '/',
redirect: () => ($read('token', '') ? '/pc/game1' : '/pc/login'),
redirect: () => ($read('token', '') ? '/game1' : '/login'),
},
{
path: '/pc/login',
path: '/login',
name: 'Login',
component: Login,
},
{
path: '/pc/game1',
path: '/game1',
name: 'Game1',
component: Game1,
meta: {
......@@ -34,7 +34,7 @@ router.beforeEach((to) => {
const token = $read('token', '')
if (to.meta.requiresAuth && !token) {
return '/pc/login'
return '/login'
}
return true
......
......@@ -6,7 +6,7 @@ import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
const buildBase = '/cc/pc/'
const buildDomain = 'https://hddpserver.guocai365.org.cn'
function copyImageAssets() {
return {
......@@ -25,11 +25,10 @@ function copyImageAssets() {
}
}
// https://vite.dev/config/
export default defineConfig(({ command }) => ({
base: command === 'build' ? buildBase : '/',
build: {
emptyOutDir: false,
base: command === 'build' ? '/cc/pc/' : '/',
define: {
__APP_DOMAIN__: JSON.stringify(command === 'build' ? buildDomain : ''),
},
plugins: [
vue(),
......@@ -51,7 +50,7 @@ export default defineConfig(({ command }) => ({
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
}))
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