jstxInfo.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <view class="ezy-jstx-ziliao-page">
  3. <view class="icon-title-navBar-box">
  4. <view @click="handleBack" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">{{data.ziliaoName}}</text>
  6. </view>
  7. <view class="ezy-page-body jstx-body">
  8. <view class="jstx-body-title"></view>
  9. <!-- 资料等级标签切换 -->
  10. <view class="jstx-tab-box">
  11. <view v-if="data.dengjiList.length > 0" v-for="(item, index) in data.dengjiList" :key="item.dengjiId" @click="zldjBtn(item,index)"
  12. class="tab-item" :class="{active: item.dengjiId == data.dengjiActiveSelect}">{{ item.dengjiName }}</view>
  13. </view>
  14. <!-- 版本卡片列表 -->
  15. <view v-if="data.banbenList.length > 0" class="jstx-card-list">
  16. <view v-for="(bbItem, index) in data.banbenList" :key="bbItem.banbenId"
  17. @click="cardBtn(bbItem)" class="ziliao-card-box">
  18. <!-- <img/> -->
  19. <img :src="bbItem.cover" class="card-img"/>
  20. <!-- 内容区 -->
  21. <view class="card-content-box">
  22. <view class="ziliao-name">{{ bbItem.ziliaoName }}</view>
  23. <view class="banben-name">{{ bbItem.banbenName}}</view>
  24. </view>
  25. <icon class="card-icon"></icon>
  26. </view>
  27. </view>
  28. <!-- 无数据提示 -->
  29. <view class="ezy-no-sj" v-else>
  30. <icon></icon>
  31. <text>暂无数据</text>
  32. </view>
  33. </view>
  34. <!-- 下载弹窗 -->
  35. <jstxDownDialog ref="jstxDownRef" @confirm-btn="jstxDialogConfirm" :content="data.jcContent"></jstxDownDialog>
  36. </view>
  37. </template>
  38. <script setup>
  39. import {reactive, ref} from "vue";
  40. import {onLoad,onShow} from "@dcloudio/uni-app"
  41. import {jisuanInfo,jisuanPdf} from '@/api/ziliao.js'
  42. import jstxDownDialog from './jstxDownDialog.vue';
  43. const data = reactive({
  44. id: '',
  45. ziliaoName: '',
  46. dengjiList: [],
  47. dengjiActiveSelect: '',
  48. dengjiActiveSelectName: '',
  49. banbenList: [],
  50. banbenId: '',
  51. jcContent: '',
  52. })
  53. const jstxDownRef = ref(null);
  54. function handleBack() {
  55. uni.switchTab({
  56. url: '/pages/chanpinZiliao/index'
  57. })
  58. }
  59. // jisuantexun Info data
  60. function getJisuanInfo() {
  61. jisuanInfo({ziliaoId:data.id}).then(res => {
  62. data.ziliaoName = res.data.ziliaoName;
  63. data.dengjiList = res.data.dengjiList;
  64. // 默认加载第一个资料等级的数据
  65. const firstLevel = data.dengjiList[0];
  66. data.dengjiActiveSelect = firstLevel.dengjiId;
  67. data.dengjiActiveSelectName = firstLevel.dengjiName;
  68. data.banbenList = firstLevel.banbenList || [];
  69. }).catch(err => {
  70. uni.showToast({ title: '加载失败,请稍后重试', icon: 'none' });
  71. })
  72. }
  73. // tab切换资料登记
  74. function zldjBtn(item,index){
  75. data.dengjiActiveSelect = item.dengjiId;
  76. data.dengjiActiveSelectName = item.dengjiName;
  77. data.banbenList = data.dengjiList[index].banbenList;
  78. }
  79. // card点击
  80. function cardBtn(bbItem) {
  81. // 确认逻辑
  82. data.banbenId = bbItem.banbenId;
  83. data.jcContent = "鹅状元将为您随机生成"+ data.dengjiActiveSelectName +"《" + bbItem.banbenName + "》100道试题。"
  84. jstxDownRef.value.handleShow();
  85. }
  86. // 弹窗确认
  87. function jstxDialogConfirm() {
  88. jisuanPdf({
  89. banbenId:data.banbenId,
  90. }).then(res1 => {
  91. const url = res1.data;
  92. if (!url) {
  93. uni.showToast({ title: '未获取到文件地址', icon: 'none' });
  94. return;
  95. }
  96. uni.downloadFile({
  97. url,
  98. success: function (res) {
  99. var filePath = res.tempFilePath;
  100. uni.openDocument({
  101. filePath: filePath,
  102. showMenu: true,
  103. success: function (res) {
  104. jstxDownRef.value.handleClose();
  105. },
  106. fail: () => {
  107. uni.showToast({ title: '无法打开文件', icon: 'none' });
  108. }
  109. });
  110. }
  111. });
  112. }).catch(err => {
  113. uni.showToast({ title: '生成失败,请稍后重试', icon: 'none' });
  114. });
  115. }
  116. onLoad((options) => {
  117. data.id = options.ziliaoId;
  118. getJisuanInfo()
  119. })
  120. </script>