App.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. nickname: '',
  28. avator: '',
  29. mobile:0,
  30. user_id: 0,
  31. },
  32. beforeDestroy() { },
  33. onLaunch: function (options) {
  34. // #ifdef APP-PLUS
  35. // var brand = uni.getSystemInfoSync().deviceBrand
  36. // setRequestPermissionTips(PermissionTips)
  37. // registerRequestPermissionTipsListener({
  38. // onRequest: (e) => {
  39. // console.log(e)
  40. // },
  41. // onConfirm: (e) => {
  42. // console.log(e)
  43. // },
  44. // onComplete: (e) => {
  45. // // 华为手机在权限禁止之后,再次申请权限不会出现权限申请框。此时应该引导用户去系统设置开启此权限,不应该频繁申请。
  46. // if (brand.toLowerCase() == "huawei" || true) {
  47. // var tips = {}
  48. // var hasDeniedPermission = false
  49. // for (var k in PermissionTips) {
  50. // if (e[k] != "denied") {
  51. // tips[k] = PermissionTips[k]
  52. // } else {
  53. // hasDeniedPermission = true
  54. // }
  55. // }
  56. // setRequestPermissionTips(tips) // 更新弹框提醒,防止华为手机不出现权限申请框时权限提醒框闪烁的情况
  57. // if (hasDeniedPermission)
  58. // uni.showModal({
  59. // content: "权限已经被拒绝,请前往设置中开启"
  60. // })
  61. // }
  62. // }
  63. // });
  64. // #endif
  65. let deviceId = "";
  66. let uuid2 = uni.getStorageSync("app_uuid");
  67. if (uuid2 && uuid2.length >= 6) {
  68. deviceId = uuid2;
  69. } else {
  70. deviceId = uni.getSystemInfoSync().deviceId || uni.getDeviceInfo().deviceId;
  71. if (!deviceId || deviceId.length < 6) {
  72. deviceId = this.generateUUID();
  73. } else {
  74. // uni.setStorageSync("app_uuid", deviceId);
  75. }
  76. }
  77. if (deviceId && deviceId.length >= 6) { } else {
  78. deviceId = new Date().getTime()
  79. }
  80. this.globalData.uuid = deviceId;
  81. uni.setStorageSync("app_uuid", deviceId);
  82. // this.globalData.uuid = "";
  83. let skey = uni.getStorageSync("wapptoken");
  84. if (skey != null && skey != "" && skey != undefined) {
  85. this.globalData.skey = skey;
  86. }
  87. if (this.globalData.headerSign == "") {
  88. let headerSignKKK = uni.getStorageSync("headerSign");
  89. if (headerSignKKK != null && headerSignKKK != "" && headerSignKKK != undefined) {
  90. this.globalData.headerSign = headerSignKKK;
  91. }
  92. }
  93. let nickname = uni.getStorageSync("nickname");
  94. if (nickname != null && nickname != "" && nickname != undefined) {
  95. this.globalData.nickname = nickname;
  96. }
  97. let avator = uni.getStorageSync("avator");
  98. if (avator != null && avator != "" && avator != undefined) {
  99. this.globalData.avator = avator;
  100. }
  101. let mobile = uni.getStorageSync("mobile");
  102. if (mobile != null && mobile != "" && mobile != undefined) {
  103. this.globalData.mobile = mobile;
  104. }
  105. let user_id = uni.getStorageSync("user_id");
  106. if (user_id != null && user_id != "" && user_id != undefined) {
  107. this.globalData.user_id = user_id;
  108. }
  109. // uni.getPushClientId({
  110. // success: (res) => {
  111. // console.log(res.cid);
  112. // // this.push_token = res.cid;
  113. // },
  114. // fail(err) {
  115. // console.log(err)
  116. // }
  117. // })
  118. // this.$nextTick(async () => {
  119. // for (var i = 0; i < tabbars.length; i++) {
  120. // await this.go(tabbars[i])
  121. // console.log('page:', i);
  122. // }
  123. // // uni.$store.commit('user/setPageState', 'loadmore')
  124. // })
  125. // #ifdef APP
  126. plus.navigator.closeSplashscreen()
  127. // #endif
  128. let that = this;
  129. uni.$on('check_login', function (callback) {
  130. let skeyLogin = uni.getStorageSync("is_login");
  131. console.log("skeylogin", skeyLogin);
  132. // callback();
  133. if (skeyLogin == null || skeyLogin == undefined || skeyLogin == "") {
  134. uni.removeStorageSync("wapptoken");
  135. uni.redirectTo({
  136. url: '/pages/login/login'
  137. });
  138. } else if (typeof callback === 'function') {
  139. callback(); // 登录状态有效时执行回调
  140. }
  141. });
  142. },
  143. onShow: function (options) {
  144. console.log('App Show');
  145. // setTimeout(()=>{
  146. // uni.hideTabBar()
  147. // },100)
  148. },
  149. onHide: function () {
  150. console.log('App Hide');
  151. },
  152. onExit: function () {
  153. unregisterRequestPermissionTipsListener(null)
  154. },
  155. onAppBackground() { },
  156. methods: {
  157. generateUUID() {
  158. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  159. const r = Math.random() * 16 | 0;
  160. const v = c === 'x' ? r : (r & 0x3 | 0x8);
  161. return v.toString(16);
  162. });
  163. },
  164. go(url) {
  165. return new Promise((resolve) => {
  166. uni.switchTab({
  167. url,
  168. complete: () => {
  169. setTimeout(() => {
  170. resolve()
  171. }, 100)
  172. }
  173. })
  174. })
  175. },
  176. }
  177. };
  178. </script>
  179. <style lang="scss">
  180. /*每个页面公共css */
  181. @import 'colorui/main.css';
  182. @import 'colorui/icon.css';
  183. @import 'style/FontStyle.css';
  184. body {
  185. -webkit-text-size-adjust: none;
  186. overscroll-behavior-y: contain;
  187. -webkit-overflow-scrolling: touch;
  188. background-color: #fff;
  189. // background: url('./http://c.yujianmate.com/images/v1/bg.png');
  190. // background-size: 750rpx 1624rpx;
  191. background-repeat: repeat-y;
  192. }
  193. /* 超出一行省略号 */
  194. .one-omit {
  195. white-space: nowrap;
  196. /*规定段落中的文本不进行换行*/
  197. overflow: hidden;
  198. /*内容会被修剪,并且其余内容是不可见的。*/
  199. text-overflow: ellipsis;
  200. /*显示省略号来代表被修剪的文本*/
  201. }
  202. .two-omit {
  203. display: -webkit-box;
  204. -webkit-line-clamp: 2;
  205. overflow: hidden;
  206. text-overflow: ellipsis;
  207. -webkit-box-orient: vertical;
  208. }
  209. img {
  210. width: 100%;
  211. }
  212. uni-modal {
  213. z-index: 998 !important;
  214. }
  215. .cu-modal {
  216. z-index: 997 !important;
  217. }
  218. </style>