index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <diy ref="diy" v-if="isDiy && loading"></diy>
  3. <visualization ref="vis" v-else-if="!isDiy && loading"></visualization>
  4. </template>
  5. <script>
  6. import diy from './diy';
  7. import visualization from './visualization';
  8. import Cache from '@/utils/cache';
  9. import { getShare, getVersion } from '@/api/public.js';
  10. import { spreadAgent } from '@/api/user.js';
  11. export default {
  12. data() {
  13. return {
  14. isDiy: uni.getStorageSync('is_diy'),
  15. shareInfo: {},
  16. loading: false
  17. };
  18. },
  19. components: {
  20. diy,
  21. visualization
  22. },
  23. onLoad(options) {
  24. uni.hideTabBar();
  25. //扫码携带参数处理
  26. // #ifdef MP
  27. const queryData = uni.getEnterOptionsSync(); // uni-app版本 3.5.1+ 支持
  28. if (queryData.query.scene){
  29. this.$Cache.set('agent_id', queryData.query.scene);
  30. }
  31. // #endif
  32. // #ifndef MP
  33. if (options.agent_id) {
  34. this.$Cache.set('agent_id', options.agent_id);
  35. }
  36. // #endif
  37. this.setOpenShare();
  38. },
  39. onShow() {
  40. this.getVersion(0);
  41. if(this.$Cache.get('agent_id')){
  42. this.bindAgent();
  43. }
  44. },
  45. onHide() {
  46. this.$Cache.clear('agent_id');
  47. },
  48. methods: {
  49. // 绑定员工关系
  50. bindAgent(agent_id) {
  51. spreadAgent({
  52. // #ifdef MP
  53. agent_code: this.$Cache.get('agent_id')
  54. // #endif
  55. // #ifndef MP
  56. agent_id: this.$Cache.get('agent_id')
  57. // #endif
  58. }).then((res) => {
  59. this.$Cache.clear('agent_id');
  60. uni.showToast({
  61. icon: 'none',
  62. title: res.msg,
  63. duration: 3000
  64. });
  65. });
  66. },
  67. getVersion(name) {
  68. uni.$emit('uploadFooter');
  69. getVersion(name)
  70. .then((res) => {
  71. this.version = res.data.version;
  72. this.isDiy = res.data.is_diy;
  73. this.loading = true;
  74. uni.setStorageSync('is_diy', res.data.is_diy);
  75. if (!uni.getStorageSync('DIY_VERSION') || res.data.version != uni.getStorageSync('DIY_VERSION')) {
  76. if (uni.getStorageSync('DIY_VERSION')) {
  77. uni.setStorageSync('DIY_VERSION', res.data.version);
  78. if (this.isDiy) {
  79. this.$refs.diy.reconnect();
  80. } else {
  81. this.$refs.vis.reconnect();
  82. }
  83. }
  84. uni.setStorageSync('DIY_VERSION', res.data.version);
  85. } else {
  86. }
  87. })
  88. .catch((err) => {
  89. // #ifdef APP-PLUS
  90. setTimeout((e) => {
  91. this.getVersion(0);
  92. }, 1500);
  93. // #endif
  94. // #ifndef APP-PLUS
  95. this.$util.Tips({
  96. title: err
  97. });
  98. // #endif
  99. });
  100. },
  101. // 微信分享;
  102. setOpenShare: function () {
  103. let that = this;
  104. getShare().then((res) => {
  105. let data = res.data;
  106. this.shareInfo = data;
  107. // #ifdef H5
  108. let url = location.href;
  109. if (this.$store.state.app.uid) {
  110. url = url.indexOf('?') === -1 ? url + '?spread=' + this.$store.state.app.uid : url + '&spread=' + this.$store.state.app.uid;
  111. }
  112. if (that.$wechat.isWeixin()) {
  113. let configAppMessage = {
  114. desc: data.synopsis,
  115. title: data.title,
  116. link: url,
  117. imgUrl: data.img
  118. };
  119. that.$wechat.wechatEvevt(['updateAppMessageShareData', 'updateTimelineShareData'], configAppMessage);
  120. }
  121. // #endif
  122. });
  123. }
  124. },
  125. onReachBottom: function () {
  126. if (this.isDiy) {
  127. this.$refs.diy.onsollBotton();
  128. }
  129. },
  130. // 滚动监听
  131. onPageScroll(e) {
  132. // 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
  133. uni.$emit('scroll');
  134. },
  135. // #ifdef MP
  136. //发送给朋友
  137. onShareAppMessage(res) {
  138. // 此处的distSource为分享者的部分信息,需要传递给其他人
  139. let that = this;
  140. return {
  141. title: this.shareInfo.title,
  142. path: '/pages/index/index?spid=' + this.$store.state.app.uid || 0,
  143. imageUrl: this.shareInfo.img
  144. };
  145. },
  146. //分享到朋友圈
  147. onShareTimeline() {
  148. return {
  149. title: this.shareInfo.title,
  150. query: {
  151. spid: this.$store.state.app.uid || 0
  152. },
  153. imageUrl: this.shareInfo.img
  154. };
  155. }
  156. // #endif
  157. };
  158. </script>
  159. <style></style>