mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-26 18:26:23 +00:00
更新登录
This commit is contained in:
@@ -14,20 +14,21 @@ import { JsonLoad, JsonUtil } from "../../extensions/ngame/assets/ngame/util/Jso
|
||||
import NGameMessage from "../../extensions/ngame/assets/ngame/util/NGameMessage";
|
||||
import axios from "../../extensions/ngame/assets/plugins/axios.js";
|
||||
import GBattleModeManager from "./battle/GBattleModeManager";
|
||||
import { GLayer, UIConfig } from "./ui/UIConfig";
|
||||
import { GLayer, GUI, UIConfig } from "./ui/UIConfig";
|
||||
import JLoaderSystem from "../../extensions/ngame/assets/ngame/system/JLoaderSystem";
|
||||
import { sp } from "cc";
|
||||
import { SpriteFrame } from "cc";
|
||||
import Loading from "../../extensions/ngame/assets/ngame/util/Loading";
|
||||
import { TB, Tables } from "../resources/config/data/schema";
|
||||
import { JsonAsset } from "cc";
|
||||
import { GAction } from "./GActionEnum";
|
||||
import { GAction } from "./consts/GActionEnum";
|
||||
import { StorageData, StorageEnum } from "./consts/GData";
|
||||
|
||||
let IP = "localhost";
|
||||
let IP = "kyu.jisol.cn";
|
||||
|
||||
//重写UI
|
||||
class JNGLayer extends JNLayer{
|
||||
layers: string[] = [GLayer.View];
|
||||
layers: string[] = [GLayer.View,GLayer.Popup,GLayer.Tips];
|
||||
views: { [key: string]: JNLayerInfo; } = UIConfig;
|
||||
}
|
||||
|
||||
@@ -37,12 +38,27 @@ class JNGSocket extends JNSocket{
|
||||
this.on(GAction.TOKEN_EXPIRED,this.onTokenExpired.bind(this));
|
||||
await super.onInit();
|
||||
}
|
||||
public url() {
|
||||
return `ws://${IP}:8080/websocket/b113a866e5664f46b386c12c985d394a`;
|
||||
public url():Promise<string> {
|
||||
return new Promise<string>(resolve => {
|
||||
//获取Token
|
||||
let token = StorageData.get(StorageEnum.Token);
|
||||
if(token){
|
||||
resolve(`ws://${IP}:8080/websocket/${token}`)
|
||||
return;
|
||||
}
|
||||
|
||||
const loginResolve = (token:string) => {
|
||||
resolve(`ws://${IP}:8080/websocket/${token}`);
|
||||
}
|
||||
//如果没有Token则弹出登入页面
|
||||
app.layer.Open(GUI.Login,loginResolve);
|
||||
});
|
||||
}
|
||||
//Token失效
|
||||
onTokenExpired(){
|
||||
console.log("onTokenExpired");
|
||||
//清除Token
|
||||
StorageData.delect(StorageEnum.Token);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,9 +0,0 @@
|
||||
|
||||
export const GData = {
|
||||
|
||||
layer: {
|
||||
World: 1,
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -23,11 +23,11 @@ export class Main extends Component {
|
||||
{path:"proto/GDemo"}
|
||||
]);
|
||||
|
||||
// //发生帧同步开始
|
||||
// app.socket.Send(JNSyncAction.NSyncFrameStart);
|
||||
//发生帧同步开始
|
||||
app.socket.Send(JNSyncAction.NSyncFrameStart);
|
||||
|
||||
// // 创建世界
|
||||
// director.getScene().addChild(instantiate(this.WorldPrefab));
|
||||
// 创建世界
|
||||
director.getScene().addChild(instantiate(this.WorldPrefab));
|
||||
|
||||
}
|
||||
|
||||
|
@@ -7,7 +7,7 @@ import { size } from "cc";
|
||||
import { Size } from "cc";
|
||||
import { v3 } from "cc";
|
||||
import { Vec2 } from "cc";
|
||||
import { GData } from "../../../GData";
|
||||
import { GData } from "../../../consts/GData";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
export interface GButtleDefaultInfo{
|
||||
|
@@ -2,7 +2,7 @@ import { UITransform } from "cc";
|
||||
import { Node } from "cc";
|
||||
import { sp } from "cc";
|
||||
import JNSkeleton from "../../../../../extensions/ngame/assets/ngame/sync/frame/game/spine/JNFrameSkeleton";
|
||||
import { GData } from "../../../GData";
|
||||
import { GData } from "../../../consts/GData";
|
||||
import GNode from "./GNode";
|
||||
|
||||
export default class GEffectUtil {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { Node } from "cc";
|
||||
import { GData } from "../../../GData";
|
||||
import { GData } from "../../../consts/GData";
|
||||
import { UITransform } from "cc";
|
||||
|
||||
|
||||
|
9
JisolGameCocos/assets/script/consts.meta
Normal file
9
JisolGameCocos/assets/script/consts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "c8e51348-b270-4894-9e0e-d27172e9324e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
32
JisolGameCocos/assets/script/consts/API.ts
Normal file
32
JisolGameCocos/assets/script/consts/API.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { app } from "../App";
|
||||
import { GUI } from "../ui/UIConfig";
|
||||
|
||||
const http = app.api;
|
||||
|
||||
const RData = (data:any) => {
|
||||
if(data.data.state == 200){
|
||||
return data.data.data;
|
||||
}else{
|
||||
//弹出提示
|
||||
app.layer.Open(GUI.Tips,{text:data.data.msg});
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export interface UserVO{
|
||||
userId:number, //玩家Id
|
||||
userName:string, //玩家名称
|
||||
userPass:string, //玩家密码
|
||||
}
|
||||
export interface UserLoginVO{
|
||||
token:string, //token
|
||||
user:UserVO, //玩家信息
|
||||
}
|
||||
|
||||
export const API = {
|
||||
|
||||
UserRegister : async () => RData(await http.post(`/user/register`)) as UserVO,
|
||||
UserLogin : async (account:string,password:string) => RData(await http.post(`/user/login`,{userId:account,userPass:password})) as UserLoginVO,
|
||||
|
||||
}
|
||||
|
9
JisolGameCocos/assets/script/consts/API.ts.meta
Normal file
9
JisolGameCocos/assets/script/consts/API.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "503f2086-2c48-470c-90e0-98e92c5dd354",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -2,7 +2,7 @@
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b0d5a426-cf84-4bbb-b06f-533234076520",
|
||||
"uuid": "ed7dee3c-9396-4f08-bd29-deb690ca6cf8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
30
JisolGameCocos/assets/script/consts/GData.ts
Normal file
30
JisolGameCocos/assets/script/consts/GData.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { sys } from "cc";
|
||||
|
||||
export enum StorageEnum{
|
||||
|
||||
Token = "Storage_Token", // Token
|
||||
|
||||
}
|
||||
|
||||
export class StorageData {
|
||||
|
||||
static get(key:string):string{
|
||||
return sys.localStorage.getItem(key);
|
||||
}
|
||||
|
||||
static set(key:string,value:string){
|
||||
sys.localStorage.setItem(key,value);
|
||||
}
|
||||
|
||||
static delect(key:string){
|
||||
sys.localStorage.removeItem(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const GData = {
|
||||
layer: {
|
||||
World: 1,
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e04ba6b5-5d91-4424-969a-8faa3dacf167",
|
||||
"uuid": "d784fece-1a89-44ad-9119-29b965912c7d",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
@@ -4,6 +4,8 @@ import { Toggle } from 'cc';
|
||||
import { JNSyncAction } from '../../../../extensions/ngame/assets/ngame/sync/JNSyncAction';
|
||||
import { director } from 'cc';
|
||||
import { WorldCanvas } from '../../WorldCanvas';
|
||||
import { StorageData, StorageEnum } from '../../consts/GData';
|
||||
import { GUI } from '../UIConfig';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('HomeView')
|
||||
@@ -39,10 +41,17 @@ export class HomeView extends JNGLayerBase {
|
||||
//前往PVP
|
||||
onClickGoPVP(){
|
||||
director.getScene().getComponentInChildren(WorldCanvas).index = 0;
|
||||
app.layer.Open(GUI.Tips,{text:"切换成功 请点击重置"});
|
||||
}
|
||||
//前往无尽
|
||||
onClickGoOnHook(){
|
||||
director.getScene().getComponentInChildren(WorldCanvas).index = 1;
|
||||
app.layer.Open(GUI.Tips,{text:"切换成功 请点击重置"});
|
||||
}
|
||||
//清除Token
|
||||
onClickToken(){
|
||||
StorageData.delect(StorageEnum.Token);
|
||||
app.layer.Open(GUI.Tips,{text:"清除成功"});
|
||||
}
|
||||
|
||||
}
|
||||
|
9
JisolGameCocos/assets/script/ui/System.meta
Normal file
9
JisolGameCocos/assets/script/ui/System.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "beb0794b-9e15-4b22-8b23-48017459df89",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
58
JisolGameCocos/assets/script/ui/System/LoginView.ts
Normal file
58
JisolGameCocos/assets/script/ui/System/LoginView.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
import JNLayerBase from '../../../../extensions/ngame/assets/ngame/ui/base/JNLayerBase';
|
||||
import { API } from '../../consts/API';
|
||||
import { EditBox } from 'cc';
|
||||
import { app } from '../../App';
|
||||
import { GUI } from '../UIConfig';
|
||||
import { StorageData, StorageEnum } from '../../consts/GData';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('LoginView')
|
||||
export class LoginView extends JNLayerBase {
|
||||
|
||||
resolve:(token:string) => void;
|
||||
|
||||
@property(EditBox)
|
||||
account:EditBox;
|
||||
@property(EditBox)
|
||||
password:EditBox;
|
||||
|
||||
onJNLoad(resolve?: (token:string) => void): void {
|
||||
super.onJNLoad();
|
||||
this.resolve = resolve;
|
||||
}
|
||||
|
||||
|
||||
//点击登录
|
||||
async onClickLogin(){
|
||||
//校验
|
||||
if(!(this.account.string.length) || !(this.password.string.length)){
|
||||
app.layer.Open(GUI.Tips,{text:"请输入账号密码"});
|
||||
return;
|
||||
}
|
||||
|
||||
//登录账号
|
||||
let info = await API.UserLogin(this.account.string,this.password.string);
|
||||
if(info){
|
||||
app.layer.Open(GUI.Tips,{text:"登录成功"});
|
||||
//保存Token
|
||||
StorageData.set(StorageEnum.Token,info.token);
|
||||
this.resolve(info.token);
|
||||
this.onJNClose();
|
||||
}
|
||||
}
|
||||
|
||||
//点击注册账号
|
||||
async onClickRegister(){
|
||||
//注册账号
|
||||
let info = await API.UserRegister();
|
||||
//显示提示
|
||||
app.layer.Open(GUI.Tips,{text:"注册成功"});
|
||||
//显示账号和密码
|
||||
this.account.string = `${info.userId}`;
|
||||
this.password.string = info.userPass;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
9
JisolGameCocos/assets/script/ui/System/LoginView.ts.meta
Normal file
9
JisolGameCocos/assets/script/ui/System/LoginView.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d36bcaa8-bb30-419b-be25-ed9f10aef387",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
9
JisolGameCocos/assets/script/ui/System/Tips.meta
Normal file
9
JisolGameCocos/assets/script/ui/System/Tips.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "072aa010-a6b8-4ff4-b104-5bc19b5ac2fb",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
35
JisolGameCocos/assets/script/ui/System/Tips/TipsView.ts
Normal file
35
JisolGameCocos/assets/script/ui/System/Tips/TipsView.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
import JNLayerBase from '../../../../../extensions/ngame/assets/ngame/ui/base/JNLayerBase';
|
||||
import { app } from '../../../App';
|
||||
import { Label } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
export interface TipsArgs{
|
||||
text?:string; //内容
|
||||
time?:number; //显示时间
|
||||
}
|
||||
|
||||
@ccclass('TipsView')
|
||||
export class TipsView extends JNLayerBase {
|
||||
|
||||
@property(Label)
|
||||
text:Label;
|
||||
|
||||
onJNLoad(data: TipsArgs = {}): void {
|
||||
if(!data) data = {};
|
||||
|
||||
data.text = data.text || "这是一个提示";
|
||||
data.time = data.time || 3;
|
||||
|
||||
//显示弹窗内容
|
||||
this.text.string = data.text;
|
||||
|
||||
this.scheduleOnce(() => {
|
||||
this.onJNClose();
|
||||
},data.time)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "76584604-effd-4af6-b3ef-7246a8c37260",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -3,15 +3,39 @@ import { JNLayerAnim, JNLayerInfo } from "../../../extensions/ngame/assets/ngame
|
||||
|
||||
export enum GLayer{
|
||||
View = "View",
|
||||
Popup = "Popup",
|
||||
Tips = "Tips",
|
||||
}
|
||||
|
||||
export enum GUI{
|
||||
Loading = "Loading",
|
||||
Home = "Home",
|
||||
/** 系统UI */
|
||||
Login = "Login", //登录页面
|
||||
Loading = "Loading", //加载页面
|
||||
Tips = "Tips", //提示
|
||||
|
||||
Home = "Home", //主页面
|
||||
}
|
||||
|
||||
export const UIConfig:{ [key: string]: JNLayerInfo; } = {
|
||||
[GUI.Loading]:{
|
||||
|
||||
//系统UI
|
||||
const UISystemConfig:{ [key: string]: JNLayerInfo; } = {
|
||||
[GUI.Tips]:{
|
||||
layer:GLayer.Tips,
|
||||
uri: "prefab/ui/System/Tips/TipsView",
|
||||
anims:{
|
||||
front:JNLayerAnim.BackOutOpen,
|
||||
back:JNLayerAnim.BackInClose
|
||||
}
|
||||
},
|
||||
[GUI.Login]:{
|
||||
layer:GLayer.Popup,
|
||||
uri: "prefab/ui/System/LoginView",
|
||||
anims:{
|
||||
front:JNLayerAnim.BackOutOpen,
|
||||
back:JNLayerAnim.BackInClose
|
||||
}
|
||||
},
|
||||
[GUI.Loading]:{
|
||||
layer:GLayer.View,
|
||||
uri: "prefab/ui/Loading/LoadingView",
|
||||
anims:{
|
||||
@@ -19,7 +43,10 @@ export const UIConfig:{ [key: string]: JNLayerInfo; } = {
|
||||
backInfo:{key:"position",start:v3(0,0,0),end:v3(-720,0,0)}
|
||||
},
|
||||
},
|
||||
[GUI.Home]:{
|
||||
}
|
||||
|
||||
export const UIConfig:{ [key: string]: JNLayerInfo; } = {
|
||||
[GUI.Home]:{
|
||||
layer:GLayer.View,
|
||||
uri: "prefab/ui/Home/HomeView",
|
||||
anims:{
|
||||
@@ -29,5 +56,6 @@ export const UIConfig:{ [key: string]: JNLayerInfo; } = {
|
||||
backInfo:{key:"position",start:v3(0,0,0),end:v3(-720,0,0)}
|
||||
},
|
||||
},
|
||||
...UISystemConfig
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user