Commit 54875a1f authored by Steven杜宇's avatar Steven杜宇

// 二维码联调接口

parent 68f8f37f
...@@ -452,7 +452,8 @@ class YHHomeWebViewController: YHBaseViewController, WKUIDelegate, WKNavigationD ...@@ -452,7 +452,8 @@ class YHHomeWebViewController: YHBaseViewController, WKUIDelegate, WKNavigationD
} }
@objc func didConsultViewTapped() { @objc func didConsultViewTapped() {
YHConsultantQRCodeView.codeView().show() let codeUrl = self.viewModel.mainModel?.clue_classify_img_url ?? ""
YHConsultantQRCodeView.codeView(codeUrl).show()
} }
@objc func loginSuccess() { @objc func loginSuccess() {
......
...@@ -18,4 +18,5 @@ class YHWebModel: YHBaseModel { ...@@ -18,4 +18,5 @@ class YHWebModel: YHBaseModel {
var media_url: String = "" var media_url: String = ""
var title: String = "" var title: String = ""
var img_url: String = "" var img_url: String = ""
var clue_classify_img_url = ""
} }
...@@ -7,9 +7,30 @@ ...@@ -7,9 +7,30 @@
// //
import UIKit import UIKit
import Photos
class YHConsultantQRCodeView: UIView { class YHConsultantQRCodeView: UIView {
var codeUrl:String = "" {
didSet {
if !codeUrl.isEmpty {
self.qrCodeImgView.kf.setImage(with: URL(string: codeUrl), placeholder: UIImage(named: "global_default_image")) { result in
switch result {
case .success(let value):
self.codeImage = value.image
self.saveBtn.alpha = 1.0
self.saveBtn.isUserInteractionEnabled = true
case .failure(let value):
self.saveBtn.alpha = 0.3
self.saveBtn.isUserInteractionEnabled = false
}
}
}
}
}
var codeImage:UIImage? = nil
// 底层蒙版 // 底层蒙版
lazy var blackMaskView: UIView = { lazy var blackMaskView: UIView = {
let view = UIView() let view = UIView()
...@@ -42,7 +63,7 @@ class YHConsultantQRCodeView: UIView { ...@@ -42,7 +63,7 @@ class YHConsultantQRCodeView: UIView {
}() }()
lazy var qrCodeImgView:UIImageView = { lazy var qrCodeImgView:UIImageView = {
let view = UIImageView(image: UIImage(named: "")) let view = UIImageView(image: UIImage(named: "global_default_image"))
view.backgroundColor = .red view.backgroundColor = .red
return view return view
}() }()
...@@ -55,6 +76,8 @@ class YHConsultantQRCodeView: UIView { ...@@ -55,6 +76,8 @@ class YHConsultantQRCodeView: UIView {
button.backgroundColor = UIColor.brandMainColor button.backgroundColor = UIColor.brandMainColor
button.addTarget(self, action: #selector(didSaveQRCodeBtnClicked), for: .touchUpInside) button.addTarget(self, action: #selector(didSaveQRCodeBtnClicked), for: .touchUpInside)
button.layer.cornerRadius = 3 button.layer.cornerRadius = 3
button.alpha = 0.3
button.isUserInteractionEnabled = false
return button return button
}() }()
...@@ -74,8 +97,9 @@ class YHConsultantQRCodeView: UIView { ...@@ -74,8 +97,9 @@ class YHConsultantQRCodeView: UIView {
createUI() createUI()
} }
static func codeView() -> YHConsultantQRCodeView { static func codeView(_ url:String) -> YHConsultantQRCodeView {
let alertView = YHConsultantQRCodeView(frame:UIScreen.main.bounds) let alertView = YHConsultantQRCodeView(frame:UIScreen.main.bounds)
alertView.codeUrl = url
return alertView return alertView
} }
...@@ -140,10 +164,34 @@ class YHConsultantQRCodeView: UIView { ...@@ -140,10 +164,34 @@ class YHConsultantQRCodeView: UIView {
} }
@objc func didSaveQRCodeBtnClicked() { @objc func didSaveQRCodeBtnClicked() {
if let img = self.codeImage {
self.saveImage(img)
}
} }
@objc func didCloseBtnClicked() { @objc func didCloseBtnClicked() {
self.dismiss() self.dismiss()
} }
func saveImage(_ image: UIImage) {
// 确保应用有权访问相册
PHPhotoLibrary.requestAuthorization { status in
if status == .authorized {
// 保存图片到相册
DispatchQueue.main.sync {
UIImageWriteToSavedPhotosAlbum(image, self, #selector(self.image(image:didFinishSavingWithError:contextInfo:)), nil)
}
} else {
YHHUD.flash(message: "没有访问图库权限")
}
}
}
@objc func image(image: UIImage,didFinishSavingWithError: NSError?,contextInfo: AnyObject) {
if didFinishSavingWithError != nil {
YHHUD.flash(message: "保存失败")
return
}
YHHUD.flash(message: "保存成功")
}
} }
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