123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- // Learn TypeScript:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
- // Learn Attribute:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
- import PopManger from "./GameUI/PopManger";
- import Sdk from "./SDK/SDK";
- import { Debug, Leave_Days } from "./Template/Const";
- import HTTPS, { NetGet, NetPost } from "./Template/HTTPS";
- import LocalData, { WorkState } from "./Template/LocalData";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class LoadScene extends cc.Component {
- //开始按钮
- @property(cc.Node)
- StartGameNode: cc.Node = null
- //开始按钮
- @property(cc.ProgressBar)
- progress: cc.ProgressBar = null
- progressNum: number = null
- @property(cc.Label)
- launchDesc: cc.Label = null
- @property(cc.Node)
- Login: cc.Node = null
- start() {
- console.error('现在的值是');
- console.error(CC_DEBUG);
- this.Login.active = false
- this.StartGameNode.active = false
- console.time('LoadBundle');
- PopManger.getInstance().LoadBundle('sub').then((e) => {
- console.timeEnd('LoadBundle');
- console.time('Start');
- cc.director.preloadScene("Start", (curcomplete, totalcount) => {
- this.progress.progress = (((curcomplete / totalcount) / 2) + 0.5)
- this.updatelaunchDesc()
- }, () => {
- console.timeEnd('Start');
- if (Debug) {
- this.initNet('res.code')
- } else {
- //得到微信Code
- Sdk.getInstance().Login(res => {
- //微信给的数据
- console.error('微信给的数据');
- console.error(res);
- // res.code
- this.initNet(res.code)
- })
- }
- })
- })
- }
- protected update(dt: number): void {
- if (this.progress.progress < 0.5) {
- this.progress.progress += 0.01
- this.updatelaunchDesc()
- }
- }
- updatelaunchDesc() {
- this.launchDesc.string = `${(this.progress.progress * 100).toFixed(0)}%`;
- }
- StartGame() {
- cc.director.loadScene("Start")
- }
- initNet(Code: string) {
- console.error(111);
- Sdk.getInstance().getLaunchOptions()
- console.error(222);
- HTTPS.Instance.get(NetGet.Map).then((resp) => {
- // 初始化地图数据
- // SetMap(resp.Data)
- if (Debug) {
- let _openId = 152281
- //邀请ID
- let _InviterId = null
- return HTTPS.Instance.post(NetPost.TestLogin, {
- OpenId: _openId,
- InviterId: _InviterId ? _InviterId : null,
- })
- } else {
- return HTTPS.Instance.post(NetPost.Login, {
- Code: Code,
- InviterId: Sdk.getInstance().inviteID ? Sdk.getInstance().inviteID : null,
- })
- }
- }).then((resp) => {
- // 处理登录信息
- HTTPS.Instance.token = 'Bearer ' + resp?.Data?.SsoToken
- Sdk.getInstance().setOpenID(resp?.Data?.OpenId)
- if (resp?.Data?.Day >= Leave_Days) {
- LocalData.getInstance().setWorkState(WorkState.引导)
- } else {
- LocalData.getInstance().setWorkState(WorkState.上班)
- }
- return HTTPS.Instance.post(NetPost.GetUserInfo, {})
- }).then((resp) => {
- console.error('resp');
- console.error(resp);
- console.error(resp);
- // 处理登个人信息
- LocalData.getInstance().setMyWorkplaceLevel(resp?.Data?.PositionLevelId)
- this.Login.active = true
- Sdk.getInstance().getUserInfo(this.Login, (res: wx.types.UserInfo) => {
- //succeed
- this.StartGameNode.active = true
- this.Login.active = false
- // console.error('来了????');
- Sdk.getInstance().getFuzzyLocation().then((res: any) => {
- if (res.OK == true) {
- console.error('成功了');
- console.error(res.latitude);
- console.error(res.longitude);
- } else {
- console.error('失败了');
- console.error(res.latitude);
- console.error(res.longitude);
- }
- })
- HTTPS.Instance.post(NetPost.Authorisation, {
- OpenId: Sdk.getInstance().getOpenID(),
- Name: res.nickName,
- Tel: '',
- City: res.city,
- Picture: res.avatarUrl,
- })
- }, () => {
- //fail
- this.StartGameNode.active = true
- this.Login.active = false
- })
- })
- }
- }
|