// // AccountService.swift // iOSFirst // // Created by 孙宇峰 on 2023/2/3. // import Foundation import Moya enum AccountService { case login(_ username: String, _ password: String, _ showLoading: Bool) } extension AccountService: TargetType { var baseURL: URL { return URL(string: Api.shoolurl)! } var path: String { switch self { case .login: return Api.Account.loginTeacher } } var method: Moya.Method { switch self { case .login: return .post default: return .post } } // var sampleData: Data { // return Data() // } // var task: Task { switch self { case .login(let username, let password, _): return .requestParameters(parameters: ["loginname": username, "loginpwd": password, "ultype":"p_phone_t", "versionnum":"3.6.0"], encoding: JSONEncoding.default) } } var headers: [String : String]? { switch self { case .login(_, _, let showLoading): return [ "st":"false", "Content-type":"application/json"] default: return nil } } var sampleData: Data { switch self { case .login: return "should be filled properly".utf8Encoded } } } private extension String { var utf8Encoded:Data { return data(using: .utf8)! } }