Commit f05a4f4b authored by Steven杜宇's avatar Steven杜宇

// 文件和图片选择

parent b2484d4f
...@@ -302,7 +302,7 @@ extension YHPrincipleUploadListVC { ...@@ -302,7 +302,7 @@ extension YHPrincipleUploadListVC {
func showUploadSheetView(supplementId: Int, completion:(()->())?) { func showUploadSheetView(supplementId: Int, completion:(()->())?) {
let sheetView = YHCertificateUploadSheetView.sheetView() let sheetView = YHCertificateUploadSheetView.sheetView()
sheetView.maxSelectCount = 9 sheetView.maxSelectImageCount = 9
sheetView.uploadImageBlock = { sheetView.uploadImageBlock = {
[weak self] targetImgArr in [weak self] targetImgArr in
guard let self = self else { return } guard let self = self else { return }
...@@ -380,18 +380,7 @@ extension YHPrincipleUploadListVC: UITableViewDelegate, UITableViewDataSource { ...@@ -380,18 +380,7 @@ extension YHPrincipleUploadListVC: UITableViewDelegate, UITableViewDataSource {
cell.uploadBtnClick = { cell.uploadBtnClick = {
[weak self] selectModel in [weak self] selectModel in
guard let self = self else { return } guard let self = self else { return }
YHImagePickerView.show() {[weak self] image in self.showSelectImageAndFileView(model)
guard let self = self else { return }
let item = YHSelectImageItem()
item.name = self.randomAlphaNumericString(10) + ".png"
item.data = image
let arr = [item]
self.viewModel.uploadImageArr(arr) {
resultArr in
model.content_url.append(contentsOf: resultArr)
self.tableView.reloadData()
}
}
} }
// 点击模版 // 点击模版
cell.templateBtnClick = { cell.templateBtnClick = {
...@@ -512,4 +501,61 @@ extension YHPrincipleUploadListVC: UITableViewDelegate, UITableViewDataSource { ...@@ -512,4 +501,61 @@ extension YHPrincipleUploadListVC: UITableViewDelegate, UITableViewDataSource {
} }
}.show() }.show()
} }
func showSelectImageAndFileView(_ model: YHPrincipleAgreementModel) {
let sheetView = YHCertificateUploadSheetView.sheetView()
sheetView.maxSelectImageCount = 9
sheetView.fileTypes = [ "public.image",
"com.adobe.pdf",
"com.microsoft.word.doc",
"org.openxmlformats.wordprocessingml.document",
"com.microsoft.powerpoint.ppt",
"org.openxmlformats.presentationml.presentation",
"org.openxmlformats.spreadsheetml.sheet",
"com.microsoft.excel.xls",]
// 上传文件
sheetView.uploadFilesBlock = {
[weak self] fileUrl in
guard let self = self else { return }
print(fileUrl)
YHHUD.show(.progress(message: "上传中..."))
self.viewModel.uploadFile(fileUrl.absoluteString) {
[weak self] successUrl, error in
YHHUD.hide()
guard let self = self else { return }
// 再调用业务接口
if let successUrl = successUrl, !successUrl.isEmpty {
let fileName = successUrl.lastPathComponent
let suffixName = successUrl.pathExtension.lowercased()
let urlModel = YHPrincipleContentUrlModel()
urlModel.name = fileName
urlModel.url = successUrl
urlModel.fileUrl = successUrl
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "YYYY:MM:dd"
let dateString = dateFormatter.string(from: Date())
urlModel.updated_at = dateString
model.content_url.insert(urlModel, at: 0)
self.tableView.reloadData()
}
}
}
// 上传图片
sheetView.uploadImageBlock = {
[weak self] targetImgArr in
guard let self = self else { return }
self.viewModel.uploadImageArr(targetImgArr) {
[weak self] resultArr in
guard let self = self else { return }
model.content_url.insert(contentsOf: resultArr, at: 0)
self.tableView.reloadData()
}
}
sheetView.show()
}
} }
...@@ -358,50 +358,4 @@ extension YHPrincleViewModel { ...@@ -358,50 +358,4 @@ extension YHPrincleViewModel {
} }
} }
} }
// func getEnvelopModel() -> YHPrincipleEnvelopeModel {
// let model = YHPrincipleEnvelopeModel()
// model.name = "黄金龙"
// model.sex = 1
// model.date = "2024-12-12"
// return model
// }
//
// func getTestModel() -> YHPrincipleWaitResultModel {
//
// var files: [YHFileNumberList] = []
// let m = YHFileNumberList()
// m.applicationName = "杜宇"
// m.fileNumber = "23412-AVAVS-SADFAS"
// let m2 = YHFileNumberList()
// m2.applicationName = "宇"
// m2.fileNumber = "23412-AVAVS-SADFAS"
// files.append(m)
// files.append(m2)
//
// var imgs: [YHResultImageList] = []
// let n = YHResultImageList()
// n.applicationName = "嘟嘟"
// let n1 = YHResultImageList()
// n1.applicationName = "嘟嘟"
// let n2 = YHResultImageList()
// n2.applicationName = "嘟嘟"
// imgs.append(n)
// imgs.append(n1)
// imgs.append(n2)
//
// let applicant = YHApplicant()
// applicant.userName = "哈哈哈"
//
// let model = YHPrincipleWaitResultModel(lastQueryAt: "2024-12-01 23:34:12",
// queryCount: 40,
// fileNumberList: files,
// resultImageList: imgs,
// applicant: applicant,
// applicationFileNumberAttachment: "你要死啊")
// return model
// }
//
} }
...@@ -146,7 +146,7 @@ class YHCertificateUploadContentListVC: YHBaseViewController { ...@@ -146,7 +146,7 @@ class YHCertificateUploadContentListVC: YHBaseViewController {
} }
let sheetView = YHCertificateUploadSheetView.sheetView() let sheetView = YHCertificateUploadSheetView.sheetView()
sheetView.maxSelectCount = 99-items.count sheetView.maxSelectImageCount = 99-items.count
sheetView.uploadFilesBlock = { sheetView.uploadFilesBlock = {
[weak self] fileUrl in [weak self] fileUrl in
guard let self = self else { return } guard let self = self else { return }
......
...@@ -42,16 +42,16 @@ enum YHCertificateUploadType: Int { ...@@ -42,16 +42,16 @@ enum YHCertificateUploadType: Int {
class YHCertificateUploadSheetView: UIView { class YHCertificateUploadSheetView: UIView {
private var _maxSelectCount: Int = 9 private var _maxSelectImageCount: Int = 9
let tips = "支持的文件格式为jpg/jpeg、png、doc/docx、pptx、pdf,最多可上传99张图片或文件" var tips = "支持的文件格式为jpg/jpeg、png、doc/docx、pptx、pdf,最多可上传99张图片或文件"
var maxSelectCount = 9 { var maxSelectImageCount = 9 {
didSet { didSet {
if maxSelectCount >= 9 { if maxSelectImageCount >= 9 {
_maxSelectCount = 9 _maxSelectImageCount = 9
} else if 0 < maxSelectCount && maxSelectCount < 9 { } else if 0 < maxSelectImageCount && maxSelectImageCount < 9 {
_maxSelectCount = maxSelectCount _maxSelectImageCount = maxSelectImageCount
} else { } else {
_maxSelectCount = 0 _maxSelectImageCount = 0
} }
} }
} }
...@@ -145,28 +145,28 @@ class YHCertificateUploadSheetView: UIView { ...@@ -145,28 +145,28 @@ class YHCertificateUploadSheetView: UIView {
return tableView return tableView
}() }()
lazy var documentPickerVC: UIDocumentPickerViewController = { var fileTypes: [String] = [ "public.image",
let docTypes = [ "public.image",
"com.adobe.pdf", "com.adobe.pdf",
"com.microsoft.word.doc", "com.microsoft.word.doc",
"org.openxmlformats.wordprocessingml.document", "org.openxmlformats.wordprocessingml.document",
"com.microsoft.powerpoint.ppt", "com.microsoft.powerpoint.ppt",
"org.openxmlformats.presentationml.presentation",] "org.openxmlformats.presentationml.presentation",
]
lazy var documentPickerVC: UIDocumentPickerViewController = {
if #available(iOS 14.0, *) { if #available(iOS 14.0, *) {
var arr:[UTType] = [] var arr:[UTType] = []
for docStr in docTypes { for fileType in self.fileTypes {
if let type = UTType(docStr) { if let type = UTType(fileType) {
arr.append(type) arr.append(type)
} }
} }
let docPickerVC = UIDocumentPickerViewController(forOpeningContentTypes: arr) let docPickerVC = UIDocumentPickerViewController(forOpeningContentTypes: arr)
docPickerVC.delegate = self docPickerVC.delegate = self
return docPickerVC return docPickerVC
} }
let docPickerVC = UIDocumentPickerViewController(documentTypes: docTypes, in: .open) let docPickerVC = UIDocumentPickerViewController(documentTypes: self.fileTypes, in: .open)
docPickerVC.delegate = self docPickerVC.delegate = self
return docPickerVC return docPickerVC
}() }()
...@@ -407,7 +407,7 @@ extension YHCertificateUploadSheetView: (UIImagePickerControllerDelegate & UINav ...@@ -407,7 +407,7 @@ extension YHCertificateUploadSheetView: (UIImagePickerControllerDelegate & UINav
var configuration = PHPickerConfiguration() var configuration = PHPickerConfiguration()
// 设置最大选择数量 // 设置最大选择数量
configuration.selectionLimit = _maxSelectCount configuration.selectionLimit = _maxSelectImageCount
// 设置选择器的过滤条件 只显示图片 // 设置选择器的过滤条件 只显示图片
configuration.filter = .images configuration.filter = .images
let picker = PHPickerViewController(configuration: configuration) let picker = PHPickerViewController(configuration: configuration)
......
...@@ -226,7 +226,7 @@ extension YHCertificateViewModel { ...@@ -226,7 +226,7 @@ extension YHCertificateViewModel {
func showUploadSheetView(supplementId: Int, completion:(()->())?) { func showUploadSheetView(supplementId: Int, completion:(()->())?) {
let sheetView = YHCertificateUploadSheetView.sheetView() let sheetView = YHCertificateUploadSheetView.sheetView()
sheetView.maxSelectCount = 9 sheetView.maxSelectImageCount = 9
sheetView.uploadFilesBlock = { sheetView.uploadFilesBlock = {
[weak self] fileUrl in [weak self] fileUrl in
guard let self = self else { return } guard let self = self else { return }
......
...@@ -571,7 +571,7 @@ extension YHWorkExperienceViewController: UITableViewDelegate, UITableViewDataSo ...@@ -571,7 +571,7 @@ extension YHWorkExperienceViewController: UITableViewDelegate, UITableViewDataSo
maxCount = 9 maxCount = 9
} }
let sheetView = YHCertificateUploadSheetView.sheetView() let sheetView = YHCertificateUploadSheetView.sheetView()
sheetView.maxSelectCount = maxCount sheetView.maxSelectImageCount = maxCount
sheetView.uploadFilesBlock = { sheetView.uploadFilesBlock = {
[weak self] fileUrl in [weak self] fileUrl in
guard let self = self else { return } guard let self = self else { return }
...@@ -703,7 +703,7 @@ extension YHWorkExperienceViewController: UITableViewDelegate, UITableViewDataSo ...@@ -703,7 +703,7 @@ extension YHWorkExperienceViewController: UITableViewDelegate, UITableViewDataSo
maxCount = 9 maxCount = 9
} }
let sheetView = YHCertificateUploadSheetView.sheetView() let sheetView = YHCertificateUploadSheetView.sheetView()
sheetView.maxSelectCount = maxCount sheetView.maxSelectImageCount = maxCount
sheetView.uploadFilesBlock = { sheetView.uploadFilesBlock = {
[weak self] fileUrl in [weak self] fileUrl in
guard let self = self else { return } guard let self = self else { return }
......
...@@ -56,6 +56,17 @@ ...@@ -56,6 +56,17 @@
<string>com.microsoft.powerpoint.ppt</string> <string>com.microsoft.powerpoint.ppt</string>
</array> </array>
</dict> </dict>
<dict>
<key>CFBundleTypeName</key>
<string>Microsoft Excel Document</string>
<key>LSHandlerRank</key>
<string>Default</string>
<key>LSItemContentTypes</key>
<array>
<string>org.openxmlformats.spreadsheetml.sheet</string>
<string>com.microsoft.excel.xls</string>
</array>
</dict>
</array> </array>
<key>CFBundleURLTypes</key> <key>CFBundleURLTypes</key>
<array> <array>
......
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