共计 6033 个字符,预计需要花费 16 分钟才能阅读完成。
1. 存储池
在我的页面,若该用户为拥有者,则可呈现存储池入口,拥有者可操作存储池的权限。
文件门路:ThirdParty/StorageManage/StorageManageViewController.swift
列表数据依据服务器获取,顶部数据为 SA 的外接硬盘数据,下局部则为云端创立的存储池数据。
private func reloadData() {let semaphore = DispatchSemaphore(value: 1)
if hardDisks.count == 0 && storagePools.count == 0 {showLoading(.custom(.white_ffffff))
}
DispatchQueue.global().async {semaphore.wait()
/// 获取限度硬盘列表
NetworkManager.shared.hardDiskList {[weak self] response in
guard let self = self else {return}
self.hardDisks = response.list
semaphore.signal()} failureCallback: { code, err in
semaphore.signal()}
/// 挂起工作, 期待硬盘列表后果
semaphore.wait()
/// 获取存储池列表
/// 传 0 间接获取全副数据 不分页
NetworkManager.shared.storagePoolList(page: 0, pageSize: 0) {[weak self] response in
guard let self = self else {return}
self.storagePools = response.list
semaphore.signal()} failureCallback: { code, err in
semaphore.signal()}
/// 挂起工作, 期待存储池列表后果
semaphore.wait()
DispatchQueue.main.async {self.collectionView.mj_header?.endRefreshing()
self.collectionView.reloadData()
self.hideLoading()
semaphore.signal()}
}
}
1.1 增加存储池
文件门路:ThirdParty/StorageManage/AddToStoragePoolViewController.swift
/// 增加到新存储池
private func tapAddStorage() {print("点击增加到新的存储池")
newStoragePoolAlert = SetNameAlertView(setNameType: .createStoragePool, currentName: "")
newStoragePoolAlert?.setNameCallback = {[weak self] name in
guard let self = self else {return}
if name.isEmpty {SceneDelegate.shared.window?.makeToast("请输出名称".localizedString)
return
}
if self.storagePools.map(\.name).contains(name) {SceneDelegate.shared.window?.makeToast("存储名称不能反复".localizedString)
return
}
/// 申请增加存储池接口
LoadingView.show()
NetworkManager.shared.addStoragePool(name: name, disk_name: self.disk_name) {[weak self] _ in
guard let self = self else {return}
LoadingView.hide()
SceneDelegate.shared.window?.makeToast("增加胜利")
self.newStoragePoolAlert?.removeFromSuperview()
self.navigationController?.popViewController(animated: true)
} failureCallback: {[weak self] code, err in
guard let self = self else {return}
LoadingView.hide()
if code == 205 { // 磁盘挂载失败
self.newStoragePoolAlert?.removeFromSuperview()
let singleTipsAlert = SingleTipsAlertView(detail: "硬盘 (\(self.disk_name)) 增加到存储池 (\(name)) 失败,请从新增加。", detailColor: .custom(.black_3f4663), sureBtnTitle: "确定")
singleTipsAlert.sureCallback = {[weak self] in
guard let self = self else {return}
singleTipsAlert.removeFromSuperview()
self.navigationController?.popViewController(animated: true)
}
SceneDelegate.shared.window?.addSubview(singleTipsAlert)
} else {SceneDelegate.shared.window?.makeToast(err)
}
}
}
SceneDelegate.shared.window?.addSubview(newStoragePoolAlert!)
}
1.2 删除存储池
private func deletePool(){let tipsAlert = TipsAlertView(title: "删除确认", detail: "确认删除该存储池吗?删除须要一些工夫解决,且删除后,该存储池下的所有分区及其文件夹 / 文件都全副删除", warning: "操作不可撤销,请审慎操作!", sureBtnTitle: "确定删除")
tipsAlert.sureCallback = {[weak self] in
guard let self = self else {return}
tipsAlert.sureBtn.buttonState = .waiting
NetworkManager.shared.deleteStoragePool(name: self.currentStoragePoolName) {[weak self] response in
guard let self = self else {return}
tipsAlert.removeFromSuperview()
// 弹框提醒后盾解决
let singleTipsAlert = SingleTipsAlertView(detail: "正在删除存储池,已为您后盾运行,可返回列表刷新查看。", detailColor: .custom(.black_3f4663), sureBtnTitle: "确定")
singleTipsAlert.sureCallback = {[weak self] in
guard let self = self else {return}
singleTipsAlert.removeFromSuperview()
self.navigationController?.popViewController(animated: true)
}
SceneDelegate.shared.window?.addSubview(singleTipsAlert)
// self.showToast("删除胜利")
// self.navigationController?.popViewController(animated: true)
} failureCallback: {[weak self] code, err in
guard let self = self else {return}
self.showToast(err)
tipsAlert.sureBtn.buttonState = .normal
}
}
SceneDelegate.shared.window?.addSubview(tipsAlert)
}
2. 存储池分区
2.1 增加存储池分区
NetworkManager.shared.addPartition(name: nameTextFiled.text ?? "", capacity: Float(capacity) ?? 0, unit: capacityButton.titleLabel?.text ??"GB", pool_name: currentStoragePoolName) {[weak self] response in
LoadingView.hide()
let singleTipsAlert = SingleTipsAlertView(detail: "正在保留分区信息,预计须要一些工夫解决, 已为您后盾运行, 可返回列表刷新查看", detailColor: .custom(.black_3f4663), sureBtnTitle: "确定")
singleTipsAlert.sureCallback = {[weak self] in
guard let self = self else {return}
singleTipsAlert.removeFromSuperview()
self.navigationController?.popViewController(animated: true)
}
SceneDelegate.shared.window?.addSubview(singleTipsAlert)
} failureCallback: {[weak self] code, err in
LoadingView.hide()
self?.showToast(err)
}
2.2 删除存储池分区
NetworkManager.shared.deletePartition(name: self.currentModel.name, pool_name: self.currentStoragePoolName) {[weak self] response in
guard let self = self else {return}
tipsAlert.sureBtn.buttonState = .normal
tipsAlert.removeFromSuperview()
// 弹框提醒后盾解决
let singleTipsAlert = SingleTipsAlertView(detail: "正在删除分区,已为您后盾运行,可返回 列表刷新查看。", detailColor: .custom(.black_3f4663), sureBtnTitle: "确定")
singleTipsAlert.sureCallback = {[weak self] in
guard let self = self else {return}
singleTipsAlert.removeFromSuperview()
self.navigationController?.popViewController(animated: true)
}
SceneDelegate.shared.window?.addSubview(singleTipsAlert)
} failureCallback: {[weak self] code, err in
guard let self = self else {return}
tipsAlert.sureBtn.buttonState = .normal
self.showToast(err)
}
2.3 编辑存储池分区
judgeInfoChange(editName: nameTextFiled.text ?? "", editCapacity: capacity, unit: capacityButton.titleLabel?.text ??"GB") {[weak self]
capacityChanged, nameChanged, allowCapacity in
guard let self = self else {return}
if allowCapacity == 2 {LoadingView.hide()
self.showToast("分区内存不能缩小")
return
}
if capacityChanged == 0 && nameChanged == 0{LoadingView.hide()
self.showToast("未修改任何内容")
return
}
// 保留编辑内容
NetworkManager.shared.editPartition(name: self.currentModel.name, new_name: self.nameTextFiled.text ?? "", pool_name: self.currentStoragePoolName, capacity: Float(capacity) ?? 0, unit: self.capacityButton.titleLabel?.text ??"GB") {[weak self] response in
LoadingView.hide()
var showText = ""
if nameChanged == 1 && capacityChanged == 0 {// 仅编辑名称
showText = "保留胜利"
}else{showText = "正在保留分区信息,须要一些工夫解决, 已为您后盾运行,可返回列表刷新查看。"}
let singleTipsAlert = SingleTipsAlertView(detail: showText, detailColor: .custom(.black_3f4663), sureBtnTitle: "确定")
singleTipsAlert.sureCallback = {[weak self] in
guard let self = self else {return}
singleTipsAlert.removeFromSuperview()
self.navigationController?.popViewController(animated: true)
}
SceneDelegate.shared.window?.addSubview(singleTipsAlert)
} failureCallback: {[weak self] code, err in
LoadingView.hide()
self?.showToast(err)
}
}
2.8 文件夹治理 #
正文完