App.vue 11 KB

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