App.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. // 执行青少年30分钟弹窗逻辑
  17. import { createTeenagePopUpWindow, setupTeenagePopupTimer } from '@/common/teenagePopup.js'
  18. uni.$createTeenagePopUpWindow = createTeenagePopUpWindow
  19. export default {
  20. globalData: {
  21. postHeader: null,
  22. headerSign: '',
  23. uuid: '',
  24. skey: '',
  25. isLogin: 0,
  26. userId: 0,
  27. socket: null,
  28. postHeader: null,
  29. systemInfo: null,
  30. nickname: '',
  31. avator: '',
  32. mobile: 0,
  33. user_id: 0,
  34. },
  35. beforeDestroy() { },
  36. onLaunch: function (options) {
  37. const intervalTime = 1000 * 30 * 60; // 30分钟的时间戳(毫秒)
  38. var timeoutId
  39. var judgingTimer = async () => {
  40. var checkTheStatusOfTeenagers = () => {
  41. return new Promise((resolve, reject) => {
  42. uni.request({
  43. url: this.$apiHost + '/Young/getYoungModeInfo',
  44. data: {
  45. uuid: this.globalData.uuid,
  46. skey: this.globalData.skey,
  47. },
  48. header: {
  49. "content-type": "application/json",
  50. 'sign': this.globalData.headerSign
  51. },
  52. success: (res) => {
  53. console.log("检查青少年状态", res.data);
  54. if (!res.data.has_password || res.data.is_open_young == 1) {
  55. setupTeenagePopupTimer()
  56. resolve(true)
  57. } else {
  58. // setupTeenagePopupTimer()
  59. resolve(false)
  60. }
  61. },
  62. complete: () => { },
  63. fail: (e) => {
  64. console.log("检查青少年状态失败", e);
  65. }
  66. });
  67. })
  68. }// 检查是否已经显示过弹窗,避免重复弹出
  69. const lastPopupTime = uni.getStorageSync('teenagePopupTime');
  70. const currentTime = Date.now();
  71. // 如果从未弹出过,或者距离上次弹出已经超过30分钟
  72. if (!lastPopupTime || (currentTime - lastPopupTime > intervalTime)) {
  73. var isTimer = await checkTheStatusOfTeenagers()
  74. console.log(isTimer, "isTimer");
  75. // 记录弹窗时间
  76. uni.setStorageSync('teenagePopupTime', currentTime);
  77. if (timeoutId) {
  78. clearTimeout(timeoutId);
  79. }
  80. if (isTimer) {
  81. timeoutId = setTimeout(judgingTimer, intervalTime);
  82. }
  83. }
  84. }
  85. setTimeout(() => {
  86. judgingTimer();
  87. }, 1000 * 60);
  88. // #ifdef APP-PLUS
  89. // var brand = uni.getSystemInfoSync().deviceBrand
  90. // setRequestPermissionTips(PermissionTips)
  91. // registerRequestPermissionTipsListener({
  92. // onRequest: (e) => {
  93. // console.log(e)
  94. // },
  95. // onConfirm: (e) => {
  96. // console.log(e)
  97. // },
  98. // onComplete: (e) => {
  99. // // 华为手机在权限禁止之后,再次申请权限不会出现权限申请框。此时应该引导用户去系统设置开启此权限,不应该频繁申请。
  100. // if (brand.toLowerCase() == "huawei" || true) {
  101. // var tips = {}
  102. // var hasDeniedPermission = false
  103. // for (var k in PermissionTips) {
  104. // if (e[k] != "denied") {
  105. // tips[k] = PermissionTips[k]
  106. // } else {
  107. // hasDeniedPermission = true
  108. // }
  109. // }
  110. // setRequestPermissionTips(tips) // 更新弹框提醒,防止华为手机不出现权限申请框时权限提醒框闪烁的情况
  111. // if (hasDeniedPermission)
  112. // uni.showModal({
  113. // content: "权限已经被拒绝,请前往设置中开启"
  114. // })
  115. // }
  116. // }
  117. // });
  118. // #endif
  119. let deviceId = "";
  120. let uuid2 = uni.getStorageSync("app_uuid");
  121. if (uuid2 && uuid2.length >= 6) {
  122. deviceId = uuid2;
  123. } else {
  124. deviceId = uni.getSystemInfoSync().deviceId || uni.getDeviceInfo().deviceId;
  125. if (!deviceId || deviceId.length < 6) {
  126. deviceId = this.generateUUID();
  127. } else {
  128. // uni.setStorageSync("app_uuid", deviceId);
  129. }
  130. }
  131. if (deviceId && deviceId.length >= 6) { } else {
  132. deviceId = new Date().getTime()
  133. }
  134. this.globalData.uuid = deviceId;
  135. uni.setStorageSync("app_uuid", deviceId);
  136. // this.globalData.uuid = "";
  137. let skey = uni.getStorageSync("wapptoken");
  138. if (skey != null && skey != "" && skey != undefined) {
  139. this.globalData.skey = skey;
  140. }
  141. if (this.globalData.headerSign == "") {
  142. let headerSignKKK = uni.getStorageSync("headerSign");
  143. if (headerSignKKK != null && headerSignKKK != "" && headerSignKKK != undefined) {
  144. this.globalData.headerSign = headerSignKKK;
  145. }
  146. }
  147. let nickname = uni.getStorageSync("nickname");
  148. if (nickname != null && nickname != "" && nickname != undefined) {
  149. this.globalData.nickname = nickname;
  150. }
  151. let avator = uni.getStorageSync("avator");
  152. if (avator != null && avator != "" && avator != undefined) {
  153. this.globalData.avator = avator;
  154. }
  155. let mobile = uni.getStorageSync("mobile");
  156. if (mobile != null && mobile != "" && mobile != undefined) {
  157. this.globalData.mobile = mobile;
  158. }
  159. let user_id = uni.getStorageSync("user_id");
  160. if (user_id != null && user_id != "" && user_id != undefined) {
  161. this.globalData.user_id = user_id;
  162. }
  163. // uni.getPushClientId({
  164. // success: (res) => {
  165. // console.log(res.cid);
  166. // // this.push_token = res.cid;
  167. // },
  168. // fail(err) {
  169. // console.log(err)
  170. // }
  171. // })
  172. // this.$nextTick(async () => {
  173. // for (var i = 0; i < tabbars.length; i++) {
  174. // await this.go(tabbars[i])
  175. // console.log('page:', i);
  176. // }
  177. // // uni.$store.commit('user/setPageState', 'loadmore')
  178. // })
  179. // #ifdef APP
  180. plus.navigator.closeSplashscreen()
  181. // #endif
  182. let that = this;
  183. uni.$on('check_login', function (callback) {
  184. let skeyLogin = uni.getStorageSync("is_login");
  185. console.log("skeylogin", skeyLogin);
  186. // callback();
  187. if (skeyLogin == null || skeyLogin == undefined || skeyLogin == "") {
  188. uni.removeStorageSync("wapptoken");
  189. uni.redirectTo({
  190. url: '/pages/login/login'
  191. });
  192. } else if (typeof callback === 'function') {
  193. callback(); // 登录状态有效时执行回调
  194. }
  195. });
  196. },
  197. onShow: function (options) {
  198. console.log('App Show');
  199. // setTimeout(()=>{
  200. // uni.hideTabBar()
  201. // },100)
  202. },
  203. onHide: function () {
  204. console.log('App Hide');
  205. },
  206. onExit: function () {
  207. unregisterRequestPermissionTipsListener(null)
  208. },
  209. onAppBackground() { },
  210. methods: {
  211. generateUUID() {
  212. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  213. const r = Math.random() * 16 | 0;
  214. const v = c === 'x' ? r : (r & 0x3 | 0x8);
  215. return v.toString(16);
  216. });
  217. },
  218. go(url) {
  219. return new Promise((resolve) => {
  220. uni.switchTab({
  221. url,
  222. complete: () => {
  223. setTimeout(() => {
  224. resolve()
  225. }, 100)
  226. }
  227. })
  228. })
  229. },
  230. }
  231. };
  232. </script>
  233. <style lang="scss">
  234. /*每个页面公共css */
  235. @import 'colorui/main.css';
  236. @import 'colorui/icon.css';
  237. @import 'style/FontStyle.css';
  238. @import url("https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css");
  239. body {
  240. -webkit-text-size-adjust: none;
  241. overscroll-behavior-y: contain;
  242. -webkit-overflow-scrolling: touch;
  243. background-color: #fff;
  244. // background: url('./http://c.yujianmate.com/images/v1/bg.png');
  245. // background-size: 750rpx 1624rpx;
  246. background-repeat: repeat-y;
  247. }
  248. /* 超出一行省略号 */
  249. .one-omit {
  250. white-space: nowrap;
  251. /*规定段落中的文本不进行换行*/
  252. overflow: hidden;
  253. /*内容会被修剪,并且其余内容是不可见的。*/
  254. text-overflow: ellipsis;
  255. /*显示省略号来代表被修剪的文本*/
  256. }
  257. .two-omit {
  258. display: -webkit-box;
  259. -webkit-line-clamp: 2;
  260. overflow: hidden;
  261. text-overflow: ellipsis;
  262. -webkit-box-orient: vertical;
  263. }
  264. img {
  265. width: 100%;
  266. }
  267. uni-modal {
  268. z-index: 998 !important;
  269. }
  270. .cu-modal {
  271. z-index: 997 !important;
  272. }
  273. </style>