subscriptionUserConfig.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <view>
  3. <!-- 已订阅列表 -->
  4. <uni-list>
  5. <uni-list-item v-for="(item, index) in subscriptionUserConfigList" :key="item.id">
  6. <template v-slot:body>
  7. <view class="item-box">
  8. <view @click="goSubscriptionSourceDetail(item)">
  9. <view class="title">{{ item.title }}</view>
  10. <view class="description">{{ item.subTitle }}</view>
  11. </view>
  12. <view class="func-box">
  13. <view class="date">剩余有效期:{{ item.remainingDays }}天</view>
  14. <view class="switch-text">
  15. <span>通知状态:{{ item.pushOption == 'ENABLED' ? '开启中' : '关闭' }}</span>
  16. <switch color="#FFD800" style="transform:scale(0.7)" :checked="item.pushOption == 'ENABLED'"
  17. @change="e => pushOptionSwitchChange(e, item)" />
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. </uni-list-item>
  23. </uni-list>
  24. </view>
  25. </template>
  26. <script setup>
  27. import { ref } from 'vue';
  28. import { onPullDownRefresh, onShow } from "@dcloudio/uni-app";
  29. import { subscriptionApi } from '@/apis/apis.js';
  30. import router from '@/common/router.js';
  31. // 属性
  32. const subscriptionUserConfigList = ref([]);
  33. // 方法
  34. /**
  35. * 加载数据
  36. */
  37. const loadData = async () => {
  38. subscriptionUserConfigList.value = [];
  39. try {
  40. uni.showLoading({
  41. title: '加载中',
  42. mask: true
  43. });
  44. subscriptionUserConfigList.value = await subscriptionApi.querySubscriptionUserConfig();
  45. } finally {
  46. uni.hideLoading();
  47. }
  48. };
  49. /**
  50. * 跳转到订阅源详情页面
  51. */
  52. const goSubscriptionSourceDetail = (dataObj) => {
  53. uni.navigateTo({
  54. url: router.SUBSCRIPTION_SOURCE_DETAIL_PAGE + `?id=${dataObj.id}`
  55. });
  56. };
  57. /**
  58. * 推送选项切换
  59. * @param e switch开关事件
  60. */
  61. const pushOptionSwitchChange = async (e, configObj) => {
  62. await subscriptionApi.modifyPushOption({
  63. id: configObj.id,
  64. pushOption: e.detail.value ? 'ENABLED' : 'DISABLED'
  65. });
  66. loadData();
  67. }
  68. // 生命周期
  69. onShow(() => {
  70. loadData();
  71. });
  72. onPullDownRefresh(() => {
  73. loadData();
  74. uni.stopPullDownRefresh();
  75. });
  76. </script>
  77. <style lang="scss" scoped>
  78. .item-box {
  79. width: 100%;
  80. .title {
  81. font-size: 29.17rpx;
  82. font-weight: 400;
  83. letter-spacing: 0rpx;
  84. line-height: 40.02rpx;
  85. color: #191919;
  86. text-align: left;
  87. vertical-align: top;
  88. }
  89. .description,
  90. .date,
  91. .switch-text {
  92. font-size: 25rpx;
  93. font-weight: 400;
  94. letter-spacing: 0rpx;
  95. line-height: 34.3rpx;
  96. color: #999999;
  97. text-align: left;
  98. vertical-align: top;
  99. }
  100. .func-box {
  101. display: flex;
  102. }
  103. .date,
  104. .switch-text {
  105. flex: 0 0 50%;
  106. /* 禁止伸缩,基础宽度50% */
  107. display: flex;
  108. align-items: center;
  109. }
  110. .switch-text {
  111. justify-content: space-between; // 修改: 添加此行以使两个元素按一头一尾排列
  112. }
  113. }
  114. </style>