UserQuickEntry.vue 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <view class="user-quick-entry">
  3. <view class="user-info">
  4. <text class="user-info-text">
  5. 👤 当前用户:{{ userName }}({{ roleName }})
  6. </text>
  7. <view class="child-switcher" v-if="children && children.length > 0" @click="showChildPicker">
  8. <text class="child-switcher-text">
  9. 切换孩子:{{ currentChildName || '选择' }} ▼
  10. </text>
  11. </view>
  12. </view>
  13. <view class="quick-actions">
  14. <view class="quick-btn" @click="$emit('scrollTo', 'tasks')">
  15. <text class="quick-btn-icon">📋</text>
  16. <text class="quick-btn-label">今日任务</text>
  17. </view>
  18. <view class="quick-btn" @click="$emit('scrollTo', 'activities')">
  19. <text class="quick-btn-icon">🔥</text>
  20. <text class="quick-btn-label">相关活动</text>
  21. </view>
  22. <view class="quick-btn" @click="$emit('scrollTo', 'products')">
  23. <text class="quick-btn-icon">🛍️</text>
  24. <text class="quick-btn-label">推荐商品</text>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. props: {
  32. userName: { type: String, default: '' },
  33. roleName: { type: String, default: '' },
  34. currentChildName: { type: String, default: '' },
  35. children: { type: Array, default: function() { return [] } }
  36. },
  37. methods: {
  38. showChildPicker: function() {
  39. var self = this
  40. var items = this.children.map(function(c) { return c.childName })
  41. uni.showActionSheet({
  42. itemList: items,
  43. success: function(res) {
  44. var child = self.children[res.tapIndex]
  45. if (child) {
  46. // FIX: 通过 Vuex store mutation 切换孩子,确保状态一致性
  47. self.$store.commit('switchToChild', child.childId)
  48. uni.setStorageSync('currentChildId', child.childId)
  49. self.$emit('childChanged', child)
  50. }
  51. }
  52. })
  53. }
  54. }
  55. }
  56. </script>
  57. <style scoped>
  58. .user-quick-entry {
  59. margin: 0 30rpx 20rpx;
  60. background: #fff;
  61. border-radius: 20rpx;
  62. padding: 20rpx 24rpx;
  63. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.04);
  64. }
  65. .user-info {
  66. display: flex;
  67. flex-direction: row;
  68. justify-content: space-between;
  69. align-items: center;
  70. margin-bottom: 16rpx;
  71. }
  72. .user-info-text { font-size: 26rpx; color: #666; }
  73. .child-switcher-text { font-size: 24rpx; color: #F97316; }
  74. .quick-actions {
  75. display: flex;
  76. flex-direction: row;
  77. }
  78. .quick-btn {
  79. flex: 1;
  80. display: flex;
  81. flex-direction: column;
  82. align-items: center;
  83. padding: 16rpx 0;
  84. background: #FFF7ED;
  85. border-radius: 16rpx;
  86. margin-right: 16rpx;
  87. }
  88. .quick-btn:last-child { margin-right: 0; }
  89. .quick-btn:active { opacity: 0.7; }
  90. .quick-btn-icon { font-size: 36rpx; margin-bottom: 6rpx; }
  91. .quick-btn-label { font-size: 22rpx; color: #666; }
  92. </style>