OnboardingGuide.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <view class="onboarding-overlay" v-if="show">
  3. <view class="onboarding-card">
  4. <!-- 顶部品牌条 -->
  5. <view class="onboarding-topbar"></view>
  6. <!-- 步骤内容 -->
  7. <view class="onboarding-content" :key="currentStep" :class="{ 'onboarding-content--intro': steps[currentStep].isIntro }">
  8. <text class="onboarding-icon">{{ steps[currentStep].icon }}</text>
  9. <text class="onboarding-title" :class="{ 'onboarding-title--intro': steps[currentStep].isIntro }">{{ steps[currentStep].title }}</text>
  10. <text class="onboarding-desc">{{ steps[currentStep].desc }}</text>
  11. </view>
  12. <!-- 步进器 -->
  13. <view class="onboarding-dots">
  14. <view
  15. v-for="(s, i) in steps"
  16. :key="i"
  17. class="dot"
  18. :class="{ active: i === currentStep }">
  19. </view>
  20. </view>
  21. <!-- 按钮 -->
  22. <view class="onboarding-action">
  23. <view
  24. class="onboarding-btn"
  25. :class="{ 'onboarding-btn--last': currentStep === steps.length - 1 }"
  26. @click="handleNext">
  27. <text>{{ currentStep < steps.length - 1 ? '下一步' : '开始体验!' }}</text>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import { getGuideConfig, ackGuideConfig } from '../utils/api.js'
  35. var PARENT_STEPS = [
  36. {
  37. icon: '🔍',
  38. title: '你真的了解家人的状态吗?',
  39. desc: '情绪低落没察觉、习惯变化没注意、能力短板没发现——什么问题等爆发了才看见。浠艾福帮你在问题发生前,看清每位家人的真实状态。',
  40. isIntro: true
  41. },
  42. {
  43. icon: '🌏',
  44. title: '五维能量,看见全家',
  45. desc: '身·心·智·行·富,一张全景图看清每位家人。谁的身体需要关注、谁的情绪需要疏导、谁的状态正在下滑——不用猜,看得见。'
  46. },
  47. {
  48. icon: '📋',
  49. title: '小行动,大改变',
  50. desc: '全家一起完成每日小任务,各自攒星星。每天一点点积累,好习惯自然养成。'
  51. },
  52. {
  53. icon: '🎁',
  54. title: '心愿墙,看得见努力',
  55. desc: '每位家人用自己的星星兑换心愿。努力有回报,全家人都能看到彼此的坚持。'
  56. }
  57. ]
  58. var CHILD_STEPS = [
  59. {
  60. icon: '🔍',
  61. title: '你的每一点努力,全家都看得见',
  62. desc: '今天完成了几个任务?比昨天进步了多少?浠艾福帮你记录每一点成长,让进步被全家看见。',
  63. isIntro: true
  64. },
  65. {
  66. icon: '🌟',
  67. title: '赚星星',
  68. desc: '完成爸爸妈妈布置的任务,就能获得星星积分,越努力越多!'
  69. },
  70. {
  71. icon: '🎮',
  72. title: '玩中学',
  73. desc: '完成任务后可以玩小游戏、兑换心愿,学习和快乐两不误!'
  74. },
  75. {
  76. icon: '🏆',
  77. title: '升级挑战',
  78. desc: '从星星宝宝到宇宙小英雄,一步步升级,看看你能走多远!'
  79. }
  80. ]
  81. export default {
  82. name: 'OnboardingGuide',
  83. props: {
  84. role: { type: String, default: 'parent' },
  85. show: { type: Boolean, default: false },
  86. position: { type: String, default: 'home' }
  87. },
  88. data() {
  89. return {
  90. currentStep: 0,
  91. _configSteps: null,
  92. _configVersion: '1.0',
  93. _configHash: ''
  94. }
  95. },
  96. created() {
  97. var self = this
  98. getGuideConfig({ position: this.position, role: this.role }).then(function(res) {
  99. var cfg = (res && res.data) ? res.data : null
  100. if (cfg) {
  101. if (cfg.parent || cfg.child) {
  102. self._configSteps = cfg
  103. self._configVersion = cfg.version || '1.0'
  104. }
  105. self._configHash = cfg.contentHash || ''
  106. }
  107. }).catch(function() {
  108. // 拉取配置失败,保持 null 走默认步骤
  109. })
  110. },
  111. computed: {
  112. steps() {
  113. if (this._configSteps) {
  114. return this.role === 'child' ? (this._configSteps.child || CHILD_STEPS) : (this._configSteps.parent || PARENT_STEPS)
  115. }
  116. if (this.role === 'child') return CHILD_STEPS
  117. return PARENT_STEPS
  118. }
  119. },
  120. watch: {
  121. show(val) {
  122. if (val) {
  123. this.currentStep = 0
  124. }
  125. }
  126. },
  127. methods: {
  128. handleNext() {
  129. if (this.currentStep < this.steps.length - 1) {
  130. this.currentStep++
  131. } else {
  132. var doneVersion = this._configVersion || '1.0'
  133. var payload = {
  134. position: this.position,
  135. role: this.role,
  136. version: doneVersion,
  137. contentHash: this._configHash || ''
  138. }
  139. // 本机兜底记录带 userId,避免同一设备多账号互相覆盖(服务端已读状态为准)
  140. uni.setStorageSync('_onboardingDone', JSON.stringify({
  141. version: doneVersion,
  142. doneAt: Date.now(),
  143. userId: uni.getStorageSync('userId') || ''
  144. }))
  145. ackGuideConfig(payload).catch(function() {
  146. // 上报失败不阻塞关闭:本机已记录,下次联网仍可被服务端纠正
  147. })
  148. this.$emit('close')
  149. }
  150. }
  151. }
  152. }
  153. </script>
  154. <style scoped lang="scss">
  155. /* ============================================================
  156. OnboardingGuide — 首次登录引导浮层
  157. 设计体系:统一使用 uni.scss design tokens
  158. ============================================================ */
  159. .onboarding-overlay {
  160. position: fixed;
  161. top: 0;
  162. left: 0;
  163. width: 100%;
  164. height: 100%;
  165. background: rgba(0, 0, 0, 0.5);
  166. display: flex;
  167. align-items: center;
  168. justify-content: center;
  169. z-index: 9998;
  170. animation: fadeIn 0.25s ease;
  171. }
  172. .onboarding-card {
  173. width: 640rpx;
  174. min-height: 680rpx;
  175. background: var(--surface, $app-surface);
  176. border-radius: var(--radius-xl, 32rpx);
  177. display: flex;
  178. flex-direction: column;
  179. align-items: center;
  180. overflow: hidden;
  181. box-shadow: var(--shadow-lg, 0 8rpx 32rpx rgba(249,115,22,0.10));
  182. animation: scaleIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  183. }
  184. /* 顶部品牌装饰条 — 暖珊瑚色 */
  185. .onboarding-topbar {
  186. width: 100%;
  187. height: 12rpx;
  188. background: var(--color-primary, $brand-primary);
  189. flex-shrink: 0;
  190. }
  191. /* ============================================================
  192. 内容区 — flex 居中,带淡入动画
  193. ============================================================ */
  194. .onboarding-content {
  195. flex: 1;
  196. display: flex;
  197. flex-direction: column;
  198. align-items: center;
  199. justify-content: center;
  200. padding: 80rpx 56rpx 48rpx;
  201. animation: fadeIn 0.3s ease;
  202. }
  203. .onboarding-icon {
  204. font-size: calc(80rpx * var(--font-scale, 1));
  205. margin-bottom: 32rpx;
  206. display: block;
  207. }
  208. .onboarding-title {
  209. font-size: calc(36rpx * var(--font-scale, 1));
  210. font-weight: 700;
  211. color: var(--text, $uni-text-color);
  212. text-align: center;
  213. margin-bottom: 20rpx;
  214. display: block;
  215. line-height: 1.3;
  216. }
  217. .onboarding-desc {
  218. font-size: calc(28rpx * var(--font-scale, 1));
  219. color: var(--text-secondary, $uni-text-color-secondary);
  220. text-align: center;
  221. line-height: 1.6;
  222. display: block;
  223. padding: 0 16rpx;
  224. }
  225. /* ============================================================
  226. 介绍步骤 — 开场身份定义页
  227. ============================================================ */
  228. .onboarding-content--intro {
  229. padding: 64rpx 56rpx 48rpx;
  230. }
  231. .onboarding-title--intro {
  232. font-size: calc(32rpx * var(--font-scale, 1));
  233. font-weight: 700;
  234. color: var(--color-primary, $brand-primary);
  235. line-height: 1.4;
  236. }
  237. /* ============================================================
  238. 步进器圆点
  239. ============================================================ */
  240. .onboarding-dots {
  241. display: flex;
  242. align-items: center;
  243. justify-content: center;
  244. gap: 16rpx;
  245. padding: 0 56rpx 40rpx;
  246. flex-shrink: 0;
  247. }
  248. .dot {
  249. width: 14rpx;
  250. height: 14rpx;
  251. border-radius: 50%;
  252. background: var(--border, $uni-border-color);
  253. transition: background 0.3s ease, transform 0.3s ease;
  254. }
  255. .dot.active {
  256. background: var(--color-primary, $brand-primary);
  257. transform: scale(1.3);
  258. }
  259. /* ============================================================
  260. 底部按钮
  261. ============================================================ */
  262. .onboarding-action {
  263. width: 100%;
  264. padding: 0 56rpx 48rpx;
  265. flex-shrink: 0;
  266. box-sizing: border-box;
  267. }
  268. .onboarding-btn {
  269. width: 100%;
  270. height: 88rpx;
  271. border-radius: 999rpx;
  272. background: var(--color-primary, $brand-primary);
  273. color: $app-surface;
  274. font-size: calc(32rpx * var(--font-scale, 1));
  275. font-weight: 700;
  276. display: flex;
  277. align-items: center;
  278. justify-content: center;
  279. transition: opacity 0.2s ease, transform 0.15s ease;
  280. box-shadow: 0 4rpx 16rpx rgba(249,115,22,0.25);
  281. }
  282. .onboarding-btn:active {
  283. opacity: 0.85;
  284. transform: scale(0.97);
  285. }
  286. /* 最后一步:暖珊瑚色按钮 */
  287. .onboarding-btn--last {
  288. background: var(--color-primary, $brand-primary);
  289. box-shadow: 0 4rpx 16rpx rgba(249, 115, 22, 0.30);
  290. }
  291. </style>