index.uvue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <uni-navbar-lite :showLeft=false title="首页"></uni-navbar-lite>
  3. <view class="page-container">
  4. <!-- 背景图 -->
  5. <!-- <image class="bg-image" src="/static/images/index/1.png" mode="widthFix"></image> -->
  6. <view class="bg-color"></view>
  7. <scroll-view class="page-content">
  8. <!-- 支流出库流量图表 -->
  9. <view class="chart-section">
  10. <text class="section-title">支流出库流量 (m³/s)</text>
  11. <flow-chart />
  12. </view>
  13. <view>
  14. <button @click="handlePush">通知</button>
  15. </view>
  16. </scroll-view>
  17. <!-- 底部 TabBar -->
  18. <custom-tabbar :current="0" />
  19. </view>
  20. </template>
  21. <script setup lang="uts">
  22. import { ref, onMounted } from 'vue'
  23. import { getUserInfo } from '../../utils/storage'
  24. import FlowChart from '../../components/index/flow-chart/flow-chart.uvue'
  25. // 用户名
  26. const userName = ref<string>('用户')
  27. const handleCreateChannel = (showToast : boolean) => {
  28. // #ifdef APP-ANDROID
  29. const manager = uni.getPushChannelManager()
  30. manager.setPushChannel({
  31. channelId: "msg-pass",
  32. channelDesc: "留言审核通过",
  33. soundName: "#填写配置的声音文件名#",
  34. enableLights: true,
  35. enableVibration: true,
  36. importance: 4,
  37. lockscreenVisibility: 1
  38. } as SetPushChannelOptions)
  39. if (showToast) {
  40. uni.showToast({
  41. title: "设置渠道成功"
  42. })
  43. }
  44. // #endif
  45. }
  46. const handleCreateLocalNotification = () => {
  47. if (uni.getAppAuthorizeSetting().notificationAuthorized == "authorized") {
  48. handleCreateChannel(false)
  49. const date = new Date();
  50. const hour = date.getHours()
  51. const minute = date.getMinutes()
  52. const second = date.getSeconds()
  53. const formateTime = (target : number) : string => {
  54. return target < 10 ? `0${target}` : `${target}`
  55. }
  56. uni.createPushMessage({
  57. title: "主标题(title)",
  58. content: `内容(content),创建时间: ${formateTime(hour)}:${formateTime(minute)}:${formateTime(second)}`,
  59. cover: false,
  60. channelId: "msg-pass",
  61. when: Date.now() + 10000,
  62. icon: "/static/uni.png",
  63. sound: "system",
  64. delay: 1,
  65. payload: {
  66. pkey: "pvalue1"
  67. },
  68. // #ifdef APP-HARMONY
  69. category: "SOCIAL_COMMUNICATION",
  70. // #endif
  71. // #ifndef APP-HARMONY
  72. category: "IM",
  73. // #endif
  74. success(res) {
  75. console.log("res: " + res);
  76. uni.hideToast()
  77. uni.showToast({
  78. title: "创建本地通知消息成功"
  79. })
  80. },
  81. fail(e) {
  82. console.log("fail :" + e);
  83. uni.hideToast()
  84. uni.showToast({
  85. title: "创建本地通知消息失败",
  86. icon: "error"
  87. })
  88. }
  89. })
  90. } else {
  91. uni.showToast({
  92. title: "请在设置中开启通知权限",
  93. icon: "error"
  94. })
  95. }
  96. }
  97. const handlePush = () => {
  98. // uni.navigateTo({
  99. // url: '/pages/push/index',
  100. // fail: (err: any) => {
  101. // console.log('导航失败', err)
  102. // }
  103. // })
  104. handleCreateLocalNotification();
  105. };
  106. // 初始化
  107. onMounted(() => {
  108. const userInfo = getUserInfo()
  109. if (userInfo != null) {
  110. const realName = userInfo['nickName'] as string | null
  111. userName.value = realName ?? '用户'
  112. }
  113. })
  114. </script>
  115. <style lang="scss">
  116. .page-container {
  117. position: relative;
  118. flex: 1;
  119. padding-top: env(safe-area-inset-top);
  120. }
  121. .bg-image {
  122. position: absolute;
  123. top: 0;
  124. left: 0;
  125. width: 100%;
  126. height: 100%;
  127. z-index: 0;
  128. }
  129. .bg-color {
  130. position: absolute;
  131. top: 0;
  132. left: 0;
  133. width: 100%;
  134. height: 100%;
  135. z-index: -1;
  136. background: #71a6e4;
  137. }
  138. .page-content {
  139. position: relative;
  140. flex: 1;
  141. margin-bottom: 150rpx;
  142. padding: 30rpx;
  143. z-index: 10;
  144. }
  145. .header {
  146. flex-direction: row;
  147. height: 40px;
  148. &-title {
  149. font-size: 40rpx;
  150. color: #ffffff;
  151. font-weight: bold;
  152. margin-bottom: 15rpx;
  153. }
  154. &-greeting {
  155. font-size: 28rpx;
  156. color: rgba(255, 255, 255, 0.9);
  157. }
  158. }
  159. .section-title {
  160. font-size: 32rpx;
  161. color: #333333;
  162. font-weight: bold;
  163. margin-bottom: 20rpx;
  164. }
  165. /* 图表区域 */
  166. .chart-section {
  167. padding: 30rpx;
  168. margin-bottom: 20rpx;
  169. background: linear-gradient(180deg, rgba(255, 255, 255, 0.7) 0%, rgba(255, 255, 255, 0.9) 100%);
  170. box-shadow: 0 0 16rpx 0 rgba(0, 0, 0, 0.1);
  171. border-radius: 16rpx;
  172. }
  173. </style>