/**/
export default {
template: `
{{contentFiles.length}}个项目
去获取
选择
请选择具备创建文件夹权限的目录
否则将无法分配给子用户使用
当前开启秒传能力,上述路径将存储文件索引
真实文件储存在下方位置
选择
保存
取消
刷新
取消
前往
选择当前目录
取消
..
{{item.name}}
`,
props: ['win'],
data(){
return {
hasLogin:true,
contentFiles:Vue.reactive([]),
title:"",
fileTree:{},
caches:[],
cacheIndex:0,
pathData:[],
dataPath:"",
selectMap:{},
starList:[],
starZk:true,
isMain:false,
ioDriveEdit:{
show:false,
data:{},
title:"新增磁盘"
},
driveTypeList:[],
configDialog:{
show:false,
url:"",
title:"阿里云盘",
width:0,
height:0,
},
iconWidth:43,
rename:{
name:"",
newName:""
},
loading:false,
selectPathData:{
show:false,
parentPath:"",
list:[],
loading:false,
field:""
}
}
},
methods: {
selectCurrentPath:function (){
const that = this;
that.ioDriveEdit.data[that.selectPathData.field] = that.selectPathData.parentPath.replace("//","/");
that.selectPathData.show = false;
},
getFolderByParentPathLast:async function (){
const that = this;
var sz = that.selectPathData.parentPath.split("/");
sz.length -= 1;
await that.getFolderByParentPath(sz.join("/"));
},
getFolderByParentPath:async function(parentPath){
const that = this;
var driveType = that.ioDriveEdit.data.driveType;
var tokenId = that.ioDriveEdit.data.tokenId;
that.selectPathData.loading = true;
var res = await webos.drive.getFolderByParentPath({parentPath,driveType,tokenId});
that.selectPathData.list = res.data;
that.selectPathData.parentPath = res.parent;
that.selectPathData.loading = false;
},
selectPath:async function (){
const that = this;
if(that.ioDriveEdit.data.driveType != "local"){
webos.context.set("showErrMsg", true);
var tid = await webos.drive.getTokenId(that.ioDriveEdit.data.driveType,that.ioDriveEdit.data.tokenId);
if(tid){
that.ioDriveEdit.data.tokenId = tid;
}else{
return;
}
}
await that.getFolderByParentPath("");
that.selectPathData.field = "path";
that.selectPathData.show = true;
webos.el.dialogCenter(that.$refs["io-drive-select-path"]);
},
selectRealPath:async function (){
const that = this;
await that.getFolderByParentPath("");
that.selectPathData.field = "realFilePath";
that.selectPathData.show = true;
webos.el.dialogCenter(that.$refs["io-drive-select-path"]);
},
topToolAction:function (type){
webos.message.error("请使用右键代替");
},
fileListActionLast:function (){
var that = this
var sz = that.dataPath.split("/");
if(sz.length>1){
sz.length = sz.length - 1;
that.fileListAction(sz.join("/"));
}else{
var path = sz[0];
if(!webos.fileSystem.isSpecialPath(path)){
if(path.startsWith("{io:")){
that.fileListAction("disk");
}else if(path.startsWith("{sio:")){
that.fileListAction("share");
}else if(path.startsWith("{uio:")){
that.fileListAction("thispc");
}
}
}
},
fileListActionCache:function (type){
var that = this;
var oldIndex = that.cacheIndex;
var index = that.cacheIndex + type;
if(index>that.caches.length -1){
index = that.caches.length -1;
}
if(index < 0){
index = 0;
}
if(oldIndex == index){
return;
}
that.cacheIndex = index;
that.fileListAction(that.caches[index],true);
},
fileStarAction:async function (){
var that = this;
var data =await webos.userDrive.starList();
data.push({"name":"我的共享","path":"share","type":"share"});
data.push({"name":"回收站","path":"trash","type":"trash"});
that.starList = data;
},
emitSelectFile:function (){
var that = this;
that.$emit("select-file");
},
fileExplorerLoading:function (flag){
this.loading = flag;
},
fileListAction:async function (path,ignoreCache){
var that = this;
if(that.actionIng){
return
}
if(!path){
path = "thispc";
}
if(path !="/" && path.endsWith("/")){
path = path.substring(0,path.length-1);
}
that.dataPath = path;
that.contentFiles = [];
if(!that.caches){
that.caches = [path];
that.cacheIndex = 0;
};
if(!ignoreCache){
//需要操作缓存
if(that.caches[that.caches.length-1] != path){
that.caches.push(path);
};
that.cacheIndex = that.caches.length-1;
};
that.actionIng = true;
that.loading = true;
let hasExpData = false;
var data = await webos.fileSystem.getFileListByParentPath(path,function (fileList,expData){
that.loading = false;
if(!hasExpData){
hasExpData = true;
that.pathData = expData.pathData;
that.title = expData.title;
}
if(path == "thispc"){
fileList.forEach(function (item){
item.thumbnail = "modules/win11/imgs/"+(item.isSystem===1?"disc-sm.png":"disk-sm.png");
});
}else if(path == "disk"){
fileList.forEach(function (item){
item.thumbnail = "imgs/"+item.driveType+".png";
if(item.driveType == "local"){
item.thumbnail = "modules/win11/imgs/disk-sm.png";
}
});
}else{
fileList.forEach(function (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";
}
}
});
};
that.contentFiles = that.contentFiles.concat(fileList);
});
if(!data){
that.actionIng = false;
return;
};
var config = webos.context.get("rightMenuConfig");
if(config){
if(config.largeIcon){
that.iconWidth = 54;
}else if(config.mediumIcon){
that.iconWidth = 43;
}else if(config.smallIcon){
that.iconWidth = 36;
}
}
if(config && that.contentFiles.length>0){
that.contentFiles.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);
}
});
}
let win = webos.el.findParentComponent(that,"window-component");
let propsWin = win.$props.win;
propsWin.data.name = that.title;
propsWin.data.icon = "modules/win11/imgs/" + (path == "thispc"?"thispc.png":"folder-sm.png");
that.actionIng = false;
},
fileTreeAction:function (node){
if(!node){
this.fileTree = Vue.reactive({
path:"thispc",
name:"此电脑",
icon:"modules/win11/imgs/thispc.png",
starZk:false
});
}
},
fileViewInWinMouseDbl:function (file,e){
var that = this;
if(e.button != 0){
return;
}
if(that.lastClickObj && that.lastClickObj.dataFile == file && Date.now() - that.lastClickObj.time <= 400){
if(file.path.startsWith("{trash:")){
webos.message.error("请恢复后再进行访问");
return;
}
if(file.type == 2){
that.fileListAction(file.path);
}else{
var desktop = webos.el.findParentComponent(that,"desktop-component");
desktop.openFile(file.path,file.type,file.name,file.thumbnail,"edit,open");
}
};
that.lastClickObj = {
dataFile:file,
time:Date.now()
}
},
refreshFileList:function (path){
if(this.dataPath == path){
this.fileListAction(path);
}
},
clearSelectMap:function (){
this.selectMap = {};
},
toEditIoDrive:async function (id){
var that = this;
if(that.driveTypeList.length < 1){
that.driveTypeList = await webos.dict.select("IO_DRIVE_TYPE");
}
if(!id){
//新增
that.ioDriveEdit.title = "添加磁盘";
that.ioDriveEdit.data = {}
}else{
//修改
that.ioDriveEdit.title = "编辑磁盘";
that.ioDriveEdit.data = await webos.drive.info(id);
}
that.ioDriveEdit.show = true;
webos.el.dialogCenter(that.$refs["io-drive-edit"]);
},
toRemoveIoDrive:function (item){
const that = this;
utils.$.confirm("确认移除'"+item.filterName+"'存储吗?",function (flag){
if(!flag){
return;
};
utils.$.confirm("再次确认移除'"+item.filterName+"'存储吗?移除后该盘下的用户数据将无法访问!",async function (flag2){
if(!flag2){
return;
};
webos.context.set("showOkErrMsg", true);
flag = await webos.drive.dels([item.id]);
if(flag){
that.fileListAction(that.dataPath);
}
});
});
},
toEditShareData:function (id){
var that = this;
var desktop = webos.el.findParentComponent(that,"desktop-component");
desktop.toEditShareData(id);
},
toRemoveShareData:function (item){
const that = this;
utils.$.confirm("确认取消'"+item.filterName+"'共享吗?取消后该分享数据将无法访问!",async function (flag){
if(!flag){
return;
};
webos.context.set("showOkErrMsg", true);
flag = await webos.shareFile.dels([item.id]);
if(flag){
await that.fileListAction(that.dataPath);
}
});
},
configDialogRefresh:function (){
var that = this;
var tmpUrl = that.configDialog.url;
that.configDialog.url = "";
setTimeout(function (){
that.configDialog.url = tmpUrl;
},300);
},
toGetToken:function (){
const that = this;
const driveType = that.ioDriveEdit.data.driveType;
const onTokenOrCookie = function (tokenId){
that.ioDriveEdit.data.tokenId = tokenId;
that.configDialog.url = "";
that.configDialog.show = false;
}
const defaultFunc = function (){
webos.drive.defaultEventAction = function (e){
var data = e.data;
if(data.type == "cookie"){
onTokenOrCookie(data.data);
};
}
if(webos.drive.initDefaultEvent){
return;
}
if(!webos.drive.initDefaultEvent){
webos.drive.initDefaultEvent = true;
window.addEventListener("message",function (e){
webos.drive.defaultEventAction(e);
});
}
}
const typeMap = {
pan123:false,
local:false,
aliyundrive:{
title:"阿里云盘-登录",
url:"https://passport.aliyundrive.com/mini_login.htm?lang=zh_cn&appName=aliyun_drive&appEntrance=web&styleType=auto&bizParams=¬LoadSsoView=false¬KeepLogin=false&isMobile=false&ad__pass__q__rememberLogin=false&ad__pass__q__forgotPassword=true&ad__pass__q__licenseMargin=true&ad__pass__q__loginType=normal&hidePhoneCode=true",
func:function (){
webos.drive.aliyunEvent(function (res){
if(res.type == "token"){
//获取token
var data = res.data;
onTokenOrCookie(data.refreshToken);
}
});
}
},
pan189:{
title:"天翼云盘-登录",
url:"common/pan189_web/login.html",
func:defaultFunc
},
kodbox:{
title:"可道云-登录",
url:"common/kodbox_web/login.html",
func:defaultFunc
},
}
if(!typeMap[driveType]){
webos.message.error("当前不支持使用窗口获取token");
return;
};
const typeData = typeMap[driveType];
//登录页
that.configDialog.title = typeData.title;
that.configDialog.url = typeData.url;
that.configDialog.width = 388;
that.configDialog.height = 343;
that.configDialog.show = true;
typeData.func();
webos.el.dialogCenter(that.$refs["iframe-dialog"]);
},
saveIoDrive:async function (){
var that = this;
var flag;
webos.context.set("showOkErrMsg", true);
if(that.ioDriveEdit.data.id){
//编辑
flag = await webos.drive.update(that.ioDriveEdit.data);
}else{
//新增
flag = await webos.drive.save(that.ioDriveEdit.data);
}
if(flag){
that.ioDriveEdit.show = false;
that.fileListAction("disk");
}
},
moreSelectStart:function (e){
var desktop = webos.el.findParentComponent(this,"desktop-component");
desktop.moreSelectStart(e,"fileExplorer",this);
},
toRename:async function(file,item){
var that = this;
if(item){
//需要将此文件插入末尾
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";
}
}
that.contentFiles.push(item);
}
file.newName = file.name;
that.rename = file;
that.renameStatus(true);
utils.delayAction(function (){
return that.$refs && that.$refs["rename-ta"] && (that.$refs["rename-ta"]).length>0;
},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);
await that.fileListAction(that.dataPath);
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.fileListAction(that.dataPath);
});
}else{
webos.context.set("showOkErrMsg", true);
await webos.fileSystem.rename({path:file.path,name:text,type:file.type});
that.renameStatus(false);
await that.fileListAction(that.dataPath);
}
},
renameStatus:function (flag){
var that = this;
if(!flag){
that.rename.newName = "";
that.rename.name = "";
}
},
},
created:async function () {
this.fileListAction(this.win.data.path,true);
var hasLogin = await webos.user.hasLogin();
if(hasLogin){
await this.fileStarAction();
this.fileTreeAction();
}else {
this.hasLogin = false;
}
if(this.hasLogin){
var info = await webos.user.info();
if(info){
this.isMain = info.userType == 1;
}
}
}
}