App.uvue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <script lang="uts">
  2. export default {
  3. onLaunch: function (options: OnLaunchOptions) {
  4. console.log('App Launch')
  5. console.log('启动参数:', options)
  6. uni.onPushMessage((res) => {
  7. console.log("收到推送消息:",res) //监听推送消息
  8. if(res.type =='receive'){
  9. uni.setAppBadgeNumber(0);
  10. // 安全取出推送数据并强转类型
  11. const pushData = res.data as UTSJSONObject
  12. const title = pushData["title"] as string
  13. const content = pushData["content"] as string
  14. if (title!=null && content!=null) {
  15. uni.createPushMessage({
  16. title: title,
  17. content: content,
  18. when: Date.now() + 10000,
  19. icon: "/static/login/2.png",
  20. sound: "system",
  21. success: (res) => {
  22. console.log('创建推送消息成功', res);
  23. },
  24. fail: (err) => {
  25. console.error('创建推送消息失败', err);
  26. }
  27. });
  28. }
  29. }
  30. })
  31. // 清空之前的缓存
  32. uni.removeStorageSync('emcs_ticket')
  33. // 如果有启动参数,尝试提取apptoken
  34. if (options != null) {
  35. // 1. 从query获取
  36. const query = options.query
  37. if (query != null) {
  38. const ticketValue = query['ticket']
  39. if (ticketValue != null) {
  40. const ticket = ticketValue as string
  41. console.log('保存ticket到缓存:', ticket)
  42. uni.setStorageSync('emcs_ticket', ticket)
  43. }
  44. }
  45. }
  46. uni.setStorageSync("notify_key", "0")
  47. },
  48. onShow: function (options: OnShowOptions) {
  49. console.log('App Show')
  50. },
  51. onHide: function () {
  52. console.log('App Hide')
  53. // this.startTimer();
  54. },
  55. // #ifdef APP-ANDROID
  56. onLastPageBackPress: function () {
  57. console.log('App LastPageBackPress')
  58. // #ifdef APP-ANDROID
  59. UTSAndroid.getUniActivity()?.moveTaskToBack(true)
  60. // #endif
  61. // #ifdef APP-HARMONY
  62. UTSHarmony.getUIAbilityContext().moveAbilityToBackground()
  63. // #endif
  64. },
  65. // #endif
  66. onExit: function () {
  67. console.log('App Exit')
  68. },
  69. methods:{
  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>