index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * 功能:全局混入函数
  3. * 作者:小莫唐尼
  4. * 邮箱:studio@925i.cn
  5. * 时间:2022年07月21日 17:39:32
  6. * 版本:v0.1.0
  7. * 修改记录:
  8. * 修改内容:
  9. * 修改人员:
  10. * 修改时间:
  11. */
  12. import HaloConfig from '@/config/halo.config.js';
  13. import HaloAdConfig from '@/config/ad.config.js';
  14. import HaloPluginsConfig from '@/config/plugins.config.js';
  15. export default {
  16. install(Vue) {
  17. Vue.mixin({
  18. data() {
  19. return {
  20. author: HaloConfig.author,
  21. _isWechat: true,
  22. haloConfig: HaloConfig,
  23. haloAdConfig: HaloAdConfig,
  24. haloPluginsConfig: HaloPluginsConfig,
  25. _aniWaitIndex: 0, // 动画索引
  26. };
  27. },
  28. computed: {
  29. // 获取全局应用设置
  30. globalAppSettings() {
  31. return uni.$tm.vx.getters().getSettings;
  32. },
  33. // 计算动画索引
  34. calcAniWait() {
  35. return (index) => {
  36. if ((index + 1) % 10 == 0) {
  37. this._aniWaitIndex = 1;
  38. } else {
  39. this._aniWaitIndex += 1;
  40. }
  41. console.log('this._aniWaitIndex', this._aniWaitIndex);
  42. return this._aniWaitIndex * 50
  43. }
  44. }
  45. },
  46. onLoad() {
  47. this.fnResetSetAniWaitIndex()
  48. },
  49. created() {
  50. // #ifdef MP-WEIXIN
  51. this._isWechat = true;
  52. uni.$tm.vx.commit('setWxShare', HaloConfig.wxShareConfig);
  53. // #endif
  54. // #ifndef MP-WEIXIN
  55. this._isWechat = false;
  56. // #endif
  57. },
  58. onShow() {
  59. this.fnResetSetAniWaitIndex()
  60. },
  61. methods: {
  62. /**
  63. * 设置页面标题
  64. * @param {Object} title 标题
  65. */
  66. fnSetPageTitle(title) {
  67. uni.setNavigationBarTitle({
  68. title: title || HaloConfig.title
  69. })
  70. },
  71. /**
  72. * 页面返回顶部
  73. */
  74. fnToTopPage(duration = 500) {
  75. duration = isNaN(duration) ? 500 : duration
  76. uni.pageScrollTo({
  77. scrollTop: 0,
  78. duration: duration,
  79. fail: (err) => {
  80. console.log('err:', err);
  81. },
  82. });
  83. },
  84. // 初始化动画索引值(需要在每个页面调用)
  85. fnResetSetAniWaitIndex() {
  86. this._aniWaitIndex = 0
  87. }
  88. },
  89. });
  90. },
  91. };