index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <template>
  2. <view class="blacklist-page">
  3. <!-- 顶部导航栏 -->
  4. <view class="header">
  5. <view class="back-btn" @click="goBack">
  6. <text class="back-icon">←</text>
  7. </view>
  8. <text class="header-title">黑名单</text>
  9. <view class="placeholder"></view>
  10. </view>
  11. <scroll-view scroll-y class="content">
  12. <!-- 说明提示 -->
  13. <view class="tips-section">
  14. <view class="tips-icon">ℹ️</view>
  15. <view class="tips-content">
  16. <text class="tips-text">拉黑后,对方将无法查看您的资料,也无法向您发送消息</text>
  17. </view>
  18. </view>
  19. <!-- 黑名单列表 -->
  20. <view class="list-section" v-if="blacklist.length > 0">
  21. <view class="blacklist-item" v-for="(item, index) in blacklist" :key="item.id">
  22. <view class="user-info" @click="viewProfile(item)">
  23. <image class="avatar" :src="item.avatar || defaultAvatar" mode="aspectFill"></image>
  24. <view class="info">
  25. <view class="name-row">
  26. <text class="nickname">{{ item.nickname }}</text>
  27. <text class="gender-icon" v-if="item.gender === 1">♂</text>
  28. <text class="gender-icon female" v-if="item.gender === 2">♀</text>
  29. <view class="vip-badge" v-if="item.isVip">
  30. <text class="vip-icon">👑</text>
  31. </view>
  32. </view>
  33. <view class="detail-row">
  34. <text class="age">{{ item.age > 0 ? item.age + '岁' : '年龄未知' }}</text>
  35. <text class="divider">|</text>
  36. <text class="location">{{ item.city }}</text>
  37. </view>
  38. <text class="block-time">拉黑时间:{{ formatDate(item.blockTime) }}</text>
  39. </view>
  40. </view>
  41. <view class="action-btn" @click="removeFromBlacklist(item, index)">
  42. <text class="btn-text">移除</text>
  43. </view>
  44. </view>
  45. </view>
  46. <!-- 空状态 -->
  47. <view class="empty-state" v-else>
  48. <text class="empty-icon">📋</text>
  49. <text class="empty-text">暂无黑名单用户</text>
  50. <text class="empty-tip">拉黑的用户将显示在这里</text>
  51. </view>
  52. </scroll-view>
  53. </view>
  54. </template>
  55. <script>
  56. export default {
  57. data() {
  58. return {
  59. gatewayURL: 'http://localhost:8083',
  60. currentUserId: null,
  61. defaultAvatar: 'https://via.placeholder.com/100',
  62. blacklist: []
  63. }
  64. },
  65. onLoad() {
  66. // 获取当前用户ID
  67. this.currentUserId = uni.getStorageSync('userId') || 1
  68. this.loadBlacklist()
  69. },
  70. methods: {
  71. // 返回
  72. goBack() {
  73. uni.navigateBack()
  74. },
  75. // 加载黑名单
  76. loadBlacklist() {
  77. uni.showLoading({
  78. title: '加载中...'
  79. })
  80. // 调用后端接口获取黑名单
  81. uni.request({
  82. url: `${this.gatewayURL}/api/blacklist/list`,
  83. method: 'GET',
  84. data: {
  85. userId: this.currentUserId
  86. },
  87. success: (res) => {
  88. console.log('黑名单列表响应:', res)
  89. if (res.data && res.data.code === 200) {
  90. // 转换后端数据格式到前端需要的格式
  91. this.blacklist = res.data.data.map(item => ({
  92. id: item.id,
  93. userId: item.blockedUserId,
  94. nickname: item.blockedUserNickname || '未知用户',
  95. avatar: item.blockedUserAvatar || this.defaultAvatar,
  96. gender: item.blockedUserGender, // 0-未知 1-男 2-女
  97. age: item.blockedUserAge || 0,
  98. city: item.blockedUserCity || '未知',
  99. isVip: false,
  100. blockTime: item.createdAt,
  101. reason: item.reason
  102. }))
  103. } else {
  104. uni.showToast({
  105. title: res.data ? res.data.message : '加载失败',
  106. icon: 'none'
  107. })
  108. }
  109. },
  110. fail: (err) => {
  111. console.error('加载黑名单失败:', err)
  112. uni.showToast({
  113. title: '网络请求失败',
  114. icon: 'none'
  115. })
  116. },
  117. complete: () => {
  118. uni.hideLoading()
  119. }
  120. })
  121. },
  122. // 格式化日期
  123. formatDate(dateStr) {
  124. if (!dateStr) return ''
  125. // 简单格式化,只显示日期
  126. return dateStr.split(' ')[0]
  127. },
  128. // 查看用户资料
  129. viewProfile(item) {
  130. uni.showModal({
  131. title: '提示',
  132. content: '该用户已在黑名单中,是否先移除黑名单?',
  133. success: (res) => {
  134. if (res.confirm) {
  135. // 移除后跳转
  136. const index = this.blacklist.findIndex(u => u.id === item.id)
  137. this.removeFromBlacklist(item, index, true)
  138. }
  139. }
  140. })
  141. },
  142. // 移除黑名单
  143. removeFromBlacklist(item, index, needRedirect = false) {
  144. uni.showModal({
  145. title: '移除黑名单',
  146. content: `确定要将"${item.nickname}"移出黑名单吗?`,
  147. success: (res) => {
  148. if (res.confirm) {
  149. uni.showLoading({
  150. title: '处理中...'
  151. })
  152. // 调用后端接口移除黑名单
  153. uni.request({
  154. url: `${this.gatewayURL}/api/blacklist/remove?userId=${this.currentUserId}&blockedUserId=${item.userId}`,
  155. method: 'DELETE',
  156. success: (response) => {
  157. console.log('移除黑名单响应:', response)
  158. if (response.data && response.data.code === 200) {
  159. // 从列表中移除
  160. this.blacklist.splice(index, 1)
  161. uni.showToast({
  162. title: '已移除黑名单',
  163. icon: 'success'
  164. })
  165. // 如果需要跳转到用户资料
  166. if (needRedirect) {
  167. setTimeout(() => {
  168. uni.navigateTo({
  169. url: '/pages/user-detail/index?userId=' + item.userId
  170. })
  171. }, 1000)
  172. }
  173. } else {
  174. uni.showToast({
  175. title: response.data ? response.data.message : '移除失败',
  176. icon: 'none'
  177. })
  178. }
  179. },
  180. fail: (err) => {
  181. console.error('移除黑名单失败:', err)
  182. uni.showToast({
  183. title: '网络请求失败',
  184. icon: 'none'
  185. })
  186. },
  187. complete: () => {
  188. uni.hideLoading()
  189. }
  190. })
  191. }
  192. }
  193. })
  194. }
  195. }
  196. }
  197. </script>
  198. <style lang="scss" scoped>
  199. .blacklist-page {
  200. min-height: 100vh;
  201. background: #F5F5F5;
  202. display: flex;
  203. flex-direction: column;
  204. }
  205. /* 顶部导航栏 */
  206. .header {
  207. display: flex;
  208. align-items: center;
  209. justify-content: space-between;
  210. padding: 25rpx 30rpx;
  211. padding-top: calc(25rpx + env(safe-area-inset-top));
  212. background: linear-gradient(135deg, #FF8A9B 0%, #FFB4C0 100%);
  213. .back-btn {
  214. width: 70rpx;
  215. height: 70rpx;
  216. display: flex;
  217. align-items: center;
  218. justify-content: center;
  219. background: rgba(255, 255, 255, 0.2);
  220. border-radius: 50%;
  221. .back-icon {
  222. font-size: 44rpx;
  223. color: #FFFFFF;
  224. font-weight: bold;
  225. }
  226. }
  227. .header-title {
  228. font-size: 38rpx;
  229. font-weight: bold;
  230. color: #FFFFFF;
  231. }
  232. .placeholder {
  233. width: 70rpx;
  234. }
  235. }
  236. .content {
  237. flex: 1;
  238. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  239. }
  240. /* 提示区域 */
  241. .tips-section {
  242. margin: 30rpx;
  243. padding: 25rpx;
  244. background: linear-gradient(135deg, #FFF4E6 0%, #FFE8CC 100%);
  245. border-radius: 15rpx;
  246. border-left: 6rpx solid #FFA726;
  247. display: flex;
  248. align-items: flex-start;
  249. .tips-icon {
  250. font-size: 36rpx;
  251. margin-right: 15rpx;
  252. flex-shrink: 0;
  253. }
  254. .tips-content {
  255. flex: 1;
  256. }
  257. .tips-text {
  258. font-size: 26rpx;
  259. color: #E65100;
  260. line-height: 1.6;
  261. }
  262. }
  263. /* 列表区域 */
  264. .list-section {
  265. padding: 0 30rpx;
  266. .blacklist-item {
  267. background: #FFFFFF;
  268. border-radius: 15rpx;
  269. padding: 25rpx;
  270. margin-bottom: 20rpx;
  271. display: flex;
  272. align-items: center;
  273. justify-content: space-between;
  274. box-shadow: 0 2rpx 15rpx rgba(0, 0, 0, 0.05);
  275. .user-info {
  276. flex: 1;
  277. display: flex;
  278. align-items: center;
  279. margin-right: 20rpx;
  280. .avatar {
  281. width: 100rpx;
  282. height: 100rpx;
  283. border-radius: 50%;
  284. margin-right: 20rpx;
  285. border: 3rpx solid #F0F0F0;
  286. flex-shrink: 0;
  287. }
  288. .info {
  289. flex: 1;
  290. .name-row {
  291. display: flex;
  292. align-items: center;
  293. margin-bottom: 10rpx;
  294. .nickname {
  295. font-size: 32rpx;
  296. font-weight: bold;
  297. color: #333333;
  298. margin-right: 10rpx;
  299. }
  300. .gender-icon {
  301. font-size: 28rpx;
  302. color: #4A90E2;
  303. margin-right: 10rpx;
  304. font-weight: bold;
  305. &.female {
  306. color: #FF6B9D;
  307. }
  308. }
  309. .vip-badge {
  310. background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
  311. padding: 4rpx 12rpx;
  312. border-radius: 20rpx;
  313. display: flex;
  314. align-items: center;
  315. .vip-icon {
  316. font-size: 20rpx;
  317. }
  318. }
  319. }
  320. .detail-row {
  321. display: flex;
  322. align-items: center;
  323. margin-bottom: 8rpx;
  324. .age,
  325. .location {
  326. font-size: 26rpx;
  327. color: #666666;
  328. }
  329. .divider {
  330. margin: 0 15rpx;
  331. color: #CCCCCC;
  332. }
  333. }
  334. .block-time {
  335. font-size: 22rpx;
  336. color: #999999;
  337. }
  338. }
  339. }
  340. .action-btn {
  341. padding: 12rpx 30rpx;
  342. background: linear-gradient(135deg, #FF8A9B 0%, #FF6B8A 100%);
  343. border-radius: 30rpx;
  344. flex-shrink: 0;
  345. .btn-text {
  346. font-size: 26rpx;
  347. color: #FFFFFF;
  348. font-weight: 500;
  349. }
  350. }
  351. }
  352. }
  353. /* 空状态 */
  354. .empty-state {
  355. display: flex;
  356. flex-direction: column;
  357. align-items: center;
  358. justify-content: center;
  359. padding: 150rpx 50rpx;
  360. .empty-icon {
  361. font-size: 120rpx;
  362. margin-bottom: 30rpx;
  363. opacity: 0.3;
  364. }
  365. .empty-text {
  366. font-size: 32rpx;
  367. color: #999999;
  368. margin-bottom: 15rpx;
  369. }
  370. .empty-tip {
  371. font-size: 26rpx;
  372. color: #CCCCCC;
  373. }
  374. }
  375. </style>