index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. },
  47. methods: {
  48. // 绑定员工关系
  49. bindAgent(agent_id) {
  50. spreadAgent({
  51. // #ifdef MP
  52. agent_code: this.$Cache.get('agent_id')
  53. // #endif
  54. // #ifndef MP
  55. agent_id: this.$Cache.get('agent_id')
  56. // #endif
  57. }).then((res) => {
  58. this.$Cache.clear('agent_id');
  59. uni.showToast({
  60. icon: 'none',
  61. title: res.msg,
  62. duration: 3000
  63. });
  64. });
  65. },
  66. getVersion(name) {
  67. uni.$emit('uploadFooter');
  68. getVersion(name)
  69. .then((res) => {
  70. this.version = res.data.version;
  71. this.isDiy = res.data.is_diy;
  72. this.loading = true;
  73. uni.setStorageSync('is_diy', res.data.is_diy);
  74. if (!uni.getStorageSync('DIY_VERSION') || res.data.version != uni.getStorageSync('DIY_VERSION')) {
  75. if (uni.getStorageSync('DIY_VERSION')) {
  76. uni.setStorageSync('DIY_VERSION', res.data.version);
  77. if (this.isDiy) {
  78. this.$refs.diy.reconnect();
  79. } else {
  80. this.$refs.vis.reconnect();
  81. }
  82. }
  83. uni.setStorageSync('DIY_VERSION', res.data.version);
  84. } else {
  85. }
  86. })
  87. .catch((err) => {
  88. // #ifdef APP-PLUS
  89. setTimeout((e) => {
  90. this.getVersion(0);
  91. }, 1500);
  92. // #endif
  93. // #ifndef APP-PLUS
  94. this.$util.Tips({
  95. title: err
  96. });
  97. // #endif
  98. });
  99. },
  100. // 微信分享;
  101. setOpenShare: function () {
  102. let that = this;
  103. getShare().then((res) => {
  104. let data = res.data;
  105. this.shareInfo = data;
  106. // #ifdef H5
  107. let url = location.href;
  108. if (this.$store.state.app.uid) {
  109. url = url.indexOf('?') === -1 ? url + '?spread=' + this.$store.state.app.uid : url + '&spread=' + this.$store.state.app.uid;
  110. }
  111. if (that.$wechat.isWeixin()) {
  112. let configAppMessage = {
  113. desc: data.synopsis,
  114. title: data.title,
  115. link: url,
  116. imgUrl: data.img
  117. };
  118. that.$wechat.wechatEvevt(['updateAppMessageShareData', 'updateTimelineShareData'], configAppMessage);
  119. }
  120. // #endif
  121. });
  122. }
  123. },
  124. onReachBottom: function () {
  125. if (this.isDiy) {
  126. this.$refs.diy.onsollBotton();
  127. }
  128. },
  129. // 滚动监听
  130. onPageScroll(e) {
  131. // 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
  132. uni.$emit('scroll');
  133. },
  134. // #ifdef MP
  135. //发送给朋友
  136. onShareAppMessage(res) {
  137. // 此处的distSource为分享者的部分信息,需要传递给其他人
  138. let that = this;
  139. return {
  140. title: this.shareInfo.title,
  141. path: '/pages/index/index?spid=' + this.$store.state.app.uid || 0,
  142. imageUrl: this.shareInfo.img
  143. };
  144. },
  145. //分享到朋友圈
  146. onShareTimeline() {
  147. return {
  148. title: this.shareInfo.title,
  149. query: {
  150. spid: this.$store.state.app.uid || 0
  151. },
  152. imageUrl: this.shareInfo.img
  153. };
  154. }
  155. // #endif
  156. };
  157. </script>
  158. <style></style>