DFWatchFigmaHomeViews.swift 2.51 KB
import SwiftUI

struct DFDefaultWatchHomeView: View {
    @State private var weekday: String = ""
    @State private var day: String = ""
    
    var hasData: Bool = false
    var hrvValue: String = "38ms"
    var hrvTime: String = "19:04"

    var body: some View {
        VStack{
            HStack{
                Spacer()
                Text(weekday)
                    .font(.system(size: 16, weight: .medium))
                    .foregroundColor(DFWatchFigmaColor.purple)
                Spacer().frame(width: 4)
                Text(day)
                    .font(.system(size: 16, weight: .medium))
                    .foregroundColor(.white)
            }
            Text(.now, style: .time)
                .font(.system(size: 52, weight: .medium))
                .foregroundColor(.white)
                .frame(height: 50)
            HStack(alignment: .center){
                HStack{}
                    .frame(width: 44, height: 44)
                    .background(Color(hex: "#FF0000"))
                Spacer().frame(width: 14)
                VStack(alignment: .leading, spacing: 0) {
                    Text(hasData ? "状态优秀" : "暂无数据")
                        .font(.system(size: 16, weight: .semibold))
                        .foregroundColor(hasData ? DFWatchFigmaColor.green : DFWatchFigmaColor.grayText)
                    Text(hasData ? "\(hrvValue)·\(hrvTime)" : "--ms·--:--")
                        .font(.system(size: 12, weight: .medium))
                        .foregroundColor(.white)
                    DFWatchFigmaSegmentBar(selected: nil)
                        .frame(height: 14)
                }
            }
            HStack{
                DFWatchHeartBeatCircle(progress: 0, value: nil)
                    .frame(width: 45, height: 44)
                Spacer()
                DFWatchCloseCircle(outerProgress: 0, middleProgress: 0, innerProgress: 0)
                    .frame(width: 44, height: 44)
                Spacer()
                DFWatchStepCountCircle(progress: 0, value: 0)
                    .frame(width: 44, height: 44)
            }
        }
        .padding(.all, 15)
        .onAppear {
            updateDate()
        }
    }

    private func updateDate(){
        let calendar = Calendar.current
        let component = calendar.component(.weekday, from: .now)
        weekday = calendar.shortWeekdaySymbols[component].uppercased()
        
        let formatter = DateFormatter()
        formatter.dateFormat = "dd"
        day = formatter.string(from: .now)
    }
}