show.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // subpackages/show/show.js
  2. import { models, db } from '../../utils/cloudbase.js'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. categoriesindex: 1,
  9. viewType: 'grid',
  10. categories: [],
  11. courseList: [],
  12. sou: '',
  13. show_1: '',
  14. xiazi: '',
  15. itemlist: {},
  16. pageNumber: 1,
  17. pageSize: 10,
  18. hasMore: true, // 是否还有更多数据
  19. isLoading: false, // 防止多次触发
  20. searchText: '', // 搜索关键词
  21. // url: '',
  22. // pdfurl: '',
  23. // ppturl: '',
  24. // audioUrl: '',
  25. // carousel: ''
  26. },
  27. onLoad(options) {
  28. // 存储 options 到 this 中
  29. this.options = options;
  30. // 获取tab数据
  31. this.getTabdata();
  32. const fileIDs = [
  33. 'cloud://honghgaier-5guiffgcf17a2eea.686f-honghgaier-5guiffgcf17a2eea-1373037829/images/icon/sou.png',
  34. 'cloud://honghgaier-5guiffgcf17a2eea.686f-honghgaier-5guiffgcf17a2eea-1373037829/images/icon/show_1.png',
  35. 'cloud://honghgaier-5guiffgcf17a2eea.686f-honghgaier-5guiffgcf17a2eea-1373037829/images/icon/xiazi.png',
  36. ];
  37. // 并发下载多个 fileID
  38. Promise.all(
  39. fileIDs.map(fileID => wx.cloud.downloadFile({ fileID }))
  40. ).then(results => {
  41. // 每个 result 对应一个下载结果
  42. const tempFilePaths = results.map(r => r.tempFilePath);
  43. console.log('全部下载成功:', tempFilePaths);
  44. this.setData({
  45. sou: tempFilePaths[0],
  46. show_1: tempFilePaths[1],
  47. xiazi: tempFilePaths[2],
  48. // url: tempFilePaths[3],
  49. // pdfurl: tempFilePaths[4],
  50. // ppturl: tempFilePaths[5],
  51. // audioUrl: tempFilePaths[6],
  52. // carousel: tempFilePaths[7]
  53. });
  54. }).catch(err => {
  55. console.error('有文件下载失败:', err);
  56. });
  57. },
  58. // tab数据
  59. async getTabdata() {
  60. const { data } = await models.tab.list({
  61. filter: {
  62. where: {
  63. position: 3, // 显示位置
  64. // layout_type: 0, // 布局类型
  65. },
  66. },
  67. // envType: pre 体验环境, prod 正式环境
  68. envType: "prod",
  69. });
  70. // 返回查询到的数据
  71. const sortedRecords = data.records.sort((a, b) => {
  72. return a.sort - b.sort; // 升序排列
  73. });
  74. this.setData({
  75. categories: sortedRecords
  76. }, () => {
  77. const type = Number(this.options.type) || 1;
  78. this.data.categories.forEach((item, index) => {
  79. if (item.sort === type) {
  80. this.setData({
  81. categorieslist: item,
  82. categoriesindex: type
  83. });
  84. if (this.data.categorieslist.layout_type === 0) {
  85. this.setData({ viewType: 'list' });
  86. } else {
  87. this.setData({ viewType: 'grid' });
  88. }
  89. // 获取列表数据
  90. this.getdatalist()
  91. }
  92. });
  93. })
  94. },
  95. onReachBottom() {
  96. // 上拉触底事件的处理函数
  97. this.loadMore();
  98. },
  99. loadMore() {
  100. // 加载更多数据的逻辑
  101. console.log('加载更多');
  102. // this.getdatalist(true);
  103. if (this.data.isLoading || !this.data.hasMore) return;
  104. this.setData({ isLoading: true });
  105. this.getdatalist(true);
  106. },
  107. // 模糊搜索
  108. onSearchInput(e) {
  109. const keyword = e.detail.value.trim();
  110. this.setData({
  111. searchText: keyword,
  112. pageNumber: 1,
  113. hasMore: true,
  114. goods: []
  115. }, () => {
  116. this.getdatalist(this.data.types_ids); // 重新加载
  117. });
  118. },
  119. // 列表数据
  120. async getdatalist(isLoadMore = false) {
  121. if (!this.data.categorieslist._id) return; // 防止 _id 为 undefined
  122. const { pageNumber, pageSize, searchText } = this.data;
  123. // 构造 where 条件
  124. const where = {
  125. tag_id: this.data.categorieslist._id,
  126. };
  127. // 模糊搜索关键字
  128. if (searchText) {
  129. where.name = {
  130. $regex_ci: searchText
  131. };
  132. }
  133. const { data } = await models.file_manage.list({
  134. filter: { where },
  135. pageSize,
  136. pageNumber,
  137. getCount: true,
  138. envType: "prod",
  139. });
  140. const collectList = data.records || [];
  141. this.setData({
  142. courseList: isLoadMore ? this.data.courseList.concat(collectList) : collectList,
  143. pageNumber: pageNumber + 1,
  144. hasMore: collectList.length === pageSize,
  145. isLoading: false
  146. });
  147. },
  148. tabcategories(e) {
  149. const sort = Number(e.currentTarget.dataset.type); // 直接转换为数字
  150. const currentCategory = this.data.categories.find(item => item.sort === sort);
  151. if (!currentCategory) return;
  152. const viewType = currentCategory.layout_type === 0 ? 'list' : 'grid';
  153. this.setData({
  154. categoriesindex: sort,
  155. categorieslist: currentCategory,
  156. viewType,
  157. courseList: [], // 重置课程列表
  158. pageNumber: 1, // 重置分页
  159. hasMore: true,
  160. isLoading: false
  161. }, () => {
  162. this.getdatalist(); // 重新加载数据
  163. });
  164. },
  165. goToGoodsList(event) {
  166. // 获取绑定的数据
  167. const item = event.currentTarget.dataset.item;
  168. // 将数据转换为 JSON 字符串并传递
  169. const itemStr = encodeURIComponent(JSON.stringify(item));
  170. wx.navigateTo({
  171. url: `/subpackagestow/details/details?item=${itemStr}`
  172. });
  173. },
  174. // previewPDF() {
  175. // wx.openDocument({
  176. // filePath: this.data.ppturl,
  177. // fileType: 'ppt',
  178. // success(res) {
  179. // console.log('打开 PDF 成功');
  180. // },
  181. // fail(err) {
  182. // console.error('打开 PDF 失败', err);
  183. // }
  184. // });
  185. // }
  186. })