App.vue 9.5 KB

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