Commit d1d2f989 authored by David黄金龙's avatar David黄金龙

Merge branch 'develop' of http://gitlab.galaxy-immi.com/mobile-group/galaxy-iOS into develop

* 'develop' of http://gitlab.galaxy-immi.com/mobile-group/galaxy-iOS:
  // 我的证书
  上传文件
parents 8f6932b1 9a2b6f58
......@@ -72,4 +72,26 @@ class YHBaseViewModel {
callBackBlock(nil,err)
}
}
// 上传方法
func uploadFile(_ url: String, callBackBlock:@escaping (_ success: String?, _ error:YHErrorModel?)->()) {
let strUrl = YHBaseUrlManager.shared.curOssURL() + YHAllApiName.OSS.uploadApi
printLog("\(url)")
let boundary = UUID().uuidString
let headers: HTTPHeaders = [
"Content-type": "multipart/form-data; boundary=\(boundary)",
"businessCode": "4001001"
]
let _ = YHNetRequest.uplaodFileRequest(url: strUrl, headers: headers, fileUrl: url) { [weak self] json, code in
guard let self = self else { return }
if json.code == 200 {
callBackBlock(json.data as? String, nil)
} else {
let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code), errorMsg: json.msg)
callBackBlock(nil, error)
}
} failBlock: { err in
callBackBlock(nil, err)
}
}
}
......@@ -205,6 +205,9 @@ extension YHCertificateResourceUploadVC {
}
items.append(contentsOf: results)
}
// 数量统计
NotificationCenter.default.post(name: countStatisticsNotify, object: [self.status: items.count])
emptyDataTipsView.isHidden = items.count > 0
self.tableView.reloadData()
......
......@@ -9,6 +9,9 @@
import UIKit
import JXSegmentedView
// 统计数量
public let countStatisticsNotify = NSNotification.Name("didCertificateCountStatistics")
class YHCertificateCategoryItem {
var type : YHCertificateUploadStatus = .all
var title : String {
......@@ -57,7 +60,7 @@ class YHMaterialListViewController: YHBaseViewController {
return bar
}()
var titles = ["全部".local, "待上传".local, "已驳回".local, "审核中".local, "已通过".local]
var titles = ["全部(0)", "待上传(0)", "已驳回(0)", "审核中(0)", "已通过(0)"]
let categoryItems = [ YHCertificateCategoryItem(type: .all),
YHCertificateCategoryItem(type: .preUpload),
YHCertificateCategoryItem(type: .rejected),
......@@ -79,14 +82,14 @@ class YHMaterialListViewController: YHBaseViewController {
return segview
}()
lazy var segmentedDataSource: JXSegmentedBaseDataSource = {
lazy var segmentedDataSource: JXSegmentedTitleDataSource = {
let dataSource = JXSegmentedTitleDataSource()
dataSource.isTitleColorGradientEnabled = true
dataSource.titles = titles
dataSource.titleNormalFont = UIFont.PFSC_R(ofSize: 14)
dataSource.titleNormalColor = .labelTextColor2
dataSource.titleSelectedFont = UIFont.PFSC_M(ofSize: 16)
dataSource.titleSelectedColor = .brandMainColor
dataSource.titleSelectedColor = UIColor(hexString: "#000000")
dataSource.isItemSpacingAverageEnabled = false
dataSource.itemWidth = JXSegmentedViewAutomaticDimension
dataSource.itemSpacing = 24
......@@ -125,13 +128,14 @@ class YHMaterialListViewController: YHBaseViewController {
super.viewDidLoad()
self.gk_navigationBar.isHidden = true
titles.removeAll()
NotificationCenter.default.addObserver(self, selector: #selector(didCertificateCountStatistics(_:)), name:countStatisticsNotify , object: nil)
for item in categoryItems {
titles.append(item.title)
let vc = YHCertificateResourceUploadVC()
vc.orderId = orderId
vc.status = item.type
vc.categoryInfo = categoryInfo
vc.requestList(status: item.type)
itemVCs.append(vc)
}
view.addSubview(navBar)
......@@ -174,6 +178,35 @@ class YHMaterialListViewController: YHBaseViewController {
//离开页面的时候,需要恢复屏幕边缘手势,不能影响其他页面
navigationController?.interactivePopGestureRecognizer?.isEnabled = true
}
@objc func didCertificateCountStatistics(_ notification: Notification) {
guard let dic = notification.object as? [YHCertificateUploadStatus: Int] else { return }
print(dic)
if let count = dic[YHCertificateUploadStatus.all] {
titles[0] = "全部(\(count))"
} else if let count = dic[YHCertificateUploadStatus.preUpload] {
titles[1] = "待上传(\(count))"
} else if let count = dic[YHCertificateUploadStatus.rejected] {
titles[2] = "已驳回(\(count))"
} else if let count = dic[YHCertificateUploadStatus.review] {
titles[3] = "审核中(\(count))"
} else if let count = dic[YHCertificateUploadStatus.finish] {
titles[4] = "已通过(\(count))"
}
DispatchQueue.main.async {
self.segmentedDataSource.titles = self.titles
self.segmentedView.reloadData()
}
}
deinit {
NotificationCenter.default.removeObserver(self)
}
}
......
......@@ -102,6 +102,10 @@ class YHUploadContentVC: YHBaseViewController {
// 将文件数据上传到服务器
let size = String(format: "%.2fM", Double(fileData.count)/(1024.0 * 1024.0))
print("\(size)")
self.viewModel.uploadFile(fileUrl.absoluteString) {[weak self] success, error in
guard let self = self else { return }
}
}
}
sheetView.uploadImageBlock = {
......@@ -179,10 +183,16 @@ extension YHUploadContentVC: UITableViewDelegate, UITableViewDataSource {
[weak self] contentItem in
guard let self = self else { return }
selectEditItem = contentItem
let items = [YHCertificateEditItem(type:.rename, title:"重命名"),
var items = [YHCertificateEditItem(type:.rename, title:"重命名"),
YHCertificateEditItem(type:.preview, title:"预览"),
YHCertificateEditItem(type:.delete, title:"删除"),
YHCertificateEditItem(type:.cancel, title:"取消")]
if uploadInfo.checkStatus == YHCertificateUploadStatus.finish.rawValue {
items = [YHCertificateEditItem(type:.preview, title:"预览"),
YHCertificateEditItem(type:.cancel, title:"取消")]
}
YHCertificateEditSheetView.sheetView(items:items) {
[weak self] editType in
guard let self = self else { return }
......@@ -194,7 +204,12 @@ extension YHUploadContentVC: UITableViewDelegate, UITableViewDataSource {
renameInputView.textField.becomeFirstResponder()
} else if editType == .delete { // 删除
let msg = "您确定要删除文档\(contentItem.name)吗"
YHTwoOptionAlertView.showAlertView(message:msg) { sure in
if !sure { return }
self.updateCertificateItem(contentItem, operation: "del", rename: "")
}
} else if editType == .preview { // 预览
// 预览 contentItem
......@@ -238,13 +253,37 @@ extension YHUploadContentVC: UITableViewDelegate, UITableViewDataSource {
view.addSubview(titlelabel)
let statusLabel = UILabel()
statusLabel.textColor = .warnColor
statusLabel.backgroundColor = .warnColor8
statusLabel.textAlignment = .center
statusLabel.font = UIFont.PFSC_M(ofSize:10)
statusLabel.text = uploadInfo.getStatusName()
statusLabel.layer.cornerRadius = 3.0
view.addSubview(statusLabel)
var text = ""
var textColor:UIColor = .clear
var bgColor:UIColor = .clear
if uploadInfo.checkStatus == YHCertificateUploadStatus.review.rawValue {
text = "审核中".local
textColor = UIColor(hexString: "#FF9900")
bgColor = UIColor(hexString: "#FF9900", 0.08)
} else if uploadInfo.checkStatus == YHCertificateUploadStatus.preUpload.rawValue {
text = "待上传".local
textColor = UIColor(hexString: "#2F7EF6")
bgColor = UIColor(hexString: "#2F7EF6", 0.08)
} else if uploadInfo.checkStatus == YHCertificateUploadStatus.finish.rawValue {
text = "已通过".local
textColor = UIColor(hexString: "#49D2B1")
bgColor = UIColor(hexString: "#49D2B1", 0.08)
} else if uploadInfo.checkStatus == YHCertificateUploadStatus.rejected.rawValue {
text = "已驳回".local
textColor = UIColor(hexString: "#F81D22")
bgColor = UIColor(hexString: "#F81D22", 0.08)
}
statusLabel.text = text
statusLabel.textColor = textColor
statusLabel.backgroundColor = bgColor
let tipsLabel = UILabel()
tipsLabel.textColor = .warnColor
tipsLabel.font = UIFont.PFSC_R(ofSize:12)
......@@ -293,7 +332,7 @@ extension YHUploadContentVC: UITableViewDelegate, UITableViewDataSource {
label.textColor = UIColor.labelTextColor2
label.textAlignment = .center
label.font = UIFont.PFSC_R(ofSize:12)
label.text = "*最多上传5/99张图片或文件"
label.text = "*最多上传\(items.count)/99张图片或文件"
view.addSubview(label)
return view
......@@ -312,8 +351,8 @@ extension YHUploadContentVC {
func addKeyBoardNotify() {
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification), name: UIResponder.keyboardWillHideNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
}
func removeNotify() {
......
......@@ -9,7 +9,7 @@ import Foundation
import Alamofire
import CryptoSwift
import UIKit
import CoreServices
//class YHNetErrorModel {
// var responseStatusCode: Int = 0
// var responseStatusCodeStr: String = ""
......@@ -198,6 +198,52 @@ class YHNetRequest: NSObject {
return uploadRequest
}
func uploadFileRequest(_ headers: HTTPHeaders, _ url: String) -> Request? {
guard YHNetworkStatusManager.shared.isNetWorkOK == true else {
YHHUD.flash(message: "网络异常")
return httpRequest
}
guard let fileData = try? Data(contentsOf: URL(string: url) ?? URL(fileURLWithPath: "")) else {
return httpRequest
}
let fileExtension = URL(fileURLWithPath: url).pathExtension.lowercased()
let fileUTI = mimeType(for: url)
#if DEBUG
printLog("\(fileExtension)-------\(fileUTI ?? "")")
#endif
let multipartFormData = MultipartFormData()
// 将图片添加到multipartFormData中
multipartFormData.append(fileData, withName: "file", fileName: "image.\(fileExtension)", mimeType: fileUTI)
// 发送POST请求
let uploadRequest = AF.upload(multipartFormData: multipartFormData, to: self.url!, headers: headers)
uploadRequest.responseString(completionHandler: { string in
#if DEBUG
printLog("\n网络请求已返回 string=\(string)")
#endif
self.completeHandle(string: string)
})
return uploadRequest
}
func mimeType(for path: String) -> String? {
let url = URL(fileURLWithPath: path)
let pathExtension = url.pathExtension
if let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension as CFString, nil)?.takeRetainedValue() {
if let mimeType = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)?.takeRetainedValue() {
return mimeType as String
}
}
return nil
}
/// 请求response完成处理
func completeHandle(string: AFDataResponse<String>) {
let responseResult = string.result
......@@ -267,4 +313,9 @@ extension YHNetRequest {
printLog("\n发起请求的URL是===> url = \(url)")
return YHNetRequest().url(url).success(successBlock).failed(failBlock).uploadRequest(headers, image)
}
class func uplaodFileRequest(url:String, headers:HTTPHeaders, fileUrl: String, successBlock: SuccessResultType!, failBlock: FailureHandlerType!) -> Request? {
printLog("\n发起请求的URL是===> url = \(url)")
return YHNetRequest().url(url).success(successBlock).failed(failBlock).uploadFileRequest(headers, fileUrl)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment