App.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  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 api from "@/api/api";
  10. export default {
  11. data() {
  12. return {
  13. socketTask: null,//websocket对象
  14. }
  15. },
  16. onLaunch: function () {
  17. //app在线版本更新
  18. this.checkVersion()
  19. // this.getVersionFn()
  20. //消息推送
  21. this.getPushClientID()
  22. const savedIP = uni.getStorageSync("selectedIP");
  23. if (configService.apiUrl !== "") {
  24. uni.getSystemInfo({
  25. success: function (e) {
  26. // #ifdef APP-PLUS
  27. // 检测升级
  28. appUpdate();
  29. // #endif
  30. // #ifndef MP
  31. Vue.prototype.StatusBar = e.statusBarHeight;
  32. if (e.platform == "android") {
  33. Vue.prototype.CustomBar = e.statusBarHeight + 50;
  34. } else {
  35. Vue.prototype.CustomBar = e.statusBarHeight + 45;
  36. }
  37. // #endif
  38. // #ifdef MP-WEIXIN
  39. Vue.prototype.StatusBar = e.statusBarHeight;
  40. let custom = wx.getMenuButtonBoundingClientRect();
  41. Vue.prototype.Custom = custom;
  42. Vue.prototype.CustomBar =
  43. custom.bottom + custom.top - e.statusBarHeight;
  44. // #endif
  45. // #ifdef MP-ALIPAY
  46. Vue.prototype.StatusBar = e.statusBarHeight;
  47. Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
  48. // #endif
  49. // #ifdef APP-PLUS
  50. //Vue.prototype.$api.listenTranMsg()
  51. // var info = plus.push.getClientInfo();
  52. // /* 5+ push 消息推送 ps:使用:H5+的方式监听,实现推送*/
  53. // plus.push.addEventListener("click", function(msg) {
  54. // console.log("click:" + JSON.stringify(msg));
  55. // console.log(msg.payload);
  56. // console.log(JSON.stringify(msg));
  57. // //这里可以写跳转业务代码
  58. // }, false);
  59. // // 监听在线消息事件
  60. // plus.push.addEventListener("receive", function(msg) {
  61. // // plus.ui.alert(2);
  62. // //这里可以写跳转业务代码
  63. // console.log("recevice:" + JSON.stringify(msg))
  64. // }, false);
  65. // #endif
  66. //Vue.prototype.$api.initLogin()
  67. },
  68. });
  69. Vue.prototype.NavBarColor = "bg-gradual-blue";
  70. Vue.prototype.Radio_Check_Size = "scale(0.7)";
  71. Vue.prototype.ColorList = [
  72. {
  73. title: "嫣红",
  74. name: "red",
  75. color: "#e54d42",
  76. },
  77. {
  78. title: "桔橙",
  79. name: "orange",
  80. color: "#f37b1d",
  81. },
  82. {
  83. title: "明黄",
  84. name: "yellow",
  85. color: "#fbbd08",
  86. },
  87. {
  88. title: "橄榄",
  89. name: "olive",
  90. color: "#8dc63f",
  91. },
  92. {
  93. title: "森绿",
  94. name: "green",
  95. color: "#39b54a",
  96. },
  97. {
  98. title: "天青",
  99. name: "cyan",
  100. color: "#1cbbb4",
  101. },
  102. {
  103. title: "海蓝",
  104. name: "blue",
  105. color: "#0081ff",
  106. },
  107. {
  108. title: "姹紫",
  109. name: "purple",
  110. color: "#6739b6",
  111. },
  112. {
  113. title: "木槿",
  114. name: "mauve",
  115. color: "#9c26b0",
  116. },
  117. {
  118. title: "桃粉",
  119. name: "pink",
  120. color: "#e03997",
  121. },
  122. {
  123. title: "棕褐",
  124. name: "brown",
  125. color: "#a5673f",
  126. },
  127. {
  128. title: "玄灰",
  129. name: "grey",
  130. color: "#8799a3",
  131. },
  132. {
  133. title: "草灰",
  134. name: "gray",
  135. color: "#aaaaaa",
  136. },
  137. {
  138. title: "墨黑",
  139. name: "black",
  140. color: "#333333",
  141. },
  142. {
  143. title: "雅白",
  144. name: "white",
  145. color: "#ffffff",
  146. },
  147. ];
  148. } else {
  149. if (!savedIP) {
  150. uni.reLaunch({ url: "/pages/ipConfig/ipConfig" });
  151. return;
  152. } else {
  153. uni.getSystemInfo({
  154. success: function (e) {
  155. // #ifdef APP-PLUS
  156. // 检测升级
  157. appUpdate();
  158. // #endif
  159. // #ifndef MP
  160. Vue.prototype.StatusBar = e.statusBarHeight;
  161. if (e.platform == "android") {
  162. Vue.prototype.CustomBar = e.statusBarHeight + 50;
  163. } else {
  164. Vue.prototype.CustomBar = e.statusBarHeight + 45;
  165. }
  166. // #endif
  167. // #ifdef MP-WEIXIN
  168. Vue.prototype.StatusBar = e.statusBarHeight;
  169. let custom = wx.getMenuButtonBoundingClientRect();
  170. Vue.prototype.Custom = custom;
  171. Vue.prototype.CustomBar =
  172. custom.bottom + custom.top - e.statusBarHeight;
  173. // #endif
  174. // #ifdef MP-ALIPAY
  175. Vue.prototype.StatusBar = e.statusBarHeight;
  176. Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
  177. // #endif
  178. // #ifdef APP-PLUS
  179. //Vue.prototype.$api.listenTranMsg()
  180. // var info = plus.push.getClientInfo();
  181. // /* 5+ push 消息推送 ps:使用:H5+的方式监听,实现推送*/
  182. // plus.push.addEventListener("click", function(msg) {
  183. // console.log("click:" + JSON.stringify(msg));
  184. // console.log(msg.payload);
  185. // console.log(JSON.stringify(msg));
  186. // //这里可以写跳转业务代码
  187. // }, false);
  188. // // 监听在线消息事件
  189. // plus.push.addEventListener("receive", function(msg) {
  190. // // plus.ui.alert(2);
  191. // //这里可以写跳转业务代码
  192. // console.log("recevice:" + JSON.stringify(msg))
  193. // }, false);
  194. // #endif
  195. //Vue.prototype.$api.initLogin()
  196. },
  197. });
  198. Vue.prototype.NavBarColor = "bg-gradual-blue";
  199. Vue.prototype.Radio_Check_Size = "scale(0.7)";
  200. Vue.prototype.ColorList = [
  201. {
  202. title: "嫣红",
  203. name: "red",
  204. color: "#e54d42",
  205. },
  206. {
  207. title: "桔橙",
  208. name: "orange",
  209. color: "#f37b1d",
  210. },
  211. {
  212. title: "明黄",
  213. name: "yellow",
  214. color: "#fbbd08",
  215. },
  216. {
  217. title: "橄榄",
  218. name: "olive",
  219. color: "#8dc63f",
  220. },
  221. {
  222. title: "森绿",
  223. name: "green",
  224. color: "#39b54a",
  225. },
  226. {
  227. title: "天青",
  228. name: "cyan",
  229. color: "#1cbbb4",
  230. },
  231. {
  232. title: "海蓝",
  233. name: "blue",
  234. color: "#0081ff",
  235. },
  236. {
  237. title: "姹紫",
  238. name: "purple",
  239. color: "#6739b6",
  240. },
  241. {
  242. title: "木槿",
  243. name: "mauve",
  244. color: "#9c26b0",
  245. },
  246. {
  247. title: "桃粉",
  248. name: "pink",
  249. color: "#e03997",
  250. },
  251. {
  252. title: "棕褐",
  253. name: "brown",
  254. color: "#a5673f",
  255. },
  256. {
  257. title: "玄灰",
  258. name: "grey",
  259. color: "#8799a3",
  260. },
  261. {
  262. title: "草灰",
  263. name: "gray",
  264. color: "#aaaaaa",
  265. },
  266. {
  267. title: "墨黑",
  268. name: "black",
  269. color: "#333333",
  270. },
  271. {
  272. title: "雅白",
  273. name: "white",
  274. color: "#ffffff",
  275. },
  276. ];
  277. }
  278. }
  279. },
  280. onShow: function () {
  281. console.log("App Show");
  282. },
  283. onHide: function () {
  284. console.log("App Hide");
  285. clearInterval(this.$store.state.timer); // 假设定时器存储在 Vuex 的状态管理中
  286. },
  287. methods: {
  288. //消息推送
  289. getPushClientID() {
  290. uni.getPushClientId({
  291. //获取客户端推送标识
  292. success: (res) => {
  293. console.log(res.cid, 'cid---');
  294. uni.setStorageSync('push_cid', res.cid); // 存储CID供后续使用
  295. },
  296. fail(err) {
  297. console.log(err)
  298. }
  299. });
  300. },
  301. // 检测版本
  302. checkVersion() {
  303. plus.runtime.getProperty(plus.runtime.appid, (appInfo) => {
  304. // 获取版本号
  305. const currentVersion = appInfo.version
  306. // 这是用来看看版本是多少的
  307. console.log(currentVersion, '版本号');
  308. this.getVersionFn(currentVersion)
  309. });
  310. },
  311. getVersionFn(currentVersion) {
  312. let that = this
  313. new Promise((resolve, reject) => {
  314. api
  315. .getAppLast({})
  316. .then((response) => {
  317. if (response.statusCode == 200) {
  318. console.log(response, '响应数据')
  319. const updateUrl = `${configService.apiUrlP}:9999${response.data.downloadUrl}`; // 下载地址
  320. let indexF = response.data.filename.lastIndexOf('-')
  321. let indexL = response.data.filename.lastIndexOf('.')
  322. const latestVersion = response.data.filename.substring(indexF + 1, indexL)// 版本号
  323. console.log(updateUrl, '下载地址')
  324. console.log(latestVersion, '版本号')
  325. // 比较版本号,判断是否有新版本
  326. if (that.compareVersion(currentVersion, latestVersion) < 0) {
  327. // 提示用户更新
  328. uni.showModal({
  329. title: '更新提示',
  330. content: '检测到新版本,是否立即更新?',
  331. success: (modalRes) => {
  332. if (modalRes.confirm) {
  333. // 用户确认更新,下载新版本
  334. that.downloadAndInstall(updateUrl);
  335. }
  336. }
  337. });
  338. } else {
  339. console.log('当前已是最新版本');
  340. }
  341. } else {
  342. reject(response);
  343. }
  344. })
  345. .catch((error) => {
  346. console.log("catch===>response", response);
  347. reject(error);
  348. });
  349. });
  350. },
  351. // 比较版本号
  352. compareVersion(v1, v2) {
  353. const version1 = v1.split('.').map(Number);
  354. const version2 = v2.split('.').map(Number);
  355. for (let i = 0; i < version1.length; i++) {
  356. if (version1[i] < version2[i]) {
  357. return -1;
  358. } else if (version1[i] > version2[i]) {
  359. return 1;
  360. }
  361. }
  362. return 0;
  363. },
  364. // 下载并安装新版本
  365. downloadAndInstall(url) {
  366. let dtask = plus.downloader.createDownload(url, {
  367. filename: '_downloads/temporary.apk' //利用保存路径,实现下载文件的重命名
  368. },
  369. function (d, status) {
  370. // 下载完成
  371. if (status == 200) {
  372. plus.runtime.install(plus.io.convertLocalFileSystemURL(
  373. d.filename), {}, {}, function (error) {
  374. uni.showToast({
  375. title: '安装失败',
  376. duration: 1500
  377. });
  378. })
  379. } else {
  380. uni.showToast({
  381. title: '更新失败',
  382. duration: 1500
  383. });
  384. }
  385. });
  386. try {
  387. console.log('开始下载');
  388. dtask.start(); // 开启下载的任务
  389. let prg = 0;
  390. let showLoading = plus.nativeUI.showWaiting(
  391. "正在下载"); //创建一个showWaiting对象
  392. dtask.addEventListener('statechanged', function (
  393. task,
  394. status
  395. ) {
  396. // 给下载任务设置一个监听 并根据状态 做操作
  397. switch (task.state) {
  398. case 1:
  399. showLoading.setTitle("正在下载");
  400. break;
  401. case 2:
  402. showLoading.setTitle("已连接到服务器");
  403. break;
  404. case 3:
  405. prg = parseInt(
  406. (parseFloat(task.downloadedSize) /
  407. parseFloat(task.totalSize)) *
  408. 100
  409. );
  410. showLoading.setTitle(" 正在下载" + prg + "% ");
  411. break;
  412. case 4:
  413. plus.nativeUI.closeWaiting();
  414. //下载完成
  415. break;
  416. }
  417. });
  418. } catch (err) {
  419. plus.nativeUI.closeWaiting();
  420. uni.showToast({
  421. title: '更新失败',
  422. mask: false,
  423. duration: 1500
  424. });
  425. }
  426. }
  427. }
  428. };
  429. </script>
  430. <style>
  431. @import "plugin/colorui/main.css";
  432. @import "plugin/colorui/icon.css";
  433. @import "plugin/colorui/animation.css";
  434. .nav-list {
  435. display: flex;
  436. flex-wrap: wrap;
  437. padding: 0px 40upx 0px;
  438. justify-content: space-between;
  439. }
  440. .nav-li {
  441. padding: 30upx;
  442. border-radius: 12upx;
  443. width: 45%;
  444. margin: 0 2.5% 40upx;
  445. background-image: url(https://cdn.nlark.com/yuque/0/2019/png/280374/1552996358352-assets/web-upload/cc3b1807-c684-4b83-8f80-80e5b8a6b975.png);
  446. background-size: cover;
  447. background-position: center;
  448. position: relative;
  449. z-index: 1;
  450. }
  451. .nav-li::after {
  452. content: "";
  453. position: absolute;
  454. z-index: -1;
  455. background-color: inherit;
  456. width: 100%;
  457. height: 100%;
  458. left: 0;
  459. bottom: -10%;
  460. border-radius: 10upx;
  461. opacity: 0.2;
  462. transform: scale(0.9, 0.9);
  463. }
  464. .nav-li.cur {
  465. color: #fff;
  466. background: rgb(94, 185, 94);
  467. box-shadow: 4upx 4upx 6upx rgba(94, 185, 94, 0.4);
  468. }
  469. .nav-title {
  470. font-size: 32upx;
  471. font-weight: 300;
  472. }
  473. .nav-title::first-letter {
  474. font-size: 40upx;
  475. margin-right: 4upx;
  476. }
  477. .nav-name {
  478. font-size: 28upx;
  479. text-transform: Capitalize;
  480. margin-top: 20upx;
  481. position: relative;
  482. }
  483. .nav-name::before {
  484. content: "";
  485. position: absolute;
  486. display: block;
  487. width: 40upx;
  488. height: 6upx;
  489. background: #fff;
  490. bottom: 0;
  491. right: 0;
  492. opacity: 0.5;
  493. }
  494. .nav-name::after {
  495. content: "";
  496. position: absolute;
  497. display: block;
  498. width: 100upx;
  499. height: 1px;
  500. background: #fff;
  501. bottom: 0;
  502. right: 40upx;
  503. opacity: 0.3;
  504. }
  505. .nav-name::first-letter {
  506. font-weight: bold;
  507. font-size: 36upx;
  508. margin-right: 1px;
  509. }
  510. .nav-li text {
  511. position: absolute;
  512. right: 30upx;
  513. top: 30upx;
  514. font-size: 52upx;
  515. width: 60upx;
  516. height: 60upx;
  517. text-align: center;
  518. line-height: 60upx;
  519. }
  520. .text-light {
  521. font-weight: 300;
  522. }
  523. @keyframes show {
  524. 0% {
  525. transform: translateY(-50px);
  526. }
  527. 60% {
  528. transform: translateY(40upx);
  529. }
  530. 100% {
  531. transform: translateY(0px);
  532. }
  533. }
  534. @-webkit-keyframes show {
  535. 0% {
  536. transform: translateY(-50px);
  537. }
  538. 60% {
  539. transform: translateY(40upx);
  540. }
  541. 100% {
  542. transform: translateY(0px);
  543. }
  544. }
  545. </style>