index.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. export default {
  15. install(Vue) {
  16. Vue.mixin({
  17. data() {
  18. return {
  19. author: HaloConfig.author,
  20. _isWechat: true,
  21. haloAdConfig: HaloAdConfig,
  22. _aniWaitIndex: 0, // 动画索引
  23. };
  24. },
  25. computed: {
  26. // 获取全局应用设置
  27. globalAppSettings() {
  28. return uni.$tm.vx.getters().getSettings;
  29. },
  30. // 计算动画索引
  31. calcAniWait() {
  32. return (index) => {
  33. if ((index + 1) % 10 == 0) {
  34. this._aniWaitIndex = 1;
  35. } else {
  36. this._aniWaitIndex += 1;
  37. }
  38. console.log('this._aniWaitIndex', this._aniWaitIndex);
  39. return this._aniWaitIndex * 50
  40. }
  41. }
  42. },
  43. onLoad() {
  44. this.fnResetSetAniWaitIndex()
  45. },
  46. created() {
  47. // #ifdef MP-WEIXIN
  48. this._isWechat = true;
  49. uni.$tm.vx.commit('setWxShare', HaloConfig.wxShareConfig);
  50. // #endif
  51. // #ifndef MP-WEIXIN
  52. this._isWechat = false;
  53. // #endif
  54. },
  55. onShow() {
  56. this.fnResetSetAniWaitIndex()
  57. },
  58. methods: {
  59. /**
  60. * 设置页面标题
  61. * @param {Object} title 标题
  62. */
  63. fnSetPageTitle(title) {
  64. uni.setNavigationBarTitle({
  65. title: title || HaloConfig.title
  66. })
  67. },
  68. /**
  69. * 页面返回顶部
  70. */
  71. fnToTopPage(duration = 500) {
  72. duration = isNaN(duration) ? 500 : duration
  73. uni.pageScrollTo({
  74. scrollTop: 0,
  75. duration: duration,
  76. fail: (err) => {
  77. console.log('err:', err);
  78. },
  79. });
  80. },
  81. // 初始化动画索引值(需要在每个页面调用)
  82. fnResetSetAniWaitIndex() {
  83. this._aniWaitIndex = 0
  84. }
  85. },
  86. });
  87. },
  88. };