App.vue 12 KB

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