| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import { _decorator, Node, Label, Sprite, Texture2D, SpriteFrame, ImageAsset, ProgressBar } from 'cc';
- import { JSB } from 'cc/env';
- import InfiniteCell from '../../core/InfiniteList/InfiniteCell';
- import { Http } from '../../core/net/Http';
- import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
- import { g } from '../../Data/g';
- import { platform } from '../../Data/platform';
- const { ccclass, property } = _decorator;
- @ccclass('EachWindowItem')
- export class EachWindowItem extends InfiniteCell {
- @property({ type: Label, tooltip: "名字文本" }) titleLabel: Label;
- @property({ type: Label, tooltip: "描述文本" }) decLabel: Label;
- @property({ type: Sprite, tooltip: "图标" }) icon: Sprite;
- @property({ type: Http, tooltip: "Http组件" }) http: Http;
- @property({ type: Node, tooltip: "安装" }) installNode: Node;
- @property({ type: Node, tooltip: "启动" }) startNode: Node;
- @property({ type: Node, tooltip: "下载" }) downLoadNode: Node;
- @property({ type: Node, tooltip: "进度" }) progressNode: Node;
- @property({ type: ProgressBar, tooltip: "下载进度条" }) progressBar: ProgressBar;
- @property({ type: Label, tooltip: "下载进度文本" }) progressLabel: Label;
- private url: string = "";
- private nebulaAppId: string = "";
- private id: number;
- private packageName: string = '';
- private downProgress = 0;
- private isInstrall = false;
- private hasApk = false;
- async UpdateContent(itemData: any) {
- this.installNode.active = this.startNode.active = this.downLoadNode.active = this.progressNode.active = false;
- this.id = itemData.id;
- this.titleLabel.string = itemData.title;
- this.decLabel.string = itemData.dec;
- this.nebulaAppId = itemData.nebulaAppId;
- this.packageName = itemData.packageName;
- this.url = itemData.url;
- if (JSB) {
- let img = await ResourcesUtils.loadRemote<ImageAsset>(itemData.icon, { ext: ".png" }, this);
- const spriteFrame = new SpriteFrame();
- const texture = new Texture2D();
- texture.image = img;
- spriteFrame.texture = texture;
- this.icon.spriteFrame = spriteFrame;
- this.setState();
- }
- }
- private setState() {
- this.isInstrall = platform.isInstalled(this.packageName);//是否有安装
- if (this.isInstrall) {//显示启动
- this.startNode.active = true;
- } else {
- this.hasApk = platform.isExistAPK(this.titleLabel.string + ".apk");//是否存在安装包
- if (this.hasApk) {//显示安装
- this.installNode.active = true
- } else {
- this.downLoadNode.active = true;
- //显示下载
- }
- }
- let str = '{"downProgress' + this.id + '":' + this.downProgress + '}';
- let data = JSON.parse(str);
- g.downLoadData.setData(data);
- }
- update() {
- if (g.downLoadData["downProgress" + this.id] != this.downProgress) {
- this.downProgress = g.downLoadData["downProgress" + this.id];
- this.downProgress = this.downProgress || 0;
- this.progressBar.progress = this.downProgress / 100;
- this.progressLabel.string = this.downProgress + '%';
- if (this.downProgress == 100) {
- g.downLoadData["downProgress" + this.id] = 0;
- this.progressNode.active = false;
- this.installNode.active = true;
- this.onInstall();
- }
- }
- }
- private onClick(): void {
- platform.downloadFile(this.url, this.titleLabel.string + ".apk", 'g.downLoadData["downProgress' + this.id + '"]');
- this.http.send("/api/recommend/AppDownloadLog", { downloadAppId: this.nebulaAppId, unionId: null, imei: g.deviceData.imei, idfa: g.deviceData.idfa, androId: g.deviceData.androId, oaid: g.deviceData.oaid, mac: g.deviceData.mac });
- this.downLoadNode.active = false;
- this.progressNode.active = true;
- }
- private onInstall() {
- platform.installApp(this.titleLabel.string + ".apk");
- }
- private startApp() {
- platform.startApp(this.packageName);
- }
- }
|