Merge branch 'main' of http://47.107.44.202:3000/xionglijia/18xchat
This commit is contained in:
@@ -27,6 +27,9 @@ import { promptItem } from "../Item/promptItem";
|
|||||||
import LanguageUtils, { LanguageType } from "../../Main/Common/LanguageUtils";
|
import LanguageUtils, { LanguageType } from "../../Main/Common/LanguageUtils";
|
||||||
import { DataManager } from "../../chat18x/data/DataManager";
|
import { DataManager } from "../../chat18x/data/DataManager";
|
||||||
import ConfigManager from "../../chat18x/manager/ConfigManager";
|
import ConfigManager from "../../chat18x/manager/ConfigManager";
|
||||||
|
import { AppConfig } from "db://assets/Scripts/chat18x/config/env/appConfig";
|
||||||
|
import DeviceIdService from "db://assets/Scripts/chat18x/foundation/identity/DeviceIdService";
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
@ccclass("PreloadUI")
|
@ccclass("PreloadUI")
|
||||||
@@ -59,8 +62,12 @@ export class PreloadUI extends Component {
|
|||||||
this.jinduFilled.fillRange = 0;
|
this.jinduFilled.fillRange = 0;
|
||||||
//this.btnLogin.node.active = false;
|
//this.btnLogin.node.active = false;
|
||||||
|
|
||||||
|
// 初始化环境配置
|
||||||
|
AppConfig.I;
|
||||||
// 初始化数据层
|
// 初始化数据层
|
||||||
DataManager.I.init();
|
DataManager.I.init();
|
||||||
|
// 设备号
|
||||||
|
DeviceIdService.I.init();
|
||||||
|
|
||||||
this.preloadFiles();
|
this.preloadFiles();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.2.0",
|
||||||
|
"importer": "directory",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "f42171fd-943c-43f1-8e9b-a01c598a7968",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.2.0",
|
||||||
|
"importer": "directory",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "c4d4cb16-e0f2-47ce-bb95-e432ef6a103b",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
export default class DeviceId {
|
||||||
|
static uuidv4(): string {
|
||||||
|
const hex: string[] = [];
|
||||||
|
for (let i = 0; i < 256; i++) hex[i] = (i < 16 ? "0" : "") + i.toString(16);
|
||||||
|
const r: number[] = [];
|
||||||
|
for (let i = 0; i < 16; i++) r[i] = Math.floor(Math.random() * 256);
|
||||||
|
r[6] = (r[6] & 0x0f) | 0x40; // version 4
|
||||||
|
r[8] = (r[8] & 0x3f) | 0x80; // variant
|
||||||
|
return (
|
||||||
|
hex[r[0]] + hex[r[1]] + hex[r[2]] + hex[r[3]] + "-" +
|
||||||
|
hex[r[4]] + hex[r[5]] + "-" +
|
||||||
|
hex[r[6]] + hex[r[7]] + "-" +
|
||||||
|
hex[r[8]] + hex[r[9]] + "-" +
|
||||||
|
hex[r[10]] + hex[r[11]] + hex[r[12]] + hex[r[13]] + hex[r[14]] + hex[r[15]]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "4.0.24",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "b1f91060-ad0e-41a8-af88-04b18e36e9d1",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import KVStore from "../storage/KVStore";
|
||||||
|
import DeviceId from "./DeviceId";
|
||||||
|
|
||||||
|
export class DeviceIdService {
|
||||||
|
private static _I: DeviceIdService | null = null;
|
||||||
|
static get I(): DeviceIdService { return this._I ?? (this._I = new DeviceIdService()); }
|
||||||
|
private constructor(private store = new KVStore("app:")) {}
|
||||||
|
|
||||||
|
private static KEY = "device_id";
|
||||||
|
private _id: string | null = null;
|
||||||
|
private _inited = false;
|
||||||
|
|
||||||
|
/** 启动时调用:加载或生成并持久化 */
|
||||||
|
init(): void {
|
||||||
|
if (this._inited) return;
|
||||||
|
const saved = this.store.get(DeviceIdService.KEY);
|
||||||
|
if (saved) {
|
||||||
|
this._id = saved;
|
||||||
|
} else {
|
||||||
|
// 如需原生ID,可先尝试原生,再用 UUID 兜底
|
||||||
|
this._id = DeviceId.uuidv4();
|
||||||
|
this.store.set(DeviceIdService.KEY, this._id);
|
||||||
|
}
|
||||||
|
this._inited = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取设备号(若未 init,会懒初始化一次) */
|
||||||
|
get id(): string {
|
||||||
|
if (!this._inited) this.init();
|
||||||
|
// 理论上不为空,保险起见再兜底
|
||||||
|
return this._id ?? DeviceId.uuidv4();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 重置(合规/调试用) */
|
||||||
|
reset(): void {
|
||||||
|
this.store.remove(DeviceIdService.KEY);
|
||||||
|
this._id = null;
|
||||||
|
this._inited = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default DeviceIdService;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "4.0.24",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "23dd5007-7e97-4e49-9035-8fbca04d0d03",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.2.0",
|
||||||
|
"importer": "directory",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "cd3361cc-4e2b-4bc0-8a6e-016111f5e5d8",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { sys } from "cc";
|
||||||
|
|
||||||
|
export default class KVStore {
|
||||||
|
constructor(private prefix = "app:") {}
|
||||||
|
private key(k: string) { return `${this.prefix}${k}`; }
|
||||||
|
|
||||||
|
get(k: string): string | null { return sys.localStorage.getItem(this.key(k)); }
|
||||||
|
set(k: string, v: string): void { sys.localStorage.setItem(this.key(k), v); }
|
||||||
|
remove(k: string): void { sys.localStorage.removeItem(this.key(k)); }
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "4.0.24",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "be7e3168-3885-4ad8-8775-8e2f1fe957ce",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user