App.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <script>
  2. export default {
  3. onLaunch: function() {
  4. console.log('App Launch')
  5. // #ifdef APP-PLUS
  6. // token标志来判断
  7. let token= uni.getStorageSync('userInfo');
  8. if (token) {
  9. //存在则关闭启动页进入首页
  10. plus.navigator.closeSplashscreen();
  11. } else {
  12. //不存在则跳转至登录页
  13. // uni.reLaunch({
  14. // url: "/pages/login/login",
  15. // success: () => {
  16. // plus.navigator.closeSplashscreen();
  17. // }
  18. // })
  19. }
  20. // #endif
  21. },
  22. onShow: function() {
  23. console.log('App Show')
  24. },
  25. onHide: function() {
  26. console.log('App Hide')
  27. },
  28. globalData: {
  29. baseUrl: 'http://192.168.137.1:8888',
  30. userName: 'admin',
  31. password: '123456'
  32. },
  33. methods: {
  34. AppExit() {
  35. uni.showModal({
  36. //计算删除的数量
  37. title: '提示',
  38. content: '是否要退出应用?', //文章内容
  39. cancelText: '取消', //取消按钮的文字
  40. confirmText: '确定', //确定文本的文字
  41. cancelColor: '#007aff', //取消按钮文本颜色
  42. confirmColor: '#007aff', //确定按钮文本颜色
  43. success: function(res) {
  44. if (res.confirm) {
  45. //console.log('用户点击了确定')
  46. let userMsg = uni.getStorageSync('userInfo')
  47. if(userMsg) {
  48. uni.request({
  49. url: 'http://192.168.137.1:8888/logout',
  50. //自定义请求头信息
  51. header: {
  52. Authorization: 'Bearer ' + userMsg.tokenStr + '',
  53. 'content-type': 'application/json'
  54. },
  55. method: 'POST',
  56. })
  57. //指定移除登录后缓存的user用户信息
  58. uni.removeStorage({
  59. key: 'userInfo',
  60. success: function(res) {
  61. //console.log('清空了用户缓存信息', );
  62. uni.showToast({
  63. title: '退出应用成功',
  64. icon: 'success',
  65. duration: 500
  66. })
  67. }
  68. })
  69. }
  70. setTimeout(() => {
  71. // main.finish();
  72. plus.runtime.quit();
  73. }, 600)
  74. } else if (res.cancel) {
  75. //console.log('用户点击了取消')
  76. }
  77. }
  78. })
  79. },
  80. RequestData(parm) {
  81. return new Promise((resolve,reject) => {
  82. let userMsg = uni.getStorageSync('userInfo')
  83. // console.log(parm.data)
  84. uni.request({
  85. url: getApp().globalData.baseUrl + parm.url,
  86. data: parm.data,
  87. header: { //自定义请求头信息
  88. Authorization: parm.isHaveToken? 'Bearer ' + userMsg.tokenStr + '' : '',
  89. 'content-type': 'application/json'
  90. },
  91. timeout: 10000,
  92. method: parm.method,
  93. success: (res) => {
  94. resolve({
  95. isSuccess : true,
  96. data : res.data,
  97. retMsg : '请求成功!'
  98. })
  99. },
  100. fail: (res) => {
  101. reject({
  102. isSuccess : false,
  103. data : {},
  104. retMsg : '请求失败!' + res.errMsg
  105. })
  106. }
  107. });
  108. })
  109. }
  110. }
  111. }
  112. </script>
  113. <style>
  114. /* #ifndef APP-PLUS-NVUE */
  115. /* uni.css - 通用组件、模板样式库,可以当作一套ui库应用 */
  116. @import './common/uni.css';
  117. @import '@/static/customicons.css';
  118. /* H5 兼容 pc 所需 */
  119. /* #ifdef H5 */
  120. @media screen and (min-width: 768px) {
  121. body {
  122. overflow-y: scroll;
  123. }
  124. }
  125. /* 顶栏通栏样式 */
  126. /* .uni-top-window {
  127. left: 0;
  128. right: 0;
  129. } */
  130. uni-page-body {
  131. background-color: #F5F5F5 !important;
  132. min-height: 100% !important;
  133. height: auto !important;
  134. }
  135. .uni-top-window uni-tabbar .uni-tabbar {
  136. background-color: #fff !important;
  137. }
  138. .uni-app--showleftwindow .hideOnPc {
  139. display: none !important;
  140. }
  141. /* #endif */
  142. /* 以下样式用于 hello uni-app 演示所需 */
  143. page {
  144. background-color: #efeff4;
  145. height: 100%;
  146. font-size: 28rpx;
  147. /* line-height: 1.8; */
  148. }
  149. .fix-pc-padding {
  150. padding: 0 50px;
  151. }
  152. .uni-header-logo {
  153. padding: 30rpx;
  154. flex-direction: column;
  155. justify-content: center;
  156. align-items: center;
  157. margin-top: 10rpx;
  158. }
  159. .uni-header-image {
  160. width: 100px;
  161. height: 100px;
  162. }
  163. .uni-hello-text {
  164. color: #7A7E83;
  165. }
  166. .uni-hello-addfile {
  167. text-align: center;
  168. line-height: 300rpx;
  169. background: #FFF;
  170. padding: 50rpx;
  171. margin-top: 10px;
  172. font-size: 38rpx;
  173. color: #808080;
  174. }
  175. /* #endif*/
  176. </style>