game/assets/game-api.js
李鹏宇 f5c7ea4ddf 1.世界等级五个阶段,自己想办法命名和设计
2.势力等级分为6个
3.人物角色等级分为14个
4.货币也分为6档

一个背景的菜单栏。
写特色,介绍,背景,说明,致玩家等等
2026-07-23 18:53:54 +08:00

62 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 宇森游戏 · 前端与 Odoo 通信层
// 本地调试:前端 8888 -> Odoo 8069跨域带调试 CORS 头)
// 生产部署:前端与 Odoo 同域,由 nginx 代理 /game/*。
const API_CONFIG = {
base: (location.hostname === '127.0.0.1' && location.port === '8888')
? 'http://127.0.0.1:8069'
: (location.hostname === 'localhost' && location.port === '8888')
? 'http://127.0.0.1:8069'
: '',
db: (location.hostname === '127.0.0.1' && location.port === '8888') ? 'study' : 'game',
};
const _cred = API_CONFIG.base ? 'include' : 'same-origin';
function _url(path) {
return `${API_CONFIG.base}${path}?db=${API_CONFIG.db}`;
}
const API = {
async me() {
return (await fetch(_url('/game/api/me'), { credentials: _cred })).json();
},
async login(login, password) {
return (await fetch(_url('/game/api/login'), {
method: 'POST', credentials: _cred,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ login, password }),
})).json();
},
async register(payload) {
return (await fetch(_url('/game/api/register'), {
method: 'POST', credentials: _cred,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
})).json();
},
async logout() {
return (await fetch(_url('/game/api/logout'), {
method: 'POST', credentials: _cred,
})).json();
},
async codex() {
return (await fetch(_url('/game/api/codex'), { credentials: _cred })).json();
},
async rules() {
return (await fetch(_url('/game/api/rules'), { credentials: _cred })).json();
},
async currencies() {
return (await fetch(_url('/game/api/currencies'), { credentials: _cred })).json();
},
async pages() {
return (await fetch(_url('/game/api/pages'), { credentials: _cred })).json();
},
async threads() {
return (await fetch(_url('/game/api/threads'), { credentials: _cred })).json();
},
async announcements() {
return (await fetch(_url('/game/api/announcements'), { credentials: _cred })).json();
},
};