index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. <template>
  2. <view class="container">
  3. <!-- 品牌头部 -->
  4. <PageBanner theme="action"
  5. tagline="知行合一 · 快乐成长"
  6. quote="千里之行,始于足下" />
  7. <!-- 家庭成员切换条 -->
  8. <FamilyMemberStrip
  9. v-if="isLoggedIn && familyMembersVisible.length > 0"
  10. :members="familyMembersVisible"
  11. :selectedMemberId="selectedMemberId"
  12. :selectedMemberType="selectedMemberType"
  13. @select="onMemberSelect" />
  14. <!-- 游客登录引导卡 -->
  15. <template v-if="!isLoggedIn">
  16. <LoginGuideCard
  17. title="登录后查看任务和活动记录"
  18. :items="[
  19. '查看今日任务,完成打卡获取行动能量',
  20. '报名参加热门活动,记录成长足迹',
  21. '查看专属商品和活动价格'
  22. ]" />
  23. </template>
  24. <!-- 登录后:五维能量条 -->
  25. <FamilyEnergyBar
  26. v-if="isLoggedIn"
  27. dimensionCode="action"
  28. :sandboxData="sandboxData"
  29. :dualDimension="dualDimension" />
  30. <!-- 登录后:用户快捷入口 -->
  31. <UserQuickEntry
  32. v-if="isLoggedIn"
  33. :userName="userName"
  34. roleName="家长"
  35. :currentChildName="currentChildName"
  36. :children="children"
  37. @childChanged="onChildChanged"
  38. @scrollTo="scrollToSection" />
  39. <!-- ===== 维度任务/活动/商品 ===== -->
  40. <DimensionTasks
  41. v-if="isLoggedIn"
  42. dimensionCode="action"
  43. :tasks="dimensionTasks"
  44. @taskClick="onTaskClick"
  45. @moreTasks="goTasks" />
  46. <DimensionActivities
  47. v-if="isLoggedIn"
  48. dimensionCode="action"
  49. :activities="dimensionActivities"
  50. @activityClick="goActivityDetail"
  51. @moreActivities="goMoreActivities" />
  52. <DimensionProducts
  53. v-if="isLoggedIn"
  54. dimensionCode="action"
  55. :products="dimensionProducts"
  56. @productClick="goProductDetail"
  57. @moreProducts="goMoreProducts" />
  58. <!-- ===== 重要关系维护 ===== -->
  59. <view class="contact-section" v-if="isLoggedIn">
  60. <view class="contact-header">
  61. <text class="contact-section-title">重要关系</text>
  62. <view class="contact-header-right">
  63. <text class="contact-more" @click="loadContacts">刷新</text>
  64. <text class="contact-import-btn" @click="onShowImport">+ 导入</text>
  65. </view>
  66. </view>
  67. <scroll-view class="contact-scroll" scroll-x enable-flex>
  68. <view class="contact-scroll-inner">
  69. <view class="contact-card-wrap" v-for="item in contactList" :key="item.id" @click="onContactClick(item)">
  70. <ContactCard :contact="item" />
  71. </view>
  72. <view class="contact-card-wrap contact-add-card" @click="onShowImport">
  73. <view class="add-card-inner">
  74. <text class="add-card-icon">+</text>
  75. <text class="add-card-label">导入通讯录</text>
  76. </view>
  77. </view>
  78. </view>
  79. </scroll-view>
  80. <view class="contact-empty" v-if="contactList.length === 0">
  81. <text class="contact-empty-text">暂无重要联系人,点击导入添加</text>
  82. </view>
  83. </view>
  84. <!-- 功能入口(4个:活动、商品、课程) -->
  85. <view class="func-section" v-if="sectionVisible('func_entries')">
  86. <view class="func-grid">
  87. <view class="func-item" v-for="item in funcList" :key="item.label" @click="onFuncClick(item)">
  88. <view class="func-icon-wrap">
  89. <text class="func-icon">{{ item.icon }}</text>
  90. </view>
  91. <text class="func-label">{{ item.label }}</text>
  92. </view>
  93. </view>
  94. </view>
  95. <!-- 导入联系人弹窗 -->
  96. <ContactImport
  97. :visible="showImportModal"
  98. @close="onCloseImport"
  99. @success="onImportSuccess" />
  100. <!-- 底部占位 -->
  101. <view class="bottom-spacer"></view>
  102. </view>
  103. </template>
  104. <script>
  105. import PageBanner from '../../components/PageBanner.vue'
  106. import LoginGuideCard from '../../components/LoginGuideCard.vue'
  107. import FamilyEnergyBar from '../../components/FamilyEnergyBar.vue'
  108. import UserQuickEntry from '../../components/UserQuickEntry.vue'
  109. import DimensionTasks from '../../components/DimensionTasks.vue'
  110. import DimensionActivities from '../../components/DimensionActivities.vue'
  111. import DimensionProducts from '../../components/DimensionProducts.vue'
  112. import ContactCard from '../../components/ContactCard.vue'
  113. import ContactImport from '../../components/ContactImport.vue'
  114. import FamilyMemberStrip from '../../components/FamilyMemberStrip.vue'
  115. import { getVisibleSections, getEnergyOverview, getFamilyEnergySandbox, getTodayTasksByCategory, getActivityList, getProductsByDomain, getChildren, getContactList, getVisibleFamilyMembers } from '../../utils/api.js'
  116. export default {
  117. components: { PageBanner, LoginGuideCard, FamilyEnergyBar, UserQuickEntry, DimensionTasks, DimensionActivities, DimensionProducts, ContactCard, ContactImport, FamilyMemberStrip },
  118. data() {
  119. return {
  120. isLoggedIn: false,
  121. role: null,
  122. currentChildId: null,
  123. currentChildName: '',
  124. userName: '',
  125. children: [],
  126. familyMembersVisible: [],
  127. selectedMemberId: 0,
  128. selectedMemberType: 'all',
  129. sandboxData: null,
  130. dualDimension: null,
  131. visibleSections: [],
  132. dimensionTasks: [],
  133. dimensionActivities: [],
  134. dimensionProducts: [],
  135. contactList: [],
  136. showImportModal: false,
  137. funcList: [
  138. { icon: '\u{1F3CB}', label: '任务', needLogin: true, page: '/pages/tasks/tasks' },
  139. { icon: '\u{1F3C0}', label: '活动', needLogin: false, page: '/pages/discover/index?type=activity' },
  140. { icon: '\u{1F6CD}', label: '商城', needLogin: false, page: '/pages/shop/index' },
  141. { icon: '\u{1F3EB}', label: '课程', needLogin: false, page: '/pages/discover/index?type=course' }
  142. ]
  143. }
  144. },
  145. onShow() {
  146. var token = uni.getStorageSync('token')
  147. this.isLoggedIn = !!token
  148. if (this.isLoggedIn) {
  149. this.role = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || null
  150. this.currentChildId = uni.getStorageSync('currentChildId') || null
  151. this.userName = uni.getStorageSync('nickname') || uni.getStorageSync('userName') || '家长'
  152. }
  153. this.loadSectionConfig()
  154. if (this.isLoggedIn) {
  155. this.loadChildren()
  156. this.loadFamilyMembersVisible()
  157. }
  158. },
  159. methods: {
  160. loadSectionConfig: function() {
  161. var self = this
  162. var baseSections = ['func_entries']
  163. if (!uni.getStorageSync('token')) {
  164. self.visibleSections = baseSections
  165. return
  166. }
  167. var role = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || null
  168. getVisibleSections({ pageKey: 'action', role: role }).then(function(res) {
  169. if (res.code === 200 && res.data) {
  170. var keys = res.data.map(function(s) { return s.sectionKey })
  171. var merged = baseSections.slice()
  172. keys.forEach(function(k) { if (merged.indexOf(k) === -1) merged.push(k) })
  173. self.visibleSections = merged
  174. }
  175. }).catch(function() {
  176. self.visibleSections = ['func_entries']
  177. })
  178. },
  179. loadChildren: function() {
  180. var self = this
  181. getChildren().then(function(res) {
  182. if (res.code === 200 && res.data) {
  183. self.children = res.data
  184. var savedChildId = uni.getStorageSync('currentChildId')
  185. var found = false
  186. for (var i = 0; i < self.children.length; i++) {
  187. if (self.children[i].childId === savedChildId) {
  188. self.currentChildId = savedChildId
  189. self.currentChildName = self.children[i].name || self.children[i].nickname || '孩子'
  190. found = true
  191. break
  192. }
  193. }
  194. if (!found && self.children.length > 0) {
  195. self.currentChildId = self.children[0].childId
  196. self.currentChildName = self.children[0].name || self.children[0].nickname || '孩子'
  197. uni.setStorageSync('currentChildId', self.currentChildId)
  198. }
  199. if (self.currentChildId) {
  200. self.loadDimensionData()
  201. }
  202. self.loadContacts()
  203. }
  204. }).catch(function(e) {
  205. console.log('获取孩子列表失败', e)
  206. })
  207. },
  208. loadDimensionData: function() {
  209. this.loadEnergyData()
  210. this.loadSandboxData()
  211. this.loadDimensionTasks()
  212. this.loadDimensionActivities()
  213. this.loadDimensionProducts()
  214. },
  215. loadEnergyData: function() {
  216. var self = this
  217. if (!this.currentChildId) return
  218. getEnergyOverview(this.currentChildId).then(function(res) {
  219. if (res && res.data) {
  220. var dims = res.data.dimensions
  221. if (dims && dims.length > 0) {
  222. for (var i = 0; i < dims.length; i++) {
  223. if (dims[i].code === 'action') {
  224. self.dualDimension = dims[i]
  225. break
  226. }
  227. }
  228. }
  229. }
  230. }).catch(function(e) {
  231. console.log('获取能量概览失败', e)
  232. })
  233. },
  234. loadSandboxData: function() {
  235. var self = this
  236. getFamilyEnergySandbox().then(function(res) {
  237. if (res && res.data) {
  238. self.sandboxData = res.data
  239. }
  240. }).catch(function() {})
  241. },
  242. loadDimensionTasks: function() {
  243. var self = this
  244. if (!this.currentChildId) return
  245. getTodayTasksByCategory(this.currentChildId, 'action').then(function(res) {
  246. if (res && res.data) {
  247. self.dimensionTasks = Array.isArray(res.data) ? res.data.slice(0, 5) : []
  248. }
  249. }).catch(function() { self.dimensionTasks = [] })
  250. },
  251. loadDimensionActivities: function() {
  252. var self = this
  253. getActivityList({ dimensionCode: 'action', page: 1, size: 3 }).then(function(res) {
  254. if (res && res.data) {
  255. var list = Array.isArray(res.data) ? res.data : (res.data.records || [])
  256. self.dimensionActivities = list.slice(0, 3)
  257. }
  258. }).catch(function() { self.dimensionActivities = [] })
  259. },
  260. loadDimensionProducts: function() {
  261. var self = this
  262. getProductsByDomain('action', 1, 4).then(function(res) {
  263. if (res && res.data) {
  264. var list = Array.isArray(res.data) ? res.data : (res.data.records || [])
  265. self.dimensionProducts = list.slice(0, 4)
  266. }
  267. }).catch(function() { self.dimensionProducts = [] })
  268. },
  269. loadContacts: function() {
  270. var self = this
  271. getContactList({}).then(function(res) {
  272. if (res.code === 200 && res.data) {
  273. self.contactList = Array.isArray(res.data) ? res.data : []
  274. }
  275. }).catch(function(e) {
  276. console.log('获取联系人失败', e)
  277. })
  278. },
  279. onContactClick: function(item) {
  280. uni.navigateTo({ url: '/pages/action/contact-detail?id=' + item.id })
  281. },
  282. onShowImport: function() {
  283. this.showImportModal = true
  284. },
  285. onCloseImport: function() {
  286. this.showImportModal = false
  287. },
  288. onImportSuccess: function() {
  289. this.showImportModal = false
  290. this.loadContacts()
  291. },
  292. onChildChanged: function(child) {
  293. this.currentChildId = child.childId
  294. this.currentChildName = child.name || child.nickname || '孩子'
  295. uni.setStorageSync('currentChildId', child.childId)
  296. this.loadDimensionData()
  297. },
  298. loadFamilyMembersVisible: function() {
  299. var self = this
  300. getVisibleFamilyMembers().then(function(res) {
  301. self.familyMembersVisible = res.data || []
  302. }).catch(function(e) {
  303. console.log('获取可见家庭成员失败', e)
  304. self.familyMembersVisible = []
  305. })
  306. },
  307. onMemberSelect: function(member) {
  308. if (member.memberType === 'all') {
  309. this.selectedMemberId = 0
  310. this.selectedMemberType = 'all'
  311. } else {
  312. this.selectedMemberId = member.id
  313. this.selectedMemberType = member.memberType
  314. }
  315. // TODO: 根据选中成员重新加载对应维度数据
  316. },
  317. scrollToSection: function(section) {
  318. uni.pageScrollTo({ selector: '#' + section, duration: 300 })
  319. },
  320. sectionVisible: function(key) {
  321. return this.visibleSections.length === 0 || this.visibleSections.indexOf(key) !== -1
  322. },
  323. onTaskClick: function(task) {
  324. uni.navigateTo({ url: '/pages/tasks/tasks' })
  325. },
  326. goActivityDetail: function(act) {
  327. if (act && act.id) uni.navigateTo({ url: '/pages/discover/index?type=activity&id=' + act.id })
  328. },
  329. goMoreActivities: function() {
  330. uni.navigateTo({ url: '/pages/discover/index?type=activity&dimension=action' })
  331. },
  332. goProductDetail: function(prod) {
  333. if (prod && prod.id) uni.navigateTo({ url: '/pages/discover/product-detail/product-detail?id=' + prod.id })
  334. },
  335. goMoreProducts: function() {
  336. uni.navigateTo({ url: '/pages/discover/index?type=product&domain=action' })
  337. },
  338. onFuncClick: function(item) {
  339. if (item.needLogin && !this.isLoggedIn) {
  340. uni.showModal({
  341. title: '提示',
  342. content: '请先登录后使用此功能',
  343. success: function(res) { if (res.confirm) uni.navigateTo({ url: '/pages/login/login' }) }
  344. })
  345. return
  346. }
  347. if (item.page) {
  348. var nativeTabs = ['/pages/tasks/tasks', '/pages/index/index', '/pages/body/index', '/pages/mind/index', '/pages/action/index', '/pages/profile/profile']
  349. if (nativeTabs.indexOf(item.page) !== -1) {
  350. uni.switchTab({ url: item.page })
  351. } else {
  352. uni.navigateTo({ url: item.page })
  353. }
  354. }
  355. },
  356. goTasks: function() { uni.switchTab({ url: '/pages/tasks/tasks' }) },
  357. goLogin: function() { uni.navigateTo({ url: '/pages/login/login' }) }
  358. }
  359. }
  360. </script>
  361. <style scoped>
  362. .container {
  363. min-height: 100vh;
  364. background: #f5f7fa;
  365. padding-bottom: 120rpx;
  366. }
  367. /* ===== 功能入口 ===== */
  368. .func-section {
  369. margin: -40rpx 20rpx 0;
  370. position: relative;
  371. z-index: 2;
  372. }
  373. .func-grid {
  374. background: #fff;
  375. border-radius: 24rpx;
  376. padding: 30rpx 16rpx;
  377. display: flex;
  378. box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.06);
  379. }
  380. .func-item {
  381. flex: 1;
  382. display: flex;
  383. flex-direction: column;
  384. align-items: center;
  385. }
  386. .func-item:active {
  387. opacity: 0.7;
  388. }
  389. .func-icon-wrap {
  390. width: 88rpx;
  391. height: 88rpx;
  392. border-radius: 50%;
  393. background: #FFF7ED;
  394. display: flex;
  395. align-items: center;
  396. justify-content: center;
  397. margin-bottom: 10rpx;
  398. }
  399. .func-icon {
  400. font-size: 40rpx;
  401. }
  402. .func-label {
  403. font-size: 24rpx;
  404. color: #333;
  405. font-weight: 500;
  406. }
  407. /* ===== 重要关系 ===== */
  408. .contact-section {
  409. margin: 20rpx 20rpx 0;
  410. }
  411. .contact-header {
  412. display: flex;
  413. justify-content: space-between;
  414. align-items: center;
  415. margin-bottom: 16rpx;
  416. }
  417. .contact-section-title {
  418. font-size: 30rpx;
  419. font-weight: 600;
  420. color: #333;
  421. }
  422. .contact-header-right {
  423. display: flex;
  424. gap: 16rpx;
  425. align-items: center;
  426. }
  427. .contact-more {
  428. font-size: 24rpx;
  429. color: #999;
  430. }
  431. .contact-import-btn {
  432. font-size: 24rpx;
  433. color: #F97316;
  434. font-weight: 500;
  435. }
  436. .contact-scroll {
  437. white-space: nowrap;
  438. overflow: hidden;
  439. }
  440. .contact-scroll-inner {
  441. display: flex;
  442. flex-direction: row;
  443. gap: 16rpx;
  444. padding: 8rpx 0 16rpx;
  445. }
  446. .contact-card-wrap {
  447. flex-shrink: 0;
  448. width: 220rpx;
  449. }
  450. .contact-card-wrap:active {
  451. opacity: 0.8;
  452. }
  453. .contact-add-card {
  454. width: 160rpx;
  455. }
  456. .add-card-inner {
  457. width: 160rpx;
  458. height: 280rpx;
  459. background: #fff;
  460. border-radius: 16rpx;
  461. border: 2rpx dashed #ddd;
  462. display: flex;
  463. flex-direction: column;
  464. align-items: center;
  465. justify-content: center;
  466. gap: 12rpx;
  467. }
  468. .add-card-icon {
  469. font-size: 48rpx;
  470. color: #ccc;
  471. }
  472. .add-card-label {
  473. font-size: 22rpx;
  474. color: #999;
  475. }
  476. .contact-empty {
  477. padding: 40rpx 0;
  478. text-align: center;
  479. }
  480. .contact-empty-text {
  481. font-size: 26rpx;
  482. color: #ccc;
  483. }
  484. /* ===== 底部 ===== */
  485. .bottom-spacer {
  486. height: 20rpx;
  487. }
  488. </style>