App.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. <style lang="scss">
  2. /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
  3. @import "@/uni_modules/uview-ui/index.scss";
  4. </style>
  5. <script>
  6. import Vue from "vue";
  7. import appUpdate from "common/util/appUpdate.js";
  8. import configService from "@/common/service/config.service.js";
  9. import { connectWebSocket, sendWebSocketMessage, closeWebSocket } from '@/common/util/websocket'
  10. export default {
  11. data() {
  12. return {
  13. socketTask: null,//websocket对象
  14. }
  15. },
  16. onLaunch: function () {
  17. //消息推送
  18. uni.getPushClientId({
  19. //获取客户端推送标识
  20. success: (res) => {
  21. console.log(res.cid, 'cid---');
  22. uni.setStorageSync('push_cid', res.cid); // 存储CID供后续使用
  23. },
  24. fail(err) {
  25. console.log(err)
  26. }
  27. });
  28. uni.onPushMessage((res) => {
  29. //客户端监听推送消息
  30. console.log("收到推送消息:", res) //监听推送消息
  31. if (res.data) {
  32. uni.createPushMessage(res.data) //收到消息推送,创建系统状态栏及锁屏通 知
  33. }
  34. })
  35. const savedIP = uni.getStorageSync("selectedIP");
  36. if (configService.apiUrl !== "") {
  37. uni.getSystemInfo({
  38. success: function (e) {
  39. // #ifdef APP-PLUS
  40. // 检测升级
  41. appUpdate();
  42. // #endif
  43. // #ifndef MP
  44. Vue.prototype.StatusBar = e.statusBarHeight;
  45. if (e.platform == "android") {
  46. Vue.prototype.CustomBar = e.statusBarHeight + 50;
  47. } else {
  48. Vue.prototype.CustomBar = e.statusBarHeight + 45;
  49. }
  50. // #endif
  51. // #ifdef MP-WEIXIN
  52. Vue.prototype.StatusBar = e.statusBarHeight;
  53. let custom = wx.getMenuButtonBoundingClientRect();
  54. Vue.prototype.Custom = custom;
  55. Vue.prototype.CustomBar =
  56. custom.bottom + custom.top - e.statusBarHeight;
  57. // #endif
  58. // #ifdef MP-ALIPAY
  59. Vue.prototype.StatusBar = e.statusBarHeight;
  60. Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
  61. // #endif
  62. // #ifdef APP-PLUS
  63. //Vue.prototype.$api.listenTranMsg()
  64. // var info = plus.push.getClientInfo();
  65. // /* 5+ push 消息推送 ps:使用:H5+的方式监听,实现推送*/
  66. // plus.push.addEventListener("click", function(msg) {
  67. // console.log("click:" + JSON.stringify(msg));
  68. // console.log(msg.payload);
  69. // console.log(JSON.stringify(msg));
  70. // //这里可以写跳转业务代码
  71. // }, false);
  72. // // 监听在线消息事件
  73. // plus.push.addEventListener("receive", function(msg) {
  74. // // plus.ui.alert(2);
  75. // //这里可以写跳转业务代码
  76. // console.log("recevice:" + JSON.stringify(msg))
  77. // }, false);
  78. // #endif
  79. //Vue.prototype.$api.initLogin()
  80. },
  81. });
  82. Vue.prototype.NavBarColor = "bg-gradual-blue";
  83. Vue.prototype.Radio_Check_Size = "scale(0.7)";
  84. Vue.prototype.ColorList = [
  85. {
  86. title: "嫣红",
  87. name: "red",
  88. color: "#e54d42",
  89. },
  90. {
  91. title: "桔橙",
  92. name: "orange",
  93. color: "#f37b1d",
  94. },
  95. {
  96. title: "明黄",
  97. name: "yellow",
  98. color: "#fbbd08",
  99. },
  100. {
  101. title: "橄榄",
  102. name: "olive",
  103. color: "#8dc63f",
  104. },
  105. {
  106. title: "森绿",
  107. name: "green",
  108. color: "#39b54a",
  109. },
  110. {
  111. title: "天青",
  112. name: "cyan",
  113. color: "#1cbbb4",
  114. },
  115. {
  116. title: "海蓝",
  117. name: "blue",
  118. color: "#0081ff",
  119. },
  120. {
  121. title: "姹紫",
  122. name: "purple",
  123. color: "#6739b6",
  124. },
  125. {
  126. title: "木槿",
  127. name: "mauve",
  128. color: "#9c26b0",
  129. },
  130. {
  131. title: "桃粉",
  132. name: "pink",
  133. color: "#e03997",
  134. },
  135. {
  136. title: "棕褐",
  137. name: "brown",
  138. color: "#a5673f",
  139. },
  140. {
  141. title: "玄灰",
  142. name: "grey",
  143. color: "#8799a3",
  144. },
  145. {
  146. title: "草灰",
  147. name: "gray",
  148. color: "#aaaaaa",
  149. },
  150. {
  151. title: "墨黑",
  152. name: "black",
  153. color: "#333333",
  154. },
  155. {
  156. title: "雅白",
  157. name: "white",
  158. color: "#ffffff",
  159. },
  160. ];
  161. } else {
  162. if (!savedIP) {
  163. uni.reLaunch({ url: "/pages/ipConfig/ipConfig" });
  164. return;
  165. } else {
  166. uni.getSystemInfo({
  167. success: function (e) {
  168. // #ifdef APP-PLUS
  169. // 检测升级
  170. appUpdate();
  171. // #endif
  172. // #ifndef MP
  173. Vue.prototype.StatusBar = e.statusBarHeight;
  174. if (e.platform == "android") {
  175. Vue.prototype.CustomBar = e.statusBarHeight + 50;
  176. } else {
  177. Vue.prototype.CustomBar = e.statusBarHeight + 45;
  178. }
  179. // #endif
  180. // #ifdef MP-WEIXIN
  181. Vue.prototype.StatusBar = e.statusBarHeight;
  182. let custom = wx.getMenuButtonBoundingClientRect();
  183. Vue.prototype.Custom = custom;
  184. Vue.prototype.CustomBar =
  185. custom.bottom + custom.top - e.statusBarHeight;
  186. // #endif
  187. // #ifdef MP-ALIPAY
  188. Vue.prototype.StatusBar = e.statusBarHeight;
  189. Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
  190. // #endif
  191. // #ifdef APP-PLUS
  192. //Vue.prototype.$api.listenTranMsg()
  193. // var info = plus.push.getClientInfo();
  194. // /* 5+ push 消息推送 ps:使用:H5+的方式监听,实现推送*/
  195. // plus.push.addEventListener("click", function(msg) {
  196. // console.log("click:" + JSON.stringify(msg));
  197. // console.log(msg.payload);
  198. // console.log(JSON.stringify(msg));
  199. // //这里可以写跳转业务代码
  200. // }, false);
  201. // // 监听在线消息事件
  202. // plus.push.addEventListener("receive", function(msg) {
  203. // // plus.ui.alert(2);
  204. // //这里可以写跳转业务代码
  205. // console.log("recevice:" + JSON.stringify(msg))
  206. // }, false);
  207. // #endif
  208. //Vue.prototype.$api.initLogin()
  209. },
  210. });
  211. Vue.prototype.NavBarColor = "bg-gradual-blue";
  212. Vue.prototype.Radio_Check_Size = "scale(0.7)";
  213. Vue.prototype.ColorList = [
  214. {
  215. title: "嫣红",
  216. name: "red",
  217. color: "#e54d42",
  218. },
  219. {
  220. title: "桔橙",
  221. name: "orange",
  222. color: "#f37b1d",
  223. },
  224. {
  225. title: "明黄",
  226. name: "yellow",
  227. color: "#fbbd08",
  228. },
  229. {
  230. title: "橄榄",
  231. name: "olive",
  232. color: "#8dc63f",
  233. },
  234. {
  235. title: "森绿",
  236. name: "green",
  237. color: "#39b54a",
  238. },
  239. {
  240. title: "天青",
  241. name: "cyan",
  242. color: "#1cbbb4",
  243. },
  244. {
  245. title: "海蓝",
  246. name: "blue",
  247. color: "#0081ff",
  248. },
  249. {
  250. title: "姹紫",
  251. name: "purple",
  252. color: "#6739b6",
  253. },
  254. {
  255. title: "木槿",
  256. name: "mauve",
  257. color: "#9c26b0",
  258. },
  259. {
  260. title: "桃粉",
  261. name: "pink",
  262. color: "#e03997",
  263. },
  264. {
  265. title: "棕褐",
  266. name: "brown",
  267. color: "#a5673f",
  268. },
  269. {
  270. title: "玄灰",
  271. name: "grey",
  272. color: "#8799a3",
  273. },
  274. {
  275. title: "草灰",
  276. name: "gray",
  277. color: "#aaaaaa",
  278. },
  279. {
  280. title: "墨黑",
  281. name: "black",
  282. color: "#333333",
  283. },
  284. {
  285. title: "雅白",
  286. name: "white",
  287. color: "#ffffff",
  288. },
  289. ];
  290. }
  291. }
  292. },
  293. onShow: function () {
  294. console.log("App Show");
  295. this.getConnect()
  296. },
  297. onHide: function () {
  298. console.log("App Hide");
  299. clearInterval(this.$store.state.timer); // 假设定时器存储在 Vuex 的状态管理中
  300. },
  301. methods: {
  302. //获取推送消息,标题
  303. getInfoInit(title, message) {
  304. uni.request({
  305. url: 'https://fc-mp-2578c13f-eaaa-45e9-a01e-6a48b45fb7a0.next.bspapp.com/testPush', //云函数url
  306. data: {
  307. cid: uni.getStorageSync('push_cid'),
  308. title: title, //可按需传入动态参数,在云函数index.js接收参数
  309. content: message,
  310. },
  311. method: 'get',
  312. success(result) {
  313. console.log('发送通知', result);
  314. },
  315. fail({ errMsg }) {
  316. console.log('request fail', errMsg)
  317. }
  318. })
  319. },
  320. //连接websocket
  321. async getConnect() {
  322. let that = this
  323. try {
  324. that.socketTask = await connectWebSocket();
  325. that.socketTask.onMessage((res) => {
  326. console.log('收到消息:websocket已连接 ', res)
  327. let message = JSON.parse(res.data)
  328. //报警信息推送
  329. if (message.warndata) {
  330. that.getInfoInit(message.msgTitle, message.warndata)
  331. }
  332. });
  333. } catch (err) {
  334. console.log('连接失败: ' + err)
  335. }
  336. },
  337. }
  338. };
  339. </script>
  340. <style>
  341. @import "plugin/colorui/main.css";
  342. @import "plugin/colorui/icon.css";
  343. @import "plugin/colorui/animation.css";
  344. .nav-list {
  345. display: flex;
  346. flex-wrap: wrap;
  347. padding: 0px 40upx 0px;
  348. justify-content: space-between;
  349. }
  350. .nav-li {
  351. padding: 30upx;
  352. border-radius: 12upx;
  353. width: 45%;
  354. margin: 0 2.5% 40upx;
  355. background-image: url(https://cdn.nlark.com/yuque/0/2019/png/280374/1552996358352-assets/web-upload/cc3b1807-c684-4b83-8f80-80e5b8a6b975.png);
  356. background-size: cover;
  357. background-position: center;
  358. position: relative;
  359. z-index: 1;
  360. }
  361. .nav-li::after {
  362. content: "";
  363. position: absolute;
  364. z-index: -1;
  365. background-color: inherit;
  366. width: 100%;
  367. height: 100%;
  368. left: 0;
  369. bottom: -10%;
  370. border-radius: 10upx;
  371. opacity: 0.2;
  372. transform: scale(0.9, 0.9);
  373. }
  374. .nav-li.cur {
  375. color: #fff;
  376. background: rgb(94, 185, 94);
  377. box-shadow: 4upx 4upx 6upx rgba(94, 185, 94, 0.4);
  378. }
  379. .nav-title {
  380. font-size: 32upx;
  381. font-weight: 300;
  382. }
  383. .nav-title::first-letter {
  384. font-size: 40upx;
  385. margin-right: 4upx;
  386. }
  387. .nav-name {
  388. font-size: 28upx;
  389. text-transform: Capitalize;
  390. margin-top: 20upx;
  391. position: relative;
  392. }
  393. .nav-name::before {
  394. content: "";
  395. position: absolute;
  396. display: block;
  397. width: 40upx;
  398. height: 6upx;
  399. background: #fff;
  400. bottom: 0;
  401. right: 0;
  402. opacity: 0.5;
  403. }
  404. .nav-name::after {
  405. content: "";
  406. position: absolute;
  407. display: block;
  408. width: 100upx;
  409. height: 1px;
  410. background: #fff;
  411. bottom: 0;
  412. right: 40upx;
  413. opacity: 0.3;
  414. }
  415. .nav-name::first-letter {
  416. font-weight: bold;
  417. font-size: 36upx;
  418. margin-right: 1px;
  419. }
  420. .nav-li text {
  421. position: absolute;
  422. right: 30upx;
  423. top: 30upx;
  424. font-size: 52upx;
  425. width: 60upx;
  426. height: 60upx;
  427. text-align: center;
  428. line-height: 60upx;
  429. }
  430. .text-light {
  431. font-weight: 300;
  432. }
  433. @keyframes show {
  434. 0% {
  435. transform: translateY(-50px);
  436. }
  437. 60% {
  438. transform: translateY(40upx);
  439. }
  440. 100% {
  441. transform: translateY(0px);
  442. }
  443. }
  444. @-webkit-keyframes show {
  445. 0% {
  446. transform: translateY(-50px);
  447. }
  448. 60% {
  449. transform: translateY(40upx);
  450. }
  451. 100% {
  452. transform: translateY(0px);
  453. }
  454. }
  455. </style>