index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <view class="container">
  3. <PageBanner theme="wisdom"
  4. tagline="学以启智 · 慧及未来"
  5. quote="知者不惑,仁者不忧" />
  6. <view class="section" v-if="sectionVisible('today_tasks') && isLoggedIn">
  7. <view class="section-header">
  8. <text class="section-title">📋 我的任务</text>
  9. <text class="section-more" @click="goTasks">全部 ›</text>
  10. </view>
  11. <view class="task-wrap" v-if="todayTasks.length > 0">
  12. <view class="task-item" v-for="task in todayTasks" :key="task.id">
  13. <text class="task-name">{{ task.title }}</text>
  14. <text class="task-points">+{{ task.points || 0 }}分</text>
  15. </view>
  16. </view>
  17. <view class="task-empty" v-else>
  18. <text class="task-empty-text">今日暂无任务</text>
  19. </view>
  20. </view>
  21. <view class="func-section" v-if="sectionVisible('func_entries')">
  22. <view class="func-grid">
  23. <view class="func-item" v-for="item in funcList" :key="item.label" @click="onFuncClick(item)">
  24. <view class="func-icon-wrap">
  25. <text class="func-icon">{{ item.icon }}</text>
  26. </view>
  27. <text class="func-label">{{ item.label }}</text>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="section" v-if="sectionVisible('hot_activities')">
  32. <view class="section-header">
  33. <text class="section-title">🔥 热门活动</text>
  34. <text class="section-more" @click="goMoreActivities">更多 ›</text>
  35. </view>
  36. <scroll-view scroll-x class="activity-scroll" show-scrollbar="false">
  37. <view class="activity-card" v-for="act in hotActivities" :key="act.id" @click="goActivityDetail(act.id)">
  38. <image class="activity-img" :src="act.image || '/static/default-activity.png'" mode="aspectFill" />
  39. <view class="activity-info">
  40. <text class="activity-name">{{ act.name }}</text>
  41. <text class="activity-meta">{{ act.date }} · {{ act.location }}</text>
  42. </view>
  43. </view>
  44. </scroll-view>
  45. </view>
  46. <view class="section" v-if="sectionVisible('recommended_products')">
  47. <view class="section-header">
  48. <text class="section-title">🛍️ 推荐商品</text>
  49. <text class="section-more" @click="goMoreProducts">更多 ›</text>
  50. </view>
  51. <view class="product-list">
  52. <view class="product-card" v-for="prod in recommendedProducts" :key="prod.id" @click="goProductDetail(prod.id)">
  53. <image class="product-img" :src="prod.image || '/static/default-product.png'" mode="aspectFill" />
  54. <text class="product-name line-clamp-2">{{ prod.name }}</text>
  55. <text class="product-price">{{ formatPriceWithSymbol(prod.price) }}</text>
  56. </view>
  57. </view>
  58. </view>
  59. <view class="bottom-spacer"></view>
  60. </view>
  61. </template>
  62. <script>
  63. import PageBanner from '../../components/PageBanner.vue'
  64. import { getVisibleSections, getEnergyOverview, getTodayTasks } from '../../utils/api.js'
  65. export default {
  66. components: { PageBanner },
  67. data() {
  68. return {
  69. isLoggedIn: false,
  70. role: null,
  71. currentChildId: null,
  72. totalEnergy: null,
  73. visibleSections: [],
  74. funcList: [
  75. { icon: '\u{1F4DA}', label: '学习任务', needLogin: true, page: '/pages/tasks/tasks' },
  76. { icon: '\u{1F3AE}', label: '小游戏', needLogin: false, page: '/pages/games/list' },
  77. { icon: '\u{1F9E9}', label: '测评中心', needLogin: false, page: '/pages/assessment/apply' },
  78. { icon: '\u{1F4D6}', label: '阅读天地', needLogin: false, page: '/pages/mind/articles' },
  79. { icon: '\u{1F4A1}', label: '知识挑战', needLogin: false, page: '' }
  80. ],
  81. hotActivities: [
  82. { id: 1, name: '少儿编程启蒙营', date: '周六', location: '线上', image: '' },
  83. { id: 2, name: '经典阅读分享会', date: '周日', location: '浠艾福中心', image: '' },
  84. { id: 3, name: '科学实验探索课', date: '下周六', location: '浠艾福中心', image: '' }
  85. ],
  86. recommendedProducts: [
  87. { id: 1, name: '儿童百科全书套装', price: 199, image: '' },
  88. { id: 2, name: '益智棋类礼盒', price: 159, image: '' },
  89. { id: 3, name: '科学实验套装', price: 299, image: '' },
  90. { id: 4, name: '中外名著精选', price: 129, image: '' }
  91. ],
  92. todayTasks: []
  93. }
  94. },
  95. onShow() {
  96. var token = uni.getStorageSync('token')
  97. this.isLoggedIn = !!token
  98. if (this.isLoggedIn) {
  99. this.role = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || null
  100. this.currentChildId = uni.getStorageSync('currentChildId') || null
  101. }
  102. this.loadSectionConfig()
  103. if (this.isLoggedIn) {
  104. this.loadEnergyData()
  105. this.loadTodayTasks()
  106. }
  107. },
  108. methods: {
  109. async loadSectionConfig() {
  110. var baseSections = ['func_entries', 'hot_activities', 'recommended_products']
  111. if (!uni.getStorageSync('token')) {
  112. this.visibleSections = baseSections
  113. return
  114. }
  115. var role = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || null
  116. try {
  117. var res = await getVisibleSections({ pageKey: 'wisdom', role: role })
  118. if (res.code === 200 && res.data) {
  119. var keys = res.data.map(function(s) { return s.sectionKey })
  120. var merged = baseSections.slice()
  121. keys.forEach(function(k) { if (merged.indexOf(k) === -1) merged.push(k) })
  122. this.visibleSections = merged
  123. }
  124. } catch (e) {
  125. this.visibleSections = ['func_entries', 'hot_activities', 'recommended_products']
  126. }
  127. },
  128. async loadEnergyData() {
  129. var childId = this.currentChildId
  130. if (!childId) return
  131. try {
  132. var res = await getEnergyOverview(childId)
  133. if (res && res.data) {
  134. this.totalEnergy = res.data.totalEnergy || 0
  135. }
  136. } catch (e) { console.log('获取能量概览失败', e) }
  137. },
  138. async loadTodayTasks() {
  139. var childId = this.currentChildId
  140. if (!childId) return
  141. try {
  142. var res = await getTodayTasks(childId)
  143. if (res && res.data) {
  144. this.todayTasks = res.data.slice(0, 5)
  145. }
  146. } catch (e) { console.log('获取今日任务失败', e) }
  147. },
  148. sectionVisible(key) {
  149. return this.visibleSections.length === 0 || this.visibleSections.indexOf(key) !== -1
  150. },
  151. onFuncClick(item) {
  152. if (item.needLogin && !this.isLoggedIn) {
  153. uni.showModal({
  154. title: '提示',
  155. content: '请先登录后使用此功能',
  156. success: function(res) { if (res.confirm) uni.navigateTo({ url: '/pages/login/login' }) }
  157. })
  158. return
  159. }
  160. if (item.page) {
  161. var nativeTabs = ['/pages/tasks/tasks', '/pages/index/index', '/pages/body/index', '/pages/mind/index', '/pages/action/index', '/pages/wisdom/index', '/pages/profile/profile']
  162. if (nativeTabs.indexOf(item.page) !== -1) {
  163. uni.switchTab({ url: item.page })
  164. } else {
  165. uni.navigateTo({ url: item.page })
  166. }
  167. }
  168. },
  169. goMoreActivities() {},
  170. goActivityDetail(id) {},
  171. goMoreProducts() {},
  172. goProductDetail(id) {
  173. var token = uni.getStorageSync('token')
  174. if (token) {
  175. uni.navigateTo({ url: '/pages/discover/product-detail/product-detail?id=' + id })
  176. } else {
  177. uni.navigateTo({ url: '/pages/login/login?redirect=' + encodeURIComponent('/pages/wisdom/index') })
  178. }
  179. },
  180. goTasks() { uni.switchTab({ url: '/pages/tasks/tasks' }) },
  181. goLogin() { uni.navigateTo({ url: '/pages/login/login' }) }
  182. }
  183. }
  184. </script>
  185. <style scoped>
  186. .container {
  187. min-height: 100vh;
  188. background: #f5f7fa;
  189. padding-bottom: 120rpx;
  190. }
  191. .func-section {
  192. margin: -40rpx 20rpx 0;
  193. position: relative;
  194. z-index: 2;
  195. }
  196. .func-grid {
  197. background: #fff;
  198. border-radius: 24rpx;
  199. padding: 30rpx 16rpx;
  200. display: flex;
  201. box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.06);
  202. }
  203. .func-item {
  204. flex: 1;
  205. display: flex;
  206. flex-direction: column;
  207. align-items: center;
  208. }
  209. .func-item:active {
  210. opacity: 0.7;
  211. }
  212. .func-icon-wrap {
  213. width: 88rpx;
  214. height: 88rpx;
  215. border-radius: 50%;
  216. background: #FFF8E1;
  217. display: flex;
  218. align-items: center;
  219. justify-content: center;
  220. margin-bottom: 10rpx;
  221. }
  222. .func-icon {
  223. font-size: 40rpx;
  224. }
  225. .func-label {
  226. font-size: 24rpx;
  227. color: #333;
  228. font-weight: 500;
  229. }
  230. .section {
  231. margin: 20rpx 20rpx;
  232. }
  233. .section-header {
  234. display: flex;
  235. justify-content: space-between;
  236. align-items: center;
  237. margin-bottom: 20rpx;
  238. }
  239. .section-title {
  240. font-size: 30rpx;
  241. font-weight: bold;
  242. color: #333;
  243. }
  244. .section-more {
  245. font-size: 24rpx;
  246. color: #999;
  247. }
  248. .activity-scroll {
  249. white-space: nowrap;
  250. }
  251. .activity-card {
  252. display: inline-block;
  253. width: 280rpx;
  254. margin-right: 20rpx;
  255. background: #fff;
  256. border-radius: 16rpx;
  257. overflow: hidden;
  258. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  259. }
  260. .activity-img {
  261. width: 280rpx;
  262. height: 180rpx;
  263. background: #f0f0f0;
  264. }
  265. .activity-info {
  266. padding: 16rpx;
  267. }
  268. .activity-name {
  269. font-size: 26rpx;
  270. font-weight: bold;
  271. color: #333;
  272. display: block;
  273. }
  274. .activity-meta {
  275. font-size: 22rpx;
  276. color: #999;
  277. margin-top: 8rpx;
  278. display: block;
  279. }
  280. .product-list {
  281. display: flex;
  282. flex-wrap: wrap;
  283. gap: 20rpx;
  284. }
  285. .product-card {
  286. width: calc(50% - 10rpx);
  287. background: #fff;
  288. border-radius: 16rpx;
  289. overflow: hidden;
  290. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  291. }
  292. .product-img {
  293. width: 100%;
  294. height: 240rpx;
  295. background: #f0f0f0;
  296. }
  297. .product-name {
  298. font-size: 26rpx;
  299. color: #333;
  300. padding: 12rpx 16rpx 0;
  301. }
  302. .product-price {
  303. font-size: 28rpx;
  304. color: #F97316;
  305. font-weight: bold;
  306. padding: 8rpx 16rpx 16rpx;
  307. display: block;
  308. }
  309. .line-clamp-2 {
  310. overflow: hidden;
  311. text-overflow: ellipsis;
  312. display: -webkit-box;
  313. -webkit-line-clamp: 2;
  314. -webkit-box-orient: vertical;
  315. }
  316. .task-wrap {
  317. background: #fff;
  318. border-radius: 16rpx;
  319. overflow: hidden;
  320. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  321. }
  322. .task-item {
  323. display: flex;
  324. justify-content: space-between;
  325. padding: 28rpx 24rpx;
  326. border-bottom: 1rpx solid #f0f0f0;
  327. }
  328. .task-item:last-child {
  329. border-bottom: none;
  330. }
  331. .task-name {
  332. font-size: 26rpx;
  333. color: #333;
  334. }
  335. .task-points {
  336. font-size: 24rpx;
  337. color: #F97316;
  338. }
  339. .task-empty {
  340. background: #fff;
  341. border-radius: 16rpx;
  342. padding: 60rpx;
  343. text-align: center;
  344. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  345. }
  346. .task-empty-text {
  347. font-size: 26rpx;
  348. color: #999;
  349. }
  350. .bottom-spacer {
  351. height: 20rpx;
  352. }
  353. </style>