App.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <script>
  2. import permision from "@/js_sdk/wa-permission/permission.js"
  3. import _action from './common/_action';
  4. import _get from './common/_get';
  5. import _data from './common/_data';
  6. import _page from './common/common';
  7. // import SDK from "./common/tendenceImSdk";
  8. // #ifdef APP-PLUS
  9. import TIM from 'tim-wx-sdk';
  10. import {
  11. genTestUserSig
  12. } from './debug/GenerateTestUserSig.js';
  13. // 首先需要通过 uni.requireNativePlugin("ModuleName") 获取 module
  14. // const TUICalling = uni.requireNativePlugin('TencentCloud-TUICallKit');
  15. // const TUICalling = uni.requireNativePlugin('TUICallingUniPlugin-TUICallingModule');
  16. // console.error(TUICalling, 'TUICalling | ok');
  17. // const TUICallingEvent = uni.requireNativePlugin('globalEvent');
  18. // #endif
  19. export default {
  20. globalData: {
  21. /** 代理客户id */
  22. agent_id: 1,
  23. /** http 服务端地址 */
  24. http_url: 'https://im.yiqushangshi.com',
  25. /** 静态文件存放地址 */
  26. static_url: 'https://im.yiqushangshi.com',
  27. /** socket 服务端地址 */
  28. socket_url: 'wss://im.yiqushangshi.com/ws',
  29. /** socket 连接状态 */
  30. socket_state: 0,
  31. /** 好友申请通知 */
  32. new_friend_tips_num: 0,
  33. /** 群认证通知 */
  34. new_group_tips_num: 0,
  35. /** 朋友圈通知 */
  36. no_reader_circle: 0,
  37. /** 朋友圈消息未读数 */
  38. no_reader_circle_chat_num: 0,
  39. /** 缓存的数据 */
  40. cache: {
  41. /** 个人头像缓存数据 */
  42. local_photo: '',
  43. },
  44. /** 用户信息 */
  45. user_info: {
  46. id: 0,
  47. nickname: '',
  48. username: '',
  49. photo: 'default_man/70.jpg',
  50. doodling: '',
  51. phone: '',
  52. circle_img: 'default_circle_img.jpg?_=3.1415926',
  53. },
  54. isOnlie: true,
  55. dragInfo: {
  56. moveX: 260,
  57. moveY: 180,
  58. state: -1
  59. }
  60. },
  61. onLaunch() {
  62. console.log('到这里');
  63. // 登录腾讯IM
  64. // #ifdef APP-PLUS
  65. // uni.$TUIKit = TIM.create({
  66. // SDKAppID: genTestUserSig('').sdkAppID
  67. // });
  68. // // 将原生插件挂载在 uni 上
  69. // console.log(TUICalling,'TUICalling');
  70. // uni.$TUICalling = TUICalling;
  71. // uni.$TUICallingEvent = TUICallingEvent;
  72. // #endif
  73. this.$store.commit('initRECORD');
  74. // 其他监听
  75. //#ifdef APP-PLUS
  76. // plus.push.addEventListener("click", function(msg) {
  77. // console.log("msg.payload", JSON.stringify(msg.payload));
  78. // let content_type = msg.payload.content_type;
  79. // if (Object.keys(msg.payload).length) {
  80. // switch (parseInt(content_type)) {
  81. // case 6:
  82. // case 7:
  83. // uni.navigateTo({
  84. // url: '/pages/chat/videoCall?' + _page.pageParam(msg.payload)
  85. // });
  86. // break;
  87. // }
  88. // }
  89. // //这里可以写跳转业务代码
  90. // }, false);
  91. // 监听在线消息事件
  92. // plus.push.addEventListener("receive", function(msg) {
  93. // // plus.ui.alert(2);
  94. // //这里可以写跳转业务代码
  95. // console.log("recevice:" + JSON.stringify(msg))
  96. // }, false);
  97. //#endif
  98. // #ifdef APP-PLUS
  99. /** 锁定屏幕方向 */
  100. plus.screen.lockOrientation('portrait-primary');
  101. // let main = plus.android.runtimeMainActivity();
  102. // //为了防止快速点按返回键导致程序退出重写quit方法改为隐藏至后台
  103. // plus.runtime.quit = function(){
  104. // return false;
  105. // };
  106. //重写toast方法如果内容为 ‘再按一次退出应用’ 就隐藏应用,其他正常toast
  107. // plus.nativeUI.toast = (function(str){
  108. // if(str == '再按一次退出应用'){
  109. // return false;
  110. // }else{
  111. // return false;
  112. // // uni.showToast({
  113. // // title: '再按一次退出应用',
  114. // // icon:'none',
  115. // // })
  116. // }
  117. // });
  118. /** 检测升级 */
  119. let _this = this;
  120. plus.runtime.getProperty(plus.runtime.appid, function(info) {
  121. _this.$httpSend({
  122. path: '/im/app/update',
  123. data: {
  124. appid: info.appid,
  125. version: info.version,
  126. },
  127. success(res) {
  128. if (res.status) {
  129. _action.checkFail();
  130. let wgtWaiting = plus.nativeUI.showWaiting("更新开始下载"),
  131. update_url = (plus.os.name == 'Android' ? res.update_url.android : res
  132. .update_url.ios),
  133. downloadTask = uni.downloadFile({
  134. url: update_url,
  135. success: (res) => {
  136. wgtWaiting.close();
  137. if (res.statusCode === 200) {
  138. plus.runtime.install(res.tempFilePath, {}, () => {
  139. plus.runtime.restart();
  140. }, (e) => {
  141. uni.showModal({
  142. content: "update error [" + e
  143. .code + "]:" + e.message,
  144. showCancel: false,
  145. });
  146. });
  147. } else {
  148. uni.showModal({
  149. content: "api error update fail!",
  150. showCancel: false,
  151. });
  152. }
  153. }
  154. });
  155. downloadTask.onProgressUpdate((res) => {
  156. wgtWaiting.setTitle('下载中...' + res.progress + '%');
  157. });
  158. }
  159. },
  160. });
  161. });
  162. // #endif
  163. //登陆腾讯im
  164. // #ifdef APP-PLUS
  165. // let localLoginData = uni.getStorageSync('localLoginData');
  166. // if (localLoginData) {
  167. // SDK.IMSDK.joinRoom(localLoginData, function(sdk_ret) {
  168. // console.log(sdk_ret);
  169. // console.log("99999999999999999999999999");
  170. // })
  171. // }
  172. // #endif
  173. },
  174. onShow() {
  175. //在微信小程序或是app中,通过curPage.options;如果是H5,则需要curPage.$route.query(H5中的curPage.options为undefined)
  176. let curParam = this.options || this.$route.query;
  177. if (curParam.channelCode) {
  178. _data.localData('channelCode', curParam.channelCode)
  179. } else {
  180. _data.localData('channelCode', '')
  181. }
  182. // #ifdef APP-PLUS
  183. this.requestAn()
  184. // #endif
  185. let _this = this;
  186. if (!_data.localData('token')) {
  187. return;
  188. }
  189. /**
  190. * 每次app启动都加载最新的会话列表数据,只要是最新的会话列表数据,会话界面数据也会是最新的
  191. * 这里延时100ms,不然会全局变量没有加载完成,会报错。
  192. */
  193. if (_data.data('socket_state') <= 0) {
  194. _this.$reset().$reconnect(function() {
  195. if (_data.localData('token')) _get.getChatList();
  196. });
  197. }
  198. /**
  199. * @param {Object} res
  200. * 监听网络变化
  201. * 如果有网络变化,断开socket,再重新连接
  202. * 重新获取会话列表数据
  203. * 如果是在会话界面,再重新获取这个的对话数据
  204. */
  205. uni.onNetworkStatusChange(function(res) {
  206. console.log("App onNetworkStatusChange...");
  207. /** 断开重新再连接,再获取最新数据 */
  208. if (_data.data('socket_state') <= 0 && _data.localData('token')) {
  209. _this.$reset().$reconnect(function() {
  210. if (_data.localData('message_list_id') && _data.localData('token')) {
  211. _get.getChatData({
  212. send_data: {
  213. list_id: _data.localData('message_list_id'),
  214. time: 0,
  215. is_up: 1,
  216. },
  217. is_action_data: 1,
  218. });
  219. }
  220. });
  221. }
  222. });
  223. },
  224. onHide() {
  225. this.globalData.isOnlie = false;
  226. },
  227. methods: {
  228. requestAn() {
  229. switch (uni.getSystemInfoSync().platform) {
  230. case 'android':
  231. permision.requestAndroidPermission("android.permission.RECORD_AUDIO")
  232. break;
  233. case 'ios':
  234. permision.judgeIosPermission("record")
  235. break;
  236. }
  237. }
  238. }
  239. }
  240. </script>
  241. <style>
  242. /* #ifndef APP-PLUS-NVUE */
  243. /** uni.css - 通用组件、模板样式库,可以当作一套ui库应用 */
  244. @import "./static/css/font/iconfont.css";
  245. @import "./static/css/font/iconfont-im.css";
  246. @import "./static/css/uni.css";
  247. /** 设置 body 的背景色 */
  248. page {
  249. background-color: #f9f9f9;
  250. }
  251. /** 导航栏自定义图标样式调整 */
  252. .uni-page-head .uni-btn-icon {
  253. min-width: auto !important;
  254. overflow: inherit !important;
  255. }
  256. uni-checkbox .uni-checkbox-input {
  257. border-radius: 50%;
  258. width: 18px !important;
  259. height: 18px !important;
  260. border: 1px solid #007aff !important;
  261. }
  262. uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked {
  263. background-color: #007aff;
  264. border: 1px solid #007aff !important;
  265. color: white !important;
  266. }
  267. uni-checkbox .uni-checkbox-wrapper {
  268. width: 100%;
  269. }
  270. /* #endif */
  271. </style>