index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view class="phone-haibao-page">
  3. <view class="icon-title-navBar-box">
  4. <view @click="goUpPage" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">职业海报</text>
  6. </view>
  7. <view class="haibao-body-box">
  8. <view class="haibao-menu-box">
  9. <view v-for="menu in menuData" :key="menu.id" class="menu-item-box"
  10. :class="{ active: selectedCategory === Number(menu.id) }"
  11. @click="menuBtn(menu.id)">
  12. {{ menu.name }}
  13. </view>
  14. </view>
  15. <view class="haibao-show-box">
  16. <view class="haibao-title">共{{cardData.length}}个海报</view>
  17. <view class="card-list-box">
  18. <view v-for="item in cardData" :key="item.id" class="haibao-card-box"
  19. @click="cardBtn(item.id)">
  20. <img :src="item.image"/>
  21. <view class="card-name">{{ item.name }}</view>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script setup>
  29. import * as httpApi from '@/api/haibao.js'
  30. import { ref, reactive } from "vue"
  31. import {onLoad} from "@dcloudio/uni-app";
  32. const menuData = ref([])
  33. const cardData = ref([])
  34. // 当前选中的分类
  35. const selectedCategory = ref(null)
  36. function goUpPage() {
  37. uni.redirectTo({
  38. url: `/pages/admin/ShouYe/shouye`
  39. })
  40. }
  41. // 加载海报列表
  42. function getHaibaoListData(zyId) {
  43. if (zyId == null) return;
  44. httpApi.getHaibaoList({ zyId }).then(res => {
  45. cardData.value = Array.isArray(res.data) ? res.data : [];
  46. }).catch(err => {
  47. console.error('获取海报列表失败:', err);
  48. cardData.value = [];
  49. uni.showToast({ title: '加载失败', icon: 'none' });
  50. });
  51. }
  52. // 菜单按钮点击
  53. function menuBtn(id) {
  54. const numericId = Number(id);
  55. selectedCategory.value = numericId;
  56. getHaibaoListData(numericId);
  57. }
  58. // 海报卡片点击
  59. function cardBtn(data) {
  60. uni.redirectTo({
  61. url: `/pages/admin/haibao/haibaoInfo?cardId=${data}&menuId=${selectedCategory.value}`
  62. });
  63. }
  64. // 首次进入页面初始化
  65. function pageInit() {
  66. httpApi.getHaibaoOpsZhiye().then(res => {
  67. menuData.value = Array.isArray(res.data) ? res.data : [];
  68. if (menuData.value.length > 0) {
  69. const firstId = Number(menuData.value[0].id);
  70. selectedCategory.value = firstId;
  71. getHaibaoListData(firstId);
  72. }
  73. }).catch(err => {
  74. console.error('初始化职业失败:', err);
  75. menuData.value = [];
  76. uni.showToast({ title: '职业加载失败', icon: 'none' });
  77. });
  78. }
  79. // 从详情页返回时恢复状态
  80. function pageRecover(data) {
  81. httpApi.getHaibaoOpsZhiye().then(res => {
  82. menuData.value = Array.isArray(res.data) ? res.data : [];
  83. const menuId = Number(data.menuId);
  84. menuBtn(menuId);
  85. }).catch(err => {
  86. console.error('页面加载:', err);
  87. uni.showToast({ title: '页面加载失败', icon: 'none' });
  88. });
  89. }
  90. onLoad((options) => {
  91. // 详情页返回
  92. if(options.menuId){
  93. pageRecover(options)
  94. }else{
  95. // 首页进入
  96. pageInit()
  97. }
  98. })
  99. </script>