From 5d20a7def3bc519cf6756b01fb4ef8d04000f357 Mon Sep 17 00:00:00 2001 From: kubbo Date: Tue, 30 Sep 2025 18:39:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(web):=E9=87=8D=E6=9E=84=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=92=8C=E9=85=8D=E7=BD=AE=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除旧版全局变量定义,采用Vue Router管理页面跳转 - 新增配置文件统一管理游戏名称和注册码设置 -优化加载条逻辑,使用onMounted确保DOM元素正确获取 - 添加服务端配置接口,动态加载游戏配置信息 - 升级依赖包,引入vue-router支持单页应用 - 调整项目结构,分离服务器端代码至独立目录 - 配置Vite代理转发API请求到本地开发服务器 - 更新package.json脚本命令,支持前后端联合调试 - 引入pnpm workspace管理模式,提升多包协作效率 --- package.json | 10 ++- pnpm-workspace.yaml | 2 + public/config.json | 4 ++ public/js/index.js | 49 ++++++--------- server/config/index.js | 0 server/index.js | 27 ++++++++ server/package.json | 15 +++++ src/App.vue | 136 +++++++++++++++++++++-------------------- src/config.js | 5 ++ src/main.js | 9 ++- src/router/index.js | 22 +++++++ src/views/index.vue | 10 +++ src/views/login.vue | 49 +++++++++++++++ vite.config.js | 11 +++- 14 files changed, 249 insertions(+), 100 deletions(-) create mode 100644 pnpm-workspace.yaml create mode 100644 public/config.json create mode 100644 server/config/index.js create mode 100644 server/index.js create mode 100644 server/package.json create mode 100644 src/config.js create mode 100644 src/router/index.js create mode 100644 src/views/index.vue create mode 100644 src/views/login.vue diff --git a/package.json b/package.json index 1b370be..1e5f0e5 100644 --- a/package.json +++ b/package.json @@ -5,14 +5,22 @@ "type": "module", "scripts": { "dev": "vite", + "dev:server": "pnpm --filter chuanqi-server dev", + "start:server": "pnpm --filter chuanqi-server start", "build": "vite build", "preview": "vite preview" }, "dependencies": { - "vue": "^3.5.21" + "vue": "^3.5.21", + "vue-router": "^4.5.1" }, "devDependencies": { "@vitejs/plugin-vue": "^6.0.1", "vite": "^7.1.7" + }, + "pnpm": { + "workspace": [ + "server" + ] } } diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 0000000..3d17f04 --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +packages: + - server \ No newline at end of file diff --git a/public/config.json b/public/config.json new file mode 100644 index 0000000..f3e1a34 --- /dev/null +++ b/public/config.json @@ -0,0 +1,4 @@ +{ + "reg_code_open": true, + "code_type": "" +} \ No newline at end of file diff --git a/public/js/index.js b/public/js/index.js index b823e80..da36def 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1,17 +1,7 @@ -/** - * 冰雪传奇H5 - * 2022 XX信息科技有限公司 - * - * @author 123456 - * @wx 123456 - * @qq 123456 - */ - let host = window.location.hostname || '100.88.157.105'; let port = 80; -const webUrl = getHttp() + host + (port && 80 != port ? ':' + port : ''), - account = getQueryString('account'), +const account = getQueryString('account'), token = getQueryString('token'), noLogin = !account || !token; @@ -20,7 +10,7 @@ if (noLogin) { loadBarClear(); loadBarFull(); setTimeout(function () { - window.location.href = webUrl + '/login'; + window.location.href = '/login'; }, randomRange(250, 500)); }, 1e3); } @@ -79,19 +69,18 @@ window['loginView'] = 'app.MainLoginView'; // 相关URL window['webHost'] = host; -window['webUrl'] = webUrl; -window['serviceListdUrl'] = webUrl + '/server'; -window['setServiceListdUrl'] = webUrl + '/server'; -window['payUrl'] = webUrl + '/pay'; -window['apiUrl'] = webUrl + '/api'; -window['orderUrl'] = webUrl + '/api?act=order'; -window['reportUrl'] = webUrl + '/api?act=report'; // 上报接口 -window['errorReportUrl'] = webUrl + '/api?act=report&do=error';// 错误上报接口 -window['checkUrl'] = webUrl + '/api?act=check'; // 验证URL -window['versionUrl'] = webUrl + '/api?act=version'; // 请求客户端版本 -window['getActorInfoUrl'] = webUrl + '/api?act=actor'; -window['roleInfoUrl'] = webUrl + '/api?act=role'; -window['gongGaoUrl'] = webUrl + '/notice.txt'; +window['serviceListdUrl'] = '/server'; +window['setServiceListdUrl'] = '/server'; +window['payUrl'] = '/pay'; +window['apiUrl'] = '/api'; +window['orderUrl'] = '/api?act=order'; +window['reportUrl'] = '/api?act=report'; // 上报接口 +window['errorReportUrl'] = '/api?act=report&do=error';// 错误上报接口 +window['checkUrl'] = '/api?act=check'; // 验证URL +window['versionUrl'] = '/api?act=version'; // 请求客户端版本 +window['getActorInfoUrl'] = '/api?act=actor'; +window['roleInfoUrl'] = '/api?act=role'; +window['gongGaoUrl'] = '/notice.txt'; // 客服信息 window['kfQQ'] = '123456'; @@ -341,7 +330,7 @@ function feedbackFunction(info) { param += key + '=' + msgInfo[key] + '&' } param = param.substring(0, param.length - 1) - let srcStr = webUrl + '/api?' + param; + let srcStr = '/api?' + param; const div = document.createElement('div'); div.id = 'iframDiv'; div.innerHTML = ''; @@ -369,7 +358,7 @@ function feedbackFunction(info) { // 防沉迷 function IdCardFunction() { - window.open(webUrl); + window.open(); } function addQQGrp() { @@ -378,17 +367,17 @@ function addQQGrp() { //下载YY游戏大厅 function downYYGameHallFun() { - window.open(webUrl); + window.open(); } //开通会员 function openYYVip() { - window.open(webUrl); + window.open(); } //开超玩会员 function openChaoWanVip() { - window.open(webUrl); + window.open(); } function removeIfram() { diff --git a/server/config/index.js b/server/config/index.js new file mode 100644 index 0000000..e69de29 diff --git a/server/index.js b/server/index.js new file mode 100644 index 0000000..27d17c4 --- /dev/null +++ b/server/index.js @@ -0,0 +1,27 @@ +import Koa from 'koa'; +import Router from 'koa-router'; +import config from "./config/index.js" + +const app = new Koa(); +const router = new Router(); + +// 简单的路由示例 +router.get('/', (ctx) => { + ctx.body = {message: 'Hello from Koa server!'}; +}); + +router.get('/api/test', (ctx) => { + ctx.body = {message: 'This is a test API endpoint'}; +}); + +router.get('/api/config', (ctx) => { + ctx.body = {data: config} +}) +app.use(router.routes()); +app.use(router.allowedMethods()); + +const PORT = process.env.PORT || 3001; + +app.listen(PORT, () => { + console.log(`Koa server is running on port ${PORT}`); +}); \ No newline at end of file diff --git a/server/package.json b/server/package.json new file mode 100644 index 0000000..8dd043c --- /dev/null +++ b/server/package.json @@ -0,0 +1,15 @@ +{ + "name": "chuanqi-server", + "version": "1.0.0", + "description": "A simple Koa server for chuanqi web", + "main": "index.js", + "type": "module", + "scripts": { + "start": "node index.js", + "dev": "node index.js" + }, + "dependencies": { + "koa": "^2.15.0", + "koa-router": "^12.0.0" + } +} \ No newline at end of file diff --git a/src/App.vue b/src/App.vue index 29a975f..2c658f2 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,6 +1,7 @@ @@ -103,4 +105,4 @@ if (isMobile()) { justify-content: center; } } - + \ No newline at end of file diff --git a/src/config.js b/src/config.js new file mode 100644 index 0000000..6664f04 --- /dev/null +++ b/src/config.js @@ -0,0 +1,5 @@ +export default { + gameName: "神临苍月", + reg_code_open: true, + code_type: "email", +} \ No newline at end of file diff --git a/src/main.js b/src/main.js index 8aa1dda..3fa5d22 100644 --- a/src/main.js +++ b/src/main.js @@ -1,6 +1,7 @@ import {createApp} from 'vue' import './style.css' import App from './App.vue' +import router from './router' // window.external?.OpenGameWindowNew(window.location.href, '', '', '', false); document.onkeydown = document.onkeyup = document.onkeypress = function (e) { @@ -9,4 +10,10 @@ document.onkeydown = document.onkeyup = document.onkeypress = function (e) { return false; } } -createApp(App).mount('#app') +const app = createApp(App) + +fetch("/api/config", {method: "GET"}).then(res => res.json()).then(res => { + app.config.globalProperties.$gameName = res.data.gameName || "神临苍月"; + app.config.globalProperties.$_CONFIG = res.data; + app.use(router).mount('#app') +}) diff --git a/src/router/index.js b/src/router/index.js new file mode 100644 index 0000000..f430f77 --- /dev/null +++ b/src/router/index.js @@ -0,0 +1,22 @@ +import {createRouter, createWebHistory} from 'vue-router' +import Index from "../views/index.vue"; + +// 示例路由配置 +const routes = [ + { + path: '/', + name: 'Home', + component: Index + }, + { + path: '/login', name: 'Login', + component: () => import('../views/login.vue') + } +] + +const router = createRouter({ + history: createWebHistory(), + routes +}) + +export default router \ No newline at end of file diff --git a/src/views/index.vue b/src/views/index.vue new file mode 100644 index 0000000..efc275b --- /dev/null +++ b/src/views/index.vue @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/src/views/login.vue b/src/views/login.vue new file mode 100644 index 0000000..6108236 --- /dev/null +++ b/src/views/login.vue @@ -0,0 +1,49 @@ + + + + + \ No newline at end of file diff --git a/vite.config.js b/vite.config.js index bbcf80c..171bc3b 100644 --- a/vite.config.js +++ b/vite.config.js @@ -4,4 +4,13 @@ import vue from '@vitejs/plugin-vue' // https://vite.dev/config/ export default defineConfig({ plugins: [vue()], -}) + server: { + proxy: { + '/api': { + target: 'http://localhost:3001', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/api/, '') + } + } + } +}) \ No newline at end of file