123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- //
- // IndexUIView.swift
- // fiveConstant
- //
- // Created by 李建 on 2023/1/20.
- //
- import SwiftUI
- import SwiftyUserDefaults
- struct IndexUIView: View {
- @StateObject var userInfoData: UserInfoData
- @State var roomList: [RoomInfo] = []
- @EnvironmentObject var progressState: ProgressState;
- @State var isShowEmpty = false
- var body: some View {
- VStack {
- // 用户头像及欢迎
- HStack {
- VStack(alignment: .leading) {
- Text("欢迎回来,\(Defaults[\.userName] ?? "")")
- .bold()
- Text("感谢使用永续绿建五恒系统")
- }
- Spacer()
- UserPhoto(url: $userInfoData.photo).frame(width: 50, height: 50)
- .onTapGesture {
- Defaults.removeAll()
- }
- }
- // 天气
- ZStack {
- RoundedRectangle(cornerRadius: 8)
- .fill(Color("SecondColor"))
- .frame(maxHeight: 100)
- HStack {
- VStack {
- HStack() {
- Text("27")
- .font(.largeTitle)
- Text("℃")
- Text("优")
- .font(.callout)
- .fontWeight(.bold)
- }
- Text("9.12 星期一 睛")
- .font(.caption)
-
- }
- Spacer()
- // 中间部分
- VStack(alignment: .leading) {
- HStack {
- Image("icon_location")
- Text("济南市")
- }
- HStack {
- Image("icon_humidity")
- Text("59%")
- }
- }
- .font(.caption)
-
- }
- .padding()
- }
- .foregroundColor(Color.white)
- .padding(.bottom, 30)
- HStack {
- Text("我的房间")
- .font(.title3)
- .bold()
- Spacer()
- }
-
-
- if roomList.count > 0 {
- ScrollView {
- LazyVGrid(columns: Array(repeating: GridItem(.fixed(170)), count: 2), spacing: 20) {
- ForEach(roomList, id: \.record_id) { list in
- NavigationLink(destination: {
- RoomControlView(roomInfo: list, controller: RoomController(roomId: list.record_id!, gatewayId: "YX20230203", controlNumber: list.control_number!))
- }, label: {
- RoomCard(roomData: list)
- })
- }
- }
- }
- } else if isShowEmpty {
- ZStack {
- Image("img_no_room")
- .resizable()
- .frame(width: 274, height: 280)
- VStack(alignment: .center, spacing: 13) {
- Text("您还没有添加房间")
- .font(.footnote)
- .foregroundColor(.gray)
- Button {
-
- } label: {
- HStack {
- Image(systemName: "plus").font(.caption)
- .foregroundColor(Color("MainColor"))
- Text("添加房间")
- .font(.caption)
- .foregroundColor(Color("MainColor"))
- }
- .padding(8)
- .overlay(RoundedRectangle(cornerRadius: 50).stroke(Color("MainColor")))
- }
- }.padding(.top, 150)
-
- }.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
- }
-
-
- Spacer()
- }
- .padding()
- .onAppear {
- HttpRequest<[RoomInfo]>.loadData(target: UserApi.myRooms) { returnData in
- roomList = returnData
- if roomList.count == 0 {
- isShowEmpty = true
- } else {
- isShowEmpty = false
- }
- }
- }
- }
- }
- struct IndexUIView_Previews: PreviewProvider {
- static var previews: some View {
- IndexUIView(userInfoData: UserInfoData(), roomList: [])
- }
- }
|