App.vue 9.6 KB

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