App.vue 10 KB

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