Gik 常用写法

1、下载文件

download(attachmentItem) {
    this.$toast.loading("下载中...");
    let baseUrl = window['gik_entrance_info'].proxy;
    this.$gikBridge.call("file", "downloadFile", {
        url: baseUrl + attachmentItem.downloadUrl,
        targetFilePath: attachmentItem.name,
        timeout: 180,
        method: 'get',
        existMode: "delete"
    }).then(res => {
        this.$toast.clear();
        this.$toast.fail("下载成功");
        console.log("download res = ", res);
        if (res.code == 0) {
            this.preview(res.result.filePath);
        } else {
            this.$toast.fail("下载失败");
        }
    }, err => {
        this.$toast.clear();
        this.$toast.fail("下载失败");
        console.log("download err = ", err);
    }).catch(err => {
        this.$toast.fail("下载失败");
        console.log("download err = ", err);
    });
},

2、预览文件

preview(filePath) {
    this.$gikBridge.call("file", "previewFile", {
        filePath: filePath
    });
},

3、返回上一页并刷新

closePage() {
    this.$gikBus.$emit("XXXX");
    this.$router.go(-1);
},

mounted() {
    this.$gikBus.$on("XXXX", () => {
        this.loadData();
    });
},

4、打开网页

this.$gikBridge.call('app', 'openNewPage', { url: this.urlPath }).then(res=> {});

5、监听界面切换

watch:{
    $route(to, from) {
        console.log("from : " + from.name + ", to : " + to.name);
        if (to.name == 'home' || to.name == 'login') {
            this.loadCount();
        }
    }
},

6、监听界面消失后重新出现(例如切换多任务到其他应用或者桌面后,又重新切回来)

mounted() {
    document.addEventListener('visibilitychange', this.handleVisiable)
},
destroyed() {
    document.removeEventListener('visibilitychange', this.handleVisiable)
},
methods: {  
    handleVisiable(e) { 
        switch(e.target.visibilityState) {
            case 'hidden':
                console.log('内容不可见:处理后台、最小化、锁屏状态等');
                break;
            case 'visible':
                console.log('内容可见');
                break;
            default:
                break;
        }
    }
}

7、获取当前激活码对应配置的域名

this.$gikBridge.call("entrance", "getEntranceInfo", {}).then(res=> {
    console.log("====== res = " + JSON.stringify(res));
    console.log("res.result.proxy" + res.result.proxy);
});

8、监听返回按键的点击事件(虚拟按键或实体按键),要结合第 5 点界面切换监听来使用

data() {
	return {
		initted: false,
		currentPageName: 'login',
		exitTime: 0,
	};
},
mounted() {
	this.beginInit();
},
methods: {
	beginInit() {
		this.$store.dispatch("init").then(res => {
			//初始化过程完成
			this.initted = true;
			this.$gikBus.$on("onKeyback", (res) => {
				console.log("onKeyback currentPageName = " + this.currentPageName);
				if (this.currentPageName == 'home' || this.currentPageName == 'login') {
					console.log('点了返回键');
					if ((new Date().getTime() - this.exitTime) > 2000) {
						this.$toast('再按一次退出应用');
						this.exitTime = new Date().getTime();
					} else {
						this.$toast.clear();
						this.$gikBridge.call("app", "quitApp");
					}
				} else {
					this.$router.go(-1);
				}
			});
		});
	},
}

9、界面之间传递信息

this.$gikBus.$on("XXXXXX", (data) => {});
this.$gikBus.$off("XXXXXX");
this.$gikBus.$emit("XXXXXX");

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

却染人间愁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值