App.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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. // callback();
  249. if (skeyLogin == null || skeyLogin == undefined || skeyLogin == "") {
  250. uni.removeStorageSync("wapptoken");
  251. var currentPage = getCurrentPages()[getCurrentPages().length - 1];
  252. var redirectUrl = currentPage.route;
  253. var options = currentPage.options;
  254. var queryString = '';
  255. // 将options对象转换为查询字符串
  256. if (options && Object.keys(options).length > 0) {
  257. queryString = '?' + Object.keys(options)
  258. .map(key => `${key}=${encodeURIComponent(options[key])}`)
  259. .join('&');
  260. }
  261. uni.navigateTo({
  262. url: "/pages/login/login",
  263. success: function(res) {
  264. // 通过 eventChannel 向被打开页面传送数据
  265. res.eventChannel.emit('acceptDataFromOpener', {
  266. redirectUrl: redirectUrl + queryString
  267. });
  268. }
  269. });
  270. } else if (typeof callback === "function") {
  271. callback(); // 登录状态有效时执行回调
  272. }
  273. });
  274. // 将permission挂载到全局
  275. getApp().globalData.permission = permission;
  276. },
  277. onShow: function (options) {
  278. console.log("App Show");
  279. // setTimeout(()=>{
  280. // uni.hideTabBar()
  281. // },100)
  282. },
  283. onHide: function () {
  284. console.log("App Hide");
  285. },
  286. onExit: function () {
  287. unregisterRequestPermissionTipsListener(null);
  288. },
  289. onAppBackground() { },
  290. methods: {
  291. ...mapMutations('rightsManagement', ['setTeenageMode']),
  292. ...mapMutations('hideModule', ['setIsSmsLogin']),
  293. generateUUID() {
  294. return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
  295. /[xy]/g,
  296. function (c) {
  297. const r = (Math.random() * 16) | 0;
  298. const v = c === "x" ? r : (r & 0x3) | 0x8;
  299. return v.toString(16);
  300. }
  301. );
  302. },
  303. go(url) {
  304. return new Promise((resolve) => {
  305. uni.switchTab({
  306. url,
  307. complete: () => {
  308. setTimeout(() => {
  309. resolve();
  310. }, 100);
  311. },
  312. });
  313. });
  314. },
  315. },
  316. };
  317. </script>
  318. <style lang="scss">
  319. /*每个页面公共css */
  320. @import "colorui/main.css";
  321. @import "colorui/icon.css";
  322. @import "style/FontStyle.css";
  323. @import '/static/fonts/font-awesome.min.css';
  324. view,text{
  325. font-family: "PingFang SC-Medium";
  326. }
  327. body {
  328. -webkit-text-size-adjust: none;
  329. overscroll-behavior-y: contain;
  330. -webkit-overflow-scrolling: touch;
  331. background-color: #fff;
  332. // background: url('./http://c.yujianmate.com/images/v1/bg.png');
  333. // background-size: 750rpx 1624rpx;
  334. background-repeat: repeat-y;
  335. }
  336. /* 超出一行省略号 */
  337. .one-omit {
  338. white-space: nowrap;
  339. /*规定段落中的文本不进行换行*/
  340. overflow: hidden;
  341. /*内容会被修剪,并且其余内容是不可见的。*/
  342. text-overflow: ellipsis;
  343. /*显示省略号来代表被修剪的文本*/
  344. }
  345. .two-omit {
  346. display: -webkit-box;
  347. -webkit-line-clamp: 2;
  348. overflow: hidden;
  349. text-overflow: ellipsis;
  350. -webkit-box-orient: vertical;
  351. }
  352. img {
  353. width: 100%;
  354. }
  355. uni-modal {
  356. z-index: 998 !important;
  357. }
  358. .cu-modal {
  359. z-index: 997 !important;
  360. }
  361. .money-add {
  362. width: 28rpx !important;
  363. height:28rpx !important;
  364. margin-left: 10rpx;
  365. }
  366. .blick-btn-animation {
  367. position: relative;
  368. &:active {
  369. transform: scale(0.98);
  370. background-color: #333333;
  371. }
  372. &::after {
  373. content: '';
  374. position: absolute;
  375. top: 50%;
  376. left: 50%;
  377. width: 0;
  378. height: 0;
  379. background: rgba(255, 255, 255, 0.2);
  380. border-radius: 50%;
  381. transform: translate(-50%, -50%);
  382. transition: width 0.3s ease, height 0.3s ease;
  383. }
  384. &:active::after {
  385. width: 200%;
  386. height: 200%;
  387. }
  388. }
  389. .scale-tap {
  390. transition: transform 0.15s;
  391. }
  392. .scale-tap:active {
  393. transform: scale(0.92);
  394. }
  395. </style>