index.js 3.0 KB

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