
主要变更: 1. 在 Info.plist 中将应用名称和描述中的 "E-Parti" 替换为 "E-Party"。 2. 更新多个本地化字符串和提示信息,确保一致性。 3. 修改部分代码中的错误提示信息,使用本地化字符串替代硬编码文本。 此更新旨在提升品牌一致性,确保用户在使用过程中获得统一的体验。
112 lines
4.1 KiB
Swift
112 lines
4.1 KiB
Swift
//
|
||
// EPMomentAPISwiftHelper.swift
|
||
// YuMi
|
||
//
|
||
// Created by AI on 2025-10-11.
|
||
//
|
||
|
||
import Foundation
|
||
|
||
/// 动态 API 封装(Swift 现代化版本)
|
||
/// 统一封装列表获取和发布功能,完全替代 OC 版本
|
||
@objc class EPMomentAPISwiftHelper: NSObject {
|
||
|
||
/// 拉取最新动态列表
|
||
/// - Parameters:
|
||
/// - nextID: 下一页 ID,首次传空字符串
|
||
/// - completion: 成功回调 (动态列表, 下一页ID)
|
||
/// - failure: 失败回调 (错误码, 错误信息)
|
||
@objc func fetchLatestMomentsWithNextID(
|
||
_ nextID: String,
|
||
completion: @escaping ([MomentsInfoModel], String) -> Void,
|
||
failure: @escaping (Int, String) -> Void
|
||
) {
|
||
let pageSize = "20"
|
||
let types = "0,2" // 图片+文字
|
||
|
||
Api.momentsLatestList({ (data, code, msg) in
|
||
if code == 200, let dict = data?.data as? NSDictionary {
|
||
// 从返回数据中提取原始 dictionary 数组
|
||
if let listArray = dict["dynamicList"] as? NSArray {
|
||
// MJExtension 在 Swift 中的正确用法(返回 NSMutableArray)
|
||
let modelsArray = MomentsInfoModel.mj_objectArray(withKeyValuesArray: listArray)
|
||
let nextID = dict["nextDynamicId"] as? String ?? ""
|
||
// 将 NSMutableArray 转换为 NSArray 传递给 OC
|
||
completion(modelsArray as? [MomentsInfoModel] ?? [], nextID)
|
||
} else {
|
||
completion([], "")
|
||
}
|
||
} else {
|
||
failure(Int(code), msg ?? YMLocalizedString("error.request_failed"))
|
||
}
|
||
}, dynamicId: nextID, pageSize: pageSize, types: types)
|
||
}
|
||
|
||
/// 发布动态
|
||
/// - Parameters:
|
||
/// - type: "0"=纯文本, "2"=图片
|
||
/// - content: 文本内容
|
||
/// - resList: 图片信息数组
|
||
/// - completion: 成功回调
|
||
/// - failure: 失败回调 (错误码, 错误信息)
|
||
@objc func publishMoment(
|
||
type: String,
|
||
content: String,
|
||
resList: [[String: Any]],
|
||
completion: @escaping () -> Void,
|
||
failure: @escaping (Int, String) -> Void
|
||
) {
|
||
guard let uid = AccountInfoStorage.instance().getUid() else {
|
||
failure(-1, YMLocalizedString("error.not_logged_in"))
|
||
return
|
||
}
|
||
|
||
// worldId 传空字符串(话题功能不实现)
|
||
// NOTE: 旧版本 XPMonentsPublishViewController 包含话题选择功能
|
||
// 但实际业务中话题功能使用率低,新版本暂不实现
|
||
// 如需实现参考: YuMi/Modules/YMMonents/View/XPMonentsPublishTopicView
|
||
|
||
Api.momentsPublish({ (data, code, msg) in
|
||
if code == 200 {
|
||
completion()
|
||
} else {
|
||
failure(Int(code), msg ?? YMLocalizedString("error.publish_failed"))
|
||
}
|
||
}, uid: uid, type: type, worldId: "", content: content, resList: resList)
|
||
}
|
||
|
||
/// 点赞/取消点赞动态
|
||
/// - Parameters:
|
||
/// - dynamicId: 动态 ID
|
||
/// - isLike: true=点赞,false=取消点赞
|
||
/// - likedUid: 动态发布者 UID
|
||
/// - worldId: 话题 ID
|
||
/// - completion: 成功回调
|
||
/// - failure: 失败回调 (错误码, 错误信息)
|
||
@objc func likeMoment(
|
||
dynamicId: String,
|
||
isLike: Bool,
|
||
likedUid: String,
|
||
worldId: Int,
|
||
completion: @escaping () -> Void,
|
||
failure: @escaping (Int, String) -> Void
|
||
) {
|
||
guard let uid = AccountInfoStorage.instance().getUid() else {
|
||
failure(-1, YMLocalizedString("error.not_logged_in"))
|
||
return
|
||
}
|
||
|
||
let status = isLike ? "1" : "0"
|
||
let worldIdStr = String(format: "%ld", worldId)
|
||
|
||
Api.momentsLike({ (data, code, msg) in
|
||
if code == 200 {
|
||
completion()
|
||
} else {
|
||
failure(Int(code), msg ?? YMLocalizedString("error.like_failed"))
|
||
}
|
||
}, dynamicId: dynamicId, uid: uid, status: status, likedUid: likedUid, worldId: worldIdStr)
|
||
}
|
||
}
|
||
|