App.vue 15 KB

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