You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
weibo/Weibo/SendView.swift

163 lines
8.3 KiB

//
// SendView.swift
// Weibo
//
// Created by Qihua Pan on 2020/8/20.
// Copyright © 2020 Qihua Pan. All rights reserved.
//
import SwiftUI
import CoreData
import Alamofire
import SwiftyJSON
struct SendView: View {
@Environment(\.managedObjectContext) var contenxt:NSManagedObjectContext
@EnvironmentObject var user:User
var flag={}
@State var text:String?=""
@State private var textStyle = UIFont.TextStyle.body
//
// @State var value:CGFloat = 0
let domain="https://sukura.com"
@State var showAlert=false
@State var showTip=false
var body: some View {
VStack {
if self.showTip{
Spacer()
LoadView()
Spacer()
}
else{
HStack {
Button(action: {
self.flag()
// self.alert(isPresented: self.$showAlert, content: {
// Alert(title: Text("fuck"),primaryButton: .destructive(Text("")) { print("...") }, secondaryButton: .cancel())
//
// }).navigationBarTitle(Text("Alert"))
}) {
Text("取消")
.foregroundColor(Color.black)
}
Spacer()
VStack {
Text("发微博")
// Text(self.$user.name).foregroundColor(Color.gray)
Text("用户7450769290")
.foregroundColor(Color.gray)
}
Spacer()
Button(action: {
print("send")
if let access_token=self.user.access_token,let text=self.text{
self.showTip=true
AF.request("https://api.weibo.com/2/statuses/share.json",method: .post,parameters: ["access_token":access_token,"status":"\(text):\(self.domain)"]).responseJSON { response in
self.showTip=false
if let data=response.data,let json = try? JSON(data: data){
print("分享微博信息返回\(json)")
self.flag()
}else{
print("发送微博失败")
self.alert(isPresented: self.$showAlert, content: {
Alert(title: Text("错误提示").foregroundColor(Color.red),message: Text("发送微博失败,请联系管理员"))
})
}
}
}
}){
Text("发送")
.foregroundColor(Color.gray)
}
.padding(.all, 5.0)
.frame(width: 50.0)
.background(/*@START_MENU_TOKEN@*/Color.orange/*@END_MENU_TOKEN@*/)
.cornerRadius(30)
}
.padding(.horizontal)
.background(Color(red: 229/255, green: 230/255, blue: 229/255, opacity: 1.0))
// MultiLineTextView(text: self.$text, textStyle: self.$textStyle)
GrowingTextInputView(text: $text, placeholder: "分享新鲜事...")
HStack {
Button(action: {
}) {
HStack(spacing: 0.0) {
Image("location").foregroundColor(Color(red: 148/255, green: 148/255, blue: 148/255, opacity: 1.0))
Text("你在哪里?").foregroundColor(Color.gray)
}
}
.padding(.all, 10.0)
// .background(Color.red)
.background(Color(red: 228/255, green: 228/255, blue: 228/255, opacity: 1.0))
.cornerRadius(20)
Spacer()
if self.text!.count>0{
Text("\(self.text!.count)").font(.title)
}
Button(action: {
}) {
HStack(spacing: 0.0) {
Image("earth")
Text("公开")
}
}.padding(.all, 10.0)
// .background(Color.red)
.background(Color(red: 228/255, green: 228/255, blue: 228/255, opacity: 1.0))
.cornerRadius(/*@START_MENU_TOKEN@*/20.0/*@END_MENU_TOKEN@*/)
}
.padding(.horizontal)
Spacer()
}
// .offset(y : -value)
// .animation(.spring()).onAppear(perform: {
//
// NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillShowNotification, object: nil, queue: OperationQueue.current) { (noti) in
// let value = noti.userInfo![UIResponder.keyboardFrameEndUserInfoKey] as! CGRect
// let height = value.height
// self.value = height - UIApplication.shared.windows.first!.safeAreaInsets.bottom
// }
// //
// NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillHideNotification, object: nil, queue: OperationQueue.current) { (noti) in
// self.value = 0
// }
// })
}
}
}
class KeyBoardView:UITextField{
}
struct SendView_Previews: PreviewProvider {
static var previews: some View {
SendView()
}
}