/*edge浏览器组件*/
export default {
template: `
`,
props: [],
data(){
return Vue.reactive({
caches:[],
index:0,
star:{
},
data:{
starList:[],
home:"https://www.bing.com"
},
url:"https://www.bing.com",
})
},
methods: {
edgeAction: function (type, sq) {
var that = this;
if (type == 1) {
//上一页
if (that.caches.length == 0) {
return;
}
;
if (that.index < 1) {
return;
}
that.index--;
that.url = that.caches[that.index];
} else if (type == 2) {
//下一页
if (that.caches.length == 0) {
return;
}
;
if (that.index > that.caches.length - 2) {
return;
}
;
that.index++;
that.url = that.caches[that.index];
} else if (type == 3) {
//刷新
} else if (type == 4) {
//首页
if (that.data && that.data.home) {
that.url = that.data.home;
that.edgeAction(5);
}
} else if (type == 5) {
//访问
if (!that.url.toLowerCase().startsWith("http")) {
that.url = "https://www.bing.com/search?q=" + encodeURIComponent(that.url);
}
if (that.caches.length == 0) {
that.caches.push(that.url);
}
;
if (that.caches[that.caches.length - 1] != that.url) {
that.caches.push(that.url);
}
;
that.index = that.caches.length - 1;
} else if (type == 6) {
//收藏
that.star = {
show: true,
data: {
name: "未填写",
url: that.url
}
}
} else if (type == 7) {
//保存书签
var data = that.star.data;
data.id = utils.uuid();
that.data.starList.push(data);
webos.context.set("showOkErrMsg", true);
var flag = webos.softUserData.save({appCode: "edgeBrowser", data: JSON.stringify(that.data)});
if (flag) {
that.star.show = false;
}
} else if (type == 8) {
//删除书签
utils.$.confirm("确认删除书签'" + sq.name + "'?", function (flag) {
if (!flag) {
return;
}
;
for (var i = 0; i < that.data.starList.length; i++) {
var tmp = that.data.starList[i];
if (tmp.id == sq.id) {
that.data.starList.splice(i, 1);
break;
}
}
webos.softUserData.save({appCode: "edgeBrowser", data: JSON.stringify(that.data)});
});
} else if (type == 9) {
//访问书签
that.url = sq.url;
that.edgeAction(5);
}
}
},
created: async function () {
var that = this;
that.edgeAction(5);
var res = await webos.softUserData.get({appCode: "edgeBrowser"});
if (res) {
var data = JSON.parse(res);
if (data) {
that.data = data;
}
}
}
}