App.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <style lang="scss">
  2. /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
  3. @import "uview-ui/index.scss";
  4. </style>
  5. <script>
  6. import store from "@/store";
  7. import socket from "@/config/socket";
  8. import DB from "@/common/sqlite";
  9. export default {
  10. onLaunch: function(e) {
  11. //取出缓存数据
  12. store.commit("setCacheData");
  13. if (store.state.token) {
  14. socket.init();
  15. } else {
  16. var url = window.location.href;
  17. if ((url.indexOf("pages/carInsure/quoteDetail1") > 0) || (url.indexOf("pages/carInsure/quoteDetail") >
  18. 0) || (url.indexOf("pages/register/register") > 0) ||
  19. (url.indexOf("pages/register/registerSuccess") > 0) || (url.indexOf("pages/carInsure/payVerify") >
  20. 0) || (url.indexOf("pages/login/mimi") > 0) || (url.indexOf("pages/login/xieyi") > 0) || (url
  21. .indexOf("pages/carInsure1/yonganCode") > 0)) {
  22. uni.navigateTo({
  23. url: url
  24. })
  25. } else {
  26. }
  27. }
  28. // #ifdef H5
  29. if (store.state.token) {
  30. socket.init();
  31. } else {
  32. var url = window.location.href;
  33. if ((url.indexOf("pages/carInsure/quoteDetail") > 0) || (url.indexOf("pages/register/register") > 0) ||
  34. (url.indexOf("pages/register/registerSuccess") > 0) || (url.indexOf("pages/carInsure/payVerify") >
  35. 0) || (url.indexOf("pages/login/mimi") > 0) || (url.indexOf("pages/login/xieyi") > 0) || (url
  36. .indexOf("pages/carInsure1/yonganCode") > 0)) {
  37. uni.navigateTo({
  38. url: url
  39. })
  40. } else {
  41. }
  42. }
  43. // #endif
  44. // #ifdef APP-PLUS
  45. this.launch()
  46. if (store.state.token) {
  47. socket.init();
  48. } else {
  49. var url = window.location.href;
  50. if ((url.indexOf("pages/carInsure/quoteDetail1") > 0) || (url.indexOf("pages/carInsure/quoteDetail") >
  51. 0) || (url.indexOf("pages/register/register") > 0) ||
  52. (url.indexOf("pages/register/registerSuccess") > 0) || (url.indexOf("pages/carInsure/payVerify") >
  53. 0) || (url.indexOf("pages/login/mimi") > 0) || (url.indexOf("pages/login/xieyi") > 0) || (url
  54. .indexOf("pages/carInsure1/yonganCode") > 0)) {
  55. uni.navigateTo({
  56. url: url
  57. })
  58. } else {
  59. }
  60. }
  61. // #endif
  62. //#ifdef APP-PLUS
  63. var info = plus.push.getClientInfo()
  64. // 使用5+App的方式进行监听消息推送
  65. plus.push.addEventListener("click", function(msg) {
  66. console.log("click:" + JSON.stringify(msg));
  67. console.log(msg.payload);
  68. console.log(JSON.stringify(msg));
  69. // onLaunch 生命周期里,页面跳转有问题,跳不过去
  70. // 应该是页面还没加载,加上定时后,就可以了;
  71. setTimeout(() => {
  72. uni.navigateTo({
  73. url: `pages/charging/chargeCoupon?data=${JSON.parse(msg.payload)}`
  74. })
  75. }, 1000)
  76. }, false);
  77. // 监听在线消息事件
  78. plus.push.addEventListener("receive", function(msg) {
  79. //业务代码
  80. console.log("recevice:" + JSON.stringify(msg))
  81. }, false);
  82. //#endif
  83. },
  84. onShow: function(e) {
  85. // #ifdef APP-PLUS
  86. DB.openSqlite()
  87. .then(res => {})
  88. .catch(error => {});
  89. // #endif
  90. // #ifdef MP-WEIXIN
  91. //获取二维码携带的参数
  92. let scene = decodeURIComponent(e.query.scene);
  93. scene = scene.split("&");
  94. let data = {
  95. //场景值
  96. scene: e.scene
  97. };
  98. scene.forEach(item => {
  99. let arr = item.split("=");
  100. if (arr.length == 2) {
  101. data[arr[0]] = arr[1];
  102. }
  103. });
  104. store.commit("setChatScenesInfo", Object.assign(e.query, data));
  105. //小程序更新
  106. if (uni.getUpdateManager) {
  107. const updateManager = uni.getUpdateManager();
  108. updateManager.onCheckForUpdate(function(res) {
  109. // 请求完新版本信息的回调
  110. // console.log(res.hasUpdate);
  111. });
  112. updateManager.onUpdateReady(function(res) {
  113. uni.showModal({
  114. title: "更新提示",
  115. content: "新版本已经准备好,是否重启应用?",
  116. success(res) {
  117. if (res.confirm) {
  118. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  119. updateManager.applyUpdate();
  120. }
  121. }
  122. });
  123. });
  124. updateManager.onUpdateFailed(function(res) {
  125. // 新的版本下载失败
  126. uni.showModal({
  127. title: "已经有新版本了哟~",
  128. content: "新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~",
  129. showCancel: false
  130. });
  131. });
  132. }
  133. // #endif
  134. },
  135. onHide: function() {},
  136. methods: {
  137. // TODO 开屏广告 后续优化添加
  138. launch() {
  139. try {
  140. var date = new Date();
  141. var year = date.getFullYear();
  142. var month = date.getMonth() + 1;
  143. var strDate = date.getDate();
  144. var currentdate = year + '' + month + '' + strDate + '' + plus.runtime.version;
  145. // 获取本地存储中launchFlag标识(不可动)
  146. const value = uni.getStorageSync("launchFlag");
  147. if (value == currentdate) {} else {
  148. //app启动时打开启动广告页
  149. var w = plus.webview.open(
  150. "/hybrid/html/advertise/advertise.html",
  151. "本地地址", {
  152. top: 0,
  153. bottom: 0,
  154. zindex: 999,
  155. },
  156. "fade-in",
  157. 500
  158. );
  159. //设置定时器,4s后关闭启动
  160. setTimeout(function() {
  161. uni.setStorage({
  162. key: "launchFlag",
  163. data: currentdate
  164. });
  165. plus.webview.close(w);
  166. }, 3000);
  167. }
  168. } catch (e) {
  169. // error
  170. uni.setStorage({
  171. key: "launchFlag",
  172. data: currentdate,
  173. success: function() {
  174. console.log("error时存储launchFlag");
  175. },
  176. });
  177. }
  178. },
  179. }
  180. };
  181. </script>
  182. <style>
  183. /* #ifndef APP-NVUE */
  184. @import "/style/uni.css";
  185. /* 官方ui库 */
  186. @import "/style/animate.min.css";
  187. /* 第三方动画库 */
  188. /* @import "/style/icon.css"; */
  189. /* 自定义图标库 */
  190. @import 'http://at.alicdn.com/t/font_1807257_t3nqcuysmns.css';
  191. @import "/style/common.css";
  192. /* 公共样式库 */
  193. @import "/style/zcm-main.css";
  194. /* UI基础库 */
  195. /* @import "/style/input.scss"; */
  196. /* 基础表单样式*/
  197. /* #endif */
  198. /* #ifdef H5 */
  199. /* 修复H5底部导航挡住内容bug */
  200. uni-app {
  201. height: auto;
  202. }
  203. /* 修复H5输入框上下不居中bug */
  204. .uni-input-form {
  205. height: 100%;
  206. }
  207. /* 去除地图上高德地图标识符 */
  208. .amap-copyright {
  209. display: none !important;
  210. }
  211. .amap-logo {
  212. display: none !important;
  213. }
  214. .amap-ui-control-zoom {
  215. width: 60upx !important;
  216. }
  217. .amap-ui-control-zoom>* {
  218. width: 60upx !important;
  219. height: 60upx !important;
  220. line-height: 60upx !important;
  221. }
  222. .amap-ui-control-theme-dark {
  223. display: none !important;
  224. }
  225. /* #endif */
  226. </style>