index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <template>
  2. <view class="container">
  3. <PageBanner theme="wealth"
  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">¥{{ 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{1F4B0}', label: '财商打卡', needLogin: true, page: '/pages/wealth/checkin' },
  76. { icon: '\u{1F4B5}', label: '零花钱管理', needLogin: true, page: '' },
  77. { icon: '\u{1F4C8}', label: '推广中心', needLogin: true, page: '/pages/promotion/index' },
  78. { icon: '\u{1F3E6}', label: '商城', needLogin: false, page: '/pages/shop/index' },
  79. { icon: '\u{1F4CB}', label: '保单管理', needLogin: true, page: '/pages/wealth/insurance-list' }
  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: 49, image: '' },
  90. { id: 4, name: '少儿财商课程', price: 399, 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. if (!uni.getStorageSync('token')) {
  111. this.visibleSections = ['func_entries', 'hot_activities', 'recommended_products']
  112. return
  113. }
  114. var role = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || null
  115. try {
  116. var res = await getVisibleSections({ pageKey: 'wealth', role: role })
  117. if (res.code === 200 && res.data) {
  118. this.visibleSections = res.data.map(function(s) { return s.sectionKey })
  119. }
  120. } catch (e) {
  121. this.visibleSections = ['func_entries', 'hot_activities', 'recommended_products']
  122. }
  123. },
  124. async loadEnergyData() {
  125. var childId = this.currentChildId
  126. if (!childId) return
  127. try {
  128. var res = await getEnergyOverview(childId)
  129. if (res && res.data) {
  130. this.totalEnergy = res.data.totalEnergy || 0
  131. }
  132. } catch (e) { console.log('获取能量概览失败', e) }
  133. },
  134. async loadTodayTasks() {
  135. var childId = this.currentChildId
  136. if (!childId) return
  137. try {
  138. var res = await getTodayTasks(childId)
  139. if (res && res.data) {
  140. this.todayTasks = res.data.slice(0, 5)
  141. }
  142. } catch (e) { console.log('获取今日任务失败', e) }
  143. },
  144. sectionVisible(key) {
  145. return this.visibleSections.length === 0 || this.visibleSections.indexOf(key) !== -1
  146. },
  147. onFuncClick(item) {
  148. if (item.needLogin && !this.isLoggedIn) {
  149. uni.showModal({
  150. title: '提示',
  151. content: '请先登录后使用此功能',
  152. success: function(res) { if (res.confirm) uni.navigateTo({ url: '/pages/login/login' }) }
  153. })
  154. return
  155. }
  156. if (item.page) {
  157. var nativeTabs = ['/pages/tasks/tasks', '/pages/index/index', '/pages/body/index', '/pages/mind/index', '/pages/action/index', '/pages/wisdom/index', '/pages/profile/profile']
  158. if (nativeTabs.indexOf(item.page) !== -1) {
  159. uni.switchTab({ url: item.page })
  160. } else {
  161. uni.navigateTo({ url: item.page })
  162. }
  163. }
  164. },
  165. goMoreActivities() {},
  166. goActivityDetail(id) {},
  167. goMoreProducts() {},
  168. goProductDetail(id) {
  169. var token = uni.getStorageSync('token')
  170. if (token) {
  171. uni.navigateTo({ url: '/pages/discover/product-detail/product-detail?id=' + id })
  172. } else {
  173. uni.navigateTo({ url: '/pages/login/login?redirect=' + encodeURIComponent('/pages/wealth/index') })
  174. }
  175. },
  176. goTasks() { uni.switchTab({ url: '/pages/tasks/tasks' }) },
  177. goLogin() { uni.navigateTo({ url: '/pages/login/login' }) }
  178. }
  179. }
  180. </script>
  181. <style scoped>
  182. .container {
  183. min-height: 100vh;
  184. background: #f5f7fa;
  185. padding-bottom: 120rpx;
  186. }
  187. .func-section {
  188. margin: -40rpx 20rpx 0;
  189. position: relative;
  190. z-index: 2;
  191. }
  192. .func-grid {
  193. background: #fff;
  194. border-radius: 24rpx;
  195. padding: 30rpx 16rpx;
  196. display: flex;
  197. box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.06);
  198. }
  199. .func-item {
  200. flex: 1;
  201. display: flex;
  202. flex-direction: column;
  203. align-items: center;
  204. }
  205. .func-item:active {
  206. opacity: 0.7;
  207. }
  208. .func-icon-wrap {
  209. width: 88rpx;
  210. height: 88rpx;
  211. border-radius: 50%;
  212. background: #E3F2FD;
  213. display: flex;
  214. align-items: center;
  215. justify-content: center;
  216. margin-bottom: 10rpx;
  217. }
  218. .func-icon {
  219. font-size: 40rpx;
  220. }
  221. .func-label {
  222. font-size: 24rpx;
  223. color: #333;
  224. font-weight: 500;
  225. }
  226. .section {
  227. margin: 20rpx 20rpx;
  228. }
  229. .section-header {
  230. display: flex;
  231. justify-content: space-between;
  232. align-items: center;
  233. margin-bottom: 20rpx;
  234. }
  235. .section-title {
  236. font-size: 30rpx;
  237. font-weight: bold;
  238. color: #333;
  239. }
  240. .section-more {
  241. font-size: 24rpx;
  242. color: #999;
  243. }
  244. .activity-scroll {
  245. white-space: nowrap;
  246. }
  247. .activity-card {
  248. display: inline-block;
  249. width: 280rpx;
  250. margin-right: 20rpx;
  251. background: #fff;
  252. border-radius: 16rpx;
  253. overflow: hidden;
  254. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  255. }
  256. .activity-img {
  257. width: 280rpx;
  258. height: 180rpx;
  259. background: #f0f0f0;
  260. }
  261. .activity-info {
  262. padding: 16rpx;
  263. }
  264. .activity-name {
  265. font-size: 26rpx;
  266. font-weight: bold;
  267. color: #333;
  268. display: block;
  269. }
  270. .activity-meta {
  271. font-size: 22rpx;
  272. color: #999;
  273. margin-top: 8rpx;
  274. display: block;
  275. }
  276. .product-list {
  277. display: flex;
  278. flex-wrap: wrap;
  279. gap: 20rpx;
  280. }
  281. .product-card {
  282. width: calc(50% - 10rpx);
  283. background: #fff;
  284. border-radius: 16rpx;
  285. overflow: hidden;
  286. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  287. }
  288. .product-img {
  289. width: 100%;
  290. height: 240rpx;
  291. background: #f0f0f0;
  292. }
  293. .product-name {
  294. font-size: 26rpx;
  295. color: #333;
  296. padding: 12rpx 16rpx 0;
  297. }
  298. .product-price {
  299. font-size: 28rpx;
  300. color: #F97316;
  301. font-weight: bold;
  302. padding: 8rpx 16rpx 16rpx;
  303. display: block;
  304. }
  305. .line-clamp-2 {
  306. overflow: hidden;
  307. text-overflow: ellipsis;
  308. display: -webkit-box;
  309. -webkit-line-clamp: 2;
  310. -webkit-box-orient: vertical;
  311. }
  312. .task-wrap {
  313. background: #fff;
  314. border-radius: 16rpx;
  315. overflow: hidden;
  316. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  317. }
  318. .task-item {
  319. display: flex;
  320. justify-content: space-between;
  321. padding: 28rpx 24rpx;
  322. border-bottom: 1rpx solid #f0f0f0;
  323. }
  324. .task-item:last-child {
  325. border-bottom: none;
  326. }
  327. .task-name {
  328. font-size: 26rpx;
  329. color: #333;
  330. }
  331. .task-points {
  332. font-size: 24rpx;
  333. color: #F97316;
  334. }
  335. .task-empty {
  336. background: #fff;
  337. border-radius: 16rpx;
  338. padding: 60rpx;
  339. text-align: center;
  340. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  341. }
  342. .task-empty-text {
  343. font-size: 26rpx;
  344. color: #999;
  345. }
  346. .bottom-spacer {
  347. height: 20rpx;
  348. }
  349. </style>