Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
S
ShorthandMaster
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lmj
ShorthandMaster
Commits
310abcf6
Commit
310abcf6
authored
Sep 27, 2020
by
lmj_521aiau@163.com
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'branch_1.0.1' of gitlab.huolea.com:lmi/shorthandmaster into branch_1.0.1
parents
ff4cdcd3
3a2189a1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
199 additions
and
119 deletions
+199
-119
SHInputController.swift
ShorthandMaster/Input/Controller/SHInputController.swift
+128
-103
SHInputViewModel.swift
ShorthandMaster/Input/ViewModel/SHInputViewModel.swift
+64
-16
SHRecordDetailsVC.swift
ShorthandMaster/Record/SHRecordDetailsVC.swift
+7
-0
No files found.
ShorthandMaster/Input/Controller/SHInputController.swift
View file @
310abcf6
This diff is collapsed.
Click to expand it.
ShorthandMaster/Input/ViewModel/SHInputViewModel.swift
View file @
310abcf6
...
...
@@ -11,12 +11,15 @@ import UIKit
class
SHInputViewModel
:
NSObject
{
// MARK: - property
/// 标题文字
var
title
:
String
=
""
/// 内容文字
var
content
:
String
=
""
/// 图片数组
var
imageArray
:
Array
=
Array
<
Any
>
()
// /// 标题文字
// var title : String = ""
// /// 内容文字
// var content : String = ""
// /// 图片数组
// var imageArray : Array = Array<Any>()
// var recordModel : SHRecordModel = SHRecordModel()
...
...
@@ -50,34 +53,79 @@ class SHInputViewModel: NSObject {
return
titleAttributes
}
// MARK: 获取
图片
数组
class
func
getImageArrayWithTextView
(
textView
:
UITextView
)
->
Array
<
Any
>
// MARK: 获取
textView中的图片, 保存到本地, 并生成
数组
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
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
{
let
imageAttachment
=
attributes
as!
NSTextAttachment
// 找到图片
if
imageAttachment
.
image
!=
nil
{
// 将图片保存在本地
// 把图片转成Data类型
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
)
}
}
ShorthandMaster/Record/SHRecordDetailsVC.swift
View file @
310abcf6
...
...
@@ -346,7 +346,14 @@ extension SHRecordDetailsVC {
switch
sender
.
tag
{
case
200
:
let
input
=
SHInputController
.
init
()
input
.
folderModel
=
currentModel
self
.
navigationController
?
.
pushViewController
(
input
,
animated
:
true
)
input
.
saveSuccessCallBack
=
{
model
in
self
.
currentModel
=
model
self
.
updateocloudUI
()
}
break
default
:
let
record
=
UIStoryboard
.
init
(
name
:
"Record"
,
bundle
:
nil
)
.
instantiateViewController
(
withIdentifier
:
"SHRecordViewController"
)
as!
SHRecordViewController
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment