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");