123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- // 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 EventName from "../EventName/EventName";
- import HTTPS, { NetPost } from "../Template/HTTPS";
- import LocalData from "../Template/LocalData";
- import MyComponent from "../Template/MyComponent";
- import PopManger from "./PopManger";
- interface ResponseData {
- Version: string;
- Code: number;
- Message: string;
- Data: RoleData[];
- DataCount: number;
- PageCount: number;
- Mac: string;
- Timestamp: string;
- }
- interface RoleData {
- Id: number;
- Name: string;
- TotalNumber: number;
- List: UserData[];
- }
- interface UserData {
- UserId: number;
- Picture: string | null; // 可能是 null
- CollectId: number;
- CollectPicture: string;
- FullBodyPhoto: string;
- }
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class HallScrollView extends MyComponent {
- @property(cc.Node)
- content: cc.Node = null
- MyScrollView: cc.ScrollView = null
- onLoad() {
- super.onLoad();
- this.MyScrollView = this.node.getComponent(cc.ScrollView)
- this.regEvent(EventName.WhereMy, this.WhereMy, this)
- // this.content.children.forEach((e, index) => {
- // e.children.forEach((e1) => {
- // console.error(index);
- // if (index == 13) {
- // } else {
- // this.ddddd(e1)
- // }
- // })
- // })
- }
- start() {
- this.req()
- }
- Retrycount = 5
- req() {
- HTTPS.Instance.post(NetPost.GetPositionLevelRanking,
- {}).then((resp: ResponseData) => {
- for (let index = 0; index < resp.Data.length; index++) {
- const Data = resp.Data[index];
- const Node = this.content.children[index];
- for (let k = 0; k < Node.children.length; k++) {
- const RoleNode = Node.children[k];
- const RoleInfo = Data.List[k];
- if (RoleInfo) {
- // CollectPicture 半身
- // FullBodyPhoto 全身
- cc.assetManager.loadRemote(RoleInfo.FullBodyPhoto, (err, res: cc.Texture2D) => {
- if (!err) {
- RoleNode.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(res);
- RoleNode.active = true
- }
- })
- } else {
- RoleNode.active = false
- }
- }
- }
- })
- .catch((error) => {
- console.error('error');
- console.error(error);
- if (this.Retrycount-- > 0) {
- this.req()
- }
- })
- }
- WhereMy() {
- this.MyScrollView.stopAutoScroll()
- let contentNode = this.node.getChildByName("view").getChildByName("content")
- contentNode.height
- let index = LocalData.getInstance().getMyWorkplaceLevel()
- const y = contentNode.getChildByName(index + '').getPosition().y
- this.MyScrollView.scrollToOffset(cc.v2(0, Math.abs(y)), 0.3)
- }
- // ddddd(node: cc.Node) {
- // let path = 'Texture/Start/Desk/1/CEO' + this.getRandomNumber(1, 28)
- // PopManger.getInstance().LoadAssets<cc.Texture2D>(path).then((sp) => {
- // if (sp) {
- // node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(sp)
- // }
- // }).catch((error) => {
- // // 加载失败的处理
- // });
- // }
- // getRandomNumber(min: number, max: number): number {
- // return Math.floor(Math.random() * (max - min + 1)) + min;
- // }
- // update (dt) {}
- }
|