• 思路
      • 首次启动展示引导页,之后启动不再展示。那么就意味着,我们需要一个标识来确定,App是否已经启动过。
      • 我们可以在本地存储一个key来做为已经启动过App的标识。那么,我们在入口这里,就可以读取这个key,来决定是否展示引导页。
    1. "pages" : [
    2. { //引导页判断跳转
    3. "path" : "pages/common/index",
    4. "style" : {
    5. "app-plus" : {
    6. "scrollIndicator" : "none",
    7. "bounce" : "none",
    8. "titleNView": false
    9. },
    10. "h5" : {
    11. "titleNView" : false,
    12. "type" : "default",
    13. "scrollIndicator" : "none"
    14. }
    15. }
    16. },
    17. {
    18. "path" : "pages/index/index",
    19. "style" : {
    20. "navigationBarTitleText" : "首页",
    21. "enablePullDownRefresh" : true,
    22. "navigationBarTextStyle": "black",
    23. "app-plus" : {
    24. "titleNView" : false,
    25. "scrollIndicator" : "none",
    26. "bounce" : "none",
    27. "pullToRefresh" : {
    28. "support" : false
    29. }
    30. },
    31. "h5" : {
    32. "titleNView" : false,
    33. "type" : "default",
    34. "pullToRefresh" : {
    35. "offset" : "45px"
    36. }
    37. }
    38. }
    39. }
    40. ]
    1. 首页:/pages/index/index
    2. 引导页:/pages/index/guide
    3. 当前页:/pages/common/index
    4. try {
    5. const value = uni.getStorageSync('launchFlag');
    6. if (value) {
    7. if (value == true) {
    8. uni.switchTab({
    9. url: '/pages/index/index'
    10. });
    11. } else {
    12. uni.redirectTo({
    13. url: '/pages/index/guide'
    14. });
    15. }
    16. } else {
    17. uni.setStorage({
    18. key: 'launchFlag',
    19. data: true
    20. });
    21. uni.redirectTo({
    22. url: '/pages/index/guide'
    23. });
    24. }
    25. } catch(e) {
    26. // error
    27. uni.setStorage({ key: 'launchFlag',
    28. data: true
    29. });
    30. uni.redirectTo({
    31. url: '/pages/index/guide'
    32. });
    33. }
    • 测试代码块
      1. uni.showModal({
      2. title: '清除launchFlag值',
      3. content: '确定要清除launchFlag值,进行重启测试?',
      4. success: function (res) {
      5. if (res.confirm) {
      6. console.log('用户点击确定');
      7. // 清除缓存
      8. uni.clearStorage();
      9. uni.showToast({
      10. icon: 'none',
      11. duration:3000,
      12. title: '清除成功2秒后重启'
      13. });
      14. // 两秒后重启
      15. setTimeout(function() {
      16. uni.hideToast();
      17. plus.runtime.restart();
      18. }, 2000);
      19. } else if (res.cancel) {
      20. console.log('用户点击取消');
      21. }
      22. }
      23. });