App.uvue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. uni.removeStorageSync('emcs_nextUrl')
  34. // 如果有启动参数,尝试提取apptoken
  35. if (options != null) {
  36. // 1. 从query获取
  37. const query = options.query
  38. if (query != null) {
  39. const ticketValue = query['ticket']
  40. const nextUrl = query['next']
  41. if (ticketValue != null) {
  42. const ticket = ticketValue as string
  43. console.log('保存ticket到缓存:', ticket)
  44. uni.setStorageSync('emcs_ticket', ticket)
  45. uni.setStorageSync('emcs_nextUrl', nextUrl)
  46. }
  47. }
  48. }
  49. uni.setStorageSync("notify_key", "0")
  50. },
  51. onShow: function (options: OnShowOptions) {
  52. console.log('App Show')
  53. },
  54. onHide: function () {
  55. console.log('App Hide')
  56. // this.startTimer();
  57. },
  58. // #ifdef APP-ANDROID
  59. onLastPageBackPress: function () {
  60. console.log('App LastPageBackPress')
  61. // #ifdef APP-ANDROID
  62. UTSAndroid.getUniActivity()?.moveTaskToBack(true)
  63. // #endif
  64. // #ifdef APP-HARMONY
  65. UTSHarmony.getUIAbilityContext().moveAbilityToBackground()
  66. // #endif
  67. },
  68. // #endif
  69. onExit: function () {
  70. console.log('App Exit')
  71. },
  72. methods:{
  73. }
  74. }
  75. </script>
  76. <style lang="scss">
  77. @import './static/css/form.scss';
  78. /*每个页面公共css */
  79. /* 布局 */
  80. .uni-row {
  81. flex-direction: row;
  82. }
  83. .uni-column {
  84. flex-direction: column;
  85. }
  86. /* 文字颜色 */
  87. .text-primary {
  88. color: #333333;
  89. }
  90. .text-secondary {
  91. color: #666666;
  92. }
  93. .text-placeholder {
  94. color: #999999;
  95. }
  96. /* 背景色 */
  97. .bg-white {
  98. background-color: #ffffff;
  99. }
  100. .bg-gray {
  101. background-color: #f5f5f5;
  102. }
  103. /* 间距 */
  104. .padding-sm {
  105. padding: 15rpx;
  106. }
  107. .padding-md {
  108. padding: 20rpx;
  109. }
  110. .padding-lg {
  111. padding: 30rpx;
  112. }
  113. .margin-sm {
  114. margin: 15rpx;
  115. }
  116. .margin-md {
  117. margin: 20rpx;
  118. }
  119. .margin-lg {
  120. margin: 30rpx;
  121. }
  122. /* 圆角 */
  123. .radius-sm {
  124. border-radius: 4rpx;
  125. }
  126. .radius-md {
  127. border-radius: 8rpx;
  128. }
  129. .radius-lg {
  130. border-radius: 12rpx;
  131. }
  132. </style>
  133. <style>
  134. /* #ifdef APP-HARMONY */
  135. /* 鸿蒙平台全局样式 */
  136. .l-input__placeholder {
  137. font-weight: 400 !important;
  138. font-size: 28rpx !important;
  139. color: #999999 !important;
  140. }
  141. .l-textarea__placeholder {
  142. font-weight: 400 !important;
  143. font-size: 28rpx !important;
  144. color: #999999 !important;
  145. }
  146. .l-input__control {
  147. font-weight: 400 !important;
  148. font-size: 28rpx !important;
  149. color: #131415 !important;
  150. }
  151. .l-textarea__control {
  152. font-weight: 400 !important;
  153. font-size: 28rpx !important;
  154. color: #131415 !important;
  155. }
  156. .uni-input-input {
  157. font-weight: 400 !important;
  158. font-size: 28rpx !important;
  159. color: #131415 !important;
  160. }
  161. .uni-textarea-textarea {
  162. font-weight: 400 !important;
  163. font-size: 28rpx !important;
  164. color: #131415 !important;
  165. }
  166. .uni-input-placeholder,
  167. .uni-textarea-placeholder {
  168. font-weight: 400 !important;
  169. font-size: 28rpx !important;
  170. color: #999999 !important;
  171. }
  172. /* #endif */
  173. </style>