/*桌面和图标组件*/ let attr = {}; export default { template: `
{{dragFile.length}}
拖放将复制到"{{dragUpload.title}}"
{{file.filterName}}
{{file.filterName}}
`, props: [], data(){ return { systemApps:[], shareEdit:{ show:false, data:{}, title:"分享文件", preUrl:"" }, currentPath:"", showIcon:false, files:[], fileSelectMap:{}, iconWidth:43, wins:[], wallpaper:{ url:"", type:"" }, dragUpload:{ path:"", title:"", show:false, uploadTasks:[] }, dragFile:{ icon:"", length:0 }, rename:{ name:"", newName:"" } } }, methods: { init:async function (){ var that = this; var hasLogin =await webos.user.hasLogin(); if(hasLogin){ that.refreshDesktop(); that.dragUploadFileInit(); } }, toRemoveShareData:function (item){ const that = this; utils.$.confirm("确认取消'"+item.name+"'共享吗?取消后该分享数据将无法访问!",async function (flag){ if(!flag){ return; }; webos.context.set("showOkErrMsg", true); flag = await webos.shareFile.dels([item.id]); if(flag){ await that.refreshDesktop(); } }); }, refreshDesktop:async function (){ var that = this; var count = await webos.userRecycle.count(); that.systemApps.forEach(function (item){ if(item.path == "trash"){ item.thumbnail = "modules/win11/imgs/icon/trash"+(count==0?"e":"")+".png"; } }); that.files = []; var config = webos.context.get("rightMenuConfig"); if(!config){ var config = await webos.softUserData.syncObject("settings_right_menu"); if(config.largeIcon === undefined){ config = {"largeIcon":false,"mediumIcon":true,"smallIcon":false,"showIcon":true,"sortName":"asc","sortSize":false,"sortDate":false}; } } if(config){ if(config.largeIcon){ that.iconWidth = 54; }else if(config.mediumIcon){ that.iconWidth = 43; }else if(config.smallIcon){ that.iconWidth = 36; } that.showIcon = config.showIcon; } var data = await webos.userDrive.specialFiles("desktop"); if(data){ that.files = data.list; that.currentPath = data.parentPath; for (let i = 0; i < that.files.length; i++) { let item = that.files[i]; await webos.fileSystem.fileIconCalc(item); if(item.type == 2){ if(!item.thumbnail){ item.thumbnail = "modules/win11/imgs/folder-sm.png"; } }else{ if(!item.thumbnail){ item.thumbnail = "imgs/file_icon/file.png"; } } } if(config){ that.files.sort(function (a,b){ var field = "filterName"; var order = "asc"; if(config.sortName){ field = "filterName"; order = config.sortName; }else if(config.sortDate){ field = "updatedAt"; order = config.sortDate; }else if(config.sortSize){ field = "size"; order = config.sortSize; } var av = a[field]?a[field]:""; var bv = b[field]?b[field]:""; av+=""; bv+=""; if(order == "asc"){ return av.localeCompare(bv); }else{ return bv.localeCompare(av); } }); } }; }, selectFileAction:async function(accept,multi,fn){ //accept 如果是folder说明是目录,其他情况是文件的后缀,多个用逗号分割 //multi 是否多选 true多选 false单选 //fn回调事件,返回[内容]数组 const that = this; var actionWin = await that.openFile("file-select",3,"请选择文件"+(accept=="folder"?"夹":""),"modules/win11/imgs/icon/explorer.png"); actionWin.data.multi = multi; actionWin.data.fn = fn; actionWin.data.selectExt = accept; var sz=accept.split(","); for (let i = 0; i < sz.length; i++) { if(!sz[i]){ sz[i] = "*"; } sz[i] = "*."+sz[i]; } actionWin.data.selectExtName = accept=="folder"?"文件夹":"文件("+sz.join(";")+")"; actionWin.width = 700; actionWin.height = 500; }, openFile:async function (path,type,name,icon,expAction){ //path type为1,2时为文件路径,type为3时为app名字,type为4时候代表页面路径,可以是相对路径,也可以是http开头的url //type 1文件 2文件夹 3系统app 4通用app //name 名称 //icon 存在则使用此icon,不存在将使用modules/模板/imgs/icon/应用名称.png let isDbl = false; if(!expAction){ expAction = "open"; }else if(expAction == "edit,open"){ //双击操作 isDbl = true; } var expActions = expAction.split(","); var that = this; var win = null; //winType 1正常 2最大化 3最小化 12 21 13 31 23 32 for (var i = 0; i < that.wins.length; i++) { var tmp = that.wins[i]; if(tmp.close){ win = tmp; break; } }; if(!win){ win = Vue.reactive({ id:"id-"+utils.uuid() }); that.wins.push(win); }; var height = window.innerHeight*0.8; if(height>700){ height = 700; }; var width = window.innerWidth*0.8; if(width>1024){ width = 1024; }; var tmpWin = { show:false, width:width, height:height, left:window.innerWidth/2-width/2, top:window.innerHeight/2-height/2, winLastType:3, winNowType:1, close:true, isSimple:false, hideMax:false, hideMin:false, hideSize:false, hideClose:false, disableMax:false, disableClose:false, disableMin:false, }; for(var key in tmpWin){ win[key] = tmpWin[key]; }; win.data = {}; if(type == 2){ //桌面打开文件夹,调用文件管理器 if(!icon){ icon = "modules/win11/imgs/folder-sm.png"; } win.data = { app: "fileExplorer", icon: icon, name: name, path: path }; }else{ if(type == 3){ //系统app win.data = { app: path, icon: icon?icon:"modules/win11/imgs/icon/"+path+".png", name: name } }else if(type == 4){ //通用app 用于插件和轻应用 win.data = { app: "commonApp", icon: icon?icon:"modules/win11/imgs/icon/commonApp.png", name: name, url: path }; }else{ //打开文件 if(name.endsWith(".webosapp")){ //这是打开app var systemAppMap = that.systemAppMap(); if(systemAppMap[path]){ win.data = that.realSystemData(path); }else{ var fileCache = await webos.fileSystem.getFileCache(path); var text = String.fromCharCode.apply(null, new Uint8Array(fileCache)); text = decodeURIComponent(escape(text)); win.data = JSON.parse(text); } var icon = win.data.app; if(win.data.targetApp){ win.data.app = win.data.targetApp; } if(!win.data.icon){ win.data.icon = "modules/win11/imgs/icon/"+icon+".png"; } }else{ var ext = webos.util.getExtByName(name); if(isDbl && webos.util.isMedia(ext)){ //如果是双击的又是媒体资源,优先使用打开模式 expActions = ["open","edit"]; } var privateApp = await webos.util.userOpenApp(ext,expActions); if(!privateApp){ webos.message.error("此文件不支持打开,可前往商城寻找支持的程序"); return; } var fileUrl = await webos.fileSystem.zl(path,2); var url = privateApp.url+"?action=openwith&url="+encodeURIComponent(fileUrl)+"&ext="+encodeURIComponent(ext)+"&fname="+encodeURIComponent(name)+"&path="+encodeURIComponent(path)+"&expAction="+privateApp.expAction; win.data = { app: "commonApp", icon: privateApp.iconUrl, name: privateApp.appName, url: url } } } } win.close = false; win.show = true; utils.delayAction(function (){ return document.querySelector("#"+win.id+"header"); },function (){ var header = document.querySelector("#"+win.id+"header"); that.topWindow({target:header}); var target = header.parentElement.parentElement; var aid = webos.el.animationCss({left:document.body.clientWidth/2,top:document.body.clientHeight,height:0,width:0},win); target.style.left = win.left+"px"; target.style.top = win.top+"px"; target.style.height = win.height+"px"; target.style.width = win.width+"px"; target.style.animation = aid+" 0.3s"; target.style["animation-fill-mode"] = "none"; }); return win; }, winMoveAction:function (e){ if(this.$refs.wins_dialog){ this.$refs.wins_dialog[0].moveAction(e); } }, winMoveStop:function (e){ if(this.$refs.wins_dialog){ this.$refs.wins_dialog[0].windowSizeChangeEnd(e); this.$refs.wins_dialog[0].windowMoveEnd(e); } }, topWindow:function (e){ if(document.activeElement && document.activeElement.className.indexOf("el-dialog") != -1){ document.activeElement.blur(); } var that = this; var target = e.target; if(!target){ return; } for (let i = 0; i < 50; i++) { if(!target){ break; } if(target.classList.contains("el-dialog")){ break; } target = target.parentElement; } if(!target){ return; } var isFirst = false; if(!attr.dragDialog){ attr.dragDialog = { last:target, index:2001 } isFirst = true; } if(isFirst || attr.dragDialog.last != target){ attr.dragDialog.index ++; attr.dragDialog.last = target; attr.dragDialog.last.style["z-index"] = attr.dragDialog.index; var header = target.querySelector(".win-header"); if(!header){ return; }; if(!header.id){ return; } var winId = header.id.replace("header",""); for (let i = 0; i < that.wins.length; i++) { that.wins[i].active = that.wins[i].id == winId; } } }, dragUploadFileInit:function (){ var that = this; utils.delayAction(function (){ return document.body; },function (){ if(webos.context.get("hasBindUpload")){ return; }; webos.context.set("hasBindUpload",true); function calcDrag(e){ //本地拖拽上传 var ele = webos.el.isInClass(e.target,"webos-file-panel"); if(!ele){ that.dragUpload.show = false; return false; }; if(webos.fileSystem.isSpecialPath(ele.dataset.path)){ that.dragUpload.show = false; return false; }; that.dragUpload.title = ele.dataset.title; that.dragUpload.path = ele.dataset.path; that.dragUpload.show = true; return true; } webos.fileSystem.bindEleToDragUpload({ ele:document.body, enter:function(ele,e){ calcDrag(e); }, leave:function(ele,e){ that.dragUpload.show = false; }, drop:function(ele,e,flag){ that.dragUpload.show = false; if(flag){ webos.message.success(e.dataTransfer.items.length+"个文件或文件夹即将上传"); } }, dragover:function(ele,e){ calcDrag(e); }, canUpload:function (ele,e){ return calcDrag(e); }, path:function (){ return that.dragUpload.path; }, pathName:function (){ return that.dragUpload.title; }, sourceName:function (){ return "本地"; }, callback:function (task){ that.uploadFileCallback(task); }, }); }); }, refreshFileBrower:function(parentPath){ var that = this; if(parentPath == that.currentPath){ that.refreshDesktop(); }; if(that.$refs.wins_dialog){ for(var i=0;i0; },function (){ that.$refs["rename-ta"][0].focus(); that.$refs["rename-ta"][0].select(); },3000); }, actionRename:async function (file){ var that = this; var text = that.rename.newName; if(text == file.name){ that.renameStatus(false); return; } if(webos.util.getExtByName(text) != file.ext && file.type == 1){ if(!webos.util.getExtByName(text)){ webos.message.error("后缀名不可为空"); return; } utils.$.confirm("当前后缀名和之前不一致,确定继续?",async function (flag2){ if(!flag2){ that.renameStatus(false); return; }; webos.context.set("showOkErrMsg", true); await webos.fileSystem.rename({path:file.path,name:text,type:file.type}); that.renameStatus(false); await that.refreshDesktop(); }); }else{ webos.context.set("showOkErrMsg", true); await webos.fileSystem.rename({path:file.path,name:text,type:file.type}); that.renameStatus(false); await that.refreshDesktop(); } }, renameStatus:function (flag){ var that = this; attr.reanmeShow = flag; if(!flag){ that.rename.newName = ""; that.rename.name = ""; } }, dragFileEleMove:function (e){ var that = this; if(attr.reanmeShow){ return; } if(!attr.dragFileEle){ that.dragUpload.show = false; return; }; if(!attr.dragFileEle.move){ attr.dragFileEle.target = null; that.dragUpload.show = false; return; }; var dragEle = document.querySelector(".file-drag-wrap"); dragEle.style.display = "initial"; dragEle.style.left = e.clientX+"px"; dragEle.style.top = e.clientY+"px"; var ele = webos.el.isInClass(e.target,"webos-file-panel"); if(!ele){ attr.dragFileEle.target = null; that.dragUpload.show = false; return; }; if(webos.fileSystem.isSpecialPath(ele.dataset.path)){ attr.dragFileEle.target = null; that.dragUpload.show = false; return; } if(ele.dataset.path == attr.dragFileEle.source.path){ attr.dragFileEle.target = null; that.dragUpload.show = false; return; }; attr.dragFileEle.target = {path:ele.dataset.path,title:ele.dataset.title}; that.dragUpload.title = attr.dragFileEle.target.title; that.dragUpload.path = attr.dragFileEle.target.path; that.dragUpload.show = true; }, dragFileEleOver:function (e){ var that = this; if(attr&&attr.dragFileEle&&attr.dragFileEle.move){ that.dragUpload.show = false; attr.dragFileEle.move = false; var dragEle = document.querySelector(".file-drag-wrap"); dragEle.style.display = ""; if(attr.dragFileEle.target){ var files = attr.dragFileEle.source.files; var app = webos.el.findParentComponent(that,"app-component"); app.$refs["rm"].desktopTzCopy(files,e); } } }, calcMoreSelect:function (e){ //计算选中的元素 var that = this; var div = document.querySelector(".more-select-wrap"); function is_rect_intersect(x01,x02,y01,y02,x11,x12,y11,y12){ var zx = Math.abs(x01 + x02 -x11 - x12); var x = Math.abs(x01 - x02) + Math.abs(x11 - x12); var zy = Math.abs(y01 + y02 - y11 - y12); var y = Math.abs(y01 - y02) + Math.abs(y11 - y12); return zx <= x && zy <= y; } var divX1 = div.offsetLeft; var divY1 = div.offsetTop; var divX2 = div.offsetLeft+div.offsetWidth; var divY2 = div.offsetTop+div.offsetHeight; var type = attr.moreSelectLastStatus.type; if(type == "desktop"){ div.style["z-index"] = 500; var list = document.querySelector(".webos-file-panel").querySelectorAll(".webos-file"); for (var i = 0; i < list.length; i++) { var item = list[i]; var itemX1 = item.offsetLeft; var itemY1 = item.offsetTop; var itemX2 = item.offsetLeft+item.offsetWidth; var itemY2 = item.offsetTop+item.offsetHeight; if(is_rect_intersect(itemX1,itemX2,itemY1,itemY2,divX1,divX2,divY1,divY2)){ that.fileSelectMap[item.dataset.path] = { path:item.dataset.path, type:item.dataset.type, icon:item.dataset.icon, name:item.dataset.name, ext:item.dataset.ext }; } } }else if(type == "fileExplorer"){ div.style["z-index"] = 9999999; var list = attr.moreSelectLastStatus.component.$refs['filePanel'].querySelectorAll(".webos-file"); for (var i = 0; i < list.length; i++) { var item = list[i]; var itemX1 = attr.moreSelectLastStatus.offsetLeft+item.offsetLeft; var itemY1 = attr.moreSelectLastStatus.offsetTop+item.offsetTop; var itemX2 = itemX1+item.offsetWidth; var itemY2 = itemY1+item.offsetHeight; if(is_rect_intersect(itemX1,itemX2,itemY1,itemY2,divX1,divX2,divY1,divY2)){ attr.moreSelectLastStatus.component.selectMap[item.dataset.path] = { path:item.dataset.path, type:item.dataset.type, icon:item.dataset.icon, name:item.dataset.name, ext:item.dataset.ext }; }; } attr.moreSelectLastStatus.component.emitSelectFile(); } }, moreSelectMove:function (e){ var that = this; if(attr.moreSelectLastStatus && attr.moreSelectLastStatus.move){ //多选蒙版处理 var div = document.querySelector(".more-select-wrap"); var left = attr.moreSelectLastStatus.clientX; var top = attr.moreSelectLastStatus.clientY; var width = e.clientX - left; var height =e.clientY - top; if(width<0){ left = e.clientX; width = -width; } if(height<0){ top = e.clientY; height = -height; } div.style.left = left+"px"; div.style.top = top+"px"; div.style.width = width+"px"; div.style.height = height+"px"; that.calcMoreSelect(e); } }, moreSelectOver:function (){ if(attr.moreSelectLastStatus && attr.moreSelectLastStatus.move){ var div = document.querySelector(".more-select-wrap"); attr.moreSelectLastStatus = {}; div.style.display="none"; } }, fileDblClick:function (file,e){ var that = this; if(attr.reanmeShow){ return; } if(e.button != 0){ return; } if(that.lastClickObj && that.lastClickObj.dataFile == file && Date.now() - that.lastClickObj.time <= 400){ that.openFile(file.path,file.type,file.name,file.thumbnail,"edit,open"); }; that.lastClickObj = { dataFile:file, time:Date.now() } }, toEditShareData:async function (id){ const that = this; var info = await webos.shareFile.info(id); that.shareEdit.title = info.name; that.shareEdit.show = true; that.shareEdit.data = info; var url = window.location.origin + window.location.pathname; var sz = url.split("/"); sz.length = sz.length - 1; that.shareEdit.preUrl = sz.join("/")+"/index.html?share="; }, toShareData:async function(files){ var that = this; var getParentCurrentPath = function (path){ var sz = path.split("/"); var currentPath = sz[sz.length-1]; sz.length = sz.length - 1; var parentPath = sz.join("/"); return {currentPath,parentPath}; }; var list = []; var parentPath; for (let i = 0; i < files.length; i++) { var pathMap = getParentCurrentPath(files[i].path); if(!parentPath){ parentPath = pathMap.parentPath; } if(parentPath != pathMap.parentPath){ webos.message.error("当前选中文件不在同一个目录中"); return; } list.push(pathMap.currentPath); } var filesStr = list.join(";"); var shareId = await webos.shareFile.findOne({path:parentPath,files:filesStr}); if(shareId){ await that.toEditShareData(shareId); return; } var code = await webos.shareFile.getCode(); if(!code){ webos.message.error("编码生成失败"); return; } var title = files[0].name; if(files.length>1){ if(title.length>5){ title = title.substring(0,5)+"..."; } title += "等"+files.length+"个文件"; } title = title + "分享"; that.shareEdit.title = title; that.shareEdit.show = true; that.shareEdit.data = { code:code, name:title, path:parentPath, files:filesStr }; var url = window.location.origin + window.location.pathname; var sz = url.split("/"); sz.length = sz.length - 1; that.shareEdit.preUrl = sz.join("/")+"/index.html?share="; }, saveShareEdit:async function (){ var that = this; webos.context.set("showOkErrMsg", true); var flag = await webos.shareFile.save(that.shareEdit.data); }, systemAppMap:function (){ var map = { fileExplorer:"此电脑", trash:"回收站", store:"应用商店", edgeBrowser:"Microsoft Edge", }; return map; }, systemAppsInit:function (){ const that = this; var map = that.systemAppMap(); var sz = []; for(var key in map){ sz.push({filterName:map[key],thumbnail:"modules/win11/imgs/icon/"+key+".png",path:key,type:1,name:map[key]+".webosapp"}); } that.systemApps = sz; }, realSystemData:function (app){ const that = this; var data = {app:app,type:3,name:that.systemAppMap()[app]}; if(app == "fileExplorer"){ data.path="thispc"; }else if(app == "trash"){ data.path="trash"; data.targetApp = "fileExplorer"; } return data; } }, created:function () { var that = this; that.systemAppsInit(); //that.init(); } }