App.vue 16 KB

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