Commit 310abcf6 authored by lmj_521aiau@163.com's avatar lmj_521aiau@163.com

Merge branch 'branch_1.0.1' of gitlab.huolea.com:lmi/shorthandmaster into branch_1.0.1

parents ff4cdcd3 3a2189a1
...@@ -11,12 +11,15 @@ import UIKit ...@@ -11,12 +11,15 @@ import UIKit
class SHInputViewModel: NSObject { class SHInputViewModel: NSObject {
// MARK: - property // MARK: - property
/// 标题文字 // /// 标题文字
var title : String = "" // var title : String = ""
/// 内容文字 // /// 内容文字
var content : String = "" // var content : String = ""
/// 图片数组 // /// 图片数组
var imageArray : Array = Array<Any>() // var imageArray : Array = Array<Any>()
// var recordModel : SHRecordModel = SHRecordModel()
...@@ -50,34 +53,79 @@ class SHInputViewModel: NSObject { ...@@ -50,34 +53,79 @@ class SHInputViewModel: NSObject {
return titleAttributes return titleAttributes
} }
// MARK: 获取图片数组 // MARK: 获取textView中的图片, 保存到本地, 并生成数组
class func getImageArrayWithTextView(textView : UITextView) -> Array<Any> class func setUpImageArrayWithTextView(textView: UITextView) -> (imagesPathArray: Array<String>, imagesIndexArray: Array<Int>)
{ {
var imageArray = Array<Any>() /// 图片路径数组
var imagesPathArray = Array<String>()
/// 图片位置数组
var imagesIndexArray = Array<Int>()
// 创建文件夹
/// 文件夹路径
let subFile = Date().format("yyyyMMdd")
let time = Date.init().timeStamp
let filePath = DocumentPath + "/" + subFile + time
do
{
try FileManager.default.createDirectory(atPath: filePath, withIntermediateDirectories: true, attributes: nil)
}
catch let error
{
print(error)
return (imagesPathArray, imagesIndexArray)
}
// 遍历textView文字中的NSTextAttachment
let attributedString = textView.attributedText let attributedString = textView.attributedText
attributedString?.enumerateAttribute(NSAttributedString.Key.attachment, in: NSRange(location: 0, length: attributedString!.length), options: NSAttributedString.EnumerationOptions.longestEffectiveRangeNotRequired, using: { (attributes, range, stop) in attributedString?.enumerateAttribute(NSAttributedString.Key.attachment, in: NSRange(location: 0, length: attributedString!.length), options: NSAttributedString.EnumerationOptions.longestEffectiveRangeNotRequired, using: { (attributes, range, stop) in
var imageDictionary : Dictionary<String, Any> = Dictionary()
if attributes != nil if attributes != nil
{ {
let imageAttachment = attributes as! NSTextAttachment let imageAttachment = attributes as! NSTextAttachment
// 找到图片
if imageAttachment.image != nil if imageAttachment.image != nil
{ {
// 将图片保存在本地
// 把图片转成Data类型
let imageData : Data = (imageAttachment.image?.jpegData(compressionQuality: 1.0))! let imageData : Data = (imageAttachment.image?.jpegData(compressionQuality: 1.0))!
imageDictionary.updateValue(imageData.base64EncodedString(options: Data.Base64EncodingOptions.lineLength64Characters), forKey: "imageData") // 保存的本地路径
imageDictionary.updateValue(range.location, forKey: "imageLocation") let imagePath = filePath + "/" + "image.jpeg" + imagesPathArray.count.string
let imageUrl : URL = URL(fileURLWithPath: imagePath)
var saveSucceed : Bool = Bool(true)
// 将图片保存到沙盒
do
{
try imageData.write(to: imageUrl)
}
catch let error
{
saveSucceed = false
print(error)
}
imageArray.append(imageDictionary) if saveSucceed
{
// 保存成功后存储保存的路径
imagesPathArray.append(imagePath)
// 存储图片位置
imagesIndexArray.append(range.location)
}
} }
} }
}) })
return imageArray return (imagesPathArray, imagesIndexArray)
} }
} }
...@@ -346,7 +346,14 @@ extension SHRecordDetailsVC { ...@@ -346,7 +346,14 @@ extension SHRecordDetailsVC {
switch sender.tag { switch sender.tag {
case 200: case 200:
let input = SHInputController.init() let input = SHInputController.init()
input.folderModel = currentModel
self.navigationController?.pushViewController(input, animated: true) self.navigationController?.pushViewController(input, animated: true)
input.saveSuccessCallBack = { model in
self.currentModel = model
self.updateocloudUI()
}
break break
default: default:
let record = UIStoryboard.init(name: "Record", bundle: nil).instantiateViewController(withIdentifier: "SHRecordViewController") as! SHRecordViewController let record = UIStoryboard.init(name: "Record", bundle: nil).instantiateViewController(withIdentifier: "SHRecordViewController") as! SHRecordViewController
......
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