App.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <script>
  2. // APP 和 小程序平台
  3. // #ifdef APP-PLUS || MP-WEIXIN
  4. import TIM from 'tim-wx-sdk';
  5. import COS from 'cos-wx-sdk-v5';
  6. // #endif
  7. // #ifdef H5
  8. import TIM from 'tim-js-sdk';
  9. import TIMUploadPlugin from 'tim-upload-plugin'
  10. // #endif
  11. // #ifdef APP-PLUS
  12. import Aegis from 'aegis-weex-sdk';
  13. // #endif
  14. // #ifdef MP-WEIXIN
  15. import Aegis from 'aegis-mp-sdk';
  16. // #endif
  17. // #ifdef H5
  18. import Aegis from 'aegis-web-sdk';
  19. // #endif
  20. import logger from './utils/logger'; // app.js
  21. import {
  22. genTestUserSig
  23. } from './debug/GenerateTestUserSig.js';
  24. import { getLang, setTabBar } from '@/utils/util'
  25. import animationMixin from '@/pages/mixins/animation'
  26. const aegis = new Aegis({
  27. id: 'iHWefAYqKznuxWjLnr', // 项目key
  28. reportApiSpeed: true, // 接口测速
  29. });
  30. uni.$aegis = aegis
  31. // 首先需要通过 uni.requireNativePlugin("ModuleName") 获取 module
  32. // #ifdef APP-PLUS
  33. const TUICalling = uni.requireNativePlugin('TUICallingUniPlugin-TUICallingModule');
  34. if(typeof(TUICalling) == 'undefined') {
  35. logger.error('如果需要音视频功能,请集成原生插件,使用真机运行并且自定义基座调试哦~ 插件地址:https://ext.dcloud.net.cn/plugin?id=7097 , 调试地址:https://nativesupport.dcloud.net.cn/NativePlugin/use/use');
  36. }
  37. // #endif
  38. export default {
  39. onLaunch() {
  40. var obj = this.$route.query;
  41. if (obj.adgroup_id) {
  42. localStorage.setItem('adgroup_id', JSON.stringify(obj.adgroup_id))
  43. }
  44. if (obj.agency_id) {
  45. localStorage.setItem('agency_id', JSON.stringify(obj.agency_id))
  46. }
  47. if (obj.code) {
  48. localStorage.setItem('agency_code', JSON.stringify(obj.code))
  49. }
  50. const SDKAppID = genTestUserSig('').sdkAppID;
  51. uni.$aegis.reportEvent({
  52. name: 'onLaunch',
  53. ext1: 'onLaunch-success',
  54. ext2: 'uniTuikitExternal',
  55. ext3: `${SDKAppID}`,
  56. })
  57. uni.setStorageSync(`TIM_${SDKAppID}_isTUIKit`, true);
  58. // 重点注意: 为了 uni-app 更好地接入使用 tim,快速定位和解决问题,请勿修改 uni.$TUIKit 命名。
  59. // 如果您已经接入 tim ,请将 uni.tim 修改为 uni.$TUIKit。
  60. uni.$TUIKit = TIM.create({
  61. SDKAppID: SDKAppID
  62. });
  63. // #ifndef H5
  64. uni.$TUIKit.registerPlugin({
  65. 'cos-wx-sdk': COS
  66. });
  67. // #endif
  68. // #ifdef H5
  69. uni.$TUIKit.registerPlugin({ 'tim-upload-plugin':TIMUploadPlugin })
  70. // #endif
  71. // 将原生插件挂载在 uni 上
  72. // #ifdef APP-PLUS
  73. uni.$TUICalling = TUICalling;
  74. // #endif
  75. // 如果您已创建了 tim,请将 tim 实例挂载在 wx 上,且不可以修改 wx.$TIM(修改变量可能导致 TUICalling 组件无法正常使用), 完成 TUICalling 初始化,
  76. // 如果您没有创建,可以不传
  77. // #ifdef MP-WEIXIN
  78. wx.$TIM = uni.$TUIKit;
  79. // #endif
  80. uni.$TUIKitTIM = TIM;
  81. uni.$TUIKitEvent = TIM.EVENT;
  82. uni.$TUIKitVersion = TIM.VERSION;
  83. uni.$TUIKitTypes = TIM.TYPES; // 监听系统级事件
  84. uni.$resetLoginData = this.resetLoginData();
  85. uni.$TUIKit.on(uni.$TUIKitEvent.SDK_READY, this.onSDKReady);
  86. uni.$TUIKit.on(uni.$TUIKitEvent.SDK_NOT_READY, this.onSdkNotReady);
  87. uni.$TUIKit.on(uni.$TUIKitEvent.KICKED_OUT, this.onKickedOut);
  88. uni.$TUIKit.on(uni.$TUIKitEvent.ERROR, this.onTIMError);
  89. uni.$TUIKit.on(uni.$TUIKitEvent.NET_STATE_CHANGE, this.onNetStateChange);
  90. uni.$TUIKit.on(uni.$TUIKitEvent.SDK_RELOAD, this.onSDKReload);
  91. this.getSystem()
  92. let time = new Date();
  93. let timeZone = time.toLocaleTimeString('en-us',{timeZoneName:'short'}); //'1:12:38 PM GMT+8'
  94. let timeZoneId = Intl.DateTimeFormat().resolvedOptions().timeZone; //'Asia/Shanghai'
  95. this.$store.state.timeZone = timeZoneId;
  96. this.$i18n.locale = getLang()
  97. setTabBar(this)
  98. },
  99. watch: {
  100. '$route'() {
  101. this.$store.state.loginShowSign = false
  102. }
  103. },
  104. mixins: [animationMixin],
  105. globalData: {
  106. // userInfo: userID userSig token phone
  107. userInfo: null,
  108. // 个人信息
  109. userProfile: null,
  110. isTUIKit: true,
  111. headerHeight: 0,
  112. statusBarHeight: 0,
  113. SDKAppID: genTestUserSig('').sdkAppID
  114. },
  115. mounted() {
  116. this.$(window).scroll(this.scrollFun);
  117. },
  118. methods: {
  119. // 获取系统配置
  120. getSystem() {
  121. let _this = this
  122. uni.$u.http.get('/api/universal/getHot', {}).then(res => {
  123. // this.$db.set('system'.res.data)
  124. // res.announcement1 = []
  125. // res.announcement1.push(res.announcement)
  126. _this.$store.state.system = res;
  127. localStorage.setItem('system',JSON.stringify(res))
  128. })
  129. // 判断是否登录,没有登录需要获取游客im
  130. let information = this.$common.get('information') || {}
  131. this.getQiNiu()
  132. // setInterval(res=>{
  133. // this.getQiNiu()
  134. // },60000)
  135. /* 判断用户是否登录 */
  136. if(JSON.stringify(information) !== '{}'){
  137. uni.$u.http.get('api/Member/info').then(res => {
  138. _this.$store.state.info = res
  139. })
  140. }else {
  141. _this.$store.state.isLogin = 2;
  142. }
  143. },
  144. getQiNiu(status) {
  145. if(this.$store.state.isLogin == 2) return
  146. this.$store.dispatch('getQiNiu')
  147. },
  148. // TODO:
  149. resetLoginData() {
  150. this.globalData.expiresIn = '';
  151. this.globalData.sessionID = '';
  152. this.globalData.userInfo = {
  153. userID: '',
  154. userSig: '',
  155. token: '',
  156. phone: ''
  157. };
  158. this.globalData.userProfile = null;
  159. logger.log(`| app | resetLoginData | globalData: ${this.globalData}`);
  160. },
  161. onTIMError() {},
  162. onSDKReady({name}) {
  163. const isSDKReady = name === uni.$TUIKitEvent.SDK_READY ? true : false
  164. uni.$emit('isSDKReady', {
  165. isSDKReady: true
  166. });
  167. },
  168. onNetStateChange() {},
  169. onSDKReload() {},
  170. onSdkNotReady() {},
  171. onKickedOut() {
  172. uni.showToast({
  173. title: 'You are being kicked offline',
  174. icon: 'error'
  175. });
  176. this.$common.del('information');
  177. this.$common.del('imTouristAccount');
  178. this.$store.state.isLogin = 2;
  179. this.$store.state.info={};
  180. // console.log('您被踢下线');
  181. // uni.navigateTo({
  182. // url: './pages/TUI-Login/login'
  183. // });
  184. }
  185. }
  186. };
  187. </script>
  188. <style lang="scss">
  189. /*每个页面公共css */
  190. @import "uview-ui/index.scss";
  191. @import "@/static/css/common.scss";
  192. @import "@/static/css/animation.scss";
  193. @import "@/static/css/style.css";
  194. .uni-tabbar__label {
  195. margin-top: 0 !important;
  196. }
  197. body {
  198. // font-family: CWC, "Noto Sans Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
  199. }
  200. .uni-app--showtabbar uni-page-wrapper::after {
  201. height: 0 !important;
  202. }
  203. .u-toast__content {
  204. position: relative;
  205. z-index: 9999;
  206. }
  207. .calendar .u-popup__content {
  208. border-top-left-radius: 20rpx;
  209. border-top-right-radius: 20rpx;
  210. }
  211. uni-tabbar .uni-tabbar__icon {
  212. margin-bottom: 3px;
  213. }
  214. </style>