App.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <script>
  2. import {
  3. getDictByKey,
  4. getAppVersion,
  5. getRealLinkDomainName
  6. } from '@/api/common';
  7. import {
  8. appCheckUdate,
  9. openDownload
  10. } from '@/utils/APPUpdate.js';
  11. import {
  12. getUserInfo,
  13. getPushLogRead
  14. } from '@/api/user';
  15. import {
  16. mapGetters,
  17. mapActions
  18. } from 'vuex';
  19. let updateDownloadTask = null;
  20. let notificationIntance = null;
  21. let pausing = false;
  22. let innerAudioContext;
  23. let notification;
  24. let uPushPlugin;
  25. // #ifdef APP-PLUS
  26. import {
  27. getTlsSig
  28. } from '@/api/common.js';
  29. import {
  30. qconfig
  31. } from './utils/config';
  32. // import { getImAdminToken } from '@/pages_im/api/imApi';
  33. // import { ar } from 'date-fns/locale';
  34. // #endif
  35. let offlineMsg = null;
  36. let offlineHandleNewMsg = null;
  37. export default {
  38. globalData: {
  39. wsUrl: 'ws://doctor.ai.cdwjyyh.com',
  40. corpId: 'ww70ac72e824957fc9', //客服企业id
  41. miniprogamId: "gh_7a6a32e5ef61",
  42. },
  43. onLaunch: function(options) {
  44. uni.hideTabBar();
  45. //设置字体大小
  46. // let fontsize = uni.getStorageSync('fontSize');
  47. // if (fontsize) {
  48. // uni.setStorageSync('fontSize', fontsize);
  49. // }
  50. // else {
  51. // let scale = this.getSystemFontScale();
  52. // let oriFontSize = 18;
  53. // fontsize = oriFontSize * scale;
  54. // if (fontsize < oriFontSize) {
  55. // fontsize = oriFontSize;
  56. // }
  57. // if (fontsize < 16) {
  58. // fontsize = 16;
  59. // }
  60. // if (fontsize >= 21) {
  61. // fontsize = 21;
  62. // }
  63. // uni.setStorageSync('fontSize', fontsize);
  64. // }
  65. uni.removeStorageSync('openUrl');
  66. if (this.$isLogin()) {
  67. uni.setStorageSync("onLaunch", 1);
  68. }
  69. let that = this;
  70. // #ifdef APP-PLUS
  71. //#endif
  72. },
  73. onLoad() {
  74. },
  75. onShow() {
  76. var that = this;
  77. // #ifdef APP-PLUS
  78. if (uni.$u.os() === 'android') {
  79. this.checkUpdateApp();
  80. }
  81. // this.checkPermission(["android.permission.BLUETOOTH_CONNECT"],"蓝牙",function(){
  82. // console.log('checkPermission BLUETOOTH_CONNECT OK!');
  83. // });
  84. // #endif
  85. },
  86. onHide() {
  87. console.log("qxj onHide");
  88. uni.removeStorageSync('onLaunch');
  89. // if(uni.$u.os() === 'android'){
  90. // IMSDK.asyncApi(IMSDK.IMMethods.SetAppBackgroundStatus, IMSDK.uuid(), true);
  91. // // meetingModule?.onListenerAppBackground(true);
  92. // }
  93. },
  94. computed: {
  95. },
  96. methods: {
  97. checkPermission(permissions, permissionName, success) {
  98. plus.android.requestPermissions(permissions, function(e) {
  99. if (e.deniedAlways.length > 0) { //权限被永久拒绝
  100. // 弹出提示框解释为何需要读写手机储存权限,引导用户打开设置页面开启
  101. uni.showModal({
  102. title: permissionName + '权限',
  103. content: '您可能拒绝了' + permissionName + '权限或您的设备无需设置权限',
  104. success: function(res) {
  105. if (res.confirm) {
  106. // console.log('用户点击确定');
  107. } else if (res.cancel) {
  108. // console.log('用户点击取消');
  109. }
  110. }
  111. });
  112. }
  113. if (e.deniedPresent.length > 0) { //权限被临时拒绝
  114. plus.android.requestPermissions(permissions)
  115. }
  116. if (e.granted.length > 0) { //权限被允许
  117. if (success) {
  118. success();
  119. }
  120. }
  121. }, function(e) {
  122. });
  123. },
  124. // 处理Launch信息
  125. handlerLaunchMsg() {
  126. let that = this;
  127. // 监听通知点击事件
  128. plus.push.addEventListener('click', function(msg) {
  129. console.log('应用通过点击通知启动:', msg);
  130. let newServerMsg = msg.payload;
  131. // uni.switchTab({url: 'pages_im/pages/conversation/conversationList/index'});
  132. //uni.$u.throttle(() => that.notifyGoToChat(newServerMsg), 1000);
  133. });
  134. // 获取启动时的通知
  135. plus.push.getClientInfoAsync(function(info) {
  136. console.log("qxj getClientInfoAsync", info);
  137. if (info.id && info.id == "unipush") { //荣耀离线推送
  138. offlineMsg = info;
  139. }
  140. if (info.title && info.content && info.payload) {
  141. // uni.switchTab({url: 'pages_im/pages/conversation/conversationList/index'});
  142. }
  143. if (info.launch && info.launch.payload) {
  144. let newServerMsg = info.launch.payload;
  145. console.log('应用通过通知启动:', info);
  146. // uni.switchTab({url: 'pages_im/pages/conversation/conversationList/index'});
  147. //uni.$u.throttle(() => that.notifyGoToChat(newServerMsg), 1000);
  148. }
  149. }, function(err) {
  150. console.error("Error getting client info:", err);
  151. });
  152. },
  153. getSystemFontScale: function() {
  154. let scale = 1;
  155. if (uni.getSystemInfoSync) {
  156. let systemInfo = uni.getSystemInfoSync();
  157. if (systemInfo.fontSizeSetting) {
  158. scale = systemInfo.fontSizeSetting / 16; // 16 是默认字体大小
  159. }
  160. }
  161. return scale;
  162. },
  163. adjustFontSize: function() {
  164. let scale = getSystemFontScale();
  165. let rootElement = document.documentElement;
  166. rootElement.style.fontSize = 16 * scale + 'px';
  167. },
  168. /* 检查更新 在线更新 */
  169. checkUpdateApp() {
  170. // 获取manifest.json里的配置信息
  171. let that = this;
  172. plus.runtime.getProperty(plus.runtime.appid, function(widgetinfo) {
  173. // console.log("qxj widgetinfo:"+JSON.stringify(widgetinfo));
  174. // 可以根据manifest.json里的应用名称来进行针对性的APP升级
  175. if (widgetinfo.name == qconfig.appName) {
  176. //APP名称
  177. // 获取manifest.json里的版本号
  178. let platform = uni.getSystemInfoSync().platform;
  179. let isAndroid = platform == 'android';
  180. let type = isAndroid ? 5 : 2;
  181. // console.log("qxj widgetinfo:"+type);
  182. getAppVersion(type).then((srcData) => {
  183. if (srcData.code == 200) {
  184. //console.log("qxj widgetinfo:"+srcData);
  185. let data = srcData.data;
  186. let version = widgetinfo.versionCode, //用户当前app版本
  187. appVersion = data.versionCode, //升级包版本
  188. appName = widgetinfo.name, //app名称
  189. isForce = data.isForce, //是否强制热更新
  190. updateConfig = JSON.parse(data.updateConfig),
  191. appurl = data.url, //升级包地址
  192. intro = data.note; //升级包提示
  193. //如果用户版本号小于升级包版本号,先升级
  194. let afterVer = false;
  195. if (plus.runtime.channel == 'baidu') {
  196. afterVer = that.$qconfig.isAppStore ? updateConfig.baidu : false;
  197. } else if (plus.runtime.channel == 'huawei') {
  198. afterVer = that.$qconfig.isAppStore ? updateConfig.huawei : false;
  199. } else if (plus.runtime.channel == 'xiaomi') {
  200. afterVer = that.$qconfig.isAppStore ? updateConfig.xiaomi : false;
  201. } else if (plus.runtime.channel == 'yyb') {
  202. afterVer = that.$qconfig.isAppStore ? updateConfig.yyb : false;
  203. } else {
  204. afterVer = that.$qconfig.isAppStore ? isForce : true;
  205. }
  206. if (data && version < appVersion && afterVer) {
  207. uni.showModal({
  208. title: '更新提示',
  209. confirmText: '立即升级',
  210. content: intro,
  211. cancelText: '确定',
  212. confirmText: '取消',
  213. success: (res) => {
  214. if (res.cancel) {
  215. openDownload(srcData.data);
  216. } else if (res.confirm) {
  217. if (isForce == 1) {
  218. uni.showToast({
  219. title: '请先升级APP版本',
  220. icon: 'none',
  221. duration: 2000
  222. });
  223. //退出app
  224. setTimeout(function() {
  225. plus.runtime.quit();
  226. }, 2000);
  227. }
  228. }
  229. },
  230. fail: () => {
  231. uni.hideLoading();
  232. }
  233. });
  234. }
  235. }
  236. },
  237. (rej) => {}
  238. )
  239. .catch(() => {
  240. //联网失败, 结束加载
  241. this.mescroll.endErr();
  242. });
  243. }
  244. });
  245. }
  246. }
  247. };
  248. </script>
  249. <style lang="scss">
  250. /*每个页面公共css */
  251. @import '@/uni_modules/uview-plus/index.scss';
  252. /*#ifndef APP-NVUE*/
  253. view {
  254. box-sizing: border-box;
  255. }
  256. .ellipsis {
  257. overflow: hidden;
  258. text-overflow: ellipsis;
  259. white-space: nowrap;
  260. }
  261. .ellipsis2 {
  262. overflow: hidden;
  263. text-overflow: ellipsis;
  264. display: -webkit-box;
  265. -webkit-box-orient: vertical;
  266. -webkit-line-clamp: 2;
  267. }
  268. uni-modal {
  269. z-index: 1100;
  270. }
  271. .no-data-box {
  272. height: 100%;
  273. width: 100%;
  274. display: flex;
  275. justify-content: center;
  276. align-items: center;
  277. flex-direction: column;
  278. image {
  279. width: 264upx;
  280. height: 212upx;
  281. }
  282. .empty-title {
  283. margin-top: 20rpx;
  284. font-size: 28rpx;
  285. color: gray;
  286. }
  287. }
  288. /*#endif*/
  289. </style>
  290. <style lang="less">
  291. /*每个页面公共css */
  292. // @import './assets/iconfont/iconfont.css';
  293. @import './assets/css/common.less';
  294. /* 全局flex样式 */
  295. @import './common/css/flexCommon.css';
  296. /*引入全局补充样式*/
  297. @import './assets/css/czy/es.1.base.css';
  298. @import './assets/css/czy/es.2.color.css';
  299. @import './assets/css/czy/es.3.icon.css';
  300. @import './assets/css/czy/es.4.view.css';
  301. .textOne {
  302. overflow: hidden;
  303. white-space: nowrap;
  304. text-overflow: ellipsis;
  305. }
  306. .textTwo {
  307. overflow: hidden;
  308. text-overflow: ellipsis;
  309. display: -webkit-box;
  310. -webkit-line-clamp: 2;
  311. -webkit-box-orient: vertical;
  312. }
  313. </style>