App.vue 6.6 KB

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