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 文件夹管理#