App.uvue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. // 清空之前的缓存
  9. uni.removeStorageSync('ice_apptoken')
  10. // 如果有启动参数,尝试提取apptoken
  11. if (options != null) {
  12. // 1. 从query获取
  13. const query = options.query
  14. if (query != null) {
  15. const apptokenValue = query['apptoken']
  16. if (apptokenValue != null) {
  17. const apptoken = apptokenValue as string
  18. console.log('保存apptoken到缓存:', apptoken)
  19. uni.setStorageSync('ice_apptoken', apptoken)
  20. }
  21. }
  22. // 2. 从appScheme获取
  23. const appScheme = options.appScheme
  24. if (appScheme != null) {
  25. const schemeStr = appScheme as string
  26. console.log('AppScheme:', schemeStr)
  27. // 简单解析apptoken
  28. if (schemeStr.includes('apptoken=')) {
  29. const parts = schemeStr.split('apptoken=')
  30. if (parts.length > 1) {
  31. const tokenPart = parts[1]
  32. const token = tokenPart.split('&')[0] // 去掉可能的后缀
  33. console.log('从scheme解析apptoken:', token)
  34. uni.setStorageSync('ice_apptoken', token)
  35. }
  36. }
  37. }
  38. }
  39. uni.setStorageSync("notify_key", "0")
  40. },
  41. onShow: function (options: OnShowOptions) {
  42. console.log('App Show')
  43. // 再次检查并保存(确保不会漏掉)
  44. if (options != null) {
  45. const query = options.query
  46. if (query != null) {
  47. const apptokenValue = query['apptoken']
  48. if (apptokenValue != null) {
  49. const apptoken = apptokenValue as string
  50. console.log('Show时保存apptoken:', apptoken)
  51. uni.setStorageSync('ice_apptoken', apptoken)
  52. }
  53. }
  54. }
  55. },
  56. onHide: function () {
  57. console.log('App Hide')
  58. // this.startTimer();
  59. },
  60. // #ifdef APP-ANDROID
  61. onLastPageBackPress: function () {
  62. console.log('App LastPageBackPress')
  63. // #ifdef APP-ANDROID
  64. UTSAndroid.getUniActivity()?.moveTaskToBack(true)
  65. // #endif
  66. // #ifdef APP-HARMONY
  67. UTSHarmony.getUIAbilityContext().moveAbilityToBackground()
  68. // #endif
  69. },
  70. // #endif
  71. onExit: function () {
  72. console.log('App Exit')
  73. },
  74. methods:{
  75. startTimer() {
  76. console.log("==========")
  77. timer = setInterval(() => {
  78. console.log('定时器运行');
  79. // 这里写你的定时任务
  80. }, 10000); // 每1000毫秒运行一次
  81. },
  82. stopTimer() {
  83. if (timer > 0) {
  84. clearInterval(timer);
  85. timer = 0;
  86. }
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang="scss">
  92. @import './static/css/form.scss';
  93. /*每个页面公共css */
  94. /* 布局 */
  95. .uni-row {
  96. flex-direction: row;
  97. }
  98. .uni-column {
  99. flex-direction: column;
  100. }
  101. /* 文字颜色 */
  102. .text-primary {
  103. color: #333333;
  104. }
  105. .text-secondary {
  106. color: #666666;
  107. }
  108. .text-placeholder {
  109. color: #999999;
  110. }
  111. /* 背景色 */
  112. .bg-white {
  113. background-color: #ffffff;
  114. }
  115. .bg-gray {
  116. background-color: #f5f5f5;
  117. }
  118. /* 间距 */
  119. .padding-sm {
  120. padding: 15rpx;
  121. }
  122. .padding-md {
  123. padding: 20rpx;
  124. }
  125. .padding-lg {
  126. padding: 30rpx;
  127. }
  128. .margin-sm {
  129. margin: 15rpx;
  130. }
  131. .margin-md {
  132. margin: 20rpx;
  133. }
  134. .margin-lg {
  135. margin: 30rpx;
  136. }
  137. /* 圆角 */
  138. .radius-sm {
  139. border-radius: 4rpx;
  140. }
  141. .radius-md {
  142. border-radius: 8rpx;
  143. }
  144. .radius-lg {
  145. border-radius: 12rpx;
  146. }
  147. </style>
  148. <style>
  149. /* #ifdef APP-HARMONY */
  150. /* 鸿蒙平台全局样式 */
  151. .l-input__placeholder {
  152. font-weight: 400 !important;
  153. font-size: 28rpx !important;
  154. color: #999999 !important;
  155. }
  156. .l-textarea__placeholder {
  157. font-weight: 400 !important;
  158. font-size: 28rpx !important;
  159. color: #999999 !important;
  160. }
  161. .l-input__control {
  162. font-weight: 400 !important;
  163. font-size: 28rpx !important;
  164. color: #131415 !important;
  165. }
  166. .l-textarea__control {
  167. font-weight: 400 !important;
  168. font-size: 28rpx !important;
  169. color: #131415 !important;
  170. }
  171. .uni-input-input {
  172. font-weight: 400 !important;
  173. font-size: 28rpx !important;
  174. color: #131415 !important;
  175. }
  176. .uni-textarea-textarea {
  177. font-weight: 400 !important;
  178. font-size: 28rpx !important;
  179. color: #131415 !important;
  180. }
  181. .uni-input-placeholder,
  182. .uni-textarea-placeholder {
  183. font-weight: 400 !important;
  184. font-size: 28rpx !important;
  185. color: #999999 !important;
  186. }
  187. /* #endif */
  188. </style>