App.uvue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <script lang="uts">
  2. let firstBackTime = 0
  3. let timer = 0;
  4. export default {
  5. onLaunch: function (options: OnLaunchOptions) {
  6. console.log('App Launch')
  7. console.log('启动参数:', options)
  8. uni.onPushMessage((res) => {
  9. console.log("收到推送消息:",res) //监听推送消息
  10. if(res.type =='receive'){
  11. uni.setAppBadgeNumber(0);
  12. // 安全取出推送数据并强转类型
  13. const pushData = res.data as UTSJSONObject
  14. const title = pushData["title"] as string
  15. const content = pushData["content"] as string
  16. if (title!=null && content!=null) {
  17. uni.createPushMessage({
  18. title: title,
  19. content: content,
  20. when: Date.now() + 10000,
  21. icon: "/static/login/2.png",
  22. sound: "system",
  23. success: (res) => {
  24. console.log('创建推送消息成功', res);
  25. },
  26. fail: (err) => {
  27. console.error('创建推送消息失败', err);
  28. }
  29. });
  30. }
  31. }
  32. })
  33. uni.setStorageSync("notify_key", "0")
  34. },
  35. onShow: function (options: OnShowOptions) {
  36. console.log('App Show')
  37. },
  38. onHide: function () {
  39. console.log('App Hide')
  40. // this.startTimer();
  41. },
  42. // #ifdef APP-ANDROID
  43. onLastPageBackPress: function () {
  44. console.log('App LastPageBackPress')
  45. // #ifdef APP-ANDROID
  46. UTSAndroid.getUniActivity()?.moveTaskToBack(true)
  47. // #endif
  48. // #ifdef APP-HARMONY
  49. UTSHarmony.getUIAbilityContext().moveAbilityToBackground()
  50. // #endif
  51. },
  52. // #endif
  53. onExit: function () {
  54. console.log('App Exit')
  55. },
  56. methods:{
  57. startTimer() {
  58. console.log("==========")
  59. timer = setInterval(() => {
  60. console.log('定时器运行');
  61. // 这里写你的定时任务
  62. }, 10000); // 每1000毫秒运行一次
  63. },
  64. stopTimer() {
  65. if (timer > 0) {
  66. clearInterval(timer);
  67. timer = 0;
  68. }
  69. }
  70. }
  71. }
  72. </script>
  73. <style lang="scss">
  74. @import './static/css/form.scss';
  75. /*每个页面公共css */
  76. /* 布局 */
  77. .uni-row {
  78. flex-direction: row;
  79. }
  80. .uni-column {
  81. flex-direction: column;
  82. }
  83. /* 文字颜色 */
  84. .text-primary {
  85. color: #333333;
  86. }
  87. .text-secondary {
  88. color: #666666;
  89. }
  90. .text-placeholder {
  91. color: #999999;
  92. }
  93. /* 背景色 */
  94. .bg-white {
  95. background-color: #ffffff;
  96. }
  97. .bg-gray {
  98. background-color: #f5f5f5;
  99. }
  100. /* 间距 */
  101. .padding-sm {
  102. padding: 15rpx;
  103. }
  104. .padding-md {
  105. padding: 20rpx;
  106. }
  107. .padding-lg {
  108. padding: 30rpx;
  109. }
  110. .margin-sm {
  111. margin: 15rpx;
  112. }
  113. .margin-md {
  114. margin: 20rpx;
  115. }
  116. .margin-lg {
  117. margin: 30rpx;
  118. }
  119. /* 圆角 */
  120. .radius-sm {
  121. border-radius: 4rpx;
  122. }
  123. .radius-md {
  124. border-radius: 8rpx;
  125. }
  126. .radius-lg {
  127. border-radius: 12rpx;
  128. }
  129. </style>
  130. <style>
  131. /* #ifdef APP-HARMONY */
  132. /* 鸿蒙平台全局样式 */
  133. .l-input__placeholder {
  134. font-weight: 400 !important;
  135. font-size: 28rpx !important;
  136. color: #999999 !important;
  137. }
  138. .l-textarea__placeholder {
  139. font-weight: 400 !important;
  140. font-size: 28rpx !important;
  141. color: #999999 !important;
  142. }
  143. .l-input__control {
  144. font-weight: 400 !important;
  145. font-size: 28rpx !important;
  146. color: #131415 !important;
  147. }
  148. .l-textarea__control {
  149. font-weight: 400 !important;
  150. font-size: 28rpx !important;
  151. color: #131415 !important;
  152. }
  153. .uni-input-input {
  154. font-weight: 400 !important;
  155. font-size: 28rpx !important;
  156. color: #131415 !important;
  157. }
  158. .uni-textarea-textarea {
  159. font-weight: 400 !important;
  160. font-size: 28rpx !important;
  161. color: #131415 !important;
  162. }
  163. .uni-input-placeholder,
  164. .uni-textarea-placeholder {
  165. font-weight: 400 !important;
  166. font-size: 28rpx !important;
  167. color: #999999 !important;
  168. }
  169. /* #endif */
  170. </style>