health_tip_collect.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <view v-if="favor_health_list" class="content">
  3. <view v-for="(value, key) in favor_health_list" :key="value" class="tip-group">
  4. <view class="tip-item flex justify-between">
  5. <div class="center" v-html="formatHealthTip(health_tips[value])"></div>
  6. <view @click="change_favor(value,key)" class="flex justify-end relative">
  7. <text v-if="change_favor_list[key]" class="favor cuIcon-favorfill text-red"></text>
  8. <text v-else class="favor cuIcon-favor"></text>
  9. </view>
  10. </view>
  11. </view>
  12. </view>
  13. <view v-else class="no_data"></view>
  14. </template>
  15. <script>
  16. import health_tips from '@/static/health_tip.js'
  17. export default {
  18. onLoad() {
  19. let favor_health_list = uni.getStorageSync('favor_health_list');
  20. if(favor_health_list && Object.keys(favor_health_list).length != 0) this.favor_health_list = favor_health_list;
  21. this.change_favor_list = new Array(favor_health_list.length).fill(1);
  22. },
  23. data() {
  24. return {
  25. health_tips,
  26. favor_health_list: null,
  27. change_favor_list: null
  28. }
  29. },
  30. methods: {
  31. formatHealthTip(health_tip) {
  32. const totalLength = health_tip.length;
  33. const numRows = Math.ceil(totalLength / 15); // 计算总行数
  34. const charsPerRow = Math.ceil(totalLength / numRows); // 计算每行字符数
  35. let formattedTip = '';
  36. for (let i = 0; i < totalLength; i += charsPerRow) {
  37. formattedTip += health_tip.slice(i, i + charsPerRow) + '<br>';
  38. }
  39. // 去掉最后一行多余的 <br>
  40. formattedTip = formattedTip.slice(0, -4);
  41. return formattedTip;
  42. },
  43. change_favor(index,key){
  44. console.log('index: ',index);
  45. console.log('key: ',key);
  46. let favor_health_list = uni.getStorageSync('favor_health_list');
  47. if(favor_health_list){
  48. if(favor_health_list.includes(index))
  49. favor_health_list.splice(favor_health_list.indexOf(index), 1);
  50. else favor_health_list.unshift(index);
  51. }
  52. else favor_health_list = [index];
  53. uni.setStorageSync('favor_health_list',favor_health_list);
  54. if(this.change_favor_list[key] == 1) this.change_favor_list[key] = 0;
  55. else this.change_favor_list[key] = 1;
  56. this.$forceUpdate();
  57. },
  58. }
  59. }
  60. </script>
  61. <style lang="less">
  62. page{
  63. background-color: #f5f5f5;
  64. }
  65. text{
  66. font-size: 18px;
  67. display: flex;
  68. justify-content: center; /* 水平居中 */
  69. align-items: center; /* 垂直居中 */
  70. }
  71. .content {
  72. padding:5px 20px;
  73. border: none;
  74. }
  75. .tip-group{
  76. border: none;
  77. border-radius: 15px;
  78. width: 100%;
  79. background-color: #ffffff;
  80. margin-bottom: 10px;
  81. :first-child{
  82. border-radius: 15px 15px 0% 0%;
  83. }
  84. :last-child{
  85. border-radius:0% 0% 15px 15px;
  86. }
  87. :only-child {
  88. border-radius: 15px;
  89. }
  90. }
  91. .tip-item{
  92. font-size: 18px;
  93. border: 0px;
  94. height: 14vw;
  95. padding: 0 10px;
  96. background-color: #ffffff;
  97. }
  98. .tip-item::after {
  99. display: none;
  100. }
  101. .favor{
  102. font-size: 24px;
  103. margin-right: 5px;
  104. }
  105. </style>