1
0

index.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. onLoad() {
  45. this.fnResetSetAniWaitIndex()
  46. },
  47. created() {
  48. // #ifdef MP-WEIXIN
  49. this._isWechat = true;
  50. // #endif
  51. // #ifndef MP-WEIXIN
  52. this._isWechat = false;
  53. // #endif
  54. },
  55. onShow() {
  56. this.fnResetSetAniWaitIndex()
  57. },
  58. methods: {
  59. // 设置页面标题
  60. fnSetPageTitle(title) {
  61. uni.setNavigationBarTitle({
  62. title: title || this.haloConfig?.appConfig?.startConfig?.title || "uni-halo",
  63. })
  64. },
  65. // 页面返回顶部
  66. fnToTopPage(duration = 500) {
  67. duration = isNaN(duration) ? 500 : duration
  68. uni.pageScrollTo({
  69. scrollTop: 0,
  70. duration: duration,
  71. fail: (err) => {
  72. console.log('err:', err);
  73. },
  74. });
  75. },
  76. // 初始化动画索引值(需要在每个页面调用)
  77. fnResetSetAniWaitIndex() {
  78. this._aniWaitIndex = 0
  79. }
  80. },
  81. });
  82. },
  83. };