App.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <script>
  2. // // #ifdef APP-PLUS
  3. // import {
  4. // registerRequestPermissionTipsListener,
  5. // unregisterRequestPermissionTipsListener,
  6. // setRequestPermissionTips
  7. // } from "@/uni_modules/uni-registerRequestPermissionTips"
  8. // var PermissionTips = {
  9. // "android.permission.CAMERA": "<h4 style=\"font-size:40px;\">正在获取相机、存储权限</h4><font color=#cccccc>该权限用于获取设备拍摄或获取本地应用相册,进行头像或图片上传。</font>",
  10. // "android.permission.WRITE_EXTERNAL_STORAGE": "<h4 style=\"font-size:40px;\">正在获取相机、存储权限</h4><font color=#cccccc>该权限用于获取设备拍摄或获取本地应用相册,进行头像或图片上传。</font>",
  11. // "android.permission.READ_EXTERNAL_STORAGE": "<h4 style=\"font-size:40px;\">正在获取相机、存储权限</h4><font color=#cccccc>该权限用于获取设备拍摄或获取本地应用相册,进行头像或图片上传。</font>",
  12. // "android.permission.RECORD_AUDIO": "<h4 style=\"font-size:40px;\">正在获取麦克风权限</h4><font color=#cccccc>该权限用于获取设备语音通话、语音等录音或通讯场景所需。</font>"
  13. // }
  14. // // #endif
  15. const tabbars = ['/pages/my/my', '/pages/make/index', '/pages/message/mailMessage', '/pages/index/index']
  16. export default {
  17. globalData: {
  18. postHeader: null,
  19. headerSign: '',
  20. uuid: '',
  21. skey: '',
  22. isLogin: 0,
  23. userId: 0,
  24. socket: null,
  25. postHeader: null,
  26. systemInfo: null,
  27. push_token: null
  28. },
  29. beforeDestroy() {},
  30. onLaunch: function(options) {
  31. // #ifdef APP-PLUS
  32. // var brand = uni.getSystemInfoSync().deviceBrand
  33. // setRequestPermissionTips(PermissionTips)
  34. // registerRequestPermissionTipsListener({
  35. // onRequest: (e) => {
  36. // console.log(e)
  37. // },
  38. // onConfirm: (e) => {
  39. // console.log(e)
  40. // },
  41. // onComplete: (e) => {
  42. // // 华为手机在权限禁止之后,再次申请权限不会出现权限申请框。此时应该引导用户去系统设置开启此权限,不应该频繁申请。
  43. // if (brand.toLowerCase() == "huawei" || true) {
  44. // var tips = {}
  45. // var hasDeniedPermission = false
  46. // for (var k in PermissionTips) {
  47. // if (e[k] != "denied") {
  48. // tips[k] = PermissionTips[k]
  49. // } else {
  50. // hasDeniedPermission = true
  51. // }
  52. // }
  53. // setRequestPermissionTips(tips) // 更新弹框提醒,防止华为手机不出现权限申请框时权限提醒框闪烁的情况
  54. // if (hasDeniedPermission)
  55. // uni.showModal({
  56. // content: "权限已经被拒绝,请前往设置中开启"
  57. // })
  58. // }
  59. // }
  60. // });
  61. // #endif
  62. let deviceId = "";
  63. let uuid2 = uni.getStorageSync("app_uuid");
  64. if (uuid2 && uuid2.length >= 6) {
  65. deviceId = uuid2;
  66. } else {
  67. deviceId = uni.getSystemInfoSync().deviceId || uni.getDeviceInfo().deviceId;
  68. if (!deviceId || deviceId.length < 6) {
  69. deviceId = this.generateUUID();
  70. } else {
  71. // uni.setStorageSync("app_uuid", deviceId);
  72. }
  73. }
  74. if (deviceId && deviceId.length >= 6) {} else {
  75. deviceId = new Date().getTime()
  76. }
  77. this.globalData.uuid = deviceId;
  78. uni.setStorageSync("app_uuid", deviceId);
  79. // this.globalData.uuid = "";
  80. let skey = uni.getStorageSync("wapptoken");
  81. if (skey != null && skey != "" && skey != undefined) {
  82. this.globalData.skey = skey;
  83. }
  84. if (this.globalData.headerSign == "") {
  85. let headerSignKKK = uni.getStorageSync("headerSign");
  86. if (headerSignKKK != null && headerSignKKK != "" && headerSignKKK != undefined) {
  87. this.globalData.headerSign = headerSignKKK;
  88. }
  89. }
  90. // #ifdef APP
  91. // 注释掉所有推送相关代码
  92. /*
  93. // 初始化推送服务
  94. try {
  95. // 先设置一个计时器,延迟获取推送客户端ID
  96. setTimeout(() => {
  97. uni.getPushClientId({
  98. success: (res) => {
  99. console.log("App getPushClientId success:", res.cid);
  100. // 存储推送token以便后续使用
  101. this.globalData.push_token = res.cid;
  102. },
  103. fail: (err) => {
  104. console.error("App getPushClientId fail:", err);
  105. // 尝试再次获取
  106. setTimeout(() => {
  107. uni.getPushClientId({
  108. success: (res) => {
  109. console.log(
  110. "App getPushClientId retry success:",
  111. res.cid);
  112. this.globalData.push_token = res.cid;
  113. },
  114. fail: (retryErr) => {
  115. console.error(
  116. "App getPushClientId retry fail:",
  117. retryErr);
  118. }
  119. });
  120. }, 3000); // 再等待3秒重试
  121. }
  122. });
  123. }, 1000); // 延迟1秒再获取
  124. } catch (e) {
  125. console.error("getPushClientId exception:", e);
  126. }
  127. */
  128. // #endif
  129. // this.$nextTick(async () => {
  130. // for (var i = 0; i < tabbars.length; i++) {
  131. // await this.go(tabbars[i])
  132. // console.log('page:', i);
  133. // }
  134. // // uni.$store.commit('user/setPageState', 'loadmore')
  135. // })
  136. // #ifdef APP
  137. plus.navigator.closeSplashscreen()
  138. // #endif
  139. let that = this;
  140. uni.$on('check_login', function(callback) {
  141. let skeyLogin = uni.getStorageSync("is_login");
  142. console.log("skeylogin", skeyLogin);
  143. if (skeyLogin == null || skeyLogin == undefined || skeyLogin == "") {
  144. uni.removeStorageSync("wapptoken");
  145. uni.redirectTo({
  146. url: '/pages/login/login'
  147. });
  148. } else if (typeof callback === 'function') {
  149. callback(); // 登录状态有效时执行回调
  150. }
  151. });
  152. },
  153. onShow: function(options) {
  154. console.log('App Show');
  155. // setTimeout(()=>{
  156. // uni.hideTabBar()
  157. // },100)
  158. },
  159. onHide: function() {
  160. console.log('App Hide');
  161. },
  162. onExit: function() {
  163. unregisterRequestPermissionTipsListener(null)
  164. },
  165. onAppBackground() {},
  166. methods: {
  167. generateUUID() {
  168. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  169. const r = Math.random() * 16 | 0;
  170. const v = c === 'x' ? r : (r & 0x3 | 0x8);
  171. return v.toString(16);
  172. });
  173. },
  174. go(url) {
  175. return new Promise((resolve) => {
  176. uni.switchTab({
  177. url,
  178. complete: () => {
  179. setTimeout(() => {
  180. resolve()
  181. }, 100)
  182. }
  183. })
  184. })
  185. },
  186. }
  187. };
  188. </script>
  189. <style lang="scss">
  190. /*每个页面公共css */
  191. @import 'colorui/main.css';
  192. @import 'colorui/icon.css';
  193. @import 'style/FontStyle.css';
  194. body {
  195. -webkit-text-size-adjust: none;
  196. overscroll-behavior-y: contain;
  197. -webkit-overflow-scrolling: touch;
  198. background-color: #161616;
  199. // background: url('./http://c.yujianmate.com/images/v1/bg.png');
  200. // background-size: 750rpx 1624rpx;
  201. background-repeat: repeat-y;
  202. }
  203. /* 超出一行省略号 */
  204. .one-omit {
  205. white-space: nowrap;
  206. /*规定段落中的文本不进行换行*/
  207. overflow: hidden;
  208. /*内容会被修剪,并且其余内容是不可见的。*/
  209. text-overflow: ellipsis;
  210. /*显示省略号来代表被修剪的文本*/
  211. }
  212. .two-omit {
  213. display: -webkit-box;
  214. -webkit-line-clamp: 2;
  215. overflow: hidden;
  216. text-overflow: ellipsis;
  217. -webkit-box-orient: vertical;
  218. }
  219. img {
  220. width: 100%;
  221. }
  222. uni-modal {
  223. z-index: 998 !important;
  224. }
  225. .cu-modal {
  226. z-index: 997 !important;
  227. }
  228. </style>